3 # $Id: signup.cgi,v 1.24 2002-04-19 13:17:56 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 = -e 'signup.html'
36 : '/usr/local/freeside/signup.html';
37 $success_html = -e 'success.html'
39 : '/usr/local/freeside/success.html';
41 if ( -e $ieak_file ) {
42 my $ieak_txt = Text::Template::_load_text($ieak_file)
43 or die $Text::Template::ERROR;
44 $ieak_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
46 $ieak_template = new Text::Template ( TYPE => 'STRING', SOURCE => $ieak_txt )
47 or die $Text::Template::ERROR;
53 my $cck_txt = Text::Template::_load_text($cck_file)
54 or die $Text::Template::ERROR;
55 $cck_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
57 $cck_template = new Text::Template ( TYPE => 'STRING', SOURCE => $cck_txt )
58 or die $Text::Template::ERROR;
64 if ( -e $signup_html ) {
65 my $signup_txt = Text::Template::_load_text($signup_html)
66 or die $Text::Template::ERROR;
67 $signup_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
69 $signup_template = new Text::Template ( TYPE => 'STRING',
70 SOURCE => $signup_txt,
71 DELIMITERS => [ '<%=', '%>' ]
73 or die $Text::Template::ERROR;
75 /<\s*INPUT TYPE="?hidden"?\s+NAME="?agentnum"?\s+VALUE="?(\d+)"?\s*>/si
80 $signup_template = new Text::Template ( TYPE => 'STRING',
81 SOURCE => &signup_default,
82 DELIMITERS => [ '<%=', '%>' ]
84 or die $Text::Template::ERROR;
87 if ( -e $success_html ) {
88 my $success_txt = Text::Template::_load_text($success_html)
89 or die $Text::Template::ERROR;
90 $success_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
92 $success_template = new Text::Template ( TYPE => 'STRING',
93 SOURCE => $success_txt,
94 DELIMITERS => [ '<%=', '%>' ],
96 or die $Text::Template::ERROR;
98 $success_template = new Text::Template ( TYPE => 'STRING',
99 SOURCE => &success_default,
100 DELIMITERS => [ '<%=', '%>' ],
102 or die $Text::Template::ERROR;
106 ( $locales, $packages, $pops, $init_data ) = signup_info();
107 @payby = @{$init_data->{'payby'}} if @{$init_data->{'payby'}};
108 $packages = $init_data->{agentnum2part_pkg}{$agentnum} if $agentnum;
112 if ( defined $cgi->param('magic') ) {
113 if ( $cgi->param('magic') eq 'process' ) {
115 $cgi->param('state') =~ /^(\w*)( \(([\w ]+)\))? ?\/ ?(\w+)$/
116 or die "Oops, illegal \"state\" param: ". $cgi->param('state');
121 $payby = $cgi->param('payby');
122 $payinfo = $cgi->param( $payby. '_payinfo' );
124 $cgi->param( $payby. '_month' ). '-'. $cgi->param( $payby. '_year' );
125 $payname = $cgi->param( $payby. '_payname' );
127 if ( $invoicing_list = $cgi->param('invoicing_list') ) {
128 $invoicing_list .= ', POST' if $cgi->param('invoicing_list_POST');
130 $invoicing_list = 'POST';
135 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
136 $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
140 $password2 = $cgi->param('_password2');
142 if ( $payby eq 'CARD' && $cgi->param('CARD_type') ) {
145 $payinfo =~ /^(\d{13,16})$/
146 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
149 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
150 cardtype($payinfo) eq $cgi->param('CARD_type')
151 or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
154 $error ||= new_customer ( {
155 'last' => $last = $cgi->param('last'),
156 'first' => $first = $cgi->param('first'),
157 'ss' => $ss = $cgi->param('ss'),
158 'company' => $company = $cgi->param('company'),
159 'address1' => $address1 = $cgi->param('address1'),
160 'address2' => $address2 = $cgi->param('address2'),
161 'city' => $city = $cgi->param('city'),
164 'zip' => $zip = $cgi->param('zip'),
165 'country' => $country,
166 'daytime' => $daytime = $cgi->param('daytime'),
167 'night' => $night = $cgi->param('night'),
168 'fax' => $fax = $cgi->param('fax'),
170 'payinfo' => $payinfo,
171 'paydate' => $paydate,
172 'payname' => $payname,
173 'invoicing_list' => $invoicing_list,
174 'referral_custnum' => $referral_custnum = $cgi->param('ref'),
175 'pkgpart' => $pkgpart = $cgi->param('pkgpart'),
176 'username' => $username = $cgi->param('username'),
177 'sec_phrase' => $sec_phrase = $cgi->param('sec_phrase'),
178 '_password' => $password = $cgi->param('_password'),
179 'popnum' => $popnum = $cgi->param('popnum'),
180 'agentnum' => $agentnum, # = $cgi->param('agentnum'),
192 die "unrecognized magic: ". $cgi->param('magic');
210 $invoicing_list = '';
221 $referral_custnum = $cgi->param('ref') || '';
228 $self_url = $cgi->self_url;
230 $error = "Error: $error" if $error;
232 print $cgi->header( '-expires' => 'now' ),
233 $signup_template->fill_in();
238 my $user_agent = new HTTP::Headers::UserAgent $ENV{HTTP_USER_AGENT};
240 $cgi->param('username') =~ /^(.+)$/
241 or die "fatal: invalid username got past FS::SignupClient::new_customer";
243 $cgi->param('_password') =~ /^(.+)$/
244 or die "fatal: invalid password got past FS::SignupClient::new_customer";
246 ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
247 or die "fatal: invalid email_name got past FS::SignupClient::new_customer";
250 my $pop = pop_info($cgi->param('popnum'));
251 #or die "fatal: invalid popnum got past FS::SignupClient::new_customer";
253 ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
255 ( $ac, $exch, $loc ) = ( '', '', ''); #presumably you're not using them.
258 my $pkg = ( grep { $_->{'pkgpart'} eq $pkgpart } @$packages )[0]->{'pkg'};
261 && $user_agent->platform eq 'ia32'
262 && $user_agent->os =~ /^win/
263 && ($user_agent->browser)[0] eq 'IE'
265 { #send an IEAK config
266 print $cgi->header('application/x-Internet-signup'),
267 $ieak_template->fill_in();
268 } elsif ( $cck_template
269 && $user_agent->platform eq 'ia32'
270 && $user_agent->os =~ /^win/
271 && ($user_agent->browser)[0] eq 'Netscape'
273 { #send a Netscape config
274 my $cck_data = $cck_template->fill_in();
275 print $cgi->header('application/x-netscape-autoconfigure-dialer-v2'),
278 pack("N", length($1)). $1. pack("N", length($2)). $2;
279 } split(/\n/, $cck_data);
281 } else { #send a simple confirmation
282 print $cgi->header( '-expires' => 'now' ),
283 $success_template->fill_in();
290 foreach $pop ( @{$pops} ) {
291 if ( $pop->{'popnum'} == $popnum ) { return $pop; }
296 #horrible false laziness with FS/FS/svc_acct_pop.pm::popselector
298 my( $popnum, $state ) = @_;
300 return '<INPUT TYPE="hidden" NAME="popnum" VALUE="">' unless @$pops;
301 return $pops->[0]{city}. ', '. $pops->[0]{state}.
302 ' ('. $pops->[0]{ac}. ')/'. $pops->[0]{exch}.
303 '<INPUT TYPE="hidden" NAME="popnum" VALUE="'. $pops->[0]{popnum}. '">'
304 if scalar(@$pops) == 1;
307 push @{ $pop{$_->{state}} }, $_ foreach @$pops;
311 function opt(what,href,text) {
312 var optionName = new Option(text, href, false, false)
313 var length = what.length;
314 what.options[length] = optionName;
317 function popstate_changed(what) {
318 state = what.options[what.selectedIndex].text;
319 for (var i = what.form.popnum.length;i > 0;i--)
320 what.form.popnum.options[i] = null;
321 what.form.popnum.options[0] = new Option("", "", false, true);
324 foreach my $popstate ( sort { $a cmp $b } keys %pop ) {
325 $text .= "\nif ( state == \"$popstate\" ) {\n";
327 foreach my $pop ( @{$pop{$popstate}}) {
328 my $o_popnum = $pop->{popnum};
329 my $poptext = $pop->{city}. ', '. $pop->{state}.
330 ' ('. $pop->{ac}. ')/'. $pop->{exch};
332 $text .= "opt(what.form.popnum, \"$o_popnum\", \"$poptext\");\n"
337 $text .= "}\n</SCRIPT>\n";
340 qq!<SELECT NAME="popstate" SIZE=1 onChange="popstate_changed(this)">!.
342 $text .= "<OPTION>$_" foreach sort { $a cmp $b } keys %pop;
343 $text .= '</SELECT>'; #callback? return 3 html pieces? #'</TD><TD>';
345 $text .= qq!<SELECT NAME="popnum" SIZE=1><OPTION> !;
346 foreach my $pop ( @$pops ) {
347 $text .= qq!<OPTION VALUE="!. $pop->{popnum}. '"'.
348 ( ( $popnum && $pop->{popnum} == $popnum ) ? ' SELECTED' : '' ). ">".
349 $pop->{city}. ', '. $pop->{state}.
350 ' ('. $pop->{ac}. ')/'. $pop->{exch};
352 $text .= '</SELECT>';
359 my $date = shift || '';
360 my( $m, $y ) = ( 0, 0 );
361 if ( $date =~ /^(\d{4})-(\d{2})-\d{2}$/ ) { #PostgreSQL date format
362 ( $m, $y ) = ( $2, $1 );
363 } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
364 ( $m, $y ) = ( $1, $3 );
366 my $return = qq!<SELECT NAME="$prefix!. qq!_month" SIZE="1">!;
368 $return .= "<OPTION";
369 $return .= " SELECTED" if $_ == $m;
372 $return .= qq!</SELECT>/<SELECT NAME="$prefix!. qq!_year" SIZE="1">!;
373 for ( 2001 .. 2037 ) {
374 $return .= "<OPTION";
375 $return .= " SELECTED" if $_ == $y;
378 $return .= "</SELECT>";
383 sub success_default { #html to use if you don't specify a success file
385 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
386 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
387 Thanks for signing up!
389 Signup information for <%= $email_name %>:
391 Username: <%= $username %><BR>
392 Password: <%= $password %><BR>
393 Access number: (<%= $ac %>) / $exch - $local<BR>
394 Package: <%= $pkg %><BR>
399 sub signup_default { #html to use if you don't specify a template file
401 <HTML><HEAD><TITLE>ISP Signup form</TITLE></HEAD>
402 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>ISP Signup form</FONT><BR><BR>
403 <FONT SIZE="+1" COLOR="#ff0000"><%= $error %></FONT>
404 <FORM ACTION="<%= $self_url %>" METHOD=POST>
405 <INPUT TYPE="hidden" NAME="magic" VALUE="process">
406 <INPUT TYPE="hidden" NAME="ref" VALUE="<%= $referral_custnum %>">
407 <INPUT TYPE="hidden" NAME="ss" VALUE="">
409 <TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=0 WIDTH="100%">
411 <TH ALIGN="right"><font color="#ff0000">*</font>Contact name<BR>(last, first)</TH>
412 <TD COLSPAN=5><INPUT TYPE="text" NAME="last" VALUE="<%= $last %>">,
413 <INPUT TYPE="text" NAME="first" VALUE="<%= $first %>"></TD>
416 <TD ALIGN="right">Company</TD>
417 <TD COLSPAN=5><INPUT TYPE="text" NAME="company" SIZE=70 VALUE="<%= $company %>"></TD>
420 <TH ALIGN="right"><font color="#ff0000">*</font>Address</TH>
421 <TD COLSPAN=5><INPUT TYPE="text" NAME="address1" SIZE=70 VALUE="<%= $address1 %>"></TD>
424 <TD ALIGN="right"> </TD>
425 <TD COLSPAN=5><INPUT TYPE="text" NAME="address2" SIZE=70 VALUE="<%= $address2 %>"></TD>
428 <TH ALIGN="right"><font color="#ff0000">*</font>City</TH>
429 <TD><INPUT TYPE="text" NAME="city" VALUE="<%= $city %>"></TD>
430 <TH ALIGN="right"><font color="#ff0000">*</font>State/Country</TH>
431 <TD><SELECT NAME="state" SIZE="1">
434 foreach ( @{$locales} ) {
436 $OUT .= ' SELECTED' if ( $state eq $_->{'state'}
437 && $county eq $_->{'county'}
438 && $country eq $_->{'country'}
440 $OUT .= '>'. $_->{'state'};
441 $OUT .= ' ('. $_->{'county'}. ')' if $_->{'county'};
442 $OUT .= ' / '. $_->{'country'};
447 <TH><font color="#ff0000">*</font>Zip</TH>
448 <TD><INPUT TYPE="text" NAME="zip" SIZE=10 VALUE="<%= $zip %>"></TD>
451 <TD ALIGN="right">Day Phone</TD>
452 <TD COLSPAN=5><INPUT TYPE="text" NAME="daytime" VALUE="<%= $daytime %>" SIZE=18></TD>
455 <TD ALIGN="right">Night Phone</TD>
456 <TD COLSPAN=5><INPUT TYPE="text" NAME="night" VALUE="<%= $night %>" SIZE=18></TD>
459 <TD ALIGN="right">Fax</TD>
460 <TD COLSPAN=5><INPUT TYPE="text" NAME="fax" VALUE="<%= $fax %>" SIZE=12></TD>
462 </TABLE><font color="#ff0000">*</font> required fields<BR>
463 <BR>Billing information<TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=0 WIDTH="100%">
467 $OUT .= '<INPUT TYPE="checkbox" NAME="invoicing_list_POST" VALUE="POST"';
468 my @invoicing_list = split(', ', $invoicing_list );
470 if ! @invoicing_list || grep { $_ eq 'POST' } @invoicing_list;
476 <TR><TD>Email invoice <INPUT TYPE="text" NAME="invoicing_list" VALUE="<%= join(', ', grep { $_ ne 'POST' } split(', ', $invoicing_list ) ) %>">
478 <%= scalar(@payby) > 1 ? '<TR><TD>Billing type</TD></TR>' : '' %>
480 <TABLE BGCOLOR="#c0c0c0" BORDER=1 WIDTH="100%">
485 my $cardselect = '<SELECT NAME="CARD_type"><OPTION></OPTION>';
487 'VISA' => 'VISA card',
488 'MasterCard' => 'MasterCard',
489 'Discover' => 'Discover card',
490 'American Express' => 'American Express card',
492 foreach ( keys %types ) {
493 $selected = $cgi->param('CARD_type') eq $types{$_} ? 'SELECTED' : '';
494 $cardselect .= qq!<OPTION $selected VALUE="$types{$_}">$_</OPTION>!;
496 $cardselect .= '</SELECT>';
499 '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="">!,
500 '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">!,
501 '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"),
502 'PREPAY' => qq!Prepaid card<BR><font color="#ff0000">*</font><INPUT TYPE="text" NAME="PREPAY_payinfo" VALUE="" MAXLENGTH=80>!,
506 '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">!,
507 '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">!,
508 '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),
509 'PREPAY' => qq!Prepaid card<BR><font color="#ff0000">*</font><INPUT TYPE="text" NAME="PREPAY_payinfo" VALUE="$payinfo" MAXLENGTH=80>!,
513 if ( scalar(@payby) == 1) {
514 $OUT .= '<TD VALIGN=TOP>'.
515 qq!<INPUT TYPE="hidden" NAME="payby" VALUE="$_">!.
516 "$paybychecked{$_}</TD>";
518 $OUT .= qq!<TD VALIGN=TOP><INPUT TYPE="radio" NAME="payby" VALUE="$_"!;
520 $OUT .= qq! CHECKED> $paybychecked{$_}</TD>!;
522 $OUT .= qq!> $payby{$_}</TD>!;
529 </TR></TABLE><font color="#ff0000">*</font> required fields for each billing type
530 <BR><BR>First package
531 <TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=0 WIDTH="100%">
533 <TD COLSPAN=2><SELECT NAME="pkgpart"><OPTION VALUE="">(none)
536 foreach my $package ( @{$packages} ) {
537 $OUT .= '<OPTION VALUE="'. $package->{'pkgpart'}. '"';
538 $OUT .= ' SELECTED' if $pkgpart && $package->{'pkgpart'} == $pkgpart;
539 $OUT .= '>'. $package->{'pkg'};
546 <TD ALIGN="right">Username</TD>
547 <TD><INPUT TYPE="text" NAME="username" VALUE="<%= $username %>"></TD>
550 <TD ALIGN="right">Password</TD>
551 <TD><INPUT TYPE="password" NAME="_password" VALUE="<%= $password %>"></TD>
554 <TD ALIGN="right">Re-enter Password</TD>
555 <TD><INPUT TYPE="password" NAME="_password2" VALUE="<%= $password2 %>"></TD>
558 if ( $init_data->{'security_phrase'} ) {
561 <TD ALIGN="right">Security Phrase</TD>
562 <TD><INPUT TYPE="text" NAME="sec_phrase" VALUE="$sec_phrase">
567 $OUT .= '<INPUT TYPE="hidden" NAME="sec_phrase" VALUE="">';
571 if ( scalar(@$pops) ) {
572 $OUT .= '<TR><TD ALIGN="right">Access number</TD><TD>'.
573 popselector($popnum). '</TD></TR>';
575 $OUT .= popselector($popnum);
579 <BR><BR><INPUT TYPE="submit" VALUE="Signup">
580 </FORM></BODY></HTML>