#!/home/y/bin/perl

#use CGI::Carp qw(fatalsToBrowser);

 

#################################################################################################

#

# All-purpose whois script for SimpleNet.  Written by Michael Sussna, October 1999.

#

# Two forms call this, both on the same HTML page, /whois/lookup.html.

#

# Form1 allows a domain lookup with user-specified tld.  Lookup details are optional.

# Form2 allows lookups on hypothetical domain names based on user or company name, hobby, etc.

#

#################################################################################################

 

use LWP::UserAgent;

use HTTP::Request;

 

use lib '/Space/CGI/modules';

 

use YDNSTools;

use UDB_access;

 

require '/Space/CGI/libraries/domains-api-post.lib';

require '/Space/CGI/libraries/yid.pl'; # yahoo id extractor

 

 

#require '/Space/CGI/libraries/domain-name-availability.pl';

#require '/Space/209.132.1/068/cgi-bin/domain-name-availability.pl';

 

@result_rows = "";

$result_rownum = 0;

$num_per_page = "500";

$error_flag = 0;

 

#################################################################################################

#DoTimeIn();

 

GetFormInput();

Init();

 

# Action 1 = internal to blackbox, 2 = external (e.g. from banner)

 

SetupLookAndFeel();

PostSetupInit();

 

if       ($aForm{action} eq "")                  {Error("0"); ExitScript();}

if       ($aForm{name} eq "")

{

       if       ($landing)                 {OutputPage(); ExitScript();}

       else                               {Error("1"); ExitScript();}

}

 

if     (

              $aForm{update_my_list}

       or       $aForm{review_my_list}

       or       $aForm{'view_more.x'}

       or       $aForm{update_my_list_viewmore}

       )

                                          {UpdateAndOutputPage(); ExitScript();}

      

if     (

              $aForm{update_my_list_review}

       or       $aForm{secure_checkout}

       )

                                          {UpdateReview(); ExitScript();}

 

if       ($aForm{num_domains} > 0)        {NotFirstTime();}

else                                      {$first_time = 1; Form1();}

 

OutputPage();

 

ExitScript();

 

#################################################################################################

sub Init

{

       $|=1;

 

       $property = "domains";

#       $property = $aForm{property};

 

       yid_main();

 

       if       ($yid)       {$auth_time_limit = 172800;} # 48 hours

       else          {$auth_time_limit = 3600;} # 1 hour

 

       # Set the domain bit of the cookie as appropriate according to the cookie RFC

       $cookie_auth_domain = $ENV{HTTP_HOST};

       $cookie_auth_domain =~ s/^(whois)\.//i;

       $cookie_auth_domain =~ s/\:.*//;

       $cookie_auth_domain_nodot = $cookie_auth_domain;

       $cookie_auth_domain = ".$cookie_auth_domain";

 

       if       (

                     (not $aForm{update_my_list})

              and       (not $aForm{update_my_list_review})

              and       (not $aForm{secure_checkout})

              and       (not $aForm{review_my_list})

              and       (not $aForm{'view_more.x'})

              and       (not $aForm{update_my_list_viewmore})

              )

       {

              print "Content-type: text/html\n\n";

       }

 

       $woops = "";

       $woops_count = 0;

       $first_time = 0;

       $landing = 0;

 

       if ($aForm{ext} eq "" or $aForm{ext} eq "null") {$aForm{ext} = "\.xxx";}

 

       $num_oingo_fields_before_tlds = 3;

 

       srand (time ^ $$ ^ unpack "%32L*", `ps axww | gzip`);

       $ran = int rand 1000000000;

 

       if ($aForm{name} eq "" and $aForm{action} =~ /2/) {$landing = 1;}

       $secondary_avails_here = 0;

       if ($aForm{'view_more.x'})

       {

              $something_new = 1;

              @oingo_tldfields = split /,/,$aForm{oingo_tld_fields};

       }

       else       {$something_new = 0;}

       $something_more = 0;

       $tld_requested = 0;

 

       $aForm{template} =~ /(.*)_.*/;

       $template_directory = $1;

      

       $biz_blurb = "

              <div align=\"left\"><font size = -2 face = arial,helvetica>

              Registrations in the .biz top-level domain (TLD) must be used or intended to be used primarily for bona fide

              business or commercial purposes. For more information about appropriate & inappropriate use, refer to the

              <a href=\"http://domains.yahoo.com/inwwagree.html\">Domain Registration Agreement</a>.</font><br><br></div>

       ";

}

 

 

sub SetupLookAndFeel

{

       # Template 1 is the results page, template 2 is the landing page.

       # Split each into two parts.  Part "a" is output before the blackbox output,

       # part "b" after it.

      

       # Look and feel variables in the blackbox html are first filled

       # in from the defaults in the defaults file.  Then any user-defined

       # overrides are applied on top of that, from the user variables file.

       # The black box html (with search results, if any) is inserted at

       # the appropriate point in the template html.

 

       if (-e "/Space/209.132.1/068/Server/Documents/Templates/$template_directory/$aForm{template}_1.html"

       and -e "/Space/209.132.1/068/Server/Documents/Templates/$template_directory/$aForm{template}_2.html")

       {

              $template1_path = "/Space/209.132.1/068/Server/Documents/Templates/$template_directory/$aForm{template}_1.html";

              $template2_path = "/Space/209.132.1/068/Server/Documents/Templates/$template_directory/$aForm{template}_2.html";

       }

       else

       {

              $template1_path = "/Space/209.132.1/068/Server/Documents/Templates/domains/domains_a_1.html";

              $template2_path = "/Space/209.132.1/068/Server/Documents/Templates/domains/domains_a_2.html";

       }

 

       open(TEMPLATE1_FILE,"$template1_path") or die "Can't open $template1_path: $!\n";

       while ($line = <TEMPLATE1_FILE> and $line !~ /blackboxoutput/)

       {

              $template1a_html .= $line;

       }

       while ($line = <TEMPLATE1_FILE>) {$template1b_html .= $line;}

       close TEMPLATE1_FILE;

 

       open(TEMPLATE2_FILE,"$template2_path") or die "Can't open $template2_path: $!\n";

       while ($line = <TEMPLATE2_FILE> and $line !~ /blackboxoutput/)

       {

              $template2a_html .= $line;

       }

       while ($line = <TEMPLATE2_FILE>) {$template2b_html .= $line;}

       close TEMPLATE2_FILE;

 

       open(BLACKBOX_FILE,"/Space/209.132.1/068/Server/Documents/Templates/blackbox.html") or die "Can't open /Templates/blackbox.html: $!\n";

       while ($line = <BLACKBOX_FILE>)

       {

              $blackbox_html .= $line;

       }

       close BLACKBOX_FILE;

 

       if       ($landing)

       {

              $blackbox_html =~ s/searchbox_/landing_searchbox_/ig;

              $blackbox_html =~ s/main_border_/landing_main_border_/ig;

              $blackbox_html =~ s/main_interior_/landing_main_interior_/ig;

       }

       else

       {

              $blackbox_html =~ s/searchbox_/results_searchbox_/ig;

              $blackbox_html =~ s/main_border_/results_main_border_/ig;

              $blackbox_html =~ s/main_interior_/results_main_interior_/ig;

       }

 

       # Populate look and feel variables hash with default values

       open(DEFAULT_VARIABLES_FILE,"/Space/209.132.1/068/Server/Documents/Templates/default/default_variables.txt") or die "Can't open /Templates/default/default_variables.txt: $!\n";

       while ($line = <DEFAULT_VARIABLES_FILE>)

       {

              if       ($line =~ /^\#/ or $line =~ /^\s/)       {next;}

              if       ($line =~ /=/)

              {

                     ($name,$value) = split /=/,$line,2; # 2 allows ='s in value

                     chomp($value);

                     $lookandfeel{$name} = $value;

              }

       }

       close DEFAULT_VARIABLES_FILE;

 

       # Override any look and feel variables with values that user has supplied

       open(USER_VARIABLES_FILE,"/Space/209.132.1/068/Server/Documents/Templates/$template_directory/$aForm{template}_variables.txt") or die "Can't open /Templates/$template_directory/$aForm{template}_variables.txt: $!\n";

       while ($line = <USER_VARIABLES_FILE>)

       {

              if       ($line =~ /^\#/ or $line =~ /^\s/)       {next;}

              if       ($line =~ /=/)

              {

                     ($name,$value) = split /=/,$line,2; # 2 allows ='s in value

                     chomp($value);            

                     $lookandfeel{$name} = $value;

              }

       }

       close USER_VARIABLES_FILE;

 

       # Do this now so any overrides already seen are overriden by this

       if ($landing) {$lookandfeel{searchagain_type} = "box";}

 

       if ($aForm{review_my_list}

       or $aForm{update_my_list}

       or $aForm{update_my_list_review}

       or $aForm{'view_more.x'}

       or $aForm{update_my_list_viewmore} 

       )

       {

              $lookandfeel{primary_border_color} = "#FFFFFF";

       }

 

       if ($lookandfeel{user_show_landing} =~ /y/ or $lookandfeel{user_show_results} =~ /y/)

       {SetupUseridAppearance();}

 

       # Apply merged variable values to blackbox html

       foreach $key (sort keys %lookandfeel)

       {

              $temp = $lookandfeel{$key};

              $blackbox_html =~ s/$key/$temp/ig;

       }

}

 

 

sub PostSetupInit

{

       @tld = split /,/, $lookandfeel{tld_list};

 

       @default_tlds = split /,/,$lookandfeel{default_tld};

      

       $num_primary_domains = $#tld + 1;

 

       $num_secondary_rows_page1 = $lookandfeel{secondary_display_number1};

       if       ($lookandfeel{secondary_display_number2} =~ /all/)

       {

              $max_viewmore_rows = 999;

       }

       else       # Set to 0 to turn off

       {

              $max_viewmore_rows = $lookandfeel{secondary_display_number2};

       }

#       $num_secondary_rows_page1 = 3;

#       $max_viewmore_rows = 50;  # Set to 0 to turn off

}

 

 

sub ExitScript

{

       #DoTimeOut();

       exit; 

}

 

 

sub OutputPage

{

       OutputBlackboxA();

       OutputBeginning();

 

       if       ($error_exists or $landing)                   {}

       elsif

       (

              $aForm{update_my_list}

       or       $aForm{review_my_list}

       or       $aForm{update_my_list_review}

       or       $aForm{update_my_list_viewmore}

       or       $aForm{secure_checkout}

       )

                                                        {OutputReview();}

       elsif       ($aForm{'view_more.x'})                        {OutputViewMore();}

       else       # I.e., first time

       {

              OutputPreliminary();

              if       (not $aForm{'view_more.x'})            {OutputPrimary();}

              if       ($lookandfeel{secondary_show} =~ /y/i)       {OutputSecondary();}

              if        ($lookandfeel{user_show_results} =~ /y/i

                     and $yid

                     and not $aForm{'view_more.x'})            {OutputUserid();}

              OutputButtonsResults();

              OutputEndForm();

       }

 

       OutputSearchagain();

       if ($landing and $lookandfeel{user_show_landing} =~ /y/i)

       {

              $first_time = 1;

              $aForm{name} = "fromlanding";

              $num_domains = $aForm{num_domains};

              OutputFormAndMiscHiddens();

              if ($yid) {OutputUserid();}

              UpdateDomainlistCookieHiddens(); # Needs OutputUserid done 1st to get s_d_l

              @sorted_page_list = @page_list;

              $num_domains = @sorted_domain_list;

              OutputButtonsResults();

              OutputEndForm();

       }

        OutputBeacon();

        OutputEnd();

        OutputBlackboxB();

}

 

 

sub OutputBlackboxA

{

       SetupPersonalization();

      

       if       ($landing)                               # Landing page

       {

              (@out_lines_a) = split /\n/,$template2a_html;

              (@out_lines_b) = split /\n/,$template2b_html;

       }

       else                                             # Results page

       {

              (@out_lines_a) = split /\n/,$template1a_html;

              (@out_lines_b) = split /\n/,$template1b_html;

       }

      

       foreach $line (@out_lines_a) {print "$line\n";}

      

       SetupQuerystring(); # Do now, before split, even if not used

 

       (@out_blackbox_lines) = split /\n/,$blackbox_html;

       ChopupBlackbox();

             

       $bbi = 0;

}

 

 

sub SetupPersonalization

{

       if       ($yid)

       {     

              $person = "

<table width=750 cellpadding=2 cellspacing=0 border=0 bgcolor=\"#dcdcdc\" align=\"center\">

  <tr>

    <td><font face=arial size=-1><b>Welcome, $yid!</b></font></td>

    <td align=right nowrap><font face=arial size=-1><a href=http://edit.yahoo.com/config/eval_profile?.done=http%3a//domains.yahoo.com/>Account Info</a> -

      <a href=http://login.yahoo.com/config/login?logout=1&.intl=us&.src=dom&.done=http%3a//login.yahoo.com/config/login%3f.intl=us%26.src=dom%26.done=http%253a//domains.yahoo.com>Sign Out</a></font></td>

    </tr>

</table>";

       }

       else

       {

              $person = "

<table width=750 cellpadding=2 cellspacing=0 border=0 bgcolor=\"#dcdcdc\" align=\"center\">

  <tr>

    <td><font face=arial size=-1><b>Welcome, Guest</b></font></td>

    <td align=right nowrap><font face=arial size=-1>

      <a href=http://login.yahoo.com/config/login?.src=dom>Sign In</a></font></td>

  </tr>

</table>";

       }

 

       if       ($landing)

       {

              $template2a_html =~ s/begin personalization bar -->/begin personalization bar --> $person/;

       }

       else

       {

              $template1a_html =~ s/begin personalization bar -->/begin personalization bar --> $person/;

       }

}

 

 

sub ChopupBlackbox

{

       CaptureBeginning();

       CaptureBeginForm();

       CapturePrimary();

       CaptureSecondary();

       CaptureUserid();

       CaptureReview();

       CaptureResultSubmit();

       CaptureSearchagain();

       CaptureBeacon();

       CaptureEnd();

}

 

 

sub CaptureBeginning

{

       my $bbi = 0;

       until (@out_blackbox_lines[$bbi] =~ /Start the begin-form tag/)

       {

              push @blackbox_beginning_lines,@out_blackbox_lines[$bbi];

              $bbi++;

       }

}

 

 

sub CaptureBeginForm

{

       my $bbi = 0;

       while (@out_blackbox_lines[$bbi] !~ /Start the begin-form tag/) {$bbi++;}

       until (@out_blackbox_lines[$bbi] =~ /End the begin-form tag/)

       {

              push @blackbox_beginform_lines,@out_blackbox_lines[$bbi];

              $bbi++;

       }

       push @blackbox_beginform_lines,@out_blackbox_lines[$bbi];

}

 

 

sub CapturePrimary

{

       my $bbi = 0;

       while (@out_blackbox_lines[$bbi] !~ /Start Holding Table Primary Output/) {$bbi++;}

       until (@out_blackbox_lines[$bbi] =~ /End Holding Table Primary Output/)

       {

              push @blackbox_primary_lines,@out_blackbox_lines[$bbi];

              $bbi++;

       }

       push @blackbox_primary_lines,@out_blackbox_lines[$bbi];

}

 

 

sub CaptureSecondary

{

       my $bbi = 0;

       while (@out_blackbox_lines[$bbi] !~ /Start Holding Table Secondary Output/) {$bbi++;}

       until (@out_blackbox_lines[$bbi] =~ /End Holding Table Secondary Output/)

       {

              push @blackbox_secondary_lines,@out_blackbox_lines[$bbi];

              $bbi++;

       }

       push @blackbox_secondary_lines,@out_blackbox_lines[$bbi];

}

 

 

sub CaptureUserid

{

       my $bbi = 0;