diff --git a/contrib/webconsole/torrent-rpc.js b/contrib/webconsole/torrent-rpc.js deleted file mode 100644 index 1faadff2..00000000 --- a/contrib/webconsole/torrent-rpc.js +++ /dev/null @@ -1,105 +0,0 @@ -class TorrentClient { - constructor(host = '127.0.0.1', port = 9191, path = 'mytorrents') { - this.host = host; - this.port = port; - this.path = path; - } - - setConnection(host, port, path) { - this.host = host; - this.port = port; - this.path = path; - } - - getEndpoint() { - return `http://${this.host}:${this.port}${this.path}`; - } - - getStatusString(status) { - switch (status) { - case 4: return 'DOWNLOADING'; - case 6: return 'SEEDING'; - case 0: return 'STOPPED'; - case 2: return 'CHECKING'; - default: return 'QUEUED'; - } - } - - formatBytes(bytesPerSec) { - if (!bytesPerSec) return '0 B/s'; - if (bytesPerSec > 1024 * 1024) { - return (bytesPerSec / (1024 * 1024)).toFixed(2) + ' MB/s'; - } - return (bytesPerSec / 1024).toFixed(2) + ' KB/s'; - } - - async addTorrentByMagnet(magnet) - { - // TODO: check link - const magnetRegex = /^magnet:\?xt=urn:btih:[a-f0-9]{40}(&.+)?$/i; - if(!magnetRegex.test(magnet)) return false; - const res = await fetch(this.getEndpoint(), { - method: "POST", - body: JSON.stringify({ 'method': 'torrent-add', 'arguments': { 'filename': magnet } }), - headers: { 'Content-Type': 'application/json' } - }); - return res.json(); - - } - async addTorrent(b64metainfo) { - const res = await fetch(this.getEndpoint(), { - method: "POST", - body: JSON.stringify({ 'method': 'torrent-add', 'arguments': { 'metainfo': b64metainfo } }), - headers: { 'Content-Type': 'application/json' } - }); - return res.json(); - } - - async removeTorrent(id) { - const res = await fetch(this.getEndpoint(), { - method: "POST", - body: JSON.stringify({ 'method': 'torrent-remove', 'arguments': { 'ids': [id], 'delete-local-data': true } }), - headers: { 'Content-Type': 'application/json' } - }); - return res.json(); - } - - async getTorrents() { - const res = await fetch(this.getEndpoint(), { - method: "POST", - body: JSON.stringify({ - 'method': 'torrent-get', - 'arguments': { "fields": ["id", "name", "status", "rateDownload", "rateUpload", "totalSize", "percentDone", "files", "peers", "trackers", "trackerStats","hashString"] } - }), - headers: { 'Content-Type': 'application/json' } - }); - return res.json(); - } - async stopTorrent(ids = []) { - const res = await fetch(this.getEndpoint(), { - method: "POST", - body: JSON.stringify({ - 'method': 'torrent-stop', - 'arguments': ids.length ? { ids } : {}, - 'tag': 666 - }), - headers: { 'Content-Type': 'application/json' } - }); - return res.json(); -} - -async startTorrent(ids = []) { - const res = await fetch(this.getEndpoint(), { - method: "POST", - body: JSON.stringify({ - 'method': 'torrent-start', - 'arguments': ids.length ? { ids } : {}, - 'tag': 666 - }), - headers: { 'Content-Type': 'application/json' } - }); - return res.json(); -} -} - -//window.tjs = new TorrentClient(); diff --git a/contrib/webconsole/torrent_client.html b/contrib/webconsole/torrent_client.html deleted file mode 100644 index b2e907f0..00000000 --- a/contrib/webconsole/torrent_client.html +++ /dev/null @@ -1,312 +0,0 @@ - -
- Torrent Client -
-
-
- - - - - diff --git a/daemon/HTTPServer.cpp b/daemon/HTTPServer.cpp index 52d10e85..d2dc90a1 100644 --- a/daemon/HTTPServer.cpp +++ b/daemon/HTTPServer.cpp @@ -96,7 +96,6 @@ namespace http { const char HTTP_COMMAND_RELOAD_CSS[] = "reload_css"; const char HTTP_COMMAND_EXPIRELEASE[] = "expirelease"; - const char OPENJS_TORRENT_CLIENT_PAGE[] = "torrent_client_open"; static std::string ConvertTime (uint64_t time) { struct tm caltime; @@ -1267,71 +1266,6 @@ namespace http { #endif } - static void ShowTorrentsPage (std::stringstream& s, std::map& params) - { -#ifndef NO_TORRENTS - 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"; -#else - s << "

Torrents are not supported

\r\n"; -#endif - } - HTTPConnection::HTTPConnection (std::string hostname, std::shared_ptr socket): m_Socket (socket), m_BufferLen (0), expected_host(hostname) { @@ -1521,8 +1455,6 @@ namespace http { ShowSAMSession (s, params["sam_id"]); else if (page == HTTP_PAGE_I2P_TUNNELS) ShowI2PTunnels (s); - else if (page == OPENJS_TORRENT_CLIENT_PAGE) - ShowTorrentsPage (s, params); else if (page == HTTP_PAGE_LEASESETS) ShowLeasesSets(s); else { diff --git a/libi2pd/Config.cpp b/libi2pd/Config.cpp index a7f132fc..c6168305 100644 --- a/libi2pd/Config.cpp +++ b/libi2pd/Config.cpp @@ -121,7 +121,6 @@ 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");