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