summaryrefslogtreecommitdiff
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
parent8032977c915b42634c70feee045b4ec42c3db98f (diff)
untested code to suck in CDRs in from VoIP RADIUS exports, RT#4100
-rw-r--r--FS/FS/part_export/phone_sqlradius.pm70
-rw-r--r--FS/FS/part_export/sqlradius.pm6
-rw-r--r--FS/bin/freeside-sqlradius-radacctd6
3 files changed, 75 insertions, 7 deletions
diff --git a/FS/FS/part_export/phone_sqlradius.pm b/FS/FS/part_export/phone_sqlradius.pm
index b93fe8c1a..eb867a273 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;
diff --git a/FS/FS/part_export/sqlradius.pm b/FS/FS/part_export/sqlradius.pm
index fca6e09fe..87c5739a1 100644
--- a/FS/FS/part_export/sqlradius.pm
+++ b/FS/FS/part_export/sqlradius.pm
@@ -672,7 +672,7 @@ sub usage_sessions {
=cut
-sub update_svc_acct {
+sub update_svc {
my $self = shift;
my $conf = new FS::Conf;
@@ -706,7 +706,7 @@ sub update_svc_acct {
$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 @@ sub all_sqlradius {
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;
}
diff --git a/FS/bin/freeside-sqlradius-radacctd b/FS/bin/freeside-sqlradius-radacctd
index 4c5c11a2d..7b2d04dc7 100644
--- a/FS/bin/freeside-sqlradius-radacctd
+++ b/FS/bin/freeside-sqlradius-radacctd
@@ -32,8 +32,8 @@ daemonize2();
my @part_export = FS::part_export::sqlradius->all_sqlradius_withaccounting();
-die "no sqlradius, sqlradius_withdomain or radiator exports without".
- " ignore_accounting"
+die "no sqlradius, sqlradius_withdomain, radiator or phone_sqlradius exports".
+ " without ignore_accounting"
unless @part_export;
while (1) {
@@ -55,7 +55,7 @@ while (1) {
adminsuidsetup($user); #get our own db handle
until ( sigint || sigterm ) {
- $part_export->update_svc_acct();
+ $part_export->update_svc();
sleep 1;
}