From 307a7d85568a15f5eb0d97c648507484108fcc56 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 10 Nov 2011 21:40:05 +0000 Subject: [PATCH] RADIUS groups for svc_broadband, #14695 --- FS/FS/Conf.pm | 7 + FS/FS/nas.pm | 7 +- FS/FS/part_export.pm | 7 +- FS/FS/part_export/broadband_sqlradius.pm | 100 +++++++++ FS/FS/part_export/phone_sqlradius.pm | 1 - FS/FS/part_svc.pm | 16 +- FS/FS/radius_usergroup.pm | 14 +- FS/FS/svc_Radius_Mixin.pm | 94 ++++++++ FS/FS/svc_acct.pm | 137 +----------- FS/FS/svc_broadband.pm | 11 +- FS/bin/freeside-sqlradius-reset | 7 +- httemplate/browse/part_svc.cgi | 6 +- httemplate/edit/process/svc_broadband.cgi | 14 +- httemplate/edit/svc_acct.cgi | 3 +- httemplate/edit/svc_broadband.cgi | 26 ++- httemplate/elements/select-radius_group.html | 23 +- httemplate/elements/tr-fixed.html | 12 +- httemplate/elements/tr-select-radius_group.html | 11 + httemplate/view/elements/svc_Common.html | 14 +- httemplate/view/svc_acct/basics.html | 2 +- httemplate/view/svc_broadband.cgi | 274 +++++------------------- 21 files changed, 385 insertions(+), 401 deletions(-) create mode 100644 FS/FS/part_export/broadband_sqlradius.pm create mode 100644 FS/FS/svc_Radius_Mixin.pm create mode 100644 httemplate/elements/tr-select-radius_group.html diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 4104fda9c..8d26e91aa 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -2297,6 +2297,13 @@ and customer address. Include units.', }, { + 'key' => 'svc_broadband-radius', + 'section' => '', + 'description' => 'Enable RADIUS groups for broadband services.', + 'type' => 'checkbox', + }, + + { 'key' => 'svc_acct-alldomains', 'section' => '', 'description' => 'Allow accounts to select any domain in the database. Normally accounts can only select from the domain set in the service definition and those purchased by the customer.', diff --git a/FS/FS/nas.pm b/FS/FS/nas.pm index 4564a6342..af5a23a24 100644 --- a/FS/FS/nas.pm +++ b/FS/FS/nas.pm @@ -87,8 +87,11 @@ sub delete { my $dbh = dbh; my $self = shift; - my $error = $self->process_m2m([]) - || $self->SUPER::delete; + my $error = $self->process_m2m( + link_table => 'export_nas', + target_table => 'part_export', + params => [] + ) || $self->SUPER::delete; if ( $error ) { $dbh->rollback; diff --git a/FS/FS/part_export.pm b/FS/FS/part_export.pm index f84f2a096..4b60953cf 100644 --- a/FS/FS/part_export.pm +++ b/FS/FS/part_export.pm @@ -128,7 +128,12 @@ sub delete { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my $error = $self->SUPER::delete; + # clean up export_nas records + my $error = $self->process_m2m( + 'link_table' => 'export_nas', + 'target_table' => 'nas', + 'params' => [], + ) || $self->SUPER::delete; if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; diff --git a/FS/FS/part_export/broadband_sqlradius.pm b/FS/FS/part_export/broadband_sqlradius.pm new file mode 100644 index 000000000..ae0876ddf --- /dev/null +++ b/FS/FS/part_export/broadband_sqlradius.pm @@ -0,0 +1,100 @@ +package FS::part_export::broadband_sqlradius; + +use strict; +use vars qw($DEBUG @ISA %options %info $conf); +use Tie::IxHash; +use FS::Conf; +use FS::Record qw( dbh str2time_sql ); #qsearch qsearchs ); +use FS::part_export::sqlradius qw(sqlradius_connect); + +FS::UID->install_callback(sub { $conf = new FS::Conf }); + +@ISA = qw(FS::part_export::sqlradius); + +$DEBUG = 0; + +tie %options, 'Tie::IxHash', + 'datasrc' => { label=>'DBI data source ' }, + 'username' => { label=>'Database username' }, + 'password' => { label=>'Database password' }, + 'usergroup'=> { label => 'Group table', + type => 'select', + options => [qw( radusergroup usergroup )], + }, +# session report doesn't currently know about this export anyway +# 'hide_ip' => { +# type => 'checkbox', +# label => 'Hide IP address on session reports', +# }, + 'mac_as_password' => { + type => 'checkbox', + default => '1', + label => 'Use MAC address as password', + }, + 'radius_password' => { label=>'Fixed password' }, + 'ip_addr_as' => { label => 'Send IP address as', + default => 'Framed-IP-Address' }, +; + +%info = ( + 'svc' => 'svc_broadband', + 'desc' => 'Real-time export to SQL-backed RADIUS (such as FreeRadius) for broadband services', + 'options' => \%options, + 'nas' => 'Y', + 'notes' => <radcheck, radreply, and usergroup +tables to any SQL database for +FreeRADIUS +or ICRADIUS. +

+ +This export is for broadband service access control based on MAC address. +For a more typical RADIUS export, see sqlradius. +

+ +See the +DBI documentation +and the +documentation for your DBD +for the exact syntax of a DBI data source. + +END +); + +sub rebless { shift; } + +sub export_username { + my($self, $svc_broadband) = (shift, shift); + $svc_broadband->mac_addr; +} + +sub radius_reply { + my($self, $svc_broadband) = (shift, shift); + my %reply; + if ( length($self->option('ip_addr_as',1)) + and length($svc_broadband->ip_addr) ) { + $reply{$self->option('ip_addr_as')} = $svc_broadband->ip_addr; + } + %reply; +} + +sub radius_check { + my($self, $svc_broadband) = (shift, shift); + my $password_attrib = $conf->config('radius-password') || 'Password'; + my %check; + if ( $self->option('mac_as_password') ) { + $check{$password_attrib} = $svc_broadband->mac_addr; #formatting? + } + elsif ( length( $self->option('radius_password',1)) ) { + $check{$password_attrib} = $self->option('radius_password'); + } + %check; +} + +sub _export_suspend {} +sub _export_unsuspend {} + +sub update_svc {} #do nothing + +1; + diff --git a/FS/FS/part_export/phone_sqlradius.pm b/FS/FS/part_export/phone_sqlradius.pm index 0816efab6..6b14bed3c 100644 --- a/FS/FS/part_export/phone_sqlradius.pm +++ b/FS/FS/part_export/phone_sqlradius.pm @@ -44,7 +44,6 @@ tie %options, 'Tie::IxHash', 'options' => \%options, 'notes' => <radcheck table -