From b7151e972bafb085d972e8597b055292f4508bf3 Mon Sep 17 00:00:00 2001 From: dr|z3d Date: Thu, 12 Aug 2021 11:53:42 +0000 Subject: [PATCH] Console: Conditionally display 'reload css' if file exists; display error if attempted when file has been removed --- daemon/HTTPServer.cpp | 43 ++++++++++++++++++++++++++++--------------- webconsole/style.css | 12 ++++++++++-- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/daemon/HTTPServer.cpp b/daemon/HTTPServer.cpp index a48ce0e0..c3a1b224 100644 --- a/daemon/HTTPServer.cpp +++ b/daemon/HTTPServer.cpp @@ -112,7 +112,7 @@ namespace http { "--textshadow:0 1px 1px rgba(0,0,0.7)}" "html,body{min-height:100%;background:var(--page)}" "html,body,textarea{scrollbar-color:var(--scrollbar)}" -"body{margin:0;padding:0;width:100%;height:100%;display:table;line-height:1.6;position:absolute;top:0;left:0;text-align:center;font:14pt var(--bodyfont);color:var(--ink);background:radial-gradient(circle at center,rgba(48,0,48,.4),rgba(0,0,0,0)),linear-gradient(to bottom,rgba(0,0,0,.3),rgba(32,0,32,.6),rgba(0,0,0,.3))}" +"body{margin:0;padding:0;width:100%;height:100%;display:table;line-height:1.6;position:absolute;top:0;left:0;text-align:center;font:14pt var(--bodyfont);color:var(--ink);background:radial-gradient(circle at center,rgba(48,0,48,.3),rgba(0,0,0,.05)),linear-gradient(to bottom,rgba(0,0,0,.3),rgba(32,0,32,.6),rgba(0,0,0,.3)), var(--page)}" ".wrapper{margin:0 auto;padding:5px;width:100%;display:table-cell;vertical-align:middle;text-align:center}" ".header{display:inline-block;width:100%;vertical-align:middle;position:relative}" "#shutdownbutton{position:absolute;top:0;right:-10px;display:inline-block;width:40px;height:44px;font-size:0;background:var(--shutdown) no-repeat center center / 24px}" @@ -181,6 +181,7 @@ namespace http { ".listitem:last-child{border-bottom:1px solid var(--button-border)}" ".listitem.out .arrowup,.listitem.in .arrowdown{margin:3px 8px 0 16px;float:left}" ".error,.notify{padding:30px 12px 40px;font-size:110%;color:#fff;box-shadow:var(--highlight),inset 0 0 3px 3px rgba(0,0,0,.6);text-align:center;background:linear-gradient(to bottom,rgba(32,0,32,.5),rgba(4,0,4,.7))}" +".toast + .toast {display: none}" "#warning,#success{margin:-5px 0 10px;width:100%;height:48px;display:block;background:var(--error) no-repeat center top / 44px}" "#success{background:var(--success) no-repeat center top / 40px}" ".thin{width:1%;white-space:nowrap}" @@ -253,6 +254,7 @@ namespace http { "input[type=checkbox] + label::after{content:\"+\";display:inline-block;vertical-align:middle;float:right;margin:-6px 10px 2px 0;font-size:16pt;font-weight:700;color:var(--ink);opacity:.7}" "input[type=checkbox]:checked + label::after{content:\"–\"}" ".slide label:hover{color:var(--link_hover);background:var(--button_hover);opacity:.9}" +".slide label:active::after {transform: scale(.9)}" ".slide table{width:100%}" "@media screen and (max-width: 1000px) {" "body{font-size:13pt!important}" @@ -530,7 +532,7 @@ namespace http { static void ShowError(std::stringstream& s, const std::string& string) { - s << "\r\n" << tr("ERROR") + s << "\r\n" << tr("ERROR") << ": " << string << "\r\n"; } @@ -1171,14 +1173,20 @@ namespace http { s << " " << tr("Force shutdown") << "\r\n"; + } +/* only one option? displayed in the header } else { s << " " << tr("Shutdown") << "\r\n"; } +*/ + std::string styleFile = i2p::fs::DataDirPath ("webconsole/style.css"); + if (i2p::fs::Exists(styleFile)) { s << "" << tr("Reload external CSS styles") << "\r\n"; + } s << "\r\n
" << tr("Note: Configuration changes made here persist for the duration of the router session and will not be saved to your config file.") @@ -1833,18 +1841,18 @@ namespace http { if (dest) { if(dest->DeleteStream (streamID)) - s << "" << tr("SUCCESS") << ": " + s << "" << tr("SUCCESS") << ": " << tr("Stream closed") << "\r\n"; else - s << "" << tr("ERROR") << ": " + s << "" << tr("ERROR") << ": " << tr("Stream not found or already was closed") << "\r\n"; } else - s << "" << tr("ERROR") << ": " + s << "" << tr("ERROR") << ": " << tr("Destination not found") << "\r\n"; } else - s << "" << tr("ERROR") << ": " + s << "" << tr("ERROR") << ": " << tr("StreamID can't be null") << "\r\n"; redirect = "2; url=" + webroot + "?page=local_destination&b32=" + b32; @@ -1857,7 +1865,7 @@ namespace http { if (limit > 0 && limit <= 65535) SetMaxNumTransitTunnels (limit); else { - s << "" << tr("ERROR") << ": " + s << "" << tr("ERROR") << ": " << tr("Transit tunnels count must not exceed 65535") << "\r\n\r\n"; res.add_header("Refresh", redirect.c_str()); return; @@ -1891,7 +1899,7 @@ namespace http { auto len = i2p::data::ByteStreamToBase64 (signature, signatureLen, sig, signatureLen*2); sig[len] = 0; out << "#!sig=" << sig; - s << "" << tr("SUCCESS") + s << "" << tr("SUCCESS") << ":
\r\n
\r\n" << "\r\n
\r\n
\r\n" @@ -1904,15 +1912,15 @@ namespace http { delete[] sig; } else - s << "" << tr("ERROR") << "
: " + s << "" << tr("ERROR") << ": " << tr("Domain can't end with .b32.i2p") << "\r\n
\r\n\r\n"; } else - s << "" << tr("ERROR") << ": " + s << "" << tr("ERROR") << ": " << tr("Domain must end with .i2p") << "\r\n
\r\n\r\n"; } else - s << "" << tr("ERROR") << ": " + s << "" << tr("ERROR") << ": " << tr("No such destination found") << "\r\n
\r\n<\r\n"; // s << "" << tr("Return to destination page") << "\r\n"; @@ -1928,7 +1936,11 @@ namespace http { } else if (cmd == HTTP_COMMAND_RELOAD_CSS) { - LoadExtCSS(); + std::string styleFile = i2p::fs::DataDirPath ("webconsole/style.css"); + if (i2p::fs::Exists(styleFile)) + LoadExtCSS(); + else + ShowError(s, tr("No CSS file found on disk!")); } else { @@ -1937,14 +1949,15 @@ namespace http { return; } - s << ""; + + s << ""; if (cmd == HTTP_COMMAND_SHUTDOWN_NOW) s << tr("Immediate router shutdown initiated"); else if (cmd == HTTP_COMMAND_SHUTDOWN_CANCEL) s << tr("Router shutdown cancelled"); - else if (cmd == HTTP_COMMAND_RELOAD_CSS) + else if (cmd == HTTP_COMMAND_RELOAD_CSS) { s << tr("Console CSS stylesheet reloaded"); - else if (cmd == HTTP_COMMAND_LIMITTRANSIT) + } else if (cmd == HTTP_COMMAND_LIMITTRANSIT) s << tr("Maximum transit tunnels configured for session"); else if (cmd == HTTP_COMMAND_ENABLE_TRANSIT) s << tr("Transit tunnels enabled for session"); diff --git a/webconsole/style.css b/webconsole/style.css index 8dc902e0..1f9568c7 100644 --- a/webconsole/style.css +++ b/webconsole/style.css @@ -91,8 +91,8 @@ body { text-align: center; font: 14pt var(--bodyfont); color: var(--ink); - background: radial-gradient(circle at center, rgba(48,0,48,.4), rgba(0,0,0,0)), - linear-gradient(to bottom, rgba(0,0,0,.3), rgba(32,0,32,.6), rgba(0,0,0,.3)); + background: radial-gradient(circle at center, rgba(48,0,48,.3), rgba(0,0,0,.05)), + linear-gradient(to bottom, rgba(0,0,0,.3), rgba(32,0,32,.6), rgba(0,0,0,.3)), var(--page); } .wrapper { @@ -512,6 +512,10 @@ td:last-child { background: linear-gradient(to bottom, rgba(32,0,32,.5), rgba(4,0,4,.7)); } +.toast + .toast { + display: none; +} + #warning, #success { margin: -5px 0 10px; width: 100%; @@ -965,6 +969,10 @@ input[type=checkbox]:checked + label::after { opacity: .9; } +.slide label:active::after { + transform: scale(.9); +} + .slide table { width: 100%; }