mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Define Port Groups * . * . * . * API Calls * . * . * . * minor changes * . * update forms * remove link * . * change column settings * change migration * change update position * db migration fix * . * . * . * add missing doc reference * update test data * update test data * update test data * . * . * . * . * . * . * . * . * port group association in seperate table * . * . * show all found groups on port * select multiple Portgroups per Port * change on migration file * change query to eloquent * Code changes * move port group menu to ports main menu * port group update to eloquent * . * . * update to new setting way * add missing merge parameter * Use select2 and port some things to Laravel some fixes, hopefully no new added bugs * schema * don't use on update restrict unfortunately * remove unused import and revert changes Co-authored-by: Tony Murray <murraytony@gmail.com>
82 lines
2.3 KiB
PHP
82 lines
2.3 KiB
PHP
<?php
|
|
|
|
header('Content-type: application/json');
|
|
|
|
if (! Auth::user()->hasGlobalAdmin()) {
|
|
$response = [
|
|
'status' => 'error',
|
|
'message' => 'Need to be admin',
|
|
];
|
|
echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
$status = 'error';
|
|
$message = 'Error with config';
|
|
|
|
// enable/disable ports/interfaces on devices.
|
|
$device_id = intval($_POST['device']);
|
|
$rows_updated = 0;
|
|
|
|
foreach ($_POST as $key => $val) {
|
|
if (strncmp($key, 'oldign_', 7) == 0) {
|
|
// Interface identifier passed as part of the field name
|
|
$port_id = intval(substr($key, 7));
|
|
|
|
$oldign = intval($val) ? 1 : 0;
|
|
$newign = $_POST['ignore_' . $port_id] ? 1 : 0;
|
|
|
|
// As checkboxes are not posted when unset - we effectively need to do a diff to work
|
|
// out a set->unset case.
|
|
if ($oldign == $newign) {
|
|
continue;
|
|
}
|
|
|
|
$n = dbUpdate(['ignore' => $newign], 'ports', '`device_id` = ? AND `port_id` = ?', [$device_id, $port_id]);
|
|
|
|
if ($n < 0) {
|
|
$rows_updated = -1;
|
|
break;
|
|
}
|
|
|
|
$rows_updated += $n;
|
|
} elseif (strncmp($key, 'olddis_', 7) == 0) {
|
|
// Interface identifier passed as part of the field name
|
|
$port_id = intval(substr($key, 7));
|
|
|
|
$olddis = intval($val) ? 1 : 0;
|
|
$newdis = $_POST['disabled_' . $port_id] ? 1 : 0;
|
|
|
|
// As checkboxes are not posted when unset - we effectively need to do a diff to work
|
|
// out a set->unset case.
|
|
if ($olddis == $newdis) {
|
|
continue;
|
|
}
|
|
|
|
$n = dbUpdate(['disabled' => $newdis], 'ports', '`device_id` = ? AND `port_id` = ?', [$device_id, $port_id]);
|
|
|
|
if ($n < 0) {
|
|
$rows_updated = -1;
|
|
break;
|
|
}
|
|
|
|
$rows_updated += $n;
|
|
}//end if
|
|
}//end foreach
|
|
|
|
if ($rows_updated > 0) {
|
|
$message = $rows_updated . ' Port record(s) updated.';
|
|
$status = 'ok';
|
|
} elseif ($rows_updated = '-1') {
|
|
$message = 'Port records unchanged. No update necessary.';
|
|
$status = 'ok';
|
|
} else {
|
|
$message = 'Port record update error.';
|
|
}
|
|
|
|
$response = [
|
|
'status' => $status,
|
|
'message' => $message,
|
|
];
|
|
echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|