| 1 |
// For all support, instructions and copyright go to: |
| 2 |
// http://e2guardian.org/ |
| 3 |
// Released under the GPL v2, with the OpenSSL exception described in the README file. |
| 4 |
|
| 5 |
#ifndef __HPP_NAUGHTYFILTER |
| 6 |
#define __HPP_NAUGHTYFILTER |
| 7 |
|
| 8 |
// INCLUDES |
| 9 |
|
| 10 |
//#include "String.hpp" |
| 11 |
//#include "OptionContainer.hpp" |
| 12 |
//#include "DataBuffer.hpp" |
| 13 |
#include "HTTPHeader.hpp" |
| 14 |
//#include "FOptionContainer.hpp" |
| 15 |
#include "UrlRec.hpp" |
| 16 |
#include "Auth.hpp" |
| 17 |
|
| 18 |
class FOptionContainer; |
| 19 |
|
| 20 |
// DECLARATIONS bool isListCheck = false; |
| 21 |
|
| 22 |
class NaughtyFilter |
| 23 |
{ |
| 24 |
public: |
| 25 |
// should the content be blocked? |
| 26 |
bool isItNaughty = false; |
| 27 |
// should the content bypass any further filtering? |
| 28 |
bool isException = false; |
| 29 |
// is the url/site in Greylist - forces content check |
| 30 |
bool isGrey = false; |
| 31 |
// is the url/site in SSLGreylist |
| 32 |
bool isSSLGrey = false; |
| 33 |
// is the url a search request |
| 34 |
bool isSearch = false; |
| 35 |
// is the url to be blocked |
| 36 |
bool isBlocked = false; |
| 37 |
bool hasSNI = false; // used in transparent https mode |
| 38 |
bool hasECH = false; // used in transparent https mode |
| 39 |
bool isTLS = false; // used in transparent https mode |
| 40 |
String orig_ip; // used in transparent mode |
| 41 |
int orig_port = 0; // used in transparent mode |
| 42 |
bool got_orig_ip = false; // used in transparent mode |
| 43 |
// bad certificat |
| 44 |
bool badcert = false; |
| 45 |
int listen_port = 0; // listening port |
| 46 |
struct auth_rec *authrec = nullptr; |
| 47 |
|
| 48 |
// return true or false? |
| 49 |
bool isReturn = false; |
| 50 |
|
| 51 |
bool reverse_checked = false; |
| 52 |
|
| 53 |
bool hasEmbededURL = false; |
| 54 |
std::deque<String> embededURLs; |
| 55 |
std::deque<url_rec> reversedURLs; |
| 56 |
|
| 57 |
HTTPHeader* request_header; |
| 58 |
HTTPHeader* response_header; |
| 59 |
|
| 60 |
bool isIPHostnameStrip(String url); |
| 61 |
|
| 62 |
RegExp ch_isiphost; |
| 63 |
RegResult Rch_isiphost; |
| 64 |
|
| 65 |
bool gomitm = false; |
| 66 |
bool nomitm = false; |
| 67 |
bool automitm = false; |
| 68 |
bool alert = false; |
| 69 |
bool deep_urls_checked = false; |
| 70 |
bool has_deep_urls = false; |
| 71 |
std::deque<url_rec> deep_urls; |
| 72 |
|
| 73 |
bool anon_user = false; |
| 74 |
bool anon_url = false; |
| 75 |
// flags from ConnectionHandler |
| 76 |
bool upfailure = false; //set when problem with upstream connection (site or proxy) |
| 77 |
bool waschecked = false; |
| 78 |
bool wasrequested = false; |
| 79 |
bool isexception = false; |
| 80 |
bool issemiexception = false; |
| 81 |
bool isourwebserver = false; |
| 82 |
bool wasclean = false; |
| 83 |
bool cachehit = false; |
| 84 |
bool isbypass = false; |
| 85 |
bool iscookiebypass = false; |
| 86 |
bool isvirusbypass = false; |
| 87 |
bool isscanbypass = false; |
| 88 |
bool isbypassallowed = false; |
| 89 |
bool isinfectionbypassallowed = false; |
| 90 |
bool isscanbypassallowed = false; |
| 91 |
bool istoobigbypassallowed = false; |
| 92 |
bool ispostblock = false; |
| 93 |
bool pausedtoobig = false; |
| 94 |
bool wasinfected = false; |
| 95 |
bool wasscanned = false; |
| 96 |
bool contentmodified = false; |
| 97 |
bool urlmodified = false; |
| 98 |
bool headermodified = false; |
| 99 |
bool headeradded = false; |
| 100 |
bool isconnect = false; |
| 101 |
bool ishead = false; |
| 102 |
bool isiphost = false; |
| 103 |
bool scanerror = false; |
| 104 |
bool ismitmcandidate = false; |
| 105 |
bool is_ssl = false; |
| 106 |
bool is_ip = false; |
| 107 |
bool ismitm = false; |
| 108 |
bool isdone = false; |
| 109 |
bool nolog = false; |
| 110 |
bool nocheckcert = false; |
| 111 |
bool logcategory = false; |
| 112 |
bool noviruscheck = true; |
| 113 |
bool urlredirect = false; |
| 114 |
bool isdirect = false; // go direct if true via proxy if false |
| 115 |
bool tunnel_rest = false; |
| 116 |
bool tunnel_2way = false; |
| 117 |
bool is_text = false; |
| 118 |
bool issiteonly = false; |
| 119 |
int auth_result = 0; |
| 120 |
String search_words; |
| 121 |
String search_terms; |
| 122 |
struct timeval thestart; |
| 123 |
|
| 124 |
// 0=none,1=first line,2=all |
| 125 |
int headersent = 0; |
| 126 |
|
| 127 |
int bypasstimestamp = 0; |
| 128 |
|
| 129 |
std::string mimetype; |
| 130 |
|
| 131 |
String url; // the normalised url |
| 132 |
String baseurl; // url with 'http[s]://' removed |
| 133 |
String logurl; // url with called protocol |
| 134 |
String urld; // decoded url |
| 135 |
String urldomain; // the domain or site part of the url |
| 136 |
String urldomainport; // the domain or site part of the url with port number |
| 137 |
String connect_site; // the site to connect to - normally same as urldomain |
| 138 |
String user; // result of auth plug-in id - may be network log-in name or client IP or port |
| 139 |
String realuser; // real or authed user name |
| 140 |
String lastmatch; |
| 141 |
String result; |
| 142 |
|
| 143 |
String get_lastmatch(); |
| 144 |
String get_logUrl(); |
| 145 |
String main_category(); |
| 146 |
|
| 147 |
std::string exceptionreason; // to hold the reason for not blocking |
| 148 |
std::string exceptioncat; |
| 149 |
off_t docsize; // to store the size of the returned document for logging |
| 150 |
int filtergroup; |
| 151 |
|
| 152 |
String tempfilename; |
| 153 |
String tempfilemime; |
| 154 |
String tempfiledis; |
| 155 |
|
| 156 |
// should the browser use the categories string or the displaycategories string? |
| 157 |
// (related to category list thresholding) |
| 158 |
bool usedisplaycats = false; |
| 159 |
// blocked data type - 0 = response body, 1 = request body (POST data), |
| 160 |
// 2 = URL parameters (search terms) |
| 161 |
int blocktype = 0; |
| 162 |
// flag for use by ContentScanners to say whether data should be stored |
| 163 |
// for future inspection. storage only implemented for POST data. |
| 164 |
bool store = false; |
| 165 |
|
| 166 |
int message_no = 0; |
| 167 |
int log_message_no = 0; |
| 168 |
|
| 169 |
// the reason for banning, what to say about it in the logs, and the |
| 170 |
// categories under which banning has taken place |
| 171 |
std::string whatIsNaughty; |
| 172 |
std::string whatIsNaughtyLog; |
| 173 |
std::string whatIsNaughtyCategories; |
| 174 |
std::string whatIsNaughtyDisplayCategories; |
| 175 |
std::string clienthost; |
| 176 |
std::string clientip; |
| 177 |
|
| 178 |
NaughtyFilter(); |
| 179 |
NaughtyFilter(HTTPHeader &request, HTTPHeader &response); |
| 180 |
NaughtyFilter(HTTPHeader &request, HTTPHeader &response, auth_rec &authrecin); |
| 181 |
void reset(); |
| 182 |
|
| 183 |
void setURL(bool set_ismitm = false); |
| 184 |
void setURL(String &sni); |
| 185 |
|
| 186 |
void checkme(const char *rawbody, off_t rawbodylen, const String *url, const String *domain, |
| 187 |
FOptionContainer* &foc, unsigned int phraselist, int limit, bool searchterms = false); |
| 188 |
|
| 189 |
String getFlags(); |
| 190 |
|
| 191 |
// highest positive (or lowest negative) weighting out of |
| 192 |
// both phrase filtering passes (smart/raw) |
| 193 |
int naughtiness = 0; |
| 194 |
String lastcategory; |
| 195 |
|
| 196 |
private: |
| 197 |
// check the banned, weighted & exception lists |
| 198 |
// pass in both URL & domain to activate embedded URL checking |
| 199 |
// (this is made optional in this manner because it's pointless |
| 200 |
// trying to look for links etc. in "smart" filtering mode, i.e. |
| 201 |
// after HTML has been removed, and in search terms.) |
| 202 |
void checkphrase(char *file, off_t filelen, const String *url, const String *domain, |
| 203 |
FOptionContainer* &foc, unsigned int phraselist, int limit, bool searchterms); |
| 204 |
|
| 205 |
}; |
| 206 |
|
| 207 |
#define __HPP_NAUGHTYFILTER |
| 208 |
#endif |