From 848bc57f29ca4aa8357617a8470afb063748dd99 Mon Sep 17 00:00:00 2001
From: Andrew Dolgov <noreply@fakecake.org>
Date: Thu, 11 Feb 2021 21:19:57 +0300
Subject: [PATCH] disable themes in safe mode; rework safe mode warning/login
 prompt

---
 classes/dlg.php        |  2 +-
 classes/rpc.php        |  1 +
 include/login_form.php |  7 +++++--
 index.php              |  2 +-
 js/Feeds.js            | 32 ++++++++++++++++++++++++++++++++
 prefs.php              |  2 +-
 6 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/classes/dlg.php b/classes/dlg.php
index fa154d7a4..64f9aca9d 100644
--- a/classes/dlg.php
+++ b/classes/dlg.php
@@ -202,6 +202,6 @@ class Dlg extends Handler_Protected {
 		print "<button dojoType='dijit.form.Button'
 			onclick=\"return dijit.byId('defaultPasswordDlg').hide();\">".
 			__('Close this window')."</button>";
-		print "</footeer>";
+		print "</footer>";
 	}
 }
diff --git a/classes/rpc.php b/classes/rpc.php
index d4fdd1cd0..a6ddf7004 100755
--- a/classes/rpc.php
+++ b/classes/rpc.php
@@ -454,6 +454,7 @@ class RPC extends Handler_Protected {
 			$params[strtolower($param)] = (int) get_pref($param);
 		}
 
+		$params["safe_mode"] = !empty($_SESSION["safe_mode"]);
 		$params["check_for_updates"] = CHECK_FOR_UPDATES;
 		$params["icons_url"] = ICONS_URL;
 		$params["cookie_lifetime"] = SESSION_COOKIE_LIFETIME;
diff --git a/include/login_form.php b/include/login_form.php
index 0e8f8389e..f3f5d448e 100755
--- a/include/login_form.php
+++ b/include/login_form.php
@@ -153,11 +153,14 @@
 			<fieldset class="narrow">
 				<label> </label>
 
-				<label ><input dojoType="dijit.form.CheckBox" name="safe_mode" id="safe_mode"
+				<label id="safe_mode_label"><input dojoType="dijit.form.CheckBox" name="safe_mode" id="safe_mode"
 					  type="checkbox">
-					<?php echo __("Safe mode (no plugins)") ?></label>
+					<?php echo __("Safe mode") ?></label>
 			</fieldset>
 
+			<div dojoType="dijit.Tooltip" connectId="safe_mode_label" position="below" style="display:none">
+				<?php echo __("Uses default theme and prevents all plugins from loading."); ?>
+			</div>
 			<?php if (SESSION_COOKIE_LIFETIME > 0) { ?>
 
 				<fieldset class="narrow">
diff --git a/index.php b/index.php
index ead02f2c4..93b3da71e 100644
--- a/index.php
+++ b/index.php
@@ -39,7 +39,7 @@
 	<title>Tiny Tiny RSS</title>
     <meta name="viewport" content="initial-scale=1,width=device-width" />
 
-	<?php if ($_SESSION["uid"] && !isset($_REQUEST["ignore-theme"])) {
+	<?php if ($_SESSION["uid"] && empty($_SESSION["safe_mode"])) {
 		$theme = get_pref("USER_CSS_THEME", false, false);
 		if ($theme && theme_exists("$theme")) {
 			echo stylesheet_tag(get_theme_path($theme), 'theme_css');
diff --git a/js/Feeds.js b/js/Feeds.js
index ccb982cb3..64e932ca2 100644
--- a/js/Feeds.js
+++ b/js/Feeds.js
@@ -247,6 +247,38 @@ const	Feeds = {
 			});
 		}
 
+		if (dijit.byId("safeModeDlg"))
+				dijit.byId("safeModeDlg").destroyRecursive();
+
+		if (App.getInitParam("safe_mode")) {
+			const dialog = new dijit.Dialog({
+				title: __("Safe mode"),
+				content: `
+					<div class='alert alert-info'>
+						${__('Tiny Tiny RSS is running in safe mode. All themes and plugins are disabled. You will need to log out and back in to disable it.')}
+					</div>
+					<footer class='text-center'>
+						<button dojoType='dijit.form.Button' type='submit'>
+							${__('Close this window')}
+						</button>
+					</footer>
+					`,
+				id: 'safeModeDlg',
+				style: "width: 600px",
+				onCancel: function () {
+					return true;
+				},
+				onExecute: function () {
+					return true;
+				},
+				onClose: function () {
+					return true;
+				}
+			});
+
+			dialog.show();
+		}
+
 		// bw_limit disables timeout() so we request initial counters separately
 		if (App.getInitParam("bw_limit")) {
 			this.requestCounters(true);
diff --git a/prefs.php b/prefs.php
index 07e636a0a..671a81473 100644
--- a/prefs.php
+++ b/prefs.php
@@ -31,7 +31,7 @@
 	<title>Tiny Tiny RSS : <?php echo __("Preferences") ?></title>
     <meta name="viewport" content="initial-scale=1,width=device-width" />
 
-	<?php if ($_SESSION["uid"] && !isset($_REQUEST["ignore-theme"])) {
+	<?php if ($_SESSION["uid"] && empty($_SESSION["safe_mode"])) {
 		$theme = get_pref("USER_CSS_THEME", false, false);
 		if ($theme && theme_exists("$theme")) {
 			echo stylesheet_tag(get_theme_path($theme), 'theme_css');
-- 
GitLab