summaryrefslogtreecommitdiff
path: root/FS/FS/part_export/phone_sqlradius.pm
diff options
context:
space:
mode:
authorivan <ivan>2008-10-24 02:54:07 +0000
committerivan <ivan>2008-10-24 02:54:07 +0000
commite9a16054f80c25ba75e5d1b3aba64052e3192d00 (patch)
treeb00600acb860bee37943e379b560f476a725ac90 /FS/FS/part_export/phone_sqlradius.pm
parent8032977c915b42634c70feee045b4ec42c3db98f (diff)
untested code to suck in CDRs in from VoIP RADIUS exports, RT#4100
Diffstat (limited to 'FS/FS/part_export/phone_sqlradius.pm')
-rw-r--r--FS/FS/part_export/phone_sqlradius.pm70
1 files changed, 69 insertions, 1 deletions
diff --git a/FS/FS/part_export/phone_sqlradius.pm b/FS/FS/part_export/phone_sqlradius.pm
index b93fe8c..eb867a2 100644
--- a/FS/FS/part_export/phone_sqlradius.pm
+++ b/FS/FS/part_export/phone_sqlradius.pm
@@ -2,7 +2,7 @@ package FS::part_export::phone_sqlradius;
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 @@ sub _export_unsuspend {}
#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;