| 1 |
// SBFunction class |
| 2 |
|
| 3 |
// For all support, instructions and copyright go to: |
| 4 |
// http://e2guardian.org/ |
| 5 |
// Released under the GPL v2, with the OpenSSL exception described in the README file. |
| 6 |
|
| 7 |
#ifndef __HPP_SBFN |
| 8 |
#define __HPP_SBFN |
| 9 |
|
| 10 |
// INLCUDES |
| 11 |
|
| 12 |
#include <vector> |
| 13 |
#include <deque> |
| 14 |
#include <map> |
| 15 |
#include <string> |
| 16 |
#include "String.hpp" |
| 17 |
#include "RegExp.hpp" |
| 18 |
#include "ListMeta.hpp" |
| 19 |
|
| 20 |
// commands |
| 21 |
#define SB_COM_STARTFUNCTION 1 |
| 22 |
#define SB_COM_ENDFUNCTION 2 |
| 23 |
#define SB_COM_IF 3 |
| 24 |
#define SB_COM_IFNOT 4 |
| 25 |
|
| 26 |
// STATES indicates test to be performed |
| 27 |
|
| 28 |
// xIN states takes list as argument and checks if x is in list |
| 29 |
#define SB_STATE_URLIN 1 |
| 30 |
#define SB_STATE_SITEIN 2 |
| 31 |
#define SB_STATE_SEARCHIN 3 |
| 32 |
#define SB_STATE_EMBEDDEDIN 4 |
| 33 |
#define SB_STATE_REFERERIN 5 |
| 34 |
#define SB_STATE_HEADERIN 6 |
| 35 |
#define SB_STATE_FULLURLIN 7 |
| 36 |
#define SB_STATE_EXTENSIONIN 8 |
| 37 |
#define SB_STATE_MIMEIN 9 |
| 38 |
#define SB_STATE_CLIENTIN 10 |
| 39 |
#define SB_STATE_USERAGENTIN 11 |
| 40 |
#define SB_STATE_TIMEIN 12 |
| 41 |
#define SB_STATE_USERIN 13 |
| 42 |
#define SB_STATE_LISTEN_PORTIN 14 |
| 43 |
#define SB_STATE_RESHEADERIN 15 |
| 44 |
#define SB_STATE_CATEGORYIN 16 |
| 45 |
|
| 46 |
#define SB_STATE_TOPIN 17 // all below this require a valid list |
| 47 |
|
| 48 |
// Check type of request |
| 49 |
#define SB_STATE_CONNECT 17 |
| 50 |
#define SB_STATE_POST 18 |
| 51 |
#define SB_STATE_GET 19 |
| 52 |
#define SB_STATE_SITEISIP 20 |
| 53 |
#define SB_STATE_TLS 21 |
| 54 |
|
| 55 |
// xSET check setting of flag x |
| 56 |
#define SB_STATE_EXCEPTIONSET 22 |
| 57 |
#define SB_STATE_GREYSET 23 |
| 58 |
#define SB_STATE_BLOCKSET 24 |
| 59 |
#define SB_STATE_MITMSET 25 |
| 60 |
#define SB_STATE_DONESET 26 |
| 61 |
#define SB_STATE_RETURNSET 27 |
| 62 |
#define SB_STATE_TRUE 28 |
| 63 |
#define SB_STATE_HASSNI 29 |
| 64 |
#define SB_STATE_REDIRECTSET 30 |
| 65 |
#define SB_STATE_VIRUSCHECKSET 31 |
| 66 |
#define SB_STATE_BYPASSSET 32 |
| 67 |
#define SB_STATE_BYPASSALLOWEDSET 33 |
| 68 |
#define SB_STATE_INFECTIONBYPASSALLOWEDSET 34 |
| 69 |
#define SB_STATE_SEMIEXCEPTIONSET 35 |
| 70 |
|
| 71 |
#define SB_STATE_MAP_SIZE 35 |
| 72 |
|
| 73 |
// Storyboard defined functions IDs start at 1 - Built-in actions at 5001 |
| 74 |
#define SB_BI_FUNC_BASE 5000 |
| 75 |
|
| 76 |
// BUILT_IN functions |
| 77 |
#define SB_FUNC_SETEXCEPTION 5001 |
| 78 |
#define SB_FUNC_SETGREY 5002 |
| 79 |
#define SB_FUNC_SETBLOCK 5003 |
| 80 |
#define SB_FUNC_SETMODURL 5004 |
| 81 |
#define SB_FUNC_SETDONE 5005 |
| 82 |
#define SB_FUNC_SETTRUE 5006 |
| 83 |
#define SB_FUNC_SETFALSE 5007 |
| 84 |
#define SB_FUNC_SETGOMITM 5008 |
| 85 |
#define SB_FUNC_SETLOGCAT 5009 |
| 86 |
#define SB_FUNC_SETADDHEADER 5010 |
| 87 |
#define SB_FUNC_SETREDIRECT 5011 |
| 88 |
#define SB_FUNC_SETNOCHECKCERT 5012 |
| 89 |
#define SB_FUNC_SETSEARCHTERM 5013 |
| 90 |
#define SB_FUNC_SETMODHEADER 5014 |
| 91 |
#define SB_FUNC_SETGODIRECT 5015 |
| 92 |
#define SB_FUNC_SETNOLOG 5016 |
| 93 |
#define SB_FUNC_SETALERT 5017 |
| 94 |
#define SB_FUNC_UNSETVIRUSCHECK 5018 |
| 95 |
#define SB_FUNC_UNSETBYPASS 5019 |
| 96 |
#define SB_FUNC_SETCONNECTSITE 5020 |
| 97 |
#define SB_FUNC_UNSETBYPASSALLOW 5021 |
| 98 |
#define SB_FUNC_UNSETINFECTIONBYPASSALLOW 5022 |
| 99 |
#define SB_FUNC_SETNOMITM 5023 |
| 100 |
#define SB_FUNC_SETAUTOMITM 5024 |
| 101 |
#define SB_FUNC_UNSETAUTOMITM 5025 |
| 102 |
#define SB_FUNC_SETGROUP 5026 |
| 103 |
#define SB_FUNC_SETSEMIEXCEPTION 5027 |
| 104 |
#define SB_FUNC_UNSETSEMIEXCEPTION 5028 |
| 105 |
|
| 106 |
|
| 107 |
#define SB_FUNC_MAP_SIZE 28 |
| 108 |
|
| 109 |
|
| 110 |
// DECLARATIONS |
| 111 |
|
| 112 |
class SBFunction |
| 113 |
{ |
| 114 |
private: |
| 115 |
String state_map[SB_STATE_MAP_SIZE] = { |
| 116 |
"urlin", |
| 117 |
"sitein", |
| 118 |
"searchin", |
| 119 |
"embeddedin", |
| 120 |
"refererin", |
| 121 |
"headerin", |
| 122 |
"fullurlin", |
| 123 |
"extensionin", |
| 124 |
"mimein", |
| 125 |
"clientin", |
| 126 |
"useragentin", |
| 127 |
"timein", |
| 128 |
"userin", |
| 129 |
"listenportin", |
| 130 |
"responseheaderin", |
| 131 |
"categoryin", |
| 132 |
"connect", |
| 133 |
"post", |
| 134 |
"get", |
| 135 |
"siteisip", |
| 136 |
"tls", |
| 137 |
"exceptionset", |
| 138 |
"greyset", |
| 139 |
"blockset", |
| 140 |
"mitmset", |
| 141 |
"doneset", |
| 142 |
"returnset", |
| 143 |
"true", |
| 144 |
"hassniset", |
| 145 |
"redirectset", |
| 146 |
"viruscheckset", |
| 147 |
"bypassset", |
| 148 |
"bypassallowset", |
| 149 |
"infectionbypassallowset", |
| 150 |
"semiexceptionset" |
| 151 |
}; |
| 152 |
|
| 153 |
String command_map[4] = { "function", |
| 154 |
"end", |
| 155 |
"if", |
| 156 |
"ifnot", |
| 157 |
}; |
| 158 |
|
| 159 |
std::vector<String> bi_funct_map = { |
| 160 |
"setexception", |
| 161 |
"setgrey", |
| 162 |
"setblock", |
| 163 |
"setmodurl", |
| 164 |
"setdone", |
| 165 |
"true", |
| 166 |
"false", |
| 167 |
"setgomitm", |
| 168 |
"setlogcategory", |
| 169 |
"setaddheader", |
| 170 |
"setredirect", |
| 171 |
"setnocheckcert", |
| 172 |
"setsearchterm", |
| 173 |
"setmodheader", |
| 174 |
"setgodirect", |
| 175 |
"setnolog", |
| 176 |
"setalert", |
| 177 |
"unsetviruscheck", |
| 178 |
"unsetbypass", |
| 179 |
"setconnectsite", |
| 180 |
"unsetbypassallow", |
| 181 |
"unsetinfectionbypassallow", |
| 182 |
"setnomitm", |
| 183 |
"setautomitm", |
| 184 |
"unsetautomitm", |
| 185 |
"setgroup", |
| 186 |
"setsemiexception", |
| 187 |
"unsetsemiexception" |
| 188 |
}; |
| 189 |
|
| 190 |
public: |
| 191 |
int items; |
| 192 |
|
| 193 |
|
| 194 |
struct com_rec { |
| 195 |
bool isif = false; // true if if - false is ifnot |
| 196 |
unsigned int state; // what is being tested e.g. url site search etc |
| 197 |
std::deque<ListMeta::list_info> list_id_dq; // holds ids of list(s) being used |
| 198 |
unsigned int mess_no = 0; // optional overide of list defaults |
| 199 |
unsigned int log_mess_no = 0; // optional overide of list defaults |
| 200 |
unsigned int action_id; // action to take if result true |
| 201 |
bool return_after_action = false; |
| 202 |
bool return_after_action_is_true = false; |
| 203 |
bool optional = false; // if true do not abort if lists do not exist |
| 204 |
unsigned int file_lineno; // used for debug output |
| 205 |
String action_name; // name of action |
| 206 |
String list_name; // name of list |
| 207 |
}; |
| 208 |
|
| 209 |
String name; // holds name of function |
| 210 |
unsigned int fn_id; |
| 211 |
std::deque<com_rec> comm_dq; |
| 212 |
String file_name; // holds source file path for debug |
| 213 |
unsigned int file_lineno; // used for debug output |
| 214 |
|
| 215 |
SBFunction(); |
| 216 |
~SBFunction(); |
| 217 |
|
| 218 |
void reset(); |
| 219 |
bool start(String & name, unsigned int id, unsigned int& line_noi, String filename); |
| 220 |
bool end(); |
| 221 |
bool addline(String command, String params, String action, unsigned int line_no); |
| 222 |
unsigned int getStateID(String & state); |
| 223 |
unsigned int getBIFunctID(String & action); |
| 224 |
String getState(unsigned int id); |
| 225 |
String getBIFunct(unsigned int &id); |
| 226 |
String getName(); |
| 227 |
|
| 228 |
|
| 229 |
}; |
| 230 |
|
| 231 |
#endif |