Exemple #1
0
 function updateInformation($param)
 {
     if (isset($param['networkgateway'])) {
         $param['networkgateway'] = trim($param['networkgateway']);
         if ($param['networkgateway']) {
             validate_ipaddress($param['networkgateway'], 'networkgateway');
         }
     }
     return $param;
 }
 static function isValidIpaddress($ip)
 {
     return validate_ipaddress($ip);
 }
Exemple #3
0
function validate_ipaddress_and_throw($ip, $variable)
{
    if (!validate_ipaddress($ip)) {
        throw new lxException('Invalid IP address: ' . $ip, $variable);
    }
}
 function checkPort()
 {
     global $gbl, $sgbl, $login, $ghtml;
     $num = $this->portnumber;
     $sname = $this->getParentO()->servername;
     dprint("Checking Port {$sname}: {$num}\n");
     print_time("checkprot");
     $sip = gethostbyname($sname);
     if (validate_ipaddress($sip)) {
         $res = fsockopen($sip, $num, $erno, $erstr, 10);
     } else {
         $res = null;
         $erno = 1;
         $erstr = "Dns failed";
     }
     print_time("checkprot", "Fsockopen");
     $name = $sgbl->thisserver . "___" . $this->nname;
     $obj = new PortStatus(null, "localhost", $name);
     $obj->initThisDef();
     if (!$res) {
         $obj->portstatus = 'off';
         $obj->errornumber = $erno;
         $obj->errorstring = $erstr;
     } else {
         fclose($res);
         $obj->portstatus = 'on';
     }
     $obj->portnname = $this->nname;
     $obj->servername = $sgbl->thisserver;
     $obj->updatetime = time();
     $obj->setUpdateSubaction();
     return $obj;
 }
function do_monitor_list($portmonlist, &$serverhistlist)
{
    global $global_ip_array;
    global $global_remoteserver;
    global $global_remoteport;
    $loopcount = 0;
    while (true) {
        $count = 0;
        $loopcount++;
        foreach ($portmonlist as $s => &$serv) {
            foreach ($serv as $k => &$data) {
                $nname = $k;
                if ($data[4] === 'done') {
                    continue;
                }
                if (isset($global_ip_array[$data[0]])) {
                    $ip = $global_ip_array[$data[0]];
                } else {
                    $ip = "Silly screwup. Can't find dns for {$data[0]}\n";
                }
                if (!validate_ipaddress($ip)) {
                    //print("failed Dns $ip for *{$data[0]}*\n");
                    $obj['portstatus'] = 'off';
                    //$obj['errornumber'] = 100;
                    $obj['errorstring'] = "DNS failed for {$ip}";
                    $obj['portnname'] = $nname;
                    $data[2] = null;
                    $data[4] = 'done';
                    $serverhistlist[$s][$k] = $obj;
                    socket_clear_error();
                    continue;
                }
                $ret = socket_connect($data[2], $ip, $data[1]);
                $err = socket_last_error($data[2]);
                if ($ret === true || $err === 10056 || $err === 0) {
                    fclose($data[2]);
                    $data[2] = null;
                    $data[4] = 'done';
                    $obj['portstatus'] = 'on';
                    $obj['errorstring'] = "SSS";
                    //	$obj['errornumber'] = 0;
                    $obj['portnname'] = $nname;
                    $serverhistlist[$s][$k] = $obj;
                    continue;
                }
                //print("$s: $k, $ret, $err $here\n");
                if ($err === 115 || $err === 114 || $err === 10035 || $err === 10037) {
                    $data[4] = 'notdone';
                    $count++;
                    if ($loopcount < 14) {
                        //print("Timeout not reached ... " . time() . " $startmon\n");
                    } else {
                        $obj['portstatus'] = 'off';
                        //$obj['errornumber'] = $err;
                        $obj['errorstring'] = "Timeout";
                        $obj['portnname'] = $nname;
                        $data[2] = null;
                        $data[4] = 'done';
                        $serverhistlist[$s][$k] = $obj;
                        socket_clear_error();
                    }
                    continue;
                }
                //$obj['errornumber'] = $err;
                $strerror = socket_strerror($err);
                $vrttt = var_export($ret, true);
                if (!$err || !$strerror || $strerror === "Success") {
                    $obj['errorstring'] = "Got NO error. Errno {$err}... ret was {$vrttt}";
                    $obj['portstatus'] = 'on';
                } else {
                    $obj['errorstring'] = "({$err}) {$strerror} (ret: {$vrttt})";
                    $obj['portstatus'] = 'off';
                }
                $obj['portnname'] = $nname;
                $data[2] = null;
                $data[4] = 'done';
                $serverhistlist[$s][$k] = $obj;
                socket_clear_error();
            }
        }
        if ($count === 0) {
            break;
        }
        sleep(1);
    }
    return $serverhistlist;
}
Exemple #6
0
function validate_ipaddress_and_throw($ip, $variable)
{
    if (!validate_ipaddress($ip)) {
        throw new lxException("invalid_ipaddress", $variable);
    }
}