Browse Source

add loglevel checker, fix fields passing to translated string formatter

Signed-off-by: R4SAS <r4sas@i2pmail.org>
pull/1854/head
R4SAS 2 years ago
parent
commit
84d4e074ce
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 586
      contrib/webconsole/style.css
  2. 15
      daemon/HTTPServer.cpp
  3. 2
      daemon/HTTPServer.h
  4. 4
      daemon/HTTPServerResources.h
  5. 2
      libi2pd/Log.cpp
  6. 11
      libi2pd_client/HTTPProxy.cpp

586
contrib/webconsole/style.css

@ -1,293 +1,293 @@
/* /*
* Copyright (c) 2021-2022, The PurpleI2P Project * Copyright (c) 2021-2023, The PurpleI2P Project
* *
* This file is part of Purple i2pd project and licensed under BSD3 * This file is part of Purple i2pd project and licensed under BSD3
* *
* See full license text in LICENSE file at top of project tree * See full license text in LICENSE file at top of project tree
* *
****************************************************************** ******************************************************************
* *
* This is style sheet for webconsole, with @media selectors for adaptive * This is style sheet for webconsole, with @media selectors for adaptive
* view on desktop and mobile devices, respecting preferred user's color * view on desktop and mobile devices, respecting preferred user's color
* scheme used in system/browser. * scheme used in system/browser.
* *
* Minified copy of that style sheet is bundled inside i2pd sources. * Minified copy of that style sheet is bundled inside i2pd sources.
*/ */
:root { :root {
--main-bg-color: #fafafa; --main-bg-color: #fafafa;
--main-text-color: #103456; --main-text-color: #103456;
--main-link-color: #894c84; --main-link-color: #894c84;
--main-link-hover-color: #fafafa; --main-link-hover-color: #fafafa;
} }
@media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {
:root { :root {
--main-bg-color: #242424; --main-bg-color: #242424;
--main-text-color: #17ab5c; --main-text-color: #17ab5c;
--main-link-color: #bf64b7; --main-link-color: #bf64b7;
--main-link-hover-color: #000000; --main-link-hover-color: #000000;
} }
} }
body { body {
font: 100%/1.5em sans-serif; font: 100%/1.5em sans-serif;
margin: 0; margin: 0;
padding: 1.5em; padding: 1.5em;
background: var(--main-bg-color); background: var(--main-bg-color);
color: var(--main-text-color); color: var(--main-text-color);
} }
a, .slide label { a, .slide label {
text-decoration: none; text-decoration: none;
color: var(--main-link-color); color: var(--main-link-color);
} }
a:hover, .slide label:hover, button[type=submit]:hover { a:hover, a.button.selected, .slide label:hover, button[type=submit]:hover {
color: var(--main-link-hover-color); color: var(--main-link-hover-color);
background: var(--main-link-color); background: var(--main-link-color);
} }
a.button { a.button {
appearance: button; appearance: button;
text-decoration: none; text-decoration: none;
padding: 0 5px; padding: 0 5px;
border: 1px solid var(--main-link-color); border: 1px solid var(--main-link-color);
} }
.header { .header {
font-size: 2.5em; font-size: 2.5em;
text-align: center; text-align: center;
margin: 1em 0; margin: 1em 0;
color: var(--main-link-color); color: var(--main-link-color);
} }
.wrapper { .wrapper {
margin: 0 auto; margin: 0 auto;
padding: 1em; padding: 1em;
max-width: 64em; max-width: 64em;
} }
.menu { .menu {
display: block; display: block;
float: left; float: left;
overflow: hidden; overflow: hidden;
padding: 4px; padding: 4px;
max-width: 12em; max-width: 12em;
white-space: nowrap; white-space: nowrap;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.listitem { .listitem {
display: block; display: block;
font-family: monospace; font-family: monospace;
font-size: 1.2em; font-size: 1.2em;
white-space: nowrap; white-space: nowrap;
} }
.tableitem { .tableitem {
font-family: monospace; font-family: monospace;
font-size: 1.2em; font-size: 1.2em;
white-space: nowrap; white-space: nowrap;
} }
.content { .content {
float: left; float: left;
font-size: 1em; font-size: 1em;
margin-left: 2em; margin-left: 2em;
padding: 4px; padding: 4px;
max-width: 50em; max-width: 50em;
overflow: auto; overflow: auto;
} }
.tunnel.established { .tunnel.established {
color: #56B734; color: #56B734;
} }
.tunnel.expiring { .tunnel.expiring {
color: #D3AE3F; color: #D3AE3F;
} }
.tunnel.failed { .tunnel.failed {
color: #D33F3F; color: #D33F3F;
} }
.tunnel.building { .tunnel.building {
color: #434343; color: #434343;
} }
caption { caption {
font-size: 1.5em; font-size: 1.5em;
text-align: center; text-align: center;
color: var(--main-link-color); color: var(--main-link-color);
} }
table { table {
display: table; display: table;
border-collapse: collapse; border-collapse: collapse;
text-align: center; text-align: center;
} }
table.extaddr { table.extaddr {
text-align: left; text-align: left;
} }
table.services { table.services {
width: 100%; width: 100%;
} }
textarea { textarea {
background-color: var(--main-bg-color); background-color: var(--main-bg-color);
color: var(--main-text-color); color: var(--main-text-color);
word-break: break-all; word-break: break-all;
} }
.streamdest { .streamdest {
width: 120px; width: 120px;
max-width: 240px; max-width: 240px;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.slide div.slidecontent, .slide [type="checkbox"] { .slide div.slidecontent, .slide [type="checkbox"] {
display: none; display: none;
} }
.slide [type="checkbox"]:checked ~ div.slidecontent { .slide [type="checkbox"]:checked ~ div.slidecontent {
display: block; display: block;
margin-top: 0; margin-top: 0;
padding: 0; padding: 0;
} }
.disabled { .disabled {
color: #D33F3F; color: #D33F3F;
} }
.enabled { .enabled {
color: #56B734; color: #56B734;
} }
button[type=submit] { button[type=submit] {
background-color: transparent; background-color: transparent;
color: var(--main-link-color); color: var(--main-link-color);
text-decoration: none; text-decoration: none;
padding: 5px; padding: 5px;
border: 1px solid var(--main-link-color); border: 1px solid var(--main-link-color);
font-size: 14px; font-size: 14px;
} }
input, select, select option { input, select, select option {
background-color: var(--main-bg-color); background-color: var(--main-bg-color);
color: var(--main-link-color); color: var(--main-link-color);
padding: 5px; padding: 5px;
border: 1px solid var(--main-link-color); border: 1px solid var(--main-link-color);
font-size: 14px; font-size: 14px;
} }
input:focus, select:focus, select option:focus { input:focus, select:focus, select option:focus {
outline: none; outline: none;
} }
input[type=number]::-webkit-inner-spin-button { input[type=number]::-webkit-inner-spin-button {
-webkit-appearance: none; -webkit-appearance: none;
} }
@media screen and (max-width: 1150px) { /* adaptive style */ @media screen and (max-width: 1150px) { /* adaptive style */
.wrapper { .wrapper {
max-width: 58em; max-width: 58em;
} }
.content { .content {
max-width: 40em; max-width: 40em;
} }
} }
@media screen and (max-width: 980px) { @media screen and (max-width: 980px) {
body { body {
font: 100%/1.2em sans-serif; font: 100%/1.2em sans-serif;
padding: 1.2em 0 0 0; padding: 1.2em 0 0 0;
} }
.menu { .menu {
width: 100%; width: 100%;
max-width: unset; max-width: unset;
display: block; display: block;
float: none; float: none;
position: unset; position: unset;
font-size: 16px; font-size: 16px;
text-align: center; text-align: center;
} }
.menu a, .commands a { .menu a, .commands a {
display: inline-block; display: inline-block;
padding: 4px; padding: 4px;
} }
.content { .content {
float: none; float: none;
margin-left: unset; margin-left: unset;
margin-top: 16px; margin-top: 16px;
max-width: 100%; max-width: 100%;
width: 100%; width: 100%;
text-align: center; text-align: center;
} }
a, .slide label { a, .slide label {
display: block; display: block;
} }
.header { .header {
margin: unset; margin: unset;
font-size: 1.5em; font-size: 1.5em;
} }
small { small {
display: block display: block
} }
a.button { a.button {
appearance: button; appearance: button;
text-decoration: none; text-decoration: none;
margin-top: 10px; margin-top: 10px;
padding: 6px; padding: 6px;
border: 2px solid var(--main-link-color); border: 2px solid var(--main-link-color);
border-radius: 5px; border-radius: 5px;
width: -webkit-fill-available; width: -webkit-fill-available;
} }
input, select { input, select {
width: 35%; width: 35%;
text-align: center; text-align: center;
padding: 5px; padding: 5px;
border: 2px solid var(--main-link-color); border: 2px solid var(--main-link-color);
border-radius: 5px; border-radius: 5px;
font-size: 18px; font-size: 18px;
} }
table.extaddr { table.extaddr {
margin: auto; margin: auto;
text-align: unset; text-align: unset;
} }
textarea { textarea {
width: -webkit-fill-available; width: -webkit-fill-available;
height: auto; height: auto;
padding: 5px; padding: 5px;
border: 2px solid var(--main-link-color); border: 2px solid var(--main-link-color);
border-radius: 5px; border-radius: 5px;
font-size: 12px; font-size: 12px;
} }
button[type=submit] { button[type=submit] {
padding: 5px 15px; padding: 5px 15px;
background: transparent; background: transparent;
border: 2px solid var(--main-link-color); border: 2px solid var(--main-link-color);
cursor: pointer; cursor: pointer;
-webkit-border-radius: 5px; -webkit-border-radius: 5px;
border-radius: 5px; border-radius: 5px;
position: relative; position: relative;
height: 36px; height: 36px;
display: -webkit-inline-box; display: -webkit-inline-box;
margin-top: 10px; margin-top: 10px;
} }
} }

15
daemon/HTTPServer.cpp

@ -198,7 +198,7 @@ namespace http {
if (i2p::context.AcceptsTunnels () || i2p::tunnel::tunnels.CountTransitTunnels()) if (i2p::context.AcceptsTunnels () || i2p::tunnel::tunnels.CountTransitTunnels())
s << " <a href=\"" << webroot << "?page=" << HTTP_PAGE_TRANSIT_TUNNELS << "\">" << tr("Transit Tunnels") << "</a><br>\r\n"; s << " <a href=\"" << webroot << "?page=" << HTTP_PAGE_TRANSIT_TUNNELS << "\">" << tr("Transit Tunnels") << "</a><br>\r\n";
s << s <<
" <a href=\"" << webroot << "?page=" << HTTP_PAGE_TRANSPORTS << "\">" << tr ("Transports") << "</a><br>\r\n" " <a href=\"" << webroot << "?page=" << HTTP_PAGE_TRANSPORTS << "\">" << tr("Transports") << "</a><br>\r\n"
" <a href=\"" << webroot << "?page=" << HTTP_PAGE_I2P_TUNNELS << "\">" << tr("I2P tunnels") << "</a><br>\r\n"; " <a href=\"" << webroot << "?page=" << HTTP_PAGE_I2P_TUNNELS << "\">" << tr("I2P tunnels") << "</a><br>\r\n";
if (i2p::client::context.GetSAMBridge ()) if (i2p::client::context.GetSAMBridge ())
s << " <a href=\"" << webroot << "?page=" << HTTP_PAGE_SAM_SESSIONS << "\">" << tr("SAM sessions") << "</a><br>\r\n"; s << " <a href=\"" << webroot << "?page=" << HTTP_PAGE_SAM_SESSIONS << "\">" << tr("SAM sessions") << "</a><br>\r\n";
@ -736,19 +736,20 @@ namespace http {
s << "<br>\r\n<small>" << tr("<b>Note:</b> any action done here are not persistent and not changes your config files.") << "</small>\r\n<br>\r\n"; s << "<br>\r\n<small>" << tr("<b>Note:</b> any action done here are not persistent and not changes your config files.") << "</small>\r\n<br>\r\n";
auto loglevel = i2p::log::Logger().GetLogLevel();
s << "<b>" << tr("Logging level") << "</b><br>\r\n"; s << "<b>" << tr("Logging level") << "</b><br>\r\n";
s << " <a class=\"button\" href=\"" << webroot << "?cmd=" << HTTP_COMMAND_LOGLEVEL << "&level=none&token=" << token << "\"> none </a> \r\n"; s << " <a class=\"button" << (loglevel == eLogNone ? " selected" : "") << "\" href=\"" << webroot << "?cmd=" << HTTP_COMMAND_LOGLEVEL << "&level=none&token=" << token << "\"> none </a> \r\n";
s << " <a class=\"button\" href=\"" << webroot << "?cmd=" << HTTP_COMMAND_LOGLEVEL << "&level=error&token=" << token << "\"> error </a> \r\n"; s << " <a class=\"button" << (loglevel == eLogError ? " selected" : "") << "\" href=\"" << webroot << "?cmd=" << HTTP_COMMAND_LOGLEVEL << "&level=error&token=" << token << "\"> error </a> \r\n";
s << " <a class=\"button\" href=\"" << webroot << "?cmd=" << HTTP_COMMAND_LOGLEVEL << "&level=warn&token=" << token << "\"> warn </a> \r\n"; s << " <a class=\"button" << (loglevel == eLogWarning ? " selected" : "") << "\" href=\"" << webroot << "?cmd=" << HTTP_COMMAND_LOGLEVEL << "&level=warn&token=" << token << "\"> warn </a> \r\n";
s << " <a class=\"button\" href=\"" << webroot << "?cmd=" << HTTP_COMMAND_LOGLEVEL << "&level=info&token=" << token << "\"> info </a> \r\n"; s << " <a class=\"button" << (loglevel == eLogInfo ? " selected" : "") << "\" href=\"" << webroot << "?cmd=" << HTTP_COMMAND_LOGLEVEL << "&level=info&token=" << token << "\"> info </a> \r\n";
s << " <a class=\"button\" href=\"" << webroot << "?cmd=" << HTTP_COMMAND_LOGLEVEL << "&level=debug&token=" << token << "\"> debug </a><br>\r\n<br>\r\n"; s << " <a class=\"button" << (loglevel == eLogDebug ? " selected" : "") << "\" href=\"" << webroot << "?cmd=" << HTTP_COMMAND_LOGLEVEL << "&level=debug&token=" << token << "\"> debug </a><br>\r\n<br>\r\n";
uint16_t maxTunnels = GetMaxNumTransitTunnels (); uint16_t maxTunnels = GetMaxNumTransitTunnels ();
s << "<b>" << tr("Transit tunnels limit") << "</b><br>\r\n"; s << "<b>" << tr("Transit tunnels limit") << "</b><br>\r\n";
s << "<form method=\"get\" action=\"" << webroot << "\">\r\n"; s << "<form method=\"get\" action=\"" << webroot << "\">\r\n";
s << " <input type=\"hidden\" name=\"cmd\" value=\"" << HTTP_COMMAND_LIMITTRANSIT << "\">\r\n"; s << " <input type=\"hidden\" name=\"cmd\" value=\"" << HTTP_COMMAND_LIMITTRANSIT << "\">\r\n";
s << " <input type=\"hidden\" name=\"token\" value=\"" << token << "\">\r\n"; s << " <input type=\"hidden\" name=\"token\" value=\"" << token << "\">\r\n";
s << " <input type=\"number\" min=\"0\" max=\"65535\" name=\"limit\" value=\"" << maxTunnels << "\">\r\n"; s << " <input type=\"number\" min=\"0\" max=\"" << TRANSIT_TUNNELS_LIMIT <<"\" name=\"limit\" value=\"" << maxTunnels << "\">\r\n";
s << " <button type=\"submit\">" << tr("Change") << "</button>\r\n"; s << " <button type=\"submit\">" << tr("Change") << "</button>\r\n";
s << "</form>\r\n<br>\r\n"; s << "</form>\r\n<br>\r\n";

2
daemon/HTTPServer.h

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2020, The PurpleI2P Project * Copyright (c) 2013-2023, The PurpleI2P Project
* *
* This file is part of Purple i2pd project and licensed under BSD3 * This file is part of Purple i2pd project and licensed under BSD3
* *

4
daemon/HTTPServerResources.h

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2022, The PurpleI2P Project * Copyright (c) 2013-2023, The PurpleI2P Project
* *
* This file is part of Purple i2pd project and licensed under BSD3 * This file is part of Purple i2pd project and licensed under BSD3
* *
@ -38,7 +38,7 @@ namespace http
"@media (prefers-color-scheme: dark) { :root { --main-bg-color: #242424; --main-text-color: #17ab5c; --main-link-color: #bf64b7; --main-link-hover-color: #000000; } }\r\n" "@media (prefers-color-scheme: dark) { :root { --main-bg-color: #242424; --main-text-color: #17ab5c; --main-link-color: #bf64b7; --main-link-hover-color: #000000; } }\r\n"
"body { font: 100%/1.5em sans-serif; margin: 0; padding: 1.5em; background: var(--main-bg-color); color: var(--main-text-color); }\r\n" "body { font: 100%/1.5em sans-serif; margin: 0; padding: 1.5em; background: var(--main-bg-color); color: var(--main-text-color); }\r\n"
"a, .slide label { text-decoration: none; color: var(--main-link-color); }\r\n" "a, .slide label { text-decoration: none; color: var(--main-link-color); }\r\n"
"a:hover, .slide label:hover, button[type=submit]:hover { color: var(--main-link-hover-color); background: var(--main-link-color); }\r\n" "a:hover, a.button.selected, .slide label:hover, button[type=submit]:hover { color: var(--main-link-hover-color); background: var(--main-link-color); }\r\n"
"a.button { appearance: button; text-decoration: none; padding: 0 5px; border: 1px solid var(--main-link-color); }\r\n" "a.button { appearance: button; text-decoration: none; padding: 0 5px; border: 1px solid var(--main-link-color); }\r\n"
".header { font-size: 2.5em; text-align: center; margin: 1em 0; color: var(--main-link-color); }\r\n" ".header { font-size: 2.5em; text-align: center; margin: 1em 0; color: var(--main-link-color); }\r\n"
".wrapper { margin: 0 auto; padding: 1em; max-width: 64em; }\r\n" ".wrapper { margin: 0 auto; padding: 1em; max-width: 64em; }\r\n"

2
libi2pd/Log.cpp

@ -126,7 +126,7 @@ namespace log {
if (level == "none") { m_MinLevel = eLogNone; } if (level == "none") { m_MinLevel = eLogNone; }
else if (level == "error") { m_MinLevel = eLogError; } else if (level == "error") { m_MinLevel = eLogError; }
else if (level == "warn") { m_MinLevel = eLogWarning; } else if (level == "warn") { m_MinLevel = eLogWarning; }
else if (level == "info") { m_MinLevel = eLogInfo; } else if (level == "info") { m_MinLevel = eLogInfo; }
else if (level == "debug") { m_MinLevel = eLogDebug; } else if (level == "debug") { m_MinLevel = eLogDebug; }
else { else {
LogPrint(eLogError, "Log: Unknown loglevel: ", level); LogPrint(eLogError, "Log: Unknown loglevel: ", level);

11
libi2pd_client/HTTPProxy.cpp

@ -347,7 +347,7 @@ namespace proxy {
std::string full_url = m_RequestURL.to_string(); std::string full_url = m_RequestURL.to_string();
std::stringstream ss; std::stringstream ss;
ss << tr("Host %s is <font color=red>already in router's addressbook</font>. <b>Be careful: source of this URL may be harmful!</b> Click here to update record: <a href=\"%s%s%s&update=true\">Continue</a>.", ss << tr("Host %s is <font color=red>already in router's addressbook</font>. <b>Be careful: source of this URL may be harmful!</b> Click here to update record: <a href=\"%s%s%s&update=true\">Continue</a>.",
m_RequestURL.host, full_url, (full_url.find('?') != std::string::npos ? "&i2paddresshelper=" : "?i2paddresshelper="), jump); m_RequestURL.host.c_str(), full_url.c_str(), (full_url.find('?') != std::string::npos ? "&i2paddresshelper=" : "?i2paddresshelper="), jump.c_str());
GenericProxyInfo(tr("Addresshelper forced update rejected"), ss.str()); GenericProxyInfo(tr("Addresshelper forced update rejected"), ss.str());
} }
else // Preventing unauthorized additions to the address book else // Preventing unauthorized additions to the address book
@ -356,7 +356,7 @@ namespace proxy {
std::string full_url = m_RequestURL.to_string(); std::string full_url = m_RequestURL.to_string();
std::stringstream ss; std::stringstream ss;
ss << tr("To add host <b>%s</b> in router's addressbook, click here: <a href=\"%s%s%s\">Continue</a>.", ss << tr("To add host <b>%s</b> in router's addressbook, click here: <a href=\"%s%s%s\">Continue</a>.",
m_RequestURL.host, full_url, (full_url.find('?') != std::string::npos ? "&i2paddresshelper=" : "?i2paddresshelper="), jump); m_RequestURL.host.c_str(), full_url.c_str(), (full_url.find('?') != std::string::npos ? "&i2paddresshelper=" : "?i2paddresshelper="), jump.c_str());
GenericProxyInfo(tr("Addresshelper request"), ss.str()); GenericProxyInfo(tr("Addresshelper request"), ss.str());
} }
return true; /* request processed */ return true; /* request processed */
@ -366,7 +366,8 @@ namespace proxy {
LogPrint (eLogInfo, "HTTPProxy: Added address from addresshelper for ", m_RequestURL.host); LogPrint (eLogInfo, "HTTPProxy: Added address from addresshelper for ", m_RequestURL.host);
std::string full_url = m_RequestURL.to_string(); std::string full_url = m_RequestURL.to_string();
std::stringstream ss; std::stringstream ss;
ss << tr("Host %s added to router's addressbook from helper. Click here to proceed: <a href=\"%s\">Continue</a>.", m_RequestURL.host, full_url); ss << tr("Host %s added to router's addressbook from helper. Click here to proceed: <a href=\"%s\">Continue</a>.",
m_RequestURL.host.c_str(), full_url.c_str());
GenericProxyInfo(tr("Addresshelper adding"), ss.str()); GenericProxyInfo(tr("Addresshelper adding"), ss.str());
return true; /* request processed */ return true; /* request processed */
} }
@ -375,7 +376,7 @@ namespace proxy {
std::string full_url = m_RequestURL.to_string(); std::string full_url = m_RequestURL.to_string();
std::stringstream ss; std::stringstream ss;
ss << tr("Host %s is <font color=red>already in router's addressbook</font>. Click here to update record: <a href=\"%s%s%s&update=true\">Continue</a>.", ss << tr("Host %s is <font color=red>already in router's addressbook</font>. Click here to update record: <a href=\"%s%s%s&update=true\">Continue</a>.",
m_RequestURL.host, full_url, (full_url.find('?') != std::string::npos ? "&i2paddresshelper=" : "?i2paddresshelper="), jump); m_RequestURL.host.c_str(), full_url.c_str(), (full_url.find('?') != std::string::npos ? "&i2paddresshelper=" : "?i2paddresshelper="), jump.c_str());
GenericProxyInfo(tr("Addresshelper update"), ss.str()); GenericProxyInfo(tr("Addresshelper update"), ss.str());
return true; /* request processed */ return true; /* request processed */
} }
@ -452,7 +453,7 @@ namespace proxy {
GenericProxyError(tr("Outproxy failure"), tr("Bad outproxy settings")); GenericProxyError(tr("Outproxy failure"), tr("Bad outproxy settings"));
} else { } else {
LogPrint (eLogWarning, "HTTPProxy: Outproxy failure for ", dest_host, ": no outproxy enabled"); LogPrint (eLogWarning, "HTTPProxy: Outproxy failure for ", dest_host, ": no outproxy enabled");
std::stringstream ss; ss << tr("Host %s is not inside I2P network, but outproxy is not enabled", dest_host); std::stringstream ss; ss << tr("Host %s is not inside I2P network, but outproxy is not enabled", dest_host.c_str());
GenericProxyError(tr("Outproxy failure"), ss.str()); GenericProxyError(tr("Outproxy failure"), ss.str());
} }
return true; return true;

Loading…
Cancel
Save