Fix 'occurred' typo
[bpdyndnsd] / src / config.cpp
index b5f60a5..b326a11 100644 (file)
@@ -7,11 +7,17 @@
  * @license GPLv2
 */
 
-#include "config.h"
-
-#include "serviceholder.h"
-#include "dhs.h"
-#include "ods.h"
+#include "config.hpp"
+
+#include "service_dhs.hpp"
+#include "service_ods.hpp"
+#include "service_dyndns.hpp"
+#include "service_dyns.hpp"
+#include "service_easydns.hpp"
+#include "service_tzo.hpp"
+#include "service_zoneedit.hpp"
+#include "service_gnudip.hpp"
+#include "service_gnudip_fullhostname.hpp"
 
 #include <time.h>
 #include <iostream>
 #include <boost/foreach.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/regex.hpp>
-#include <boost/archive/text_oarchive.hpp>
-#include <boost/archive/text_iarchive.hpp>
-#include <boost/archive/archive_exception.hpp>
-#include <boost/serialization/export.hpp>
-#include <boost/serialization/shared_ptr.hpp>
+#include <boost/algorithm/string.hpp>
 
-// Following boost macros are needed for serialization of derived classes through a base class pointer (Service *).
-BOOST_CLASS_EXPORT_GUID(ODS, "ODS")
-BOOST_CLASS_EXPORT_GUID(DHS, "DHS")
 
 namespace po = boost::program_options;
 namespace fs = boost::filesystem;
+namespace ba = boost::algorithm;
+
+typedef boost::shared_ptr<boost::program_options::options_description> Options_descriptionPtr;
 
 using namespace std;
 
+
 /**
  * Default Constructor. Available command line and config file options with their default values are defined here.
  */
-Config::Config(Logger::Ptr _log)
+Config::Config()
     : Log(new Logger)
+    , ServiceHolder(new Serviceholder)
     , DaemonMode(false)
+    , Syslog(false)
+    , EnableIPv6(false)
+    , LogPasswords(false)
     , Loglevel(0)
+    , ConfigPath("/etc/bpdyndnsd")
+    , WebcheckInterval(0)
+    , ProxyPort(0)
+    , ExternalWarningLog("")
+    , ExternalWarningLevel(0)
+    , StartOffline(false)
+    , WebcheckEnabled(false)
+    , ExternalLogOnlyOnce(false)
+    , DialupMode(false)
+    , DialupBurstPeriodSeconds(120)
+    , DialupSleepSeconds(10 * 60)
+{
+    define_config_options();
+}
+
+
+/**
+ * Constructor with Logger and Serviceholder objects. Available command line and config file options with their default values are defined here.
+ * @todo Move the program options init code to a function used by both constructors
+ */
+Config::Config(Logger::Ptr _log, Serviceholder::Ptr _serviceholder)
+    : Log(_log)
+    , ServiceHolder(_serviceholder)
+    , DaemonMode(false)
     , Syslog(false)
+    , EnableIPv6(false)
+    , LogPasswords(false)
+    , Loglevel(0)
     , ConfigPath("/etc/bpdyndnsd")
+    , WebcheckInterval(0)
+    , ProxyPort(0)
+    , ExternalWarningLog("")
+    , ExternalWarningLevel(0)
+    , StartOffline(false)
+    , WebcheckEnabled(false)
+    , ExternalLogOnlyOnce(false)
+    , DialupMode(false)
+    , DialupBurstPeriodSeconds(120)
+    , DialupSleepSeconds(10 * 60)
 {
-    // initialize Logger
-    Log = _log;
+    define_config_options();
+}
 
+
+/**
+ * Default Destructor
+ */
+Config::~Config()
+{
+}
+
+
+/**
+* Define valid config options with default parameters.
+*/
+void Config::define_config_options()
+{
     // Available service description config options
     po::options_description opt_desc_service("Service description options");
     opt_desc_service.add_options()
         ("protocol",po::value<string>(),"The service protocol.")
+        ("server",po::value<string>(),"Servername needed for gnudip/dyndns protocol.")
         ("host",po::value<string>(),"The hostname to update.")
         ("login",po::value<string>(),"Login name.")
         ("password",po::value<string>(),"Corresponding password.")
+        ("update_interval",po::value<int>()->default_value(-1),"Update interval in minutes.")
+        ("max_updates_within_interval",po::value<int>()->default_value(-1),"How many updates can be made in one interval.")
+        ("max_equal_updates_in_succession",po::value<int>()->default_value(-1),"How many updates with the same IP in succession should be made.")
+        ("dns_cache_ttl",po::value<int>()->default_value(-1),"How long a dns record is valid.")
     ;
 
     // Available command line only options
@@ -65,171 +128,51 @@ Config::Config(Logger::Ptr _log)
         ("config,c",po::value<string>()->default_value("/etc/bpdyndnsd"),"Set the config path.")
     ;
 
-     // Available generic options. Valid on cmd or in config file.
+    // Available generic options. Valid on cmd or in config file.
     po::options_description opt_desc_generic("Generic config options");
     opt_desc_generic.add_options()
         ("daemon_mode",po::value<bool>()->default_value(false),"Run as system daemon.")
         ("loglevel",po::value<int>()->default_value(0),"Loglevel.")
         ("syslog",po::value<bool>()->default_value(false),"Use syslog facility.")
+        ("log_passwords",po::value<bool>()->default_value(false),"Log passwords in cleartext.")
+        ("enable_ipv6",po::value<bool>()->default_value(false),"Try to use IPv6.")
+        ("webcheck_enabled",po::value<bool>()->default_value(false),"Use webcheck url to determine actual IP address.")
+        ("webcheck_url",po::value<string>()->default_value(""),"Use this URL to determine IP.")
+        ("webcheck_url_alt",po::value<string>()->default_value(""),"Use this alternative URL to determine IP.")
+        ("webcheck_interval",po::value<int>()->default_value(10),"The webcheck interval in minutes.")
+        ("http_proxy",po::value<string>(),"Use this proxy for all http requests.")
+        ("http_proxy_port",po::value<int>(),"Port of the proxy.")
+        ("external_warning_log",po::value<string>()->default_value(""),"External programm to pass warning log messages to.")
+        ("external_warning_level",po::value<int>()->default_value(0),"Warning messages of which loglevel should be passed to external programm.")
+        ("external_log_only_once",po::value<bool>()->default_value(false),"Log the same external message only once until next reload or restart.")
+        ("start_offline",po::value<bool>()->default_value(false),"Start in offline mode.")
+        ("dialup_mode",po::value<bool>()->default_value(false),"Enable dialup mode (sleep periods between network traffic)")
+        ("dialup_burst_period_seconds",po::value<int>()->default_value(120),"Seconds of normal operation before entering dialup mode")
+        ("dialup_sleep_seconds",po::value<int>()->default_value(10 * 60),"Seconds to sleep between network traffic")
+        ("wan_ip_override",po::value<string>(),"Manual override for automatic WAN IP detection")
     ;
 
     // Define valid command line parameters
-    Options_descriptionPtr _opt_desc_cmd(new po::options_description("Command line options"));
-    OptDescCmd = _opt_desc_cmd;
-    _opt_desc_cmd.reset();
+    OptDescCmd = Options_descriptionPtr(new po::options_description("Command line options"));
     OptDescCmd->add(opt_desc_cmd_only);
     OptDescCmd->add(opt_desc_generic);
     OptDescCmd->add(opt_desc_service);
 
     // Define valid config file options
-    Options_descriptionPtr _opt_desc_conf_main(new po::options_description("Config file options"));
-    OptDescConfMain = _opt_desc_conf_main;
-    _opt_desc_conf_main.reset();
+    OptDescConfMain = Options_descriptionPtr(new po::options_description("Config file options"));
     OptDescConfMain->add(opt_desc_generic);
 
     // Define valid service file options
-    Options_descriptionPtr _opt_desc_conf_service(new po::options_description("Service file options"));
-    OptDescConfService = _opt_desc_conf_service;
-    _opt_desc_conf_service.reset();
+    OptDescConfService = Options_descriptionPtr(new po::options_description("Service file options"));
     OptDescConfService->add(opt_desc_service);
 }
 
 
 /**
- * Default Destructor
- */
-Config::~Config()
-{
-}
-
-
-/**
- * This function serializes all Service objects in Services and OldServices (where the update Timeout isn't expired) into a specified file.
- * @return 0 if all is fine, -1 if output file could not be opened for reading or error while serializing.
- */
-int Config::serialize_services()
-{
-    // Put Services and OldServices into Serviceholder.
-    Serviceholder::Ptr service_holder(new Serviceholder());
-
-    BOOST_FOREACH(Service::Ptr service, Services)
-    {
-        service_holder->add_service(service);
-    }
-
-    int current_time = time(NULL);
-
-    BOOST_FOREACH(Service::Ptr service, OldServices)
-    {
-        if ( ( service->get_lastupdated() + service->get_timeout() ) >= current_time )  // Update Timeout of service isn't expired.
-            service_holder->add_service(service);
-    }
-
-    // Serialize Serviceholder into file.
-    ofstream ofs(OBJECT_FILE);
-    if ( ofs.is_open() )
-    {
-        Serviceholder* _service_holder = service_holder.get();
-        try
-        {
-            boost::archive::text_oarchive oa(ofs);
-            oa << _service_holder;
-        }
-        catch( boost::archive::archive_exception e )
-        {
-            Log->print_exception_serialize(e.what());
-            ofs.close();
-            return -1;
-        }
-
-        ofs.close();
-    }
-    else
-    {
-        Log->print_error_opening_rw(OBJECT_FILE);
-        return -1;
-    }
-
-    Log->print_serialized_objects_success();
-
-    return 0;
-}
-
-
-/**
- * This function de-serializes the Serviceholder (containing Services) from the object file.
- * @return 0 if all is fine, -1 if object file couldn't be opened for reading or error while de-serializing.
- */
-int Config::deserialize_services()
-{
-    // test if OBJECT_FILE exists
-    fs::path object_file = fs::system_complete(fs::path(OBJECT_FILE));
-    if ( !fs::exists(object_file) )
-    {
-        // There is no object file, possibly first program start, continue without recovering old Services' state.
-        Log->print_no_object_file(OBJECT_FILE);
-        return 0;
-    }
-
-    ifstream ifs(OBJECT_FILE);
-    if ( ifs.is_open() )
-    {
-        // deserialize Serviceholder
-        Serviceholder* _service_holder;
-        try
-        {
-            boost::archive::text_iarchive ia(ifs);
-            ia >> _service_holder;       // ends up in default constructor call for Serviceholder
-        }
-        catch( boost::archive::archive_exception e )
-        {
-            Log->print_exception_deserialize(e.what());
-            ifs.close();
-            return -1;
-        }
-        Serviceholder::Ptr service_holder(_service_holder);
-        ifs.close();
-
-        // Get the list of old Services from de-serialized Serviceholder object.
-        list<Service::Ptr> _old_services = service_holder->get_hold_services();
-
-        // Put all de-serialized Services into OldServices member and
-        // compare new Services (generated from config file and cmd) with old Services (de-serialized from object file)
-        // if identical Service was found, adopt the value from old Service to recover Services' state.
-        BOOST_FOREACH(Service::Ptr old_service, _old_services)
-        {
-            OldServices.push_back(old_service);
-            Log->print_service_object("Deserialized following Service object:", old_service->get_protocol(), old_service->get_hostname(), old_service->get_login() ,old_service->get_password() ,old_service->get_actual_ip(), old_service->get_lastupdated());
-            BOOST_FOREACH(Service::Ptr service, Services)
-            {
-                if ( *service == *old_service )
-                {
-                    service->set_lastupdated(old_service->get_lastupdated());
-                    service->set_actual_ip(old_service->get_actual_ip());
-                    Log->print_service_object("New Service object with adopted values:", service->get_protocol(), service->get_hostname(), service->get_login() ,service->get_password() ,service->get_actual_ip(), service->get_lastupdated());
-                    // We have adopted the values of the old_service. Just set lastupdated and timeout to 0, so this old_service wont be serialized.
-                    old_service->set_lastupdated(0);
-                    old_service->set_timeout(0);
-                }
-            }
-        }
-        Log->print_deserialized_objects_success();
-    }
-    else
-    {
-        Log->print_error_opening_r(OBJECT_FILE);
-        return -1;
-    }
-
-    return 0;
-}
-
-
-/**
  * Parses the command line arguments and does the needed actions.
  * @param argc Command line argument number given to main.
  * @param argv[] Pointer to command line argument array given to main.
- * @return 0 if all is fine, 1 if not.
+ * @return 0 if all is fine, -1 if not.
  */
 int Config::parse_cmd_line(int argc, char *argv[])
 {
@@ -241,12 +184,12 @@ int Config::parse_cmd_line(int argc, char *argv[])
         if ( VariablesMap.count("help") )
         {
             Log->print_usage(OptDescCmd);
-            return 1;
+            return -1;
         }
         else if ( VariablesMap.count("version") )
         {
             Log->print_version();
-            return 1;
+            return -1;
         }
 
         // Create a service object if all needed options are set on the command line
@@ -258,19 +201,44 @@ int Config::parse_cmd_line(int argc, char *argv[])
             string login = VariablesMap["login"].as<string>();
             string password = VariablesMap["password"].as<string>();
 
-            //TODO: convert protocol option to lowercase
+            protocol = ba::to_lower_copy(protocol);
+
+            string server;
+            if ( VariablesMap.count("server") )
+                server = VariablesMap["server"].as<string>();
+
+            int update_interval = 0;
+            if ( VariablesMap.count("update_interval") )
+                update_interval = VariablesMap["update_interval"].as<int>();
+
+            int max_updates_within_interval = 0;
+            if ( VariablesMap.count("max_updates_within_interval") )
+                max_updates_within_interval = VariablesMap["max_updates_within_interval"].as<int>();
+
+            int max_equal_updates_in_succession = 0;
+            if ( VariablesMap.count("max_equal_updates_in_succession") )
+                max_equal_updates_in_succession = VariablesMap["max_equal_updates_in_succession"].as<int>();
 
-            Service::Ptr service = create_service(protocol,host,login,password);
+            int dns_cache_ttl = 0;
+            if ( VariablesMap.count("dns_cache_ttl") )
+                dns_cache_ttl = VariablesMap["dns_cache_ttl"].as<int>();
+
+            Service::Ptr service = create_service(protocol,server,host,login,password,update_interval,max_updates_within_interval,max_equal_updates_in_succession,dns_cache_ttl);
             if ( service )
-                Services.push_back(service);
+            {
+                ServiceHolder->add_service(service);
+                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_max_equal_updates_in_succession(), service->get_dns_cache_ttl() , service->get_actual_ip(), service->get_last_updates(), service->get_activated());
+            }
             else
-                return 1;
+            {
+                Log->print_invalid_service_config();
+            }
         }
         else if ( VariablesMap.count("protocol") || VariablesMap.count("host") || VariablesMap.count("login") || VariablesMap.count("password") )
         {
             Log->print_missing_cmd_service_option();
             Log->print_usage(OptDescCmd);
-            return 1;
+            return -1;
         }
 
         if ( VariablesMap.count("config") )
@@ -281,47 +249,176 @@ int Config::parse_cmd_line(int argc, char *argv[])
             {
                 // Config path doesn't exist or is not a directory
                 Log->print_error_config_path(ConfigPath);
-                return 1;
+                return -1;
             }
         }
 
+        if ( VariablesMap.count("daemon_mode") )
+            DaemonMode = VariablesMap["daemon_mode"].as<bool>();
+
         if ( VariablesMap.count("loglevel") )
             Loglevel = VariablesMap["loglevel"].as<int>();
 
         if ( VariablesMap.count("syslog") )
             Syslog = VariablesMap["syslog"].as<bool>();
 
+        if ( VariablesMap.count("log_passwords") )
+            LogPasswords = VariablesMap["log_passwords"].as<bool>();
+
+        if ( VariablesMap.count("enable_ipv6") )
+            EnableIPv6 = VariablesMap["enable_ipv6"].as<bool>();
+
+        if ( VariablesMap.count("webcheck_enabled") )
+            WebcheckEnabled = VariablesMap["webcheck_enabled"].as<bool>();
+
+        if ( VariablesMap.count("webcheck_url") )
+            WebcheckIpUrl = VariablesMap["webcheck_url"].as<string>();
+
+        if ( VariablesMap.count("webcheck_url_alt") )
+            WebcheckIpUrlAlt = VariablesMap["webcheck_url_alt"].as<string>();
+
+        if ( VariablesMap.count("webcheck_interval") )
+            WebcheckInterval = VariablesMap["webcheck_interval"].as<int>();
+
+        if ( VariablesMap.count("http_proxy") && VariablesMap.count("http_proxy_port") )
+        {
+            Proxy = VariablesMap["http_proxy"].as<string>();
+            ProxyPort = VariablesMap["http_proxy_port"].as<int>();
+        }
+        else if ( VariablesMap.count("http_proxy") || VariablesMap.count("http_proxy_port") )
+        {
+            Log->print_missing_cmd_proxy_option();
+            Log->print_usage(OptDescCmd);
+            return -1;
+        }
+
+        if ( VariablesMap.count("external_warning_log") )
+            ExternalWarningLog = VariablesMap["external_warning_log"].as<string>();
+
+        if ( VariablesMap.count("external_warning_level") )
+            ExternalWarningLevel = VariablesMap["external_warning_level"].as<int>();
+
+        if ( VariablesMap.count("external_log_only_once") )
+            ExternalLogOnlyOnce = VariablesMap["external_log_only_once"].as<bool>();
+
+        if ( VariablesMap.count("start_offline") )
+            StartOffline = VariablesMap["start_offline"].as<bool>();
+
+        if ( VariablesMap.count("dialup_mode") )
+            DialupMode = VariablesMap["dialup_mode"].as<bool>();
+        if ( VariablesMap.count("dialup_burst_period_seconds") )
+            DialupBurstPeriodSeconds = VariablesMap["dialup_burst_period_seconds"].as<int>();
+        if ( VariablesMap.count("dialup_sleep_seconds") )
+            DialupSleepSeconds = VariablesMap["dialup_sleep_seconds"].as<int>();
+
+        if ( VariablesMap.count("wan_ip_override") )
+            WanIpOverride = VariablesMap["wan_ip_override"].as<string>();
     }
-    catch(po::unknown_option e)
+    catch( const po::unknown_option& e )
     {
         Log->print_unknown_cmd_option(e.what());
         Log->print_usage(OptDescCmd);
-        return 1;
+        return -1;
+    }
+    catch( const po::multiple_occurrences& e )
+    {
+        Log->print_multiple_cmd_option(e.what());
+        Log->print_usage(OptDescCmd);
+        return -1;
+    }
+    catch( const po::error& e )
+    {
+        Log->print_error_parsing_cmd(e.what());
+        Log->print_usage(OptDescCmd);
+        return -1;
     }
     return 0;
 }
 
 
 /**
- * 
- * @param protocol 
- * @param host 
- * @param login 
- * @param password 
+ * Creates a Service object from the given parameters.
+ * @param protocol Protocol to use.
+ * @param host Hostname to update.
+ * @param login Login.
+ * @param password Password.
  * @return A pointer to the created Service object.
  */
-Service::Ptr Config::create_service(const string &protocol,const string &hostname, const string &login, const string &password)
+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 max_equal_updates_in_succession, const int dns_cache_ttl)
 {
+    // Test for valid hostname. Must contain 3 parts minimum.
+    list<string> fqhn_parts;
+    ba::split(fqhn_parts,hostname,boost::is_any_of("."));
+    if ( fqhn_parts.size() < 3 )
+    {
+        Log->print_invalid_hostname(hostname);
+        Service::Ptr service;
+        return service;
+    }
+
     if(protocol == "dhs")
     {
-        Service::Ptr service_dhs(new DHS(protocol,hostname,login,password,Log,0,60,1));
+        Service::Ptr service_dhs(new ServiceDhs(protocol,hostname,login,password,Log,update_interval,max_updates_within_interval,max_equal_updates_in_succession,dns_cache_ttl,Proxy,ProxyPort));
         return service_dhs;
     }
     else if(protocol == "ods")
     {
-        Service::Ptr service_ods(new ODS(protocol,hostname,login,password,Log,0,60,1));
+        Service::Ptr service_ods(new ServiceOds(protocol,hostname,login,password,Log,update_interval,max_updates_within_interval,max_equal_updates_in_succession,dns_cache_ttl));
         return service_ods;
     }
+    else if(protocol == "dyndns")
+    {
+        Service::Ptr service_dyndns(new ServiceDyndns(protocol,hostname,login,password,Log,update_interval,max_updates_within_interval,max_equal_updates_in_succession,dns_cache_ttl,Proxy,ProxyPort,server));
+        return service_dyndns;
+    }
+    else if(protocol == "dyns")
+    {
+        Service::Ptr service_dyns(new ServiceDyns(protocol,hostname,login,password,Log,update_interval,max_updates_within_interval,max_equal_updates_in_succession,dns_cache_ttl,Proxy,ProxyPort));
+        return service_dyns;
+    }
+    else if(protocol == "easydns")
+    {
+        Service::Ptr service_easydns(new ServiceEasydns(protocol,hostname,login,password,Log,update_interval,max_updates_within_interval,max_equal_updates_in_succession,dns_cache_ttl,Proxy,ProxyPort));
+        return service_easydns;
+    }
+    else if(protocol == "tzo")
+    {
+        Service::Ptr service_tzo(new ServiceTzo(protocol,hostname,login,password,Log,update_interval,max_updates_within_interval,max_equal_updates_in_succession,dns_cache_ttl,Proxy,ProxyPort));
+        return service_tzo;
+    }
+    else if(protocol == "zoneedit")
+    {
+        Service::Ptr service_zoneedit(new ServiceZoneedit(protocol,hostname,login,password,Log,update_interval,max_updates_within_interval,max_equal_updates_in_succession,dns_cache_ttl,Proxy,ProxyPort));
+        return service_zoneedit;
+    }
+    else if(protocol == "gnudip")
+    {
+        if ( !server.empty() )
+        {
+            Service::Ptr service_gnudip(new ServiceGnudip(protocol,server,hostname,login,password,Log,update_interval,max_updates_within_interval,max_equal_updates_in_succession,dns_cache_ttl,Proxy,ProxyPort));
+            return service_gnudip;
+        }
+        else
+        {
+            Log->print_gnudip_requires_servername();
+            Service::Ptr service;
+            return service;
+        }
+    }
+    else if(protocol == "gnudip-fullhostname")
+    {
+        if ( !server.empty() )
+        {
+            Service::Ptr service_gnudip_fullhostname(new ServiceGnudipFullhostname(protocol,server,hostname,login,password,Log,update_interval,max_updates_within_interval,max_equal_updates_in_succession,dns_cache_ttl,Proxy,ProxyPort));
+            return service_gnudip_fullhostname;
+        }
+        else
+        {
+            Log->print_gnudip_requires_servername();
+            Service::Ptr service;
+            return service;
+        }
+    }
     else
     {
         Log->print_unknown_protocol(protocol);
@@ -334,7 +431,7 @@ Service::Ptr Config::create_service(const string &protocol,const string &hostnam
 /**
  * Loads a service config file, invoked by load_config_from_files.
  * @param full_filename Filename of the service config file to load.
- * @return 0 if all is fine, 3 if an unknown option was detected, 4 if the service file could not be opened for reading.
+ * @return 0 if all is fine, -1 otherwise.
  */
 int Config::load_service_config_file(const string& full_filename)
 {
@@ -346,7 +443,7 @@ int Config::load_service_config_file(const string& full_filename)
         try
         {
             po::variables_map vm;
-            po::parsed_options parsed_service_options = po::parse_config_file(service_config_file,*this->OptDescConfService,true);
+            po::parsed_options parsed_service_options = po::parse_config_file(service_config_file,*this->OptDescConfService,false);
             po::store(parsed_service_options,vm);
             po::notify(vm);
 
@@ -356,25 +453,66 @@ int Config::load_service_config_file(const string& full_filename)
                 string protocol = vm["protocol"].as<string>();
                 string host = vm["host"].as<string>();
                 string login = vm["login"].as<string>();
-                string password = vm["password"].as<string>();
+                    string password = vm["password"].as<string>();
+
+                protocol = ba::to_lower_copy(protocol);
+
+                string server;
+                if ( vm.count("server") )
+                    server = vm["server"].as<string>();
+
+                int update_interval = 0;
+                if ( vm.count("update_interval") )
+                    update_interval = vm["update_interval"].as<int>();
+
+                int max_updates_within_interval = 0;
+                if ( vm.count("max_updates_within_interval") )
+                    max_updates_within_interval = vm["max_updates_within_interval"].as<int>();
+
+                int max_equal_updates_in_succession = 0;
+                if ( vm.count("max_equal_updates_in_succession") )
+                    max_equal_updates_in_succession = vm["max_equal_updates_in_succession"].as<int>();
 
-                // TODO: convert protocol to lowercase
-                //protocol = tolower(protocol.c_str());
+                int dns_cache_ttl = 0;
+                if ( vm.count("dns_cache_ttl") )
+                    dns_cache_ttl = vm["dns_cache_ttl"].as<int>();
 
-                Service::Ptr service = create_service(protocol,host,login,password);
+                Service::Ptr service = create_service(protocol,server,host,login,password,update_interval,max_updates_within_interval,max_equal_updates_in_succession,dns_cache_ttl);
                 if ( service )
                 {
-                    Services.push_back(service);
-                    Log->print_service_object("New Service object from config:", service->get_protocol(), service->get_hostname(), service->get_login() ,service->get_password() ,service->get_actual_ip(), service->get_lastupdated());
+                    ServiceHolder->add_service(service);
+                    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_max_equal_updates_in_succession(), service->get_dns_cache_ttl() , service->get_actual_ip(), service->get_last_updates(), service->get_activated());
+                }
+                else
+                {
+                    Log->print_invalid_service_config();
                 }
             }
+            else if ( vm.count("protocol") || vm.count("host") || vm.count("login") || vm.count("password") )
+            {
+                service_config_file.close();
+                Log->print_missing_service_conf_option(full_filename);
+                return -1;
+            }
         }
-        catch ( po::unknown_option e )
+        catch( const po::unknown_option& e )
         {
             // unknown option in config file detected
             service_config_file.close();
-            Log->print_unknown_service_conf_option(e.what());
-            return 1;
+            Log->print_unknown_service_conf_option(full_filename,e.what());
+            return -1;
+        }
+        catch( const po::multiple_occurrences& e )
+        {
+            service_config_file.close();
+            Log->print_multiple_service_conf_option(full_filename,e.what());
+            return -1;
+        }
+        catch( const po::error& e )
+        {
+            service_config_file.close();
+            Log->print_error_parsing_config_file(full_filename,e.what());
+            return -1;
         }
         service_config_file.close();
     }
@@ -382,7 +520,7 @@ int Config::load_service_config_file(const string& full_filename)
     {
         // error opening service config file for reading
         Log->print_error_opening_r(full_filename);
-        return 1;
+        return -1;
     }
     return 0;
 }
@@ -391,7 +529,7 @@ int Config::load_service_config_file(const string& full_filename)
 /**
  * Loads the main config file, invoked by load_config_from_files
  * @param full_filename The full filename of the main config file to load
- * @return 0 if all is fine. 3 if unknown option was detected, 4 if main config file could not be opened for reading
+ * @return 0 if all is fine, -1 otherwise
  */
 int Config::load_main_config_file(const string& full_filename)
 {
@@ -402,23 +540,83 @@ int Config::load_main_config_file(const string& full_filename)
     {
         try
         {
-            po::parsed_options parsed_main_options = po::parse_config_file(main_config_file,*this->OptDescConfMain,true);
+            po::parsed_options parsed_main_options = po::parse_config_file(main_config_file,*this->OptDescConfMain,false);
             po::store(parsed_main_options,VariablesMap);
             po::notify(VariablesMap);
 
-            if(VariablesMap.count("daemon_mode") && VariablesMap.count("loglevel") && VariablesMap.count("syslog"))
-            {
+            if ( VariablesMap.count("daemon_mode") )
                 DaemonMode = VariablesMap["daemon_mode"].as<bool>();
+
+            if ( VariablesMap.count("loglevel") )
                 Loglevel = VariablesMap["loglevel"].as<int>();
+
+            if ( VariablesMap.count("syslog") )
                 Syslog = VariablesMap["syslog"].as<bool>();
+
+            if ( VariablesMap.count("log_passwords") )
+                LogPasswords = VariablesMap["log_passwords"].as<bool>();
+
+            if ( VariablesMap.count("enable_ipv6") )
+                EnableIPv6 = VariablesMap["enable_ipv6"].as<bool>();
+
+            if ( VariablesMap.count("webcheck_enabled") )
+                WebcheckEnabled = VariablesMap["webcheck_enabled"].as<bool>();
+
+            if ( VariablesMap.count("webcheck_url") )
+                WebcheckIpUrl = VariablesMap["webcheck_url"].as<string>();
+
+            if ( VariablesMap.count("webcheck_url_alt") )
+                WebcheckIpUrlAlt = VariablesMap["webcheck_url_alt"].as<string>();
+
+            if ( VariablesMap.count("webcheck_interval") )
+                WebcheckInterval = VariablesMap["webcheck_interval"].as<int>();
+
+            if ( VariablesMap.count("http_proxy") && VariablesMap.count("http_proxy_port") )
+            {
+                Proxy = VariablesMap["http_proxy"].as<string>();
+                ProxyPort = VariablesMap["http_proxy_port"].as<int>();
             }
+            else if ( VariablesMap.count("http_proxy") || VariablesMap.count("http_proxy_port") )
+            {
+                main_config_file.close();
+                Log->print_missing_conf_proxy_option(full_filename);
+                return -1;
+            }
+
+            if ( VariablesMap.count("external_warning_log") )
+                ExternalWarningLog = VariablesMap["external_warning_log"].as<string>();
+
+            if ( VariablesMap.count("external_warning_level") )
+                ExternalWarningLevel = VariablesMap["external_warning_level"].as<int>();
+
+            if ( VariablesMap.count("external_log_only_once") )
+                ExternalLogOnlyOnce = VariablesMap["external_log_only_once"].as<bool>();
+
+            if ( VariablesMap.count("start_offline") )
+                StartOffline = VariablesMap["start_offline"].as<bool>();
+
+            if ( VariablesMap.count("dialup_mode") )
+                DialupMode = VariablesMap["dialup_mode"].as<bool>();
+            if ( VariablesMap.count("dialup_burst_period_seconds") )
+                DialupBurstPeriodSeconds = VariablesMap["dialup_burst_period_seconds"].as<int>();
+            if ( VariablesMap.count("dialup_sleep_seconds") )
+                DialupSleepSeconds = VariablesMap["dialup_sleep_seconds"].as<int>();
+
+            if ( VariablesMap.count("wan_ip_override") )
+                WanIpOverride = VariablesMap["wan_ip_override"].as<string>();
         }
-        catch ( po::unknown_option e )      // at the moment 04-08-2009 this exception is never thrown :-(
+        catch( const po::unknown_option& e )
         {
             // unknown option in main config file detected
             main_config_file.close();
             Log->print_unknown_main_conf_option(e.what());
-            return 1;
+            return -1;
+        }
+        catch( const po::multiple_occurrences& e )
+        {
+            main_config_file.close();
+            Log->print_multiple_main_conf_option(full_filename,e.what());
+            return -1;
         }
         main_config_file.close();
     }
@@ -426,7 +624,7 @@ int Config::load_main_config_file(const string& full_filename)
     {
         // error opening main config file for reading
         Log->print_error_opening_r(full_filename);
-        return 1;
+        return -1;
     }
     return 0;
 }
@@ -435,7 +633,7 @@ int Config::load_main_config_file(const string& full_filename)
 /**
  * Loads the main and the service config file and does the needed action.
  * @param config_path The path to the config directory.
- * @return 0 if all is fine.
+ * @return 0 if all is fine, -1 otherwise
  */
 int Config::load_config_from_files()
 {
@@ -446,22 +644,26 @@ int Config::load_config_from_files()
     {
         if( fs::is_regular_file( dir_itr->status() ) )
         {
+#if BOOST_FILESYSTEM_VERSION >= 3
+            string actual_file = dir_itr->path().filename().string();
+#else
             string actual_file = dir_itr->path().filename();
-            boost::regex expr(".*\\.conf?");
+#endif
+            boost::regex expr(".*\\.conf$");
              // If it is the main config file do the following
             if ( actual_file == "bpdyndnsd.conf" )
             {
                 // Load the main config file
                 string full_filename = dir_itr->path().string();
                 if ( load_main_config_file(full_filename) != 0 )
-                    return 1;
+                    return -1;
             }
             // If it is a service definition file *.conf, parse it and generate the corresponding service
             else if ( boost::regex_search( actual_file,expr ) )
             {
                 string full_filename = dir_itr->path().string();
                 if ( load_service_config_file(full_filename) != 0 )
-                    return 1;
+                    return -1;
             }
         }
     }
@@ -472,20 +674,10 @@ int Config::load_config_from_files()
 
 
 /**
- * Getter method for Service list member.
- * @return Pointer to a list of Service's.
- */
-list<Service::Ptr> Config::get_services()
-{
-    return this->Services;
-}
-
-
-/**
  * Getter method for member OptDescCmd.
  * @return options_description*.
  */
-Config::Options_descriptionPtr Config::get_opt_desc_cmd()
+Options_descriptionPtr Config::get_opt_desc_cmd() const
 {
     return OptDescCmd;
 }
@@ -495,7 +687,7 @@ Config::Options_descriptionPtr Config::get_opt_desc_cmd()
  * Getter method for member OptDescConfMain.
  * @return options_description*.
  */
-Config::Options_descriptionPtr Config::get_opt_desc_conf_main()
+Options_descriptionPtr Config::get_opt_desc_conf_main() const
 {
     return OptDescConfMain;
 }
@@ -505,7 +697,7 @@ Config::Options_descriptionPtr Config::get_opt_desc_conf_main()
  * Getter method for member OptDescConfService.
  * @return options_description*.
  */
-Config::Options_descriptionPtr Config::get_opt_desc_conf_service()
+Options_descriptionPtr Config::get_opt_desc_conf_service() const
 {
     return OptDescConfService;
 }
@@ -515,7 +707,7 @@ Config::Options_descriptionPtr Config::get_opt_desc_conf_service()
  * Getter for member Loglevel.
  * @return Member Loglevel.
  */
-int Config::get_loglevel()
+int Config::get_loglevel() const
 {
     return Loglevel;
 }
@@ -525,32 +717,13 @@ int Config::get_loglevel()
  * Getter for member DaemonMode.
  * @return TRUE if enabled, FALSE if disabled.
  */
-bool Config::get_daemon_mode()
+bool Config::get_daemon_mode() const
 {
     return DaemonMode;
 }
 
 
 /**
- * Resets all shared Service pointers and clears the Services list.
- */
-void Config::delete_services()
-{
-    BOOST_FOREACH( Service::Ptr service, Services )
-    {
-        service.reset();
-    }
-    Services.clear();
-
-    BOOST_FOREACH( Service::Ptr service, OldServices )
-    {
-        service.reset();
-    }
-    OldServices.clear();
-}
-
-
-/**
  * Deletes the map with the previously parsed options.
  * This is needed in case we reload the config and don't want the old cmd options to overwrite new config file options.
  */
@@ -567,7 +740,174 @@ void Config::delete_variables_map()
  * Getter for member Syslog.
  * @return True if logging through syslog is enabled, false otherwise.
  */
-bool Config::get_syslog()
+bool Config::get_syslog() const
 {
     return Syslog;
 }
+
+
+/**
+ * Getter for member LogPasswords.
+ * @return True if we want to log passwords in cleartext.
+ */
+bool Config::get_log_passwords() const
+{
+    return LogPasswords;
+}
+
+
+/**
+ * Getter for member EnableIPv6
+ * @return Wether IPv6 should be used or not.
+ */
+bool Config::get_enable_ipv6() const
+{
+    return EnableIPv6;
+}
+
+
+/**
+ * Getter for member WebcheckEnabled
+ * @return Is webcheck enabled by default.
+ */
+bool Config::get_webcheck_enabled() const
+{
+    return WebcheckEnabled;
+}
+
+
+/**
+ * Setter for member WebcheckEnabled
+ * @return Is webcheck enabled by default.
+ */
+void Config::set_webcheck_enabled( bool webcheck_enabled )
+{
+    WebcheckEnabled = webcheck_enabled;
+}
+
+
+/**
+ * Getter for member WebcheckIpUrl
+ * @return The primary IP Webcheck URL
+ */
+string Config::get_webcheck_ip_url() const
+{
+    return WebcheckIpUrl;
+}
+
+
+/**
+ * Getter for member WebcheckIpUrlAlt
+ * @return The alternative IP Webcheck URL
+ */
+string Config::get_webcheck_ip_url_alt() const
+{
+    return WebcheckIpUrlAlt;
+}
+
+
+/**
+ * Get member WebcheckInterval
+ * @return WebcheckInterval
+ */
+int Config::get_webcheck_interval() const
+{
+    return WebcheckInterval;
+}
+
+
+/**
+ * Get member Proxy
+ * @return Proxy
+ */
+string Config::get_proxy() const
+{
+    return Proxy;
+}
+
+
+/**
+ * Get member ProxyPort
+ * @return ProxyPort
+ */
+int Config::get_proxy_port() const
+{
+    return ProxyPort;
+}
+
+
+/**
+ * Get member ExternalWarningLog
+ * @return ExternalWarningLog
+ */
+string Config::get_external_warning_log() const
+{
+    return ExternalWarningLog;
+}
+
+
+/**
+ * Get member ExternalWarningLevel
+ * @return ExternalWaringLevel
+ */
+int Config::get_external_warning_level() const
+{
+    return ExternalWarningLevel;
+}
+
+
+/**
+ * Get member StartOffline
+ * @return StartOffline
+ */
+bool Config::get_start_offline() const
+{
+    return StartOffline;
+}
+
+
+/**
+ * Get member ExternalLogOnlyOnce
+ * @return StartOffline
+ */
+bool Config::get_external_log_only_once() const
+{
+    return ExternalLogOnlyOnce;
+}
+
+
+/**
+ * Get member DialupMode
+ * @return DIalupMode
+*/
+bool Config::get_dialup_mode() const
+{
+    return DialupMode;
+}
+
+/**
+ * Get member DialupBurstPeriodSeconds
+ * @return DialupBurstPeriodSeconds
+*/
+int Config::get_dialup_burst_period_seconds() const
+{
+    return DialupBurstPeriodSeconds;
+}
+
+/**
+ * Get member DialupSleepSeconds
+ * @return DialupSleepSeconds
+*/
+int Config::get_dialup_sleep_seconds() const
+{
+    return DialupSleepSeconds;
+}
+
+/**
+ * Get WAN override IP (if present)
+ * @return WanIpOverride
+*/
+std::string Config::get_wan_ip_override() const
+{
+    return WanIpOverride;
+}