FreeRADIUS-Database
view release on metacpan or search on metacpan
lib/FreeRADIUS/Database.pm view on Meta::CPAN
}
else {
$datetime = DateTime->now( time_zone => $self->TIMEZONE() );
}
if ( $get_what eq 'day' ) {
return $datetime->ymd();
}
if ( $get_what eq 'month' ) {
my $month = $datetime->month();
if ( length( $month ) == 1 ) {
$month = 0 . $month;
}
my $date = $datetime->year() . "-" . $month;
return $date;
}
if ( $get_what eq 'year' ) {
my $date = $datetime->year();
return $date;
}
return ( DateTime->now( time_zone => $self->TIMEZONE()) );
}
sub password {
my $self = shift;
my $params = shift;
my $username = $params->{ username };
my $new_pw = $params->{ password };
my $schema = $self->_schema();
my $rs = $schema->resultset( 'Radcheck' )->find({ UserName => $username });
return if ! $rs;
my $orig_pw = $rs->Value();
return $orig_pw if ! $new_pw;
if ( $new_pw ) {
$rs->Value( $new_pw );
$rs->update();
}
return $self->password({ username => $username });
}
# NAS
sub update_ras_name {
my $self = shift;
my $params = shift;
my $day = $params->{ day };
my $ras_href = $self->RAS();
my @classified_ras;
my $schema = $self->_schema();
while ( my( $ras_class, $ras_regex ) = ( each %$ras_href ) ) {
my @ras_ips;
if ( $ras_regex =~ /|/ ) {
@ras_ips = split ( /\|/, $ras_regex );
}
else {
push @ras_ips, $ras_regex;
}
for my $ras_to_classify ( @ras_ips ) {
my $rs = $schema->resultset( 'Radacct' )->search({
'AcctStopTime' => { like => "$day%" },
'NASIPAddress' => { like => "$ras_to_classify%" },
});
$rs->update({ NASIPAddress => $ras_class });
}
}
return 0;
}
# mathematical functions
sub seconds_to_hours {
my $self = shift;
my $seconds = shift;
my $hours = sprintf ( '%.2f', ( ($seconds / 60) / 60 ) );
return $hours;
}
sub bytes_to_megabytes {
my $self = shift;
my $bytes = shift;
my $mb = sprintf ( '%.2f', ( ($bytes / 1024) / 1024 ) );
return $mb;
}
sub bytes_to_gigabytes {
my $self = shift;
( run in 1.478 second using v1.01-cache-2.11-cpan-39bf76dae61 )