diff --git a/src/output/output_http.cpp b/src/output/output_http.cpp index 11eed5ee..a0fd37a6 100644 --- a/src/output/output_http.cpp +++ b/src/output/output_http.cpp @@ -309,15 +309,13 @@ namespace Mist { DTSC::Scan prots = rProto.getScan(); unsigned int prots_ctr = prots.getSize(); - //find connector in config - for (unsigned int i=0; i < prots_ctr; ++i){ - if (prots.getIndice(i).getMember("connector").asString() == connector) { - id = i; - break; //pick the first protocol in the list that matches the connector + if (connector == "HTTP" || connector == "HTTP.exe"){ + //restore from values in the environment, regardless of configged settings + if (getenv("MIST_HTTP_pubaddr")){ + p["pubaddr"] = getenv("MIST_HTTP_pubaddr"); } - } - if (id == -1) { - connector = connector + ".exe"; + }else{ + //find connector in config for (unsigned int i=0; i < prots_ctr; ++i){ if (prots.getIndice(i).getMember("connector").asString() == connector) { id = i; @@ -325,13 +323,22 @@ namespace Mist { } } if (id == -1) { - connector = connector.substr(0, connector.size() - 4); - ERROR_MSG("No connector found for: %s", connector.c_str()); - return; + connector = connector + ".exe"; + for (unsigned int i=0; i < prots_ctr; ++i){ + if (prots.getIndice(i).getMember("connector").asString() == connector) { + id = i; + break; //pick the first protocol in the list that matches the connector + } + } + if (id == -1) { + connector = connector.substr(0, connector.size() - 4); + ERROR_MSG("No connector found for: %s", connector.c_str()); + return; + } } + //read options from found connector + p = prots.getIndice(id).asJSON(); } - //read options from found connector - p = prots.getIndice(id).asJSON(); HIGH_MSG("Connector found: %s", connector.c_str()); Util::DTSCShmReader rCapa(SHM_CAPA); diff --git a/src/output/output_http_internal.cpp b/src/output/output_http_internal.cpp index d09df3ab..2dcc0ef4 100644 --- a/src/output/output_http_internal.cpp +++ b/src/output/output_http_internal.cpp @@ -45,6 +45,9 @@ namespace Mist { myConn.open(STDOUT_FILENO, STDIN_FILENO); myConn.setHost(host); } + if (config->getString("pubaddr").size()){ + setenv("MIST_HTTP_pubaddr", config->getString("pubaddr").c_str(), 1); + } if (config->getOption("wrappers",true).size() == 0 || config->getString("wrappers") == ""){ JSON::Value & wrappers = config->getOption("wrappers",true); wrappers.shrink(0); @@ -142,6 +145,12 @@ namespace Mist { capa["optional"]["certbot"]["option"] = "--certbot"; capa["optional"]["certbot"]["short"] = "C"; cfg->addConnectorOptions(8080, capa); + cfg->addOption("pubaddr", JSON::fromString("{\"arg\":\"string\", \"default\":\"\", \"short\":\"A\",\"long\":\"public-address\",\"help\":\"Full public address this output is available as.\"}")); + capa["optional"]["pubaddr"]["name"] = "Public address"; + capa["optional"]["pubaddr"]["help"] = "Full public address this output is available as, if being proxied"; + capa["optional"]["pubaddr"]["default"] = ""; + capa["optional"]["pubaddr"]["type"] = "str"; + capa["optional"]["pubaddr"]["option"] = "--public-address"; } /// Sorts the JSON::Value objects that hold source information by preference. @@ -282,6 +291,13 @@ namespace Mist { if (!fullURL.protocol.size()){ fullURL.protocol = getProtocolForPort(fullURL.getPort()); } + if (config->getString("pubaddr") != ""){ + HTTP::URL altURL(config->getString("pubaddr")); + fullURL.protocol = altURL.protocol; + if (altURL.host.size()){fullURL.host = altURL.host;} + fullURL.port = altURL.port; + fullURL.path = altURL.path; + } std::string uAgent = H.GetHeader("User-Agent"); std::string forceType = ""; @@ -438,6 +454,13 @@ namespace Mist { if (outURL.protocol.find(':') != std::string::npos){ outURL.protocol.erase(outURL.protocol.find(':')); } + if (prots.getIndice(i).hasMember("pubaddr") && prots.getIndice(i).getMember("pubaddr").asString().size()){ + HTTP::URL altURL(prots.getIndice(i).getMember("pubaddr").asString()); + outURL.protocol = altURL.protocol; + if (altURL.host.size()){outURL.host = altURL.host;} + outURL.port = altURL.port; + outURL.path = altURL.path; + } //and a URL - then list the URL JSON::Value capa_json = capa.asJSON(); if (capa.getMember("url_rel") || capa.getMember("methods")){ @@ -652,6 +675,13 @@ namespace Mist { if (!fullURL.protocol.size()){ fullURL.protocol = getProtocolForPort(fullURL.getPort()); } + if (config->getString("pubaddr") != ""){ + HTTP::URL altURL(config->getString("pubaddr")); + fullURL.protocol = altURL.protocol; + if (altURL.host.size()){fullURL.host = altURL.host;} + fullURL.port = altURL.port; + fullURL.path = altURL.path; + } std::string response; std::string rURL = H.url; H.Clean(); diff --git a/src/output/output_https.cpp b/src/output/output_https.cpp index 8aa3666e..12ac051f 100644 --- a/src/output/output_https.cpp +++ b/src/output/output_https.cpp @@ -41,6 +41,12 @@ namespace Mist{ capa["optional"]["wrappers"]["option"] = "--wrappers"; capa["optional"]["wrappers"]["short"] = "w"; cfg->addConnectorOptions(4433, capa); + cfg->addOption("pubaddr", JSON::fromString("{\"arg\":\"string\", \"default\":\"\", \"short\":\"A\",\"long\":\"public-address\",\"help\":\"Full public address this output is available as.\"}")); + capa["optional"]["pubaddr"]["name"] = "Public address"; + capa["optional"]["pubaddr"]["help"] = "Full public address this output is available as, if being proxied"; + capa["optional"]["pubaddr"]["default"] = ""; + capa["optional"]["pubaddr"]["type"] = "str"; + capa["optional"]["pubaddr"]["option"] = "--public-address"; config = cfg; } @@ -96,6 +102,10 @@ namespace Mist{ args.push_back(Util::getMyPath() + "MistOutHTTP"); args.push_back("--ip"); args.push_back(myConn.getHost()); + if (config->getString("pubaddr").size()){ + args.push_back("--public-address"); + args.push_back(config->getString("pubaddr")); + } args.push_back(""); Util::Procs::socketList.insert(fd[0]); pid_t http_proc = Util::Procs::StartPiped(args, &(fd[1]), &(fd[1]), &fderr);