Exemplo n.º 1
0
function getOurHostID()
{
    $db = gs_db_slave_connect();
    $rs = $db->execute('SELECT `id`, `host` FROM `hosts`');
    $hosts = array();
    while ($r = $rs->fetchRow()) {
        $hosts[] = $r;
    }
    $ips = array();
    foreach ($hosts as $h) {
        $h['host'] = trim(normalizeIPs($h['host']));
        if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $h['host'])) {
            $ips[$h['host']] = $h['id'];
        } else {
            $tmp = getHostByNameL($h['host']);
            if (is_array($tmp)) {
                foreach ($tmp as $ip) {
                    $ips[normalizeIPs($ip)] = $h['id'];
                }
            }
        }
    }
    unset($hosts);
    $ifconfig = normalizeIPs(trim(@shell_exec('ifconfig 2>>/dev/null')));
    foreach ($ips as $ip => $hostid) {
        if (strPos($ifconfig, $ip) !== false) {
            return $hostid;
        }
    }
    return false;
}
Exemplo n.º 2
0
 function connect($host, $port = null, $user = '', $pass = '')
 {
     $this->disconnect();
     $this->_host = $host;
     $this->_port = $port;
     if (in_array($user, array('', null, false), true)) {
         $user = '******';
         $pass = '******';
     }
     $this->_user = $user;
     $this->_pass = $pass;
     if (!extension_loaded('ftp')) {
         gs_log(GS_LOG_WARNING, 'ftp extension for PHP not available');
         $this->_conn_failed = true;
         return false;
     }
     if (!preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$/', $this->_host)) {
         $ips = getHostByNameL($this->_host);
         # for some strange reason this is a lot faster than to
         # leave the lookup up to ftp_connect()
         if (!is_array($ips) || count($ips) < 1) {
             gs_log(GS_LOG_WARNING, 'Failed to resolve "' . $this->_host . '"');
             $this->_conn_failed = true;
             return false;
         }
         $this->_host = $ips[0];
     }
     $this->_conn = ftp_connect($this->_host, $this->_port, 4);
     if (!$this->_conn) {
         gs_log(GS_LOG_NOTICE, 'Failed to connect to ftp://' . $this->_host);
         $this->_conn_failed = true;
         return false;
     }
     @ftp_set_option($this->_conn, FTP_TIMEOUT_SEC, 3);
     if (!@ftp_login($this->_conn, $this->_user, $this->_pass)) {
         gs_log(GS_LOG_NOTICE, 'Failed to log in at ftp://' . $this->_host);
         $this->_conn_failed = true;
         @ftp_close($this->_conn);
         return false;
     }
     $this->_connected = true;
     return true;
 }