Пример #1
0
function process_main()
{
    global $gbl, $sgbl, $login, $ghtml;
    ob_start();
    $exitchar = $sgbl->__var_exit_char;
    $res = new Remote();
    $res->exception = null;
    $res->ddata = "hello";
    $res->message = "hello";
    $in = fopen('php://stdin', 'r');
    $out = fopen('php://stdout', 'w');
    $total = null;
    while (true) {
        $buf = fgets($in, 30);
        //$buf = fgets($in);
        if ($buf) {
            $total .= $buf;
        }
        if (strstr($total, $exitchar)) {
            fprint("GOt Full {$total}");
            $reply = process_server_input(null, $total);
            ob_end_clean();
            print "{$reply}\n{$exitchar}\n";
            flush();
            //fprint("here");
            ob_start();
            $total = null;
        }
    }
}
Пример #2
0
function process_main()
{
    global $gbl, $sgbl, $login, $ghtml;
    global $argv;
    $list = parse_opt($argv);
    $exitchar = $sgbl->__var_exit_char;
    $res = new Remote();
    $res->exception = null;
    $res->ddata = "hello";
    $res->message = "hello";
    $total = file_get_contents($list['temp-input-file']);
    @lunlink($list['temp-input-file']);
    $string = explode("\n", $total);
    if (csb($total, "__file::")) {
        ob_end_clean();
        file_server(null, $total);
    } else {
        $reply = process_server_input($total);
        //fprint(unserialize(base64_decode($reply)));
        ob_end_clean();
        print "{$reply}\n{$exitchar}\n";
        flush();
    }
    exit;
}
Пример #3
0
function some_server_windows()
{
    global $gbl, $sgbl, $login, $ghtml;
    dprint("In Windows Server\n");
    $exitchar = $sgbl->__var_exit_char;
    $con = $sgbl->__var_connection_type;
    // Set the ip and port we will listen on
    // Array that will hold client information
    $clients = array();
    // Create a TCP Stream socket
    //$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    $sockr = stream_socket_server("ssl://0.0.0.0:7779");
    $sockl = stream_socket_server("tcp://127.0.0.1:7776");
    if (!$sockr) {
        die("Could not bind Remote address\n");
    }
    if (!$sockl) {
        die("Could not local bind address\n");
    }
    stream_context_set_option($sockr, 'ssl', 'verify_peer', false);
    stream_context_set_option($sockr, 'ssl', 'allow_self_signed', true);
    //stream_context_set_option($sock, 'ssl', 'cafile', "/etc/httpd/conf/ssl.crt/server.crt");
    stream_context_set_option($sockr, 'ssl', 'local_cert', "{$sgbl->__path_program_root}/file/program.key");
    $client = null;
    // Loop continuously
    $client = null;
    // Loop continuously
    while (true) {
        // Setup clients listen socket for reading
        $read = null;
        $read[0] = $sockr;
        $read[1] = $sockl;
        $writea = null;
        $excpta = null;
        /*
        	foreach((array) $client as $c) {
        		$read[] = $c['sock'];
        	}
        */
        //dprint("Before: ");
        //dprintr($read);
        // Set up a blocking call to stream_select()
        $ready = stream_select($read, $writea, $excpta, 30);
        if ($ready === 0) {
            continue;
        }
        //dprint("After: $ready");
        //dprintr($read);
        // This means that sock - which is our main master socket - is ready for reading, which in turn signifies that a NEW connection has arrived. The other members of the read array
        if (in_array($sockl, $read)) {
            //dprint("Local:");
            //dprintr($read);
            $c = stream_socket_accept($sockl);
        } else {
            if (in_array($sockr, $read)) {
                //dprint("Remote:");
                //dprintr($read);
                $c = stream_socket_accept($sockr);
            }
        }
        // If a client is trying to write - handle it now
        $total = null;
        while (true) {
            $input = fread($c, 8092);
            if ($input == null) {
                //fclose($c);
                break;
            }
            //dprintr($input . "\n");
            $total .= $input;
            if (csa($total, $exitchar)) {
                // requested disconnect
                //dprint("got total $total\n");
                $out = process_server_input($total);
                fwrite($c, $out);
                fwrite($c, "\n");
                fwrite($c, $exitchar);
                fwrite($c, "\n");
                // Server shouldn't close the socket. It is the client's job to do so.
                //fclose($c);
                break;
            }
        }
    }
    // end while
    // Close the master sockets
    fclose($sock);
}