Implemented logic for ability to activate webcheck through signals.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Fri, 21 May 2010 08:09:06 +0000 (10:09 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Fri, 21 May 2010 08:09:06 +0000 (10:09 +0200)
config/bpdyndnsd.conf
src/config.cpp
src/config.h
src/ip_addr_helper.cpp
src/ip_addr_helper.h
src/main.cpp
src/updater.cpp

index 8d0bd2e..cc9fa3e 100644 (file)
@@ -1,5 +1,6 @@
 daemon_mode=1
 loglevel=0
 syslog=1
-# Uncomment following line if located behind a NAT router.
+# Uncomment following two lines if located behind a NAT router.
+#webcheck_enabled=1
 #webcheck_url=http://checkip.dyndns.com
index efce38b..7afc166 100644 (file)
@@ -53,6 +53,7 @@ Config::Config()
     , ExternalWarningLog("")
     , ExternalWarningLevel(0)
     , StartOffline(false)
+    , WebcheckEnabled(false)
 {
     // Available service description config options
     po::options_description opt_desc_service("Service description options");
@@ -82,6 +83,7 @@ Config::Config()
         ("loglevel",po::value<int>()->default_value(0),"Loglevel.")
         ("syslog",po::value<bool>()->default_value(false),"Use syslog facility.")
         ("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.")
@@ -124,6 +126,7 @@ Config::Config(Logger::Ptr _log, Serviceholder::Ptr _serviceholder)
     , ExternalWarningLog("")
     , ExternalWarningLevel(0)
     , StartOffline(false)
+    , WebcheckEnabled(false)
 {
     // Available service description config options
     po::options_description opt_desc_service("Service description options");
@@ -153,6 +156,7 @@ Config::Config(Logger::Ptr _log, Serviceholder::Ptr _serviceholder)
         ("loglevel",po::value<int>()->default_value(0),"Loglevel.")
         ("syslog",po::value<bool>()->default_value(false),"Use syslog facility.")
         ("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.")
@@ -278,6 +282,9 @@ int Config::parse_cmd_line(int argc, char *argv[])
         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>();
 
@@ -532,6 +539,9 @@ int Config::load_main_config_file(const string& full_filename)
             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>();
 
@@ -711,6 +721,26 @@ bool Config::get_enable_ipv6() const
 
 
 /**
+ * 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
  */
index d6e8d45..b282c6e 100644 (file)
@@ -47,6 +47,7 @@ private:
     std::string ExternalWarningLog;
     int ExternalWarningLevel;
     bool StartOffline;
+    bool WebcheckEnabled;
 
     Service::Ptr create_service(const std::string& protocol, const std::string& server, const std::string& hostname, const std::string& login, const std::string& password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl);
     int load_main_config_file(const std::string& full_filename);
@@ -84,6 +85,10 @@ public:
 
     int get_proxy_port() const;
 
+    bool get_webcheck_enabled() const;
+
+    void set_webcheck_enabled( bool webcheck_enabled );
+
     std::string get_webcheck_ip_url() const;
 
     std::string get_webcheck_ip_url_alt() const;
index 5070a94..280257c 100644 (file)
@@ -181,14 +181,14 @@ bool IPAddrHelper::is_local_ipv4(const string ip) const
  * Get the actual IP of this host through a conventional DNS query or through a IP webcheck URL if configured so.
  * @return A string representation of the actual IP in dotted format or an empty string if something went wrong.
  */
-string IPAddrHelper::get_actual_ip()
+string IPAddrHelper::get_actual_ip( bool use_webcheck )
 {
     string ip;
 
-    if ( WebcheckIpUrl.empty() )
-        ip = get_local_wan_nic_ip();
-    else
+    if ( !WebcheckIpUrl.empty() && use_webcheck )
         ip = webcheck_ip();
+    else
+        ip = get_local_wan_nic_ip();
 
     return ip;
 }
index f817854..72eb1fe 100644 (file)
@@ -61,7 +61,7 @@ public:
 
     std::string dns_query(const std::string& _hostname) const;
 
-    std::string get_actual_ip();
+    std::string get_actual_ip( bool use_webcheck );
 
     std::string get_local_wan_nic_ip() const;
 
index e2d7ed9..2b42217 100644 (file)
@@ -310,12 +310,17 @@ int main(int argc, char *argv[])
 
     // Should we start in offline mode?
     is_online = !updater->get_config()->get_start_offline();
+    webcheck_enabled = updater->get_config()->get_webcheck_enabled();
 
     // service processing starts here
     do
     {
         if ( is_online == true )
         {
+            // Check if webcheck_enabled differs due to caught singnal then set it in config correspondingly
+            if ( updater->get_config()->get_webcheck_enabled() != webcheck_enabled )
+                updater->get_config()->set_webcheck_enabled(webcheck_enabled);
+
             // update all configured services
             updater->update_services();
         }
index 74ae13f..648baef 100644 (file)
@@ -219,7 +219,7 @@ void Updater::update_services() const
     list<Service::Ptr> services = ServiceHolder->get_services();
 
     // Get the actual IP of this host.
-    string ip_host = IPAddrHelp->get_actual_ip();
+    string ip_host = IPAddrHelp->get_actual_ip(Conf->get_webcheck_enabled());
 
     if ( !ip_host.empty() )
     {