if (strncmp(var,"logfile", 7) == 0) {
if (zstr(val)) {
- globals.logfile_name = switch_core_strdup(globals.modpool, val);
- } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Null or empty Logfile attribute %s: %s\n", var, val);
+ } else {
+ globals.logfile_name = switch_core_strdup(globals.modpool, val);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown attribute %s: %s\n", var, val);
}
}
}
- if ( ! globals.logfile_name ) {
- switch_core_sprintf(globals.modpool, globals.logfile_name, "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, "fail2ban.log");
+ if ( zstr(globals.logfile_name) ) {
+ globals.logfile_name = switch_core_sprintf(globals.modpool, "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, "fail2ban.log");
}
if ((status = switch_file_open(&globals.logfile, globals.logfile_name, SWITCH_FOPEN_WRITE|SWITCH_FOPEN_APPEND|SWITCH_FOPEN_CREATE, SWITCH_FPROT_OS_DEFAULT, globals.modpool)) != SWITCH_STATUS_SUCCESS) {
static int fail2ban_logger(const char *message, char *user, char *ip)
{
+ switch_time_exp_t tm;
if (!globals.logfile) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not print to fail2ban log!\n");
return -1;
}
- struct tm * timeinfo = localtime(switch_epoch_time_now(NULL));
- return switch_file_printf(globals.logfile, "%s user[%s] ip[%s] at[%s]\n", message, user, ip, asctime(timeinfo));
+ switch_time_exp_lt(&tm, switch_micro_time_now());
+ return switch_file_printf(globals.logfile, "%s user[%s] ip[%s] at[%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d]\n", message, user, ip,
+ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+ tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
}
static void fail2ban_event_handler(switch_event_t *event)
{
- struct tm * timeinfo = localtime(switch_epoch_time_now(NULL));
if (event->event_id == SWITCH_EVENT_CUSTOM) {
if (strncmp(event->subclass_name, "sofia::register_attempt",23) == 0) {
fail2ban_logger("A registration was attempted", switch_event_get_header(event, "to-user"), switch_event_get_header(event, "network-ip"));