From 6cd87c0d3b5280446301c647fa5f1ec5a593fa3f Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 4 Aug 1999 09:03:53 +0000 Subject: initial checkin of module files for proper perl installation --- FS/FS/svc_acct.pm | 468 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 468 insertions(+) create mode 100644 FS/FS/svc_acct.pm (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm new file mode 100644 index 0000000..b2f23c9 --- /dev/null +++ b/FS/FS/svc_acct.pm @@ -0,0 +1,468 @@ +package FS::svc_acct; + +use strict; +use vars qw(@ISA $nossh_hack $conf $dir_prefix @shells + $shellmachine @saltset @pw_set); +use FS::Conf; +use FS::Record qw( qsearchs fields ); +use FS::svc_Common; +use FS::SSH qw(ssh); +use FS::part_svc; +use FS::svc_acct_pop; + +@ISA = qw( FS::svc_Common ); + +#ask FS::UID to run this stuff for us later +$FS::UID::callback{'FS::svc_acct'} = sub { + $conf = new FS::Conf; + $dir_prefix = $conf->config('home'); + @shells = $conf->config('shells'); + $shellmachine = $conf->config('shellmachine'); +}; + +@saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' ); +@pw_set = ( 'a'..'z', 'A'..'Z', '0'..'9', '(', ')', '#', '!', '.', ',' ); + +#not needed in 5.004 #srand($$|time); + +=head1 NAME + +FS::svc_acct - Object methods for svc_acct records + +=head1 SYNOPSIS + + use FS::svc_acct; + + $record = new FS::svc_acct \%hash; + $record = new FS::svc_acct { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + + $error = $record->suspend; + + $error = $record->unsuspend; + + $error = $record->cancel; + +=head1 DESCRIPTION + +An FS::svc_acct object represents an account. FS::svc_acct inherits from +FS::svc_Common. The following fields are currently supported: + +=over 4 + +=item svcnum - primary key (assigned automatcially for new accounts) + +=item username + +=item _password - generated if blank + +=item popnum - Point of presence (see L) + +=item uid + +=item gid + +=item finger - GECOS + +=item dir - set automatically if blank (and uid is not) + +=item shell + +=item quota - (unimplementd) + +=item slipip - IP address + +=item radius_I - I + +=back + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new account. To add the account to the database, see L<"insert">. + +=cut + +sub table { 'svc_acct'; } + +=item insert + +Adds this account to the database. If there is an error, returns the error, +otherwise returns false. + +The additional fields pkgnum and svcpart (see L) should be +defined. An FS::cust_svc record will be created and inserted. + +If the configuration value (see L) shellmachine exists, and the +username, uid, and dir fields are defined, the command + + useradd -d $dir -m -s $shell -u $uid $username + +is executed on shellmachine via ssh. This behaviour can be surpressed by +setting $FS::svc_acct::nossh_hack true. + +=cut + +sub insert { + my $self = shift; + my $error; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + $error = $self->check; + return $error if $error; + + return "Username ". $self->username. " in use" + if qsearchs( 'svc_acct', { 'username' => $self->username } ); + + my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } ); + return "Unkonwn svcpart" unless $part_svc; + return "uid in use" + if $part_svc->svc_acct__uid_flag ne 'F' + && qsearchs( 'svc_acct', { 'uid' => $self->uid } ) + && $self->username !~ /^(hyla)?fax$/ + ; + + $error = $self->SUPER::insert; + return $error if $error; + + my ( $username, $uid, $dir, $shell ) = ( + $self->username, + $self->uid, + $self->dir, + $self->shell, + ); + if ( $username + && $uid + && $dir + && $shellmachine + && ! $nossh_hack ) { + #one way + ssh("root\@$shellmachine", + "useradd -d $dir -m -s $shell -u $uid $username" + ); + #another way + #ssh("root\@$shellmachine","/bin/mkdir $dir; /bin/chmod 711 $dir; ". + # "/bin/cp -p /etc/skel/.* $dir 2>/dev/null; ". + # "/bin/cp -pR /etc/skel/Maildir $dir 2>/dev/null; ". + # "/bin/chown -R $uid $dir") unless $nossh_hack; + } + + ''; #no error +} + +=item delete + +Deletes this account from the database. If there is an error, returns the +error, otherwise returns false. + +The corresponding FS::cust_svc record will be deleted as well. + +If the configuration value (see L) shellmachine exists, the command: + + userdel $username + +is executed on shellmachine via ssh. This behaviour can be surpressed by +setting $FS::svc_acct::nossh_hack true. + +=cut + +sub delete { + my $self = shift; + my $error; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + $error = $self->SUPER::delete; + return $error if $error; + + my $username = $self->username; + if ( $username && $shellmachine && ! $nossh_hack ) { + ssh("root\@$shellmachine","userdel $username"); + } + + ''; +} + +=item replace OLD_RECORD + +Replaces OLD_RECORD with this one in the database. If there is an error, +returns the error, otherwise returns false. + +If the configuration value (see L) shellmachine exists, and the +dir field has changed, the command: + + [ -d $old_dir ] && ( + chmod u+t $old_dir; + umask 022; + mkdir $new_dir; + cd $old_dir; + find . -depth -print | cpio -pdm $new_dir; + chmod u-t $new_dir; + chown -R $uid.$gid $new_dir; + rm -rf $old_dir + ) + +is executed on shellmachine via ssh. This behaviour can be surpressed by +setting $FS::svc_acct::nossh_hack true. + +=cut + +sub replace { + my ( $new, $old ) = ( shift, shift ); + my $error; + + return "Username in use" + if $old->username ne $new->username && + qsearchs( 'svc_acct', { 'username' => $new->username } ); + + return "Can't change uid!" if $old->uid != $new->uid; + + #change homdir when we change username + $new->setfield('dir', '') if $old->username ne $new->username; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + $error = $new->SUPER::replace($old); + return $error if $error; + + my ( $old_dir, $new_dir ) = ( $old->getfield('dir'), $new->getfield('dir') ); + my ( $uid, $gid) = ( $new->getfield('uid'), $new->getfield('gid') ); + if ( $old_dir + && $new_dir + && $old_dir ne $new_dir + && ! $nossh_hack + ) { + ssh("root\@$shellmachine","[ -d $old_dir ] && ". + "( chmod u+t $old_dir; ". #turn off qmail delivery + "umask 022; mkdir $new_dir; cd $old_dir; ". + "find . -depth -print | cpio -pdm $new_dir; ". + "chmod u-t $new_dir; chown -R $uid.$gid $new_dir; ". + "rm -rf $old_dir". + ")" + ); + } + + ''; #no error +} + +=item suspend + +Suspends this account by prefixing *SUSPENDED* to the password. If there is an +error, returns the error, otherwise returns false. + +Called by the suspend method of FS::cust_pkg (see L). + +=cut + +sub suspend { + my $self = shift; + my %hash = $self->hash; + unless ( $hash{_password} =~ /^\*SUSPENDED\* / ) { + $hash{_password} = '*SUSPENDED* '.$hash{_password}; + my $new = new FS::svc_acct ( \%hash ); + $new->replace($self); + } else { + ''; #no error (already suspended) + } +} + +=item unsuspend + +Unsuspends this account by removing *SUSPENDED* from the password. If there is +an error, returns the error, otherwise returns false. + +Called by the unsuspend method of FS::cust_pkg (see L). + +=cut + +sub unsuspend { + my $self = shift; + my %hash = $self->hash; + if ( $hash{_password} =~ /^\*SUSPENDED\* (.*)$/ ) { + $hash{_password} = $1; + my $new = new FS::svc_acct ( \%hash ); + $new->replace($self); + } else { + ''; #no error (already unsuspended) + } +} + +=item cancel + +Just returns false (no error) for now. + +Called by the cancel method of FS::cust_pkg (see L). + +=item check + +Checks all fields to make sure this is a valid service. If there is an error, +returns the error, otherwise returns false. Called by the insert and replace +methods. + +Sets any fixed values; see L. + +=cut + +sub check { + my $self = shift; + + my($recref) = $self->hashref; + + my $x = $self->setfixed; + return $x unless ref($x); + my $part_svc = $x; + + my $ulen =$self->dbdef_table->column('username')->length; + $recref->{username} =~ /^([a-z0-9_\-]{2,$ulen})$/ + or return "Illegal username"; + $recref->{username} = $1; + $recref->{username} =~ /[a-z]/ or return "Illegal username"; + + $recref->{popnum} =~ /^(\d*)$/ or return "Illegal popnum"; + $recref->{popnum} = $1; + return "Unkonwn popnum" unless + ! $recref->{popnum} || + qsearchs('svc_acct_pop',{'popnum'=> $recref->{popnum} } ); + + unless ( $part_svc->getfield('svc_acct__uid_flag') eq 'F' ) { + + $recref->{uid} =~ /^(\d*)$/ or return "Illegal uid"; + $recref->{uid} = $1 eq '' ? $self->unique('uid') : $1; + + $recref->{gid} =~ /^(\d*)$/ or return "Illegal gid"; + $recref->{gid} = $1 eq '' ? $recref->{uid} : $1; + #not all systems use gid=uid + #you can set a fixed gid in part_svc + + 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'); + + $recref->{dir} =~ /^([\/\w\-]*)$/ + or return "Illegal directory"; + $recref->{dir} = $1 || + $dir_prefix . '/' . $recref->{username} + #$dir_prefix . '/' . substr($recref->{username},0,1). '/' . $recref->{username} + ; + + unless ( $recref->{username} eq 'sync' ) { + my($shell); + if ( $shell = (grep $_ eq $recref->{shell}, @shells)[0] ) { + $recref->{shell} = $shell; + } else { + return "Illegal shell \`". $self->shell. "\'; ". + $conf->dir. "/shells contains: @shells"; + } + } else { + $recref->{shell} = '/bin/sync'; + } + + $recref->{quota} =~ /^(\d*)$/ or return "Illegal quota (unimplemented)"; + $recref->{quota} = $1; + + } else { + $recref->{gid} ne '' ? + return "Can't have gid without uid" : ( $recref->{gid}='' ); + $recref->{finger} ne '' ? + return "Can't have finger-name without uid" : ( $recref->{finger}='' ); + $recref->{dir} ne '' ? + return "Can't have directory without uid" : ( $recref->{dir}='' ); + $recref->{shell} ne '' ? + return "Can't have shell without uid" : ( $recref->{shell}='' ); + $recref->{quota} ne '' ? + return "Can't have quota without uid" : ( $recref->{quota}='' ); + } + + unless ( $part_svc->getfield('svc_acct__slipip_flag') eq 'F' ) { + unless ( $recref->{slipip} eq '0e0' ) { + $recref->{slipip} =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/ + or return "Illegal slipip". $self->slipip; + $recref->{slipip} = $1; + } else { + $recref->{slipip} = '0e0'; + } + + } + + #arbitrary RADIUS stuff; allow ut_textn for now + foreach ( grep /^radius_/, fields('svc_acct') ) { + $self->ut_textn($_); + } + + #generate a password if it is blank + $recref->{_password} = join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) ) + unless ( $recref->{_password} ); + + #if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{4,16})$/ ) { + if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{4,8})$/ ) { + $recref->{_password} = $1.$3; + #uncomment this to encrypt password immediately upon entry, or run + #bin/crypt_pw in cron to give new users a window during which their + #password is available to techs, for faxing, etc. (also be aware of + #radius issues!) + #$recref->{password} = $1. + # crypt($3,$saltset[int(rand(64))].$saltset[int(rand(64))] + #; + } elsif ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([\w\.\/]{13,24})$/ ) { + $recref->{_password} = $1.$3; + } elsif ( $recref->{_password} eq '*' ) { + $recref->{_password} = '*'; + } else { + return "Illegal password"; + } + + ''; #no error +} + +=back + +=head1 VERSION + +$Id: svc_acct.pm,v 1.1 1999-08-04 09:03:53 ivan Exp $ + +=head1 BUGS + +The remote commands should be configurable. + +The bits which ssh should fork before doing so. + +The $recref stuff in sub check should be cleaned up. + +=head1 SEE ALSO + +L, L, L, L, +L, L, L, L, L, +schema.html from the base documentation. + +=cut + +1; + -- cgit v1.1 From aa39234613e8148c531ad3fd0ca46ee806563f6c Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 12 Aug 1999 00:05:03 +0000 Subject: configurable min/max username length, min password length, periods in usernames --- FS/FS/svc_acct.pm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index b2f23c9..079508b 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -1,8 +1,9 @@ package FS::svc_acct; use strict; -use vars qw(@ISA $nossh_hack $conf $dir_prefix @shells - $shellmachine @saltset @pw_set); +use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin + $usernamemax $passwordmin + $shellmachine @saltset @pw_set); use FS::Conf; use FS::Record qw( qsearchs fields ); use FS::svc_Common; @@ -18,6 +19,9 @@ $FS::UID::callback{'FS::svc_acct'} = sub { $dir_prefix = $conf->config('home'); @shells = $conf->config('shells'); $shellmachine = $conf->config('shellmachine'); + $usernamemin = $conf->config('usernamemin') || 2; + $usernamemax = $conf->config('usernamemax'); + $passwordmin = $conf->config('passwordmin') || 6; }; @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' ); @@ -338,8 +342,8 @@ sub check { return $x unless ref($x); my $part_svc = $x; - my $ulen =$self->dbdef_table->column('username')->length; - $recref->{username} =~ /^([a-z0-9_\-]{2,$ulen})$/ + 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"; @@ -422,7 +426,7 @@ sub check { unless ( $recref->{_password} ); #if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{4,16})$/ ) { - if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{4,8})$/ ) { + if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{$passwordmin,8})$/ ) { $recref->{_password} = $1.$3; #uncomment this to encrypt password immediately upon entry, or run #bin/crypt_pw in cron to give new users a window during which their @@ -446,7 +450,7 @@ sub check { =head1 VERSION -$Id: svc_acct.pm,v 1.1 1999-08-04 09:03:53 ivan Exp $ +$Id: svc_acct.pm,v 1.2 1999-08-12 00:05:03 ivan Exp $ =head1 BUGS -- cgit v1.1 From e3aaca5c08b8b39627978eb30d10dfb241946b93 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 6 Mar 2000 16:38:42 +0000 Subject: better error message. bah. --- FS/FS/svc_acct.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 079508b..fcd8030 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -348,7 +348,7 @@ sub check { $recref->{username} = $1; $recref->{username} =~ /[a-z]/ or return "Illegal username"; - $recref->{popnum} =~ /^(\d*)$/ or return "Illegal popnum"; + $recref->{popnum} =~ /^(\d*)$/ or return "Illegal popnum: ".$recref->{popnum}; $recref->{popnum} = $1; return "Unkonwn popnum" unless ! $recref->{popnum} || @@ -450,7 +450,7 @@ sub check { =head1 VERSION -$Id: svc_acct.pm,v 1.2 1999-08-12 00:05:03 ivan Exp $ +$Id: svc_acct.pm,v 1.3 2000-03-06 16:38:42 ivan Exp $ =head1 BUGS -- cgit v1.1 From 85d18115231d9c0a98e79eec997444d9f0d30866 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 15 Jun 2000 13:35:47 +0000 Subject: add radius method --- FS/FS/svc_acct.pm | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index fcd8030..339081a 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -54,6 +54,8 @@ FS::svc_acct - Object methods for svc_acct records $error = $record->cancel; + %hash = $record->radius; + =head1 DESCRIPTION An FS::svc_acct object represents an account. FS::svc_acct inherits from @@ -446,11 +448,32 @@ sub check { ''; #no error } +=item radius + +Returns key/value pairs, suitable for assigning to a hash, for any RADIUS +attributes of this record. + +Note that this is now the preferred method for reading RADIUS attributes - +accessing the columns directly is discouraged, as the column names are +expected to change in the future. + +=cut + +sub radius { + my $self = shift; + map { + /^(radius_(.*))$/; + my($column, $attrib) = ($1, $2); + $attrib =~ s/_/\-/g; + ( $attrib, $self->getfield($column) ); + } grep { /^radius_/ && $self->getfield($_) } fields( $self->table ); +} + =back =head1 VERSION -$Id: svc_acct.pm,v 1.3 2000-03-06 16:38:42 ivan Exp $ +$Id: svc_acct.pm,v 1.4 2000-06-15 13:35:47 ivan Exp $ =head1 BUGS -- cgit v1.1 From be4e54da250b7b94ddfd67c9f8eeb02288e10020 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 28 Jun 2000 12:52:22 +0000 Subject: bugfix to accept shells that evaluate to false in perl, like the empty string. --- FS/FS/svc_acct.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 339081a..14979ed 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -381,8 +381,8 @@ sub check { unless ( $recref->{username} eq 'sync' ) { my($shell); - if ( $shell = (grep $_ eq $recref->{shell}, @shells)[0] ) { - $recref->{shell} = $shell; + if ( grep $_ eq $recref->{shell}, @shells ) { + $recref->{shell} = (grep $_ eq $recref->{shell}, @shells)[0]; } else { return "Illegal shell \`". $self->shell. "\'; ". $conf->dir. "/shells contains: @shells"; @@ -473,7 +473,7 @@ sub radius { =head1 VERSION -$Id: svc_acct.pm,v 1.4 2000-06-15 13:35:47 ivan Exp $ +$Id: svc_acct.pm,v 1.5 2000-06-28 12:52:22 ivan Exp $ =head1 BUGS -- cgit v1.1 From 9d6e81f15df01d7146def82c6e62d7c65fd2bc82 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 28 Jun 2000 12:54:33 +0000 Subject: superfluous my() --- FS/FS/svc_acct.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 14979ed..9335429 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -380,7 +380,6 @@ sub check { ; unless ( $recref->{username} eq 'sync' ) { - my($shell); if ( grep $_ eq $recref->{shell}, @shells ) { $recref->{shell} = (grep $_ eq $recref->{shell}, @shells)[0]; } else { @@ -473,7 +472,7 @@ sub radius { =head1 VERSION -$Id: svc_acct.pm,v 1.5 2000-06-28 12:52:22 ivan Exp $ +$Id: svc_acct.pm,v 1.6 2000-06-28 12:54:33 ivan Exp $ =head1 BUGS -- cgit v1.1 From 5072965ec7e8d55ef82769fc322240abc7fb7e00 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 29 Jun 2000 11:56:52 +0000 Subject: md5 passwords can are 34 characters long and have $ in them. --- FS/FS/svc_acct.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 9335429..26c634b 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -436,7 +436,7 @@ sub check { #$recref->{password} = $1. # crypt($3,$saltset[int(rand(64))].$saltset[int(rand(64))] #; - } elsif ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([\w\.\/]{13,24})$/ ) { + } elsif ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([\w\.\/\$]{13,34})$/ ) { $recref->{_password} = $1.$3; } elsif ( $recref->{_password} eq '*' ) { $recref->{_password} = '*'; @@ -472,7 +472,7 @@ sub radius { =head1 VERSION -$Id: svc_acct.pm,v 1.6 2000-06-28 12:54:33 ivan Exp $ +$Id: svc_acct.pm,v 1.7 2000-06-29 11:56:52 ivan Exp $ =head1 BUGS -- cgit v1.1 From 24a036da06d8418666d966895aa94cf0675318fd Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 4 Jul 2000 13:42:37 +0000 Subject: noted a API inconsistancy --- FS/FS/svc_acct.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 26c634b..a59d863 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -472,7 +472,7 @@ sub radius { =head1 VERSION -$Id: svc_acct.pm,v 1.7 2000-06-29 11:56:52 ivan Exp $ +$Id: svc_acct.pm,v 1.8 2000-07-04 13:42:37 ivan Exp $ =head1 BUGS @@ -482,6 +482,10 @@ The bits which ssh should fork before doing so. The $recref stuff in sub check should be cleaned up. +The suspend, unsuspend and cancel methods update the database, but not the +current object. This is probably a bug as it's unexpected and +counterintuitive. + =head1 SEE ALSO L, L, L, L, -- cgit v1.1 From 61fc4e61c6644d2e0abdffe8cbdfafd4b092e84b Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 6 Jul 2000 08:57:28 +0000 Subject: support for radius check attributes (except importing). poorly documented. --- FS/FS/svc_acct.pm | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index a59d863..558e383 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -4,6 +4,7 @@ use strict; use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin $usernamemax $passwordmin $shellmachine @saltset @pw_set); +use Carp; use FS::Conf; use FS::Record qw( qsearchs fields ); use FS::svc_Common; @@ -449,8 +450,19 @@ sub check { =item radius +Depriciated, use radius_reply instead. + +=cut + +sub radius { + carp "FS::svc_acct::radius depriciated, use radius_reply"; + $_[0]->radius_reply; +} + +=item radius_reply + Returns key/value pairs, suitable for assigning to a hash, for any RADIUS -attributes of this record. +reply attributes of this record. Note that this is now the preferred method for reading RADIUS attributes - accessing the columns directly is discouraged, as the column names are @@ -458,7 +470,7 @@ expected to change in the future. =cut -sub radius { +sub radius_reply { my $self = shift; map { /^(radius_(.*))$/; @@ -468,11 +480,29 @@ sub radius { } grep { /^radius_/ && $self->getfield($_) } fields( $self->table ); } +=item radius_check + +Returns key/value pairs, suitable for assigning to a hash, for any RADIUS +check attributes of this record. + +Accessing RADIUS attributes directly is not supported and will break in the +future. + =back +sub radius_check { + my $self = shift; + map { + /^(rc_(.*))$/; + my($column, $attrib) = ($1, $2); + $attrib =~ s/_/\-/g; + ( $attrib, $self->getfield($column) ); + } grep { /^rc_/ && $self->getfield($_) } fields( $self->table ); +} + =head1 VERSION -$Id: svc_acct.pm,v 1.8 2000-07-04 13:42:37 ivan Exp $ +$Id: svc_acct.pm,v 1.9 2000-07-06 08:57:27 ivan Exp $ =head1 BUGS -- cgit v1.1 From aa0ba10d4319ee7cd473776df10abf7a3eec18fc Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 6 Jul 2000 13:56:42 +0000 Subject: mis-PODed =back should have been a =cut in conjunction with AUTOLOAD this was sure a pain to find --- FS/FS/svc_acct.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 558e383..56ad5d7 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -488,7 +488,7 @@ check attributes of this record. Accessing RADIUS attributes directly is not supported and will break in the future. -=back +=cut sub radius_check { my $self = shift; @@ -500,9 +500,11 @@ sub radius_check { } grep { /^rc_/ && $self->getfield($_) } fields( $self->table ); } +=cut + =head1 VERSION -$Id: svc_acct.pm,v 1.9 2000-07-06 08:57:27 ivan Exp $ +$Id: svc_acct.pm,v 1.10 2000-07-06 13:56:42 ivan Exp $ =head1 BUGS -- cgit v1.1 From ec0441faaefa3fa2bd41e88ddc4bd3049198612a Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 17 Jul 2000 10:37:27 +0000 Subject: make remote commands configurable --- FS/FS/svc_acct.pm | 119 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 46 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 56ad5d7..5986bff 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -3,7 +3,8 @@ package FS::svc_acct; use strict; use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin $usernamemax $passwordmin - $shellmachine @saltset @pw_set); + $shellmachine $useradd $usermod $userdel + @saltset @pw_set); use Carp; use FS::Conf; use FS::Record qw( qsearchs fields ); @@ -23,6 +24,27 @@ $FS::UID::callback{'FS::svc_acct'} = sub { $usernamemin = $conf->config('usernamemin') || 2; $usernamemax = $conf->config('usernamemax'); $passwordmin = $conf->config('passwordmin') || 6; + if ( $shellmachine ) { + if ( $conf->exists('shellmachine-useradd') ) { + $useradd = join("\n", $conf->config('shellmachine-useradd') ) + || 'cp -pr /etc/skel $dir; chown -R $uid.$gid $dir'; + } else { + $useradd = 'useradd -d $dir -m -s $shell -u $uid $username'; + } + if ( $conf->exists('shellmachine-userdel') ) { + $userdel = join("\n", $conf->config('shellmachine-userdel') ) + || 'rm -rf $dir'; + } else { + $userdel = 'userdel $username'; + } + $usermod = join("\n", $conf->config('shellmachine-usermod') ) + || '[ -d $old_dir ] && mv $old_dir $new_dir || ( '. + 'chmod u+t $old_dir; mkdir $new_dir; cd $old_dir; '. + 'find . -depth -print | cpio -pdm $new_dir; '. + 'chmod u-t $new_dir; chown -R $uid.$gid $new_dir; '. + 'rm -rf $old_dir'. + ')'; + } }; @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' ); @@ -111,12 +133,21 @@ The additional fields pkgnum and svcpart (see L) should be defined. An FS::cust_svc record will be created and inserted. If the configuration value (see L) shellmachine exists, and the -username, uid, and dir fields are defined, the command +username, uid, and dir fields are defined, the command(s) specified in +the shellmachine-useradd configuration are exectued on shellmachine via ssh. +This behaviour can be surpressed by setting $FS::svc_acct::nossh_hack true. +If the shellmachine-useradd configuration file does not exist, useradd -d $dir -m -s $shell -u $uid $username -is executed on shellmachine via ssh. This behaviour can be surpressed by -setting $FS::svc_acct::nossh_hack true. +is the default. If the shellmachine-useradd configuration file exists but +it empty, + + cp -pr /etc/skel $dir; chown -R $uid.$gid $dir + +is the default instead. Otherwise the contents of the file are treated as +a double-quoted perl string, with the following variables available: +$username, $uid, $gid, $dir, and $shell. =cut @@ -148,26 +179,15 @@ sub insert { $error = $self->SUPER::insert; return $error if $error; - my ( $username, $uid, $dir, $shell ) = ( + my( $username, $uid, $gid, $dir, $shell ) = ( $self->username, $self->uid, + $self->gid, $self->dir, $self->shell, ); - if ( $username - && $uid - && $dir - && $shellmachine - && ! $nossh_hack ) { - #one way - ssh("root\@$shellmachine", - "useradd -d $dir -m -s $shell -u $uid $username" - ); - #another way - #ssh("root\@$shellmachine","/bin/mkdir $dir; /bin/chmod 711 $dir; ". - # "/bin/cp -p /etc/skel/.* $dir 2>/dev/null; ". - # "/bin/cp -pR /etc/skel/Maildir $dir 2>/dev/null; ". - # "/bin/chown -R $uid $dir") unless $nossh_hack; + if ( $username && $uid && $dir && $shellmachine && ! $nossh_hack ) { + ssh("root\@$shellmachine", eval "$useradd"); } ''; #no error @@ -180,12 +200,22 @@ error, otherwise returns false. The corresponding FS::cust_svc record will be deleted as well. -If the configuration value (see L) shellmachine exists, the command: +If the configuration value (see L) shellmachine exists, the +command(s) specified in the shellmachine-userdel configuration file are +executed on shellmachine via ssh. This behavior can be surpressed by setting +$FS::svc_acct::nossh_hack true. If the shellmachine-userdel configuration +file does not exist, userdel $username -is executed on shellmachine via ssh. This behaviour can be surpressed by -setting $FS::svc_acct::nossh_hack true. +is the default. If the shellmachine-userdel configuration file exists but +is empty, + + rm -rf $dir + +is the default instead. Otherwise the contents of the file are treated as a +double-quoted perl string, with the following variables available: +$username and $dir. =cut @@ -203,9 +233,12 @@ sub delete { $error = $self->SUPER::delete; return $error if $error; - my $username = $self->username; + my( $username, $dir ) = ( + $self->username, + $self->dir, + ); if ( $username && $shellmachine && ! $nossh_hack ) { - ssh("root\@$shellmachine","userdel $username"); + ssh("root\@$shellmachine", eval "$userdel"); } ''; @@ -217,11 +250,13 @@ Replaces OLD_RECORD with this one in the database. If there is an error, returns the error, otherwise returns false. If the configuration value (see L) shellmachine exists, and the -dir field has changed, the command: +dir field has changed, the command(s) specified in the shellmachine-usermod +configuraiton file are executed on shellmachine via ssh. This behavior can +be surpressed by setting $FS::svc-acct::nossh_hack true. If the +shellmachine-userdel configuration file does not exist or is empty, : - [ -d $old_dir ] && ( + [ -d $old_dir ] && mv $old_dir $new_dir || ( chmod u+t $old_dir; - umask 022; mkdir $new_dir; cd $old_dir; find . -depth -print | cpio -pdm $new_dir; @@ -258,21 +293,14 @@ sub replace { $error = $new->SUPER::replace($old); return $error if $error; - my ( $old_dir, $new_dir ) = ( $old->getfield('dir'), $new->getfield('dir') ); - my ( $uid, $gid) = ( $new->getfield('uid'), $new->getfield('gid') ); - if ( $old_dir - && $new_dir - && $old_dir ne $new_dir - && ! $nossh_hack - ) { - ssh("root\@$shellmachine","[ -d $old_dir ] && ". - "( chmod u+t $old_dir; ". #turn off qmail delivery - "umask 022; mkdir $new_dir; cd $old_dir; ". - "find . -depth -print | cpio -pdm $new_dir; ". - "chmod u-t $new_dir; chown -R $uid.$gid $new_dir; ". - "rm -rf $old_dir". - ")" - ); + my ( $old_dir, $new_dir, $uid, $gid ) = ( + $old->getfield('dir'), + $new->getfield('dir'), + $new->getfield('uid'), + $new->getfield('gid'), + ); + if ( $old_dir && $new_dir && $old_dir ne $new_dir && ! $nossh_hack ) { + ssh("root\@$shellmachine", eval "$usermod" ); } ''; #no error @@ -504,13 +532,12 @@ sub radius_check { =head1 VERSION -$Id: svc_acct.pm,v 1.10 2000-07-06 13:56:42 ivan Exp $ +$Id: svc_acct.pm,v 1.11 2000-07-17 10:37:27 ivan Exp $ =head1 BUGS -The remote commands should be configurable. - -The bits which ssh should fork before doing so. +The bits which ssh should fork before doing so (or maybe queue jobs for a +daemon). The $recref stuff in sub check should be cleaned up. -- cgit v1.1 From 41e9b7ac95959d4392a7aee9b8aef1cc301a1eb6 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 17 Jul 2000 10:53:42 +0000 Subject: prevent accounts which are the target of mail aliases from being deleted --- FS/FS/svc_acct.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 5986bff..93b657f 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -12,6 +12,7 @@ use FS::svc_Common; use FS::SSH qw(ssh); use FS::part_svc; use FS::svc_acct_pop; +use FS::svc_acct_sm; @ISA = qw( FS::svc_Common ); @@ -223,6 +224,9 @@ sub delete { my $self = shift; my $error; + return "Can't delete an account which has mail aliases pointed to it!" + if $self->uid && qsearch( 'svc_acct_sm', { 'domuid' => $self->uid } ); + local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; local $SIG{QUIT} = 'IGNORE'; @@ -532,7 +536,7 @@ sub radius_check { =head1 VERSION -$Id: svc_acct.pm,v 1.11 2000-07-17 10:37:27 ivan Exp $ +$Id: svc_acct.pm,v 1.12 2000-07-17 10:53:42 ivan Exp $ =head1 BUGS -- cgit v1.1 From 48b905cd57f4b9e0f33e84bcee15b28d812c3d9f Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 17 Jul 2000 13:51:07 +0000 Subject: silly mistake --- FS/FS/svc_acct.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 93b657f..d2e3918 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -188,7 +188,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 @@ -242,7 +242,7 @@ sub delete { $self->dir, ); if ( $username && $shellmachine && ! $nossh_hack ) { - ssh("root\@$shellmachine", eval "$userdel"); + ssh("root\@$shellmachine", eval qq("$userdel") ); } ''; @@ -304,7 +304,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 @@ -536,7 +536,7 @@ sub radius_check { =head1 VERSION -$Id: svc_acct.pm,v 1.12 2000-07-17 10:53:42 ivan Exp $ +$Id: svc_acct.pm,v 1.13 2000-07-17 13:51:07 ivan Exp $ =head1 BUGS -- cgit v1.1 From d746dfce2e320169ec8217cb09b9dbb0d403675d Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 31 Jan 2001 07:21:00 +0000 Subject: fix tyops --- FS/FS/svc_acct.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index d2e3918..9d2db0e 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -170,7 +170,7 @@ sub insert { if qsearchs( 'svc_acct', { 'username' => $self->username } ); 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 } ) @@ -385,7 +385,7 @@ sub check { $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} } ); @@ -536,7 +536,7 @@ sub radius_check { =head1 VERSION -$Id: svc_acct.pm,v 1.13 2000-07-17 13:51:07 ivan Exp $ +$Id: svc_acct.pm,v 1.14 2001-01-31 07:21:00 ivan Exp $ =head1 BUGS -- cgit v1.1 From 1c14b1faec0f3f07a6d4190cf535b3ddb45075ce Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 22 Apr 2001 01:56:15 +0000 Subject: get rid of FS::SSH.pm (became Net::SSH and Net::SCP on CPAN) --- FS/FS/svc_acct.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 9d2db0e..79104b8 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -9,7 +9,7 @@ use Carp; use FS::Conf; use FS::Record qw( 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; @@ -536,7 +536,7 @@ sub radius_check { =head1 VERSION -$Id: svc_acct.pm,v 1.14 2001-01-31 07:21:00 ivan Exp $ +$Id: svc_acct.pm,v 1.15 2001-04-22 01:56:15 ivan Exp $ =head1 BUGS @@ -552,7 +552,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 -- cgit v1.1 From 71a3746e52903b26baf7246d38bd46349a5b10cb Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 3 Jun 2001 11:37:08 +0000 Subject: fixes Can't locate object method "setfield" via package "svc_acct_sm" at /usr/local/lib/perl5/site_perl/5.005/FS/Record.pm line 318 --- FS/FS/svc_acct.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 79104b8..774b8d0 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -7,7 +7,7 @@ use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin @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 Net::SSH qw(ssh); use FS::part_svc; @@ -536,7 +536,7 @@ sub radius_check { =head1 VERSION -$Id: svc_acct.pm,v 1.15 2001-04-22 01:56:15 ivan Exp $ +$Id: svc_acct.pm,v 1.16 2001-06-03 11:37:08 ivan Exp $ =head1 BUGS -- cgit v1.1 From 4d23190fe52f0c3c5071c806187a524ecfa52cdd Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 3 Jun 2001 12:36:10 +0000 Subject: add username-letter and username-letterfirst config files --- FS/FS/svc_acct.pm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 774b8d0..0e0c885 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -2,7 +2,7 @@ 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; @@ -46,6 +46,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' , '.' , '/' ); @@ -381,7 +383,11 @@ sub check { $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; @@ -536,7 +542,7 @@ sub radius_check { =head1 VERSION -$Id: svc_acct.pm,v 1.16 2001-06-03 11:37:08 ivan Exp $ +$Id: svc_acct.pm,v 1.17 2001-06-03 12:36:10 ivan Exp $ =head1 BUGS -- cgit v1.1 From 0c6ad8b79dc68d779adf04256bb616f78d556505 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 30 Jul 2001 06:28:45 +0000 Subject: allow !! as password for disabled accounts --- FS/FS/svc_acct.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 0e0c885..a22ecdf 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -479,6 +479,8 @@ sub check { $recref->{_password} = $1.$3; } elsif ( $recref->{_password} eq '*' ) { $recref->{_password} = '*'; + } elsif ( $recref->{_password} eq '!!' ) { + $recref->{_password} = '!!'; } else { return "Illegal password"; } @@ -542,7 +544,7 @@ sub radius_check { =head1 VERSION -$Id: svc_acct.pm,v 1.17 2001-06-03 12:36:10 ivan Exp $ +$Id: svc_acct.pm,v 1.18 2001-07-30 06:28:45 ivan Exp $ =head1 BUGS -- cgit v1.1 From 9c2016b3a564d439960420114ce6f4cab3bf723b Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 30 Jul 2001 07:34:41 +0000 Subject: podnitfix --- FS/FS/svc_acct.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index a22ecdf..4b7ec98 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -540,11 +540,11 @@ sub radius_check { } grep { /^rc_/ && $self->getfield($_) } fields( $self->table ); } -=cut +=back =head1 VERSION -$Id: svc_acct.pm,v 1.18 2001-07-30 06:28:45 ivan Exp $ +$Id: svc_acct.pm,v 1.19 2001-07-30 07:34:41 ivan Exp $ =head1 BUGS -- cgit v1.1 From 4d513ff5a17bd3b697502b54c9516577a0a8d3e4 Mon Sep 17 00:00:00 2001 From: jeff Date: Sun, 12 Aug 2001 19:41:26 +0000 Subject: merging vpopmail support branch --- FS/FS/svc_acct.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 4b7ec98..83263b0 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -82,6 +82,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 @@ -113,6 +117,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 @@ -169,7 +175,9 @@ 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 "Unknown svcpart" unless $part_svc; @@ -544,7 +552,7 @@ sub radius_check { =head1 VERSION -$Id: svc_acct.pm,v 1.19 2001-07-30 07:34:41 ivan Exp $ +$Id: svc_acct.pm,v 1.20 2001-08-12 19:41:24 jeff Exp $ =head1 BUGS -- cgit v1.1 From 60953c6f2f313949e5773350f0917b7d68ebd939 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 13 Aug 2001 00:21:54 +0000 Subject: untaint svcnum & domsvc --- FS/FS/svc_acct.pm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 83263b0..9f95f40 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -381,6 +381,12 @@ Sets any fixed values; see L. sub check { my $self = shift; + my $error = + $self->ut_numbern('svcnum') + || $self->ut_number('domsvc') + ; + return $error if $error; + my($recref) = $self->hashref; my $x = $self->setfixed; @@ -416,8 +422,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"; @@ -552,7 +558,7 @@ sub radius_check { =head1 VERSION -$Id: svc_acct.pm,v 1.20 2001-08-12 19:41:24 jeff Exp $ +$Id: svc_acct.pm,v 1.21 2001-08-13 00:21:54 ivan Exp $ =head1 BUGS -- cgit v1.1 From ddb8528c025f6bef778f08885ae1411122874207 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 19 Aug 2001 08:15:10 +0000 Subject: set fixed fields before checking domsvc --- FS/FS/svc_acct.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 9f95f40..b0e007f 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -381,18 +381,18 @@ Sets any fixed values; see L. sub check { my $self = shift; - my $error = - $self->ut_numbern('svcnum') - || $self->ut_number('domsvc') - ; - return $error if $error; - my($recref) = $self->hashref; my $x = $self->setfixed; 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"; @@ -558,7 +558,7 @@ sub radius_check { =head1 VERSION -$Id: svc_acct.pm,v 1.21 2001-08-13 00:21:54 ivan Exp $ +$Id: svc_acct.pm,v 1.22 2001-08-19 08:15:10 ivan Exp $ =head1 BUGS -- cgit v1.1 From c2652bd1f1928b495e1dc5b4a43c46bffcc9022d Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 19 Aug 2001 08:18:01 +0000 Subject: ->setfixed untaints svcnum --- FS/FS/svc_acct.pm | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index b0e007f..253d56c 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -387,10 +387,7 @@ sub check { return $x unless ref($x); my $part_svc = $x; - my $error = - $self->ut_numbern('svcnum') - || $self->ut_number('domsvc') - ; + my $error = $self->ut_number('domsvc'); return $error if $error; my $ulen = $usernamemax || $self->dbdef_table->column('username')->length; @@ -558,7 +555,7 @@ sub radius_check { =head1 VERSION -$Id: svc_acct.pm,v 1.22 2001-08-19 08:15:10 ivan Exp $ +$Id: svc_acct.pm,v 1.23 2001-08-19 08:18:01 ivan Exp $ =head1 BUGS -- cgit v1.1 From 8a8c9386cbd3383b0134aae8e32b5995f8886fb2 Mon Sep 17 00:00:00 2001 From: jeff Date: Sun, 19 Aug 2001 15:53:36 +0000 Subject: added user interface for svc_forward and vpopmail support --- FS/FS/svc_acct.pm | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 253d56c..42eb7d9 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -551,11 +551,30 @@ sub radius_check { } grep { /^rc_/ && $self->getfield($_) } fields( $self->table ); } +=item email + +Returns an email address associated with the account. + +=cut + +sub email { + my $self = shift; + my $domain; + my $svc_domain = qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } ); + if ($svc_domain) { + $domain=$svc_domain->domain; + }else{ + warn "couldn't find svc_acct.domsvc " . $self->domsvc . "!"; + $domain="unknown"; + } + return $self->username . "@" . $domain; +} + =back =head1 VERSION -$Id: svc_acct.pm,v 1.23 2001-08-19 08:18:01 ivan Exp $ +$Id: svc_acct.pm,v 1.24 2001-08-19 15:53:34 jeff Exp $ =head1 BUGS -- cgit v1.1 From c6708c86785662d8f0c12e23936bf7b1916f411c Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 20 Aug 2001 09:41:52 +0000 Subject: dtrt when deleting accouts wrt forwards, catchalls & other references to svc_acct records depreciate svc_acct_sm further; move qmail catchall handling to svc_domain --- FS/FS/svc_acct.pm | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 42eb7d9..6551d94 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -13,6 +13,8 @@ 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 ); @@ -232,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'; @@ -244,8 +256,43 @@ 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, @@ -574,7 +621,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.24 2001-08-19 15:53:34 jeff Exp $ +$Id: svc_acct.pm,v 1.25 2001-08-20 09:41:52 ivan Exp $ =head1 BUGS -- cgit v1.1 From a9ec5a5c02a137cadd9f2a522fba904d945ddbe3 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 20 Aug 2001 11:04:38 +0000 Subject: more svc_forward work --- FS/FS/svc_acct.pm | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 6551d94..85b4888 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -434,7 +434,9 @@ sub check { return $x unless ref($x); my $part_svc = $x; - my $error = $self->ut_number('domsvc'); + my $error = $self->ut_numbern('svcnum') + || $self->ut_number('domsvc') + ; return $error if $error; my $ulen = $usernamemax || $self->dbdef_table->column('username')->length; @@ -598,6 +600,19 @@ 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. @@ -606,22 +621,14 @@ Returns an email address associated with the account. sub email { my $self = shift; - my $domain; - my $svc_domain = qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } ); - if ($svc_domain) { - $domain=$svc_domain->domain; - }else{ - warn "couldn't find svc_acct.domsvc " . $self->domsvc . "!"; - $domain="unknown"; - } - return $self->username . "@" . $domain; + $self->username. '@'. $self->domain; } =back =head1 VERSION -$Id: svc_acct.pm,v 1.25 2001-08-20 09:41:52 ivan Exp $ +$Id: svc_acct.pm,v 1.26 2001-08-20 11:04:38 ivan Exp $ =head1 BUGS -- cgit v1.1 From 3d2530a7d08dfae1473015d96d7394dc15b86ce1 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 21 Aug 2001 00:39:07 +0000 Subject: fix some silly syntax errors --- FS/FS/svc_acct.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 85b4888..97117b5 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -7,7 +7,7 @@ use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin @saltset @pw_set); use Carp; use FS::Conf; -use FS::Record qw( qsearch qsearchs fields ); +use FS::Record qw( qsearch qsearchs fields dbh ); use FS::svc_Common; use Net::SSH qw(ssh); use FS::part_svc; @@ -628,7 +628,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.26 2001-08-20 11:04:38 ivan Exp $ +$Id: svc_acct.pm,v 1.27 2001-08-21 00:39:07 ivan Exp $ =head1 BUGS -- cgit v1.1 From bfb8e18f5e245c3043ea44fad8fe3119ee73b37a Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 21 Aug 2001 03:03:36 +0000 Subject: fix domain method, and it works against old databases now too --- FS/FS/svc_acct.pm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 97117b5..9c95b21 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -3,7 +3,7 @@ package FS::svc_acct; use strict; use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin $usernamemax $passwordmin $username_letter $username_letterfirst - $shellmachine $useradd $usermod $userdel + $shellmachine $useradd $usermod $userdel $mydomain @saltset @pw_set); use Carp; use FS::Conf; @@ -50,6 +50,7 @@ $FS::UID::callback{'FS::svc_acct'} = sub { } $username_letter = $conf->exists('username-letter'); $username_letterfirst = $conf->exists('username-letterfirst'); + $mydomain = $conf->config('domain'); }; @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' ); @@ -604,13 +605,16 @@ sub radius_check { Returns the domain associated with this account. --cut +=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; + if ( $self->domsvc ) { + my $svc_domain = qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } ); + $svc_domain->domain; + } else { + $mydomain or die "svc_acct.domsvc is null and no legacy domain config file"; + } } =item email @@ -628,7 +632,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.27 2001-08-21 00:39:07 ivan Exp $ +$Id: svc_acct.pm,v 1.28 2001-08-21 03:03:36 ivan Exp $ =head1 BUGS -- cgit v1.1 From 9b81123e5ff5825d2c3c000432e4dd18b5fd764f Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 2 Sep 2001 04:51:11 +0000 Subject: better error msgs --- FS/FS/svc_acct.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 9c95b21..7e27fd8 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -610,7 +610,8 @@ Returns the domain associated with this account. sub domain { my $self = shift; if ( $self->domsvc ) { - my $svc_domain = qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } ); + my $svc_domain = qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } ) + or die "no svc_domain.svcnum for svc_acct.domsvc ". $self->domsvc; $svc_domain->domain; } else { $mydomain or die "svc_acct.domsvc is null and no legacy domain config file"; @@ -632,7 +633,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.28 2001-08-21 03:03:36 ivan Exp $ +$Id: svc_acct.pm,v 1.29 2001-09-02 04:51:11 ivan Exp $ =head1 BUGS -- cgit v1.1 From 57d69d5c1f98f778a0df82795ce21ee7bd21042a Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 6 Sep 2001 20:42:00 +0000 Subject: finally fix part_svc!!! --- FS/FS/svc_acct.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 7e27fd8..a4ce3f7 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -185,7 +185,7 @@ sub insert { my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } ); return "Unknown svcpart" unless $part_svc; return "uid in use" - if $part_svc->svc_acct__uid_flag ne 'F' + if $part_svc->part_svc_column('uid')->columnflag ne 'F' && qsearchs( 'svc_acct', { 'uid' => $self->uid } ) && $self->username !~ /^(hyla)?fax$/ ; @@ -456,7 +456,7 @@ sub check { ! $recref->{popnum} || qsearchs('svc_acct_pop',{'popnum'=> $recref->{popnum} } ); - unless ( $part_svc->getfield('svc_acct__uid_flag') eq 'F' ) { + unless ( $part_svc->part_svc_column('uid')->columnflag eq 'F' ) { $recref->{uid} =~ /^(\d*)$/ or return "Illegal uid"; $recref->{uid} = $1 eq '' ? $self->unique('uid') : $1; @@ -506,7 +506,7 @@ sub check { return "Can't have quota without uid" : ( $recref->{quota}='' ); } - unless ( $part_svc->getfield('svc_acct__slipip_flag') eq 'F' ) { + unless ( $part_svc->part_svc_column('slipip')->columnflag eq 'F' ) { unless ( $recref->{slipip} eq '0e0' ) { $recref->{slipip} =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/ or return "Illegal slipip". $self->slipip; @@ -633,7 +633,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.29 2001-09-02 04:51:11 ivan Exp $ +$Id: svc_acct.pm,v 1.30 2001-09-06 20:41:59 ivan Exp $ =head1 BUGS -- cgit v1.1 From e9c47f5904df328e0ac6e8ab993927d9aab3867c Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 6 Sep 2001 21:20:58 +0000 Subject: doc --- FS/FS/svc_acct.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index a4ce3f7..8a4d693 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -118,6 +118,10 @@ FS::svc_Common. The following fields are currently supported: =item slipip - IP address +=item seconds - + +=item domsvc - svcnum from svc_domain + =item radius_I - I =item domsvc - service number of svc_domain with which to associate @@ -633,7 +637,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.30 2001-09-06 20:41:59 ivan Exp $ +$Id: svc_acct.pm,v 1.31 2001-09-06 21:20:58 ivan Exp $ =head1 BUGS -- cgit v1.1 From 3beb58199322355f8caa166000bb94e9419b4232 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 7 Sep 2001 20:17:50 +0000 Subject: fix RADIUS attribute capitalization --- FS/FS/svc_acct.pm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 8a4d693..11e5a3c 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -15,6 +15,7 @@ use FS::svc_acct_pop; use FS::svc_acct_sm; use FS::cust_main_invoice; use FS::svc_domain; +use FS::raddb; @ISA = qw( FS::svc_Common ); @@ -580,8 +581,8 @@ sub radius_reply { map { /^(radius_(.*))$/; my($column, $attrib) = ($1, $2); - $attrib =~ s/_/\-/g; - ( $attrib, $self->getfield($column) ); + #$attrib =~ s/_/\-/g; + ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) ); } grep { /^radius_/ && $self->getfield($_) } fields( $self->table ); } @@ -600,8 +601,8 @@ sub radius_check { map { /^(rc_(.*))$/; my($column, $attrib) = ($1, $2); - $attrib =~ s/_/\-/g; - ( $attrib, $self->getfield($column) ); + #$attrib =~ s/_/\-/g; + ( $FS::raddb:attrib{lc($attrib)}, $self->getfield($column) ); } grep { /^rc_/ && $self->getfield($_) } fields( $self->table ); } @@ -637,7 +638,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.31 2001-09-06 21:20:58 ivan Exp $ +$Id: svc_acct.pm,v 1.32 2001-09-07 20:17:49 ivan Exp $ =head1 BUGS -- cgit v1.1 From 7b9a325db80ce49e6bc71e7132cfdf9e900af9cc Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 7 Sep 2001 20:26:33 +0000 Subject: tyops --- FS/FS/svc_acct.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 11e5a3c..fa055cf 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -602,7 +602,7 @@ sub radius_check { /^(rc_(.*))$/; my($column, $attrib) = ($1, $2); #$attrib =~ s/_/\-/g; - ( $FS::raddb:attrib{lc($attrib)}, $self->getfield($column) ); + ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) ); } grep { /^rc_/ && $self->getfield($_) } fields( $self->table ); } @@ -638,7 +638,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.32 2001-09-07 20:17:49 ivan Exp $ +$Id: svc_acct.pm,v 1.33 2001-09-07 20:26:33 ivan Exp $ =head1 BUGS -- cgit v1.1 From 842df85f746a2e1b961d6c9e3a8c5cc3678ae6dd Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 11 Sep 2001 03:15:58 +0000 Subject: cyrus support --- FS/FS/svc_acct.pm | 151 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 136 insertions(+), 15 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index fa055cf..926a9d3 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -4,6 +4,7 @@ use strict; use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin $usernamemax $passwordmin $username_letter $username_letterfirst $shellmachine $useradd $usermod $userdel $mydomain + $cyrus_server $cyrus_admin_user $cyrus_admin_pass @saltset @pw_set); use Carp; use FS::Conf; @@ -16,6 +17,7 @@ use FS::svc_acct_sm; use FS::cust_main_invoice; use FS::svc_domain; use FS::raddb; +use FS::queue; @ISA = qw( FS::svc_Common ); @@ -52,6 +54,15 @@ $FS::UID::callback{'FS::svc_acct'} = sub { $username_letter = $conf->exists('username-letter'); $username_letterfirst = $conf->exists('username-letterfirst'); $mydomain = $conf->config('domain'); + if ( $conf->exists('cyrus') ) { + ($cyrus_server, $cyrus_admin_user, $cyrus_admin_pass) = + $conf->config('cyrus'); + eval "use Cyrus::IMAP::Admin;" + } else { + $cyrus_server = ''; + $cyrus_admin_user = ''; + $cyrus_admin_pass = ''; + } }; @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' ); @@ -151,7 +162,8 @@ defined. An FS::cust_svc record will be created and inserted. If the configuration value (see L) shellmachine exists, and the username, uid, and dir fields are defined, the command(s) specified in -the shellmachine-useradd configuration are exectued on shellmachine via ssh. +the shellmachine-useradd configuration are added to the job queue (see +L and L) to be exectued on shellmachine via ssh. This behaviour can be surpressed by setting $FS::svc_acct::nossh_hack true. If the shellmachine-useradd configuration file does not exist, @@ -166,6 +178,8 @@ is the default instead. Otherwise the contents of the file are treated as a double-quoted perl string, with the following variables available: $username, $uid, $gid, $dir, and $shell. +(TODOC: cyrus config file, L and L) + =cut sub insert { @@ -179,6 +193,12 @@ sub insert { local $SIG{TSTP} = 'IGNORE'; local $SIG{PIPE} = 'IGNORE'; + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my $amount = 0; + $error = $self->check; return $error if $error; @@ -196,7 +216,10 @@ sub insert { ; $error = $self->SUPER::insert; - return $error if $error; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } my( $username, $uid, $gid, $dir, $shell ) = ( $self->username, @@ -206,12 +229,54 @@ sub insert { $self->shell, ); if ( $username && $uid && $dir && $shellmachine && ! $nossh_hack ) { - ssh("root\@$shellmachine", eval qq("$useradd") ); + my $queue = new FS::queue { 'job' => 'Net::SSH::ssh' }; + $error = $queue->insert("root\@$shellmachine", eval qq("$useradd") ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } } + if ( $cyrus_server ) { + my $queue = new FS::queue { 'job' => 'FS::svc_acct::cyrus_insert' }; + $error = $queue->insert($self->username, $self->quota); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; #no error } +sub cyrus_insert { + my( $username, $quota ) = + + my $client = Cyrus::IMAP::Admin->new($cyrus_server); + $client->authenticate( + -user => $cyrus_admin_user, + -mechanism => "login", + -password => $cyrus_admin_pass + ); + + my $rc = $client->create("user.$username"); + my $error = $client->error; + die $error if $error; + + $rc = $client->setacl("user.$username", $username => 'all' ); + $error = $client->error; + die $error if $error; + + if ( $quota ) { + $rc = $client->setquota("user.$username", 'STORAGE' => $quota ); + $error = $client->error; + die $error if $error; + } + + 1; +} + =item delete Deletes this account from the database. If there is an error, returns the @@ -221,7 +286,8 @@ The corresponding FS::cust_svc record will be deleted as well. If the configuration value (see L) shellmachine exists, the command(s) specified in the shellmachine-userdel configuration file are -executed on shellmachine via ssh. This behavior can be surpressed by setting +added to the job queue (see L and L) to be executed +on shellmachine via ssh. This behavior can be surpressed by setting $FS::svc_acct::nossh_hack true. If the shellmachine-userdel configuration file does not exist, @@ -236,6 +302,8 @@ is the default instead. Otherwise the contents of the file are treated as a double-quoted perl string, with the following variables available: $username and $dir. +(TODOC: cyrus config file) + =cut sub delete { @@ -298,19 +366,54 @@ sub delete { 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 qq("$userdel") ); + my $queue = new FS::queue { 'job' => 'Net::SSH::ssh' }; + $error = $queue->insert("root\@$shellmachine", eval qq("$userdel") ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } + + } + + if ( $cyrus_server ) { + my $queue = new FS::queue { 'job' => 'FS::svc_acct::cyrus_delete' }; + $error = $queue->insert($self->username); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; } +sub cyrus_delete { + my( $username ) = shift; + + my $client = Cyrus::IMAP::Admin->new($cyrus_server); + $client->authenticate( + -user => $cyrus_admin_user, + -mechanism => "login", + -password => $cyrus_admin_pass + ); + + my $rc = $client->setacl("user.$username", $cyrus_admin_user => 'all' ); + my $error = $client->error; + die $error if $error; + + $rc = $client->delete("user.$username"); + $error = $client->error; + die $error if $error; + + 1; +} + =item replace OLD_RECORD Replaces OLD_RECORD with this one in the database. If there is an error, @@ -318,9 +421,10 @@ returns the error, otherwise returns false. If the configuration value (see L) shellmachine exists, and the dir field has changed, the command(s) specified in the shellmachine-usermod -configuraiton file are executed on shellmachine via ssh. This behavior can +configuraiton file are added to the job queue (see L and +L) to be executed on shellmachine via ssh. This behavior can be surpressed by setting $FS::svc-acct::nossh_hack true. If the -shellmachine-userdel configuration file does not exist or is empty, : +shellmachine-userdel configuration file does not exist or is empty, [ -d $old_dir ] && mv $old_dir $new_dir || ( chmod u+t $old_dir; @@ -332,8 +436,8 @@ shellmachine-userdel configuration file does not exist or is empty, : rm -rf $old_dir ) -is executed on shellmachine via ssh. This behaviour can be surpressed by -setting $FS::svc_acct::nossh_hack true. +is the default. This behaviour can be surpressed by setting +$FS::svc_acct::nossh_hack true. =cut @@ -347,6 +451,9 @@ sub replace { return "Can't change uid!" if $old->uid != $new->uid; + return "can't change username using Cyrus" + if $cyrus_server && $old->username ne $new->username; + #change homdir when we change username $new->setfield('dir', '') if $old->username ne $new->username; @@ -357,8 +464,15 @@ sub replace { local $SIG{TSTP} = 'IGNORE'; local $SIG{PIPE} = 'IGNORE'; + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + $error = $new->SUPER::replace($old); - return $error if $error; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error if $error; + } my ( $old_dir, $new_dir, $uid, $gid ) = ( $old->getfield('dir'), @@ -367,9 +481,15 @@ sub replace { $new->getfield('gid'), ); if ( $old_dir && $new_dir && $old_dir ne $new_dir && ! $nossh_hack ) { - ssh("root\@$shellmachine", eval qq("$usermod") ); + my $queue = new FS::queue { 'job' => 'Net::SSH::ssh' }; + $error = $queue->insert("root\@$shellmachine", eval qq("$usermod") ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; #no error } @@ -638,7 +758,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.33 2001-09-07 20:26:33 ivan Exp $ +$Id: svc_acct.pm,v 1.34 2001-09-11 03:15:58 ivan Exp $ =head1 BUGS @@ -654,7 +774,8 @@ counterintuitive. =head1 SEE ALSO L, L, L, L, -L, L, L, L, L, +L, L, L, L), +L, L, L, schema.html from the base documentation. =cut -- cgit v1.1 From 8d6016abb9ca2e9d270d668e9607445921846aaa Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 11 Sep 2001 04:17:47 +0000 Subject: username-noperiod config file --- FS/FS/svc_acct.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 926a9d3..f7d2fd7 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -3,6 +3,7 @@ package FS::svc_acct; use strict; use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin $usernamemax $passwordmin $username_letter $username_letterfirst + $username_noperiod $shellmachine $useradd $usermod $userdel $mydomain $cyrus_server $cyrus_admin_user $cyrus_admin_pass @saltset @pw_set); @@ -53,6 +54,7 @@ $FS::UID::callback{'FS::svc_acct'} = sub { } $username_letter = $conf->exists('username-letter'); $username_letterfirst = $conf->exists('username-letterfirst'); + $username_noperiod = $conf->exists('username-noperiod'); $mydomain = $conf->config('domain'); if ( $conf->exists('cyrus') ) { ($cyrus_server, $cyrus_admin_user, $cyrus_admin_pass) = @@ -574,6 +576,9 @@ sub check { } elsif ( $username_letter ) { $recref->{username} =~ /[a-z]/ or return "Illegal username"; } + if ( $username_noperiod ) { + $recref->{username} =~ /\./ and return "Illegal username"; + } $recref->{popnum} =~ /^(\d*)$/ or return "Illegal popnum: ".$recref->{popnum}; $recref->{popnum} = $1; @@ -758,7 +763,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.34 2001-09-11 03:15:58 ivan Exp $ +$Id: svc_acct.pm,v 1.35 2001-09-11 04:17:47 ivan Exp $ =head1 BUGS -- cgit v1.1 From 38e8651d6bf1b6a394bff792c92a83d88654c098 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 11 Sep 2001 12:00:19 +0000 Subject: cyrus fix! --- FS/FS/svc_acct.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index f7d2fd7..3988634 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -253,7 +253,7 @@ sub insert { } sub cyrus_insert { - my( $username, $quota ) = + my( $username, $quota ) = @_; my $client = Cyrus::IMAP::Admin->new($cyrus_server); $client->authenticate( @@ -396,7 +396,7 @@ sub delete { } sub cyrus_delete { - my( $username ) = shift; + my $username = shift; my $client = Cyrus::IMAP::Admin->new($cyrus_server); $client->authenticate( @@ -763,7 +763,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.35 2001-09-11 04:17:47 ivan Exp $ +$Id: svc_acct.pm,v 1.36 2001-09-11 12:00:19 ivan Exp $ =head1 BUGS -- cgit v1.1 From e92e1a168b8fc6f6fcba9fd06f72e88ed9780457 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 11 Sep 2001 12:06:57 +0000 Subject: better logging --- FS/FS/svc_acct.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 3988634..d7dbcfa 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -255,22 +255,30 @@ sub insert { sub cyrus_insert { my( $username, $quota ) = @_; + warn "cyrus_insert: starting for user $username, quota $quota\n"; + + warn "cyrus_insert: connecting to $cyrus_server\n"; my $client = Cyrus::IMAP::Admin->new($cyrus_server); + + warn "cyrus_insert: authentication as $cyrus_admin_user\n"; $client->authenticate( -user => $cyrus_admin_user, -mechanism => "login", -password => $cyrus_admin_pass ); + warn "cyrus_insert: creating user.$username\n"; my $rc = $client->create("user.$username"); my $error = $client->error; - die $error if $error; + die "cyrus_insert: error creating user.$username: $error" if $error; + warn "cyrus_insert: setacl user.$username, $username => all\n"; $rc = $client->setacl("user.$username", $username => 'all' ); $error = $client->error; die $error if $error; if ( $quota ) { + warn "cyrus_insert: setquota user.$username, STORAGE => $quota\n"; $rc = $client->setquota("user.$username", 'STORAGE' => $quota ); $error = $client->error; die $error if $error; @@ -763,7 +771,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.36 2001-09-11 12:00:19 ivan Exp $ +$Id: svc_acct.pm,v 1.37 2001-09-11 12:06:57 ivan Exp $ =head1 BUGS -- cgit v1.1 From e9eba9d8d429675865a49af7008f3bdcca5ccb92 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 11 Sep 2001 13:10:22 +0000 Subject: transactional job-queued icradius/freeradius export --- FS/FS/svc_acct.pm | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 3 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index d7dbcfa..74a5f31 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -6,6 +6,7 @@ use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin $username_noperiod $shellmachine $useradd $usermod $userdel $mydomain $cyrus_server $cyrus_admin_user $cyrus_admin_pass + $icradius_dbh @saltset @pw_set); use Carp; use FS::Conf; @@ -65,6 +66,12 @@ $FS::UID::callback{'FS::svc_acct'} = sub { $cyrus_admin_user = ''; $cyrus_admin_pass = ''; } + if ( $conf->exists('icradius_secrets') ) { + $icradius_dbh = DBI->connect($conf->config('icradius_secrets')) + or die $DBI::errstr; + } else { + $icradius_dbh = ''; + } }; @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' ); @@ -247,6 +254,17 @@ sub insert { return "queueing job (transaction rolled back): $error"; } } + if ( $icradius_dbh ) { + my $queue = new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_insert' }; + $error = $queue->insert( $self->username, + $self->_password, + $self->radius_check + ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } + } $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; #no error @@ -275,13 +293,43 @@ sub cyrus_insert { warn "cyrus_insert: setacl user.$username, $username => all\n"; $rc = $client->setacl("user.$username", $username => 'all' ); $error = $client->error; - die $error if $error; + die "cyrus_insert: error setacl user.$username: $error" if $error; if ( $quota ) { warn "cyrus_insert: setquota user.$username, STORAGE => $quota\n"; $rc = $client->setquota("user.$username", 'STORAGE' => $quota ); $error = $client->error; - die $error if $error; + die "cyrus_insert: error setquota user.$username: $error" if $error; + } + + 1; +} + +sub icradius_rc_insert { + my( $username, $password, %radcheck ) = @_; + + my $sth = $icradius_dbh->prepare( + "INSERT INTO radcheck ( id, UserName, Attribute, Value ) VALUES ( ". + join(", ", map { $icradius_dbh->quote($_) } ( + '', + $username, + "Password", + $password, + ) ). " )" + ); + $sth->execute or die "can't insert into radcheck table: ". $sth->errstr; + + foreach my $attribute ( keys %radcheck ) { + my $sth = $icradius_dbh->prepare( + "INSERT INTO radcheck ( id, UserName, Attribute, Value ) VALUES ( ". + join(", ", map { $icradius_dbh->quote($_) } ( + '', + $username, + $attribute, + $radcheck{$attribute}, + ) ). " )" + ); + $sth->execute or die "can't insert into radcheck table: ". $sth->errstr; } 1; @@ -398,6 +446,14 @@ sub delete { return "queueing job (transaction rolled back): $error"; } } + if ( $icradius_dbh ) { + my $queue = new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_delete' }; + $error = $queue->insert( $self->username ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } + } $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; @@ -424,6 +480,18 @@ sub cyrus_delete { 1; } +sub icradius_rc_delete { + my $username = shift; + + my $sth = $icradius_dbh->prepare( + 'DELETE FROM radcheck WHERE UserName = ?' + ); + $sth->execute($username) + or die "can't delete from radcheck table: ". $sth->errstr; + + 1; +} + =item replace OLD_RECORD Replaces OLD_RECORD with this one in the database. If there is an error, @@ -771,7 +839,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.37 2001-09-11 12:06:57 ivan Exp $ +$Id: svc_acct.pm,v 1.38 2001-09-11 13:10:22 ivan Exp $ =head1 BUGS -- cgit v1.1 From 5477d23b51bd3135893c4d79091a9e272a17f4f8 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 14 Sep 2001 19:54:22 +0000 Subject: fix for no svc_acct_sm!!! --- FS/FS/svc_acct.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 74a5f31..e52cebf 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -367,8 +367,10 @@ $username and $dir. sub delete { my $self = shift; - return "Can't delete an account which has (svc_acct_sm) mail aliases!" - if $self->uid && qsearch( 'svc_acct_sm', { 'domuid' => $self->uid } ); + if ( defined( $FS::Record::dbdef->table('svc_acct_sm') ) ) { + 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 } ); @@ -839,7 +841,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.38 2001-09-11 13:10:22 ivan Exp $ +$Id: svc_acct.pm,v 1.39 2001-09-14 19:54:22 ivan Exp $ =head1 BUGS -- cgit v1.1 From 87661d51ce44b78c5b156f4ee7c52e75a9d38746 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 16 Sep 2001 12:45:35 +0000 Subject: fix oops in FS::cust_main_invoice::replace preventing package cancellation add toggle switch to cust_main searching to show/hide cancelled customers. hidecancelledcustomers config file is just which state it starts in. add signupurl config file to enable showing of the customer's signup URL on the view page. --- FS/FS/svc_acct.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index e52cebf..c6b6593 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -397,6 +397,9 @@ sub delete { foreach my $cust_main_invoice ( qsearch( 'cust_main_invoice', { 'dest' => $self->svcnum } ) ) { + #next unless defined; #wtf is up with qsearch? + warn $cust_main_invoice; + next unless defined $cust_main_invoice; my %hash = $cust_main_invoice->hash; $hash{'dest'} = $self->email; my $new = new FS::cust_main_invoice \%hash; @@ -841,7 +844,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.39 2001-09-14 19:54:22 ivan Exp $ +$Id: svc_acct.pm,v 1.40 2001-09-16 12:45:35 ivan Exp $ =head1 BUGS -- cgit v1.1 From a08088c61827caac7d518ffa771494f4eceb11a9 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 19 Sep 2001 00:24:27 +0000 Subject: icradius transactional password changes (suspensions, unsuspensions) --- FS/FS/svc_acct.pm | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index c6b6593..fb773c0 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -572,10 +572,33 @@ sub replace { } } + if ( $icradius_dbh ) { + my $queue = new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_replace' }; + $error = $queue->insert( $new->username, + $new->_password, + ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } + } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; #no error } +sub icradius_rc_replace { + my( $username, $new_password ) = @_; + + my $sth = $icradius_dbh->prepare( + "UPDATE radcheck SET Value = ? WHERE UserName = ? and Attribute = ?" + ); + $sth->execute($new_password, $username, 'Password' ) + or die "can't update radcheck table: ". $sth->errstr; + + 1; +} + =item suspend Suspends this account by prefixing *SUSPENDED* to the password. If there is an @@ -844,7 +867,7 @@ sub email { =head1 VERSION -$Id: svc_acct.pm,v 1.40 2001-09-16 12:45:35 ivan Exp $ +$Id: svc_acct.pm,v 1.41 2001-09-19 00:24:27 ivan Exp $ =head1 BUGS -- cgit v1.1 From cc1d28920f8df9cc31bb7d788f828e8597f465b6 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 19 Sep 2001 19:19:00 +0000 Subject: FS::svc_acct::ssh --- FS/FS/svc_acct.pm | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index fb773c0..194c8b7 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -238,7 +238,7 @@ sub insert { $self->shell, ); if ( $username && $uid && $dir && $shellmachine && ! $nossh_hack ) { - my $queue = new FS::queue { 'job' => 'Net::SSH::ssh' }; + my $queue = new FS::queue { 'job' => 'FS::svc_acct::ssh' }; $error = $queue->insert("root\@$shellmachine", eval qq("$useradd") ); if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -434,7 +434,7 @@ sub delete { $self->dir, ); if ( $username && $shellmachine && ! $nossh_hack ) { - my $queue = new FS::queue { 'job' => 'Net::SSH::ssh' }; + my $queue = new FS::queue { 'job' => 'FS::svc_acct::ssh' }; $error = $queue->insert("root\@$shellmachine", eval qq("$userdel") ); if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -564,7 +564,7 @@ sub replace { $new->getfield('gid'), ); if ( $old_dir && $new_dir && $old_dir ne $new_dir && ! $nossh_hack ) { - my $queue = new FS::queue { 'job' => 'Net::SSH::ssh' }; + my $queue = new FS::queue { 'job' => 'FS::svc_acct::ssh' }; $error = $queue->insert("root\@$shellmachine", eval qq("$usermod") ); if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -863,11 +863,20 @@ sub email { $self->username. '@'. $self->domain; } +=item ssh + +=cut + +sub ssh { + my @args = @_; + ssh(@args,">>/usr/local/etc/freeside/sshoutput 2>&1"); +} + =back =head1 VERSION -$Id: svc_acct.pm,v 1.41 2001-09-19 00:24:27 ivan Exp $ +$Id: svc_acct.pm,v 1.42 2001-09-19 19:19:00 ivan Exp $ =head1 BUGS -- cgit v1.1 From bde088d345e93b12c88072c4a3fb5f021ffc9157 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 19 Sep 2001 19:28:17 +0000 Subject: ;args --- FS/FS/svc_acct.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 194c8b7..4b902ff 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -12,7 +12,7 @@ use Carp; use FS::Conf; use FS::Record qw( qsearch qsearchs fields dbh ); use FS::svc_Common; -use Net::SSH qw(ssh); +use Net::SSH; use FS::part_svc; use FS::svc_acct_pop; use FS::svc_acct_sm; @@ -869,14 +869,14 @@ sub email { sub ssh { my @args = @_; - ssh(@args,">>/usr/local/etc/freeside/sshoutput 2>&1"); + &Net::SSH::ssh(@args,">>/usr/local/etc/freeside/sshoutput 2>&1"); } =back =head1 VERSION -$Id: svc_acct.pm,v 1.42 2001-09-19 19:19:00 ivan Exp $ +$Id: svc_acct.pm,v 1.43 2001-09-19 19:28:17 ivan Exp $ =head1 BUGS -- cgit v1.1 From 14f855379a4022a283e21f3d6b52ebd4ac0b1a22 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 19 Sep 2001 19:39:24 +0000 Subject: hopefully report some sort of ssh error --- FS/FS/svc_acct.pm | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 4b902ff..8e3c729 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -868,15 +868,33 @@ sub email { =cut sub ssh { - my @args = @_; - &Net::SSH::ssh(@args,">>/usr/local/etc/freeside/sshoutput 2>&1"); + my ( $host, @cmd_and_args ) = @_; + + use IO::File; + my $reader = IO::File->new(); + my $writer = IO::File->new(); + my $error = IO::file->new(); + + &Net::SSH::sshopen3( $host, $reader, $writer, $error, @cmd_and_args) or die $!; + + local $/ = undef; + my $output_stream = <$writer>; + my $error_stream = <$error>; + if ( length $error_stream ) { + warn "[FS::svc_acct::ssh] STDERR $error_stream"; + } + if ( length $output_stream ) { + warn "[FS::svc_acct::ssh] STDOUT $output_stream"; + } + +# &Net::SSH::ssh(@args,">>/usr/local/etc/freeside/sshoutput 2>&1"); } =back =head1 VERSION -$Id: svc_acct.pm,v 1.43 2001-09-19 19:28:17 ivan Exp $ +$Id: svc_acct.pm,v 1.44 2001-09-19 19:39:24 ivan Exp $ =head1 BUGS -- cgit v1.1 From 091f86cf5f5da77e72ce5512c7ef61594c964929 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 19 Sep 2001 19:41:28 +0000 Subject: tyop --- FS/FS/svc_acct.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 8e3c729..a9c93af 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -873,7 +873,7 @@ sub ssh { use IO::File; my $reader = IO::File->new(); my $writer = IO::File->new(); - my $error = IO::file->new(); + my $error = IO::File->new(); &Net::SSH::sshopen3( $host, $reader, $writer, $error, @cmd_and_args) or die $!; @@ -894,7 +894,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.44 2001-09-19 19:39:24 ivan Exp $ +$Id: svc_acct.pm,v 1.45 2001-09-19 19:41:28 ivan Exp $ =head1 BUGS -- cgit v1.1 From 310a027b9b72cf7d98c7f3e05b3bd1164077f2ab Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 19 Sep 2001 21:06:17 +0000 Subject: directory hashing remove jeff's lib patch from freeside-apply-credits add freeside-apply-credits to MANIFEST README for pre3-4 --- FS/FS/svc_acct.pm | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index a9c93af..46208aa 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -6,6 +6,7 @@ use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin $username_noperiod $shellmachine $useradd $usermod $userdel $mydomain $cyrus_server $cyrus_admin_user $cyrus_admin_pass + $dirhash $icradius_dbh @saltset @pw_set); use Carp; @@ -72,6 +73,7 @@ $FS::UID::callback{'FS::svc_acct'} = sub { } else { $icradius_dbh = ''; } + $dirhash = $conf->config('dirhash') || 0; }; @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' ); @@ -708,10 +710,21 @@ sub check { $recref->{dir} =~ /^([\/\w\-]*)$/ or return "Illegal directory"; - $recref->{dir} = $1 || - $dir_prefix . '/' . $recref->{username} - #$dir_prefix . '/' . substr($recref->{username},0,1). '/' . $recref->{username} + $recref->{dir} = $1; + unless ( $recref->{dir} ) { + $recref->{dir} = $dir_prefix . '/'; + if ( $dirhash > 0 ) { + for my $h ( 1 .. $dirhash ) { + $recref->{dir} .= substr($recref->{username}, $h-1, 1). '/'; + } + } elsif ( $dirhash < 0 ) { + for my $h ( reverse $dirhash .. -1 ) { + $recref->{dir} .= substr($recref->{username}, $h, 1). '/'; + } + } + $recref->{dir} .= $recref->{username}; ; + } unless ( $recref->{username} eq 'sync' ) { if ( grep $_ eq $recref->{shell}, @shells ) { @@ -881,7 +894,8 @@ sub ssh { my $output_stream = <$writer>; my $error_stream = <$error>; if ( length $error_stream ) { - warn "[FS::svc_acct::ssh] STDERR $error_stream"; + #warn "[FS::svc_acct::ssh] STDERR $error_stream"; + die "[FS::svc_acct::ssh] STDERR $error_stream"; } if ( length $output_stream ) { warn "[FS::svc_acct::ssh] STDOUT $output_stream"; @@ -894,7 +908,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.45 2001-09-19 19:41:28 ivan Exp $ +$Id: svc_acct.pm,v 1.46 2001-09-19 21:06:17 ivan Exp $ =head1 BUGS -- cgit v1.1 From d390ca47b755c896af0644ae83ec583973c319b6 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 30 Sep 2001 20:30:09 +0000 Subject: username-uppercase config file --- FS/FS/svc_acct.pm | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 46208aa..3530001 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -3,7 +3,7 @@ package FS::svc_acct; use strict; use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin $usernamemax $passwordmin $username_letter $username_letterfirst - $username_noperiod + $username_noperiod $username_uppercase $shellmachine $useradd $usermod $userdel $mydomain $cyrus_server $cyrus_admin_user $cyrus_admin_pass $dirhash @@ -57,6 +57,7 @@ $FS::UID::callback{'FS::svc_acct'} = sub { $username_letter = $conf->exists('username-letter'); $username_letterfirst = $conf->exists('username-letterfirst'); $username_noperiod = $conf->exists('username-noperiod'); + $username_uppercase = $conf->exists('username-uppercase'); $mydomain = $conf->config('domain'); if ( $conf->exists('cyrus') ) { ($cyrus_server, $cyrus_admin_user, $cyrus_admin_pass) = @@ -674,9 +675,15 @@ sub check { return $error if $error; my $ulen = $usernamemax || $self->dbdef_table->column('username')->length; - $recref->{username} =~ /^([a-z0-9_\-\.]{$usernamemin,$ulen})$/ - or return "Illegal username"; + if ( $username_uppercase ) { + $recref->{username} =~ /^([a-z0-9_\-\.]{$usernamemin,$ulen})$/i + or return "Illegal username"; + } else { + $recref->{username} =~ /^([a-z0-9_\-\.]{$usernamemin,$ulen})$/ + or return "Illegal username"; + } $recref->{username} = $1; + if ( $username_letterfirst ) { $recref->{username} =~ /^[a-z]/ or return "Illegal username"; } elsif ( $username_letter ) { @@ -705,8 +712,12 @@ sub check { return "Only root can have uid 0" if $recref->{uid} == 0 && $recref->{username} ne 'root'; - $error = $self->ut_textn('finger'); - return $error if $error; +# $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); $recref->{dir} =~ /^([\/\w\-]*)$/ or return "Illegal directory"; @@ -908,7 +919,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.46 2001-09-19 21:06:17 ivan Exp $ +$Id: svc_acct.pm,v 1.47 2001-09-30 20:30:09 ivan Exp $ =head1 BUGS -- cgit v1.1 From 4ff1dd39976ab5c7550081743ca89a741100cfa3 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 30 Sep 2001 22:19:34 +0000 Subject: $1 doesn't seem to last very long... --- FS/FS/svc_acct.pm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 3530001..e46b4e5 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -676,13 +676,14 @@ sub check { my $ulen = $usernamemax || $self->dbdef_table->column('username')->length; if ( $username_uppercase ) { - $recref->{username} =~ /^([a-z0-9_\-\.]{$usernamemin,$ulen})$/i - or return "Illegal username"; + $recref->{username} =~ /^([a-z0-9_\-\.]{$usernamemin,$ulen})$/ + or return "Illegal username: ". $recref->{username}; + $recref->{username} = $1; } else { $recref->{username} =~ /^([a-z0-9_\-\.]{$usernamemin,$ulen})$/ - or return "Illegal username"; + or return "Illegal username: ". $recref->{username}; + $recref->{username} = $1; } - $recref->{username} = $1; if ( $username_letterfirst ) { $recref->{username} =~ /^[a-z]/ or return "Illegal username"; @@ -919,7 +920,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.47 2001-09-30 20:30:09 ivan Exp $ +$Id: svc_acct.pm,v 1.48 2001-09-30 22:19:34 ivan Exp $ =head1 BUGS -- cgit v1.1 From f832b7bf60eed131141facd8207a1c44a134d3ca Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 30 Sep 2001 22:35:34 +0000 Subject: arg --- FS/FS/svc_acct.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index e46b4e5..2390de0 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -676,7 +676,7 @@ sub check { my $ulen = $usernamemax || $self->dbdef_table->column('username')->length; if ( $username_uppercase ) { - $recref->{username} =~ /^([a-z0-9_\-\.]{$usernamemin,$ulen})$/ + $recref->{username} =~ /^([a-z0-9_\-\.]{$usernamemin,$ulen})$/i or return "Illegal username: ". $recref->{username}; $recref->{username} = $1; } else { @@ -920,7 +920,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.48 2001-09-30 22:19:34 ivan Exp $ +$Id: svc_acct.pm,v 1.49 2001-09-30 22:35:34 ivan Exp $ =head1 BUGS -- cgit v1.1 From fce8244a87d152312852eef77411c644f992314d Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 2 Oct 2001 11:10:19 +0000 Subject: allow some more characters in GECOS... showing up in fix.net's password files --- FS/FS/svc_acct.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 2390de0..71c47d6 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -716,7 +716,7 @@ sub check { # $error = $self->ut_textn('finger'); # return $error if $error; $self->getfield('finger') =~ - /^([\w \t\!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\*]*)$/ + /^([\w \t\!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\*\<\>]*)$/ or return "Illegal finger: ". $self->getfield('finger'); $self->setfield('finger', $1); @@ -920,7 +920,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.49 2001-09-30 22:35:34 ivan Exp $ +$Id: svc_acct.pm,v 1.50 2001-10-02 11:10:19 ivan Exp $ =head1 BUGS -- cgit v1.1 From b7cdcea59f34c12f7d181c41014e0d2559bf983c Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 22 Oct 2001 14:48:28 +0000 Subject: fix dir check --- FS/FS/svc_acct.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 71c47d6..8e29cb7 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -720,9 +720,10 @@ sub check { or return "Illegal finger: ". $self->getfield('finger'); $self->setfield('finger', $1); - $recref->{dir} =~ /^([\/\w\-]*)$/ + $recref->{dir} =~ /^([\/\w\-\.]*)$/ or return "Illegal directory"; $recref->{dir} = $1; + return "Illegal directory" if $recref->{dir} =~ /\.\./; #no .. unless ( $recref->{dir} ) { $recref->{dir} = $dir_prefix . '/'; if ( $dirhash > 0 ) { @@ -920,7 +921,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.50 2001-10-02 11:10:19 ivan Exp $ +$Id: svc_acct.pm,v 1.51 2001-10-22 14:48:28 ivan Exp $ =head1 BUGS -- cgit v1.1 From e6b57805f6b3e76448ab9b6d280f2c53bc1410f3 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 24 Oct 2001 15:29:31 +0000 Subject: preliminary web config editor new config files: username-ampersand, passwordmax fs-setup updates get rid of old and crufty and unused registries/ config foo documentation updates --- FS/FS/svc_acct.pm | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 8e29cb7..3e7230f 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -2,7 +2,8 @@ package FS::svc_acct; use strict; use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin - $usernamemax $passwordmin $username_letter $username_letterfirst + $usernamemax $passwordmin $passwordmax + $username_ampersand $username_letter $username_letterfirst $username_noperiod $username_uppercase $shellmachine $useradd $usermod $userdel $mydomain $cyrus_server $cyrus_admin_user $cyrus_admin_pass @@ -33,6 +34,7 @@ $FS::UID::callback{'FS::svc_acct'} = sub { $usernamemin = $conf->config('usernamemin') || 2; $usernamemax = $conf->config('usernamemax'); $passwordmin = $conf->config('passwordmin') || 6; + $passwordmax = $conf->config('passwordmax') || 8; if ( $shellmachine ) { if ( $conf->exists('shellmachine-useradd') ) { $useradd = join("\n", $conf->config('shellmachine-useradd') ) @@ -58,6 +60,7 @@ $FS::UID::callback{'FS::svc_acct'} = sub { $username_letterfirst = $conf->exists('username-letterfirst'); $username_noperiod = $conf->exists('username-noperiod'); $username_uppercase = $conf->exists('username-uppercase'); + $username_ampersand = $conf->exists('username-ampersand'); $mydomain = $conf->config('domain'); if ( $conf->exists('cyrus') ) { ($cyrus_server, $cyrus_admin_user, $cyrus_admin_pass) = @@ -676,11 +679,11 @@ sub check { my $ulen = $usernamemax || $self->dbdef_table->column('username')->length; if ( $username_uppercase ) { - $recref->{username} =~ /^([a-z0-9_\-\.]{$usernamemin,$ulen})$/i + $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/i or return "Illegal username: ". $recref->{username}; $recref->{username} = $1; } else { - $recref->{username} =~ /^([a-z0-9_\-\.]{$usernamemin,$ulen})$/ + $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/ or return "Illegal username: ". $recref->{username}; $recref->{username} = $1; } @@ -693,6 +696,9 @@ sub check { if ( $username_noperiod ) { $recref->{username} =~ /\./ and return "Illegal username"; } + unless ( $username_ampersand ) { + $recref->{username} =~ /\&/ and return "Illegal username"; + } $recref->{popnum} =~ /^(\d*)$/ or return "Illegal popnum: ".$recref->{popnum}; $recref->{popnum} = $1; @@ -720,10 +726,13 @@ sub check { or return "Illegal finger: ". $self->getfield('finger'); $self->setfield('finger', $1); - $recref->{dir} =~ /^([\/\w\-\.]*)$/ + $recref->{dir} =~ /^([\/\w\-\.\&]*)$/ or return "Illegal directory"; $recref->{dir} = $1; - return "Illegal directory" if $recref->{dir} =~ /\.\./; #no .. + return "Illegal directory" + if $recref->{dir} =~ /(^|\/)\.+(\/|$)/; #no .. component + return "Illegal directory" + if $recref->{dir} =~ /\&/ && ! $username_ampersand; unless ( $recref->{dir} ) { $recref->{dir} = $dir_prefix . '/'; if ( $dirhash > 0 ) { @@ -787,7 +796,7 @@ sub check { unless ( $recref->{_password} ); #if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{4,16})$/ ) { - if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{$passwordmin,8})$/ ) { + if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{$passwordmin,$passwordmax})$/ ) { $recref->{_password} = $1.$3; #uncomment this to encrypt password immediately upon entry, or run #bin/crypt_pw in cron to give new users a window during which their @@ -803,7 +812,8 @@ sub check { } elsif ( $recref->{_password} eq '!!' ) { $recref->{_password} = '!!'; } else { - return "Illegal password"; + #return "Illegal password"; + return "Illegal password: ". $recref->{_password}; } ''; #no error @@ -921,7 +931,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.51 2001-10-22 14:48:28 ivan Exp $ +$Id: svc_acct.pm,v 1.52 2001-10-24 15:29:30 ivan Exp $ =head1 BUGS -- cgit v1.1 From fd72d2af8120195f96826eb044e217dbfcaee1c7 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 3 Nov 2001 17:49:52 +0000 Subject: new 'jsearch' call for big joined searches & caching support preliminary customer browse optimizations, much faster! --- FS/FS/svc_acct.pm | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 3e7230f..219d8d4 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -85,6 +85,18 @@ $FS::UID::callback{'FS::svc_acct'} = sub { #not needed in 5.004 #srand($$|time); +sub _cache { + my $self = shift; + my ( $hashref, $cache ) = @_; + if ( $hashref->{'svc_acct_svcnum'} ) { + $self->{'_domsvc'} = FS::svc_domain->new( { + 'svcnum' => $hashref->{'domsvc'}, + 'domain' => $hashref->{'svc_acct_domain'}, + 'catchall' => $hashref->{'svc_acct_catchall'}, + } ); + } +} + =head1 NAME FS::svc_acct - Object methods for svc_acct records @@ -880,7 +892,8 @@ Returns the domain associated with this account. sub domain { my $self = shift; if ( $self->domsvc ) { - my $svc_domain = qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } ) + #$self->svc_domain->domain; + my $svc_domain = $self->svc_domain or die "no svc_domain.svcnum for svc_acct.domsvc ". $self->domsvc; $svc_domain->domain; } else { @@ -888,6 +901,20 @@ sub domain { } } +=item svc_domain + +Returns the FS::svc_domain record for this account's domain (see +L{'_domsvc'} + ? $self->{'_domsvc'} + : qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } ); +} + =item email Returns an email address associated with the account. @@ -931,7 +958,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.52 2001-10-24 15:29:30 ivan Exp $ +$Id: svc_acct.pm,v 1.53 2001-11-03 17:49:52 ivan Exp $ =head1 BUGS -- cgit v1.1 From b8e6793aff1a70bb437361af00a0b69026e56543 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 5 Nov 2001 13:57:31 +0000 Subject: doc tyop --- FS/FS/svc_acct.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 219d8d4..e049af0 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -904,7 +904,7 @@ sub domain { =item svc_domain Returns the FS::svc_domain record for this account's domain (see -L. =cut @@ -958,7 +958,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.53 2001-11-03 17:49:52 ivan Exp $ +$Id: svc_acct.pm,v 1.54 2001-11-05 13:57:31 ivan Exp $ =head1 BUGS -- cgit v1.1 From 92eaaea542d3dfdcc1e258b50785f79d8e6aad8c Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 5 Nov 2001 17:00:41 +0000 Subject: improved svc_acct replacement --- FS/FS/svc_acct.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index e049af0..8f9216f 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -548,7 +548,9 @@ sub replace { return "Username in use" if $old->username ne $new->username && - qsearchs( 'svc_acct', { 'username' => $new->username } ); + qsearchs( 'svc_acct', { 'username' => $new->username, + 'domsvc' => $new->domsvc, + } ); return "Can't change uid!" if $old->uid != $new->uid; @@ -958,7 +960,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.54 2001-11-05 13:57:31 ivan Exp $ +$Id: svc_acct.pm,v 1.55 2001-11-05 17:00:41 jeff Exp $ =head1 BUGS -- cgit v1.1 From c52f29f23bed4af764c0a3deda0f43e2d40c8e51 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 18 Dec 2001 01:49:35 +0000 Subject: add freeside-setinvoice to MANIFEST fix warning: FS::cust_main_invoice=HASH(0x90c86c4) at /usr/local/lib/perl5/site_perl/5.005/FS/svc_acct.pm line 419. --- FS/FS/svc_acct.pm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 8f9216f..382987e 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -415,9 +415,10 @@ sub delete { foreach my $cust_main_invoice ( qsearch( 'cust_main_invoice', { 'dest' => $self->svcnum } ) ) { - #next unless defined; #wtf is up with qsearch? - warn $cust_main_invoice; - next unless defined $cust_main_invoice; + unless ( defined($cust_main_invoice) ) { + warn "WARNING: something's wrong with qsearch"; + next; + } my %hash = $cust_main_invoice->hash; $hash{'dest'} = $self->email; my $new = new FS::cust_main_invoice \%hash; @@ -960,7 +961,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.55 2001-11-05 17:00:41 jeff Exp $ +$Id: svc_acct.pm,v 1.56 2001-12-18 01:49:35 ivan Exp $ =head1 BUGS -- cgit v1.1 From 4a7a96cd297d390d7d58aafed554672ab949143e Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 19 Dec 2001 14:30:12 +0000 Subject: surpress warnings --- FS/FS/svc_acct.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 382987e..11f09a1 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -552,8 +552,10 @@ sub replace { qsearchs( 'svc_acct', { 'username' => $new->username, 'domsvc' => $new->domsvc, } ); - - return "Can't change uid!" if $old->uid != $new->uid; + { + no warnings 'numeric'; + return "Can't change uid!" if $old->uid != $new->uid; + } return "can't change username using Cyrus" if $cyrus_server && $old->username ne $new->username; @@ -961,7 +963,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.56 2001-12-18 01:49:35 ivan Exp $ +$Id: svc_acct.pm,v 1.57 2001-12-19 14:30:12 ivan Exp $ =head1 BUGS -- cgit v1.1 From b1c7bf3ab64205054c5b677fa55d21049e7a4d26 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 19 Dec 2001 14:33:48 +0000 Subject: alas, a 5.6-ism --- FS/FS/svc_acct.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 11f09a1..139303b 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -552,10 +552,10 @@ sub replace { qsearchs( 'svc_acct', { 'username' => $new->username, 'domsvc' => $new->domsvc, } ); - { - no warnings 'numeric'; +# { +# no warnings 'numeric'; #alas, a 5.006-ism return "Can't change uid!" if $old->uid != $new->uid; - } +# } return "can't change username using Cyrus" if $cyrus_server && $old->username ne $new->username; @@ -963,7 +963,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.57 2001-12-19 14:30:12 ivan Exp $ +$Id: svc_acct.pm,v 1.58 2001-12-19 14:33:48 ivan Exp $ =head1 BUGS -- cgit v1.1 From 80fad8cc255a422c562e0b4f040bfce91f074adc Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 20 Dec 2001 02:07:04 +0000 Subject: quiet warnings --- FS/FS/svc_acct.pm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 139303b..ba8f32f 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -552,10 +552,11 @@ sub replace { qsearchs( 'svc_acct', { 'username' => $new->username, 'domsvc' => $new->domsvc, } ); -# { -# no warnings 'numeric'; #alas, a 5.006-ism + { + #no warnings 'numeric'; #alas, a 5.006-ism + local($^W) = 0; return "Can't change uid!" if $old->uid != $new->uid; -# } + } return "can't change username using Cyrus" if $cyrus_server && $old->username ne $new->username; @@ -963,7 +964,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.58 2001-12-19 14:33:48 ivan Exp $ +$Id: svc_acct.pm,v 1.59 2001-12-20 02:07:04 ivan Exp $ =head1 BUGS -- cgit v1.1 From 363349b93ce19e66749126bd14eed75710e57479 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 20 Dec 2001 02:09:52 +0000 Subject: don't error trying to suspend accounts with '*' password --- FS/FS/svc_acct.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index ba8f32f..49a55e9 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -635,7 +635,9 @@ Called by the suspend method of FS::cust_pkg (see L). sub suspend { my $self = shift; my %hash = $self->hash; - unless ( $hash{_password} =~ /^\*SUSPENDED\* / ) { + unless ( $hash{_password} =~ /^\*SUSPENDED\* / + || $hash{_password} eq '*' + ) { $hash{_password} = '*SUSPENDED* '.$hash{_password}; my $new = new FS::svc_acct ( \%hash ); $new->replace($self); @@ -964,7 +966,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.59 2001-12-20 02:07:04 ivan Exp $ +$Id: svc_acct.pm,v 1.60 2001-12-20 02:09:52 ivan Exp $ =head1 BUGS -- cgit v1.1 From be58a1538ce963c4d3b6319c163960513703108d Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 14 Jan 2002 20:28:17 +0000 Subject: pay some attention to 1.4 RADIUS SQL export --- FS/FS/svc_acct.pm | 95 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 15 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 49a55e9..28c0f57 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -71,9 +71,15 @@ $FS::UID::callback{'FS::svc_acct'} = sub { $cyrus_admin_user = ''; $cyrus_admin_pass = ''; } - if ( $conf->exists('icradius_secrets') ) { - $icradius_dbh = DBI->connect($conf->config('icradius_secrets')) - or die $DBI::errstr; + if ( $conf->exists('icradiusmachines') ) { + if ( $conf->exists('icradius_secrets') ) { + #need some sort of late binding so it's only connected to when + # actually used, hmm + $icradius_dbh = DBI->connect($conf->config('icradius_secrets')) + or die $DBI::errstr; + } else { + $icradius_dbh = dbh; + } } else { $icradius_dbh = ''; } @@ -273,15 +279,29 @@ sub insert { } } if ( $icradius_dbh ) { - my $queue = new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_insert' }; - $error = $queue->insert( $self->username, - $self->_password, - $self->radius_check - ); + + my $radcheck_queue = + new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_insert' }; + $error = $radcheck_queue->insert( $self->username, + $self->_password, + $self->radius_check + ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } + + my $radreply_queue = + new FS::queue { 'job' => 'FS::svc_acct::icradius_rr_insert' }; + $error = $radreply_queue->insert( $self->username, + $self->_password, + $self->radius_reply + ); if ( $error ) { $dbh->rollback if $oldAutoCommit; return "queueing job (transaction rolled back): $error"; } + } $dbh->commit or die $dbh->errstr if $oldAutoCommit; @@ -353,6 +373,25 @@ sub icradius_rc_insert { 1; } +sub icradius_rr_insert { + my( $username, $password, %radreply ) = @_; + + foreach my $attribute ( keys %radreply ) { + my $sth = $icradius_dbh->prepare( + "INSERT INTO radreply ( id, UserName, Attribute, Value ) VALUES ( ". + join(", ", map { $icradius_dbh->quote($_) } ( + '', + $username, + $attribute, + $radreply{$attribute}, + ) ). " )" + ); + $sth->execute or die "can't insert into radreply table: ". $sth->errstr; + } + + 1; +} + =item delete Deletes this account from the database. If there is an error, returns the @@ -471,12 +510,21 @@ sub delete { } } if ( $icradius_dbh ) { + my $queue = new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_delete' }; $error = $queue->insert( $self->username ); if ( $error ) { $dbh->rollback if $oldAutoCommit; return "queueing job (transaction rolled back): $error"; } + + my $queue = new FS::queue { 'job' => 'FS::svc_acct::icradius_rr_delete' }; + $error = $queue->insert( $self->username ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } + } $dbh->commit or die $dbh->errstr if $oldAutoCommit; @@ -516,6 +564,18 @@ sub icradius_rc_delete { 1; } +sub icradius_rr_delete { + my $username = shift; + + my $sth = $icradius_dbh->prepare( + 'DELETE FROM radreply WHERE UserName = ?' + ); + $sth->execute($username) + or die "can't delete from radreply table: ". $sth->errstr; + + 1; +} + =item replace OLD_RECORD Replaces OLD_RECORD with this one in the database. If there is an error, @@ -863,12 +923,17 @@ expected to change in the future. sub radius_reply { my $self = shift; - map { - /^(radius_(.*))$/; - my($column, $attrib) = ($1, $2); - #$attrib =~ s/_/\-/g; - ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) ); - } grep { /^radius_/ && $self->getfield($_) } fields( $self->table ); + my %reply = + map { + /^(radius_(.*))$/; + my($column, $attrib) = ($1, $2); + #$attrib =~ s/_/\-/g; + ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) ); + } grep { /^radius_/ && $self->getfield($_) } fields( $self->table ); + if ( $self->ip && $self->ip ne '0e0' ) { + $reply{Framed-IP-Address} = $self->ip; + } + %reply; } =item radius_check @@ -966,7 +1031,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.60 2001-12-20 02:09:52 ivan Exp $ +$Id: svc_acct.pm,v 1.61 2002-01-14 20:28:17 ivan Exp $ =head1 BUGS -- cgit v1.1 From 52c1b2edef2c53822d8e67952710ba45dae1d293 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 16 Jan 2002 15:37:42 +0000 Subject: doc --- FS/FS/svc_acct.pm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 28c0f57..3f97189 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -1031,7 +1031,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.61 2002-01-14 20:28:17 ivan Exp $ +$Id: svc_acct.pm,v 1.62 2002-01-16 15:37:42 ivan Exp $ =head1 BUGS @@ -1046,9 +1046,10 @@ counterintuitive. =head1 SEE ALSO -L, L, L, L, -L, L, L, L), -L, L, L, +L, edit/part_svc.cgi from an installed web interface, +export.html from the base documentation, L, L, +L, L, L, L, +L), L, L, L, schema.html from the base documentation. =cut -- cgit v1.1 From 3a625afa978c85a769c2a40b1bfaeb4aa9d1bc45 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 22 Jan 2002 14:53:26 +0000 Subject: silly compilation problem --- FS/FS/svc_acct.pm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 3f97189..0340e7c 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -511,15 +511,17 @@ sub delete { } if ( $icradius_dbh ) { - my $queue = new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_delete' }; - $error = $queue->insert( $self->username ); + my $radcheck_queue = + new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_delete' }; + $error = $radcheck_queue->insert( $self->username ); if ( $error ) { $dbh->rollback if $oldAutoCommit; return "queueing job (transaction rolled back): $error"; } - my $queue = new FS::queue { 'job' => 'FS::svc_acct::icradius_rr_delete' }; - $error = $queue->insert( $self->username ); + my $radreply_queue = + new FS::queue { 'job' => 'FS::svc_acct::icradius_rr_delete' }; + $error = $radreply_queue->insert( $self->username ); if ( $error ) { $dbh->rollback if $oldAutoCommit; return "queueing job (transaction rolled back): $error"; @@ -931,7 +933,7 @@ sub radius_reply { ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) ); } grep { /^radius_/ && $self->getfield($_) } fields( $self->table ); if ( $self->ip && $self->ip ne '0e0' ) { - $reply{Framed-IP-Address} = $self->ip; + $reply{'Framed-IP-Address'} = $self->ip; } %reply; } @@ -1031,7 +1033,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.62 2002-01-16 15:37:42 ivan Exp $ +$Id: svc_acct.pm,v 1.63 2002-01-22 14:53:26 ivan Exp $ =head1 BUGS -- cgit v1.1 From 6991d4986df7fb3a6c7c49b5ae1b3713e87a16c4 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 29 Jan 2002 16:33:16 +0000 Subject: - web interface for hourly account charges! (FS::cust_pkg, FS::cust_svc and FS::svc_acct seconds_since methods) - Makefile target to regenerate HTML manpages on install - FS.pm doc update - $FS::Record::Debug now dumps all SQL - new FS::cust_main methods: ->cancel, ->invoicing_list_addpost - start of a billing event web interface - cust_pay::upgrade_replace doesn't error out if history includes overapplied payments --- FS/FS/svc_acct.pm | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 0340e7c..16270f9 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -134,6 +134,14 @@ FS::svc_acct - Object methods for svc_acct records %hash = $record->radius_check; + $domain = $record->domain; + + $svc_domain = $record->svc_domain; + + $email = $record->email; + + $seconds_since = $record->seconds_since($timestamp); + =head1 DESCRIPTION An FS::svc_acct object represents an account. FS::svc_acct inherits from @@ -990,6 +998,15 @@ sub svc_domain { : qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } ); } +=item cust_svc + +Returns the FS::cust_svc record for this account (see L). + +sub cust_svc { + my $self = shift; + qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } ); +} + =item email Returns an email address associated with the account. @@ -1001,6 +1018,22 @@ sub email { $self->username. '@'. $self->domain; } +=item seconds_since TIMESTAMP + +Returns the number of seconds this account has been online since TIMESTAMP. +See L + +TIMESTAMP is specified as a UNIX timestamp; see L. Also see +L and L for conversion functions. + +=cut + +#note: POD here, implementation in FS::cust_svc +sub seconds_since { + my $self = shift; + $self->cust_svc->seconds_since(@_); +} + =item ssh =cut @@ -1033,7 +1066,7 @@ sub ssh { =head1 VERSION -$Id: svc_acct.pm,v 1.63 2002-01-22 14:53:26 ivan Exp $ +$Id: svc_acct.pm,v 1.64 2002-01-29 16:33:15 ivan Exp $ =head1 BUGS -- cgit v1.1 From a2c24812441a8f8ae3045a8c0c93c7f009d4f494 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 12 Feb 2002 02:06:39 +0000 Subject: that's not a bug anymore, don't list it in the BUGS section --- FS/FS/svc_acct.pm | 7 ------- 1 file changed, 7 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 16270f9..f3c2d76 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -1064,15 +1064,8 @@ sub ssh { =back -=head1 VERSION - -$Id: svc_acct.pm,v 1.64 2002-01-29 16:33:15 ivan Exp $ - =head1 BUGS -The bits which ssh should fork before doing so (or maybe queue jobs for a -daemon). - The $recref stuff in sub check should be cleaned up. The suspend, unsuspend and cancel methods update the database, but not the -- cgit v1.1 From 0dc8c09556f5e74b5a58931e40c2da06619a6be7 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 15 Feb 2002 19:33:41 +0000 Subject: CP provisioning!! --- FS/FS/svc_acct.pm | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index f3c2d76..65a58fc 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -7,6 +7,7 @@ use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin $username_noperiod $username_uppercase $shellmachine $useradd $usermod $userdel $mydomain $cyrus_server $cyrus_admin_user $cyrus_admin_pass + $cp_server $cp_user $cp_pass $cp_workgroup $dirhash $icradius_dbh @saltset @pw_set); @@ -71,6 +72,16 @@ $FS::UID::callback{'FS::svc_acct'} = sub { $cyrus_admin_user = ''; $cyrus_admin_pass = ''; } + if ( $conf->exists('cp_app') ) { + ($cp_server, $cp_user, $cp_pass, $cp_workgroup) = + $conf->config('cp_app'); + eval "use Net::APP;" + } else { + $cp_server = ''; + $cp_user = ''; + $cp_pass = ''; + $cp_workgroup = ''; + } if ( $conf->exists('icradiusmachines') ) { if ( $conf->exists('icradius_secrets') ) { #need some sort of late binding so it's only connected to when @@ -286,6 +297,16 @@ sub insert { return "queueing job (transaction rolled back): $error"; } } + + if ( $cp_server ) { + my $queue = new FS::queue { 'job' => 'FS::svc_acct::cp_insert' }; + $error = $queue->insert($self->username, $self->_password); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } + } + if ( $icradius_dbh ) { my $radcheck_queue = @@ -351,6 +372,27 @@ sub cyrus_insert { 1; } +sub cp_insert { + my( $username, $password ) = @_; + + my $app = new Net::APP ( $cp_server, + User => $cp_user, + Password => $cp_pass, + Domain => $mydomain, + Timeout => 60, + #Debug => 1, + ) or die $@; + + $app->create_mailbox( + Mailbox => $username, + Password => $password, + Workgroup => $cp_workgroup, + Domain => $mydomain, + ); + + die $app->message unless $app->ok; +} + sub icradius_rc_insert { my( $username, $password, %radcheck ) = @_; @@ -517,6 +559,16 @@ sub delete { return "queueing job (transaction rolled back): $error"; } } + + if ( $cp_server ) { + my $queue = new FS::queue { 'job' => 'FS::svc_acct::cp_delete' }; + $error = $queue->insert($self->username); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } + } + if ( $icradius_dbh ) { my $radcheck_queue = @@ -562,6 +614,24 @@ sub cyrus_delete { 1; } +sub cp_delete { + my( $username ) = @_; + my $app = new Net::APP ( $cp_server, + User => $cp_user, + Password => $cp_pass, + Domain => $mydomain, + Timeout => 60, + #Debug => 1, + ) or die $@; + + $app->delete_mailbox( + Mailbox => $username, + Domain => $mydomain, + ); + + die $app->message unless $app->ok; +} + sub icradius_rc_delete { my $username = shift; @@ -666,6 +736,24 @@ sub replace { } } + if ( $cp_server && $old->username ne $new->username ) { + my $queue = new FS::queue { 'job' => 'FS::svc_acct::cp_rename' }; + $error = $queue->insert( $old->username, $new->username ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } + } + + if ( $cp_server && $old->_password ne $new->_password ) { + my $queue = new FS::queue { 'job' => 'FS::svc_acct::cp_change' }; + $error = $queue->insert( $new->username, $new->_password ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } + } + if ( $icradius_dbh ) { my $queue = new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_replace' }; $error = $queue->insert( $new->username, @@ -693,6 +781,48 @@ sub icradius_rc_replace { 1; } +sub cp_rename { + my ( $old_username, $new_username ); + + my $app = new Net::APP ( $cp_server, + User => $cp_user, + Password => $cp_pass, + Domain => $mydomain, + Timeout => 60, + #Debug => 1, + ) or die $@; + + $app->rename_mailbox( + Domain => $mydomain, + Old_Mailbox => $old_username, + New_Mailbox => $new_username, + ); + + die $app->message unless $app->ok; + +} + +sub cp_change { + my ( $username, $password ); + + my $app = new Net::APP ( $cp_server, + User => $cp_user, + Password => $cp_pass, + Domain => $mydomain, + Timeout => 60, + #Debug => 1, + ) or die $@; + + $app->change_mailbox( + Domain => $mydomain, + Mailbox => $username, + Password => $password, + ); + + die $app->message unless $app->ok; + +} + =item suspend Suspends this account by prefixing *SUSPENDED* to the password. If there is an -- cgit v1.1 From 8f42b751aebda2e7dce2c363bed6f1e15b411b1d Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 20 Feb 2002 01:03:10 +0000 Subject: use Net::SSH::ssh_cmd for all job queueing rather than local duplicated ssh subs queue daemon updates: retry & remove links work, bubble up error message to webinterface, link to svcnum & have job listings on view/svc_* pages, closes: Bug#280 s/option/optionname/ schema change, dumb mysql, closes: Bug#334 --- FS/FS/svc_acct.pm | 75 +++++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 38 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 65a58fc..2f327a3 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -281,7 +281,10 @@ sub insert { $self->shell, ); if ( $username && $uid && $dir && $shellmachine && ! $nossh_hack ) { - my $queue = new FS::queue { 'job' => 'FS::svc_acct::ssh' }; + my $queue = new FS::queue { + 'svcnum' => $self->svcnum, + 'job' => 'Net::SSH::ssh_cmd', + }; $error = $queue->insert("root\@$shellmachine", eval qq("$useradd") ); if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -290,7 +293,10 @@ sub insert { } if ( $cyrus_server ) { - my $queue = new FS::queue { 'job' => 'FS::svc_acct::cyrus_insert' }; + my $queue = new FS::queue { + 'svcnum' => $self->svcnum, + 'job' => 'FS::svc_acct::cyrus_insert', + }; $error = $queue->insert($self->username, $self->quota); if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -299,7 +305,10 @@ sub insert { } if ( $cp_server ) { - my $queue = new FS::queue { 'job' => 'FS::svc_acct::cp_insert' }; + my $queue = new FS::queue { + 'svcnum' => $self->svcnum, + 'job' => 'FS::svc_acct::cp_insert' + }; $error = $queue->insert($self->username, $self->_password); if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -310,7 +319,10 @@ sub insert { if ( $icradius_dbh ) { my $radcheck_queue = - new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_insert' }; + new FS::queue { + 'svcnum' => $self->svcnum, + 'job' => 'FS::svc_acct::icradius_rc_insert' + }; $error = $radcheck_queue->insert( $self->username, $self->_password, $self->radius_check @@ -321,7 +333,10 @@ sub insert { } my $radreply_queue = - new FS::queue { 'job' => 'FS::svc_acct::icradius_rr_insert' }; + new FS::queue { + 'svcnum' => $self->svcnum, + 'job' => 'FS::svc_acct::icradius_rr_insert' + }; $error = $radreply_queue->insert( $self->username, $self->_password, $self->radius_reply @@ -542,7 +557,7 @@ sub delete { $self->dir, ); if ( $username && $shellmachine && ! $nossh_hack ) { - my $queue = new FS::queue { 'job' => 'FS::svc_acct::ssh' }; + my $queue = new FS::queue { 'job' => 'Net::SSH::ssh_cmd' }; $error = $queue->insert("root\@$shellmachine", eval qq("$userdel") ); if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -728,7 +743,10 @@ sub replace { $new->getfield('gid'), ); if ( $old_dir && $new_dir && $old_dir ne $new_dir && ! $nossh_hack ) { - my $queue = new FS::queue { 'job' => 'FS::svc_acct::ssh' }; + my $queue = new FS::queue { + 'svcnum' => $new->svcnum, + 'job' => 'Net::SSH::ssh_cmd' + }; $error = $queue->insert("root\@$shellmachine", eval qq("$usermod") ); if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -737,7 +755,10 @@ sub replace { } if ( $cp_server && $old->username ne $new->username ) { - my $queue = new FS::queue { 'job' => 'FS::svc_acct::cp_rename' }; + my $queue = new FS::queue { + 'svcnum' => $new->svcnum, + 'job' => 'FS::svc_acct::cp_rename' + }; $error = $queue->insert( $old->username, $new->username ); if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -746,7 +767,10 @@ sub replace { } if ( $cp_server && $old->_password ne $new->_password ) { - my $queue = new FS::queue { 'job' => 'FS::svc_acct::cp_change' }; + my $queue = new FS::queue { + 'svcnum' => $new->svcnum, + 'job' => 'FS::svc_acct::cp_change' + }; $error = $queue->insert( $new->username, $new->_password ); if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -755,7 +779,10 @@ sub replace { } if ( $icradius_dbh ) { - my $queue = new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_replace' }; + my $queue = new FS::queue { + 'svcnum' => $new->svcnum, + 'job' => 'FS::svc_acct::icradius_rc_replace' + }; $error = $queue->insert( $new->username, $new->_password, ); @@ -1164,34 +1191,6 @@ sub seconds_since { $self->cust_svc->seconds_since(@_); } -=item ssh - -=cut - -sub ssh { - my ( $host, @cmd_and_args ) = @_; - - use IO::File; - my $reader = IO::File->new(); - my $writer = IO::File->new(); - my $error = IO::File->new(); - - &Net::SSH::sshopen3( $host, $reader, $writer, $error, @cmd_and_args) or die $!; - - local $/ = undef; - my $output_stream = <$writer>; - my $error_stream = <$error>; - if ( length $error_stream ) { - #warn "[FS::svc_acct::ssh] STDERR $error_stream"; - die "[FS::svc_acct::ssh] STDERR $error_stream"; - } - if ( length $output_stream ) { - warn "[FS::svc_acct::ssh] STDOUT $output_stream"; - } - -# &Net::SSH::ssh(@args,">>/usr/local/etc/freeside/sshoutput 2>&1"); -} - =back =head1 BUGS -- cgit v1.1 From ce4d2cc94fed25fc3b4aa85531022ae1e6eed778 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 22 Feb 2002 05:56:48 +0000 Subject: fix bugs in CP mailbox changes: cp_change and cp_rename --- FS/FS/svc_acct.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 2f327a3..20db38b 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -809,7 +809,7 @@ sub icradius_rc_replace { } sub cp_rename { - my ( $old_username, $new_username ); + my ( $old_username, $new_username ) = @_; my $app = new Net::APP ( $cp_server, User => $cp_user, @@ -830,7 +830,7 @@ sub cp_rename { } sub cp_change { - my ( $username, $password ); + my ( $username, $password ) = @_; my $app = new Net::APP ( $cp_server, User => $cp_user, -- cgit v1.1 From da4c9633b45d04091fc1b8d420e5d75e294ebf86 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 22 Feb 2002 06:23:44 +0000 Subject: don't leak perl line numbers on cp provisioning errors --- FS/FS/svc_acct.pm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 20db38b..2a0c904 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -396,7 +396,7 @@ sub cp_insert { Domain => $mydomain, Timeout => 60, #Debug => 1, - ) or die $@; + ) or die "$@\n"; $app->create_mailbox( Mailbox => $username, @@ -405,7 +405,7 @@ sub cp_insert { Domain => $mydomain, ); - die $app->message unless $app->ok; + die $app->message."\n" unless $app->ok; } sub icradius_rc_insert { @@ -637,14 +637,14 @@ sub cp_delete { Domain => $mydomain, Timeout => 60, #Debug => 1, - ) or die $@; + ) or die "$@\n"; $app->delete_mailbox( Mailbox => $username, Domain => $mydomain, ); - die $app->message unless $app->ok; + die $app->message."\n" unless $app->ok; } sub icradius_rc_delete { @@ -817,7 +817,7 @@ sub cp_rename { Domain => $mydomain, Timeout => 60, #Debug => 1, - ) or die $@; + ) or die "$@\n"; $app->rename_mailbox( Domain => $mydomain, @@ -825,7 +825,7 @@ sub cp_rename { New_Mailbox => $new_username, ); - die $app->message unless $app->ok; + die $app->message."\n" unless $app->ok; } @@ -838,7 +838,7 @@ sub cp_change { Domain => $mydomain, Timeout => 60, #Debug => 1, - ) or die $@; + ) or die "$@\n"; $app->change_mailbox( Domain => $mydomain, @@ -846,7 +846,7 @@ sub cp_change { Password => $password, ); - die $app->message unless $app->ok; + die $app->message."\n" unless $app->ok; } -- cgit v1.1 From 1cd0fc70e60e5ecccb10e2bd4dae112a53dde330 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 22 Feb 2002 08:58:11 +0000 Subject: freeside *SUSPENDED* -> CP set_mailbox_status OTHER/OTHER_BOUNCE --- FS/FS/svc_acct.pm | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 2a0c904..314a752 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -840,12 +840,25 @@ sub cp_change { #Debug => 1, ) or die "$@\n"; + if ( $password =~ /^\*SUSPENDED\* (.*)$/ ) { + $password = $1; + $app->set_mailbox_status( + Other => 'T', + Other_Bounce => 'T', + ); + } else { + $app->set_mailbox_status( + Other => 'F', + Other_Bounce => 'F', + ); + } + die $app->message."\n" unless $app->ok; + $app->change_mailbox( Domain => $mydomain, Mailbox => $username, Password => $password, ); - die $app->message."\n" unless $app->ok; } -- cgit v1.1 From f430dd9ec58e429c2ddc7c3c83aeaf8d8c74c4fd Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 22 Feb 2002 09:01:08 +0000 Subject: correctly disable/enable accounts @ CP --- FS/FS/svc_acct.pm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 314a752..b90cbe8 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -843,12 +843,16 @@ sub cp_change { if ( $password =~ /^\*SUSPENDED\* (.*)$/ ) { $password = $1; $app->set_mailbox_status( - Other => 'T', + Domain => $mydomain, + Mailbox => $username, + Other => 'T', Other_Bounce => 'T', ); } else { $app->set_mailbox_status( - Other => 'F', + Domain => $mydomain, + Mailbox => $username, + Other => 'F', Other_Bounce => 'F', ); } -- cgit v1.1 From 5a30e3a89e4e313a526a7f03afbe94282c715bdd Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 28 Feb 2002 00:28:02 +0000 Subject: improved vpopmail support for svc_acct records --- FS/FS/svc_acct.pm | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index b90cbe8..6ac2b9d 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -11,7 +11,11 @@ use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin $dirhash $icradius_dbh @saltset @pw_set); + $rsync $ssh); use Carp; +use File::Path; +use Fcntl qw(:flock); +use FS::UID qw( datasrc ); use FS::Conf; use FS::Record qw( qsearch qsearchs fields dbh ); use FS::svc_Common; @@ -28,6 +32,8 @@ use FS::queue; #ask FS::UID to run this stuff for us later $FS::UID::callback{'FS::svc_acct'} = sub { + $rsync = "rsync"; + $ssh = "ssh"; $conf = new FS::Conf; $dir_prefix = $conf->config('home'); @shells = $conf->config('shells'); @@ -95,6 +101,14 @@ $FS::UID::callback{'FS::svc_acct'} = sub { $icradius_dbh = ''; } $dirhash = $conf->config('dirhash') || 0; + $exportdir = "/usr/local/etc/freeside/export." . datasrc; + if ( $conf->exists('vpopmailmachines') ) { + my (@vpopmailmachines) = $conf->config('vpopmailmachines'); + my ($machine, $dir, $uid, $gid) = split (/\s+/, $vpopmailmachines[0]); + $vpopdir = $dir; + } else { + $vpopdir = ''; + } }; @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' ); @@ -345,9 +359,28 @@ sub insert { $dbh->rollback if $oldAutoCommit; return "queueing job (transaction rolled back): $error"; } + } + + if ( $vpopdir ) { + + my $vpopmail_queue = + new FS::queue { + 'svcnum' => $self->svcnum, + 'job' => 'FS::svc_acct::vpopmail_insert' + }; + $error = $vpopmail_queue->insert( $self->username, + crypt($self->_password,$saltset[int(rand(64))].$saltset[int(rand(64))]), + $self->domain, + $vpopdir, + ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; #no error } @@ -457,6 +490,49 @@ sub icradius_rr_insert { 1; } + +sub vpopmail_insert { + my( $username, $password, $domain, $vpopdir ) = @_; + + (open(VPASSWD, ">>$exportdir/domains/$domain/vpasswd") + and flock(VPASSWD,LOCK_EX|LOCK_NB) + ) or die "can't open vpasswd file for $username\@$domain: $exportdir/domains/$domain/vpasswd"; + print VPASSWD join(":", + $username, + $password, + '1', + '0', + $username, + "$vpopdir/domains/$domain/$username", + 'NOQUOTA', + ), "\n"; + + flock(VPASSWD,LOCK_UN); + close(VPASSWD); + + mkdir "$exportdir/domains/$domain/$username", 0700 or die "can't create Maildir"; + mkdir "$exportdir/domains/$domain/$username/Maildir", 0700 or die "can't create Maildir"; + mkdir "$exportdir/domains/$domain/$username/Maildir/cur", 0700 or die "can't create Maildir"; + mkdir "$exportdir/domains/$domain/$username/Maildir/new", 0700 or die "can't create Maildir"; + mkdir "$exportdir/domains/$domain/$username/Maildir/tmp", 0700 or die "can't create Maildir"; + + my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_sync' }; + $error = $queue->insert; + + 1; +} + +sub vpopmail_sync { + + my (@vpopmailmachines) = $conf->config('vpopmailmachines'); + my ($machine, $dir, $uid, $gid) = split (/\s+/, $vpopmailmachines[0]); + + chdir $exportdir; + my @args = ("$rsync", "-rlpt", "-e", "$ssh", "domains/", "vpopmail\@$machine:$pdir/domains/") + system {$args[0]} @args; + +} + =item delete Deletes this account from the database. If there is an error, returns the @@ -601,6 +677,14 @@ sub delete { $dbh->rollback if $oldAutoCommit; return "queueing job (transaction rolled back): $error"; } + } + if ( $vpopdir ) { + my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_delete' }; + $error = $queue->insert( $self->username, $self->domain ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } } @@ -671,6 +755,33 @@ sub icradius_rr_delete { 1; } +sub vpopmail_delete { + my( $username, $domain ) = @_; + + (open(VPASSWD, "$exportdir/domains/$domain/vpasswd") + and flock(VPASSWD,LOCK_EX|LOCK_NB) + ) or die "can't open $exportdir/domains/$domain/vpasswd: $!"; + + open(VPASSWDTMP, ">$exportdir/domains/$domain/vpasswd.tmp") + or die "Can't open $exportdir/domains/$domain/vpasswd.tmp: $!"; + + while () { + my ($mailbox, $rest) = split(':', $_); + print VPASSWDTMP $_ unless $username eq $mailbox; + } + + close(VPASSWDTMP); + + rename "$exportdir/domains/$domain/vpasswd.tmp", "$exportdir/domains/$domain/vpasswd" + or die "Can't rename $exportdir/domains/$domain/vpasswd.tmp: $!"; + + flock(VPASSWD,LOCK_UN); + close(VPASSWD); + + rmtree "$exportdir/domains/$domain/$username" or die "can't destroy Maildir";+ + 1; +} + =item replace OLD_RECORD Replaces OLD_RECORD with this one in the database. If there is an error, @@ -791,6 +902,31 @@ sub replace { return "queueing job (transaction rolled back): $error"; } } + if ( $vpopdir ) { + my $cpassword = crypt( + $new->_password,$saltset[int(rand(64))].$saltset[int(rand(64))] + ); + + if ($old->username ne $new->username || $old->domain ne $new->domain ) { + my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_delete' }; + $error = $queue->insert( $old->username, $old->domain ); + my $queue2 = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_insert' }; + $error = $queue2->insert( $new->username, + $cpassword, + $new->domain, + $vpopdir, + ) + unless $error; + } elsif ($old->_password ne $new->_password) { + my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_replace_password' }; + $error = $queue->insert( $new->username, $cpassword, $new->domain ); + } + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "queueing job (transaction rolled back): $error"; + } + } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; #no error @@ -867,6 +1003,38 @@ sub cp_change { } +sub vpopmail_replace_password { + my( $username, $password, $domain ) = @_; + + (open(VPASSWD, "$exportdir/domains/$domain/vpasswd") + and flock(VPASSWD,LOCK_EX|LOCK_NB) + ) or die "can't open $exportdir/domains/$domain/vpasswd: $!"; + + open(VPASSWDTMP, ">$exportdir/domains/$domain/vpasswd.tmp") + or die "Can't open $exportdir/domains/$domain/vpasswd.tmp: $!"; + + while () { + my ($mailbox, $pw, @rest) = split(':', $_); + print VPASSWDTMP $_ unless $username eq $mailbox; + print VPASSWDTMP join (':', ($mailbox, $password, @rest)) + if $username eq $mailbox; + } + + close(VPASSWDTMP); + + rename "$exportdir/domains/$domain/vpasswd.tmp", "$exportdir/domains/$domain/vpasswd" + or die "Can't rename $exportdir/domains/$domain/vpasswd.tmp: $!"; + + flock(VPASSWD,LOCK_UN); + close(VPASSWD); + + my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_sync' }; + $error = $queue->insert; + + 1; +} + + =item suspend Suspends this account by prefixing *SUSPENDED* to the password. If there is an -- cgit v1.1 From 251540415dbf35a7c91e8338986ece244d77a987 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 28 Feb 2002 23:13:23 +0000 Subject: eek --- FS/FS/svc_acct.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 6ac2b9d..89fb76c 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -10,7 +10,7 @@ use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin $cp_server $cp_user $cp_pass $cp_workgroup $dirhash $icradius_dbh - @saltset @pw_set); + @saltset @pw_set $rsync $ssh); use Carp; use File::Path; -- cgit v1.1 From e296e99c38ed8fedae98bfd2b8ad063ae513583c Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 28 Feb 2002 23:17:31 +0000 Subject: clean up mess --- FS/FS/svc_acct.pm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 89fb76c..86132ff 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -11,7 +11,7 @@ use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin $dirhash $icradius_dbh @saltset @pw_set - $rsync $ssh); + $rsync $ssh $exportdir $vpopdir); use Carp; use File::Path; use Fcntl qw(:flock); @@ -495,7 +495,7 @@ sub vpopmail_insert { my( $username, $password, $domain, $vpopdir ) = @_; (open(VPASSWD, ">>$exportdir/domains/$domain/vpasswd") - and flock(VPASSWD,LOCK_EX|LOCK_NB) + and flock(VPASSWD,LOCK_EX) ) or die "can't open vpasswd file for $username\@$domain: $exportdir/domains/$domain/vpasswd"; print VPASSWD join(":", $username, @@ -517,7 +517,8 @@ sub vpopmail_insert { mkdir "$exportdir/domains/$domain/$username/Maildir/tmp", 0700 or die "can't create Maildir"; my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_sync' }; - $error = $queue->insert; + my $error = $queue->insert; + die $error if $error; 1; } @@ -528,7 +529,7 @@ sub vpopmail_sync { my ($machine, $dir, $uid, $gid) = split (/\s+/, $vpopmailmachines[0]); chdir $exportdir; - my @args = ("$rsync", "-rlpt", "-e", "$ssh", "domains/", "vpopmail\@$machine:$pdir/domains/") + my @args = ("$rsync", "-rlpt", "-e", "$ssh", "domains/", "vpopmail\@$machine:$vpoppdir/domains/"); system {$args[0]} @args; } @@ -759,7 +760,7 @@ sub vpopmail_delete { my( $username, $domain ) = @_; (open(VPASSWD, "$exportdir/domains/$domain/vpasswd") - and flock(VPASSWD,LOCK_EX|LOCK_NB) + and flock(VPASSWD,LOCK_EX) ) or die "can't open $exportdir/domains/$domain/vpasswd: $!"; open(VPASSWDTMP, ">$exportdir/domains/$domain/vpasswd.tmp") @@ -1007,7 +1008,7 @@ sub vpopmail_replace_password { my( $username, $password, $domain ) = @_; (open(VPASSWD, "$exportdir/domains/$domain/vpasswd") - and flock(VPASSWD,LOCK_EX|LOCK_NB) + and flock(VPASSWD,LOCK_EX) ) or die "can't open $exportdir/domains/$domain/vpasswd: $!"; open(VPASSWDTMP, ">$exportdir/domains/$domain/vpasswd.tmp") -- cgit v1.1 From e5b4bae07ce072ba1cc6997eadbe3f0c09ff7308 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 28 Feb 2002 23:18:46 +0000 Subject: clean up mess. *sigh* --- FS/FS/svc_acct.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 86132ff..3c564ec 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -529,7 +529,7 @@ sub vpopmail_sync { my ($machine, $dir, $uid, $gid) = split (/\s+/, $vpopmailmachines[0]); chdir $exportdir; - my @args = ("$rsync", "-rlpt", "-e", "$ssh", "domains/", "vpopmail\@$machine:$vpoppdir/domains/"); + my @args = ("$rsync", "-rlpt", "-e", "$ssh", "domains/", "vpopmail\@$machine:$vpopdir/domains/"); system {$args[0]} @args; } @@ -1030,7 +1030,8 @@ sub vpopmail_replace_password { close(VPASSWD); my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_sync' }; - $error = $queue->insert; + my $error = $queue->insert; + die $error if $error; 1; } -- cgit v1.1 From dd12d8bcbb33acb0ffa087a70c566e8328fbe9c3 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 18 Mar 2002 16:05:35 +0000 Subject: handle inserting cust_svc and svc_acct records separately also, to handle imports preserving svcnum --- FS/FS/svc_acct.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 3c564ec..bb9fe67 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -273,6 +273,16 @@ sub insert { 'domsvc' => $self->domsvc, } ); + if ( $self->svcnum ) { + my $cust_svc = qsearchs('cust_svc',{'svcnum'=>$self->svcnum}); + unless ( $cust_svc ) { + $dbh->rollback if $oldAutoCommit; + return "no cust_svc record found for svcnum ". $self->svcnum; + } + $self->pkgnum($cust_svc->pkgnum); + $self->svcpart($cust_svc->svcpart); + } + my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } ); return "Unknown svcpart" unless $part_svc; return "uid in use" -- cgit v1.1 From f1038a648b3d53db925b23519e7cd2a30c6837ed Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 20 Mar 2002 21:31:49 +0000 Subject: new export! infostreet and sqlradius provisioning switched over (Bug #299 - doesn't close it, but all the groundwork is done) also removes non-transactional ICRADIUS export from svc_acct.export (closes: Bug#347) --- FS/FS/svc_acct.pm | 236 +++++++++++++++--------------------------------------- 1 file changed, 65 insertions(+), 171 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index bb9fe67..2305aeb 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -1,7 +1,8 @@ package FS::svc_acct; use strict; -use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin +use vars qw( @ISA $nossh_hack $noexport_hack $conf + $dir_prefix @shells $usernamemin $usernamemax $passwordmin $passwordmax $username_ampersand $username_letter $username_letterfirst $username_noperiod $username_uppercase @@ -9,7 +10,6 @@ use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin $cyrus_server $cyrus_admin_user $cyrus_admin_pass $cp_server $cp_user $cp_pass $cp_workgroup $dirhash - $icradius_dbh @saltset @pw_set $rsync $ssh $exportdir $vpopdir); use Carp; @@ -88,18 +88,7 @@ $FS::UID::callback{'FS::svc_acct'} = sub { $cp_pass = ''; $cp_workgroup = ''; } - if ( $conf->exists('icradiusmachines') ) { - if ( $conf->exists('icradius_secrets') ) { - #need some sort of late binding so it's only connected to when - # actually used, hmm - $icradius_dbh = DBI->connect($conf->config('icradius_secrets')) - or die $DBI::errstr; - } else { - $icradius_dbh = dbh; - } - } else { - $icradius_dbh = ''; - } + $dirhash = $conf->config('dirhash') || 0; $exportdir = "/usr/local/etc/freeside/export." . datasrc; if ( $conf->exists('vpopmailmachines') ) { @@ -246,6 +235,8 @@ $username, $uid, $gid, $dir, and $shell. (TODOC: cyrus config file, L and L) +(TODOC: new exports! $noexport_hack) + =cut sub insert { @@ -297,6 +288,20 @@ sub insert { return $error; } + #new-style exports! + unless ( $noexport_hack ) { + foreach my $part_export ( $self->cust_svc->part_svc->part_export ) { + my $error = $part_export->export_insert($self); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "exporting to ". $part_export->exporttype. + " (transaction rolled back): $error"; + } + } + } + + #old-style exports + my( $username, $uid, $gid, $dir, $shell ) = ( $self->username, $self->uid, @@ -340,37 +345,6 @@ sub insert { } } - if ( $icradius_dbh ) { - - my $radcheck_queue = - new FS::queue { - 'svcnum' => $self->svcnum, - 'job' => 'FS::svc_acct::icradius_rc_insert' - }; - $error = $radcheck_queue->insert( $self->username, - $self->_password, - $self->radius_check - ); - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return "queueing job (transaction rolled back): $error"; - } - - my $radreply_queue = - new FS::queue { - 'svcnum' => $self->svcnum, - 'job' => 'FS::svc_acct::icradius_rr_insert' - }; - $error = $radreply_queue->insert( $self->username, - $self->_password, - $self->radius_reply - ); - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return "queueing job (transaction rolled back): $error"; - } - } - if ( $vpopdir ) { my $vpopmail_queue = @@ -390,6 +364,7 @@ sub insert { } + #end of old-style exports $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; #no error @@ -451,56 +426,6 @@ sub cp_insert { die $app->message."\n" unless $app->ok; } -sub icradius_rc_insert { - my( $username, $password, %radcheck ) = @_; - - my $sth = $icradius_dbh->prepare( - "INSERT INTO radcheck ( id, UserName, Attribute, Value ) VALUES ( ". - join(", ", map { $icradius_dbh->quote($_) } ( - '', - $username, - "Password", - $password, - ) ). " )" - ); - $sth->execute or die "can't insert into radcheck table: ". $sth->errstr; - - foreach my $attribute ( keys %radcheck ) { - my $sth = $icradius_dbh->prepare( - "INSERT INTO radcheck ( id, UserName, Attribute, Value ) VALUES ( ". - join(", ", map { $icradius_dbh->quote($_) } ( - '', - $username, - $attribute, - $radcheck{$attribute}, - ) ). " )" - ); - $sth->execute or die "can't insert into radcheck table: ". $sth->errstr; - } - - 1; -} - -sub icradius_rr_insert { - my( $username, $password, %radreply ) = @_; - - foreach my $attribute ( keys %radreply ) { - my $sth = $icradius_dbh->prepare( - "INSERT INTO radreply ( id, UserName, Attribute, Value ) VALUES ( ". - join(", ", map { $icradius_dbh->quote($_) } ( - '', - $username, - $attribute, - $radreply{$attribute}, - ) ). " )" - ); - $sth->execute or die "can't insert into radreply table: ". $sth->errstr; - } - - 1; -} - - sub vpopmail_insert { my( $username, $password, $domain, $vpopdir ) = @_; @@ -571,6 +496,8 @@ $username and $dir. (TODOC: cyrus config file) +(TODOC: new exports! $noexport_hack) + =cut sub delete { @@ -590,7 +517,7 @@ sub delete { return "Can't delete an account with (svc_www) web service!" if qsearch( 'svc_www', { 'usersvc' => $self->usersvc } ); - # what about records in session ? + # what about records in session ? (they should refer to history table) local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; @@ -639,6 +566,20 @@ sub delete { return $error; } + #new-style exports! + unless ( $noexport_hack ) { + foreach my $part_export ( $self->cust_svc->part_svc->part_export ) { + my $error = $part_export->export_delete($self); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "exporting to ". $part_export->exporttype. + " (transaction rolled back): $error"; + } + } + } + + #old-style exports + my( $username, $dir ) = ( $self->username, $self->dir, @@ -671,24 +612,6 @@ sub delete { } } - if ( $icradius_dbh ) { - - my $radcheck_queue = - new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_delete' }; - $error = $radcheck_queue->insert( $self->username ); - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return "queueing job (transaction rolled back): $error"; - } - - my $radreply_queue = - new FS::queue { 'job' => 'FS::svc_acct::icradius_rr_delete' }; - $error = $radreply_queue->insert( $self->username ); - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return "queueing job (transaction rolled back): $error"; - } - } if ( $vpopdir ) { my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_delete' }; $error = $queue->insert( $self->username, $self->domain ); @@ -699,6 +622,8 @@ sub delete { } + #end of old-style exports + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; } @@ -742,30 +667,6 @@ sub cp_delete { die $app->message."\n" unless $app->ok; } -sub icradius_rc_delete { - my $username = shift; - - my $sth = $icradius_dbh->prepare( - 'DELETE FROM radcheck WHERE UserName = ?' - ); - $sth->execute($username) - or die "can't delete from radcheck table: ". $sth->errstr; - - 1; -} - -sub icradius_rr_delete { - my $username = shift; - - my $sth = $icradius_dbh->prepare( - 'DELETE FROM radreply WHERE UserName = ?' - ); - $sth->execute($username) - or die "can't delete from radreply table: ". $sth->errstr; - - 1; -} - sub vpopmail_delete { my( $username, $domain ) = @_; @@ -858,6 +759,20 @@ sub replace { return $error if $error; } + #new-style exports! + unless ( $noexport_hack ) { + foreach my $part_export ( $new->cust_svc->part_svc->part_export ) { + my $error = $part_export->export_replace($new,$old); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "exporting to ". $part_export->exporttype. + " (transaction rolled back): $error"; + } + } + } + + #old-style exports + my ( $old_dir, $new_dir, $uid, $gid ) = ( $old->getfield('dir'), $new->getfield('dir'), @@ -900,19 +815,6 @@ sub replace { } } - if ( $icradius_dbh ) { - my $queue = new FS::queue { - 'svcnum' => $new->svcnum, - 'job' => 'FS::svc_acct::icradius_rc_replace' - }; - $error = $queue->insert( $new->username, - $new->_password, - ); - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return "queueing job (transaction rolled back): $error"; - } - } if ( $vpopdir ) { my $cpassword = crypt( $new->_password,$saltset[int(rand(64))].$saltset[int(rand(64))] @@ -938,23 +840,12 @@ sub replace { } } + #end of old-style exports $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; #no error } -sub icradius_rc_replace { - my( $username, $new_password ) = @_; - - my $sth = $icradius_dbh->prepare( - "UPDATE radcheck SET Value = ? WHERE UserName = ? and Attribute = ?" - ); - $sth->execute($new_password, $username, 'Password' ) - or die "can't update radcheck table: ". $sth->errstr; - - 1; -} - sub cp_rename { my ( $old_username, $new_username ) = @_; @@ -1305,19 +1196,22 @@ sub radius_reply { Returns key/value pairs, suitable for assigning to a hash, for any RADIUS check attributes of this record. -Accessing RADIUS attributes directly is not supported and will break in the -future. +Note that this is now the preferred method for reading RADIUS attributes - +accessing the columns directly is discouraged, as the column names are +expected to change in the future. =cut sub radius_check { my $self = shift; - map { - /^(rc_(.*))$/; - my($column, $attrib) = ($1, $2); - #$attrib =~ s/_/\-/g; - ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) ); - } grep { /^rc_/ && $self->getfield($_) } fields( $self->table ); + ( 'Password' => $self->_password, + map { + /^(rc_(.*))$/; + my($column, $attrib) = ($1, $2); + #$attrib =~ s/_/\-/g; + ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) ); + } grep { /^rc_/ && $self->getfield($_) } fields( $self->table ) + ); } =item domain -- cgit v1.1 From 20bb426a02c0ea54d8feaea7c5da51735ab70293 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 22 Mar 2002 18:56:33 +0000 Subject: RADIUS groups on the way! --- FS/FS/svc_acct.pm | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 2305aeb..9da5a66 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -27,6 +27,7 @@ use FS::cust_main_invoice; use FS::svc_domain; use FS::raddb; use FS::queue; +use FS::radius_usergroup; @ISA = qw( FS::svc_Common ); @@ -1282,8 +1283,64 @@ sub seconds_since { $self->cust_svc->seconds_since(@_); } +=item radius_groups + +Returns all RADIUS groups for this account (see L). + +=cut + +sub radius_groups { + my $self = shift; + map { $_->groupname } + qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } ); +} + =back +=head1 SUBROUTINES + +=item radius_usergroup_selector GROUPS_ARRAYREF + +=cut + +sub radius_usergroup_selector { + my $sel_groups = shift; + my %sel_groups = map { $_=>1 } @$sel_groups; + + my $selectname = shift || 'radius_usergroup'; + + my $dbh = dbh; + my $sth = $dbh->prepare( + 'SELECT DISTINCT(groupname) FROM radius_usergroup ORDER BY groupname' + ) or die $dbh->errstr; + $sth->execute() or die $sth->errstr; + my @all_groups = map { $_->[0] } @{$sth->fetchall_arrayref}; + + my $html = < + function ${selectname}_doadd(object) { + var myvalue = object.${selectname}_add.value; + var optionName = new Option(myvalue,myvalue,false,true); + var length = object.$selectname.length; + object.$selectname.options[length] = optionName; + } + + !. + qq!!; + + $html; +} + =head1 BUGS The $recref stuff in sub check should be cleaned up. @@ -1292,6 +1349,9 @@ The suspend, unsuspend and cancel methods update the database, but not the current object. This is probably a bug as it's unexpected and counterintuitive. +radius_usergroup_selector? putting web ui components in here? they should +probably live somewhere else... + =head1 SEE ALSO L, edit/part_svc.cgi from an installed web interface, -- cgit v1.1 From 8fe83dcb8807a86209625a5aab7e574073f0a907 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 23 Mar 2002 16:16:00 +0000 Subject: group editing seems to be working... everything except defaults... oh and export... --- FS/FS/svc_acct.pm | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 4 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 9da5a66..bb6b995 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -192,8 +192,6 @@ 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 @@ -216,6 +214,10 @@ otherwise returns false. The additional fields pkgnum and svcpart (see L) should be defined. An FS::cust_svc record will be created and inserted. +The additional field I can optionally be defined; if so it should +contain an arrayref of group names. See L. (used in +sqlradius export only) + If the configuration value (see L) shellmachine exists, and the username, uid, and dir fields are defined, the command(s) specified in the shellmachine-useradd configuration are added to the job queue (see @@ -289,6 +291,20 @@ sub insert { return $error; } + if ( $self->usergroup ) { + foreach my $groupname ( @{$self->usergroup} ) { + my $radius_usergroup = new FS::radius_usergroup ( { + svcnum => $self->svcnum, + groupname => $groupname, + } ); + my $error = $radius_usergroup->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + } + #new-style exports! unless ( $noexport_hack ) { foreach my $part_export ( $self->cust_svc->part_svc->part_export ) { @@ -561,6 +577,16 @@ sub delete { } } + foreach my $radius_usergroup ( + qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } ) + ) { + my $error = $radius_usergroup->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + my $error = $self->SUPER::delete; if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -700,6 +726,10 @@ sub vpopmail_delete { Replaces OLD_RECORD with this one in the database. If there is an error, returns the error, otherwise returns false. +The additional field I can optionally be defined; if so it should +contain an arrayref of group names. See L. (used in +sqlradius export only) + If the configuration value (see L) shellmachine exists, and the dir field has changed, the command(s) specified in the shellmachine-usermod configuraiton file are added to the job queue (see L and @@ -760,6 +790,40 @@ sub replace { return $error if $error; } + $old->usergroup( [ $old->radius_groups ] ); + + if ( $new->usergroup ) { + + foreach my $groupname ( @{$old->usergroup} ) { + if ( grep { $groupname eq $_ } @{$new->usergroup} ) { + $new->usergroup( [ grep { $groupname ne $_ } @{$new->usergroup} ] ); + next; + } + my $radius_usergroup = qsearch('radius_usergroup', { + svcnum => $old->svcnum, + groupname => $groupname, + } ); + my $error = $radius_usergroup->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "error deleting radius_usergroup $groupname: $error"; + } + } + + foreach my $groupname ( @{$new->usergroup} ) { + my $radius_usergroup = new FS::radius_usergroup ( { + svcnum => $new->svcnum, + groupname => $groupname, + } ); + my $error = $radius_usergroup->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "error adding radius_usergroup $groupname: $error"; + } + } + + } + #new-style exports! unless ( $noexport_hack ) { foreach my $part_export ( $new->cust_svc->part_svc->part_export ) { @@ -1299,7 +1363,7 @@ sub radius_groups { =head1 SUBROUTINES -=item radius_usergroup_selector GROUPS_ARRAYREF +=item radius_usergroup_selector GROUPS_ARRAYREF [ SELECTNAME ] =cut @@ -1323,6 +1387,7 @@ sub radius_usergroup_selector { var optionName = new Option(myvalue,myvalue,false,true); var length = object.$selectname.length; object.$selectname.options[length] = optionName; + object.${selectname}_add.value = ""; } !. -- cgit v1.1 From 74e64d70361848f089aad9a7881c2af9caf6e479 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 23 Mar 2002 17:49:01 +0000 Subject: okay group editing UI as well as part_svc group editing UI seem to be working --- FS/FS/svc_acct.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index bb6b995..a3e97f7 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -799,7 +799,7 @@ sub replace { $new->usergroup( [ grep { $groupname ne $_ } @{$new->usergroup} ] ); next; } - my $radius_usergroup = qsearch('radius_usergroup', { + my $radius_usergroup = qsearchs('radius_usergroup', { svcnum => $old->svcnum, groupname => $groupname, } ); @@ -1395,7 +1395,10 @@ END foreach my $group ( @all_groups ) { $html .= ' Date: Sun, 24 Mar 2002 14:29:00 +0000 Subject: ICRADIUS groups all done! UI and provisioning. closes: Bug#362 fix some bugs in the export and add queue_dangerous_controls option too --- FS/FS/svc_acct.pm | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index a3e97f7..197eec1 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -257,8 +257,6 @@ sub insert { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my $amount = 0; - $error = $self->check; return $error if $error; @@ -587,6 +585,8 @@ sub delete { } } + my $part_svc = $self->cust_svc->part_svc; + my $error = $self->SUPER::delete; if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -595,7 +595,7 @@ sub delete { #new-style exports! unless ( $noexport_hack ) { - foreach my $part_export ( $self->cust_svc->part_svc->part_export ) { + foreach my $part_export ( $part_svc->part_export ) { my $error = $part_export->export_delete($self); if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -791,34 +791,34 @@ sub replace { } $old->usergroup( [ $old->radius_groups ] ); - if ( $new->usergroup ) { - - foreach my $groupname ( @{$old->usergroup} ) { - if ( grep { $groupname eq $_ } @{$new->usergroup} ) { - $new->usergroup( [ grep { $groupname ne $_ } @{$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, - groupname => $groupname, + groupname => $oldgroup, } ); my $error = $radius_usergroup->delete; if ( $error ) { $dbh->rollback if $oldAutoCommit; - return "error deleting radius_usergroup $groupname: $error"; + return "error deleting radius_usergroup $oldgroup: $error"; } } - foreach my $groupname ( @{$new->usergroup} ) { + foreach my $newgroup ( @newgroups ) { my $radius_usergroup = new FS::radius_usergroup ( { svcnum => $new->svcnum, - groupname => $groupname, + groupname => $newgroup, } ); my $error = $radius_usergroup->insert; if ( $error ) { $dbh->rollback if $oldAutoCommit; - return "error adding radius_usergroup $groupname: $error"; + return "error adding radius_usergroup $newgroup: $error"; } } @@ -1072,6 +1072,11 @@ sub check { 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') ; -- cgit v1.1 From 87af741da0dd5f6a76bbb566b4d6c54cd5b15315 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 5 Apr 2002 23:51:18 +0000 Subject: - add message catalog table & beginning of web interface - add security_phrase and conf option to svc_acct.pm - random other stuff --- FS/FS/svc_acct.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 197eec1..8d22c21 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -1079,6 +1079,7 @@ sub check { my $error = $self->ut_numbern('svcnum') || $self->ut_number('domsvc') + || $self->ut_textn('sec_phrase') ; return $error if $error; -- cgit v1.1 From 195652229909566ccb3a6ae249d8fa26f25da55a Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 6 Apr 2002 00:08:08 +0000 Subject: security phrase bug fixes --- FS/FS/svc_acct.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'FS/FS/svc_acct.pm') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 8d22c21..8e25f6a 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -170,6 +170,8 @@ FS::svc_Common. The following fields are currently supported: =item _password - generated if blank +=item sec_phrase - security phrase + =item popnum - Point of presence (see L) =item uid -- cgit v1.1 From 0b65ce59c7d2ee712389c27954382274ddf718a5 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 10 Apr 2002 13:42:49 +0000 Subject: bulk checkin from working on the road: - use msgcat for more error messages - should be all things that would come3 back from the signup server normally now - signup server: don't display access number