diff options
author | Phil Davis <phil.davis@inf.org> | 2016-08-02 14:49:25 +0930 |
---|---|---|
committer | Stephen Beaver <sbeaver@netgate.com> | 2016-08-03 07:46:37 -0400 |
commit | be59d667c9da4e294da591cfedd8cede3c2ea913 (patch) | |
tree | 104fbc989c8457b22147749d6d30417b6195d78e /src/usr | |
parent | 21915c632c9d1645003fe3121cb7607d14408e7e (diff) | |
download | pfsense-be59d667c9da4e294da591cfedd8cede3c2ea913.zip pfsense-be59d667c9da4e294da591cfedd8cede3c2ea913.tar.gz |
Save widget settings per user
For users that have "custom settings" enabled, save the "tool" settings
of their widgets on a per-user basis.
User that do not have "custom settings" enabled will continue to use and
save widget settings to/from the system-wide settings.
(cherry picked from commit 2b7d0520818248920ec88514fde2c9b86c2a70af)
Diffstat (limited to 'src/usr')
8 files changed, 73 insertions, 73 deletions
diff --git a/src/usr/local/www/index.php b/src/usr/local/www/index.php index 63682db..d9c2800 100644 --- a/src/usr/local/www/index.php +++ b/src/usr/local/www/index.php @@ -154,8 +154,8 @@ if (!is_array($config['widgets'])) { if ($_POST && $_POST['sequence']) { - // Read in the existing widget settings - $widget_settings = $config['widgets']; + // Start with the user's widget settings. + $widget_settings = $user_settings['widgets']; $widget_settings['sequence'] = rtrim($_POST['sequence'], ','); diff --git a/src/usr/local/www/widgets/widgets/gateways.widget.php b/src/usr/local/www/widgets/widgets/gateways.widget.php index b1ece91..ecd238b 100644 --- a/src/usr/local/www/widgets/widgets/gateways.widget.php +++ b/src/usr/local/www/widgets/widgets/gateways.widget.php @@ -70,13 +70,13 @@ if ($_REQUEST && $_REQUEST['ajax']) { } if ($_POST) { - if (!is_array($config["widgets"]["gateways_widget"])) { - $config["widgets"]["gateways_widget"] = array(); + if (!is_array($user_settings["widgets"]["gateways_widget"])) { + $user_settings["widgets"]["gateways_widget"] = array(); } if (isset($_POST["display_type"])) { - $config["widgets"]["gateways_widget"]["display_type"] = $_POST["display_type"]; + $user_settings["widgets"]["gateways_widget"]["display_type"] = $_POST["display_type"]; } - write_config(gettext("Updated gateways widget settings via dashboard.")); + save_widget_settings($_SESSION['Username'], $user_settings["widgets"], gettext("Updated gateways widget settings via dashboard.")); header("Location: /"); exit(0); } @@ -113,8 +113,8 @@ if ($_POST) { $display_type_gw_ip = "checked"; $display_type_monitor_ip = ""; $display_type_both_ip = ""; - if (isset($config["widgets"]["gateways_widget"]["display_type"])) { - $selected_radio = $config["widgets"]["gateways_widget"]["display_type"]; + if (isset($user_settings["widgets"]["gateways_widget"]["display_type"])) { + $selected_radio = $user_settings["widgets"]["gateways_widget"]["display_type"]; if ($selected_radio == "gw_ip") { $display_type_gw_ip = "checked"; $display_type_monitor_ip = ""; @@ -177,7 +177,7 @@ if ($_POST) { <?php function compose_table_body_contents() { - global $config; + global $user_settings; $rtnstr = ''; @@ -185,8 +185,8 @@ function compose_table_body_contents() { $gateways_status = array(); $gateways_status = return_gateways_status(true); - if (isset($config["widgets"]["gateways_widget"]["display_type"])) { - $display_type = $config["widgets"]["gateways_widget"]["display_type"]; + if (isset($user_settings["widgets"]["gateways_widget"]["display_type"])) { + $display_type = $user_settings["widgets"]["gateways_widget"]["display_type"]; } else { $display_type = "gw_ip"; } diff --git a/src/usr/local/www/widgets/widgets/log.widget.php b/src/usr/local/www/widgets/widgets/log.widget.php index b844f9e..102522d 100644 --- a/src/usr/local/www/widgets/widgets/log.widget.php +++ b/src/usr/local/www/widgets/widgets/log.widget.php @@ -63,9 +63,9 @@ require_once("filter_log.inc"); if ($_POST) { if (is_numeric($_POST['filterlogentries'])) { - $config['widgets']['filterlogentries'] = $_POST['filterlogentries']; + $user_settings['widgets']['filterlogentries'] = $_POST['filterlogentries']; } else { - unset($config['widgets']['filterlogentries']); + unset($user_settings['widgets']['filterlogentries']); } $acts = array(); @@ -80,41 +80,41 @@ if ($_POST) { } if (!empty($acts)) { - $config['widgets']['filterlogentriesacts'] = implode(" ", $acts); + $user_settings['widgets']['filterlogentriesacts'] = implode(" ", $acts); } else { - unset($config['widgets']['filterlogentriesacts']); + unset($user_settings['widgets']['filterlogentriesacts']); } unset($acts); if (($_POST['filterlogentriesinterfaces']) and ($_POST['filterlogentriesinterfaces'] != "All")) { - $config['widgets']['filterlogentriesinterfaces'] = trim($_POST['filterlogentriesinterfaces']); + $user_settings['widgets']['filterlogentriesinterfaces'] = trim($_POST['filterlogentriesinterfaces']); } else { - unset($config['widgets']['filterlogentriesinterfaces']); + unset($user_settings['widgets']['filterlogentriesinterfaces']); } if (is_numeric($_POST['filterlogentriesinterval'])) { - $config['widgets']['filterlogentriesinterval'] = $_POST['filterlogentriesinterval']; + $user_settings['widgets']['filterlogentriesinterval'] = $_POST['filterlogentriesinterval']; } else { - unset($config['widgets']['filterlogentriesinterval']); + unset($user_settings['widgets']['filterlogentriesinterval']); } - write_config(gettext("Saved Filter Log Entries via Dashboard")); + save_widget_settings($_SESSION['Username'], $user_settings["widgets"], gettext("Saved Filter Log Entries via Dashboard.")); Header("Location: /"); exit(0); } -$nentries = isset($config['widgets']['filterlogentries']) ? $config['widgets']['filterlogentries'] : 5; +$nentries = isset($user_settings['widgets']['filterlogentries']) ? $user_settings['widgets']['filterlogentries'] : 5; //set variables for log -$nentriesacts = isset($config['widgets']['filterlogentriesacts']) ? $config['widgets']['filterlogentriesacts'] : 'All'; -$nentriesinterfaces = isset($config['widgets']['filterlogentriesinterfaces']) ? $config['widgets']['filterlogentriesinterfaces'] : 'All'; +$nentriesacts = isset($user_settings['widgets']['filterlogentriesacts']) ? $user_settings['widgets']['filterlogentriesacts'] : 'All'; +$nentriesinterfaces = isset($user_settings['widgets']['filterlogentriesinterfaces']) ? $user_settings['widgets']['filterlogentriesinterfaces'] : 'All'; $filterfieldsarray = array( "act" => $nentriesacts, "interface" => $nentriesinterfaces ); -$nentriesinterval = isset($config['widgets']['filterlogentriesinterval']) ? $config['widgets']['filterlogentriesinterval'] : 60; +$nentriesinterval = isset($user_settings['widgets']['filterlogentriesinterval']) ? $user_settings['widgets']['filterlogentriesinterval'] : 60; $filter_logfile = "{$g['varlog_path']}/filter.log"; @@ -234,8 +234,8 @@ events.push(function(){ <div id="widget-<?=$widgetname?>_panel-footer" class="panel-footer collapse"> <?php -$pconfig['nentries'] = isset($config['widgets']['filterlogentries']) ? $config['widgets']['filterlogentries'] : ''; -$pconfig['nentriesinterval'] = isset($config['widgets']['filterlogentriesinterval']) ? $config['widgets']['filterlogentriesinterval'] : ''; +$pconfig['nentries'] = isset($user_settings['widgets']['filterlogentries']) ? $user_settings['widgets']['filterlogentries'] : ''; +$pconfig['nentriesinterval'] = isset($user_settings['widgets']['filterlogentriesinterval']) ? $user_settings['widgets']['filterlogentriesinterval'] : ''; ?> <form action="/widgets/widgets/log.widget.php" method="post" class="form-horizontal"> diff --git a/src/usr/local/www/widgets/widgets/picture.widget.php b/src/usr/local/www/widgets/widgets/picture.widget.php index d960f6a..a48377b 100644 --- a/src/usr/local/www/widgets/widgets/picture.widget.php +++ b/src/usr/local/www/widgets/widgets/picture.widget.php @@ -58,12 +58,12 @@ require_once("pfsense-utils.inc"); require_once("functions.inc"); if ($_GET['getpic']=="true") { - $pic_type_s = explode(".", $config['widgets']['picturewidget_filename']); + $pic_type_s = explode(".", $user_settings['widgets']['picturewidget_filename']); $pic_type = $pic_type_s[1]; - if ($config['widgets']['picturewidget']) { - $data = base64_decode($config['widgets']['picturewidget']); + if ($user_settings['widgets']['picturewidget']) { + $data = base64_decode($user_settings['widgets']['picturewidget']); } - header("Content-Disposition: inline; filename=\"{$config['widgets']['picturewidget_filename']}\""); + header("Content-Disposition: inline; filename=\"{$user_settings['widgets']['picturewidget_filename']}\""); header("Content-Type: image/{$pic_type}"); header("Content-Length: " . strlen($data)); echo $data; @@ -84,9 +84,9 @@ if ($_POST) { die("Could not read temporary file"); } else { $picname = basename($_FILES['uploadedfile']['name']); - $config['widgets']['picturewidget'] = base64_encode($data); - $config['widgets']['picturewidget_filename'] = $_FILES['pictfile']['name']; - write_config("Picture widget saved via Dashboard."); + $user_settings['widgets']['picturewidget'] = base64_encode($data); + $user_settings['widgets']['picturewidget_filename'] = $_FILES['pictfile']['name']; + save_widget_settings($_SESSION['Username'], $user_settings["widgets"], gettext("Picture widget saved via Dashboard.")); header("Location: /index.php"); exit; } diff --git a/src/usr/local/www/widgets/widgets/rss.widget.php b/src/usr/local/www/widgets/widgets/rss.widget.php index 203ac5b..5c0e553 100644 --- a/src/usr/local/www/widgets/widgets/rss.widget.php +++ b/src/usr/local/www/widgets/widgets/rss.widget.php @@ -58,35 +58,35 @@ require_once("pfsense-utils.inc"); require_once("functions.inc"); if ($_POST['rssfeed']) { - $config['widgets']['rssfeed'] = str_replace("\n", ",", htmlspecialchars($_POST['rssfeed'], ENT_QUOTES | ENT_HTML401)); - $config['widgets']['rssmaxitems'] = str_replace("\n", ",", htmlspecialchars($_POST['rssmaxitems'], ENT_QUOTES | ENT_HTML401)); - $config['widgets']['rsswidgetheight'] = htmlspecialchars($_POST['rsswidgetheight'], ENT_QUOTES | ENT_HTML401); - $config['widgets']['rsswidgettextlength'] = htmlspecialchars($_POST['rsswidgettextlength'], ENT_QUOTES | ENT_HTML401); - write_config(gettext("Saved RSS Widget feed via Dashboard")); + $user_settings['widgets']['rssfeed'] = str_replace("\n", ",", htmlspecialchars($_POST['rssfeed'], ENT_QUOTES | ENT_HTML401)); + $user_settings['widgets']['rssmaxitems'] = str_replace("\n", ",", htmlspecialchars($_POST['rssmaxitems'], ENT_QUOTES | ENT_HTML401)); + $user_settings['widgets']['rsswidgetheight'] = htmlspecialchars($_POST['rsswidgetheight'], ENT_QUOTES | ENT_HTML401); + $user_settings['widgets']['rsswidgettextlength'] = htmlspecialchars($_POST['rsswidgettextlength'], ENT_QUOTES | ENT_HTML401); + save_widget_settings($_SESSION['Username'], $user_settings["widgets"], gettext("Saved RSS Widget feed via Dashboard.")); header("Location: /"); } // Use saved feed and max items -if ($config['widgets']['rssfeed']) { - $rss_feed_s = explode(",", $config['widgets']['rssfeed']); +if ($user_settings['widgets']['rssfeed']) { + $rss_feed_s = explode(",", $user_settings['widgets']['rssfeed']); } -if ($config['widgets']['rssmaxitems']) { - $max_items = $config['widgets']['rssmaxitems']; +if ($user_settings['widgets']['rssmaxitems']) { + $max_items = $user_settings['widgets']['rssmaxitems']; } -if (is_numeric($config['widgets']['rsswidgetheight'])) { - $rsswidgetheight = $config['widgets']['rsswidgetheight']; +if (is_numeric($user_settings['widgets']['rsswidgetheight'])) { + $rsswidgetheight = $user_settings['widgets']['rsswidgetheight']; } -if (is_numeric($config['widgets']['rsswidgettextlength'])) { - $rsswidgettextlength = $config['widgets']['rsswidgettextlength']; +if (is_numeric($user_settings['widgets']['rsswidgettextlength'])) { + $rsswidgettextlength = $user_settings['widgets']['rsswidgettextlength']; } // Set a default feed if none exists if (!$rss_feed_s) { $rss_feed_s = "https://blog.pfsense.org"; - $config['widgets']['rssfeed'] = "https://blog.pfsense.org"; + $user_settings['widgets']['rssfeed'] = "https://blog.pfsense.org"; } if (!$max_items || !is_numeric($max_items)) { @@ -101,8 +101,8 @@ if (!$rsswidgettextlength || !is_numeric($rsswidgettextlength)) { $rsswidgettextlength = 140; // oh twitter, how do we love thee? } -if ($config['widgets']['rssfeed']) { - $textarea_txt = str_replace(",", "\n", $config['widgets']['rssfeed']); +if ($user_settings['widgets']['rssfeed']) { + $textarea_txt = str_replace(",", "\n", $user_settings['widgets']['rssfeed']); } else { $textarea_txt = ""; } diff --git a/src/usr/local/www/widgets/widgets/services_status.widget.php b/src/usr/local/www/widgets/widgets/services_status.widget.php index 17ebdd0..772f833 100644 --- a/src/usr/local/www/widgets/widgets/services_status.widget.php +++ b/src/usr/local/www/widgets/widgets/services_status.widget.php @@ -89,12 +89,12 @@ if ($_POST) { } if (isset($_POST['servicestatusfilter'])) { - $config['widgets']['servicestatusfilter'] = implode(',', array_intersect($validNames, $_POST['servicestatusfilter'])); + $user_settings['widgets']['servicestatusfilter'] = implode(',', array_intersect($validNames, $_POST['servicestatusfilter'])); } else { - $config['widgets']['servicestatusfilter'] = ""; + $user_settings['widgets']['servicestatusfilter'] = ""; } - write_config(gettext("Saved Service Status Filter via Dashboard")); + save_widget_settings($_SESSION['Username'], $user_settings["widgets"], gettext("Saved Service Status Filter via Dashboard.")); header("Location: /index.php"); } @@ -110,7 +110,7 @@ if ($_POST) { </thead> <tbody> <?php -$skipservices = explode(",", $config['widgets']['servicestatusfilter']); +$skipservices = explode(",", $user_settings['widgets']['servicestatusfilter']); if (count($services) > 0) { uasort($services, "service_dispname_compare"); diff --git a/src/usr/local/www/widgets/widgets/thermal_sensors.widget.php b/src/usr/local/www/widgets/widgets/thermal_sensors.widget.php index dede222..c1042aa 100644 --- a/src/usr/local/www/widgets/widgets/thermal_sensors.widget.php +++ b/src/usr/local/www/widgets/widgets/thermal_sensors.widget.php @@ -73,21 +73,21 @@ const DEFAULT_CRITICAL_THRESHOLD = 70; //70 C const MIN_THRESHOLD_VALUE = 1; //deg C const MAX_THRESHOLD_VALUE = 100; //deg C -//NOTE: keys used in $_POST and $config should match text and checkbox inputs' IDs/names in HTML code section +//NOTE: keys used in $_POST and $config and $user_settings should match text and checkbox inputs' IDs/names in HTML code section //========================================================================= //save widget config settings on POST if ($_POST) { - saveThresholdSettings($config, $_POST, "thermal_sensors_widget_zone_warning_threshold", "thermal_sensors_widget_zone_critical_threshold"); - saveThresholdSettings($config, $_POST, "thermal_sensors_widget_core_warning_threshold", "thermal_sensors_widget_core_critical_threshold"); + saveThresholdSettings($user_settings, $_POST, "thermal_sensors_widget_zone_warning_threshold", "thermal_sensors_widget_zone_critical_threshold"); + saveThresholdSettings($user_settings, $_POST, "thermal_sensors_widget_core_warning_threshold", "thermal_sensors_widget_core_critical_threshold"); //handle checkboxes separately - saveGraphDisplaySettings($config, $_POST, "thermal_sensors_widget_show_raw_output"); - saveGraphDisplaySettings($config, $_POST, "thermal_sensors_widget_show_full_sensor_name"); - saveGraphDisplaySettings($config, $_POST, "thermal_sensors_widget_pulsate_warning"); - saveGraphDisplaySettings($config, $_POST, "thermal_sensors_widget_pulsate_critical"); + saveGraphDisplaySettings($user_settings, $_POST, "thermal_sensors_widget_show_raw_output"); + saveGraphDisplaySettings($user_settings, $_POST, "thermal_sensors_widget_show_full_sensor_name"); + saveGraphDisplaySettings($user_settings, $_POST, "thermal_sensors_widget_pulsate_warning"); + saveGraphDisplaySettings($user_settings, $_POST, "thermal_sensors_widget_pulsate_critical"); //write settings to config file - write_config(gettext("Saved thermal_sensors_widget settings via Dashboard.")); + save_widget_settings($_SESSION['Username'], $user_settings["widgets"], gettext("Saved thermal_sensors_widget settings via Dashboard.")); header("Location: ../../index.php"); } @@ -118,16 +118,16 @@ function saveGraphDisplaySettings(&$configArray, &$postArray, $valueKey) { //========================================================================= //get Threshold settings from config (apply defaults if missing) -$thermal_sensors_widget_zoneWarningTempThreshold = getThresholdValueFromConfig($config, "thermal_sensors_widget_zone_warning_threshold", DEFAULT_WARNING_THRESHOLD); -$thermal_sensors_widget_zoneCriticalTempThreshold = getThresholdValueFromConfig($config, "thermal_sensors_widget_zone_critical_threshold", DEFAULT_CRITICAL_THRESHOLD); -$thermal_sensors_widget_coreWarningTempThreshold = getThresholdValueFromConfig($config, "thermal_sensors_widget_core_warning_threshold", DEFAULT_WARNING_THRESHOLD); -$thermal_sensors_widget_coreCriticalTempThreshold = getThresholdValueFromConfig($config, "thermal_sensors_widget_core_critical_threshold", DEFAULT_CRITICAL_THRESHOLD); +$thermal_sensors_widget_zoneWarningTempThreshold = getThresholdValueFromConfig($user_settings, "thermal_sensors_widget_zone_warning_threshold", DEFAULT_WARNING_THRESHOLD); +$thermal_sensors_widget_zoneCriticalTempThreshold = getThresholdValueFromConfig($user_settings, "thermal_sensors_widget_zone_critical_threshold", DEFAULT_CRITICAL_THRESHOLD); +$thermal_sensors_widget_coreWarningTempThreshold = getThresholdValueFromConfig($user_settings, "thermal_sensors_widget_core_warning_threshold", DEFAULT_WARNING_THRESHOLD); +$thermal_sensors_widget_coreCriticalTempThreshold = getThresholdValueFromConfig($user_settings, "thermal_sensors_widget_core_critical_threshold", DEFAULT_CRITICAL_THRESHOLD); //get display settings from config (apply defaults if missing) -$thermal_sensors_widget_showRawOutput = getBoolValueFromConfig($config, "thermal_sensors_widget_show_raw_output", false); -$thermal_sensors_widget_showFullSensorName = getBoolValueFromConfig($config, "thermal_sensors_widget_show_full_sensor_name", false); -$thermal_sensors_widget_pulsateWarning = getBoolValueFromConfig($config, "thermal_sensors_widget_pulsate_warning", true); -$thermal_sensors_widget_pulsateCritical = getBoolValueFromConfig($config, "thermal_sensors_widget_pulsate_critical", true); +$thermal_sensors_widget_showRawOutput = getBoolValueFromConfig($user_settings, "thermal_sensors_widget_show_raw_output", false); +$thermal_sensors_widget_showFullSensorName = getBoolValueFromConfig($user_settings, "thermal_sensors_widget_show_full_sensor_name", false); +$thermal_sensors_widget_pulsateWarning = getBoolValueFromConfig($user_settings, "thermal_sensors_widget_pulsate_warning", true); +$thermal_sensors_widget_pulsateCritical = getBoolValueFromConfig($user_settings, "thermal_sensors_widget_pulsate_critical", true); function getThresholdValueFromConfig(&$configArray, $valueKey, $defaultValue) { diff --git a/src/usr/local/www/widgets/widgets/traffic_graphs.widget.php b/src/usr/local/www/widgets/widgets/traffic_graphs.widget.php index 74864e8..6d5d57e 100644 --- a/src/usr/local/www/widgets/widgets/traffic_graphs.widget.php +++ b/src/usr/local/www/widgets/widgets/traffic_graphs.widget.php @@ -67,12 +67,12 @@ require_once("functions.inc"); $first_time = false; -if (!is_array($config["widgets"]["trafficgraphs"])) { +if (!is_array($user_settings["widgets"]["trafficgraphs"])) { $first_time = true; - $config["widgets"]["trafficgraphs"] = array(); + $user_settings["widgets"]["trafficgraphs"] = array(); } -$a_config = &$config["widgets"]["trafficgraphs"]; +$a_config = &$user_settings["widgets"]["trafficgraphs"]; if (!is_array($a_config["shown"])) { $a_config["shown"] = array(); @@ -105,7 +105,7 @@ if ($_POST) { } } - write_config(gettext("Updated traffic graph settings via dashboard.")); + save_widget_settings($_SESSION['Username'], $user_settings["widgets"], gettext("Updated traffic graph settings via dashboard.")); header("Location: /"); exit(0); } |