Пример #1
0
		bool sendCommand(const Poco::Process::Args & extraArguments, std::string & output)
		{
			// Build arguments
			Poco::Process::Args arguments;
			arguments.push_back("-n");
			arguments.push_back("-o"); arguments.push_back("ServerIp=127.0.0.1");
			arguments.push_back("-o"); arguments.push_back("ServerPort=" + Poco::NumberFormatter::format(port_));
			arguments.push_back("-o"); arguments.push_back("OutputMode=loggable");
			for (Poco::Process::Args::const_iterator it = extraArguments.begin(); it != extraArguments.end(); ++it)
			{
				arguments.push_back(*it);
			}
			
			// Run
			Poco::Pipe out, err;
			if (Poco::Process::launch(config().getString("options.nzbgetBin", "/usr/bin/nzbget"), arguments, 0, &out, &err).wait() != 0)
			{
				// Read error
				Poco::PipeInputStream stream(err);
				Poco::StreamCopier::copyToString(stream, output);
				
				return false;
			}
			else
			{
				// Read out
				Poco::PipeInputStream stream(out);
				Poco::StreamCopier::copyToString(stream, output);
				
				return true;
			}
		}
Пример #2
0
	int main(const std::vector<std::string>& args)
	{
		int rc = Poco::Util::Application::EXIT_OK;
		if (_helpRequested || args.empty())
		{
			displayHelp();
		}
		else
		{
			Poco::Timespan connectTimeout = Poco::Timespan(config().getInt("webtunnel.connectTimeout", 30), 0);
			Poco::Timespan remoteTimeout = Poco::Timespan(config().getInt("webtunnel.remoteTimeout", 300), 0);
			Poco::Timespan localTimeout = Poco::Timespan(config().getInt("webtunnel.localTimeout", 7200), 0);

#if defined(WEBTUNNEL_ENABLE_TLS)
			bool acceptUnknownCert = config().getBool("tls.acceptUnknownCertificate", true);
			std::string cipherList = config().getString("tls.ciphers", "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
			bool extendedVerification = config().getBool("tls.extendedCertificateVerification", false);
			std::string caLocation = config().getString("tls.caLocation", "");

			Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> pCertificateHandler;
			if (acceptUnknownCert)
				pCertificateHandler = new Poco::Net::AcceptCertificateHandler(false);
			else
				pCertificateHandler = new Poco::Net::RejectCertificateHandler(false);
			Poco::Net::Context::Ptr pContext = new Poco::Net::Context(Poco::Net::Context::TLSV1_CLIENT_USE, "", "", caLocation, Poco::Net::Context::VERIFY_RELAXED, 5, true, cipherList);
			pContext->enableExtendedCertificateVerification(extendedVerification);
			Poco::Net::SSLManager::instance().initializeClient(0, pCertificateHandler, pContext);
#endif

			if (config().getBool("http.proxy.enable", false))
			{
				logger().information("Proxy enable");
				Poco::Net::HTTPClientSession::ProxyConfig proxyConfig;
				proxyConfig.host = config().getString("http.proxy.host", "");
				proxyConfig.port = static_cast<Poco::UInt16>(config().getInt("http.proxy.port", 80));
				proxyConfig.username = config().getString("http.proxy.username", "");
				proxyConfig.password = config().getString("http.proxy.password", "");
				Poco::Net::HTTPClientSession::setGlobalProxyConfig(proxyConfig);
			}

			promptLogin();

			Poco::URI uri(args[0]);
			Poco::WebTunnel::LocalPortForwarder forwarder(_localPort, _remotePort, uri, new Poco::WebTunnel::DefaultWebSocketFactory(_username, _password, connectTimeout));
			forwarder.setRemoteTimeout(remoteTimeout);
			forwarder.setLocalTimeout(localTimeout);
			
			Poco::UInt16 localPort = forwarder.localPort();
			std::string defaultVNCExecutable;
#if defined(__APPLE__)
			defaultVNCExecutable = "open";
#else
			defaultVNCExecutable = "vncviewer";
#endif
			std::string vncExecutable = config().getString("vncviewer.executable", defaultVNCExecutable);
			Poco::Process::Args vncArgs;
			if (vncExecutable == "open")
			{
				vncArgs.push_back("-W");
				vncArgs.push_back("-n");
				vncArgs.push_back("vnc://localhost:" + Poco::NumberFormatter::format(static_cast<unsigned>(localPort)));
			}
			else
			{
				vncArgs.push_back("localhost:" + Poco::NumberFormatter::format(static_cast<unsigned>(localPort)));
			}
			vncArgs.insert(vncArgs.end(), ++args.begin(), args.end());
			
			logger().debug(Poco::format("Launching VNC client: %s", vncExecutable));
			Poco::ProcessHandle ph = Poco::Process::launch(vncExecutable, vncArgs);
			rc = ph.wait();
			logger().debug(Poco::format("VNC client terminated with exit code %d", rc));
		}
		return rc;
	}