summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhil Davis <phil.davis@inf.org>2016-08-02 14:49:25 +0930
committerPhil Davis <phil.davis@inf.org>2016-08-02 14:49:25 +0930
commit2b7d0520818248920ec88514fde2c9b86c2a70af (patch)
tree3ea8d6abb23ddbba4820a1f2f9a1ecd85a3a747e /src
parent236e6a54e9a93284ca170b68aa1188dfaa195c3d (diff)
downloadpfsense-2b7d0520818248920ec88514fde2c9b86c2a70af.zip
pfsense-2b7d0520818248920ec88514fde2c9b86c2a70af.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.
Diffstat (limited to 'src')
-rw-r--r--src/etc/inc/auth.inc13
-rw-r--r--src/usr/local/www/index.php4
-rw-r--r--src/usr/local/www/widgets/widgets/gateways.widget.php18
-rw-r--r--src/usr/local/www/widgets/widgets/log.widget.php30
-rw-r--r--src/usr/local/www/widgets/widgets/picture.widget.php14
-rw-r--r--src/usr/local/www/widgets/widgets/rss.widget.php32
-rw-r--r--src/usr/local/www/widgets/widgets/services_status.widget.php8
-rw-r--r--src/usr/local/www/widgets/widgets/thermal_sensors.widget.php32
-rw-r--r--src/usr/local/www/widgets/widgets/traffic_graphs.widget.php8
9 files changed, 83 insertions, 76 deletions
diff --git a/src/etc/inc/auth.inc b/src/etc/inc/auth.inc
index 2d83326..eb18765 100644
--- a/src/etc/inc/auth.inc
+++ b/src/etc/inc/auth.inc
@@ -1529,15 +1529,22 @@ function get_user_settings($username) {
return $settings;
}
-function save_widget_settings($username, $settings) {
+function save_widget_settings($username, $settings, $message = "") {
global $config, $userindex;
$user = getUserEntry($username);
+
+ if (strlen($message) > 0) {
+ $msgout = $message;
+ } else {
+ $msgout = gettext("Widget configuration has been changed.");
+ }
+
if (isset($user['customsettings'])) {
$config['system']['user'][$userindex[$username]]['widgets'] = $settings;
- write_config(sprintf(gettext("Widget configuration has been changed for user %s."), $username));
+ write_config($msgout . " " . sprintf(gettext("(User %s)"), $username));
} else {
$config['widgets'] = $settings;
- write_config(gettext("Widget configuration has been changed."));
+ write_config($msgout);
}
}
diff --git a/src/usr/local/www/index.php b/src/usr/local/www/index.php
index 808b1df..90e1187 100644
--- a/src/usr/local/www/index.php
+++ b/src/usr/local/www/index.php
@@ -122,8 +122,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 9c0d923..765f95e 100644
--- a/src/usr/local/www/widgets/widgets/gateways.widget.php
+++ b/src/usr/local/www/widgets/widgets/gateways.widget.php
@@ -38,13 +38,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);
}
@@ -81,8 +81,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 = "";
@@ -145,7 +145,7 @@ if ($_POST) {
<?php
function compose_table_body_contents() {
- global $config;
+ global $user_settings;
$rtnstr = '';
@@ -153,8 +153,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 c40445b..7312f08 100644
--- a/src/usr/local/www/widgets/widgets/log.widget.php
+++ b/src/usr/local/www/widgets/widgets/log.widget.php
@@ -31,9 +31,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();
@@ -48,41 +48,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";
@@ -202,8 +202,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 38c6ea8..6ceff9b 100644
--- a/src/usr/local/www/widgets/widgets/picture.widget.php
+++ b/src/usr/local/www/widgets/widgets/picture.widget.php
@@ -26,12 +26,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;
@@ -52,9 +52,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 32d6a8e..3f67fa2 100644
--- a/src/usr/local/www/widgets/widgets/rss.widget.php
+++ b/src/usr/local/www/widgets/widgets/rss.widget.php
@@ -26,35 +26,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)) {
@@ -69,8 +69,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 100b20a..5da0adc 100644
--- a/src/usr/local/www/widgets/widgets/services_status.widget.php
+++ b/src/usr/local/www/widgets/widgets/services_status.widget.php
@@ -57,12 +57,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");
}
@@ -78,7 +78,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 336aaa9..0930b06 100644
--- a/src/usr/local/www/widgets/widgets/thermal_sensors.widget.php
+++ b/src/usr/local/www/widgets/widgets/thermal_sensors.widget.php
@@ -41,21 +41,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");
}
@@ -86,16 +86,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 c770975..4279c7b 100644
--- a/src/usr/local/www/widgets/widgets/traffic_graphs.widget.php
+++ b/src/usr/local/www/widgets/widgets/traffic_graphs.widget.php
@@ -35,12 +35,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();
@@ -73,7 +73,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);
}
OpenPOWER on IntegriCloud