Revert "Fix coding style old files (part 2)"

This commit is contained in:
Daniel Preussker
2015-07-15 08:09:10 +00:00
parent 4ebabc634a
commit ba90b85f9f
731 changed files with 33750 additions and 37288 deletions
+17 -21
View File
@@ -13,29 +13,25 @@
*/
$alert_id = mres($_POST['alert_id']);
$state = mres($_POST['state']);
if (!is_numeric($alert_id)) {
echo 'ERROR: No alert selected';
$state = mres($_POST['state']);
if(!is_numeric($alert_id)) {
echo('ERROR: No alert selected');
exit;
}
else if (!is_numeric($state)) {
echo 'ERROR: No state passed';
} elseif(!is_numeric($state)) {
echo('ERROR: No state passed');
exit;
}
else {
if ($state == 2) {
$state = dbFetchCell('SELECT alerted FROM alerts WHERE id = ?', array($alert_id));
}
else if ($state >= 1) {
} else {
if($state == 2) {
$state = dbFetchCell('SELECT alerted FROM alerts WHERE id = ?',array($alert_id));
} elseif($state >= 1) {
$state = 2;
}
if(dbUpdate(array('state' => $state), 'alerts', 'id=?',array($alert_id)) >= 0) {
echo('Alert acknowledged status changed.');
exit;
} else {
echo('ERROR: Alert has not been acknowledged.');
exit;
}
}
if (dbUpdate(array('state' => $state), 'alerts', 'id=?', array($alert_id)) >= 0) {
echo 'Alert acknowledged status changed.';
exit;
}
else {
echo 'ERROR: Alert has not been acknowledged.';
exit;
}
}//end if
+10 -18
View File
@@ -4,12 +4,12 @@
* 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.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
@@ -44,43 +44,35 @@ if(!empty($name)) {
}
if(dbUpdate(array('rule_id' => mres($_REQUEST['rule_id']), 'name' => $name), "alert_templates", "id = ?", array($_REQUEST['template_id']))) {
$ok = "Updated template and rule id mapping";
}
else {
} else {
$error ="Failed to update the template and rule id mapping";
}
}
elseif( $_REQUEST['template'] && is_numeric($_REQUEST['template_id']) ) {
} elseif( $_REQUEST['template'] && is_numeric($_REQUEST['template_id']) ) {
//Update template-text
if($ret = dbUpdate(array('template' => $_REQUEST['template'], 'name' => $name), "alert_templates", "id = ?", array($_REQUEST['template_id']))) {
$ok = "Updated template";
}
else {
} else {
$error = "Failed to update the template";
}
}
elseif( $_REQUEST['template'] ) {
} elseif( $_REQUEST['template'] ) {
//Create new template
if(dbInsert(array('template' => $_REQUEST['template'], 'name' => $name), "alert_templates")) {
$ok = "Alert template has been created.";
}
else {
} else {
$error = "Could not create alert template";
}
}
else {
} else {
$error = "We could not work out what you wanted to do!";
}
}
else {
} else {
$error = "You haven't given your template a name, it feels sad :( - $name";
}
if(!empty( $ok )) {
die("$ok");
}
else {
} else {
die("ERROR: $error");
}
?>
+14 -16
View File
@@ -12,32 +12,30 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
if (!is_numeric($_POST['template_id'])) {
echo 'ERROR: No template selected';
if(!is_numeric($_POST['template_id'])) {
echo('ERROR: No template selected');
exit;
}
else {
$rules = preg_split('/,/', mres($_POST['rule_id']));
$success = false;
} else {
$rules = preg_split("/,/",mres($_POST['rule_id']));
$success = FALSE;
foreach ($rules as $rule_id) {
$db_id = dbInsert(array('alert_rule_id' => $rule_id, 'alert_templates_id' => mres($_POST['template_id'])), 'alert_template_map');
if ($db_id > 0) {
$success = true;
$ids[] = $db_id;
}
else {
echo 'ERROR: Alert rules have not been attached to this template.';
$success = TRUE;
$ids[] = $db_id;
} else {
echo('ERROR: Alert rules have not been attached to this template.');
exit;
}
}
if ($success === true) {
dbDelete('alert_template_map', 'id NOT IN ('.implode(',', $ids).')');
if ($success === TRUE) {
dbDelete('alert_template_map',"id NOT IN (".implode(',',$ids).")");
echo "Alert rules have been attached to this template. $template_map_ids";
exit;
}
}//end if
}
+2 -4
View File
@@ -14,11 +14,9 @@
if ($_POST['state'] == 'true') {
$state = 1;
}
elseif ($_POST['state'] == 'false') {
} elseif ($_POST['state'] == 'false') {
$state = 0;
}
else {
} else {
$state = 0;
}
+32 -24
View File
@@ -13,28 +13,36 @@
*/
// FUA
if (!is_numeric($_POST['config_id'])) {
echo 'error with data';
exit;
}
else {
if ($_POST['state'] == 'true') {
$state = 1;
}
else if ($_POST['state'] == 'false') {
$state = 0;
}
else {
$state = 0;
}
$update = dbUpdate(array('config_disabled' => $state), 'config', '`config_id` = ?', array($_POST['config_id']));
if (!empty($update) || $update == '0') {
echo 'success';
exit;
}
else {
echo 'error';
exit;
}
}//end if
if(!is_numeric($_POST['config_id']))
{
echo('error with data');
exit;
}
else
{
if($_POST['state'] == 'true')
{
$state = 1;
}
elseif($_POST['state'] == 'false')
{
$state = 0;
}
else
{
$state = 0;
}
$update = dbUpdate(array('config_disabled' => $state), 'config', '`config_id` = ?', array($_POST['config_id']));
if(!empty($update) || $update == '0')
{
echo('success');
exit;
}
else
{
echo('error');
exit;
}
}
+20 -14
View File
@@ -13,19 +13,25 @@
*/
// FUA
if (!is_numeric($_POST['config_id']) || empty($_POST['data'])) {
echo 'error with data';
if(!is_numeric($_POST['config_id']) || empty($_POST['data']))
{
echo('error with data');
exit;
}
else
{
$data = mres($_POST['data']);
$update = dbUpdate(array('config_value' => "$data"), 'config', '`config_id` = ?', array($_POST['config_id']));
if(!empty($update) || $update == '0')
{
echo('success');
exit;
}
else
{
echo('error');
exit;
}
}
else {
$data = mres($_POST['data']);
$update = dbUpdate(array('config_value' => "$data"), 'config', '`config_id` = ?', array($_POST['config_id']));
if (!empty($update) || $update == '0') {
echo 'success';
exit;
}
else {
echo 'error';
exit;
}
}
+61 -85
View File
@@ -12,145 +12,121 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
$response = array(
'status' => 'error',
'message' => 'Need to be admin',
);
if(is_admin() === false) {
$response = array('status'=>'error','message'=>'Need to be admin');
echo _json_encode($response);
exit;
}
$action = mres($_POST['action']);
$config_group = mres($_POST['config_group']);
$action = mres($_POST['action']);
$config_group = mres($_POST['config_group']);
$config_sub_group = mres($_POST['config_sub_group']);
$config_name = mres($_POST['config_name']);
$config_value = mres($_POST['config_value']);
$config_extra = mres($_POST['config_extra']);
$config_room_id = mres($_POST['config_room_id']);
$config_from = mres($_POST['config_from']);
$config_userkey = mres($_POST['config_userkey']);
$status = 'error';
$message = 'Error with config';
$config_name = mres($_POST['config_name']);
$config_value = mres($_POST['config_value']);
$config_extra = mres($_POST['config_extra']);
$config_room_id = mres($_POST['config_room_id']);
$config_from = mres($_POST['config_from']);
$config_userkey = mres($_POST['config_userkey']);
$status = 'error';
$message = 'Error with config';
if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipchat' || $action == 'remove-pushover') {
$config_id = mres($_POST['config_id']);
if (empty($config_id)) {
$message = 'No config id passed';
}
else {
} else {
if (dbDelete('config', '`config_id`=?', array($config_id))) {
if ($action == 'remove-slack') {
dbDelete('config', "`config_name` LIKE 'alert.transports.slack.$config_id.%'");
}
else if ($action == 'remove-hipchat') {
} elseif ($action == 'remove-hipchat') {
dbDelete('config', "`config_name` LIKE 'alert.transports.hipchat.$config_id.%'");
}
else if ($action == 'remove-pushover') {
} elseif ($action == 'remove-pushover') {
dbDelete('config', "`config_name` LIKE 'alert.transports.pushover.$config_id.%'");
}
$status = 'ok';
$status = 'ok';
$message = 'Config item removed';
}
else {
} else {
$message = 'General error, could not remove config';
}
}
}
else if ($action == 'add-slack') {
} elseif ($action == 'add-slack') {
if (empty($config_value)) {
$message = 'No Slack url provided';
}
else {
$config_id = dbInsert(array('config_name' => 'alert.transports.slack.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Slack Transport'), 'config');
} else {
$config_id = dbInsert(array('config_name' => 'alert.transports.slack.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_value, 'config_descr'=>'Slack Transport'), 'config');
if ($config_id > 0) {
dbUpdate(array('config_name' => 'alert.transports.slack.'.$config_id.'.url'), 'config', 'config_id=?', array($config_id));
$status = 'ok';
$status = 'ok';
$message = 'Config item created';
$extras = explode('\n', $config_extra);
$extras = explode('\n',$config_extra);
foreach ($extras as $option) {
list($k,$v) = explode('=', $option, 2);
list($k,$v) = explode("=", $option,2);
if (!empty($k) || !empty($v)) {
dbInsert(array('config_name' => 'alert.transports.slack.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Slack Transport'), 'config');
dbInsert(array('config_name' => 'alert.transports.slack.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$v, 'config_descr'=>'Slack Transport'), 'config');
}
}
}
else {
} else {
$message = 'Could not create config item';
}
}
}
else if ($action == 'add-hipchat') {
} elseif ($action == 'add-hipchat') {
if (empty($config_value) || empty($config_room_id) || empty($config_from)) {
$message = 'No hipchat url, room id or from provided';
}
else {
$config_id = dbInsert(array('config_name' => 'alert.transports.hipchat.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Hipchat Transport'), 'config');
} else {
$config_id = dbInsert(array('config_name' => 'alert.transports.hipchat.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_value, 'config_descr'=>'Hipchat Transport'), 'config');
if ($config_id > 0) {
dbUpdate(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.url'), 'config', 'config_id=?', array($config_id));
$additional_id['room_id'] = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.room_id', 'config_value' => $config_room_id, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_room_id, 'config_descr' => 'Hipchat URL'), 'config');
$additional_id['from'] = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.from', 'config_value' => $config_from, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_from, 'config_descr' => 'Hipchat From'), 'config');
$status = 'ok';
$message = 'Config item created';
$extras = explode('\n', $config_extra);
$additional_id['room_id'] = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.room_id', 'config_value' => $config_room_id, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_room_id, 'config_descr'=>'Hipchat URL'), 'config');
$additional_id['from'] = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.from', 'config_value' => $config_from, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_from, 'config_descr'=>'Hipchat From'), 'config');
$status = 'ok';
$message = 'Config item created';
$extras = explode('\n',$config_extra);
foreach ($extras as $option) {
list($k,$v) = explode('=', $option, 2);
list($k,$v) = explode("=", $option,2);
if (!empty($k) || !empty($v)) {
dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Hipchat '.$v), 'config');
dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$v, 'config_descr'=>'Hipchat '.$v), 'config');
}
}
}
else {
} else {
$message = 'Could not create config item';
}
}//end if
}
else if ($action == 'add-pushover') {
}
} elseif ($action == 'add-pushover') {
if (empty($config_value) || empty($config_userkey)) {
$message = 'No pushover appkey or userkey provided';
}
else {
$config_id = dbInsert(array('config_name' => 'alert.transports.pushover.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Pushover Transport'), 'config');
} else {
$config_id = dbInsert(array('config_name' => 'alert.transports.pushover.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_value, 'config_descr'=>'Pushover Transport'), 'config');
if ($config_id > 0) {
dbUpdate(array('config_name' => 'alert.transports.pushover.'.$config_id.'.appkey'), 'config', 'config_id=?', array($config_id));
$additional_id['userkey'] = dbInsert(array('config_name' => 'alert.transports.pushover.'.$config_id.'.userkey', 'config_value' => $config_userkey, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_userkey, 'config_descr' => 'Pushver Userkey'), 'config');
$status = 'ok';
$message = 'Config item created';
$extras = explode('\n', $config_extra);
$additional_id['userkey'] = dbInsert(array('config_name' => 'alert.transports.pushover.'.$config_id.'.userkey', 'config_value' => $config_userkey, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_userkey, 'config_descr'=>'Pushver Userkey'), 'config');
$status = 'ok';
$message = 'Config item created';
$extras = explode('\n',$config_extra);
foreach ($extras as $option) {
list($k,$v) = explode('=', $option, 2);
list($k,$v) = explode("=", $option,2);
if (!empty($k) || !empty($v)) {
dbInsert(array('config_name' => 'alert.transports.pushover.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Pushover '.$v), 'config');
dbInsert(array('config_name' => 'alert.transports.pushover.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$v, 'config_descr'=>'Pushover '.$v), 'config');
}
}
} else {
$message = 'Could not create config item';
}
else {
}
} else {
if (empty($config_group) || empty($config_sub_group) || empty($config_name) || empty($config_value)) {
$message = 'Missing config name or value';
} else {
$config_id = dbInsert(array('config_name' => $config_name, 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_value, 'config_descr'=>'API Transport'), 'config');
if ($config_id > 0) {
dbUpdate(array('config_name'=>$config_name.$config_id),'config','config_id=?',array($config_id));
$status = 'ok';
$message = 'Config item created';
} else {
$message = 'Could not create config item';
}
}
}
else {
if (empty($config_group) || empty($config_sub_group) || empty($config_name) || empty($config_value)) {
$message = 'Missing config name or value';
}
else {
$config_id = dbInsert(array('config_name' => $config_name, 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'API Transport'), 'config');
if ($config_id > 0) {
dbUpdate(array('config_name' => $config_name.$config_id), 'config', 'config_id=?', array($config_id));
$status = 'ok';
$message = 'Config item created';
}
else {
$message = 'Could not create config item';
}
}
}//end if
$response = array(
'status' => $status,
'message' => $message,
'config_id' => $config_id,
'additional_id' => $additional_id,
);
$response = array('status'=>$status,'message'=>$message, 'config_id'=>$config_id, 'additional_id'=>$additional_id);
echo _json_encode($response);
+36 -53
View File
@@ -12,85 +12,68 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
$rule = implode(' ', $_POST['rules']);
$rule = rtrim($rule, '&&');
$rule = rtrim($rule, '||');
$rule = implode(" ", $_POST['rules']);
$rule = rtrim($rule,'&&');
$rule = rtrim($rule,'||');
$alert_id = $_POST['alert_id'];
$count = mres($_POST['count']);
$delay = mres($_POST['delay']);
$count = mres($_POST['count']);
$delay = mres($_POST['delay']);
$interval = mres($_POST['interval']);
$mute = mres($_POST['mute']);
$invert = mres($_POST['invert']);
$name = mres($_POST['name']);
$mute = mres($_POST['mute']);
$invert = mres($_POST['invert']);
$name = mres($_POST['name']);
if (empty($rule)) {
$update_message = 'ERROR: No rule was generated - did you forget to click and / or?';
}
else if (validate_device_id($_POST['device_id']) || $_POST['device_id'] == '-1' || $_POST['device_id'][0] == ':') {
if(empty($rule)) {
$update_message = "ERROR: No rule was generated - did you forget to click and / or?";
} elseif(validate_device_id($_POST['device_id']) || $_POST['device_id'] == '-1' || $_POST['device_id'][0] == ':') {
$device_id = $_POST['device_id'];
if (!is_numeric($count)) {
$count = '-1';
if(!is_numeric($count)) {
$count='-1';
}
$delay_sec = convert_delay($delay);
$delay_sec = convert_delay($delay);
$interval_sec = convert_delay($interval);
if ($mute == 'on') {
if($mute == 'on') {
$mute = true;
}
else {
} else {
$mute = false;
}
if ($invert == 'on') {
if($invert == 'on') {
$invert = true;
}
else {
} else {
$invert = false;
}
$extra = array(
'mute' => $mute,
'count' => $count,
'delay' => $delay_sec,
'invert' => $invert,
'interval' => $interval_sec,
);
$extra = array('mute'=>$mute,'count'=>$count,'delay'=>$delay_sec,'invert'=>$invert,'interval'=>$interval_sec);
$extra_json = json_encode($extra);
if (is_numeric($alert_id) && $alert_id > 0) {
if (dbUpdate(array('rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'name' => $name), 'alert_rules', 'id=?', array($alert_id)) >= 0) {
if(is_numeric($alert_id) && $alert_id > 0) {
if(dbUpdate(array('rule' => $rule,'severity'=>mres($_POST['severity']),'extra'=>$extra_json,'name'=>$name), 'alert_rules', 'id=?',array($alert_id)) >= 0) {
$update_message = "Edited Rule: <i>$name: $rule</i>";
} else {
$update_message = "ERROR: Failed to edit Rule: <i>".$rule."</i>";
}
else {
$update_message = 'ERROR: Failed to edit Rule: <i>'.$rule.'</i>';
}
}
else {
if (is_array($_POST['maps'])) {
} else {
if( is_array($_POST['maps']) ) {
$device_id = ':'.$device_id;
}
if (dbInsert(array('device_id' => $device_id, 'rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'name' => $name), 'alert_rules')) {
if( dbInsert(array('device_id'=>$device_id,'rule'=>$rule,'severity'=>mres($_POST['severity']),'extra'=>$extra_json,'name'=>$name),'alert_rules') ) {
$update_message = "Added Rule: <i>$name: $rule</i>";
if (is_array($_POST['maps'])) {
foreach ($_POST['maps'] as $target) {
$_POST['rule'] = $name;
if( is_array($_POST['maps']) ) {
foreach( $_POST['maps'] as $target ) {
$_POST['rule'] = $name;
$_POST['target'] = $target;
$_POST['map_id'] = '';
include 'forms/create-map-item.inc.php';
include('forms/create-map-item.inc.php');
unset($ret,$target,$raw,$rule,$msg,$map_id);
}
}
} else {
$update_message = "ERROR: Failed to add Rule: <i>".$rule."</i>";
}
else {
$update_message = 'ERROR: Failed to add Rule: <i>'.$rule.'</i>';
}
}//end if
}
} else {
$update_message = "ERROR: invalid device ID or not a global alert";
}
else {
$update_message = 'ERROR: invalid device ID or not a global alert';
}//end if
echo $update_message;
+24 -31
View File
@@ -12,46 +12,39 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
$pattern = $_POST['patterns'];
$pattern = $_POST['patterns'];
$group_id = $_POST['group_id'];
$name = mres($_POST['name']);
$desc = mres($_POST['desc']);
$name = mres($_POST['name']);
$desc = mres($_POST['desc']);
if (is_array($pattern)) {
$pattern = implode(' ', $pattern);
}
else if (!empty($_POST['pattern']) && !empty($_POST['condition']) && !empty($_POST['value'])) {
$pattern = '%'.$_POST['pattern'].' '.$_POST['condition'].' ';
if (is_numeric($_POST['value'])) {
$pattern .= $_POST['value'];
}
else {
$pattern .= '"'.$_POST['value'].'"';
}
if( is_array($pattern) ) {
$pattern = implode(" ", $pattern);
} elseif( !empty($_POST['pattern']) && !empty($_POST['condition']) && !empty($_POST['value']) ) {
$pattern = '%'.$_POST['pattern'].' '.$_POST['condition'].' ';
if( is_numeric($_POST['value']) ) {
$pattern .= $_POST['value'];
} else {
$pattern .= '"'.$_POST['value'].'"';
}
}
if (empty($pattern)) {
$update_message = 'ERROR: No group was generated';
}
else if (is_numeric($group_id) && $group_id > 0) {
if (dbUpdate(array('pattern' => $pattern, 'name' => $name, 'desc' => $desc), 'device_groups', 'id=?', array($group_id)) >= 0) {
$update_message = "Edited Group: <i>$name: $pattern</i>";
if(empty($pattern)) {
$update_message = "ERROR: No group was generated";
} elseif(is_numeric($group_id) && $group_id > 0) {
if(dbUpdate(array('pattern' => $pattern,'name'=>$name,'desc'=>$desc), 'device_groups', 'id=?',array($group_id)) >= 0) {
$update_message = "Edited Group: <i>$name: $pattern</i>";
} else {
$update_message = "ERROR: Failed to edit Group: <i>".$pattern."</i>";
}
else {
$update_message = 'ERROR: Failed to edit Group: <i>'.$pattern.'</i>';
}
}
else {
if (dbInsert(array('pattern' => $pattern, 'name' => $name, 'desc' => $desc), 'device_groups')) {
} else {
if( dbInsert(array('pattern'=>$pattern,'name'=>$name,'desc'=>$desc),'device_groups') ) {
$update_message = "Added Group: <i>$name: $pattern</i>";
}
else {
$update_message = 'ERROR: Failed to add Group: <i>'.$pattern.'</i>';
} else {
$update_message = "ERROR: Failed to add Group: <i>".$pattern."</i>";
}
}
echo $update_message;
+42 -52
View File
@@ -12,7 +12,7 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
@@ -21,56 +21,46 @@ $target = mres($_POST['target']);
$map_id = mres($_POST['map_id']);
$ret = array();
if (empty($rule) || empty($target)) {
$ret[] = 'ERROR: No map was generated';
if( empty($rule) || empty($target) ) {
$ret[] = "ERROR: No map was generated";
} else {
$raw = $rule;
$rule = dbFetchCell('SELECT id FROM alert_rules WHERE name = ?',array($rule));
if( !is_numeric($rule) ) {
array_unshift($ret, "ERROR: Could not find rule for '".$raw."'");
} else {
$raw = $target;
if( $target[0].$target[1] == "g:" ) {
$target = "g".dbFetchCell('SELECT id FROM device_groups WHERE name = ?',array(substr($target,2)));
} else {
$target = dbFetchCell('SELECT device_id FROM devices WHERE hostname = ?',array($target));
}
if( !is_numeric(str_replace('g','',$target)) ) {
array_unshift($ret, "ERROR: Could not find entry for '".$raw."'");
} else {
if(is_numeric($map_id) && $map_id > 0) {
if(dbUpdate(array('rule' => $rule,'target'=>$target), 'alert_map', 'id=?',array($map_id)) >= 0) {
$ret[] = "Edited Map: <i>".$map_id.": ".$rule." = ".$target."</i>";
} else {
array_unshift($ret,"ERROR: Failed to edit Map: <i>".$map_id.": ".$rule." = ".$target."</i>");
}
} else {
if( dbInsert(array('rule'=>$rule,'target'=>$target),'alert_map') ) {
$ret[] = "Added Map: <i>".$rule." = ".$target."</i>";
} else {
array_unshift($ret,"ERROR: Failed to add Map: <i>".$rule." = ".$target."</i>");
}
}
if( ($tmp=dbFetchCell('SELECT device_id FROM alert_rules WHERE id = ?',array($rule))) && $tmp[0] != ":" ) {
if(dbUpdate(array('device_id' => ':'.$tmp), 'alert_rules', 'id=?',array($rule)) >= 0) {
$ret[] = "Edited Rule: <i>".$rule." device_id = ':".$tmp."'</i>";
} else {
array_unshift($ret,"ERROR: Failed to edit Rule: <i>".$rule.": device_id = ':".$tmp."'</i>");
}
}
}
}
}
else {
$raw = $rule;
$rule = dbFetchCell('SELECT id FROM alert_rules WHERE name = ?', array($rule));
if (!is_numeric($rule)) {
array_unshift($ret, "ERROR: Could not find rule for '".$raw."'");
}
else {
$raw = $target;
if ($target[0].$target[1] == 'g:') {
$target = 'g'.dbFetchCell('SELECT id FROM device_groups WHERE name = ?', array(substr($target, 2)));
}
else {
$target = dbFetchCell('SELECT device_id FROM devices WHERE hostname = ?', array($target));
}
if (!is_numeric(str_replace('g', '', $target))) {
array_unshift($ret, "ERROR: Could not find entry for '".$raw."'");
}
else {
if (is_numeric($map_id) && $map_id > 0) {
if (dbUpdate(array('rule' => $rule, 'target' => $target), 'alert_map', 'id=?', array($map_id)) >= 0) {
$ret[] = 'Edited Map: <i>'.$map_id.': '.$rule.' = '.$target.'</i>';
}
else {
array_unshift($ret, 'ERROR: Failed to edit Map: <i>'.$map_id.': '.$rule.' = '.$target.'</i>');
}
}
else {
if (dbInsert(array('rule' => $rule, 'target' => $target), 'alert_map')) {
$ret[] = 'Added Map: <i>'.$rule.' = '.$target.'</i>';
}
else {
array_unshift($ret, 'ERROR: Failed to add Map: <i>'.$rule.' = '.$target.'</i>');
}
}
if (($tmp = dbFetchCell('SELECT device_id FROM alert_rules WHERE id = ?', array($rule))) && $tmp[0] != ':') {
if (dbUpdate(array('device_id' => ':'.$tmp), 'alert_rules', 'id=?', array($rule)) >= 0) {
$ret[] = 'Edited Rule: <i>'.$rule." device_id = ':".$tmp."'</i>";
}
else {
array_unshift($ret, 'ERROR: Failed to edit Rule: <i>'.$rule.": device_id = ':".$tmp."'</i>");
}
}
}//end if
}//end if
}//end if
foreach ($ret as $msg) {
echo $msg.'<br/>';
foreach( $ret as $msg ) {
echo $msg."<br/>";
}
+21 -27
View File
@@ -12,36 +12,30 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
$ret = array();
$brk = false;
if (!is_numeric($_POST['map_id'])) {
array_unshift($ret, 'ERROR: No map selected');
if( !is_numeric($_POST['map_id']) ) {
array_unshift($ret,'ERROR: No map selected');
} else {
if( dbFetchCell('SELECT COUNT(B.id) FROM alert_map,alert_map AS B WHERE alert_map.rule=B.rule && alert_map.id = ?',array($_POST['map_id'])) <= 1 ) {
$rule = dbFetchRow('SELECT alert_rules.id,alert_rules.device_id FROM alert_map,alert_rules WHERE alert_map.rule=alert_rules.id && alert_map.id = ?',array($_POST['map_id']));
$rule['device_id'] = str_replace(":",'',$rule['device_id']);
if( dbUpdate(array('device_id'=>$rule['device_id']),'alert_rules','id = ?',array($rule['id'])) >= 0 ) {
$ret[] = "Restored Rule: <i>".$rule['id'].": device_id = '".$rule['device_id']."'</i>";
} else {
array_unshift($ret, 'ERROR: Rule '.$rule['id'].' has not been restored.');
$brk = true;
}
}
if( $brk === false && dbDelete('alert_map', "`id` = ?", array($_POST['map_id'])) ) {
$ret[] = 'Map has been deleted.';
} else {
array_unshift($ret, 'ERROR: Map has not been deleted.');
}
}
else {
if (dbFetchCell('SELECT COUNT(B.id) FROM alert_map,alert_map AS B WHERE alert_map.rule=B.rule && alert_map.id = ?', array($_POST['map_id'])) <= 1) {
$rule = dbFetchRow('SELECT alert_rules.id,alert_rules.device_id FROM alert_map,alert_rules WHERE alert_map.rule=alert_rules.id && alert_map.id = ?', array($_POST['map_id']));
$rule['device_id'] = str_replace(':', '', $rule['device_id']);
if (dbUpdate(array('device_id' => $rule['device_id']), 'alert_rules', 'id = ?', array($rule['id'])) >= 0) {
$ret[] = 'Restored Rule: <i>'.$rule['id'].": device_id = '".$rule['device_id']."'</i>";
}
else {
array_unshift($ret, 'ERROR: Rule '.$rule['id'].' has not been restored.');
$brk = true;
}
}
if ($brk === false && dbDelete('alert_map', '`id` = ?', array($_POST['map_id']))) {
$ret[] = 'Map has been deleted.';
}
else {
array_unshift($ret, 'ERROR: Map has not been deleted.');
}
}
foreach ($ret as $msg) {
echo $msg.'<br/>';
foreach( $ret as $msg ) {
echo $msg."<br/>";
}
+16 -19
View File
@@ -12,28 +12,25 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
if (!is_numeric($_POST['alert_id'])) {
echo 'ERROR: No alert selected';
if(!is_numeric($_POST['alert_id'])) {
echo('ERROR: No alert selected');
exit;
} else {
if(dbDelete('alert_rules', "`id` = ?", array($_POST['alert_id']))) {
if(dbDelete('alert_map', "rule = ?", array($_POST['alert_id'])) || dbFetchCell('COUNT(id) FROM alert_map WHERE rule = ?',array($_POST['alert_id'])) == 0) {
echo('Maps has been deleted.');
} else {
echo('WARNING: Maps could not be deleted.');
}
echo('Alert rule has been deleted.');
exit;
} else {
echo('ERROR: Alert rule has not been deleted.');
exit;
}
}
else {
if (dbDelete('alert_rules', '`id` = ?', array($_POST['alert_id']))) {
if (dbDelete('alert_map', 'rule = ?', array($_POST['alert_id'])) || dbFetchCell('COUNT(id) FROM alert_map WHERE rule = ?', array($_POST['alert_id'])) == 0) {
echo 'Maps has been deleted.';
}
else {
echo 'WARNING: Maps could not be deleted.';
}
echo 'Alert rule has been deleted.';
exit;
}
else {
echo 'ERROR: Alert rule has not been deleted.';
exit;
}
}
+20 -21
View File
@@ -1,32 +1,31 @@
<?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.
* 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.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
if (!is_numeric($_POST['template_id'])) {
echo 'ERROR: No template selected';
if(!is_numeric($_POST['template_id'])) {
echo('ERROR: No template selected');
exit;
}
else {
if (dbDelete('alert_templates', '`id` = ?', array($_POST['template_id']))) {
echo 'Alert template has been deleted.';
exit;
}
else {
echo 'ERROR: Alert template has not been deleted.';
exit;
} else {
if(dbDelete('alert_templates', "`id` = ?", array($_POST['template_id']))) {
echo('Alert template has been deleted.');
exit;
} else {
echo('ERROR: Alert template has not been deleted.');
exit;
}
}
+16 -18
View File
@@ -12,28 +12,26 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
if (!is_numeric($_POST['group_id'])) {
echo 'ERROR: No group selected';
if(!is_numeric($_POST['group_id'])) {
echo('ERROR: No group selected');
exit;
}
else {
if (dbDelete('device_groups', '`id` = ?', array($_POST['group_id']))) {
if (dbFetchCell('SELECT COUNT(id) FROM alert_map WHERE target = ?', array('g'.$_POST['group_id'])) >= 1) {
foreach (dbFetchRows('SELECT id FROM alert_map WHERE target = ?', array('g'.$_POST['group_id'])) as $map) {
$_POST['map_id'] = $map['id'];
include 'forms/delete-alert-map.inc.php';
}
} else {
if(dbDelete('device_groups', "`id` = ?", array($_POST['group_id']))) {
if( dbFetchCell('SELECT COUNT(id) FROM alert_map WHERE target = ?',array('g'.$_POST['group_id'])) >= 1 ) {
foreach( dbFetchRows('SELECT id FROM alert_map WHERE target = ?',array('g'.$_POST['group_id'])) as $map ) {
$_POST['map_id'] = $map['id'];
include('forms/delete-alert-map.inc.php');
}
echo 'Group has been deleted.';
exit;
}
else {
echo 'ERROR: Group has not been deleted.';
exit;
}
echo('Group has been deleted.');
exit;
} else {
echo('ERROR: Group has not been deleted.');
exit;
}
}
+29 -20
View File
@@ -1,28 +1,37 @@
<?php
// FUA
$device['device_id'] = $_POST['device_id'];
$module = 'discover_'.$_POST['discovery_module'];
$module = 'discover_'.$_POST['discovery_module'];
if (!isset($module) && validate_device_id($device['device_id']) === false) {
echo 'error with data';
exit;
if(!isset($module) && validate_device_id($device['device_id']) === false)
{
echo('error with data');
exit;
}
else {
if ($_POST['state'] == 'true') {
$state = 1;
}
else if ($_POST['state'] == 'false') {
$state = 0;
}
else {
$state = 0;
}
else
{
if($_POST['state'] == 'true')
{
$state = 1;
}
elseif($_POST['state'] == 'false')
{
$state = 0;
}
else
{
$state = 0;
}
if (isset($attribs['discover_'.$module]) && $attribs['discover_'.$module] != $config['discover_modules'][$module]) {
del_dev_attrib($device, $module);
}
else {
set_dev_attrib($device, $module, $state);
}
if(isset($attribs['discover_'.$module]) && $attribs['discover_'.$module] != $config['discover_modules'][$module])
{
del_dev_attrib($device, $module);
}
else
{
set_dev_attrib($device, $module, $state);
}
}
+19 -13
View File
@@ -13,18 +13,24 @@
*/
// FUA
if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id']) || (empty($_POST['data']) || !isset($_POST['data']))) {
echo 'error with data';
if(!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id']) || (empty($_POST['data']) || !isset($_POST['data'])))
{
echo('error with data');
exit;
}
else
{
$update = dbUpdate(array($_POST['value_type'] => $_POST['data'], 'sensor_custom' => 'Yes'), 'sensors', '`sensor_id` = ? AND `device_id` = ?', array($_POST['sensor_id'],$_POST['device_id']));
if(!empty($update) || $update == '0')
{
echo('success');
exit;
}
else
{
echo('error');
exit;
}
}
else {
$update = dbUpdate(array($_POST['value_type'] => $_POST['data'], 'sensor_custom' => 'Yes'), 'sensors', '`sensor_id` = ? AND `device_id` = ?', array($_POST['sensor_id'], $_POST['device_id']));
if (!empty($update) || $update == '0') {
echo 'success';
exit;
}
else {
echo 'error';
exit;
}
}
+8 -13
View File
@@ -12,24 +12,19 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
$map_id = $_POST['map_id'];
if (is_numeric($map_id) && $map_id > 0) {
$map = dbFetchRow('SELECT alert_rules.name,alert_map.target FROM alert_map,alert_rules WHERE alert_map.rule=alert_rules.id && alert_map.id = ?', array($map_id));
if ($map['target'][0] == 'g') {
$map['target'] = 'g:'.dbFetchCell('SELECT name FROM device_groups WHERE id = ?', array(substr($map['target'], 1)));
if(is_numeric($map_id) && $map_id > 0) {
$map = dbFetchRow("SELECT alert_rules.name,alert_map.target FROM alert_map,alert_rules WHERE alert_map.rule=alert_rules.id && alert_map.id = ?",array($map_id));
if( $map['target'][0] == "g" ) {
$map['target'] = 'g:'.dbFetchCell("SELECT name FROM device_groups WHERE id = ?",array(substr($map['target'],1)));
} else {
$map['target'] = dbFetchCell("SELECT hostname FROM devices WHERE device_id = ?",array($map['target']));
}
else {
$map['target'] = dbFetchCell('SELECT hostname FROM devices WHERE device_id = ?', array($map['target']));
}
$output = array(
'rule' => $map['name'],
'target' => $map['target'],
);
$output = array('rule'=>$map['name'],'target'=>$map['target']);
echo _json_encode($output);
}
+6 -11
View File
@@ -12,22 +12,17 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
$alert_id = $_POST['alert_id'];
if (is_numeric($alert_id) && $alert_id > 0) {
$rule = dbFetchRow('SELECT * FROM `alert_rules` WHERE `id` = ? LIMIT 1', array($alert_id));
$rule_split = preg_split('/([a-zA-Z0-9_\-\.\=\%\<\>\ \"\'\!\~\(\)\*\/\@]+[&&\|\|]+)/', $rule['rule'], -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));
$count = (count($rule_split) - 1);
if(is_numeric($alert_id) && $alert_id > 0) {
$rule = dbFetchRow("SELECT * FROM `alert_rules` WHERE `id` = ? LIMIT 1",array($alert_id));
$rule_split = preg_split('/([a-zA-Z0-9_\-\.\=\%\<\>\ \"\'\!\~\(\)\*\/\@]+[&&\|\|]+)/',$rule['rule'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$count = count($rule_split) - 1;
$rule_split[$count] = $rule_split[$count].' &&';
$output = array(
'severity' => $rule['severity'],
'extra' => $rule['extra'],
'name' => $rule['name'],
'rules' => $rule_split,
);
$output = array('severity'=>$rule['severity'],'extra'=>$rule['extra'],'name'=>$rule['name'],'rules'=>$rule_split);
echo _json_encode($output);
}
+4 -7
View File
@@ -12,17 +12,14 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
$template_id = ($_POST['template_id']);
if (is_numeric($template_id) && $template_id > 0) {
$template = dbFetchRow('SELECT * FROM `alert_templates` WHERE `id` = ? LIMIT 1', array($template_id));
$output = array(
'template' => $template['template'],
'name' => $template['name'],
);
if(is_numeric($template_id) && $template_id > 0) {
$template = dbFetchRow("SELECT * FROM `alert_templates` WHERE `id` = ? LIMIT 1",array($template_id));
$output = array('template'=>$template['template'],'name'=>$template['name']);
echo _json_encode($output);
}
+8 -14
View File
@@ -12,27 +12,21 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
$group_id = $_POST['group_id'];
if (is_numeric($group_id) && $group_id > 0) {
$group = dbFetchRow('SELECT * FROM `device_groups` WHERE `id` = ? LIMIT 1', array($group_id));
$group_split = preg_split('/([a-zA-Z0-9_\-\.\=\%\<\>\ \"\'\!\~\(\)\*\/\@\[\]]+[&&\|\|]+)/', $group['pattern'], -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));
$count = (count($group_split) - 1);
if (preg_match('/\&\&$/', $group_split[$count]) == 1 || preg_match('/\|\|$/', $group_split[$count]) == 1) {
if(is_numeric($group_id) && $group_id > 0) {
$group = dbFetchRow("SELECT * FROM `device_groups` WHERE `id` = ? LIMIT 1",array($group_id));
$group_split = preg_split('/([a-zA-Z0-9_\-\.\=\%\<\>\ \"\'\!\~\(\)\*\/\@\[\]]+[&&\|\|]+)/',$group['pattern'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$count = count($group_split) - 1;
if (preg_match("/\&\&$/",$group_split[$count]) == 1 || preg_match("/\|\|$/", $group_split[$count]) == 1) {
$group_split[$count] = $group_split[$count];
}
else {
} else {
$group_split[$count] = $group_split[$count].' &&';
}
$output = array(
'name' => $group['name'],
'desc' => $group['desc'],
'pattern' => $group_split,
);
$output = array('name'=>$group['name'],'desc'=>$group['desc'],'pattern'=>$group_split);
echo _json_encode($output);
}
+4 -7
View File
@@ -12,17 +12,14 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
$group_id = ($_POST['group_id']);
if (is_numeric($group_id) && $group_id > 0) {
$group = dbFetchRow('SELECT * FROM `poller_groups` WHERE `id` = ? LIMIT 1', array($group_id));
$output = array(
'group_name' => $group['group_name'],
'descr' => $group['descr'],
);
if(is_numeric($group_id) && $group_id > 0) {
$group = dbFetchRow("SELECT * FROM `poller_groups` WHERE `id` = ? LIMIT 1",array($group_id));
$output = array('group_name'=>$group['group_name'],'descr'=>$group['descr']);
echo _json_encode($output);
}
+4 -5
View File
@@ -12,17 +12,16 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
$template_id = ($_POST['template_id']);
if (is_numeric($template_id) && $template_id > 0) {
foreach (dbFetchRows('SELECT `alert_rule_id` FROM `alert_template_map` WHERE `alert_templates_id` = ?', array($template_id)) as $rule) {
if(is_numeric($template_id) && $template_id > 0) {
foreach (dbFetchRows("SELECT `alert_rule_id` FROM `alert_template_map` WHERE `alert_templates_id` = ?",array($template_id)) as $rule) {
$rules[] = $rule['alert_rule_id'];
}
$output = array('rule_id' => $rules);
$output = array('rule_id'=>$rules);
echo _json_encode($output);
}
+13 -14
View File
@@ -13,19 +13,18 @@
*/
if (!is_numeric($_POST['group_id'])) {
echo 'error with data';
exit;
}
else {
if ($_POST['confirm'] == 'yes') {
$delete = dbDelete('poller_groups', '`id` = ?', array($_POST['group_id']));
if ($delete > '0') {
echo 'Poller group has been removed';
exit;
}
else {
echo 'An error occurred removing the Poller group';
exit;
}
echo('error with data');
exit;
} else {
if($_POST['confirm'] == 'yes')
{
$delete = dbDelete('poller_groups', '`id` = ?', array($_POST['group_id']));
if ($delete > '0') {
echo('Poller group has been removed');
exit;
} else {
echo('An error occurred removing the Poller group');
exit;
}
}
}
+19 -23
View File
@@ -12,40 +12,36 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
$ok = '';
$error = '';
$group_id = $_POST['group_id'];
$ok = '';
$error = '';
$group_id = $_POST['group_id'];
$group_name = mres($_POST['group_name']);
$descr = mres($_POST['descr']);
if (!empty($group_name)) {
if (is_numeric($group_id)) {
if (dbUpdate(array('group_name' => $group_name, 'descr' => $descr), 'poller_groups', 'id = ?', array($group_id))) {
$ok = 'Updated poller group';
$descr = mres($_POST['descr']);
if(!empty($group_name)) {
if( is_numeric($group_id)) {
if (dbUpdate(array('group_name' => $group_name, 'descr' => $descr), "poller_groups", "id = ?", array($group_id))) {
$ok = "Updated poller group";
} else {
$error = "Failed to update the poller group";
}
else {
$error = 'Failed to update the poller group';
}
}
else {
} else {
if (dbInsert(array('group_name' => $group_name, 'descr' => $descr), 'poller_groups') >= 0) {
$ok = 'Added new poller group';
}
else {
$error = 'Failed to create new poller group';
$ok = "Added new poller group";
} else {
$error = "Failed to create new poller group";
}
}
}
else {
} else {
$error = "You haven't given your poller group a name, it feels sad :( - $group_name";
}
if (!empty($ok)) {
if(!empty( $ok )) {
die("$ok");
}
else {
} else {
die("ERROR: $error");
}
?>
+29 -20
View File
@@ -1,28 +1,37 @@
<?php
// FUA
$device['device_id'] = $_POST['device_id'];
$module = 'poll_'.$_POST['poller_module'];
$module = 'poll_'.$_POST['poller_module'];
if (!isset($module) && validate_device_id($device['device_id']) === false) {
echo 'error with data';
exit;
if(!isset($module) && validate_device_id($device['device_id']) === false)
{
echo('error with data');
exit;
}
else {
if ($_POST['state'] == 'true') {
$state = 1;
}
else if ($_POST['state'] == 'false') {
$state = 0;
}
else {
$state = 0;
}
else
{
if($_POST['state'] == 'true')
{
$state = 1;
}
elseif($_POST['state'] == 'false')
{
$state = 0;
}
else
{
$state = 0;
}
if (isset($attribs['poll_'.$module]) && $attribs['poll_'.$module] != $config['poller_modules'][$module]) {
del_dev_attrib($device, $module);
}
else {
set_dev_attrib($device, $module, $state);
}
if(isset($attribs['poll_'.$module]) && $attribs['poll_'.$module] != $config['poller_modules'][$module])
{
del_dev_attrib($device, $module);
}
else
{
set_dev_attrib($device, $module, $state);
}
}
+24 -29
View File
@@ -1,37 +1,32 @@
<?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.
* 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.
*/
// FIXME: Make this part of the API instead of a standalone function
if (!is_numeric($_POST['device_id'])) {
$status = 'error';
$message = 'Invalid device id';
}
else {
$update = dbUpdate(array('last_discovered' => array('NULL')), 'devices', '`device_id` = ?', array($_POST['device_id']));
if (!empty($update) || $update == '0') {
$status = 'ok';
$message = 'Device will be rediscovered';
}
else {
$status = 'error';
$message = 'Error rediscovering device';
}
}
$output = array(
'status' => $status,
'message' => $message,
);
header('Content-type: application/json');
if(!is_numeric($_POST['device_id'])) {
$status = "error";
$message = "Invalid device id";
} else {
$update = dbUpdate(array('last_discovered' => array('NULL')), 'devices', '`device_id` = ?', array($_POST['device_id']));
if(!empty($update) || $update == '0') {
$status = "ok";
$message = "Device will be rediscovered";
} else {
$status = "error";
$message = "Error rediscovering device";
}
}
$output = array("status" => $status, "message" => $message);
header("Content-type: application/json");
echo _json_encode($output);
+39 -62
View File
@@ -12,13 +12,14 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
$sub_type = $_POST['sub_type'];
if ($sub_type == 'new-maintenance') {
// Defaults
$status = 'error';
$update = 0;
@@ -27,7 +28,6 @@ if ($sub_type == 'new-maintenance') {
if ($schedule_id > 0) {
$update = 1;
}
$title = mres($_POST['title']);
$notes = mres($_POST['notes']);
$start = mres($_POST['start']);
@@ -35,98 +35,75 @@ if ($sub_type == 'new-maintenance') {
$maps = mres($_POST['maps']);
if (empty($title)) {
$message = 'Missing title<br />';
$message = "Missing title<br />";
}
if (empty($start)) {
$message .= 'Missing start date<br />';
$message .= "Missing start date<br />";
}
if (empty($end)) {
$message .= 'Missing end date<br />';
$message .= "Missing end date<br />";
}
if (!is_array($_POST['maps'])) {
$message .= 'Not mapped to any groups or devices<br />';
if( !is_array($_POST['maps']) ) {
$message .= "Not mapped to any groups or devices<br />";
}
if (empty($message)) {
if (empty($schedule_id)) {
$schedule_id = dbInsert(array('start' => $start, 'end' => $end, 'title' => $title, 'notes' => $notes), 'alert_schedule');
$schedule_id = dbInsert(array('start'=>$start,'end'=>$end,'title'=>$title,'notes'=>$notes),'alert_schedule');
} else {
dbUpdate(array('start'=>$start,'end'=>$end,'title'=>$title,'notes'=>$notes),'alert_schedule','`schedule_id`=?',array($schedule_id));
}
else {
dbUpdate(array('start' => $start, 'end' => $end, 'title' => $title, 'notes' => $notes), 'alert_schedule', '`schedule_id`=?', array($schedule_id));
}
if ($schedule_id > 0) {
$items = array();
$fail = 0;
$fail = 0;
if ($update == 1) {
dbDelete('alert_schedule_items', '`schedule_id`=?', array($schedule_id));
}
foreach ($_POST['maps'] as $target) {
foreach( $_POST['maps'] as $target ) {
$target = target_to_id($target);
$item = dbInsert(array('schedule_id' => $schedule_id, 'target' => $target), 'alert_schedule_items');
$item = dbInsert(array('schedule_id'=>$schedule_id,'target'=>$target),'alert_schedule_items');
if ($item > 0) {
array_push($items, $item);
}
else {
array_push($items,$item);
} else {
$fail = 1;
}
}
if ($fail == 1 && $update == 0) {
foreach ($items as $item) {
dbDelete('alert_schedule_items', '`item_id`=?', array($item));
}
dbDelete('alert_schedule', '`schedule_id`=?', array($schedule_id));
$message = 'Issue scheduling maintenance';
}
else {
$status = 'ok';
} else {
$status = 'ok';
$message = 'Scheduling maintenance ok';
}
} else {
$message = "Issue scheduling maintenance";
}
else {
$message = 'Issue scheduling maintenance';
}//end if
}//end if
$response = array(
'status' => $status,
'message' => $message,
);
}
else if ($sub_type == 'parse-maintenance') {
$schedule_id = mres($_POST['schedule_id']);
$schedule = dbFetchRow('SELECT * FROM `alert_schedule` WHERE `schedule_id`=?', array($schedule_id));
$items = array();
foreach (dbFetchRows('SELECT `target` FROM `alert_schedule_items` WHERE `schedule_id`=?', array($schedule_id)) as $targets) {
$targets = id_to_target($targets['target']);
array_push($items, $targets);
}
$response = array(
'start' => $schedule['start'],
'end' => $schedule['end'],
'title' => $schedule['title'],
'notes' => $schedule['notes'],
'targets' => $items,
);
}
else if ($sub_type == 'del-maintenance') {
$response = array('status'=>$status,'message'=>$message);
} elseif ($sub_type == 'parse-maintenance') {
$schedule_id = mres($_POST['schedule_id']);
$schedule = dbFetchRow("SELECT * FROM `alert_schedule` WHERE `schedule_id`=?",array($schedule_id));
$items = array();
foreach (dbFetchRows("SELECT `target` FROM `alert_schedule_items` WHERE `schedule_id`=?",array($schedule_id)) as $targets) {
$targets = id_to_target($targets['target']);
array_push($items,$targets);
}
$response = array('start'=>$schedule['start'],'end'=>$schedule['end'],'title'=>$schedule['title'],'notes'=>$schedule['notes'],'targets'=>$items);
} elseif ($sub_type == 'del-maintenance') {
$schedule_id = mres($_POST['del_schedule_id']);
dbDelete('alert_schedule_items', '`schedule_id`=?', array($schedule_id));
dbDelete('alert_schedule', '`schedule_id`=?', array($schedule_id));
$status = 'ok';
$message = 'Maintenance schedule has been removed';
$response = array(
'status' => $status,
'message' => $message,
);
}//end if
dbDelete('alert_schedule_items','`schedule_id`=?',array($schedule_id));
dbDelete('alert_schedule','`schedule_id`=?', array($schedule_id));
$status = 'ok';
$message = 'Maintenance schedule has been removed';
$response = array('status'=>$status,'message'=>$message);
}
echo _json_encode($response);
+14 -11
View File
@@ -1,18 +1,21 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk>
*
* 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.
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk>
*
* 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.
*/
// FUA
for ($x = 0; $x < count($_POST['sensor_id']); $x++) {
dbUpdate(array('sensor_limit' => $_POST['sensor_limit'][$x], 'sensor_limit_low' => $_POST['sensor_limit_low'][$x], 'sensor_alert' => $_POST['sensor_alert'][$x]), 'sensors', '`sensor_id` = ?', array($_POST['sensor_id'][$x]));
for($x=0;$x<count($_POST['sensor_id']);$x++)
{
dbUpdate(array('sensor_limit' => $_POST['sensor_limit'][$x], 'sensor_limit_low' => $_POST['sensor_limit_low'][$x], 'sensor_alert' => $_POST['sensor_alert'][$x]), 'sensors', '`sensor_id` = ?', array($_POST['sensor_id'][$x]));
}
+34 -26
View File
@@ -13,33 +13,41 @@
*/
// FUA
if (isset($_POST['sub_type']) && !empty($_POST['sub_type'])) {
dbUpdate(array('sensor_custom' => 'No'), 'sensors', '`sensor_id` = ?', array($_POST['sensor_id']));
}
else {
if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id'])) {
echo 'error with data';
exit;
}
else {
if ($_POST['state'] == 'true') {
$state = 1;
}
else if ($_POST['state'] == 'false') {
$state = 0;
}
else {
$state = 0;
}
} else {
$update = dbUpdate(array('sensor_alert' => $state), 'sensors', '`sensor_id` = ? AND `device_id` = ?', array($_POST['sensor_id'], $_POST['device_id']));
if (!empty($update) || $update == '0') {
echo 'success';
exit;
}
else {
echo 'error';
exit;
}
}
if(!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id']))
{
echo('error with data');
exit;
}
else
{
if($_POST['state'] == 'true')
{
$state = 1;
}
elseif($_POST['state'] == 'false')
{
$state = 0;
}
else
{
$state = 0;
}
$update = dbUpdate(array('sensor_alert' => $state), 'sensors', '`sensor_id` = ? AND `device_id` = ?', array($_POST['sensor_id'],$_POST['device_id']));
if(!empty($update) || $update == '0')
{
echo('success');
exit;
}
else
{
echo('error');
exit;
}
}
}
+35 -29
View File
@@ -1,38 +1,44 @@
<?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.
* 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.
*/
if (!is_numeric($_POST['user_id']) || !isset($_POST['token'])) {
echo 'ERROR: error with data, please ensure a valid user and token have been specified.';
exit;
if(!is_numeric($_POST['user_id']) || !isset($_POST['token']))
{
echo('ERROR: error with data, please ensure a valid user and token have been specified.');
exit;
}
else if (strlen($_POST['token']) > 32) {
echo 'ERROR: The token is more than 32 characters';
exit;
elseif(strlen($_POST['token']) > 32)
{
echo('ERROR: The token is more than 32 characters');
exit;
}
else if (strlen($_POST['token']) < 16) {
echo 'ERROR: The token is less than 16 characters';
elseif(strlen($_POST['token']) < 16)
{
echo('ERROR: The token is less than 16 characters');
exit;
}
else
{
$create = dbInsert(array('user_id' => $_POST['user_id'], 'token_hash' => $_POST['token'], 'description' => $_POST['description']), 'api_tokens');
if($create > '0')
{
echo('API token has been created');
$_SESSION['api_token'] = TRUE;
exit;
}
else
{
echo('ERROR: An error occurred creating the API token');
exit;
}
}
else {
$create = dbInsert(array('user_id' => $_POST['user_id'], 'token_hash' => $_POST['token'], 'description' => $_POST['description']), 'api_tokens');
if ($create > '0') {
echo 'API token has been created';
$_SESSION['api_token'] = true;
exit;
}
else {
echo 'ERROR: An error occurred creating the API token';
exit;
}
}//end if
+38 -32
View File
@@ -1,39 +1,45 @@
<?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.
* 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.
*/
if (!is_numeric($_POST['token_id'])) {
echo 'error with data';
if(!is_numeric($_POST['token_id']))
{
echo('error with data');
exit;
}
else
{
if($_POST['state'] == 'true')
{
$state = 1;
}
elseif($_POST['state'] == 'false')
{
$state = 0;
}
else
{
$state = 0;
}
$update = dbUpdate(array('disabled' => $state), 'api_tokens', '`id` = ?', array($_POST['token_id']));
if(!empty($update) || $update == '0')
{
echo('success');
exit;
}
else
{
echo('error');
exit;
}
}
else {
if ($_POST['state'] == 'true') {
$state = 1;
}
else if ($_POST['state'] == 'false') {
$state = 0;
}
else {
$state = 0;
}
$update = dbUpdate(array('disabled' => $state), 'api_tokens', '`id` = ?', array($_POST['token_id']));
if (!empty($update) || $update == '0') {
echo 'success';
exit;
}
else {
echo 'error';
exit;
}
}//end if
+29 -24
View File
@@ -1,31 +1,36 @@
<?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.
* 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.
*/
if (!is_numeric($_POST['token_id'])) {
echo 'error with data';
exit;
if(!is_numeric($_POST['token_id']))
{
echo('error with data');
exit;
}
else {
if ($_POST['confirm'] == 'yes') {
$delete = dbDelete('api_tokens', '`id` = ?', array($_POST['token_id']));
if ($delete > '0') {
echo 'API token has been removed';
exit;
}
else {
echo 'An error occurred removing the API token';
exit;
}
else
{
if($_POST['confirm'] == 'yes')
{
$delete = dbDelete('api_tokens', '`id` = ?', array($_POST['token_id']));
if($delete > '0')
{
echo('API token has been removed');
exit;
}
}//end if
else
{
echo('An error occurred removing the API token');
exit;
}
}
}
+30 -23
View File
@@ -12,32 +12,39 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
if (!is_numeric($_POST['alert_id'])) {
echo 'ERROR: No alert selected';
if(!is_numeric($_POST['alert_id']))
{
echo('ERROR: No alert selected');
exit;
}
else
{
if($_POST['state'] == 'true')
{
$state = 0;
}
elseif($_POST['state'] == 'false')
{
$state = 1;
}
else
{
$state = 1;
}
$update = dbUpdate(array('disabled' => $state), 'alert_rules', '`id`=?', array($_POST['alert_id']));
if(!empty($update) || $update == '0')
{
echo('Alert rule has been updated.');
exit;
}
else
{
echo('ERROR: Alert rule has not been updated.');
exit;
}
}
else {
if ($_POST['state'] == 'true') {
$state = 0;
}
else if ($_POST['state'] == 'false') {
$state = 1;
}
else {
$state = 1;
}
$update = dbUpdate(array('disabled' => $state), 'alert_rules', '`id`=?', array($_POST['alert_id']));
if (!empty($update) || $update == '0') {
echo 'Alert rule has been updated.';
exit;
}
else {
echo 'ERROR: Alert rule has not been updated.';
exit;
}
}
+26 -38
View File
@@ -12,70 +12,58 @@
* the source code distribution for details.
*/
if (is_admin() === false) {
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
$config_id = mres($_POST['config_id']);
$action = mres($_POST['action']);
$config_id = mres($_POST['config_id']);
$action = mres($_POST['action']);
$config_type = mres($_POST['config_type']);
$status = 'error';
if (!is_numeric($config_id)) {
$message = 'ERROR: No alert selected';
}
else if ($action == 'update-textarea') {
$extras = explode(PHP_EOL, $_POST['config_value']);
} elseif ($action == 'update-textarea') {
$extras = explode(PHP_EOL,$_POST['config_value']);
foreach ($extras as $option) {
list($k,$v) = explode('=', $option, 2);
list($k,$v) = explode("=", $option,2);
if (!empty($k) || !empty($v)) {
if ($config_type == 'slack') {
$db_id[] = dbInsert(array('config_name' => 'alert.transports.slack.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default' => $v, 'config_descr' => 'Slack Transport'), 'config');
}
else if ($config_type == 'hipchat') {
$db_id[] = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default' => $v, 'config_descr' => 'Hipchat Transport'), 'config');
}
else if ($config_type == 'pushover') {
$db_id[] = dbInsert(array('config_name' => 'alert.transports.pushover.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default' => $v, 'config_descr' => 'Pushover Transport'), 'config');
$db_id[] = dbInsert(array('config_name' => 'alert.transports.slack.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default'=>$v, 'config_descr'=>'Slack Transport'), 'config');
} elseif ($config_type == 'hipchat') {
$db_id[] = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default'=>$v, 'config_descr'=>'Hipchat Transport'), 'config');
} elseif ($config_type == 'pushover') {
$db_id[] = dbInsert(array('config_name' => 'alert.transports.pushover.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default'=>$v, 'config_descr'=>'Pushover Transport'), 'config');
}
}
}
$db_inserts = implode(',', $db_id);
$db_inserts = implode(",",$db_id);
if (!empty($db_inserts) || empty($_POST['config_value'])) {
if (empty($_POST['config_value'])) {
$db_inserts = 0;
}
if ($config_type == 'slack') {
dbDelete('config', "(`config_name` LIKE 'alert.transports.slack.$config_id.%' AND `config_name` != 'alert.transports.slack.$config_id.url' AND `config_id` NOT IN ($db_inserts))");
}
else if ($config_type == 'hipchat') {
dbDelete('config', "(`config_name` LIKE 'alert.transports.hipchat.$config_id.%' AND (`config_name` != 'alert.transports.hipchat.$config_id.url' AND `config_name` != 'alert.transports.hipchat.$config_id.room_id' AND `config_name` != 'alert.transports.hipchat.$config_id.from') AND `config_id` NOT IN ($db_inserts))");
}
else if ($config_type == 'pushover') {
dbDelete('config', "(`config_name` LIKE 'alert.transports.pushover.$config_id.%' AND (`config_name` != 'alert.transports.pushover.$config_id.appkey' AND `config_name` != 'alert.transports.pushover.$config_id.userkey') AND `config_id` NOT IN ($db_inserts))");
dbDelete('config',"(`config_name` LIKE 'alert.transports.slack.$config_id.%' AND `config_name` != 'alert.transports.slack.$config_id.url' AND `config_id` NOT IN ($db_inserts))");
} elseif ($config_type == 'hipchat') {
dbDelete('config',"(`config_name` LIKE 'alert.transports.hipchat.$config_id.%' AND (`config_name` != 'alert.transports.hipchat.$config_id.url' AND `config_name` != 'alert.transports.hipchat.$config_id.room_id' AND `config_name` != 'alert.transports.hipchat.$config_id.from') AND `config_id` NOT IN ($db_inserts))");
} elseif ($config_type == 'pushover') {
dbDelete('config',"(`config_name` LIKE 'alert.transports.pushover.$config_id.%' AND (`config_name` != 'alert.transports.pushover.$config_id.appkey' AND `config_name` != 'alert.transports.pushover.$config_id.userkey') AND `config_id` NOT IN ($db_inserts))");
}
}
$message = 'Config item has been updated:';
$status = 'ok';
}
else {
$state = mres($_POST['config_value']);
$status = 'ok';
} else {
$state = mres($_POST['config_value']);
$update = dbUpdate(array('config_value' => $state), 'config', '`config_id`=?', array($config_id));
if (!empty($update) || $update == '0') {
if(!empty($update) || $update == '0')
{
$message = 'Alert rule has been updated.';
$status = 'ok';
}
else {
$status = 'ok';
} else {
$message = 'ERROR: Alert rule has not been updated.';
}
}//end if
}
$response = array(
'status' => $status,
'message' => $message,
);
$response = array('status'=>$status,'message'=>$message);
echo _json_encode($response);