3 # $Id: signup.cgi,v 1.21 2002-04-16 00:02:26 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 $success_html $success_template
17 use subs qw( print_form print_okay expselect signup_default success_default );
19 #use CGI::Carp qw(fatalsToBrowser);
21 use Business::CreditCard;
22 use HTTP::Headers::UserAgent 2.00;
23 use FS::SignupClient 0.03 qw( signup_info new_customer );
25 #acceptable payment methods
27 #@payby = qw( CARD BILL COMP );
28 #@payby = qw( CARD BILL );
30 @payby = qw( CARD PREPAY );
32 $ieak_file = '/usr/local/freeside/ieak.template';
33 $cck_file = '/usr/local/freeside/cck.template';
34 $signup_html = '/usr/local/freeside/signup.html';
35 $success_html = '/usr/local/freeside/success.html';
37 if ( -e $ieak_file ) {
38 my $ieak_txt = Text::Template::_load_text($ieak_file)
39 or die $Text::Template::ERROR;
40 $ieak_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
42 $ieak_template = new Text::Template ( TYPE => 'STRING', SOURCE => $ieak_txt )
43 or die $Text::Template::ERROR;
49 my $cck_txt = Text::Template::_load_text($cck_file)
50 or die $Text::Template::ERROR;
51 $cck_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
53 $cck_template = new Text::Template ( TYPE => 'STRING', SOURCE => $cck_txt )
54 or die $Text::Template::ERROR;
59 if ( -e $signup_html ) {
60 my $signup_txt = Text::Template::_load_text($signup_html)
61 or die $Text::Template::ERROR;
62 $signup_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
64 $signup_template = new Text::Template ( TYPE => 'STRING',
65 SOURCE => $signup_txt,
66 DELIMITERS => [ '<%=', '%>' ]
68 or die $Text::Template::ERROR;
70 $signup_template = new Text::Template ( TYPE => 'STRING',
71 SOURCE => &signup_default,
72 DELIMITERS => [ '<%=', '%>' ]
74 or die $Text::Template::ERROR;
77 if ( -e $success_html ) {
78 my $success_txt = Text::Template::_load_text($success_html)
79 or die $Text::Template::ERROR;
80 $success_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
82 $success_template = new Text::Template ( TYPE => 'STRING',
83 SOURCE => $success_txt,
84 DELIMITERS => [ '<%=', '%>' ],
86 or die $Text::Template::ERROR;
88 $success_template = new Text::Template ( TYPE => 'STRING',
89 SOURCE => &success_default,
90 DELIMITERS => [ '<%=', '%>' ],
92 or die $Text::Template::ERROR;
95 ( $locales, $packages, $pops, $init_data ) = signup_info();
96 @payby = @{$init_data->{'payby'}} if @{$init_data->{'payby'}};
100 if ( defined $cgi->param('magic') ) {
101 if ( $cgi->param('magic') eq 'process' ) {
103 $cgi->param('state') =~ /^(\w*)( \(([\w ]+)\))? ?\/ ?(\w+)$/
104 or die "Oops, illegal \"state\" param: ". $cgi->param('state');
109 $payby = $cgi->param('payby');
110 $payinfo = $cgi->param( $payby. '_payinfo' );
112 $cgi->param( $payby. '_month' ). '-'. $cgi->param( $payby. '_year' );
113 $payname = $cgi->param( $payby. '_payname' );
115 if ( $invoicing_list = $cgi->param('invoicing_list') ) {
116 $invoicing_list .= ', POST' if $cgi->param('invoicing_list_POST');
118 $invoicing_list = 'POST';
123 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
124 $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
128 $password2 = $cgi->param('_password2');
130 if ( $payby eq 'CARD' && $cgi->param('CARD_type') ) {
133 $payinfo =~ /^(\d{13,16})$/
134 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
137 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
138 cardtype($payinfo) eq $cgi->param('CARD_type')
139 or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
142 $error ||= new_customer ( {
143 'last' => $last = $cgi->param('last'),
144 'first' => $first = $cgi->param('first'),
145 'ss' => $ss = $cgi->param('ss'),
146 'company' => $company = $cgi->param('company'),
147 'address1' => $address1 = $cgi->param('address1'),
148 'address2' => $address2 = $cgi->param('address2'),
149 'city' => $city = $cgi->param('city'),
152 'zip' => $zip = $cgi->param('zip'),
153 'country' => $country,
154 'daytime' => $daytime = $cgi->param('daytime'),
155 'night' => $night = $cgi->param('night'),
156 'fax' => $fax = $cgi->param('fax'),
158 'payinfo' => $payinfo,
159 'paydate' => $paydate,
160 'payname' => $payname,
161 'invoicing_list' => $invoicing_list,
162 'referral_custnum' => $referral_custnum = $cgi->param('ref'),
163 'pkgpart' => $pkgpart = $cgi->param('pkgpart'),
164 'username' => $username = $cgi->param('username'),
165 'sec_phrase' => $sec_phrase = $cgi->param('sec_phrase'),
166 '_password' => $password = $cgi->param('_password'),
167 'popnum' => $popnum = $cgi->param('popnum'),
168 'agentnum' => $agentnum = $cgi->param('agentnum'),
180 die "unrecognized magic: ". $cgi->param('magic');
198 $invoicing_list = '';
209 $referral_custnum = $cgi->param('ref') || '';
216 $self_url = $cgi->self_url;
218 $error = "Error: $error" if $error;
220 print $cgi->header( '-expires' => 'now' ),
221 $signup_template->fill_in();
226 my $user_agent = new HTTP::Headers::UserAgent $ENV{HTTP_USER_AGENT};
228 $cgi->param('username') =~ /^(.+)$/
229 or die "fatal: invalid username got past FS::SignupClient::new_customer";
231 $cgi->param('_password') =~ /^(.+)$/
232 or die "fatal: invalid password got past FS::SignupClient::new_customer";
234 ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
235 or die "fatal: invalid email_name got past FS::SignupClient::new_customer";
238 my $pop = pop_info($cgi->param('popnum'))
239 or die "fatal: invalid popnum got past FS::SignupClient::new_customer";
240 ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
242 my $pkg = ( grep { $_->{'pkgpart'} eq $pkgpart } @$packages )[0]->{'pkg'};
245 && $user_agent->platform eq 'ia32'
246 && $user_agent->os =~ /^win/
247 && ($user_agent->browser)[0] eq 'IE'
249 { #send an IEAK config
250 print $cgi->header('application/x-Internet-signup'),
251 $ieak_template->fill_in();
252 } elsif ( $cck_template
253 && $user_agent->platform eq 'ia32'
254 && $user_agent->os =~ /^win/
255 && ($user_agent->browser)[0] eq 'Netscape'
257 { #send a Netscape config
258 my $cck_data = $cck_template->fill_in();
259 print $cgi->header('application/x-netscape-autoconfigure-dialer-v2'),
262 pack("N", length($1)). $1. pack("N", length($2)). $2;
263 } split(/\n/, $cck_data);
265 } else { #send a simple confirmation
266 print $cgi->header( '-expires' => 'now' ),
267 $success_template->fill_in();
274 foreach $pop ( @{$pops} ) {
275 if ( $pop->{'popnum'} == $popnum ) { return $pop; }
280 #horrible false laziness with FS/FS/svc_acct_pop.pm::popselector
282 my( $popnum, $state ) = @_;
284 return '<INPUT TYPE="hidden" NAME="popnum" VALUE="">' unless @$pops;
285 return $pops->[0]{city}. ', '. $pops->[0]{state}.
286 ' ('. $pops->[0]{ac}. ')/'. $pops->[0]{exch}.
287 '<INPUT TYPE="hidden" NAME="popnum" VALUE="'. $pops->[0]{popnum}. '">'
288 if scalar(@$pops) == 1;
291 push @{ $pop{$_->{state}} }, $_ foreach @$pops;
295 function opt(what,href,text) {
296 var optionName = new Option(text, href, false, false)
297 var length = what.length;
298 what.options[length] = optionName;
301 function popstate_changed(what) {
302 state = what.options[what.selectedIndex].text;
303 for (var i = what.form.popnum.length;i > 0;i--)
304 what.form.popnum.options[i] = null;
305 what.form.popnum.options[0] = new Option("", "", false, true);
308 foreach my $popstate ( sort { $a cmp $b } keys %pop ) {
309 $text .= "\nif ( state == \"$popstate\" ) {\n";
311 foreach my $pop ( @{$pop{$popstate}}) {
312 my $o_popnum = $pop->{popnum};
313 my $poptext = $pop->{city}. ', '. $pop->{state}.
314 ' ('. $pop->{ac}. ')/'. $pop->{exch};
316 $text .= "opt(what.form.popnum, \"$o_popnum\", \"$poptext\");\n"
321 $text .= "}\n</SCRIPT>\n";
324 qq!<SELECT NAME="popstate" SIZE=1 onChange="popstate_changed(this)">!.
326 $text .= "<OPTION>$_" foreach sort { $a cmp $b } keys %pop;
327 $text .= '</SELECT>'; #callback? return 3 html pieces? #'</TD><TD>';
329 $text .= qq!<SELECT NAME="popnum" SIZE=1><OPTION> !;
330 foreach my $pop ( @$pops ) {
331 $text .= qq!<OPTION VALUE="!. $pop->{popnum}. '"'.
332 ( ( $popnum && $pop->{popnum} == $popnum ) ? ' SELECTED' : '' ). ">".
333 $pop->{city}. ', '. $pop->{state}.
334 ' ('. $pop->{ac}. ')/'. $pop->{exch};
336 $text .= '</SELECT>';
343 my $date = shift || '';
344 my( $m, $y ) = ( 0, 0 );
345 if ( $date =~ /^(\d{4})-(\d{2})-\d{2}$/ ) { #PostgreSQL date format
346 ( $m, $y ) = ( $2, $1 );
347 } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
348 ( $m, $y ) = ( $1, $3 );
350 my $return = qq!<SELECT NAME="$prefix!. qq!_month" SIZE="1">!;
352 $return .= "<OPTION";
353 $return .= " SELECTED" if $_ == $m;
356 $return .= qq!</SELECT>/<SELECT NAME="$prefix!. qq!_year" SIZE="1">!;
357 for ( 2001 .. 2037 ) {
358 $return .= "<OPTION";
359 $return .= " SELECTED" if $_ == $y;
362 $return .= "</SELECT>";
367 sub success_default { #html to use if you don't specify a success file
369 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
370 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
371 Thanks for signing up!
373 Signup information for <%= $email_name %>:
375 Username: <%= $username %><BR>
376 Password: <%= $password %><BR>
377 Access number: (<%= $ac %>) / $exch - $local<BR>
378 Package: <%= $pkg %><BR>
383 sub signup_default { #html to use if you don't specify a template file
385 <HTML><HEAD><TITLE>ISP Signup form</TITLE></HEAD>
386 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>ISP Signup form</FONT><BR><BR>
387 <FONT SIZE="+1" COLOR="#ff0000"><%= $error %></FONT>
388 <FORM ACTION="<%= $self_url %>" METHOD=POST>
389 <INPUT TYPE="hidden" NAME="magic" VALUE="process">
390 <INPUT TYPE="hidden" NAME="ref" VALUE="<%= $referral_custnum %>">
391 <INPUT TYPE="hidden" NAME="ss" VALUE="">
393 <TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=0 WIDTH="100%">
395 <TH ALIGN="right"><font color="#ff0000">*</font>Contact name<BR>(last, first)</TH>
396 <TD COLSPAN=5><INPUT TYPE="text" NAME="last" VALUE="<%= $last %>">,
397 <INPUT TYPE="text" NAME="first" VALUE="<%= $first %>"></TD>
400 <TD ALIGN="right">Company</TD>
401 <TD COLSPAN=5><INPUT TYPE="text" NAME="company" SIZE=70 VALUE="<%= $company %>"></TD>
404 <TH ALIGN="right"><font color="#ff0000">*</font>Address</TH>
405 <TD COLSPAN=5><INPUT TYPE="text" NAME="address1" SIZE=70 VALUE="<%= $address1 %>"></TD>
408 <TD ALIGN="right"> </TD>
409 <TD COLSPAN=5><INPUT TYPE="text" NAME="address2" SIZE=70 VALUE="<%= $address2 %>"></TD>
412 <TH ALIGN="right"><font color="#ff0000">*</font>City</TH>
413 <TD><INPUT TYPE="text" NAME="city" VALUE="<%= $city %>"></TD>
414 <TH ALIGN="right"><font color="#ff0000">*</font>State/Country</TH>
415 <TD><SELECT NAME="state" SIZE="1">
418 foreach ( @{$locales} ) {
420 $OUT .= ' SELECTED' if ( $state eq $_->{'state'}
421 && $county eq $_->{'county'}
422 && $country eq $_->{'country'}
424 $OUT .= '>'. $_->{'state'};
425 $OUT .= ' ('. $_->{'county'}. ')' if $_->{'county'};
426 $OUT .= ' / '. $_->{'country'};
431 <TH><font color="#ff0000">*</font>Zip</TH>
432 <TD><INPUT TYPE="text" NAME="zip" SIZE=10 VALUE="<%= $zip %>"></TD>
435 <TD ALIGN="right">Day Phone</TD>
436 <TD COLSPAN=5><INPUT TYPE="text" NAME="daytime" VALUE="<%= $daytime %>" SIZE=18></TD>
439 <TD ALIGN="right">Night Phone</TD>
440 <TD COLSPAN=5><INPUT TYPE="text" NAME="night" VALUE="<%= $night %>" SIZE=18></TD>
443 <TD ALIGN="right">Fax</TD>
444 <TD COLSPAN=5><INPUT TYPE="text" NAME="fax" VALUE="<%= $fax %>" SIZE=12></TD>
446 </TABLE><font color="#ff0000">*</font> required fields<BR>
447 <BR>Billing information<TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=0 WIDTH="100%">
451 $OUT .= '<INPUT TYPE="checkbox" NAME="invoicing_list_POST" VALUE="POST"';
452 my @invoicing_list = split(', ', $invoicing_list );
454 if ! @invoicing_list || grep { $_ eq 'POST' } @invoicing_list;
460 <TR><TD>Email invoice <INPUT TYPE="text" NAME="invoicing_list" VALUE="<%= join(', ', grep { $_ ne 'POST' } split(', ', $invoicing_list ) ) %>">
462 <%= scalar(@payby) > 1 ? '<TR><TD>Billing type</TD></TR>' : '' %>
464 <TABLE BGCOLOR="#c0c0c0" BORDER=1 WIDTH="100%">
469 my $cardselect = '<SELECT NAME="CARD_type"><OPTION></OPTION>';
471 'VISA' => 'VISA card',
472 'MasterCard' => 'MasterCard',
473 'Discover' => 'Discover card',
474 'American Express' => 'American Express card',
476 foreach ( keys %types ) {
477 $selected = $cgi->param('CARD_type') eq $types{$_} ? 'SELECTED' : '';
478 $cardselect .= qq!<OPTION $selected VALUE="$types{$_}">$_</OPTION>!;
480 $cardselect .= '</SELECT>';
483 '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="">!,
484 '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">!,
485 '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"),
486 'PREPAY' => qq!Prepaid card<BR><font color="#ff0000">*</font><INPUT TYPE="text" NAME="PREPAY_payinfo" VALUE="" MAXLENGTH=80>!,
490 '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">!,
491 '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">!,
492 '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),
493 'PREPAY' => qq!Prepaid card<BR><font color="#ff0000">*</font><INPUT TYPE="text" NAME="PREPAY_payinfo" VALUE="$payinfo" MAXLENGTH=80>!,
497 if ( scalar(@payby) == 1) {
498 $OUT .= '<TD VALIGN=TOP>'.
499 qq!<INPUT TYPE="hidden" NAME="payby" VALUE="$_">!.
500 "$paybychecked{$_}</TD>";
502 $OUT .= qq!<TD VALIGN=TOP><INPUT TYPE="radio" NAME="payby" VALUE="$_"!;
504 $OUT .= qq! CHECKED> $paybychecked{$_}</TD>!;
506 $OUT .= qq!> $payby{$_}</TD>!;
513 </TR></TABLE><font color="#ff0000">*</font> required fields for each billing type
514 <BR><BR>First package
515 <TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=0 WIDTH="100%">
517 <TD COLSPAN=2><SELECT NAME="pkgpart"><OPTION VALUE="">(none)
520 foreach my $package ( @{$packages} ) {
521 $OUT .= '<OPTION VALUE="'. $package->{'pkgpart'}. '"';
522 $OUT .= ' SELECTED' if $pkgpart && $package->{'pkgpart'} == $pkgpart;
523 $OUT .= '>'. $package->{'pkg'};
530 <TD ALIGN="right">Username</TD>
531 <TD><INPUT TYPE="text" NAME="username" VALUE="<%= $username %>"></TD>
534 <TD ALIGN="right">Password</TD>
535 <TD><INPUT TYPE="password" NAME="_password" VALUE="<%= $password %>"></TD>
538 <TD ALIGN="right">Re-enter Password</TD>
539 <TD><INPUT TYPE="password" NAME="_password2" VALUE="<%= $password2 %>"></TD>
542 if ( $init_data->{'security_phrase'} ) {
545 <TD ALIGN="right">Security Phrase</TD>
546 <TD><INPUT TYPE="text" NAME="sec_phrase" VALUE="$sec_phrase">
551 $OUT .= '<INPUT TYPE="hidden" NAME="sec_phrase" VALUE="">';
555 if ( scalar(@$pops) ) {
556 $OUT .= '<TR><TD ALIGN="right">Access number</TD><TD>'.
557 popselector($popnum). '</TD></TR>';
559 $OUT .= popselector($popnum);
563 <BR><BR><INPUT TYPE="submit" VALUE="Signup">
564 </FORM></BODY></HTML>