| 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_OPTIONCONTAINER |
| 6 |
#define __HPP_OPTIONCONTAINER |
| 7 |
|
| 8 |
// INCLUDES |
| 9 |
|
| 10 |
#include "Auth.hpp" |
| 11 |
#include "CertificateAuthority.hpp" |
| 12 |
#include "ConfigReader.hpp" |
| 13 |
#include "FOptionContainer.hpp" |
| 14 |
#include "DownloadManager.hpp" |
| 15 |
#include "ContentScanner.hpp" |
| 16 |
#include "String.hpp" |
| 17 |
#include "HTMLTemplate.hpp" |
| 18 |
#include "ImageContainer.hpp" |
| 19 |
#include "ListContainer.hpp" |
| 20 |
#include "ListManager.hpp" |
| 21 |
#include "LanguageContainer.hpp" |
| 22 |
#include "LOptionContainer.hpp" |
| 23 |
#include "RegExp.hpp" |
| 24 |
#include "IPList.hpp" |
| 25 |
#include "Queue.hpp" |
| 26 |
#include <atomic> |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
// DECLARATIONS |
| 31 |
struct AccessLogOptions |
| 32 |
{ |
| 33 |
std::string log_location; |
| 34 |
std::string RQlog_location; |
| 35 |
std::string RSlog_location; |
| 36 |
std::string ALlog_location; |
| 37 |
|
| 38 |
Queue<std::string>* log_Q; |
| 39 |
Queue<std::string>* RQlog_Q; |
| 40 |
|
| 41 |
//Queue<AccessLogger::LogRecord*> log_Q; |
| 42 |
//Queue<AccessLogger::LogRecord*> RQlog_Q; |
| 43 |
|
| 44 |
int log_level = 0; |
| 45 |
int log_file_format = 0; |
| 46 |
int log_exception_hits = 0; |
| 47 |
|
| 48 |
bool log_requests = false; |
| 49 |
bool log_responses = false; |
| 50 |
bool log_alerts = false; |
| 51 |
bool log_client_hostnames = false; |
| 52 |
bool log_client_host_and_ip = false; // todo: unused - this IS used - PP |
| 53 |
bool anonymise_logs = false; |
| 54 |
bool log_ad_blocks = false; |
| 55 |
bool log_timestamp = false; |
| 56 |
bool log_user_agent = false; |
| 57 |
bool use_dash_for_blanks = true; |
| 58 |
bool addECHtoFlags = false; |
| 59 |
unsigned int max_logitem_length = 2000; |
| 60 |
|
| 61 |
std::string dns_user_logging_domain; // TODO: not documented ?? |
| 62 |
bool dns_user_logging() { return !dns_user_logging_domain.empty(); }; |
| 63 |
|
| 64 |
// Hardware/organisation/etc. IDs |
| 65 |
std::string logid_1; |
| 66 |
std::string logid_2; |
| 67 |
std::string prod_id; |
| 68 |
}; |
| 69 |
|
| 70 |
struct AuthPluginOptions |
| 71 |
{ |
| 72 |
bool auth_requires_user_and_group = false; |
| 73 |
|
| 74 |
std::map<int, String> auth_map; |
| 75 |
}; |
| 76 |
struct BlockPageOptions |
| 77 |
{ |
| 78 |
int reporting_level = 0; |
| 79 |
|
| 80 |
bool use_custom_banned_image = false; |
| 81 |
std::string custom_banned_image_file; |
| 82 |
ImageContainer banned_image; |
| 83 |
|
| 84 |
bool use_custom_banned_flash = false; |
| 85 |
std::string custom_banned_flash_file; |
| 86 |
ImageContainer banned_flash; |
| 87 |
|
| 88 |
}; |
| 89 |
struct CertificateOptions |
| 90 |
{ |
| 91 |
bool enable_ssl = false; |
| 92 |
|
| 93 |
std::string ssl_certificate_path; |
| 94 |
std::string ca_certificate_path; |
| 95 |
std::string ca_private_key_path; |
| 96 |
std::string cert_private_key_path; |
| 97 |
std::string generated_cert_path; |
| 98 |
std::string generated_link_path; |
| 99 |
std::string openssl_conf_path; |
| 100 |
CertificateAuthority *ca; |
| 101 |
|
| 102 |
time_t gen_cert_start, gen_cert_end; |
| 103 |
bool use_openssl_conf = false; |
| 104 |
bool have_openssl_conf = false; |
| 105 |
bool generated_auto_start_end = true; |
| 106 |
std::string set_cipher_list; |
| 107 |
|
| 108 |
bool generate_ca_certificate(); |
| 109 |
}; |
| 110 |
struct ConfigOptions |
| 111 |
{ |
| 112 |
std::string prog_name; // (default e2guardian) |
| 113 |
std::string configfile; // Main Configfile (default ${e2sysconfdir}/e2guardian.conf) |
| 114 |
std::string languagepath; |
| 115 |
|
| 116 |
char benchmark = '\0'; |
| 117 |
bool total_block_list = false; |
| 118 |
}; |
| 119 |
struct ConnectionHandlerOptions { |
| 120 |
|
| 121 |
bool use_original_ip_port = false; // only for transparent and no upstream proxy |
| 122 |
bool logconerror = false; |
| 123 |
|
| 124 |
bool reverse_client_ip_lookups = false; |
| 125 |
|
| 126 |
// internal test urls |
| 127 |
std::string internal_test_url; |
| 128 |
std::string internal_status_url; |
| 129 |
|
| 130 |
}; |
| 131 |
struct ContentScannerOptions { |
| 132 |
|
| 133 |
bool contentscanning = false; |
| 134 |
|
| 135 |
off_t max_content_filter_size; |
| 136 |
off_t max_content_ramcache_scan_size; |
| 137 |
off_t max_content_filecache_scan_size; |
| 138 |
bool scan_clean_cache = false; // Check: Not used? |
| 139 |
bool content_scan_exceptions = false; // Check: Not used? (There is another one in FOptionContainer) |
| 140 |
int initial_trickle_delay = 0; |
| 141 |
int trickle_delay = 0; |
| 142 |
int content_scanner_timeout = 0; |
| 143 |
int content_scanner_timeout_sec = 0; |
| 144 |
|
| 145 |
std::string download_dir; |
| 146 |
bool delete_downloaded_temp_files = false; |
| 147 |
}; |
| 148 |
struct DStatOptions |
| 149 |
{ |
| 150 |
std::string dstat_location; |
| 151 |
bool dstat_log_flag = false; |
| 152 |
bool stats_human_readable = false; |
| 153 |
int dstat_interval = 300; |
| 154 |
}; |
| 155 |
struct FilterGroupOptions |
| 156 |
{ |
| 157 |
int filter_groups = 0; |
| 158 |
int numfg = 0; |
| 159 |
int default_fg = 0; |
| 160 |
int default_trans_fg = 0; |
| 161 |
int default_icap_fg = 0; |
| 162 |
bool use_group_names_list = false; // Never set ?!?! |
| 163 |
|
| 164 |
std::string filter_groups_list_location; |
| 165 |
ListContainer filter_groups_list; |
| 166 |
|
| 167 |
}; |
| 168 |
struct HTTPHeaderOptions |
| 169 |
{ |
| 170 |
std::string ident_header_value; |
| 171 |
bool forwarded_for = false; |
| 172 |
unsigned int max_header_lines = 0; |
| 173 |
|
| 174 |
}; |
| 175 |
struct ICAPOptions |
| 176 |
{ |
| 177 |
std::string icap_reqmod_url; |
| 178 |
std::string icap_resmod_url; |
| 179 |
}; |
| 180 |
struct ListsOptions |
| 181 |
{ |
| 182 |
bool read_from_stdin = false; // unused ?? kdg 22.12.2020 |
| 183 |
bool force_quick_search = false; |
| 184 |
bool abort_on_missing_list = false; |
| 185 |
bool search_sitelist_for_ip = false; |
| 186 |
|
| 187 |
std::deque<String> iplist_dq; |
| 188 |
std::deque<String> sitelist_dq; |
| 189 |
std::deque<String> ipsitelist_dq; |
| 190 |
std::deque<String> urllist_dq; |
| 191 |
std::deque<String> regexpboollist_dq; |
| 192 |
std::deque<String> maplist_dq; |
| 193 |
std::deque<String> ipmaplist_dq; |
| 194 |
|
| 195 |
}; |
| 196 |
struct LoggerOptions |
| 197 |
{ |
| 198 |
int debug_format = 1; |
| 199 |
|
| 200 |
bool log_ssl_errors = false; |
| 201 |
bool SB_trace = false; |
| 202 |
int udp_source_port = 39000; |
| 203 |
|
| 204 |
std::string name_suffix; // for SyslogName, where configured ?? |
| 205 |
|
| 206 |
}; |
| 207 |
struct MonitorOptions |
| 208 |
{ |
| 209 |
std::string monitor_flag_prefix; |
| 210 |
bool monitor_flag_flag = false; |
| 211 |
}; |
| 212 |
struct NetworkOptions |
| 213 |
{ |
| 214 |
std::string server_name; |
| 215 |
|
| 216 |
std::string proxy_ip; |
| 217 |
bool no_proxy = true; |
| 218 |
|
| 219 |
std::string TLSproxyCN; |
| 220 |
bool TLSproxyCN_is_ip = false; |
| 221 |
|
| 222 |
std::deque<String> filter_ip; |
| 223 |
std::deque<String> check_ip; |
| 224 |
std::deque<String> xforwardedfor_filter_ip; |
| 225 |
std::deque<String> filter_ports; |
| 226 |
std::deque<String> check_ports; |
| 227 |
std::deque<String> TLS_filter_ports; |
| 228 |
|
| 229 |
int filter_port = 0; |
| 230 |
int proxy_port = 0; |
| 231 |
int transparenthttps_port = 0; |
| 232 |
int icap_port = 0; |
| 233 |
|
| 234 |
int connect_timeout = 0; |
| 235 |
int connect_timeout_sec = 0; |
| 236 |
int connect_retries = 0; |
| 237 |
int proxy_timeout = 0; |
| 238 |
int proxy_timeout_sec = 0; |
| 239 |
int pcon_timeout = 0; |
| 240 |
int pcon_timeout_sec = 0; |
| 241 |
int exchange_timeout = 0; |
| 242 |
int exchange_timeout_sec = 0; |
| 243 |
|
| 244 |
int proxy_failure_log_interval = 0; // or in LogOptions ?? |
| 245 |
|
| 246 |
int number_of_fds_neded(); |
| 247 |
}; |
| 248 |
struct NaughtyOptions |
| 249 |
{ |
| 250 |
int phrase_filter_mode = 0; |
| 251 |
int weighted_phrase_mode = 0; // PIP added in - not sure if still required (There is another on in FOption Container) |
| 252 |
bool show_weighted_found = false; |
| 253 |
bool show_all_weighted_found = false; // logs weighted less than limit |
| 254 |
int preserve_case = 0; |
| 255 |
bool hex_decode_content = false; |
| 256 |
}; |
| 257 |
struct PluginOptions |
| 258 |
{ |
| 259 |
std::deque<Plugin *> dmplugins; |
| 260 |
std::deque<Plugin *> csplugins; |
| 261 |
std::deque<Plugin *> authplugins; |
| 262 |
std::deque<Plugin *>::iterator dmplugins_begin; |
| 263 |
std::deque<Plugin *>::iterator dmplugins_end; |
| 264 |
std::deque<Plugin *>::iterator csplugins_begin; |
| 265 |
std::deque<Plugin *>::iterator csplugins_end; |
| 266 |
std::deque<Plugin *>::iterator authplugins_begin; |
| 267 |
std::deque<Plugin *>::iterator authplugins_end; |
| 268 |
|
| 269 |
bool loadDMPlugins(ConfigReader &cr); |
| 270 |
bool loadCSPlugins(ConfigReader &cr); |
| 271 |
bool loadAuthPlugins(ConfigReader &cr); |
| 272 |
|
| 273 |
void deletePlugins(std::deque<Plugin *> &list); |
| 274 |
|
| 275 |
AuthPluginOptions auth; // for Auth Plugin |
| 276 |
}; |
| 277 |
struct ProcessOptions |
| 278 |
{ |
| 279 |
int root_user = 0; |
| 280 |
int proxy_user = 0; |
| 281 |
int proxy_group = 0; |
| 282 |
|
| 283 |
//std::string daemon_user; |
| 284 |
//std::string daemon_group; |
| 285 |
std::string daemon_user_name; |
| 286 |
std::string daemon_group_name; |
| 287 |
|
| 288 |
std::string pid_filename; |
| 289 |
|
| 290 |
int http_workers = 0; |
| 291 |
|
| 292 |
bool no_daemon = false; |
| 293 |
bool is_daemonised = false; |
| 294 |
bool is_dockermode = false; |
| 295 |
|
| 296 |
bool find_user_ids(); |
| 297 |
bool become_root_user(); |
| 298 |
bool become_proxy_user(); |
| 299 |
bool daemonise(); // Fork ourselves off into the background |
| 300 |
}; |
| 301 |
struct StoryBoardOptions |
| 302 |
{ |
| 303 |
struct SB_entry_map { |
| 304 |
int entry_id = 0; |
| 305 |
String entry_function; |
| 306 |
}; |
| 307 |
|
| 308 |
std::string storyboard_location; // better: preauth_location ?? |
| 309 |
|
| 310 |
std::deque<SB_entry_map> auth_entry_dq; |
| 311 |
std::deque<SB_entry_map> dm_entry_dq; |
| 312 |
|
| 313 |
bool reverse_lookups = false; |
| 314 |
|
| 315 |
}; |
| 316 |
|
| 317 |
class OptionContainer |
| 318 |
{ |
| 319 |
public: |
| 320 |
// all our many, many options |
| 321 |
AccessLogOptions log; |
| 322 |
BlockPageOptions block; |
| 323 |
CertificateOptions cert; |
| 324 |
ConfigOptions config; |
| 325 |
ConnectionHandlerOptions conn; |
| 326 |
ContentScannerOptions content; |
| 327 |
DStatOptions dstat; |
| 328 |
FilterGroupOptions filter; |
| 329 |
HTTPHeaderOptions header; |
| 330 |
ICAPOptions icap; |
| 331 |
ListsOptions lists; |
| 332 |
LoggerOptions logger; |
| 333 |
MonitorOptions monitor; |
| 334 |
NaughtyOptions naughty; |
| 335 |
NetworkOptions net; |
| 336 |
PluginOptions plugins; |
| 337 |
ProcessOptions proc; |
| 338 |
StoryBoardOptions story; |
| 339 |
|
| 340 |
LanguageContainer language_list; |
| 341 |
ListManager lm; |
| 342 |
|
| 343 |
Queue<LQ_rec> http_worker_Q; |
| 344 |
|
| 345 |
bool config_error = false; |
| 346 |
|
| 347 |
bool use_xforwardedfor = false; |
| 348 |
|
| 349 |
#ifdef ENABLE_EMAIL |
| 350 |
// Email notification patch by J. Gauthier |
| 351 |
std::string mailer; |
| 352 |
#endif |
| 353 |
|
| 354 |
HTMLTemplate html_template; // unused ?? never set, not mentioned in e2guardian.conf but used in FOptionContainer::getHTMLTemplate |
| 355 |
|
| 356 |
std::string per_room_directory_location; // not used but in LOptionContainer ?? |
| 357 |
|
| 358 |
OptionContainer(); |
| 359 |
~OptionContainer(); |
| 360 |
|
| 361 |
bool read_config(const Path &filename, bool readFullConfig=true); |
| 362 |
void reset(); |
| 363 |
|
| 364 |
bool readinStdin(); |
| 365 |
|
| 366 |
bool createLists(int load_id); |
| 367 |
|
| 368 |
std::atomic<int> LC_cnt; |
| 369 |
std::shared_ptr<LOptionContainer> current_LOC; |
| 370 |
std::shared_ptr<LOptionContainer> currentLists(); |
| 371 |
|
| 372 |
|
| 373 |
private: |
| 374 |
|
| 375 |
bool findAccessLogOptions(ConfigReader &cr); |
| 376 |
bool findBlockPageOptions(ConfigReader &cr); |
| 377 |
bool findCertificateOptions(ConfigReader &cr); |
| 378 |
bool findConfigOptions(ConfigReader &cr); |
| 379 |
bool findConnectionHandlerOptions(ConfigReader &cr); |
| 380 |
bool findContentScannerOptions(ConfigReader &cr); |
| 381 |
bool findDStatOptions(ConfigReader &cr); |
| 382 |
bool findFilterGroupOptions(ConfigReader &cr); |
| 383 |
bool findHeaderOptions(ConfigReader &cr); |
| 384 |
bool findICAPOptions(ConfigReader &cr); |
| 385 |
bool findListsOptions(ConfigReader &cr); |
| 386 |
bool findLoggerOptions(ConfigReader &cr); |
| 387 |
bool findMonitorOptions(ConfigReader &cr); |
| 388 |
bool findNaughtyOptions(ConfigReader &cr); |
| 389 |
bool findNetworkOptions(ConfigReader &cr); |
| 390 |
bool findPluginOptions(ConfigReader &cr); |
| 391 |
bool findProcOptions(ConfigReader &cr); |
| 392 |
bool findStoryBoardOptions(ConfigReader &cr); |
| 393 |
|
| 394 |
bool realitycheck(long int l, long int minl, long int maxl, const char *emessage); |
| 395 |
// bool readAnotherFilterGroupConf(const char *filename, const char *groupname, bool &need_html); |
| 396 |
|
| 397 |
}; |
| 398 |
|
| 399 |
#endif |