2017-08-18 4 views
1

私はどこかで見つけた私のウェブサイトにphp whois domain availability checkスクリプトをインストールしたいと思います。PHPドメイン可用性スクリプトexec()関数の代替

私は& "linux"モードに切り替えることができるwhois_class.phpファイルを持っています。

"win"モードをオンにすると、Windows OSを使用しているので、ローカルホストで正常に動作します。

私はそれをサーバにアップロードすると、私のサーバはLinuxサーバなので動作しなくなります。

私はそれを "linux"モードに切り替えて、whois_class.phpを再アップロードする必要があります。これは正常に動作することが期待されていましたが、Linuxモードでは、スクリプトの開発者は私のホストがセキュリティの目的で無効にしたexec()関数を使用していました。

私は、サーバープラットフォームをLinuxからWindowsに変更するだけです。しかし、それは混乱するでしょう。

私はこのスクリプトをWindows OSのlocalhost上で動作するように、Linuxサーバー上でスムーズに動作させる方法を探していました。スクリプトを実行させるための変更や変更は感謝します。

whois_class.php

<?php 
class Whois_domain { 

    var $possible_tlds; 
    var $whois_server; 
    var $free_string; 
    var $whois_param; 
    var $domain; 
    var $tld; 
    var $compl_domain; 
    var $full_info; 
    var $msg; 
    var $info; 
    var $os_system = "win"; // switch between "linux" and "win" 

    function Whois_domain() { 
     $this->info = ""; 
     $this->msg = ""; 
    } 
    function process() { 
     if ($this->create_domain()) { 
      if ($this->full_info == "yes") { 
       $this->get_domain_info(); 
      } else { 
       if ($this->check_only() == 1) { 
        $this->msg = "<p style='font-size: 16px'>The domain name: <font color='#000'>".$this->compl_domain."</font> is <font color='#2ec62e'>available</font>.</p>"; 
        return true; 
       } elseif ($this->check_only() == 0) { 
        $this->msg = "<p style='font-size: 16px'>The domain name: <font color='#000'>".$this->compl_domain."</font> is <font color='red'>registered</font>.</p>"; 
        return false; 
       } else { 
        $this->msg = "<p style='font-size: 16px'>There was something wrong, try it again.</p>"; 
       } 
      } 
     } else { 
      $this->msg = "<p style='font-size: 16px'>Only letters, numbers and hyphens (-) are valid!</p>"; 
     } 
    } 
    function check_entry() { 
     if (preg_match("/^([a-z0-9]+(\-?[a-z0-9]*)){2,63}$/i", $this->domain)) { 
      return true; 
     } else { 
      return false; 
     } 
    } 
    function create_tld_select() { 
     $menu = "<select id=\"tld\" name=\"tld\" style=\"margin-left:0; width: 100px; margin-top: 20px; border-radius: 5px\">\n"; 
     foreach ($this->possible_tlds as $val) { 
      $menu .= " <option value=\"".$val."\""; 
      $menu .= (isset($_POST['tld']) && $_POST['tld'] == $val) ? " selected=\"selected\">" : ">"; 
      $menu .= $val."</option>\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() { 
     $data = $this->get_whois_data(); 
     if (is_array($data)) { 
      $found = 0; 
      foreach ($data as $val) { 
       if (preg_match('/'.$this->free_string.'/', $val)) { 
        $found = 1; 
       } 
      } 
      return $found; 
     } else { 
      $this->msg = "<p style='font-size: 16px'>Error, please try it again.</p>"; 
     } 
    } 
    function get_domain_info() { 
     if ($this->create_domain()) { 
      $data = ($this->tld == "nl") ? $this->get_whois_data(true) : $this->get_whois_data(); 
      //print_r($data); 
      if (is_array($data)) { 
       foreach ($data as $val) { 
        if (eregi($this->free_string, $val)) { 
         $this->msg = "<p style='font-size: 16px'>The domain name: <font color='#000'>".$this->compl_domain."</font> is <font color='#2ec62e'>available</font>.</p>"; 
         $this->info = ""; 
         break; 
        } 
        $this->info .= $val; 
       } 
      } else { 
       $this->msg = "<p style='font-size: 16px'>Error, please try it again.</p>"; 
      } 
     } else { 
      $this->msg = "<p style='font-size: 16px'>Only letters, numbers and hyphens (-) are valid!</p>"; 
     } 
    } 
    function get_whois_data($empty_param = false) { 
    // the parameter is new since version 1.20 and is used for .nl (dutch) domains only 
     if ($empty_param) { 
      $this->whois_param = ""; 
     } 
     if ($this->tld == "de") $this->os_system = "win"; // this tld must be queried with fsock otherwise it will not work 
     if ($this->os_system == "win") { 
      $connection = @fsockopen($this->whois_server, 43); 
      if (!$connection) { 
       unset($connection); 
       $this->msg = "<p style='font-size: 16px'>Can't connect to the server!</p>"; 
       return; 
      } else { 
       sleep(2); 
       fputs($connection, $this->whois_param.$this->compl_domain."\r\n"); 
       while (!feof($connection)) { 
        $buffer[] = fgets($connection, 4096); 
       } 
       fclose($connection); 
      } 
     } else { 
      $string = "whois -h ".$this->whois_server." \"".$this->whois_param.$this->compl_domain."\""; 
      $string = str_replace (";", "", $string).";"; 
      exec($string, $buffer); 
     } 
     if (isset($buffer)) { 
      //print_r($buffer); 
      return $buffer; 
     } else { 
      $this->msg = "<p style='font-size: 16px'>Can't retrieve data from the server!</p>"; 
     } 
    } 
} 
?> 

問題がplenty of functions related to program executionがありますが、ここで私のホストによって

if ($this->os_system == "win") { 
     $connection = @fsockopen($this->whois_server, 43); 
     if (!$connection) { 
      unset($connection); 
      $this->msg = "<p style='font-size: 16px'>Can't connect to the server!</p>"; 
      return; 
     } else { 
      sleep(2); 
      fputs($connection, $this->whois_param.$this->compl_domain."\r\n"); 
      while (!feof($connection)) { 
       $buffer[] = fgets($connection, 4096); 
      } 
      fclose($connection); 
     } 
    } else { 
     $string = "whois -h ".$this->whois_server." \"".$this->whois_param.$this->compl_domain."\""; 
     $string = str_replace (";", "", $string).";"; 
     exec($string, $buffer); 
    } 

無効機能

system,exec,shell_exec,passthru,popen,proc_open,pcntl_exec,highlight_file,show_source,symlink,link,posix_getpwuid,posix_getpwnam,posix_getgrgid,posix_getgrnam,posix_kill,posix_mkfifo,posix_getrlimit 
+0

Linuxでwinメソッドを使ってみましたか?例えば'if'行と' else'ブロックを削除します。条件を 'if(true)'に変更して – cmbuckley

+0

をテストするか、単に '$ os_system =" win "'を設定するだけです??同じことbro ..同じ結果を与えるだろう...! @ cmbuckley –

+0

今、私はそのサーバーが何であるか知りたいですか?共有ホスティング?管理されたvServer? – Soundz

答えて

0

です。しかし、あなたの設定で無効になっている機能を確認する必要があります:

var_dump(ini_get("disable_functions")); 
+0

私の編集を参照してください。私は私のホストによって無効にされている機能を入れている。 –