From 3abdc3134b6d7ed64d98044cdd570ab389274062 Mon Sep 17 00:00:00 2001 From: Hanabishi <13597663+HanabishiRecca@users.noreply.github.com> Date: Sat, 29 Mar 2025 17:32:22 +0500 Subject: [PATCH] WebUI: Disable alternative UI in case of the index page being inaccessible Initial failed access shows an error as before, but on the next reload it falls back to the default WebUI. PR #22399. Closes #18401. --- src/webui/webapplication.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index 94c7b3ca3..1b83b9915 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -74,6 +74,7 @@ const QString DEFAULT_SESSION_COOKIE_NAME = u"SID"_s; const QString WWW_FOLDER = u":/www"_s; const QString PUBLIC_FOLDER = u"/public"_s; const QString PRIVATE_FOLDER = u"/private"_s; +const QString INDEX_HTML = u"/index.html"_s; namespace { @@ -194,7 +195,7 @@ void WebApplication::sendWebUIFile() const QString path = (request().path != u"/") ? request().path - : u"/index.html"_s; + : INDEX_HTML; Path localPath = m_rootFolder / Path(session() ? PRIVATE_FOLDER : PUBLIC_FOLDER) @@ -208,7 +209,17 @@ void WebApplication::sendWebUIFile() if (m_isAltUIUsed) { if (!Utils::Fs::isRegularFile(localPath)) + { +#ifdef DISABLE_GUI + if (path == INDEX_HTML) + { + auto *preferences = Preferences::instance(); + preferences->setAltWebUIEnabled(false); + preferences->apply(); + } +#endif throw InternalServerErrorHTTPError(tr("Unacceptable file type, only regular file is allowed.")); + } const QString rootFolder = m_rootFolder.data(); @@ -216,7 +227,17 @@ void WebApplication::sendWebUIFile() while (fileInfo.path() != rootFolder) { if (fileInfo.isSymLink()) + { +#ifdef DISABLE_GUI + if (path == INDEX_HTML) + { + auto *preferences = Preferences::instance(); + preferences->setAltWebUIEnabled(false); + preferences->apply(); + } +#endif throw InternalServerErrorHTTPError(tr("Symlinks inside alternative UI folder are forbidden.")); + } fileInfo.setFile(fileInfo.path()); }