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 customer_info edit_info invoice
13 payment_info process_payment
15 list_pkgs order_pkg signup_info order_recharge
16 part_svc_info provision_acct provision_external
17 unprovision_svc change_pkg domainselector
18 list_svcs list_svc_usage myaccount_passwd
29 unless ( defined $cgi->param('session') ) {
30 do_template('login',{});
34 if ( $cgi->param('session') eq 'login' ) {
36 $cgi->param('username') =~ /^\s*([a-z0-9_\-\.\&]{0,$form_max})\s*$/i
37 or die "illegal username";
40 $cgi->param('domain') =~ /^\s*([\w\-\.]{0,$form_max})\s*$/
41 or die "illegal domain";
44 $cgi->param('password') =~ /^(.{0,$form_max})$/
45 or die "illegal password";
49 'username' => $username,
51 'password' => $password,
54 do_template('login', {
55 'error' => $rv->{error},
56 'username' => $username,
61 $cgi->param('session' => $rv->{session_id} );
62 $cgi->param('action' => 'myaccount' );
66 $session_id = $cgi->param('session');
68 #order|pw_list XXX ???
69 $cgi->param('action') =~
70 /^(myaccount|view_invoice|make_payment|make_ach_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|change_password|process_change_password)$/
71 or die "unknown action ". $cgi->param('action');
74 warn "calling $action sub\n"
76 $FS::SelfService::DEBUG = $DEBUG;
77 my $result = eval "&$action();";
80 if ( $result->{error} eq "Can't resume session"
81 || $result->{error} eq "Expired session" ) { #ick
83 do_template('login',{});
87 #warn $result->{'open_invoices'};
88 #warn scalar(@{$result->{'open_invoices'}});
90 warn "processing template $action\n"
92 do_template($action, {
93 'session_id' => $session_id,
94 'action' => $action, #so the menu knows what tab we're on...
100 sub myaccount { customer_info( 'session_id' => $session_id ); }
102 sub change_bill { my $payment_info =
103 payment_info( 'session_id' => $session_id );
104 return $payment_info if ( $payment_info->{'error'} );
106 customer_info( 'session_id' => $session_id );
112 sub change_ship { change_bill(@_); }
113 sub change_pay { change_bill(@_); }
115 sub _process_change_info {
116 my ($erroraction, @fields) = @_;
120 $results ||= edit_info (
121 'session_id' => $session_id,
122 map { ($_ => $cgi->param($_)) } grep { defined($cgi->param($_)) } @fields,
126 if ( $results->{'error'} ) {
128 $action = $erroraction;
132 'error' => '<FONT COLOR="#FF0000">'. $results->{'error'}. '</FONT>',
139 sub process_change_bill {
140 _process_change_info( 'change_bill',
141 qw( first last company address1 address2 city state
142 county state zip country daytime night fax )
146 sub process_change_ship {
147 my @list = map { "ship_$_" }
148 qw( first last company address1 address2 city state
149 county zip country daytime night fax
151 if ($cgi->param('same') eq 'Y') {
152 foreach (@list) { $cgi->param($_, '') }
155 _process_change_info( 'change_ship', @list );
158 sub process_change_pay {
159 _process_change_info( 'change_pay',
160 qw( payby payinfo payinfo1 payinfo2 month year payname
161 address1 address2 city county state zip country auto paytype
162 paystate ss stateid stateid_state )
168 $cgi->param('invnum') =~ /^(\d+)$/ or die "illegal invnum";
171 invoice( 'session_id' => $session_id,
177 sub customer_order_pkg {
178 my $init_data = signup_info( 'customer_session_id' => $session_id );
179 return $init_data if ( $init_data->{'error'} );
181 my $customer_info = customer_info( 'session_id' => $session_id );
182 return $customer_info if ( $customer_info->{'error'} );
185 ( map { $_ => $init_data->{$_} }
186 qw( part_pkg security_phrase svc_acct_pop ),
192 sub customer_change_pkg {
193 my $init_data = signup_info( 'customer_session_id' => $session_id );
194 return $init_data if ( $init_data->{'error'} );
196 my $customer_info = customer_info( 'session_id' => $session_id );
197 return $customer_info if ( $customer_info->{'error'} );
200 ( map { $_ => $init_data->{$_} }
201 qw( part_pkg security_phrase svc_acct_pop ),
203 ( map { $_ => $cgi->param($_) }
210 sub process_order_pkg {
214 unless ( length($cgi->param('_password')) ) {
215 my $init_data = signup_info( 'customer_session_id' => $session_id );
216 $results = { 'error' => $init_data->{msgcat}{empty_password} };
217 $results = { 'error' => $init_data->{error} } if($init_data->{error});
219 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
220 my $init_data = signup_info( 'customer_session_id' => $session_id );
221 $results = { 'error' => $init_data->{msgcat}{passwords_dont_match} };
222 $results = { 'error' => $init_data->{error} } if($init_data->{error});
223 $cgi->param('_password', '');
224 $cgi->param('_password2', '');
227 $results ||= order_pkg (
228 'session_id' => $session_id,
229 map { $_ => $cgi->param($_) }
230 qw( custnum pkgpart username _password _password2 sec_phrase popnum )
234 if ( $results->{'error'} ) {
235 $action = 'customer_order_pkg';
238 %{customer_order_pkg()},
239 'error' => '<FONT COLOR="#FF0000">'. $results->{'error'}. '</FONT>',
247 sub process_change_pkg {
251 $results ||= change_pkg (
252 'session_id' => $session_id,
253 map { $_ => $cgi->param($_) }
258 if ( $results->{'error'} ) {
259 $action = 'customer_change_pkg';
262 %{customer_change_pkg()},
263 'error' => '<FONT COLOR="#FF0000">'. $results->{'error'}. '</FONT>',
271 sub process_order_recharge {
275 $results ||= order_recharge (
276 'session_id' => $session_id,
277 map { $_ => $cgi->param($_) }
282 if ( $results->{'error'} ) {
283 $action = 'view_usage';
284 if ($results->{'error'} eq '_decline') {
285 $results->{'error'} = "There has been an error processing your account. Please contact customer support."
290 'error' => '<FONT COLOR="#FF0000">'. $results->{'error'}. '</FONT>',
299 payment_info( 'session_id' => $session_id );
302 sub payment_results {
304 use Business::CreditCard;
306 #we should only do basic checking here for DoS attacks and things
307 #that couldn't be constructed by the web form... let process_payment() do
308 #the rest, it gives better error messages
310 $cgi->param('amount') =~ /^\s*(\d+(\.\d{2})?)\s*$/
311 or die "Illegal amount: ". $cgi->param('amount'); #!!!
314 my $payinfo = $cgi->param('payinfo');
316 $payinfo =~ /^(\d{13,16})$/
317 #or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
318 or die "illegal card"; #!!!
321 #or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
322 or die "invalid card"; #!!!
324 if ( $cgi->param('card_type') ) {
325 cardtype($payinfo) eq $cgi->param('card_type')
326 #or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
327 or die "not a ". $cgi->param('card_type');
330 $cgi->param('paycvv') =~ /^\s*(.{0,4})\s*$/ or die "illegal CVV2";
333 $cgi->param('month') =~ /^(\d{2})$/ or die "illegal month";
335 $cgi->param('year') =~ /^(\d{4})$/ or die "illegal year";
338 $cgi->param('payname') =~ /^(.{0,80})$/ or die "illegal payname";
341 $cgi->param('address1') =~ /^(.{0,80})$/ or die "illegal address1";
344 $cgi->param('address2') =~ /^(.{0,80})$/ or die "illegal address2";
347 $cgi->param('city') =~ /^(.{0,80})$/ or die "illegal city";
350 $cgi->param('state') =~ /^(.{2})$/ or die "illegal state";
353 $cgi->param('zip') =~ /^(.{0,10})$/ or die "illegal zip";
357 $save = 1 if $cgi->param('save');
360 $auto = 1 if $cgi->param('auto');
362 $cgi->param('paybatch') =~ /^([\w\-\.]+)$/ or die "illegal paybatch";
366 'session_id' => $session_id,
369 'payinfo' => $payinfo,
373 'payname' => $payname,
374 'address1' => $address1,
375 'address2' => $address2,
381 'paybatch' => $paybatch,
386 sub make_ach_payment {
387 payment_info( 'session_id' => $session_id );
390 sub ach_payment_results {
392 #we should only do basic checking here for DoS attacks and things
393 #that couldn't be constructed by the web form... let process_payment() do
394 #the rest, it gives better error messages
396 $cgi->param('amount') =~ /^\s*(\d+(\.\d{2})?)\s*$/
397 or die "illegal amount"; #!!!
400 my $payinfo1 = $cgi->param('payinfo1');
401 $payinfo1=~ /^(\d+)$/
402 or die "illegal account"; #!!!
405 my $payinfo2 = $cgi->param('payinfo2');
406 $payinfo2=~ /^(\d+)$/
407 or die "illegal ABA/routing code"; #!!!
410 $cgi->param('payname') =~ /^(.{0,80})$/ or die "illegal payname";
413 $cgi->param('paystate') =~ /^(.{0,2})$/ or die "illegal paystate";
416 $cgi->param('paytype') =~ /^(.{0,80})$/ or die "illegal paytype";
419 $cgi->param('ss') =~ /^(.{0,80})$/ or die "illegal ss";
422 $cgi->param('stateid') =~ /^(.{0,80})$/ or die "illegal stateid";
425 $cgi->param('stateid_state') =~ /^(.{0,2})$/ or die "illegal stateid_state";
426 my $stateid_state = $1;
429 $save = 1 if $cgi->param('save');
432 $auto = 1 if $cgi->param('auto');
434 $cgi->param('paybatch') =~ /^([\w\-\.]+)$/ or die "illegal paybatch";
438 'session_id' => $session_id,
441 'payinfo1' => $payinfo1,
442 'payinfo2' => $payinfo2,
445 'payname' => $payname,
446 'paytype' => $paytype,
447 'paystate' => $paystate,
449 'stateid' => $stateid,
450 'stateid_state' => $stateid_state,
453 'paybatch' => $paybatch,
458 sub recharge_prepay {
459 customer_info( 'session_id' => $session_id );
462 sub recharge_results {
464 my $prepaid_cardnum = $cgi->param('prepaid_cardnum');
465 $prepaid_cardnum =~ s/\W//g;
466 $prepaid_cardnum =~ /^(\w*)$/ or die "illegal prepaid card number";
467 $prepaid_cardnum = $1;
469 process_prepay ( 'session_id' => $session_id,
470 'prepaid_cardnum' => $prepaid_cardnum,
475 FS::SelfService::logout( 'session_id' => $session_id );
479 my $result = list_pkgs( 'session_id' => $session_id );
480 die $result->{'error'} if exists $result->{'error'} && $result->{'error'};
486 my $result = part_svc_info(
487 'session_id' => $session_id,
488 map { $_ => $cgi->param($_) } qw( pkgnum svcpart ),
490 die $result->{'error'} if exists $result->{'error'} && $result->{'error'};
492 $result->{'svcdb'} =~ /^svc_(.*)$/
493 #or return { 'error' => 'Unknown svcdb '. $result->{'svcdb'} };
494 or die 'Unknown svcdb '. $result->{'svcdb'};
500 sub process_svc_acct {
502 my $result = provision_acct (
503 'session_id' => $session_id,
504 map { $_ => $cgi->param($_) } qw(
505 pkgnum svcpart username domsvc _password _password2 sec_phrase popnum )
508 if ( exists $result->{'error'} && $result->{'error'} ) {
509 #warn "$result $result->{'error'}";
510 $action = 'provision_svc_acct';
513 %{ part_svc_info( 'session_id' => $session_id,
514 map { $_ => $cgi->param($_) } qw( pkgnum svcpart )
517 'error' => $result->{'error'},
520 #warn "$result $result->{'error'}";
526 sub process_svc_external {
528 'session_id' => $session_id,
529 map { $_ => $cgi->param($_) } qw( pkgnum svcpart )
535 'session_id' => $session_id,
536 'svcnum' => $cgi->param('svcnum'),
542 'session_id' => $session_id,
543 'svcdb' => 'svc_acct',
548 sub view_usage_details {
550 'session_id' => $session_id,
551 'svcnum' => $cgi->param('svcnum'),
552 'beginning' => $cgi->param('beginning') || '',
553 'ending' => $cgi->param('ending') || '',
557 sub change_password {
559 'session_id' => $session_id,
560 'svcdb' => 'svc_acct',
564 sub process_change_password {
566 my $result = myaccount_passwd(
567 'session_id' => $session_id,
568 map { $_ => $cgi->param($_) } qw( svcnum new_password new_password2 )
571 if ( exists $result->{'error'} && $result->{'error'} ) {
573 $action = 'change_password';
576 %{ list_svcs( 'session_id' => $session_id,
577 'svcdb' => 'svc_acct',
580 #'svcnum' => $cgi->param('svcnum'),
581 'error' => $result->{'error'}
599 $fill_in->{'selfurl'} = $cgi->self_url;
600 $fill_in->{'cgi'} = \$cgi;
602 my $template = new Text::Template( TYPE => 'FILE',
603 SOURCE => "$template_dir/$name.html",
604 DELIMITERS => [ '<%=', '%>' ],
606 or die $Text::Template::ERROR;
608 print $cgi->header( '-expires' => 'now' ),
609 $template->fill_in( PACKAGE => 'FS::SelfService::_selfservicecgi',
614 #*FS::SelfService::_selfservicecgi::include = \&Text::Template::fill_in_file;
616 package FS::SelfService::_selfservicecgi;
618 #use FS::SelfService qw(regionselector expselect popselector);
620 use FS::SelfService qw(regionselector popselector domainselector);
622 #false laziness w/agent.cgi
625 my $template = new Text::Template( TYPE => 'FILE',
626 SOURCE => "$main::template_dir/$name.html",
627 DELIMITERS => [ '<%=', '%>' ],
630 or die $Text::Template::ERROR;
632 $template->fill_in( PACKAGE => 'FS::SelfService::_selfservicecgi',