Exemple #1
0
function hg_getip()
{
    global $_INPUT;
    if ($_INPUT['lpip']) {
        if (hg_checkip($_INPUT['lpip'])) {
            return $_INPUT['lpip'];
        }
    }
    if (isset($_SERVER)) {
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $realip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } elseif ($_SERVER['HTTP_X_REAL_IP']) {
            $realip = $_SERVER['HTTP_X_REAL_IP'];
        } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
            $realip = $_SERVER['HTTP_CLIENT_IP'];
        } else {
            $realip = $_SERVER['REMOTE_ADDR'];
        }
    } else {
        if (getenv("HTTP_X_FORWARDED_FOR")) {
            $realip = getenv("HTTP_X_FORWARDED_FOR");
        } elseif (getenv('HTTP_X_REAL_IP')) {
            $realip = getenv('HTTP_X_REAL_IP');
        } elseif (getenv("HTTP_CLIENT_IP")) {
            $realip = getenv("HTTP_CLIENT_IP");
        } else {
            $realip = getenv("REMOTE_ADDR");
        }
    }
    $realip = explode(',', $realip);
    return $realip[0];
}
Exemple #2
0
 public function update()
 {
     if (!$this->input['id']) {
         $this->errorOutput(NOID);
     }
     $fields = ' SET  ';
     if ($this->input['name']) {
         $sql = " SELECT count(*) as total FROM " . DB_PREFIX . "server WHERE name = '" . urldecode($this->input['name']) . "' AND id != '" . intval($this->input['id']) . "'";
         $arr = $this->db->query_first($sql);
         if (intval($arr['total']) >= 1) {
             $this->errorOutput('服务器已经存在');
         }
         $fields .= '  name = \'' . urldecode($this->input['name']) . '\',';
     } else {
         $this->errorOutput('服务器名称不能为空');
     }
     if ($this->input['uniqueid']) {
         $sql = " SELECT count(*) as total FROM " . DB_PREFIX . "server WHERE uniqueid = '" . urldecode($this->input['uniqueid']) . "' AND id != '" . intval($this->input['id']) . "'";
         $arr = $this->db->query_first($sql);
         if (intval($arr['total']) >= 1) {
             $this->errorOutput('标识已经存在');
         }
         $fields .= '  uniqueid = \'' . urldecode($this->input['uniqueid']) . '\',';
     } else {
         $this->errorOutput('标识不能为空');
     }
     if ($this->input['ip']) {
         if (!hg_checkip(urldecode($this->input['ip']))) {
             $this->errorOutput('ip有误');
         }
         $fields .= '  ip = \'' . urldecode($this->input['ip']) . '\',';
     }
     if ($this->input['outside_ip']) {
         if (!hg_checkip(urldecode($this->input['outside_ip']))) {
             $this->errorOutput('外网ip有误');
         }
         $fields .= '  outside_ip = \'' . urldecode($this->input['outside_ip']) . '\',';
     }
     if ($this->input['port']) {
         $fields .= '  port = \'' . intval($this->input['port']) . '\',';
     }
     if ($this->input['user']) {
         $fields .= '  user = \'' . urldecode($this->input['user']) . '\',';
     }
     if ($this->input['password']) {
         $fields .= '  password = \'' . hg_encript_str(urldecode($this->input['password'])) . '\',';
     }
     if ($this->input['iscur']) {
         $fields .= '  iscur = 1,';
     } else {
         $fields .= '  iscur = 0,';
     }
     $fields .= '  update_time = \'' . TIMENOW . '\'';
     $sql = "UPDATE " . DB_PREFIX . 'server ' . $fields . '  WHERE  id = ' . intval($this->input['id']);
     $this->db->query($sql);
     //返回数据
     $sql = "SELECT * FROM " . DB_PREFIX . "server WHERE id = '" . intval($this->input['id']) . "'";
     $ret = $this->db->query_first($sql);
     $ret['password'] = hg_encript_str($ret['password'], 0);
     $this->addItem($ret);
     $this->output();
 }
Exemple #3
0
 public function domodify_serv_hosts()
 {
     $ip = trim($this->input['ip']);
     $domain = trim($this->input['domain']);
     if (!hg_checkip($ip)) {
         $this->modify_serv_hosts('ip格式不正确');
     }
     if (!$domain || strstr($domain, '/')) {
         $this->modify_serv_hosts('域名格式不正确');
     }
     $sql = 'SELECT * FROM ' . DB_PREFIX . "server_domain sd LEFT JOIN " . DB_PREFIX . 'server s ON sd.server_id=s.id';
     $q = $this->db->query($sql);
     $hostscontent = '';
     $ipdomains = array();
     $alldomains = array();
     while ($r = $this->db->fetch_array($q)) {
         $hostscontent .= "\n" . $r['ip'] . '	' . $r['domain'];
         $ipdomains[$r['ip']][] = $r['domain'];
         $alldomains[] = $r['domain'];
     }
     if ($ipdomains) {
         foreach ($ipdomains as $sip => $domains) {
             $app = array('hosts' => $sip, 'ip' => $sip, 'port' => 6233);
             $socket = new hgSocket();
             $con = $socket->connect($app['ip'], $app['port']);
             if (!intval($con)) {
                 echo $app['ip'] . '服务器无法连接,请确认服务器ip是否正确或服务程序hogeMonitor.py是否监听在' . $app['ip'] . ':' . $app['port'] . '上<br />';
                 $socket->close();
                 continue;
             }
             $socket->close();
             $servhosts = get_serv_file($app, '/etc/hosts');
             $existshosts = hg_get_hosts($servhosts);
             unset($existshosts[$domain]);
             $servhosts = '';
             if ($existshosts) {
                 foreach ($existshosts as $dm => $dip) {
                     $servhosts .= "\n" . $dip . '	' . $dm;
                 }
             }
             $servhosts .= "\n" . $ip . '	' . $domain;
             write_serv_file($app, '/etc/hosts', $servhosts);
             echo $sip . 'hosts已更改<br />';
         }
     }
     $app = array('hosts' => $ip, 'ip' => $ip, 'port' => 6233);
     $socket = new hgSocket();
     $con = $socket->connect($app['ip'], $app['port']);
     if (!intval($con)) {
         echo $app['ip'] . '服务器无法连接,请确认服务器ip是否正确或服务程序hogeMonitor.py是否监听在' . $app['ip'] . ':' . $app['port'] . '上<br />';
         $socket->close();
         exit;
     }
     $socket->close();
     $servhosts = get_serv_file($app, '/etc/hosts');
     $existshosts = hg_get_hosts($servhosts);
     unset($existshosts[$domain]);
     if ($alldomains) {
         foreach ($alldomains as $dm) {
             unset($existshosts[$dm]);
         }
     }
     $servhosts = '';
     if ($existshosts) {
         foreach ($existshosts as $dm => $dip) {
             $servhosts .= "\n" . $dip . '	' . $dm;
         }
     }
     $servhosts .= "\n" . $ip . '	' . $domain;
     write_serv_file($app, '/etc/hosts', $hostscontent . $servhosts);
     echo $ip . 'hosts已更改<br />';
 }