RADIUS groups for svc_broadband, #14695
[freeside.git] / FS / FS / part_export / broadband_sqlradius.pm
1 package FS::part_export::broadband_sqlradius;
2
3 use strict;
4 use vars qw($DEBUG @ISA %options %info $conf);
5 use Tie::IxHash;
6 use FS::Conf;
7 use FS::Record qw( dbh str2time_sql ); #qsearch qsearchs );
8 use FS::part_export::sqlradius qw(sqlradius_connect);
9
10 FS::UID->install_callback(sub { $conf = new FS::Conf });
11
12 @ISA = qw(FS::part_export::sqlradius);
13
14 $DEBUG = 0;
15
16 tie %options, 'Tie::IxHash',
17   'datasrc'  => { label=>'DBI data source ' },
18   'username' => { label=>'Database username' },
19   'password' => { label=>'Database password' },
20   'usergroup'=> { label   => 'Group table',
21                   type    => 'select',
22                   options => [qw( radusergroup usergroup )],
23                 },
24 # session report doesn't currently know about this export anyway
25 #  'hide_ip' => {
26 #    type  => 'checkbox',
27 #    label => 'Hide IP address on session reports',
28 #  },
29   'mac_as_password' => { 
30     type => 'checkbox',
31     default => '1',
32     label => 'Use MAC address as password',
33   },
34   'radius_password' => { label=>'Fixed password' },
35   'ip_addr_as' => { label => 'Send IP address as',
36                     default => 'Framed-IP-Address' },
37 ;
38
39 %info = (
40   'svc'      => 'svc_broadband',
41   'desc'     => 'Real-time export to SQL-backed RADIUS (such as FreeRadius) for broadband services',
42   'options'  => \%options,
43   'nas'      => 'Y',
44   'notes'    => <<END,
45 Real-time export of <b>radcheck</b>, <b>radreply</b>, and <b>usergroup</b> 
46 tables to any SQL database for 
47 <a href="http://www.freeradius.org/">FreeRADIUS</a>
48 or <a href="http://radius.innercite.com/">ICRADIUS</a>.
49 <br><br>
50
51 This export is for broadband service access control based on MAC address.  
52 For a more typical RADIUS export, see sqlradius.
53 <br><br>
54
55 See the
56 <a href="http://search.cpan.org/dist/DBI/DBI.pm#connect">DBI documentation</a>
57 and the
58 <a href="http://search.cpan.org/search?mode=module&query=DBD%3A%3A">documentation for your DBD</a>
59 for the exact syntax of a DBI data source.
60
61 END
62 );
63
64 sub rebless { shift; }
65
66 sub export_username {
67   my($self, $svc_broadband) = (shift, shift);
68   $svc_broadband->mac_addr;
69 }
70
71 sub radius_reply {
72   my($self, $svc_broadband) = (shift, shift);
73   my %reply;
74   if (  length($self->option('ip_addr_as',1)) 
75     and length($svc_broadband->ip_addr) ) {
76     $reply{$self->option('ip_addr_as')} = $svc_broadband->ip_addr;
77   }
78   %reply;
79 }
80
81 sub radius_check {
82   my($self, $svc_broadband) = (shift, shift);
83   my $password_attrib = $conf->config('radius-password') || 'Password';
84   my %check;
85   if ( $self->option('mac_as_password') ) {
86     $check{$password_attrib} = $svc_broadband->mac_addr; #formatting?
87   }
88   elsif ( length( $self->option('radius_password',1)) ) {
89     $check{$password_attrib} = $self->option('radius_password');
90   }
91   %check;
92 }
93
94 sub _export_suspend {}
95 sub _export_unsuspend {}
96
97 sub update_svc {} #do nothing
98
99 1;
100