#!/usr/bin/perl # MAKE SURE THE ABOVE LINE POINTS TO YOUR PERL5 BINARY # This script requires atleast Perl5.003 use Socket; $| = 1; ######################################################################### # | _) # __| _` | _ \ __ `__ \ _` | | __ \ # ( ( | ( | | | | ( | | | | # \___|\__,_|\___/ _| _| _|\__,_|_|_| _| for UNIX and NT # # CdomainFree Copyright (C) 1998 Jason Hatch # Cdomain products can be found at http://www.cdomain.com # # Use of this software is at your own risk. Help is available by e-mailing # support@cdomain.com. # # LICENSE AGREEMENT # # Any and all use of this product, in whole or in part, is subject to and # signifies agreement to the terms set forth in the CdomainFree End User # License Agreement that is referenced at http://www.cdomain.com/license. # For your reference, a copy of the above mentioned license is provided as # part of this distribution in a file called LICENSE.TXT. In the event a # discrepancy exists between the license contained on our web site and the # license accompanying this software, the license contained on our web site # shall be deemed authoritative. # # INSTRUCTIONS: # # This is the main script that does error-checking on the entered domain # and checks to see if its registered by contacting "whois" and # interpreting the results. # # Put this file in your CGI scripts directory (ie, /cgi-bin/) # # See the README file that is accompanied with this distribution for # additional documentation. # # It is IMPORTANT that you change this variable to point to the complete # URL of your script, ie: http://mysite.com/cgi-bin/cdomain.pl # $SCRIPT = "/cgi-bin/cdfree.pl"; # # Change these variables to change varous fonts and sizes # $HEADER_FONT="Arial,Geneva"; $TEXT_FONT="Arial,Geneva"; $HEADER_FONT_SIZE = "-1"; $TEXT_FONT_SIZE = "-1"; $H_COLOR = "#A80000"; # # You can change these to customize the headers and footers that # Cdomain uses. # $ERROR = "DOMAIN NAME ERROR"; $AVAIL = "DOMAIN NAME AVAILABLE"; $USED = "DOMAIN NAME IN USE"; $RAW = "DOMAIN LOOKUP OUTPUT"; $INTERNIC_DOWN = "INTERNIC DATABASE BUSY"; # # If you define this order form, Cdomain will print a link to it on # lookups that return available domains. This makes Cdomain a good # preamble to order forms. Uncomment and put the URL to your order form. # # If you set the below line to something, be sure to UNCOMMENT it. # TO UNCOMMENT IT, REMOVE THE "#" # #$ORDER_FORM = "http://myname.com/order.html"; # # Set this to the number of times Cdomain should retry the InterNIC if it # is busy. # $maxtries = 3; # First try plus 2 more # # No need to modify anything below this line. # &Get_POST; if ( ( defined( $ENV{'SERVER_NAME'} ) ) && ( defined( $ENV{'REQUEST_URI'} )) ) { $SCRIPT = "http://" . $ENV{'SERVER_NAME'} . $ENV{'REQUEST_URI'}; } &print_html_header; $attempts = 1; $root_allowed = $in{'root_allowed'}; if ($in{'lookup'} ne "OK" ) { if ($root_allowed == 1 ) { &print_form_header(); &form_root(); &print_form_footer(); } else { &print_form_header(); &form_checkoff(); &print_form_footer(); } } if (!defined($in{'cdomain'})) { &c_error("version variable cdomain not defined in html code."); } else { $version = $in{'cdomain'}; } &print_r_header; $raw = $in{'raw'}; $fqdn = $in{'fqdn'}; $domain = $in{'domain'}; $root = $in{'root'}; if (($root_allowed != 1) && ($raw != 1)) { $domain = $domain . "." . $root; } @domain_fields = split('\.',$domain); $rindex = $#domain_fields; if ($rindex > 1) { if ("\L$domain_fields[0]" eq "www" && $rindex < 3 ) { $domain = $domain_fields[$rindex - 1] . "." . $domain_fields[$rindex]; } else { &error("$domain: contains too many \".\'s\" (dots)"); } } $root = $domain_fields[$#domain_fields]; @TLDS = ("com","net","org","edu"); $server = "whois.crsnic.net"; $nomatch = "No match"; $ok = 0; foreach $record (@TLDS) { if ($record eq $root) { $ok = 1; } } if ($ok != 1) { &error("I don't support the $root TLD"); } if ($raw != 1) { $domain =~ s/[ \t]+//g; $cdomain = $domain; $fqdn = $domain; # Check for "-" in the beginning or end of the domain if ($domain_fields[$rindex - 1] =~ /^-|-$/) { &error("$fqdn: \"-\" located at beginning or end"); } # Remove the "-" character since its allowed and it won't cause an # an error when we check for non word characters below $cdomain =~ s/-//g; $cdomain =~ s/\.//g; # Perform some simple checks to make sure there's no bad characters if ($cdomain =~ /_/) { &error("$fqdn: underscore (_) not permitted in domains."); } if ($cdomain =~ /\W/) { &error("$fqdn: non word character."); } if ($cdomain eq "") { &error("no domain entered"); } if ($domain =~ "debug1debug") { &debug("normal"); exit(0); } } # Fire off whois @result = &get_whois($fqdn,$server); # Check its output. if ($raw != 1) { $used = 1; foreach (@result) { if (/$nomatch/) { $used = 0; last; } elsif (/^\*/) { $attempts++; if ($attempts > $maxtries) { &internic_down($domain,$root); } } } if ($used == 1) { &used($fqdn,$domain,$root); } else { &available($fqdn); } } else { foreach (@result) { if (/Whois Server:\s(.*)/) { $newserver = $1 } } if ($newserver) {@result=get_whois($fqdn,$newserver)} &raw($fqdn); } &close_html; exit 0; #---------------------------------------------------------------- # # WHOIS # #---------------------------------------------------------------- sub get_whois { local($fqdn,$server) = @_; local(@test,$sin,$len,$offset,$written,$buff,$myfqdn); socket(SOCK, PF_INET, SOCK_STREAM, (getprotobyname('tcp'))[2]) || return (("")); $sin = sockaddr_in(43, inet_aton($server)); connect(SOCK, $sin) || return (("")); $offset = 0; $buff = $fqdn . "\r\n"; $len = length($buff); while($len) { $written = syswrite(SOCK,$buff,$len,$offset); $len -= $written; $offset += $written; } @test=; close(SOCK); return(@test); } #---------------------------------------------------------------- # # ENVIRONMENT # #---------------------------------------------------------------- sub Get_POST { # The following code snippet was taken from cgi-lib.pl and is # Copyright (c) 1995 Steven E. Brenner local ($i, $key, $val, $arglist); if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; } else { read(STDIN,$in,$ENV{'CONTENT_LENGTH'}); } @in = split(/[&;]/,$in); foreach $i (0 .. $#in) { $in[$i] =~ s/\+/ /g; ($key, $val) = split(/=/,$in[$i],2); # splits on the first =. $key =~ s/%(..)/pack("c",hex($1))/ge; $val =~ s/%(..)/pack("c",hex($1))/ge; $in{$key} .= "\0" if (defined($in{$key})); $in{$key} .= $val; } return scalar(@in); } #---------------------------------------------------------------- # # HTML FUNCTIONS # You can modify HTML in these functions. # The beginning and end of HTML in these functions are delimited # by lines that look like this: # ------------------------- BEGIN HTML # ------------------------- END HTML # IMPORTANT: DO NOT MODIFY PERL CODE OUTSIDE THOSE DELIMITERS # ALSO, DO NOT REMOVE THE "print < Domain Name Check Results EOM #------------------------- END HTML } #---------------------------------------------------------------- # HTML FUNCTION: close_html # Description: Closes HTML output # #---------------------------------------------------------------- sub close_html { #------------------------- BEGIN HTML print < EOM #------------------------- END HTML } #---------------------------------------------------------------- # HTML FUNCTION: raw # Description: calls p_header, prints backlink # Be careful modifying this #---------------------------------------------------------------- sub raw { &p_header($RAW); #------------------------- BEGIN HTML print < EOM #------------------------- END HTML if( defined( $in{'prv'} ) ) { #------------------------- BEGIN HTML print <here to return to the Whois Lookup.

EOM } #------------------------- END HTML #------------------------- BEGIN HTML print <$fqdn:

@result

EOM #------------------------- END HTML &p_footer($RAW); } #---------------------------------------------------------------- # HTML FUNCTION: available # Description: This prints AVAILABLE domain OUTPUT # Where ever $fqdn appears, it will be replaced with the domain #---------------------------------------------------------------- sub available { local($fqdn) = @_; &p_header($AVAIL); #------------------------- BEGIN HTML print < A search performed on $server has revealed that the domain "$fqdn" is available. You may register this domain. EOM #------------------------- END HTML #------------------------- BEGIN HTML # Define the variable $ORDER_FORM above, and this will print if ( defined($ORDER_FORM) ) { print <On-Line Order Form to purchase service using this domain. EOM #------------------------- END HTML } if( defined( $ENV{'HTTP_REFERER'} ) ) { #------------------------- BEGIN HTML # This will print a link back to the form print <Click here to return to the previous page. EOM #------------------------- END HTML } else { print <Please click on your Browser's "Back" button to return to the previous page. EOM } print <

EOM &p_footer($AVAIL); } sub internic_down { local($domain,$root) = @_; &p_header($INTERNIC_DOWN); print < I have tried to look up the domain ${domain}.${root} several times, but the InterNIC is reporting that its database is down. Please wait a few seconds and click on the button below to retry your search, EOM if( defined( $ENV{'HTTP_REFERER'} ) ) { print <here to return to the Whois Lookup, EOM } else { print <

EOM &p_footer($INTERNIC_DOWN); } #---------------------------------------------------------------- # HTML FUNCTION: used # Description: This is called when a domain is USED # Be careful modifying this #---------------------------------------------------------------- sub used { local($fqdn,$domain,$root) = @_; &p_header($USED); if ($root_allowed == 1) { $domain = $fqdn; } #------------------------- BEGIN HTML print < A search on $server has revealed that the domain name $fqdn is in use by another company or individual. You cannot register this domain. EOM #------------------------- END HTML if( defined( $ENV{'HTTP_REFERER'} ) ) { #------------------------- BEGIN HTML # This prints a back link print <here to return to the Whois Lookup, EOM #------------------------- END HTML } else { #------------------------- BEGIN HTML #This is called if we can't figure out where they came from print <

EOM if ($root_allowed == 1) { print "\n"; } print <

EOM #------------------------- END HTML &p_footer($USED); } #---------------------------------------------------------------- # HTML FUNCTION: debug # Description: You wont need to modify this #---------------------------------------------------------------- sub debug { local($HEADER) = "DEBUGGING INFO"; &p_header($HEADER); print < Cdomain v2.7 Copyright (C) 1997,1998,1999 Cdomain Software. Written by J. Allen Hatch.

Debug Information:

Cdomain Version: $in{'cdomain'}
domain: $domain
cdomain: $cdomain
root: $root
fqdn: $fqdn
root: $rfields[0]
whois: $rfields[1]
nomatch: $rfields[2]

This is CdomainFree v2.7

EOM &p_footer($HEADER); } # #---------------------------------------------------------------- # HTML FUNCTION: c_error # Description: This is called if there is an error with script #---------------------------------------------------------------- sub c_error { local($error) = @_; &p_header("Cdomain Error"); #------------------------- BEGIN HTML print < An error was encountered:

$error

  • Can I find your "whois" binary?
  • Does the hidden variable "cdomain" appear in the form calling this script? If so, does it contain the version number?

EOM #------------------------- END HTML &p_footer("Cdomain Error"); &close_html; die("$error\n"); } #---------------------------------------------------------------- # HTML FUNCTION: error # Description: This is called if there is an error with user # input. #---------------------------------------------------------------- sub error { local($REASON) = @_; &p_header($ERROR); if ( ! $fqdn ) { $fqdn = $domain; } #------------------------- BEGIN HTML print < There was an error processing your request for the domain:

$fqdn

EOM #------------------------- END HTML if( defined( $ENV{'HTTP_REFERER'} ) ) { print <here to re-enter the Domain Name. EOM } else { print <ERROR: $REASON

Hint: Do not include any dots (".") or underscores ("_") in the domain you enter into the "Domain" field. Also, do not enter a root domain (ie, ".com" ".org" or ".net") under the "Domain" field; rather, use the radio buttons to the right to select your root level domain.

EOM #------------------------- END HTML &p_footer($ERROR); &close_html; exit 0; } # # #---------------------------------------------------------------- # HTML FUNCTION: p_header # Description: This function prints the HTML for all output #---------------------------------------------------------------- sub p_header { local ($HEADER) = @_; #------------------------- BEGIN HTML print <
$HEADER


EOM #------------------------- END HTML } #---------------------------------------------------------------- # HTML FUNCTION: p_header # Description: this prints the bottom bar for all html output # #---------------------------------------------------------------- sub p_footer { local ($HEADER) = @_; #------------------------- BEGIN HTML print <
Output Generated by CdomainFree

$HEADER
EOM #------------------------- END HTML } # ############################################################## sub print_form_header { # # This subroutine prints the intial form header for all requests # # print < Domain Name Check by Cdomain

EOM } # ############################################################## sub form_checkoff { # # This is the "middle" of the page, the actual form itself. It # is printed when you request a form where the user is required # to check off the entered domain. # print <
Domain Check by CdomainFree


Please use the following form to check the availability of a domain name. Please provide a value for a domain name and select one of the extensions, ".com", ".net", ".org" or ".edu". A query will be performed on the appropriate WHOIS database.

EOM } # ############################################################## sub form_root { # # This is the "middle" of the page, the actual form itself. It # is printed when you request a form where the user is required # to check off the entered domain. # print <
DOMAIN NAME:
WWW. .
Please use the following form to check the availability of a domain name. Please provide a value for a domain name, including its extension (i.e., ".com", etc.). Please do not include the "www". A query on the appropriate WHOIS database will be performed.

I currently do lookups on ".com", ".net", ".org", and ".edu" domains.

EOM } # ############################################################## sub print_form_footer { # # This is the footer used for all requests for the form # # print <
DOMAIN NAME:

CdomainFree v2.7 (C) 1998 J. Allen Hatch

Domain Check by CdomainFree

EOM &close_html(); exit(0); }