📄 foptioncontainer.cpp
字号:
return i; // exact match } } return NULL; // and our survey said "UUHH UURRGHH"}bool FOptionContainer::inGreySiteList(String url) { url.removeWhiteSpace(); // just in case of weird browser crap url.toLower(); url.removePTP(); // chop off the ht(f)tp(s):// if (url.contains("/")) { url = url.before("/"); // chop off any path after the domain } char *i; bool isipurl = isIPHostname(url); if (reverse_lookups == 1 && isipurl) { // change that ip into hostname std::deque<String> url2s = ipToHostname(url); String url2; unsigned int j; for (j = 0; j < url2s.size(); j++) { url2 = url2s[j]; while (url2.contains(".")) { i = (*o.lm.l[grey_site_list]).findInList(url2.toCharArray()); if (i != NULL) { return true; // exact match } url2 = url2.after("."); // check for being in hld } } } while (url.contains(".")) { i = (*o.lm.l[grey_site_list]).findInList(url.toCharArray()); if (i != NULL) { return true; // exact match } url = url.after("."); // check for being in higher level domains } if (url.length() > 1) { // allows matching of .tld url = "." + url; i = (*o.lm.l[grey_site_list]).findInList(url.toCharArray()); if (i != NULL) { return true; // exact match } } return false;}char* FOptionContainer::inBannedExtensionList(String url) { url.removeWhiteSpace(); // just in case of weird browser crap url.toLower(); url.hexDecode(); url.removePTP(); // chop off the ht(f)tp(s):// url = url.after("/"); // chop off any domain before the path if (url.length() < 2) { // will never match return NULL; } return (*o.lm.l[banned_extension_list]).findEndsWith(url.toCharArray());}char* FOptionContainer::inBannedURLList(String url) { int fl; char *i; String foundurl; #ifdef DGDEBUG std::cout << "inBannedURLList:" << url << std::endl; #endif url.removeWhiteSpace(); // just in case of weird browser crap url.toLower(); url.removePTP(); // chop off the ht(f)tp(s):// if (url.contains("/")) { String tpath = "/"; tpath += url.after("/"); url = url.before("/"); tpath.hexDecode(); tpath.realPath(); url += tpath; // will resolve ../ and %2e2e/ and // etc } #ifdef DGDEBUG std::cout << "inBannedURLList(processed):" << url << std::endl; #endif if (url.endsWith("/")) { url.chop(); // chop off trailing / if any } if (reverse_lookups == 1 && url.after("/").length() > 0) { String hostname = url.before("/"); if (isIPHostname(hostname)) { std::deque<String> url2s = ipToHostname(hostname); String url2; unsigned int j; for (j = 0; j < url2s.size(); j++) { url2 = url2s[j]; url2 += "/"; url2 += url.after("/"); while (url2.before("/").contains(".")) { i = (*o.lm.l[banned_url_list]).findStartsWith(url2.toCharArray()); if (i != NULL) { foundurl = i; fl = foundurl.length(); if (url2.length() > fl) { unsigned char c = url[fl]; if (c == '/' || c == '?' || c == '&' || c == '=') { return i; // matches /blah/ or /blah/foo // but not /blahfoo } } else { return i; // exact match } } url2 = url2.after("."); // check for being in hld } } } } while (url.before("/").contains(".")) { i = (*o.lm.l[banned_url_list]).findStartsWith(url.toCharArray()); if (i != NULL) { foundurl = i; fl = foundurl.length(); #ifdef DGDEBUG std::cout << "foundurl:" << foundurl << foundurl.length() << std::endl; std::cout << "url:" << url << fl << std::endl; #endif if (url.length() > fl) { if (url[fl] == '/') { return i; // matches /blah/ or /blah/foo but not /blahfoo } } else { return i; // exact match } } url = url.after("."); // check for being in higher level domains } return NULL;}bool FOptionContainer::inGreyURLList(String url) { int fl; char *i; String foundurl; url.removeWhiteSpace(); // just in case of weird browser crap url.toLower(); url.removePTP(); // chop off the ht(f)tp(s):// if (url.contains("/")) { String tpath = "/"; tpath += url.after("/"); url = url.before("/"); tpath.hexDecode(); tpath.realPath(); url += tpath; // will resolve ../ and %2e2e/ and // etc } if (url.endsWith("/")) { url.chop(); // chop off trailing / if any } if (reverse_lookups == 1 && url.after("/").length() > 0) { String hostname = url.before("/"); if (isIPHostname(hostname)) { std::deque<String> url2s = ipToHostname(hostname); String url2; unsigned int j; for (j = 0; j < url2s.size(); j++) { url2 = url2s[j]; url2 += "/"; url2 += url.after("/"); while (url2.before("/").contains(".")) { i = (*o.lm.l[grey_url_list]).findStartsWith(url2.toCharArray()); if (i != NULL) { foundurl = i; fl = foundurl.length(); if (url2.length() > fl) { unsigned char c = url[fl]; if (c == '/' || c == '?' || c == '&' || c == '=') { return true; // matches /blah/ or /blah/foo // but not /blahfoo } } else { return true; // exact match } } url2 = url2.after("."); // check for being in hld } } } } while (url.before("/").contains(".")) { i = (*o.lm.l[grey_url_list]).findStartsWith(url.toCharArray()); if (i != NULL) { foundurl = i; fl = foundurl.length(); #ifdef DGDEBUG std::cout << "foundurl:" << foundurl << foundurl.length() << std::endl; std::cout << "url:" << url << fl << std::endl; #endif if (url.length() > fl) { if (url[fl] == '/') { return true; // matches /blah/ or /blah/foo but not /blahfoo } } else { return true; // exact match } } url = url.after("."); // check for being in higher level domains } return false;}// NOTE TO SELF - MOVE TO LISTCONTAINER TO SOLVE FUDGEint FOptionContainer::inBannedRegExpURLList(String url) { url.removeWhiteSpace(); // just in case of weird browser crap url.toLower(); url.removePTP(); // chop off the ht(f)tp(s):// if (url.contains("/")) { String tpath = "/"; tpath += url.after("/"); url = url.before("/"); tpath.hexDecode(); tpath.realPath(); url += tpath; // will resolve ../ and %2e2e/ and // etc } if (url.endsWith("/")) { url.chop(); // chop off trailing / if any } unsigned int i; for (i = 0; i < banned_regexpurl_list_comp.size(); i++) { banned_regexpurl_list_comp[i].match(url.toCharArray()); if (banned_regexpurl_list_comp[i].matched()) { return i; } } return -1;}std::deque<String> FOptionContainer::ipToHostname(String ip) { std::deque<String> result; struct in_addr address, ** addrptr; if (inet_aton(ip.toCharArray(), &address)) { // convert to in_addr struct hostent* answer; answer = gethostbyaddr((char*) &address, sizeof(address), AF_INET); if (answer) { // sucess in reverse dns result.push_back(String(answer->h_name)); for (addrptr = (struct in_addr **) answer->h_addr_list; *addrptr; addrptr++) { result.push_back(String(inet_ntoa(**addrptr))); } } } return result;}bool FOptionContainer::isIPHostname(String url) { if (!isiphost.match(url.toCharArray())) { return true; } return false;}int FOptionContainer::findoptionI(const char* option) { int res = String(findoptionS(option).c_str()).toInteger(); return res;}std::string FOptionContainer::findoptionS(const char* option) { // findoptionS returns a found option stored in the deque String temp; String temp2; String o = option; for (int i = 0; i < (signed)conffile.size(); i++) { temp = conffile[i].c_str(); temp2 = temp.before("="); while(temp2.endsWith(" ")) { // get rid of tailing spaces before = temp2.chop(); } if (o == temp2) { temp = temp.after("="); while(temp.startsWith(" ")) { // get rid of heading spaces temp.lop(); } if(temp.startsWith("'")) { // inverted commas temp.lop(); } while(temp.endsWith(" ")) { // get rid of tailing spaces temp.chop(); } if(temp.endsWith("'")) { // inverted commas temp.chop(); } return temp.toCharArray(); } } return "";}bool FOptionContainer::realitycheck(String s, int minl, int maxl, char* emessage) { // realitycheck checks a String for certain expected criteria // so we can spot problems in the conf files easier if ((signed)s.length() < minl) { if (!isDaemonised) { std::cerr << emessage << std::endl; // when called we have not detached from // the console so we can write back an // error std::cerr << "Too short or missing." << std::endl; } syslog(LOG_ERR, "%s", emessage); syslog(LOG_ERR, "%s", "Too short or missing."); return false; } if ((signed)s.length() > maxl && maxl > 0) { if (!isDaemonised) { std::cerr << emessage << std::endl; std::cerr << "Too long or broken." << std::endl; } syslog(LOG_ERR, "%s", emessage); syslog(LOG_ERR, "%s", "Too long or broken."); return false; } return true;}bool FOptionContainer::precompileregexps() { if (!pics1.comp("pics-label\"[ \t]*content=[\'\"]([^>]*)[\'\"]")) { if (!isDaemonised) { std::cerr << "Error compiling RegExp pics1." << std::endl; } syslog(LOG_ERR, "%s", "Error compiling RegExp pics1."); return false; } if (!pics2.comp("[r|{ratings}] *\\(([^\\)]*)\\)")) { if (!isDaemonised) { std::cerr << "Error compiling RegExp pics2." << std::endl; } syslog(LOG_ERR, "%s", "Error compiling RegExp pics2."); return false; } if (!isiphost.comp(".*[a-z|A-Z].*")) { if (!isDaemonised) { std::cerr << "Error compiling RegExp isiphost." << std::endl; } syslog(LOG_ERR, "%s", "Error compiling RegExp isiphost."); return false; } return true;}bool FOptionContainer::iswebserver(String url) { url.removeWhiteSpace(); // just in case of weird browser crap url.toLower(); url.removePTP(); // chop off the ht(f)tp(s):// if (url.contains("/")) { url = url.before("/"); // chop off any path after the domain } if (url.startsWith(ada.toCharArray())) { // don't filter our web // server return true; } return false;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -