mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge branch 'issue-laf-110-new' of git://github.com/laf/librenms into laf-issue-laf-110-new
Conflicts: html/pages/health/mempool.inc.php includes/defaults.inc.php
This commit is contained in:
48
html/forms/config-item-disable.inc.php
Normal file
48
html/forms/config-item-disable.inc.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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_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;
|
||||
}
|
||||
}
|
||||
|
37
html/forms/config-item-update.inc.php
Normal file
37
html/forms/config-item-update.inc.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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_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;
|
||||
}
|
||||
}
|
||||
|
108
html/forms/config-item.inc.php
Normal file
108
html/forms/config-item.inc.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?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']);
|
||||
$status = 'error';
|
||||
$message = 'Error with config';
|
||||
|
||||
if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipchat') {
|
||||
$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.%'");
|
||||
} elseif ($action == 'remove-hipchat') {
|
||||
dbDelete('config', "`config_name` LIKE 'alert.transports.hipchat.$config_id.%'");
|
||||
}
|
||||
$status = 'ok';
|
||||
$message = 'Config item removed';
|
||||
} else {
|
||||
$message = 'General error, could not remove config';
|
||||
}
|
||||
}
|
||||
} 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');
|
||||
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';
|
||||
}
|
||||
}
|
||||
} 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');
|
||||
if ($config_id > 0) {
|
||||
dbUpdate(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.url'), 'config', 'config_id=?', array($config_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');
|
||||
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';
|
||||
}
|
||||
}
|
||||
} 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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$response = array('status'=>$status,'message'=>$message, 'config_id'=>$config_id);
|
||||
echo _json_encode($response);
|
62
html/forms/update-config-item.inc.php
Normal file
62
html/forms/update-config-item.inc.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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';
|
||||
} elseif ($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');
|
||||
} 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');
|
||||
}
|
||||
}
|
||||
}
|
||||
$db_inserts = implode(",",$db_id);
|
||||
if (!empty($db_inserts)) {
|
||||
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))");
|
||||
} 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))");
|
||||
}
|
||||
}
|
||||
$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.';
|
||||
}
|
||||
}
|
||||
|
||||
$response = array('status'=>$status,'message'=>$message);
|
||||
echo _json_encode($response);
|
Reference in New Issue
Block a user