Added possibility to override automatic WAN IP detection
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 8 Dec 2010 14:42:52 +0000 (15:42 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 8 Dec 2010 14:42:52 +0000 (15:42 +0100)
src/config.cpp
src/config.hpp
src/ip_addr_helper.cpp
src/ip_addr_helper.hpp
src/updater.cpp

index b3b1494..acc8a27 100644 (file)
@@ -144,6 +144,7 @@ void Config::define_config_options()
         ("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
@@ -297,6 +298,9 @@ int Config::parse_cmd_line(int argc, char *argv[])
             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( const po::unknown_option& e )
     {
@@ -564,6 +568,9 @@ int Config::load_main_config_file(const string& full_filename)
                 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( const po::unknown_option& e )
         {
@@ -848,3 +855,12 @@ 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;
+}
index a5b75f3..bf836cc 100644 (file)
@@ -52,6 +52,7 @@ private:
     bool DialupMode;
     int DialupBurstPeriodSeconds;
     int DialupSleepSeconds;
+    std::string WanIpOverride;
 
     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);
@@ -113,6 +114,8 @@ public:
     bool get_dialup_mode() const;
     int get_dialup_burst_period_seconds() const;
     int get_dialup_sleep_seconds() const;
+
+    std::string get_wan_ip_override() const;
 };
 
 #endif
index 16359dd..b0b2a84 100644 (file)
@@ -180,15 +180,19 @@ 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.
+ * @param use_webcheck If true: Determine IP via web check
  * @param changed_to_online Indicates if we just went online
+ * @param wan_override_ip Override automatic WAN IP detection if not empty
  * @return A string representation of the actual IP in dotted format or an empty string if something went wrong.
  */
-string IPAddrHelper::get_actual_ip( bool use_webcheck, bool changed_to_online )
+string IPAddrHelper::get_actual_ip( bool use_webcheck, bool changed_to_online, const std::string &wan_override_ip )
 {
     string ip;
 
     if ( !WebcheckIpUrl.empty() && use_webcheck )
         ip = webcheck_ip(changed_to_online);
+    else if (!wan_override_ip.empty())
+        ip = wan_override_ip;
     else
         ip = get_local_wan_nic_ip();
 
index c150f39..c54a503 100644 (file)
@@ -61,7 +61,7 @@ public:
 
     std::string dns_query(const std::string& _hostname) const;
 
-    std::string get_actual_ip( bool use_webcheck, bool changed_to_online );
+    std::string get_actual_ip( bool use_webcheck, bool changed_to_online, const std::string &wan_override_ip );
 
     std::string get_local_wan_nic_ip() const;
 
index f204b4f..5d32d10 100644 (file)
@@ -228,7 +228,7 @@ void Updater::update_services(bool changed_to_online) const
     list<Service::Ptr> services = ServiceHolder->get_services();
 
     // Get the actual IP of this host.
-    string ip_host = IPAddrHelp->get_actual_ip(Conf->get_webcheck_enabled(), changed_to_online);
+    string ip_host = IPAddrHelp->get_actual_ip(Conf->get_webcheck_enabled(), changed_to_online, Conf->get_wan_ip_override());
     if ( ip_host.empty() )
     {
         Log->print_no_wan_ip(changed_to_online);