Codice PHP:
// include the config file
require "config.php";
error_reporting ( E_WARNING | ~ E_NOTICE ) ;
// check whether we are going to use the header and footer template files
if(!isset($use_global_templates)) {
$use_global_templates = $use_global_templates_by_default; // whether to use the global templates
}
// some extensions (com/net/org) have a server which contains the name of the server which should be used for the information, this simply tells the script to use the whois server as a source for the server info... ;)
$whois_si_servers = array();
// an array of the `whois' servers
$whois_servers = array();
// default whois servers for info
$whois_info_servers = array();
// the backup whois servers to try
$whois_info_servers_backup = array();
// the strings that are returned if the domain is available
$whois_avail_strings = array();
// the page titles
$whois_page_titles = array();
// the template list
$whois_templates = array();
// some substitution strings follow
$errormsg = "";
$titlebar = "MWhois written by Matt Wilson"; // the default title bar
$rawoutput = "";
$avail = array();
$unavail = array();
$whois_server = "";
// the name of the script
$script_name = "mwhois.php";
function my_in_array($val,$array_)
{
for($l=0; $l<sizeof($array_); $l++) {
if($array_[$l] == $val) {
return 1;
}
}
return 0;
}
// in case the theme can't be found
function fatal_theme()
{
global $theme;
echo '<HTML><BODY><FONT FACE=VERDANA SIZE=2>MWhois could not load the specified theme `[B]'.$theme.'[/B]\', check the directory exists and try again!</FONT></BODY></HTML>';
exit();
}
// in case the theme can't be found
function fatal_servers_lst()
{
echo '<HTML><BODY><FONT FACE=VERDANA SIZE=2>MWhois could not locate the `servers.lst\' file in the current directory!</FONT></BODY></HTML>';
exit();
}
// loads the page titles into a hash
function load_page_titles()
{
global $whois_page_titles;
global $theme;
global $dir_split;
// load the titles.cfg file
$titles_cfg_file = @file($theme.$dir_split."titles.cfg");
if(!$titles_cfg_file) { echo "\n"; }
// go through each line of the titles config file and grab what we want
for($l=0; $l<sizeof($titles_cfg_file); $l++){
// trim each line and see if its a comment
$titles_cfg_file[$l] = trim($titles_cfg_file[$l]);
if(substr($titles_cfg_file[$l],0,1) == ";") { continue; }
// explode the bits, we can't use the limit paramater in case of PHP<4.0.1
$bits = explode("|", $titles_cfg_file[$l]);
// check to make sure there are at least two bits
if(sizeof($bits) < 2) { continue; }
// glue the bits of the line together that are after 2
$flag = $bits[0];
$title = $bits[1];
for($t=0; $t<sizeof($bits)-2; $t++){ $title .= "|".$bits[$t]; }
// put the page title in to the hash array
$whois_page_titles[$flag] = $title;
// for the sakes of debugging show whats happening
//echo "\n";
}
}
// loads the template filenames into a hash ref
function load_template_names()
{
global $whois_templates;
global $theme;
global $dir_split;
// load the titles.cfg file
$template_cfg_file = @file($theme.$dir_split."templates.cfg");
if(!$template_cfg_file) { fatal_theme(); }
// go through each line of the titles config file and grab what we want
for($l=0; $l<sizeof($template_cfg_file); $l++){
// trim each line and see if its a comment
$template_cfg_file[$l] = trim($template_cfg_file[$l]);
if(substr($template_cfg_file[$l],0,1) == ";") { continue; }
// explode the bits, we can't use the limit paramater in case of PHP<4.0.1
$bits = explode("|", $template_cfg_file[$l]);
// check to make sure there are at least two bits
if(sizeof($bits) < 2) { continue; }
// glue the bits of the line together that are after 2
$flag = $bits[0];
$template = $bits[1];
for($t=0; $t<sizeof($bits)-2; $t++){ $template .= "|".$bits[$t]; }
// put the page title in to the hash array
$whois_templates[$flag] = $theme.$dir_split.$template;
// for the sakes of debugging show whats happening
//echo "\n";
}
}
// this loads the server info for the extensions in $whois_exts;
function load_server_info()
{
global $whois_exts;
global $whois_si_servers;
global $whois_servers;
global $whois_info_servers;
global $whois_info_servers_backup;
global $whois_avail_strings;
global $vars;
// load the servers.lst file
$tlds = @file("servers.lst");
if(!$tlds) { fatal_servers_lst(); }
for($l=0; $l<sizeof($tlds); $l++){
// time leading spaces or trailing spaces
$tlds[$l] = chop($tlds[$l]);
// filter out the commented lines (begin with #)
if(substr($tlds[$l], 0, 1) == "#" || !strlen($tlds[$l])) { continue; }
// explode via the seperation char `|'
$es = explode("|", $tlds[$l]);
// check to see whether we want this TLD
if(!my_in_array($es[0], $whois_exts)) { continue; }
// yes we do, so store the details in the appropriate arrays
$whois_servers[$es[0]] = $es[1];
$whois_si_servers[$es[0]] = $es[5];
$whois_info_servers[$es[0]] = $es[3];
$whois_info_servers_backup[$es[0]] = $es[4];
$whois_avail_strings[$es[1]] = $es[2];
// thats it!
}
}
function choose_info_server($domain, $ext)
{
global $whois_info_servers;
global $whois_si_servers;
global $whois_server;
global $whois_servers;
global $vars;
$whois_server = "";
if($whois_si_servers[$ext]){
if(($co = fsockopen($whois_servers[$ext], 43)) == false){
//echo "\n";
$whois_server = $whois_servers[$ext];
} else {
//echo "\n";
fputs($co, $domain.".".$ext."\r\n");
while(!feof($co)) { $output .= fgets($co,128); }
fclose($co);
$he = strpos($output, $whois_si_servers[$ext]) + strlen($whois_si_servers[$ext]);
$le = strpos($output, "\n", $he);
$whois_server = substr($output, $he, $le-$he);
//echo "\n";
}
} else {
$whois_server = $whois_info_servers[$ext];
}
$whois_server = trim($whois_server);
}
// make all the changes
function make_changes($fil)
{
global $vars;
global $errormsg;
global $titlebar;
global $rawoutput;
global $avail;
global $unavail;
global $whois_exts;
global $whois_servers;
global $script_name;
global $theme;
global $dir_split;
$f = implode("", file($fil));
$f = str_replace("[>WHOIS_SERVER<]",$whois_servers[$vars["ext"]],$f);
$f = str_replace("[>TITLE_BAR<]",$titlebar,$f);
$f = str_replace("[>DOMAIN<]",$vars["domain"],$f);
$f = str_replace("[>FULLDOMAIN<]", $vars["fulldomain"], $f);
$f = str_replace("[>ERROR_MSG<]",$errormsg,$f);
$f = str_replace("[>RAWOUTPUT<]",$rawoutput,$f);
for($l=0; $l<sizeof($avail); $l++){
$sp[1] = substr(strchr($avail[$l],"."),1);
$sp[0] = substr($avail[$l],0,strlen($avail[$l])-strlen($sp[1])-1);
$avail_s = $avail_s."<a href=\"".$script_name."?domain=".$sp[0]."&ext=".$sp[1]."\">".$avail[$l]."</a>
";
}
for($l=0; $l<sizeof($unavail); $l++){
$sp[1] = substr(strchr($unavail[$l],"."),1);
$sp[0] = substr($unavail[$l],0,strlen($unavail[$l])-strlen($sp[1])-1);
$unavail_s = $unavail_s."<a href=\"".$script_name."?domain=".$sp[0]."&ext=".$sp[1]."\">".$unavail[$l]."</a>
";
}
$f = str_replace("[>AVAIL_LIST<]",$avail_s,$f);
$f = str_replace("[>UNAVAIL_LIST<]",$unavail_s,$f);
$f = str_replace("[>SCRIPT_NAME<]", $script_name, $f);
$f = str_replace("[>EXT<]",$vars["ext"],$f);
$f = str_replace("[>EXT_LIST<]",implode("
",$whois_exts),$f);
$f = str_replace("[>EXT_HTML_LIST<]","<select name=\"ext\">\n<option>".implode("\n<option>",$whois_exts)."\n</select>",$f);
return $f;
}
continua