Javascript 通过PHP远程访问其他服务器

Javascript 通过PHP远程访问其他服务器,javascript,php,linux,windows,apache,Javascript,Php,Linux,Windows,Apache,我有两台服务器 A:网络服务器 B:DNS服务器 我有下面的代码,我把它放在服务器A中 <?php $submit = $_POST['submit']; if($submit == "Restart") { if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist"); if(!($con = ssh2_connect("x.x.x.x", 22))){ echo "fail: una

我有两台服务器

  • A:网络服务器
  • B:DNS服务器
我有下面的代码,我把它放在服务器A中

<?php $submit = $_POST['submit'];
if($submit == "Restart") {
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't
exist");
if(!($con = ssh2_connect("x.x.x.x", 22))){
echo "fail: unable to establish connection\n";
} else {
if(!ssh2_auth_password($con, "user", "password")) {
    echo "fail: unable to authenticate\n";
} else {
    // allright, we're in!
    echo "OK: logged in...end Restart\n";

    // execute a command
    if (!($stream = ssh2_exec($con, "service bind9 restart" ))) {
        echo "fail: unable to execute command\n";
    } else {
        // collect returning data from command
        stream_set_blocking($stream, true);
        $data = "";
        while ($buf = fread($stream,4096)) {
            $data .= $buf;
        }
        fclose($stream);
        echo "<pre>";
        echo $data; //Prints the output
        echo "</pre>"; 
        } 
      } 
    } 
  } echo '<form action="" method="post"
    <input type="submit" name="submit" value="Restart"></form>';
  ?>

我只想重新启动服务bind9您需要sudo权限才能重新启动服务bind9,我敢打赌,apache/php用户是不允许这样做的。。。谷歌搜索bash脚本和SUID位。。我祈祷你知道你想要什么也不知道为什么。。。我也有这个问题,结束了制作bash脚本并运行bash脚本启动bind时查看/var/log/syslog,看看它是否抛出了导致问题的任何特定错误(tail-f/var/log/syslog)。donal123哈哈。。谢谢你的祈祷,谢谢你的建议谢谢,案子已经解决了,我只是改成了root,现在脚本已经完成了