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