1 package FS::part_export::radiator;
3 use vars qw(@ISA %info $radusers);
5 use FS::part_export::sqlradius;
7 tie my %options, 'Tie::IxHash', %FS::part_export::sqlradius::options;
11 'desc' => 'Real-time export to RADIATOR',
12 'options' => \%options,
15 Real-time export of the <b>radusers</b> table to any SQL database in
16 <a href="http://www.open.com.au/radiator/">Radiator</a>-native format.
17 To setup accounting, see the RADIATOR documentation for hooks to update
18 a standard <b>radacct</b> table.
22 @ISA = qw(FS::part_export::sqlradius); #for regular sqlradius accounting
24 $radusers = 'RADUSERS'; #MySQL is case sensitive about table names! huh
26 #sub export_username {
27 # my($self, $svc_acct) = (shift, shift);
32 my( $self, $svc_acct ) = (shift, shift);
34 $self->radiator_queue(
37 $self->_radiator_hash($svc_acct),
42 my( $self, $new, $old ) = (shift, shift, shift);
44 # return "can't (yet) change domain with radiator export"
45 # if $old->domain ne $new->domain;
46 # return "can't (yet) change username with radiator export"
47 # if $old->username ne $new->username;
49 $self->radiator_queue(
52 $self->export_username($old),
53 $self->_radiator_hash($new),
58 my( $self, $svc_acct ) = (shift, shift);
60 $self->radiator_queue(
63 $self->export_username($svc_acct),
68 my( $self, $svc_acct ) = @_;
70 'username' => $self->export_username($svc_acct),
71 'pass_word' => $svc_acct->crypt_password,
72 'fullname' => $svc_acct->finger,
73 map { my $method = "radius_$_"; $_ => $svc_acct->$method(); }
74 qw( framed_filter_id framed_mtu framed_netmask framed_protocol
75 framed_routing login_host login_service login_tcp_port )
77 $hash{'timeleft'} = $svc_acct->seconds
78 if $svc_acct->seconds =~ /^\d+$/;
79 $hash{'staticaddress'} = $svc_acct->slipip
80 if $svc_acct->slipip =~ /^[\d\.]+$/; # and $self->slipip ne '0.0.0.0';
82 $hash{'servicename'} = ( $svc_acct->radius_groups )[0];
84 my $cust_pkg = $svc_acct->cust_svc->cust_pkg;
85 $hash{'validto'} = $cust_pkg->bill
86 if $cust_pkg && $cust_pkg->part_pkg->is_prepaid && $cust_pkg->bill;
88 #some other random stuff, should probably be attributes or virtual fields
89 #$hash{'state'} = 0; #only inserts
90 #$hash{'badlogins'} = 0; #only inserts
91 $hash{'maxlogins'} = 1;
92 $hash{'addeddate'} = $cust_pkg->setup
93 if $cust_pkg && $cust_pkg->setup;
94 $hash{'validfrom'} = $cust_pkg->last_bill || $cust_pkg->setup
95 if $cust_pkg && ( $cust_pkg->last_bill || $cust_pkg->setup );
96 $hash{'state'} = $cust_pkg->susp ? 1 : 0
103 my( $self, $svcnum, $method ) = (shift, shift, shift);
104 my $queue = new FS::queue {
106 'job' => "FS::part_export::radiator::radiator_$method",
109 $self->option('datasrc'),
110 $self->option('username'),
111 $self->option('password'),
116 sub radiator_insert { #subroutine, not method
117 my $dbh = radiator_connect(shift, shift, shift);
119 $hash{'state'} = 0; #see "random stuff" above
120 $hash{'badlogins'} = 0; #see "random stuff" above
122 my $sth = $dbh->prepare(
123 "INSERT INTO $radusers ( ". join(', ', keys %hash ). ' ) '.
124 'VALUES ( '. join(', ', map '?', keys %hash ). ' ) '
125 ) or die $dbh->errstr;
126 $sth->execute( values %hash )
133 sub radiator_replace { #subroutine, not method
134 my $dbh = radiator_connect(shift, shift, shift);
135 my ( $old_username, %hash ) = @_;
137 my $sth = $dbh->prepare(
138 "UPDATE $radusers SET ". join(', ', map " $_ = ?", keys %hash ).
139 ' WHERE username = ?'
140 ) or die $dbh->errstr;
141 $sth->execute( values(%hash), $old_username )
147 sub radiator_delete { #subroutine, not method
148 my $dbh = radiator_connect(shift, shift, shift);
149 my ( $username ) = @_;
151 my $sth = $dbh->prepare(
152 "DELETE FROM $radusers WHERE username = ?"
153 ) or die $dbh->errstr;
154 $sth->execute( $username )
161 sub radiator_connect {
162 #my($datasrc, $username, $password) = @_;
163 #DBI->connect($datasrc, $username, $password) or die $DBI::errstr;
164 DBI->connect(@_) or die $DBI::errstr;