| 1385 | } |
| 1386 | |
| 1387 | void HTTPConnection::HandleCommand (const HTTPReq& req, HTTPRes& res, std::stringstream& s) |
| 1388 | { |
| 1389 | std::map<std::string, std::string> params; |
| 1390 | URL url; |
| 1391 | |
| 1392 | url.parse(req.uri); |
| 1393 | url.parse_query(params); |
| 1394 | |
| 1395 | std::string webroot; i2p::config::GetOption("http.webroot", webroot); |
| 1396 | std::string redirect = std::to_string(COMMAND_REDIRECT_TIMEOUT) + "; url=" + webroot + "?page=commands"; |
| 1397 | std::string token = params["token"]; |
| 1398 | |
| 1399 | if (token.empty () || m_Tokens.find (std::stoi (token)) == m_Tokens.end ()) |
| 1400 | { |
| 1401 | ShowError(s, tr("Invalid token")); |
| 1402 | return; |
| 1403 | } |
| 1404 | |
| 1405 | std::string cmd = params["cmd"]; |
| 1406 | if (cmd == HTTP_COMMAND_RUN_PEER_TEST) |
| 1407 | i2p::transport::transports.PeerTest (); |
| 1408 | else if (cmd == HTTP_COMMAND_RELOAD_TUNNELS_CONFIG) |
| 1409 | i2p::client::context.ReloadConfig (); |
| 1410 | else if (cmd == HTTP_COMMAND_ENABLE_TRANSIT) |
| 1411 | i2p::context.SetAcceptsTunnels (true); |
| 1412 | else if (cmd == HTTP_COMMAND_DISABLE_TRANSIT) |
| 1413 | i2p::context.SetAcceptsTunnels (false); |
| 1414 | else if (cmd == HTTP_COMMAND_SHUTDOWN_START) |
| 1415 | { |
| 1416 | i2p::context.SetAcceptsTunnels (false); |
| 1417 | #if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY)) |
| 1418 | Daemon.gracefulShutdownInterval = 10*60; |
| 1419 | #elif defined(WIN32_APP) |
| 1420 | i2p::win32::GracefulShutdown (); |
| 1421 | #endif |
| 1422 | } |
| 1423 | else if (cmd == HTTP_COMMAND_SHUTDOWN_CANCEL) |
| 1424 | { |
| 1425 | i2p::context.SetAcceptsTunnels (true); |
| 1426 | #if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY)) |
| 1427 | Daemon.gracefulShutdownInterval = 0; |
| 1428 | #elif defined(WIN32_APP) |
| 1429 | i2p::win32::StopGracefulShutdown (); |
| 1430 | #endif |
| 1431 | } |
| 1432 | else if (cmd == HTTP_COMMAND_SHUTDOWN_NOW) |
| 1433 | { |
| 1434 | #ifndef WIN32_APP |
| 1435 | Daemon.running = false; |
| 1436 | #else |
| 1437 | i2p::win32::StopWin32App (); |
| 1438 | #endif |
| 1439 | } |
| 1440 | else if (cmd == HTTP_COMMAND_LOGLEVEL) |
| 1441 | { |
| 1442 | std::string level = params["level"]; |
| 1443 | SetLogLevel (level); |
| 1444 | } |
nothing calls this directly
no test coverage detected