User Tools

Site Tools


whois

NP_Whois.php

NP_Whois is a simple plugin that adds a domain search form to your site and prints the whois data for searched domains. You may also want to replace the servers list. Here's a complete list with servers you can choose.

Feedback

Post bug reports and suggestions here at the Nucleus forum: http://forum.nucleuscms.org/viewtopic.php?t=5150

Instructions

  1. Save the code below as NP_Whois.php and upload it to your plugins directory.
  2. Install the plugin.
  3. Put <%~Whois%> inside a skin.
  4. Done!

Plugin code

<?php
/************************************************************************
NP_Whois is based on:
Whois domain - v1.10
Copyright (C) 2004 - Olaf Lederer
available at http://www.finalwebsites.com
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
*************************************************************************/
 
class NP_Whois extends NucleusPlugin {
   function getName()       { return 'Whois'; }
   function getAuthor()     { return 'moraes (based on class by Olaf Lederer)'; }
   function getURL()        { return 'http://www.tipos.com.br'; }
   function getVersion()    { return '0.1'; }
   function getDescription() { return 'Check the whois information for domain names.'; }
   function supportsFeature($what) {
      switch($what) {
         case 'SqlTablePrefix': return 1;
         default: return 0;
      }
   }
 
   var $possible_tlds;
   var $free_string;
   var $whois_server;
   var $domain;
   var $tld;
   var $compl_domain;
   var $full_info = "no";
   var $msg;
   var $info;
 
   function NP_Whois() {
      $this->info = "";
      $this->msg = "";
   }
 
   function process() {
      if ($this->full_info == "yes") {
         $this->get_domain_info();
      } else {
         $this->check_only();
      }
   }
 
   function check_entry() {
      if (preg_match("/^[A-Za-z0-9]+(\-?[A-za-z0-9]*){1,63}$/", $this->domain)) {
         return true;
      } else {
         return false;
      }
   }
 
   function create_tld_select() {
      $menu = "<select name=\"tld\">\n";
      $possible_tlds = array_keys($this->getServers());
      foreach ($possible_tlds as $val) {
         $menu .= "  <option value=\"".$val."\"";
         $tld = postVar('tld');
         $menu .= ((isset($tld)) && ($tld == $val)) ? " selected>" : ">";
         $menu .= $val."\n";
      }
      $menu .= "</select>\n";
      return $menu;
   }
 
   function create_domain() {
      if ($this->check_entry()) {
         $this->domain = strtolower($this->domain);
         $this->compl_domain = $this->domain.".".$this->tld;
         return true;
      } else {
         return false;
      }
   }
 
   function check_only() {
      if ($this->create_domain()) {
         if ($this->get_whois_data()) {
            $this->msg = "The domain name: <b>".$this->compl_domain."</b> is registered";
         } else {
            $this->msg = "The domain name: <b>".$this->compl_domain."</b> is free.";
         }
      } else {
         $this->msg = "Only letters, numbers and hyphens (-) are valid!";
      }
   }
 
   function get_domain_info() {
      if ($this->create_domain()) {
         if ($this->get_whois_data()) {
            $info_array = split("\n", $this->get_whois_data());
            for ($i = 0; $i < count($info_array); $i++) {
               $this->info .= $info_array[$i]."\n";
            }   
         }
      } else {
         $this->msg = "Only letters, numbers and hyphens (-) are valid!";
      }
   }
 
   function get_whois_data() {
      $buffer = "";
      $connection = fsockopen($this->whois_server, 43, $errno, $errstr, 10);
      if (!$connection) {
         $this->msg = "Can't connect to the server!";
         break;
      } else {
         fputs($connection, $this->compl_domain."\r\n");
         while (!feof($connection)) {
            $buffer .= fgets($connection, 4096);
         }
         fclose($connection);
      }
      if ($this->full_info == "no") {
         if (eregi($this->free_string, $buffer)) {
            return false;
         } else {
            return true;
         }
      } else {
         if (eregi($this->free_string, $buffer)) {
            $this->msg = "The domain name: <b>".$this->compl_domain."</b> is free.";
            return false;
         } else {
            return $buffer;
         }
      }
   }
 
	function getServers() {
		// This is the list with servers which are used by the plugin
		// Add here more servers if you like!
		// about the values for the key "free": this is the string (answer) what the server returns if there is no match.
		$servers['com']['address'] = "whois.crsnic.net";
		$servers['com']['free'] = "No match";
 
		$servers['info']['address'] = "whois.afilias.net";
		$servers['info']['free'] = "NOT FOUND";
 
		$servers['org']['address'] = "whois.pir.org";
		$servers['org']['free'] = "NOT FOUND";
 
		$servers['nl']['address'] = "whois.domain-registry.nl";
		$servers['nl']['free'] = "is free";
 
		$servers['be']['address'] = "whois.ripe.net";
		$servers['be']['free'] = "No such domain";
 
		$servers['biz']['address'] = "whois.nic.biz";
		$servers['biz']['free'] = "Not found";
 
		$servers['net']['address'] = "whois.opensrs.net";
		$servers['net']['free'] = "Can't get information on non-local domain";
 
		$servers['com.br']['address'] = "whois.registro.br";
		$servers['com.br']['free'] = "No match";
 
      return $servers;
   }
 
   function doSkinVar($skinType) {
      $all_info = postVar('all_info');
      $whois = postVar('whois');
 
      echo '<p>Enter a domain name and select the type of tld you want to check.<br />';
      echo '<form action="" method="post">';
      echo '<input type="hidden" name="whois" value="1" />';
      echo '<input type="text" name="domain" size="14" maxlength="63" value="'.postVar('domain').'" />';
      // this method generates the select menu woth all tld's
      echo $this->create_tld_select();
      echo '<br />';
      echo '<input name="all_info" type="checkbox" value="yes"';
      if($all_info == 'yes') {
         echo ' checked';
      }
      echo '>show complete info<br />';
      echo '<input name="submit" type="submit" value="check domain">';
      echo '</form></p>';
 
      if (isset($whois)) {
         $this->tld = postVar('tld');
         $this->domain = postVar('domain');
         $servers = $this->getServers();
         $this->possible_tlds = array_keys($servers);
         $this->free_string = $servers[postVar('tld')]['free'];
         $this->whois_server = $servers[postVar('tld')]['address'];
 
		 // between "no" and "yes" to get all whois information
         $this->full_info = (isset($all_info)) ? $all_info : 'no';
         $this->process();
 
         echo ($this->msg != "") ? '<p>'.$this->msg.'</p>' : "";
         // this will show up all info from the whois server
         if ($this->info != "") {
            echo '<h1>Whois '.$this->compl_domain.'?</h1>';
            echo '<p>'.nl2br($this->info).'</p>';
         }
      }
   }
}
?>

History

  • version 0.1 (november 12, 2004): initial version
whois.txt · Last modified: 2006/07/05 13:03 (external edit)