diff --git a/daemon/HTTPServer.cpp b/daemon/HTTPServer.cpp index c66f3eea..c260770a 100644 --- a/daemon/HTTPServer.cpp +++ b/daemon/HTTPServer.cpp @@ -1212,6 +1212,67 @@ namespace http { } } + static void ShowTorrentsPage (std::stringstream& s, std::map& params) + { + bool js; i2p::config::GetOption("http.javascript", js); + if (!js) + { + s << "

Javascript is off

\r\n"; + return; + } + std::string tunnelname = params["tunnelname"]; + auto findTunnelEndpoint = [](const std::string& tunnelname) -> std::pair + { + LogPrint(eLogDebug,"HTTPServer: GetTorrentsRPC"); + for (auto& [port, server] : i2p::client::context.GetTorrentsRPCServers()) + { + if (!server) + { + LogPrint(eLogError,"HTTPServer: GetTorrentsRPCServers return nothing"); + continue; + } + for (const auto& [rpcPath, weakTunnel] : server->GetTunnels()) + { + if (auto tunnel = weakTunnel.lock()) + { + LogPrint(eLogDebug, "HTTPServer: TUNNEL_OPENJS", tunnel->GetName()); + if (tunnel->GetName() == tunnelname) + { + uint16_t rpcPort = server->GetAcceptor().local_endpoint().port(); + return { rpcPort, rpcPath }; + } + } + } + } + return { 0, "" }; + }; + auto [rpcPort, rpcPath] = findTunnelEndpoint(tunnelname); + if (rpcPort && rpcPath.length()) + { + std::string tjs_file = i2p::fs::DataDirPath("webconsole/torrent-rpc.js"); + std::string tclient_file = i2p::fs::DataDirPath("webconsole/torrent_client.html"); + if (i2p::fs::Exists(tjs_file)) + { + std::ifstream f(tjs_file, std::ifstream::binary); + std::stringstream tjsss; + tjsss << f.rdbuf(); + s << "\r\n"; + s << "\r\n"; + } + else + s << "

Not found $datadir/webconsole/torrent-rpc.js

\r\n"; + if (i2p::fs::Exists(tclient_file)) + { + std::ifstream f(tclient_file, std::ifstream::binary); + s << f.rdbuf() << "\r\n"; + } + else + s << "

Not found $datadir/webconsole/torrent_client.html

\r\n"; + } + else + s << "

Not found rpc tunnel " << tunnelname << "

\r\n"; + } + HTTPConnection::HTTPConnection (std::string hostname, std::shared_ptr socket): m_Socket (socket), m_BufferLen (0), expected_host(hostname) { @@ -1402,58 +1463,7 @@ namespace http { else if (page == HTTP_PAGE_I2P_TUNNELS) ShowI2PTunnels (s); else if (page == OPENJS_TORRENT_CLIENT_PAGE) - { - // todo: to an another method with return; - std::string tunnelname = params["tunnelname"]; - auto findTunnelEndpoint = [](const std::string& tunnelname) -> std::pair { - LogPrint(eLogDebug,"GetTorrentsRPC"); - for (auto& [port, server] : i2p::client::context.GetTorrentsRPCServers()) - { - if (!server) { - LogPrint(eLogError,"GetTorrentsRPCServers return nothing"); - continue; - } - for (const auto& [rpcPath, weakTunnel] : server->GetTunnels()) - { - if (auto tunnel = weakTunnel.lock()) - { - LogPrint(eLogDebug, "TUNNEL_OPENJS", tunnel->GetName()); - if (tunnel->GetName() == tunnelname) - { - uint16_t rpcPort = server->GetAcceptor().local_endpoint().port(); - return std::pair(rpcPort, rpcPath); - } - } - } - } - return std::pair(0, ""); - }; - auto [rpcPort, rpcPath] = findTunnelEndpoint(tunnelname); - if (rpcPort && rpcPath.length()) - { - std::string tjs_file = i2p::fs::DataDirPath("webconsole/torrent-rpc.js"); - std::string tclient_file = i2p::fs::DataDirPath("webconsole/torrent_client.html"); - if (i2p::fs::Exists(tjs_file)) { - std::ifstream f(tjs_file, std::ifstream::binary); - std::stringstream tjsss; - tjsss << f.rdbuf(); - s << "\r\n"; - s << "\r\n"; - } - else { - s << "

Not found $datadir/webconsole/torrent-rpc.js

\r\n"; - } - if (i2p::fs::Exists(tclient_file)) { - std::ifstream f(tclient_file, std::ifstream::binary); - s << f.rdbuf() << "\r\n"; - } - else { - s << "

Not found $datadir/webconsole/torrent_client.html

\r\n"; - } - } else { - s << "

Not found rpc tunnel " << tunnelname << "

\r\n"; - } - } + ShowTorrentsPage (s, params); else if (page == HTTP_PAGE_LEASESETS) ShowLeasesSets(s); else { diff --git a/libi2pd/Config.cpp b/libi2pd/Config.cpp index e7e58321..7ee29aa2 100644 --- a/libi2pd/Config.cpp +++ b/libi2pd/Config.cpp @@ -121,6 +121,7 @@ namespace config { ("http.lang", value()->default_value("english"), "WebUI language (default: english )") ("http.showTotalTCSR", value()->default_value(false), "Show additional value with total TCSR since router's start (default: false)") ("http.theme", value()->default_value("light"), "Theme for http web console") + ("http.javascript", value()->default_value(true), "Allow pages with javascript") ; options_description httpproxy("HTTP Proxy options");