From 6e845350314a831e654c5c30a0666a64cae71a99 Mon Sep 17 00:00:00 2001 From: laf Date: Thu, 22 Jan 2015 21:22:37 +0000 Subject: [PATCH 01/12] Dynamic config system --- html/form_new_config.php | 99 ++++++ html/forms/config-item-disable.inc.php | 48 +++ html/forms/config-item-update.inc.php | 37 +++ html/includes/functions.inc.php | 9 + html/pages/device/health/mempool.inc.php | 2 +- .../device/overview/generic/sensor.inc.php | 2 +- html/pages/device/overview/mempools.inc.php | 2 +- html/pages/device/port.inc.php | 2 +- html/pages/device/ports.inc.php | 2 +- html/pages/health/mempool.inc.php | 2 +- html/pages/health/sensors.inc.php | 2 +- html/pages/settings.inc.php | 282 +++++++++++++++--- includes/definitions.inc.php | 103 ++++++- includes/functions.php | 2 +- includes/polling/functions.inc.php | 2 +- includes/polling/mempools.inc.php | 2 +- includes/polling/ports.inc.php | 12 +- includes/polling/storage.inc.php | 2 +- 18 files changed, 544 insertions(+), 68 deletions(-) create mode 100644 html/form_new_config.php create mode 100644 html/forms/config-item-disable.inc.php create mode 100644 html/forms/config-item-update.inc.php diff --git a/html/form_new_config.php b/html/form_new_config.php new file mode 100644 index 000000000..6f45a3d6c --- /dev/null +++ b/html/form_new_config.php @@ -0,0 +1,99 @@ + + * + * 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. + */ + +enable_debug(); + +include_once("../includes/defaults.inc.php"); +include_once("../config.php"); +include_once("../includes/definitions.inc.php"); +include_once("includes/functions.inc.php"); +include_once("../includes/functions.php"); +include_once("includes/authenticate.inc.php"); + +if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; } + +$new_conf_type = $_POST['new_conf_type']; +$new_conf_name = $_POST['new_conf_name']; +$new_conf_desc = $_POST['new_conf_desc']; + +if(empty($new_conf_name)) +{ + echo("You haven't specified a config name"); + exit; +} +elseif(empty($new_conf_desc)) +{ + echo("You haven't specified a config description"); + exit; +} +elseif(empty($_POST['new_conf_single_value']) && empty($_POST['new_conf_multi_value'])) +{ + echo("You haven't specified a config value"); + exit; +} + +$db_inserted = '0'; + +if($new_conf_type == 'Single') +{ + $new_conf_type = 'single'; + $new_conf_value = $_POST['new_conf_single_value']; + $db_inserted = add_config_item($new_conf_name,$new_conf_value,$new_conf_type,$new_conf_desc); +} +elseif($new_conf_type == 'Single Array') +{ + $new_conf_type = 'single-array'; + $new_conf_value = $_POST['new_conf_single_value']; + $db_inserted = add_config_item($new_conf_name,$new_conf_value,$new_conf_type,$new_conf_desc); +} +elseif($new_conf_type == 'Standard Array' || $new_conf_type == 'Multi Array') +{ + if($new_conf_type == 'Standard Array') + { + $new_conf_type = 'array'; + } + elseif($new_conf_type == 'Multi Array') + { + $new_conf_type = 'multi-array'; + } + else + { + # $new_conf_type is invalid so clear values so we don't create any config + $new_conf_value = ''; + } + $new_conf_value = nl2br($_POST['new_conf_multi_value']); + $values = explode('
',$new_conf_value); + foreach ($values as $item) + { + $new_conf_value = trim($item); + $db_inserted = add_config_item($new_conf_name,$new_conf_value,$new_conf_type,$new_conf_desc); + } +} +else +{ + echo('Bad config type!'); + $db_inserted = 0; + exit; +} + +if($db_inserted == 1) +{ + echo('Your new config item has been added'); +} +else +{ + echo('An error occurred adding your config item to the database'); +} + +?> diff --git a/html/forms/config-item-disable.inc.php b/html/forms/config-item-disable.inc.php new file mode 100644 index 000000000..e44f6afdc --- /dev/null +++ b/html/forms/config-item-disable.inc.php @@ -0,0 +1,48 @@ + + * + * 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; + } +} + diff --git a/html/forms/config-item-update.inc.php b/html/forms/config-item-update.inc.php new file mode 100644 index 000000000..9ba795786 --- /dev/null +++ b/html/forms/config-item-update.inc.php @@ -0,0 +1,37 @@ + + * + * 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; + } +} + diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index 7118facdb..9c37be97b 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -774,7 +774,16 @@ function clean_bootgrid($string) { $output = str_replace(array("\r","\n"), "", $string); $output = addslashes($output); return $output; +} +//Insert new config items +function add_config_item($new_conf_name,$new_conf_value,$new_conf_type,$new_conf_desc) { + if (dbInsert(array('config_name' => $new_conf_name, 'config_value' => $new_conf_value, 'config_default' => $new_conf_value, 'config_type' => $new_conf_type, 'config_desc' => $new_conf_desc, 'config_group' => '500_Custom Settings', 'config_sub_group' => '01_Custom settings', 'config_hidden' => '0', 'config_disabled' => '0'), 'config')) { + $db_inserted = 1; + } else { + $db_inserted = 0; + } + return($db_inserted); } ?> diff --git a/html/pages/device/health/mempool.inc.php b/html/pages/device/health/mempool.inc.php index 2b4e5fcc8..6630c3147 100644 --- a/html/pages/device/health/mempool.inc.php +++ b/html/pages/device/health/mempool.inc.php @@ -13,7 +13,7 @@ foreach (dbFetchRows("SELECT * FROM `mempools` WHERE device_id = ?", array($devi { if (!is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); if($debug) { print_r($state); } diff --git a/html/pages/device/overview/generic/sensor.inc.php b/html/pages/device/overview/generic/sensor.inc.php index bda3d04bd..6194c37c0 100644 --- a/html/pages/device/overview/generic/sensor.inc.php +++ b/html/pages/device/overview/generic/sensor.inc.php @@ -14,7 +14,7 @@ if (count($sensors)) '); foreach ($sensors as $sensor) { - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); } diff --git a/html/pages/device/overview/mempools.inc.php b/html/pages/device/overview/mempools.inc.php index f11b6beaa..3d35a8d55 100644 --- a/html/pages/device/overview/mempools.inc.php +++ b/html/pages/device/overview/mempools.inc.php @@ -22,7 +22,7 @@ if (count($mempools)) foreach ($mempools as $mempool) { - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); if($debug) { print_r($state); } diff --git a/html/pages/device/port.inc.php b/html/pages/device/port.inc.php index 944b10a55..ecb25cfd2 100644 --- a/html/pages/device/port.inc.php +++ b/html/pages/device/port.inc.php @@ -4,7 +4,7 @@ if (!isset($vars['view']) ) { $vars['view'] = "graphs"; } $port = dbFetchRow("SELECT * FROM `ports` WHERE `port_id` = ?", array($vars['port'])); -if ($config['memcached']['enable']) +if ($config['memcached']['enable'] === TRUE) { $state = $memcache->get('port-'.$port['port_id'].'-state'); if($debug) { print_r($state); } diff --git a/html/pages/device/ports.inc.php b/html/pages/device/ports.inc.php index df7c691d6..b254b376d 100644 --- a/html/pages/device/ports.inc.php +++ b/html/pages/device/ports.inc.php @@ -106,7 +106,7 @@ if ($vars['view'] == 'minigraphs') foreach ($ports as $port) { - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $state = $memcache->get('port-'.$port['port_id'].'-state'); if($debug) { print_r($state); } diff --git a/html/pages/health/mempool.inc.php b/html/pages/health/mempool.inc.php index b348724e5..212a04709 100644 --- a/html/pages/health/mempool.inc.php +++ b/html/pages/health/mempool.inc.php @@ -19,7 +19,7 @@ foreach (dbFetchRows("SELECT * FROM `mempools` AS M, `devices` as D WHERE D.devi { $text_descr = $mempool['mempool_descr']; - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); if($debug) { print_r($state); } diff --git a/html/pages/health/sensors.inc.php b/html/pages/health/sensors.inc.php index 82f9862ce..02224d485 100644 --- a/html/pages/health/sensors.inc.php +++ b/html/pages/health/sensors.inc.php @@ -26,7 +26,7 @@ echo(' foreach (dbFetchRows($sql, $param) as $sensor) { - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); if($debug) { echo("Memcached[".'sensor-'.$sensor['sensor_id'].'-value'."=".$sensor['sensor_current']."]"); } diff --git a/html/pages/settings.inc.php b/html/pages/settings.inc.php index 8885e131c..584d3d87f 100644 --- a/html/pages/settings.inc.php +++ b/html/pages/settings.inc.php @@ -1,46 +1,248 @@ - * 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 . */ -/** - * Global Settings - * @author f0o - * @copyright 2015 f0o, LibreNMS - * @license GPL - * @package LibreNMS - * @subpackage Page +/* + * LibreNMS + * + * Copyright (c) 2014 Neil Lathwood + * + * 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. */ -/** - * Array-To-Table - * @param array $a N-Dimensional, Associative Array - * @return string - */ -function a2t($a) { - $r = "
"; - foreach( $a as $k=>$v ) { - if( !empty($v) ) { - $r .= ""; - } - } - $r .= '
".$k."".(is_array($v)?a2t($v):"".wordwrap($v,75,"
")."
")."
'; - return $r; -} +if ($_SESSION['userlevel'] >= '10') { + +?> + + + + +
+ +
+ +
+
+

System Settings

+
+
+ +
+
+
+
+'); + + foreach (dbFetchRows("SELECT config_id,config_group FROM `config` WHERE config_hidden='0' GROUP BY config_group ORDER BY config_group ASC") as $group) + { + list($grp_num,$grp_title) = explode("_",$group['config_group']); + $found++; + echo(' +
+ +
+
+'); + foreach (dbFetchRows("SELECT * FROM `config` WHERE config_group='".$group['config_group']."' ORDER BY config_sub_group ASC, config_name ASC") as $cfg) + { + $cfg_ids[] = $cfg['config_id']; + $cfg_disabled = ''; + if($cfg['config_disabled'] == '1') + { + $cfg_disabled = 'checked'; + } + echo(' +
+ +
+ +
+
+
+ +
+
+ +
+
+'); + + } + + echo(' +
+
+
+'); + + } + + + echo(' + +'); + + if ($debug) + { + echo("
");
+    print_r($config);
+    echo("
"); + } + +?> + + + + += 10 ) { - echo "
".a2t($config)."
"; -} else { - include("includes/error-no-perm.inc.php"); -} ?> diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index 78bd5a95f..3da03d78b 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -1,5 +1,96 @@ MySQL Error"); + echo(mysql_error()); + die; +} +$database_db = mysql_select_db($config['db_name'], $database_link); + +function create_array(&$arr,$string,$data,$type) +{ + // The original source of this code is from Stackoverflow (www.stackoverflow.com). + // http://stackoverflow.com/questions/9145902/create-variable-length-array-from-string + // Answer provided by stewe (http://stackoverflow.com/users/511300/stewe) + // This code is slightly adapted from the original posting. + + $a=explode(',',$string); + $last=count($a)-1; + $p=&$arr; + + foreach($a as $k=>$key) + { + if ($k==$last) + { + if($type == 'multi') + { + $p[$key]=explode(',',$data); + } + elseif($type == 'single') + { + $p[$key]=$data; + } + } + else if (is_array($p)) + { +// $p[$key]=array(); + } + $p=&$p[$key]; + } +} + +// We should be able to get config values from the DB now. +// Single field config values +$config_vars = get_defined_vars(); +$single_config = dbFetchRows("SELECT `config_name`, `config_value` FROM `config` WHERE `config_type` = 'single' AND `config_disabled` = '0'"); +foreach ($single_config as $config_data) +{ + $tmp_name = $config_data['config_name']; + if(!array_key_exists($config[$tmp_name], $config_vars)) + { + $config[$tmp_name] = $config_data['config_value']; + } +} +// Array config values +$config_vars = get_defined_vars(); +$array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'array' AND `config_disabled` = '0' GROUP BY config_name"); +foreach ($array_config as $config_data) +{ + $tmp_name = $config_data['config_name']; + if(!array_key_exists($config[$tmp_name], $config_vars)) + { + $config[$tmp_name] = explode(',',$config_data['config_value']); + } +} + +// Multi-array config values +$config_vars = get_defined_vars(); +$multi_array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'multi-array' AND `config_disabled` = '0' GROUP BY config_name"); +foreach ($multi_array_config as $config_data) +{ + create_array($config,$config_data['config_name'],$config_data['config_value'],'multi'); +} + +// Single-array config values +$config_vars = get_defined_vars(); +$single_array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'single-array' AND `config_disabled` = '0' GROUP BY config_name"); +foreach ($single_array_config as $config_data) +{ +// $tmp_name = explode(',',$config_data['config_name']); +// $new_name = implode('][',$tmp_name); +// if(!array_key_exists($config["{$tmp_name}"], $config_vars)) +// { +// $config["{$new_name}"] = $config_data['config_value']; +// } + create_array($config,$config_data['config_name'],$config_data['config_value'],'single'); +} + ///////////////////////////////////////////////////////// # NO CHANGES TO THIS FILE, IT IS NOT USER-EDITABLE # ///////////////////////////////////////////////////////// @@ -1726,17 +1817,7 @@ if (isset($_SERVER['HTTPS'])) $config['base_url'] = preg_replace('/^http:/','https:', $config['base_url']); } -// Connect to database -$database_link = mysql_pconnect($config['db_host'], $config['db_user'], $config['db_pass']); -if (!$database_link) -{ - echo("

MySQL Error

"); - echo(mysql_error()); - die; -} -$database_db = mysql_select_db($config['db_name'], $database_link); - -if ($config['memcached']['enable']) +if ($config['memcached']['enable'] === TRUE) { if (class_exists("Memcached")) { diff --git a/includes/functions.php b/includes/functions.php index c66dff623..d91259d0c 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -18,6 +18,7 @@ include_once("Net/IPv4.php"); include_once("Net/IPv6.php"); // Observium Includes +include_once($config['install_dir'] . "/includes/dbFacile.php"); include_once($config['install_dir'] . "/includes/common.php"); include_once($config['install_dir'] . "/includes/rrdtool.inc.php"); @@ -27,7 +28,6 @@ include_once($config['install_dir'] . "/includes/syslog.php"); include_once($config['install_dir'] . "/includes/rewrites.php"); include_once($config['install_dir'] . "/includes/snmp.inc.php"); include_once($config['install_dir'] . "/includes/services.inc.php"); -include_once($config['install_dir'] . "/includes/dbFacile.php"); include_once($config['install_dir'] . "/includes/console_colour.php"); $console_color = new Console_Color2(); diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index a85dfa4ab..33bd0cfe0 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -97,7 +97,7 @@ function poll_sensor($device, $class, $unit) log_event(ucfirst($class) . ' ' . $sensor['sensor_descr'] . " above threshold: " . $sensor_value . " $unit (> " . $sensor['sensor_limit'] . " $unit)", $device, $class, $sensor['sensor_id']); } - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $memcache->set('sensor-'.$sensor['sensor_id'].'-value', $sensor_value); } else { diff --git a/includes/polling/mempools.inc.php b/includes/polling/mempools.inc.php index 2d065afe1..abc94a496 100644 --- a/includes/polling/mempools.inc.php +++ b/includes/polling/mempools.inc.php @@ -46,7 +46,7 @@ foreach (dbFetchRows("SELECT * FROM mempools WHERE device_id = ?", array($device $mempool['state']['mempool_lowestfree'] = $mempool['lowestfree']; } - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { if($debug) { print_r($mempool['state']); } $memcache->set('mempool-'.$mempool['mempool_id'].'-value', $mempool['state']); diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index 03896c69c..bad8e5cf0 100644 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -164,7 +164,7 @@ foreach ($ports as $port) if ($device['os'] == "vmware" && preg_match("/Device ([a-z0-9]+) at .*/", $this_port['ifDescr'], $matches)) { $this_port['ifDescr'] = $matches[1]; } - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $state = $memcache->get('port-'.$port['port_id'].'-state'); if($debug) { print_r($state); } @@ -184,7 +184,7 @@ foreach ($ports as $port) $port['update']['poll_period'] = $polled_period; } - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $port['state']['poll_time'] = $polled; $port['state']['poll_prev'] = $port['poll_time']; @@ -303,7 +303,7 @@ foreach ($ports as $port) $port['update'][$oid.'_prev'] = $port[$oid]; } - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $port['state'][$oid] = $this_port[$oid]; $port['state'][$oid.'_prev'] = $port[$oid]; @@ -323,7 +323,7 @@ foreach ($ports as $port) $port['update'][$oid.'_delta'] = $oid_diff; } - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $port['state'][$oid.'_rate'] = $oid_rate; $port['state'][$oid.'_delta'] = $oid_diff; @@ -356,7 +356,7 @@ foreach ($ports as $port) echo('pkts('.format_si($port['stats']['ifInUcastPkts_rate']).'pps/'.format_si($port['stats']['ifOutUcastPkts_rate']).'pps)'); // Store aggregate in/out state - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $port['state']['ifOctets_rate'] = $port['stats']['ifOutOctets_rate'] + $port['stats']['ifInOctets_rate']; $port['state']['ifUcastPkts_rate'] = $port['stats']['ifOutUcastPkts_rate'] + $port['stats']['ifInUcastPkts_rate']; @@ -434,7 +434,7 @@ foreach ($ports as $port) if ($device['os'] == "aos") { include("port-alcatel.inc.php"); } // Update Memcached - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { if($debug) { print_r($port['state']); } $memcache->set('port-'.$port['port_id'].'-state', $port['state']); diff --git a/includes/polling/storage.inc.php b/includes/polling/storage.inc.php index 2485f822d..4c68d1752 100644 --- a/includes/polling/storage.inc.php +++ b/includes/polling/storage.inc.php @@ -36,7 +36,7 @@ foreach (dbFetchRows("SELECT * FROM storage WHERE device_id = ?", array($device[ rrdtool_update($storage_rrd,"N:".$storage['used'].":".$storage['free']); - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $memcache->set('storage-'.$storage['storage_id'].'-used', $storage['used']); $memcache->set('storage-'.$storage['storage_id'].'-free', $storage['free']); From d315014c96fea93ed145af7db4735acfea30481c Mon Sep 17 00:00:00 2001 From: laf Date: Thu, 5 Mar 2015 15:52:01 +0000 Subject: [PATCH 02/12] Updated to use isset rather than array check for speed --- includes/definitions.inc.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index 3da03d78b..28e66069f 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -30,11 +30,15 @@ function create_array(&$arr,$string,$data,$type) { if($type == 'multi') { - $p[$key]=explode(',',$data); + if (!isset($p[$key])) { + $p[$key]=explode(',',$data); + } } elseif($type == 'single') { - $p[$key]=$data; + if (!isset($p[$key])) { + $p[$key]=$data; + } } } else if (is_array($p)) @@ -52,7 +56,7 @@ $single_config = dbFetchRows("SELECT `config_name`, `config_value` FROM `config foreach ($single_config as $config_data) { $tmp_name = $config_data['config_name']; - if(!array_key_exists($config[$tmp_name], $config_vars)) + if(!isset($config[$tmp_name])) { $config[$tmp_name] = $config_data['config_value']; } @@ -63,7 +67,7 @@ $array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` foreach ($array_config as $config_data) { $tmp_name = $config_data['config_name']; - if(!array_key_exists($config[$tmp_name], $config_vars)) + if(!isset($config[$tmp_name])) { $config[$tmp_name] = explode(',',$config_data['config_value']); } @@ -82,14 +86,9 @@ $config_vars = get_defined_vars(); $single_array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'single-array' AND `config_disabled` = '0' GROUP BY config_name"); foreach ($single_array_config as $config_data) { -// $tmp_name = explode(',',$config_data['config_name']); -// $new_name = implode('][',$tmp_name); -// if(!array_key_exists($config["{$tmp_name}"], $config_vars)) -// { -// $config["{$new_name}"] = $config_data['config_value']; -// } create_array($config,$config_data['config_name'],$config_data['config_value'],'single'); } +unset($config_vars); ///////////////////////////////////////////////////////// # NO CHANGES TO THIS FILE, IT IS NOT USER-EDITABLE # From 8327466d14e09b01e9d7540e4b85fbc8c8eb17f5 Mon Sep 17 00:00:00 2001 From: laf Date: Fri, 15 May 2015 14:19:45 +0100 Subject: [PATCH 03/12] Adding alerting config --- html/pages/settings.inc.php | 64 +++++++++++++++++++++++++++--------- includes/defaults.inc.php | 38 --------------------- includes/definitions.inc.php | 8 ++--- sql-schema/051.sql | 1 + 4 files changed, 54 insertions(+), 57 deletions(-) create mode 100644 sql-schema/051.sql diff --git a/html/pages/settings.inc.php b/html/pages/settings.inc.php index 584d3d87f..1b38e87cf 100644 --- a/html/pages/settings.inc.php +++ b/html/pages/settings.inc.php @@ -1,17 +1,50 @@ - * - * 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. +/* Copyright (C) 2015 Daniel Preussker + * 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 . */ + +/** + * Global Settings + * @author f0o + * @copyright 2015 f0o, LibreNMS + * @license GPL + * @package LibreNMS + * @subpackage Page */ +/** + * Array-To-Table + * @param array $a N-Dimensional, Associative Array + * @return string + */ + +function a2t($a) { + $r = ""; + foreach( $a as $k=>$v ) { + if( !empty($v) ) { + $r .= ""; + } + } + $r .= '
".$k."".(is_array($v)?a2t($v):"".wordwrap($v,75,"
")."
")."
'; + return $r; +} +if( $_SESSION['userlevel'] >= 10 ) { + echo "
".a2t($config)."
"; +} else { + include("includes/error-no-perm.inc.php"); +} + if ($_SESSION['userlevel'] >= '10') { ?> @@ -101,9 +134,10 @@ $('#multi_value').toggle();
'); - foreach (dbFetchRows("SELECT config_id,config_group FROM `config` WHERE config_hidden='0' GROUP BY config_group ORDER BY config_group ASC") as $group) + foreach (dbFetchRows("SELECT config_id,config_group FROM `config` WHERE config_hidden='0' GROUP BY config_group ORDER BY config_group ASC ,config_group_order DESC") as $group) { - list($grp_num,$grp_title) = explode("_",$group['config_group']); + $grp_num = $group['config_group_order']; + $grp_title = $group['config_group']; $found++; echo('
@@ -117,7 +151,7 @@ $('#multi_value').toggle();
'); - foreach (dbFetchRows("SELECT * FROM `config` WHERE config_group='".$group['config_group']."' ORDER BY config_sub_group ASC, config_name ASC") as $cfg) + foreach (dbFetchRows("SELECT * FROM `config` WHERE config_group='".$group['config_group']."' ORDER BY config_sub_group ASC, config_sub_group_order DESC, config_name ASC") as $cfg) { $cfg_ids[] = $cfg['config_id']; $cfg_disabled = ''; @@ -127,9 +161,9 @@ $('#multi_value').toggle(); } echo('
- +
- +
diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index b8943412f..62b67b5f4 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -201,44 +201,6 @@ $config['email_smtp_auth'] = FALSE; // Whether or not $config['email_smtp_username'] = NULL; // SMTP username. $config['email_smtp_password'] = NULL; // Password for SMTP authentication. -// Alerting Settings - -$config['alert'] = array( - 'macros' => array( //Macros: - 'rule' => array( // For Rules - //Time Macros - 'now' => 'NOW()', - 'past_5m' => 'DATE_SUB(NOW(),INTERVAL 5 MINUTE)', - 'past_10m' => 'DATE_SUB(NOW(),INTERVAL 10 MINUTE)', - 'past_15m' => 'DATE_SUB(NOW(),INTERVAL 15 MINUTE)', - 'past_30m' => 'DATE_SUB(NOW(),INTERVAL 30 MINUTE)', - 'past_60m' => 'DATE_SUB(NOW(),INTERVAL 60 MINUTE)', - - //Device Macros - 'device' => '(%devices.disabled = "0" && %devices.ignore = "0")', - 'device_up' => '(%devices.status = "1" && %macros.device)', - 'device_down' => '(%devices.status = "0" && %macros.device)', - - //Port Macros - 'port' => '(%ports.deleted = "0" && %ports.ignore = "0" && %ports.disabled = "0")', - 'port_up' => '(%ports.ifOperStatus = "up" && %ports.ifAdminStatus = "up" && %macros.port)', - 'port_down' => '(%ports.ifOperStatus = "down" && %ports.ifAdminStatus != "down" && %macros.port)', - 'port_usage_perc' => '((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100', - - //Misc Macros - ), - ), - 'transports' => array( //Transports: - 'dummy' => false, // Dummy alerting (debug) - 'mail' => false, // E-Mail alerting - 'irc' => false, // IRC Alerting - ), - 'globals' => false, //Issue to global-read users - 'admins' => false, //Issue to administrators - 'default_only' => false, //Only issue to default - 'default_mail' => '', //Default email -); - //Legacy options $config['alerts']['email']['default'] = NULL; // Default alert recipient diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index 28e66069f..564697dfe 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -58,7 +58,7 @@ foreach ($single_config as $config_data) $tmp_name = $config_data['config_name']; if(!isset($config[$tmp_name])) { - $config[$tmp_name] = $config_data['config_value']; + $config[$tmp_name] = stripslashes($config_data['config_value']); } } // Array config values @@ -69,7 +69,7 @@ foreach ($array_config as $config_data) $tmp_name = $config_data['config_name']; if(!isset($config[$tmp_name])) { - $config[$tmp_name] = explode(',',$config_data['config_value']); + $config[$tmp_name] = explode(',',stripslashes($config_data['config_value'])); } } @@ -78,7 +78,7 @@ $config_vars = get_defined_vars(); $multi_array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'multi-array' AND `config_disabled` = '0' GROUP BY config_name"); foreach ($multi_array_config as $config_data) { - create_array($config,$config_data['config_name'],$config_data['config_value'],'multi'); + create_array($config,$config_data['config_name'],stripslashes($config_data['config_value']),'multi'); } // Single-array config values @@ -86,7 +86,7 @@ $config_vars = get_defined_vars(); $single_array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'single-array' AND `config_disabled` = '0' GROUP BY config_name"); foreach ($single_array_config as $config_data) { - create_array($config,$config_data['config_name'],$config_data['config_value'],'single'); + create_array($config,$config_data['config_name'],stripslashes($config_data['config_value']),'single'); } unset($config_vars); diff --git a/sql-schema/051.sql b/sql-schema/051.sql new file mode 100644 index 000000000..55ee4adfc --- /dev/null +++ b/sql-schema/051.sql @@ -0,0 +1 @@ +CREATE TABLE `config` ( `config_id` int(11) NOT NULL AUTO_INCREMENT, `config_name` varchar(255) NOT NULL, `config_value` varchar(255) NOT NULL, `config_default` varchar(255) NOT NULL, `config_type` enum('array','single','multi-array','single-array') NOT NULL DEFAULT 'single', `config_desc` varchar(100) NOT NULL, `config_group` varchar(50) NOT NULL, `config_sub_group` varchar(50) NOT NULL, `config_hidden` enum('0','1') NOT NULL DEFAULT '0', `config_disabled` enum('0','1') NOT NULL DEFAULT '0', PRIMARY KEY (`config_id`) ) ENGINE=InnoDB AUTO_INCREMENT=437 DEFAULT CHARSET=latin1; From d0a0df4e88beb1c6dc578d6b42b0169899cf476b Mon Sep 17 00:00:00 2001 From: laf Date: Sat, 16 May 2015 14:06:48 +0100 Subject: [PATCH 04/12] More updates to dynconfig + alert settings --- html/pages/settings.inc.php | 35 +++++++++++++++++++++++++--- html/pages/settings/alerting.inc.php | 21 +++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 html/pages/settings/alerting.inc.php diff --git a/html/pages/settings.inc.php b/html/pages/settings.inc.php index 1b38e87cf..85c69e96e 100644 --- a/html/pages/settings.inc.php +++ b/html/pages/settings.inc.php @@ -23,6 +23,35 @@ * @subpackage Page */ +if (isset($vars['sub'])) { + + if (file_exists(mres($vars['sub']))) { + require_once "pages/settings/".mres($vars['sub']).".inc.php"; + } else { + print_error("This settings page doesn't exist, please go to the main settings page"); + } + +} else { + +?> + +
+
+ +
+ +
+ +
+
+ + diff --git a/html/pages/settings/alerting.inc.php b/html/pages/settings/alerting.inc.php new file mode 100644 index 000000000..06647581c --- /dev/null +++ b/html/pages/settings/alerting.inc.php @@ -0,0 +1,21 @@ + + * + * 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. + */ + +?> + + +
+
+'; + ?> -
-
-
'); + } else { + $("#message").html('
' + data.message + '
'); + } + }, + error: function () { + $("#message").html('
An error occurred.
'); + } + }); + }); + diff --git a/sql-schema/051.sql b/sql-schema/051.sql index 55ee4adfc..6538df71f 100644 --- a/sql-schema/051.sql +++ b/sql-schema/051.sql @@ -1 +1,2 @@ -CREATE TABLE `config` ( `config_id` int(11) NOT NULL AUTO_INCREMENT, `config_name` varchar(255) NOT NULL, `config_value` varchar(255) NOT NULL, `config_default` varchar(255) NOT NULL, `config_type` enum('array','single','multi-array','single-array') NOT NULL DEFAULT 'single', `config_desc` varchar(100) NOT NULL, `config_group` varchar(50) NOT NULL, `config_sub_group` varchar(50) NOT NULL, `config_hidden` enum('0','1') NOT NULL DEFAULT '0', `config_disabled` enum('0','1') NOT NULL DEFAULT '0', PRIMARY KEY (`config_id`) ) ENGINE=InnoDB AUTO_INCREMENT=437 DEFAULT CHARSET=latin1; +CREATE TABLE `config` ( `config_id` int(11) NOT NULL AUTO_INCREMENT, `config_name` varchar(255) NOT NULL, `config_value` varchar(512) NOT NULL, `config_default` varchar(512) NOT NULL, `config_type` enum('array','single','multi-array','single-array') NOT NULL DEFAULT 'single', `config_desc` varchar(100) NOT NULL, `config_form` text NOT NULL, `config_group` varchar(50) NOT NULL, `config_group_order` int(11) NOT NULL, `config_sub_group` varchar(50) NOT NULL, `config_sub_group_order` int(11) NOT NULL, `config_hidden` enum('0','1') NOT NULL DEFAULT '0', `config_disabled` enum('0','1') NOT NULL DEFAULT '0', PRIMARY KEY (`config_id`) ENGINE=InnoDB AUTO_INCREMENT=428 DEFAULT CHARSET=latin1; +INSERT INTO `config` VALUES (405,'alert,macros,rule,now','NOW()','NOW()','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(406,'alert,macros,rule,past_5m','DATE_SUB(NOW(),INTERVAL 5 MINUTE)','DATE_SUB(NOW(),INTERVAL 5 MINUTE)','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(407,'alert,macros,rule,past_10m','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(408,'alert,macros,rule,past_15m','DATE_SUB(NOW(),INTERVAL 15 MINUTE)','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(409,'alert,macros,rule,past_30m','DATE_SUB(NOW(),INTERVAL 30 MINUTE)','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(410,'alert,macros,rule,past_60m','DATE_SUB(NOW(),INTERVAL 60 MINUTE)','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(411,'alert,macros,rule,device','(%devices.disabled = \"0\" && %devices.ignore = \"0\")','(%devices.disabled = \"0\" && %devices.ignore = \"0\")','single-array','Device macro','text:','alerting',100,'macros',10,'0','0'),(412,'alert,macros,rule,device_up','(%devices.status = \"1\" && %macros.device)','(%devices.status = \"1\" && %macros.device)','single-array','Device macro','text:','alerting',100,'macros',10,'0','0'),(413,'alert,macros,rule,device_down','(%devices.status = \"0\" && %macros.device)','(%devices.status = \"0\" && %macros.device)','single-array','Device macro','text:','alerting',100,'macros',10,'0','0'),(414,'alert,macros,rule,port','(%ports.deleted = \\\"0\\\" && %ports.ignore = \\\"0\\\" && %ports.disabled = \\\"0\\\")','(%ports.deleted = \"0\" && %ports.ignore = \"0\" && %ports.disabled = \"0\")','single-array','Port macro','text:','alerting',100,'macros',10,'0','0'),(415,'alert,macros,rule,port_up','(%ports.ifOperStatus = \"up\" && %ports.ifAdminStatus = \"up\" && %macros.port)','(%ports.ifOperStatus = \"up\" && %ports.ifAdminStatus = \"up\" && %macros.port)','single-array','Port macro','text:','alerting',100,'macros',10,'0','0'),(416,'alert,macros,rule,port_down','(%ports.ifOperStatus = \\\"down\\\" && %ports.ifAdminStatus != \\\"down\\\" && %macros.port)','(%ports.ifOperStatus = \"down\" && %ports.ifAdminStatus != \"down\" && %macros.port)','single-array','Port macro','text:','alerting',100,'macros',10,'0','0'),(417,'alert,macros,rule,port_usage_perc','((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100','((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100','single-array','Port macro','text:','alerting',100,'macros',10,'0','0'),(418,'alert,transports,dummy','false','false','single-array','Transports','radio:false,true','alerting',100,'transports',8,'0','0'),(419,'alert,transports,mail','false','false','single-array','Transports','radio:false,true','alerting',100,'transports',8,'0','0'),(420,'alert,transports,irc','false','false','single-array','Transports','radio:false,true','alerting',100,'transports',8,'0','0'),(421,'alert,globals','false','false','single-array','Issue alerts to global-read users','radio:false,true','alerting',100,'global',5,'0','0'),(422,'alert,admins','true','false','single-array','Issue alerts to admins','radio:false,true','alerting',100,'global',5,'0','0'),(423,'alert,default_only','true','false','single-array','Alert settings','radio:false,true','alerting',100,'global',5,'0','0'),(424,'alert,default_mail','','','single-array','Alert settings','text:','alerting',100,'global',5,'0','0'),(425,'alert,transports,pagerduty','false','false','single-array','Pagerduty transport','','alerting',100,'transports',8,'0','0'),(426,'alert,pagerduty,account','false','false','single-array','Pagerduty account name','','alerting',100,'transports',8,'0','0'),(427,'alert,pagerduty,service','false','false','single-array','Pagerduty service name','','alerting',100,'transports',8,'0','0'); From e1c0e7725d56e6182558ed1c837a2226ff1a2724 Mon Sep 17 00:00:00 2001 From: laf Date: Sun, 17 May 2015 21:45:06 +0100 Subject: [PATCH 06/12] More dynconfig alerting code --- html/forms/update-config-item.inc.php | 9 +- html/pages/settings/alerting.inc.php | 280 ++++++++++++++++++++++---- 2 files changed, 248 insertions(+), 41 deletions(-) diff --git a/html/forms/update-config-item.inc.php b/html/forms/update-config-item.inc.php index 1671d2f27..b7604a325 100644 --- a/html/forms/update-config-item.inc.php +++ b/html/forms/update-config-item.inc.php @@ -22,12 +22,7 @@ if (!is_numeric($_POST['config_id'])) { $message = 'ERROR: No alert selected'; exit; } else { - if($_POST['config_value'] === true) { - $state = TRUE; - } else { - $state = FALSE; - } - $state = $_POST['config_value']; + $state = mres($_POST['config_value']); $update = dbUpdate(array('config_value' => $state), 'config', '`config_id`=?', array($_POST['config_id'])); if(!empty($update) || $update == '0') { @@ -39,4 +34,4 @@ if (!is_numeric($_POST['config_id'])) { } $response = array('status'=>$status,'message'=>$message); -echo _json_encode($response); \ No newline at end of file +echo _json_encode($response); diff --git a/html/pages/settings/alerting.inc.php b/html/pages/settings/alerting.inc.php index 66a058440..0cc6811a1 100644 --- a/html/pages/settings/alerting.inc.php +++ b/html/pages/settings/alerting.inc.php @@ -22,6 +22,7 @@ if (isset($_GET['account']) && isset($_GET['service_key']) && isset($_GET['servi set_config_name('alert,pagerduty,service',$_GET['service_name']); } +// Default settings config $admin_config = get_config_by_name('alert,admins'); if (strcasecmp($admin_config[0]['config_value'],"true") == 0) { $admin_checked = 'checked'; @@ -41,6 +42,31 @@ if (strcasecmp($default_only_config[0]['config_value'],"true") == 0) { $default_only_checked = ''; } $default_mail_config = get_config_by_name('alert,default_mail'); +$tolerance_window_config = get_config_by_name('alert,tolerance_window'); + +// Mail transport config +$email_transport_config = get_config_by_name('alert,transports,mail'); +if (strcasecmp($email_transport_config[0]['config_value'],"true") == 0) { + $email_transport_checked = 'checked'; +} else { + $email_transport_checked = ''; +} +$email_backend_config = get_config_by_name('email_backend'); +$email_from_config = get_config_by_name('email_from'); +$email_user_config = get_config_by_name('email_user'); +$email_sendmail_path_config = get_config_by_name('email_sendmail_path'); +$email_smtp_host_config = get_config_by_name('email_smtp_host'); +$email_smtp_port_config = get_config_by_name('email_smtp_port'); +$email_smtp_timeout_config = get_config_by_name('email_smtp_timeout'); +$email_smtp_secure_config = get_config_by_name('email_smtp_secure'); +$email_smtp_auth_config = get_config_by_name('email_smtp_auth'); +if (strcasecmp($email_smtp_auth_config[0]['config_value'],"true") == 0) { + $email_smtp_auth_checked = 'checked'; +} else { + $email_smtp_auth_checked = ''; +} +$email_smtp_username_config = get_config_by_name('email_smtp_username'); +$email_smtp_password_config = get_config_by_name('email_smtp_password'); if (isset($config['base_url'])) { $callback = $config['base_url'].'/'.$_SERVER['REQUEST_URI'].'/'; @@ -50,48 +76,203 @@ if (isset($config['base_url'])) { $callback = urlencode($callback); echo ' -
-
-
- -
- -
- +
+ +
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
- Connect to PagerDuty -
-
- +
-
+
+
+

+ Email transport +

+
+
+
+
+ +
+
+ +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ +
+
+ +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+
+
+
+
+

+ API transport +

+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+ Connect to PagerDuty +
+
+
+
+
+
'; ?> From 388d30d2a6d1e5fc1f89c5ddbd147e160ed51160 Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 25 May 2015 02:12:48 +0100 Subject: [PATCH 07/12] updating to f0os function --- includes/definitions.inc.php | 93 +++++++++--------------------------- includes/functions.php | 1 + 2 files changed, 24 insertions(+), 70 deletions(-) diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index 564697dfe..65245dc73 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -13,82 +13,35 @@ if (!$database_link) } $database_db = mysql_select_db($config['db_name'], $database_link); -function create_array(&$arr,$string,$data,$type) -{ - // The original source of this code is from Stackoverflow (www.stackoverflow.com). - // http://stackoverflow.com/questions/9145902/create-variable-length-array-from-string - // Answer provided by stewe (http://stackoverflow.com/users/511300/stewe) - // This code is slightly adapted from the original posting. - - $a=explode(',',$string); - $last=count($a)-1; - $p=&$arr; - - foreach($a as $k=>$key) - { - if ($k==$last) - { - if($type == 'multi') - { - if (!isset($p[$key])) { - $p[$key]=explode(',',$data); +function mergecnf($obj) { + global $config; + $val = $obj['config_value']; + $obj = $obj['config_name']; + $obj = explode('.',$obj); + $str = ""; + foreach ($obj as $sub) { + if (!empty($sub)) { + $str .= "['".addslashes($sub)."']"; + } else { + $str .= "[]"; } - } - elseif($type == 'single') - { - if (!isset($p[$key])) { - $p[$key]=$data; - } - } } - else if (is_array($p)) - { -// $p[$key]=array(); + $str = '$config'.$str.' = '; + if (filter_var($val,FILTER_VALIDATE_INT)) { + $str .= "(int) '$val';"; + } elseif (filter_var($val,FILTER_VALIDATE_FLOAT)) { + $str .= "(float) '$val';"; + } elseif (filter_var($val,FILTER_VALIDATE_BOOLEAN)) { + $str .= "(boolean) '$val';"; + } else { + $str .= "'$val';"; } - $p=&$p[$key]; - } + eval('return array('.$str.')'); } -// We should be able to get config values from the DB now. -// Single field config values -$config_vars = get_defined_vars(); -$single_config = dbFetchRows("SELECT `config_name`, `config_value` FROM `config` WHERE `config_type` = 'single' AND `config_disabled` = '0'"); -foreach ($single_config as $config_data) -{ - $tmp_name = $config_data['config_name']; - if(!isset($config[$tmp_name])) - { - $config[$tmp_name] = stripslashes($config_data['config_value']); - } +foreach( dbFetchRows('select config_name,config_value from config') as $obj ) { + $config = array_merge_recursive($config,mergecnf($obj)); } -// Array config values -$config_vars = get_defined_vars(); -$array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'array' AND `config_disabled` = '0' GROUP BY config_name"); -foreach ($array_config as $config_data) -{ - $tmp_name = $config_data['config_name']; - if(!isset($config[$tmp_name])) - { - $config[$tmp_name] = explode(',',stripslashes($config_data['config_value'])); - } -} - -// Multi-array config values -$config_vars = get_defined_vars(); -$multi_array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'multi-array' AND `config_disabled` = '0' GROUP BY config_name"); -foreach ($multi_array_config as $config_data) -{ - create_array($config,$config_data['config_name'],stripslashes($config_data['config_value']),'multi'); -} - -// Single-array config values -$config_vars = get_defined_vars(); -$single_array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'single-array' AND `config_disabled` = '0' GROUP BY config_name"); -foreach ($single_array_config as $config_data) -{ - create_array($config,$config_data['config_name'],stripslashes($config_data['config_value']),'single'); -} -unset($config_vars); ///////////////////////////////////////////////////////// # NO CHANGES TO THIS FILE, IT IS NOT USER-EDITABLE # diff --git a/includes/functions.php b/includes/functions.php index d91259d0c..618117efc 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -28,6 +28,7 @@ include_once($config['install_dir'] . "/includes/syslog.php"); include_once($config['install_dir'] . "/includes/rewrites.php"); include_once($config['install_dir'] . "/includes/snmp.inc.php"); include_once($config['install_dir'] . "/includes/services.inc.php"); +echo $config['install_dir'] . "/includes/console_colour.php"; include_once($config['install_dir'] . "/includes/console_colour.php"); $console_color = new Console_Color2(); From 0ccbc7a6b1b97b74bf6b6c0dddeb464fc4e7180f Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 25 May 2015 18:05:11 +0100 Subject: [PATCH 08/12] More updates --- html/includes/functions.inc.php | 13 +- html/pages/settings/alerting.inc.php | 213 ++++++++++++++------------- includes/defaults.inc.php | 3 + includes/definitions.inc.php | 34 ++--- includes/functions.php | 1 - 5 files changed, 144 insertions(+), 120 deletions(-) diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index 2a86aa055..3bb433ddd 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -789,7 +789,18 @@ function add_config_item($new_conf_name,$new_conf_value,$new_conf_type,$new_conf function get_config_by_group($group) { $group = array($group); foreach (dbFetchRows("SELECT * FROM `config` WHERE `config_group` = '?'", array($group)) as $config_item) { - $items[] = $config_item; + $val = $config_item['config_value']; + if (filter_var($val,FILTER_VALIDATE_INT)) { + $val = (int) $val; + } elseif (filter_var($val,FILTER_VALIDATE_FLOAT)) { + $val = (float) $val; + } elseif (filter_var($val,FILTER_VALIDATE_BOOLEAN)) { + $val =(boolean) $val; + } + if ($val === TRUE) { + $config_item += array('config_checked'=>'checked'); + } + $items[$config_item['config_name']] = $config_item; } return $items; } diff --git a/html/pages/settings/alerting.inc.php b/html/pages/settings/alerting.inc.php index 0cc6811a1..2092b1084 100644 --- a/html/pages/settings/alerting.inc.php +++ b/html/pages/settings/alerting.inc.php @@ -17,56 +17,12 @@ if (isset($_GET['error'])) { } if (isset($_GET['account']) && isset($_GET['service_key']) && isset($_GET['service_name'])) { - set_config_name('alert,transports,pagerduty',$_GET['service_key']); - set_config_name('alert,pagerduty,account',$_GET['account']); - set_config_name('alert,pagerduty,service',$_GET['service_name']); + set_config_name('alert.transports.pagerduty',$_GET['service_key']); + set_config_name('alert.pagerduty.account',$_GET['account']); + set_config_name('alert.pagerduty.service',$_GET['service_name']); } -// Default settings config -$admin_config = get_config_by_name('alert,admins'); -if (strcasecmp($admin_config[0]['config_value'],"true") == 0) { - $admin_checked = 'checked'; -} else { - $admin_checked = ''; -} -$read_config = get_config_by_name('alert,globals'); -if (strcasecmp($read_config[0]['config_value'],"true") == 0) { - $read_checked = 'checked'; -} else { - $read_checked = ''; -} -$default_only_config = get_config_by_name('alert,default_only'); -if (strcasecmp($default_only_config[0]['config_value'],"true") == 0) { - $default_only_checked = 'checked'; -} else { - $default_only_checked = ''; -} -$default_mail_config = get_config_by_name('alert,default_mail'); -$tolerance_window_config = get_config_by_name('alert,tolerance_window'); - -// Mail transport config -$email_transport_config = get_config_by_name('alert,transports,mail'); -if (strcasecmp($email_transport_config[0]['config_value'],"true") == 0) { - $email_transport_checked = 'checked'; -} else { - $email_transport_checked = ''; -} -$email_backend_config = get_config_by_name('email_backend'); -$email_from_config = get_config_by_name('email_from'); -$email_user_config = get_config_by_name('email_user'); -$email_sendmail_path_config = get_config_by_name('email_sendmail_path'); -$email_smtp_host_config = get_config_by_name('email_smtp_host'); -$email_smtp_port_config = get_config_by_name('email_smtp_port'); -$email_smtp_timeout_config = get_config_by_name('email_smtp_timeout'); -$email_smtp_secure_config = get_config_by_name('email_smtp_secure'); -$email_smtp_auth_config = get_config_by_name('email_smtp_auth'); -if (strcasecmp($email_smtp_auth_config[0]['config_value'],"true") == 0) { - $email_smtp_auth_checked = 'checked'; -} else { - $email_smtp_auth_checked = ''; -} -$email_smtp_username_config = get_config_by_name('email_smtp_username'); -$email_smtp_password_config = get_config_by_name('email_smtp_password'); +$config_groups = get_config_by_group('alerting'); if (isset($config['base_url'])) { $callback = $config['base_url'].'/'.$_SERVER['REQUEST_URI'].'/'; @@ -87,39 +43,39 @@ echo '
- -
+ +
- +
- -
+ +
- +
- -
+ +
- +
- -
+ +
- +
- -
+ +
- +
@@ -135,96 +91,114 @@ echo '
- -
+ +
- +
- -
+ +
- +
- -
+ +
- +
- -
+ +
- +
- -
+ +
- +
- -
+ +
- +
- -
+ +
- +
- -
+ +
- +
- -
+ +
- +
- -
+ +
- +
- -
+ +
- +
- -
+ +
- +
@@ -256,9 +230,16 @@ echo '
-
+
Connect to PagerDuty
+
'; + if (empty($config_groups['alert.transports.pagerduty']['config_value']) === FALSE) { + echo "". $config_groups['alert.transports.pagerduty']['config_value']; + } else { + echo ""; + } + echo '
@@ -325,4 +306,36 @@ echo ' } }); }); + $( 'select[name="global-config-select"]').change(function(event) { + event.preventDefault(); + var $this = $(this); + var config_id = $this.data("config_id"); + var config_value = $this.val(); + $.ajax({ + type: 'POST', + url: '/ajax_form.php', + data: {type: "update-config-item", config_id: config_id, config_value: config_value}, + dataType: "json", + success: function (data) { + if (data.status == 'ok') { + $this.closest('.form-group').addClass('has-success'); + $this.next().addClass('glyphicon-ok'); + setTimeout(function(){ + $this.closest('.form-group').removeClass('has-success'); + $this.next().removeClass('glyphicon-ok'); + }, 2000); + } else { + $(this).closest('.form-group').addClass('has-error'); + $this.next().addClass('glyphicon-remove'); + setTimeout(function(){ + $this.closest('.form-group').removeClass('has-error'); + $this.next().removeClass('glyphicon-remove'); + }, 2000); + } + }, + error: function () { + $("#message").html('
An error occurred.
'); + } + }); + }); diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 62b67b5f4..3190c1f85 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -625,4 +625,7 @@ $config['ipmi']['type'][] = "lan"; $config['ipmi']['type'][] = "imb"; $config['ipmi']['type'][] = "open"; +// Options needed for dyn config - do NOT edit +$dyn_config['email_backend'] = array('mail','sendmail','smtp'); +$dyn_config['email_smtp_secure'] = array('', 'tls', 'ssl'); ?> diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index 65245dc73..6897cb6dc 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -14,29 +14,27 @@ if (!$database_link) $database_db = mysql_select_db($config['db_name'], $database_link); function mergecnf($obj) { - global $config; + $pointer = array(); $val = $obj['config_value']; $obj = $obj['config_name']; - $obj = explode('.',$obj); - $str = ""; - foreach ($obj as $sub) { - if (!empty($sub)) { - $str .= "['".addslashes($sub)."']"; - } else { - $str .= "[]"; + $obj = explode('.',$obj,2); + if (!isset($obj[1])) { + if (filter_var($val,FILTER_VALIDATE_INT)) { + $val = (int) $val; + } elseif (filter_var($val,FILTER_VALIDATE_FLOAT)) { + $val = (float) $val; + } elseif (filter_var($val,FILTER_VALIDATE_BOOLEAN)) { + $val =(boolean) $val; + } + if (!empty($obj[0])) { + return array($obj[0] => $val); + } else { + return array($val); } - } - $str = '$config'.$str.' = '; - if (filter_var($val,FILTER_VALIDATE_INT)) { - $str .= "(int) '$val';"; - } elseif (filter_var($val,FILTER_VALIDATE_FLOAT)) { - $str .= "(float) '$val';"; - } elseif (filter_var($val,FILTER_VALIDATE_BOOLEAN)) { - $str .= "(boolean) '$val';"; } else { - $str .= "'$val';"; + $pointer[$obj[0]] = mergecnf(array('config_name'=>$obj[1],'config_value'=>$val)); } - eval('return array('.$str.')'); + return $pointer; } foreach( dbFetchRows('select config_name,config_value from config') as $obj ) { diff --git a/includes/functions.php b/includes/functions.php index 618117efc..d91259d0c 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -28,7 +28,6 @@ include_once($config['install_dir'] . "/includes/syslog.php"); include_once($config['install_dir'] . "/includes/rewrites.php"); include_once($config['install_dir'] . "/includes/snmp.inc.php"); include_once($config['install_dir'] . "/includes/services.inc.php"); -echo $config['install_dir'] . "/includes/console_colour.php"; include_once($config['install_dir'] . "/includes/console_colour.php"); $console_color = new Console_Color2(); From 5b57e75b2e90c899efd94fac575cbed7c8324354 Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 25 May 2015 21:51:27 +0100 Subject: [PATCH 09/12] Final work getting alerts dynconfig done --- alerts.php | 2 +- doc/Extensions/Alerting.md | 14 + doc/Support/Configuration.md | 2 + html/forms/config-item.inc.php | 108 +++++ html/forms/update-config-item.inc.php | 31 +- html/includes/functions.inc.php | 11 +- html/pages/settings.inc.php | 237 +---------- html/pages/settings/alerting.inc.php | 567 +++++++++++++++++++++++++- includes/definitions.inc.php | 44 +- 9 files changed, 751 insertions(+), 265 deletions(-) create mode 100644 html/forms/config-item.inc.php diff --git a/alerts.php b/alerts.php index 6af7370b3..83194849c 100755 --- a/alerts.php +++ b/alerts.php @@ -247,7 +247,7 @@ function ExtTransports($obj) { global $config; $tmp = false; //To keep scrutinizer from naging because it doesnt understand eval foreach( $config['alert']['transports'] as $transport=>$opts ) { - if( ($opts === true || !empty($opts)) && file_exists($config['install_dir']."/includes/alerts/transport.".$transport.".php") ) { + if( ($opts === true || !empty($opts)) && $opts != false && file_exists($config['install_dir']."/includes/alerts/transport.".$transport.".php") ) { echo $transport." => "; eval('$tmp = function($obj,$opts) { global $config; '.file_get_contents($config['install_dir']."/includes/alerts/transport.".$transport.".php").' };'); $tmp = $tmp($obj,$opts); diff --git a/doc/Extensions/Alerting.md b/doc/Extensions/Alerting.md index 59fb295f9..7448a279c 100644 --- a/doc/Extensions/Alerting.md +++ b/doc/Extensions/Alerting.md @@ -138,6 +138,8 @@ $config['alert']['admins'] = true; //Include Adminstrators into alert-contacts ## E-Mail +> You can configure these options within the WebUI now, please avoid setting these options within config.php + E-Mail transport is enabled with adding the following to your `config.php`: ```php $config['alert']['transports']['mail'] = true; @@ -164,6 +166,8 @@ $config['alert']['default_mail'] = ''; //Default ema ## API +> You can configure these options within the WebUI now, please avoid setting these options within config.php + API transports definitions are a bit more complex than the E-Mail configuration. The basis for configuration is `$config['alert']['transports']['api'][METHOD]` where `METHOD` can be `get`,`post` or `put`. This basis has to contain an array with URLs of each API to call. @@ -179,6 +183,8 @@ $config['alert']['transports']['api']['get'][] = "https://api.thirdparti.es/issu ## Nagios Compatible +> You can configure these options within the WebUI now, please avoid setting these options within config.php + The nagios transport will feed a FIFO at the defined location with the same format that nagios would. This allows you to use other Alerting-Systems to work with LibreNMS, for example [Flapjack](http://flapjack.io). ```php @@ -187,6 +193,8 @@ $config['alert']['transports']['nagios'] = "/path/to/my.fifo"; //Flapjack expect ## IRC +> You can configure these options within the WebUI now, please avoid setting these options within config.php + The IRC transports only works together with the LibreNMS IRC-Bot. Configuration of the LibreNMS IRC-Bot is described [here](https://github.com/librenms/librenms/blob/master/doc/Extensions/IRC-Bot.md). ```php @@ -195,6 +203,8 @@ $config['alert']['transports']['irc'] = true; ## Slack +> You can configure these options within the WebUI now, please avoid setting these options within config.php + The Slack transport will POST the alert message to your Slack Incoming WebHook, you are able to specify multiple webhooks along with the relevant options to go with it. All options are optional, the only required value is for url, without this then no call to Slack will be made. Below is an example of how to send alerts to two channels with different customised options: ```php @@ -206,6 +216,8 @@ $config['alert']['transports']['slack'][] = array('url' => "https://hooks.slack. ## HipChat +> You can configure these options within the WebUI now, please avoid setting these options within config.php + The HipChat transport requires the following: __room_id__ = HipChat Room ID @@ -251,6 +263,8 @@ $config['alert']['transports']['hipchat'][] = array("url" => "https://api.hipcha ## PagerDuty +> You can configure these options within the WebUI now, please avoid setting these options within config.php + Enabling PagerDuty transports is almost as easy as enabling email-transports. All you need is to create a Service with type Generic API on your PagerDuty dashboard. diff --git a/doc/Support/Configuration.md b/doc/Support/Configuration.md index 4ef27c2c0..79b24e91b 100644 --- a/doc/Support/Configuration.md +++ b/doc/Support/Configuration.md @@ -211,6 +211,8 @@ Arrays of subnets to exclude in auto discovery mode. #### Email configuration +> You can configure these options within the WebUI now, please avoid setting these options within config.php + ```php $config['email_backend'] = 'mail'; $config['email_from'] = NULL; diff --git a/html/forms/config-item.inc.php b/html/forms/config-item.inc.php new file mode 100644 index 000000000..1a481b64a --- /dev/null +++ b/html/forms/config-item.inc.php @@ -0,0 +1,108 @@ + + * + * 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); diff --git a/html/forms/update-config-item.inc.php b/html/forms/update-config-item.inc.php index b7604a325..4c8cc5545 100644 --- a/html/forms/update-config-item.inc.php +++ b/html/forms/update-config-item.inc.php @@ -16,14 +16,39 @@ 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($_POST['config_id'])) { +if (!is_numeric($config_id)) { $message = 'ERROR: No alert selected'; - exit; +} 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($_POST['config_id'])); + $update = dbUpdate(array('config_value' => $state), 'config', '`config_id`=?', array($config_id)); if(!empty($update) || $update == '0') { $message = 'Alert rule has been updated.'; diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index 65772e2e3..d846d2ce8 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -805,14 +805,19 @@ function get_config_by_group($group) { return $items; } -function get_config_by_name($name) { +function get_config_like_name($name) { $name = array($name); - foreach (dbFetchRows("SELECT * FROM `config` WHERE `config_name` = '?'", array($name)) as $config_item) { - $items[] = $config_item; + foreach (dbFetchRows("SELECT * FROM `config` WHERE `config_name` LIKE '%?%'", array($name)) as $config_item) { + $items[$config_item['config_name']] = $config_item; } return $items; } +function get_config_by_name($name) { + $config_item = dbFetchRow("SELECT * FROM `config` WHERE `config_name` = ?", array($name)); + return $config_item; +} + function set_config_name($name,$config_value) { return dbUpdate(array('config_value' => $config_value), 'config', '`config_name`=?', array($name)); } diff --git a/html/pages/settings.inc.php b/html/pages/settings.inc.php index 3dac71da6..cb2d3ca94 100644 --- a/html/pages/settings.inc.php +++ b/html/pages/settings.inc.php @@ -54,14 +54,14 @@ foreach (dbFetchRows("SELECT `config_group` FROM `config` GROUP BY `config_group $sub_page = $sub_page['config_group']; ?>
- +
= 10 ) { include("includes/error-no-perm.inc.php"); } -if ($_SESSION['userlevel'] >= '10') { + if ($_SESSION['userlevel'] >= '10') { -?> - - - - -
- -
-
-
-
-

System Settings

-
-
- -
-
-
-
-'); - - foreach (dbFetchRows("SELECT config_id,config_group FROM `config` WHERE config_hidden='0' GROUP BY config_group ORDER BY config_group ASC ,config_group_order DESC") as $group) - { - $grp_num = $group['config_group_order']; - $grp_title = $group['config_group']; - $found++; - echo(' -
- -
-
-'); - foreach (dbFetchRows("SELECT * FROM `config` WHERE config_group='".$group['config_group']."' ORDER BY config_sub_group ASC, config_sub_group_order DESC, config_name ASC") as $cfg) - { - $cfg_ids[] = $cfg['config_id']; - $cfg_disabled = ''; - if($cfg['config_disabled'] == '1') - { - $cfg_disabled = 'checked'; - } - echo(' -
- -
- -
-
-
- -
-
- -
-
-'); - - } - - echo(' -
-
-
-'); - - } - - - echo(' - -'); - - if ($debug) - { - echo("
");
-    print_r($config);
-    echo("
"); - } - -?> - - - - - + + + + + + + + + + + + + +
-
+
- + +
+
+
+ +
+
+
@@ -79,6 +188,13 @@ echo '
+
+ +
+
+ +
+
@@ -92,9 +208,9 @@ echo '
-
+
- +
@@ -215,7 +331,32 @@ echo '
- + +
+
'; + $api_urls = get_config_like_name('alert.transports.api.%.'); + foreach ($api_urls as $api_url) { + $api_split = split("\.", $api_url['config_name']); + $api_method = $api_split[3]; + echo '
+ +
+ + +
+
+ +
+
'; + } + echo '
+ +
+ + +
+
+
@@ -235,7 +376,7 @@ echo '
'; if (empty($config_groups['alert.transports.pagerduty']['config_value']) === FALSE) { - echo "". $config_groups['alert.transports.pagerduty']['config_value']; + echo ""; } else { echo ""; } @@ -244,6 +385,201 @@ echo '
+
+ +
+
+
+ +
+
+ + +
+
+
+
+
+
+
+

+ IRC transport +

+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+

+ Slack transport +

+
+
+
+
+
+ +
+
'; + $slack_urls = get_config_like_name('alert.transports.slack.%.url'); + foreach ($slack_urls as $slack_url) { + unset($upd_slack_extra); + $new_slack_extra = array(); + $slack_extras = get_config_like_name('alert.transports.slack.'.$slack_url['config_id'].'.%'); + foreach ($slack_extras as $extra) { + $split_extra = explode('.',$extra['config_name']); + if ($split_extra[4] != 'url') { + $new_slack_extra[] = $split_extra[4] . '=' . $extra['config_value']; + } + } + $upd_slack_extra = implode(PHP_EOL,$new_slack_extra); + echo '
+
+ +
+ + +
+
+ +
+
+
+
+ + +
+
+
'; + } + echo '
+
+ +
+ + +
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+ +
+
'; + $hipchat_urls = get_config_like_name('alert.transports.hipchat.%.url'); + foreach ($hipchat_urls as $hipchat_url) { + unset($upd_hipchat_extra); + $new_hipchat_extra = array(); + $hipchat_extras = get_config_like_name('alert.transports.hipchat.'.$hipchat_url['config_id'].'.%'); + $hipchat_room_id = get_config_by_name('alert.transports.hipchat.'.$hipchat_url['config_id'].'.room_id'); + $hipchat_from = get_config_by_name('alert.transports.hipchat.'.$hipchat_url['config_id'].'.from'); + foreach ($hipchat_extras as $extra) { + $split_extra = explode('.',$extra['config_name']); + if ($split_extra[4] != 'url' && $split_extra[4] != 'room_id' && $split_extra[4] != 'from') { + $new_hipchat_extra[] = $split_extra[4] . '=' . $extra['config_value']; + } + } + $upd_hipchat_extra = implode(PHP_EOL,$new_hipchat_extra); + echo '
+
+ +
+ + +
+
+ +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+ + +
+
+
'; + } + echo '
+
+ +
+ + +
+
+ +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+ +
+
+
+
+
+
'; @@ -252,8 +588,192 @@ echo ' diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index c8029c51f..ea8dd65c6 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -14,32 +14,34 @@ if (!$database_link) $database_db = mysql_select_db($config['db_name'], $database_link); function mergecnf($obj) { - $pointer = array(); - $val = $obj['config_value']; - $obj = $obj['config_name']; - $obj = explode('.',$obj,2); - if (!isset($obj[1])) { - if (filter_var($val,FILTER_VALIDATE_INT)) { - $val = (int) $val; - } elseif (filter_var($val,FILTER_VALIDATE_FLOAT)) { - $val = (float) $val; - } elseif (filter_var($val,FILTER_VALIDATE_BOOLEAN)) { - $val =(boolean) $val; - } - if (!empty($obj[0])) { - return array($obj[0] => $val); - } else { - return array($val); - } - } else { - $pointer[$obj[0]] = mergecnf(array('config_name'=>$obj[1],'config_value'=>$val)); + $pointer = array(); + $val = $obj['config_value']; + $obj = $obj['config_name']; + $obj = explode('.',$obj,2); + if( !isset($obj[1]) ) { + if( filter_var($val,FILTER_VALIDATE_INT) ) { + $val = (int) $val; + } elseif( filter_var($val,FILTER_VALIDATE_FLOAT) ) { + $val = (float) $val; + } elseif( filter_var($val,FILTER_VALIDATE_BOOLEAN,FILTER_NULL_ON_FAILURE) !== NULL ) { + $val = filter_var($val,FILTER_VALIDATE_BOOLEAN); } - return $pointer; + if( !empty($obj[0]) ) { + return array($obj[0] => $val); + } else { + return array($val); + } + } else { + $pointer[$obj[0]] = mergecnf(array('config_name'=>$obj[1],'config_value'=>$val)); + } + return $pointer; } +$clone = $config; foreach( dbFetchRows('select config_name,config_value from config') as $obj ) { - $config = array_merge_recursive($config,mergecnf($obj)); + $clone = array_replace_recursive($clone,mergecnf($obj)); } +$config = array_replace_recursive($clone,$config); ///////////////////////////////////////////////////////// # NO CHANGES TO THIS FILE, IT IS NOT USER-EDITABLE # From 6fab7cf718e7258befcfa2e14a336707ceefbcd1 Mon Sep 17 00:00:00 2001 From: laf Date: Thu, 28 May 2015 17:07:14 +0100 Subject: [PATCH 10/12] Some last changes --- includes/defaults.inc.php | 18 ------------------ sql-schema/051.sql | 7 +++++-- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 3190c1f85..e97c64fc9 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -187,24 +187,6 @@ $config['autodiscovery']['nets-exclude'][] = "169.254.0.0/16"; $config['autodiscovery']['nets-exclude'][] = "224.0.0.0/4"; $config['autodiscovery']['nets-exclude'][] = "240.0.0.0/4"; -// Mailer backend Settings - -$config['email_backend'] = 'mail'; // Mail backend. Allowed: "mail" (PHP's built-in), "sendmail", "smtp". -$config['email_from'] = NULL; // Mail from. Default: "ProjectName" -$config['email_user'] = $config['project_id']; -$config['email_sendmail_path'] = '/usr/sbin/sendmail'; // The location of the sendmail program. -$config['email_smtp_host'] = 'localhost'; // Outgoing SMTP server name. -$config['email_smtp_port'] = 25; // The port to connect. -$config['email_smtp_timeout'] = 10; // SMTP connection timeout in seconds. -$config['email_smtp_secure'] = NULL; // Enable encryption. Use 'tls' or 'ssl' -$config['email_smtp_auth'] = FALSE; // Whether or not to use SMTP authentication. -$config['email_smtp_username'] = NULL; // SMTP username. -$config['email_smtp_password'] = NULL; // Password for SMTP authentication. - -//Legacy options - -$config['alerts']['email']['default'] = NULL; // Default alert recipient -$config['alerts']['email']['default_only'] = FALSE; // Only use default recipient $config['alerts']['email']['enable'] = TRUE; // Enable email alerts $config['alerts']['bgp']['whitelist'] = NULL; // Populate as an array() with ASNs to alert on. $config['alerts']['port']['ifdown'] = FALSE; // Generate alerts for ports that go down diff --git a/sql-schema/051.sql b/sql-schema/051.sql index 6538df71f..10fb97fb3 100644 --- a/sql-schema/051.sql +++ b/sql-schema/051.sql @@ -1,2 +1,5 @@ -CREATE TABLE `config` ( `config_id` int(11) NOT NULL AUTO_INCREMENT, `config_name` varchar(255) NOT NULL, `config_value` varchar(512) NOT NULL, `config_default` varchar(512) NOT NULL, `config_type` enum('array','single','multi-array','single-array') NOT NULL DEFAULT 'single', `config_desc` varchar(100) NOT NULL, `config_form` text NOT NULL, `config_group` varchar(50) NOT NULL, `config_group_order` int(11) NOT NULL, `config_sub_group` varchar(50) NOT NULL, `config_sub_group_order` int(11) NOT NULL, `config_hidden` enum('0','1') NOT NULL DEFAULT '0', `config_disabled` enum('0','1') NOT NULL DEFAULT '0', PRIMARY KEY (`config_id`) ENGINE=InnoDB AUTO_INCREMENT=428 DEFAULT CHARSET=latin1; -INSERT INTO `config` VALUES (405,'alert,macros,rule,now','NOW()','NOW()','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(406,'alert,macros,rule,past_5m','DATE_SUB(NOW(),INTERVAL 5 MINUTE)','DATE_SUB(NOW(),INTERVAL 5 MINUTE)','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(407,'alert,macros,rule,past_10m','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(408,'alert,macros,rule,past_15m','DATE_SUB(NOW(),INTERVAL 15 MINUTE)','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(409,'alert,macros,rule,past_30m','DATE_SUB(NOW(),INTERVAL 30 MINUTE)','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(410,'alert,macros,rule,past_60m','DATE_SUB(NOW(),INTERVAL 60 MINUTE)','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(411,'alert,macros,rule,device','(%devices.disabled = \"0\" && %devices.ignore = \"0\")','(%devices.disabled = \"0\" && %devices.ignore = \"0\")','single-array','Device macro','text:','alerting',100,'macros',10,'0','0'),(412,'alert,macros,rule,device_up','(%devices.status = \"1\" && %macros.device)','(%devices.status = \"1\" && %macros.device)','single-array','Device macro','text:','alerting',100,'macros',10,'0','0'),(413,'alert,macros,rule,device_down','(%devices.status = \"0\" && %macros.device)','(%devices.status = \"0\" && %macros.device)','single-array','Device macro','text:','alerting',100,'macros',10,'0','0'),(414,'alert,macros,rule,port','(%ports.deleted = \\\"0\\\" && %ports.ignore = \\\"0\\\" && %ports.disabled = \\\"0\\\")','(%ports.deleted = \"0\" && %ports.ignore = \"0\" && %ports.disabled = \"0\")','single-array','Port macro','text:','alerting',100,'macros',10,'0','0'),(415,'alert,macros,rule,port_up','(%ports.ifOperStatus = \"up\" && %ports.ifAdminStatus = \"up\" && %macros.port)','(%ports.ifOperStatus = \"up\" && %ports.ifAdminStatus = \"up\" && %macros.port)','single-array','Port macro','text:','alerting',100,'macros',10,'0','0'),(416,'alert,macros,rule,port_down','(%ports.ifOperStatus = \\\"down\\\" && %ports.ifAdminStatus != \\\"down\\\" && %macros.port)','(%ports.ifOperStatus = \"down\" && %ports.ifAdminStatus != \"down\" && %macros.port)','single-array','Port macro','text:','alerting',100,'macros',10,'0','0'),(417,'alert,macros,rule,port_usage_perc','((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100','((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100','single-array','Port macro','text:','alerting',100,'macros',10,'0','0'),(418,'alert,transports,dummy','false','false','single-array','Transports','radio:false,true','alerting',100,'transports',8,'0','0'),(419,'alert,transports,mail','false','false','single-array','Transports','radio:false,true','alerting',100,'transports',8,'0','0'),(420,'alert,transports,irc','false','false','single-array','Transports','radio:false,true','alerting',100,'transports',8,'0','0'),(421,'alert,globals','false','false','single-array','Issue alerts to global-read users','radio:false,true','alerting',100,'global',5,'0','0'),(422,'alert,admins','true','false','single-array','Issue alerts to admins','radio:false,true','alerting',100,'global',5,'0','0'),(423,'alert,default_only','true','false','single-array','Alert settings','radio:false,true','alerting',100,'global',5,'0','0'),(424,'alert,default_mail','','','single-array','Alert settings','text:','alerting',100,'global',5,'0','0'),(425,'alert,transports,pagerduty','false','false','single-array','Pagerduty transport','','alerting',100,'transports',8,'0','0'),(426,'alert,pagerduty,account','false','false','single-array','Pagerduty account name','','alerting',100,'transports',8,'0','0'),(427,'alert,pagerduty,service','false','false','single-array','Pagerduty service name','','alerting',100,'transports',8,'0','0'); +DROP TABLE IF EXISTS `config`; +CREATE TABLE `config` ( `config_id` int(11) NOT NULL AUTO_INCREMENT, `config_name` varchar(255) NOT NULL, `config_value` varchar(512) NOT NULL, `config_default` varchar(512) NOT NULL, `config_descr` varchar(100) NOT NULL, `config_group` varchar(50) NOT NULL, `config_group_order` int(11) NOT NULL, `config_sub_group` varchar(50) NOT NULL, `config_sub_group_order` int(11) NOT NULL, `config_hidden` enum('0','1') NOT NULL DEFAULT '0', `config_disabled` enum('0','1') NOT NULL DEFAULT '0', PRIMARY KEY (`config_id`)) ENGINE=InnoDB AUTO_INCREMENT=720 DEFAULT CHARSET=latin1; +LOCK TABLES `config` WRITE; +INSERT INTO `config` VALUES (441,'alert.macros.rule.now','NOW()','NOW()','Macro currenttime','alerting',0,'macros',0,'1','0'),(442,'alert.macros.rule.past_5m','DATE_SUB(NOW(),INTERVAL 5 MINUTE)','DATE_SUB(NOW(),INTERVAL 5 MINUTE)','Macro past 5 minutes','alerting',0,'macros',0,'1','0'),(443,'alert.macros.rule.past_10m','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','Macro past 10 minutes','alerting',0,'macros',0,'1','0'),(444,'alert.macros.rule.past_15m','DATE_SUB(NOW(),INTERVAL 15 MINUTE)','DATE_SUB(NOW(),INTERVAL 15 MINUTE)','Macro past 15 minutes','alerting',0,'macros',0,'1','0'),(445,'alert.macros.rule.past_30m','DATE_SUB(NOW(),INTERVAL 30 MINUTE)','DATE_SUB(NOW(),INTERVAL 30 MINUTE)','Macro past 30 minutes','alerting',0,'macros',0,'1','0'),(446,'alert.macros.rule.device','(%devices.disabled = 0 && %devices.ignore = 0)','(%devices.disabled = 0 && %devices.ignore = 0)','Devices that aren\'t disabled or ignored','alerting',0,'macros',0,'1','0'),(447,'alert.macros.rule.device_up','(%devices.status = 1 && %macros.device)','(%devices.status = 1 && %macros.device)','Devices that are up','alerting',0,'macros',0,'1','0'),(448,'alert.macros.rule.device_down','(%devices.status = 0 && %macros.device)','(%devices.status = 0 && %macros.device)','Devices that are down','alerting',0,'macros',0,'1','0'),(449,'alert.macros.rule.port','(%ports.deleted = 0 && %ports.ignore = 0 && %ports.disabled = 0)','(%ports.deleted = 0 && %ports.ignore = 0 && %ports.disabled = 0)','Ports that aren\'t disabled, ignored or delete','alerting',0,'macros',0,'1','0'),(450,'alert.macros.rule.port_up','(%ports.ifOperStatus = \"up\" && %ports.ifAdminStatus = \"up\" && %macros.port)','(%ports.ifOperStatus = \"up\" && %ports.ifAdminStatus = \"up\" && %macros.port)','Ports that are up','alerting',0,'macros',0,'1','0'),(451,'alert.admins','true','true','Alert administrators','alerting',0,'general',0,'0','0'),(452,'alert.default_only','true','true','Only alert default mail contact','alerting',0,'general',0,'0','0'),(453,'alert.default_mail','','','The default mail contact','alerting',0,'general',0,'0','0'),(454,'alert.transports.pagerduty','','','Pagerduty transport - put your API key here','alerting',0,'transports',0,'0','0'),(455,'alert.pagerduty.account','','','Pagerduty account name','alerting',0,'transports',0,'0','0'),(456,'alert.pagerduty.service','','','Pagerduty service name','alerting',0,'transports',0,'0','0'),(457,'alert.tolerance_window','5','5','Tolerance window in seconds','alerting',0,'general',0,'0','0'),(458,'email_backend','mail','mail','The backend to use for sending email, can be mail, sendmail or smtp','alerting',0,'general',0,'0','0'),(459,'alert.macros.rule.past_60m','DATE_SUB(NOW(),INTERVAL 60 MINUTE)','DATE_SUB(NOW(),INTERVAL 60 MINUTE)','Macro past 60 minutes','alerting',0,'macros',0,'1','0'),(460,'alert.macros.rule.port_usage_perc','((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100','((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100','Ports using more than X perc','alerting',0,'macros',0,'1','0'),(461,'alert.transports.dummy','false','false','Dummy transport','alerting',0,'transports',0,'0','0'),(462,'alert.transports.mail','true','true','Mail alerting transport','alerting',0,'transports',0,'0','0'),(463,'alert.transports.irc','FALSE','false','IRC alerting transport','alerting',0,'transports',0,'0','0'),(464,'alert.globals','true','TRUE','Alert read only administrators','alerting',0,'general',0,'0','0'),(465,'email_from','NULL','NULL','Email address used for sending emails (from)','alerting',0,'general',0,'0','0'),(466,'email_user','LibreNMS','LibreNMS','Name used as part of the from address','alerting',0,'general',0,'0','0'),(467,'email_sendmail_path','/usr/sbin/sendmail','/usr/sbin/sendmail','Location of sendmail if using this option','alerting',0,'general',0,'0','0'),(468,'email_smtp_host','localhost','localhost','SMTP Host for sending email if using this option','alerting',0,'general',0,'0','0'),(469,'email_smtp_port','25','25','SMTP port setting','alerting',0,'general',0,'0','0'),(470,'email_smtp_timeout','10','10','SMTP timeout setting','alerting',0,'general',0,'0','0'),(471,'email_smtp_secure','','','Enable / disable encryption (use tls or ssl)','alerting',0,'general',0,'0','0'),(472,'email_smtp_auth','false','FALSE','Enable / disable smtp authentication','alerting',0,'general',0,'0','0'),(473,'email_smtp_username','NULL','NULL','SMTP Auth username','alerting',0,'general',0,'0','0'),(474,'email_smtp_password','NULL','NULL','SMTP Auth password','alerting',0,'general',0,'0','0'),(475,'alert.macros.rule.port_down','(%ports.ifOperStatus = \"down\" && %ports.ifAdminStatus != \"down\" && %macros.port)','(%ports.ifOperStatus = \"down\" && %ports.ifAdminStatus != \"down\" && %macros.port)','Ports that are down','alerting',0,'macros',0,'1','0'),(486,'alert.syscontact','true','TRUE','Issue alerts to sysContact','alerting',0,'general',0,'0','0'),(487,'alert.fixed-contacts','true','TRUE','If TRUE any changes to sysContact or users emails will not be honoured whilst alert is active','alerting',0,'general',0,'0','0'),(488,'alert.transports.nagios','','','Nagios compatible via FIFO','alerting',0,'transports',0,'0','0'); +UNLOCK TABLES; From 7e6b51f75c4fe77c8e3dd1f67310a3419a22744f Mon Sep 17 00:00:00 2001 From: laf Date: Thu, 28 May 2015 17:18:05 +0100 Subject: [PATCH 11/12] Added f0os license --- includes/definitions.inc.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index ea8dd65c6..e13cb405a 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -14,6 +14,29 @@ if (!$database_link) $database_db = mysql_select_db($config['db_name'], $database_link); function mergecnf($obj) { +/* Copyright (C) 2014 Daniel Preussker + * 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 . */ + +/** + * Merge config function + * @author f0o + * @copyright 2015 f0o, LibreNMS + * @license GPL + * @package LibreNMS + * @subpackage Config + */ + $pointer = array(); $val = $obj['config_value']; $obj = $obj['config_name']; From 451d0322c15f7cc45a9c252f854ad1439896d5bc Mon Sep 17 00:00:00 2001 From: laf Date: Fri, 29 May 2015 14:26:29 +0100 Subject: [PATCH 12/12] Fixed scrut issues --- html/includes/functions.inc.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index d846d2ce8..d7fe5b323 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -788,6 +788,7 @@ function add_config_item($new_conf_name,$new_conf_value,$new_conf_type,$new_conf function get_config_by_group($group) { $group = array($group); + $items = array(); foreach (dbFetchRows("SELECT * FROM `config` WHERE `config_group` = '?'", array($group)) as $config_item) { $val = $config_item['config_value']; if (filter_var($val,FILTER_VALIDATE_INT)) { @@ -807,6 +808,7 @@ function get_config_by_group($group) { function get_config_like_name($name) { $name = array($name); + $items = array(); foreach (dbFetchRows("SELECT * FROM `config` WHERE `config_name` LIKE '%?%'", array($name)) as $config_item) { $items[$config_item['config_name']] = $config_item; }