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
10 $welcome_template $welcome_from $welcome_subject $welcome_mimetype
16 use FS::UID qw( datasrc );
18 use FS::Record qw( qsearch qsearchs fields dbh );
23 use FS::cust_main_invoice;
27 use FS::radius_usergroup;
30 use FS::Msgcat qw(gettext);
32 @ISA = qw( FS::svc_Common );
34 #ask FS::UID to run this stuff for us later
35 $FS::UID::callback{'FS::svc_acct'} = sub {
37 $dir_prefix = $conf->config('home');
38 @shells = $conf->config('shells');
39 $usernamemin = $conf->config('usernamemin') || 2;
40 $usernamemax = $conf->config('usernamemax');
41 $passwordmin = $conf->config('passwordmin') || 6;
42 $passwordmax = $conf->config('passwordmax') || 8;
43 $username_letter = $conf->exists('username-letter');
44 $username_letterfirst = $conf->exists('username-letterfirst');
45 $username_noperiod = $conf->exists('username-noperiod');
46 $username_nounderscore = $conf->exists('username-nounderscore');
47 $username_nodash = $conf->exists('username-nodash');
48 $username_uppercase = $conf->exists('username-uppercase');
49 $username_ampersand = $conf->exists('username-ampersand');
50 $dirhash = $conf->config('dirhash') || 0;
51 if ( $conf->exists('welcome_email') ) {
52 $welcome_template = new Text::Template (
54 SOURCE => [ map "$_\n", $conf->config('welcome_email') ]
55 ) or warn "can't create welcome email template: $Text::Template::ERROR";
56 $welcome_from = $conf->config('welcome_email-from'); # || 'your-isp-is-dum'
57 $welcome_subject = $conf->config('welcome_email-subject') || 'Welcome';
58 $welcome_mimetype = $conf->config('welcome_email-mimetype') || 'text/plain';
60 $welcome_template = '';
62 $smtpmachine = $conf->config('smtpmachine');
65 @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' );
66 @pw_set = ( 'a'..'z', 'A'..'Z', '0'..'9', '(', ')', '#', '!', '.', ',' );
70 my ( $hashref, $cache ) = @_;
71 if ( $hashref->{'svc_acct_svcnum'} ) {
72 $self->{'_domsvc'} = FS::svc_domain->new( {
73 'svcnum' => $hashref->{'domsvc'},
74 'domain' => $hashref->{'svc_acct_domain'},
75 'catchall' => $hashref->{'svc_acct_catchall'},
82 FS::svc_acct - Object methods for svc_acct records
88 $record = new FS::svc_acct \%hash;
89 $record = new FS::svc_acct { 'column' => 'value' };
91 $error = $record->insert;
93 $error = $new_record->replace($old_record);
95 $error = $record->delete;
97 $error = $record->check;
99 $error = $record->suspend;
101 $error = $record->unsuspend;
103 $error = $record->cancel;
105 %hash = $record->radius;
107 %hash = $record->radius_reply;
109 %hash = $record->radius_check;
111 $domain = $record->domain;
113 $svc_domain = $record->svc_domain;
115 $email = $record->email;
117 $seconds_since = $record->seconds_since($timestamp);
121 An FS::svc_acct object represents an account. FS::svc_acct inherits from
122 FS::svc_Common. The following fields are currently supported:
126 =item svcnum - primary key (assigned automatcially for new accounts)
130 =item _password - generated if blank
132 =item sec_phrase - security phrase
134 =item popnum - Point of presence (see L<FS::svc_acct_pop>)
142 =item dir - set automatically if blank (and uid is not)
146 =item quota - (unimplementd)
148 =item slipip - IP address
152 =item domsvc - svcnum from svc_domain
154 =item radius_I<Radius_Attribute> - I<Radius-Attribute>
164 Creates a new account. To add the account to the database, see L<"insert">.
168 sub table { 'svc_acct'; }
172 Adds this account to the database. If there is an error, returns the error,
173 otherwise returns false.
175 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
176 defined. An FS::cust_svc record will be created and inserted.
178 The additional field I<usergroup> can optionally be defined; if so it should
179 contain an arrayref of group names. See L<FS::radius_usergroup>. (used in
180 sqlradius export only)
182 (TODOC: L<FS::queue> and L<freeside-queued>)
184 (TODOC: new exports! $noexport_hack)
192 local $SIG{HUP} = 'IGNORE';
193 local $SIG{INT} = 'IGNORE';
194 local $SIG{QUIT} = 'IGNORE';
195 local $SIG{TERM} = 'IGNORE';
196 local $SIG{TSTP} = 'IGNORE';
197 local $SIG{PIPE} = 'IGNORE';
199 my $oldAutoCommit = $FS::UID::AutoCommit;
200 local $FS::UID::AutoCommit = 0;
203 $error = $self->check;
204 return $error if $error;
206 #no, duplicate checking just got a whole lot more complicated
207 #(perhaps keep this check with a config option to turn on?)
209 #return gettext('username_in_use'). ": ". $self->username
210 # if qsearchs( 'svc_acct', { 'username' => $self->username,
211 # 'domsvc' => $self->domsvc,
214 if ( $self->svcnum ) {
215 my $cust_svc = qsearchs('cust_svc',{'svcnum'=>$self->svcnum});
216 unless ( $cust_svc ) {
217 $dbh->rollback if $oldAutoCommit;
218 return "no cust_svc record found for svcnum ". $self->svcnum;
220 $self->pkgnum($cust_svc->pkgnum);
221 $self->svcpart($cust_svc->svcpart);
224 #new duplicate username checking
226 my $part_svc = qsearchs('part_svc', { 'svcpart' => $self->svcpart } );
227 unless ( $part_svc ) {
228 $dbh->rollback if $oldAutoCommit;
229 return 'unknown svcpart '. $self->svcpart;
232 my @dup_user = qsearch( 'svc_acct', { 'username' => $self->username } );
233 my @dup_userdomain = qsearch( 'svc_acct', { 'username' => $self->username,
234 'domsvc' => $self->domsvc } );
236 if ( $part_svc->part_svc_column('uid')->columnflag ne 'F'
237 && $self->username !~ /^(toor|(hyla)?fax)$/ ) {
238 @dup_uid = qsearch( 'svc_acct', { 'uid' => $self->uid } );
243 if ( @dup_user || @dup_userdomain || @dup_uid ) {
244 my $exports = FS::part_export::export_info('svc_acct');
245 my %conflict_user_svcpart;
246 my %conflict_userdomain_svcpart = ( $self->svcpart => 'SELF', );
248 foreach my $part_export ( $part_svc->part_export ) {
250 #this will catch to the same exact export
251 my @svcparts = map { $_->svcpart }
252 qsearch('export_svc', { 'exportnum' => $part_export->exportnum });
254 #this will catch to exports w/same exporthost+type ???
255 #my @other_part_export = qsearch('part_export', {
256 # 'machine' => $part_export->machine,
257 # 'exporttype' => $part_export->exporttype,
259 #foreach my $other_part_export ( @other_part_export ) {
260 # push @svcparts, map { $_->svcpart }
261 # qsearch('export_svc', { 'exportnum' => $part_export->exportnum });
264 my $nodomain = $exports->{$part_export->exporttype}{'nodomain'};
265 if ( $nodomain =~ /^Y/i ) {
266 $conflict_user_svcpart{$_} = $part_export->exportnum
269 $conflict_userdomain_svcpart{$_} = $part_export->exportnum
274 foreach my $dup_user ( @dup_user ) {
275 my $dup_svcpart = $dup_user->cust_svc->svcpart;
276 if ( exists($conflict_user_svcpart{$dup_svcpart}) ) {
277 $dbh->rollback if $oldAutoCommit;
278 return "duplicate username: conflicts with svcnum ". $dup_user->svcnum.
279 " via exportnum ". $conflict_user_svcpart{$dup_svcpart};
283 foreach my $dup_userdomain ( @dup_userdomain ) {
284 my $dup_svcpart = $dup_userdomain->cust_svc->svcpart;
285 if ( exists($conflict_userdomain_svcpart{$dup_svcpart}) ) {
286 $dbh->rollback if $oldAutoCommit;
287 return "duplicate username\@domain: conflicts with svcnum ".
288 $dup_userdomain->svcnum. " via exportnum ".
289 $conflict_userdomain_svcpart{$dup_svcpart};
293 foreach my $dup_uid ( @dup_uid ) {
294 my $dup_svcpart = $dup_uid->cust_svc->svcpart;
295 if ( exists($conflict_user_svcpart{$dup_svcpart})
296 || exists($conflict_userdomain_svcpart{$dup_svcpart}) ) {
297 $dbh->rollback if $oldAutoCommit;
298 return "duplicate uid: conflicts with svcnum". $dup_uid->svcnum.
299 "via exportnum ". $conflict_user_svcpart{$dup_svcpart}
300 || $conflict_userdomain_svcpart{$dup_svcpart};
306 #see? i told you it was more complicated
309 $error = $self->SUPER::insert(\@jobnums);
311 $dbh->rollback if $oldAutoCommit;
315 if ( $self->usergroup ) {
316 foreach my $groupname ( @{$self->usergroup} ) {
317 my $radius_usergroup = new FS::radius_usergroup ( {
318 svcnum => $self->svcnum,
319 groupname => $groupname,
321 my $error = $radius_usergroup->insert;
323 $dbh->rollback if $oldAutoCommit;
329 #false laziness with sub replace (and cust_main)
330 my $queue = new FS::queue {
331 'svcnum' => $self->svcnum,
332 'job' => 'FS::svc_acct::append_fuzzyfiles'
334 $error = $queue->insert($self->username);
336 $dbh->rollback if $oldAutoCommit;
337 return "queueing job (transaction rolled back): $error";
340 my $cust_pkg = $self->cust_svc->cust_pkg;
341 my $cust_main = $cust_pkg->cust_main;
343 if ( $conf->exists('emailinvoiceauto') ) {
344 my @invoicing_list = $cust_main->invoicing_list;
345 push @invoicing_list, $self->email;
346 $cust_main->invoicing_list(@invoicing_list);
351 if ( $welcome_template && $cust_pkg ) {
352 my $to = join(', ', grep { $_ ne 'POST' } $cust_main->invoicing_list );
354 my $wqueue = new FS::queue {
355 'svcnum' => $self->svcnum,
356 'job' => 'FS::svc_acct::send_email'
358 warn "attempting to queue email to $to";
359 my $error = $wqueue->insert(
361 'from' => $welcome_from,
362 'subject' => $welcome_subject,
363 'mimetype' => $welcome_mimetype,
364 'body' => $welcome_template->fill_in( HASH => {
365 'username' => $self->username,
366 'password' => $self->_password,
367 'first' => $cust_main->first,
368 'last' => $cust_main->getfield('last'),
369 'pkg' => $cust_pkg->part_pkg->pkg,
373 $dbh->rollback if $oldAutoCommit;
374 return "queuing welcome email: $error";
377 foreach my $jobnum ( @jobnums ) {
378 my $error = $wqueue->depend_insert($jobnum);
380 $dbh->rollback if $oldAutoCommit;
381 return "queuing welcome email job dependancy: $error";
389 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
395 Deletes this account from the database. If there is an error, returns the
396 error, otherwise returns false.
398 The corresponding FS::cust_svc record will be deleted as well.
400 (TODOC: new exports! $noexport_hack)
407 return "Can't delete an account which is a (svc_forward) source!"
408 if qsearch( 'svc_forward', { 'srcsvc' => $self->svcnum } );
410 return "Can't delete an account which is a (svc_forward) destination!"
411 if qsearch( 'svc_forward', { 'dstsvc' => $self->svcnum } );
413 return "Can't delete an account with (svc_www) web service!"
414 if qsearch( 'svc_www', { 'usersvc' => $self->usersvc } );
416 # what about records in session ? (they should refer to history table)
418 local $SIG{HUP} = 'IGNORE';
419 local $SIG{INT} = 'IGNORE';
420 local $SIG{QUIT} = 'IGNORE';
421 local $SIG{TERM} = 'IGNORE';
422 local $SIG{TSTP} = 'IGNORE';
423 local $SIG{PIPE} = 'IGNORE';
425 my $oldAutoCommit = $FS::UID::AutoCommit;
426 local $FS::UID::AutoCommit = 0;
429 foreach my $cust_main_invoice (
430 qsearch( 'cust_main_invoice', { 'dest' => $self->svcnum } )
432 unless ( defined($cust_main_invoice) ) {
433 warn "WARNING: something's wrong with qsearch";
436 my %hash = $cust_main_invoice->hash;
437 $hash{'dest'} = $self->email;
438 my $new = new FS::cust_main_invoice \%hash;
439 my $error = $new->replace($cust_main_invoice);
441 $dbh->rollback if $oldAutoCommit;
446 foreach my $svc_domain (
447 qsearch( 'svc_domain', { 'catchall' => $self->svcnum } )
449 my %hash = new FS::svc_domain->hash;
450 $hash{'catchall'} = '';
451 my $new = new FS::svc_domain \%hash;
452 my $error = $new->replace($svc_domain);
454 $dbh->rollback if $oldAutoCommit;
459 foreach my $radius_usergroup (
460 qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } )
462 my $error = $radius_usergroup->delete;
464 $dbh->rollback if $oldAutoCommit;
469 my $error = $self->SUPER::delete;
471 $dbh->rollback if $oldAutoCommit;
475 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
479 =item replace OLD_RECORD
481 Replaces OLD_RECORD with this one in the database. If there is an error,
482 returns the error, otherwise returns false.
484 The additional field I<usergroup> can optionally be defined; if so it should
485 contain an arrayref of group names. See L<FS::radius_usergroup>. (used in
486 sqlradius export only)
491 my ( $new, $old ) = ( shift, shift );
494 return "Username in use"
495 if $old->username ne $new->username &&
496 qsearchs( 'svc_acct', { 'username' => $new->username,
497 'domsvc' => $new->domsvc,
500 #no warnings 'numeric'; #alas, a 5.006-ism
502 return "Can't change uid!" if $old->uid != $new->uid;
505 #change homdir when we change username
506 $new->setfield('dir', '') if $old->username ne $new->username;
508 local $SIG{HUP} = 'IGNORE';
509 local $SIG{INT} = 'IGNORE';
510 local $SIG{QUIT} = 'IGNORE';
511 local $SIG{TERM} = 'IGNORE';
512 local $SIG{TSTP} = 'IGNORE';
513 local $SIG{PIPE} = 'IGNORE';
515 my $oldAutoCommit = $FS::UID::AutoCommit;
516 local $FS::UID::AutoCommit = 0;
519 $old->usergroup( [ $old->radius_groups ] );
520 if ( $new->usergroup ) {
521 #(sorta) false laziness with FS::part_export::sqlradius::_export_replace
522 my @newgroups = @{$new->usergroup};
523 foreach my $oldgroup ( @{$old->usergroup} ) {
524 if ( grep { $oldgroup eq $_ } @newgroups ) {
525 @newgroups = grep { $oldgroup ne $_ } @newgroups;
528 my $radius_usergroup = qsearchs('radius_usergroup', {
529 svcnum => $old->svcnum,
530 groupname => $oldgroup,
532 my $error = $radius_usergroup->delete;
534 $dbh->rollback if $oldAutoCommit;
535 return "error deleting radius_usergroup $oldgroup: $error";
539 foreach my $newgroup ( @newgroups ) {
540 my $radius_usergroup = new FS::radius_usergroup ( {
541 svcnum => $new->svcnum,
542 groupname => $newgroup,
544 my $error = $radius_usergroup->insert;
546 $dbh->rollback if $oldAutoCommit;
547 return "error adding radius_usergroup $newgroup: $error";
553 $error = $new->SUPER::replace($old);
555 $dbh->rollback if $oldAutoCommit;
556 return $error if $error;
559 #false laziness with sub insert (and cust_main)
560 my $queue = new FS::queue {
561 'svcnum' => $new->svcnum,
562 'job' => 'FS::svc_acct::append_fuzzyfiles'
564 $error = $queue->insert($new->username);
566 $dbh->rollback if $oldAutoCommit;
567 return "queueing job (transaction rolled back): $error";
571 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
577 Suspends this account by prefixing *SUSPENDED* to the password. If there is an
578 error, returns the error, otherwise returns false.
580 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
586 my %hash = $self->hash;
587 unless ( $hash{_password} =~ /^\*SUSPENDED\* /
588 || $hash{_password} eq '*'
590 $hash{_password} = '*SUSPENDED* '.$hash{_password};
591 my $new = new FS::svc_acct ( \%hash );
592 my $error = $new->replace($self);
593 return $error if $error;
596 $self->SUPER::suspend;
601 Unsuspends this account by removing *SUSPENDED* from the password. If there is
602 an error, returns the error, otherwise returns false.
604 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
610 my %hash = $self->hash;
611 if ( $hash{_password} =~ /^\*SUSPENDED\* (.*)$/ ) {
612 $hash{_password} = $1;
613 my $new = new FS::svc_acct ( \%hash );
614 my $error = $new->replace($self);
615 return $error if $error;
618 $self->SUPER::unsuspend;
623 Just returns false (no error) for now.
625 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
629 Checks all fields to make sure this is a valid service. If there is an error,
630 returns the error, otherwise returns false. Called by the insert and replace
633 Sets any fixed values; see L<FS::part_svc>.
640 my($recref) = $self->hashref;
642 my $x = $self->setfixed;
643 return $x unless ref($x);
646 if ( $part_svc->part_svc_column('usergroup')->columnflag eq "F" ) {
648 [ split(',', $part_svc->part_svc_column('usergroup')->columnvalue) ] );
651 my $error = $self->ut_numbern('svcnum')
652 || $self->ut_number('domsvc')
653 || $self->ut_textn('sec_phrase')
655 return $error if $error;
657 my $ulen = $usernamemax || $self->dbdef_table->column('username')->length;
658 if ( $username_uppercase ) {
659 $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/i
660 or return gettext('illegal_username'). " ($usernamemin-$ulen): ". $recref->{username};
661 $recref->{username} = $1;
663 $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/
664 or return gettext('illegal_username'). " ($usernamemin-$ulen): ". $recref->{username};
665 $recref->{username} = $1;
668 if ( $username_letterfirst ) {
669 $recref->{username} =~ /^[a-z]/ or return gettext('illegal_username');
670 } elsif ( $username_letter ) {
671 $recref->{username} =~ /[a-z]/ or return gettext('illegal_username');
673 if ( $username_noperiod ) {
674 $recref->{username} =~ /\./ and return gettext('illegal_username');
676 if ( $username_nounderscore ) {
677 $recref->{username} =~ /_/ and return gettext('illegal_username');
679 if ( $username_nodash ) {
680 $recref->{username} =~ /\-/ and return gettext('illegal_username');
682 unless ( $username_ampersand ) {
683 $recref->{username} =~ /\&/ and return gettext('illegal_username');
686 $recref->{popnum} =~ /^(\d*)$/ or return "Illegal popnum: ".$recref->{popnum};
687 $recref->{popnum} = $1;
688 return "Unknown popnum" unless
689 ! $recref->{popnum} ||
690 qsearchs('svc_acct_pop',{'popnum'=> $recref->{popnum} } );
692 unless ( $part_svc->part_svc_column('uid')->columnflag eq 'F' ) {
694 $recref->{uid} =~ /^(\d*)$/ or return "Illegal uid";
695 $recref->{uid} = $1 eq '' ? $self->unique('uid') : $1;
697 $recref->{gid} =~ /^(\d*)$/ or return "Illegal gid";
698 $recref->{gid} = $1 eq '' ? $recref->{uid} : $1;
699 #not all systems use gid=uid
700 #you can set a fixed gid in part_svc
702 return "Only root can have uid 0"
703 if $recref->{uid} == 0
704 && $recref->{username} ne 'root'
705 && $recref->{username} ne 'toor';
708 $recref->{dir} =~ /^([\/\w\-\.\&]*)$/
709 or return "Illegal directory: ". $recref->{dir};
711 return "Illegal directory"
712 if $recref->{dir} =~ /(^|\/)\.+(\/|$)/; #no .. component
713 return "Illegal directory"
714 if $recref->{dir} =~ /\&/ && ! $username_ampersand;
715 unless ( $recref->{dir} ) {
716 $recref->{dir} = $dir_prefix . '/';
717 if ( $dirhash > 0 ) {
718 for my $h ( 1 .. $dirhash ) {
719 $recref->{dir} .= substr($recref->{username}, $h-1, 1). '/';
721 } elsif ( $dirhash < 0 ) {
722 for my $h ( reverse $dirhash .. -1 ) {
723 $recref->{dir} .= substr($recref->{username}, $h, 1). '/';
726 $recref->{dir} .= $recref->{username};
730 unless ( $recref->{username} eq 'sync' ) {
731 if ( grep $_ eq $recref->{shell}, @shells ) {
732 $recref->{shell} = (grep $_ eq $recref->{shell}, @shells)[0];
734 return "Illegal shell \`". $self->shell. "\'; ".
735 $conf->dir. "/shells contains: @shells";
738 $recref->{shell} = '/bin/sync';
742 $recref->{gid} ne '' ?
743 return "Can't have gid without uid" : ( $recref->{gid}='' );
744 $recref->{dir} ne '' ?
745 return "Can't have directory without uid" : ( $recref->{dir}='' );
746 $recref->{shell} ne '' ?
747 return "Can't have shell without uid" : ( $recref->{shell}='' );
750 # $error = $self->ut_textn('finger');
751 # return $error if $error;
752 $self->getfield('finger') =~
753 /^([\w \t\!\@\#\$\%\&\(\)\-\+\;\'\"\,\.\?\/\*\<\>]*)$/
754 or return "Illegal finger: ". $self->getfield('finger');
755 $self->setfield('finger', $1);
757 $recref->{quota} =~ /^(\d*)$/ or return "Illegal quota";
758 $recref->{quota} = $1;
760 unless ( $part_svc->part_svc_column('slipip')->columnflag eq 'F' ) {
761 unless ( $recref->{slipip} eq '0e0' ) {
762 $recref->{slipip} =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/
763 or return "Illegal slipip". $self->slipip;
764 $recref->{slipip} = $1;
766 $recref->{slipip} = '0e0';
771 #arbitrary RADIUS stuff; allow ut_textn for now
772 foreach ( grep /^radius_/, fields('svc_acct') ) {
776 #generate a password if it is blank
777 $recref->{_password} = join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) )
778 unless ( $recref->{_password} );
780 #if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{4,16})$/ ) {
781 if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{$passwordmin,$passwordmax})$/ ) {
782 $recref->{_password} = $1.$3;
783 #uncomment this to encrypt password immediately upon entry, or run
784 #bin/crypt_pw in cron to give new users a window during which their
785 #password is available to techs, for faxing, etc. (also be aware of
787 #$recref->{password} = $1.
788 # crypt($3,$saltset[int(rand(64))].$saltset[int(rand(64))]
790 } elsif ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([\w\.\/\$\;]{13,34})$/ ) {
791 $recref->{_password} = $1.$3;
792 } elsif ( $recref->{_password} eq '*' ) {
793 $recref->{_password} = '*';
794 } elsif ( $recref->{_password} eq '!!' ) {
795 $recref->{_password} = '!!';
797 #return "Illegal password";
798 return gettext('illegal_password'). " $passwordmin-$passwordmax ".
799 FS::Msgcat::_gettext('illegal_password_characters').
800 ": ". $recref->{_password};
808 Depriciated, use radius_reply instead.
813 carp "FS::svc_acct::radius depriciated, use radius_reply";
819 Returns key/value pairs, suitable for assigning to a hash, for any RADIUS
820 reply attributes of this record.
822 Note that this is now the preferred method for reading RADIUS attributes -
823 accessing the columns directly is discouraged, as the column names are
824 expected to change in the future.
833 my($column, $attrib) = ($1, $2);
834 #$attrib =~ s/_/\-/g;
835 ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) );
836 } grep { /^radius_/ && $self->getfield($_) } fields( $self->table );
837 if ( $self->slipip && $self->slipip ne '0e0' ) {
838 $reply{'Framed-IP-Address'} = $self->slipip;
845 Returns key/value pairs, suitable for assigning to a hash, for any RADIUS
846 check attributes of this record.
848 Note that this is now the preferred method for reading RADIUS attributes -
849 accessing the columns directly is discouraged, as the column names are
850 expected to change in the future.
856 ( 'Password' => $self->_password,
859 my($column, $attrib) = ($1, $2);
860 #$attrib =~ s/_/\-/g;
861 ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) );
862 } grep { /^rc_/ && $self->getfield($_) } fields( $self->table )
868 Returns the domain associated with this account.
874 die "svc_acct.domsvc is null for svcnum ". $self->svcnum unless $self->domsvc;
875 my $svc_domain = $self->svc_domain
876 or die "no svc_domain.svcnum for svc_acct.domsvc ". $self->domsvc;
882 Returns the FS::svc_domain record for this account's domain (see
891 : qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } );
896 Returns the FS::cust_svc record for this account (see L<FS::cust_svc>).
900 qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
905 Returns an email address associated with the account.
911 $self->username. '@'. $self->domain;
914 =item seconds_since TIMESTAMP
916 Returns the number of seconds this account has been online since TIMESTAMP.
919 TIMESTAMP is specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
920 L<Time::Local> and L<Date::Parse> for conversion functions.
924 #note: POD here, implementation in FS::cust_svc
927 $self->cust_svc->seconds_since(@_);
932 Returns all RADIUS groups for this account (see L<FS::radius_usergroup>).
938 if ( $self->usergroup ) {
939 #when provisioning records, export callback runs in svc_Common.pm before
940 #radius_usergroup records can be inserted...
943 map { $_->groupname }
944 qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } );
962 use Mail::Internet 1.44;
965 $opt{mimetype} ||= 'text/plain';
966 $opt{mimetype} .= '; charset="iso-8859-1"' unless $opt{mimetype} =~ /charset/;
968 $ENV{MAILADDRESS} = $opt{from};
969 my $header = new Mail::Header ( [
972 "Sender: $opt{from}",
973 "Reply-To: $opt{from}",
974 "Date: ". time2str("%a, %d %b %Y %X %z", time),
975 "Subject: $opt{subject}",
976 "Content-Type: $opt{mimetype}",
978 my $message = new Mail::Internet (
980 'Body' => [ map "$_\n", split("\n", $opt{body}) ],
983 $message->smtpsend( Host => $smtpmachine )
984 or $message->smtpsend( Host => $smtpmachine, Debug => 1 )
985 or die "can't send email to $opt{to} via $smtpmachine with SMTP: $!";
988 =item check_and_rebuild_fuzzyfiles
992 sub check_and_rebuild_fuzzyfiles {
993 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
994 -e "$dir/svc_acct.username"
995 or &rebuild_fuzzyfiles;
998 =item rebuild_fuzzyfiles
1002 sub rebuild_fuzzyfiles {
1004 use Fcntl qw(:flock);
1006 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
1010 open(USERNAMELOCK,">>$dir/svc_acct.username")
1011 or die "can't open $dir/svc_acct.username: $!";
1012 flock(USERNAMELOCK,LOCK_EX)
1013 or die "can't lock $dir/svc_acct.username: $!";
1015 my @all_username = map $_->getfield('username'), qsearch('svc_acct', {});
1017 open (USERNAMECACHE,">$dir/svc_acct.username.tmp")
1018 or die "can't open $dir/svc_acct.username.tmp: $!";
1019 print USERNAMECACHE join("\n", @all_username), "\n";
1020 close USERNAMECACHE or die "can't close $dir/svc_acct.username.tmp: $!";
1022 rename "$dir/svc_acct.username.tmp", "$dir/svc_acct.username";
1032 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
1033 open(USERNAMECACHE,"<$dir/svc_acct.username")
1034 or die "can't open $dir/svc_acct.username: $!";
1035 my @array = map { chomp; $_; } <USERNAMECACHE>;
1036 close USERNAMECACHE;
1040 =item append_fuzzyfiles USERNAME
1044 sub append_fuzzyfiles {
1045 my $username = shift;
1047 &check_and_rebuild_fuzzyfiles;
1049 use Fcntl qw(:flock);
1051 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
1053 open(USERNAME,">>$dir/svc_acct.username")
1054 or die "can't open $dir/svc_acct.username: $!";
1055 flock(USERNAME,LOCK_EX)
1056 or die "can't lock $dir/svc_acct.username: $!";
1058 print USERNAME "$username\n";
1060 flock(USERNAME,LOCK_UN)
1061 or die "can't unlock $dir/svc_acct.username: $!";
1069 =item radius_usergroup_selector GROUPS_ARRAYREF [ SELECTNAME ]
1073 sub radius_usergroup_selector {
1074 my $sel_groups = shift;
1075 my %sel_groups = map { $_=>1 } @$sel_groups;
1077 my $selectname = shift || 'radius_usergroup';
1080 my $sth = $dbh->prepare(
1081 'SELECT DISTINCT(groupname) FROM radius_usergroup ORDER BY groupname'
1082 ) or die $dbh->errstr;
1083 $sth->execute() or die $sth->errstr;
1084 my @all_groups = map { $_->[0] } @{$sth->fetchall_arrayref};
1088 function ${selectname}_doadd(object) {
1089 var myvalue = object.${selectname}_add.value;
1090 var optionName = new Option(myvalue,myvalue,false,true);
1091 var length = object.$selectname.length;
1092 object.$selectname.options[length] = optionName;
1093 object.${selectname}_add.value = "";
1096 <SELECT MULTIPLE NAME="$selectname">
1099 foreach my $group ( @all_groups ) {
1101 if ( $sel_groups{$group} ) {
1102 $html .= ' SELECTED';
1103 $sel_groups{$group} = 0;
1105 $html .= ">$group</OPTION>\n";
1107 foreach my $group ( grep { $sel_groups{$_} } keys %sel_groups ) {
1108 $html .= "<OPTION SELECTED>$group</OPTION>\n";
1110 $html .= '</SELECT>';
1112 $html .= qq!<BR><INPUT TYPE="text" NAME="${selectname}_add">!.
1113 qq!<INPUT TYPE="button" VALUE="Add new group" onClick="${selectname}_doadd(this.form)">!;
1122 The $recref stuff in sub check should be cleaned up.
1124 The suspend, unsuspend and cancel methods update the database, but not the
1125 current object. This is probably a bug as it's unexpected and
1128 radius_usergroup_selector? putting web ui components in here? they should
1129 probably live somewhere else...
1133 L<FS::svc_Common>, edit/part_svc.cgi from an installed web interface,
1134 export.html from the base documentation, L<FS::Record>, L<FS::Conf>,
1135 L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>, L<FS::queue>,
1136 L<freeside-queued>), L<FS::svc_acct_pop>,
1137 schema.html from the base documentation.