コード例 #1
0
ファイル: lxportmonitor.php プロジェクト: lonelywoolf/hypervm
function monitor_main()
{
    global $gbl, $sgbl, $login, $ghtml;
    global $argv;
    global $global_ip_array;
    global $global_remoteserver;
    global $global_remoteport;
    error_reporting(E_ALL);
    $list = parse_opt($argv);
    if (isset($list['data-server'])) {
        $global_remoteserver = $list['data-server'];
        $global_remoteport = "8888";
    } else {
        $global_remoteserver = "localhost";
        $global_remoteport = "5558";
    }
    if (false) {
        if (function_exists("posix_getpwnam")) {
            if (!isset($list['switch-user'])) {
                print "Needs a non-privileged user to be suplied as --switch-user=<user>... Using lxlabs\n";
                $list['switch-user'] = '******';
            }
            $pw = posix_getpwnam($list['switch-user']);
            if (!$pw) {
                print "User {$list['switch-user']} doesnt exist. Please create it\n\n\n\n";
                exit;
            }
            posix_setuid($pw['uid']);
            posix_setgid($pw['gid']);
        }
    }
    $sgbl->thisserver = get_my_name();
    $list = get_data_from_server();
    if (!$list) {
        print "No list from the server...\n";
    }
    dprintr($list);
    getDnsesFirst($list);
    $oldserverhistlist = null;
    $maincount = 0;
    while (1) {
        $maincount++;
        $serverhistlist = null;
        $sendserverhistlist = null;
        $startmaintime = time();
        foreach ($list as $l) {
            $ports = $l['monitorport_l'];
            $porthistlist = null;
            foreach ($ports as $p) {
                if (isset($portmonlist[$l['nname']][$p['nname']][2])) {
                    print "Socket Already exists... \n";
                    socket_close($portmonlist[$l['nname']][$p['nname']][2]);
                }
                $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
                socket_set_nonblock($socket);
                $portmonlist[$l['nname']][$p['nname']] = array($l['servername'], $p['portnumber'], $socket);
            }
        }
        $serverhistlist = null;
        dprintr($portmonlist);
        do_monitor_list($portmonlist, $serverhistlist);
        $portmonlist = prepare_error_portmonlist($serverhistlist);
        dprintr("Second try\n\n");
        dprintr($portmonlist);
        sleep(1);
        do_monitor_list($portmonlist, $serverhistlist);
        $endmaintime = time();
        if ($oldserverhistlist) {
            foreach ($serverhistlist as $s => $slist) {
                foreach ($slist as $p => $plist) {
                    if (!isset($oldserverhistlist[$s][$p])) {
                        $sendserverhistlist[$s][$p] = $serverhistlist[$s][$p];
                        continue;
                    }
                    if ($serverhistlist[$s][$p]['portstatus'] !== $oldserverhistlist[$s][$p]['portstatus']) {
                        $sendserverhistlist[$s][$p] = $serverhistlist[$s][$p];
                    }
                }
            }
        } else {
            $sendserverhistlist = $serverhistlist;
        }
        $oldserverhistlist = $serverhistlist;
        if ($sendserverhistlist) {
            dprint("Sending Data\n");
            //print_r($sendserverhistlist);
            dprintr($sendserverhistlist);
            send_data_to_server($sendserverhistlist);
        }
        $timeleft = 60 - $endmaintime + $startmaintime;
        if ($timeleft > 0) {
            //print("Sleep for $timeleft\n");
            sleep($timeleft);
        } else {
            //print("No sleep for $timeleft\n");
        }
        if ($maincount === 10) {
            $maincount = 1;
            if ($global_failure) {
                //print("Sending Data\n");
                //print($serverhistlist);
                send_data_to_server($serverhistlist);
            }
            $list = get_data_from_server();
            send_alive_info();
            //print("Getting again from server\n");
            //$oldserverhistlist = null;
            //print_r($list);
            getDnsesFirst($list);
        }
    }
}
コード例 #2
0
            if (!empty($arr)) {
                if (isset($get['isPrint']) && $get['isPrint'] == 1) {
                    send_data_to_server($arr[1]);
                } else {
                    $_SESSION['PREVIEW_SERVER_DATA'] = $arr[1];
                }
                echo json_encode($arr[0]);
            } else {
                header('HTTP/1.1 400 Bad Request');
                header('Content-Type: application/json; charset=UTF-8');
                echo json_encode(array('message' => 'empty array', 'code' => 1100));
            }
            break;
        case 'send_data_to_server':
            if (isset($_SESSION['PREVIEW_SERVER_DATA'])) {
                send_data_to_server($_SESSION['PREVIEW_SERVER_DATA']);
                unset($_SESSION['PREVIEW_SERVER_DATA']);
            } else {
                header('HTTP/1.1 400 Bad Request');
                header('Content-Type: application/json; charset=UTF-8');
                echo json_encode(array('message' => 'session data missing', 'code' => 1000));
            }
            break;
    }
}
// get data from server
function get_receipt_data_from_server()
{
    $manager = new Management();
    $data = $manager->get_list_of_product_info();
    $receipt = new Receipt();