PHP域可用性脚本exec()函数替代

时间:2017-08-18 14:38:21

标签: php linux

我想在我的网站上安装一个php whois域可用性检查脚本,我在某处找到了。

它有一个whois_class.php文件,允许我在“win”和&之间切换。 “linux”模式。

当我打开“win”模式时,它在我的localhost中工作正常,因为我使用的是Windows操作系统。

但是当我将它上传到服务器时,它停止工作,因为我的服务器是Linux服务器。

所以我必须将其切换到“linux”模式并重新上传whois_class.php。预计这可以正常工作,但对于linux模式,脚本的开发人员使用了exec()函数,我的主机已将其禁用以用于安全目的。

因此,我猜的唯一选择是将服务器平台从Linux更改为Windows。但是,那将是一团糟。

我正在寻找一种方法,我可以使用这个脚本在我的Linux服务器上顺利运行,就像它在Windows操作系统中的本地主机上运行一样。对脚本进行任何更改或修改以使其运行将不胜感激。

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>";
        }
    }
}
?>

问题出在这里

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

1 个答案:

答案 0 :(得分:0)

plenty of functions related to program execution。但是,您应该检查您的设置中禁用了哪些其他功能:

var_dump(ini_get("disable_functions"));