CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
How to preoccupy a form with my whois search

 



Twizted
New User

Sep 28, 2002, 12:36 PM

Post #1 of 2 (468 views)
     How to preoccupy a form with my whois search  

I need help. I am trying to preoccupy a form with my whois search results. The whois works great but I want the outcome (if domain is not taken) to be able to register this with my site. The outcome now has yourname.com is available and I can link the available part but I need it to preoccupy a form to register that name if it is not taken. Below is my complete whois script.

#!/usr/bin/perl
#My Whois

$showdetail ="yes";
$submit_button_text ="Do the search";
$default_search_text = "your-name";
$filename = "whois.html";
$availabletext="<font color='#ff0000'>is available</font>";
$unavailabletext="is unavailable";

####################################
# Any changes below are unsupported.
####################################
use CGI;
$query = new CGI;
use Socket;
print $query->header;

$pathtoscript = $0;
$scriptname = "whois.pl";
$pathtoscript =~s/$scriptname//g;
@tlds_db =();
@server_db =();
$results = "";
$error = "";


if ($query->param('debug') eq "password")
{
&debug;
}

open (TLD,"$pathtoscript" . "tlds.txt") or &ohdear("Cannot open $pathtoscript". "tlds\.txt");
@TLDS = <TLD>;
close(TLD);
foreach $xxx (@TLDS)
{
if ($xxx !~ /^\#/)
{
@xxxx = split(/\|/, $xxx);
@tlds_db = (@tlds_db,$xxxx[0]);
@server_db = (@server_db,$xxxx[1]);
@match_db = (@match_db,$xxxx[2]);
}
}

open(HTMLFILE,"$pathtoscript" . "$filename") or &ohdear("Cannot open $pathtoscript$filename");
{ local $/; $htmlContent = <HTMLFILE> }
close(HTMLFILE);

if ($htmlContent =~ /\*\*dropdown\*\*/)
{
$dropdownlist = "<select size=\"1\" name=\"tld\">";
$num = 0;
foreach $xxx (@tlds_db)
{
if ($query->param('tld') eq $xxx)
{
$dropdownlist = $dropdownlist . "<option selected>$xxx<\/option>";
}
else
{
if ($num eq 0)
{
$dropdownlist = $dropdownlist . "<option selected>$xxx<\/option>";
}
else
{
$dropdownlist = $dropdownlist . "<option>$xxx<\/option>";
}
}
$num++;
}
$dropdownlist = $dropdownlist . "<\/select>";
}

if ($query->param('fqdn') ne "" )
{
$default_search_text = $query->param('fqdn');
}
$htmlContent =~ s/\*\*searchbox\*\*/<form action="$scriptname" method=get><input type="text" name="fqdn" value="$default_search_text" size="25">/;
$htmlContent =~ s/\*\*submit\*\*/<input type="submit" name="submit" value="$submit_button_text"><\/form>/;
$htmlContent =~ s/\*\*dropdown\*\*/$dropdownlist/;

if( $query->param('fqdn') eq "" )
{
&print_html;
}
$server = @server_db[$index];
chomp($server);
$idomain = $query->param('fqdn');
$idomain=~ s/^http\:\/\///; #Remove http://.
$idomain=~ s/^www\.//; #Remove www.

if( $query->param('tld') ne "" )
{
$domainname = $idomain;
$tld=$query->param('tld');
}
else
{
@splitdomain = split(/\./, $idomain , 2);
$domainname = $splitdomain[0];
$tld = "." . $splitdomain[1];
if ($tld eq ".")
{
$tld = $tlds_db[0];
}
}

$count = 0;
foreach $x (@tlds_db)
{
if ($tld eq $x){$index=$count;last;}
$count++;
}

$domainname =~s/^\s+|\s*\n$//g;
$domainname=~tr/A-Z/a-z/;
$domainname=~s/[^a-z0-9\-]//g;
$domainname=~s/^\-//;
$domainname=~s/\-$//;

if( $domainname eq "" )
{
&print_html;
}

$server = @server_db[$index];
chomp($server);
$fqdn = $domainname . $tld;
&checkdomain;

if ($showdetail eq "yes")
{
$results = $results . $out;
}

&print_html;

exit;

sub checkdomain
{

$port = getservbyname('whois','tcp');
$iaddr = inet_aton($server) || die &ohdear("Error No Such Host: $server"); $paddr = sockaddr_in($port, $iaddr);
$proto = getprotobyname('tcp');
socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die &ohdear("socket: $!"); connect(SOCK, $paddr) || die &ohdear(" $! $server");
select SOCK;
$| = 1;
print SOCK "$fqdn\015\012";
select STDOUT;
while($line = <SOCK>)
{
if ($line =~ /@match_db[$index]/i)
{
$available="yes";
}
$out = $out . $line . "<br>\r";
if ($line =~ /Whois Server: whois./)
{
$server =$line;
$server =~s/Whois Server: //;
$server =~ s/^\s+|\s*\n$//g;
$out = $out . "<p><b>**Going to $server for full record.**</b><p>";
&checkdomain;
}
}
close (SOCK);


if ($available eq "yes")
{
$results = "<p>$fqdn $availabletext<p>";
}
else
{
$results = "<p>$fqdn $unavailabletext<p>";
}
}


sub print_html
{

$results = $results . "<div align=\"center\"><p>Powered by <a href=\"http\://www.web-shack.net/products/acewhois/\">AceWhois</a></div>";
$htmlContent =~ s/\*\*results\*\*/$results/;
print "$htmlContent";
exit;
}

sub ohdear
{
print<<"STUFF";
<font face="Arial, Helvetica, sans-serif" color="#FF0000" size="3"><b>$out An Error Has Occured: $_[0]</b></font>
STUFF
exit;
}


#########
sub debug
{

print<<"HTML";
<font face="Arial, Helvetica, sans-serif" color="#FF0000" size="3"><b>This is $version
HTML

print "<br><br>";
print "The path for this file is $0";
print "<br>";
print "<br>DOCUMENT_ROOT is $ENV{'DOCUMENT_ROOT'}<br>\n";



foreach $key (keys(%ENV))
{
print"$key = $ENV{$key}<br>\n";
}


@dir_list = @INC;

$i = 0;
while ($i <= $#dir_list) {

$dir = $dir_list[$i];

&check_dir($dir);

$i++;
}





print "</b></font>";

exit;

#endsub
}



sub check_dir {
my($dir) = $_[0];
my(@list);
my($new_dir);
my($filename);

if ($dir eq ".") {
return;
}

chdir( $dir );

@list = glob("\*");

foreach $filename (@list) {

if ($filename =~ /pm$/ ) {
print "$dir/$filename <br>\n";
}

# Check if is directory.
if ( -d $filename ) {

$new_dir = $dir . "/" . $filename;

# Append directory name onto dir list.
$pos = $#dir_list + 1;

$dir_list[$pos] = $new_dir;
}
}
}


Paul
Enthusiast

Sep 28, 2002, 12:50 PM

Post #2 of 2 (467 views)
     Re: [Twizted] How to preoccupy a form with my whois search [In reply to]  

Please do not post duplicate threads.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives