| 93 | } |
| 94 | |
| 95 | std::string executeOpenVPN(const std::string &pars) |
| 96 | { |
| 97 | std::string config, httpProxy, socksProxy; |
| 98 | unsigned int port, httpPort, socksPort; |
| 99 | CmdDnsManager dnsManager; |
| 100 | deserializePars(pars, config, port, httpProxy, httpPort, socksProxy, socksPort, dnsManager); |
| 101 | |
| 102 | std::string script = Utils::getDnsScript(dnsManager); |
| 103 | if (script.empty()) { |
| 104 | spdlog::error("Could not find appropriate DNS manager script"); |
| 105 | return serializeResult(false); |
| 106 | } |
| 107 | |
| 108 | // The proxy address must be an IP literal: the GUI restricts it to one (NetworkingValidation:: |
| 109 | // isIp) and no other path sets it. Validate here too rather than trust the client — an invalid |
| 110 | // value is dropped so it can't reach the OpenVPN config the helper writes as root. The proxy |
| 111 | // lines are appended after OvpnDirectiveWhitelist::filterConfig, so they aren't otherwise |
| 112 | // filtered. isValidIpAddress also rejects whitespace, subsuming the previous whitespace guard. |
| 113 | if (!httpProxy.empty() && !Validation::isValidIpAddress(httpProxy)) { |
| 114 | spdlog::warn("executeOpenVPN: invalid httpProxy, ignoring"); |
| 115 | httpProxy = ""; |
| 116 | } |
| 117 | if (!socksProxy.empty() && !Validation::isValidIpAddress(socksProxy)) { |
| 118 | spdlog::warn("executeOpenVPN: invalid socksProxy, ignoring"); |
| 119 | socksProxy = ""; |
| 120 | } |
| 121 | |
| 122 | if (!OVPN::writeOVPNFile(script, port, config, httpProxy, httpPort, socksProxy, socksPort)) { |
| 123 | spdlog::error("Could not write OpenVPN config"); |
| 124 | return serializeResult(false); |
| 125 | } |
| 126 | |
| 127 | std::string ovpnPath; |
| 128 | if (!Utils::resolveExePath(Utils::getExePath(), WS_PRODUCT_NAME_LOWER "openvpn", ovpnPath)) { |
| 129 | return serializeResult(false); |
| 130 | } |
| 131 | |
| 132 | Spawn::Options opts; |
| 133 | opts.extraEnv = {{"OPENSSL_CONF", "/dev/null"}}; |
| 134 | opts.cwd = WS_LINUX_INSTALL_DIR; |
| 135 | std::vector<std::string> args = {"--mark", "20310", "--config", WS_LINUX_RUN_DIR "/config.ovpn"}; |
| 136 | return serializeResult(Spawn::spawnDetached(ovpnPath, args, opts)); |
| 137 | } |
| 138 | |
| 139 | std::string setOpenVpnDcoMode(const std::string &pars) |
| 140 | { |
nothing calls this directly
no test coverage detected