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 "FOptionContainer.hpp"
11 #include "DownloadManager.hpp"
12 #include "ContentScanner.hpp"
13 #include "String.hpp"
14 #include "HTMLTemplate.hpp"
15 #include "ListContainer.hpp"
16 #include "ListManager.hpp"
17 #include "LanguageContainer.hpp"
18 #include "ImageContainer.hpp"
19 #include "RegExp.hpp"
20 #include "Auth.hpp"
21 #include "IPList.hpp"
22 #include "Queue.hpp"
23 #include "LOptionContainer.hpp"
24 #include "DebugManager.hpp"
25 #include <deque>
26 #include <atomic>
27 
28 #ifdef __SSLMITM
29 #include "CertificateAuthority.hpp"
30 #endif
31 
32 
33 // DECLARATIONS
34 
35 class OptionContainer
36 {
37     public:
38     Queue<std::string>* log_Q;
39     Queue<std::string>* RQlog_Q;
40     Queue<LQ_rec> http_worker_Q;
41 
42 #ifndef NEWDEBUG_OFF
43     std::string debuglevel;
44     std::string path_debuglevel;
45     DebugManager * myDebug;
46 #endif
47 
48     // all our many, many options
49     int filter_groups = 0;
50     int log_exception_hits = 0;
51     bool non_standard_delimiter;
52     int log_file_format = 0;
53     std::string log_header_value;
54     std::string ident_header_value;
55     int weighted_phrase_mode = 0; // PIP added in - not sure if still required
56     bool show_weighted_found = false;
57     bool forwarded_for = false;
58     bool use_custom_banned_image = false;
59     std::string custom_banned_image_file;
60     bool use_custom_banned_flash = false;
61     std::string custom_banned_flash_file;
62     bool reverse_lookups = false;
63     bool reverse_client_ip_lookups = false;
64     bool log_client_hostnames = false;
65     bool use_xforwardedfor = false;
66     std::deque<String> xforwardedfor_filter_ip;
67     bool logconerror = false;
68     bool logchildprocs = false;
69     bool log_ssl_errors = false;
70     int url_cache_number = 0;
71     int url_cache_age = 0;
72     int phrase_filter_mode = 0;
73     int preserve_case = 0;
74     unsigned int max_header_lines = 0;
75     int default_fg = 0;
76     int default_trans_fg = 0;
77     int default_icap_fg = 0;
78 
79     bool hex_decode_content = false;
80     bool force_quick_search = false;
81     bool map_auth_to_ports = false;
82     bool map_ports_to_ips = false;
83     int filter_port = 0;
84     int proxy_port = 0;
85     bool no_proxy = false;
86     int transparenthttps_port = 0;
87     int icap_port = 0;
88     std::string icap_reqmod_url;
89     std::string icap_resmod_url;
90     std::string proxy_ip;
91     std::deque<String> filter_ip;
92     std::deque<String> check_ip;
93     std::deque<String> filter_ports;
94     std::map<int, String> auth_map;
95     bool abort_on_missing_list = false;
96     bool SB_trace = false;
97 #ifdef ENABLE_ORIG_IP
98     bool get_orig_ip = false;
99 #endif
100     int ll = 0;
101     int connect_timeout = 0;
102     int connect_timeout_sec = 0;
103     int connect_retries = 0;
104     int proxy_timeout = 0;
105     int proxy_timeout_sec = 0;
106     int proxy_failure_log_interval = 0;
107     int exchange_timeout = 0;
108     int exchange_timeout_sec = 0;
109     int pcon_timeout = 0;
110     int pcon_timeout_sec = 0;
111     int http_workers = 0;
112     std::string daemon_user_name;
113     std::string daemon_group_name;
114     int proxy_user = 0;
115     int proxy_group = 0;
116     int root_user = 0;
117     int max_ips = 0;
118     bool recheck_replaced_urls;
119     bool use_filter_groups_list = false;
120     bool use_group_names_list = false;
121     bool auth_needs_proxy_query = false;
122     bool auth_requires_user_and_group = false;
123     bool enable_ssl = false;
124     bool auth_needs_proxy_in_plugin = false;
125 
126     bool prefer_cached_lists = false;
127     std::string languagepath;
128     std::string filter_groups_list_location;
129     std::string banned_ip_list_location;
130     std::string exception_ip_list_location;
131     std::string log_location;
132     std::string RQlog_location;
133     bool log_requests = false;
134     std::string stat_location;
135     std::string ipc_filename;
136     std::string urlipc_filename;
137     std::string ipipc_filename;
138     std::string pid_filename;
139     std::string blocked_content_store;
140     std::string monitor_helper;
141     bool monitor_helper_flag = false;
142     std::string monitor_flag_prefix;
143     bool monitor_flag_flag = false;
144     std::string dstat_location;
145     bool dstat_log_flag = false;
146     bool stats_human_readable = false;
147     int dstat_interval = 300;
148     bool dns_user_logging = false;
149     std::string dns_user_logging_domain;
150 
151     // Hardware/organisation/etc. IDs
152     std::string logid_1;
153     std::string logid_2;
154 
155     bool no_daemon = false;
156     bool e2_front_log = false;
157     bool no_logger = false;
158     bool log_syslog = false;
159     std::string name_suffix;
160     unsigned int max_logitem_length = 2000;
161     bool anonymise_logs = false;
162     bool log_ad_blocks = false;
163     bool log_timestamp = false;
164     bool log_user_agent = false;
165     bool soft_restart = false;
166 
167 #ifdef __SSLMITM
168     std::string ssl_certificate_path;
169 #endif
170 
171 #ifdef __SSLMITM
172     std::string ca_certificate_path;
173     std::string ca_private_key_path;
174     std::string cert_private_key_path;
175     std::string generated_cert_path;
176     std::string generated_link_path;
177     std::string openssl_conf_path;
178     CertificateAuthority *ca;
179     bool use_openssl_conf = false;
180     bool have_openssl_conf = false;
181 #endif
182     std::string set_cipher_list;
183 
184 #ifdef ENABLE_EMAIL
185     // Email notification patch by J. Gauthier
186     std::string mailer;
187 #endif
188 
189     std::string storyboard_location;
190 
191     std::deque<String> iplist_dq;
192     std::deque<String> sitelist_dq;
193     std::deque<String> ipsitelist_dq;
194     std::deque<String> urllist_dq;
195 
196     std::string daemon_user;
197     std::string daemon_group;
198     off_t max_content_filter_size;
199     off_t max_content_ramcache_scan_size;
200     off_t max_content_filecache_scan_size;
201     bool scan_clean_cache = false;
202     bool content_scan_exceptions = false;
203     bool delete_downloaded_temp_files = false;
204     bool search_sitelist_for_ip = false;
205     std::string download_dir;
206     int initial_trickle_delay = 0;
207     int trickle_delay = 0;
208     int content_scanner_timeout = 0;
209     int content_scanner_timeout_sec = 0;
210 
211     HTMLTemplate html_template;
212     ListContainer filter_groups_list;
213     LanguageContainer language_list;
214     ImageContainer banned_image;
215     ImageContainer banned_flash;
216 
217     std::deque<Plugin *> dmplugins;
218     std::deque<Plugin *> csplugins;
219     std::deque<Plugin *> authplugins;
220     std::deque<Plugin *>::iterator dmplugins_begin;
221     std::deque<Plugin *>::iterator dmplugins_end;
222     std::deque<Plugin *>::iterator csplugins_begin;
223     std::deque<Plugin *>::iterator csplugins_end;
224     std::deque<Plugin *>::iterator authplugins_begin;
225     std::deque<Plugin *>::iterator authplugins_end;
226 
227     ListManager lm;
228     int numfg = 0;
229 
230     // access denied domain (when using the CGI)
231     String access_denied_domain;
232 
233     bool loadCSPlugins();
234     bool loadAuthPlugins();
235     void deletePlugins(std::deque<Plugin *> &list);
236  //   void deleteFilterGroups();
237   //  void deleteFilterGroupsJustListData();
238 
239     //...and the functions that read them
240 
241     OptionContainer();
242     ~OptionContainer();
243     bool read(std::string& filename, int type);
244     void reset();
245   //  bool inExceptionIPList(const std::string *ip, std::string *&host);
246   //  bool inBannedIPList(const std::string *ip, std::string *&host);
247     //bool readFilterGroupConf();
248     // public so fc_controlit can reload filter group config files
249 //    bool doReadItemList(const char *filename, ListContainer *lc, const char *fname, bool swsort);
250 
251     const char *inSiteList(String &url, ListContainer *lc, bool swsort, bool ip);
252     char *inURLList(String &url, ListContainer *lc, bool swsort, bool ip);
253 
254     //bool readStdin(ListContainer *lc, bool swsort, const char *listname );
255     bool readinStdin();
256   //  bool inTotalBlockList(String &url);
257     bool use_total_block_list = false;
258     std::string per_room_directory_location;
259     bool createLists(int load_id);
260     std::shared_ptr<LOptionContainer> currentLists();
261     std::atomic<int> LC_cnt;
262 
263     //LOptionContainer* current_LOC;
264     std::shared_ptr<LOptionContainer> current_LOC;
265     std::string conffilename;
266  //   std::string html_template_location;
267     std::string group_names_list_location;
268 
269     private:
270     std::deque<std::string> conffile;
271     int reporting_level = 0;
272 
273 
274     bool loadDMPlugins();
275 
276   //  bool precompileregexps();
277     long int findoptionI(const char *option);
278     std::string findoptionS(const char *option);
279     bool realitycheck(long int l, long int minl, long int maxl, const char *emessage);
280    // bool readAnotherFilterGroupConf(const char *filename, const char *groupname, bool &need_html);
281     std::deque<String> findoptionM(const char *option);
282 
283 //    bool inIPList(const std::string *ip, ListContainer &list, std::string *&host);
284 };
285 
286 #endif
287