[freeside-commits] freeside/FS/FS/part_export sqlradius.pm, 1.38, 1.39 phone_sqlradius.pm, 1.1, 1.2
Ivan,,,
ivan at wavetail.420.am
Thu Oct 23 19:54:09 PDT 2008
Update of /home/cvs/cvsroot/freeside/FS/FS/part_export
In directory wavetail.420.am:/tmp/cvs-serv21419/FS/part_export
Modified Files:
sqlradius.pm phone_sqlradius.pm
Log Message:
untested code to suck in CDRs in from VoIP RADIUS exports, RT#4100
Index: phone_sqlradius.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_export/phone_sqlradius.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- phone_sqlradius.pm 24 Oct 2008 01:19:46 -0000 1.1
+++ phone_sqlradius.pm 24 Oct 2008 02:54:06 -0000 1.2
@@ -2,7 +2,7 @@
use vars qw(@ISA $DEBUG %info );
use Tie::IxHash;
-use FS::Record; #qw( dbh qsearch qsearchs str2time_sql );
+use FS::Record qw( dbh str2time_sql ); #qsearch qsearchs );
#use FS::part_export;
use FS::part_export::sqlradius;
#use FS::svc_phone;
@@ -88,5 +88,73 @@
#probably harmless that we ->can('usage_sessions').... ?
+#we want to feed these into CDRs, not update svc_acct records
+sub update_svc {
+ my $self = shift;
+
+ my $fdbh = dbh;
+ my $dbh = sqlradius_connect( map $self->option($_),
+ qw( datasrc username password ) );
+
+ my $str2time = str2time_sql( $dbh->{Driver}->{Name} );
+
+
+
+ my @fields = qw( radacctid username realm acctsessiontime );
+
+ my @param = ();
+ my $where = '';
+
+ my $sth = $dbh->prepare("
+ SELECT RadAcctId, UserName, AcctSessionTime,
+ $str2time AcctStartTime), $str2time AcctStopTime),
+ CallingStationID, CalledStationID
+ FROM radacct
+ WHERE FreesideStatus IS NULL
+ AND AcctStopTime != 0
+ ") or die $dbh->errstr;
+ $sth->execute() or die $sth->errstr;
+
+ while ( my $row = $sth->fetchrow_arrayref ) {
+ my( $RadAcctId, $UserName, $AcctSessionTime,
+ $AcctStartTime, $AcctStopTime,
+ $CallingStationID, $CalledStationID,
+ )= @$row;
+ warn "processing record: ".
+ "$RadAcctId ($UserName for ${AcctSessionTime}s"
+ if $DEBUG;
+
+ my $oldAutoCommit = $FS::UID::AutoCommit; # can't undo side effects, but at
+ local $FS::UID::AutoCommit = 0; # least we can avoid over counting
+
+ my $cdr = new FS::cdr {
+ 'src' => $CallingStationID,
+ 'charged_party' => $UserName,
+ 'dst' => $CalledStationID,
+ 'startdate' => $AcctStartTime,
+ 'enddate' => $AcctStopTime,
+ 'duration' => $AcctStopTime - $AcctStartTime,
+ 'billsec' => $AcctSessionTime,
+ };
+
+ my $errinfo = "for RADIUS detail RadAcctID $RadAcctId ".
+ "(UserName $UserName)";
+
+ my $error = $cdr->insert;
+ my $status = $error ? 'skipped' : 'done';
+
+ warn "setting FreesideStatus to $status $errinfo\n" if $DEBUG;
+ my $psth = $dbh->prepare("UPDATE radacct
+ SET FreesideStatus = ?
+ WHERE RadAcctId = ?"
+ ) or die $dbh->errstr;
+ $psth->execute($status, $RadAcctId) or die $psth->errstr;
+
+ $fdbh->commit or die $fdbh->errstr if $oldAutoCommit;
+
+ }
+
+}
+
1;
Index: sqlradius.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_export/sqlradius.pm,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- sqlradius.pm 24 Oct 2008 01:19:46 -0000 1.38
+++ sqlradius.pm 24 Oct 2008 02:54:06 -0000 1.39
@@ -672,7 +672,7 @@
=cut
-sub update_svc_acct {
+sub update_svc {
my $self = shift;
my $conf = new FS::Conf;
@@ -706,7 +706,7 @@
$UserName = lc($UserName) unless $conf->exists('username-uppercase');
- my %search = ( 'username' => $UserName );
+ #my %search = ( 'username' => $UserName );
my $extra_sql = '';
if ( ref($self) =~ /withdomain/ ) { #well...
@@ -799,7 +799,7 @@
my @part_export = ();
push @part_export, qsearch('part_export', { 'exporttype' => $_ } )
- foreach qw(sqlradius sqlradius_withdomain radiator);
+ foreach qw( sqlradius sqlradius_withdomain radiator phone_sqlradius );
@part_export;
}
More information about the freeside-commits
mailing list