Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-20-2010, 10:47 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Help needed to integrate some php with vbulletin

Hi all i have created a vbulletin page using this mod https://vborg.vbsupport.ru/showthread.php?t=62164, what i want to do is incorporate a whoisip lookup script within it (it's the first step of two) here's the entire php for whois:
PHP Code:
<?php
/*************************************************************************
php easy :: whois lookup script
==========================================================================
Author:      php easy code, www.phpeasycode.com
Web Site:    http://www.phpeasycode.com
Contact:     webmaster@phpeasycode.com
*************************************************************************/

$domain $_GET['domain'];

// For the full list of TLDs/Whois servers see http://www.iana.org/domains/root/db/ and http://www.whois365.com/en/listtld/
$whoisservers = array(
    
"ac" =>"whois.nic.ac",
    
"ae" =>"whois.nic.ae",
    
"aero"=>"whois.aero",
    
"af" =>"whois.nic.af",
    
"ag" =>"whois.nic.ag",
    
"al" =>"whois.ripe.net",
    
"am" =>"whois.amnic.net",
    
"arpa" =>"whois.iana.org",
    
"as" =>"whois.nic.as",
    
"asia" =>"whois.nic.asia",
    
"at" =>"whois.nic.at",
    
"au" =>"whois.aunic.net",
    
"az" =>"whois.ripe.net",
    
"ba" =>"whois.ripe.net",
    
"be" =>"whois.dns.be",
    
"bg" =>"whois.register.bg",
    
"bi" =>"whois.nic.bi",
    
"biz" =>"whois.biz",
    
"bj" =>"whois.nic.bj",
    
"br" =>"whois.registro.br",
    
"bt" =>"whois.netnames.net",
    
"by" =>"whois.ripe.net",
    
"bz" =>"whois.belizenic.bz",
    
"ca" =>"whois.cira.ca",
    
"cat" =>"whois.cat",
    
"cc" =>"whois.nic.cc",
    
"cd" =>"whois.nic.cd",
    
"ch" =>"whois.nic.ch",
    
"ci" =>"whois.nic.ci",
    
"ck" =>"whois.nic.ck",
    
"cl" =>"whois.nic.cl",
    
"cn" =>"whois.cnnic.net.cn",
    
"com" =>"whois.verisign-grs.com",
    
"coop" =>"whois.nic.coop",
    
"cx" =>"whois.nic.cx",
    
"cy" =>"whois.ripe.net",
    
"cz" =>"whois.nic.cz",
    
"de" =>"whois.denic.de",
    
"dk" =>"whois.dk-hostmaster.dk",
    
"dm" =>"whois.nic.cx",
    
"dz" =>"whois.ripe.net",
    
"edu" =>"whois.educause.edu",
    
"ee" =>"whois.eenet.ee",
    
"eg" =>"whois.ripe.net",
    
"es" =>"whois.ripe.net",
    
"eu" =>"whois.eu",
    
"fi" =>"whois.ficora.fi",
    
"fo" =>"whois.ripe.net",
    
"fr" =>"whois.nic.fr",
    
"gb" =>"whois.ripe.net",
    
"gd" =>"whois.adamsnames.com",
    
"ge" =>"whois.ripe.net",
    
"gg" =>"whois.channelisles.net",
    
"gi" =>"whois2.afilias-grs.net",
    
"gl" =>"whois.ripe.net",
    
"gm" =>"whois.ripe.net",
    
"gov" =>"whois.nic.gov",
    
"gr" =>"whois.ripe.net",
    
"gs" =>"whois.nic.gs",
    
"gw" =>"whois.nic.gw",
    
"gy" =>"whois.registry.gy",
    
"hk" =>"whois.hkirc.hk",
    
"hm" =>"whois.registry.hm",
    
"hn" =>"whois2.afilias-grs.net",
    
"hr" =>"whois.ripe.net",
    
"hu" =>"whois.nic.hu",
    
"ie" =>"whois.domainregistry.ie",
    
"il" =>"whois.isoc.org.il",
    
"in" =>"whois.inregistry.net",
    
"info" =>"whois.afilias.info",
    
"int" =>"whois.iana.org",
    
"io" =>"whois.nic.io",
    
"iq" =>"vrx.net",
    
"ir" =>"whois.nic.ir",
    
"is" =>"whois.isnic.is",
    
"it" =>"whois.nic.it",
    
"je" =>"whois.channelisles.net",
    
"jobs" =>"jobswhois.verisign-grs.com",
    
"jp" =>"whois.jprs.jp",
    
"ke" =>"whois.kenic.or.ke",
    
"kg" =>"www.domain.kg",
    
"ki" =>"whois.nic.ki",
    
"kr" =>"whois.nic.or.kr",
    
"kz" =>"whois.nic.kz",
    
"la" =>"whois.nic.la",
    
"li" =>"whois.nic.li",
    
"lt" =>"whois.domreg.lt",
    
"lu" =>"whois.dns.lu",
    
"lv" =>"whois.nic.lv",
    
"ly" =>"whois.nic.ly",
    
"ma" =>"whois.iam.net.ma",
    
"mc" =>"whois.ripe.net",
    
"md" =>"whois.ripe.net",
    
"me" =>"whois.meregistry.net",
    
"mg" =>"whois.nic.mg",
    
"mil" =>"whois.nic.mil",
    
"mn" =>"whois.nic.mn",
    
"mobi" =>"whois.dotmobiregistry.net",
    
"ms" =>"whois.adamsnames.tc",
    
"mt" =>"whois.ripe.net",
    
"mu" =>"whois.nic.mu",
    
"museum" =>"whois.museum",
    
"mx" =>"whois.nic.mx",
    
"my" =>"whois.mynic.net.my",
    
"na" =>"whois.na-nic.com.na",
    
"name" =>"whois.nic.name",
    
"net" =>"whois.verisign-grs.net",
    
"nf" =>"whois.nic.nf",
    
"nl" =>"whois.domain-registry.nl",
    
"no" =>"whois.norid.no",
    
"nu" =>"whois.nic.nu",
    
"nz" =>"whois.srs.net.nz",
    
"org" =>"whois.pir.org",
    
"pl" =>"whois.dns.pl",
    
"pm" =>"whois.nic.pm",
    
"pr" =>"whois.uprr.pr",
    
"pro" =>"whois.registrypro.pro",
    
"pt" =>"whois.dns.pt",
    
"re" =>"whois.nic.re",
    
"ro" =>"whois.rotld.ro",
    
"ru" =>"whois.ripn.net",
    
"sa" =>"whois.nic.net.sa",
    
"sb" =>"whois.nic.net.sb",
    
"sc" =>"whois2.afilias-grs.net",
    
"se" =>"whois.iis.se",
    
"sg" =>"whois.nic.net.sg",
    
"sh" =>"whois.nic.sh",
    
"si" =>"whois.arnes.si",
    
"sk" =>"whois.ripe.net",
    
"sm" =>"whois.ripe.net",
    
"st" =>"whois.nic.st",
    
"su" =>"whois.ripn.net",
    
"tc" =>"whois.adamsnames.tc",
    
"tel" =>"whois.nic.tel",
    
"tf" =>"whois.nic.tf",
    
"th" =>"whois.thnic.net",
    
"tj" =>"whois.nic.tj",
    
"tk" =>"whois.dot.tk",
    
"tl" =>"whois.nic.tl",
    
"tm" =>"whois.nic.tm",
    
"tn" =>"whois.ripe.net",
    
"to" =>"whois.tonic.to",
    
"tp" =>"whois.nic.tl",
    
"tr" =>"whois.nic.tr",
    
"travel" =>"whois.nic.travel",
    
"tv" => "tvwhois.verisign-grs.com",
    
"tw" =>"whois.twnic.net.tw",
    
"ua" =>"whois.net.ua",
    
"ug" =>"whois.co.ug",
    
"uk" =>"whois.nic.uk",
    
"us" =>"whois.nic.us",
    
"uy" =>"nic.uy",
    
"uz" =>"whois.cctld.uz",
    
"va" =>"whois.ripe.net",
    
"vc" =>"whois2.afilias-grs.net",
    
"ve" =>"whois.nic.ve",
    
"vg" =>"whois.adamsnames.tc",
    
"wf" =>"whois.nic.wf",
    
"ws" =>"whois.website.ws",
    
"yt" =>"whois.nic.yt",
    
"yu" =>"whois.ripe.net");

function 
LookupDomain($domain){
    global 
$whoisservers;
    
$whoisserver "";
    foreach(
$whoisservers as $tld=>$server) {
        if(
substr($domain, -strlen($tld)) == $tld) {
            
$whoisserver $server;
            break;
        }
    }
    if(!
$whoisserver) {
        return 
"Error: No appropriate Whois server found for $domain domain!";
    }
    
$result QueryWhoisServer($whoisserver$domain);
    if(!
$result) {
        return 
"Error: No results retrieved from $whoisserver server for $domain domain!";
    }
    else {
        
preg_match("/Whois Server: (.*)/"$result$matches);
        
$secondary $matches[1];
        if(
$secondary) {
            
$result QueryWhoisServer($secondary$domain);
            return 
"$domain domain lookup results from $secondary server:\n\n" $result;
        }
        else {
            return 
"$domain domain lookup results from $whoisserver server:\n\n" $result;
        }
    }
}

function 
LookupIP($ip) {
    
$whoisservers = array(
        
//"whois.afrinic.net", // Africa - returns timeout error :-(
        
"whois.apnic.net"// Asia/Pacific - OK :-)
        
"whois.arin.net"// North America - OK :-)
        
"whois.lacnic.net"// Latin America and some Caribbean - OK :-)
        
"whois.ripe.net" // Europe, the Middle East, and Central Asia - OK :-)
    
);
    
$out = array();
    foreach(
$whoisservers as $whoisserver) {
        
$result QueryWhoisServer($whoisserver$ip);
        if(
preg_match("/Country: (.*)/i"$result$matches)) {
            
$out[]= "lookup results for $ip from $whoisserver server:\n\n" $result;
        }
    }
    return 
count($out) . " RESULTS FOUND:\n-------------\n" implode("\n\n-------------\n\n"$out);
}

function 
ValidateIP($ip) {
    
$ipnums explode("."$ip);
    if(
count($ipnums) != 4) {
        return 
false;
    }
    foreach(
$ipnums as $ipnum) {
        if(!
is_numeric($ipnum) || ($ipnum 255)) {
            return 
false;
        }
    }
    return 
$ip;
}

function 
ValidateDomain($domain) {
    if(!
preg_match("/^([-a-z0-9]{2,100})\.([a-z\.]{2,8})$/i"$domain)) {
        return 
false;
    }
    return 
$domain;
}

function 
QueryWhoisServer($whoisserver$domain) {
    
$port 43;
    
$timeout 10;
    
$fp = @fsockopen($whoisserver$port$errno$errstr$timeout) or die("Socket Error " $errno " - " $errstr);
    
fputs($fp$domain "\r\n");
    
$out "";
    while(!
feof($fp)){
        
$out .= fgets($fp);
    }
    
fclose($fp);
    
    return 
$out;
}
?>
<html>
<head>
<title>The Code Cage Whois Lookup</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>
<body>
                
<form action="<?=$_SERVER['PHP_SELF'];?>">
<p><b><label for="domain">Domain/IP Address:</label></b> <input type="text" name="domain" id="domain" value="<?=$domain;?>"> <input type="submit" value="Lookup"></p>
</form>
<?
if($domain) {
    $domain = trim($domain);
    if(ValidateIP($domain)) {
        $result = LookupIP($domain);
    }
    elseif(ValidateDomain($domain)) {
        $result = LookupDomain($domain);
    }
    else die("Invalid Input!");
    echo "<pre>\r\n" . $result . "\r\n</pre>\r\n";
}
?>
</body>
</html>
my template looks like this
HTML Code:
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>$vboptions[bbtitle]</title>

$headinclude
</head>
<body>
$header

$navbar

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
    <td class="tcat">IP Lookup</td>

</tr>
<tr>
<td><div><form action[B]="<?=$_SERVER['PHP_SELF'];?>">[/B]
<p><b><label for="domain">Domain/IP Address:</label></b> <input type="text" name="domain" id="domain" value="<?=$domain;?>"> <input type="submit" value="Lookup"></p>
</form>
<?
if($domain) {
	$domain = trim($domain);
	if(ValidateIP($domain)) {
		$result = LookupIP($domain);
	}
	elseif(ValidateDomain($domain)) {
		$result = LookupDomain($domain);
	}
	else die("Invalid Input!");
	echo "<pre>\r\n" . $result . "\r\n</pre>\r\n";
}
?>

</div></td>
</tr>
</table>



$footer
</body>
</html>
However it faults when saving due to the bold section of Form Action, i clearly don't know what i'm doing, if you use the php above as a stand alone it works perfect, but i want the form within a vbulletin page (thats the first part), the second part is i want the value of the form to be populated with the IP Address from a link like this in the postbit for mods
HTML Code:
<tr><td class="vbmenu_option"><span onmouseover="this.style.cursor='hand';" onClick="window.open('modcp/whois.php','edit','width=900,height=380,scrollbars=yes')">WhoisIP for $post[username]: $post[ip]</span></td></tr>
My template is called lookupip and the php file i created to run the template is called iptest.php

Any help at all would be great!
Reply With Quote
  #2  
Old 02-20-2010, 01:59 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, for the form part I think you just need to get rid of the <? and ?>, like

Code:
<td><div><form action="$_SERVER['PHP_SELF']">
<p><b><label for="domain">Domain/IP Address:</label></b> <input type="text" name="domain" id="domain" value="$domain"> <input type="submit" value="Lookup"></p>
</form>
I'm also not sure if "$_SERVER['PHP_SELF']" will be what you want there.

Also, the PHP you have there won't work in a template, [S]you'll need to put it in a plugin, which means you'll have to find a hook where it can be executed.[/S] Edit: Sorry, I reread your post - you won't necessarily need a plugin if you've got your own php file.

Both of these come from the fact that a vbulletin template is kind of like a php stand alone program but not quite, you don't need <? and ?> and you're limited to a certain set of functions you can call in conditionals.
Reply With Quote
  #3  
Old 02-20-2010, 02:13 PM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the reply but i get the same error:
Quote:
The following error occurred when attempting to evaluate this template:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/thecodec/public_html/forumz/includes/adminfunctions_template.php(3950) : eval()'d code on line 19

This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.
If i remove $_SERVER['PHP_SELF'] it will allow me to save it.
Reply With Quote
  #4  
Old 02-20-2010, 02:23 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

oh, right, i keep forgetting, I think you need to remove the single quotes, try

Code:
$_SERVER[PHP_SELF]
or

Code:
{$_SERVER['PHP_SELF']}
Reply With Quote
  #5  
Old 02-20-2010, 02:34 PM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

great! removing the ' worked, now i need to know how to add all this or call it?
PHP Code:
<?php
/*************************************************************************
php easy :: whois lookup script
==========================================================================
Author:      php easy code, www.phpeasycode.com
Web Site:    http://www.phpeasycode.com
Contact:     webmaster@phpeasycode.com
*************************************************************************/

$domain $_GET['domain'];

// For the full list of TLDs/Whois servers see http://www.iana.org/domains/root/db/ and http://www.whois365.com/en/listtld/
$whoisservers = array(
    
"ac" =>"whois.nic.ac",
    
"ae" =>"whois.nic.ae",
    
"aero"=>"whois.aero",
    
"af" =>"whois.nic.af",
    
"ag" =>"whois.nic.ag",
    
"al" =>"whois.ripe.net",
    
"am" =>"whois.amnic.net",
    
"arpa" =>"whois.iana.org",
    
"as" =>"whois.nic.as",
    
"asia" =>"whois.nic.asia",
    
"at" =>"whois.nic.at",
    
"au" =>"whois.aunic.net",
    
"az" =>"whois.ripe.net",
    
"ba" =>"whois.ripe.net",
    
"be" =>"whois.dns.be",
    
"bg" =>"whois.register.bg",
    
"bi" =>"whois.nic.bi",
    
"biz" =>"whois.biz",
    
"bj" =>"whois.nic.bj",
    
"br" =>"whois.registro.br",
    
"bt" =>"whois.netnames.net",
    
"by" =>"whois.ripe.net",
    
"bz" =>"whois.belizenic.bz",
    
"ca" =>"whois.cira.ca",
    
"cat" =>"whois.cat",
    
"cc" =>"whois.nic.cc",
    
"cd" =>"whois.nic.cd",
    
"ch" =>"whois.nic.ch",
    
"ci" =>"whois.nic.ci",
    
"ck" =>"whois.nic.ck",
    
"cl" =>"whois.nic.cl",
    
"cn" =>"whois.cnnic.net.cn",
    
"com" =>"whois.verisign-grs.com",
    
"coop" =>"whois.nic.coop",
    
"cx" =>"whois.nic.cx",
    
"cy" =>"whois.ripe.net",
    
"cz" =>"whois.nic.cz",
    
"de" =>"whois.denic.de",
    
"dk" =>"whois.dk-hostmaster.dk",
    
"dm" =>"whois.nic.cx",
    
"dz" =>"whois.ripe.net",
    
"edu" =>"whois.educause.edu",
    
"ee" =>"whois.eenet.ee",
    
"eg" =>"whois.ripe.net",
    
"es" =>"whois.ripe.net",
    
"eu" =>"whois.eu",
    
"fi" =>"whois.ficora.fi",
    
"fo" =>"whois.ripe.net",
    
"fr" =>"whois.nic.fr",
    
"gb" =>"whois.ripe.net",
    
"gd" =>"whois.adamsnames.com",
    
"ge" =>"whois.ripe.net",
    
"gg" =>"whois.channelisles.net",
    
"gi" =>"whois2.afilias-grs.net",
    
"gl" =>"whois.ripe.net",
    
"gm" =>"whois.ripe.net",
    
"gov" =>"whois.nic.gov",
    
"gr" =>"whois.ripe.net",
    
"gs" =>"whois.nic.gs",
    
"gw" =>"whois.nic.gw",
    
"gy" =>"whois.registry.gy",
    
"hk" =>"whois.hkirc.hk",
    
"hm" =>"whois.registry.hm",
    
"hn" =>"whois2.afilias-grs.net",
    
"hr" =>"whois.ripe.net",
    
"hu" =>"whois.nic.hu",
    
"ie" =>"whois.domainregistry.ie",
    
"il" =>"whois.isoc.org.il",
    
"in" =>"whois.inregistry.net",
    
"info" =>"whois.afilias.info",
    
"int" =>"whois.iana.org",
    
"io" =>"whois.nic.io",
    
"iq" =>"vrx.net",
    
"ir" =>"whois.nic.ir",
    
"is" =>"whois.isnic.is",
    
"it" =>"whois.nic.it",
    
"je" =>"whois.channelisles.net",
    
"jobs" =>"jobswhois.verisign-grs.com",
    
"jp" =>"whois.jprs.jp",
    
"ke" =>"whois.kenic.or.ke",
    
"kg" =>"www.domain.kg",
    
"ki" =>"whois.nic.ki",
    
"kr" =>"whois.nic.or.kr",
    
"kz" =>"whois.nic.kz",
    
"la" =>"whois.nic.la",
    
"li" =>"whois.nic.li",
    
"lt" =>"whois.domreg.lt",
    
"lu" =>"whois.dns.lu",
    
"lv" =>"whois.nic.lv",
    
"ly" =>"whois.nic.ly",
    
"ma" =>"whois.iam.net.ma",
    
"mc" =>"whois.ripe.net",
    
"md" =>"whois.ripe.net",
    
"me" =>"whois.meregistry.net",
    
"mg" =>"whois.nic.mg",
    
"mil" =>"whois.nic.mil",
    
"mn" =>"whois.nic.mn",
    
"mobi" =>"whois.dotmobiregistry.net",
    
"ms" =>"whois.adamsnames.tc",
    
"mt" =>"whois.ripe.net",
    
"mu" =>"whois.nic.mu",
    
"museum" =>"whois.museum",
    
"mx" =>"whois.nic.mx",
    
"my" =>"whois.mynic.net.my",
    
"na" =>"whois.na-nic.com.na",
    
"name" =>"whois.nic.name",
    
"net" =>"whois.verisign-grs.net",
    
"nf" =>"whois.nic.nf",
    
"nl" =>"whois.domain-registry.nl",
    
"no" =>"whois.norid.no",
    
"nu" =>"whois.nic.nu",
    
"nz" =>"whois.srs.net.nz",
    
"org" =>"whois.pir.org",
    
"pl" =>"whois.dns.pl",
    
"pm" =>"whois.nic.pm",
    
"pr" =>"whois.uprr.pr",
    
"pro" =>"whois.registrypro.pro",
    
"pt" =>"whois.dns.pt",
    
"re" =>"whois.nic.re",
    
"ro" =>"whois.rotld.ro",
    
"ru" =>"whois.ripn.net",
    
"sa" =>"whois.nic.net.sa",
    
"sb" =>"whois.nic.net.sb",
    
"sc" =>"whois2.afilias-grs.net",
    
"se" =>"whois.iis.se",
    
"sg" =>"whois.nic.net.sg",
    
"sh" =>"whois.nic.sh",
    
"si" =>"whois.arnes.si",
    
"sk" =>"whois.ripe.net",
    
"sm" =>"whois.ripe.net",
    
"st" =>"whois.nic.st",
    
"su" =>"whois.ripn.net",
    
"tc" =>"whois.adamsnames.tc",
    
"tel" =>"whois.nic.tel",
    
"tf" =>"whois.nic.tf",
    
"th" =>"whois.thnic.net",
    
"tj" =>"whois.nic.tj",
    
"tk" =>"whois.dot.tk",
    
"tl" =>"whois.nic.tl",
    
"tm" =>"whois.nic.tm",
    
"tn" =>"whois.ripe.net",
    
"to" =>"whois.tonic.to",
    
"tp" =>"whois.nic.tl",
    
"tr" =>"whois.nic.tr",
    
"travel" =>"whois.nic.travel",
    
"tv" => "tvwhois.verisign-grs.com",
    
"tw" =>"whois.twnic.net.tw",
    
"ua" =>"whois.net.ua",
    
"ug" =>"whois.co.ug",
    
"uk" =>"whois.nic.uk",
    
"us" =>"whois.nic.us",
    
"uy" =>"nic.uy",
    
"uz" =>"whois.cctld.uz",
    
"va" =>"whois.ripe.net",
    
"vc" =>"whois2.afilias-grs.net",
    
"ve" =>"whois.nic.ve",
    
"vg" =>"whois.adamsnames.tc",
    
"wf" =>"whois.nic.wf",
    
"ws" =>"whois.website.ws",
    
"yt" =>"whois.nic.yt",
    
"yu" =>"whois.ripe.net");

function 
LookupDomain($domain){
    global 
$whoisservers;
    
$whoisserver "";
    foreach(
$whoisservers as $tld=>$server) {
        if(
substr($domain, -strlen($tld)) == $tld) {
            
$whoisserver $server;
            break;
        }
    }
    if(!
$whoisserver) {
        return 
"Error: No appropriate Whois server found for $domain domain!";
    }
    
$result QueryWhoisServer($whoisserver$domain);
    if(!
$result) {
        return 
"Error: No results retrieved from $whoisserver server for $domain domain!";
    }
    else {
        
preg_match("/Whois Server: (.*)/"$result$matches);
        
$secondary $matches[1];
        if(
$secondary) {
            
$result QueryWhoisServer($secondary$domain);
            return 
"$domain domain lookup results from $secondary server:\n\n" $result;
        }
        else {
            return 
"$domain domain lookup results from $whoisserver server:\n\n" $result;
        }
    }
}

function 
LookupIP($ip) {
    
$whoisservers = array(
        
//"whois.afrinic.net", // Africa - returns timeout error :-(
        
"whois.apnic.net"// Asia/Pacific - OK :-)
        
"whois.arin.net"// North America - OK :-)
        
"whois.lacnic.net"// Latin America and some Caribbean - OK :-)
        
"whois.ripe.net" // Europe, the Middle East, and Central Asia - OK :-)
    
);
    
$out = array();
    foreach(
$whoisservers as $whoisserver) {
        
$result QueryWhoisServer($whoisserver$ip);
        if(
preg_match("/Country: (.*)/i"$result$matches)) {
            
$out[]= "lookup results for $ip from $whoisserver server:\n\n" $result;
        }
    }
    return 
count($out) . " RESULTS FOUND:\n-------------\n" implode("\n\n-------------\n\n"$out);
}

function 
ValidateIP($ip) {
    
$ipnums explode("."$ip);
    if(
count($ipnums) != 4) {
        return 
false;
    }
    foreach(
$ipnums as $ipnum) {
        if(!
is_numeric($ipnum) || ($ipnum 255)) {
            return 
false;
        }
    }
    return 
$ip;
}

function 
ValidateDomain($domain) {
    if(!
preg_match("/^([-a-z0-9]{2,100})\.([a-z\.]{2,8})$/i"$domain)) {
        return 
false;
    }
    return 
$domain;
}

function 
QueryWhoisServer($whoisserver$domain) {
    
$port 43;
    
$timeout 10;
    
$fp = @fsockopen($whoisserver$port$errno$errstr$timeout) or die("Socket Error " $errno " - " $errstr);
    
fputs($fp$domain "\r\n");
    
$out "";
    while(!
feof($fp)){
        
$out .= fgets($fp);
    }
    
fclose($fp);
    
    return 
$out;
}
?>
Reply With Quote
  #6  
Old 02-20-2010, 03:00 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm...sorry, I guess I'm not sure if you're using a separate php file or not. I guess not or else you'd just put it in there. So the alternative is a plugin. You could just use the global_start hook since your code only defines things and doesn't do stuff on it's own. You'd normally want to find a place that only includes the code when you need it of course.

And hopefully there won't be any variable scope problems.
Reply With Quote
  #7  
Old 02-20-2010, 03:24 PM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I can use a seperate php file no problem, i just don't know how to link the two parts, in my first post it is all together and runs as a stand alone web page, but i removed the stuff in the HTML tags and plonked it in to my newly created template, how do i now link that with the rest of it.....i'm no coder so i'll need a kind of walk through if thats ok?

--------------- Added [DATE]1266687519[/DATE] at [TIME]1266687519[/TIME] ---------------

All the left over code i put in a plugin, used global_start as the hook, my template now looks like this
HTML Code:
$stylevar[htmldoctype]
$iplookup
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>$vboptions[bbtitle]</title>

$headinclude
</head>
<body>
$header

$navbar

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
    <td class="tcat">IP Lookup</td>

</tr>

<tr>
<td><div><form action="$_SERVER[PHP_SELF]">
<p><b><label for="domain">Domain/IP Address:</label></b> <input type="text" name="domain" id="domain" value="$domain"> <input type="submit" value="Lookup"></p>
</form><?
if($domain) {
	$domain = trim($domain);
	if(ValidateIP($domain)) {
		$result = LookupIP($domain);
	}
	elseif(ValidateDomain($domain)) {
		$result = LookupDomain($domain);
	}
	else die("Invalid Input!");
	echo "<pre>\r\n" . $result . "\r\n</pre>\r\n";
}
?>

</div></td></tr> 
</table>

$footer
</body>
</html>
I called the plug in iplookup so used this at the top of the template $iplookup it doesn't bug out but it doesn't display any results?
Reply With Quote
  #8  
Old 02-20-2010, 03:47 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry again (I end up saying that a lot). As is the case all too often when I try to help someone, by the time I got through looking at the code I had forgotten about the very first line of your first post where you posted a link explaining what you're doing. If you've created a separate php file like in those instructions, then you just need to put your "leftover" code in that file somewhere instead of a plugin. At the top should be fine.

The output of your page should come from the

Code:
eval('print_output("' . fetch_template('TEST') . '");');
at the end of the sample page, with TEST replaced by your template, of course.
Reply With Quote
  #9  
Old 02-20-2010, 03:53 PM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Where you say "at the top" do you mean above
PHP Code:
<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
How will the form/button re-call that file to give the results?

--------------- Added [DATE]1266688703[/DATE] at [TIME]1266688703[/TIME] ---------------

I added the rest of that code below <? here's my page http://www.thecodecage.com/forumz/iptest.php i don't get an output to the page when searching an ip?
Reply With Quote
  #10  
Old 02-20-2010, 04:02 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, I guess if I were doing it I'd probably put it just under the comment that says "Start main script".

Looking where you posted above, you need to get rid of some of the stuff out of that template, specifically:

Code:
<?
if($domain) {
	$domain = trim($domain);
	if(ValidateIP($domain)) {
		$result = LookupIP($domain);
	}
	elseif(ValidateDomain($domain)) {
		$result = LookupDomain($domain);
	}
	else die("Invalid Input!");
	echo "<pre>\r\n" . $result . "\r\n</pre>\r\n";
}
?>
Instead you probably want just:

Code:
<if condition="$domain">
   <pre>
   $result
   </pre>
</if>
In your template (replacing the part between the <? and ?>) and

Code:
	
        $domain = trim($domain);
	if(ValidateIP($domain)) {
		$result = LookupIP($domain);
	}
	elseif(ValidateDomain($domain)) {
		$result = LookupDomain($domain);
	}
	else $result = "Invalid Input!";
in your php file, under the "extra" code you're inserting, before the template eval stuff.


To answer your other question, I haven't figured out all the code so I don't know how it's supposed to do it's thing when you submit the form. Because the action is "PHP_SELF" I figure it must load the same page again.

ETA: I added an <if> tag to the template changes above, and that answers the question, I think - that part only appears if $domain is defined, so it's just the same page loaded again when submit is pressed.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:54 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04422 seconds
  • Memory Usage 2,482KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (7)bbcode_code
  • (3)bbcode_html
  • (3)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete