4 use vars qw( @ISA $nossh_hack $conf $dir_prefix @shells $usernamemin
5 $usernamemax $passwordmin $passwordmax
6 $username_ampersand $username_letter $username_letterfirst
7 $username_noperiod $username_uppercase
8 $shellmachine $useradd $usermod $userdel $mydomain
9 $cyrus_server $cyrus_admin_user $cyrus_admin_pass
10 $cp_server $cp_user $cp_pass $cp_workgroup
16 use FS::Record qw( qsearch qsearchs fields dbh );
22 use FS::cust_main_invoice;
27 @ISA = qw( FS::svc_Common );
29 #ask FS::UID to run this stuff for us later
30 $FS::UID::callback{'FS::svc_acct'} = sub {
32 $dir_prefix = $conf->config('home');
33 @shells = $conf->config('shells');
34 $shellmachine = $conf->config('shellmachine');
35 $usernamemin = $conf->config('usernamemin') || 2;
36 $usernamemax = $conf->config('usernamemax');
37 $passwordmin = $conf->config('passwordmin') || 6;
38 $passwordmax = $conf->config('passwordmax') || 8;
39 if ( $shellmachine ) {
40 if ( $conf->exists('shellmachine-useradd') ) {
41 $useradd = join("\n", $conf->config('shellmachine-useradd') )
42 || 'cp -pr /etc/skel $dir; chown -R $uid.$gid $dir';
44 $useradd = 'useradd -d $dir -m -s $shell -u $uid $username';
46 if ( $conf->exists('shellmachine-userdel') ) {
47 $userdel = join("\n", $conf->config('shellmachine-userdel') )
50 $userdel = 'userdel $username';
52 $usermod = join("\n", $conf->config('shellmachine-usermod') )
53 || '[ -d $old_dir ] && mv $old_dir $new_dir || ( '.
54 'chmod u+t $old_dir; mkdir $new_dir; cd $old_dir; '.
55 'find . -depth -print | cpio -pdm $new_dir; '.
56 'chmod u-t $new_dir; chown -R $uid.$gid $new_dir; '.
60 $username_letter = $conf->exists('username-letter');
61 $username_letterfirst = $conf->exists('username-letterfirst');
62 $username_noperiod = $conf->exists('username-noperiod');
63 $username_uppercase = $conf->exists('username-uppercase');
64 $username_ampersand = $conf->exists('username-ampersand');
65 $mydomain = $conf->config('domain');
66 if ( $conf->exists('cyrus') ) {
67 ($cyrus_server, $cyrus_admin_user, $cyrus_admin_pass) =
68 $conf->config('cyrus');
69 eval "use Cyrus::IMAP::Admin;"
72 $cyrus_admin_user = '';
73 $cyrus_admin_pass = '';
75 if ( $conf->exists('cp_app') ) {
76 ($cp_server, $cp_user, $cp_pass, $cp_workgroup) =
77 $conf->config('cp_app');
85 if ( $conf->exists('icradiusmachines') ) {
86 if ( $conf->exists('icradius_secrets') ) {
87 #need some sort of late binding so it's only connected to when
89 $icradius_dbh = DBI->connect($conf->config('icradius_secrets'))
97 $dirhash = $conf->config('dirhash') || 0;
100 @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' );
101 @pw_set = ( 'a'..'z', 'A'..'Z', '0'..'9', '(', ')', '#', '!', '.', ',' );
103 #not needed in 5.004 #srand($$|time);
107 my ( $hashref, $cache ) = @_;
108 if ( $hashref->{'svc_acct_svcnum'} ) {
109 $self->{'_domsvc'} = FS::svc_domain->new( {
110 'svcnum' => $hashref->{'domsvc'},
111 'domain' => $hashref->{'svc_acct_domain'},
112 'catchall' => $hashref->{'svc_acct_catchall'},
119 FS::svc_acct - Object methods for svc_acct records
125 $record = new FS::svc_acct \%hash;
126 $record = new FS::svc_acct { 'column' => 'value' };
128 $error = $record->insert;
130 $error = $new_record->replace($old_record);
132 $error = $record->delete;
134 $error = $record->check;
136 $error = $record->suspend;
138 $error = $record->unsuspend;
140 $error = $record->cancel;
142 %hash = $record->radius;
144 %hash = $record->radius_reply;
146 %hash = $record->radius_check;
148 $domain = $record->domain;
150 $svc_domain = $record->svc_domain;
152 $email = $record->email;
154 $seconds_since = $record->seconds_since($timestamp);
158 An FS::svc_acct object represents an account. FS::svc_acct inherits from
159 FS::svc_Common. The following fields are currently supported:
163 =item svcnum - primary key (assigned automatcially for new accounts)
167 =item _password - generated if blank
169 =item popnum - Point of presence (see L<FS::svc_acct_pop>)
177 =item dir - set automatically if blank (and uid is not)
181 =item quota - (unimplementd)
183 =item slipip - IP address
187 =item domsvc - svcnum from svc_domain
189 =item radius_I<Radius_Attribute> - I<Radius-Attribute>
191 =item domsvc - service number of svc_domain with which to associate
201 Creates a new account. To add the account to the database, see L<"insert">.
205 sub table { 'svc_acct'; }
209 Adds this account to the database. If there is an error, returns the error,
210 otherwise returns false.
212 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
213 defined. An FS::cust_svc record will be created and inserted.
215 If the configuration value (see L<FS::Conf>) shellmachine exists, and the
216 username, uid, and dir fields are defined, the command(s) specified in
217 the shellmachine-useradd configuration are added to the job queue (see
218 L<FS::queue> and L<freeside-queued>) to be exectued on shellmachine via ssh.
219 This behaviour can be surpressed by setting $FS::svc_acct::nossh_hack true.
220 If the shellmachine-useradd configuration file does not exist,
222 useradd -d $dir -m -s $shell -u $uid $username
224 is the default. If the shellmachine-useradd configuration file exists but
227 cp -pr /etc/skel $dir; chown -R $uid.$gid $dir
229 is the default instead. Otherwise the contents of the file are treated as
230 a double-quoted perl string, with the following variables available:
231 $username, $uid, $gid, $dir, and $shell.
233 (TODOC: cyrus config file, L<FS::queue> and L<freeside-queued>)
241 local $SIG{HUP} = 'IGNORE';
242 local $SIG{INT} = 'IGNORE';
243 local $SIG{QUIT} = 'IGNORE';
244 local $SIG{TERM} = 'IGNORE';
245 local $SIG{TSTP} = 'IGNORE';
246 local $SIG{PIPE} = 'IGNORE';
248 my $oldAutoCommit = $FS::UID::AutoCommit;
249 local $FS::UID::AutoCommit = 0;
254 $error = $self->check;
255 return $error if $error;
257 return "Username ". $self->username. " in use"
258 if qsearchs( 'svc_acct', { 'username' => $self->username,
259 'domsvc' => $self->domsvc,
262 my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
263 return "Unknown svcpart" unless $part_svc;
265 if $part_svc->part_svc_column('uid')->columnflag ne 'F'
266 && qsearchs( 'svc_acct', { 'uid' => $self->uid } )
267 && $self->username !~ /^(hyla)?fax$/
270 $error = $self->SUPER::insert;
272 $dbh->rollback if $oldAutoCommit;
276 my( $username, $uid, $gid, $dir, $shell ) = (
283 if ( $username && $uid && $dir && $shellmachine && ! $nossh_hack ) {
284 my $queue = new FS::queue {
285 'svcnum' => $self->svcnum,
286 'job' => 'Net::SSH::ssh_cmd',
288 $error = $queue->insert("root\@$shellmachine", eval qq("$useradd") );
290 $dbh->rollback if $oldAutoCommit;
291 return "queueing job (transaction rolled back): $error";
295 if ( $cyrus_server ) {
296 my $queue = new FS::queue {
297 'svcnum' => $self->svcnum,
298 'job' => 'FS::svc_acct::cyrus_insert',
300 $error = $queue->insert($self->username, $self->quota);
302 $dbh->rollback if $oldAutoCommit;
303 return "queueing job (transaction rolled back): $error";
308 my $queue = new FS::queue {
309 'svcnum' => $self->svcnum,
310 'job' => 'FS::svc_acct::cp_insert'
312 $error = $queue->insert($self->username, $self->_password);
314 $dbh->rollback if $oldAutoCommit;
315 return "queueing job (transaction rolled back): $error";
319 if ( $icradius_dbh ) {
323 'svcnum' => $self->svcnum,
324 'job' => 'FS::svc_acct::icradius_rc_insert'
326 $error = $radcheck_queue->insert( $self->username,
331 $dbh->rollback if $oldAutoCommit;
332 return "queueing job (transaction rolled back): $error";
337 'svcnum' => $self->svcnum,
338 'job' => 'FS::svc_acct::icradius_rr_insert'
340 $error = $radreply_queue->insert( $self->username,
345 $dbh->rollback if $oldAutoCommit;
346 return "queueing job (transaction rolled back): $error";
351 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
356 my( $username, $quota ) = @_;
358 warn "cyrus_insert: starting for user $username, quota $quota\n";
360 warn "cyrus_insert: connecting to $cyrus_server\n";
361 my $client = Cyrus::IMAP::Admin->new($cyrus_server);
363 warn "cyrus_insert: authentication as $cyrus_admin_user\n";
364 $client->authenticate(
365 -user => $cyrus_admin_user,
366 -mechanism => "login",
367 -password => $cyrus_admin_pass
370 warn "cyrus_insert: creating user.$username\n";
371 my $rc = $client->create("user.$username");
372 my $error = $client->error;
373 die "cyrus_insert: error creating user.$username: $error" if $error;
375 warn "cyrus_insert: setacl user.$username, $username => all\n";
376 $rc = $client->setacl("user.$username", $username => 'all' );
377 $error = $client->error;
378 die "cyrus_insert: error setacl user.$username: $error" if $error;
381 warn "cyrus_insert: setquota user.$username, STORAGE => $quota\n";
382 $rc = $client->setquota("user.$username", 'STORAGE' => $quota );
383 $error = $client->error;
384 die "cyrus_insert: error setquota user.$username: $error" if $error;
391 my( $username, $password ) = @_;
393 my $app = new Net::APP ( $cp_server,
395 Password => $cp_pass,
401 $app->create_mailbox(
402 Mailbox => $username,
403 Password => $password,
404 Workgroup => $cp_workgroup,
408 die $app->message unless $app->ok;
411 sub icradius_rc_insert {
412 my( $username, $password, %radcheck ) = @_;
414 my $sth = $icradius_dbh->prepare(
415 "INSERT INTO radcheck ( id, UserName, Attribute, Value ) VALUES ( ".
416 join(", ", map { $icradius_dbh->quote($_) } (
423 $sth->execute or die "can't insert into radcheck table: ". $sth->errstr;
425 foreach my $attribute ( keys %radcheck ) {
426 my $sth = $icradius_dbh->prepare(
427 "INSERT INTO radcheck ( id, UserName, Attribute, Value ) VALUES ( ".
428 join(", ", map { $icradius_dbh->quote($_) } (
432 $radcheck{$attribute},
435 $sth->execute or die "can't insert into radcheck table: ". $sth->errstr;
441 sub icradius_rr_insert {
442 my( $username, $password, %radreply ) = @_;
444 foreach my $attribute ( keys %radreply ) {
445 my $sth = $icradius_dbh->prepare(
446 "INSERT INTO radreply ( id, UserName, Attribute, Value ) VALUES ( ".
447 join(", ", map { $icradius_dbh->quote($_) } (
451 $radreply{$attribute},
454 $sth->execute or die "can't insert into radreply table: ". $sth->errstr;
462 Deletes this account from the database. If there is an error, returns the
463 error, otherwise returns false.
465 The corresponding FS::cust_svc record will be deleted as well.
467 If the configuration value (see L<FS::Conf>) shellmachine exists, the
468 command(s) specified in the shellmachine-userdel configuration file are
469 added to the job queue (see L<FS::queue> and L<freeside-queued>) to be executed
470 on shellmachine via ssh. This behavior can be surpressed by setting
471 $FS::svc_acct::nossh_hack true. If the shellmachine-userdel configuration
476 is the default. If the shellmachine-userdel configuration file exists but
481 is the default instead. Otherwise the contents of the file are treated as a
482 double-quoted perl string, with the following variables available:
485 (TODOC: cyrus config file)
492 if ( defined( $FS::Record::dbdef->table('svc_acct_sm') ) ) {
493 return "Can't delete an account which has (svc_acct_sm) mail aliases!"
494 if $self->uid && qsearch( 'svc_acct_sm', { 'domuid' => $self->uid } );
497 return "Can't delete an account which is a (svc_forward) source!"
498 if qsearch( 'svc_forward', { 'srcsvc' => $self->svcnum } );
500 return "Can't delete an account which is a (svc_forward) destination!"
501 if qsearch( 'svc_forward', { 'dstsvc' => $self->svcnum } );
503 return "Can't delete an account with (svc_www) web service!"
504 if qsearch( 'svc_www', { 'usersvc' => $self->usersvc } );
506 # what about records in session ?
508 local $SIG{HUP} = 'IGNORE';
509 local $SIG{INT} = 'IGNORE';
510 local $SIG{QUIT} = 'IGNORE';
511 local $SIG{TERM} = 'IGNORE';
512 local $SIG{TSTP} = 'IGNORE';
513 local $SIG{PIPE} = 'IGNORE';
515 my $oldAutoCommit = $FS::UID::AutoCommit;
516 local $FS::UID::AutoCommit = 0;
519 foreach my $cust_main_invoice (
520 qsearch( 'cust_main_invoice', { 'dest' => $self->svcnum } )
522 unless ( defined($cust_main_invoice) ) {
523 warn "WARNING: something's wrong with qsearch";
526 my %hash = $cust_main_invoice->hash;
527 $hash{'dest'} = $self->email;
528 my $new = new FS::cust_main_invoice \%hash;
529 my $error = $new->replace($cust_main_invoice);
531 $dbh->rollback if $oldAutoCommit;
536 foreach my $svc_domain (
537 qsearch( 'svc_domain', { 'catchall' => $self->svcnum } )
539 my %hash = new FS::svc_domain->hash;
540 $hash{'catchall'} = '';
541 my $new = new FS::svc_domain \%hash;
542 my $error = $new->replace($svc_domain);
544 $dbh->rollback if $oldAutoCommit;
549 my $error = $self->SUPER::delete;
551 $dbh->rollback if $oldAutoCommit;
555 my( $username, $dir ) = (
559 if ( $username && $shellmachine && ! $nossh_hack ) {
560 my $queue = new FS::queue { 'job' => 'Net::SSH::ssh_cmd' };
561 $error = $queue->insert("root\@$shellmachine", eval qq("$userdel") );
563 $dbh->rollback if $oldAutoCommit;
564 return "queueing job (transaction rolled back): $error";
569 if ( $cyrus_server ) {
570 my $queue = new FS::queue { 'job' => 'FS::svc_acct::cyrus_delete' };
571 $error = $queue->insert($self->username);
573 $dbh->rollback if $oldAutoCommit;
574 return "queueing job (transaction rolled back): $error";
579 my $queue = new FS::queue { 'job' => 'FS::svc_acct::cp_delete' };
580 $error = $queue->insert($self->username);
582 $dbh->rollback if $oldAutoCommit;
583 return "queueing job (transaction rolled back): $error";
587 if ( $icradius_dbh ) {
590 new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_delete' };
591 $error = $radcheck_queue->insert( $self->username );
593 $dbh->rollback if $oldAutoCommit;
594 return "queueing job (transaction rolled back): $error";
598 new FS::queue { 'job' => 'FS::svc_acct::icradius_rr_delete' };
599 $error = $radreply_queue->insert( $self->username );
601 $dbh->rollback if $oldAutoCommit;
602 return "queueing job (transaction rolled back): $error";
607 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
612 my $username = shift;
614 my $client = Cyrus::IMAP::Admin->new($cyrus_server);
615 $client->authenticate(
616 -user => $cyrus_admin_user,
617 -mechanism => "login",
618 -password => $cyrus_admin_pass
621 my $rc = $client->setacl("user.$username", $cyrus_admin_user => 'all' );
622 my $error = $client->error;
623 die $error if $error;
625 $rc = $client->delete("user.$username");
626 $error = $client->error;
627 die $error if $error;
633 my( $username ) = @_;
634 my $app = new Net::APP ( $cp_server,
636 Password => $cp_pass,
642 $app->delete_mailbox(
643 Mailbox => $username,
647 die $app->message unless $app->ok;
650 sub icradius_rc_delete {
651 my $username = shift;
653 my $sth = $icradius_dbh->prepare(
654 'DELETE FROM radcheck WHERE UserName = ?'
656 $sth->execute($username)
657 or die "can't delete from radcheck table: ". $sth->errstr;
662 sub icradius_rr_delete {
663 my $username = shift;
665 my $sth = $icradius_dbh->prepare(
666 'DELETE FROM radreply WHERE UserName = ?'
668 $sth->execute($username)
669 or die "can't delete from radreply table: ". $sth->errstr;
674 =item replace OLD_RECORD
676 Replaces OLD_RECORD with this one in the database. If there is an error,
677 returns the error, otherwise returns false.
679 If the configuration value (see L<FS::Conf>) shellmachine exists, and the
680 dir field has changed, the command(s) specified in the shellmachine-usermod
681 configuraiton file are added to the job queue (see L<FS::queue> and
682 L<freeside-queued>) to be executed on shellmachine via ssh. This behavior can
683 be surpressed by setting $FS::svc-acct::nossh_hack true. If the
684 shellmachine-userdel configuration file does not exist or is empty,
686 [ -d $old_dir ] && mv $old_dir $new_dir || (
690 find . -depth -print | cpio -pdm $new_dir;
692 chown -R $uid.$gid $new_dir;
696 is the default. This behaviour can be surpressed by setting
697 $FS::svc_acct::nossh_hack true.
702 my ( $new, $old ) = ( shift, shift );
705 return "Username in use"
706 if $old->username ne $new->username &&
707 qsearchs( 'svc_acct', { 'username' => $new->username,
708 'domsvc' => $new->domsvc,
711 #no warnings 'numeric'; #alas, a 5.006-ism
713 return "Can't change uid!" if $old->uid != $new->uid;
716 return "can't change username using Cyrus"
717 if $cyrus_server && $old->username ne $new->username;
719 #change homdir when we change username
720 $new->setfield('dir', '') if $old->username ne $new->username;
722 local $SIG{HUP} = 'IGNORE';
723 local $SIG{INT} = 'IGNORE';
724 local $SIG{QUIT} = 'IGNORE';
725 local $SIG{TERM} = 'IGNORE';
726 local $SIG{TSTP} = 'IGNORE';
727 local $SIG{PIPE} = 'IGNORE';
729 my $oldAutoCommit = $FS::UID::AutoCommit;
730 local $FS::UID::AutoCommit = 0;
733 $error = $new->SUPER::replace($old);
735 $dbh->rollback if $oldAutoCommit;
736 return $error if $error;
739 my ( $old_dir, $new_dir, $uid, $gid ) = (
740 $old->getfield('dir'),
741 $new->getfield('dir'),
742 $new->getfield('uid'),
743 $new->getfield('gid'),
745 if ( $old_dir && $new_dir && $old_dir ne $new_dir && ! $nossh_hack ) {
746 my $queue = new FS::queue {
747 'svcnum' => $new->svcnum,
748 'job' => 'Net::SSH::ssh_cmd'
750 $error = $queue->insert("root\@$shellmachine", eval qq("$usermod") );
752 $dbh->rollback if $oldAutoCommit;
753 return "queueing job (transaction rolled back): $error";
757 if ( $cp_server && $old->username ne $new->username ) {
758 my $queue = new FS::queue {
759 'svcnum' => $new->svcnum,
760 'job' => 'FS::svc_acct::cp_rename'
762 $error = $queue->insert( $old->username, $new->username );
764 $dbh->rollback if $oldAutoCommit;
765 return "queueing job (transaction rolled back): $error";
769 if ( $cp_server && $old->_password ne $new->_password ) {
770 my $queue = new FS::queue {
771 'svcnum' => $new->svcnum,
772 'job' => 'FS::svc_acct::cp_change'
774 $error = $queue->insert( $new->username, $new->_password );
776 $dbh->rollback if $oldAutoCommit;
777 return "queueing job (transaction rolled back): $error";
781 if ( $icradius_dbh ) {
782 my $queue = new FS::queue {
783 'svcnum' => $new->svcnum,
784 'job' => 'FS::svc_acct::icradius_rc_replace'
786 $error = $queue->insert( $new->username,
790 $dbh->rollback if $oldAutoCommit;
791 return "queueing job (transaction rolled back): $error";
795 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
799 sub icradius_rc_replace {
800 my( $username, $new_password ) = @_;
802 my $sth = $icradius_dbh->prepare(
803 "UPDATE radcheck SET Value = ? WHERE UserName = ? and Attribute = ?"
805 $sth->execute($new_password, $username, 'Password' )
806 or die "can't update radcheck table: ". $sth->errstr;
812 my ( $old_username, $new_username );
814 my $app = new Net::APP ( $cp_server,
816 Password => $cp_pass,
822 $app->rename_mailbox(
824 Old_Mailbox => $old_username,
825 New_Mailbox => $new_username,
828 die $app->message unless $app->ok;
833 my ( $username, $password );
835 my $app = new Net::APP ( $cp_server,
837 Password => $cp_pass,
843 $app->change_mailbox(
845 Mailbox => $username,
846 Password => $password,
849 die $app->message unless $app->ok;
855 Suspends this account by prefixing *SUSPENDED* to the password. If there is an
856 error, returns the error, otherwise returns false.
858 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
864 my %hash = $self->hash;
865 unless ( $hash{_password} =~ /^\*SUSPENDED\* /
866 || $hash{_password} eq '*'
868 $hash{_password} = '*SUSPENDED* '.$hash{_password};
869 my $new = new FS::svc_acct ( \%hash );
870 $new->replace($self);
872 ''; #no error (already suspended)
878 Unsuspends this account by removing *SUSPENDED* from the password. If there is
879 an error, returns the error, otherwise returns false.
881 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
887 my %hash = $self->hash;
888 if ( $hash{_password} =~ /^\*SUSPENDED\* (.*)$/ ) {
889 $hash{_password} = $1;
890 my $new = new FS::svc_acct ( \%hash );
891 $new->replace($self);
893 ''; #no error (already unsuspended)
899 Just returns false (no error) for now.
901 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
905 Checks all fields to make sure this is a valid service. If there is an error,
906 returns the error, otherwise returns false. Called by the insert and replace
909 Sets any fixed values; see L<FS::part_svc>.
916 my($recref) = $self->hashref;
918 my $x = $self->setfixed;
919 return $x unless ref($x);
922 my $error = $self->ut_numbern('svcnum')
923 || $self->ut_number('domsvc')
925 return $error if $error;
927 my $ulen = $usernamemax || $self->dbdef_table->column('username')->length;
928 if ( $username_uppercase ) {
929 $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/i
930 or return "Illegal username: ". $recref->{username};
931 $recref->{username} = $1;
933 $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/
934 or return "Illegal username: ". $recref->{username};
935 $recref->{username} = $1;
938 if ( $username_letterfirst ) {
939 $recref->{username} =~ /^[a-z]/ or return "Illegal username";
940 } elsif ( $username_letter ) {
941 $recref->{username} =~ /[a-z]/ or return "Illegal username";
943 if ( $username_noperiod ) {
944 $recref->{username} =~ /\./ and return "Illegal username";
946 unless ( $username_ampersand ) {
947 $recref->{username} =~ /\&/ and return "Illegal username";
950 $recref->{popnum} =~ /^(\d*)$/ or return "Illegal popnum: ".$recref->{popnum};
951 $recref->{popnum} = $1;
952 return "Unknown popnum" unless
953 ! $recref->{popnum} ||
954 qsearchs('svc_acct_pop',{'popnum'=> $recref->{popnum} } );
956 unless ( $part_svc->part_svc_column('uid')->columnflag eq 'F' ) {
958 $recref->{uid} =~ /^(\d*)$/ or return "Illegal uid";
959 $recref->{uid} = $1 eq '' ? $self->unique('uid') : $1;
961 $recref->{gid} =~ /^(\d*)$/ or return "Illegal gid";
962 $recref->{gid} = $1 eq '' ? $recref->{uid} : $1;
963 #not all systems use gid=uid
964 #you can set a fixed gid in part_svc
966 return "Only root can have uid 0"
967 if $recref->{uid} == 0 && $recref->{username} ne 'root';
969 # $error = $self->ut_textn('finger');
970 # return $error if $error;
971 $self->getfield('finger') =~
972 /^([\w \t\!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\*\<\>]*)$/
973 or return "Illegal finger: ". $self->getfield('finger');
974 $self->setfield('finger', $1);
976 $recref->{dir} =~ /^([\/\w\-\.\&]*)$/
977 or return "Illegal directory";
979 return "Illegal directory"
980 if $recref->{dir} =~ /(^|\/)\.+(\/|$)/; #no .. component
981 return "Illegal directory"
982 if $recref->{dir} =~ /\&/ && ! $username_ampersand;
983 unless ( $recref->{dir} ) {
984 $recref->{dir} = $dir_prefix . '/';
985 if ( $dirhash > 0 ) {
986 for my $h ( 1 .. $dirhash ) {
987 $recref->{dir} .= substr($recref->{username}, $h-1, 1). '/';
989 } elsif ( $dirhash < 0 ) {
990 for my $h ( reverse $dirhash .. -1 ) {
991 $recref->{dir} .= substr($recref->{username}, $h, 1). '/';
994 $recref->{dir} .= $recref->{username};
998 unless ( $recref->{username} eq 'sync' ) {
999 if ( grep $_ eq $recref->{shell}, @shells ) {
1000 $recref->{shell} = (grep $_ eq $recref->{shell}, @shells)[0];
1002 return "Illegal shell \`". $self->shell. "\'; ".
1003 $conf->dir. "/shells contains: @shells";
1006 $recref->{shell} = '/bin/sync';
1009 $recref->{quota} =~ /^(\d*)$/ or return "Illegal quota (unimplemented)";
1010 $recref->{quota} = $1;
1013 $recref->{gid} ne '' ?
1014 return "Can't have gid without uid" : ( $recref->{gid}='' );
1015 $recref->{finger} ne '' ?
1016 return "Can't have finger-name without uid" : ( $recref->{finger}='' );
1017 $recref->{dir} ne '' ?
1018 return "Can't have directory without uid" : ( $recref->{dir}='' );
1019 $recref->{shell} ne '' ?
1020 return "Can't have shell without uid" : ( $recref->{shell}='' );
1021 $recref->{quota} ne '' ?
1022 return "Can't have quota without uid" : ( $recref->{quota}='' );
1025 unless ( $part_svc->part_svc_column('slipip')->columnflag eq 'F' ) {
1026 unless ( $recref->{slipip} eq '0e0' ) {
1027 $recref->{slipip} =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/
1028 or return "Illegal slipip". $self->slipip;
1029 $recref->{slipip} = $1;
1031 $recref->{slipip} = '0e0';
1036 #arbitrary RADIUS stuff; allow ut_textn for now
1037 foreach ( grep /^radius_/, fields('svc_acct') ) {
1038 $self->ut_textn($_);
1041 #generate a password if it is blank
1042 $recref->{_password} = join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) )
1043 unless ( $recref->{_password} );
1045 #if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{4,16})$/ ) {
1046 if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{$passwordmin,$passwordmax})$/ ) {
1047 $recref->{_password} = $1.$3;
1048 #uncomment this to encrypt password immediately upon entry, or run
1049 #bin/crypt_pw in cron to give new users a window during which their
1050 #password is available to techs, for faxing, etc. (also be aware of
1052 #$recref->{password} = $1.
1053 # crypt($3,$saltset[int(rand(64))].$saltset[int(rand(64))]
1055 } elsif ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([\w\.\/\$]{13,34})$/ ) {
1056 $recref->{_password} = $1.$3;
1057 } elsif ( $recref->{_password} eq '*' ) {
1058 $recref->{_password} = '*';
1059 } elsif ( $recref->{_password} eq '!!' ) {
1060 $recref->{_password} = '!!';
1062 #return "Illegal password";
1063 return "Illegal password: ". $recref->{_password};
1071 Depriciated, use radius_reply instead.
1076 carp "FS::svc_acct::radius depriciated, use radius_reply";
1077 $_[0]->radius_reply;
1082 Returns key/value pairs, suitable for assigning to a hash, for any RADIUS
1083 reply attributes of this record.
1085 Note that this is now the preferred method for reading RADIUS attributes -
1086 accessing the columns directly is discouraged, as the column names are
1087 expected to change in the future.
1096 my($column, $attrib) = ($1, $2);
1097 #$attrib =~ s/_/\-/g;
1098 ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) );
1099 } grep { /^radius_/ && $self->getfield($_) } fields( $self->table );
1100 if ( $self->ip && $self->ip ne '0e0' ) {
1101 $reply{'Framed-IP-Address'} = $self->ip;
1108 Returns key/value pairs, suitable for assigning to a hash, for any RADIUS
1109 check attributes of this record.
1111 Accessing RADIUS attributes directly is not supported and will break in the
1120 my($column, $attrib) = ($1, $2);
1121 #$attrib =~ s/_/\-/g;
1122 ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) );
1123 } grep { /^rc_/ && $self->getfield($_) } fields( $self->table );
1128 Returns the domain associated with this account.
1134 if ( $self->domsvc ) {
1135 #$self->svc_domain->domain;
1136 my $svc_domain = $self->svc_domain
1137 or die "no svc_domain.svcnum for svc_acct.domsvc ". $self->domsvc;
1138 $svc_domain->domain;
1140 $mydomain or die "svc_acct.domsvc is null and no legacy domain config file";
1146 Returns the FS::svc_domain record for this account's domain (see
1154 ? $self->{'_domsvc'}
1155 : qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } );
1160 Returns the FS::cust_svc record for this account (see L<FS::cust_svc>).
1164 qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
1169 Returns an email address associated with the account.
1175 $self->username. '@'. $self->domain;
1178 =item seconds_since TIMESTAMP
1180 Returns the number of seconds this account has been online since TIMESTAMP.
1183 TIMESTAMP is specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
1184 L<Time::Local> and L<Date::Parse> for conversion functions.
1188 #note: POD here, implementation in FS::cust_svc
1191 $self->cust_svc->seconds_since(@_);
1198 The $recref stuff in sub check should be cleaned up.
1200 The suspend, unsuspend and cancel methods update the database, but not the
1201 current object. This is probably a bug as it's unexpected and
1206 L<FS::svc_Common>, edit/part_svc.cgi from an installed web interface,
1207 export.html from the base documentation, L<FS::Record>, L<FS::Conf>,
1208 L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>, L<FS::queue>,
1209 L<freeside-queued>), L<Net::SSH>, L<ssh>, L<FS::svc_acct_pop>,
1210 schema.html from the base documentation.