Implemented logic for ability to activate webcheck through signals.
[bpdyndnsd] / src / config.cpp
1 /** @file
2  * @brief Config class implementation. This class represents the actual configuration.
3  *
4  *
5  *
6  * @copyright Intra2net AG
7  * @license GPLv2
8 */
9
10 #include "config.h"
11
12 #include "service_dhs.h"
13 #include "service_ods.h"
14 #include "service_dyndns.h"
15 #include "service_dyns.h"
16 #include "service_easydns.h"
17 #include "service_tzo.h"
18 #include "service_zoneedit.h"
19 #include "service_gnudip.h"
20
21 #include <time.h>
22 #include <iostream>
23 #include <fstream>
24
25 #include <boost/foreach.hpp>
26 #include <boost/filesystem.hpp>
27 #include <boost/regex.hpp>
28 #include <boost/algorithm/string.hpp>
29
30
31 namespace po = boost::program_options;
32 namespace fs = boost::filesystem;
33 namespace ba = boost::algorithm;
34
35 typedef boost::shared_ptr<boost::program_options::options_description> Options_descriptionPtr;
36
37 using namespace std;
38
39
40 /**
41  * Default Constructor. Available command line and config file options with their default values are defined here.
42  */
43 Config::Config()
44     : Log(new Logger)
45     , ServiceHolder(new Serviceholder)
46     , DaemonMode(false)
47     , Syslog(false)
48     , EnableIPv6(false)
49     , Loglevel(0)
50     , ConfigPath("/etc/bpdyndnsd")
51     , WebcheckInterval(0)
52     , ProxyPort(0)
53     , ExternalWarningLog("")
54     , ExternalWarningLevel(0)
55     , StartOffline(false)
56     , WebcheckEnabled(false)
57 {
58     // Available service description config options
59     po::options_description opt_desc_service("Service description options");
60     opt_desc_service.add_options()
61         ("protocol",po::value<string>(),"The service protocol.")
62         ("server",po::value<string>(),"Servername needed for gnudip protocol.")
63         ("host",po::value<string>(),"The hostname to update.")
64         ("login",po::value<string>(),"Login name.")
65         ("password",po::value<string>(),"Corresponding password.")
66         ("update_interval",po::value<int>()->default_value(-1),"Update interval in minutes.")
67         ("max_updates_within_interval",po::value<int>()->default_value(-1),"How many updates can be made in one interval.")
68         ("dns_cache_ttl",po::value<int>()->default_value(-1),"How long a dns record is valid.")
69     ;
70
71     // Available command line only options
72     po::options_description opt_desc_cmd_only("Command line only options");
73     opt_desc_cmd_only.add_options()
74         ("help,?","Show help.")
75         ("version,v","Show version.")
76         ("config,c",po::value<string>()->default_value("/etc/bpdyndnsd"),"Set the config path.")
77     ;
78
79      // Available generic options. Valid on cmd or in config file.
80     po::options_description opt_desc_generic("Generic config options");
81     opt_desc_generic.add_options()
82         ("daemon_mode",po::value<bool>()->default_value(false),"Run as system daemon.")
83         ("loglevel",po::value<int>()->default_value(0),"Loglevel.")
84         ("syslog",po::value<bool>()->default_value(false),"Use syslog facility.")
85         ("enable_ipv6",po::value<bool>()->default_value(false),"Try to use IPv6.")
86         ("webcheck_enabled",po::value<bool>()->default_value(false),"Use webcheck url to determine actual IP address.")
87         ("webcheck_url",po::value<string>()->default_value(""),"Use this URL to determine IP.")
88         ("webcheck_url_alt",po::value<string>()->default_value(""),"Use this alternative URL to determine IP.")
89         ("webcheck_interval",po::value<int>()->default_value(10),"The webcheck interval in minutes.")
90         ("http_proxy",po::value<string>(),"Use this proxy for all http requests.")
91         ("http_proxy_port",po::value<int>(),"Port of the proxy.")
92         ("external_warning_log",po::value<string>()->default_value(""),"External programm to pass warning log messages to.")
93         ("external_warning_level",po::value<int>()->default_value(0),"Warning messages of which loglevel should be passed to external programm.")
94         ("start_offline",po::value<bool>()->default_value(false),"Start in offline mode.")
95     ;
96
97     // Define valid command line parameters
98     OptDescCmd = Options_descriptionPtr(new po::options_description("Command line options"));
99     OptDescCmd->add(opt_desc_cmd_only);
100     OptDescCmd->add(opt_desc_generic);
101     OptDescCmd->add(opt_desc_service);
102
103     // Define valid config file options
104     OptDescConfMain = Options_descriptionPtr(new po::options_description("Config file options"));
105     OptDescConfMain->add(opt_desc_generic);
106
107     // Define valid service file options
108     OptDescConfService = Options_descriptionPtr(new po::options_description("Service file options"));
109     OptDescConfService->add(opt_desc_service);
110 }
111
112
113 /**
114  * Constructor with Logger and Serviceholder objects. Available command line and config file options with their default values are defined here.
115  */
116 Config::Config(Logger::Ptr _log, Serviceholder::Ptr _serviceholder)
117     : Log(_log)
118     , ServiceHolder(_serviceholder)
119     , DaemonMode(false)
120     , Syslog(false)
121     , EnableIPv6(false)
122     , Loglevel(0)
123     , ConfigPath("/etc/bpdyndnsd")
124     , WebcheckInterval(0)
125     , ProxyPort(0)
126     , ExternalWarningLog("")
127     , ExternalWarningLevel(0)
128     , StartOffline(false)
129     , WebcheckEnabled(false)
130 {
131     // Available service description config options
132     po::options_description opt_desc_service("Service description options");
133     opt_desc_service.add_options()
134         ("protocol",po::value<string>(),"The service protocol.")
135         ("server",po::value<string>(),"Servername needed for gnudip protocol.")
136         ("host",po::value<string>(),"The hostname to update.")
137         ("login",po::value<string>(),"Login name.")
138         ("password",po::value<string>(),"Corresponding password.")
139         ("update_interval",po::value<int>()->default_value(-1),"Update interval in minutes.")
140         ("max_updates_within_interval",po::value<int>()->default_value(-1),"How many updates can be made in one interval.")
141         ("dns_cache_ttl",po::value<int>()->default_value(-1),"How long a dns record is valid.")
142     ;
143
144     // Available command line only options
145     po::options_description opt_desc_cmd_only("Command line only options");
146     opt_desc_cmd_only.add_options()
147         ("help,?","Show help.")
148         ("version,v","Show version.")
149         ("config,c",po::value<string>()->default_value("/etc/bpdyndnsd"),"Set the config path.")
150     ;
151
152      // Available generic options. Valid on cmd or in config file.
153     po::options_description opt_desc_generic("Generic config options");
154     opt_desc_generic.add_options()
155         ("daemon_mode",po::value<bool>()->default_value(false),"Run as system daemon.")
156         ("loglevel",po::value<int>()->default_value(0),"Loglevel.")
157         ("syslog",po::value<bool>()->default_value(false),"Use syslog facility.")
158         ("enable_ipv6",po::value<bool>()->default_value(false),"Try to use IPv6.")
159         ("webcheck_enabled",po::value<bool>()->default_value(false),"Use webcheck url to determine actual IP address.")
160         ("webcheck_url",po::value<string>()->default_value(""),"Use this URL to determine IP.")
161         ("webcheck_url_alt",po::value<string>()->default_value(""),"Use this alternative URL to determine IP.")
162         ("webcheck_interval",po::value<int>()->default_value(10),"The webcheck interval in minutes.")
163         ("http_proxy",po::value<string>(),"Use this proxy for all http requests.")
164         ("http_proxy_port",po::value<int>(),"Port of the proxy.")
165         ("external_warning_log",po::value<string>()->default_value(""),"External programm to pass warning log messages to.")
166         ("external_warning_level",po::value<int>()->default_value(0),"Warning messages of which loglevel should be passed to external programm.")
167         ("start_offline",po::value<bool>()->default_value(false),"Start in offline mode.")
168     ;
169
170     // Define valid command line parameters
171     OptDescCmd = Options_descriptionPtr(new po::options_description("Command line options"));
172     OptDescCmd->add(opt_desc_cmd_only);
173     OptDescCmd->add(opt_desc_generic);
174     OptDescCmd->add(opt_desc_service);
175
176     // Define valid config file options
177     OptDescConfMain = Options_descriptionPtr(new po::options_description("Config file options"));
178     OptDescConfMain->add(opt_desc_generic);
179
180     // Define valid service file options
181     OptDescConfService = Options_descriptionPtr(new po::options_description("Service file options"));
182     OptDescConfService->add(opt_desc_service);
183 }
184
185
186 /**
187  * Default Destructor
188  */
189 Config::~Config()
190 {
191 }
192
193
194 /**
195  * Parses the command line arguments and does the needed actions.
196  * @param argc Command line argument number given to main.
197  * @param argv[] Pointer to command line argument array given to main.
198  * @return 0 if all is fine, -1 if not.
199  */
200 int Config::parse_cmd_line(int argc, char *argv[])
201 {
202     try
203     {
204         po::store(po::parse_command_line(argc, argv, *this->OptDescCmd), VariablesMap);
205         po::notify(VariablesMap);
206
207         if ( VariablesMap.count("help") )
208         {
209             Log->print_usage(OptDescCmd);
210             return -1;
211         }
212         else if ( VariablesMap.count("version") )
213         {
214             Log->print_version();
215             return -1;
216         }
217
218         // Create a service object if all needed options are set on the command line
219         if ( VariablesMap.count("protocol") && VariablesMap.count("host") && VariablesMap.count("login") && VariablesMap.count("password") )
220         {
221             // Get the cmd parameter values for protocol host login and password
222             string protocol = VariablesMap["protocol"].as<string>();
223             string host = VariablesMap["host"].as<string>();
224             string login = VariablesMap["login"].as<string>();
225             string password = VariablesMap["password"].as<string>();
226
227             protocol = ba::to_lower_copy(protocol);
228
229             string server;
230             if ( VariablesMap.count("server") )
231                 server = VariablesMap["server"].as<string>();
232
233             int update_interval = 0;
234             if ( VariablesMap.count("update_interval") )
235                 update_interval = VariablesMap["update_interval"].as<int>();
236
237             int max_updates_within_interval = 0;
238             if ( VariablesMap.count("max_updates_within_interval") )
239                 max_updates_within_interval = VariablesMap["max_updates_within_interval"].as<int>();
240
241             int dns_cache_ttl = 0;
242             if ( VariablesMap.count("dns_cache_ttl") )
243                 dns_cache_ttl = VariablesMap["dns_cache_ttl"].as<int>();
244
245             Service::Ptr service = create_service(protocol,server,host,login,password,update_interval,max_updates_within_interval,dns_cache_ttl);
246             if ( service )
247             {
248                 ServiceHolder->add_service(service);
249                 Log->print_service_object("New Service object from command line options:", service->get_protocol(), service->get_hostname(), service->get_login() ,service->get_password(), service->get_update_interval(), service->get_max_updates_within_interval(), service->get_dns_cache_ttl() , service->get_actual_ip(), service->get_last_updates());
250             }
251             else
252                 return -1;
253         }
254         else if ( VariablesMap.count("protocol") || VariablesMap.count("host") || VariablesMap.count("login") || VariablesMap.count("password") )
255         {
256             Log->print_missing_cmd_service_option();
257             Log->print_usage(OptDescCmd);
258             return -1;
259         }
260
261         if ( VariablesMap.count("config") )
262         {
263             fs::path full_config_path = fs::system_complete(fs::path(VariablesMap["config"].as<string>()));
264             ConfigPath = full_config_path.string();
265             if ( !fs::exists(full_config_path) ||  !fs::is_directory(full_config_path) )
266             {
267                 // Config path doesn't exist or is not a directory
268                 Log->print_error_config_path(ConfigPath);
269                 return -1;
270             }
271         }
272
273         if ( VariablesMap.count("daemon_mode") )
274             DaemonMode = VariablesMap["daemon_mode"].as<bool>();
275
276         if ( VariablesMap.count("loglevel") )
277             Loglevel = VariablesMap["loglevel"].as<int>();
278
279         if ( VariablesMap.count("syslog") )
280             Syslog = VariablesMap["syslog"].as<bool>();
281
282         if ( VariablesMap.count("enable_ipv6") )
283             EnableIPv6 = VariablesMap["enable_ipv6"].as<bool>();
284
285         if ( VariablesMap.count("webcheck_enabled") )
286             WebcheckEnabled = VariablesMap["webcheck_enabled"].as<bool>();
287
288         if ( VariablesMap.count("webcheck_url") )
289             WebcheckIpUrl = VariablesMap["webcheck_url"].as<string>();
290
291         if ( VariablesMap.count("webcheck_url_alt") )
292             WebcheckIpUrlAlt = VariablesMap["webcheck_url_alt"].as<string>();
293
294         if ( VariablesMap.count("webcheck_interval") )
295             WebcheckInterval = VariablesMap["webcheck_interval"].as<int>();
296
297         if ( VariablesMap.count("http_proxy") && VariablesMap.count("http_proxy_port") )
298         {
299             Proxy = VariablesMap["http_proxy"].as<string>();
300             ProxyPort = VariablesMap["http_proxy_port"].as<int>();
301         }
302         else if ( VariablesMap.count("http_proxy") || VariablesMap.count("http_proxy_port") )
303         {
304             Log->print_missing_cmd_proxy_option();
305             Log->print_usage(OptDescCmd);
306             return -1;
307         }
308
309         if ( VariablesMap.count("external_warning_log") )
310             ExternalWarningLog = VariablesMap["external_warning_log"].as<string>();
311
312         if ( VariablesMap.count("external_warning_level") )
313             ExternalWarningLevel = VariablesMap["external_warning_level"].as<int>();
314
315         if ( VariablesMap.count("start_offline") )
316             StartOffline = VariablesMap["start_offline"].as<bool>();
317
318     }
319     catch( const po::unknown_option& e )
320     {
321         Log->print_unknown_cmd_option(e.what());
322         Log->print_usage(OptDescCmd);
323         return -1;
324     }
325     catch( const po::multiple_occurrences& e )
326     {
327         Log->print_multiple_cmd_option(e.what());
328         Log->print_usage(OptDescCmd);
329         return -1;
330     }
331     catch( const po::error& e )
332     {
333         Log->print_error_parsing_cmd(e.what());
334         Log->print_usage(OptDescCmd);
335         return -1;
336     }
337     return 0;
338 }
339
340
341 /**
342  * Creates a Service object from the given parameters.
343  * @param protocol Protocol to use.
344  * @param host Hostname to update.
345  * @param login Login.
346  * @param password Password.
347  * @return A pointer to the created Service object.
348  */
349 Service::Ptr Config::create_service(const string &protocol, const string& server, const string& hostname, const string& login, const string& password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl)
350 {
351     // Test for valid hostname. Must contain 3 parts minimum.
352     list<string> fqhn_parts;
353     ba::split(fqhn_parts,hostname,boost::is_any_of("."));
354     if ( fqhn_parts.size() < 3 )
355     {
356         Log->print_invalid_hostname(protocol);
357         Service::Ptr service;
358         return service;
359     }
360
361     if(protocol == "dhs")
362     {
363         Service::Ptr service_dhs(new ServiceDhs(protocol,hostname,login,password,Log,update_interval,max_updates_within_interval,dns_cache_ttl,Proxy,ProxyPort));
364         return service_dhs;
365     }
366     else if(protocol == "ods")
367     {
368         Service::Ptr service_ods(new ServiceOds(protocol,hostname,login,password,Log,update_interval,max_updates_within_interval,dns_cache_ttl));
369         return service_ods;
370     }
371     else if(protocol == "dyndns")
372     {
373         Service::Ptr service_dyndns(new ServiceDyndns(protocol,hostname,login,password,Log,update_interval,max_updates_within_interval,dns_cache_ttl,Proxy,ProxyPort));
374         return service_dyndns;
375     }
376     else if(protocol == "dyns")
377     {
378         Service::Ptr service_dyns(new ServiceDyns(protocol,hostname,login,password,Log,update_interval,max_updates_within_interval,dns_cache_ttl,Proxy,ProxyPort));
379         return service_dyns;
380     }
381     else if(protocol == "easydns")
382     {
383         Service::Ptr service_easydns(new ServiceEasydns(protocol,hostname,login,password,Log,update_interval,max_updates_within_interval,dns_cache_ttl,Proxy,ProxyPort));
384         return service_easydns;
385     }
386     else if(protocol == "tzo")
387     {
388         Service::Ptr service_tzo(new ServiceTzo(protocol,hostname,login,password,Log,update_interval,max_updates_within_interval,dns_cache_ttl,Proxy,ProxyPort));
389         return service_tzo;
390     }
391     else if(protocol == "zoneedit")
392     {
393         Service::Ptr service_zoneedit(new ServiceZoneedit(protocol,hostname,login,password,Log,update_interval,max_updates_within_interval,dns_cache_ttl,Proxy,ProxyPort));
394         return service_zoneedit;
395     }
396     else if(protocol == "gnudip")
397     {
398         cout << "Server: " << server << endl; 
399         if ( !server.empty() )
400         {
401             Service::Ptr service_gnudip(new ServiceGnudip(protocol,server,hostname,login,password,Log,update_interval,max_updates_within_interval,dns_cache_ttl,Proxy,ProxyPort));
402             return service_gnudip;
403         }
404         else
405         {
406             Log->print_gnudip_requires_servername();
407             Service::Ptr service;
408             return service;
409         }
410     }
411     else
412     {
413         Log->print_unknown_protocol(protocol);
414         Service::Ptr service;
415         return service;
416     }
417 }
418
419
420 /**
421  * Loads a service config file, invoked by load_config_from_files.
422  * @param full_filename Filename of the service config file to load.
423  * @return 0 if all is fine, -1 otherwise.
424  */
425 int Config::load_service_config_file(const string& full_filename)
426 {
427     Log->print_load_service_conf(full_filename);
428
429     ifstream service_config_file(full_filename.c_str(),ifstream::in);
430     if(service_config_file.is_open())
431     {
432         try
433         {
434             po::variables_map vm;
435             po::parsed_options parsed_service_options = po::parse_config_file(service_config_file,*this->OptDescConfService,true);
436             po::store(parsed_service_options,vm);
437             po::notify(vm);
438
439             if(vm.count("protocol") && vm.count("host") && vm.count("login") && vm.count("password"))
440             {
441                 // create the corresponding service
442                 string protocol = vm["protocol"].as<string>();
443                 string host = vm["host"].as<string>();
444                 string login = vm["login"].as<string>();
445                     string password = vm["password"].as<string>();
446
447                 protocol = ba::to_lower_copy(protocol);
448
449                 string server;
450                 if ( vm.count("server") )
451                     server = vm["server"].as<string>();
452
453                 int update_interval = 0;
454                 if ( vm.count("update_interval") )
455                     update_interval = vm["update_interval"].as<int>();
456
457                 int max_updates_within_interval = 0;
458                 if ( vm.count("max_updates_within_interval") )
459                     max_updates_within_interval = vm["max_updates_within_interval"].as<int>();
460
461                 int dns_cache_ttl = 0;
462                 if ( vm.count("dns_cache_ttl") )
463                     dns_cache_ttl = vm["dns_cache_ttl"].as<int>();
464
465                 Service::Ptr service = create_service(protocol,server,host,login,password,update_interval,max_updates_within_interval,dns_cache_ttl);
466                 if ( service )
467                 {
468                     ServiceHolder->add_service(service);
469                     Log->print_service_object("New Service object from config:", service->get_protocol(), service->get_hostname(), service->get_login() ,service->get_password(), service->get_update_interval(), service->get_max_updates_within_interval(), service->get_dns_cache_ttl() , service->get_actual_ip(), service->get_last_updates());
470                 }
471                 else
472                     return -1;
473             }
474             else if ( vm.count("protocol") || vm.count("host") || vm.count("login") || vm.count("password") )
475             {
476                 service_config_file.close();
477                 Log->print_missing_service_conf_option(full_filename);
478                 return -1;
479             }
480         }
481         catch( const po::unknown_option& e )
482         {
483             // unknown option in config file detected
484             service_config_file.close();
485             Log->print_unknown_service_conf_option(full_filename,e.what());
486             return -1;
487         }
488         catch( const po::multiple_occurrences& e )
489         {
490             service_config_file.close();
491             Log->print_multiple_service_conf_option(full_filename,e.what());
492             return -1;
493         }
494         catch( const po::error& e )
495         {
496             service_config_file.close();
497             Log->print_error_parsing_config_file(full_filename,e.what());
498             return -1;
499         }
500         service_config_file.close();
501     }
502     else
503     {
504         // error opening service config file for reading
505         Log->print_error_opening_r(full_filename);
506         return -1;
507     }
508     return 0;
509 }
510
511
512 /**
513  * Loads the main config file, invoked by load_config_from_files
514  * @param full_filename The full filename of the main config file to load
515  * @return 0 if all is fine, -1 otherwise
516  */
517 int Config::load_main_config_file(const string& full_filename)
518 {
519     Log->print_load_main_conf(full_filename);
520
521     ifstream main_config_file(full_filename.c_str(),ifstream::in);
522     if(main_config_file.is_open())
523     {
524         try
525         {
526             po::parsed_options parsed_main_options = po::parse_config_file(main_config_file,*this->OptDescConfMain,true);
527             po::store(parsed_main_options,VariablesMap);
528             po::notify(VariablesMap);
529
530             if ( VariablesMap.count("daemon_mode") )
531                 DaemonMode = VariablesMap["daemon_mode"].as<bool>();
532
533             if ( VariablesMap.count("loglevel") )
534                 Loglevel = VariablesMap["loglevel"].as<int>();
535
536             if ( VariablesMap.count("syslog") )
537                 Syslog = VariablesMap["syslog"].as<bool>();
538
539             if ( VariablesMap.count("enable_ipv6") )
540                 EnableIPv6 = VariablesMap["enable_ipv6"].as<bool>();
541
542             if ( VariablesMap.count("webcheck_enabled") )
543                 WebcheckEnabled = VariablesMap["webcheck_enabled"].as<bool>();
544
545             if ( VariablesMap.count("webcheck_url") )
546                 WebcheckIpUrl = VariablesMap["webcheck_url"].as<string>();
547
548             if ( VariablesMap.count("webcheck_url_alt") )
549                 WebcheckIpUrlAlt = VariablesMap["webcheck_url_alt"].as<string>();
550
551             if ( VariablesMap.count("webcheck_interval") )
552                 WebcheckInterval = VariablesMap["webcheck_interval"].as<int>();
553
554             if ( VariablesMap.count("http_proxy") && VariablesMap.count("http_proxy_port") )
555             {
556                 Proxy = VariablesMap["http_proxy"].as<string>();
557                 ProxyPort = VariablesMap["http_proxy_port"].as<int>();
558             }
559             else if ( VariablesMap.count("http_proxy") || VariablesMap.count("http_proxy_port") )
560             {
561                 main_config_file.close();
562                 Log->print_missing_conf_proxy_option(full_filename);
563                 return -1;
564             }
565
566             if ( VariablesMap.count("external_warning_log") )
567                 ExternalWarningLog = VariablesMap["external_warning_log"].as<string>();
568
569             if ( VariablesMap.count("external_warning_level") )
570                 ExternalWarningLevel = VariablesMap["external_warning_level"].as<int>();
571
572             if ( VariablesMap.count("start_offline") )
573                 StartOffline = VariablesMap["start_offline"].as<bool>();
574
575         }
576         catch( const po::unknown_option& e )      // at the moment 04-08-2009 this exception is never thrown :-(
577         {
578             // unknown option in main config file detected
579             main_config_file.close();
580             Log->print_unknown_main_conf_option(e.what());
581             return -1;
582         }
583         catch( const po::multiple_occurrences& e )
584         {
585             main_config_file.close();
586             Log->print_multiple_main_conf_option(full_filename,e.what());
587             return -1;
588         }
589         main_config_file.close();
590     }
591     else
592     {
593         // error opening main config file for reading
594         Log->print_error_opening_r(full_filename);
595         return -1;
596     }
597     return 0;
598 }
599
600
601 /**
602  * Loads the main and the service config file and does the needed action.
603  * @param config_path The path to the config directory.
604  * @return 0 if all is fine, -1 otherwise
605  */
606 int Config::load_config_from_files()
607 {
608     fs::path full_config_path = fs::path(ConfigPath);
609
610     fs::directory_iterator end_iter;
611     for ( fs::directory_iterator dir_itr(full_config_path) ; dir_itr != end_iter ; ++dir_itr )
612     {
613         if( fs::is_regular_file( dir_itr->status() ) )
614         {
615             string actual_file = dir_itr->path().filename();
616             boost::regex expr(".*\\.conf?");
617              // If it is the main config file do the following
618             if ( actual_file == "bpdyndnsd.conf" )
619             {
620                 // Load the main config file
621                 string full_filename = dir_itr->path().string();
622                 if ( load_main_config_file(full_filename) != 0 )
623                     return -1;
624             }
625             // If it is a service definition file *.conf, parse it and generate the corresponding service
626             else if ( boost::regex_search( actual_file,expr ) )
627             {
628                 string full_filename = dir_itr->path().string();
629                 if ( load_service_config_file(full_filename) != 0 )
630                     return -1;
631             }
632         }
633     }
634     // Config file successfully loaded
635     Log->print_conf_loaded(ConfigPath);
636     return 0;
637 }
638
639
640 /**
641  * Getter method for member OptDescCmd.
642  * @return options_description*.
643  */
644 Options_descriptionPtr Config::get_opt_desc_cmd() const
645 {
646     return OptDescCmd;
647 }
648
649
650 /**
651  * Getter method for member OptDescConfMain.
652  * @return options_description*.
653  */
654 Options_descriptionPtr Config::get_opt_desc_conf_main() const
655 {
656     return OptDescConfMain;
657 }
658
659
660 /**
661  * Getter method for member OptDescConfService.
662  * @return options_description*.
663  */
664 Options_descriptionPtr Config::get_opt_desc_conf_service() const
665 {
666     return OptDescConfService;
667 }
668
669
670 /**
671  * Getter for member Loglevel.
672  * @return Member Loglevel.
673  */
674 int Config::get_loglevel() const
675 {
676     return Loglevel;
677 }
678
679
680 /**
681  * Getter for member DaemonMode.
682  * @return TRUE if enabled, FALSE if disabled.
683  */
684 bool Config::get_daemon_mode() const
685 {
686     return DaemonMode;
687 }
688
689
690 /**
691  * Deletes the map with the previously parsed options.
692  * This is needed in case we reload the config and don't want the old cmd options to overwrite new config file options.
693  */
694 void Config::delete_variables_map()
695 {
696     VariablesMap.clear();
697
698     po::variables_map _variables_map;
699     VariablesMap = _variables_map;
700 }
701
702
703 /**
704  * Getter for member Syslog.
705  * @return True if logging through syslog is enabled, false otherwise.
706  */
707 bool Config::get_syslog() const
708 {
709     return Syslog;
710 }
711
712
713 /**
714  * Getter for member EnableIPv6
715  * @return Wether IPv6 should be used or not.
716  */
717 bool Config::get_enable_ipv6() const
718 {
719     return EnableIPv6;
720 }
721
722
723 /**
724  * Getter for member WebcheckEnabled
725  * @return Is webcheck enabled by default.
726  */
727 bool Config::get_webcheck_enabled() const
728 {
729     return WebcheckEnabled;
730 }
731
732
733 /**
734  * Setter for member WebcheckEnabled
735  * @return Is webcheck enabled by default.
736  */
737 void Config::set_webcheck_enabled( bool webcheck_enabled )
738 {
739     WebcheckEnabled = webcheck_enabled;
740 }
741
742
743 /**
744  * Getter for member WebcheckIpUrl
745  * @return The primary IP Webcheck URL
746  */
747 string Config::get_webcheck_ip_url() const
748 {
749     return WebcheckIpUrl;
750 }
751
752
753 /**
754  * Getter for member WebcheckIpUrlAlt
755  * @return The alternative IP Webcheck URL
756  */
757 string Config::get_webcheck_ip_url_alt() const
758 {
759     return WebcheckIpUrlAlt;
760 }
761
762
763 /**
764  * Get member WebcheckInterval
765  * @return WebcheckInterval
766  */
767 int Config::get_webcheck_interval() const
768 {
769     return WebcheckInterval;
770 }
771
772
773 /**
774  * Get member Proxy
775  * @return Proxy
776  */
777 string Config::get_proxy() const
778 {
779     return Proxy;
780 }
781
782
783 /**
784  * Get member ProxyPort
785  * @return ProxyPort
786  */
787 int Config::get_proxy_port() const
788 {
789     return ProxyPort;
790 }
791
792
793 /**
794  * Get member ExternalWarningLog
795  * @return ExternalWarningLog
796  */
797 string Config::get_external_warning_log() const
798 {
799     return ExternalWarningLog;
800 }
801
802
803 /**
804  * Get member ExternalWarningLevel
805  * @return ExternalWaringLevel
806  */
807 int Config::get_external_warning_level() const
808 {
809     return ExternalWarningLevel;
810 }
811
812
813 /**
814  * Get member StartOffline
815  * @return StartOffline
816  */
817 bool Config::get_start_offline() const
818 {
819     return StartOffline;
820 }