untaint template source
[freeside.git] / fs_signup / FS-SignupClient / cgi / signup.cgi
index 15767c1..7576b8b 100755 (executable)
@@ -1,33 +1,53 @@
 #!/usr/bin/perl -Tw
 #
-# $Id: signup.cgi,v 1.2 1999-12-17 12:03:03 ivan Exp $
+# $Id: signup.cgi,v 1.8 2000-08-24 07:26:50 ivan Exp $
 
 use strict;
 use vars qw( @payby $cgi $locales $packages $pops $r $error
              $last $first $ss $company $address1 $address2 $city $state $county
              $country $zip $daytime $night $fax $invoicing_list $payby $payinfo
              $paydate $payname $pkgpart $username $password $popnum
-             $ieak_docroot $ieak_baseurl );
+             $ieak_file $ieak_template $cck_file $cck_template
+             $ac $exch $loc
+           );
 use subs qw( print_form print_okay expselect );
 
 use CGI;
 use CGI::Carp qw(fatalsToBrowser);
 use HTTP::Headers::UserAgent 2.00;
 use FS::SignupClient qw( signup_info new_customer );
+use Text::Template;
 
 #acceptable payment methods
 #
 #@payby = qw( CARD BILL COMP );
 #@payby = qw( CARD BILL );
-@payby = qw( CARD );
-
-#to enable ieak signups, you need to specify a directory in the web server's
-#document space and the equivalent base URL
-#
-$ieak_docroot = "/var/www/sisd.420.am/freeside/ieak";
-$ieak_baseurl = "http://sisd.420.am/freeside/ieak";
-
-#srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
+#@payby = qw( CARD );
+@payby = qw( CARD PREPAY );
+
+$ieak_file = '/usr/local/freeside/ieak.template';
+$cck_file = '/usr/local/freeside/cck.template';
+
+if ( -e $ieak_file ) {
+  my $ieak_txt = Text::Template::_load_text($ieak_file)
+    or die $Text::Template::ERROR;
+  $ieak_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
+  $ieak_txt = $1;
+  $ieak_template = new Text::Template ( TYPE => 'STRING', SOURCE => $ieak_txt )
+    or die $Text::Template::ERROR;
+} else {
+  $ieak_template = '';
+}
+if ( -e $cck_file ) {
+  my $cck_txt = Text::Template::_load_text($cck_file)
+    or die $Text::Template::ERROR;
+  $cck_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
+  $cck_txt = $1;
+  $cck_template = new Text::Template ( TYPE => 'STRING', SOURCE => $cck_txt )
+    or die $Text::Template::ERROR;
+} else {
+  $cck_template = '';
+}
 
 ( $locales, $packages, $pops ) = signup_info();
 
@@ -208,12 +228,14 @@ END
     'CARD' => qq!Credit card<BR>${r}<INPUT TYPE="text" NAME="CARD_payinfo" VALUE="" MAXLENGTH=19><BR>${r}Exp !. expselect("CARD"). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="CARD_payname" VALUE="">!,
     'BILL' => qq!Billing<BR>P.O. <INPUT TYPE="text" NAME="BILL_payinfo" VALUE=""><BR>${r}Exp !. expselect("BILL", "12-2037"). qq!<BR>${r}Attention<BR><INPUT TYPE="text" NAME="BILL_payname" VALUE="Accounts Payable">!,
     'COMP' => qq!Complimentary<BR>${r}Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE=""><BR>${r}Exp !. expselect("COMP"),
+    'PREPAY' => qq!Prepaid card<BR>${r}<INPUT TYPE="text" NAME="PREPAY_payinfo" VALUE="" MAXLENGTH=80>!,
   );
 
   my %paybychecked = (
     'CARD' => qq!Credit card<BR>${r}<INPUT TYPE="text" NAME="CARD_payinfo" VALUE="$payinfo" MAXLENGTH=19><BR>${r}Exp !. expselect("CARD", $paydate). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="CARD_payname" VALUE="$payname">!,
     'BILL' => qq!Billing<BR>P.O. <INPUT TYPE="text" NAME="BILL_payinfo" VALUE="$payinfo"><BR>${r}Exp !. expselect("BILL", $paydate). qq!<BR>${r}Attention<BR><INPUT TYPE="text" NAME="BILL_payname" VALUE="$payname">!,
     'COMP' => qq!Complimentary<BR>${r}Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE="$payinfo"><BR>${r}Exp !. expselect("COMP", $paydate),
+    'PREPAY' => qq!Prepaid card<BR>${r}<INPUT TYPE="text" NAME="PREPAY_payinfo" VALUE="$payinfo" MAXLENGTH=80>!,
   );
 
   for (@payby) {
@@ -277,65 +299,42 @@ END
 }
 
 sub print_okay {
-  $user_agent = new HTTP::Headers::UserAgnet $ENV{HTTP_USER_AGENT};
-  if (    defined($ieak_docroot)
-       && defined($ieak_baseurl)
-       && defined($ieak_secret)
+  my $user_agent = new HTTP::Headers::UserAgent $ENV{HTTP_USER_AGENT};
+
+  $cgi->param('username') =~ /^(.+)$/
+    or die "fatal: invalid username got past FS::SignupClient::new_customer";
+  my $username = $1;
+  $cgi->param('_password') =~ /^(.+)$/
+    or die "fatal: invalid password got past FS::SignupClient::new_customer";
+  my $password = $1;
+  ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
+    or die "fatal: invalid email_name got past FS::SignupCLient::new_customer";
+  my $email_name = $1;
+
+  my $pop = pop_info($cgi->param('popnum'))
+    or die "fatal: invalid popnum got past FS::SignupClient::new_customer";
+  my ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
+
+  if ( $ieak_template
        && $user_agent->platform eq 'ia32'
        && $user_agent->os =~ /^win/
-       && ($user-agent->browser)[0] eq 'IE'
+       && ($user_agent->browser)[0] eq 'IE'
      )
   { #send an IEAK config
-    my $username = $cgi->param('username');
-    my $password = $cgi->param('_password');
-    my $email_name = $cgi->param('first'). ' '. $cgi->param('last');
-    my $ins_file = rand(4294967296). ".ins";
-    open(INS_FILE, ">$ieak_docroot/$ins_file");
-    print INS_FILE <<END;
-[Entry]\r
-Entry_Name = Netloud\r
-[Phone]\r
-Dial_As_Is=no\r
-Phone_Number = 5551212\r
-Area_Code = 415\r
-Country_Code = 1\r
-Country_Id = 1\r
-[Server]\r
-Type = PPP\r
-SW_Compress = Yes\r
-PW_Encrypt = Yes\r
-Negotiate_TCP/IP = Yes\r
-Disable_LCP = No\r
-[TCP/IP]\r
-Specify_IP_Address = No\r
-Specity_Server_Address = No\r
-IP_Header_Compress = Yes\r
-Gateway_On_Remote = Yes\r
-[User]\r
-Name = $username\r
-Password = $password\r
-Display_Password = Yes\r
-[Internet_Mail]\r
-Email_Name = $email_name\r
-Email_Address = $username\@netloud.com\r
-POP_Server = mail.netloud.com\r
-POP_Server_Port_Number = 110\r
-POP_Login_Name = $username\r
-POP_Login_Password = $password\r
-SMTP_Server = mail.netloud.com\r
-SMTP_Server_Port_Number = 25\r
-Install_Mail = 1\r
-[Internet_News]\r
-NNTP_Server = news.netloud.com\r
-NNTP_Server_Port_Number = 119\r
-Logon_Required = No\r
-Install_News = 1\r
-[Branding]\r
-Window_Title = Internet Explorer From Netloud.com\r
-END
-    close INS_FILE;
-
-    print $cgi->redirect("$ieak_docroot/$ins_file");
+    print $cgi->header('application/x-Internet-signup'),
+          $ieak_template->fill_in();
+  } elsif ( $cck_template
+            && $user_agent->platform eq 'ia32'
+            && $user_agent->os =~ /^win/
+            && ($user_agent->browser)[0] eq 'Netscape'
+          )
+  { #send a Netscape config
+    my $cck_data = $cck_template->fill_in();
+    print $cgi->header('application/x-netscape-autoconfigure-dialer-v2'),
+          map {
+            m/(.*)\s+(.*)$/;
+            pack("N", length($1)). $1. pack("N", length($2)). $2;
+          } split(/\n/, $cck_data);
 
   } else { #send a simple confirmation
     print $cgi->header( '-expires' => 'now' ), <<END;
@@ -348,6 +347,15 @@ END
   }
 }
 
+sub pop_info {
+  my $popnum = shift;
+  my $pop;
+  foreach $pop ( @{$pops} ) {
+    if ( $pop->{'popnum'} == $popnum ) { return $pop; }
+  }
+  '';
+}
+
 sub expselect {
   my $prefix = shift;
   my $date = shift || '';