Example #1
0
 /**
  * Creates and initiates a socket connection
  *
  * @throws ConnectErrorException
  * @param  array $config
  * @return void
  */
 private function connect($config)
 {
     $parsed_socket = parse_url('tcp://' . $config['server']);
     if (isset($parsed_socket['port'])) {
         $config['port'] = $parsed_socket['port'];
     }
     $errno = $errstr = null;
     $this->sock = @stream_socket_client('tcp://' . $config['server'] . ':' . $config['port'], $errno, $errstr, 30);
     if (!is_resource($this->sock)) {
         throw \WhoisParser\AbstractException::factory('ConnectError', 'Unable to connect to ' . $config['server'] . ':' . $config['port'] . ' or missing configuration for this template.');
     }
     $this->connected = true;
 }
Example #2
0
 /**
  * Parses rawdata from whois server and call postProcess if exists afterwards
  * 
  * @throws NoTemplateException
  * @return void
  */
 private function parse()
 {
     $Config = $this->Config->getCurrent();
     $Template = AbstractTemplate::factory($Config['template']);
     // If Template is null then we do not have a template for that, but we
     // can still proceed to the end with just the rawdata
     if ($Template instanceof AbstractTemplate) {
         $this->parseTemplate($Template);
         // set rawdata to Result - this happens here because sometimes we
         // have to fix the rawdata as well in postProcess
         $this->Result->addItem('rawdata', explode("\n", $this->rawdata));
         // check availability upon type - IP addresses are always registered
         if (isset($Template->available) && $Template->available != '') {
             preg_match_all($Template->available, $this->rawdata, $matches);
             $this->Result->addItem('registered', empty($matches[0]));
         }
         // set registered to Result
         $this->Result->addItem('registered', isset($this->Result->registered) ? $this->Result->registered : false);
         if (!isset($this->Result->whoisserver)) {
             $this->Result->addItem('whoisserver', $Config['server']);
         }
         // start post processing
         $Template->postProcess($this);
         // set name to Result
         if (isset($this->Query->tld) && !isset($this->Query->fqdn)) {
             $this->Result->addItem('name', $this->Query->tld);
         } elseif (isset($this->Query->ip)) {
             $this->Result->addItem('name', $this->Query->ip);
         } elseif (isset($this->Query->asn)) {
             $this->Result->addItem('name', $this->Query->asn);
         } else {
             $this->Result->addItem('name', $this->Query->fqdn);
             $this->Result->addItem('idnName', $this->Query->idnFqdn);
         }
     } else {
         throw \WhoisParser\AbstractException::factory('NoTemplate', 'Template ' . $Config['template'] . ' could not be found.');
     }
 }