4 use vars qw( @ISA $DEBUG $me $conf $skip_fuzzyfiles
5 $dir_prefix @shells $usernamemin
6 $usernamemax $passwordmin $passwordmax
7 $username_ampersand $username_letter $username_letterfirst
8 $username_noperiod $username_nounderscore $username_nodash
9 $username_uppercase $username_percent
10 $password_noampersand $password_noexclamation
11 $welcome_template $welcome_from
12 $welcome_subject $welcome_subject_template $welcome_mimetype
13 $warning_template $warning_from $warning_subject $warning_mimetype
16 $radius_password $radius_ip
22 use Crypt::PasswdMD5 1.2;
25 use FS::UID qw( datasrc driver_name );
27 use FS::Record qw( qsearch qsearchs fields dbh dbdef );
28 use FS::Msgcat qw(gettext);
29 use FS::UI::bytecount;
35 use FS::cust_main_invoice;
39 use FS::radius_usergroup;
46 @ISA = qw( FS::svc_Common );
49 $me = '[FS::svc_acct]';
51 #ask FS::UID to run this stuff for us later
52 $FS::UID::callback{'FS::svc_acct'} = sub {
54 $dir_prefix = $conf->config('home');
55 @shells = $conf->config('shells');
56 $usernamemin = $conf->config('usernamemin') || 2;
57 $usernamemax = $conf->config('usernamemax');
58 $passwordmin = $conf->config('passwordmin') || 6;
59 $passwordmax = $conf->config('passwordmax') || 8;
60 $username_letter = $conf->exists('username-letter');
61 $username_letterfirst = $conf->exists('username-letterfirst');
62 $username_noperiod = $conf->exists('username-noperiod');
63 $username_nounderscore = $conf->exists('username-nounderscore');
64 $username_nodash = $conf->exists('username-nodash');
65 $username_uppercase = $conf->exists('username-uppercase');
66 $username_ampersand = $conf->exists('username-ampersand');
67 $username_percent = $conf->exists('username-percent');
68 $password_noampersand = $conf->exists('password-noexclamation');
69 $password_noexclamation = $conf->exists('password-noexclamation');
70 $dirhash = $conf->config('dirhash') || 0;
71 if ( $conf->exists('welcome_email') ) {
72 $welcome_template = new Text::Template (
74 SOURCE => [ map "$_\n", $conf->config('welcome_email') ]
75 ) or warn "can't create welcome email template: $Text::Template::ERROR";
76 $welcome_from = $conf->config('welcome_email-from'); # || 'your-isp-is-dum'
77 $welcome_subject = $conf->config('welcome_email-subject') || 'Welcome';
78 $welcome_subject_template = new Text::Template (
80 SOURCE => $welcome_subject,
81 ) or warn "can't create welcome email subject template: $Text::Template::ERROR";
82 $welcome_mimetype = $conf->config('welcome_email-mimetype') || 'text/plain';
84 $welcome_template = '';
86 $welcome_subject = '';
87 $welcome_mimetype = '';
89 if ( $conf->exists('warning_email') ) {
90 $warning_template = new Text::Template (
92 SOURCE => [ map "$_\n", $conf->config('warning_email') ]
93 ) or warn "can't create warning email template: $Text::Template::ERROR";
94 $warning_from = $conf->config('warning_email-from'); # || 'your-isp-is-dum'
95 $warning_subject = $conf->config('warning_email-subject') || 'Warning';
96 $warning_mimetype = $conf->config('warning_email-mimetype') || 'text/plain';
97 $warning_cc = $conf->config('warning_email-cc');
99 $warning_template = '';
101 $warning_subject = '';
102 $warning_mimetype = '';
105 $smtpmachine = $conf->config('smtpmachine');
106 $radius_password = $conf->config('radius-password') || 'Password';
107 $radius_ip = $conf->config('radius-ip') || 'Framed-IP-Address';
108 @pw_set = ( 'A'..'Z' ) if $conf->exists('password-generated-allcaps');
111 @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' );
112 @pw_set = ( 'a'..'z', 'A'..'Z', '0'..'9', '(', ')', '#', '!', '.', ',' );
116 my ( $hashref, $cache ) = @_;
117 if ( $hashref->{'svc_acct_svcnum'} ) {
118 $self->{'_domsvc'} = FS::svc_domain->new( {
119 'svcnum' => $hashref->{'domsvc'},
120 'domain' => $hashref->{'svc_acct_domain'},
121 'catchall' => $hashref->{'svc_acct_catchall'},
128 FS::svc_acct - Object methods for svc_acct records
134 $record = new FS::svc_acct \%hash;
135 $record = new FS::svc_acct { 'column' => 'value' };
137 $error = $record->insert;
139 $error = $new_record->replace($old_record);
141 $error = $record->delete;
143 $error = $record->check;
145 $error = $record->suspend;
147 $error = $record->unsuspend;
149 $error = $record->cancel;
151 %hash = $record->radius;
153 %hash = $record->radius_reply;
155 %hash = $record->radius_check;
157 $domain = $record->domain;
159 $svc_domain = $record->svc_domain;
161 $email = $record->email;
163 $seconds_since = $record->seconds_since($timestamp);
167 An FS::svc_acct object represents an account. FS::svc_acct inherits from
168 FS::svc_Common. The following fields are currently supported:
172 =item svcnum - primary key (assigned automatcially for new accounts)
176 =item _password - generated if blank
178 =item sec_phrase - security phrase
180 =item popnum - Point of presence (see L<FS::svc_acct_pop>)
188 =item dir - set automatically if blank (and uid is not)
192 =item quota - (unimplementd)
194 =item slipip - IP address
204 =item domsvc - svcnum from svc_domain
206 =item radius_I<Radius_Attribute> - I<Radius-Attribute> (reply)
208 =item rc_I<Radius_Attribute> - I<Radius-Attribute> (check)
218 Creates a new account. To add the account to the database, see L<"insert">.
225 'longname_plural' => 'Access accounts and mailboxes',
226 'sorts' => [ 'username', 'uid', 'last_login', ],
227 'display_weight' => 10,
228 'cancel_weight' => 50,
230 'dir' => 'Home directory',
233 def_label => 'UID (set to fixed and blank for no UIDs)',
236 'slipip' => 'IP address',
237 # 'popnum' => qq!<A HREF="$p/browse/svc_acct_pop.cgi/">POP number</A>!,
239 label => 'Access number',
241 select_table => 'svc_acct_pop',
242 select_key => 'popnum',
243 select_label => 'city',
249 disable_default => 1,
256 disable_inventory => 1,
259 '_password' => 'Password',
262 def_label => 'GID (when blank, defaults to UID)',
266 #desc =>'Shell (all service definitions should have a default or fixed shell that is present in the <b>shells</b> configuration file, set to blank for no shell tracking)',
268 def_label=> 'Shell (set to blank for no shell tracking)',
270 select_list => [ $conf->config('shells') ],
271 disable_inventory => 1,
274 'finger' => 'Real name', # (GECOS)',
277 #def_label => 'svcnum from svc_domain',
279 select_table => 'svc_domain',
280 select_key => 'svcnum',
281 select_label => 'domain',
282 disable_inventory => 1,
286 label => 'RADIUS groups',
287 type => 'radius_usergroup_selector',
288 disable_inventory => 1,
291 'seconds' => { label => 'Seconds',
293 disable_inventory => 1,
295 disable_part_svc_column => 1,
297 'upbytes' => { label => 'Upload',
299 disable_inventory => 1,
301 'format' => \&FS::UI::bytecount::display_bytecount,
302 'parse' => \&FS::UI::bytecount::parse_bytecount,
303 disable_part_svc_column => 1,
305 'downbytes' => { label => 'Download',
307 disable_inventory => 1,
309 'format' => \&FS::UI::bytecount::display_bytecount,
310 'parse' => \&FS::UI::bytecount::parse_bytecount,
311 disable_part_svc_column => 1,
313 'totalbytes'=> { label => 'Total up and download',
315 disable_inventory => 1,
317 'format' => \&FS::UI::bytecount::display_bytecount,
318 'parse' => \&FS::UI::bytecount::parse_bytecount,
319 disable_part_svc_column => 1,
321 'seconds_threshold' => { label => 'Seconds threshold',
323 disable_inventory => 1,
325 disable_part_svc_column => 1,
327 'upbytes_threshold' => { label => 'Upload threshold',
329 disable_inventory => 1,
331 'format' => \&FS::UI::bytecount::display_bytecount,
332 'parse' => \&FS::UI::bytecount::parse_bytecount,
333 disable_part_svc_column => 1,
335 'downbytes_threshold' => { label => 'Download threshold',
337 disable_inventory => 1,
339 'format' => \&FS::UI::bytecount::display_bytecount,
340 'parse' => \&FS::UI::bytecount::parse_bytecount,
341 disable_part_svc_column => 1,
343 'totalbytes_threshold'=> { label => 'Total up and download threshold',
345 disable_inventory => 1,
347 'format' => \&FS::UI::bytecount::display_bytecount,
348 'parse' => \&FS::UI::bytecount::parse_bytecount,
349 disable_part_svc_column => 1,
352 label => 'Last login',
356 label => 'Last logout',
363 sub table { 'svc_acct'; }
367 #false laziness with edit/svc_acct.cgi
369 my( $self, $groups ) = @_;
370 if ( ref($groups) eq 'ARRAY' ) {
372 } elsif ( length($groups) ) {
373 [ split(/\s*,\s*/, $groups) ];
382 shift->_lastlog('in', @_);
386 shift->_lastlog('out', @_);
390 my( $self, $op, $time ) = @_;
392 if ( defined($time) ) {
393 warn "$me last_log$op called on svcnum ". $self->svcnum.
394 ' ('. $self->email. "): $time\n"
399 my $sql = "UPDATE svc_acct SET last_log$op = ? WHERE svcnum = ?";
403 my $sth = $dbh->prepare( $sql )
404 or die "Error preparing $sql: ". $dbh->errstr;
405 my $rv = $sth->execute($time, $self->svcnum);
406 die "Error executing $sql: ". $sth->errstr
408 die "Can't update last_log$op for svcnum". $self->svcnum
411 $self->{'Hash'}->{"last_log$op"} = $time;
413 $self->getfield("last_log$op");
417 =item search_sql STRING
419 Class method which returns an SQL fragment to search for the given string.
424 my( $class, $string ) = @_;
425 if ( $string =~ /^([^@]+)@([^@]+)$/ ) {
426 my( $username, $domain ) = ( $1, $2 );
427 my $q_username = dbh->quote($username);
428 my @svc_domain = qsearch('svc_domain', { 'domain' => $domain } );
430 "svc_acct.username = $q_username AND ( ".
431 join( ' OR ', map { "svc_acct.domsvc = ". $_->svcnum; } @svc_domain ).
436 } elsif ( $string =~ /^(\d{1,3}\.){3}\d{1,3}$/ ) {
438 $class->search_sql_field('slipip', $string ).
440 $class->search_sql_field('username', $string ).
443 $class->search_sql_field('username', $string);
447 =item label [ END_TIMESTAMP [ START_TIMESTAMP ] ]
449 Returns the "username@domain" string for this account.
451 END_TIMESTAMP and START_TIMESTAMP can optionally be passed when dealing with
461 =item label_long [ END_TIMESTAMP [ START_TIMESTAMP ] ]
463 Returns a longer string label for this acccount ("Real Name <username@domain>"
464 if available, or "username@domain").
466 END_TIMESTAMP and START_TIMESTAMP can optionally be passed when dealing with
473 ( $self->finger =~ /\S/ )
474 ? $self->finger. ' <'.$self->label(@_).'>'
478 =item insert [ , OPTION => VALUE ... ]
480 Adds this account to the database. If there is an error, returns the error,
481 otherwise returns false.
483 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
484 defined. An FS::cust_svc record will be created and inserted.
486 The additional field I<usergroup> can optionally be defined; if so it should
487 contain an arrayref of group names. See L<FS::radius_usergroup>.
489 The additional field I<child_objects> can optionally be defined; if so it
490 should contain an arrayref of FS::tablename objects. They will have their
491 svcnum fields set and will be inserted after this record, but before any
492 exports are run. Each element of the array can also optionally be a
493 two-element array reference containing the child object and the name of an
494 alternate field to be filled in with the newly-inserted svcnum, for example
495 C<[ $svc_forward, 'srcsvc' ]>
497 Currently available options are: I<depend_jobnum>
499 If I<depend_jobnum> is set (to a scalar jobnum or an array reference of
500 jobnums), all provisioning jobs will have a dependancy on the supplied
501 jobnum(s) (they will not run until the specific job(s) complete(s)).
503 (TODOC: L<FS::queue> and L<freeside-queued>)
505 (TODOC: new exports!)
514 warn "[$me] insert called on $self: ". Dumper($self).
515 "\nwith options: ". Dumper(%options);
518 local $SIG{HUP} = 'IGNORE';
519 local $SIG{INT} = 'IGNORE';
520 local $SIG{QUIT} = 'IGNORE';
521 local $SIG{TERM} = 'IGNORE';
522 local $SIG{TSTP} = 'IGNORE';
523 local $SIG{PIPE} = 'IGNORE';
525 my $oldAutoCommit = $FS::UID::AutoCommit;
526 local $FS::UID::AutoCommit = 0;
529 my $error = $self->check;
530 return $error if $error;
532 if ( $self->svcnum && qsearchs('cust_svc',{'svcnum'=>$self->svcnum}) ) {
533 my $cust_svc = qsearchs('cust_svc',{'svcnum'=>$self->svcnum});
534 unless ( $cust_svc ) {
535 $dbh->rollback if $oldAutoCommit;
536 return "no cust_svc record found for svcnum ". $self->svcnum;
538 $self->pkgnum($cust_svc->pkgnum);
539 $self->svcpart($cust_svc->svcpart);
542 $error = $self->_check_duplicate;
544 $dbh->rollback if $oldAutoCommit;
548 # set usage fields and thresholds if unset but set in a package def
549 if ( $self->pkgnum ) {
550 my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
551 my $part_pkg = $cust_pkg->part_pkg if $cust_pkg;
552 if ( $part_pkg && $part_pkg->can('usage_valuehash') ) {
554 my %values = $part_pkg->usage_valuehash;
555 my $multiplier = $conf->exists('svc_acct-usage_threshold')
556 ? 1 - $conf->config('svc_acct-usage_threshold')/100
559 foreach ( keys %values ) {
560 next if $self->getfield($_);
561 $self->setfield( $_, $values{$_} );
562 $self->setfield( $_. '_threshold', int( $values{$_} * $multiplier ) );
569 $error = $self->SUPER::insert(
570 'jobnums' => \@jobnums,
571 'child_objects' => $self->child_objects,
575 $dbh->rollback if $oldAutoCommit;
579 if ( $self->usergroup ) {
580 foreach my $groupname ( @{$self->usergroup} ) {
581 my $radius_usergroup = new FS::radius_usergroup ( {
582 svcnum => $self->svcnum,
583 groupname => $groupname,
585 my $error = $radius_usergroup->insert;
587 $dbh->rollback if $oldAutoCommit;
593 unless ( $skip_fuzzyfiles ) {
594 $error = $self->queue_fuzzyfiles_update;
596 $dbh->rollback if $oldAutoCommit;
597 return "updating fuzzy search cache: $error";
601 my $cust_pkg = $self->cust_svc->cust_pkg;
604 my $cust_main = $cust_pkg->cust_main;
606 if ( $conf->exists('emailinvoiceautoalways')
607 || $conf->exists('emailinvoiceauto')
608 && ! $cust_main->invoicing_list_emailonly
610 my @invoicing_list = $cust_main->invoicing_list;
611 push @invoicing_list, $self->email;
612 $cust_main->invoicing_list(\@invoicing_list);
617 if ( $welcome_template && $cust_pkg ) {
618 my $to = join(', ', grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list );
622 'custnum' => $self->custnum,
623 'username' => $self->username,
624 'password' => $self->_password,
625 'first' => $cust_main->first,
626 'last' => $cust_main->getfield('last'),
627 'pkg' => $cust_pkg->part_pkg->pkg,
629 my $wqueue = new FS::queue {
630 'svcnum' => $self->svcnum,
631 'job' => 'FS::svc_acct::send_email'
633 my $error = $wqueue->insert(
635 'from' => $welcome_from,
636 'subject' => $welcome_subject_template->fill_in( HASH => \%hash, ),
637 'mimetype' => $welcome_mimetype,
638 'body' => $welcome_template->fill_in( HASH => \%hash, ),
641 $dbh->rollback if $oldAutoCommit;
642 return "error queuing welcome email: $error";
645 if ( $options{'depend_jobnum'} ) {
646 warn "$me depend_jobnum found; adding to welcome email dependancies"
648 if ( ref($options{'depend_jobnum'}) ) {
649 warn "$me adding jobs ". join(', ', @{$options{'depend_jobnum'}} ).
650 "to welcome email dependancies"
652 push @jobnums, @{ $options{'depend_jobnum'} };
654 warn "$me adding job $options{'depend_jobnum'} ".
655 "to welcome email dependancies"
657 push @jobnums, $options{'depend_jobnum'};
661 foreach my $jobnum ( @jobnums ) {
662 my $error = $wqueue->depend_insert($jobnum);
664 $dbh->rollback if $oldAutoCommit;
665 return "error queuing welcome email job dependancy: $error";
675 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
681 Deletes this account from the database. If there is an error, returns the
682 error, otherwise returns false.
684 The corresponding FS::cust_svc record will be deleted as well.
686 (TODOC: new exports!)
693 return "can't delete system account" if $self->_check_system;
695 return "Can't delete an account which is a (svc_forward) source!"
696 if qsearch( 'svc_forward', { 'srcsvc' => $self->svcnum } );
698 return "Can't delete an account which is a (svc_forward) destination!"
699 if qsearch( 'svc_forward', { 'dstsvc' => $self->svcnum } );
701 return "Can't delete an account with (svc_www) web service!"
702 if qsearch( 'svc_www', { 'usersvc' => $self->svcnum } );
704 # what about records in session ? (they should refer to history table)
706 local $SIG{HUP} = 'IGNORE';
707 local $SIG{INT} = 'IGNORE';
708 local $SIG{QUIT} = 'IGNORE';
709 local $SIG{TERM} = 'IGNORE';
710 local $SIG{TSTP} = 'IGNORE';
711 local $SIG{PIPE} = 'IGNORE';
713 my $oldAutoCommit = $FS::UID::AutoCommit;
714 local $FS::UID::AutoCommit = 0;
717 foreach my $cust_main_invoice (
718 qsearch( 'cust_main_invoice', { 'dest' => $self->svcnum } )
720 unless ( defined($cust_main_invoice) ) {
721 warn "WARNING: something's wrong with qsearch";
724 my %hash = $cust_main_invoice->hash;
725 $hash{'dest'} = $self->email;
726 my $new = new FS::cust_main_invoice \%hash;
727 my $error = $new->replace($cust_main_invoice);
729 $dbh->rollback if $oldAutoCommit;
734 foreach my $svc_domain (
735 qsearch( 'svc_domain', { 'catchall' => $self->svcnum } )
737 my %hash = new FS::svc_domain->hash;
738 $hash{'catchall'} = '';
739 my $new = new FS::svc_domain \%hash;
740 my $error = $new->replace($svc_domain);
742 $dbh->rollback if $oldAutoCommit;
747 my $error = $self->SUPER::delete;
749 $dbh->rollback if $oldAutoCommit;
753 foreach my $radius_usergroup (
754 qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } )
756 my $error = $radius_usergroup->delete;
758 $dbh->rollback if $oldAutoCommit;
763 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
767 =item replace OLD_RECORD
769 Replaces OLD_RECORD with this one in the database. If there is an error,
770 returns the error, otherwise returns false.
772 The additional field I<usergroup> can optionally be defined; if so it should
773 contain an arrayref of group names. See L<FS::radius_usergroup>.
779 my ( $new, $old ) = ( shift, shift );
781 warn "$me replacing $old with $new\n" if $DEBUG;
783 # We absolutely have to have an old vs. new record to make this work.
784 if (!defined($old)) {
785 $old = qsearchs( 'svc_acct', { 'svcnum' => $new->svcnum } );
788 return "can't modify system account" if $old->_check_system;
791 #no warnings 'numeric'; #alas, a 5.006-ism
794 foreach my $xid (qw( uid gid )) {
796 return "Can't change $xid!"
797 if ! $conf->exists("svc_acct-edit_$xid")
798 && $old->$xid() != $new->$xid()
799 && $new->cust_svc->part_svc->part_svc_column($xid)->columnflag ne 'F'
804 #change homdir when we change username
805 $new->setfield('dir', '') if $old->username ne $new->username;
807 local $SIG{HUP} = 'IGNORE';
808 local $SIG{INT} = 'IGNORE';
809 local $SIG{QUIT} = 'IGNORE';
810 local $SIG{TERM} = 'IGNORE';
811 local $SIG{TSTP} = 'IGNORE';
812 local $SIG{PIPE} = 'IGNORE';
814 my $oldAutoCommit = $FS::UID::AutoCommit;
815 local $FS::UID::AutoCommit = 0;
818 # redundant, but so $new->usergroup gets set
819 $error = $new->check;
820 return $error if $error;
822 $old->usergroup( [ $old->radius_groups ] );
824 warn $old->email. " old groups: ". join(' ',@{$old->usergroup}). "\n";
825 warn $new->email. "new groups: ". join(' ',@{$new->usergroup}). "\n";
827 if ( $new->usergroup ) {
828 #(sorta) false laziness with FS::part_export::sqlradius::_export_replace
829 my @newgroups = @{$new->usergroup};
830 foreach my $oldgroup ( @{$old->usergroup} ) {
831 if ( grep { $oldgroup eq $_ } @newgroups ) {
832 @newgroups = grep { $oldgroup ne $_ } @newgroups;
835 my $radius_usergroup = qsearchs('radius_usergroup', {
836 svcnum => $old->svcnum,
837 groupname => $oldgroup,
839 my $error = $radius_usergroup->delete;
841 $dbh->rollback if $oldAutoCommit;
842 return "error deleting radius_usergroup $oldgroup: $error";
846 foreach my $newgroup ( @newgroups ) {
847 my $radius_usergroup = new FS::radius_usergroup ( {
848 svcnum => $new->svcnum,
849 groupname => $newgroup,
851 my $error = $radius_usergroup->insert;
853 $dbh->rollback if $oldAutoCommit;
854 return "error adding radius_usergroup $newgroup: $error";
860 if ( $old->username ne $new->username || $old->domsvc != $new->domsvc ) {
861 $new->svcpart( $new->cust_svc->svcpart ) unless $new->svcpart;
862 $error = $new->_check_duplicate;
864 $dbh->rollback if $oldAutoCommit;
869 $error = $new->SUPER::replace($old);
871 $dbh->rollback if $oldAutoCommit;
872 return $error if $error;
875 if ( $new->username ne $old->username && ! $skip_fuzzyfiles ) {
876 $error = $new->queue_fuzzyfiles_update;
878 $dbh->rollback if $oldAutoCommit;
879 return "updating fuzzy search cache: $error";
883 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
887 =item queue_fuzzyfiles_update
889 Used by insert & replace to update the fuzzy search cache
893 sub queue_fuzzyfiles_update {
896 local $SIG{HUP} = 'IGNORE';
897 local $SIG{INT} = 'IGNORE';
898 local $SIG{QUIT} = 'IGNORE';
899 local $SIG{TERM} = 'IGNORE';
900 local $SIG{TSTP} = 'IGNORE';
901 local $SIG{PIPE} = 'IGNORE';
903 my $oldAutoCommit = $FS::UID::AutoCommit;
904 local $FS::UID::AutoCommit = 0;
907 my $queue = new FS::queue {
908 'svcnum' => $self->svcnum,
909 'job' => 'FS::svc_acct::append_fuzzyfiles'
911 my $error = $queue->insert($self->username);
913 $dbh->rollback if $oldAutoCommit;
914 return "queueing job (transaction rolled back): $error";
917 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
925 Suspends this account by calling export-specific suspend hooks. If there is
926 an error, returns the error, otherwise returns false.
928 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
934 return "can't suspend system account" if $self->_check_system;
935 $self->SUPER::suspend;
940 Unsuspends this account by by calling export-specific suspend hooks. If there
941 is an error, returns the error, otherwise returns false.
943 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
949 my %hash = $self->hash;
950 if ( $hash{_password} =~ /^\*SUSPENDED\* (.*)$/ ) {
951 $hash{_password} = $1;
952 my $new = new FS::svc_acct ( \%hash );
953 my $error = $new->replace($self);
954 return $error if $error;
957 $self->SUPER::unsuspend;
962 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
964 If the B<auto_unset_catchall> configuration option is set, this method will
965 automatically remove any references to the canceled service in the catchall
966 field of svc_domain. This allows packages that contain both a svc_domain and
967 its catchall svc_acct to be canceled in one step.
972 # Only one thing to do at this level
974 foreach my $svc_domain (
975 qsearch( 'svc_domain', { catchall => $self->svcnum } ) ) {
976 if($conf->exists('auto_unset_catchall')) {
977 my %hash = $svc_domain->hash;
978 $hash{catchall} = '';
979 my $new = new FS::svc_domain ( \%hash );
980 my $error = $new->replace($svc_domain);
981 return $error if $error;
983 return "cannot unprovision svc_acct #".$self->svcnum.
984 " while assigned as catchall for svc_domain #".$svc_domain->svcnum;
988 $self->SUPER::cancel;
994 Checks all fields to make sure this is a valid service. If there is an error,
995 returns the error, otherwise returns false. Called by the insert and replace
998 Sets any fixed values; see L<FS::part_svc>.
1005 my($recref) = $self->hashref;
1007 my $x = $self->setfixed( $self->_fieldhandlers );
1008 return $x unless ref($x);
1011 if ( $part_svc->part_svc_column('usergroup')->columnflag eq "F" ) {
1013 [ split(',', $part_svc->part_svc_column('usergroup')->columnvalue) ] );
1016 my $error = $self->ut_numbern('svcnum')
1017 #|| $self->ut_number('domsvc')
1018 || $self->ut_foreign_key('domsvc', 'svc_domain', 'svcnum' )
1019 || $self->ut_textn('sec_phrase')
1020 || $self->ut_snumbern('seconds')
1021 || $self->ut_snumbern('upbytes')
1022 || $self->ut_snumbern('downbytes')
1023 || $self->ut_snumbern('totalbytes')
1025 return $error if $error;
1027 my $ulen = $usernamemax || $self->dbdef_table->column('username')->length;
1028 if ( $username_uppercase ) {
1029 $recref->{username} =~ /^([a-z0-9_\-\.\&\%]{$usernamemin,$ulen})$/i
1030 or return gettext('illegal_username'). " ($usernamemin-$ulen): ". $recref->{username};
1031 $recref->{username} = $1;
1033 $recref->{username} =~ /^([a-z0-9_\-\.\&\%]{$usernamemin,$ulen})$/
1034 or return gettext('illegal_username'). " ($usernamemin-$ulen): ". $recref->{username};
1035 $recref->{username} = $1;
1038 if ( $username_letterfirst ) {
1039 $recref->{username} =~ /^[a-z]/ or return gettext('illegal_username');
1040 } elsif ( $username_letter ) {
1041 $recref->{username} =~ /[a-z]/ or return gettext('illegal_username');
1043 if ( $username_noperiod ) {
1044 $recref->{username} =~ /\./ and return gettext('illegal_username');
1046 if ( $username_nounderscore ) {
1047 $recref->{username} =~ /_/ and return gettext('illegal_username');
1049 if ( $username_nodash ) {
1050 $recref->{username} =~ /\-/ and return gettext('illegal_username');
1052 unless ( $username_ampersand ) {
1053 $recref->{username} =~ /\&/ and return gettext('illegal_username');
1055 if ( $password_noampersand ) {
1056 $recref->{_password} =~ /\&/ and return gettext('illegal_password');
1058 if ( $password_noexclamation ) {
1059 $recref->{_password} =~ /\!/ and return gettext('illegal_password');
1061 unless ( $username_percent ) {
1062 $recref->{username} =~ /\%/ and return gettext('illegal_username');
1065 $recref->{popnum} =~ /^(\d*)$/ or return "Illegal popnum: ".$recref->{popnum};
1066 $recref->{popnum} = $1;
1067 return "Unknown popnum" unless
1068 ! $recref->{popnum} ||
1069 qsearchs('svc_acct_pop',{'popnum'=> $recref->{popnum} } );
1071 unless ( $part_svc->part_svc_column('uid')->columnflag eq 'F' ) {
1073 $recref->{uid} =~ /^(\d*)$/ or return "Illegal uid";
1074 $recref->{uid} = $1 eq '' ? $self->unique('uid') : $1;
1076 $recref->{gid} =~ /^(\d*)$/ or return "Illegal gid";
1077 $recref->{gid} = $1 eq '' ? $recref->{uid} : $1;
1078 #not all systems use gid=uid
1079 #you can set a fixed gid in part_svc
1081 return "Only root can have uid 0"
1082 if $recref->{uid} == 0
1083 && $recref->{username} !~ /^(root|toor|smtp)$/;
1085 unless ( $recref->{username} eq 'sync' ) {
1086 if ( grep $_ eq $recref->{shell}, @shells ) {
1087 $recref->{shell} = (grep $_ eq $recref->{shell}, @shells)[0];
1089 return "Illegal shell \`". $self->shell. "\'; ".
1090 $conf->dir. "/shells contains: @shells";
1093 $recref->{shell} = '/bin/sync';
1097 $recref->{gid} ne '' ?
1098 return "Can't have gid without uid" : ( $recref->{gid}='' );
1099 #$recref->{dir} ne '' ?
1100 # return "Can't have directory without uid" : ( $recref->{dir}='' );
1101 $recref->{shell} ne '' ?
1102 return "Can't have shell without uid" : ( $recref->{shell}='' );
1105 unless ( $part_svc->part_svc_column('dir')->columnflag eq 'F' ) {
1107 $recref->{dir} =~ /^([\/\w\-\.\&]*)$/
1108 or return "Illegal directory: ". $recref->{dir};
1109 $recref->{dir} = $1;
1110 return "Illegal directory"
1111 if $recref->{dir} =~ /(^|\/)\.+(\/|$)/; #no .. component
1112 return "Illegal directory"
1113 if $recref->{dir} =~ /\&/ && ! $username_ampersand;
1114 unless ( $recref->{dir} ) {
1115 $recref->{dir} = $dir_prefix . '/';
1116 if ( $dirhash > 0 ) {
1117 for my $h ( 1 .. $dirhash ) {
1118 $recref->{dir} .= substr($recref->{username}, $h-1, 1). '/';
1120 } elsif ( $dirhash < 0 ) {
1121 for my $h ( reverse $dirhash .. -1 ) {
1122 $recref->{dir} .= substr($recref->{username}, $h, 1). '/';
1125 $recref->{dir} .= $recref->{username};
1131 # $error = $self->ut_textn('finger');
1132 # return $error if $error;
1133 if ( $self->getfield('finger') eq '' ) {
1134 my $cust_pkg = $self->svcnum
1135 ? $self->cust_svc->cust_pkg
1136 : qsearchs('cust_pkg', { 'pkgnum' => $self->getfield('pkgnum') } );
1138 my $cust_main = $cust_pkg->cust_main;
1139 $self->setfield('finger', $cust_main->first.' '.$cust_main->get('last') );
1142 $self->getfield('finger') =~
1143 /^([\w \t\!\@\#\$\%\&\(\)\-\+\;\'\"\,\.\?\/\*\<\>]*)$/
1144 or return "Illegal finger: ". $self->getfield('finger');
1145 $self->setfield('finger', $1);
1147 $recref->{quota} =~ /^(\w*)$/ or return "Illegal quota";
1148 $recref->{quota} = $1;
1150 unless ( $part_svc->part_svc_column('slipip')->columnflag eq 'F' ) {
1151 if ( $recref->{slipip} eq '' ) {
1152 $recref->{slipip} = '';
1153 } elsif ( $recref->{slipip} eq '0e0' ) {
1154 $recref->{slipip} = '0e0';
1156 $recref->{slipip} =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/
1157 or return "Illegal slipip: ". $self->slipip;
1158 $recref->{slipip} = $1;
1163 #arbitrary RADIUS stuff; allow ut_textn for now
1164 foreach ( grep /^radius_/, fields('svc_acct') ) {
1165 $self->ut_textn($_);
1168 #generate a password if it is blank
1169 $recref->{_password} = join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) )
1170 unless ( $recref->{_password} );
1172 #if ( $recref->{_password} =~ /^((\*SUSPENDED\* )?)([^\t\n]{4,16})$/ ) {
1173 if ( $recref->{_password} =~ /^((\*SUSPENDED\* |!!?)?)([^\t\n]{$passwordmin,$passwordmax})$/ ) {
1174 $recref->{_password} = $1.$3;
1175 #uncomment this to encrypt password immediately upon entry, or run
1176 #bin/crypt_pw in cron to give new users a window during which their
1177 #password is available to techs, for faxing, etc. (also be aware of
1179 #$recref->{password} = $1.
1180 # crypt($3,$saltset[int(rand(64))].$saltset[int(rand(64))]
1182 } elsif ( $recref->{_password} =~ /^((\*SUSPENDED\* |!!?)?)([\w\.\/\$\;\+]{13,64})$/ ) {
1183 $recref->{_password} = $1.$3;
1184 } elsif ( $recref->{_password} eq '*' ) {
1185 $recref->{_password} = '*';
1186 } elsif ( $recref->{_password} eq '!' ) {
1187 $recref->{_password} = '!';
1188 } elsif ( $recref->{_password} eq '!!' ) {
1189 $recref->{_password} = '!!';
1191 #return "Illegal password";
1192 return gettext('illegal_password'). " $passwordmin-$passwordmax ".
1193 FS::Msgcat::_gettext('illegal_password_characters').
1194 ": ". $recref->{_password};
1197 $self->SUPER::check;
1202 Internal function to check the username against the list of system usernames
1203 from the I<system_usernames> configuration value. Returns true if the username
1204 is listed on the system username list.
1210 scalar( grep { $self->username eq $_ || $self->email eq $_ }
1211 $conf->config('system_usernames')
1215 =item _check_duplicate
1217 Internal function to check for duplicates usernames, username@domain pairs and
1220 If the I<global_unique-username> configuration value is set to B<username> or
1221 B<username@domain>, enforces global username or username@domain uniqueness.
1223 In all cases, check for duplicate uids and usernames or username@domain pairs
1224 per export and with identical I<svcpart> values.
1228 sub _check_duplicate {
1231 my $global_unique = $conf->config('global_unique-username') || 'none';
1232 return '' if $global_unique eq 'disabled';
1234 warn "$me locking svc_acct table for duplicate search" if $DEBUG;
1235 if ( driver_name =~ /^Pg/i ) {
1236 dbh->do("LOCK TABLE svc_acct IN SHARE ROW EXCLUSIVE MODE")
1238 } elsif ( driver_name =~ /^mysql/i ) {
1239 dbh->do("SELECT * FROM duplicate_lock
1240 WHERE lockname = 'svc_acct'
1242 ) or die dbh->errstr;
1244 die "unknown database ". driver_name.
1245 "; don't know how to lock for duplicate search";
1247 warn "$me acquired svc_acct table lock for duplicate search" if $DEBUG;
1249 my $part_svc = qsearchs('part_svc', { 'svcpart' => $self->svcpart } );
1250 unless ( $part_svc ) {
1251 return 'unknown svcpart '. $self->svcpart;
1254 my @dup_user = grep { !$self->svcnum || $_->svcnum != $self->svcnum }
1255 qsearch( 'svc_acct', { 'username' => $self->username } );
1256 return gettext('username_in_use')
1257 if $global_unique eq 'username' && @dup_user;
1259 my @dup_userdomain = grep { !$self->svcnum || $_->svcnum != $self->svcnum }
1260 qsearch( 'svc_acct', { 'username' => $self->username,
1261 'domsvc' => $self->domsvc } );
1262 return gettext('username_in_use')
1263 if $global_unique eq 'username@domain' && @dup_userdomain;
1266 if ( $part_svc->part_svc_column('uid')->columnflag ne 'F'
1267 && $self->username !~ /^(toor|(hyla)?fax)$/ ) {
1268 @dup_uid = grep { !$self->svcnum || $_->svcnum != $self->svcnum }
1269 qsearch( 'svc_acct', { 'uid' => $self->uid } );
1274 if ( @dup_user || @dup_userdomain || @dup_uid ) {
1275 my $exports = FS::part_export::export_info('svc_acct');
1276 my %conflict_user_svcpart;
1277 my %conflict_userdomain_svcpart = ( $self->svcpart => 'SELF', );
1279 foreach my $part_export ( $part_svc->part_export ) {
1281 #this will catch to the same exact export
1282 my @svcparts = map { $_->svcpart } $part_export->export_svc;
1284 #this will catch to exports w/same exporthost+type ???
1285 #my @other_part_export = qsearch('part_export', {
1286 # 'machine' => $part_export->machine,
1287 # 'exporttype' => $part_export->exporttype,
1289 #foreach my $other_part_export ( @other_part_export ) {
1290 # push @svcparts, map { $_->svcpart }
1291 # qsearch('export_svc', { 'exportnum' => $part_export->exportnum });
1294 #my $nodomain = $exports->{$part_export->exporttype}{'nodomain'};
1295 #silly kludge to avoid uninitialized value errors
1296 my $nodomain = exists( $exports->{$part_export->exporttype}{'nodomain'} )
1297 ? $exports->{$part_export->exporttype}{'nodomain'}
1299 if ( $nodomain =~ /^Y/i ) {
1300 $conflict_user_svcpart{$_} = $part_export->exportnum
1303 $conflict_userdomain_svcpart{$_} = $part_export->exportnum
1308 foreach my $dup_user ( @dup_user ) {
1309 my $dup_svcpart = $dup_user->cust_svc->svcpart;
1310 if ( exists($conflict_user_svcpart{$dup_svcpart}) ) {
1311 return "duplicate username ". $self->username.
1312 ": conflicts with svcnum ". $dup_user->svcnum.
1313 " via exportnum ". $conflict_user_svcpart{$dup_svcpart};
1317 foreach my $dup_userdomain ( @dup_userdomain ) {
1318 my $dup_svcpart = $dup_userdomain->cust_svc->svcpart;
1319 if ( exists($conflict_userdomain_svcpart{$dup_svcpart}) ) {
1320 return "duplicate username\@domain ". $self->email.
1321 ": conflicts with svcnum ". $dup_userdomain->svcnum.
1322 " via exportnum ". $conflict_userdomain_svcpart{$dup_svcpart};
1326 foreach my $dup_uid ( @dup_uid ) {
1327 my $dup_svcpart = $dup_uid->cust_svc->svcpart;
1328 if ( exists($conflict_user_svcpart{$dup_svcpart})
1329 || exists($conflict_userdomain_svcpart{$dup_svcpart}) ) {
1330 return "duplicate uid ". $self->uid.
1331 ": conflicts with svcnum ". $dup_uid->svcnum.
1333 ( $conflict_user_svcpart{$dup_svcpart}
1334 || $conflict_userdomain_svcpart{$dup_svcpart} );
1346 Depriciated, use radius_reply instead.
1351 carp "FS::svc_acct::radius depriciated, use radius_reply";
1352 $_[0]->radius_reply;
1357 Returns key/value pairs, suitable for assigning to a hash, for any RADIUS
1358 reply attributes of this record.
1360 Note that this is now the preferred method for reading RADIUS attributes -
1361 accessing the columns directly is discouraged, as the column names are
1362 expected to change in the future.
1369 return %{ $self->{'radius_reply'} }
1370 if exists $self->{'radius_reply'};
1375 my($column, $attrib) = ($1, $2);
1376 #$attrib =~ s/_/\-/g;
1377 ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) );
1378 } grep { /^radius_/ && $self->getfield($_) } fields( $self->table );
1380 if ( $self->slipip && $self->slipip ne '0e0' ) {
1381 $reply{$radius_ip} = $self->slipip;
1384 if ( $self->seconds !~ /^$/ ) {
1385 $reply{'Session-Timeout'} = $self->seconds;
1393 Returns key/value pairs, suitable for assigning to a hash, for any RADIUS
1394 check attributes of this record.
1396 Note that this is now the preferred method for reading RADIUS attributes -
1397 accessing the columns directly is discouraged, as the column names are
1398 expected to change in the future.
1405 return %{ $self->{'radius_check'} }
1406 if exists $self->{'radius_check'};
1411 my($column, $attrib) = ($1, $2);
1412 #$attrib =~ s/_/\-/g;
1413 ( $FS::raddb::attrib{lc($attrib)}, $self->getfield($column) );
1414 } grep { /^rc_/ && $self->getfield($_) } fields( $self->table );
1416 my $password = $self->_password;
1417 my $pw_attrib = length($password) <= 12 ? $radius_password : 'Crypt-Password'; $check{$pw_attrib} = $password;
1419 my $cust_svc = $self->cust_svc;
1420 die "FATAL: no cust_svc record for svc_acct.svcnum ". $self->svcnum. "\n"
1422 my $cust_pkg = $cust_svc->cust_pkg;
1423 if ( $cust_pkg && $cust_pkg->part_pkg->is_prepaid && $cust_pkg->bill ) {
1424 $check{'Expiration'} = time2str('%B %e %Y %T', $cust_pkg->bill ); #http://lists.cistron.nl/pipermail/freeradius-users/2005-January/040184.html
1433 This method instructs the object to "snapshot" or freeze RADIUS check and
1434 reply attributes to the current values.
1438 #bah, my english is too broken this morning
1439 #Of note is the "Expiration" attribute, which, for accounts in prepaid packages, is typically defined on-the-fly as the associated packages cust_pkg.bill. (This is used by
1440 #the FS::cust_pkg's replace method to trigger the correct export updates when
1441 #package dates change)
1446 $self->{$_} = { $self->$_() }
1447 foreach qw( radius_reply radius_check );
1451 =item forget_snapshot
1453 This methos instructs the object to forget any previously snapshotted
1454 RADIUS check and reply attributes.
1458 sub forget_snapshot {
1462 foreach qw( radius_reply radius_check );
1466 =item domain [ END_TIMESTAMP [ START_TIMESTAMP ] ]
1468 Returns the domain associated with this account.
1470 END_TIMESTAMP and START_TIMESTAMP can optionally be passed when dealing with
1477 die "svc_acct.domsvc is null for svcnum ". $self->svcnum unless $self->domsvc;
1478 my $svc_domain = $self->svc_domain(@_)
1479 or die "no svc_domain.svcnum for svc_acct.domsvc ". $self->domsvc;
1480 $svc_domain->domain;
1485 Returns the FS::svc_domain record for this account's domain (see
1490 # FS::h_svc_acct has a history-aware svc_domain override
1495 ? $self->{'_domsvc'}
1496 : qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } );
1501 Returns the FS::cust_svc record for this account (see L<FS::cust_svc>).
1505 #inherited from svc_Common
1507 =item email [ END_TIMESTAMP [ START_TIMESTAMP ] ]
1509 Returns an email address associated with the account.
1511 END_TIMESTAMP and START_TIMESTAMP can optionally be passed when dealing with
1518 $self->username. '@'. $self->domain(@_);
1523 Returns an array of FS::acct_snarf records associated with the account.
1524 If the acct_snarf table does not exist or there are no associated records,
1525 an empty list is returned
1531 return () unless dbdef->table('acct_snarf');
1532 eval "use FS::acct_snarf;";
1534 qsearch('acct_snarf', { 'svcnum' => $self->svcnum } );
1537 =item decrement_upbytes OCTETS
1539 Decrements the I<upbytes> field of this record by the given amount. If there
1540 is an error, returns the error, otherwise returns false.
1544 sub decrement_upbytes {
1545 shift->_op_usage('-', 'upbytes', @_);
1548 =item increment_upbytes OCTETS
1550 Increments the I<upbytes> field of this record by the given amount. If there
1551 is an error, returns the error, otherwise returns false.
1555 sub increment_upbytes {
1556 shift->_op_usage('+', 'upbytes', @_);
1559 =item decrement_downbytes OCTETS
1561 Decrements the I<downbytes> field of this record by the given amount. If there
1562 is an error, returns the error, otherwise returns false.
1566 sub decrement_downbytes {
1567 shift->_op_usage('-', 'downbytes', @_);
1570 =item increment_downbytes OCTETS
1572 Increments the I<downbytes> field of this record by the given amount. If there
1573 is an error, returns the error, otherwise returns false.
1577 sub increment_downbytes {
1578 shift->_op_usage('+', 'downbytes', @_);
1581 =item decrement_totalbytes OCTETS
1583 Decrements the I<totalbytes> field of this record by the given amount. If there
1584 is an error, returns the error, otherwise returns false.
1588 sub decrement_totalbytes {
1589 shift->_op_usage('-', 'totalbytes', @_);
1592 =item increment_totalbytes OCTETS
1594 Increments the I<totalbytes> field of this record by the given amount. If there
1595 is an error, returns the error, otherwise returns false.
1599 sub increment_totalbytes {
1600 shift->_op_usage('+', 'totalbytes', @_);
1603 =item decrement_seconds SECONDS
1605 Decrements the I<seconds> field of this record by the given amount. If there
1606 is an error, returns the error, otherwise returns false.
1610 sub decrement_seconds {
1611 shift->_op_usage('-', 'seconds', @_);
1614 =item increment_seconds SECONDS
1616 Increments the I<seconds> field of this record by the given amount. If there
1617 is an error, returns the error, otherwise returns false.
1621 sub increment_seconds {
1622 shift->_op_usage('+', 'seconds', @_);
1630 my %op2condition = (
1631 '-' => sub { my($self, $column, $amount) = @_;
1632 $self->$column - $amount <= 0;
1634 '+' => sub { my($self, $column, $amount) = @_;
1635 $self->$column + $amount > 0;
1638 my %op2warncondition = (
1639 '-' => sub { my($self, $column, $amount) = @_;
1640 my $threshold = $column . '_threshold';
1641 $self->$column - $amount <= $self->$threshold + 0;
1643 '+' => sub { my($self, $column, $amount) = @_;
1644 $self->$column + $amount > 0;
1649 my( $self, $op, $column, $amount ) = @_;
1651 warn "$me _op_usage called for $column on svcnum ". $self->svcnum.
1652 ' ('. $self->email. "): $op $amount\n"
1655 return '' unless $amount;
1657 local $SIG{HUP} = 'IGNORE';
1658 local $SIG{INT} = 'IGNORE';
1659 local $SIG{QUIT} = 'IGNORE';
1660 local $SIG{TERM} = 'IGNORE';
1661 local $SIG{TSTP} = 'IGNORE';
1662 local $SIG{PIPE} = 'IGNORE';
1664 my $oldAutoCommit = $FS::UID::AutoCommit;
1665 local $FS::UID::AutoCommit = 0;
1668 my $sql = "UPDATE svc_acct SET $column = ".
1669 " CASE WHEN $column IS NULL THEN 0 ELSE $column END ". #$column||0
1670 " $op ? WHERE svcnum = ?";
1674 my $sth = $dbh->prepare( $sql )
1675 or die "Error preparing $sql: ". $dbh->errstr;
1676 my $rv = $sth->execute($amount, $self->svcnum);
1677 die "Error executing $sql: ". $sth->errstr
1678 unless defined($rv);
1679 die "Can't update $column for svcnum". $self->svcnum
1682 my $action = $op2action{$op};
1684 if ( &{$op2condition{$op}}($self, $column, $amount) &&
1685 ( $action eq 'suspend' && !$self->overlimit
1686 || $action eq 'unsuspend' && $self->overlimit )
1688 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
1689 if ($part_export->option('overlimit_groups')) {
1691 my $other = new FS::svc_acct $self->hashref;
1692 my $groups = &{ $self->_fieldhandlers->{'usergroup'} }
1693 ($self, $part_export->option('overlimit_groups'));
1694 $other->usergroup( $groups );
1695 if ($action eq 'suspend'){
1696 $new = $other; $old = $self;
1698 $new = $self; $old = $other;
1700 my $error = $part_export->export_replace($new, $old);
1701 $error ||= $self->overlimit($action);
1703 $dbh->rollback if $oldAutoCommit;
1704 return "Error replacing radius groups in export, ${op}: $error";
1710 if ( $conf->exists("svc_acct-usage_$action")
1711 && &{$op2condition{$op}}($self, $column, $amount) ) {
1712 #my $error = $self->$action();
1713 my $error = $self->cust_svc->cust_pkg->$action();
1714 # $error ||= $self->overlimit($action);
1716 $dbh->rollback if $oldAutoCommit;
1717 return "Error ${action}ing: $error";
1721 if ($warning_template && &{$op2warncondition{$op}}($self, $column, $amount)) {
1722 my $wqueue = new FS::queue {
1723 'svcnum' => $self->svcnum,
1724 'job' => 'FS::svc_acct::reached_threshold',
1729 $to = $warning_cc if &{$op2condition{$op}}($self, $column, $amount);
1733 my $error = $wqueue->insert(
1734 'svcnum' => $self->svcnum,
1736 'column' => $column,
1740 $dbh->rollback if $oldAutoCommit;
1741 return "Error queuing threshold activity: $error";
1745 warn "$me update successful; committing\n"
1747 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
1753 my( $self, $valueref, %options ) = @_;
1755 warn "$me set_usage called for svcnum ". $self->svcnum.
1756 ' ('. $self->email. "): ".
1757 join(', ', map { "$_ => " . $valueref->{$_}} keys %$valueref) . "\n"
1760 local $SIG{HUP} = 'IGNORE';
1761 local $SIG{INT} = 'IGNORE';
1762 local $SIG{QUIT} = 'IGNORE';
1763 local $SIG{TERM} = 'IGNORE';
1764 local $SIG{TSTP} = 'IGNORE';
1765 local $SIG{PIPE} = 'IGNORE';
1767 local $FS::svc_Common::noexport_hack = 1;
1768 my $oldAutoCommit = $FS::UID::AutoCommit;
1769 local $FS::UID::AutoCommit = 0;
1774 if ( $options{null} ) {
1775 %handyhash = ( map { ( $_ => 'NULL', $_."_threshold" => 'NULL' ) }
1776 qw( seconds upbytes downbytes totalbytes )
1779 foreach my $field (keys %$valueref){
1780 $reset = 1 if $valueref->{$field};
1781 $self->setfield($field, $valueref->{$field});
1782 $self->setfield( $field.'_threshold',
1783 int($self->getfield($field)
1784 * ( $conf->exists('svc_acct-usage_threshold')
1785 ? 1 - $conf->config('svc_acct-usage_threshold')/100
1790 $handyhash{$field} = $self->getfield($field);
1791 $handyhash{$field.'_threshold'} = $self->getfield($field.'_threshold');
1793 #my $error = $self->replace; #NO! we avoid the call to ->check for
1794 #die $error if $error; #services not explicity changed via the UI
1796 my $sql = "UPDATE svc_acct SET " .
1797 join (',', map { "$_ = $handyhash{$_}" } (keys %handyhash) ).
1798 " WHERE svcnum = ". $self->svcnum;
1803 if (scalar(keys %handyhash)) {
1804 my $sth = $dbh->prepare( $sql )
1805 or die "Error preparing $sql: ". $dbh->errstr;
1806 my $rv = $sth->execute();
1807 die "Error executing $sql: ". $sth->errstr
1808 unless defined($rv);
1809 die "Can't update usage for svcnum ". $self->svcnum
1816 if ($self->overlimit) {
1817 $error = $self->overlimit('unsuspend');
1818 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
1819 if ($part_export->option('overlimit_groups')) {
1820 my $old = new FS::svc_acct $self->hashref;
1821 my $groups = &{ $self->_fieldhandlers->{'usergroup'} }
1822 ($self, $part_export->option('overlimit_groups'));
1823 $old->usergroup( $groups );
1824 $error ||= $part_export->export_replace($self, $old);
1829 if ( $conf->exists("svc_acct-usage_unsuspend")) {
1830 $error ||= $self->cust_svc->cust_pkg->unsuspend;
1833 $dbh->rollback if $oldAutoCommit;
1834 return "Error unsuspending: $error";
1838 warn "$me update successful; committing\n"
1840 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
1846 =item recharge HASHREF
1848 Increments usage columns by the amount specified in HASHREF as
1849 column=>amount pairs.
1854 my ($self, $vhash) = @_;
1857 warn "[$me] recharge called on $self: ". Dumper($self).
1858 "\nwith vhash: ". Dumper($vhash);
1861 my $oldAutoCommit = $FS::UID::AutoCommit;
1862 local $FS::UID::AutoCommit = 0;
1866 foreach my $column (keys %$vhash){
1867 $error ||= $self->_op_usage('+', $column, $vhash->{$column});
1871 $dbh->rollback if $oldAutoCommit;
1873 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
1878 =item is_rechargeable
1880 Returns true if this svc_account can be "recharged" and false otherwise.
1884 sub is_rechargable {
1886 $self->seconds ne ''
1887 || $self->upbytes ne ''
1888 || $self->downbytes ne ''
1889 || $self->totalbytes ne '';
1892 =item seconds_since TIMESTAMP
1894 Returns the number of seconds this account has been online since TIMESTAMP,
1895 according to the session monitor (see L<FS::Session>).
1897 TIMESTAMP is specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
1898 L<Time::Local> and L<Date::Parse> for conversion functions.
1902 #note: POD here, implementation in FS::cust_svc
1905 $self->cust_svc->seconds_since(@_);
1908 =item seconds_since_sqlradacct TIMESTAMP_START TIMESTAMP_END
1910 Returns the numbers of seconds this account has been online between
1911 TIMESTAMP_START (inclusive) and TIMESTAMP_END (exclusive), according to an
1912 external SQL radacct table, specified via sqlradius export. Sessions which
1913 started in the specified range but are still open are counted from session
1914 start to the end of the range (unless they are over 1 day old, in which case
1915 they are presumed missing their stop record and not counted). Also, sessions
1916 which end in the range but started earlier are counted from the start of the
1917 range to session end. Finally, sessions which start before the range but end
1918 after are counted for the entire range.
1920 TIMESTAMP_START and TIMESTAMP_END are specified as UNIX timestamps; see
1921 L<perlfunc/"time">. Also see L<Time::Local> and L<Date::Parse> for conversion
1926 #note: POD here, implementation in FS::cust_svc
1927 sub seconds_since_sqlradacct {
1929 $self->cust_svc->seconds_since_sqlradacct(@_);
1932 =item attribute_since_sqlradacct TIMESTAMP_START TIMESTAMP_END ATTRIBUTE
1934 Returns the sum of the given attribute for all accounts (see L<FS::svc_acct>)
1935 in this package for sessions ending between TIMESTAMP_START (inclusive) and
1936 TIMESTAMP_END (exclusive).
1938 TIMESTAMP_START and TIMESTAMP_END are specified as UNIX timestamps; see
1939 L<perlfunc/"time">. Also see L<Time::Local> and L<Date::Parse> for conversion
1944 #note: POD here, implementation in FS::cust_svc
1945 sub attribute_since_sqlradacct {
1947 $self->cust_svc->attribute_since_sqlradacct(@_);
1950 =item get_session_history TIMESTAMP_START TIMESTAMP_END
1952 Returns an array of hash references of this customers login history for the
1953 given time range. (document this better)
1957 sub get_session_history {
1959 $self->cust_svc->get_session_history(@_);
1962 =item last_login_text
1964 Returns text describing the time of last login.
1968 sub last_login_text {
1970 $self->last_login ? ctime($self->last_login) : 'unknown';
1973 =item get_cdrs TIMESTAMP_START TIMESTAMP_END [ 'OPTION' => 'VALUE ... ]
1978 my($self, $start, $end, %opt ) = @_;
1980 my $did = $self->username; #yup
1982 my $prefix = $opt{'default_prefix'}; #convergent.au '+61'
1984 my $for_update = $opt{'for_update'} ? 'FOR UPDATE' : '';
1986 #SELECT $for_update * FROM cdr
1987 # WHERE calldate >= $start #need a conversion
1988 # AND calldate < $end #ditto
1989 # AND ( charged_party = "$did"
1990 # OR charged_party = "$prefix$did" #if length($prefix);
1991 # OR ( ( charged_party IS NULL OR charged_party = '' )
1993 # ( src = "$did" OR src = "$prefix$did" ) # if length($prefix)
1996 # AND ( freesidestatus IS NULL OR freesidestatus = '' )
1999 if ( length($prefix) ) {
2001 " AND ( charged_party = '$did'
2002 OR charged_party = '$prefix$did'
2003 OR ( ( charged_party IS NULL OR charged_party = '' )
2005 ( src = '$did' OR src = '$prefix$did' )
2011 " AND ( charged_party = '$did'
2012 OR ( ( charged_party IS NULL OR charged_party = '' )
2022 'select' => "$for_update *",
2025 #( freesidestatus IS NULL OR freesidestatus = '' )
2026 'freesidestatus' => '',
2028 'extra_sql' => $charged_or_src,
2036 Returns all RADIUS groups for this account (see L<FS::radius_usergroup>).
2042 if ( $self->usergroup ) {
2043 confess "explicitly specified usergroup not an arrayref: ". $self->usergroup
2044 unless ref($self->usergroup) eq 'ARRAY';
2045 #when provisioning records, export callback runs in svc_Common.pm before
2046 #radius_usergroup records can be inserted...
2047 @{$self->usergroup};
2049 map { $_->groupname }
2050 qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } );
2054 =item clone_suspended
2056 Constructor used by FS::part_export::_export_suspend fallback. Document
2061 sub clone_suspended {
2063 my %hash = $self->hash;
2064 $hash{_password} = join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) );
2065 new FS::svc_acct \%hash;
2068 =item clone_kludge_unsuspend
2070 Constructor used by FS::part_export::_export_unsuspend fallback. Document
2075 sub clone_kludge_unsuspend {
2077 my %hash = $self->hash;
2078 $hash{_password} = '';
2079 new FS::svc_acct \%hash;
2082 =item check_password
2084 Checks the supplied password against the (possibly encrypted) password in the
2085 database. Returns true for a successful authentication, false for no match.
2087 Currently supported encryptions are: classic DES crypt() and MD5
2091 sub check_password {
2092 my($self, $check_password) = @_;
2094 #remove old-style SUSPENDED kludge, they should be allowed to login to
2095 #self-service and pay up
2096 ( my $password = $self->_password ) =~ s/^\*SUSPENDED\* //;
2098 #eventually should check a "password-encoding" field
2099 if ( $password =~ /^(\*|!!?)$/ ) { #no self-service login
2101 } elsif ( length($password) < 13 ) { #plaintext
2102 $check_password eq $password;
2103 } elsif ( length($password) == 13 ) { #traditional DES crypt
2104 crypt($check_password, $password) eq $password;
2105 } elsif ( $password =~ /^\$1\$/ ) { #MD5 crypt
2106 unix_md5_crypt($check_password, $password) eq $password;
2107 } elsif ( $password =~ /^\$2a?\$/ ) { #Blowfish
2108 warn "Can't check password: Blowfish encryption not yet supported, svcnum".
2109 $self->svcnum. "\n";
2112 warn "Can't check password: Unrecognized encryption for svcnum ".
2113 $self->svcnum. "\n";
2119 =item crypt_password [ DEFAULT_ENCRYPTION_TYPE ]
2121 Returns an encrypted password, either by passing through an encrypted password
2122 in the database or by encrypting a plaintext password from the database.
2124 The optional DEFAULT_ENCRYPTION_TYPE parameter can be set to I<crypt> (classic
2125 UNIX DES crypt), I<md5> (md5 crypt supported by most modern Linux and BSD
2126 distrubtions), or (eventually) I<blowfish> (blowfish hashing supported by
2127 OpenBSD, SuSE, other Linux distibutions with pam_unix2, etc.). The default
2128 encryption type is only used if the password is not already encrypted in the
2133 sub crypt_password {
2135 #eventually should check a "password-encoding" field
2136 if ( length($self->_password) == 13
2137 || $self->_password =~ /^\$(1|2a?)\$/
2138 || $self->_password =~ /^(\*|NP|\*LK\*|!!?)$/
2143 my $encryption = ( scalar(@_) && $_[0] ) ? shift : 'crypt';
2144 if ( $encryption eq 'crypt' ) {
2147 $saltset[int(rand(64))].$saltset[int(rand(64))]
2149 } elsif ( $encryption eq 'md5' ) {
2150 unix_md5_crypt( $self->_password );
2151 } elsif ( $encryption eq 'blowfish' ) {
2152 croak "unknown encryption method $encryption";
2154 croak "unknown encryption method $encryption";
2159 =item ldap_password [ DEFAULT_ENCRYPTION_TYPE ]
2161 Returns an encrypted password in "LDAP" format, with a curly-bracked prefix
2162 describing the format, for example, "{CRYPT}94pAVyK/4oIBk" or
2163 "{PLAIN-MD5}5426824942db4253f87a1009fd5d2d4f".
2165 The optional DEFAULT_ENCRYPTION_TYPE is not yet used, but the idea is for it
2166 to work the same as the B</crypt_password> method.
2172 #eventually should check a "password-encoding" field
2173 if ( length($self->_password) == 13 ) { #crypt
2174 return '{CRYPT}'. $self->_password;
2175 } elsif ( $self->_password =~ /^\$1\$(.*)$/ && length($1) == 31 ) { #passwdMD5
2177 } elsif ( $self->_password =~ /^\$2a?\$(.*)$/ ) { #Blowfish
2178 warn "Blowfish encryption not supported in this context, svcnum ".
2179 $self->svcnum. "\n";
2180 return '{CRYPT}*'; #unsupported, should not auth
2181 } elsif ( $self->_password =~ /^(\w{48})$/ ) { #LDAP SSHA
2182 return '{SSHA}'. $1;
2183 } elsif ( $self->_password =~ /^(\w{64})$/ ) { #LDAP NS-MTA-MD5
2184 return '{NS-MTA-MD5}'. $1;
2186 return '{PLAIN}'. $self->_password;
2187 #my $encryption = ( scalar(@_) && $_[0] ) ? shift : 'crypt';
2188 #if ( $encryption eq 'crypt' ) {
2189 # return '{CRYPT}'. crypt(
2191 # $saltset[int(rand(64))].$saltset[int(rand(64))]
2193 #} elsif ( $encryption eq 'md5' ) {
2194 # unix_md5_crypt( $self->_password );
2195 #} elsif ( $encryption eq 'blowfish' ) {
2196 # croak "unknown encryption method $encryption";
2198 # croak "unknown encryption method $encryption";
2203 =item domain_slash_username
2205 Returns $domain/$username/
2209 sub domain_slash_username {
2211 $self->domain. '/'. $self->username. '/';
2214 =item virtual_maildir
2216 Returns $domain/maildirs/$username/
2220 sub virtual_maildir {
2222 $self->domain. '/maildirs/'. $self->username. '/';
2233 This is the FS::svc_acct job-queue-able version. It still uses
2234 FS::Misc::send_email under-the-hood.
2241 eval "use FS::Misc qw(send_email)";
2244 $opt{mimetype} ||= 'text/plain';
2245 $opt{mimetype} .= '; charset="iso-8859-1"' unless $opt{mimetype} =~ /charset/;
2247 my $error = send_email(
2248 'from' => $opt{from},
2250 'subject' => $opt{subject},
2251 'content-type' => $opt{mimetype},
2252 'body' => [ map "$_\n", split("\n", $opt{body}) ],
2254 die $error if $error;
2257 =item check_and_rebuild_fuzzyfiles
2261 sub check_and_rebuild_fuzzyfiles {
2262 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
2263 -e "$dir/svc_acct.username"
2264 or &rebuild_fuzzyfiles;
2267 =item rebuild_fuzzyfiles
2271 sub rebuild_fuzzyfiles {
2273 use Fcntl qw(:flock);
2275 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
2279 open(USERNAMELOCK,">>$dir/svc_acct.username")
2280 or die "can't open $dir/svc_acct.username: $!";
2281 flock(USERNAMELOCK,LOCK_EX)
2282 or die "can't lock $dir/svc_acct.username: $!";
2284 my @all_username = map $_->getfield('username'), qsearch('svc_acct', {});
2286 open (USERNAMECACHE,">$dir/svc_acct.username.tmp")
2287 or die "can't open $dir/svc_acct.username.tmp: $!";
2288 print USERNAMECACHE join("\n", @all_username), "\n";
2289 close USERNAMECACHE or die "can't close $dir/svc_acct.username.tmp: $!";
2291 rename "$dir/svc_acct.username.tmp", "$dir/svc_acct.username";
2301 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
2302 open(USERNAMECACHE,"<$dir/svc_acct.username")
2303 or die "can't open $dir/svc_acct.username: $!";
2304 my @array = map { chomp; $_; } <USERNAMECACHE>;
2305 close USERNAMECACHE;
2309 =item append_fuzzyfiles USERNAME
2313 sub append_fuzzyfiles {
2314 my $username = shift;
2316 &check_and_rebuild_fuzzyfiles;
2318 use Fcntl qw(:flock);
2320 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
2322 open(USERNAME,">>$dir/svc_acct.username")
2323 or die "can't open $dir/svc_acct.username: $!";
2324 flock(USERNAME,LOCK_EX)
2325 or die "can't lock $dir/svc_acct.username: $!";
2327 print USERNAME "$username\n";
2329 flock(USERNAME,LOCK_UN)
2330 or die "can't unlock $dir/svc_acct.username: $!";
2338 =item radius_usergroup_selector GROUPS_ARRAYREF [ SELECTNAME ]
2342 sub radius_usergroup_selector {
2343 my $sel_groups = shift;
2344 my %sel_groups = map { $_=>1 } @$sel_groups;
2346 my $selectname = shift || 'radius_usergroup';
2349 my $sth = $dbh->prepare(
2350 'SELECT DISTINCT(groupname) FROM radius_usergroup ORDER BY groupname'
2351 ) or die $dbh->errstr;
2352 $sth->execute() or die $sth->errstr;
2353 my @all_groups = map { $_->[0] } @{$sth->fetchall_arrayref};
2357 function ${selectname}_doadd(object) {
2358 var myvalue = object.${selectname}_add.value;
2359 var optionName = new Option(myvalue,myvalue,false,true);
2360 var length = object.$selectname.length;
2361 object.$selectname.options[length] = optionName;
2362 object.${selectname}_add.value = "";
2365 <SELECT MULTIPLE NAME="$selectname">
2368 foreach my $group ( @all_groups ) {
2369 $html .= qq(<OPTION VALUE="$group");
2370 if ( $sel_groups{$group} ) {
2371 $html .= ' SELECTED';
2372 $sel_groups{$group} = 0;
2374 $html .= ">$group</OPTION>\n";
2376 foreach my $group ( grep { $sel_groups{$_} } keys %sel_groups ) {
2377 $html .= qq(<OPTION VALUE="$group" SELECTED>$group</OPTION>\n);
2379 $html .= '</SELECT>';
2381 $html .= qq!<BR><INPUT TYPE="text" NAME="${selectname}_add">!.
2382 qq!<INPUT TYPE="button" VALUE="Add new group" onClick="${selectname}_doadd(this.form)">!;
2387 =item reached_threshold
2389 Performs some activities when svc_acct thresholds (such as number of seconds
2390 remaining) are reached.
2394 sub reached_threshold {
2397 my $svc_acct = qsearchs('svc_acct', { 'svcnum' => $opt{'svcnum'} } );
2398 die "Cannot find svc_acct with svcnum " . $opt{'svcnum'} unless $svc_acct;
2400 if ( $opt{'op'} eq '+' ){
2401 $svc_acct->setfield( $opt{'column'}.'_threshold',
2402 int($svc_acct->getfield($opt{'column'})
2403 * ( $conf->exists('svc_acct-usage_threshold')
2404 ? $conf->config('svc_acct-usage_threshold')/100
2409 my $error = $svc_acct->replace;
2410 die $error if $error;
2411 }elsif ( $opt{'op'} eq '-' ){
2413 my $threshold = $svc_acct->getfield( $opt{'column'}.'_threshold' );
2414 return '' if ($threshold eq '' );
2416 $svc_acct->setfield( $opt{'column'}.'_threshold', 0 );
2417 my $error = $svc_acct->replace;
2418 die $error if $error; # email next time, i guess
2420 if ( $warning_template ) {
2421 eval "use FS::Misc qw(send_email)";
2424 my $cust_pkg = $svc_acct->cust_svc->cust_pkg;
2425 my $cust_main = $cust_pkg->cust_main;
2427 my $to = join(', ', grep { $_ !~ /^(POST|FAX)$/ }
2428 $cust_main->invoicing_list,
2429 ($opt{'to'} ? $opt{'to'} : ())
2432 my $mimetype = $warning_mimetype;
2433 $mimetype .= '; charset="iso-8859-1"' unless $opt{mimetype} =~ /charset/;
2435 my $body = $warning_template->fill_in( HASH => {
2436 'custnum' => $cust_main->custnum,
2437 'username' => $svc_acct->username,
2438 'password' => $svc_acct->_password,
2439 'first' => $cust_main->first,
2440 'last' => $cust_main->getfield('last'),
2441 'pkg' => $cust_pkg->part_pkg->pkg,
2442 'column' => $opt{'column'},
2443 'amount' => $opt{'column'} =~/bytes/
2444 ? FS::UI::bytecount::display_bytecount($svc_acct->getfield($opt{'column'}))
2445 : $svc_acct->getfield($opt{'column'}),
2446 'threshold' => $opt{'column'} =~/bytes/
2447 ? FS::UI::bytecount::display_bytecount($threshold)
2452 my $error = send_email(
2453 'from' => $warning_from,
2455 'subject' => $warning_subject,
2456 'content-type' => $mimetype,
2457 'body' => [ map "$_\n", split("\n", $body) ],
2459 die $error if $error;
2462 die "unknown op: " . $opt{'op'};
2470 The $recref stuff in sub check should be cleaned up.
2472 The suspend, unsuspend and cancel methods update the database, but not the
2473 current object. This is probably a bug as it's unexpected and
2476 radius_usergroup_selector? putting web ui components in here? they should
2477 probably live somewhere else...
2479 insertion of RADIUS group stuff in insert could be done with child_objects now
2480 (would probably clean up export of them too)
2484 L<FS::svc_Common>, edit/part_svc.cgi from an installed web interface,
2485 export.html from the base documentation, L<FS::Record>, L<FS::Conf>,
2486 L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>, L<FS::queue>,
2487 L<freeside-queued>), L<FS::svc_acct_pop>,
2488 schema.html from the base documentation.
2492 =item domain_select_hash %OPTIONS
2494 Returns a hash SVCNUM => DOMAIN ... representing the domains this customer
2495 may at present purchase.
2497 Currently available options are: I<pkgnum> I<svcpart>
2501 sub domain_select_hash {
2502 my ($self, %options) = @_;
2508 $part_svc = $self->part_svc;
2509 $cust_pkg = $self->cust_svc->cust_pkg
2513 $part_svc = qsearchs('part_svc', { 'svcpart' => $options{svcpart} })
2514 if $options{'svcpart'};
2516 $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $options{pkgnum} })
2517 if $options{'pkgnum'};
2519 if ($part_svc && ( $part_svc->part_svc_column('domsvc')->columnflag eq 'S'
2520 || $part_svc->part_svc_column('domsvc')->columnflag eq 'F')) {
2521 %domains = map { $_->svcnum => $_->domain }
2522 map { qsearchs('svc_domain', { 'svcnum' => $_ }) }
2523 split(',', $part_svc->part_svc_column('domsvc')->columnvalue);
2524 }elsif ($cust_pkg && !$conf->exists('svc_acct-alldomains') ) {
2525 %domains = map { $_->svcnum => $_->domain }
2526 map { qsearchs('svc_domain', { 'svcnum' => $_->svcnum }) }
2527 map { qsearch('cust_svc', { 'pkgnum' => $_->pkgnum } ) }
2528 qsearch('cust_pkg', { 'custnum' => $cust_pkg->custnum });
2530 %domains = map { $_->svcnum => $_->domain } qsearch('svc_domain', {} );
2533 if ($part_svc && $part_svc->part_svc_column('domsvc')->columnflag eq 'D') {
2534 my $svc_domain = qsearchs('svc_domain',
2535 { 'svcnum' => $part_svc->part_svc_column('domsvc')->columnvalue } );
2536 if ( $svc_domain ) {
2537 $domains{$svc_domain->svcnum} = $svc_domain->domain;
2539 warn "unknown svc_domain.svcnum for part_svc_column domsvc: ".
2540 $part_svc->part_svc_column('domsvc')->columnvalue;