diff --git a/app/js/ui/main.js b/app/js/ui/main.js index 406b3620..c387ea50 100644 --- a/app/js/ui/main.js +++ b/app/js/ui/main.js @@ -582,8 +582,13 @@ $(document) .ready(loadWifiStations()); // To auto-close Bootstrap alerts; time is in milliseconds -window.setTimeout(function() { +const alertTimeout = parseInt(getCookie('alert_timeout'), 10); + +if (!isNaN(alertTimeout) && alertTimeout > 0) { + window.setTimeout(function() { $(".alert").fadeTo(500, 0).slideUp(500, function(){ - $(this).remove(); + $(this).remove(); }); -}, 5000); \ No newline at end of file + }, alertTimeout); +} + diff --git a/includes/system.php b/includes/system.php index 6bc73875..912b3750 100755 --- a/includes/system.php +++ b/includes/system.php @@ -12,6 +12,23 @@ function DisplaySystem(&$extraFooterScripts) $dashboard = new \RaspAP\UI\Dashboard; $pluginInstaller = \RaspAP\Plugins\PluginInstaller::getInstance(); + // set defaults + $optAutoclose = true; + $alertTimeout = 5000; + $good_input = true; + $config_port = false; + + // set alert_timeout from cookie if valid + if (isset($_COOKIE['alert_timeout']) && is_numeric($_COOKIE['alert_timeout'])) { + $cookieTimeout = (int) $_COOKIE['alert_timeout']; + + if ($cookieTimeout > 0) { + $alertTimeout = $cookieTimeout; + } else { + // A value of 0 means auto-close is disabled + $optAutoclose = false; + } + } if (isset($_POST['SaveLanguage'])) { if (isset($_POST['locale'])) { $_SESSION['locale'] = $_POST['locale']; @@ -21,7 +38,6 @@ function DisplaySystem(&$extraFooterScripts) if (!RASPI_MONITOR_ENABLED) { if (isset($_POST['SaveServerSettings'])) { - $good_input = true; // Validate server port if (isset($_POST['serverPort'])) { if (strlen($_POST['serverPort']) > 4 || !is_numeric($_POST['serverPort'])) { @@ -32,13 +48,13 @@ function DisplaySystem(&$extraFooterScripts) } } // Validate server bind address - $serverBind = escapeshellarg(''); - if ($_POST['serverBind'] && $_POST['serverBind'] !== null ) { - if (!filter_var($_POST['serverBind'], FILTER_VALIDATE_IP)) { + if (isset($_POST['serverBind']) && $_POST['serverBind'] !== '') { + $inputBind = trim($_POST['serverBind']); + if (!filter_var($inputBind, FILTER_VALIDATE_IP)) { $status->addMessage('Invalid value for bind address', 'danger'); $good_input = false; } else { - $serverBind = escapeshellarg($_POST['serverBind']); + $serverBind = escapeshellarg($inputBind); } } // Validate log limit @@ -58,6 +74,21 @@ function DisplaySystem(&$extraFooterScripts) $status->addMessage($line, 'info'); } } + } elseif (isset($_POST['savethemeSettings'])) { + // Validate alert timout + if (isset($_POST['autoClose'])) { + $alertTimeout = trim($_POST['alertTimeout'] ?? ''); + if (strlen($alertTimeout) > 7 || !is_numeric($alertTimeout)) { + $status->addMessage('Invalid value for alert close timeout', 'danger'); + $good_input = false; + } else { + setcookie('alert_timeout', (int) $alertTimeout); + $status->addMessage(sprintf(_('Changing alert close timeout to %s ms'), $alertTimeout), 'info'); + } + } else { + setcookie('alert_timeout', '', time() - 3600, '/'); + $optAutoclose = false; + } } } @@ -155,7 +186,9 @@ function DisplaySystem(&$extraFooterScripts) "themes", "selectedTheme", "logLimit", - "pluginsTable" + "pluginsTable", + "optAutoclose", + "alertTimeout" )); } diff --git a/locale/en_US/LC_MESSAGES/messages.mo b/locale/en_US/LC_MESSAGES/messages.mo index e2720b14..cb04e00b 100644 Binary files a/locale/en_US/LC_MESSAGES/messages.mo and b/locale/en_US/LC_MESSAGES/messages.mo differ diff --git a/locale/en_US/LC_MESSAGES/messages.po b/locale/en_US/LC_MESSAGES/messages.po index 5986aa27..05ddead4 100644 --- a/locale/en_US/LC_MESSAGES/messages.po +++ b/locale/en_US/LC_MESSAGES/messages.po @@ -58,9 +58,6 @@ msgstr "TOR proxy" msgid "Authentication" msgstr "Authentication" -msgid "Change Theme" -msgstr "Change Theme" - msgid "System" msgstr "System" @@ -1256,6 +1253,15 @@ msgstr "Details" msgid "Installed" msgstr "Installed" +msgid "Alert messages" +msgstr "Alert messages" + +msgid "Automatically close alerts after a specified timeout" +msgstr "Automatically close alerts after a specified timeout" + +msgid "Alert close timeout (milliseconds)" +msgstr "Alert close timeout (milliseconds)" + #: includes/data_usage.php msgid "Data usage" msgstr "Data usage" diff --git a/templates/system/theme.php b/templates/system/theme.php index 483a1764..045bbd8b 100644 --- a/templates/system/theme.php +++ b/templates/system/theme.php @@ -1,19 +1,38 @@
-

-
-
- - -
-
- - -
-
+

-