header("Content-type: text/plain"); Service::stop(); Environment::set_env(array("installed" => false, "vnc_port" => 5900, "policy_host" => $_GET['policy_host'], "policy_port" => 1234, "password" => "", "success" => false, "vnc_port_open" => false, "policy_port_open" => false, "encrypted_password" => "")); $env = Environment::get_env(); $l->log('Attempting to start the service in the following environment: ' . json_encode($env)); Service::start(); $trys = 0; $success = false; $vnc_running = false; $policy_running = false; while (!$success && $trys < 20) { if (!$vnc_running) { $vnc_running = !port_open($env['vnc_port']); } if (!$policy_running) { $policy_running = !port_open($env['policy_port'], $env['policy_host']); } if ($vnc_running && $policy_running) { $success = true; } $trys++; usleep(500000); } $env = Environment::get_env(); if ($success) { $l->log('Service started successfully'); Environment::update_env(array('success' => true)); } else { $l->log('Service did not start'); Environment::update_env(array('success' => false)); }
<?php require_once '../lib/logger.class.php'; $l = new Logger(); function port_open($port, $host = '127.0.0.1') { $conn = @fsockopen($host, $port, $errno, $errstr, 0.2); if ($conn) { fclose($conn); return false; } return true; } require '../lib/environment.class.php'; header("Content-type: text/plain"); Environment::default_env(array('installed' => false, 'vnc_port' => 5900, 'policy_host' => '127.0.0.1', 'policy_port' => 1234, 'password' => 'password', 'success' => false)); $env = Environment::get_env(); Environment::update_env(array('vnc_port_open' => port_open($env['vnc_port']), 'policy_port_open' => port_open($env['policy_port'], $env['policy_host']))); $env = Environment::get_env(); print json_encode($env); $l->log('Returned the following environment: ' . json_encode($env));