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 { 'job' => 'FS::svc_acct::ssh' };
285 $error = $queue->insert("root\@$shellmachine", eval qq("$useradd") );
287 $dbh->rollback if $oldAutoCommit;
288 return "queueing job (transaction rolled back): $error";
292 if ( $cyrus_server ) {
293 my $queue = new FS::queue { 'job' => 'FS::svc_acct::cyrus_insert' };
294 $error = $queue->insert($self->username, $self->quota);
296 $dbh->rollback if $oldAutoCommit;
297 return "queueing job (transaction rolled back): $error";
302 my $queue = new FS::queue { 'job' => 'FS::svc_acct::cp_insert' };
303 $error = $queue->insert($self->username, $self->_password);
305 $dbh->rollback if $oldAutoCommit;
306 return "queueing job (transaction rolled back): $error";
310 if ( $icradius_dbh ) {
313 new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_insert' };
314 $error = $radcheck_queue->insert( $self->username,
319 $dbh->rollback if $oldAutoCommit;
320 return "queueing job (transaction rolled back): $error";
324 new FS::queue { 'job' => 'FS::svc_acct::icradius_rr_insert' };
325 $error = $radreply_queue->insert( $self->username,
330 $dbh->rollback if $oldAutoCommit;
331 return "queueing job (transaction rolled back): $error";
336 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
341 my( $username, $quota ) = @_;
343 warn "cyrus_insert: starting for user $username, quota $quota\n";
345 warn "cyrus_insert: connecting to $cyrus_server\n";
346 my $client = Cyrus::IMAP::Admin->new($cyrus_server);
348 warn "cyrus_insert: authentication as $cyrus_admin_user\n";
349 $client->authenticate(
350 -user => $cyrus_admin_user,
351 -mechanism => "login",
352 -password => $cyrus_admin_pass
355 warn "cyrus_insert: creating user.$username\n";
356 my $rc = $client->create("user.$username");
357 my $error = $client->error;
358 die "cyrus_insert: error creating user.$username: $error" if $error;
360 warn "cyrus_insert: setacl user.$username, $username => all\n";
361 $rc = $client->setacl("user.$username", $username => 'all' );
362 $error = $client->error;
363 die "cyrus_insert: error setacl user.$username: $error" if $error;
366 warn "cyrus_insert: setquota user.$username, STORAGE => $quota\n";
367 $rc = $client->setquota("user.$username", 'STORAGE' => $quota );
368 $error = $client->error;
369 die "cyrus_insert: error setquota user.$username: $error" if $error;
376 my( $username, $password ) = @_;
378 my $app = new Net::APP ( $cp_server,
380 Password => $cp_pass,
386 $app->create_mailbox(
387 Mailbox => $username,
388 Password => $password,
389 Workgroup => $cp_workgroup,
393 die $app->message unless $app->ok;
396 sub icradius_rc_insert {
397 my( $username, $password, %radcheck ) = @_;
399 my $sth = $icradius_dbh->prepare(
400 "INSERT INTO radcheck ( id, UserName, Attribute, Value ) VALUES ( ".
401 join(", ", map { $icradius_dbh->quote($_) } (
408 $sth->execute or die "can't insert into radcheck table: ". $sth->errstr;
410 foreach my $attribute ( keys %radcheck ) {
411 my $sth = $icradius_dbh->prepare(
412 "INSERT INTO radcheck ( id, UserName, Attribute, Value ) VALUES ( ".
413 join(", ", map { $icradius_dbh->quote($_) } (
417 $radcheck{$attribute},
420 $sth->execute or die "can't insert into radcheck table: ". $sth->errstr;
426 sub icradius_rr_insert {
427 my( $username, $password, %radreply ) = @_;
429 foreach my $attribute ( keys %radreply ) {
430 my $sth = $icradius_dbh->prepare(
431 "INSERT INTO radreply ( id, UserName, Attribute, Value ) VALUES ( ".
432 join(", ", map { $icradius_dbh->quote($_) } (
436 $radreply{$attribute},
439 $sth->execute or die "can't insert into radreply table: ". $sth->errstr;
447 Deletes this account from the database. If there is an error, returns the
448 error, otherwise returns false.
450 The corresponding FS::cust_svc record will be deleted as well.
452 If the configuration value (see L<FS::Conf>) shellmachine exists, the
453 command(s) specified in the shellmachine-userdel configuration file are
454 added to the job queue (see L<FS::queue> and L<freeside-queued>) to be executed
455 on shellmachine via ssh. This behavior can be surpressed by setting
456 $FS::svc_acct::nossh_hack true. If the shellmachine-userdel configuration
461 is the default. If the shellmachine-userdel configuration file exists but
466 is the default instead. Otherwise the contents of the file are treated as a
467 double-quoted perl string, with the following variables available:
470 (TODOC: cyrus config file)
477 if ( defined( $FS::Record::dbdef->table('svc_acct_sm') ) ) {
478 return "Can't delete an account which has (svc_acct_sm) mail aliases!"
479 if $self->uid && qsearch( 'svc_acct_sm', { 'domuid' => $self->uid } );
482 return "Can't delete an account which is a (svc_forward) source!"
483 if qsearch( 'svc_forward', { 'srcsvc' => $self->svcnum } );
485 return "Can't delete an account which is a (svc_forward) destination!"
486 if qsearch( 'svc_forward', { 'dstsvc' => $self->svcnum } );
488 return "Can't delete an account with (svc_www) web service!"
489 if qsearch( 'svc_www', { 'usersvc' => $self->usersvc } );
491 # what about records in session ?
493 local $SIG{HUP} = 'IGNORE';
494 local $SIG{INT} = 'IGNORE';
495 local $SIG{QUIT} = 'IGNORE';
496 local $SIG{TERM} = 'IGNORE';
497 local $SIG{TSTP} = 'IGNORE';
498 local $SIG{PIPE} = 'IGNORE';
500 my $oldAutoCommit = $FS::UID::AutoCommit;
501 local $FS::UID::AutoCommit = 0;
504 foreach my $cust_main_invoice (
505 qsearch( 'cust_main_invoice', { 'dest' => $self->svcnum } )
507 unless ( defined($cust_main_invoice) ) {
508 warn "WARNING: something's wrong with qsearch";
511 my %hash = $cust_main_invoice->hash;
512 $hash{'dest'} = $self->email;
513 my $new = new FS::cust_main_invoice \%hash;
514 my $error = $new->replace($cust_main_invoice);
516 $dbh->rollback if $oldAutoCommit;
521 foreach my $svc_domain (
522 qsearch( 'svc_domain', { 'catchall' => $self->svcnum } )
524 my %hash = new FS::svc_domain->hash;
525 $hash{'catchall'} = '';
526 my $new = new FS::svc_domain \%hash;
527 my $error = $new->replace($svc_domain);
529 $dbh->rollback if $oldAutoCommit;
534 my $error = $self->SUPER::delete;
536 $dbh->rollback if $oldAutoCommit;
540 my( $username, $dir ) = (
544 if ( $username && $shellmachine && ! $nossh_hack ) {
545 my $queue = new FS::queue { 'job' => 'FS::svc_acct::ssh' };
546 $error = $queue->insert("root\@$shellmachine", eval qq("$userdel") );
548 $dbh->rollback if $oldAutoCommit;
549 return "queueing job (transaction rolled back): $error";
554 if ( $cyrus_server ) {
555 my $queue = new FS::queue { 'job' => 'FS::svc_acct::cyrus_delete' };
556 $error = $queue->insert($self->username);
558 $dbh->rollback if $oldAutoCommit;
559 return "queueing job (transaction rolled back): $error";
564 my $queue = new FS::queue { 'job' => 'FS::svc_acct::cp_delete' };
565 $error = $queue->insert($self->username);
567 $dbh->rollback if $oldAutoCommit;
568 return "queueing job (transaction rolled back): $error";
572 if ( $icradius_dbh ) {
575 new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_delete' };
576 $error = $radcheck_queue->insert( $self->username );
578 $dbh->rollback if $oldAutoCommit;
579 return "queueing job (transaction rolled back): $error";
583 new FS::queue { 'job' => 'FS::svc_acct::icradius_rr_delete' };
584 $error = $radreply_queue->insert( $self->username );
586 $dbh->rollback if $oldAutoCommit;
587 return "queueing job (transaction rolled back): $error";
592 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
597 my $username = shift;
599 my $client = Cyrus::IMAP::Admin->new($cyrus_server);
600 $client->authenticate(
601 -user => $cyrus_admin_user,
602 -mechanism => "login",
603 -password => $cyrus_admin_pass
606 my $rc = $client->setacl("user.$username", $cyrus_admin_user => 'all' );
607 my $error = $client->error;
608 die $error if $error;
610 $rc = $client->delete("user.$username");
611 $error = $client->error;
612 die $error if $error;
618 my( $username ) = @_;
619 my $app = new Net::APP ( $cp_server,
621 Password => $cp_pass,
627 $app->delete_mailbox(
628 Mailbox => $username,
632 die $app->message unless $app->ok;
635 sub icradius_rc_delete {
636 my $username = shift;
638 my $sth = $icradius_dbh->prepare(
639 'DELETE FROM radcheck WHERE UserName = ?'
641 $sth->execute($username)
642 or die "can't delete from radcheck table: ". $sth->errstr;
647 sub icradius_rr_delete {
648 my $username = shift;
650 my $sth = $icradius_dbh->prepare(
651 'DELETE FROM radreply WHERE UserName = ?'
653 $sth->execute($username)
654 or die "can't delete from radreply table: ". $sth->errstr;
659 =item replace OLD_RECORD
661 Replaces OLD_RECORD with this one in the database. If there is an error,
662 returns the error, otherwise returns false.
664 If the configuration value (see L<FS::Conf>) shellmachine exists, and the
665 dir field has changed, the command(s) specified in the shellmachine-usermod
666 configuraiton file are added to the job queue (see L<FS::queue> and
667 L<freeside-queued>) to be executed on shellmachine via ssh. This behavior can
668 be surpressed by setting $FS::svc-acct::nossh_hack true. If the
669 shellmachine-userdel configuration file does not exist or is empty,
671 [ -d $old_dir ] && mv $old_dir $new_dir || (
675 find . -depth -print | cpio -pdm $new_dir;
677 chown -R $uid.$gid $new_dir;
681 is the default. This behaviour can be surpressed by setting
682 $FS::svc_acct::nossh_hack true.
687 my ( $new, $old ) = ( shift, shift );
690 return "Username in use"
691 if $old->username ne $new->username &&
692 qsearchs( 'svc_acct', { 'username' => $new->username,
693 'domsvc' => $new->domsvc,
696 #no warnings 'numeric'; #alas, a 5.006-ism
698 return "Can't change uid!" if $old->uid != $new->uid;
701 return "can't change username using Cyrus"
702 if $cyrus_server && $old->username ne $new->username;
704 #change homdir when we change username
705 $new->setfield('dir', '') if $old->username ne $new->username;
707 local $SIG{HUP} = 'IGNORE';
708 local $SIG{INT} = 'IGNORE';
709 local $SIG{QUIT} = 'IGNORE';
710 local $SIG{TERM} = 'IGNORE';
711 local $SIG{TSTP} = 'IGNORE';
712 local $SIG{PIPE} = 'IGNORE';
714 my $oldAutoCommit = $FS::UID::AutoCommit;
715 local $FS::UID::AutoCommit = 0;
718 $error = $new->SUPER::replace($old);
720 $dbh->rollback if $oldAutoCommit;
721 return $error if $error;
724 my ( $old_dir, $new_dir, $uid, $gid ) = (
725 $old->getfield('dir'),
726 $new->getfield('dir'),
727 $new->getfield('uid'),
728 $new->getfield('gid'),
730 if ( $old_dir && $new_dir && $old_dir ne $new_dir && ! $nossh_hack ) {
731 my $queue = new FS::queue { 'job' => 'FS::svc_acct::ssh' };
732 $error = $queue->insert("root\@$shellmachine", eval qq("$usermod") );
734 $dbh->rollback if $oldAutoCommit;
735 return "queueing job (transaction rolled back): $error";
739 if ( $cp_server && $old->username ne $new->username ) {
740 my $queue = new FS::queue { 'job' => 'FS::svc_acct::cp_rename' };
741 $error = $queue->insert( $old->username, $new->username );
743 $dbh->rollback if $oldAutoCommit;
744 return "queueing job (transaction rolled back): $error";
748 if ( $cp_server && $old->_password ne $new->_password ) {
749 my $queue = new FS::queue { 'job' => 'FS::svc_acct::cp_change' };
750 $error = $queue->insert( $new->username, $new->_password );
752 $dbh->rollback if $oldAutoCommit;
753 return "queueing job (transaction rolled back): $error";
757 if ( $icradius_dbh ) {
758 my $queue = new FS::queue { 'job' => 'FS::svc_acct::icradius_rc_replace' };
759 $error = $queue->insert( $new->username,
763 $dbh->rollback if $oldAutoCommit;
764 return "queueing job (transaction rolled back): $error";
768 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
772 sub icradius_rc_replace {
773 my( $username, $new_password ) = @_;
775 my $sth = $icradius_dbh->prepare(
776 "UPDATE radcheck SET Value = ? WHERE UserName = ? and Attribute = ?"
778 $sth->execute($new_password, $username, 'Password' )
779 or die "can't update radcheck table: ". $sth->errstr;
785 my ( $old_username, $new_username );
787 my $app = new Net::APP ( $cp_server,
789 Password => $cp_pass,
795 $app->rename_mailbox(
797 Old_Mailbox => $old_username,
798 New_Mailbox => $new_username,
801 die $app->message unless $app->ok;
806 my ( $username, $password );
808 my $app = new Net::APP ( $cp_server,
810 Password => $cp_pass,
816 $app->change_mailbox(
818 Mailbox => $username,
819 Password => $password,
822 die $app->message unless $app->ok;
828 Suspends this account by prefixing *SUSPENDED* to the password. If there is an
829 error, returns the error, otherwise returns false.
831 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
837 my %hash = $self->hash;
838 unless ( $hash{_password} =~ /^\*SUSPENDED\* /
839 || $hash{_password} eq '*'
841 $hash{_password} = '*SUSPENDED* '.$hash{_password};
842 my $new = new FS::svc_acct ( \%hash );
843 $new->replace($self);
845 ''; #no error (already suspended)
851 Unsuspends this account by removing *SUSPENDED* from the password. If there is
852 an error, returns the error, otherwise returns false.
854 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
860 my %hash = $self->hash;
861 if ( $hash{_password} =~ /^\*SUSPENDED\* (.*)$/ ) {
862 $hash{_password} = $1;
863 my $new = new FS::svc_acct ( \%hash );
864 $new->replace($self);
866 ''; #no error (already unsuspended)
872 Just returns false (no error) for now.
874 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
878 Checks all fields to make sure this is a valid service. If there is an error,
879 returns the error, otherwise returns false. Called by the insert and replace
882 Sets any fixed values; see L<FS::part_svc>.
889 my($recref) = $self->hashref;
891 my $x = $self->setfixed;
892 return $x unless ref($x);
895 my $error = $self->ut_numbern('svcnum')
896 || $self->ut_number('domsvc')
898 return $error if $error;
900 my $ulen = $usernamemax || $self->dbdef_table->column('username')->length;
901 if ( $username_uppercase ) {
902 $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/i
903 or return "Illegal username: ". $recref->{username};
904 $recref->{username} = $1;
906 $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/
907 or return "Illegal username: ". $recref->{username};
908 $recref->{username} = $1;
911 if ( $username_letterfirst ) {
912 $recref->{username} =~ /^[a-z]/ or return "Illegal username";
913 } elsif ( $username_letter ) {
914 $recref->{username} =~ /[a-z]/ or return "Illegal username";
916 if ( $username_noperiod ) {
917 $recref->{username} =~ /\./ and return "Illegal username";
919 unless ( $username_ampersand ) {
920 $recref->{username} =~ /\&/ and return "Illegal username";
923 $recref->{popnum} =~ /^(\d*)$/ or return "Illegal popnum: ".$recref->{popnum};
924 $recref->{popnum} = $1;
925 return "Unknown popnum" unless
926 ! $recref->{popnum} ||
927 qsearchs('svc_acct_pop',{'popnum'=> $recref->{popnum} } );
929 unless ( $part_svc->part_svc_column('uid')->columnflag eq 'F' ) {
931 $recref->{uid} =~ /^(\d*)$/ or return "Illegal uid";
932 $recref->{uid} = $1 eq '' ? $self->unique('uid') : $1;
934 $recref->{gid} =~ /^(\d*)$/ or return "Illegal gid";
935 $recref->{gid} = $1 eq '' ? $recref->{uid} : $1;
936 #not all systems use gid=uid
937 #you can set a fixed gid in part_svc
939 return "Only root can have uid 0"
940 if $recref->{uid} == 0 && $recref->{username} ne 'root';
942 # $error = $self->ut_textn('finger');
943 # return $error if $error;
944 $self->getfield('finger') =~
945 /^([\w \t\!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\*\<\>]*)$/
946 or return "Illegal finger: ". $self->getfield('finger');
947 $self->setfield('finger', $1);
949 $recref->{dir} =~ /^([\/\w\-\.\&]*)$/
950 or return "Illegal directory";
952 return "Illegal directory"
953 if $recref->{dir} =~ /(^|\/)\.+(\/|$)/; #no .. component
954 return "Illegal directory"
955 if $recref->{dir} =~ /\&/ && ! $username_ampersand;
956 unless ( $recref->{dir} ) {
957 $recref->{dir} = $dir_prefix . '/';
958 if ( $dirhash > 0 ) {
959 for my $h ( 1 .. $dirhash ) {
960 $recref->{dir} .= substr($recref->{username}, $h-1, 1). '/';
962 } elsif ( $dirhash < 0 ) {
963 for my $h ( reverse $dirhash .. -1 ) {
964 $recref->{dir} .= substr($recref->{username}, $h, 1). '/';
967 $recref->{dir} .= $recref->{username};
971 unless ( $recref->{username} eq 'sync' ) {
972 if ( grep $_ eq $recref->{shell}, @shells ) {
973 $recref->{shell} = (grep $_ eq $recref->{shell}, @shells)[0];
975 return "Illegal shell \`". $self->shell. "\'; ".
976 $conf->dir. "/shells contains: @shells";
979 $recref->{shell} = '/bin/sync';
982 $recref->{quota} =~ /^(\d*)$/ or return "Illegal quota (unimplemented)";
983 $recref->{quota} = $1;
986 $recref->{gid} ne '' ?
987 return "Can't have gid without uid" : ( $recref->{gid}='' );
988 $recref->{finger} ne '' ?
989 return "Can't have finger-name without uid" : ( $recref->{finger}='' );
990 $recref->{dir} ne '' ?
991 return "Can't have directory without uid" : ( $recref->{dir}='' );
992 $recref->{shell} ne '' ?
993 return "Can't have shell without uid" : ( $recref->{shell}='' );
994 $recref->{quota} ne '' ?
995 return "Can't have quota without uid" : ( $recref->{quota}='' );
998 unless ( $part_svc->part_svc_column('slipip')->columnflag eq 'F' ) {
999 unless ( $recref->{slipip} eq '0e0' ) {
1000 $recref->{slipip} =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/
1001 or return "Illegal slipip". $self->slipip;
1002 $recref->{slipip} = $1;
1004 $recref->{slipip} = '0e0';
1009 #arbitrary RADIUS stuff; allow ut_textn for now
1010 foreach ( grep /^radius_/, fields('svc_acct') ) {
1011 $self->ut_textn($_);
1014 #generate a password if it is blank
1015 $recref->{_password} = join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) )
1016 unless ( $recref->{_password} );
1018 #if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{4,16})$/ ) {
1019 if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{$passwordmin,$passwordmax})$/ ) {
1020 $recref->{_password} = $1.$3;
1021 #uncomment this to encrypt password immediately upon entry, or run
1022 #bin/crypt_pw in cron to give new users a window during which their
1023 #password is available to techs, for faxing, etc. (also be aware of
1025 #$recref->{password} = $1.
1026 # crypt($3,$saltset[int(rand(64))].$saltset[int(rand(64))]
1028 } elsif ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([\w\.\/\$]{13,34})$/ ) {
1029 $recref->{_password} = $1.$3;
1030 } elsif ( $recref->{_password} eq '*' ) {
1031 $recref->{_password} = '*';
1032 } elsif ( $recref->{_password} eq '!!' ) {
1033 $recref->{_password} = '!!';
1035 #return "Illegal password";
1036 return "Illegal password: ". $recref->{_password};
1044 Depriciated, use radius_reply instead.
1049 carp "FS::svc_acct::radius depriciated, use radius_reply";
1050 $_[0]->radius_reply;
1055 Returns key/value pairs, suitable for assigning to a hash, for any RADIUS
1056 reply attributes of this record.
1058 Note that this is now the preferred method for reading RADIUS attributes -
1059 accessing the columns directly is discouraged, as the column names are
1060 expected to change in the future.
1069 my($column, $attrib) = ($1, $2);
1070 #$attrib =~ s/_/\-/g;
1071 ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) );
1072 } grep { /^radius_/ && $self->getfield($_) } fields( $self->table );
1073 if ( $self->ip && $self->ip ne '0e0' ) {
1074 $reply{'Framed-IP-Address'} = $self->ip;
1081 Returns key/value pairs, suitable for assigning to a hash, for any RADIUS
1082 check attributes of this record.
1084 Accessing RADIUS attributes directly is not supported and will break in the
1093 my($column, $attrib) = ($1, $2);
1094 #$attrib =~ s/_/\-/g;
1095 ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) );
1096 } grep { /^rc_/ && $self->getfield($_) } fields( $self->table );
1101 Returns the domain associated with this account.
1107 if ( $self->domsvc ) {
1108 #$self->svc_domain->domain;
1109 my $svc_domain = $self->svc_domain
1110 or die "no svc_domain.svcnum for svc_acct.domsvc ". $self->domsvc;
1111 $svc_domain->domain;
1113 $mydomain or die "svc_acct.domsvc is null and no legacy domain config file";
1119 Returns the FS::svc_domain record for this account's domain (see
1127 ? $self->{'_domsvc'}
1128 : qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } );
1133 Returns the FS::cust_svc record for this account (see L<FS::cust_svc>).
1137 qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
1142 Returns an email address associated with the account.
1148 $self->username. '@'. $self->domain;
1151 =item seconds_since TIMESTAMP
1153 Returns the number of seconds this account has been online since TIMESTAMP.
1156 TIMESTAMP is specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
1157 L<Time::Local> and L<Date::Parse> for conversion functions.
1161 #note: POD here, implementation in FS::cust_svc
1164 $self->cust_svc->seconds_since(@_);
1172 my ( $host, @cmd_and_args ) = @_;
1175 my $reader = IO::File->new();
1176 my $writer = IO::File->new();
1177 my $error = IO::File->new();
1179 &Net::SSH::sshopen3( $host, $reader, $writer, $error, @cmd_and_args) or die $!;
1182 my $output_stream = <$writer>;
1183 my $error_stream = <$error>;
1184 if ( length $error_stream ) {
1185 #warn "[FS::svc_acct::ssh] STDERR $error_stream";
1186 die "[FS::svc_acct::ssh] STDERR $error_stream";
1188 if ( length $output_stream ) {
1189 warn "[FS::svc_acct::ssh] STDOUT $output_stream";
1192 # &Net::SSH::ssh(@args,">>/usr/local/etc/freeside/sshoutput 2>&1");
1199 The $recref stuff in sub check should be cleaned up.
1201 The suspend, unsuspend and cancel methods update the database, but not the
1202 current object. This is probably a bug as it's unexpected and
1207 L<FS::svc_Common>, edit/part_svc.cgi from an installed web interface,
1208 export.html from the base documentation, L<FS::Record>, L<FS::Conf>,
1209 L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>, L<FS::queue>,
1210 L<freeside-queued>), L<Net::SSH>, L<ssh>, L<FS::svc_acct_pop>,
1211 schema.html from the base documentation.