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;
343 my $cust_main = $cust_pkg->cust_main;
345 if ( $conf->exists('emailinvoiceauto') ) {
346 my @invoicing_list = $cust_main->invoicing_list;
347 push @invoicing_list, $self->email;
348 $cust_main->invoicing_list(\@invoicing_list);
353 if ( $welcome_template && $cust_pkg ) {
354 my $to = join(', ', grep { $_ ne 'POST' } $cust_main->invoicing_list );
356 my $wqueue = new FS::queue {
357 'svcnum' => $self->svcnum,
358 'job' => 'FS::svc_acct::send_email'
360 warn "attempting to queue email to $to";
361 my $error = $wqueue->insert(
363 'from' => $welcome_from,
364 'subject' => $welcome_subject,
365 'mimetype' => $welcome_mimetype,
366 'body' => $welcome_template->fill_in( HASH => {
367 'username' => $self->username,
368 'password' => $self->_password,
369 'first' => $cust_main->first,
370 'last' => $cust_main->getfield('last'),
371 'pkg' => $cust_pkg->part_pkg->pkg,
375 $dbh->rollback if $oldAutoCommit;
376 return "queuing welcome email: $error";
379 foreach my $jobnum ( @jobnums ) {
380 my $error = $wqueue->depend_insert($jobnum);
382 $dbh->rollback if $oldAutoCommit;
383 return "queuing welcome email job dependancy: $error";
393 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
399 Deletes this account from the database. If there is an error, returns the
400 error, otherwise returns false.
402 The corresponding FS::cust_svc record will be deleted as well.
404 (TODOC: new exports! $noexport_hack)
411 return "Can't delete an account which is a (svc_forward) source!"
412 if qsearch( 'svc_forward', { 'srcsvc' => $self->svcnum } );
414 return "Can't delete an account which is a (svc_forward) destination!"
415 if qsearch( 'svc_forward', { 'dstsvc' => $self->svcnum } );
417 return "Can't delete an account with (svc_www) web service!"
418 if qsearch( 'svc_www', { 'usersvc' => $self->usersvc } );
420 # what about records in session ? (they should refer to history table)
422 local $SIG{HUP} = 'IGNORE';
423 local $SIG{INT} = 'IGNORE';
424 local $SIG{QUIT} = 'IGNORE';
425 local $SIG{TERM} = 'IGNORE';
426 local $SIG{TSTP} = 'IGNORE';
427 local $SIG{PIPE} = 'IGNORE';
429 my $oldAutoCommit = $FS::UID::AutoCommit;
430 local $FS::UID::AutoCommit = 0;
433 foreach my $cust_main_invoice (
434 qsearch( 'cust_main_invoice', { 'dest' => $self->svcnum } )
436 unless ( defined($cust_main_invoice) ) {
437 warn "WARNING: something's wrong with qsearch";
440 my %hash = $cust_main_invoice->hash;
441 $hash{'dest'} = $self->email;
442 my $new = new FS::cust_main_invoice \%hash;
443 my $error = $new->replace($cust_main_invoice);
445 $dbh->rollback if $oldAutoCommit;
450 foreach my $svc_domain (
451 qsearch( 'svc_domain', { 'catchall' => $self->svcnum } )
453 my %hash = new FS::svc_domain->hash;
454 $hash{'catchall'} = '';
455 my $new = new FS::svc_domain \%hash;
456 my $error = $new->replace($svc_domain);
458 $dbh->rollback if $oldAutoCommit;
463 foreach my $radius_usergroup (
464 qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } )
466 my $error = $radius_usergroup->delete;
468 $dbh->rollback if $oldAutoCommit;
473 my $error = $self->SUPER::delete;
475 $dbh->rollback if $oldAutoCommit;
479 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
483 =item replace OLD_RECORD
485 Replaces OLD_RECORD with this one in the database. If there is an error,
486 returns the error, otherwise returns false.
488 The additional field I<usergroup> can optionally be defined; if so it should
489 contain an arrayref of group names. See L<FS::radius_usergroup>. (used in
490 sqlradius export only)
495 my ( $new, $old ) = ( shift, shift );
498 return "Username in use"
499 if $old->username ne $new->username &&
500 qsearchs( 'svc_acct', { 'username' => $new->username,
501 'domsvc' => $new->domsvc,
504 #no warnings 'numeric'; #alas, a 5.006-ism
506 return "Can't change uid!" if $old->uid != $new->uid;
509 #change homdir when we change username
510 $new->setfield('dir', '') if $old->username ne $new->username;
512 local $SIG{HUP} = 'IGNORE';
513 local $SIG{INT} = 'IGNORE';
514 local $SIG{QUIT} = 'IGNORE';
515 local $SIG{TERM} = 'IGNORE';
516 local $SIG{TSTP} = 'IGNORE';
517 local $SIG{PIPE} = 'IGNORE';
519 my $oldAutoCommit = $FS::UID::AutoCommit;
520 local $FS::UID::AutoCommit = 0;
523 $old->usergroup( [ $old->radius_groups ] );
524 if ( $new->usergroup ) {
525 #(sorta) false laziness with FS::part_export::sqlradius::_export_replace
526 my @newgroups = @{$new->usergroup};
527 foreach my $oldgroup ( @{$old->usergroup} ) {
528 if ( grep { $oldgroup eq $_ } @newgroups ) {
529 @newgroups = grep { $oldgroup ne $_ } @newgroups;
532 my $radius_usergroup = qsearchs('radius_usergroup', {
533 svcnum => $old->svcnum,
534 groupname => $oldgroup,
536 my $error = $radius_usergroup->delete;
538 $dbh->rollback if $oldAutoCommit;
539 return "error deleting radius_usergroup $oldgroup: $error";
543 foreach my $newgroup ( @newgroups ) {
544 my $radius_usergroup = new FS::radius_usergroup ( {
545 svcnum => $new->svcnum,
546 groupname => $newgroup,
548 my $error = $radius_usergroup->insert;
550 $dbh->rollback if $oldAutoCommit;
551 return "error adding radius_usergroup $newgroup: $error";
557 $error = $new->SUPER::replace($old);
559 $dbh->rollback if $oldAutoCommit;
560 return $error if $error;
563 #false laziness with sub insert (and cust_main)
564 my $queue = new FS::queue {
565 'svcnum' => $new->svcnum,
566 'job' => 'FS::svc_acct::append_fuzzyfiles'
568 $error = $queue->insert($new->username);
570 $dbh->rollback if $oldAutoCommit;
571 return "queueing job (transaction rolled back): $error";
575 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
581 Suspends this account by prefixing *SUSPENDED* to the password. If there is an
582 error, returns the error, otherwise returns false.
584 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
590 my %hash = $self->hash;
591 unless ( $hash{_password} =~ /^\*SUSPENDED\* /
592 || $hash{_password} eq '*'
594 $hash{_password} = '*SUSPENDED* '.$hash{_password};
595 my $new = new FS::svc_acct ( \%hash );
596 my $error = $new->replace($self);
597 return $error if $error;
600 $self->SUPER::suspend;
605 Unsuspends this account by removing *SUSPENDED* from the password. If there is
606 an error, returns the error, otherwise returns false.
608 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
614 my %hash = $self->hash;
615 if ( $hash{_password} =~ /^\*SUSPENDED\* (.*)$/ ) {
616 $hash{_password} = $1;
617 my $new = new FS::svc_acct ( \%hash );
618 my $error = $new->replace($self);
619 return $error if $error;
622 $self->SUPER::unsuspend;
627 Just returns false (no error) for now.
629 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
633 Checks all fields to make sure this is a valid service. If there is an error,
634 returns the error, otherwise returns false. Called by the insert and replace
637 Sets any fixed values; see L<FS::part_svc>.
644 my($recref) = $self->hashref;
646 my $x = $self->setfixed;
647 return $x unless ref($x);
650 if ( $part_svc->part_svc_column('usergroup')->columnflag eq "F" ) {
652 [ split(',', $part_svc->part_svc_column('usergroup')->columnvalue) ] );
655 my $error = $self->ut_numbern('svcnum')
656 || $self->ut_number('domsvc')
657 || $self->ut_textn('sec_phrase')
659 return $error if $error;
661 my $ulen = $usernamemax || $self->dbdef_table->column('username')->length;
662 if ( $username_uppercase ) {
663 $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/i
664 or return gettext('illegal_username'). " ($usernamemin-$ulen): ". $recref->{username};
665 $recref->{username} = $1;
667 $recref->{username} =~ /^([a-z0-9_\-\.\&]{$usernamemin,$ulen})$/
668 or return gettext('illegal_username'). " ($usernamemin-$ulen): ". $recref->{username};
669 $recref->{username} = $1;
672 if ( $username_letterfirst ) {
673 $recref->{username} =~ /^[a-z]/ or return gettext('illegal_username');
674 } elsif ( $username_letter ) {
675 $recref->{username} =~ /[a-z]/ or return gettext('illegal_username');
677 if ( $username_noperiod ) {
678 $recref->{username} =~ /\./ and return gettext('illegal_username');
680 if ( $username_nounderscore ) {
681 $recref->{username} =~ /_/ and return gettext('illegal_username');
683 if ( $username_nodash ) {
684 $recref->{username} =~ /\-/ and return gettext('illegal_username');
686 unless ( $username_ampersand ) {
687 $recref->{username} =~ /\&/ and return gettext('illegal_username');
690 $recref->{popnum} =~ /^(\d*)$/ or return "Illegal popnum: ".$recref->{popnum};
691 $recref->{popnum} = $1;
692 return "Unknown popnum" unless
693 ! $recref->{popnum} ||
694 qsearchs('svc_acct_pop',{'popnum'=> $recref->{popnum} } );
696 unless ( $part_svc->part_svc_column('uid')->columnflag eq 'F' ) {
698 $recref->{uid} =~ /^(\d*)$/ or return "Illegal uid";
699 $recref->{uid} = $1 eq '' ? $self->unique('uid') : $1;
701 $recref->{gid} =~ /^(\d*)$/ or return "Illegal gid";
702 $recref->{gid} = $1 eq '' ? $recref->{uid} : $1;
703 #not all systems use gid=uid
704 #you can set a fixed gid in part_svc
706 return "Only root can have uid 0"
707 if $recref->{uid} == 0
708 && $recref->{username} ne 'root'
709 && $recref->{username} ne 'toor';
712 $recref->{dir} =~ /^([\/\w\-\.\&]*)$/
713 or return "Illegal directory: ". $recref->{dir};
715 return "Illegal directory"
716 if $recref->{dir} =~ /(^|\/)\.+(\/|$)/; #no .. component
717 return "Illegal directory"
718 if $recref->{dir} =~ /\&/ && ! $username_ampersand;
719 unless ( $recref->{dir} ) {
720 $recref->{dir} = $dir_prefix . '/';
721 if ( $dirhash > 0 ) {
722 for my $h ( 1 .. $dirhash ) {
723 $recref->{dir} .= substr($recref->{username}, $h-1, 1). '/';
725 } elsif ( $dirhash < 0 ) {
726 for my $h ( reverse $dirhash .. -1 ) {
727 $recref->{dir} .= substr($recref->{username}, $h, 1). '/';
730 $recref->{dir} .= $recref->{username};
734 unless ( $recref->{username} eq 'sync' ) {
735 if ( grep $_ eq $recref->{shell}, @shells ) {
736 $recref->{shell} = (grep $_ eq $recref->{shell}, @shells)[0];
738 return "Illegal shell \`". $self->shell. "\'; ".
739 $conf->dir. "/shells contains: @shells";
742 $recref->{shell} = '/bin/sync';
746 $recref->{gid} ne '' ?
747 return "Can't have gid without uid" : ( $recref->{gid}='' );
748 $recref->{dir} ne '' ?
749 return "Can't have directory without uid" : ( $recref->{dir}='' );
750 $recref->{shell} ne '' ?
751 return "Can't have shell without uid" : ( $recref->{shell}='' );
754 # $error = $self->ut_textn('finger');
755 # return $error if $error;
756 $self->getfield('finger') =~
757 /^([\w \t\!\@\#\$\%\&\(\)\-\+\;\'\"\,\.\?\/\*\<\>]*)$/
758 or return "Illegal finger: ". $self->getfield('finger');
759 $self->setfield('finger', $1);
761 $recref->{quota} =~ /^(\d*)$/ or return "Illegal quota";
762 $recref->{quota} = $1;
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 my $password = $self->_password;
861 my $pw_attrib = length($password) <= 12 ? 'Password' : 'Crypt-Password';
862 ( $pw_attrib => $password,
865 my($column, $attrib) = ($1, $2);
866 #$attrib =~ s/_/\-/g;
867 ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) );
868 } grep { /^rc_/ && $self->getfield($_) } fields( $self->table )
874 Returns the domain associated with this account.
880 die "svc_acct.domsvc is null for svcnum ". $self->svcnum unless $self->domsvc;
881 my $svc_domain = $self->svc_domain
882 or die "no svc_domain.svcnum for svc_acct.domsvc ". $self->domsvc;
888 Returns the FS::svc_domain record for this account's domain (see
897 : qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } );
902 Returns the FS::cust_svc record for this account (see L<FS::cust_svc>).
906 qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
911 Returns an email address associated with the account.
917 $self->username. '@'. $self->domain;
920 =item seconds_since TIMESTAMP
922 Returns the number of seconds this account has been online since TIMESTAMP.
925 TIMESTAMP is specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
926 L<Time::Local> and L<Date::Parse> for conversion functions.
930 #note: POD here, implementation in FS::cust_svc
933 $self->cust_svc->seconds_since(@_);
938 Returns all RADIUS groups for this account (see L<FS::radius_usergroup>).
944 if ( $self->usergroup ) {
945 #when provisioning records, export callback runs in svc_Common.pm before
946 #radius_usergroup records can be inserted...
949 map { $_->groupname }
950 qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } );
968 use Mail::Internet 1.44;
971 $opt{mimetype} ||= 'text/plain';
972 $opt{mimetype} .= '; charset="iso-8859-1"' unless $opt{mimetype} =~ /charset/;
974 $ENV{MAILADDRESS} = $opt{from};
975 my $header = new Mail::Header ( [
978 "Sender: $opt{from}",
979 "Reply-To: $opt{from}",
980 "Date: ". time2str("%a, %d %b %Y %X %z", time),
981 "Subject: $opt{subject}",
982 "Content-Type: $opt{mimetype}",
984 my $message = new Mail::Internet (
986 'Body' => [ map "$_\n", split("\n", $opt{body}) ],
989 $message->smtpsend( Host => $smtpmachine )
990 or $message->smtpsend( Host => $smtpmachine, Debug => 1 )
991 or die "can't send email to $opt{to} via $smtpmachine with SMTP: $!";
994 =item check_and_rebuild_fuzzyfiles
998 sub check_and_rebuild_fuzzyfiles {
999 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
1000 -e "$dir/svc_acct.username"
1001 or &rebuild_fuzzyfiles;
1004 =item rebuild_fuzzyfiles
1008 sub rebuild_fuzzyfiles {
1010 use Fcntl qw(:flock);
1012 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
1016 open(USERNAMELOCK,">>$dir/svc_acct.username")
1017 or die "can't open $dir/svc_acct.username: $!";
1018 flock(USERNAMELOCK,LOCK_EX)
1019 or die "can't lock $dir/svc_acct.username: $!";
1021 my @all_username = map $_->getfield('username'), qsearch('svc_acct', {});
1023 open (USERNAMECACHE,">$dir/svc_acct.username.tmp")
1024 or die "can't open $dir/svc_acct.username.tmp: $!";
1025 print USERNAMECACHE join("\n", @all_username), "\n";
1026 close USERNAMECACHE or die "can't close $dir/svc_acct.username.tmp: $!";
1028 rename "$dir/svc_acct.username.tmp", "$dir/svc_acct.username";
1038 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
1039 open(USERNAMECACHE,"<$dir/svc_acct.username")
1040 or die "can't open $dir/svc_acct.username: $!";
1041 my @array = map { chomp; $_; } <USERNAMECACHE>;
1042 close USERNAMECACHE;
1046 =item append_fuzzyfiles USERNAME
1050 sub append_fuzzyfiles {
1051 my $username = shift;
1053 &check_and_rebuild_fuzzyfiles;
1055 use Fcntl qw(:flock);
1057 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
1059 open(USERNAME,">>$dir/svc_acct.username")
1060 or die "can't open $dir/svc_acct.username: $!";
1061 flock(USERNAME,LOCK_EX)
1062 or die "can't lock $dir/svc_acct.username: $!";
1064 print USERNAME "$username\n";
1066 flock(USERNAME,LOCK_UN)
1067 or die "can't unlock $dir/svc_acct.username: $!";
1075 =item radius_usergroup_selector GROUPS_ARRAYREF [ SELECTNAME ]
1079 sub radius_usergroup_selector {
1080 my $sel_groups = shift;
1081 my %sel_groups = map { $_=>1 } @$sel_groups;
1083 my $selectname = shift || 'radius_usergroup';
1086 my $sth = $dbh->prepare(
1087 'SELECT DISTINCT(groupname) FROM radius_usergroup ORDER BY groupname'
1088 ) or die $dbh->errstr;
1089 $sth->execute() or die $sth->errstr;
1090 my @all_groups = map { $_->[0] } @{$sth->fetchall_arrayref};
1094 function ${selectname}_doadd(object) {
1095 var myvalue = object.${selectname}_add.value;
1096 var optionName = new Option(myvalue,myvalue,false,true);
1097 var length = object.$selectname.length;
1098 object.$selectname.options[length] = optionName;
1099 object.${selectname}_add.value = "";
1102 <SELECT MULTIPLE NAME="$selectname">
1105 foreach my $group ( @all_groups ) {
1107 if ( $sel_groups{$group} ) {
1108 $html .= ' SELECTED';
1109 $sel_groups{$group} = 0;
1111 $html .= ">$group</OPTION>\n";
1113 foreach my $group ( grep { $sel_groups{$_} } keys %sel_groups ) {
1114 $html .= "<OPTION SELECTED>$group</OPTION>\n";
1116 $html .= '</SELECT>';
1118 $html .= qq!<BR><INPUT TYPE="text" NAME="${selectname}_add">!.
1119 qq!<INPUT TYPE="button" VALUE="Add new group" onClick="${selectname}_doadd(this.form)">!;
1128 The $recref stuff in sub check should be cleaned up.
1130 The suspend, unsuspend and cancel methods update the database, but not the
1131 current object. This is probably a bug as it's unexpected and
1134 radius_usergroup_selector? putting web ui components in here? they should
1135 probably live somewhere else...
1139 L<FS::svc_Common>, edit/part_svc.cgi from an installed web interface,
1140 export.html from the base documentation, L<FS::Record>, L<FS::Conf>,
1141 L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>, L<FS::queue>,
1142 L<freeside-queued>), L<FS::svc_acct_pop>,
1143 schema.html from the base documentation.