, Loglevel(0)
, Syslog(false)
, ConfigPath("/etc/bpdyndnsd")
+ , EnableIPv6(false)
+ , WebcheckIpUrl("")
+ , WebcheckIpUrlAlt("")
{
// initialize Logger
Log = _log;
("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.")
+ ("enable_ipv6",po::value<bool>()->default_value(false),"Try to use IPv6.")
+ ("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.")
;
// Define valid command line parameters
}
}
+ 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("enable_ipv6") )
+ EnableIPv6 = VariablesMap["enable_ipv6"].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>();
+
}
catch(po::unknown_option e)
{
/**
- *
- * @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)
po::store(parsed_main_options,VariablesMap);
po::notify(VariablesMap);
- if(VariablesMap.count("daemon_mode") && VariablesMap.count("loglevel") && VariablesMap.count("syslog"))
- {
- DaemonMode = VariablesMap["daemon_mode"].as<bool>();
- Loglevel = VariablesMap["loglevel"].as<int>();
- Syslog = VariablesMap["syslog"].as<bool>();
- }
+ 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("enable_ipv6") )
+ EnableIPv6 = VariablesMap["enable_ipv6"].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>();
+
}
catch ( po::unknown_option e ) // at the moment 04-08-2009 this exception is never thrown :-(
{
{
return Syslog;
}
+
+
+/**
+ * Getter for member EnableIPv6
+ * @return Wether IPv6 should be used or not.
+ */
+bool Config::get_enable_ipv6() const
+{
+ return EnableIPv6;
+}
+
+
+/**
+ * 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;
+}
int Loglevel;
bool Syslog;
std::string ConfigPath;
+ bool EnableIPv6;
+ std::string WebcheckIpUrl;
+ std::string WebcheckIpUrlAlt;
Service::Ptr create_service(const std::string&,const std::string&,const std::string&,const std::string&);
int load_main_config_file(const std::string&);
bool get_syslog() const;
+ bool get_enable_ipv6() const;
+
+ std::string get_webcheck_ip_url() const;
+
+ std::string get_webcheck_ip_url_alt() const;
+
void delete_variables_map();
};
*/
IPHelper::IPHelper()
: Hostname("")
- , WebcheckUrl("")
- , WebcheckUrlAlt("")
+ , WebcheckIpUrl("")
+ , WebcheckIpUrlAlt("")
, UseIPv6(false)
, Log(new Logger)
{
/**
* Constructor.
*/
-IPHelper::IPHelper(Logger::Ptr _log)
+IPHelper::IPHelper(const Logger::Ptr _log, const string& _webcheck_url, const string& _webcheck_url_alt, const bool _use_ipv6)
: Hostname("")
- , WebcheckUrl("")
- , WebcheckUrlAlt("")
- , UseIPv6(false)
- , Log(new Logger)
{
Log = _log;
+ WebcheckIpUrl = _webcheck_url;
+ WebcheckIpUrlAlt = _webcheck_url_alt;
+ UseIPv6 = _use_ipv6;
+ Hostname = net::ip::host_name();
+
+ Log->print_hostname(Hostname);
}
/**
- * Initializes the ip helper.
- */
-int IPHelper::init_hostname()
-{
- Hostname = net::ip::host_name();
-
- Log->print_hostname(Hostname);
-
- return 0;
-}
-
-
-/**
* 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 IPHelper::get_actual_ip() const
{
- if ( WebcheckUrl == "" )
+ if ( WebcheckIpUrl == "" )
{
return dns_query();
}
return "";
}
-void IPHelper::set_hostname(const string& _hostname)
-{
- Hostname = _hostname;
-}
-
/**
* Get the actual IP of this host through a DNS query.
net::ip::tcp::resolver::iterator end;
while(endpoint_iterator != end)
{
- net::ip::tcp::endpoint endpoint = endpoint_iterator->endpoint();
- net::ip::address ip = endpoint.address();
+ net::ip::tcp::endpoint endpoint = endpoint_iterator->endpoint(); // this ends up in a compiler warning: cc1plus: warning: dereferencing pointer 'pretmp.37188' does break strict-aliasing rules
+ net::ip::address ip = endpoint.address(); // but why?
if ( ip.is_v4() )
ip_addr_v4 = ip.to_string();
else if ( ip.is_v6() )
ip_addr_v6 = ip.to_string();
- Log->print_own_ip(ip_addr_v4, ip_addr_v6);
+ Log->print_own_ipv4(ip_addr_v4);
+ if ( UseIPv6 == true )
+ Log->print_own_ipv6(ip_addr_v6);
endpoint_iterator++;
}
io_service.reset();
return ip_addr;
}
-
-
-/**
- * Setter for both members WebcheckUrl and WebcheckUrlAlt
- * @param _webcheck_url The primary webcheck URL.
- * @param _webcheck_url_alt The fallback webcheck URL.
- */
-void IPHelper::set_webcheck_urls(std::string& _webcheck_url, std::string& _webcheck_url_alt)
-{
-
-}
{
private:
std::string Hostname;
- std::string WebcheckUrl;
- std::string WebcheckUrlAlt;
+ std::string WebcheckIpUrl;
+ std::string WebcheckIpUrlAlt;
bool UseIPv6;
IPHelper();
- IPHelper(Logger::Ptr);
+ IPHelper(const Logger::Ptr, const std::string&, const std::string&, const bool);
~IPHelper();
- void set_hostname(const std::string&);
-
std::string get_actual_ip() const;
std::string dns_query() const;
std::string webcheck_ip() const;
-
- void set_webcheck_urls(std::string&, std::string&);
-
- int init_hostname();
};
#endif
/**
- * Prints out the detected own ip address
+ * Prints out the detected own ipv4 address
* @param ip_addr String representation of the detected ip.
*/
-void Logger::print_own_ip(const std::string& ip_addr_v4, const std::string& ip_addr_v6) const
+void Logger::print_own_ipv4(const std::string& ip_addr_v4) const
{
if ( 1 <= Loglevel )
{
ostringstream msg;
msg << "Detected following IPv4-Address of this host: " << ip_addr_v4 << endl;
+ log_notice(msg.str());
+ }
+}
+
+
+/**
+ * Prints out the detected own ipv5 address
+ * @param ip_addr String representation of the detected ip.
+ */
+void Logger::print_own_ipv6(const std::string& ip_addr_v6) const
+{
+ if ( 1 <= Loglevel )
+ {
+ ostringstream msg;
msg << "Detected following IPv6-Address of this host: " << ip_addr_v6 << endl;
log_notice(msg.str());
}
void print_hostname(const std::string&) const;
- void print_own_ip(const std::string&, const std::string&) const;
+ void print_own_ipv4(const std::string&) const;
+
+ void print_own_ipv6(const std::string&) const;
void print_error_hostname_to_ip(const std::string&, const std::string&) const;
*/
void ODS::update(const string& ip)
{
- // if update was successful, we need to set the lastupdated base member.
- time_t actual_time = time(NULL);
- set_lastupdated(actual_time);
+ if ( this->get_actual_ip() != ip )
+ {
+ this->get_logger()->print_update_service("DHS");
+
+ if ( perform_update(ip) == 0 )
+ {
+ // if update was successful, we need to set the Lastupdated and ActualIP base member.
+ this->set_lastupdated(time(NULL));
+ this->set_actual_ip(ip);
+ this->get_logger()->print_update_service_successful("DHS");
+ }
+ }
+}
+
- get_logger()->print_update_service("ODS");
+/**
+ * Performs the Service update.
+ * @param ip IP Address to set.
+ * @return 0 if all is fine, -1 otherwise.
+ */
+int ODS::perform_update(const std::string& ip)
+{
+ return 0;
}
int get_max_updates_within_timeout() const;
void update(const std::string&);
+
+ int perform_update(const std::string&);
};
#endif
* Default constructor which initializes the member Conf.
*/
Updater::Updater()
+ : IPHelp(new IPHelper)
{
// Initialize program wide Logger, at this point we don't know where to log and with which loglevel.
Logger::Ptr _log(new Logger);
Config::Ptr _config(new Config(Log));
Conf = _config;
_config.reset();
-
- // initialize IPHelper
- IPHelper::Ptr _iphelp(new IPHelper(Log));
- IPHelp = _iphelp;
- _iphelp.reset();
}
*/
int Updater::init_ip_helper()
{
- IPHelp->init_hostname();
+ // initialize IPHelper
+ IPHelper::Ptr _iphelp(new IPHelper(Log,Conf->get_webcheck_ip_url(),Conf->get_webcheck_ip_url_alt(),Conf->get_enable_ipv6()));
+ IPHelp = _iphelp;
+ _iphelp.reset();
return 0;
}