X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_acct.pm;h=85b4888b27c1588f877f9d1b01f64fa18d02e965;hb=a9ec5a5c02a137cadd9f2a522fba904d945ddbe3;hp=93b657f2dcf84c2f7e5b6f7f8b5a6f6cea4d25b1;hpb=41e9b7ac95959d4392a7aee9b8aef1cc301a1eb6;p=freeside.git diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 93b657f2d..85b4888b2 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -2,17 +2,19 @@ package FS::svc_acct; use strict; use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin - $usernamemax $passwordmin + $usernamemax $passwordmin $username_letter $username_letterfirst $shellmachine $useradd $usermod $userdel @saltset @pw_set); use Carp; use FS::Conf; -use FS::Record qw( qsearchs fields ); +use FS::Record qw( qsearch qsearchs fields ); use FS::svc_Common; -use FS::SSH qw(ssh); +use Net::SSH qw(ssh); use FS::part_svc; use FS::svc_acct_pop; use FS::svc_acct_sm; +use FS::cust_main_invoice; +use FS::svc_domain; @ISA = qw( FS::svc_Common ); @@ -46,6 +48,8 @@ $FS::UID::callback{'FS::svc_acct'} = sub { 'rm -rf $old_dir'. ')'; } + $username_letter = $conf->exists('username-letter'); + $username_letterfirst = $conf->exists('username-letterfirst'); }; @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' ); @@ -80,6 +84,10 @@ FS::svc_acct - Object methods for svc_acct records %hash = $record->radius; + %hash = $record->radius_reply; + + %hash = $record->radius_check; + =head1 DESCRIPTION An FS::svc_acct object represents an account. FS::svc_acct inherits from @@ -111,6 +119,8 @@ FS::svc_Common. The following fields are currently supported: =item radius_I - I +=item domsvc - service number of svc_domain with which to associate + =back =head1 METHODS @@ -167,10 +177,12 @@ sub insert { return $error if $error; return "Username ". $self->username. " in use" - if qsearchs( 'svc_acct', { 'username' => $self->username } ); + if qsearchs( 'svc_acct', { 'username' => $self->username, + 'domsvc' => $self->domsvc, + } ); my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } ); - return "Unkonwn svcpart" unless $part_svc; + return "Unknown svcpart" unless $part_svc; return "uid in use" if $part_svc->svc_acct__uid_flag ne 'F' && qsearchs( 'svc_acct', { 'uid' => $self->uid } ) @@ -188,7 +200,7 @@ sub insert { $self->shell, ); if ( $username && $uid && $dir && $shellmachine && ! $nossh_hack ) { - ssh("root\@$shellmachine", eval "$useradd"); + ssh("root\@$shellmachine", eval qq("$useradd") ); } ''; #no error @@ -222,11 +234,21 @@ $username and $dir. sub delete { my $self = shift; - my $error; - return "Can't delete an account which has mail aliases pointed to it!" + return "Can't delete an account which has (svc_acct_sm) mail aliases!" if $self->uid && qsearch( 'svc_acct_sm', { 'domuid' => $self->uid } ); + return "Can't delete an account which is a (svc_forward) source!" + if qsearch( 'svc_forward', { 'srcsvc' => $self->svcnum } ); + + return "Can't delete an account which is a (svc_forward) destination!" + if qsearch( 'svc_forward', { 'dstsvc' => $self->svcnum } ); + + return "Can't delete an account with (svc_www) web service!" + if qsearch( 'svc_www', { 'usersvc' => $self->usersvc } ); + + # what about records in session ? + local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; local $SIG{QUIT} = 'IGNORE'; @@ -234,15 +256,50 @@ sub delete { local $SIG{TSTP} = 'IGNORE'; local $SIG{PIPE} = 'IGNORE'; - $error = $self->SUPER::delete; - return $error if $error; + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + foreach my $cust_main_invoice ( + qsearch( 'cust_main_invoice', { 'dest' => $self->svcnum } ) + ) { + my %hash = $cust_main_invoice->hash; + $hash{'dest'} = $self->email; + my $new = new FS::cust_main_invoice \%hash; + my $error = $new->replace($cust_main_invoice); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + foreach my $svc_domain ( + qsearch( 'svc_domain', { 'catchall' => $self->svcnum } ) + ) { + my %hash = new FS::svc_domain->hash; + $hash{'catchall'} = ''; + my $new = new FS::svc_domain \%hash; + my $error = $new->replace($svc_domain); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + my $error = $self->SUPER::delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; my( $username, $dir ) = ( $self->username, $self->dir, ); if ( $username && $shellmachine && ! $nossh_hack ) { - ssh("root\@$shellmachine", eval "$userdel"); + ssh("root\@$shellmachine", eval qq("$userdel") ); } ''; @@ -304,7 +361,7 @@ sub replace { $new->getfield('gid'), ); if ( $old_dir && $new_dir && $old_dir ne $new_dir && ! $nossh_hack ) { - ssh("root\@$shellmachine", eval "$usermod" ); + ssh("root\@$shellmachine", eval qq("$usermod") ); } ''; #no error @@ -377,15 +434,24 @@ sub check { return $x unless ref($x); my $part_svc = $x; + my $error = $self->ut_numbern('svcnum') + || $self->ut_number('domsvc') + ; + return $error if $error; + my $ulen = $usernamemax || $self->dbdef_table->column('username')->length; $recref->{username} =~ /^([a-z0-9_\-\.]{$usernamemin,$ulen})$/ or return "Illegal username"; $recref->{username} = $1; - $recref->{username} =~ /[a-z]/ or return "Illegal username"; + if ( $username_letterfirst ) { + $recref->{username} =~ /^[a-z]/ or return "Illegal username"; + } elsif ( $username_letter ) { + $recref->{username} =~ /[a-z]/ or return "Illegal username"; + } $recref->{popnum} =~ /^(\d*)$/ or return "Illegal popnum: ".$recref->{popnum}; $recref->{popnum} = $1; - return "Unkonwn popnum" unless + return "Unknown popnum" unless ! $recref->{popnum} || qsearchs('svc_acct_pop',{'popnum'=> $recref->{popnum} } ); @@ -402,8 +468,8 @@ sub check { return "Only root can have uid 0" if $recref->{uid} == 0 && $recref->{username} ne 'root'; - my($error); - return $error if $error=$self->ut_textn('finger'); + $error = $self->ut_textn('finger'); + return $error if $error; $recref->{dir} =~ /^([\/\w\-]*)$/ or return "Illegal directory"; @@ -473,6 +539,8 @@ sub check { $recref->{_password} = $1.$3; } elsif ( $recref->{_password} eq '*' ) { $recref->{_password} = '*'; + } elsif ( $recref->{_password} eq '!!' ) { + $recref->{_password} = '!!'; } else { return "Illegal password"; } @@ -532,11 +600,35 @@ sub radius_check { } grep { /^rc_/ && $self->getfield($_) } fields( $self->table ); } +=item domain + +Returns the domain associated with this account. + +-cut + +sub domain { + my $self = shift; + my $svc_domain = qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } ) + or die "svc_acct.domsvc ". $self->domsvc." not found in svc_domain.svcnum"; + $svc_domain->domain; +} + +=item email + +Returns an email address associated with the account. + =cut +sub email { + my $self = shift; + $self->username. '@'. $self->domain; +} + +=back + =head1 VERSION -$Id: svc_acct.pm,v 1.12 2000-07-17 10:53:42 ivan Exp $ +$Id: svc_acct.pm,v 1.26 2001-08-20 11:04:38 ivan Exp $ =head1 BUGS @@ -552,7 +644,7 @@ counterintuitive. =head1 SEE ALSO L, L, L, L, -L, L, L, L, L, +L, L, L, L, L, schema.html from the base documentation. =cut