3 # $Id: signup.cgi,v 1.29 2002-05-30 22:45:20 ivan Exp $
6 use vars qw( @payby $cgi $locales $packages $pops $init_data $error
7 $last $first $ss $company $address1 $address2 $city $state $county
8 $country $zip $daytime $night $fax $invoicing_list $payby $payinfo
9 $paydate $payname $referral_custnum
10 $pkgpart $username $password $password2 $sec_phrase $popnum
12 $ieak_file $ieak_template $cck_file $cck_template
13 $signup_html $signup_template
14 $success_html $success_template
15 $decline_html $decline_template
20 use subs qw( print_form print_okay print_decline
21 signup_default success_default decline_default
24 #use CGI::Carp qw(fatalsToBrowser);
26 use Business::CreditCard;
27 use HTTP::Headers::UserAgent 2.00;
28 use FS::SignupClient 0.03 qw( signup_info new_customer );
30 #acceptable payment methods
32 #@payby = qw( CARD BILL COMP );
33 #@payby = qw( CARD BILL );
35 @payby = qw( CARD PREPAY );
37 $ieak_file = '/usr/local/freeside/ieak.template';
38 $cck_file = '/usr/local/freeside/cck.template';
39 $signup_html = -e 'signup.html'
41 : '/usr/local/freeside/signup.html';
42 $success_html = -e 'success.html'
44 : '/usr/local/freeside/success.html';
45 $decline_html = -e 'decline.html'
47 : '/usr/local/freeside/decline.html';
50 if ( -e $ieak_file ) {
51 my $ieak_txt = Text::Template::_load_text($ieak_file)
52 or die $Text::Template::ERROR;
53 $ieak_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
55 $ieak_txt =~ s/\r//g; # don't double \r on old templates
56 $ieak_txt =~ s/\n/\r\n/g;
57 $ieak_template = new Text::Template ( TYPE => 'STRING', SOURCE => $ieak_txt )
58 or die $Text::Template::ERROR;
64 my $cck_txt = Text::Template::_load_text($cck_file)
65 or die $Text::Template::ERROR;
66 $cck_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
68 $cck_template = new Text::Template ( TYPE => 'STRING', SOURCE => $cck_txt )
69 or die $Text::Template::ERROR;
75 if ( -e $signup_html ) {
76 my $signup_txt = Text::Template::_load_text($signup_html)
77 or die $Text::Template::ERROR;
78 $signup_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
80 $signup_template = new Text::Template ( TYPE => 'STRING',
81 SOURCE => $signup_txt,
82 DELIMITERS => [ '<%=', '%>' ]
84 or die $Text::Template::ERROR;
86 /<\s*INPUT TYPE="?hidden"?\s+NAME="?agentnum"?\s+VALUE="?(\d+)"?\s*>/si
91 $signup_template = new Text::Template ( TYPE => 'STRING',
92 SOURCE => &signup_default,
93 DELIMITERS => [ '<%=', '%>' ]
95 or die $Text::Template::ERROR;
98 if ( -e $success_html ) {
99 my $success_txt = Text::Template::_load_text($success_html)
100 or die $Text::Template::ERROR;
101 $success_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
103 $success_template = new Text::Template ( TYPE => 'STRING',
104 SOURCE => $success_txt,
105 DELIMITERS => [ '<%=', '%>' ],
107 or die $Text::Template::ERROR;
109 $success_template = new Text::Template ( TYPE => 'STRING',
110 SOURCE => &success_default,
111 DELIMITERS => [ '<%=', '%>' ],
113 or die $Text::Template::ERROR;
116 if ( -e $decline_html ) {
117 my $decline_txt = Text::Template::_load_text($decline_html)
118 or die $Text::Template::ERROR;
119 $decline_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
121 $decline_template = new Text::Template ( TYPE => 'STRING',
122 SOURCE => $decline_txt,
123 DELIMITERS => [ '<%=', '%>' ],
125 or die $Text::Template::ERROR;
127 $decline_template = new Text::Template ( TYPE => 'STRING',
128 SOURCE => &decline_default,
129 DELIMITERS => [ '<%=', '%>' ],
131 or die $Text::Template::ERROR;
135 ( $locales, $packages, $pops, $init_data ) = signup_info();
136 @payby = @{$init_data->{'payby'}} if @{$init_data->{'payby'}};
137 $packages = $init_data->{agentnum2part_pkg}{$agentnum} if $agentnum;
141 if ( defined $cgi->param('magic') ) {
142 if ( $cgi->param('magic') eq 'process' ) {
144 $cgi->param('state') =~ /^(\w*)( \(([\w ]+)\))? ?\/ ?(\w+)$/
145 or die "Oops, illegal \"state\" param: ". $cgi->param('state');
150 $payby = $cgi->param('payby');
151 $payinfo = $cgi->param( $payby. '_payinfo' );
153 $cgi->param( $payby. '_month' ). '-'. $cgi->param( $payby. '_year' );
154 $payname = $cgi->param( $payby. '_payname' );
156 if ( $invoicing_list = $cgi->param('invoicing_list') ) {
157 $invoicing_list .= ', POST' if $cgi->param('invoicing_list_POST');
159 $invoicing_list = 'POST';
164 $last = $cgi->param('last');
165 $first = $cgi->param('first');
166 $ss = $cgi->param('ss');
167 $company = $cgi->param('company');
168 $address1 = $cgi->param('address1');
169 $address2 = $cgi->param('address2');
170 $city = $cgi->param('city');
173 $zip = $cgi->param('zip');
175 $daytime = $cgi->param('daytime');
176 $night = $cgi->param('night');
177 $fax = $cgi->param('fax');
183 $referral_custnum = $cgi->param('ref');
184 $pkgpart = $cgi->param('pkgpart');
185 $username = $cgi->param('username');
186 $sec_phrase = $cgi->param('sec_phrase');
187 $password = $cgi->param('_password');
188 $popnum = $cgi->param('popnum');
189 #$agentnum, # = $cgi->param('agentnum'),
191 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
192 $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
196 $password2 = $cgi->param('_password2');
198 if ( $payby eq 'CARD' && $cgi->param('CARD_type') ) {
201 $payinfo =~ /^(\d{13,16})$/
202 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
205 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
206 cardtype($payinfo) eq $cgi->param('CARD_type')
207 or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
210 $error ||= new_customer ( {
214 'company' => $company,
215 'address1' => $address1,
216 'address2' => $address2,
221 'country' => $country,
222 'daytime' => $daytime,
226 'payinfo' => $payinfo,
227 'paydate' => $paydate,
228 'payname' => $payname,
229 'invoicing_list' => $invoicing_list,
230 'referral_custnum' => $referral_custnum,
231 'pkgpart' => $pkgpart,
232 'username' => $username,
233 'sec_phrase' => $sec_phrase,
234 '_password' => $password,
236 'agentnum' => $agentnum,
241 if ( $error eq '_decline' ) {
250 die "unrecognized magic: ". $cgi->param('magic');
268 $invoicing_list = '';
279 $referral_custnum = $cgi->param('ref') || '';
286 $self_url = $cgi->self_url;
288 $error = "Error: $error" if $error;
290 print $cgi->header( '-expires' => 'now' ),
291 $signup_template->fill_in();
296 print $cgi->header( '-expires' => 'now' ),
297 $decline_template->fill_in();
301 my $user_agent = new HTTP::Headers::UserAgent $ENV{HTTP_USER_AGENT};
303 $cgi->param('username') =~ /^(.+)$/
304 or die "fatal: invalid username got past FS::SignupClient::new_customer";
306 $cgi->param('_password') =~ /^(.+)$/
307 or die "fatal: invalid password got past FS::SignupClient::new_customer";
309 ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
310 or die "fatal: invalid email_name got past FS::SignupClient::new_customer";
311 $email_name = $1; #global for template
313 my $pop = pop_info($cgi->param('popnum'));
314 #or die "fatal: invalid popnum got past FS::SignupClient::new_customer";
316 ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
318 ( $ac, $exch, $loc ) = ( '', '', ''); #presumably you're not using them.
322 $pkg = ( grep { $_->{'pkgpart'} eq $pkgpart } @$packages )[0]->{'pkg'};
325 && $user_agent->platform eq 'ia32'
326 && $user_agent->os =~ /^win/
327 && ($user_agent->browser)[0] eq 'IE'
329 { #send an IEAK config
330 print $cgi->header('application/x-Internet-signup'),
331 $ieak_template->fill_in();
332 } elsif ( $cck_template
333 && $user_agent->platform eq 'ia32'
334 && $user_agent->os =~ /^win/
335 && ($user_agent->browser)[0] eq 'Netscape'
337 { #send a Netscape config
338 my $cck_data = $cck_template->fill_in();
339 print $cgi->header('application/x-netscape-autoconfigure-dialer-v2'),
342 pack("N", length($1)). $1. pack("N", length($2)). $2;
343 } split(/\n/, $cck_data);
345 } else { #send a simple confirmation
346 print $cgi->header( '-expires' => 'now' ),
347 $success_template->fill_in();
354 foreach $pop ( @{$pops} ) {
355 if ( $pop->{'popnum'} == $popnum ) { return $pop; }
360 #horrible false laziness with FS/FS/svc_acct_pop.pm::popselector
362 my( $popnum, $state ) = @_;
364 return '<INPUT TYPE="hidden" NAME="popnum" VALUE="">' unless @$pops;
365 return $pops->[0]{city}. ', '. $pops->[0]{state}.
366 ' ('. $pops->[0]{ac}. ')/'. $pops->[0]{exch}.
367 '<INPUT TYPE="hidden" NAME="popnum" VALUE="'. $pops->[0]{popnum}. '">'
368 if scalar(@$pops) == 1;
371 push @{ $pop{$_->{state}} }, $_ foreach @$pops;
375 function opt(what,href,text) {
376 var optionName = new Option(text, href, false, false)
377 var length = what.length;
378 what.options[length] = optionName;
381 function popstate_changed(what) {
382 state = what.options[what.selectedIndex].text;
383 for (var i = what.form.popnum.length;i > 0;i--)
384 what.form.popnum.options[i] = null;
385 what.form.popnum.options[0] = new Option("", "", false, true);
388 foreach my $popstate ( sort { $a cmp $b } keys %pop ) {
389 $text .= "\nif ( state == \"$popstate\" ) {\n";
391 foreach my $pop ( @{$pop{$popstate}}) {
392 my $o_popnum = $pop->{popnum};
393 my $poptext = $pop->{city}. ', '. $pop->{state}.
394 ' ('. $pop->{ac}. ')/'. $pop->{exch};
396 $text .= "opt(what.form.popnum, \"$o_popnum\", \"$poptext\");\n"
401 $text .= "}\n</SCRIPT>\n";
404 qq!<SELECT NAME="popstate" SIZE=1 onChange="popstate_changed(this)">!.
406 $text .= "<OPTION>$_" foreach sort { $a cmp $b } keys %pop;
407 $text .= '</SELECT>'; #callback? return 3 html pieces? #'</TD><TD>';
409 $text .= qq!<SELECT NAME="popnum" SIZE=1><OPTION> !;
410 foreach my $pop ( @$pops ) {
411 $text .= qq!<OPTION VALUE="!. $pop->{popnum}. '"'.
412 ( ( $popnum && $pop->{popnum} == $popnum ) ? ' SELECTED' : '' ). ">".
413 $pop->{city}. ', '. $pop->{state}.
414 ' ('. $pop->{ac}. ')/'. $pop->{exch};
416 $text .= '</SELECT>';
423 my $date = shift || '';
424 my( $m, $y ) = ( 0, 0 );
425 if ( $date =~ /^(\d{4})-(\d{2})-\d{2}$/ ) { #PostgreSQL date format
426 ( $m, $y ) = ( $2, $1 );
427 } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
428 ( $m, $y ) = ( $1, $3 );
430 my $return = qq!<SELECT NAME="$prefix!. qq!_month" SIZE="1">!;
432 $return .= "<OPTION";
433 $return .= " SELECTED" if $_ == $m;
436 $return .= qq!</SELECT>/<SELECT NAME="$prefix!. qq!_year" SIZE="1">!;
437 for ( 2001 .. 2037 ) {
438 $return .= "<OPTION";
439 $return .= " SELECTED" if $_ == $y;
442 $return .= "</SELECT>";
447 sub success_default { #html to use if you don't specify a success file
449 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
450 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
451 Thanks for signing up!
453 Signup information for <%= $email_name %>:
455 Username: <%= $username %><BR>
456 Password: <%= $password %><BR>
457 Access number: (<%= $ac %>) / $exch - $local<BR>
458 Package: <%= $pkg %><BR>
463 sub decline_default { #html to use if there is a decline
465 <HTML><HEAD><TITLE>Processing error</TITLE></HEAD>
466 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Processing error</FONT><BR><BR>
467 There has been an error processing your account. Please contact customer
473 sub signup_default { #html to use if you don't specify a template file
475 <HTML><HEAD><TITLE>ISP Signup form</TITLE></HEAD>
476 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>ISP Signup form</FONT><BR><BR>
477 <FONT SIZE="+1" COLOR="#ff0000"><%= $error %></FONT>
478 <FORM ACTION="<%= $self_url %>" METHOD=POST>
479 <INPUT TYPE="hidden" NAME="magic" VALUE="process">
480 <INPUT TYPE="hidden" NAME="ref" VALUE="<%= $referral_custnum %>">
481 <INPUT TYPE="hidden" NAME="ss" VALUE="">
483 <TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=0 WIDTH="100%">
485 <TH ALIGN="right"><font color="#ff0000">*</font>Contact name<BR>(last, first)</TH>
486 <TD COLSPAN=5><INPUT TYPE="text" NAME="last" VALUE="<%= $last %>">,
487 <INPUT TYPE="text" NAME="first" VALUE="<%= $first %>"></TD>
490 <TD ALIGN="right">Company</TD>
491 <TD COLSPAN=5><INPUT TYPE="text" NAME="company" SIZE=70 VALUE="<%= $company %>"></TD>
494 <TH ALIGN="right"><font color="#ff0000">*</font>Address</TH>
495 <TD COLSPAN=5><INPUT TYPE="text" NAME="address1" SIZE=70 VALUE="<%= $address1 %>"></TD>
498 <TD ALIGN="right"> </TD>
499 <TD COLSPAN=5><INPUT TYPE="text" NAME="address2" SIZE=70 VALUE="<%= $address2 %>"></TD>
502 <TH ALIGN="right"><font color="#ff0000">*</font>City</TH>
503 <TD><INPUT TYPE="text" NAME="city" VALUE="<%= $city %>"></TD>
504 <TH ALIGN="right"><font color="#ff0000">*</font>State/Country</TH>
505 <TD><SELECT NAME="state" SIZE="1">
508 foreach ( @{$locales} ) {
510 $OUT .= ' SELECTED' if ( $state eq $_->{'state'}
511 && $county eq $_->{'county'}
512 && $country eq $_->{'country'}
514 $OUT .= '>'. $_->{'state'};
515 $OUT .= ' ('. $_->{'county'}. ')' if $_->{'county'};
516 $OUT .= ' / '. $_->{'country'};
521 <TH><font color="#ff0000">*</font>Zip</TH>
522 <TD><INPUT TYPE="text" NAME="zip" SIZE=10 VALUE="<%= $zip %>"></TD>
525 <TD ALIGN="right">Day Phone</TD>
526 <TD COLSPAN=5><INPUT TYPE="text" NAME="daytime" VALUE="<%= $daytime %>" SIZE=18></TD>
529 <TD ALIGN="right">Night Phone</TD>
530 <TD COLSPAN=5><INPUT TYPE="text" NAME="night" VALUE="<%= $night %>" SIZE=18></TD>
533 <TD ALIGN="right">Fax</TD>
534 <TD COLSPAN=5><INPUT TYPE="text" NAME="fax" VALUE="<%= $fax %>" SIZE=12></TD>
536 </TABLE><font color="#ff0000">*</font> required fields<BR>
537 <BR>Billing information<TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=0 WIDTH="100%">
541 $OUT .= '<INPUT TYPE="checkbox" NAME="invoicing_list_POST" VALUE="POST"';
542 my @invoicing_list = split(', ', $invoicing_list );
544 if ! @invoicing_list || grep { $_ eq 'POST' } @invoicing_list;
550 <TR><TD>Email invoice <INPUT TYPE="text" NAME="invoicing_list" VALUE="<%= join(', ', grep { $_ ne 'POST' } split(', ', $invoicing_list ) ) %>">
552 <%= scalar(@payby) > 1 ? '<TR><TD>Billing type</TD></TR>' : '' %>
554 <TABLE BGCOLOR="#c0c0c0" BORDER=1 WIDTH="100%">
559 my $cardselect = '<SELECT NAME="CARD_type"><OPTION></OPTION>';
561 'VISA' => 'VISA card',
562 'MasterCard' => 'MasterCard',
563 'Discover' => 'Discover card',
564 'American Express' => 'American Express card',
566 foreach ( keys %types ) {
567 $selected = $cgi->param('CARD_type') eq $types{$_} ? 'SELECTED' : '';
568 $cardselect .= qq!<OPTION $selected VALUE="$types{$_}">$_</OPTION>!;
570 $cardselect .= '</SELECT>';
573 'CARD' => qq!Credit card<BR><font color="#ff0000">*</font>$cardselect<INPUT TYPE="text" NAME="CARD_payinfo" VALUE="" MAXLENGTH=19><BR><font color="#ff0000">*</font>Exp !. expselect("CARD"). qq!<BR><font color="#ff0000">*</font>Name on card<BR><INPUT TYPE="text" NAME="CARD_payname" VALUE="">!,
574 'BILL' => qq!Billing<BR>P.O. <INPUT TYPE="text" NAME="BILL_payinfo" VALUE=""><BR><font color="#ff0000">*</font>Exp !. expselect("BILL", "12-2037"). qq!<BR><font color="#ff0000">*</font>Attention<BR><INPUT TYPE="text" NAME="BILL_payname" VALUE="Accounts Payable">!,
575 'COMP' => qq!Complimentary<BR><font color="#ff0000">*</font>Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE=""><BR><font color="#ff0000">*</font>Exp !. expselect("COMP"),
576 'PREPAY' => qq!Prepaid card<BR><font color="#ff0000">*</font><INPUT TYPE="text" NAME="PREPAY_payinfo" VALUE="" MAXLENGTH=80>!,
580 'CARD' => qq!Credit card<BR><font color="#ff0000">*</font>$cardselect<INPUT TYPE="text" NAME="CARD_payinfo" VALUE="$payinfo" MAXLENGTH=19><BR><font color="#ff0000">*</font>Exp !. expselect("CARD", $paydate). qq!<BR><font color="#ff0000">*</font>Name on card<BR><INPUT TYPE="text" NAME="CARD_payname" VALUE="$payname">!,
581 'BILL' => qq!Billing<BR>P.O. <INPUT TYPE="text" NAME="BILL_payinfo" VALUE="$payinfo"><BR><font color="#ff0000">*</font>Exp !. expselect("BILL", $paydate). qq!<BR><font color="#ff0000">*</font>Attention<BR><INPUT TYPE="text" NAME="BILL_payname" VALUE="$payname">!,
582 'COMP' => qq!Complimentary<BR><font color="#ff0000">*</font>Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE="$payinfo"><BR><font color="#ff0000">*</font>Exp !. expselect("COMP", $paydate),
583 'PREPAY' => qq!Prepaid card<BR><font color="#ff0000">*</font><INPUT TYPE="text" NAME="PREPAY_payinfo" VALUE="$payinfo" MAXLENGTH=80>!,
587 if ( scalar(@payby) == 1) {
588 $OUT .= '<TD VALIGN=TOP>'.
589 qq!<INPUT TYPE="hidden" NAME="payby" VALUE="$_">!.
590 "$paybychecked{$_}</TD>";
592 $OUT .= qq!<TD VALIGN=TOP><INPUT TYPE="radio" NAME="payby" VALUE="$_"!;
594 $OUT .= qq! CHECKED> $paybychecked{$_}</TD>!;
596 $OUT .= qq!> $payby{$_}</TD>!;
603 </TR></TABLE><font color="#ff0000">*</font> required fields for each billing type
604 <BR><BR>First package
605 <TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=0 WIDTH="100%">
607 <TD COLSPAN=2><SELECT NAME="pkgpart"><OPTION VALUE="">(none)
610 foreach my $package ( @{$packages} ) {
611 $OUT .= '<OPTION VALUE="'. $package->{'pkgpart'}. '"';
612 $OUT .= ' SELECTED' if $pkgpart && $package->{'pkgpart'} == $pkgpart;
613 $OUT .= '>'. $package->{'pkg'};
620 <TD ALIGN="right">Username</TD>
621 <TD><INPUT TYPE="text" NAME="username" VALUE="<%= $username %>"></TD>
624 <TD ALIGN="right">Password</TD>
625 <TD><INPUT TYPE="password" NAME="_password" VALUE="<%= $password %>"></TD>
628 <TD ALIGN="right">Re-enter Password</TD>
629 <TD><INPUT TYPE="password" NAME="_password2" VALUE="<%= $password2 %>"></TD>
632 if ( $init_data->{'security_phrase'} ) {
635 <TD ALIGN="right">Security Phrase</TD>
636 <TD><INPUT TYPE="text" NAME="sec_phrase" VALUE="$sec_phrase">
641 $OUT .= '<INPUT TYPE="hidden" NAME="sec_phrase" VALUE="">';
645 if ( scalar(@$pops) ) {
646 $OUT .= '<TR><TD ALIGN="right">Access number</TD><TD>'.
647 popselector($popnum). '</TD></TR>';
649 $OUT .= popselector($popnum);
653 <BR><BR><INPUT TYPE="submit" VALUE="Signup">
654 </FORM></BODY></HTML>