diff --git a/INSTALL b/INSTALL index 6f5613954504b1b548e7cf9bb470cdf957c9b231..e51237344c20f81f009c207c68a2fe48a23d3d02 100644 --- a/INSTALL +++ b/INSTALL @@ -6,7 +6,7 @@ Installing SMRadius. - Net::Server >= 0.96 - Config::IniFiles (Debian based: libconfig-inifiles-perl, RPM based: perl-Config-IniFiles) - Cache::FastMmap (Debian based: libcache-fastmmap-perl, RPM based: perl-Cache-FastMmap) -- DateTime +- DateTime (requires: perl-Class-Singleton) - TimeDate - Crypt::DES - Crytpt::RC4 diff --git a/smradius/config.pm b/smradius/config.pm index 0323084275580ab26a4bd7fd3f44c32fb8f74bed..25d374f85bfc5defda1b219249b7bdc1223a5726 100644 --- a/smradius/config.pm +++ b/smradius/config.pm @@ -50,18 +50,26 @@ sub Init # Setup configuration $config = $server->{'inifile'}; + # Setup database config my $db; $db->{'DSN'} = $config->{'database'}{'dsn'}; $db->{'Username'} = $config->{'database'}{'username'}; $db->{'Password'} = $config->{'database'}{'password'}; $db->{'enabled'} = 0; - # Check we have all the config we need if (!defined($db->{'DSN'})) { $server->log(LOG_NOTICE,"smradius/config.pm: No 'DSN' defined in config file for 'database'"); } - $server->{'smradius'}{'database'} = $db; + + # Setup event timezone config + if (defined($config->{'server'}{'event_timezone'})) { + $server->{'smradius'}{'event_timezone'} = $config->{'server'}{'event_timezone'}; + } else { + $server->{'smradius'}{'event_timezone'} = "GMT"; + } + + $server->log(LOG_NOTICE,"smradius/config.pm: Using timezone '".$server->{'smradius'}{'event_timezone'}."'"); } diff --git a/smradius/modules/accounting/mod_accounting_sql.pm b/smradius/modules/accounting/mod_accounting_sql.pm index 92933cffa50fbd0238a3967cbc4a3dfbb9e3af25..e8b3e02f57135b37f4f9798280f4c24d48a729f9 100644 --- a/smradius/modules/accounting/mod_accounting_sql.pm +++ b/smradius/modules/accounting/mod_accounting_sql.pm @@ -321,7 +321,7 @@ sub getUsage $template->{'user'} = $user; # Current PeriodKey - my $now = DateTime->now; + my $now = DateTime->now->set_time_zone($server->{'smradius'}->{'event_timezone'}); $template->{'query'}->{'PeriodKey'} = $now->strftime("%Y-%m"); # Replace template entries @@ -409,7 +409,7 @@ sub acct_log $template->{'user'} = $user; # Current PeriodKey - my $now = DateTime->now; + my $now = DateTime->now->set_time_zone($server->{'smradius'}->{'event_timezone'}); my $periodKey = $now->strftime("%Y-%m"); # For our queries @@ -711,7 +711,7 @@ sub cleanup my ($server) = @_; # The datetime now.. - my $now = DateTime->now; + my $now = DateTime->now->set_time_zone($server->{'smradius'}->{'event_timezone'}); # If this is a new year my ($prevYear,$prevMonth); diff --git a/smradius/modules/system/mod_config_sql_topups.pm b/smradius/modules/system/mod_config_sql_topups.pm index ee48eebe0dc053193ff13cd835377a209dd63db8..90a5fd77a0c888c6fcea13060d9bf316273faf5a 100644 --- a/smradius/modules/system/mod_config_sql_topups.pm +++ b/smradius/modules/system/mod_config_sql_topups.pm @@ -298,7 +298,7 @@ sub cleanup DBFreeRes($sth); # The datetime now - my $now = DateTime->now; + my $now = DateTime->now->set_time_zone($server->{'smradius'}->{'event_timezone'}); # Make datetime my $thisMonth = DateTime->new( year => $now->year, month => $now->month, day => 1 ); diff --git a/smradiusd b/smradiusd index d5c6ca90729bf8cfe373cbd86942170eba9b945b..a5d5bf5e8a34c72dec3fc7950eced5b132c052e6 100755 --- a/smradiusd +++ b/smradiusd @@ -133,7 +133,7 @@ sub configure { 'min_spare_servers', 'max_spare_servers', 'max_servers', - 'max_requests', + 'max_requests' ); foreach my $param (@server_params) { $server->{$param} = $config{'server'}{$param} if (defined($config{'server'}{$param})); @@ -501,7 +501,12 @@ sub process_request { $user->{'_Internal'} = { 'Timestamp-Unix' => defined($pkt->rawattr('Event-Timestamp')) ? $pkt->rawattr('Event-Timestamp') : time() }; - my $eventTimestamp = DateTime->from_epoch( epoch => $user->{'_Internal'}->{'Timestamp-Unix'} ); + # VERY IMPORTANT!!!!!! + # Timestamp AND Timestamp-Unix are in the CONVERTED timezone (event_timezone) + my $eventTimestamp = DateTime->from_epoch( + epoch => $user->{'_Internal'}->{'Timestamp-Unix'}, + time_zone => $self->{'smradius'}->{'event_timezone'} + ); $user->{'_Internal'}->{'Timestamp'} = $eventTimestamp->strftime('%Y-%m-%d %H:%M:%S'); # Set username diff --git a/smradiusd.conf b/smradiusd.conf index 482bc978284c698f579f2d37f406a780858a45e1..056bf0477157b667fc5124c5d4ee74549fbc8dbd 100644 --- a/smradiusd.conf +++ b/smradiusd.conf @@ -68,6 +68,9 @@ #cidr_allow=0.0.0.0/0 #cidr_deny= +# Event timestamp timezone, in "Continent/City" format +# Defaults to "GMT" +event_timezone=GMT [database]