[freeside-commits] freeside/FS/FS Upgrade.pm,1.6,1.7
Ivan,,,
ivan at wavetail.420.am
Sun May 18 15:42:57 PDT 2008
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv28674/FS/FS
Modified Files:
Upgrade.pm
Log Message:
on upgrade, automatically seed from sqlradius databases, and start freeside-sqlradius-radacctd by default
Index: Upgrade.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Upgrade.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Upgrade.pm 2 May 2008 01:58:19 -0000 1.6
+++ Upgrade.pm 18 May 2008 22:42:55 -0000 1.7
@@ -5,13 +5,14 @@
use Exporter;
use Tie::IxHash;
use FS::UID qw( dbh driver_name );
+use FS::Conf;
use FS::Record;
use FS::svc_domain;
$FS::svc_domain::whois_hack = 1;
@ISA = qw( Exporter );
- at EXPORT_OK = qw( upgrade );
+ at EXPORT_OK = qw( upgrade upgrade_sqlradius );
=head1 NAME
@@ -105,6 +106,70 @@
}
+sub upgrade_sqlradius {
+ #my %opt = @_;
+
+ my $conf = new FS::Conf;
+
+ my @part_export = FS::part_export::sqlradius->all_sqlradius_withaccounting();
+
+ foreach my $part_export ( @part_export ) {
+ my $dbh = DBI->connect( map $part_export->option($_),
+ qw ( datasrc username password ) );
+
+ my $str2time = str2time_sql( $dbh->{Driver}->{Name} );
+ my $group = "UserName";
+ $group .= ",Realm"
+ if ( ref($part_export) =~ /withdomain/ );
+
+ my $sth_alter = $dbh->prepare(
+ "ALTER TABLE radacct ADD COLUMN FreesideStatus varchar(32) NULL"
+ );
+ if ( $sth_alter && $sth_alter->execute ) {
+ my $sth_update = $dbh->prepare(
+ "UPDATE radacct SET FreesideStatus = 'done' WHERE FreesideStatus IS NULL"
+ ) or die $dbh->errstr;
+ $sth_update->execute or die $sth_update->errstr;
+ }
+
+ my $sth = $dbh->prepare("SELECT UserName,
+ Realm,
+ $str2time max(AcctStartTime)),
+ $str2time max(AcctStopTime))
+ FROM radacct
+ WHERE FreesideStatus = 'done'
+ AND AcctStartTime != 0
+ AND AcctStopTime != 0
+ GROUP BY $group
+ ")
+ or die $dbh->errstr;
+ $sth->execute() or die $sth->errstr;
+
+ while (my $row = $sth->fetchrow_arrayref ) {
+ my ($username, $realm, $start, $stop) = @$row;
+
+ $username = lc($username) unless $conf->exists('username-uppercase');
+ my $extra_sql = '';
+ if ( ref($part_export) =~ /withdomain/ ) {
+ $extra_sql = " And '$realm' = ( SELECT domain FROM svc_domain
+ WHERE svc_domain.svcnum = svc_acct.domsvc ) ";
+ }
+
+ my $svc_acct = qsearchs( 'svc_acct',
+ { 'username' => $username },
+ '',
+ $extra_sql,
+ );
+ if ($svc_acct) {
+ $svc_acct->last_login($start)
+ if $start && (!$svc_acct->last_login || $start > $svc_acct->last_login);
+ $svc_acct->last_logout($stop)
+ if $stop && (!$svc_acct->last_logout || $stop > $svc_acct->last_logout);
+ }
+ }
+ }
+
+}
=back
More information about the freeside-commits
mailing list