librenms-librenms/includes/html/forms/update-ifalias.inc.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.6 KiB
PHP
Raw Normal View History

2015-08-30 20:27:55 +00:00
<?php
/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
header('Content-type: application/json');
2015-08-30 20:27:55 +00:00
$status = 'error';
$descr = $_POST['descr'];
$device_id = $_POST['device_id'];
$ifName = $_POST['ifName'];
$port_id = $_POST['port_id'];
2015-08-30 20:27:55 +00:00
if (! empty($ifName) && is_numeric($port_id)) {
// We have ifName and port id so update ifAlias
2015-08-30 13:50:44 -07:00
if (empty($descr)) {
$descr = 'repoll';
// Set to repoll so we avoid using ifDescr on port poll
}
if (dbUpdate(['ifAlias' => $descr], 'ports', '`port_id`=?', [$port_id]) > 0) {
2015-08-30 20:27:55 +00:00
$device = device_by_id_cache($device_id);
2015-08-30 14:34:37 -07:00
if ($descr === 'repoll') {
2015-10-10 13:34:51 +00:00
del_dev_attrib($device, 'ifName:' . $ifName);
log_event("$ifName Port ifAlias cleared manually", $device, 'interface', 3, $port_id);
} else {
2015-10-10 13:34:51 +00:00
set_dev_attrib($device, 'ifName:' . $ifName, 1);
log_event("$ifName Port ifAlias set manually: $descr", $device, 'interface', 3, $port_id);
2015-08-30 20:27:55 +00:00
}
$status = 'ok';
} else {
2015-08-30 20:27:55 +00:00
$status = 'na';
}
}
2015-08-30 13:47:47 -07:00
$response = [
'status' => $status,
2015-08-30 13:47:47 -07:00
];
echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);