Moved forms folder to includes and added some safety checks for non-admin users

This commit is contained in:
laf
2015-08-10 15:13:27 +00:00
parent 15a338061d
commit 261cd020f3
39 changed files with 87 additions and 2 deletions

View File

@@ -0,0 +1,41 @@
<?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.
*/
$alert_id = mres($_POST['alert_id']);
$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';
exit;
}
else {
if ($state == 2) {
$state = dbFetchCell('SELECT alerted FROM alerts WHERE id = ?', array($alert_id));
}
else if ($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;
}
}//end if

View File

@@ -0,0 +1,85 @@
<?php
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.org>
* 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.
*
* 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/>. */
/**
* Alert Templates
* @author f0o <f0o@devilcode.org>
* @copyright 2014 f0o, LibreNMS
* @license GPL
* @package LibreNMS
* @subpackage Alerts
*/
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
$ok = '';
$error = '';
$name = mres($_POST['name']);
if(!empty($name)) {
if( is_numeric($_REQUEST['template_id']) && $_REQUEST['rule_id'] ) {
//Update the template/rule mapping
if( is_array($_REQUEST['rule_id']) ) {
$_REQUEST['rule_id'] = implode(",",$_REQUEST['rule_id']);
}
if( substr($_REQUEST['rule_id'], 0,1) != "," ){
$_REQUEST['rule_id'] = ",".$_REQUEST['rule_id'];
}
if( substr($_REQUEST['rule_id'],-1,1) != "," ){
$_REQUEST['rule_id'] .= ",";
}
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 {
$error ="Failed to update the template and rule id mapping";
}
}
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 {
$error = "Failed to update the template";
}
}
elseif( $_REQUEST['template'] ) {
//Create new template
if(dbInsert(array('template' => $_REQUEST['template'], 'name' => $name), "alert_templates")) {
$ok = "Alert template has been created.";
}
else {
$error = "Could not create alert template";
}
}
else {
$error = "We could not work out what you wanted to do!";
}
}
else {
$error = "You haven't given your template a name, it feels sad :( - $name";
}
if(!empty( $ok )) {
die("$ok");
}
else {
die("ERROR: $error");
}

View File

@@ -0,0 +1,43 @@
<?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.
*/
if (is_admin() === false) {
die('ERROR: You need to be admin');
}
if (!is_numeric($_POST['template_id'])) {
echo 'ERROR: No template selected';
exit;
}
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.';
exit;
}
}
if ($success === true) {
dbDelete('alert_template_map', 'id NOT IN ('.implode(',', $ids).') AND alert_templates_id =?',array($_POST['template_id']));
echo "Alert rules have been attached to this template. $template_map_ids";
exit;
}
}//end if

View File

@@ -0,0 +1,19 @@
<?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.
*/
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
dbUpdate(array('value' => '2'), 'callback', '`name` = "enabled"', array());

View File

@@ -0,0 +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.
*/
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
if ($_POST['state'] == 'true') {
$state = 1;
}
elseif ($_POST['state'] == 'false') {
$state = 0;
}
else {
$state = 0;
}
if( dbUpdate(array('value' => $state), 'callback', '`name` = "enabled"', array()) == 0) {
dbInsert(array('value' => $state,'name' => 'enabled'), 'callback');
}

View File

@@ -0,0 +1,45 @@
<?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.
*/
// FUA
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
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

View File

@@ -0,0 +1,36 @@
<?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.
*/
// FUA
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
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;
}
}

View File

@@ -0,0 +1,182 @@
<?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.
*/
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']);
$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';
if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipchat' || $action == 'remove-pushover' || $action == 'remove-boxcar') {
$config_id = mres($_POST['config_id']);
if (empty($config_id)) {
$message = 'No config id passed';
}
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') {
dbDelete('config', "`config_name` LIKE 'alert.transports.hipchat.$config_id.%'");
}
else if ($action == 'remove-pushover') {
dbDelete('config', "`config_name` LIKE 'alert.transports.pushover.$config_id.%'");
}
elseif ($action == 'remove-boxcar') {
dbDelete('config', "`config_name` LIKE 'alert.transports.boxcar.$config_id.%'");
}
$status = 'ok';
$message = 'Config item removed';
}
else {
$message = 'General error, could not remove config';
}
}
}
else if ($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');
if ($config_id > 0) {
dbUpdate(array('config_name' => 'alert.transports.slack.'.$config_id.'.url'), 'config', 'config_id=?', array($config_id));
$status = 'ok';
$message = 'Config item created';
$extras = explode('\n', $config_extra);
foreach ($extras as $option) {
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');
}
}
}
else {
$message = 'Could not create config item';
}
}
}
else if ($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');
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);
foreach ($extras as $option) {
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');
}
}
}
else {
$message = 'Could not create config item';
}
}//end if
}
else if ($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');
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);
foreach ($extras as $option) {
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');
}
}
}
else {
$message = 'Could not create config item';
}
}
}
else if ($action == 'add-boxcar') {
if (empty($config_value)) {
$message = 'No Boxcar access token provided';
}
else {
$config_id = dbInsert(array('config_name' => 'alert.transports.boxcar.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Boxcar Transport'), 'config');
if ($config_id > 0) {
dbUpdate(array('config_name' => 'alert.transports.boxcar.'.$config_id.'.access_token'), 'config', 'config_id=?', array($config_id));
$status = 'ok';
$message = 'Config item created';
$extras = explode('\n', $config_extra);
foreach ($extras as $option) {
list($k,$v) = explode('=', $option, 2);
if (!empty($k) || !empty($v)) {
dbInsert(array('config_name' => 'alert.transports.boxcar.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Boxcar '.$v), 'config');
}
}
}
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,
);
echo _json_encode($response);

View File

@@ -0,0 +1,96 @@
<?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.
*/
if (is_admin() === false) {
die('ERROR: You need to be admin');
}
$rule = implode(' ', $_POST['rules']);
$rule = rtrim($rule, '&&');
$rule = rtrim($rule, '||');
$alert_id = $_POST['alert_id'];
$count = mres($_POST['count']);
$delay = mres($_POST['delay']);
$interval = mres($_POST['interval']);
$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] == ':') {
$device_id = $_POST['device_id'];
if (!is_numeric($count)) {
$count = '-1';
}
$delay_sec = convert_delay($delay);
$interval_sec = convert_delay($interval);
if ($mute == 'on') {
$mute = true;
}
else {
$mute = false;
}
if ($invert == 'on') {
$invert = true;
}
else {
$invert = false;
}
$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) {
$update_message = "Edited Rule: <i>$name: $rule</i>";
}
else {
$update_message = 'ERROR: Failed to edit Rule: <i>'.$rule.'</i>';
}
}
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, 'disabled' => 0, '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;
$_POST['target'] = $target;
$_POST['map_id'] = '';
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>';
}
}//end if
}
else {
$update_message = 'ERROR: invalid device ID or not a global alert';
}//end if
echo $update_message;

View File

@@ -0,0 +1,57 @@
<?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.
*/
if (is_admin() === false) {
die('ERROR: You need to be admin');
}
$pattern = $_POST['patterns'];
$group_id = $_POST['group_id'];
$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 (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>";
}
else {
$update_message = 'ERROR: Failed to edit Group: <i>'.$pattern.'</i>';
}
}
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>';
}
}
echo $update_message;

View File

@@ -0,0 +1,76 @@
<?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.
*/
if (is_admin() === false) {
die('ERROR: You need to be admin');
}
$rule = mres($_POST['rule']);
$target = mres($_POST['target']);
$map_id = mres($_POST['map_id']);
$ret = array();
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>");
}
}
}//end if
}//end if
}//end if
foreach ($ret as $msg) {
echo $msg.'<br/>';
}

View File

@@ -0,0 +1,47 @@
<?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.
*/
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');
}
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/>';
}

View File

@@ -0,0 +1,39 @@
<?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.
*/
if (is_admin() === false) {
die('ERROR: You need to be admin');
}
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;
}
}

View File

@@ -0,0 +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.
*/
if (is_admin() === false) {
die('ERROR: You need to be admin');
}
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;
}
}

View File

@@ -0,0 +1,39 @@
<?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.
*/
if (is_admin() === false) {
die('ERROR: You need to be admin');
}
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';
}
}
echo 'Group has been deleted.';
exit;
}
else {
echo 'ERROR: Group has not been deleted.';
exit;
}
}

View File

@@ -0,0 +1,33 @@
<?php
// FUA
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
$device['device_id'] = $_POST['device_id'];
$module = 'discover_'.$_POST['discovery_module'];
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;
}
if (isset($attribs['discover_'.$module]) && $attribs['discover_'.$module] != $config['discover_modules'][$module]) {
del_dev_attrib($device, $module);
}
else {
set_dev_attrib($device, $module, $state);
}
}

View File

@@ -0,0 +1,35 @@
<?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.
*/
// FUA
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
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;
}
}

View File

@@ -0,0 +1,35 @@
<?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.
*/
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)));
}
else {
$map['target'] = dbFetchCell('SELECT hostname FROM devices WHERE device_id = ?', array($map['target']));
}
$output = array(
'rule' => $map['name'],
'target' => $map['target'],
);
echo _json_encode($output);
}

View File

@@ -0,0 +1,33 @@
<?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.
*/
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);
$rule_split[$count] = $rule_split[$count].' &&';
$output = array(
'severity' => $rule['severity'],
'extra' => $rule['extra'],
'name' => $rule['name'],
'rules' => $rule_split,
);
echo _json_encode($output);
}

View File

@@ -0,0 +1,28 @@
<?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.
*/
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'],
);
echo _json_encode($output);
}

View File

@@ -0,0 +1,38 @@
<?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.
*/
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) {
$group_split[$count] = $group_split[$count];
}
else {
$group_split[$count] = $group_split[$count].' &&';
}
$output = array(
'name' => $group['name'],
'desc' => $group['desc'],
'pattern' => $group_split,
);
echo _json_encode($output);
}

View File

@@ -0,0 +1,28 @@
<?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.
*/
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'],
);
echo _json_encode($output);
}

View File

@@ -0,0 +1,28 @@
<?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.
*/
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) {
$rules[] = $rule['alert_rule_id'];
}
$output = array('rule_id' => $rules);
echo _json_encode($output);
}

View File

@@ -0,0 +1,35 @@
<?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.
*/
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
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;
}
}
}

View File

@@ -0,0 +1,51 @@
<?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.
*/
if (is_admin() === false) {
die('ERROR: You need to be admin');
}
$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';
}
else {
$error = 'Failed to update the poller group';
}
}
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';
}
}
}
else {
$error = "You haven't given your poller group a name, it feels sad :( - $group_name";
}
if (!empty($ok)) {
die("$ok");
}
else {
die("ERROR: $error");
}

View File

@@ -0,0 +1,32 @@
<?php
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
// FUA
$device['device_id'] = $_POST['device_id'];
$module = 'poll_'.$_POST['poller_module'];
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;
}
if (isset($attribs['poll_'.$module]) && $attribs['poll_'.$module] != $config['poller_modules'][$module]) {
del_dev_attrib($device, $module);
}
else {
set_dev_attrib($device, $module, $state);
}
}

View File

@@ -0,0 +1,47 @@
<?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.
*/
if (is_admin() === false) {
$response = array(
'status' => 'error',
'message' => 'Need to be admin',
);
echo _json_encode($response);
exit;
}
// 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');
echo _json_encode($output);

View File

@@ -0,0 +1,132 @@
<?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.
*/
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;
$schedule_id = mres($_POST['schedule_id']);
if ($schedule_id > 0) {
$update = 1;
}
$title = mres($_POST['title']);
$notes = mres($_POST['notes']);
$start = mres($_POST['start']);
$end = mres($_POST['end']);
$maps = mres($_POST['maps']);
if (empty($title)) {
$message = 'Missing title<br />';
}
if (empty($start)) {
$message .= 'Missing start date<br />';
}
if (empty($end)) {
$message .= 'Missing end date<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');
}
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;
if ($update == 1) {
dbDelete('alert_schedule_items', '`schedule_id`=?', array($schedule_id));
}
foreach ($_POST['maps'] as $target) {
$target = target_to_id($target);
$item = dbInsert(array('schedule_id' => $schedule_id, 'target' => $target), 'alert_schedule_items');
if ($item > 0) {
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';
$message = 'Scheduling maintenance ok';
}
}
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') {
$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
echo _json_encode($response);

View File

@@ -0,0 +1,23 @@
<?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.
*/
// FUA
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
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]));
}

View File

@@ -0,0 +1,50 @@
<?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.
*/
// FUA
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
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;
}
$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;
}
}
}

View File

@@ -0,0 +1,55 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2015 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) {
$response = array(
'status' => 'error',
'message' => 'Need to be admin',
);
echo _json_encode($response);
exit;
}
$status = 'error';
$message = 'Error updating storage information';
$device_id = mres($_POST['device_id']);
$storage_id = mres($_POST['storage_id']);
$data = mres($_POST['data']);
if (!is_numeric($device_id)) {
$message = 'Missing device id';
}
elseif (!is_numeric($storage_id)) {
$message = 'Missing storage id';
}
elseif (!is_numeric($data)) {
$message = 'Missing value';
}
else {
if (dbUpdate(array('storage_perc_warn'=>$data), 'storage', '`storage_id`=? AND `device_id`=?',array($storage_id,$device_id))) {
$message = 'Storage information updated';
$status = 'ok';
}
else {
$message = 'Could not update storage information';
}
}
$response = array(
'status' => $status,
'message' => $message,
'extra' => $extra,
);
echo _json_encode($response);

View File

@@ -0,0 +1,42 @@
<?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.
*/
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
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;
}
else if (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;
}
}//end if

View File

@@ -0,0 +1,43 @@
<?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.
*/
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
if (!is_numeric($_POST['token_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('disabled' => $state), 'api_tokens', '`id` = ?', array($_POST['token_id']));
if (!empty($update) || $update == '0') {
echo 'success';
exit;
}
else {
echo 'error';
exit;
}
}//end if

View File

@@ -0,0 +1,35 @@
<?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.
*/
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
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;
}
}
}//end if

View File

@@ -0,0 +1,43 @@
<?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.
*/
if (is_admin() === false) {
die('ERROR: You need to be admin');
}
if (!is_numeric($_POST['alert_id'])) {
echo 'ERROR: No alert selected';
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;
}
}

View File

@@ -0,0 +1,87 @@
<?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.
*/
if (is_admin() === false) {
die('ERROR: You need to be admin');
}
$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']);
foreach ($extras as $option) {
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');
}
elseif ($config_type == 'boxcar') {
$db_id[] = dbInsert(array('config_name' => 'alert.transports.boxcar.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default' => $v, 'config_descr' => 'Boxcar Transport'), 'config');
}
}
}
$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))");
}
else if ($config_type == 'boxcar') {
dbDelete('config', "(`config_name` LIKE 'alert.transports.boxcar.$config_id.%' AND (`config_name` != 'alert.transports.boxcar.$config_id.access_token' AND `config_name` != 'alert.transports.boxcar.$config_id.userkey') AND `config_id` NOT IN ($db_inserts))");
}
}
$message = 'Config item has been updated:';
$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') {
$message = 'Alert rule has been updated.';
$status = 'ok';
}
else {
$message = 'ERROR: Alert rule has not been updated.';
}
}//end if
$response = array(
'status' => $status,
'message' => $message,
);
echo _json_encode($response);

View File

@@ -0,0 +1,59 @@
<?php
$status = 'error';
$message = 'Error updating user dashboard config';
$data = json_decode($_POST['data'],true);
$sub_type = mres($_POST['sub_type']);
$widget_id = mres($_POST['widget_id']);
if ($sub_type == 'remove' && is_numeric($widget_id)) {
if ($widget_id == 0 || dbDelete('users_widgets','`user_id`=? AND `user_widget_id`=?', array($_SESSION['user_id'],$widget_id))) {
$status = 'ok';
$message = '';
}
}
elseif ($sub_type == 'remove-all') {
if (dbDelete('users_widgets','`user_id`=?', array($_SESSION['user_id']))) {
$status = 'ok';
$message = '';
}
}
elseif ($sub_type == 'add' && is_numeric($widget_id)) {
$dupe_check = dbFetchCEll('SELECT `user_widget_id` FROM `users_widgets` WHERE `user_id`=? AND `widget_id`=?',array($_SESSION['user_id'],$widget_id));
if (is_numeric($dupe_check)) {
$message = 'This widget has already been added';
}
else {
$widget = dbFetchRow('SELECT * FROM `widgets` WHERE `widget_id`=?', array($widget_id));
if (is_array($widget)) {
list($x,$y) = explode(',',$widget['base_dimensions']);
$item_id = dbInsert(array('user_id'=>$_SESSION['user_id'],'widget_id'=>$widget_id, 'col'=>1,'row'=>1,'refresh'=>60,'title'=>$widget['widget_title'],'size_x'=>$x,'size_y'=>$y),'users_widgets');
if (is_numeric($item_id)) {
$extra = array('widget_id'=>$item_id,'title'=>$widget['widget_title'],'widget'=>$widget['widget'],'size_x'=>$x,'size_y'=>$y);
$status = 'ok';
$message = '';
}
}
}
}
else {
$status = 'ok';
$message = '';
foreach ($data as $line) {
if (is_array($line)) {
$update = array('col'=>$line['col'],'row'=>$line['row'],'size_x'=>$line['size_x'],'size_y'=>$line['size_y']);
dbUpdate($update, 'users_widgets', '`user_widget_id`=?', array($line['id']));
}
}
}
$response = array(
'status' => $status,
'message' => $message,
'extra' => $extra,
);
echo _json_encode($response);

View File

@@ -0,0 +1,82 @@
<?php
if (is_admin() === false) {
$response = array(
'status' => 'error',
'message' => 'Need to be admin',
);
echo _json_encode($response);
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(array('ignore' => $newign), 'ports', '`device_id` = ? AND `port_id` = ?', array($device_id, $port_id));
if ($n < 0) {
$rows_updated = -1;
break;
}
$rows_updated += $n;
}
else if (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(array('disabled' => $newdis), 'ports', '`device_id` = ? AND `port_id` = ?', array($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.' Device record updated.';
$status = 'ok';
}
else if ($rows_updated = '-1') {
$message = 'Device record unchanged. No update necessary.';
$status = 'ok';
}
else {
$message = 'Device record update error.';
}
$response = array(
'status' => $status,
'message' => $message,
);
echo _json_encode($response);