4 # $Id: signup.cgi,v 1.52 2004-10-01 01:38:02 ivan Exp $
7 use vars qw( @payby $cgi $locales $packages
10 $last $first $ss $company $address1 $address2 $city $state $county
11 $country $zip $daytime $night $fax $invoicing_list $payby $payinfo
12 $paycvv $paydate $payname $referral_custnum $init_popstate
13 $pkgpart $username $password $password2 $sec_phrase $popnum
15 $ieak_file $ieak_template
16 $signup_html $signup_template
17 $success_html $success_template
18 $decline_html $decline_template
23 use subs qw( print_form print_okay print_decline
24 success_default decline_default );
26 #use CGI::Carp qw(fatalsToBrowser);
28 use Business::CreditCard;
29 use HTTP::BrowserDetect;
30 use FS::SignupClient 0.03 qw( signup_info new_customer
31 regionselector expselect popselector);
33 #acceptable payment methods
35 #@payby = qw( CARD BILL COMP );
36 #@payby = qw( CARD BILL );
38 @payby = qw( CARD PREPAY );
40 $ieak_file = '/usr/local/freeside/ieak.template';
41 $signup_html = -e 'signup.html'
43 : '/usr/local/freeside/signup.html';
44 $success_html = -e 'success.html'
46 : '/usr/local/freeside/success.html';
47 $decline_html = -e 'decline.html'
49 : '/usr/local/freeside/decline.html';
52 if ( -e $ieak_file ) {
53 my $ieak_txt = Text::Template::_load_text($ieak_file)
54 or die $Text::Template::ERROR;
55 $ieak_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
57 $ieak_txt =~ s/\r//g; # don't double \r on old templates
58 $ieak_txt =~ s/\n/\r\n/g;
59 $ieak_template = new Text::Template ( TYPE => 'STRING', SOURCE => $ieak_txt )
60 or die $Text::Template::ERROR;
66 if ( -e $signup_html ) {
67 my $signup_txt = Text::Template::_load_text($signup_html)
68 or die $Text::Template::ERROR;
69 $signup_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
71 $signup_template = new Text::Template ( TYPE => 'STRING',
72 SOURCE => $signup_txt,
73 DELIMITERS => [ '<%=', '%>' ]
75 or die $Text::Template::ERROR;
77 /<\s*INPUT TYPE="?hidden"?\s+NAME="?agentnum"?\s+VALUE="?(\d+)"?\s*>/si
82 #too much maintenance hassle to keep in this file
83 die "can't find ./signup.html or /usr/local/freeside/signup.html";
84 #$signup_template = new Text::Template ( TYPE => 'STRING',
85 # SOURCE => &signup_default,
86 # DELIMITERS => [ '<%=', '%>' ]
88 # or die $Text::Template::ERROR;
91 if ( -e $success_html ) {
92 my $success_txt = Text::Template::_load_text($success_html)
93 or die $Text::Template::ERROR;
94 $success_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
96 $success_template = new Text::Template ( TYPE => 'STRING',
97 SOURCE => $success_txt,
98 DELIMITERS => [ '<%=', '%>' ],
100 or die $Text::Template::ERROR;
102 $success_template = new Text::Template ( TYPE => 'STRING',
103 SOURCE => &success_default,
104 DELIMITERS => [ '<%=', '%>' ],
106 or die $Text::Template::ERROR;
109 if ( -e $decline_html ) {
110 my $decline_txt = Text::Template::_load_text($decline_html)
111 or die $Text::Template::ERROR;
112 $decline_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
114 $decline_template = new Text::Template ( TYPE => 'STRING',
115 SOURCE => $decline_txt,
116 DELIMITERS => [ '<%=', '%>' ],
118 or die $Text::Template::ERROR;
120 $decline_template = new Text::Template ( TYPE => 'STRING',
121 SOURCE => &decline_default,
122 DELIMITERS => [ '<%=', '%>' ],
124 or die $Text::Template::ERROR;
128 ( $locales, $packages, $pops, $init_data ) = signup_info();
129 @payby = @{$init_data->{'payby'}} if @{$init_data->{'payby'}};
130 $packages = $init_data->{agentnum2part_pkg}{$agentnum} if $agentnum;
134 push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
135 $popnum2pop{$_->{popnum}} = $_;
140 if ( defined $cgi->param('magic') ) {
141 if ( $cgi->param('magic') eq 'process' ) {
143 if ( $cgi->param('state') =~ /^(\w*)( \(([\w ]+)\))? ?\/ ?(\w+)$/ ) {
147 } elsif ( $cgi->param('state') =~ /^(\w*)$/ ) {
149 $cgi->param('county') =~ /^([\w ]*)$/
150 or die "illegal county: ". $cgi->param('county');
152 $cgi->param('country') =~ /^(\w+)$/
153 or die "illegal country: ". $cgi->param('country');
156 die "illegal state: ". $cgi->param('state');
159 $payby = $cgi->param('payby');
160 if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
161 #$payinfo = join('@', map { $cgi->param( $payby. "_payinfo$_" ) } (1,2) );
162 $payinfo = $cgi->param($payby. '_payinfo1'). '@'.
163 $cgi->param($payby. '_payinfo2');
165 $payinfo = $cgi->param( $payby. '_payinfo' );
168 $cgi->param( $payby. '_month' ). '-'. $cgi->param( $payby. '_year' );
169 $payname = $cgi->param( $payby. '_payname' );
170 $paycvv = defined $cgi->param( $payby. '_paycvv' )
171 ? $cgi->param( $payby. '_paycvv' )
174 if ( $invoicing_list = $cgi->param('invoicing_list') ) {
175 $invoicing_list .= ', POST' if $cgi->param('invoicing_list_POST');
177 $invoicing_list = 'POST';
182 $last = $cgi->param('last');
183 $first = $cgi->param('first');
184 $ss = $cgi->param('ss');
185 $company = $cgi->param('company');
186 $address1 = $cgi->param('address1');
187 $address2 = $cgi->param('address2');
188 $city = $cgi->param('city');
191 $zip = $cgi->param('zip');
193 $daytime = $cgi->param('daytime');
194 $night = $cgi->param('night');
195 $fax = $cgi->param('fax');
201 $referral_custnum = $cgi->param('ref');
202 $pkgpart = $cgi->param('pkgpart');
203 $username = $cgi->param('username');
204 $sec_phrase = $cgi->param('sec_phrase');
205 $password = $cgi->param('_password');
206 $popnum = $cgi->param('popnum');
207 #$agentnum, # = $cgi->param('agentnum'),
208 $agentnum ||= $cgi->param('agentnum');
209 $init_popstate = $cgi->param('init_popstate');
210 $refnum = $cgi->param('refnum');
212 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
213 $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
217 $password2 = $cgi->param('_password2');
219 if ( $payby =~ /^(CARD|DCRD)$/ && $cgi->param('CARD_type') ) {
222 $payinfo =~ /^(\d{13,16})$/
223 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
226 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
227 cardtype($payinfo) eq $cgi->param('CARD_type')
228 or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
231 $error ||= new_customer ( {
235 'company' => $company,
236 'address1' => $address1,
237 'address2' => $address2,
242 'country' => $country,
243 'daytime' => $daytime,
247 'payinfo' => $payinfo,
249 'paydate' => $paydate,
250 'payname' => $payname,
251 'invoicing_list' => $invoicing_list,
252 'referral_custnum' => $referral_custnum,
253 'pkgpart' => $pkgpart,
254 'username' => $username,
255 'sec_phrase' => $sec_phrase,
256 '_password' => $password,
258 'agentnum' => $agentnum,
260 map { $_ => $cgi->param($_) } grep { /^snarf_/ } $cgi->param
265 if ( $error eq '_decline' ) {
268 #fudge the snarf info
270 ${$_} = $cgi->param($_) foreach grep { /^snarf_/ } $cgi->param;
277 die "unrecognized magic: ". $cgi->param('magic');
288 $state = $init_data->{statedefault};
290 $country = $init_data->{countrydefault};
295 $invoicing_list = '';
306 $referral_custnum = $cgi->param('ref') || '';
307 $init_popstate = $cgi->param('init_popstate') || '';
308 $refnum = $init_data->{'refnum'};
315 $cgi->delete('init_popstate');
316 $self_url = $cgi->self_url;
318 $error = "Error: $error" if $error;
320 print $cgi->header( '-expires' => 'now' ),
321 $signup_template->fill_in();
326 print $cgi->header( '-expires' => 'now' ),
327 $decline_template->fill_in();
331 my $user_agent = new HTTP::BrowserDetect $ENV{HTTP_USER_AGENT};
333 $cgi->param('username') =~ /^(.+)$/
334 or die "fatal: invalid username got past FS::SignupClient::new_customer";
336 $cgi->param('_password') =~ /^(.+)$/
337 or die "fatal: invalid password got past FS::SignupClient::new_customer";
339 ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
340 or die "fatal: invalid email_name got past FS::SignupClient::new_customer";
341 $email_name = $1; #global for template
343 my $pop = $popnum2pop{$cgi->param('popnum')};
344 #or die "fatal: invalid popnum got past FS::SignupClient::new_customer";
346 ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
348 ( $ac, $exch, $loc ) = ( '', '', ''); #presumably you're not using them.
352 $pkg = ( grep { $_->{'pkgpart'} eq $pkgpart } @$packages )[0]->{'pkg'};
354 if ( $ieak_template && $user_agent->windows && $user_agent->ie ) {
356 print $cgi->header('application/x-Internet-signup'),
357 $ieak_template->fill_in();
358 } else { #send a simple confirmation
359 print $cgi->header( '-expires' => 'now' ),
360 $success_template->fill_in();
364 sub success_default { #html to use if you don't specify a success file
366 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
367 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
368 Thanks for signing up!
370 Signup information for <%= $email_name %>:
372 Username: <%= $username %><BR>
373 Password: <%= $password %><BR>
374 Access number: (<%= $ac %>) / <%= $exch %> - <%= $local %><BR>
375 Package: <%= $pkg %><BR>
380 sub decline_default { #html to use if there is a decline
382 <HTML><HEAD><TITLE>Processing error</TITLE></HEAD>
383 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Processing error</FONT><BR><BR>
384 There has been an error processing your account. Please contact customer