mirror of
https://github.com/pfsense/pfsense.git
synced 2025-10-26 11:38:35 +00:00
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 2b7d052081)
This commit is contained in:
parent
21915c632c
commit
be59d667c9
@ -1551,15 +1551,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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'], ',');
|
||||
|
||||
|
||||
@ -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";
|
||||
}
|
||||
|
||||
@ -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">
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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 = "";
|
||||
}
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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) {
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user