⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 foptioncontainer.cpp

📁 一个UNIX/LINUX下的基于内容的过滤服务器源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                return false;            }        }        (*o.lm.l[banned_phrase_list]).makeGraph(force_quick_search);        (*o.lm.l[banned_phrase_list]).used = true;    }    return true;}bool FOptionContainer::readeslfile(const char* filename) {    int result = o.lm.newItemList(filename, false, 0, true);    if (result < 0) {        if (!isDaemonised) {            std::cerr << "Error opening exceptionsitelist" << std::endl;        }        syslog(LOG_ERR, "%s","Error opening exceptionsitelist");        return false;    }    exception_site_list = (unsigned)result;    if (!(*o.lm.l[exception_site_list]).used) {        (*o.lm.l[exception_site_list]).endsWithSort();        if (createlistcachefiles == 1) {            if (!(*o.lm.l[exception_site_list]).createCacheFile()) {                return false;            }        }        (*o.lm.l[exception_site_list]).used = true;    }  // idea is that if the list has already been used it is already    // compiled, sorted, etc so no point doing it again    return true;}bool FOptionContainer::readeurllfile(const char* filename) {    int result = o.lm.newItemList(filename, false, 0, true);    if (result < 0) {        if (!isDaemonised) {            std::cerr << "Error opening exceptionurllist" << std::endl;        }        syslog(LOG_ERR, "%s","Error opening exceptionurllist");        return false;    }    exception_url_list = (unsigned)result;    if (!(*o.lm.l[exception_url_list]).used) {        (*o.lm.l[exception_url_list]).startsWithSort();        if (createlistcachefiles == 1) {            if (!(*o.lm.l[exception_url_list]).createCacheFile()) {                return false;            }        }        (*o.lm.l[exception_url_list]).used = true;    }    return true;}bool FOptionContainer::readbelfile(const char* filename) {    int result = o.lm.newItemList(filename, false, 0, true);    if (result < 0) {        if (!isDaemonised) {            std::cerr << "Error opening bannedextensionlist" << std::endl;        }        syslog(LOG_ERR, "%s","Error opening bannedextensionlist");        return false;    }    banned_extension_list = (unsigned)result;    if (!(*o.lm.l[banned_extension_list]).used) {        (*o.lm.l[banned_extension_list]).endsWithSort();        (*o.lm.l[banned_extension_list]).used = true;    }    return true;}bool FOptionContainer::readbslfile(const char* filename) {    int res = o.lm.newItemList(filename, false, 0, true);    if (res < 0) {        if (!isDaemonised) {            std::cerr << "Error opening bannedsitelist" << std::endl;        }        syslog(LOG_ERR, "%s","Error opening bannedsitelist");        return false;    }    banned_site_list = (unsigned)res;    if (!(*o.lm.l[banned_site_list]).used) {        (*o.lm.l[banned_site_list]).endsWithSort();        if (createlistcachefiles == 1) {            if (!(*o.lm.l[banned_site_list]).createCacheFile()) {                return false;            }        }        (*o.lm.l[banned_site_list]).used = true;    }    return true;}bool FOptionContainer::readgslfile(const char* filename) {    int res = o.lm.newItemList(filename, false, 0, true);    if (res < 0) {        if (!isDaemonised) {            std::cerr << "Error opening greysitelist" << std::endl;        }        syslog(LOG_ERR, "%s","Error opening greysitelist");        return false;    }    grey_site_list = (unsigned)res;    if (!(*o.lm.l[grey_site_list]).used) {        (*o.lm.l[grey_site_list]).endsWithSort();        if (createlistcachefiles == 1) {            if (!(*o.lm.l[grey_site_list]).createCacheFile()) {                return false;            }        }        (*o.lm.l[grey_site_list]).used = true;    }    return true;}bool FOptionContainer::readbulfile(const char* filename) {    int res = o.lm.newItemList(filename, true, 1, true);    if (res < 0) {        if (!isDaemonised) {            std::cerr << "Error opening bannedurllist" << std::endl;        }        syslog(LOG_ERR, "%s","Error opening bannedurllist");        return false;    }    banned_url_list = (unsigned)res;    if (!(*o.lm.l[banned_url_list]).used) {    (*o.lm.l[banned_url_list]).startsWithSort();        if (createlistcachefiles == 1) {            if (!(*o.lm.l[banned_url_list]).createCacheFile()) {                return false;            }        }        (*o.lm.l[banned_url_list]).used = true;    }    return true;}bool FOptionContainer::readgulfile(const char* filename) {    int res = o.lm.newItemList(filename, true, 1, true);    if (res < 0) {        if (!isDaemonised) {            std::cerr << "Error opening greyurllist" << std::endl;        }        syslog(LOG_ERR, "%s","Error opening greyurllist");        return false;    }    grey_url_list = (unsigned)res;    if (!(*o.lm.l[grey_url_list]).used) {        (*o.lm.l[grey_url_list]).startsWithSort();        if (createlistcachefiles == 1) {            if (!(*o.lm.l[grey_url_list]).createCacheFile()) {                return false;            }        }        (*o.lm.l[grey_url_list]).used = true;    }    return true;}bool FOptionContainer::readbreulfile(const char* filename) {    int result = o.lm.newItemList(filename, true, 0, true);    if (result < 0) {        if (!isDaemonised) {            std::cerr << "Error opening bannedregexpurllist" << std::endl;        }        syslog(LOG_ERR, "%s","Error opening bannedregexpurllist");        return false;    }    banned_regexpurl_list = (unsigned)result;    return compilebreulfile(banned_regexpurl_list);}// NOTE TO SELF - MOVE TO LISTCONTAINER TO SOLVE FUDGEbool FOptionContainer::compilebreulfile(unsigned int list) {    for(unsigned int i = 0; i < (*o.lm.l[list]).morelists.size(); i++) {        if (!compilebreulfile((*o.lm.l[list]).morelists[i])) {            return false;        }    }    RegExp r;    bool rv = true;    int len = (*o.lm.l[list]).getListLength();    String source;    for(int i = 0; i < len; i++) {        source = (*o.lm.l[list]).getItemAtInt(i).c_str();        rv = r.comp(source.toCharArray());        if (rv == false) {            if (!isDaemonised) {                std::cerr << "Error compiling regexp:" << source << std::endl;            }            syslog(LOG_ERR, "%s", "Error compiling regexp:");            syslog(LOG_ERR, "%s", source.toCharArray());            return false;        }        banned_regexpurl_list_comp.push_back(r);        banned_regexpurl_list_source.push_back(source);    }    (*o.lm.l[list]).used = true;    return true;}bool FOptionContainer::readcrelfile(const char* filename) {    int result = o.lm.newItemList(filename, true, 0, true);    if (result < 0) {        if (!isDaemonised) {            std::cerr << "Error opening contentregexplist" << std::endl;        }        syslog(LOG_ERR, "%s","Error opening contentregexplist");        return false;    }    content_regexp_list = (unsigned)result;    if (!(*o.lm.l[content_regexp_list]).used) {        (*o.lm.l[content_regexp_list]).startsWithSort();        (*o.lm.l[content_regexp_list]).used = true;    }    RegExp r;    bool rv = true;    String regexp;    String replacement;    for(int i = 0; i < (*o.lm.l[content_regexp_list]).getListLength(); i++) {        regexp = (*o.lm.l[content_regexp_list]).getItemAtInt(i).c_str();        replacement = regexp.after("\"->\"");        while(!replacement.endsWith("\"")) {            if (replacement.length() < 2) {                break;            }            replacement.chop();        }        replacement.chop();        regexp = regexp.after("\"").before("\"->\"");//        if (replacement.length() < 1 || regexp.length() < 1) {        if (regexp.length() < 1) {  // allow replace with blank            continue;        }        rv = r.comp(regexp.toCharArray());        if (rv == false) {            if (!isDaemonised) {                std::cerr << "Error compiling regexp:" << (*o.lm.l[content_regexp_list]).getItemAtInt(i) << std::endl;            }            syslog(LOG_ERR, "%s", "Error compiling regexp:");            syslog(LOG_ERR, "%s", (*o.lm.l[content_regexp_list]).getItemAtInt(i).c_str());        return false;        }        content_regexp_list_comp.push_back(r);        content_regexp_list_rep.push_back(replacement);    }    return true;}bool FOptionContainer::readbmlfile(const char* filename) {    int result = o.lm.newItemList(filename, false, 0, true);    if (result < 0) {        if (!isDaemonised) {            std::cerr << "Error opening bannedmimetypelist" << std::endl;        }        syslog(LOG_ERR, "%s","Error opening bannedmimetypelist");        return false;    }    banned_mimetype_list = (unsigned)result;    if (!(*o.lm.l[banned_mimetype_list]).used) {        (*o.lm.l[banned_mimetype_list]).endsWithSort();        (*o.lm.l[banned_mimetype_list]).used = true;    }    return true;}bool FOptionContainer::inexceptions(String url) {    if (iswebserver(url)) {  // don't filter our web server        return true;    }    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;    while (url.contains(".")) {        i = (*o.lm.l[exception_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[exception_site_list]).findInList(url.toCharArray());        if (i != NULL) {            return i;  // exact match        }    }    return false;  // and our survey said "UUHH UURRGHH"}bool FOptionContainer::inurlexceptions(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    }    while (url.before("/").contains(".")) {        i = (*o.lm.l[exception_url_list]).findStartsWith(url.toCharArray());        if (i != NULL) {            foundurl = i;            fl = foundurl.length();            if (url.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            }        }        url = url.after(".");  // check for being in higher level domains    }    return false;}char* FOptionContainer::inBannedSiteList(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[banned_site_list]).findInList(url2.toCharArray());                if (i != NULL) {                    return i;  // exact match                }                url2 = url2.after(".");  // check for being in hld            }        }    }    while (url.contains(".")) {        i = (*o.lm.l[banned_site_list]).findInList(url.toCharArray());        if (i != NULL) {            return i;  // 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[banned_site_list]).findInList(url.toCharArray());        if (i != NULL) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -