1 package FS::part_export::broadband_sqlradius;
4 use vars qw($DEBUG @ISA @pw_set %options %info $conf);
7 use FS::Record qw( dbh str2time_sql ); #qsearch qsearchs );
8 use FS::part_export::sqlradius qw(sqlradius_connect);
9 use FS::Password_Mixin;
12 FS::UID->install_callback(
15 @pw_set = FS::Password_Mixin->pw_set;
19 @ISA = qw(FS::part_export::sqlradius);
23 tie %options, 'Tie::IxHash',
24 'datasrc' => { label=>'DBI data source ' },
25 'username' => { label=>'Database username' },
26 'password' => { label=>'Database password' },
27 'usergroup'=> { label => 'Group table',
29 options => [qw( radusergroup usergroup )],
31 # session report doesn't currently know about this export anyway
34 # label => 'Hide IP address on session reports',
37 label => 'Export MAC address as',
39 options => [ qw(uppercase lowercase) ],
42 label => 'Separate MAC address octets with',
45 'mac_as_password' => {
48 label => 'Use MAC address as password',
50 'radius_password' => { label=>'Fixed password' },
51 'ip_addr_as' => { label => 'Send IP address as',
52 default => 'Framed-IP-Address' },
55 label => 'Export RADIUS group attributes to this database',
60 'svc' => 'svc_broadband',
61 'desc' => 'Real-time export to SQL-backed RADIUS (such as FreeRadius) for broadband services',
62 'options' => \%options,
66 Real-time export of <b>radcheck</b>, <b>radreply</b>, and <b>usergroup</b>
67 tables to any SQL database for
68 <a href="http://www.freeradius.org/">FreeRADIUS</a>
69 or <a href="http://radius.innercite.com/">ICRADIUS</a>.
72 This export is for broadband service access control based on MAC address.
73 For a more typical RADIUS export, see sqlradius.
77 <a href="http://search.cpan.org/dist/DBI/DBI.pm#connect">DBI documentation</a>
79 <a href="http://search.cpan.org/search?mode=module&query=DBD%3A%3A">documentation for your DBD</a>
80 for the exact syntax of a DBI data source.
85 sub rebless { shift; }
88 my($self, $svc_broadband) = (shift, shift);
89 $svc_broadband->mac_addr_formatted(
90 $self->option('mac_case'), $self->option('mac_delimiter')
95 my($self, $svc_broadband) = (shift, shift);
96 # start with attributes the service wants
97 my %reply = $self->NEXT::radius_reply($svc_broadband);
98 # add export-specific stuff
99 if ( length($self->option('ip_addr_as',1))
100 and length($svc_broadband->ip_addr) ) {
101 $reply{$self->option('ip_addr_as')} = $svc_broadband->ip_addr;
107 my($self, $svc_broadband) = (shift, shift);
109 my %check = $self->SUPER::radius_check($svc_broadband);
110 my $password_attrib = $conf->config('radius-password') || 'Password';
111 if ( $self->option('mac_as_password') ) {
112 $check{$password_attrib} = $self->export_username($svc_broadband);
114 elsif ( length( $self->option('radius_password',1)) ) {
115 $check{$password_attrib} = $self->option('radius_password');
120 sub radius_check_suspended {
121 my($self, $svc_broadband) = (shift, shift);
123 return () unless $self->option('mac_as_password')
124 || length( $self->option('radius_password',1));
126 my $password_attrib = $conf->config('radius-password') || 'Password';
128 $password_attrib => join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) )
132 #false laziness w/sqlradius.pm
133 sub _export_suspend {
134 my( $self, $svc_broadband ) = (shift, shift);
136 local $SIG{HUP} = 'IGNORE';
137 local $SIG{INT} = 'IGNORE';
138 local $SIG{QUIT} = 'IGNORE';
139 local $SIG{TERM} = 'IGNORE';
140 local $SIG{TSTP} = 'IGNORE';
141 local $SIG{PIPE} = 'IGNORE';
143 my $oldAutoCommit = $FS::UID::AutoCommit;
144 local $FS::UID::AutoCommit = 0;
147 my @newgroups = $self->suspended_usergroups($svc_broadband);
149 unless (@newgroups) { #don't change password if assigning to a suspended group
151 my $err_or_queue = $self->sqlradius_queue(
152 $svc_broadband->svcnum, 'insert',
153 'check', $self->export_username($svc_broadband),
154 $self->radius_check_suspended($svc_broadband)
156 unless ( ref($err_or_queue) ) {
157 $dbh->rollback if $oldAutoCommit;
158 return $err_or_queue;
164 $self->sqlreplace_usergroups(
165 $svc_broadband->svcnum,
166 $self->export_username($svc_broadband),
168 [ $svc_broadband->radius_groups('hashref') ],
172 $dbh->rollback if $oldAutoCommit;
175 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
180 sub update_svc {} #do nothing