Files

82 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2010-09-03 13:32:11 +00:00
<?php
2016-04-26 15:06:29 -07:00
header('Content-type: application/json');
2010-09-03 13:32:11 +00:00
2020-09-21 15:40:17 +02:00
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
2020-09-21 15:40:17 +02:00
];
echo _json_encode($response);
exit;
}
2020-09-21 15:40:17 +02:00
$status = 'error';
$message = 'Error with config';
2015-07-20 13:55:35 +01:00
// enable/disable ports/interfaces on devices.
2020-09-21 15:40:17 +02:00
$device_id = intval($_POST['device']);
2010-09-03 13:32:11 +00:00
$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;
2020-09-21 15:40:17 +02:00
$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;
}
2020-09-21 15:40:17 +02:00
$n = dbUpdate(['ignore' => $newign], 'ports', '`device_id` = ? AND `port_id` = ?', [$device_id, $port_id]);
2011-03-17 11:29:23 +00:00
if ($n < 0) {
$rows_updated = -1;
break;
}
$rows_updated += $n;
2016-08-18 20:28:22 -05:00
} 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;
2020-09-21 15:40:17 +02:00
$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;
}
2020-09-21 15:40:17 +02:00
$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
2011-03-17 11:29:23 +00:00
if ($rows_updated > 0) {
2020-09-21 15:40:17 +02:00
$message = $rows_updated . ' Device record updated.';
$status = 'ok';
2016-08-18 20:28:22 -05:00
} elseif ($rows_updated = '-1') {
2015-07-20 13:55:35 +01:00
$message = 'Device record unchanged. No update necessary.';
2020-09-21 15:40:17 +02:00
$status = 'ok';
2016-08-18 20:28:22 -05:00
} else {
2015-07-20 13:55:35 +01:00
$message = 'Device record update error.';
}
2015-07-20 13:55:35 +01:00
2020-09-21 15:40:17 +02:00
$response = [
2015-07-20 13:55:35 +01:00
'status' => $status,
'message' => $message,
2020-09-21 15:40:17 +02:00
];
2015-07-20 13:55:35 +01:00
echo _json_encode($response);