RADIUS group attributes, #15017
[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   'export_attrs' => { 
38     type => 'checkbox', 
39     label => 'Export RADIUS group attributes to this database', 
40   },
41   ;
42
43 %info = (
44   'svc'      => 'svc_broadband',
45   'desc'     => 'Real-time export to SQL-backed RADIUS (such as FreeRadius) for broadband services',
46   'options'  => \%options,
47   'nas'      => 'Y',
48   'notes'    => <<END,
49 Real-time export of <b>radcheck</b>, <b>radreply</b>, and <b>usergroup</b> 
50 tables to any SQL database for 
51 <a href="http://www.freeradius.org/">FreeRADIUS</a>
52 or <a href="http://radius.innercite.com/">ICRADIUS</a>.
53 <br><br>
54
55 This export is for broadband service access control based on MAC address.  
56 For a more typical RADIUS export, see sqlradius.
57 <br><br>
58
59 See the
60 <a href="http://search.cpan.org/dist/DBI/DBI.pm#connect">DBI documentation</a>
61 and the
62 <a href="http://search.cpan.org/search?mode=module&query=DBD%3A%3A">documentation for your DBD</a>
63 for the exact syntax of a DBI data source.
64
65 END
66 );
67
68 sub rebless { shift; }
69
70 sub export_username {
71   my($self, $svc_broadband) = (shift, shift);
72   $svc_broadband->mac_addr;
73 }
74
75 sub radius_reply {
76   my($self, $svc_broadband) = (shift, shift);
77   my %reply;
78   if (  length($self->option('ip_addr_as',1)) 
79     and length($svc_broadband->ip_addr) ) {
80     $reply{$self->option('ip_addr_as')} = $svc_broadband->ip_addr;
81   }
82   %reply;
83 }
84
85 sub radius_check {
86   my($self, $svc_broadband) = (shift, shift);
87   my $password_attrib = $conf->config('radius-password') || 'Password';
88   my %check;
89   if ( $self->option('mac_as_password') ) {
90     $check{$password_attrib} = $svc_broadband->mac_addr; #formatting?
91   }
92   elsif ( length( $self->option('radius_password',1)) ) {
93     $check{$password_attrib} = $self->option('radius_password');
94   }
95   %check;
96 }
97
98 sub _export_suspend {}
99 sub _export_unsuspend {}
100
101 sub update_svc {} #do nothing
102
103 1;
104