From 6e7d2c2d4a9ea04b168fb12fd9881cc41fef5c43 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Wed, 14 Sep 2016 14:39:39 +0200 Subject: [PATCH] Removed GeoIP support fully --- src/controller/controller_limits.cpp | 89 --------- src/output/mist_out.cpp | 28 --- src/output/output.cpp | 266 --------------------------- src/output/output.h | 9 - 4 files changed, 392 deletions(-) diff --git a/src/controller/controller_limits.cpp b/src/controller/controller_limits.cpp index 5b380ded..9cf6b4bc 100644 --- a/src/controller/controller_limits.cpp +++ b/src/controller/controller_limits.cpp @@ -210,7 +210,6 @@ namespace Controller{ if (myHostName == "\n"){ return false; } - std::string myCountryName = getCountry(host); bool hasWhitelist = false; bool hostOnWhitelist = false; if (Storage["streams"].isMember(streamName)){ @@ -255,37 +254,6 @@ namespace Controller{ } } } - if ((*limitIt)["name"].asString() == "geo"){ - if ((*limitIt)["value"].asString()[0] == '+'){ - if (myCountryName == ""){ - if ((*limitIt)["type"].asString() == "hard"){ - Log("HLIM", "Host " + host + " with unknown location blacklisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " with unknown location blacklisted for stream " + streamName); - } - } - if (!onList(myCountryName, (*limitIt)["value"].asString().substr(1))){ - if ((*limitIt)["type"].asString() == "hard"){ - Log("HLIM", "Host " + host + " with location " + myCountryName + " not whitelisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " with location " + myCountryName + " not whitelisted for stream " + streamName); - } - } - }else{ - if ((*limitIt)["val"].asString()[0] == '-'){ - if (onList(myCountryName, (*limitIt)["value"].asString().substr(1))){ - if ((*limitIt)["type"].asString() == "hard"){ - Log("HLIM", "Host " + host + " with location " + myCountryName + " blacklisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " with location " + myCountryName + " blacklisted for stream " + streamName); - } - } - } - } - } } } } @@ -330,37 +298,6 @@ namespace Controller{ } } } - if ((*limitIt)["name"].asString() == "geo"){ - if ((*limitIt)["value"].asString()[0] == '+'){ - if (myCountryName == ""){ - if ((*limitIt)["type"].asString() == "hard"){ - Log("HLIM", "Host " + host + " with unknown location blacklisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " with unknown location blacklisted for stream " + streamName); - } - } - if (!onList(myCountryName, (*limitIt)["value"].asString().substr(1))){ - if ((*limitIt)["type"].asString() == "hard"){ - Log("HLIM", "Host " + host + " with location " + myCountryName + " not whitelisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " with location " + myCountryName + " not whitelisted for stream " + streamName); - } - } - }else{ - if ((*limitIt)["value"].asString()[0] == '-'){ - if (onList(myCountryName, (*limitIt)["val"].asString().substr(1))){ - if ((*limitIt)["type"].asString() == "hard"){ - Log("HLIM", "Host " + host + " with location " + myCountryName + " blacklisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " with location " + myCountryName + " blacklisted for stream " + streamName); - } - } - } - } - } } } if (hasWhitelist){ @@ -373,30 +310,4 @@ namespace Controller{ return false; } - std::string getCountry(std::string ip){ - char * code = NULL; - #ifdef GEOIP - GeoIP * geoIP; - geoIP = GeoIP_open(GEOIPV4, GEOIP_STANDARD | GEOIP_CHECK_CACHE); - if (!geoIP){ - std::cerr << "An error occured loading the IPv4 database" << std::endl; - }else{ - code = (char*)GeoIP_country_code_by_addr(geoIP, ip.c_str()); - GeoIP_delete(geoIP); - } - if (!code){ - geoIP = GeoIP_open(GEOIPV6, GEOIP_STANDARD | GEOIP_CHECK_CACHE); - if (!geoIP){ - std::cerr << "An error occured loading the IPv6 database" << std::endl; - }else{ - code = (char*)GeoIP_country_code_by_addr_v6(geoIP, ip.c_str()); - GeoIP_delete(geoIP); - } - } - #endif - if (!code){ - return ""; - } - return code; - } } diff --git a/src/output/mist_out.cpp b/src/output/mist_out.cpp index 9e217552..697bbdfd 100644 --- a/src/output/mist_out.cpp +++ b/src/output/mist_out.cpp @@ -3,13 +3,6 @@ #include #include -/*LTS-START*/ -#ifdef GEOIP -#define GEOIPV4 "GeoIP.dat" -#define GEOIPV6 "GeoIPv6.dat" -#endif -/*LTS-END*/ - int spawnForked(Socket::Connection & S){ mistOut tmp(S); return tmp.run(); @@ -18,21 +11,6 @@ int spawnForked(Socket::Connection & S){ int main(int argc, char * argv[]) { Util::Config conf(argv[0]); mistOut::init(&conf); - /*LTS-START*/ - #ifdef GEOIP - mistOut::geoIP4 = GeoIP_open("/usr/share/GeoIP/" GEOIPV4, GEOIP_STANDARD | GEOIP_CHECK_CACHE); - if (!mistOut::geoIP4){ - mistOut::geoIP4 = GeoIP_open(GEOIPV4, GEOIP_STANDARD | GEOIP_CHECK_CACHE); - } - mistOut::geoIP6 = GeoIP_open("/usr/share/GeoIP/" GEOIPV6, GEOIP_STANDARD | GEOIP_CHECK_CACHE); - if (!mistOut::geoIP6){ - mistOut::geoIP6 = GeoIP_open(GEOIPV6, GEOIP_STANDARD | GEOIP_CHECK_CACHE); - } - if (!mistOut::geoIP4 || !mistOut::geoIP6){ - DEBUG_MSG(DLVL_FAIL, "Could not load all GeoIP databases. %s: %s, %s: %s", GEOIPV4, mistOut::geoIP4?"success":"fail", GEOIPV6, mistOut::geoIP6?"success":"fail"); - } - #endif - /*LTS-END*/ if (conf.parseArgs(argc, argv)) { if (conf.getBool("json")) { std::cout << mistOut::capa.toString() << std::endl; @@ -47,11 +25,5 @@ int main(int argc, char * argv[]) { return tmp.run(); } } - /*LTS-START*/ - #ifdef GEOIP - GeoIP_delete(mistOut::geoIP4); - GeoIP_delete(mistOut::geoIP6); - #endif - /*LTS-END*/ return 0; } diff --git a/src/output/output.cpp b/src/output/output.cpp index 19f10d94..8edc459e 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -684,272 +684,6 @@ namespace Mist { } } - /*LTS-START*/ - bool Output::onList(std::string ip, std::string list){ - if (list == ""){ - return false; - } - std::string entry; - std::string lowerIpv6;//lower-case - std::string upperIpv6;//full-caps - do{ - entry = list.substr(0,list.find(" "));//make sure we have a single entry - lowerIpv6 = "::ffff:" + entry; - upperIpv6 = "::FFFF:" + entry; - if (entry == ip || lowerIpv6 == ip || upperIpv6 == ip){ - return true; - } - long long unsigned int starPos = entry.find("*"); - if (starPos == std::string::npos){ - if (ip == entry){ - return true; - } - }else{ - if (starPos == 0){//beginning of the filter - if (ip.substr(ip.length() - entry.size() - 1) == entry.substr(1)){ - return true; - } - }else{ - if (starPos == entry.size() - 1){//end of the filter - if (ip.find(entry.substr(0, entry.size() - 1)) == 0 ){ - return true; - } - if (ip.find(entry.substr(0, lowerIpv6.size() - 1)) == 0 ){ - return true; - } - if (ip.find(entry.substr(0, upperIpv6.size() - 1)) == 0 ){ - return true; - } - }else{ - Log("CONF","Invalid list entry detected: " + entry); - } - } - } - list.erase(0, entry.size() + 1); - }while (list != ""); - return false; - } - - void Output::Log(std::string type, std::string message){ - /// \todo These logs need to show up in the controller. - /// \todo Additionally, the triggering and untriggering of limits should be recorded in the controller as well. - if (type == "HLIM"){ - DEBUG_MSG(DLVL_HIGH, "HardLimit Triggered: %s", message.c_str()); - } - if (type == "SLIM"){ - DEBUG_MSG(DLVL_HIGH, "SoftLimit Triggered: %s", message.c_str()); - } - } - - std::string Output::hostLookup(std::string ip){ - struct sockaddr_in6 sa; - char hostName[1024]; - char service[20]; - if (inet_pton(AF_INET6, ip.c_str(), &(sa.sin6_addr)) != 1){ - return "\n"; - } - sa.sin6_family = AF_INET6; - sa.sin6_port = 0; - sa.sin6_flowinfo = 0; - sa.sin6_scope_id = 0; - int tmpRet = getnameinfo((struct sockaddr*)&sa, sizeof sa, hostName, sizeof hostName, service, sizeof service, NI_NAMEREQD ); - if ( tmpRet == 0){ - return hostName; - } - return ""; - } - - bool Output::isBlacklisted(std::string host, std::string streamName, int timeConnected){ - return false;//blacklisting temporarily disabled for performance reasons - JSON::Value Storage = JSON::fromFile(Util::getTmpFolder() + "streamlist"); - std::string myHostName = hostLookup(host); - if (myHostName == "\n"){ - return false; - } - std::string myCountryName = getCountry(host); - bool hasWhitelist = false; - bool hostOnWhitelist = false; - if (Storage["streams"].isMember(streamName)){ - if (Storage["streams"][streamName].isMember("limits") && Storage["streams"][streamName]["limits"].size()){ - jsonForEach(Storage["streams"][streamName]["limits"], limitIt){ - if ((*limitIt)["name"].asString() == "host"){ - if ((*limitIt)["value"].asString()[0] == '+'){ - if (!onList(host, (*limitIt)["value"].asString().substr(1))){ - if (myHostName == ""){ - if (timeConnected > Storage["config"]["limit_timeout"].asInt()){ - return true; - } - }else{ - if ( !onList(myHostName, (*limitIt)["value"].asStringRef().substr(1))){ - if ((*limitIt)["type"].asStringRef() == "hard"){ - Log("HLIM", "Host " + host + " not whitelisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " not whitelisted for stream " + streamName); - } - } - } - } - }else{ - if ((*limitIt)["value"].asStringRef().size() > 1 && (*limitIt)["value"].asStringRef()[0] == '-'){ - if (onList(host, (*limitIt)["value"].asStringRef().substr(1))){ - if ((*limitIt)["type"].asStringRef() == "hard"){ - Log("HLIM", "Host " + host + " blacklisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " blacklisted for stream " + streamName); - } - } - if (myHostName != "" && onList(myHostName, (*limitIt)["value"].asString().substr(1))){ - if ((*limitIt)["type"].asStringRef() == "hard"){ - Log("HLIM", "Host " + myHostName + " blacklisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + myHostName + " blacklisted for stream " + streamName); - } - } - } - } - } - if ((*limitIt)["name"].asString() == "geo"){ - if ((*limitIt)["value"].asString()[0] == '+'){ - if (myCountryName == ""){ - if ((*limitIt)["type"].asString() == "hard"){ - Log("HLIM", "Host " + host + " with unknown location blacklisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " with unknown location blacklisted for stream " + streamName); - } - } - if (!onList(myCountryName, (*limitIt)["value"].asString().substr(1))){ - if ((*limitIt)["type"].asString() == "hard"){ - Log("HLIM", "Host " + host + " with location " + myCountryName + " not whitelisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " with location " + myCountryName + " not whitelisted for stream " + streamName); - } - } - }else{ - if ((*limitIt)["value"].asString()[0] == '-'){ - if (onList(myCountryName, (*limitIt)["value"].asString().substr(1))){ - if ((*limitIt)["type"].asString() == "hard"){ - Log("HLIM", "Host " + host + " with location " + myCountryName + " blacklisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " with location " + myCountryName + " blacklisted for stream " + streamName); - } - } - } - } - } - } - } - } - if (Storage["config"]["limits"].size()){ - jsonForEach(Storage["config"]["limits"], limitIt){ - if ((*limitIt)["name"].asString() == "host"){ - if ((*limitIt)["value"].asString()[0] == '+'){ - if (!onList(host, (*limitIt)["value"].asString().substr(1))){ - if (myHostName == ""){ - if (timeConnected > Storage["config"]["limit_timeout"].asInt()){ - return true; - } - }else{ - if ( !onList(myHostName, (*limitIt)["value"].asString().substr(1))){ - if ((*limitIt)["type"].asString() == "hard"){ - Log("HLIM", "Host " + host + " not whitelisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " not whitelisted for stream " + streamName); - } - } - } - } - }else{ - if ((*limitIt)["value"].asString()[0] == '-'){ - if (onList(host, (*limitIt)["value"].asString().substr(1))){ - if ((*limitIt)["type"].asString() == "hard"){ - Log("HLIM", "Host " + host + " blacklisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " blacklisted for stream " + streamName); - } - } - if (myHostName != "" && onList(myHostName, (*limitIt)["value"].asString().substr(1))){ - if ((*limitIt)["type"].asString() == "hard"){ - Log("HLIM", "Host " + myHostName + " blacklisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + myHostName + " blacklisted for stream " + streamName); - } - } - } - } - } - if ((*limitIt)["name"].asString() == "geo"){ - if ((*limitIt)["value"].asString()[0] == '+'){ - if (myCountryName == ""){ - if ((*limitIt)["type"].asString() == "hard"){ - Log("HLIM", "Host " + host + " with unknown location blacklisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " with unknown location blacklisted for stream " + streamName); - } - } - if (!onList(myCountryName, (*limitIt)["value"].asString().substr(1))){ - if ((*limitIt)["type"].asString() == "hard"){ - Log("HLIM", "Host " + host + " with location " + myCountryName + " not whitelisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " with location " + myCountryName + " not whitelisted for stream " + streamName); - } - } - }else{ - if ((*limitIt)["value"].asStringRef().size() > 1 && (*limitIt)["value"].asStringRef()[0] == '-'){ - if (onList(myCountryName, (*limitIt)["value"].asStringRef().substr(1))){ - if ((*limitIt)["type"].asString() == "hard"){ - Log("HLIM", "Host " + host + " with location " + myCountryName + " blacklisted for stream " + streamName); - return true; - }else{ - Log("SLIM", "Host " + host + " with location " + myCountryName + " blacklisted for stream " + streamName); - } - } - } - } - } - } - } - if (hasWhitelist){ - if (hostOnWhitelist || myHostName == ""){ - return false; - }else{ - return true; - } - } - return false; - } - - #ifdef GEOIP - GeoIP * Output::geoIP4 = 0; - GeoIP * Output::geoIP6 = 0; - #endif - std::string Output::getCountry(std::string ip){ - char * code = NULL; - #ifdef GEOIP - if (geoIP4){ - code = (char*)GeoIP_country_code_by_addr(geoIP4, ip.c_str()); - } - if (!code && geoIP6){ - code = (char*)GeoIP_country_code_by_addr_v6(geoIP6, ip.c_str()); - } - #endif - if (!code){ - return ""; - } - return code; - } - /*LTS-END*/ - /// This function decides where in the stream initial playback starts. /// The default implementation calls seek(0) for VoD. /// For live, it seeks to the last sync'ed keyframe of the main track, no closer than MIN_DELAY ms from the end. diff --git a/src/output/output.h b/src/output/output.h index f391c9fd..6b1594e9 100644 --- a/src/output/output.h +++ b/src/output/output.h @@ -9,11 +9,6 @@ #include #include #include -/*LTS-START*/ -#ifdef GEOIP -#include -#endif -/*LTS-END*/ #include "../io.h" namespace Mist { @@ -46,10 +41,6 @@ namespace Mist { static void init(Util::Config * cfg); static JSON::Value capa; /*LTS-START*/ - #ifdef GEOIP - static GeoIP * geoIP4; - static GeoIP * geoIP6; - #endif std::string reqUrl; /*LTS-END*/ //non-virtual generic functions