4 use vars qw($DEBUG $cgi $session_id $form_max $template_dir);
5 use subs qw(do_template);
7 use CGI::Carp qw(fatalsToBrowser);
11 use Number::Format 1.50;
12 use FS::SelfService qw( login_info login customer_info edit_info invoice
13 payment_info process_payment realtime_collect
15 list_pkgs order_pkg signup_info order_recharge
16 part_svc_info provision_acct provision_external
17 unprovision_svc change_pkg domainselector
19 list_svc_usage list_cdr_usage list_support_usage
31 unless ( defined $cgi->param('session') ) {
32 my $login_info = login_info();
34 do_template('login', $login_info );
38 if ( $cgi->param('session') eq 'login' ) {
40 $cgi->param('username') =~ /^\s*([a-z0-9_\-\.\&]{0,$form_max})\s*$/i
41 or die "illegal username";
44 $cgi->param('domain') =~ /^\s*([\w\-\.]{0,$form_max})\s*$/
45 or die "illegal domain";
48 $cgi->param('password') =~ /^(.{0,$form_max})$/
49 or die "illegal password";
53 'username' => $username,
55 'password' => $password,
58 my $login_info = login_info();
59 do_template('login', {
60 'error' => $rv->{error},
61 'username' => $username,
67 $cgi->param('session' => $rv->{session_id} );
68 $cgi->param('action' => 'myaccount' );
72 $session_id = $cgi->param('session');
74 #order|pw_list XXX ???
75 $cgi->param('action') =~
76 /^(myaccount|view_invoice|make_payment|make_ach_payment|make_thirdparty_payment|payment_results|ach_payment_results|recharge_prepay|recharge_results|logout|change_bill|change_ship|change_pay|process_change_bill|process_change_ship|process_change_pay|customer_order_pkg|process_order_pkg|customer_change_pkg|process_change_pkg|process_order_recharge|provision|provision_svc|process_svc_acct|process_svc_external|delete_svc|view_usage|view_usage_details|view_cdr_details|view_support_details|change_password|process_change_password)$/
77 or die "unknown action ". $cgi->param('action');
80 warn "calling $action sub\n"
82 $FS::SelfService::DEBUG = $DEBUG;
83 my $result = eval "&$action();";
86 if ( $result->{error} eq "Can't resume session"
87 || $result->{error} eq "Expired session" ) { #ick
89 my $login_info = login_info();
90 do_template('login', $login_info);
94 #warn $result->{'open_invoices'};
95 #warn scalar(@{$result->{'open_invoices'}});
97 warn "processing template $action\n"
99 do_template($action, {
100 'session_id' => $session_id,
101 'action' => $action, #so the menu knows what tab we're on...
102 %{ payment_info( 'session_id' => $session_id ) }, # cust_paybys for the menu
108 sub myaccount { customer_info( 'session_id' => $session_id ); }
110 sub change_bill { my $payment_info =
111 payment_info( 'session_id' => $session_id );
112 return $payment_info if ( $payment_info->{'error'} );
114 customer_info( 'session_id' => $session_id );
120 sub change_ship { change_bill(@_); }
121 sub change_pay { change_bill(@_); }
123 sub _process_change_info {
124 my ($erroraction, @fields) = @_;
128 $results ||= edit_info (
129 'session_id' => $session_id,
130 map { ($_ => $cgi->param($_)) } grep { defined($cgi->param($_)) } @fields,
134 if ( $results->{'error'} ) {
136 $action = $erroraction;
140 'error' => '<FONT COLOR="#FF0000">'. $results->{'error'}. '</FONT>',
147 sub process_change_bill {
148 _process_change_info( 'change_bill',
149 qw( first last company address1 address2 city state
150 county zip country daytime night fax )
154 sub process_change_ship {
155 my @list = map { "ship_$_" }
156 qw( first last company address1 address2 city state
157 county zip country daytime night fax
159 if ($cgi->param('same') eq 'Y') {
160 foreach (@list) { $cgi->param($_, '') }
163 _process_change_info( 'change_ship', @list );
166 sub process_change_pay {
167 my $postal = $cgi->param( 'postal_invoicing' );
169 qw( payby payinfo payinfo1 payinfo2 month year payname
170 address1 address2 city county state zip country auto paytype
171 paystate ss stateid stateid_state invoicing_list
173 push @list, 'postal_invoicing' if $postal;
174 unless ( $postal || $cgi->param( 'invoicing_list' ) ) {
175 $action = 'change_pay';
179 'error' => '<FONT COLOR="#FF0000">Postal or email required.</FONT>',
182 _process_change_info( 'change_pay', @list );
187 $cgi->param('invnum') =~ /^(\d+)$/ or die "illegal invnum";
190 invoice( 'session_id' => $session_id,
196 sub customer_order_pkg {
197 my $init_data = signup_info( 'customer_session_id' => $session_id );
198 return $init_data if ( $init_data->{'error'} );
200 my $customer_info = customer_info( 'session_id' => $session_id );
201 return $customer_info if ( $customer_info->{'error'} );
204 ( map { $_ => $init_data->{$_} }
205 qw( part_pkg security_phrase svc_acct_pop ),
211 sub customer_change_pkg {
212 my $init_data = signup_info( 'customer_session_id' => $session_id );
213 return $init_data if ( $init_data->{'error'} );
215 my $customer_info = customer_info( 'session_id' => $session_id );
216 return $customer_info if ( $customer_info->{'error'} );
219 ( map { $_ => $init_data->{$_} }
220 qw( part_pkg security_phrase svc_acct_pop ),
222 ( map { $_ => $cgi->param($_) }
229 sub process_order_pkg {
233 unless ( length($cgi->param('_password')) ) {
234 my $init_data = signup_info( 'customer_session_id' => $session_id );
235 $results = { 'error' => $init_data->{msgcat}{empty_password} };
236 $results = { 'error' => $init_data->{error} } if($init_data->{error});
238 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
239 my $init_data = signup_info( 'customer_session_id' => $session_id );
240 $results = { 'error' => $init_data->{msgcat}{passwords_dont_match} };
241 $results = { 'error' => $init_data->{error} } if($init_data->{error});
242 $cgi->param('_password', '');
243 $cgi->param('_password2', '');
246 $results ||= order_pkg (
247 'session_id' => $session_id,
248 map { $_ => $cgi->param($_) }
249 qw( custnum pkgpart username _password _password2 sec_phrase popnum )
253 if ( $results->{'error'} ) {
254 $action = 'customer_order_pkg';
257 %{customer_order_pkg()},
258 'error' => '<FONT COLOR="#FF0000">'. $results->{'error'}. '</FONT>',
266 sub process_change_pkg {
270 $results ||= change_pkg (
271 'session_id' => $session_id,
272 map { $_ => $cgi->param($_) }
277 if ( $results->{'error'} ) {
278 $action = 'customer_change_pkg';
281 %{customer_change_pkg()},
282 'error' => '<FONT COLOR="#FF0000">'. $results->{'error'}. '</FONT>',
290 sub process_order_recharge {
294 $results ||= order_recharge (
295 'session_id' => $session_id,
296 map { $_ => $cgi->param($_) }
301 if ( $results->{'error'} ) {
302 $action = 'view_usage';
303 if ($results->{'error'} eq '_decline') {
304 $results->{'error'} = "There has been an error processing your account. Please contact customer support."
309 'error' => '<FONT COLOR="#FF0000">'. $results->{'error'}. '</FONT>',
318 payment_info( 'session_id' => $session_id );
321 sub payment_results {
323 use Business::CreditCard;
325 #we should only do basic checking here for DoS attacks and things
326 #that couldn't be constructed by the web form... let process_payment() do
327 #the rest, it gives better error messages
329 $cgi->param('amount') =~ /^\s*(\d+(\.\d{2})?)\s*$/
330 or die "Illegal amount: ". $cgi->param('amount'); #!!!
333 my $payinfo = $cgi->param('payinfo');
335 $payinfo =~ /^(\d{13,16})$/
336 #or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
337 or die "illegal card"; #!!!
340 #or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
341 or die "invalid card"; #!!!
343 if ( $cgi->param('card_type') ) {
344 cardtype($payinfo) eq $cgi->param('card_type')
345 #or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
346 or die "not a ". $cgi->param('card_type');
349 $cgi->param('paycvv') =~ /^\s*(.{0,4})\s*$/ or die "illegal CVV2";
352 $cgi->param('month') =~ /^(\d{2})$/ or die "illegal month";
354 $cgi->param('year') =~ /^(\d{4})$/ or die "illegal year";
357 $cgi->param('payname') =~ /^(.{0,80})$/ or die "illegal payname";
360 $cgi->param('address1') =~ /^(.{0,80})$/ or die "illegal address1";
363 $cgi->param('address2') =~ /^(.{0,80})$/ or die "illegal address2";
366 $cgi->param('city') =~ /^(.{0,80})$/ or die "illegal city";
369 $cgi->param('state') =~ /^(.{2})$/ or die "illegal state";
372 $cgi->param('zip') =~ /^(.{0,10})$/ or die "illegal zip";
376 $save = 1 if $cgi->param('save');
379 $auto = 1 if $cgi->param('auto');
381 $cgi->param('paybatch') =~ /^([\w\-\.]+)$/ or die "illegal paybatch";
385 'session_id' => $session_id,
388 'payinfo' => $payinfo,
392 'payname' => $payname,
393 'address1' => $address1,
394 'address2' => $address2,
400 'paybatch' => $paybatch,
405 sub make_ach_payment {
406 payment_info( 'session_id' => $session_id );
409 sub ach_payment_results {
411 #we should only do basic checking here for DoS attacks and things
412 #that couldn't be constructed by the web form... let process_payment() do
413 #the rest, it gives better error messages
415 $cgi->param('amount') =~ /^\s*(\d+(\.\d{2})?)\s*$/
416 or die "illegal amount"; #!!!
419 my $payinfo1 = $cgi->param('payinfo1');
420 $payinfo1=~ /^(\d+)$/
421 or die "illegal account"; #!!!
424 my $payinfo2 = $cgi->param('payinfo2');
425 $payinfo2=~ /^(\d+)$/
426 or die "illegal ABA/routing code"; #!!!
429 $cgi->param('payname') =~ /^(.{0,80})$/ or die "illegal payname";
432 $cgi->param('paystate') =~ /^(.{0,2})$/ or die "illegal paystate";
435 $cgi->param('paytype') =~ /^(.{0,80})$/ or die "illegal paytype";
438 $cgi->param('ss') =~ /^(.{0,80})$/ or die "illegal ss";
441 $cgi->param('stateid') =~ /^(.{0,80})$/ or die "illegal stateid";
444 $cgi->param('stateid_state') =~ /^(.{0,2})$/ or die "illegal stateid_state";
445 my $stateid_state = $1;
448 $save = 1 if $cgi->param('save');
451 $auto = 1 if $cgi->param('auto');
453 $cgi->param('paybatch') =~ /^([\w\-\.]+)$/ or die "illegal paybatch";
457 'session_id' => $session_id,
460 'payinfo1' => $payinfo1,
461 'payinfo2' => $payinfo2,
464 'payname' => $payname,
465 'paytype' => $paytype,
466 'paystate' => $paystate,
468 'stateid' => $stateid,
469 'stateid_state' => $stateid_state,
472 'paybatch' => $paybatch,
477 sub make_thirdparty_payment {
478 $cgi->param('payby_method') =~ /^(CC|ECHECK)$/
479 or die "illegal payby method";
480 realtime_collect( 'session_id' => $session_id, 'method' => $1 );
483 sub recharge_prepay {
484 customer_info( 'session_id' => $session_id );
487 sub recharge_results {
489 my $prepaid_cardnum = $cgi->param('prepaid_cardnum');
490 $prepaid_cardnum =~ s/\W//g;
491 $prepaid_cardnum =~ /^(\w*)$/ or die "illegal prepaid card number";
492 $prepaid_cardnum = $1;
494 process_prepay ( 'session_id' => $session_id,
495 'prepaid_cardnum' => $prepaid_cardnum,
500 FS::SelfService::logout( 'session_id' => $session_id );
504 my $result = list_pkgs( 'session_id' => $session_id );
505 die $result->{'error'} if exists $result->{'error'} && $result->{'error'};
511 my $result = part_svc_info(
512 'session_id' => $session_id,
513 map { $_ => $cgi->param($_) } qw( pkgnum svcpart ),
515 die $result->{'error'} if exists $result->{'error'} && $result->{'error'};
517 $result->{'svcdb'} =~ /^svc_(.*)$/
518 #or return { 'error' => 'Unknown svcdb '. $result->{'svcdb'} };
519 or die 'Unknown svcdb '. $result->{'svcdb'};
525 sub process_svc_acct {
527 my $result = provision_acct (
528 'session_id' => $session_id,
529 map { $_ => $cgi->param($_) } qw(
530 pkgnum svcpart username domsvc _password _password2 sec_phrase popnum )
533 if ( exists $result->{'error'} && $result->{'error'} ) {
534 #warn "$result $result->{'error'}";
535 $action = 'provision_svc_acct';
538 %{ part_svc_info( 'session_id' => $session_id,
539 map { $_ => $cgi->param($_) } qw( pkgnum svcpart )
542 'error' => $result->{'error'},
545 #warn "$result $result->{'error'}";
551 sub process_svc_external {
553 'session_id' => $session_id,
554 map { $_ => $cgi->param($_) } qw( pkgnum svcpart )
560 'session_id' => $session_id,
561 'svcnum' => $cgi->param('svcnum'),
567 'session_id' => $session_id,
568 'svcdb' => [ 'svc_acct', 'svc_phone' ],
573 sub view_usage_details {
575 'session_id' => $session_id,
576 'svcnum' => $cgi->param('svcnum'),
577 'beginning' => $cgi->param('beginning') || '',
578 'ending' => $cgi->param('ending') || '',
582 sub view_cdr_details {
584 'session_id' => $session_id,
585 'svcnum' => $cgi->param('svcnum'),
586 'beginning' => $cgi->param('beginning') || '',
587 'ending' => $cgi->param('ending') || '',
591 sub view_support_details {
593 'session_id' => $session_id,
594 'svcnum' => $cgi->param('svcnum'),
595 'beginning' => $cgi->param('beginning') || '',
596 'ending' => $cgi->param('ending') || '',
600 sub change_password {
602 'session_id' => $session_id,
603 'svcdb' => 'svc_acct',
607 sub process_change_password {
609 my $result = myaccount_passwd(
610 'session_id' => $session_id,
611 map { $_ => $cgi->param($_) } qw( svcnum new_password new_password2 )
614 if ( exists $result->{'error'} && $result->{'error'} ) {
616 $action = 'change_password';
619 %{ list_svcs( 'session_id' => $session_id,
620 'svcdb' => 'svc_acct',
623 #'svcnum' => $cgi->param('svcnum'),
624 'error' => $result->{'error'}
642 $fill_in->{'selfurl'} = $cgi->self_url;
643 $fill_in->{'cgi'} = \$cgi;
645 my $source = "$template_dir/$name.html";
646 #warn "creating template for $source\n";
647 my $template = new Text::Template( TYPE => 'FILE',
649 DELIMITERS => [ '<%=', '%>' ],
652 or die $Text::Template::ERROR;
654 #warn "filling in $template with $fill_in\n";
655 print $cgi->header( '-expires' => 'now' ),
656 $template->fill_in( PACKAGE => 'FS::SelfService::_selfservicecgi',
661 #*FS::SelfService::_selfservicecgi::include = \&Text::Template::fill_in_file;
663 package FS::SelfService::_selfservicecgi;
665 #use FS::SelfService qw(regionselector expselect popselector);
667 use FS::SelfService qw(regionselector popselector domainselector location_form);
669 #false laziness w/agent.cgi
672 my $template = new Text::Template( TYPE => 'FILE',
673 SOURCE => "$main::template_dir/$name.html",
674 DELIMITERS => [ '<%=', '%>' ],
677 or die $Text::Template::ERROR;
679 $template->fill_in( PACKAGE => 'FS::SelfService::_selfservicecgi',