1 package FS::part_export::radiator;
3 use vars qw(@ISA %info $radusers);
5 use FS::part_export::sqlradius;
8 tie my %options, 'Tie::IxHash', %FS::part_export::sqlradius::options;
12 'desc' => 'Real-time export to RADIATOR',
13 'options' => \%options,
16 'default_svc_class' => 'Internet',
18 Real-time export of the <b>radusers</b> table to any SQL database in
19 <a href="http://www.open.com.au/radiator/">Radiator</a>-native format.
20 To setup accounting, see the RADIATOR documentation for hooks to update
21 a standard <b>radacct</b> table.
25 @ISA = qw(FS::part_export::sqlradius); #for regular sqlradius accounting
27 $radusers = 'RADUSERS'; #MySQL is case sensitive about table names! huh
29 #sub export_username {
30 # my($self, $svc_acct) = (shift, shift);
35 my( $self, $svc_acct ) = (shift, shift);
37 $self->radiator_queue(
40 $self->_radiator_hash($svc_acct),
45 my( $self, $new, $old ) = (shift, shift, shift);
47 # return "can't (yet) change domain with radiator export"
48 # if $old->domain ne $new->domain;
49 # return "can't (yet) change username with radiator export"
50 # if $old->username ne $new->username;
52 $self->radiator_queue(
55 $self->export_username($old),
56 $self->_radiator_hash($new),
61 my( $self, $svc_acct ) = (shift, shift);
63 $self->radiator_queue(
66 $self->export_username($svc_acct),
71 my( $self, $svc_acct ) = @_;
73 'username' => $self->export_username($svc_acct),
74 'pass_word' => $svc_acct->crypt_password,
75 'fullname' => $svc_acct->finger,
76 map { my $method = "radius_$_"; $_ => $svc_acct->$method(); }
77 qw( framed_filter_id framed_mtu framed_netmask framed_protocol
78 framed_routing login_host login_service login_tcp_port )
80 $hash{'timeleft'} = $svc_acct->seconds
81 if $svc_acct->seconds =~ /^\d+$/;
82 $hash{'staticaddress'} = $svc_acct->slipip
83 if $svc_acct->slipip =~ /^[\d\.]+$/; # and $self->slipip ne '0.0.0.0';
85 $hash{'servicename'} = ( $svc_acct->radius_groups )[0];
87 my $cust_pkg = $svc_acct->cust_svc->cust_pkg;
88 $hash{'validto'} = $cust_pkg->bill
89 if $cust_pkg && $cust_pkg->part_pkg->is_prepaid && $cust_pkg->bill;
91 #some other random stuff, should probably be attributes or virtual fields
92 #$hash{'state'} = 0; #only inserts
93 #$hash{'badlogins'} = 0; #only inserts
94 $hash{'maxlogins'} = 1;
95 $hash{'addeddate'} = $cust_pkg->setup
96 if $cust_pkg && $cust_pkg->setup;
97 $hash{'validfrom'} = $cust_pkg->last_bill || $cust_pkg->setup
98 if $cust_pkg && ( $cust_pkg->last_bill || $cust_pkg->setup );
99 $hash{'state'} = $cust_pkg->susp ? 1 : 0
106 my( $self, $svcnum, $method ) = (shift, shift, shift);
107 my $queue = new FS::queue {
109 'job' => "FS::part_export::radiator::radiator_$method",
112 $self->option('datasrc'),
113 $self->option('username'),
114 $self->option('password'),
119 sub radiator_insert { #subroutine, not method
120 my $dbh = radiator_connect(shift, shift, shift);
122 $hash{'state'} = 0; #see "random stuff" above
123 $hash{'badlogins'} = 0; #see "random stuff" above
125 my $sth = $dbh->prepare(
126 "INSERT INTO $radusers ( ". join(', ', keys %hash ). ' ) '.
127 'VALUES ( '. join(', ', map '?', keys %hash ). ' ) '
128 ) or die $dbh->errstr;
129 $sth->execute( values %hash )
136 sub radiator_replace { #subroutine, not method
137 my $dbh = radiator_connect(shift, shift, shift);
138 my ( $old_username, %hash ) = @_;
140 my $sth = $dbh->prepare(
141 "UPDATE $radusers SET ". join(', ', map " $_ = ?", keys %hash ).
142 ' WHERE username = ?'
143 ) or die $dbh->errstr;
144 $sth->execute( values(%hash), $old_username )
150 sub radiator_delete { #subroutine, not method
151 my $dbh = radiator_connect(shift, shift, shift);
152 my ( $username ) = @_;
154 my $sth = $dbh->prepare(
155 "DELETE FROM $radusers WHERE username = ?"
156 ) or die $dbh->errstr;
157 $sth->execute( $username )
164 sub radiator_connect {
165 #my($datasrc, $username, $password) = @_;
166 #DBI->connect($datasrc, $username, $password) or die $DBI::errstr;
167 FS::DBI->connect(@_) or die $FS::DBI::errstr;