4 use vars qw( @ISA $DEBUG $me $conf
5 $dir_prefix @shells $usernamemin
6 $usernamemax $passwordmin $passwordmax
7 $username_ampersand $username_letter $username_letterfirst
8 $username_noperiod $username_nounderscore $username_nodash
10 $welcome_template $welcome_from $welcome_subject $welcome_mimetype
17 use FS::UID qw( datasrc );
19 use FS::Record qw( qsearch qsearchs fields dbh );
24 use FS::cust_main_invoice;
28 use FS::radius_usergroup;
31 use FS::Msgcat qw(gettext);
33 @ISA = qw( FS::svc_Common );
36 $me = '[FS::svc_acct]';
38 #ask FS::UID to run this stuff for us later
39 $FS::UID::callback{'FS::svc_acct'} = sub {
41 $dir_prefix = $conf->config('home');
42 @shells = $conf->config('shells');
43 $usernamemin = $conf->config('usernamemin') || 2;
44 $usernamemax = $conf->config('usernamemax');
45 $passwordmin = $conf->config('passwordmin') || 6;
46 $passwordmax = $conf->config('passwordmax') || 8;
47 $username_letter = $conf->exists('username-letter');
48 $username_letterfirst = $conf->exists('username-letterfirst');
49 $username_noperiod = $conf->exists('username-noperiod');
50 $username_nounderscore = $conf->exists('username-nounderscore');
51 $username_nodash = $conf->exists('username-nodash');
52 $username_uppercase = $conf->exists('username-uppercase');
53 $username_ampersand = $conf->exists('username-ampersand');
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 $welcome_subject = '';
67 $welcome_mimetype = '';
69 $smtpmachine = $conf->config('smtpmachine');
70 $radius_password = $conf->config('radius-password') || 'Password';
73 @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' );
74 @pw_set = ( 'a'..'z', 'A'..'Z', '0'..'9', '(', ')', '#', '!', '.', ',' );
78 my ( $hashref, $cache ) = @_;
79 if ( $hashref->{'svc_acct_svcnum'} ) {
80 $self->{'_domsvc'} = FS::svc_domain->new( {
81 'svcnum' => $hashref->{'domsvc'},
82 'domain' => $hashref->{'svc_acct_domain'},
83 'catchall' => $hashref->{'svc_acct_catchall'},
90 FS::svc_acct - Object methods for svc_acct records
96 $record = new FS::svc_acct \%hash;
97 $record = new FS::svc_acct { 'column' => 'value' };
99 $error = $record->insert;
101 $error = $new_record->replace($old_record);
103 $error = $record->delete;
105 $error = $record->check;
107 $error = $record->suspend;
109 $error = $record->unsuspend;
111 $error = $record->cancel;
113 %hash = $record->radius;
115 %hash = $record->radius_reply;
117 %hash = $record->radius_check;
119 $domain = $record->domain;
121 $svc_domain = $record->svc_domain;
123 $email = $record->email;
125 $seconds_since = $record->seconds_since($timestamp);
129 An FS::svc_acct object represents an account. FS::svc_acct inherits from
130 FS::svc_Common. The following fields are currently supported:
134 =item svcnum - primary key (assigned automatcially for new accounts)
138 =item _password - generated if blank
140 =item sec_phrase - security phrase
142 =item popnum - Point of presence (see L<FS::svc_acct_pop>)
150 =item dir - set automatically if blank (and uid is not)
154 =item quota - (unimplementd)
156 =item slipip - IP address
160 =item domsvc - svcnum from svc_domain
162 =item radius_I<Radius_Attribute> - I<Radius-Attribute>
172 Creates a new account. To add the account to the database, see L<"insert">.
176 sub table { 'svc_acct'; }
180 Adds this account to the database. If there is an error, returns the error,
181 otherwise returns false.
183 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
184 defined. An FS::cust_svc record will be created and inserted.
186 The additional field I<usergroup> can optionally be defined; if so it should
187 contain an arrayref of group names. See L<FS::radius_usergroup>. (used in
188 sqlradius export only)
190 (TODOC: L<FS::queue> and L<freeside-queued>)
192 (TODOC: new exports!)
200 local $SIG{HUP} = 'IGNORE';
201 local $SIG{INT} = 'IGNORE';
202 local $SIG{QUIT} = 'IGNORE';
203 local $SIG{TERM} = 'IGNORE';
204 local $SIG{TSTP} = 'IGNORE';
205 local $SIG{PIPE} = 'IGNORE';
207 my $oldAutoCommit = $FS::UID::AutoCommit;
208 local $FS::UID::AutoCommit = 0;
211 $error = $self->check;
212 return $error if $error;
214 #no, duplicate checking just got a whole lot more complicated
215 #(perhaps keep this check with a config option to turn on?)
217 #return gettext('username_in_use'). ": ". $self->username
218 # if qsearchs( 'svc_acct', { 'username' => $self->username,
219 # 'domsvc' => $self->domsvc,
222 if ( $self->svcnum ) {
223 my $cust_svc = qsearchs('cust_svc',{'svcnum'=>$self->svcnum});
224 unless ( $cust_svc ) {
225 $dbh->rollback if $oldAutoCommit;
226 return "no cust_svc record found for svcnum ". $self->svcnum;
228 $self->pkgnum($cust_svc->pkgnum);
229 $self->svcpart($cust_svc->svcpart);
232 #new duplicate username checking
234 my $part_svc = qsearchs('part_svc', { 'svcpart' => $self->svcpart } );
235 unless ( $part_svc ) {
236 $dbh->rollback if $oldAutoCommit;
237 return 'unknown svcpart '. $self->svcpart;
240 my @dup_user = qsearch( 'svc_acct', { 'username' => $self->username } );
241 my @dup_userdomain = qsearch( 'svc_acct', { 'username' => $self->username,
242 'domsvc' => $self->domsvc } );
244 if ( $part_svc->part_svc_column('uid')->columnflag ne 'F'
245 && $self->username !~ /^(toor|(hyla)?fax)$/ ) {
246 @dup_uid = qsearch( 'svc_acct', { 'uid' => $self->uid } );
251 if ( @dup_user || @dup_userdomain || @dup_uid ) {
252 my $exports = FS::part_export::export_info('svc_acct');
253 my %conflict_user_svcpart;
254 my %conflict_userdomain_svcpart = ( $self->svcpart => 'SELF', );
256 foreach my $part_export ( $part_svc->part_export ) {
258 #this will catch to the same exact export
259 my @svcparts = map { $_->svcpart }
260 qsearch('export_svc', { 'exportnum' => $part_export->exportnum });
262 #this will catch to exports w/same exporthost+type ???
263 #my @other_part_export = qsearch('part_export', {
264 # 'machine' => $part_export->machine,
265 # 'exporttype' => $part_export->exporttype,
267 #foreach my $other_part_export ( @other_part_export ) {
268 # push @svcparts, map { $_->svcpart }
269 # qsearch('export_svc', { 'exportnum' => $part_export->exportnum });
272 #my $nodomain = $exports->{$part_export->exporttype}{'nodomain'};
273 #silly kludge to avoid uninitialized value errors
274 my $nodomain = exists( $exports->{$part_export->exporttype}{'nodomain'} )
275 ? $exports->{$part_export->exporttype}{'nodomain'}
277 if ( $nodomain =~ /^Y/i ) {
278 $conflict_user_svcpart{$_} = $part_export->exportnum
281 $conflict_userdomain_svcpart{$_} = $part_export->exportnum
286 foreach my $dup_user ( @dup_user ) {
287 my $dup_svcpart = $dup_user->cust_svc->svcpart;
288 if ( exists($conflict_user_svcpart{$dup_svcpart}) ) {
289 $dbh->rollback if $oldAutoCommit;
290 return "duplicate username: conflicts with svcnum ". $dup_user->svcnum.
291 " via exportnum ". $conflict_user_svcpart{$dup_svcpart};
295 foreach my $dup_userdomain ( @dup_userdomain ) {
296 my $dup_svcpart = $dup_userdomain->cust_svc->svcpart;
297 if ( exists($conflict_userdomain_svcpart{$dup_svcpart}) ) {
298 $dbh->rollback if $oldAutoCommit;
299 return "duplicate username\@domain: conflicts with svcnum ".
300 $dup_userdomain->svcnum. " via exportnum ".
301 $conflict_userdomain_svcpart{$dup_svcpart};
305 foreach my $dup_uid ( @dup_uid ) {
306 my $dup_svcpart = $dup_uid->cust_svc->svcpart;
307 if ( exists($conflict_user_svcpart{$dup_svcpart})
308 || exists($conflict_userdomain_svcpart{$dup_svcpart}) ) {
309 $dbh->rollback if $oldAutoCommit;
310 return "duplicate uid: conflicts with svcnum". $dup_uid->svcnum.
311 "via exportnum ". $conflict_user_svcpart{$dup_svcpart}
312 || $conflict_userdomain_svcpart{$dup_svcpart};
318 #see? i told you it was more complicated
321 $error = $self->SUPER::insert(\@jobnums);
323 $dbh->rollback if $oldAutoCommit;
327 if ( $self->usergroup ) {
328 foreach my $groupname ( @{$self->usergroup} ) {
329 my $radius_usergroup = new FS::radius_usergroup ( {
330 svcnum => $self->svcnum,
331 groupname => $groupname,
333 my $error = $radius_usergroup->insert;
335 $dbh->rollback if $oldAutoCommit;
341 #false laziness with sub replace (and cust_main)
342 my $queue = new FS::queue {
343 'svcnum' => $self->svcnum,
344 'job' => 'FS::svc_acct::append_fuzzyfiles'
346 $error = $queue->insert($self->username);
348 $dbh->rollback if $oldAutoCommit;
349 return "queueing job (transaction rolled back): $error";
352 my $cust_pkg = $self->cust_svc->cust_pkg;
355 my $cust_main = $cust_pkg->cust_main;
357 if ( $conf->exists('emailinvoiceauto') ) {
358 my @invoicing_list = $cust_main->invoicing_list;
359 push @invoicing_list, $self->email;
360 $cust_main->invoicing_list(\@invoicing_list);
365 if ( $welcome_template && $cust_pkg ) {
366 my $to = join(', ', grep { $_ ne 'POST' } $cust_main->invoicing_list );
368 my $wqueue = new FS::queue {
369 'svcnum' => $self->svcnum,
370 'job' => 'FS::svc_acct::send_email'
372 my $error = $wqueue->insert(
374 'from' => $welcome_from,
375 'subject' => $welcome_subject,
376 'mimetype' => $welcome_mimetype,
377 'body' => $welcome_template->fill_in( HASH => {
378 'custnum' => $self->custnum,
379 'username' => $self->username,
380 'password' => $self->_password,
381 'first' => $cust_main->first,
382 'last' => $cust_main->getfield('last'),
383 'pkg' => $cust_pkg->part_pkg->pkg,
387 $dbh->rollback if $oldAutoCommit;
388 return "error queuing welcome email: $error";
391 foreach my $jobnum ( @jobnums ) {
392 my $error = $wqueue->depend_insert($jobnum);
394 $dbh->rollback if $oldAutoCommit;
395 return "error queuing welcome email job dependancy: $error";
405 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
411 Deletes this account from the database. If there is an error, returns the
412 error, otherwise returns false.
414 The corresponding FS::cust_svc record will be deleted as well.
416 (TODOC: new exports!)
423 return "Can't delete an account which is a (svc_forward) source!"
424 if qsearch( 'svc_forward', { 'srcsvc' => $self->svcnum } );
426 return "Can't delete an account which is a (svc_forward) destination!"
427 if qsearch( 'svc_forward', { 'dstsvc' => $self->svcnum } );
429 return "Can't delete an account with (svc_www) web service!"
430 if qsearch( 'svc_www', { 'usersvc' => $self->usersvc } );
432 # what about records in session ? (they should refer to history table)
434 local $SIG{HUP} = 'IGNORE';
435 local $SIG{INT} = 'IGNORE';
436 local $SIG{QUIT} = 'IGNORE';
437 local $SIG{TERM} = 'IGNORE';
438 local $SIG{TSTP} = 'IGNORE';
439 local $SIG{PIPE} = 'IGNORE';
441 my $oldAutoCommit = $FS::UID::AutoCommit;
442 local $FS::UID::AutoCommit = 0;
445 foreach my $cust_main_invoice (
446 qsearch( 'cust_main_invoice', { 'dest' => $self->svcnum } )
448 unless ( defined($cust_main_invoice) ) {
449 warn "WARNING: something's wrong with qsearch";
452 my %hash = $cust_main_invoice->hash;
453 $hash{'dest'} = $self->email;
454 my $new = new FS::cust_main_invoice \%hash;
455 my $error = $new->replace($cust_main_invoice);
457 $dbh->rollback if $oldAutoCommit;
462 foreach my $svc_domain (
463 qsearch( 'svc_domain', { 'catchall' => $self->svcnum } )
465 my %hash = new FS::svc_domain->hash;
466 $hash{'catchall'} = '';
467 my $new = new FS::svc_domain \%hash;
468 my $error = $new->replace($svc_domain);
470 $dbh->rollback if $oldAutoCommit;
475 foreach my $radius_usergroup (
476 qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } )
478 my $error = $radius_usergroup->delete;
480 $dbh->rollback if $oldAutoCommit;
485 my $error = $self->SUPER::delete;
487 $dbh->rollback if $oldAutoCommit;
491 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
495 =item replace OLD_RECORD
497 Replaces OLD_RECORD with this one in the database. If there is an error,
498 returns the error, otherwise returns false.
500 The additional field I<usergroup> can optionally be defined; if so it should
501 contain an arrayref of group names. See L<FS::radius_usergroup>. (used in
502 sqlradius export only)
507 my ( $new, $old ) = ( shift, shift );
509 warn "$me replacing $old with $new\n" if $DEBUG;
511 return "Username in use"
512 if $old->username ne $new->username &&
513 qsearchs( 'svc_acct', { 'username' => $new->username,
514 'domsvc' => $new->domsvc,
517 #no warnings 'numeric'; #alas, a 5.006-ism
519 return "Can't change uid!" if $old->uid != $new->uid;
522 #change homdir when we change username
523 $new->setfield('dir', '') if $old->username ne $new->username;
525 local $SIG{HUP} = 'IGNORE';
526 local $SIG{INT} = 'IGNORE';
527 local $SIG{QUIT} = 'IGNORE';
528 local $SIG{TERM} = 'IGNORE';
529 local $SIG{TSTP} = 'IGNORE';
530 local $SIG{PIPE} = 'IGNORE';
532 my $oldAutoCommit = $FS::UID::AutoCommit;
533 local $FS::UID::AutoCommit = 0;
536 # redundant, but so $new->usergroup gets set
537 $error = $new->check;
538 return $error if $error;
540 $old->usergroup( [ $old->radius_groups ] );
541 warn "old groups: ". join(' ',@{$old->usergroup}). "\n" if $DEBUG;
542 warn "new groups: ". join(' ',@{$new->usergroup}). "\n" if $DEBUG;
543 if ( $new->usergroup ) {
544 #(sorta) false laziness with FS::part_export::sqlradius::_export_replace
545 my @newgroups = @{$new->usergroup};
546 foreach my $oldgroup ( @{$old->usergroup} ) {
547 if ( grep { $oldgroup eq $_ } @newgroups ) {
548 @newgroups = grep { $oldgroup ne $_ } @newgroups;
551 my $radius_usergroup = qsearchs('radius_usergroup', {
552 svcnum => $old->svcnum,
553 groupname => $oldgroup,
555 my $error = $radius_usergroup->delete;
557 $dbh->rollback if $oldAutoCommit;
558 return "error deleting radius_usergroup $oldgroup: $error";
562 foreach my $newgroup ( @newgroups ) {
563 my $radius_usergroup = new FS::radius_usergroup ( {
564 svcnum => $new->svcnum,
565 groupname => $newgroup,
567 my $error = $radius_usergroup->insert;
569 $dbh->rollback if $oldAutoCommit;
570 return "error adding radius_usergroup $newgroup: $error";
576 $error = $new->SUPER::replace($old);
578 $dbh->rollback if $oldAutoCommit;
579 return $error if $error;
582 if ( $new->username ne $old->username ) {
583 #false laziness with sub insert (and cust_main)
584 my $queue = new FS::queue {
585 'svcnum' => $new->svcnum,
586 'job' => 'FS::svc_acct::append_fuzzyfiles'
588 $error = $queue->insert($new->username);
590 $dbh->rollback if $oldAutoCommit;
591 return "queueing job (transaction rolled back): $error";
595 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
601 Suspends this account by prefixing *SUSPENDED* to the password. If there is an
602 error, returns the error, otherwise returns false.
604 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
606 Calls any export-specific suspend hooks.
612 my %hash = $self->hash;
613 unless ( $hash{_password} =~ /^\*SUSPENDED\* /
614 || $hash{_password} eq '*'
616 $hash{_password} = '*SUSPENDED* '.$hash{_password};
617 my $new = new FS::svc_acct ( \%hash );
618 my $error = $new->replace($self);
619 return $error if $error;
622 $self->SUPER::suspend;
627 Unsuspends this account by removing *SUSPENDED* from the password. If there is
628 an error, returns the error, otherwise returns false.
630 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
632 Calls any export-specific unsuspend hooks.
638 my %hash = $self->hash;
639 if ( $hash{_password} =~ /^\*SUSPENDED\* (.*)$/ ) {
640 $hash{_password} = $1;
641 my $new = new FS::svc_acct ( \%hash );
642 my $error = $new->replace($self);
643 return $error if $error;
646 $self->SUPER::unsuspend;
651 Just returns false (no error) for now.
653 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
657 Checks all fields to make sure this is a valid service. If there is an error,
658 returns the error, otherwise returns false. Called by the insert and replace
661 Sets any fixed values; see L<FS::part_svc>.
668 my($recref) = $self->hashref;
670 my $x = $self->setfixed;
671 return $x unless ref($x);
674 if ( $part_svc->part_svc_column('usergroup')->columnflag eq "F" ) {
676 [ split(',', $part_svc->part_svc_column('usergroup')->columnvalue) ] );
679 my $error = $self->ut_numbern('svcnum')
680 #|| $self->ut_number('domsvc')
681 || $self->ut_foreign_key('domsvc', 'svc_domain', 'svcnum' )
682 || $self->ut_textn('sec_phrase')
684 return $error if $error;
686 my $ulen = $usernamemax || $self->dbdef_table->column('username')->length;
687 if ( $username_uppercase ) {
688 $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/i
689 or return gettext('illegal_username'). " ($usernamemin-$ulen): ". $recref->{username};
690 $recref->{username} = $1;
692 $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/
693 or return gettext('illegal_username'). " ($usernamemin-$ulen): ". $recref->{username};
694 $recref->{username} = $1;
697 if ( $username_letterfirst ) {
698 $recref->{username} =~ /^[a-z]/ or return gettext('illegal_username');
699 } elsif ( $username_letter ) {
700 $recref->{username} =~ /[a-z]/ or return gettext('illegal_username');
702 if ( $username_noperiod ) {
703 $recref->{username} =~ /\./ and return gettext('illegal_username');
705 if ( $username_nounderscore ) {
706 $recref->{username} =~ /_/ and return gettext('illegal_username');
708 if ( $username_nodash ) {
709 $recref->{username} =~ /\-/ and return gettext('illegal_username');
711 unless ( $username_ampersand ) {
712 $recref->{username} =~ /\&/ and return gettext('illegal_username');
715 $recref->{popnum} =~ /^(\d*)$/ or return "Illegal popnum: ".$recref->{popnum};
716 $recref->{popnum} = $1;
717 return "Unknown popnum" unless
718 ! $recref->{popnum} ||
719 qsearchs('svc_acct_pop',{'popnum'=> $recref->{popnum} } );
721 unless ( $part_svc->part_svc_column('uid')->columnflag eq 'F' ) {
723 $recref->{uid} =~ /^(\d*)$/ or return "Illegal uid";
724 $recref->{uid} = $1 eq '' ? $self->unique('uid') : $1;
726 $recref->{gid} =~ /^(\d*)$/ or return "Illegal gid";
727 $recref->{gid} = $1 eq '' ? $recref->{uid} : $1;
728 #not all systems use gid=uid
729 #you can set a fixed gid in part_svc
731 return "Only root can have uid 0"
732 if $recref->{uid} == 0
733 && $recref->{username} ne 'root'
734 && $recref->{username} ne 'toor';
737 $recref->{dir} =~ /^([\/\w\-\.\&]*)$/
738 or return "Illegal directory: ". $recref->{dir};
740 return "Illegal directory"
741 if $recref->{dir} =~ /(^|\/)\.+(\/|$)/; #no .. component
742 return "Illegal directory"
743 if $recref->{dir} =~ /\&/ && ! $username_ampersand;
744 unless ( $recref->{dir} ) {
745 $recref->{dir} = $dir_prefix . '/';
746 if ( $dirhash > 0 ) {
747 for my $h ( 1 .. $dirhash ) {
748 $recref->{dir} .= substr($recref->{username}, $h-1, 1). '/';
750 } elsif ( $dirhash < 0 ) {
751 for my $h ( reverse $dirhash .. -1 ) {
752 $recref->{dir} .= substr($recref->{username}, $h, 1). '/';
755 $recref->{dir} .= $recref->{username};
759 unless ( $recref->{username} eq 'sync' ) {
760 if ( grep $_ eq $recref->{shell}, @shells ) {
761 $recref->{shell} = (grep $_ eq $recref->{shell}, @shells)[0];
763 return "Illegal shell \`". $self->shell. "\'; ".
764 $conf->dir. "/shells contains: @shells";
767 $recref->{shell} = '/bin/sync';
771 $recref->{gid} ne '' ?
772 return "Can't have gid without uid" : ( $recref->{gid}='' );
773 $recref->{dir} ne '' ?
774 return "Can't have directory without uid" : ( $recref->{dir}='' );
775 $recref->{shell} ne '' ?
776 return "Can't have shell without uid" : ( $recref->{shell}='' );
779 # $error = $self->ut_textn('finger');
780 # return $error if $error;
781 $self->getfield('finger') =~
782 /^([\w \t\!\@\#\$\%\&\(\)\-\+\;\'\"\,\.\?\/\*\<\>]*)$/
783 or return "Illegal finger: ". $self->getfield('finger');
784 $self->setfield('finger', $1);
786 $recref->{quota} =~ /^(\d*)$/ or return "Illegal quota";
787 $recref->{quota} = $1;
789 unless ( $part_svc->part_svc_column('slipip')->columnflag eq 'F' ) {
790 if ( $recref->{slipip} eq '' ) {
791 $recref->{slipip} = '';
792 } elsif ( $recref->{slipip} eq '0e0' ) {
793 $recref->{slipip} = '0e0';
795 $recref->{slipip} =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/
796 or return "Illegal slipip: ". $self->slipip;
797 $recref->{slipip} = $1;
802 #arbitrary RADIUS stuff; allow ut_textn for now
803 foreach ( grep /^radius_/, fields('svc_acct') ) {
807 #generate a password if it is blank
808 $recref->{_password} = join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) )
809 unless ( $recref->{_password} );
811 #if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{4,16})$/ ) {
812 if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{$passwordmin,$passwordmax})$/ ) {
813 $recref->{_password} = $1.$3;
814 #uncomment this to encrypt password immediately upon entry, or run
815 #bin/crypt_pw in cron to give new users a window during which their
816 #password is available to techs, for faxing, etc. (also be aware of
818 #$recref->{password} = $1.
819 # crypt($3,$saltset[int(rand(64))].$saltset[int(rand(64))]
821 } elsif ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([\w\.\/\$\;\+]{13,34})$/ ) {
822 $recref->{_password} = $1.$3;
823 } elsif ( $recref->{_password} eq '*' ) {
824 $recref->{_password} = '*';
825 } elsif ( $recref->{_password} eq '!!' ) {
826 $recref->{_password} = '!!';
828 #return "Illegal password";
829 return gettext('illegal_password'). " $passwordmin-$passwordmax ".
830 FS::Msgcat::_gettext('illegal_password_characters').
831 ": ". $recref->{_password};
839 Depriciated, use radius_reply instead.
844 carp "FS::svc_acct::radius depriciated, use radius_reply";
850 Returns key/value pairs, suitable for assigning to a hash, for any RADIUS
851 reply attributes of this record.
853 Note that this is now the preferred method for reading RADIUS attributes -
854 accessing the columns directly is discouraged, as the column names are
855 expected to change in the future.
864 my($column, $attrib) = ($1, $2);
865 #$attrib =~ s/_/\-/g;
866 ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) );
867 } grep { /^radius_/ && $self->getfield($_) } fields( $self->table );
868 if ( $self->slipip && $self->slipip ne '0e0' ) {
869 $reply{'Framed-IP-Address'} = $self->slipip;
876 Returns key/value pairs, suitable for assigning to a hash, for any RADIUS
877 check attributes of this record.
879 Note that this is now the preferred method for reading RADIUS attributes -
880 accessing the columns directly is discouraged, as the column names are
881 expected to change in the future.
887 my $password = $self->_password;
888 my $pw_attrib = length($password) <= 12 ? $radius_password : 'Crypt-Password';
889 ( $pw_attrib => $password,
892 my($column, $attrib) = ($1, $2);
893 #$attrib =~ s/_/\-/g;
894 ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) );
895 } grep { /^rc_/ && $self->getfield($_) } fields( $self->table )
901 Returns the domain associated with this account.
907 die "svc_acct.domsvc is null for svcnum ". $self->svcnum unless $self->domsvc;
908 my $svc_domain = $self->svc_domain
909 or die "no svc_domain.svcnum for svc_acct.domsvc ". $self->domsvc;
915 Returns the FS::svc_domain record for this account's domain (see
924 : qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } );
929 Returns the FS::cust_svc record for this account (see L<FS::cust_svc>).
935 qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
940 Returns an email address associated with the account.
946 $self->username. '@'. $self->domain;
949 =item seconds_since TIMESTAMP
951 Returns the number of seconds this account has been online since TIMESTAMP,
952 according to the session monitor (see L<FS::Session>).
954 TIMESTAMP is specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
955 L<Time::Local> and L<Date::Parse> for conversion functions.
959 #note: POD here, implementation in FS::cust_svc
962 $self->cust_svc->seconds_since(@_);
965 =item seconds_since_sqlradacct TIMESTAMP_START TIMESTAMP_END
967 Returns the numbers of seconds this account has been online between
968 TIMESTAMP_START (inclusive) and TIMESTAMP_END (exclusive), according to an
969 external SQL radacct table, specified via sqlradius export. Sessions which
970 started in the specified range but are still open are counted from session
971 start to the end of the range (unless they are over 1 day old, in which case
972 they are presumed missing their stop record and not counted). Also, sessions
973 which end in therange but started earlier are counted from the start of the
974 range to session end. Finally, sessions which start before the range but end
975 after are counted for the entire range.
977 TIMESTAMP_START and TIMESTAMP_END are specified as UNIX timestamps; see
978 L<perlfunc/"time">. Also see L<Time::Local> and L<Date::Parse> for conversion
983 #note: POD here, implementation in FS::cust_svc
984 sub seconds_since_sqlradacct {
986 $self->cust_svc->seconds_since_sqlradacct(@_);
989 =item attribute_since_sqlradacct TIMESTAMP_START TIMESTAMP_END ATTRIBUTE
991 Returns the sum of the given attribute for all accounts (see L<FS::svc_acct>)
992 in this package for sessions ending between TIMESTAMP_START (inclusive) and
993 TIMESTAMP_END (exclusive).
995 TIMESTAMP_START and TIMESTAMP_END are specified as UNIX timestamps; see
996 L<perlfunc/"time">. Also see L<Time::Local> and L<Date::Parse> for conversion
1001 #note: POD here, implementation in FS::cust_svc
1002 sub attribute_since_sqlradacct {
1004 $self->cust_svc->attribute_since_sqlradacct(@_);
1009 Returns all RADIUS groups for this account (see L<FS::radius_usergroup>).
1015 if ( $self->usergroup ) {
1016 #when provisioning records, export callback runs in svc_Common.pm before
1017 #radius_usergroup records can be inserted...
1018 @{$self->usergroup};
1020 map { $_->groupname }
1021 qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } );
1033 This is the FS::svc_acct job-queue-able version. It still uses
1034 FS::Misc::send_email under-the-hood.
1041 eval "use FS::Misc qw(send_email)";
1044 $opt{mimetype} ||= 'text/plain';
1045 $opt{mimetype} .= '; charset="iso-8859-1"' unless $opt{mimetype} =~ /charset/;
1047 my $error = send_email(
1048 'from' => $opt{from},
1050 'subject' => $opt{subject},
1051 'content-type' => $opt{mimetype},
1052 'body' => [ map "$_\n", split("\n", $opt{body}) ],
1054 die $error if $error;
1057 =item check_and_rebuild_fuzzyfiles
1061 sub check_and_rebuild_fuzzyfiles {
1062 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
1063 -e "$dir/svc_acct.username"
1064 or &rebuild_fuzzyfiles;
1067 =item rebuild_fuzzyfiles
1071 sub rebuild_fuzzyfiles {
1073 use Fcntl qw(:flock);
1075 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
1079 open(USERNAMELOCK,">>$dir/svc_acct.username")
1080 or die "can't open $dir/svc_acct.username: $!";
1081 flock(USERNAMELOCK,LOCK_EX)
1082 or die "can't lock $dir/svc_acct.username: $!";
1084 my @all_username = map $_->getfield('username'), qsearch('svc_acct', {});
1086 open (USERNAMECACHE,">$dir/svc_acct.username.tmp")
1087 or die "can't open $dir/svc_acct.username.tmp: $!";
1088 print USERNAMECACHE join("\n", @all_username), "\n";
1089 close USERNAMECACHE or die "can't close $dir/svc_acct.username.tmp: $!";
1091 rename "$dir/svc_acct.username.tmp", "$dir/svc_acct.username";
1101 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
1102 open(USERNAMECACHE,"<$dir/svc_acct.username")
1103 or die "can't open $dir/svc_acct.username: $!";
1104 my @array = map { chomp; $_; } <USERNAMECACHE>;
1105 close USERNAMECACHE;
1109 =item append_fuzzyfiles USERNAME
1113 sub append_fuzzyfiles {
1114 my $username = shift;
1116 &check_and_rebuild_fuzzyfiles;
1118 use Fcntl qw(:flock);
1120 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
1122 open(USERNAME,">>$dir/svc_acct.username")
1123 or die "can't open $dir/svc_acct.username: $!";
1124 flock(USERNAME,LOCK_EX)
1125 or die "can't lock $dir/svc_acct.username: $!";
1127 print USERNAME "$username\n";
1129 flock(USERNAME,LOCK_UN)
1130 or die "can't unlock $dir/svc_acct.username: $!";
1138 =item radius_usergroup_selector GROUPS_ARRAYREF [ SELECTNAME ]
1142 sub radius_usergroup_selector {
1143 my $sel_groups = shift;
1144 my %sel_groups = map { $_=>1 } @$sel_groups;
1146 my $selectname = shift || 'radius_usergroup';
1149 my $sth = $dbh->prepare(
1150 'SELECT DISTINCT(groupname) FROM radius_usergroup ORDER BY groupname'
1151 ) or die $dbh->errstr;
1152 $sth->execute() or die $sth->errstr;
1153 my @all_groups = map { $_->[0] } @{$sth->fetchall_arrayref};
1157 function ${selectname}_doadd(object) {
1158 var myvalue = object.${selectname}_add.value;
1159 var optionName = new Option(myvalue,myvalue,false,true);
1160 var length = object.$selectname.length;
1161 object.$selectname.options[length] = optionName;
1162 object.${selectname}_add.value = "";
1165 <SELECT MULTIPLE NAME="$selectname">
1168 foreach my $group ( @all_groups ) {
1170 if ( $sel_groups{$group} ) {
1171 $html .= ' SELECTED';
1172 $sel_groups{$group} = 0;
1174 $html .= ">$group</OPTION>\n";
1176 foreach my $group ( grep { $sel_groups{$_} } keys %sel_groups ) {
1177 $html .= "<OPTION SELECTED>$group</OPTION>\n";
1179 $html .= '</SELECT>';
1181 $html .= qq!<BR><INPUT TYPE="text" NAME="${selectname}_add">!.
1182 qq!<INPUT TYPE="button" VALUE="Add new group" onClick="${selectname}_doadd(this.form)">!;
1191 The $recref stuff in sub check should be cleaned up.
1193 The suspend, unsuspend and cancel methods update the database, but not the
1194 current object. This is probably a bug as it's unexpected and
1197 radius_usergroup_selector? putting web ui components in here? they should
1198 probably live somewhere else...
1202 L<FS::svc_Common>, edit/part_svc.cgi from an installed web interface,
1203 export.html from the base documentation, L<FS::Record>, L<FS::Conf>,
1204 L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>, L<FS::queue>,
1205 L<freeside-queued>), L<FS::svc_acct_pop>,
1206 schema.html from the base documentation.