X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_acct.pm;h=e67db43c6b265150672ebfd69270be8e638d2c78;hb=7d68066ea33f9f85fe14ce663372642d7ec2ad20;hp=9a2f0092b07cb34297f36455e170335af04c139c;hpb=350d21e77152b1da498ef88c1055e847420bcce1;p=freeside.git diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 9a2f0092b..e67db43c6 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -1,7 +1,11 @@ package FS::svc_acct; use strict; -use base qw( FS::svc_Domain_Mixin FS::svc_CGP_Mixin FS::svc_CGPRule_Mixin +use base qw( FS::svc_Domain_Mixin + FS::svc_CGP_Mixin + FS::svc_CGPRule_Mixin + FS::svc_Radius_Mixin + FS::svc_Tower_Mixin FS::svc_Common ); use vars qw( $DEBUG $me $conf $skip_fuzzyfiles $dir_prefix @shells $usernamemin @@ -23,7 +27,7 @@ use Carp; use Fcntl qw(:flock); use Date::Format; use Crypt::PasswdMD5 1.2; -use Digest::SHA1 'sha1_base64'; +use Digest::SHA 'sha1_base64'; use Digest::MD5 'md5_base64'; use Data::Dumper; use Text::Template; @@ -50,6 +54,7 @@ use FS::svc_forward; use FS::svc_www; use FS::cdr; use FS::acct_snarf; +use FS::tower_sector; $DEBUG = 0; $me = '[FS::svc_acct]'; @@ -251,6 +256,7 @@ sub table_info { 'sorts' => [ 'username', 'uid', 'seconds', 'last_login' ], 'display_weight' => 10, 'cancel_weight' => 50, + 'ip_field' => 'slipip', 'fields' => { 'dir' => 'Home directory', 'uid' => { @@ -334,11 +340,13 @@ sub table_info { disable_inventory => 1, disable_select => 1, #UI wonky, pry works otherwise }, + 'sectornum' => 'Tower sector', 'usergroup' => { label => 'RADIUS groups', type => 'select-radius_group.html', disable_inventory => 1, disable_select => 1, + multiple => 1, }, 'seconds' => { label => 'Seconds', label_sort => 'with Time Remaining', @@ -531,22 +539,6 @@ sub table { 'svc_acct'; } sub table_dupcheck_fields { ( 'username', 'domsvc' ); } -sub _fieldhandlers { - { - #false laziness with edit/svc_acct.cgi - 'usergroup' => sub { - my( $self, $groups ) = @_; - if ( ref($groups) eq 'ARRAY' ) { - $groups; - } elsif ( length($groups) ) { - [ split(/\s*,\s*/, $groups) ]; - } else { - []; - } - }, - }; -} - sub last_login { shift->_lastlog('in', @_); } @@ -699,7 +691,7 @@ sub insert { my $dbh = dbh; my @jobnums; - my $error = $self->SUPER::insert( + my $error = $self->SUPER::insert( # usergroup is here 'jobnums' => \@jobnums, 'child_objects' => $self->child_objects, %options, @@ -709,20 +701,6 @@ sub insert { return $error; } - if ( $self->usergroup ) { - foreach my $groupnum ( @{$self->usergroup} ) { - my $radius_usergroup = new FS::radius_usergroup ( { - svcnum => $self->svcnum, - groupnum => $groupnum, - } ); - my $error = $radius_usergroup->insert; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error; - } - } - } - unless ( $skip_fuzzyfiles ) { $error = $self->queue_fuzzyfiles_update; if ( $error ) { @@ -935,22 +913,12 @@ sub delete { } } - my $error = $self->SUPER::delete; + my $error = $self->SUPER::delete; # usergroup here if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; } - foreach my $radius_usergroup ( - qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } ) - ) { - my $error = $radius_usergroup->delete; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error; - } - } - $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; } @@ -1011,49 +979,7 @@ sub replace { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - # redundant, but so $new->usergroup gets set - $error = $new->check; - return $error if $error; - - $old->usergroup( [ $old->radius_groups('NUMBERS') ] ); - if ( $DEBUG ) { - warn $old->email. " old groups: ". join(' ',@{$old->usergroup}). "\n"; - warn $new->email. " new groups: ". join(' ',@{$new->usergroup}). "\n"; - } - if ( $new->usergroup ) { - #(sorta) false laziness with FS::part_export::sqlradius::_export_replace - my @newgroups = @{$new->usergroup}; - foreach my $oldgroup ( @{$old->usergroup} ) { - if ( grep { $oldgroup eq $_ } @newgroups ) { - @newgroups = grep { $oldgroup ne $_ } @newgroups; - next; - } - my $radius_usergroup = qsearchs('radius_usergroup', { - svcnum => $old->svcnum, - groupnum => $oldgroup, - } ); - my $error = $radius_usergroup->delete; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return "error deleting radius_usergroup $oldgroup: $error"; - } - } - - foreach my $newgroup ( @newgroups ) { - my $radius_usergroup = new FS::radius_usergroup ( { - svcnum => $new->svcnum, - groupnum => $newgroup, - } ); - my $error = $radius_usergroup->insert; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return "error adding radius_usergroup $newgroup: $error"; - } - } - - } - - $error = $new->SUPER::replace($old, @_); + $error = $new->SUPER::replace($old, @_); # usergroup here if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error if $error; @@ -1191,19 +1117,15 @@ sub check { my($recref) = $self->hashref; - my $x = $self->setfixed( $self->_fieldhandlers ); + my $x = $self->setfixed; return $x unless ref($x); my $part_svc = $x; - if ( $part_svc->part_svc_column('usergroup')->columnflag eq "F" ) { - $self->usergroup( - [ split(',', $part_svc->part_svc_column('usergroup')->columnvalue) ] ); - } - my $error = $self->ut_numbern('svcnum') #|| $self->ut_number('domsvc') || $self->ut_foreign_key( 'domsvc', 'svc_domain', 'svcnum' ) || $self->ut_foreign_keyn('pbxsvc', 'svc_pbx', 'svcnum' ) + || $self->ut_foreign_keyn('sectornum','tower_sector','sectornum') || $self->ut_textn('sec_phrase') || $self->ut_snumbern('seconds') || $self->ut_snumbern('upbytes') @@ -1241,6 +1163,7 @@ sub check { my $cust_pkg; local $username_letter = $username_letter; + local $username_uppercase = $username_uppercase; if ($self->svcnum) { my $cust_svc = $self->cust_svc or return "no cust_svc record found for svcnum ". $self->svcnum; @@ -1252,6 +1175,8 @@ sub check { if ($cust_pkg) { $username_letter = $conf->exists('username-letter', $cust_pkg->cust_main->agentnum); + $username_uppercase = + $conf->exists('username-uppercase', $cust_pkg->cust_main->agentnum); } my $ulen = $usernamemax || $self->dbdef_table->column('username')->length; @@ -1260,40 +1185,42 @@ sub check { or return gettext('illegal_username'). " ($usernamemin-$ulen): ". $recref->{username}; $recref->{username} = $1; + my $uerror = gettext('illegal_username'). ': '. $recref->{username}; + unless ( $username_uppercase ) { - $recref->{username} =~ /[A-Z]/ and return gettext('illegal_username'); + $recref->{username} =~ /[A-Z]/ and return $uerror; } if ( $username_letterfirst ) { - $recref->{username} =~ /^[a-z]/ or return gettext('illegal_username'); + $recref->{username} =~ /^[a-z]/ or return $uerror; } elsif ( $username_letter ) { - $recref->{username} =~ /[a-z]/ or return gettext('illegal_username'); + $recref->{username} =~ /[a-z]/ or return $uerror; } if ( $username_noperiod ) { - $recref->{username} =~ /\./ and return gettext('illegal_username'); + $recref->{username} =~ /\./ and return $uerror; } if ( $username_nounderscore ) { - $recref->{username} =~ /_/ and return gettext('illegal_username'); + $recref->{username} =~ /_/ and return $uerror; } if ( $username_nodash ) { - $recref->{username} =~ /\-/ and return gettext('illegal_username'); + $recref->{username} =~ /\-/ and return $uerror; } unless ( $username_ampersand ) { - $recref->{username} =~ /\&/ and return gettext('illegal_username'); + $recref->{username} =~ /\&/ and return $uerror; } unless ( $username_percent ) { - $recref->{username} =~ /\%/ and return gettext('illegal_username'); + $recref->{username} =~ /\%/ and return $uerror; } unless ( $username_colon ) { - $recref->{username} =~ /\:/ and return gettext('illegal_username'); + $recref->{username} =~ /\:/ and return $uerror; } unless ( $username_slash ) { - $recref->{username} =~ /\// and return gettext('illegal_username'); + $recref->{username} =~ /\// and return $uerror; } unless ( $username_equals ) { - $recref->{username} =~ /\=/ and return gettext('illegal_username'); + $recref->{username} =~ /\=/ and return $uerror; } unless ( $username_pound ) { - $recref->{username} =~ /\#/ and return gettext('illegal_username'); + $recref->{username} =~ /\#/ and return $uerror; } @@ -1363,8 +1290,6 @@ sub check { } - # $error = $self->ut_textn('finger'); - # return $error if $error; if ( $self->getfield('finger') eq '' ) { my $cust_pkg = $self->svcnum ? $self->cust_svc->cust_pkg @@ -1374,7 +1299,9 @@ sub check { $self->setfield('finger', $cust_main->first.' '.$cust_main->get('last') ); } } - $self->getfield('finger') =~ /^([\w \,\.\-\'\&\t\!\@\#\$\%\(\)\+\;\"\?\/\*\<\>]+)$/ + # $error = $self->ut_textn('finger'); + # return $error if $error; + $self->getfield('finger') =~ /^([\w \,\.\-\'\&\t\!\@\#\$\%\(\)\+\;\"\?\/\*\<\>]*)$/ or return "Illegal finger: ". $self->getfield('finger'); $self->setfield('finger', $1); @@ -1540,7 +1467,7 @@ sub set_password { if ( !$encoding ) { # set encoding to system default ($encoding, $encryption) = - split(/-/, lc($conf->config('default-password-encoding'))); + split(/-/, lc($conf->config('default-password-encoding') || '')); $encoding ||= 'legacy'; $self->_password_encoding($encoding); } @@ -2227,20 +2154,19 @@ sub _op_overlimit { my $cust_pkg = $self->cust_svc->cust_pkg; - my $conf_overlimit = + my @conf_overlimit = $cust_pkg ? $conf->config('overlimit_groups', $cust_pkg->cust_main->agentnum ) : $conf->config('overlimit_groups'); foreach my $part_export ( $self->cust_svc->part_svc->part_export ) { - my $groups = $conf_overlimit || $part_export->option('overlimit_groups'); - next unless $groups; - - my $gref = &{ $self->_fieldhandlers->{'usergroup'} }( $self, $groups ); + my @groups = scalar(@conf_overlimit) ? @conf_overlimit + : split(' ',$part_export->option('overlimit_groups')); + next unless scalar(@groups); my $other = new FS::svc_acct $self->hashref; - $other->usergroup( $gref ); + $other->usergroup(\@groups); my($new,$old); if ($action eq 'suspend') { @@ -2550,35 +2476,7 @@ sub get_cdrs { } -=item radius_groups - -Returns all RADIUS groups for this account (see L). - -=cut - -sub radius_groups { - my $self = shift; - if ( $self->usergroup ) { - confess "explicitly specified usergroup not an arrayref: ". $self->usergroup - unless ref($self->usergroup) eq 'ARRAY'; - #when provisioning records, export callback runs in svc_Common.pm before - #radius_usergroup records can be inserted... - @{$self->usergroup}; - } else { - my $format = shift || ''; - my @groups = qsearch({ 'table' => 'radius_usergroup', - 'addl_from' => 'left join radius_group using (groupnum)', - 'select' => 'radius_group.*', - 'hashref' => { 'svcnum' => $self->svcnum }, - }); - - # this is to preserve various legacy behaviour / avoid re-writing other code - return map { $_->groupnum } @groups if $format eq 'NUMBERS'; - return map { $_->description . " (" . $_->groupname . ")" } @groups - if $format eq 'COMBINED'; - map { $_->groupname } @groups; - } -} +# sub radius_groups has moved to svc_Radius_Mixin =item clone_suspended @@ -2626,7 +2524,8 @@ sub check_password { if ( $self->_password_encoding eq 'ldap' ) { - my $auth = from_rfc2307 Authen::Passphrase $self->_password; + $password =~ s/^{PLAIN}/{CLEARTEXT}/; + my $auth = from_rfc2307 Authen::Passphrase $password; return $auth->match($check_password); } elsif ( $self->_password_encoding eq 'crypt' ) { @@ -2928,7 +2827,7 @@ sub search { #agentnum if ( $params->{'agentnum'} =~ /^(\d+)$/ and $1 ) { - push @where, "agentnum = $1"; + push @where, "cust_main.agentnum = $1"; } #custnum @@ -2953,6 +2852,9 @@ sub search { push @where, "svcpart = $1"; } + # sector and tower + my @where_sector = $class->tower_sector_sql($params); + push @where, @where_sector if @where_sector; # here is the agent virtualization #if ($params->{CurrentUser}) { @@ -2980,6 +2882,9 @@ sub search { ' LEFT JOIN cust_pkg USING ( pkgnum ) '. ' LEFT JOIN cust_main USING ( custnum ) '; + $addl_from .= ' LEFT JOIN tower_sector USING ( sectornum )' + if @where_sector; + my $count_query = "SELECT COUNT(*) FROM svc_acct $addl_from $extra_sql"; #if ( keys %svc_acct ) { # $count_query .= ' WHERE '.