4 use vars qw( @ISA $noexport_hack $conf
5 $dir_prefix @shells $usernamemin
6 $usernamemax $passwordmin $passwordmax
7 $username_ampersand $username_letter $username_letterfirst
8 $username_noperiod $username_nounderscore $username_nodash
11 $welcome_template $welcome_from $welcome_subject $welcome_mimetype
17 use FS::UID qw( datasrc );
19 use FS::Record qw( qsearch qsearchs fields dbh );
26 use FS::cust_main_invoice;
30 use FS::radius_usergroup;
33 use FS::Msgcat qw(gettext);
35 @ISA = qw( FS::svc_Common );
37 #ask FS::UID to run this stuff for us later
38 $FS::UID::callback{'FS::svc_acct'} = sub {
40 $dir_prefix = $conf->config('home');
41 @shells = $conf->config('shells');
42 $usernamemin = $conf->config('usernamemin') || 2;
43 $usernamemax = $conf->config('usernamemax');
44 $passwordmin = $conf->config('passwordmin') || 6;
45 $passwordmax = $conf->config('passwordmax') || 8;
46 $username_letter = $conf->exists('username-letter');
47 $username_letterfirst = $conf->exists('username-letterfirst');
48 $username_noperiod = $conf->exists('username-noperiod');
49 $username_nounderscore = $conf->exists('username-nounderscore');
50 $username_nodash = $conf->exists('username-nodash');
51 $username_uppercase = $conf->exists('username-uppercase');
52 $username_ampersand = $conf->exists('username-ampersand');
53 $mydomain = $conf->config('domain');
54 $dirhash = $conf->config('dirhash') || 0;
55 if ( $conf->exists('welcome_email') ) {
56 $welcome_template = new Text::Template (
58 SOURCE => [ map "$_\n", $conf->config('welcome_email') ]
59 ) or warn "can't create welcome email template: $Text::Template::ERROR";
60 $welcome_from = $conf->config('welcome_email-from'); # || 'your-isp-is-dum'
61 $welcome_subject = $conf->config('welcome_email-subject') || 'Welcome';
62 $welcome_mimetype = $conf->config('welcome_email-mimetype') || 'text/plain';
64 $welcome_template = '';
66 $smtpmachine = $conf->config('smtpmachine');
69 @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' );
70 @pw_set = ( 'a'..'z', 'A'..'Z', '0'..'9', '(', ')', '#', '!', '.', ',' );
74 my ( $hashref, $cache ) = @_;
75 if ( $hashref->{'svc_acct_svcnum'} ) {
76 $self->{'_domsvc'} = FS::svc_domain->new( {
77 'svcnum' => $hashref->{'domsvc'},
78 'domain' => $hashref->{'svc_acct_domain'},
79 'catchall' => $hashref->{'svc_acct_catchall'},
86 FS::svc_acct - Object methods for svc_acct records
92 $record = new FS::svc_acct \%hash;
93 $record = new FS::svc_acct { 'column' => 'value' };
95 $error = $record->insert;
97 $error = $new_record->replace($old_record);
99 $error = $record->delete;
101 $error = $record->check;
103 $error = $record->suspend;
105 $error = $record->unsuspend;
107 $error = $record->cancel;
109 %hash = $record->radius;
111 %hash = $record->radius_reply;
113 %hash = $record->radius_check;
115 $domain = $record->domain;
117 $svc_domain = $record->svc_domain;
119 $email = $record->email;
121 $seconds_since = $record->seconds_since($timestamp);
125 An FS::svc_acct object represents an account. FS::svc_acct inherits from
126 FS::svc_Common. The following fields are currently supported:
130 =item svcnum - primary key (assigned automatcially for new accounts)
134 =item _password - generated if blank
136 =item sec_phrase - security phrase
138 =item popnum - Point of presence (see L<FS::svc_acct_pop>)
146 =item dir - set automatically if blank (and uid is not)
150 =item quota - (unimplementd)
152 =item slipip - IP address
156 =item domsvc - svcnum from svc_domain
158 =item radius_I<Radius_Attribute> - I<Radius-Attribute>
168 Creates a new account. To add the account to the database, see L<"insert">.
172 sub table { 'svc_acct'; }
176 Adds this account to the database. If there is an error, returns the error,
177 otherwise returns false.
179 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
180 defined. An FS::cust_svc record will be created and inserted.
182 The additional field I<usergroup> can optionally be defined; if so it should
183 contain an arrayref of group names. See L<FS::radius_usergroup>. (used in
184 sqlradius export only)
186 (TODOC: L<FS::queue> and L<freeside-queued>)
188 (TODOC: new exports! $noexport_hack)
196 local $SIG{HUP} = 'IGNORE';
197 local $SIG{INT} = 'IGNORE';
198 local $SIG{QUIT} = 'IGNORE';
199 local $SIG{TERM} = 'IGNORE';
200 local $SIG{TSTP} = 'IGNORE';
201 local $SIG{PIPE} = 'IGNORE';
203 my $oldAutoCommit = $FS::UID::AutoCommit;
204 local $FS::UID::AutoCommit = 0;
207 $error = $self->check;
208 return $error if $error;
210 #no, duplicate checking just got a whole lot more complicated
211 #(perhaps keep this check with a config option to turn on?)
213 #return gettext('username_in_use'). ": ". $self->username
214 # if qsearchs( 'svc_acct', { 'username' => $self->username,
215 # 'domsvc' => $self->domsvc,
218 if ( $self->svcnum ) {
219 my $cust_svc = qsearchs('cust_svc',{'svcnum'=>$self->svcnum});
220 unless ( $cust_svc ) {
221 $dbh->rollback if $oldAutoCommit;
222 return "no cust_svc record found for svcnum ". $self->svcnum;
224 $self->pkgnum($cust_svc->pkgnum);
225 $self->svcpart($cust_svc->svcpart);
228 #new duplicate username checking
230 my $part_svc = qsearchs('part_svc', { 'svcpart' => $self->svcpart } );
231 unless ( $part_svc ) {
232 $dbh->rollback if $oldAutoCommit;
233 return 'unknown svcpart '. $self->svcpart;
236 my @dup_user = qsearch( 'svc_acct', { 'username' => $self->username } );
237 my @dup_userdomain = qsearch( 'svc_acct', { 'username' => $self->username,
238 'domsvc' => $self->domsvc } );
240 if ( $part_svc->part_svc_column('uid')->columnflag ne 'F'
241 && $self->username !~ /^(toor|(hyla)?fax)$/ ) {
242 @dup_uid = qsearch( 'svc_acct', { 'uid' => $self->uid } );
247 if ( @dup_user || @dup_userdomain || @dup_uid ) {
248 my $exports = FS::part_export::export_info('svc_acct');
249 my( %conflict_user_svcpart, %conflict_userdomain_svcpart );
251 foreach my $part_export ( $part_svc->part_export ) {
253 #this will catch to the same exact export
254 my @svcparts = map { $_->svcpart }
255 qsearch('export_svc', { 'exportnum' => $part_export->exportnum });
257 #this will catch to exports w/same exporthost+type ???
258 #my @other_part_export = qsearch('part_export', {
259 # 'machine' => $part_export->machine,
260 # 'exporttype' => $part_export->exporttype,
262 #foreach my $other_part_export ( @other_part_export ) {
263 # push @svcparts, map { $_->svcpart }
264 # qsearch('export_svc', { 'exportnum' => $part_export->exportnum });
267 my $nodomain = $exports->{$part_export->exporttype}{'nodomain'};
268 if ( $nodomain =~ /^Y/i ) {
269 $conflict_user_svcpart{$_} = $part_export->exportnum
272 $conflict_userdomain_svcpart{$_} = $part_export->exportnum
277 foreach my $dup_user ( @dup_user ) {
278 my $dup_svcpart = $dup_user->cust_svc->svcpart;
279 if ( exists($conflict_user_svcpart{$dup_svcpart}) ) {
280 $dbh->rollback if $oldAutoCommit;
281 return "duplicate username: conflicts with svcnum ". $dup_user->svcnum.
282 " via exportnum ". $conflict_user_svcpart{$dup_svcpart};
286 foreach my $dup_userdomain ( @dup_userdomain ) {
287 my $dup_svcpart = $dup_userdomain->cust_svc->svcpart;
288 if ( exists($conflict_userdomain_svcpart{$dup_svcpart}) ) {
289 $dbh->rollback if $oldAutoCommit;
290 return "duplicate username\@domain: conflicts with svcnum ".
291 $dup_userdomain->svcnum. " via exportnum ".
292 $conflict_userdomain_svcpart{$dup_svcpart};
296 foreach my $dup_uid ( @dup_uid ) {
297 my $dup_svcpart = $dup_uid->cust_svc->svcpart;
298 if ( exists($conflict_user_svcpart{$dup_svcpart})
299 || exists($conflict_userdomain_svcpart{$dup_svcpart}) ) {
300 $dbh->rollback if $oldAutoCommit;
301 return "duplicate uid: conflicts with svcnum". $dup_uid->svcnum.
302 "via exportnum ". $conflict_user_svcpart{$dup_svcpart}
303 || $conflict_userdomain_svcpart{$dup_svcpart};
309 #see? i told you it was more complicated
312 $error = $self->SUPER::insert(\@jobnums);
314 $dbh->rollback if $oldAutoCommit;
318 if ( $self->usergroup ) {
319 foreach my $groupname ( @{$self->usergroup} ) {
320 my $radius_usergroup = new FS::radius_usergroup ( {
321 svcnum => $self->svcnum,
322 groupname => $groupname,
324 my $error = $radius_usergroup->insert;
326 $dbh->rollback if $oldAutoCommit;
332 #false laziness with sub replace (and cust_main)
333 my $queue = new FS::queue {
334 'svcnum' => $self->svcnum,
335 'job' => 'FS::svc_acct::append_fuzzyfiles'
337 $error = $queue->insert($self->username);
339 $dbh->rollback if $oldAutoCommit;
340 return "queueing job (transaction rolled back): $error";
344 my $cust_pkg = $self->cust_svc->cust_pkg;
345 my( $cust_main, $to ) = ( '', '' );
346 if ( $welcome_template && $cust_pkg ) {
347 my $cust_main = $cust_pkg->cust_main;
348 my $to = join(', ', grep { $_ ne 'POST' } $cust_main->invoicing_list );
350 my $wqueue = new FS::queue {
351 'svcnum' => $self->svcnum,
352 'job' => 'FS::svc_acct::send_email'
354 warn "attempting to queue email to $to";
355 my $error = $wqueue->insert(
357 'from' => $welcome_from,
358 'subject' => $welcome_subject,
359 'mimetype' => $welcome_mimetype,
360 'body' => $welcome_template->fill_in( HASH => {
361 'username' => $self->username,
362 'password' => $self->_password,
363 'first' => $cust_main->first,
364 'last' => $cust_main->getfield('last'),
365 'pkg' => $cust_pkg->part_pkg->pkg,
369 $dbh->rollback if $oldAutoCommit;
370 return "queuing welcome email: $error";
373 foreach my $jobnum ( @jobnums ) {
374 my $error = $wqueue->depend_insert($jobnum);
376 $dbh->rollback if $oldAutoCommit;
377 return "queuing welcome email job dependancy: $error";
385 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
391 Deletes this account from the database. If there is an error, returns the
392 error, otherwise returns false.
394 The corresponding FS::cust_svc record will be deleted as well.
396 (TODOC: new exports! $noexport_hack)
403 if ( defined( $FS::Record::dbdef->table('svc_acct_sm') ) ) {
404 return "Can't delete an account which has (svc_acct_sm) mail aliases!"
405 if $self->uid && qsearch( 'svc_acct_sm', { 'domuid' => $self->uid } );
408 return "Can't delete an account which is a (svc_forward) source!"
409 if qsearch( 'svc_forward', { 'srcsvc' => $self->svcnum } );
411 return "Can't delete an account which is a (svc_forward) destination!"
412 if qsearch( 'svc_forward', { 'dstsvc' => $self->svcnum } );
414 return "Can't delete an account with (svc_www) web service!"
415 if qsearch( 'svc_www', { 'usersvc' => $self->usersvc } );
417 # what about records in session ? (they should refer to history table)
419 local $SIG{HUP} = 'IGNORE';
420 local $SIG{INT} = 'IGNORE';
421 local $SIG{QUIT} = 'IGNORE';
422 local $SIG{TERM} = 'IGNORE';
423 local $SIG{TSTP} = 'IGNORE';
424 local $SIG{PIPE} = 'IGNORE';
426 my $oldAutoCommit = $FS::UID::AutoCommit;
427 local $FS::UID::AutoCommit = 0;
430 foreach my $cust_main_invoice (
431 qsearch( 'cust_main_invoice', { 'dest' => $self->svcnum } )
433 unless ( defined($cust_main_invoice) ) {
434 warn "WARNING: something's wrong with qsearch";
437 my %hash = $cust_main_invoice->hash;
438 $hash{'dest'} = $self->email;
439 my $new = new FS::cust_main_invoice \%hash;
440 my $error = $new->replace($cust_main_invoice);
442 $dbh->rollback if $oldAutoCommit;
447 foreach my $svc_domain (
448 qsearch( 'svc_domain', { 'catchall' => $self->svcnum } )
450 my %hash = new FS::svc_domain->hash;
451 $hash{'catchall'} = '';
452 my $new = new FS::svc_domain \%hash;
453 my $error = $new->replace($svc_domain);
455 $dbh->rollback if $oldAutoCommit;
460 foreach my $radius_usergroup (
461 qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } )
463 my $error = $radius_usergroup->delete;
465 $dbh->rollback if $oldAutoCommit;
470 my $error = $self->SUPER::delete;
472 $dbh->rollback if $oldAutoCommit;
476 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
480 =item replace OLD_RECORD
482 Replaces OLD_RECORD with this one in the database. If there is an error,
483 returns the error, otherwise returns false.
485 The additional field I<usergroup> can optionally be defined; if so it should
486 contain an arrayref of group names. See L<FS::radius_usergroup>. (used in
487 sqlradius export only)
492 my ( $new, $old ) = ( shift, shift );
495 return "Username in use"
496 if $old->username ne $new->username &&
497 qsearchs( 'svc_acct', { 'username' => $new->username,
498 'domsvc' => $new->domsvc,
501 #no warnings 'numeric'; #alas, a 5.006-ism
503 return "Can't change uid!" if $old->uid != $new->uid;
506 #change homdir when we change username
507 $new->setfield('dir', '') if $old->username ne $new->username;
509 local $SIG{HUP} = 'IGNORE';
510 local $SIG{INT} = 'IGNORE';
511 local $SIG{QUIT} = 'IGNORE';
512 local $SIG{TERM} = 'IGNORE';
513 local $SIG{TSTP} = 'IGNORE';
514 local $SIG{PIPE} = 'IGNORE';
516 my $oldAutoCommit = $FS::UID::AutoCommit;
517 local $FS::UID::AutoCommit = 0;
520 $old->usergroup( [ $old->radius_groups ] );
521 if ( $new->usergroup ) {
522 #(sorta) false laziness with FS::part_export::sqlradius::_export_replace
523 my @newgroups = @{$new->usergroup};
524 foreach my $oldgroup ( @{$old->usergroup} ) {
525 if ( grep { $oldgroup eq $_ } @newgroups ) {
526 @newgroups = grep { $oldgroup ne $_ } @newgroups;
529 my $radius_usergroup = qsearchs('radius_usergroup', {
530 svcnum => $old->svcnum,
531 groupname => $oldgroup,
533 my $error = $radius_usergroup->delete;
535 $dbh->rollback if $oldAutoCommit;
536 return "error deleting radius_usergroup $oldgroup: $error";
540 foreach my $newgroup ( @newgroups ) {
541 my $radius_usergroup = new FS::radius_usergroup ( {
542 svcnum => $new->svcnum,
543 groupname => $newgroup,
545 my $error = $radius_usergroup->insert;
547 $dbh->rollback if $oldAutoCommit;
548 return "error adding radius_usergroup $newgroup: $error";
554 $error = $new->SUPER::replace($old);
556 $dbh->rollback if $oldAutoCommit;
557 return $error if $error;
560 #false laziness with sub insert (and cust_main)
561 my $queue = new FS::queue {
562 'svcnum' => $new->svcnum,
563 'job' => 'FS::svc_acct::append_fuzzyfiles'
565 $error = $queue->insert($new->username);
567 $dbh->rollback if $oldAutoCommit;
568 return "queueing job (transaction rolled back): $error";
572 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
578 Suspends this account by prefixing *SUSPENDED* to the password. If there is an
579 error, returns the error, otherwise returns false.
581 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
587 my %hash = $self->hash;
588 unless ( $hash{_password} =~ /^\*SUSPENDED\* /
589 || $hash{_password} eq '*'
591 $hash{_password} = '*SUSPENDED* '.$hash{_password};
592 my $new = new FS::svc_acct ( \%hash );
593 my $error = $new->replace($self);
594 return $error if $error;
597 $self->SUPER::suspend;
602 Unsuspends this account by removing *SUSPENDED* from the password. If there is
603 an error, returns the error, otherwise returns false.
605 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
611 my %hash = $self->hash;
612 if ( $hash{_password} =~ /^\*SUSPENDED\* (.*)$/ ) {
613 $hash{_password} = $1;
614 my $new = new FS::svc_acct ( \%hash );
615 my $error = $new->replace($self);
616 return $error if $error;
619 $self->SUPER::unsuspend;
624 Just returns false (no error) for now.
626 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
630 Checks all fields to make sure this is a valid service. If there is an error,
631 returns the error, otherwise returns false. Called by the insert and replace
634 Sets any fixed values; see L<FS::part_svc>.
641 my($recref) = $self->hashref;
643 my $x = $self->setfixed;
644 return $x unless ref($x);
647 if ( $part_svc->part_svc_column('usergroup')->columnflag eq "F" ) {
649 [ split(',', $part_svc->part_svc_column('usergroup')->columnvalue) ] );
652 my $error = $self->ut_numbern('svcnum')
653 || $self->ut_number('domsvc')
654 || $self->ut_textn('sec_phrase')
656 return $error if $error;
658 my $ulen = $usernamemax || $self->dbdef_table->column('username')->length;
659 if ( $username_uppercase ) {
660 $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/i
661 or return gettext('illegal_username'). " ($usernamemin-$ulen): ". $recref->{username};
662 $recref->{username} = $1;
664 $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/
665 or return gettext('illegal_username'). " ($usernamemin-$ulen): ". $recref->{username};
666 $recref->{username} = $1;
669 if ( $username_letterfirst ) {
670 $recref->{username} =~ /^[a-z]/ or return gettext('illegal_username');
671 } elsif ( $username_letter ) {
672 $recref->{username} =~ /[a-z]/ or return gettext('illegal_username');
674 if ( $username_noperiod ) {
675 $recref->{username} =~ /\./ and return gettext('illegal_username');
677 if ( $username_nounderscore ) {
678 $recref->{username} =~ /_/ and return gettext('illegal_username');
680 if ( $username_nodash ) {
681 $recref->{username} =~ /\-/ and return gettext('illegal_username');
683 unless ( $username_ampersand ) {
684 $recref->{username} =~ /\&/ and return gettext('illegal_username');
687 $recref->{popnum} =~ /^(\d*)$/ or return "Illegal popnum: ".$recref->{popnum};
688 $recref->{popnum} = $1;
689 return "Unknown popnum" unless
690 ! $recref->{popnum} ||
691 qsearchs('svc_acct_pop',{'popnum'=> $recref->{popnum} } );
693 unless ( $part_svc->part_svc_column('uid')->columnflag eq 'F' ) {
695 $recref->{uid} =~ /^(\d*)$/ or return "Illegal uid";
696 $recref->{uid} = $1 eq '' ? $self->unique('uid') : $1;
698 $recref->{gid} =~ /^(\d*)$/ or return "Illegal gid";
699 $recref->{gid} = $1 eq '' ? $recref->{uid} : $1;
700 #not all systems use gid=uid
701 #you can set a fixed gid in part_svc
703 return "Only root can have uid 0"
704 if $recref->{uid} == 0
705 && $recref->{username} ne 'root'
706 && $recref->{username} ne 'toor';
708 # $error = $self->ut_textn('finger');
709 # return $error if $error;
710 $self->getfield('finger') =~
711 /^([\w \t\!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\*\<\>]*)$/
712 or return "Illegal finger: ". $self->getfield('finger');
713 $self->setfield('finger', $1);
715 $recref->{dir} =~ /^([\/\w\-\.\&]*)$/
716 or return "Illegal directory";
718 return "Illegal directory"
719 if $recref->{dir} =~ /(^|\/)\.+(\/|$)/; #no .. component
720 return "Illegal directory"
721 if $recref->{dir} =~ /\&/ && ! $username_ampersand;
722 unless ( $recref->{dir} ) {
723 $recref->{dir} = $dir_prefix . '/';
724 if ( $dirhash > 0 ) {
725 for my $h ( 1 .. $dirhash ) {
726 $recref->{dir} .= substr($recref->{username}, $h-1, 1). '/';
728 } elsif ( $dirhash < 0 ) {
729 for my $h ( reverse $dirhash .. -1 ) {
730 $recref->{dir} .= substr($recref->{username}, $h, 1). '/';
733 $recref->{dir} .= $recref->{username};
737 unless ( $recref->{username} eq 'sync' ) {
738 if ( grep $_ eq $recref->{shell}, @shells ) {
739 $recref->{shell} = (grep $_ eq $recref->{shell}, @shells)[0];
741 return "Illegal shell \`". $self->shell. "\'; ".
742 $conf->dir. "/shells contains: @shells";
745 $recref->{shell} = '/bin/sync';
748 $recref->{quota} =~ /^(\d*)$/ or return "Illegal quota (unimplemented)";
749 $recref->{quota} = $1;
752 $recref->{gid} ne '' ?
753 return "Can't have gid without uid" : ( $recref->{gid}='' );
754 $recref->{finger} ne '' ?
755 return "Can't have finger-name without uid" : ( $recref->{finger}='' );
756 $recref->{dir} ne '' ?
757 return "Can't have directory without uid" : ( $recref->{dir}='' );
758 $recref->{shell} ne '' ?
759 return "Can't have shell without uid" : ( $recref->{shell}='' );
760 $recref->{quota} ne '' ?
761 return "Can't have quota without uid" : ( $recref->{quota}='' );
764 unless ( $part_svc->part_svc_column('slipip')->columnflag eq 'F' ) {
765 unless ( $recref->{slipip} eq '0e0' ) {
766 $recref->{slipip} =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/
767 or return "Illegal slipip". $self->slipip;
768 $recref->{slipip} = $1;
770 $recref->{slipip} = '0e0';
775 #arbitrary RADIUS stuff; allow ut_textn for now
776 foreach ( grep /^radius_/, fields('svc_acct') ) {
780 #generate a password if it is blank
781 $recref->{_password} = join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) )
782 unless ( $recref->{_password} );
784 #if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{4,16})$/ ) {
785 if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{$passwordmin,$passwordmax})$/ ) {
786 $recref->{_password} = $1.$3;
787 #uncomment this to encrypt password immediately upon entry, or run
788 #bin/crypt_pw in cron to give new users a window during which their
789 #password is available to techs, for faxing, etc. (also be aware of
791 #$recref->{password} = $1.
792 # crypt($3,$saltset[int(rand(64))].$saltset[int(rand(64))]
794 } elsif ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([\w\.\/\$]{13,34})$/ ) {
795 $recref->{_password} = $1.$3;
796 } elsif ( $recref->{_password} eq '*' ) {
797 $recref->{_password} = '*';
798 } elsif ( $recref->{_password} eq '!!' ) {
799 $recref->{_password} = '!!';
801 #return "Illegal password";
802 return gettext('illegal_password'). " $passwordmin-$passwordmax ".
803 FS::Msgcat::_gettext('illegal_password_characters').
804 ": ". $recref->{_password};
812 Depriciated, use radius_reply instead.
817 carp "FS::svc_acct::radius depriciated, use radius_reply";
823 Returns key/value pairs, suitable for assigning to a hash, for any RADIUS
824 reply attributes of this record.
826 Note that this is now the preferred method for reading RADIUS attributes -
827 accessing the columns directly is discouraged, as the column names are
828 expected to change in the future.
837 my($column, $attrib) = ($1, $2);
838 #$attrib =~ s/_/\-/g;
839 ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) );
840 } grep { /^radius_/ && $self->getfield($_) } fields( $self->table );
841 if ( $self->slipip && $self->slipip ne '0e0' ) {
842 $reply{'Framed-IP-Address'} = $self->slipip;
849 Returns key/value pairs, suitable for assigning to a hash, for any RADIUS
850 check attributes of this record.
852 Note that this is now the preferred method for reading RADIUS attributes -
853 accessing the columns directly is discouraged, as the column names are
854 expected to change in the future.
860 ( 'Password' => $self->_password,
863 my($column, $attrib) = ($1, $2);
864 #$attrib =~ s/_/\-/g;
865 ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) );
866 } grep { /^rc_/ && $self->getfield($_) } fields( $self->table )
872 Returns the domain associated with this account.
878 if ( $self->domsvc ) {
879 #$self->svc_domain->domain;
880 my $svc_domain = $self->svc_domain
881 or die "no svc_domain.svcnum for svc_acct.domsvc ". $self->domsvc;
884 $mydomain or die "svc_acct.domsvc is null and no legacy domain config file";
890 Returns the FS::svc_domain record for this account's domain (see
899 : qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } );
904 Returns the FS::cust_svc record for this account (see L<FS::cust_svc>).
908 qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
913 Returns an email address associated with the account.
919 $self->username. '@'. $self->domain;
922 =item seconds_since TIMESTAMP
924 Returns the number of seconds this account has been online since TIMESTAMP.
927 TIMESTAMP is specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
928 L<Time::Local> and L<Date::Parse> for conversion functions.
932 #note: POD here, implementation in FS::cust_svc
935 $self->cust_svc->seconds_since(@_);
940 Returns all RADIUS groups for this account (see L<FS::radius_usergroup>).
946 if ( $self->usergroup ) {
947 #when provisioning records, export callback runs in svc_Common.pm before
948 #radius_usergroup records can be inserted...
951 map { $_->groupname }
952 qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } );
970 use Mail::Internet 1.44;
973 $opt{mimetype} ||= 'text/plain';
974 $opt{mimetype} .= '; charset="iso-8859-1"' unless $opt{mimetype} =~ /charset/;
976 $ENV{MAILADDRESS} = $opt{from};
977 my $header = new Mail::Header ( [
980 "Sender: $opt{from}",
981 "Reply-To: $opt{from}",
982 "Date: ". time2str("%a, %d %b %Y %X %z", time),
983 "Subject: $opt{subject}",
984 "Content-Type: $opt{mimetype}",
986 my $message = new Mail::Internet (
988 'Body' => [ map "$_\n", split("\n", $opt{body}) ],
991 $message->smtpsend( Host => $smtpmachine )
992 or $message->smtpsend( Host => $smtpmachine, Debug => 1 )
993 or die "can't send email to $opt{to} via $smtpmachine with SMTP: $!";
996 =item check_and_rebuild_fuzzyfiles
1000 sub check_and_rebuild_fuzzyfiles {
1001 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
1002 -e "$dir/svc_acct.username"
1003 or &rebuild_fuzzyfiles;
1006 =item rebuild_fuzzyfiles
1010 sub rebuild_fuzzyfiles {
1012 use Fcntl qw(:flock);
1014 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
1018 open(USERNAMELOCK,">>$dir/svc_acct.username")
1019 or die "can't open $dir/svc_acct.username: $!";
1020 flock(USERNAMELOCK,LOCK_EX)
1021 or die "can't lock $dir/svc_acct.username: $!";
1023 my @all_username = map $_->getfield('username'), qsearch('svc_acct', {});
1025 open (USERNAMECACHE,">$dir/svc_acct.username.tmp")
1026 or die "can't open $dir/svc_acct.username.tmp: $!";
1027 print USERNAMECACHE join("\n", @all_username), "\n";
1028 close USERNAMECACHE or die "can't close $dir/svc_acct.username.tmp: $!";
1030 rename "$dir/svc_acct.username.tmp", "$dir/svc_acct.username";
1040 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
1041 open(USERNAMECACHE,"<$dir/svc_acct.username")
1042 or die "can't open $dir/svc_acct.username: $!";
1043 my @array = map { chomp; $_; } <USERNAMECACHE>;
1044 close USERNAMECACHE;
1048 =item append_fuzzyfiles USERNAME
1052 sub append_fuzzyfiles {
1053 my $username = shift;
1055 &check_and_rebuild_fuzzyfiles;
1057 use Fcntl qw(:flock);
1059 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
1061 open(USERNAME,">>$dir/svc_acct.username")
1062 or die "can't open $dir/svc_acct.username: $!";
1063 flock(USERNAME,LOCK_EX)
1064 or die "can't lock $dir/svc_acct.username: $!";
1066 print USERNAME "$username\n";
1068 flock(USERNAME,LOCK_UN)
1069 or die "can't unlock $dir/svc_acct.username: $!";
1077 =item radius_usergroup_selector GROUPS_ARRAYREF [ SELECTNAME ]
1081 sub radius_usergroup_selector {
1082 my $sel_groups = shift;
1083 my %sel_groups = map { $_=>1 } @$sel_groups;
1085 my $selectname = shift || 'radius_usergroup';
1088 my $sth = $dbh->prepare(
1089 'SELECT DISTINCT(groupname) FROM radius_usergroup ORDER BY groupname'
1090 ) or die $dbh->errstr;
1091 $sth->execute() or die $sth->errstr;
1092 my @all_groups = map { $_->[0] } @{$sth->fetchall_arrayref};
1096 function ${selectname}_doadd(object) {
1097 var myvalue = object.${selectname}_add.value;
1098 var optionName = new Option(myvalue,myvalue,false,true);
1099 var length = object.$selectname.length;
1100 object.$selectname.options[length] = optionName;
1101 object.${selectname}_add.value = "";
1104 <SELECT MULTIPLE NAME="$selectname">
1107 foreach my $group ( @all_groups ) {
1109 if ( $sel_groups{$group} ) {
1110 $html .= ' SELECTED';
1111 $sel_groups{$group} = 0;
1113 $html .= ">$group</OPTION>\n";
1115 foreach my $group ( grep { $sel_groups{$_} } keys %sel_groups ) {
1116 $html .= "<OPTION SELECTED>$group</OPTION>\n";
1118 $html .= '</SELECT>';
1120 $html .= qq!<BR><INPUT TYPE="text" NAME="${selectname}_add">!.
1121 qq!<INPUT TYPE="button" VALUE="Add new group" onClick="${selectname}_doadd(this.form)">!;
1130 The $recref stuff in sub check should be cleaned up.
1132 The suspend, unsuspend and cancel methods update the database, but not the
1133 current object. This is probably a bug as it's unexpected and
1136 radius_usergroup_selector? putting web ui components in here? they should
1137 probably live somewhere else...
1141 L<FS::svc_Common>, edit/part_svc.cgi from an installed web interface,
1142 export.html from the base documentation, L<FS::Record>, L<FS::Conf>,
1143 L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>, L<FS::queue>,
1144 L<freeside-queued>), L<Net::SSH>, L<ssh>, L<FS::svc_acct_pop>,
1145 schema.html from the base documentation.