forked from e2guardian/e2guardian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OptionContainer.cpp
1395 lines (1235 loc) · 47.1 KB
/
OptionContainer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// For all support, instructions and copyright go to:
// http://e2guardian.org/
// Released under the GPL v2, with the OpenSSL exception described in the README file.
// INCLUDES
#ifdef HAVE_CONFIG_H
#include "e2config.h"
#endif
#include "LOptionContainer.hpp"
#include "OptionContainer.hpp"
#include "RegExp.hpp"
#include "ConfigVar.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <syslog.h>
#include <dirent.h>
#include <cstdlib>
#include <unistd.h> // checkme: remove?
// GLOBALS
extern bool is_daemonised;
extern thread_local std::string thread_id;
//ListContainer total_block_site_list;
//ListContainer total_block_url_list;
// IMPLEMENTATION
OptionContainer::OptionContainer() {
log_Q = new Queue<std::string>;
RQlog_Q = new Queue<std::string>;
// http_worker_Q = new Queue<LQ_rec>;
}
OptionContainer::~OptionContainer() {
reset();
}
void OptionContainer::reset() {
//deleteFilterGroups();
deletePlugins(dmplugins);
deletePlugins(csplugins);
deletePlugins(authplugins);
//deleteRooms();
//exception_ip_list.reset();
//banned_ip_list.reset();
language_list.reset();
conffile.clear();
filter_ip.clear();
filter_ports.clear();
auth_map.clear();
}
void OptionContainer::deletePlugins(std::deque<Plugin *> &list) {
for (std::deque<Plugin *>::iterator i = list.begin(); i != list.end(); i++) {
if ((*i) != NULL) {
(*i)->quit();
delete (*i);
}
}
list.clear();
}
bool OptionContainer::readConfFile(const char *filename, String &list_pwd) {
std::string linebuffer;
String temp; // for tempory conversion and storage
String now_pwd(list_pwd);
std::ifstream conffiles(filename, std::ios::in); // e2guardianfN.conf
if (!conffiles.good()) {
if (!is_daemonised) {
std::cerr << thread_id << "Error reading: " << filename << std::endl;
}
syslog(LOG_ERR, "Error reading %s", filename);
return false;
}
String base_dir(filename);
base_dir.baseDir();
while (!conffiles.eof()) {
getline(conffiles, linebuffer);
if (!conffiles.fail() && linebuffer.length() != 0) {
if (linebuffer[0] != '#') { // i.e. not commented out
temp = (char *) linebuffer.c_str();
if (temp.contains("#")) {
temp = temp.before("#");
}
temp.removeWhiteSpace(); // get rid of spaces at end of line
while (temp.contains("__LISTDIR__")) {
String temp2 = temp.before("__LISTDIR__");
temp2 += now_pwd;
temp2 += temp.after("__LISTDIR__");
temp = temp2;
}
// deal with included files
if (temp.startsWith(".")) {
temp = temp.after(".Include<").before(">");
if (temp.length() > 0) {
temp.fullPath(base_dir);
if (!readConfFile(temp.toCharArray(), now_pwd)) {
conffiles.close();
return false;
}
}
String temp2 = temp.after(".Define LISTDIR <").before(">");
if (temp2.length() > 0) {
now_pwd = temp2;
//if(!now_pwd.endsWith("/"))
// now_pwd += "/";
}
continue;
}
// append ,listdir=now_pwd if line contains a file path - so that now_pwd can be passed
// to list file handler so that it can honour __LISTDIR__ in Included listfiles
if (temp.contains("path=") && !temp.contains("listdir=")) {
temp += ",listdir=";
temp += now_pwd;
}
linebuffer = temp.toCharArray();
conffile.push_back(linebuffer); // stick option in deque
}
}
}
conffiles.close();
return true;
}
bool OptionContainer::read(std::string &filename, int type) {
conffilename = filename;
// all sorts of exceptions could occur reading conf files
try {
String list_pwd = __CONFDIR;
list_pwd += "/lists/common";
if (!readConfFile(filename.c_str(), list_pwd))
return false;
if (type == 0 || type == 2) {
if ((pid_filename = findoptionS("pidfilename")) == "") {
pid_filename = __PIDDIR;
pid_filename += "/e2guardian.pid";
}
if (findoptionS("dockermode") == "on") {
dockermode = true;
};
if (findoptionS("logsyslog") == "on") {
log_syslog = true;
if ((name_suffix = findoptionS("namesuffix")) == "") {
name_suffix = "";
}
} else if ((log_location = findoptionS("loglocation")) == "") {
log_location = __LOGLOCATION;
log_location += "/access.log";
log_syslog = false;
}
#ifndef NEWDEBUG_OFF
if ((debuglevel = findoptionS("debuglevel")) != "") {
}
if ((path_debuglevel = findoptionS("debuglevelfile")) != "") {
}
myDebug = new DebugManager(debuglevel, path_debuglevel);
#endif
if ((RQlog_location = findoptionS("rqloglocation")) == "") {
log_requests = false;
} else {
log_requests = true;
}
if ((dstat_location = findoptionS("dstatlocation")) == "") {
dstat_log_flag = false;
} else {
dstat_log_flag = true;
dstat_interval = findoptionI("dstatinterval");
if (dstat_interval == 0) {
dstat_interval = 300; // 5 mins
}
}
if (findoptionS("statshumanreadable") == "on") {
stats_human_readable = true;
} else {
stats_human_readable = false;
}
if ((dns_user_logging_domain = findoptionS("dnsuserloggingdomain")) == "") {
dns_user_logging = false;
} else {
dns_user_logging = true;
}
log_header_value = findoptionS("logheadervalue");
if (type == 0) {
return true;
}
}
if ((daemon_user_name = findoptionS("daemonuser")) == "") {
daemon_user_name = __PROXYUSER;
}
if ((daemon_group_name = findoptionS("daemongroup")) == "") {
daemon_group_name = __PROXYGROUP;
}
if (findoptionS("nodaemon") == "on") {
no_daemon = true;
} else {
no_daemon = false;
}
if (dockermode) {
no_daemon = true;
e2_front_log = true;
} else {
no_daemon = false;
e2_front_log = false;
}
if (findoptionS("nologger") == "on") {
no_logger = true;
} else {
no_logger = false;
}
#ifdef __SSLMITM
ssl_certificate_path = findoptionS("sslcertificatepath") + "/";
if (ssl_certificate_path == "/") {
ssl_certificate_path = ""; // "" will enable default openssl certs
}
#endif
#ifdef __SSLMITM
if (findoptionS("enablessl") == "on") {
enable_ssl = true;
} else {
enable_ssl = false;
}
if(enable_ssl) {
bool ret = true;
if (findoptionS("useopensslconf") == "on") {
use_openssl_conf = true;
openssl_conf_path = findoptionS("opensslconffile");
if (openssl_conf_path == "") {
have_openssl_conf = false;
} else {
have_openssl_conf = true;
}
} else {
use_openssl_conf = false;
};
ca_certificate_path = findoptionS("cacertificatepath");
if (ca_certificate_path == "") {
if (!is_daemonised){
std::cerr << "cacertificatepath is required when ssl is enabled" << std::endl;
}
syslog(LOG_ERR, "%s", "cacertificatepath is required when ssl is enabled");
ret = false;
}
ca_private_key_path = findoptionS("caprivatekeypath");
if (ca_private_key_path == "") {
if (!is_daemonised){
std::cerr << "caprivatekeypath is required when ssl is enabled" << std::endl;
}
syslog(LOG_ERR, "%s", "caprivatekeypath is required when ssl is enabled");
ret = false;
}
cert_private_key_path = findoptionS("certprivatekeypath");
if (cert_private_key_path == "") {
if (!is_daemonised){
std::cerr << "certprivatekeypath is required when ssl is enabled" << std::endl;
}
syslog(LOG_ERR, "%s", "certprivatekeypath is required when ssl is enabled");
ret = false;
}
generated_cert_path = findoptionS("generatedcertpath") + "/";
if (generated_cert_path == "/") {
if (!is_daemonised){
std::cerr << "generatedcertpath is required when ssl is enabled" << std::endl;
}
syslog(LOG_ERR, "%s", "generatedcertpath is required when ssl is enabled");
ret = false;
}
time_t gen_cert_start, gen_cert_end;
time_t def_start = 1417872951; // 6th Dec 2014
time_t ten_years = 315532800;
gen_cert_start = findoptionI("generatedcertstart");
if (gen_cert_start < def_start)
gen_cert_start = def_start;
gen_cert_end = findoptionI("generatedcertend");
if (gen_cert_end < gen_cert_start)
gen_cert_end = gen_cert_start + ten_years;
set_cipher_list = findoptionS("setcipherlist");
if (set_cipher_list == "")
set_cipher_list = "HIGH:!ADH:!MD5:!RC4:!SRP:!PSK:!DSS";
if (ret) {
ca = new CertificateAuthority(ca_certificate_path.c_str(),
ca_private_key_path.c_str(),
cert_private_key_path.c_str(),
generated_cert_path.c_str(),
gen_cert_start, gen_cert_end);
} else {
return false;
}
}
#endif
#ifdef ENABLE_EMAIL
// Email notification patch by J. Gauthier
mailer = findoptionS("mailer");
#endif
monitor_helper = findoptionS("monitorhelper");
if (monitor_helper == "") {
monitor_helper_flag = false;
} else {
monitor_helper_flag = true;
}
server_name = findoptionS("servername");
if (server_name == "") {
char sysname[256];
int r;
r = gethostname(sysname, 256);
if (r == 0) {
server_name = sysname;
}
}
max_header_lines = findoptionI("maxheaderlines");
if (max_header_lines == 0)
max_header_lines = 50;
if (!realitycheck(max_header_lines, 10, 250, "maxheaderlines")) {
return false;
}
max_logitem_length = findoptionI("maxlogitemlength");
// default of unlimited no longer allowed as could cause buffer overflow
if (max_logitem_length == 0)
max_logitem_length = 2000;
if (!realitycheck(max_logitem_length, 10, 32000, "maxlogitemlength")) {
return false;
}
connect_timeout_sec = findoptionI("connecttimeout");
if (connect_timeout_sec == 0)
connect_timeout_sec = 5;
if (!realitycheck(connect_timeout_sec, 1, 100, "connecttimeout")) {
return false;
} // check its a reasonable value
connect_timeout = connect_timeout_sec * 1000;
connect_retries = findoptionI("connectretries");
if (connect_retries == 0)
connect_retries = 1;
if (!realitycheck(connect_retries, 1, 100, "connectretries")) {
return false;
} // check its a reasonable value
proxy_timeout_sec = findoptionI("proxytimeout");
if (proxy_timeout_sec == 0) proxy_timeout_sec = 55;
if (!realitycheck(proxy_timeout_sec, 5, 100, "proxytimeout")) {
return false;
} // check its a reasonable value
proxy_timeout = proxy_timeout_sec * 1000;
pcon_timeout_sec = findoptionI("pcontimeout");
if (pcon_timeout_sec == 0) pcon_timeout_sec = 55;
if (!realitycheck(pcon_timeout_sec, 5, 300, "pcontimeout")) {
return false;
} // check its a reasonable value
pcon_timeout = pcon_timeout_sec * 1000;
exchange_timeout_sec = findoptionI("proxyexchange");
if (exchange_timeout_sec == 0) exchange_timeout_sec = 61;
if (!realitycheck(exchange_timeout_sec, 5, 300, "proxyexchange")) {
return false;
}
exchange_timeout = exchange_timeout_sec * 1000;
if (findoptionS("httpworkers").empty()) {
http_workers = 500;
} else {
http_workers = findoptionI("httpworkers");
}
if (!realitycheck(http_workers, 20, 20000, "httpworkers")) {
return false;
} // check its a reasonable value
monitor_helper = findoptionS("monitorhelper");
if (monitor_helper == "") {
monitor_helper_flag = false;
} else {
monitor_helper_flag = true;
}
monitor_flag_prefix = findoptionS("monitorflagprefix");
if (monitor_flag_prefix == "") {
monitor_flag_flag = false;
} else {
monitor_flag_flag = true;
}
max_content_filter_size = findoptionI("maxcontentfiltersize");
if (!realitycheck(max_content_filter_size, 0, 0, "maxcontentfiltersize")) {
return false;
} // check its a reasonable value
if (max_content_filter_size == 0) {
max_content_filter_size = 2048;
}
max_content_filter_size *= 1024;
if(findoptionS("maxcontentramcachescansize").empty()) {
max_content_ramcache_scan_size = 2048;
} else {
max_content_ramcache_scan_size = findoptionI("maxcontentramcachescansize");
}
if (!realitycheck(max_content_ramcache_scan_size, 0, 0, "maxcontentramcachescansize")) {
return false;
}
max_content_ramcache_scan_size *= 1024;
max_content_filecache_scan_size = findoptionI("maxcontentfilecachescansize");
if (!realitycheck(max_content_filecache_scan_size, 0, 0, "maxcontentfilecachescansize")) {
return false;
}
if (max_content_filecache_scan_size == 0) {
max_content_filecache_scan_size = 20000;
}
max_content_filecache_scan_size *= 1024;
if (max_content_ramcache_scan_size == 0) {
max_content_ramcache_scan_size = max_content_filecache_scan_size;
}
if ( findoptionS("weightedphrasemode").empty()) {
weighted_phrase_mode = 2;
} else {
weighted_phrase_mode = findoptionI("weightedphrasemode");
}
if (!realitycheck(weighted_phrase_mode, 0, 2, "weightedphrasemode")) {
return false;
}
bool contentscanning = findoptionM("contentscanner").size() > 0;
if (contentscanning) {
if (max_content_filter_size > max_content_ramcache_scan_size) {
if (!is_daemonised) {
std::cerr << "maxcontentfiltersize can not be greater than maxcontentramcachescansize" << std::endl;
}
syslog(LOG_ERR, "%s", "maxcontentfiltersize can not be greater than maxcontentramcachescansize");
return false;
}
if (max_content_ramcache_scan_size > max_content_filecache_scan_size) {
if (!is_daemonised) {
std::cerr << "maxcontentramcachescansize can not be greater than maxcontentfilecachescansize"
<< std::endl;
}
syslog(LOG_ERR, "%s", "maxcontentramcachescansize can not be greater than maxcontentfilecachescansize");
return false;
}
trickle_delay = findoptionI("trickledelay");
if (trickle_delay == 0) {
trickle_delay = 10;
}
if (!realitycheck(trickle_delay, 1, 0, "trickledelay")) {
return false;
}
initial_trickle_delay = findoptionI("initialtrickledelay");
if (initial_trickle_delay == 0) {
initial_trickle_delay = 20;
}
if (!realitycheck(initial_trickle_delay, 1, 0, "initialtrickledelay")) {
return false;
}
content_scanner_timeout_sec = findoptionI("contentscannertimeout");
if (content_scanner_timeout_sec == 0) content_scanner_timeout_sec = 60;
if (!realitycheck(content_scanner_timeout_sec, 1, 0, "contentscannertimeout")) {
return false;
}
if (content_scanner_timeout_sec > 0)
content_scanner_timeout = content_scanner_timeout_sec * 1000;
else {
content_scanner_timeout = pcon_timeout;
content_scanner_timeout_sec = pcon_timeout_sec;
}
}
if (findoptionS("deletedownloadedtempfiles") == "off") {
delete_downloaded_temp_files = false;
} else {
delete_downloaded_temp_files = true;
}
if (findoptionS("searchsitelistforip"
"") == "off") {
search_sitelist_for_ip = false;
} else {
search_sitelist_for_ip = true;
}
if (findoptionS("phrasefiltermode").empty()) {
phrase_filter_mode = 2;
} else {
phrase_filter_mode = findoptionI("phrasefiltermode");
}
if (!realitycheck(phrase_filter_mode, 0, 3, "phrasefiltermode")) {
return false;
}
preserve_case = findoptionI("preservecase");
if (!realitycheck(preserve_case, 0, 2, "preservecase")) {
return false;
}
if (findoptionS("hexdecodecontent") == "on") {
hex_decode_content = true;
} else {
hex_decode_content = false;
}
if (findoptionS("forcequicksearch") == "on") {
force_quick_search = true;
} else {
force_quick_search = false;
}
if (findoptionS("mapportstoips") == "on") { // to be removed in v5.5
map_ports_to_ips = true;
} else {
map_ports_to_ips = false;
}
if (findoptionS("mapauthtoports") == "on") { // to be removed in v5.5
map_auth_to_ports = true;
} else {
map_auth_to_ports = false;
}
if (findoptionS("usecustombannedimage") == "off") {
use_custom_banned_image = false;
} else {
use_custom_banned_image = true;
custom_banned_image_file = findoptionS("custombannedimagefile");
if (custom_banned_image_file.empty()) {
custom_banned_image_file = __DATADIR;
custom_banned_image_file += "/transparent1x1.gif";
}
banned_image.read(custom_banned_image_file.c_str());
}
if (findoptionS("usecustombannedflash") == "off") {
use_custom_banned_flash = false;
} else {
use_custom_banned_flash = true;
custom_banned_flash_file = findoptionS("custombannedflashfile");
if (custom_banned_flash_file.empty()) {
custom_banned_flash_file = __DATADIR;
custom_banned_flash_file += "/blockedflash.swf";
}
banned_flash.read(custom_banned_flash_file.c_str());
}
proxy_ip = findoptionS("proxyip");
if (proxy_ip == "")
no_proxy = true;
else
no_proxy = false;
if (!no_proxy) {
proxy_port = findoptionI("proxyport");
if(proxy_port == 0) proxy_port = 3128;
if (!realitycheck(proxy_port, 1, 65535, "proxyport")) {
return false;
} // etc
}
// multiple listen IP support
filter_ip = findoptionMD("filterip",":");
if( filter_ip.empty()) filter_ip.push_back("");
if (filter_ip.size() > 127) {
if (!is_daemonised) {
std::cerr << "Can not listen on more than 127 IPs" << std::endl;
}
syslog(LOG_ERR, "%s", "Can not listen on more than 127 IPs");
return false;
}
// multiple check IP support - used for loop checking
check_ip = findoptionMD("checkip",":");
if (check_ip.size() > 127) {
if (!is_daemonised) {
std::cerr << "Can not check on more than 127 IPs" << std::endl;
}
syslog(LOG_ERR, "%s", "Can not check on more than 127 IPs");
return false;
}
if (check_ip.empty()) {
String t = "127.0.0.1";
check_ip.push_back(t);
}
filter_ports = findoptionMD("filterports",":");
if (filter_ports.empty())
filter_ports.push_back("8080");
if (map_ports_to_ips and filter_ports.size() != filter_ip.size()) {
if (!is_daemonised) {
std::cerr << "filterports (" << filter_ports.size() << ") must match number of filterips ("
<< filter_ip.size() << ")" << std::endl;
}
syslog(LOG_ERR, "%s", "filterports must match number of filterips");
return false;
}
filter_port = filter_ports[0].toInteger();
if (!realitycheck(filter_port, 1, 65535, "filterport[0]")) {
return false;
} // check its a reasonable value
check_ports = findoptionMD("extracheckports", ":");
// now add filter_ports to check_ports
for (auto pt : filter_ports) {
check_ports.push_back(pt);
}
transparenthttps_port = findoptionI("transparenthttpsport");
if (!realitycheck(transparenthttps_port, 0, 65535, "transparenthttpsport")) {
return false;
} // check its a reasonable value
icap_port = findoptionI("icapport");
if (!realitycheck(filter_port, 0, 65535, "icapport")) {
return false;
} // check its a reasonable value
if (icap_port > 0) { // add non-plugin auth for ICAP
auth_entry sen;
sen.entry_function = "auth_icap";
sen.entry_id = ENT_STORYA_AUTH_ICAP;
auth_entry_dq.push_back(sen);
}
icap_reqmod_url = findoptionS("icapreqmodurl");
if (icap_reqmod_url == "")
icap_reqmod_url = "request";
icap_resmod_url = findoptionS("icapresmodurl");
if (icap_resmod_url == "")
icap_resmod_url = "response";
if (findoptionS("useoriginalip") == "off") {
use_original_ip_port = false;
} else {
use_original_ip_port = true;
}
if(findoptionS("loglevel").empty()) {
ll = 3;
} else {
ll = findoptionI("loglevel");
}
if (!realitycheck(ll, 0, 3, "loglevel")) {
return false;
} // etc
log_file_format = findoptionI("logfileformat");
if(log_file_format == 0) log_file_format = 8;
if (!realitycheck(log_file_format, 1, 8, "logfileformat")) {
return false;
} // etc
if (findoptionS("anonymizelogs") == "on") {
anonymise_logs = true;
} else {
anonymise_logs = false;
}
if (findoptionS("logadblocks") == "on") {
log_ad_blocks = true;
} else {
log_ad_blocks = false;
}
if (findoptionS("logtimestamp") == "on") {
log_timestamp = true;
} else {
log_timestamp = false;
}
if (findoptionS("loguseragent") == "on") {
log_user_agent = true;
} else {
log_user_agent = false;
}
if (findoptionS("usedashforblank") == "off") {
use_dash_for_blanks = false;
} else {
use_dash_for_blanks = true;
}
if (findoptionS("logclientnameandip") == "off") {
log_client_host_and_ip = false;
} else {
log_client_host_and_ip = true;
}
logid_1.assign(findoptionS("logid1"));
if (logid_1.empty())
logid_1.assign("-");
logid_2.assign(findoptionS("logid2"));
if (logid_2.empty())
logid_2.assign("-");
#ifdef SG_LOGFORMAT
prod_id.assign(findoptionS("productid"));
if (prod_id.empty())
// SG '08
prod_id.assign("2");
#endif
if (findoptionS("showweightedfound") == "off") {
show_weighted_found = false;
} else {
show_weighted_found = true;
}
if (findoptionS("showallweightedfound") == "on") {
show_all_weighted_found = true;
show_weighted_found = true;
} else {
show_all_weighted_found = false;
}
if(findoptionS("reportinglevel").empty()) {
reporting_level = 3;
} else {
reporting_level = findoptionI("reportinglevel");
}
if (!realitycheck(reporting_level, -1, 3, "reportinglevel")) {
return false;
}
String t = findoptionS("languagedir") + "/" ;
if (t == "/") {
t = __DATADIR;
t += "/languages";
}
languagepath = t;
languagepath += "/";
languagepath += findoptionS("language") + "/";
if (findoptionS("forwardedfor") == "on") {
forwarded_for = true;
} else {
forwarded_for = false;
}
if (findoptionS("addforwardedfor") == "on") {
forwarded_for = true;
}
if (findoptionS("logexceptionhits").empty()) {
log_exception_hits = 2;
} else {
log_exception_hits = findoptionI("logexceptionhits");
}
if (!realitycheck(log_exception_hits, 0, 2, "logexceptionhits")) {
return false;
}
if (findoptionS("logconnectionhandlingerrors") == "on") {
logconerror = true;
} else {
logconerror = false;
}
if (findoptionS("logchildprocesshandling") == "on") {
logchildprocs = true;
} else {
logchildprocs = false;
}
if (findoptionS("logsslerrors") == "on") {
log_ssl_errors = true;
} else {
log_ssl_errors = false;
}
if (findoptionS("reverseaddresslookups") == "on") {
reverse_lookups = true;
} else {
reverse_lookups = false;
}
if (findoptionS("reverseclientiplookups") == "on") {
reverse_client_ip_lookups = true;
} else {
reverse_client_ip_lookups = false;
}
if (findoptionS("logclienthostnames") == "on") {
log_client_hostnames = true;
reverse_client_ip_lookups = true;
} else {
log_client_hostnames = false;
}
if (findoptionS("recheckreplacedurls") == "on") {
recheck_replaced_urls = true;
} else {
recheck_replaced_urls = false;
}
if (findoptionS("usexforwardedfor") == "on") {
use_xforwardedfor = true;
} else {
use_xforwardedfor = false;
}
xforwardedfor_filter_ip = findoptionM("xforwardedforfilterip");
filter_groups = findoptionI("filtergroups");
if (filter_groups == 0) filter_groups = 1;
default_fg = findoptionI("defaultfiltergroup");
if (default_fg > 0) {
if (default_fg <= filter_groups) {
default_fg--;
} else {
syslog(LOG_ERR, "defaultfiltergroup out of range");
return false;
}
}
default_trans_fg = findoptionI("defaulttransparentfiltergroup");
if (default_trans_fg > 0) {
if (default_trans_fg <= filter_groups) {
default_trans_fg--;
} else {
syslog(LOG_ERR, "defaulttransparentfiltergroup out of range");
return false;
}
}
default_icap_fg = findoptionI("defaulticapfiltergroup");
if (default_icap_fg > 0) {
if (default_icap_fg <= filter_groups) {
default_icap_fg--;
} else {
syslog(LOG_ERR, "defaulticapfiltergroup out of range");
return false;
}
}
if (findoptionS("abortiflistmissing") == "on") {
abort_on_missing_list = true;
} else {
abort_on_missing_list = false;
}
if (findoptionS("storyboardtrace") == "on") {
SB_trace = true;
} else {
SB_trace = false;
}
storyboard_location = findoptionS("preauthstoryboard");
if (storyboard_location.empty()) {
storyboard_location = __CONFDIR;
storyboard_location += "/preauth.story";
}
per_room_directory_location = findoptionS("perroomdirectory");
if (!realitycheck(filter_groups, 1, 0, "filtergroups")) {
return false;
}
if (filter_groups < 1) {
if (!is_daemonised) {
std::cerr << "filtergroups too small" << std::endl;
}
return false;
}
if ((internal_test_url = findoptionS("internaltesturl")).empty()) {
internal_test_url = "internal.test.e2guardian.org";
}
if ((internal_status_url = findoptionS("internalstatusurl")).empty()) {
internal_status_url = "internal.status.e2guardian.org";
}
if (!loadDMPlugins()) {
if (!is_daemonised) {
std::cerr << "Error loading DM plugins" << std::endl;
}
syslog(LOG_ERR, "Error loading DM plugins");
return false;
}
// this needs to be known before loading CS plugins,
// because ClamAV plugin makes use of it during init()
download_dir = findoptionS("filecachedir");
if (download_dir.empty()) {
download_dir = "/tmp";
}
if (contentscanning) {
if (!loadCSPlugins()) {
if (!is_daemonised) {
std::cerr << "Error loading CS plugins" << std::endl;
}
syslog(LOG_ERR, "Error loading CS plugins");
return false;
}
}
if (!loadAuthPlugins()) {
if (!is_daemonised) {
std::cerr << "Error loading auth plugins" << std::endl;
}
syslog(LOG_ERR, "Error loading auth plugins");
return false;
}
// check if same number of auth-plugin as ports if in
// authmaptoport mode
if (map_auth_to_ports && (filter_ports.size() > 1)
&& (filter_ports.size() != authplugins.size())) {
std::cerr << "In mapauthtoports mode you need to setup one port per auth plugin" << std::endl;
return false;
}
// map port numbers to auth plugin names
for (unsigned int i = 0; i < authplugins.size(); i++) {
AuthPlugin *tmpPlugin = (AuthPlugin *) authplugins[i];
String tmpStr = tmpPlugin->getPluginName();
if ((!map_auth_to_ports) || filter_ports.size() == 1)
auth_map[i] = tmpStr;
else
auth_map[filter_ports[i].toInteger()] = tmpStr;
}
// if the more than one port is being used, validate the combination of auth plugins
if (authplugins.size() > 1 and filter_ports.size() > 1 and map_auth_to_ports) {
std::deque<Plugin *>::iterator it = authplugins.begin();
String firstPlugin;
while (it != authplugins.end()) {
AuthPlugin *tmp = (AuthPlugin *) *it;
if (tmp->getPluginName().startsWith("proxy-basic")) {
if (!is_daemonised)
std::cerr << "Proxy auth is not possible with multiple ports" << std::endl;
syslog(LOG_ERR, "Proxy auth is not possible with multiple ports");
return false;
}
if (tmp->getPluginName().startsWith("proxy-ntlm") && (tmp->isTransparent() == false)) {
if (!is_daemonised)
std::cerr << "Non-transparent NTLM is not possible with multiple ports" << std::endl;
syslog(LOG_ERR, "Non-transparent NTLM is not possible with multiple ports");
return false;
}
if (it == authplugins.begin())
firstPlugin = tmp->getPluginName();
else {
if ((firstPlugin == tmp->getPluginName()) and (!tmp->getPluginName().startsWith("ssl-core"))) {
if (!is_daemonised)
std::cerr << "Auth plugins can not be the same" << std::endl;
syslog(LOG_ERR, "Auth plugins can not be the same");
return false;
}
}
*it++;
}
}
// if there's no auth enabled, we only need the first group's settings - THIS IS NO LONGER THE CASE TRANs, ICAP canbe set to different defaults
//if (authplugins.size() == 0)
// filter_groups = 1;
numfg = filter_groups;
//filter_groups_list_location = findoptionS("filtergroupslist");
// banned_ip_list_location = findoptionS("bannediplist");
group_names_list_location = findoptionS("groupnamesfile");
std::string language_list_location(languagepath + "messages");
iplist_dq = findoptionM("iplist");