From ef3f4aaf1a30fc5ddb8cbf169fecff24d07c8b88 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 28 Feb 2017 14:08:08 +0100 Subject: [PATCH] Unified all push-in-enabled outputs into a single style/function of accepting incoming pushes --- src/input/input_ts.cpp | 2 +- src/output/output.cpp | 28 +++++++++++++++++ src/output/output_dtsc.cpp | 62 +++----------------------------------- src/output/output_rtmp.cpp | 2 +- src/output/output_rtsp.cpp | 60 +++--------------------------------- 5 files changed, 40 insertions(+), 114 deletions(-) diff --git a/src/input/input_ts.cpp b/src/input/input_ts.cpp index 12a9a4d1..db2d278c 100755 --- a/src/input/input_ts.cpp +++ b/src/input/input_ts.cpp @@ -295,7 +295,7 @@ namespace Mist { } void inputTS::stream() { - if (!Util::startInput(streamName, "push://")) {//manually override stream url to start the buffer + if (!Util::startInput(streamName, "push://INTERNAL_ONLY:"+config->getString("input"))) {//manually override stream url to start the buffer FAIL_MSG("Could not start buffer for %s", streamName.c_str()); return; } diff --git a/src/output/output.cpp b/src/output/output.cpp index ae374bb5..2e60c8cc 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -1294,6 +1294,34 @@ namespace Mist{ std::string source = strmSource.substr(7); std::string IP = source.substr(0, source.find('@')); + + /*LTS-START*/ + std::string password; + if (source.find('@') != std::string::npos){ + password = source.substr(source.find('@')+1); + if (password != ""){ + if (password == passwd){ + INFO_MSG("Password accepted - ignoring IP settings."); + IP = ""; + }else{ + INFO_MSG("Password rejected - checking IP."); + if (IP == ""){ + IP = "deny-all.invalid"; + } + } + } + } + + std::string smp = streamName.substr(0, streamName.find_first_of("+ ")); + if(Triggers::shouldTrigger("STREAM_PUSH", smp)){ + std::string payload = streamName+"\n" + getConnectedHost() +"\n"+capa["name"].asStringRef()+"\n"+reqUrl; + if (!Triggers::doTrigger("STREAM_PUSH", payload, smp)){ + FAIL_MSG("Push from %s to %s rejected - STREAM_PUSH trigger denied the push", getConnectedHost().c_str(), streamName.c_str()); + return false; + } + } + /*LTS-END*/ + if (IP != ""){ if (!myConn.isAddress(IP)){ FAIL_MSG("Push from %s to %s rejected - source host not whitelisted", getConnectedHost().c_str(), streamName.c_str()); diff --git a/src/output/output_dtsc.cpp b/src/output/output_dtsc.cpp index f905dff1..3d90da69 100644 --- a/src/output/output_dtsc.cpp +++ b/src/output/output_dtsc.cpp @@ -173,65 +173,13 @@ namespace Mist { void OutDTSC::handlePush(DTSC::Scan & dScan){ streamName = dScan.getMember("stream").asString(); std::string passString = dScan.getMember("password").asString(); - Util::sanitizeName(streamName); - //pull the server configuration - std::string smp = streamName.substr(0,(streamName.find_first_of("+ "))); - IPC::sharedPage serverCfg("!mistConfig", DEFAULT_CONF_PAGE_SIZE); ///< Contains server configuration and capabilities - IPC::semaphore configLock("!mistConfLock", O_CREAT | O_RDWR, ACCESSPERMS, 1); - configLock.wait(); - - DTSC::Scan streamCfg = DTSC::Scan(serverCfg.mapped, serverCfg.len).getMember("streams").getMember(smp); - if (streamCfg){ - if (streamCfg.getMember("source").asString().substr(0, 7) != "push://"){ - DEBUG_MSG(DLVL_FAIL, "Push rejected - stream %s not a push-able stream. (%s != push://*)", streamName.c_str(), streamCfg.getMember("source").asString().c_str()); - myConn.close(); - }else{ - std::string source = streamCfg.getMember("source").asString().substr(7); - std::string IP = source.substr(0, source.find('@')); - /*LTS-START*/ - std::string password; - if (source.find('@') != std::string::npos){ - password = source.substr(source.find('@')+1); - if (password != ""){ - if (passString == Secure::md5(salt + password)){ - DEBUG_MSG(DLVL_DEVEL, "Password accepted - ignoring IP settings."); - IP = ""; - }else{ - DEBUG_MSG(DLVL_DEVEL, "Password rejected - checking IP."); - if (IP == ""){ - IP = "deny-all.invalid"; - } - } - } - } - if(Triggers::shouldTrigger("STREAM_PUSH", smp)){ - std::string payload = streamName+"\n" + myConn.getHost() +"\n"+capa["name"].asStringRef()+"\n"+reqUrl; - if (!Triggers::doTrigger("STREAM_PUSH", payload, smp)){ - DEBUG_MSG(DLVL_FAIL, "Push from %s to %s rejected - STREAM_PUSH trigger denied the push", myConn.getHost().c_str(), streamName.c_str()); - myConn.close(); - configLock.post(); - configLock.close(); - return; - } - } - /*LTS-END*/ - if (IP != ""){ - if (!myConn.isAddress(IP)){ - DEBUG_MSG(DLVL_FAIL, "Push from %s to %s rejected - source host not whitelisted", myConn.getHost().c_str(), streamName.c_str()); - myConn.close(); - } - } - } - }else{ - DEBUG_MSG(DLVL_FAIL, "Push from %s rejected - stream '%s' not configured.", myConn.getHost().c_str(), streamName.c_str()); - myConn.close(); - } - configLock.post(); - configLock.close(); - if (!myConn){return;}//do not initialize if rejected - initialize(); pushing = true; + if (!allowPush(passString)){ + pushing = false; + myConn.close(); + return; + } } diff --git a/src/output/output_rtmp.cpp b/src/output/output_rtmp.cpp index 50b1a162..f160be36 100644 --- a/src/output/output_rtmp.cpp +++ b/src/output/output_rtmp.cpp @@ -779,7 +779,7 @@ namespace Mist { Util::sanitizeName(streamName); isPushing = true; - if (!allowPush("")){ + if (!allowPush(app_name)){ isPushing = false; onFinish(); return; diff --git a/src/output/output_rtsp.cpp b/src/output/output_rtsp.cpp index 39e0b55b..c50e4c68 100644 --- a/src/output/output_rtsp.cpp +++ b/src/output/output_rtsp.cpp @@ -359,62 +359,12 @@ namespace Mist { continue; } if (HTTP_R.method == "ANNOUNCE"){ - std::string smp = streamName.substr(0,(streamName.find_first_of("+ "))); - IPC::sharedPage serverCfg(SHM_CONF, DEFAULT_CONF_PAGE_SIZE); ///< Contains server configuration and capabilities - IPC::semaphore configLock(SEM_CONF, O_CREAT | O_RDWR, ACCESSPERMS, 1); - configLock.wait(); - - DTSC::Scan streamCfg = DTSC::Scan(serverCfg.mapped, serverCfg.len).getMember("streams").getMember(smp); - if (streamCfg){ - if (streamCfg.getMember("source").asString().substr(0, 7) != "push://"){ - FAIL_MSG("Push rejected - stream %s not a push-able stream. (%s != push://*)", streamName.c_str(), streamCfg.getMember("source").asString().c_str()); - onFinish(); - }else{ - std::string source = streamCfg.getMember("source").asString().substr(7); - std::string IP = source.substr(0, source.find('@')); - /*LTS-START*/ - std::string password; - if (source.find('@') != std::string::npos){ - password = source.substr(source.find('@')+1); - if (password != ""){ - if (password == HTTP_R.GetVar("pass")){ - INFO_MSG("Password accepted - ignoring IP settings."); - IP = ""; - }else{ - INFO_MSG("Password rejected - checking IP."); - if (IP == ""){ - IP = "deny-all.invalid"; - } - } - } - } - if(Triggers::shouldTrigger("STREAM_PUSH", smp)){ - std::string payload = streamName+"\n" + getConnectedHost() +"\n"+capa["name"].asStringRef()+"\n"+reqUrl; - if (!Triggers::doTrigger("STREAM_PUSH", payload, smp)){ - FAIL_MSG("Push from %s to %s rejected - STREAM_PUSH trigger denied the push", getConnectedHost().c_str(), streamName.c_str()); - onFinish(); - configLock.post(); - configLock.close(); - return; - } - } - /*LTS-END*/ - if (IP != ""){ - if (!myConn.isAddress(IP)){ - FAIL_MSG("Push from %s to %s rejected - source host not whitelisted", getConnectedHost().c_str(), streamName.c_str()); - onFinish(); - } - } - } - }else{ - FAIL_MSG("Push from %s rejected - stream '%s' not configured.", getConnectedHost().c_str(), streamName.c_str()); - onFinish(); - } - configLock.post(); - configLock.close(); - if (!myConn){return;}//do not initialize if rejected isPushing = true; - initialize(); + if (!allowPush(HTTP_R.GetVar("pass"))){ + isPushing = false; + onFinish(); + return; + } INFO_MSG("Pushing to stream %s", streamName.c_str()); parseSDP(HTTP_R.body); HTTP_S.SendResponse("200", "OK", myConn);