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);
11 FS::UID->install_callback(sub { $conf = new FS::Conf });
13 @ISA = qw(FS::part_export::sqlradius);
17 @pw_set = ( 'a'..'z', 'A'..'Z', '0'..'9', '(', ')', '#', '.', ',' );
19 tie %options, 'Tie::IxHash',
20 'datasrc' => { label=>'DBI data source ' },
21 'username' => { label=>'Database username' },
22 'password' => { label=>'Database password' },
23 'usergroup'=> { label => 'Group table',
25 options => [qw( radusergroup usergroup )],
27 # session report doesn't currently know about this export anyway
30 # label => 'Hide IP address on session reports',
33 label => 'Export MAC address as',
35 options => [ qw(uppercase lowercase) ],
38 label => 'Separate MAC address octets with',
41 'mac_as_password' => {
44 label => 'Use MAC address as password',
46 'radius_password' => { label=>'Fixed password' },
47 'ip_addr_as' => { label => 'Send IP address as',
48 default => 'Framed-IP-Address' },
51 label => 'Export RADIUS group attributes to this database',
56 'svc' => 'svc_broadband',
57 'desc' => 'Real-time export to SQL-backed RADIUS (such as FreeRadius) for broadband services',
58 'options' => \%options,
62 Real-time export of <b>radcheck</b>, <b>radreply</b>, and <b>usergroup</b>
63 tables to any SQL database for
64 <a href="http://www.freeradius.org/">FreeRADIUS</a>
65 or <a href="http://radius.innercite.com/">ICRADIUS</a>.
68 This export is for broadband service access control based on MAC address.
69 For a more typical RADIUS export, see sqlradius.
73 <a href="http://search.cpan.org/dist/DBI/DBI.pm#connect">DBI documentation</a>
75 <a href="http://search.cpan.org/search?mode=module&query=DBD%3A%3A">documentation for your DBD</a>
76 for the exact syntax of a DBI data source.
81 sub rebless { shift; }
84 my($self, $svc_broadband) = (shift, shift);
85 $svc_broadband->mac_addr_formatted(
86 $self->option('mac_case'), $self->option('mac_delimiter')
91 my($self, $svc_broadband) = (shift, shift);
92 # start with attributes the service wants
93 my %reply = $self->NEXT::radius_reply($svc_broadband);
94 # add export-specific stuff
95 if ( length($self->option('ip_addr_as',1))
96 and length($svc_broadband->ip_addr) ) {
97 $reply{$self->option('ip_addr_as')} = $svc_broadband->ip_addr;
103 my($self, $svc_broadband) = (shift, shift);
105 my %check = $self->SUPER::radius_check($svc_broadband);
106 my $password_attrib = $conf->config('radius-password') || 'Password';
107 if ( $self->option('mac_as_password') ) {
108 $check{$password_attrib} = $self->export_username($svc_broadband);
110 elsif ( length( $self->option('radius_password',1)) ) {
111 $check{$password_attrib} = $self->option('radius_password');
116 sub radius_check_suspended {
117 my($self, $svc_broadband) = (shift, shift);
119 return () unless $self->option('mac_as_password')
120 || length( $self->option('radius_password',1));
122 my $password_attrib = $conf->config('radius-password') || 'Password';
124 $password_attrib => join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) )
128 #false laziness w/sqlradius.pm
129 sub _export_suspend {
130 my( $self, $svc_broadband ) = (shift, shift);
132 local $SIG{HUP} = 'IGNORE';
133 local $SIG{INT} = 'IGNORE';
134 local $SIG{QUIT} = 'IGNORE';
135 local $SIG{TERM} = 'IGNORE';
136 local $SIG{TSTP} = 'IGNORE';
137 local $SIG{PIPE} = 'IGNORE';
139 my $oldAutoCommit = $FS::UID::AutoCommit;
140 local $FS::UID::AutoCommit = 0;
143 my @newgroups = $self->suspended_usergroups($svc_broadband);
145 unless (@newgroups) { #don't change password if assigning to a suspended group
147 my $err_or_queue = $self->sqlradius_queue(
148 $svc_broadband->svcnum, 'insert',
149 'check', $self->export_username($svc_broadband),
150 $self->radius_check_suspended($svc_broadband)
152 unless ( ref($err_or_queue) ) {
153 $dbh->rollback if $oldAutoCommit;
154 return $err_or_queue;
160 $self->sqlreplace_usergroups(
161 $svc_broadband->svcnum,
162 $self->export_username($svc_broadband),
164 [ $svc_broadband->radius_groups('hashref') ],
168 $dbh->rollback if $oldAutoCommit;
171 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
176 sub update_svc {} #do nothing