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

📄 optioncontainer.cpp

📁 一个UNIX/LINUX下的基于内容的过滤服务器源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        exceptions_user_list_location = findoptionS("exceptionuserlist");        exceptions_ip_list_location = findoptionS("exceptioniplist");        language_list_location = findoptionS("languagedir") + "/" + findoptionS("language") + "/messages";        access_denied_address = findoptionS("accessdeniedaddress");        ada = access_denied_address.c_str();        ada = ada.after("://");        ada.removeWhiteSpace();        if (ada.contains("/")) {            ada = ada.before("/"); // ada now contains the FQ host nom of the                               // server that serves the accessdenied.html                               // file        }        if (ada.contains(":")) {            ada = ada.before(":");  // chop off the port number if any        }        if (reporting_level == 1 || reporting_level == 2) {            if (ada.length() < 4) {                if (!isDaemonised) {                    cerr << "accessdeniedaddress setting appears to be wrong." << endl;                }                syslog(LOG_ERR, "%s", "accessdeniedaddress setting appears to be wrong.");                return false;            }        }        if (!readfgfile(filter_groups_list_location.c_str())) {            return false;        }        if (!readbilfile(banned_ip_list_location.c_str())) {            return false;        }  // read banned ip list        if (!readbuslfile(banned_user_list_location.c_str())) {            return false;        }  // read banned user list        if (!readeilfile(exceptions_ip_list_location.c_str())) {            return false;        }  // ip exceptions        if (!readeulfile(exceptions_user_list_location.c_str())) {            return false;        }  // site exceptions        if (!language_list.readLanguageList(language_list_location.c_str())) {            return false;        }  // messages language file        if (reporting_level == 3) {  // only if reporting set to HTML templ            if (!html_template.readTemplateFile(html_template_location.c_str())) {                if (!isDaemonised) {                    std::cerr << "Error reading HTML Template file:" << html_template_location << std::endl;                }                syslog(LOG_ERR, "%s", "Error reading HTML Template file.");                return false;                // HTML template file            }        }        if (!readFilterGroupConf()) {            if (!isDaemonised) {                std::cerr << "Error reading filter group conf file(s)." << std::endl;            }            syslog(LOG_ERR, "%s", "Error reading filter group conf file(s).");           return false;        }    } catch (exception& e) {        if (!isDaemonised) {            std::cerr << e.what() << std::endl;  // when called the daemon has not                                   // detached so we can do this        }	return false;    }    return true;}bool OptionContainer::readfgfile(const char* filename) {    bool result = filter_groups_list.readItemList(filename, false, 0);    if (!result) {        if (!isDaemonised) {            std::cerr << "Error opening filtergroupslist" << std::endl;        }        syslog(LOG_ERR, "%s","Error opening filtergroupslist");        return false;    }    filter_groups_list.startsWithSort();    return true;}bool OptionContainer::readbilfile(const char* filename) {    bool result = banned_ip_list.readItemList(filename, false, 0);    if (!result) {        if (!isDaemonised) {            std::cerr << "Error opening bannediplist" << std::endl;        }        syslog(LOG_ERR, "%s","Error opening bannediplist");        return false;    }    banned_ip_list.startsWithSort();    return true;}bool OptionContainer::readbuslfile(const char* filename) {    bool result = banned_user_list.readItemList(filename, false, 0);    if (!result) {        if (!isDaemonised) {            std::cerr << "Error opening banneduserlist" << std::endl;        }        syslog(LOG_ERR, "%s","Error opening banneduserlist");        return false;    }    banned_user_list.startsWithSort();    return true;}bool OptionContainer::readeulfile(const char* filename) {    bool result = exception_user_list.readItemList(filename, false, 0);    if (!result) {        if (!isDaemonised) {            std::cerr << "Error opening exceptionuserlist" << std::endl;        }        syslog(LOG_ERR, "%s","Error opening exceptionuserlist");        return false;    }    exception_user_list.endsWithSort();    return true;}bool OptionContainer::readeilfile(const char* filename) {    bool result = exception_ip_list.readItemList(filename, false, 0);    if (!result) {        if (!isDaemonised) {            std::cerr << "Error opening exceptioniplist" << std::endl;        }        syslog(LOG_ERR, "%s","Error opening exceptioniplist");        return false;    }    exception_ip_list.endsWithSort();    return true;}bool OptionContainer::inuserexceptions(const std::string *user) {    if ((*user).length() < 1) {        return false;    }    return exception_user_list.inList((char*)(*user).c_str());}bool OptionContainer::inipexceptions(const std::string *ip) {    if ((*ip).length() < 1) {        return false;    }    if (reverse_client_ip_lookups != 1) {        return exception_ip_list.inList((char*)(*ip).c_str());    }    if (exception_ip_list.inList((char*)(*ip).c_str())) {        return true;    }    std::deque<String> hostnames = (*fg[0]).ipToHostname((*ip).c_str());    bool result;    for (unsigned int i = 0; i < hostnames.size(); i++) {        result = exception_ip_list.inList(hostnames[i].toCharArray());        if (result) {            return true;        }    }    return false;}bool OptionContainer::inBannedUserList(const std::string *user) {    if ((*user).length() < 1) {        return false;    }    return banned_user_list.inList((char*)(*user).c_str());}bool OptionContainer::inBannedIPList(const std::string *ip) {    if ((*ip).length() < 1) {        return false;    }    if (reverse_client_ip_lookups != 1) {        return banned_ip_list.inList((char*)(*ip).c_str());    }    if (banned_ip_list.inList((char*)(*ip).c_str())) {        return true;    }    std::deque<String> hostnames = (*fg[0]).ipToHostname((*ip).c_str());    bool result;    for (unsigned int i = 0; i < hostnames.size(); i++) {        result = banned_ip_list.inList(hostnames[i].toCharArray());        if (result) {            return true;        }    }    return false;}int OptionContainer::findoptionI(const char* option) {    int res = String(findoptionS(option).c_str()).toInteger();    return res;}std::string OptionContainer::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 OptionContainer::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 OptionContainer::readFilterGroupConf() {    String prefix = conffilename;    prefix = prefix.before(".conf");    prefix += "f";    String file;    for(int i = 1; i <= filter_groups; i++){        file = prefix + String(i);        file += ".conf";        if (!readAnotherFilterGroupConf(file.toCharArray())) {            if (!isDaemonised) {                std::cerr << "Error opening filter list:" << file << std::endl;            }            syslog(LOG_ERR, "%s","Error opening filter list:");            syslog(LOG_ERR, "%s",file.toCharArray());            return false;        }    }    return true;}bool OptionContainer::readAnotherFilterGroupConf(const char *filename) {    #ifdef DGDEBUG        std::cout << "adding filter group" << numfg << " " << filename << std::endl;    #endif    // array of pointers to FOptionContainer    typedef FOptionContainer* PFOptionContainer;    FOptionContainer** temp = new PFOptionContainer[numfg + 1];    for(int i = 0; i < numfg; i++) {        temp[i] = fg[i];    }    if (numfg > 0) {        delete[] fg;    }    fg = temp;    fg[numfg] = new FOptionContainer;    #ifdef DGDEBUG        std::cout << "added filter group" << numfg << " " << filename << std::endl;    #endif    // pass all the vars from OptionContainer needed    (*fg[numfg]).weighted_phrase_mode = weighted_phrase_mode;    (*fg[numfg]).force_quick_search = force_quick_search;    (*fg[numfg]).createlistcachefiles = createlistcachefiles;    (*fg[numfg]).reverse_lookups = reverse_lookups;    (*fg[numfg]).ada = ada;    #ifdef DGDEBUG        std::cout << "passed variables to filter group" << numfg << " " << filename << std::endl;    #endif    bool rc = (*fg[numfg]).read(filename);    #ifdef DGDEBUG        std::cout << "read filter group" << numfg << " " << filename << std::endl;    #endif    numfg++;    if (!rc) {        return false;    }    return true;}

⌨️ 快捷键说明

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