4 use vars qw( @ISA $nossh_hack $noexport_hack $conf
5 $dir_prefix @shells $usernamemin
6 $usernamemax $passwordmin $passwordmax
7 $username_ampersand $username_letter $username_letterfirst
8 $username_noperiod $username_uppercase
12 $rsync $ssh $exportdir $vpopdir);
16 use FS::UID qw( datasrc );
18 use FS::Record qw( qsearch qsearchs fields dbh );
24 use FS::cust_main_invoice;
28 use FS::radius_usergroup;
29 use FS::Msgcat qw(gettext);
31 @ISA = qw( FS::svc_Common );
33 #ask FS::UID to run this stuff for us later
34 $FS::UID::callback{'FS::svc_acct'} = sub {
38 $dir_prefix = $conf->config('home');
39 @shells = $conf->config('shells');
40 $usernamemin = $conf->config('usernamemin') || 2;
41 $usernamemax = $conf->config('usernamemax');
42 $passwordmin = $conf->config('passwordmin') || 6;
43 $passwordmax = $conf->config('passwordmax') || 8;
44 $username_letter = $conf->exists('username-letter');
45 $username_letterfirst = $conf->exists('username-letterfirst');
46 $username_noperiod = $conf->exists('username-noperiod');
47 $username_uppercase = $conf->exists('username-uppercase');
48 $username_ampersand = $conf->exists('username-ampersand');
49 $mydomain = $conf->config('domain');
51 $dirhash = $conf->config('dirhash') || 0;
52 $exportdir = "/usr/local/etc/freeside/export." . datasrc;
53 if ( $conf->exists('vpopmailmachines') ) {
54 my (@vpopmailmachines) = $conf->config('vpopmailmachines');
55 my ($machine, $dir, $uid, $gid) = split (/\s+/, $vpopmailmachines[0]);
62 @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' );
63 @pw_set = ( 'a'..'z', 'A'..'Z', '0'..'9', '(', ')', '#', '!', '.', ',' );
67 my ( $hashref, $cache ) = @_;
68 if ( $hashref->{'svc_acct_svcnum'} ) {
69 $self->{'_domsvc'} = FS::svc_domain->new( {
70 'svcnum' => $hashref->{'domsvc'},
71 'domain' => $hashref->{'svc_acct_domain'},
72 'catchall' => $hashref->{'svc_acct_catchall'},
79 FS::svc_acct - Object methods for svc_acct records
85 $record = new FS::svc_acct \%hash;
86 $record = new FS::svc_acct { 'column' => 'value' };
88 $error = $record->insert;
90 $error = $new_record->replace($old_record);
92 $error = $record->delete;
94 $error = $record->check;
96 $error = $record->suspend;
98 $error = $record->unsuspend;
100 $error = $record->cancel;
102 %hash = $record->radius;
104 %hash = $record->radius_reply;
106 %hash = $record->radius_check;
108 $domain = $record->domain;
110 $svc_domain = $record->svc_domain;
112 $email = $record->email;
114 $seconds_since = $record->seconds_since($timestamp);
118 An FS::svc_acct object represents an account. FS::svc_acct inherits from
119 FS::svc_Common. The following fields are currently supported:
123 =item svcnum - primary key (assigned automatcially for new accounts)
127 =item _password - generated if blank
129 =item sec_phrase - security phrase
131 =item popnum - Point of presence (see L<FS::svc_acct_pop>)
139 =item dir - set automatically if blank (and uid is not)
143 =item quota - (unimplementd)
145 =item slipip - IP address
149 =item domsvc - svcnum from svc_domain
151 =item radius_I<Radius_Attribute> - I<Radius-Attribute>
161 Creates a new account. To add the account to the database, see L<"insert">.
165 sub table { 'svc_acct'; }
169 Adds this account to the database. If there is an error, returns the error,
170 otherwise returns false.
172 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
173 defined. An FS::cust_svc record will be created and inserted.
175 The additional field I<usergroup> can optionally be defined; if so it should
176 contain an arrayref of group names. See L<FS::radius_usergroup>. (used in
177 sqlradius export only)
179 If the configuration value (see L<FS::Conf>) shellmachine exists, and the
180 username, uid, and dir fields are defined, the command(s) specified in
181 the shellmachine-useradd configuration are added to the job queue (see
182 L<FS::queue> and L<freeside-queued>) to be exectued on shellmachine via ssh.
183 This behaviour can be surpressed by setting $FS::svc_acct::nossh_hack true.
184 If the shellmachine-useradd configuration file does not exist,
186 useradd -d $dir -m -s $shell -u $uid $username
188 is the default. If the shellmachine-useradd configuration file exists but
191 cp -pr /etc/skel $dir; chown -R $uid.$gid $dir
193 is the default instead. Otherwise the contents of the file are treated as
194 a double-quoted perl string, with the following variables available:
195 $username, $uid, $gid, $dir, and $shell.
197 (TODOC: L<FS::queue> and L<freeside-queued>)
199 (TODOC: new exports! $noexport_hack)
207 local $SIG{HUP} = 'IGNORE';
208 local $SIG{INT} = 'IGNORE';
209 local $SIG{QUIT} = 'IGNORE';
210 local $SIG{TERM} = 'IGNORE';
211 local $SIG{TSTP} = 'IGNORE';
212 local $SIG{PIPE} = 'IGNORE';
214 my $oldAutoCommit = $FS::UID::AutoCommit;
215 local $FS::UID::AutoCommit = 0;
218 $error = $self->check;
219 return $error if $error;
221 return gettext('username_in_use'). ": ". $self->username
222 if qsearchs( 'svc_acct', { 'username' => $self->username,
223 'domsvc' => $self->domsvc,
226 if ( $self->svcnum ) {
227 my $cust_svc = qsearchs('cust_svc',{'svcnum'=>$self->svcnum});
228 unless ( $cust_svc ) {
229 $dbh->rollback if $oldAutoCommit;
230 return "no cust_svc record found for svcnum ". $self->svcnum;
232 $self->pkgnum($cust_svc->pkgnum);
233 $self->svcpart($cust_svc->svcpart);
236 my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
237 return "Unknown svcpart" unless $part_svc;
239 if $part_svc->part_svc_column('uid')->columnflag ne 'F'
240 && qsearchs( 'svc_acct', { 'uid' => $self->uid } )
241 && $self->username !~ /^(hyla)?fax$/
244 $error = $self->SUPER::insert;
246 $dbh->rollback if $oldAutoCommit;
250 if ( $self->usergroup ) {
251 foreach my $groupname ( @{$self->usergroup} ) {
252 my $radius_usergroup = new FS::radius_usergroup ( {
253 svcnum => $self->svcnum,
254 groupname => $groupname,
256 my $error = $radius_usergroup->insert;
258 $dbh->rollback if $oldAutoCommit;
265 unless ( $noexport_hack ) {
266 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
267 my $error = $part_export->export_insert($self);
269 $dbh->rollback if $oldAutoCommit;
270 return "exporting to ". $part_export->exporttype.
271 " (transaction rolled back): $error";
282 'svcnum' => $self->svcnum,
283 'job' => 'FS::svc_acct::vpopmail_insert'
285 $error = $vpopmail_queue->insert( $self->username,
286 crypt($self->_password,$saltset[int(rand(64))].$saltset[int(rand(64))]),
291 $dbh->rollback if $oldAutoCommit;
292 return "queueing job (transaction rolled back): $error";
297 #end of old-style exports
299 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
303 sub vpopmail_insert {
304 my( $username, $password, $domain, $vpopdir ) = @_;
306 (open(VPASSWD, ">>$exportdir/domains/$domain/vpasswd")
307 and flock(VPASSWD,LOCK_EX)
308 ) or die "can't open vpasswd file for $username\@$domain: $exportdir/domains/$domain/vpasswd";
309 print VPASSWD join(":",
315 "$vpopdir/domains/$domain/$username",
319 flock(VPASSWD,LOCK_UN);
322 mkdir "$exportdir/domains/$domain/$username", 0700 or die "can't create Maildir";
323 mkdir "$exportdir/domains/$domain/$username/Maildir", 0700 or die "can't create Maildir";
324 mkdir "$exportdir/domains/$domain/$username/Maildir/cur", 0700 or die "can't create Maildir";
325 mkdir "$exportdir/domains/$domain/$username/Maildir/new", 0700 or die "can't create Maildir";
326 mkdir "$exportdir/domains/$domain/$username/Maildir/tmp", 0700 or die "can't create Maildir";
328 my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_sync' };
329 my $error = $queue->insert;
330 die $error if $error;
337 my (@vpopmailmachines) = $conf->config('vpopmailmachines');
338 my ($machine, $dir, $uid, $gid) = split (/\s+/, $vpopmailmachines[0]);
341 my @args = ("$rsync", "-rlpt", "-e", "$ssh", "domains/", "vpopmail\@$machine:$vpopdir/domains/");
342 system {$args[0]} @args;
348 Deletes this account from the database. If there is an error, returns the
349 error, otherwise returns false.
351 The corresponding FS::cust_svc record will be deleted as well.
353 If the configuration value (see L<FS::Conf>) shellmachine exists, the
354 command(s) specified in the shellmachine-userdel configuration file are
355 added to the job queue (see L<FS::queue> and L<freeside-queued>) to be executed
356 on shellmachine via ssh. This behavior can be surpressed by setting
357 $FS::svc_acct::nossh_hack true. If the shellmachine-userdel configuration
362 is the default. If the shellmachine-userdel configuration file exists but
367 is the default instead. Otherwise the contents of the file are treated as a
368 double-quoted perl string, with the following variables available:
371 (TODOC: new exports! $noexport_hack)
378 if ( defined( $FS::Record::dbdef->table('svc_acct_sm') ) ) {
379 return "Can't delete an account which has (svc_acct_sm) mail aliases!"
380 if $self->uid && qsearch( 'svc_acct_sm', { 'domuid' => $self->uid } );
383 return "Can't delete an account which is a (svc_forward) source!"
384 if qsearch( 'svc_forward', { 'srcsvc' => $self->svcnum } );
386 return "Can't delete an account which is a (svc_forward) destination!"
387 if qsearch( 'svc_forward', { 'dstsvc' => $self->svcnum } );
389 return "Can't delete an account with (svc_www) web service!"
390 if qsearch( 'svc_www', { 'usersvc' => $self->usersvc } );
392 # what about records in session ? (they should refer to history table)
394 local $SIG{HUP} = 'IGNORE';
395 local $SIG{INT} = 'IGNORE';
396 local $SIG{QUIT} = 'IGNORE';
397 local $SIG{TERM} = 'IGNORE';
398 local $SIG{TSTP} = 'IGNORE';
399 local $SIG{PIPE} = 'IGNORE';
401 my $oldAutoCommit = $FS::UID::AutoCommit;
402 local $FS::UID::AutoCommit = 0;
405 foreach my $cust_main_invoice (
406 qsearch( 'cust_main_invoice', { 'dest' => $self->svcnum } )
408 unless ( defined($cust_main_invoice) ) {
409 warn "WARNING: something's wrong with qsearch";
412 my %hash = $cust_main_invoice->hash;
413 $hash{'dest'} = $self->email;
414 my $new = new FS::cust_main_invoice \%hash;
415 my $error = $new->replace($cust_main_invoice);
417 $dbh->rollback if $oldAutoCommit;
422 foreach my $svc_domain (
423 qsearch( 'svc_domain', { 'catchall' => $self->svcnum } )
425 my %hash = new FS::svc_domain->hash;
426 $hash{'catchall'} = '';
427 my $new = new FS::svc_domain \%hash;
428 my $error = $new->replace($svc_domain);
430 $dbh->rollback if $oldAutoCommit;
435 foreach my $radius_usergroup (
436 qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } )
438 my $error = $radius_usergroup->delete;
440 $dbh->rollback if $oldAutoCommit;
445 my $part_svc = $self->cust_svc->part_svc;
447 my $error = $self->SUPER::delete;
449 $dbh->rollback if $oldAutoCommit;
454 unless ( $noexport_hack ) {
455 foreach my $part_export ( $part_svc->part_export ) {
456 my $error = $part_export->export_delete($self);
458 $dbh->rollback if $oldAutoCommit;
459 return "exporting to ". $part_export->exporttype.
460 " (transaction rolled back): $error";
468 my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_delete' };
469 $error = $queue->insert( $self->username, $self->domain );
471 $dbh->rollback if $oldAutoCommit;
472 return "queueing job (transaction rolled back): $error";
477 #end of old-style exports
479 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
483 sub vpopmail_delete {
484 my( $username, $domain ) = @_;
486 (open(VPASSWD, "$exportdir/domains/$domain/vpasswd")
487 and flock(VPASSWD,LOCK_EX)
488 ) or die "can't open $exportdir/domains/$domain/vpasswd: $!";
490 open(VPASSWDTMP, ">$exportdir/domains/$domain/vpasswd.tmp")
491 or die "Can't open $exportdir/domains/$domain/vpasswd.tmp: $!";
494 my ($mailbox, $rest) = split(':', $_);
495 print VPASSWDTMP $_ unless $username eq $mailbox;
500 rename "$exportdir/domains/$domain/vpasswd.tmp", "$exportdir/domains/$domain/vpasswd"
501 or die "Can't rename $exportdir/domains/$domain/vpasswd.tmp: $!";
503 flock(VPASSWD,LOCK_UN);
506 rmtree "$exportdir/domains/$domain/$username" or die "can't destroy Maildir";
510 =item replace OLD_RECORD
512 Replaces OLD_RECORD with this one in the database. If there is an error,
513 returns the error, otherwise returns false.
515 The additional field I<usergroup> can optionally be defined; if so it should
516 contain an arrayref of group names. See L<FS::radius_usergroup>. (used in
517 sqlradius export only)
519 If the configuration value (see L<FS::Conf>) shellmachine exists, and the
520 dir field has changed, the command(s) specified in the shellmachine-usermod
521 configuraiton file are added to the job queue (see L<FS::queue> and
522 L<freeside-queued>) to be executed on shellmachine via ssh. This behavior can
523 be surpressed by setting $FS::svc-acct::nossh_hack true. If the
524 shellmachine-userdel configuration file does not exist or is empty,
526 [ -d $old_dir ] && mv $old_dir $new_dir || (
530 find . -depth -print | cpio -pdm $new_dir;
532 chown -R $uid.$gid $new_dir;
536 is the default. This behaviour can be surpressed by setting
537 $FS::svc_acct::nossh_hack true.
542 my ( $new, $old ) = ( shift, shift );
545 return "Username in use"
546 if $old->username ne $new->username &&
547 qsearchs( 'svc_acct', { 'username' => $new->username,
548 'domsvc' => $new->domsvc,
551 #no warnings 'numeric'; #alas, a 5.006-ism
553 return "Can't change uid!" if $old->uid != $new->uid;
556 #change homdir when we change username
557 $new->setfield('dir', '') if $old->username ne $new->username;
559 local $SIG{HUP} = 'IGNORE';
560 local $SIG{INT} = 'IGNORE';
561 local $SIG{QUIT} = 'IGNORE';
562 local $SIG{TERM} = 'IGNORE';
563 local $SIG{TSTP} = 'IGNORE';
564 local $SIG{PIPE} = 'IGNORE';
566 my $oldAutoCommit = $FS::UID::AutoCommit;
567 local $FS::UID::AutoCommit = 0;
570 $error = $new->SUPER::replace($old);
572 $dbh->rollback if $oldAutoCommit;
573 return $error if $error;
576 $old->usergroup( [ $old->radius_groups ] );
577 if ( $new->usergroup ) {
578 #(sorta) false laziness with FS::part_export::sqlradius::_export_replace
579 my @newgroups = @{$new->usergroup};
580 foreach my $oldgroup ( @{$old->usergroup} ) {
581 if ( grep { $oldgroup eq $_ } @newgroups ) {
582 @newgroups = grep { $oldgroup ne $_ } @newgroups;
585 my $radius_usergroup = qsearchs('radius_usergroup', {
586 svcnum => $old->svcnum,
587 groupname => $oldgroup,
589 my $error = $radius_usergroup->delete;
591 $dbh->rollback if $oldAutoCommit;
592 return "error deleting radius_usergroup $oldgroup: $error";
596 foreach my $newgroup ( @newgroups ) {
597 my $radius_usergroup = new FS::radius_usergroup ( {
598 svcnum => $new->svcnum,
599 groupname => $newgroup,
601 my $error = $radius_usergroup->insert;
603 $dbh->rollback if $oldAutoCommit;
604 return "error adding radius_usergroup $newgroup: $error";
611 unless ( $noexport_hack ) {
612 foreach my $part_export ( $new->cust_svc->part_svc->part_export ) {
613 my $error = $part_export->export_replace($new,$old);
615 $dbh->rollback if $oldAutoCommit;
616 return "exporting to ". $part_export->exporttype.
617 " (transaction rolled back): $error";
625 my $cpassword = crypt(
626 $new->_password,$saltset[int(rand(64))].$saltset[int(rand(64))]
629 if ($old->username ne $new->username || $old->domain ne $new->domain ) {
630 my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_delete' };
631 $error = $queue->insert( $old->username, $old->domain );
632 my $queue2 = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_insert' };
633 $error = $queue2->insert( $new->username,
639 } elsif ($old->_password ne $new->_password) {
640 my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_replace_password' };
641 $error = $queue->insert( $new->username, $cpassword, $new->domain );
644 $dbh->rollback if $oldAutoCommit;
645 return "queueing job (transaction rolled back): $error";
649 #end of old-style exports
651 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
655 sub vpopmail_replace_password {
656 my( $username, $password, $domain ) = @_;
658 (open(VPASSWD, "$exportdir/domains/$domain/vpasswd")
659 and flock(VPASSWD,LOCK_EX)
660 ) or die "can't open $exportdir/domains/$domain/vpasswd: $!";
662 open(VPASSWDTMP, ">$exportdir/domains/$domain/vpasswd.tmp")
663 or die "Can't open $exportdir/domains/$domain/vpasswd.tmp: $!";
666 my ($mailbox, $pw, @rest) = split(':', $_);
667 print VPASSWDTMP $_ unless $username eq $mailbox;
668 print VPASSWDTMP join (':', ($mailbox, $password, @rest))
669 if $username eq $mailbox;
674 rename "$exportdir/domains/$domain/vpasswd.tmp", "$exportdir/domains/$domain/vpasswd"
675 or die "Can't rename $exportdir/domains/$domain/vpasswd.tmp: $!";
677 flock(VPASSWD,LOCK_UN);
680 my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_sync' };
681 my $error = $queue->insert;
682 die $error if $error;
690 Suspends this account by prefixing *SUSPENDED* to the password. If there is an
691 error, returns the error, otherwise returns false.
693 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
699 my %hash = $self->hash;
700 unless ( $hash{_password} =~ /^\*SUSPENDED\* /
701 || $hash{_password} eq '*'
703 $hash{_password} = '*SUSPENDED* '.$hash{_password};
704 my $new = new FS::svc_acct ( \%hash );
705 $new->replace($self);
707 ''; #no error (already suspended)
713 Unsuspends this account by removing *SUSPENDED* from the password. If there is
714 an error, returns the error, otherwise returns false.
716 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
722 my %hash = $self->hash;
723 if ( $hash{_password} =~ /^\*SUSPENDED\* (.*)$/ ) {
724 $hash{_password} = $1;
725 my $new = new FS::svc_acct ( \%hash );
726 $new->replace($self);
728 ''; #no error (already unsuspended)
734 Just returns false (no error) for now.
736 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
740 Checks all fields to make sure this is a valid service. If there is an error,
741 returns the error, otherwise returns false. Called by the insert and replace
744 Sets any fixed values; see L<FS::part_svc>.
751 my($recref) = $self->hashref;
753 my $x = $self->setfixed;
754 return $x unless ref($x);
757 if ( $part_svc->part_svc_column('usergroup')->columnflag eq "F" ) {
759 [ split(',', $part_svc->part_svc_column('usergroup')->columnvalue) ] );
762 my $error = $self->ut_numbern('svcnum')
763 || $self->ut_number('domsvc')
764 || $self->ut_textn('sec_phrase')
766 return $error if $error;
768 my $ulen = $usernamemax || $self->dbdef_table->column('username')->length;
769 if ( $username_uppercase ) {
770 $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/i
771 or return gettext('illegal_username'). ": ". $recref->{username};
772 $recref->{username} = $1;
774 $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/
775 or return gettext('illegal_username'). ": ". $recref->{username};
776 $recref->{username} = $1;
779 if ( $username_letterfirst ) {
780 $recref->{username} =~ /^[a-z]/ or return gettext('illegal_username');
781 } elsif ( $username_letter ) {
782 $recref->{username} =~ /[a-z]/ or return gettext('illegal_username');
784 if ( $username_noperiod ) {
785 $recref->{username} =~ /\./ and return gettext('illegal_username');
787 unless ( $username_ampersand ) {
788 $recref->{username} =~ /\&/ and return gettext('illegal_username');
791 $recref->{popnum} =~ /^(\d*)$/ or return "Illegal popnum: ".$recref->{popnum};
792 $recref->{popnum} = $1;
793 return "Unknown popnum" unless
794 ! $recref->{popnum} ||
795 qsearchs('svc_acct_pop',{'popnum'=> $recref->{popnum} } );
797 unless ( $part_svc->part_svc_column('uid')->columnflag eq 'F' ) {
799 $recref->{uid} =~ /^(\d*)$/ or return "Illegal uid";
800 $recref->{uid} = $1 eq '' ? $self->unique('uid') : $1;
802 $recref->{gid} =~ /^(\d*)$/ or return "Illegal gid";
803 $recref->{gid} = $1 eq '' ? $recref->{uid} : $1;
804 #not all systems use gid=uid
805 #you can set a fixed gid in part_svc
807 return "Only root can have uid 0"
808 if $recref->{uid} == 0 && $recref->{username} ne 'root';
810 # $error = $self->ut_textn('finger');
811 # return $error if $error;
812 $self->getfield('finger') =~
813 /^([\w \t\!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\*\<\>]*)$/
814 or return "Illegal finger: ". $self->getfield('finger');
815 $self->setfield('finger', $1);
817 $recref->{dir} =~ /^([\/\w\-\.\&]*)$/
818 or return "Illegal directory";
820 return "Illegal directory"
821 if $recref->{dir} =~ /(^|\/)\.+(\/|$)/; #no .. component
822 return "Illegal directory"
823 if $recref->{dir} =~ /\&/ && ! $username_ampersand;
824 unless ( $recref->{dir} ) {
825 $recref->{dir} = $dir_prefix . '/';
826 if ( $dirhash > 0 ) {
827 for my $h ( 1 .. $dirhash ) {
828 $recref->{dir} .= substr($recref->{username}, $h-1, 1). '/';
830 } elsif ( $dirhash < 0 ) {
831 for my $h ( reverse $dirhash .. -1 ) {
832 $recref->{dir} .= substr($recref->{username}, $h, 1). '/';
835 $recref->{dir} .= $recref->{username};
839 unless ( $recref->{username} eq 'sync' ) {
840 if ( grep $_ eq $recref->{shell}, @shells ) {
841 $recref->{shell} = (grep $_ eq $recref->{shell}, @shells)[0];
843 return "Illegal shell \`". $self->shell. "\'; ".
844 $conf->dir. "/shells contains: @shells";
847 $recref->{shell} = '/bin/sync';
850 $recref->{quota} =~ /^(\d*)$/ or return "Illegal quota (unimplemented)";
851 $recref->{quota} = $1;
854 $recref->{gid} ne '' ?
855 return "Can't have gid without uid" : ( $recref->{gid}='' );
856 $recref->{finger} ne '' ?
857 return "Can't have finger-name without uid" : ( $recref->{finger}='' );
858 $recref->{dir} ne '' ?
859 return "Can't have directory without uid" : ( $recref->{dir}='' );
860 $recref->{shell} ne '' ?
861 return "Can't have shell without uid" : ( $recref->{shell}='' );
862 $recref->{quota} ne '' ?
863 return "Can't have quota without uid" : ( $recref->{quota}='' );
866 unless ( $part_svc->part_svc_column('slipip')->columnflag eq 'F' ) {
867 unless ( $recref->{slipip} eq '0e0' ) {
868 $recref->{slipip} =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/
869 or return "Illegal slipip". $self->slipip;
870 $recref->{slipip} = $1;
872 $recref->{slipip} = '0e0';
877 #arbitrary RADIUS stuff; allow ut_textn for now
878 foreach ( grep /^radius_/, fields('svc_acct') ) {
882 #generate a password if it is blank
883 $recref->{_password} = join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) )
884 unless ( $recref->{_password} );
886 #if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{4,16})$/ ) {
887 if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{$passwordmin,$passwordmax})$/ ) {
888 $recref->{_password} = $1.$3;
889 #uncomment this to encrypt password immediately upon entry, or run
890 #bin/crypt_pw in cron to give new users a window during which their
891 #password is available to techs, for faxing, etc. (also be aware of
893 #$recref->{password} = $1.
894 # crypt($3,$saltset[int(rand(64))].$saltset[int(rand(64))]
896 } elsif ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([\w\.\/\$]{13,34})$/ ) {
897 $recref->{_password} = $1.$3;
898 } elsif ( $recref->{_password} eq '*' ) {
899 $recref->{_password} = '*';
900 } elsif ( $recref->{_password} eq '!!' ) {
901 $recref->{_password} = '!!';
903 #return "Illegal password";
904 return gettext('illegal_password'). ": ". $recref->{_password};
912 Depriciated, use radius_reply instead.
917 carp "FS::svc_acct::radius depriciated, use radius_reply";
923 Returns key/value pairs, suitable for assigning to a hash, for any RADIUS
924 reply attributes of this record.
926 Note that this is now the preferred method for reading RADIUS attributes -
927 accessing the columns directly is discouraged, as the column names are
928 expected to change in the future.
937 my($column, $attrib) = ($1, $2);
938 #$attrib =~ s/_/\-/g;
939 ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) );
940 } grep { /^radius_/ && $self->getfield($_) } fields( $self->table );
941 if ( $self->ip && $self->ip ne '0e0' ) {
942 $reply{'Framed-IP-Address'} = $self->ip;
949 Returns key/value pairs, suitable for assigning to a hash, for any RADIUS
950 check attributes of this record.
952 Note that this is now the preferred method for reading RADIUS attributes -
953 accessing the columns directly is discouraged, as the column names are
954 expected to change in the future.
960 ( 'Password' => $self->_password,
963 my($column, $attrib) = ($1, $2);
964 #$attrib =~ s/_/\-/g;
965 ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) );
966 } grep { /^rc_/ && $self->getfield($_) } fields( $self->table )
972 Returns the domain associated with this account.
978 if ( $self->domsvc ) {
979 #$self->svc_domain->domain;
980 my $svc_domain = $self->svc_domain
981 or die "no svc_domain.svcnum for svc_acct.domsvc ". $self->domsvc;
984 $mydomain or die "svc_acct.domsvc is null and no legacy domain config file";
990 Returns the FS::svc_domain record for this account's domain (see
999 : qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } );
1004 Returns the FS::cust_svc record for this account (see L<FS::cust_svc>).
1008 qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
1013 Returns an email address associated with the account.
1019 $self->username. '@'. $self->domain;
1022 =item seconds_since TIMESTAMP
1024 Returns the number of seconds this account has been online since TIMESTAMP.
1027 TIMESTAMP is specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
1028 L<Time::Local> and L<Date::Parse> for conversion functions.
1032 #note: POD here, implementation in FS::cust_svc
1035 $self->cust_svc->seconds_since(@_);
1040 Returns all RADIUS groups for this account (see L<FS::radius_usergroup>).
1046 map { $_->groupname }
1047 qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } );
1054 =item radius_usergroup_selector GROUPS_ARRAYREF [ SELECTNAME ]
1058 sub radius_usergroup_selector {
1059 my $sel_groups = shift;
1060 my %sel_groups = map { $_=>1 } @$sel_groups;
1062 my $selectname = shift || 'radius_usergroup';
1065 my $sth = $dbh->prepare(
1066 'SELECT DISTINCT(groupname) FROM radius_usergroup ORDER BY groupname'
1067 ) or die $dbh->errstr;
1068 $sth->execute() or die $sth->errstr;
1069 my @all_groups = map { $_->[0] } @{$sth->fetchall_arrayref};
1073 function ${selectname}_doadd(object) {
1074 var myvalue = object.${selectname}_add.value;
1075 var optionName = new Option(myvalue,myvalue,false,true);
1076 var length = object.$selectname.length;
1077 object.$selectname.options[length] = optionName;
1078 object.${selectname}_add.value = "";
1081 <SELECT MULTIPLE NAME="$selectname">
1084 foreach my $group ( @all_groups ) {
1086 if ( $sel_groups{$group} ) {
1087 $html .= ' SELECTED';
1088 $sel_groups{$group} = 0;
1090 $html .= ">$group</OPTION>\n";
1092 foreach my $group ( grep { $sel_groups{$_} } keys %sel_groups ) {
1093 $html .= "<OPTION SELECTED>$group</OPTION>\n";
1095 $html .= '</SELECT>';
1097 $html .= qq!<BR><INPUT TYPE="text" NAME="${selectname}_add">!.
1098 qq!<INPUT TYPE="button" VALUE="Add new group" onClick="${selectname}_doadd(this.form)">!;
1105 The $recref stuff in sub check should be cleaned up.
1107 The suspend, unsuspend and cancel methods update the database, but not the
1108 current object. This is probably a bug as it's unexpected and
1111 radius_usergroup_selector? putting web ui components in here? they should
1112 probably live somewhere else...
1116 L<FS::svc_Common>, edit/part_svc.cgi from an installed web interface,
1117 export.html from the base documentation, L<FS::Record>, L<FS::Conf>,
1118 L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>, L<FS::queue>,
1119 L<freeside-queued>), L<Net::SSH>, L<ssh>, L<FS::svc_acct_pop>,
1120 schema.html from the base documentation.