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 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 my $postal = $cgi->param( 'postal_invoicing' );
161 qw( payby payinfo payinfo1 payinfo2 month year payname
162 address1 address2 city county state zip country auto paytype
163 paystate ss stateid stateid_state invoicing_list
165 push @list, 'postal_invoicing' if $postal;
166 unless ( $postal || $cgi->param( 'invoicing_list' ) ) {
167 $action = 'change_pay';
171 'error' => '<FONT COLOR="#FF0000">Postal or email required.</FONT>',
174 _process_change_info( 'change_pay', @list );
179 $cgi->param('invnum') =~ /^(\d+)$/ or die "illegal invnum";
182 invoice( 'session_id' => $session_id,
188 sub customer_order_pkg {
189 my $init_data = signup_info( 'customer_session_id' => $session_id );
190 return $init_data if ( $init_data->{'error'} );
192 my $customer_info = customer_info( 'session_id' => $session_id );
193 return $customer_info if ( $customer_info->{'error'} );
196 ( map { $_ => $init_data->{$_} }
197 qw( part_pkg security_phrase svc_acct_pop ),
203 sub customer_change_pkg {
204 my $init_data = signup_info( 'customer_session_id' => $session_id );
205 return $init_data if ( $init_data->{'error'} );
207 my $customer_info = customer_info( 'session_id' => $session_id );
208 return $customer_info if ( $customer_info->{'error'} );
211 ( map { $_ => $init_data->{$_} }
212 qw( part_pkg security_phrase svc_acct_pop ),
214 ( map { $_ => $cgi->param($_) }
221 sub process_order_pkg {
225 unless ( length($cgi->param('_password')) ) {
226 my $init_data = signup_info( 'customer_session_id' => $session_id );
227 $results = { 'error' => $init_data->{msgcat}{empty_password} };
228 $results = { 'error' => $init_data->{error} } if($init_data->{error});
230 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
231 my $init_data = signup_info( 'customer_session_id' => $session_id );
232 $results = { 'error' => $init_data->{msgcat}{passwords_dont_match} };
233 $results = { 'error' => $init_data->{error} } if($init_data->{error});
234 $cgi->param('_password', '');
235 $cgi->param('_password2', '');
238 $results ||= order_pkg (
239 'session_id' => $session_id,
240 map { $_ => $cgi->param($_) }
241 qw( custnum pkgpart username _password _password2 sec_phrase popnum )
245 if ( $results->{'error'} ) {
246 $action = 'customer_order_pkg';
249 %{customer_order_pkg()},
250 'error' => '<FONT COLOR="#FF0000">'. $results->{'error'}. '</FONT>',
258 sub process_change_pkg {
262 $results ||= change_pkg (
263 'session_id' => $session_id,
264 map { $_ => $cgi->param($_) }
269 if ( $results->{'error'} ) {
270 $action = 'customer_change_pkg';
273 %{customer_change_pkg()},
274 'error' => '<FONT COLOR="#FF0000">'. $results->{'error'}. '</FONT>',
282 sub process_order_recharge {
286 $results ||= order_recharge (
287 'session_id' => $session_id,
288 map { $_ => $cgi->param($_) }
293 if ( $results->{'error'} ) {
294 $action = 'view_usage';
295 if ($results->{'error'} eq '_decline') {
296 $results->{'error'} = "There has been an error processing your account. Please contact customer support."
301 'error' => '<FONT COLOR="#FF0000">'. $results->{'error'}. '</FONT>',
310 payment_info( 'session_id' => $session_id );
313 sub payment_results {
315 use Business::CreditCard;
317 #we should only do basic checking here for DoS attacks and things
318 #that couldn't be constructed by the web form... let process_payment() do
319 #the rest, it gives better error messages
321 $cgi->param('amount') =~ /^\s*(\d+(\.\d{2})?)\s*$/
322 or die "Illegal amount: ". $cgi->param('amount'); #!!!
325 my $payinfo = $cgi->param('payinfo');
327 $payinfo =~ /^(\d{13,16})$/
328 #or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
329 or die "illegal card"; #!!!
332 #or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
333 or die "invalid card"; #!!!
335 if ( $cgi->param('card_type') ) {
336 cardtype($payinfo) eq $cgi->param('card_type')
337 #or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
338 or die "not a ". $cgi->param('card_type');
341 $cgi->param('paycvv') =~ /^\s*(.{0,4})\s*$/ or die "illegal CVV2";
344 $cgi->param('month') =~ /^(\d{2})$/ or die "illegal month";
346 $cgi->param('year') =~ /^(\d{4})$/ or die "illegal year";
349 $cgi->param('payname') =~ /^(.{0,80})$/ or die "illegal payname";
352 $cgi->param('address1') =~ /^(.{0,80})$/ or die "illegal address1";
355 $cgi->param('address2') =~ /^(.{0,80})$/ or die "illegal address2";
358 $cgi->param('city') =~ /^(.{0,80})$/ or die "illegal city";
361 $cgi->param('state') =~ /^(.{2})$/ or die "illegal state";
364 $cgi->param('zip') =~ /^(.{0,10})$/ or die "illegal zip";
368 $save = 1 if $cgi->param('save');
371 $auto = 1 if $cgi->param('auto');
373 $cgi->param('paybatch') =~ /^([\w\-\.]+)$/ or die "illegal paybatch";
377 'session_id' => $session_id,
380 'payinfo' => $payinfo,
384 'payname' => $payname,
385 'address1' => $address1,
386 'address2' => $address2,
392 'paybatch' => $paybatch,
397 sub make_ach_payment {
398 payment_info( 'session_id' => $session_id );
401 sub ach_payment_results {
403 #we should only do basic checking here for DoS attacks and things
404 #that couldn't be constructed by the web form... let process_payment() do
405 #the rest, it gives better error messages
407 $cgi->param('amount') =~ /^\s*(\d+(\.\d{2})?)\s*$/
408 or die "illegal amount"; #!!!
411 my $payinfo1 = $cgi->param('payinfo1');
412 $payinfo1=~ /^(\d+)$/
413 or die "illegal account"; #!!!
416 my $payinfo2 = $cgi->param('payinfo2');
417 $payinfo2=~ /^(\d+)$/
418 or die "illegal ABA/routing code"; #!!!
421 $cgi->param('payname') =~ /^(.{0,80})$/ or die "illegal payname";
424 $cgi->param('paystate') =~ /^(.{0,2})$/ or die "illegal paystate";
427 $cgi->param('paytype') =~ /^(.{0,80})$/ or die "illegal paytype";
430 $cgi->param('ss') =~ /^(.{0,80})$/ or die "illegal ss";
433 $cgi->param('stateid') =~ /^(.{0,80})$/ or die "illegal stateid";
436 $cgi->param('stateid_state') =~ /^(.{0,2})$/ or die "illegal stateid_state";
437 my $stateid_state = $1;
440 $save = 1 if $cgi->param('save');
443 $auto = 1 if $cgi->param('auto');
445 $cgi->param('paybatch') =~ /^([\w\-\.]+)$/ or die "illegal paybatch";
449 'session_id' => $session_id,
452 'payinfo1' => $payinfo1,
453 'payinfo2' => $payinfo2,
456 'payname' => $payname,
457 'paytype' => $paytype,
458 'paystate' => $paystate,
460 'stateid' => $stateid,
461 'stateid_state' => $stateid_state,
464 'paybatch' => $paybatch,
469 sub recharge_prepay {
470 customer_info( 'session_id' => $session_id );
473 sub recharge_results {
475 my $prepaid_cardnum = $cgi->param('prepaid_cardnum');
476 $prepaid_cardnum =~ s/\W//g;
477 $prepaid_cardnum =~ /^(\w*)$/ or die "illegal prepaid card number";
478 $prepaid_cardnum = $1;
480 process_prepay ( 'session_id' => $session_id,
481 'prepaid_cardnum' => $prepaid_cardnum,
486 FS::SelfService::logout( 'session_id' => $session_id );
490 my $result = list_pkgs( 'session_id' => $session_id );
491 die $result->{'error'} if exists $result->{'error'} && $result->{'error'};
497 my $result = part_svc_info(
498 'session_id' => $session_id,
499 map { $_ => $cgi->param($_) } qw( pkgnum svcpart ),
501 die $result->{'error'} if exists $result->{'error'} && $result->{'error'};
503 $result->{'svcdb'} =~ /^svc_(.*)$/
504 #or return { 'error' => 'Unknown svcdb '. $result->{'svcdb'} };
505 or die 'Unknown svcdb '. $result->{'svcdb'};
511 sub process_svc_acct {
513 my $result = provision_acct (
514 'session_id' => $session_id,
515 map { $_ => $cgi->param($_) } qw(
516 pkgnum svcpart username domsvc _password _password2 sec_phrase popnum )
519 if ( exists $result->{'error'} && $result->{'error'} ) {
520 #warn "$result $result->{'error'}";
521 $action = 'provision_svc_acct';
524 %{ part_svc_info( 'session_id' => $session_id,
525 map { $_ => $cgi->param($_) } qw( pkgnum svcpart )
528 'error' => $result->{'error'},
531 #warn "$result $result->{'error'}";
537 sub process_svc_external {
539 'session_id' => $session_id,
540 map { $_ => $cgi->param($_) } qw( pkgnum svcpart )
546 'session_id' => $session_id,
547 'svcnum' => $cgi->param('svcnum'),
553 'session_id' => $session_id,
554 'svcdb' => 'svc_acct',
559 sub view_usage_details {
561 'session_id' => $session_id,
562 'svcnum' => $cgi->param('svcnum'),
563 'beginning' => $cgi->param('beginning') || '',
564 'ending' => $cgi->param('ending') || '',
568 sub change_password {
570 'session_id' => $session_id,
571 'svcdb' => 'svc_acct',
575 sub process_change_password {
577 my $result = myaccount_passwd(
578 'session_id' => $session_id,
579 map { $_ => $cgi->param($_) } qw( svcnum new_password new_password2 )
582 if ( exists $result->{'error'} && $result->{'error'} ) {
584 $action = 'change_password';
587 %{ list_svcs( 'session_id' => $session_id,
588 'svcdb' => 'svc_acct',
591 #'svcnum' => $cgi->param('svcnum'),
592 'error' => $result->{'error'}
610 $fill_in->{'selfurl'} = $cgi->self_url;
611 $fill_in->{'cgi'} = \$cgi;
613 my $template = new Text::Template( TYPE => 'FILE',
614 SOURCE => "$template_dir/$name.html",
615 DELIMITERS => [ '<%=', '%>' ],
617 or die $Text::Template::ERROR;
619 print $cgi->header( '-expires' => 'now' ),
620 $template->fill_in( PACKAGE => 'FS::SelfService::_selfservicecgi',
625 #*FS::SelfService::_selfservicecgi::include = \&Text::Template::fill_in_file;
627 package FS::SelfService::_selfservicecgi;
629 #use FS::SelfService qw(regionselector expselect popselector);
631 use FS::SelfService qw(regionselector popselector domainselector);
633 #false laziness w/agent.cgi
636 my $template = new Text::Template( TYPE => 'FILE',
637 SOURCE => "$main::template_dir/$name.html",
638 DELIMITERS => [ '<%=', '%>' ],
641 or die $Text::Template::ERROR;
643 $template->fill_in( PACKAGE => 'FS::SelfService::_selfservicecgi',