| 1 | /** @file |
| 2 | * @brief Logger class header. This class represents the Logging facility. |
| 3 | * |
| 4 | * |
| 5 | * |
| 6 | * @copyright Intra2net AG |
| 7 | * @license GPLv2 |
| 8 | */ |
| 9 | |
| 10 | #ifndef LOGGER_H |
| 11 | #define LOGGER_H |
| 12 | |
| 13 | #include <string> |
| 14 | #include <list> |
| 15 | |
| 16 | #include <boost/program_options.hpp> |
| 17 | #include <boost/shared_ptr.hpp> |
| 18 | |
| 19 | #include <curl/curl.h> |
| 20 | |
| 21 | class Logger |
| 22 | { |
| 23 | |
| 24 | private: |
| 25 | |
| 26 | int Loglevel; |
| 27 | bool Syslog; |
| 28 | std::string ExternalWarningLog; |
| 29 | int ExternalWarningLevel; |
| 30 | std::set<std::string> ExternalSendMessages; |
| 31 | bool ExternalLogOnlyOnce; |
| 32 | bool LogPasswords; |
| 33 | |
| 34 | public: |
| 35 | |
| 36 | typedef boost::shared_ptr<Logger> Ptr; |
| 37 | |
| 38 | Logger(); |
| 39 | |
| 40 | ~Logger(); |
| 41 | |
| 42 | void set_external_log_only_once( const bool _external_log_only_once ); |
| 43 | |
| 44 | void set_log_passwords( const bool _log_passwords ); |
| 45 | |
| 46 | void clear_external_send_messages(); |
| 47 | |
| 48 | std::string escape_shellarg(const std::string &input); |
| 49 | |
| 50 | void log_notice(const std::string& msg) const; |
| 51 | |
| 52 | void log_warning(const std::string& msg, int loglevel); |
| 53 | |
| 54 | void log_error(const std::string& msg) const; |
| 55 | |
| 56 | void set_loglevel(const int _loglevel); |
| 57 | |
| 58 | int get_loglevel() const; |
| 59 | |
| 60 | void set_syslog(const bool _syslog); |
| 61 | |
| 62 | bool get_syslog() const; |
| 63 | |
| 64 | void set_log_facility(const int _loglevel, const bool _syslog, const std::string& _external_error_log, const int _external_error_level, const bool _external_log_only_once ); |
| 65 | |
| 66 | bool is_allowed_to_send( const std::string& msg ) const; |
| 67 | |
| 68 | // Start log messages. |
| 69 | |
| 70 | void print_usage(const boost::shared_ptr<boost::program_options::options_description> opt_desc) const; |
| 71 | |
| 72 | void print_version() const; |
| 73 | |
| 74 | void print_started() const; |
| 75 | |
| 76 | void print_cmd_parsed() const; |
| 77 | |
| 78 | void print_conf_files_parsed() const; |
| 79 | |
| 80 | void print_destructor_call(const std::string& _class) const; |
| 81 | |
| 82 | void print_constructor_call(const std::string& _class) const; |
| 83 | |
| 84 | void print_update_service(const std::string& service) const; |
| 85 | |
| 86 | void print_update_service_is_blocked(const std::string& service, int remaining_seconds) const; |
| 87 | |
| 88 | void print_block_service(const std::string& service, int block_seconds) const; |
| 89 | |
| 90 | void print_unknown_cmd_option(const std::string& unknown_option) const; |
| 91 | |
| 92 | void print_unknown_protocol(const std::string& protocol) const; |
| 93 | |
| 94 | void print_load_service_conf(const std::string& filename) const; |
| 95 | |
| 96 | void print_load_main_conf(const std::string& filename) const; |
| 97 | |
| 98 | void print_unknown_service_conf_option(const std::string& service_conf_file, const std::string& unknown_option) const; |
| 99 | |
| 100 | void print_unknown_main_conf_option(const std::string& unknown_option) const; |
| 101 | |
| 102 | void print_error_opening_r(const std::string& filename) const; |
| 103 | |
| 104 | void print_error_opening_rw(const std::string& filename) const; |
| 105 | |
| 106 | void print_error_config_path(const std::string& config_path) const; |
| 107 | |
| 108 | void print_conf_loaded(const std::string& config_path) const; |
| 109 | |
| 110 | void print_conf_not_loaded(const std::string& config_path) const; |
| 111 | |
| 112 | void print_conf_reload_failed_exit() const; |
| 113 | |
| 114 | void print_missing_cmd_service_option() const; |
| 115 | |
| 116 | void print_missing_service_conf_option(const std::string& service_conf_file) const; |
| 117 | |
| 118 | void print_runnig_as_daemon(const int pid) const; |
| 119 | |
| 120 | void print_daemon_mode(const bool daemon_mode) const; |
| 121 | |
| 122 | void print_error_fork() const; |
| 123 | |
| 124 | void print_pid_found(const int pid) const; |
| 125 | |
| 126 | void print_process_already_running(const int pid) const; |
| 127 | |
| 128 | void print_caught_sigterm() const; |
| 129 | |
| 130 | void print_caught_siguser1() const; |
| 131 | |
| 132 | void print_caught_sighup() const; |
| 133 | |
| 134 | void print_caught_siguser2() const; |
| 135 | |
| 136 | void print_caught_sigrtmin() const; |
| 137 | |
| 138 | void print_caught_sigrtmax(int new_loglevel) const; |
| 139 | |
| 140 | void print_error_setting_signal(const std::string& signal) const; |
| 141 | |
| 142 | void print_init_log_facility() const; |
| 143 | |
| 144 | void print_offline_mode() const; |
| 145 | |
| 146 | void print_sleep_dialup_mode(time_t sleep_until) const; |
| 147 | |
| 148 | void print_serialized_objects_success() const; |
| 149 | |
| 150 | void print_deserialized_objects_success() const; |
| 151 | |
| 152 | void print_service_object(const std::string& message, const std::string& protocol, const std::string& hostname, const std::string& login, const std::string& password, const int update_interval, const int max_updates_within_interval, const int max_equal_updates_in_succession, const int dns_cache_ttl , const std::string& actual_ip, std::map<time_t,std::string> lastupdates, const bool activated) const; |
| 153 | |
| 154 | void print_exception_serialize(const std::string& errMsg) const; |
| 155 | |
| 156 | void print_exception_deserialize(const std::string& errMsg) const; |
| 157 | |
| 158 | void print_error_kill_child(const int pid) const; |
| 159 | |
| 160 | void print_child_killed(const int pid) const; |
| 161 | |
| 162 | void print_no_object_file(const std::string& object_file); |
| 163 | |
| 164 | void print_hostname(const std::string& hostname) const; |
| 165 | |
| 166 | void print_own_ipv4(const std::string& ip_addr_v4, const std::string& hostname) const; |
| 167 | |
| 168 | void print_own_ipv6(const std::string& ip_addr_v6, const std::string& hostname) const; |
| 169 | |
| 170 | void print_error_hostname_to_ip(const std::string& errMsg, const std::string& hostname) const; |
| 171 | |
| 172 | void print_update_service_successful(const std::string& service, const std::string& ip_addr) const; |
| 173 | |
| 174 | void print_webcheck_no_ip(); |
| 175 | |
| 176 | void print_no_wan_ip(bool override_log_level) const; |
| 177 | |
| 178 | void print_external_wan_ip(bool override_log_level, const std::string &wan_ip) const; |
| 179 | |
| 180 | void print_dns_lookup_failed(bool override_log_level, const std::string &hostname) const; |
| 181 | |
| 182 | void print_webcheck_url_connection_problem(const char * curl_err_buff, const std::string& url); |
| 183 | |
| 184 | void print_webcheck_error(const char * curl_err_buff, const std::string& url) const; |
| 185 | |
| 186 | void print_received_curl_data(const std::string& curl_data) const; |
| 187 | |
| 188 | void print_regex_found_ip(const std::string& ip) const; |
| 189 | |
| 190 | void print_regex_ip_not_found(const std::string& data); |
| 191 | |
| 192 | void print_multiple_cmd_option(const std::string& message) const; |
| 193 | |
| 194 | void print_multiple_service_conf_option(const std::string& service_conf_file, const std::string& message) const; |
| 195 | |
| 196 | void print_multiple_main_conf_option(const std::string& main_conf_file, const std::string& message) const; |
| 197 | |
| 198 | void print_update_not_allowed(bool override_log_level, const time_t current_time, const time_t old_time, const int MaxUpdatesWithinInterval, const std::string& service); |
| 199 | |
| 200 | void print_update_service_failure(const std::string& service); |
| 201 | |
| 202 | void print_starting_shutdown() const; |
| 203 | |
| 204 | void print_shutdown_succeeded() const; |
| 205 | |
| 206 | void print_shutdown_parent_succeeded() const; |
| 207 | |
| 208 | void print_starting_shutdown_parent() const; |
| 209 | |
| 210 | void print_recheck_dns_entry(const std::string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const; |
| 211 | |
| 212 | void print_missing_cmd_proxy_option() const; |
| 213 | |
| 214 | void print_missing_conf_proxy_option(const std::string& main_conf_filename) const; |
| 215 | |
| 216 | void print_no_domain_part(const std::string& hostname) const; |
| 217 | |
| 218 | void print_curl_error_init(const std::string& err_msg, const CURLcode curl_err_code) const; |
| 219 | |
| 220 | void print_curl_error(const std::string& url, const CURLcode curl_err_code) const; |
| 221 | |
| 222 | void print_curl_error(const std::string& url, const CURLcode curl_err_code, const char * curl_err_buff) const; |
| 223 | |
| 224 | void print_curl_data(const std::string& curl_writedata_buff) const; |
| 225 | |
| 226 | void print_service_not_authorized(const std::string& service, const std::string& username, const std::string& password) const; |
| 227 | |
| 228 | void print_httphelper_not_initialized() const; |
| 229 | |
| 230 | void print_http_status_code(const std::string& url, const long http_code) const; |
| 231 | |
| 232 | void print_update_failure(const std::string& url, const std::string& curl_data) const; |
| 233 | |
| 234 | void print_update_failure(const std::string& url, const long http_status_code) const; |
| 235 | |
| 236 | void print_invalid_hostname(const std::string& hostname); |
| 237 | |
| 238 | void print_ip_is_local(const std::string& ip); |
| 239 | |
| 240 | void print_regex_match(const std::string& regex, const std::string& matching_string) const; |
| 241 | |
| 242 | void print_no_regex_match(const std::string& regex, const std::string& not_matching_string); |
| 243 | |
| 244 | void print_could_not_parse_received_data(const std::string& curl_data) const; |
| 245 | |
| 246 | void print_could_not_get_initial_gnudip_data() const; |
| 247 | |
| 248 | void print_gnudip_requires_servername(); |
| 249 | |
| 250 | void print_exception_md5_sum(const std::string& what) const; |
| 251 | |
| 252 | void print_network_error(const std::string& what) const; |
| 253 | |
| 254 | void print_undefined_protocol_error(const std::string& protocol, const std::string& error) const; |
| 255 | |
| 256 | void print_error_external_logging(const std::string& external_prog) const; |
| 257 | |
| 258 | void print_error_parsing_config_file(const std::string& filename, const std::string& error) const; |
| 259 | |
| 260 | void print_error_parsing_cmd(const std::string& error) const; |
| 261 | |
| 262 | void print_webcheck_exceed_interval( const time_t last_webcheck, const int webcheck_interval, const time_t current_time ) const; |
| 263 | |
| 264 | void print_check_service_update(const std::string& hostname, const time_t current_time, const time_t lastupdated) const; |
| 265 | |
| 266 | void print_cached_dns_entry(const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host) const; |
| 267 | |
| 268 | void print_update_service(const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host, const time_t lastupdated) const; |
| 269 | |
| 270 | void print_update_service_ttl_expired(const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host, const time_t lastupdated, const int dns_cache_ttl, const time_t current_time) const; |
| 271 | |
| 272 | void print_update_service_ttl_not_expired(bool override_log_level, const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host, const time_t lastupdated, const int dns_cache_ttl, const time_t current_time) const; |
| 273 | |
| 274 | void print_no_update_needed(bool override_log_level, const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host, const time_t lastupdated) const; |
| 275 | |
| 276 | void print_error_getting_local_wan_ip(const std::string& system_call, const std::string& error) const; |
| 277 | |
| 278 | void print_invalid_service_config() const; |
| 279 | |
| 280 | void print_msg( const std::string& msg ) const; |
| 281 | |
| 282 | void print_last_updates( const std::string& ip_host, const time_t current_time, const int update_interval, const int max_updates_within_interval, const int max_equal_updates_in_succession, const std::map<time_t,std::string>& last_updates, const std::string& servicename ) const; |
| 283 | |
| 284 | void print_ip_burnt( const std::string& ip_host, const std::string& hostname ) const; |
| 285 | }; |
| 286 | |
| 287 | #endif |