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']);