From 0ccbc7a6b1b97b74bf6b6c0dddeb464fc4e7180f Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 25 May 2015 18:05:11 +0100 Subject: [PATCH] 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 2a86aa0550..3bb433dddc 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 0cc6811a1c..2092b1084d 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 62b67b5f47..3190c1f85b 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 65245dc739..6897cb6dcd 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 618117efc0..d91259d0c1 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();