public static function add_to_log($message)
 {
     static $logger = null;
     if ($logger == null) {
         $logger = new pts_logger();
     }
     $logger->log($message);
 }
        foreach ($index_files as $index_file) {
            $index_data = json_decode(file_get_contents($index_file), true);
            $json_repos['repos'][basename($index_file, '.index')] = array('title' => basename($index_file, '.index'), 'generated' => $index_data['main']['generated']);
        }
        echo json_encode($json_repos);
    } else {
        if (isset($_GET['test'])) {
            $repo = str_replace(array('..', '/'), null, $_GET['repo']);
            $test = str_replace(array('..', '/'), null, $_GET['test']);
            if (pts_openbenchmarking::is_repository($repo)) {
                pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' requested a copy of the ' . $repo . '/' . $test . ' test profile');
                $realpath_file = realpath(PTS_OPENBENCHMARKING_SCRATCH_PATH . $repo . '/' . $test . '.zip');
                if (is_file($realpath_file) && strpos($realpath_file, PTS_OPENBENCHMARKING_SCRATCH_PATH) === 0) {
                    echo base64_encode(file_get_contents($realpath_file));
                }
            }
        } else {
            if (isset($_GET['suite'])) {
                $repo = str_replace(array('..', '/'), null, $_GET['repo']);
                $test = str_replace(array('..', '/'), null, $_GET['test']);
                if (pts_openbenchmarking::is_repository($repo)) {
                    pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' requested a copy of the ' . $repo . '/' . $test . ' test suite');
                    $realpath_file = realpath(PTS_OPENBENCHMARKING_SCRATCH_PATH . $repo . '/' . $test . '.zip');
                    if (is_file($realpath_file) && strpos($realpath_file, PTS_OPENBENCHMARKING_SCRATCH_PATH) === 0) {
                        echo base64_encode(file_get_contents($realpath_file));
                    }
                }
            }
        }
    }
}
    public static function render_page_process($PATH)
    {
        $account_creation_string = phoromatic_server::read_setting('account_creation_alt');
        $account_creation_enabled = $account_creation_string == null;
        if ($account_creation_enabled && isset($_POST['register_username']) && isset($_POST['register_password']) && isset($_POST['register_password_confirm']) && isset($_POST['register_email'])) {
            $new_account = create_new_phoromatic_account($_POST['register_username'], $_POST['register_password'], $_POST['register_password_confirm'], $_POST['register_email'], isset($_POST['seed_accountid']) ? $_POST['seed_accountid'] : null);
            if ($new_account) {
                echo phoromatic_webui_header(array('Account Created'), '');
                $box = '<h1>Account Created</h1>
				<p>Your account has been created. You may now log-in to begin utilizing the Phoronix Test Suite\'s Phoromatic.</p>
				<form name="login_form" id="login_form" action="?login" method="post" onsubmit="return phoromatic_login(this);">
				<p><div style="width: 200px; font-weight: bold; float: left;">User:</div> <input type="text" name="username" /></p>
				<p><div style="width: 200px; font-weight: bold; float: left;">Password:</div> <input type="password" name="password" /></p>
				<p><div style="width: 200px; font-weight: bold; float: left;">&nbsp;</div> <input type="submit" value="Submit" /></p>
				</form>';
                echo phoromatic_webui_box($box);
                echo phoromatic_webui_footer();
            }
        } else {
            if (isset($_POST['username']) && isset($_POST['password']) && strtolower($_POST['username']) == 'rootadmin') {
                $admin_pw = phoromatic_server::read_setting('root_admin_pw');
                if (empty($admin_pw)) {
                    echo phoromatic_webui_header(array('Action Required'), '');
                    $box = '<h1>Root Admin Password Not Set</h1>
				<p>The root admin password has not yet been set for this system. It can be set by running on the system: <strong>phoronix-test-suite phoromatic.set-root-admin-password</strong>.</p>';
                    echo phoromatic_webui_box($box);
                    echo phoromatic_webui_footer();
                    return false;
                } else {
                    if (hash('sha256', 'PTS' . $_POST['password']) != $admin_pw) {
                        echo phoromatic_webui_header(array('Invalid Password'), '');
                        $box = '<h1>Root Admin Password Incorrect</h1>
				<p>The root admin password is incorrect.</p>';
                        echo phoromatic_webui_box($box);
                        echo phoromatic_webui_footer();
                        return false;
                    } else {
                        session_regenerate_id();
                        $_SESSION['UserID'] = 0;
                        $_SESSION['UserName'] = '******';
                        $_SESSION['AccountID'] = 0;
                        $_SESSION['AdminLevel'] = -40;
                        $_SESSION['CreatedOn'] = null;
                        $_SESSION['CoreVersionOnSignOn'] = PTS_CORE_VERSION;
                        session_write_close();
                        header('Location: /?admin');
                    }
                }
            } else {
                if (isset($_POST['username']) && isset($_POST['password'])) {
                    $matching_user = phoromatic_server::$db->querySingle('SELECT UserName, Password, AccountID, UserID, AdminLevel, CreatedOn FROM phoromatic_users WHERE UserName = \'' . SQLite3::escapeString($_POST['username']) . '\'', true);
                    if (!empty($matching_user)) {
                        $user_id = $matching_user['UserID'];
                        $created_on = $matching_user['CreatedOn'];
                        $user = $matching_user['UserName'];
                        $hashed_password = $matching_user['Password'];
                        $account_id = $matching_user['AccountID'];
                        $admin_level = $matching_user['AdminLevel'];
                        if ($admin_level < 1) {
                            pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' attempted to log-in to a disabled account: ' . $_POST['username']);
                            phoromatic_error_page('Disabled Account', 'The log-in is not possible as this account has been disabled.');
                            return false;
                        }
                        if ($user == $_POST['username']) {
                            $account_salt = phoromatic_server::$db->querySingle('SELECT Salt FROM phoromatic_accounts WHERE AccountID = \'' . $account_id . '\'');
                        } else {
                            $account_salt = null;
                        }
                        if ($account_salt != null && hash('sha256', $account_salt . $_POST['password']) == $hashed_password) {
                            session_regenerate_id();
                            $_SESSION['UserID'] = $user_id;
                            $_SESSION['UserName'] = $user;
                            $_SESSION['AccountID'] = $account_id;
                            $_SESSION['AdminLevel'] = $admin_level;
                            $_SESSION['CreatedOn'] = $created_on;
                            $_SESSION['CoreVersionOnSignOn'] = PTS_CORE_VERSION;
                            $account_salt = phoromatic_server::$db->exec('UPDATE phoromatic_users SET LastIP = \'' . $_SERVER['REMOTE_ADDR'] . '\', LastLogin = \'' . phoromatic_server::current_time() . '\' WHERE UserName = "******"');
                            session_write_close();
                            pts_file_io::mkdir(phoromatic_server::phoromatic_account_path($account_id));
                            pts_file_io::mkdir(phoromatic_server::phoromatic_account_result_path($account_id));
                            pts_file_io::mkdir(phoromatic_server::phoromatic_account_system_path($account_id));
                            pts_file_io::mkdir(phoromatic_server::phoromatic_account_suite_path($account_id));
                            echo phoromatic_webui_header(array('Welcome, ' . $user), '');
                            $box = '<h1>Log-In Successful</h1>
					<p><strong>' . $user . '</strong>, we are now redirecting you to your account portal. If you are not redirected within a few seconds, please <a href="?main">click here</a>.<script type="text/javascript">window.location.href = "?main";</script></p>';
                            echo phoromatic_webui_box($box);
                            echo phoromatic_webui_footer();
                            pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' successfully logged in as user: '******'REMOTE_ADDR'] . ' failed a log-in attempt as: ' . $_POST['username']);
                            phoromatic_error_page('Invalid Information', 'The user-name or password did not match our records.');
                            return false;
                        }
                    } else {
                        pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' failed a log-in attempt as: ' . $_POST['username']);
                        phoromatic_error_page('Invalid Information', 'The user-name was not found within our system.');
                        return false;
                    }
                } else {
                    echo phoromatic_webui_header(array(), '');
                    $box = '<h1>Welcome</h1>
			<p>You must log-in to your Phoromatic account or create an account to access this service.</p>
			<p>Phoromatic is the remote management and test orchestration system for the Phoronix Test Suite. Phoromatic allows the automatic scheduling of tests, remote installation of new tests, and the management of multiple test systems over a LAN or WAN all through an intuitive, easy-to-use web interface. Tests can be scheduled to automatically run on a routine basis across multiple test systems. The test results are then available from this central, secure location.</p>
			<p>Phoromatic makes it very easy to provide for automated scheduling of tests on multiple systems, is extremely extensible, allows various remote testing possibilities, makes it very trivial to manage multiple systems, and centralizes result management within an organization.</p>
			<p><a href="about.php">Learn more about Phoromatic</a>.</p>
			<hr />
			<h1>Log-In</h1>
			<form name="login_form" id="login_form" action="?login" method="post" onsubmit="return phoromatic_login(this);">
			<p><div style="width: 200px; font-weight: 500; float: left;">User:</div> <input type="text" name="username" /></p>
			<p><div style="width: 200px; font-weight: 500; float: left;">Password:</div> <input type="password" name="password" /></p>
			<p><div style="width: 200px; font-weight: 500; float: left;">&nbsp;</div> <input type="submit" value="Submit" /></p>
			</form>
			<hr />
			<h1>Register</h1>';
                    if (!empty($account_creation_string)) {
                        $box .= '<p>' . $account_creation_string . '</p>';
                    } else {
                        $box .= '
					<p>Creating a new Phoromatic account is free and easy. The public, open-source version of the Phoronix Test Suite client is limited in its Phoromatic server abilities when it comes to result management and local storage outside of the OpenBenchmarking.org cloud. For organizations looking for behind-the-firewall support and other enterprise features, <a href="http://www.phoronix-test-suite.com/?k=commercial">contact us</a>. To create a new account for this Phoromatic server, simply fill out the form below.</p>';
                        $box .= '<form name="register_form" id="register_form" action="?register" method="post" onsubmit="return phoromatic_initial_registration(this);">

					<div style="clear: both; font-weight: 500;">
					<div style="float: left; width: 25%;">Username</div>
					<div style="float: left; width: 25%;">Password</div>
					<div style="float: left; width: 25%;">Confirm Password</div>
					<div style="float: left; width: 25%;">Email Address</div>
					</div>

					<div style="clear: both;">
					<div style="float: left; width: 25%;"><input type="hidden" name="seed_accountid" value="' . (isset($_GET['seed_accountid']) ? $_GET['seed_accountid'] : null) . '" /><input type="text" name="register_username" /> <sup>1</sup></div>
					<div style="float: left; width: 25%;"><input type="password" name="register_password" /> <sup>2</sup></div>
					<div style="float: left; width: 25%;"><input type="password" name="register_password_confirm" /></div>
					<div style="float: left; width: 25%;"><input type="text" name="register_email" /> <sup>3</sup><br /><br /><input type="submit" value="Create Account" /></div>
					</div>

					</form>';
                        $box .= '<p style="font-size: 11px;"><sup>1</sup> Usernames shall be at least four characters long, not contain any spaces, and only be composed of normal ASCII characters.<br />
						<sup>2</sup> Passwords shall be at least six characters long.<br />
						<sup>3</sup> A valid email address is required for notifications, password reset, and other verification purposes.<br />
						</p>';
                    }
                    $box .= '<hr />
			<h1>View Public Results</h1>
			<p>For accounts that opted to share their test results publicly, you can directly <a href="public.php">view the public test results</a>.</p><hr />';
                    echo phoromatic_webui_box($box);
                    echo phoromatic_webui_footer();
                }
            }
        }
    }
示例#4
0
$sys_stmt->bindValue(':system_id', SYSTEM_ID);
$sys_result = $sys_stmt->execute();
$sys_row = $sys_result->fetchArray();
// SEE IF SCHEDULE NEEDS TO RUN
$schedule_row = phoromatic_server::system_check_for_open_schedule_run(ACCOUNT_ID, SYSTEM_ID, 0, $sys_row);
if ($schedule_row != false) {
    $res = phoromatic_generate_test_suite($schedule_row, $json, $phoromatic_account_settings, $sys_row);
    if ($res) {
        return;
    }
}
// END OF SCHEDULE RUN
// BENCHMARK TICKET
$ticket_row = phoromatic_server::system_check_for_open_benchmark_ticket(ACCOUNT_ID, SYSTEM_ID, $sys_row);
if ($ticket_row != false) {
    pts_logger::add_to_log(SYSTEM_ID . ' - needs to benchmark ticket for ' . $ticket_row['Title']);
    $res = phoromatic_generate_benchmark_ticket($ticket_row, $json, $phoromatic_account_settings, $sys_row);
    if ($res) {
        return;
    }
}
// END OF BENCHMARK TICKET
if ($CLIENT_CORE_VERSION >= 5511 && date('i') == 0 && $phoromatic_account_settings['PreSeedTestInstalls'] == 1 && phoromatic_pre_seed_tests_to_install($json, $phoromatic_account_settings, $sys_row)) {
    // XXX TODO: with WS backend won't need to limit to on the hour attempt
    return;
}
// Provide client with update script to ensure client is updated if it's doing nothing besides idling/shutting down
$update_script_path = phoromatic_server::phoromatic_account_path(ACCOUNT_ID) . 'client-update-script.sh';
if (is_file($update_script_path)) {
    $json['phoromatic']['client_update_script'] = file_get_contents($update_script_path);
}
function create_new_phoromatic_account($register_username, $register_password, $register_password_confirm, $register_email, $seed_accountid = null)
{
    // REGISTER NEW USER
    if (strlen($register_username) < 4 || strpos($register_username, ' ') !== false) {
        phoromatic_error_page('Oops!', 'Please go back and ensure the supplied username is at least four characters long and contains no spaces.');
        return false;
    }
    if (in_array(strtolower($register_username), array('admin', 'administrator', 'rootadmin'))) {
        phoromatic_error_page('Oops!', $register_username . ' is a reserved and common username that may be used for other purposes, please make a different selection.');
        return false;
    }
    if (strlen($register_password) < 6) {
        phoromatic_error_page('Oops!', 'Please go back and ensure the supplied password is at least six characters long.');
        return false;
    }
    if ($register_password != $register_password_confirm) {
        phoromatic_error_page('Oops!', 'Please go back and ensure the supplied password matches the password confirmation.');
        return false;
    }
    if ($register_email == null || filter_var($register_email, FILTER_VALIDATE_EMAIL) == false) {
        phoromatic_error_page('Oops!', 'Please enter a valid email address.');
        return false;
    }
    $valid_user_name_chars = '1234567890-_.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    for ($i = 0; $i < count($register_username); $i++) {
        if (strpos($valid_user_name_chars, substr($register_username, $i, 1)) === false) {
            phoromatic_error_page('Oops!', 'Please go back and ensure a valid user-name. The character <em>' . substr($register_username, $i, 1) . '</em> is not allowed.');
            return false;
        }
    }
    $matching_users = phoromatic_server::$db->querySingle('SELECT UserName FROM phoromatic_users WHERE UserName = \'' . SQLite3::escapeString($register_username) . '\'');
    if (!empty($matching_users)) {
        phoromatic_error_page('Oops!', 'The user-name is already taken.');
        return false;
    }
    if (phoromatic_server::read_setting('add_new_users_to_account') != null) {
        $account_id = phoromatic_server::read_setting('add_new_users_to_account');
        $is_new_account = false;
    } else {
        $id_tries = 0;
        do {
            if ($id_tries == 0 && $seed_accountid != null && isset($seed_accountid[5])) {
                $account_id = strtoupper(substr($seed_accountid, 0, 6));
            } else {
                $account_id = pts_strings::random_characters(6, true);
            }
            $matching_accounts = phoromatic_server::$db->querySingle('SELECT AccountID FROM phoromatic_accounts WHERE AccountID = \'' . $account_id . '\'');
            $id_tries++;
        } while (!empty($matching_accounts));
        $is_new_account = true;
    }
    $user_id = pts_strings::random_characters(4, true);
    if ($is_new_account) {
        pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' created a new account: ' . $user_id . ' - ' . $account_id);
        $account_salt = pts_strings::random_characters(12, true);
        $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_accounts (AccountID, ValidateID, CreatedOn, Salt) VALUES (:account_id, :validate_id, :current_time, :salt)');
        $stmt->bindValue(':account_id', $account_id);
        $stmt->bindValue(':validate_id', pts_strings::random_characters(4, true));
        $stmt->bindValue(':salt', $account_salt);
        $stmt->bindValue(':current_time', phoromatic_server::current_time());
        $result = $stmt->execute();
        $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_account_settings (AccountID) VALUES (:account_id)');
        $stmt->bindValue(':account_id', $account_id);
        $result = $stmt->execute();
        $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_user_settings (UserID, AccountID) VALUES (:user_id, :account_id)');
        $stmt->bindValue(':user_id', $user_id);
        $stmt->bindValue(':account_id', $account_id);
        $result = $stmt->execute();
    } else {
        pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' being added to an account: ' . $user_id . ' - ' . $account_id);
        $account_salt = phoromatic_server::$db->querySingle('SELECT Salt FROM phoromatic_accounts WHERE AccountID = \'' . $account_id . '\'');
    }
    $salted_password = hash('sha256', $account_salt . $register_password);
    $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_users (UserID, AccountID, UserName, Email, Password, CreatedOn, LastIP, AdminLevel) VALUES (:user_id, :account_id, :user_name, :email, :password, :current_time, :last_ip, :admin_level)');
    $stmt->bindValue(':user_id', $user_id);
    $stmt->bindValue(':account_id', $account_id);
    $stmt->bindValue(':user_name', $register_username);
    $stmt->bindValue(':email', $register_email);
    $stmt->bindValue(':password', $salted_password);
    $stmt->bindValue(':last_ip', $_SERVER['REMOTE_ADDR']);
    $stmt->bindValue(':current_time', phoromatic_server::current_time());
    $stmt->bindValue(':admin_level', $is_new_account ? 1 : 10);
    $result = $stmt->execute();
    pts_file_io::mkdir(phoromatic_server::phoromatic_account_path($account_id));
    phoromatic_server::send_email($register_email, 'Phoromatic Account Registration', ($e = phoromatic_server::read_setting('admin_support_email')) != null ? $e : '*****@*****.**', '<p><strong>' . $register_username . '</strong>:</p><p>Your Phoromatic account has been created and is now active.</p>');
    return true;
}
if (isset($_GET['repo'])) {
    readfile(phoromatic_server::find_download_cache());
    pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' requested a copy of the download cache JSON');
} else {
    if (isset($_GET['download'])) {
        $requested_file = str_replace(array('..', '/'), null, $_GET['download']);
        pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' is attempting to download ' . $requested_file . ' from the download cache');
        if (($dc = pts_strings::add_trailing_slash(pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)))) && is_file($dc . $requested_file)) {
            $file_path = $dc . $requested_file;
        } else {
            if (is_file(PTS_DOWNLOAD_CACHE_PATH . $requested_file)) {
                $file_path = PTS_DOWNLOAD_CACHE_PATH . $requested_file;
            } else {
                if (is_file(PTS_SHARE_PATH . 'download-cache/' . $requested_file)) {
                    $file_path = PTS_SHARE_PATH . 'download-cache/' . $requested_file;
                } else {
                    if (is_file('/var/cache/phoronix-test-suite/download-cache/' . $requested_file)) {
                        $file_path = '/var/cache/phoronix-test-suite/download-cache/' . $requested_file;
                    } else {
                        pts_logger::add_to_log($requested_file . ' could not be found in the download cache');
                        exit;
                    }
                }
            }
        }
        //pts_logger::add_to_log($requested_file . ' to be downloaded from ' . $file_path);
        ob_end_clean();
        readfile($file_path);
        exit;
    }
}
    public static function run($r)
    {
        if (pts_client::create_lock(PTS_USER_PATH . 'phoromatic_server_lock') == false) {
            trigger_error('The Phoromatic Server is already running.', E_USER_ERROR);
            return false;
        }
        pts_file_io::unlink(getenv('PTS_EXT_LAUNCH_SCRIPT_DIR') . '/phoromatic-server-launcher');
        if (PHP_VERSION_ID < 50400) {
            echo 'Running an unsupported PHP version. PHP 5.4+ is required to use this feature.' . PHP_EOL . PHP_EOL;
            return false;
        }
        if (!function_exists('socket_create_listen')) {
            echo 'PHP Sockets support is needed to use the Phoromatic Server.' . PHP_EOL . PHP_EOL;
            return false;
        }
        $server_launcher = '#!/bin/sh' . PHP_EOL;
        $web_port = 0;
        $remote_access = pts_config::read_user_config('PhoronixTestSuite/Options/Server/RemoteAccessPort', 'RANDOM');
        $fp = false;
        $errno = null;
        $errstr = null;
        if ($remote_access == 'RANDOM') {
            do {
                if ($fp) {
                    fclose($fp);
                }
                $remote_access = rand(8000, 8999);
            } while (($fp = fsockopen('127.0.0.1', $remote_access, $errno, $errstr, 5)) != false);
            echo 'Port ' . $remote_access . ' chosen as random port for this instance. Change the default port via the Phoronix Test Suite user configuration file.' . PHP_EOL;
        }
        $remote_access = is_numeric($remote_access) && $remote_access > 1 ? $remote_access : false;
        $blocked_ports = array(2049, 3659, 4045, 6000, 9000);
        if ($remote_access) {
            // ALLOWING SERVER TO BE REMOTELY ACCESSIBLE
            $server_ip = '0.0.0.0';
            if (($fp = fsockopen('127.0.0.1', $remote_access, $errno, $errstr, 5)) != false) {
                fclose($fp);
                trigger_error('Port ' . $remote_access . ' is already in use by another server process. Close that process or change the Phoronix Test Suite server port via' . pts_config::get_config_file_location() . ' to proceed.', E_USER_ERROR);
                return false;
            } else {
                $web_port = $remote_access;
                $web_socket_port = pts_config::read_user_config('PhoronixTestSuite/Options/Server/WebSocketPort', '');
                while ($web_socket_port == null || !is_numeric($web_socket_port) || ($fp = fsockopen('127.0.0.1', $web_socket_port, $errno, $errstr, 5)) != false) {
                    if ($fp) {
                        fclose($fp);
                    }
                    $web_socket_port = rand(8000, 8999);
                }
            }
        } else {
            echo PHP_EOL . PHP_EOL . 'You must first configure the remote web / Phoromatic settings via:' . PHP_EOL . '    ' . pts_config::get_config_file_location() . PHP_EOL . PHP_EOL . 'The RemoteAccessPort should be a network port to use for HTTP communication while WebSocketPort should be set to another available network port. Set to RANDOM if wishing to use randomly chosen available ports.' . PHP_EOL . PHP_EOL;
            return false;
        }
        if (!extension_loaded('sqlite3')) {
            echo PHP_EOL . PHP_EOL . 'PHP SQLite3 support must first be enabled before accessing the Phoromatic server (e.g. installing the php5-sqlite or php-pdo package depending on the distribution).' . PHP_EOL . PHP_EOL;
            return false;
        }
        // Setup server logger
        define('PHOROMATIC_SERVER', true);
        // Just create the logger so now it will flush it out
        $pts_logger = new pts_logger();
        $pts_logger->clear_log();
        echo pts_core::program_title(true) . ' starting Phoromatic Server' . PHP_EOL;
        $pts_logger->log(pts_core::program_title(true) . ' starting Phoromatic Server on ' . pts_network::get_local_ip());
        echo 'Phoronix Test Suite User-Data Directory Path: ' . PTS_USER_PATH . PHP_EOL;
        echo 'Phoronix Test Suite Configuration File: ' . pts_config::get_config_file_location() . PHP_EOL;
        echo 'Phoromatic Server Log File: ' . $pts_logger->get_log_file_location() . PHP_EOL;
        $pts_logger->log('PTS_USER_PATH = ' . PTS_USER_PATH);
        $pts_logger->log('PTS_DOWNLOAD_CACHE_PATH = ' . PTS_DOWNLOAD_CACHE_PATH);
        $pts_logger->log('XML Configuration File = ' . pts_config::get_config_file_location());
        // WebSocket Server Setup
        $server_launcher .= 'export PTS_WEB_PORT=' . $web_port . PHP_EOL;
        $server_launcher .= 'export PTS_WEBSOCKET_PORT=' . $web_socket_port . PHP_EOL;
        $server_launcher .= 'export PTS_WEBSOCKET_SERVER=PHOROMATIC' . PHP_EOL;
        $server_launcher .= 'export PTS_NO_FLUSH_LOGGER=1' . PHP_EOL;
        $server_launcher .= 'export PTS_PHOROMATIC_SERVER=1' . PHP_EOL;
        $server_launcher .= 'export PTS_PHOROMATIC_LOG_LOCATION=' . $pts_logger->get_log_file_location() . PHP_EOL;
        $server_launcher .= 'cd ' . getenv('PTS_DIR') . ' && PTS_MODE="CLIENT" ' . getenv('PHP_BIN') . ' pts-core/phoronix-test-suite.php start-ws-server &' . PHP_EOL;
        $server_launcher .= 'websocket_server_pid=$!' . PHP_EOL;
        $pts_logger->log('Starting WebSocket process on port ' . $web_socket_port);
        $server_launcher .= 'cd ' . getenv('PTS_DIR') . ' && PTS_MODE="CLIENT" ' . getenv('PHP_BIN') . ' pts-core/phoronix-test-suite.php start-phoromatic-event-server &' . PHP_EOL;
        $server_launcher .= 'event_server_pid=$!' . PHP_EOL;
        // HTTP Server Setup
        if (false && pts_client::executable_in_path('nginx') && is_file('/run/php-fpm/php-fpm.pid')) {
            // NGINX
            $nginx_conf = 'error_log /tmp/error.log;
			pid /tmp/nginx.pid;
			worker_processes 1;

			events {
			  worker_connections 1024;
			}

			http {
			  client_body_temp_path /tmp/client_body;
			  fastcgi_temp_path /tmp/fastcgi_temp;
			  proxy_temp_path /tmp/proxy_temp;
			  scgi_temp_path /tmp/scgi_temp;
			  uwsgi_temp_path /tmp/uwsgi_temp;
			  tcp_nopush on;
			  tcp_nodelay on;
			  keepalive_timeout 180;
			  types_hash_max_size 2048;
			  include /etc/nginx/mime.types;
			  index index.php;

			  server {
			    listen ' . $web_port . ';
			    listen [::]:' . $web_port . ' default ipv6only=on;
			    access_log /tmp/access.log;
			    error_log /tmp/error.log;
			    root ' . PTS_CORE_PATH . 'phoromatic/public_html;
				index index.php;
			      try_files $uri $uri/ /index.php;
				location / {
				autoindex on;
				}
				location ~ \\.php$ {
				     include        /etc/nginx/fastcgi_params;
				     fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
				     fastcgi_split_path_info ^(.+\\.php)(/.+)$;
				     fastcgi_pass   127.0.0.1:9000;
				     fastcgi_index  index.php;
				}
			  }
			}';
            $nginx_conf_file = tempnam(PTS_USER_PATH, 'nginx_conf_');
            file_put_contents($nginx_conf_file, $nginx_conf);
            $server_launcher .= 'nginx -c ' . $nginx_conf_file . PHP_EOL . 'rm -f ' . $nginx_conf_file . PHP_EOL;
        } else {
            if (($mongoose = pts_client::executable_in_path('mongoose')) && ($php_cgi = pts_client::executable_in_path('php-cgi'))) {
                // Mongoose Embedded Web Server
                $server_launcher .= $mongoose . ' -p ' . $web_port . ' -r ' . PTS_CORE_PATH . 'phoromatic/public_html/ -I ' . $php_cgi . ' -i index.php > /dev/null 2>> $PTS_PHOROMATIC_LOG_LOCATION &' . PHP_EOL;
                //2> /dev/null
            } else {
                if (strpos(getenv('PHP_BIN'), 'hhvm')) {
                    echo PHP_EOL . 'Unfortunately, the HHVM built-in web server has abandoned upstream. Users will need to use the PHP binary or other alternatives.' . PHP_EOL . PHP_EOL;
                    return;
                } else {
                    // PHP Web Server
                    $server_launcher .= getenv('PHP_BIN') . ' -S ' . $server_ip . ':' . $web_port . ' -t ' . PTS_CORE_PATH . 'phoromatic/public_html/ > /dev/null 2>> $PTS_PHOROMATIC_LOG_LOCATION &' . PHP_EOL;
                    //2> /dev/null
                }
            }
        }
        $server_launcher .= 'http_server_pid=$!' . PHP_EOL;
        $server_launcher .= 'sleep 1' . PHP_EOL;
        $server_launcher .= 'echo "The Phoromatic Web Interface Is Accessible At: http://localhost:' . $web_port . '"' . PHP_EOL;
        $pts_logger->log('Starting HTTP process @ http://localhost:' . $web_port);
        // Avahi for zeroconf network discovery support
        if (pts_config::read_user_config('PhoronixTestSuite/Options/Server/AdvertiseServiceZeroConf', 'TRUE')) {
            if (is_dir('/etc/avahi/services') && is_writable('/etc/avahi/services')) {
                file_put_contents('/etc/avahi/services/phoromatic-server.service', '<?xml version="1.0" standalone=\'no\'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name replace-wildcards="yes">phoromatic-server-%h</name>
  <service>
    <type>_http._tcp</type>
    <port>' . $web_port . '</port>
  </service>
</service-group>');
            } else {
                if (pts_client::executable_in_path('avahi-publish')) {
                    $hostname = phodevi::read_property('system', 'hostname');
                    $hostname = $hostname == null ? rand(0, 99) : $hostname;
                    $server_launcher .= 'avahi-publish -s phoromatic-server-' . $hostname . ' _http._tcp ' . $web_port . ' "Phoronix Test Suite Phoromatic" > /dev/null 2> /dev/null &' . PHP_EOL;
                    $server_launcher .= 'avahi_publish_pid=$!' . PHP_EOL;
                }
            }
        }
        // Wait for input to shutdown process..
        if (!PTS_IS_DAEMONIZED_SERVER_PROCESS) {
            $server_launcher .= PHP_EOL . 'echo -n "Press [ENTER] to kill server..."' . PHP_EOL;
            $server_launcher .= PHP_EOL . 'read var_name';
        } else {
            $server_launcher .= PHP_EOL . 'while [ ! -f "/var/lib/phoronix-test-suite/end-phoromatic-server" ];';
            $server_launcher .= PHP_EOL . 'do';
            $server_launcher .= PHP_EOL . 'sleep 1';
            $server_launcher .= PHP_EOL . 'done';
            $server_launcher .= PHP_EOL . 'rm -f /var/lib/phoronix-test-suite/end-phoromatic-server' . PHP_EOL;
        }
        // Shutdown / Kill Servers
        $server_launcher .= PHP_EOL . 'kill $http_server_pid';
        $server_launcher .= PHP_EOL . 'kill $websocket_server_pid';
        $server_launcher .= PHP_EOL . 'kill $event_server_pid';
        if (is_writable('/etc/avahi/services') && is_file('/etc/avahi/services/phoromatic-server.service')) {
            $server_launcher .= PHP_EOL . 'rm -f /etc/avahi/services/phoromatic-server.service';
        } else {
            $server_launcher .= PHP_EOL . 'kill $avahi_publish_pid';
        }
        $server_launcher .= PHP_EOL . 'rm -f ~/.phoronix-test-suite/run-lock*';
        file_put_contents(getenv('PTS_EXT_LAUNCH_SCRIPT_DIR') . '/phoromatic-server-launcher', $server_launcher);
    }
示例#8
0
	Copyright (C) 2014 - 2015, Phoronix Media
	Copyright (C) 2014 - 2015, Michael Larabel

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (isset($_GET['phoromatic_info'])) {
    define('PHOROMATIC_SERVER', true);
    //ini_set('memory_limit', '64M');
    define('PTS_MODE', 'WEB_CLIENT');
    define('PTS_AUTO_LOAD_OBJECTS', true);
    error_reporting(E_ALL);
    include '../../pts-core.php';
    pts_core::init();
    $json_info = array('http_server' => isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : null, 'pts' => pts_core::program_title(), 'pts_core' => PTS_CORE_VERSION, 'ws_port' => getenv('PTS_WEBSOCKET_PORT'), 'download_cache' => '/download-cache.php', 'openbenchmarking_cache' => '/openbenchmarking-cache.php');
    echo json_encode($json_info);
    pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' requested the Phoromatic Server deployment details');
} else {
    include '../../pts-core.php';
    echo pts_core::program_title(true) . ' Phoromatic Server [' . $_SERVER['SERVER_SOFTWARE'] . ']';
}
    public static function render_page_process($PATH)
    {
        if ($_SESSION['AdminLevel'] > 3) {
            echo phoromatic_error_page('Unauthorized Access', 'You aren\'t an account administrator!');
            return;
        }
        if (isset($_POST['group_name'])) {
            $stmt = phoromatic_server::$db->prepare('UPDATE phoromatic_accounts SET GroupName = :group_name WHERE AccountID = :account_id');
            $stmt->bindValue(':group_name', $_POST['group_name']);
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $result = $stmt->execute();
        }
        if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['confirm_password']) && isset($_POST['email'])) {
            // REGISTER NEW USER
            if (strlen($_POST['username']) < 4 || strpos($_POST['username'], ' ') !== false) {
                phoromatic_error_page('Oops!', 'Please go back and ensure the supplied username is at least four characters long and contains no spaces.');
                return false;
            }
            if (in_array(strtolower($_POST['username']), array('admin', 'administrator'))) {
                phoromatic_error_page('Oops!', $_POST['username'] . ' is a reserved and common username that may be used for other purposes, please make a different selection.');
                return false;
            }
            if (strlen($_POST['password']) < 6) {
                phoromatic_error_page('Oops!', 'Please go back and ensure the supplied password is at least six characters long.');
                return false;
            }
            if ($_POST['password'] != $_POST['confirm_password']) {
                phoromatic_error_page('Oops!', 'Please go back and ensure the supplied password matches the password confirmation.');
                return false;
            }
            if ($_POST['email'] == null || filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) == false) {
                phoromatic_error_page('Oops!', 'Please enter a valid email address.');
                return false;
            }
            $valid_user_name_chars = '1234567890-_.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
            for ($i = 0; $i < count($_POST['username']); $i++) {
                if (strpos($valid_user_name_chars, substr($_POST['username'], $i, 1)) === false) {
                    phoromatic_error_page('Oops!', 'Please go back and ensure a valid user-name. The character <em>' . substr($_POST['username'], $i, 1) . '</em> is not allowed.');
                    return false;
                }
            }
            $matching_users = phoromatic_server::$db->querySingle('SELECT UserName FROM phoromatic_users WHERE UserName = \'' . SQLite3::escapeString($_POST['username']) . '\'');
            if (!empty($matching_users)) {
                phoromatic_error_page('Oops!', 'The user-name is already taken.');
                return false;
            }
            if (!isset($_POST['admin_level']) || $_POST['admin_level'] == 1 || !is_numeric($_POST['admin_level'])) {
                phoromatic_error_page('Oops!', 'Invalid administration level.');
                return false;
            }
            $stmt = phoromatic_server::$db->prepare('SELECT Salt FROM phoromatic_accounts WHERE AccountID = :account_id');
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $result = $stmt->execute();
            $row = $result->fetchArray();
            $account_salt = $row['Salt'];
            $user_id = pts_strings::random_characters(4, true);
            $salted_password = hash('sha256', $account_salt . $_POST['password']);
            pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' created a new account: ' . $user_id . ' - ' . $_SESSION['AccountID']);
            $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_users (UserID, AccountID, UserName, Email, Password, CreatedOn, LastIP, AdminLevel) VALUES (:user_id, :account_id, :user_name, :email, :password, :current_time, :last_ip, :admin_level)');
            $stmt->bindValue(':user_id', $user_id);
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $stmt->bindValue(':user_name', $_POST['username']);
            $stmt->bindValue(':email', $_POST['email']);
            $stmt->bindValue(':password', $salted_password);
            $stmt->bindValue(':last_ip', $_SERVER['REMOTE_ADDR']);
            $stmt->bindValue(':current_time', phoromatic_server::current_time());
            $stmt->bindValue(':admin_level', $_POST['admin_level']);
            $result = $stmt->execute();
            $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_user_settings (UserID, AccountID) VALUES (:user_id, :account_id)');
            $stmt->bindValue(':user_id', $user_id);
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $result = $stmt->execute();
            phoromatic_add_activity_stream_event('users', $_POST['username'], 'added');
        }
        if ($_SESSION['AdminLevel'] == 1 && isset($_POST['update_user_levels'])) {
            foreach (explode(',', $_POST['update_user_levels']) as $user_id) {
                if (isset($_POST['admin_level_' . $user_id]) && is_numeric($_POST['admin_level_' . $user_id])) {
                    $stmt = phoromatic_server::$db->prepare('UPDATE phoromatic_users SET AdminLevel = :admin_level WHERE AccountID = :account_id AND UserID = :user_id');
                    $stmt->bindValue(':admin_level', $_POST['admin_level_' . $user_id]);
                    $stmt->bindValue(':user_id', $user_id);
                    $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                    $result = $stmt->execute();
                }
            }
        }
        $main = '<h2>Users</h2>
			<p>Users associated with this account. Phoromatic users can be one of several tiers with varying privileges:</p>
			<ol>
				<li><strong>Group Administrator:</strong> The user with full control over the account, the one who originally signed up for the Phoromatic account.</li>
				<li><strong>Administrator:</strong> Additional users created by the group administrator with the same access rights as the group administrator.</li>
				<li><strong>Power Users:</strong> Additional users created by the group administrator with read/write/modify access to all standard Phoromatic functionality, aside from being able to create additional users.</li>
				<li><strong>Viewer:</strong> Additional users created by the group administrator that have access to view data but not to create new schedules, alter system settings, etc.</li>
			</ol>
			<div class="pts_phoromatic_info_box_area">

				<div style="margin: 0 20%;"><form action="' . $_SERVER['REQUEST_URI'] . '" name="edit_user" id="edit_user" method="post">
					<ul>
						<li><h1>All Users</h1></li>';
        $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_users WHERE AccountID = :account_id ORDER BY UserName ASC');
        $stmt->bindValue(':account_id', $_SESSION['AccountID']);
        $result = $stmt->execute();
        $row = $result->fetchArray();
        $user_ids = array();
        do {
            switch ($row['AdminLevel']) {
                case 1:
                    $level = 'Group Administrator';
                    break;
                case 2:
                    $level = 'Administrator';
                    break;
                case 3:
                    $level = 'Power User';
                    break;
                case 10:
                    $level = 'Viewer';
                    break;
                default:
                    if ($row['AdminLevel'] < 1) {
                        $level = 'Disabled';
                    } else {
                        $level = 'Unknown';
                    }
                    break;
            }
            $main .= '<a href="#"><li>' . $row['UserName'] . '<br /><table><tr><td>';
            if ($row['AdminLevel'] == 1 || $_SESSION['AdminLevel'] != 1) {
                $main .= '<strong>' . $level . '</strong>';
            } else {
                $main .= '<select name="admin_level_' . $row['UserID'] . '">';
                foreach (array($row['AdminLevel'] * -1 => 'Disabled', 2 => 'Administrator', 3 => 'Power User', 10 => 'Viewer') as $level_id => $level_string) {
                    $main .= '<option value="' . $level_id . '"' . ($row['AdminLevel'] == $level_id ? ' selected="selected"' : null) . '>' . $level_string . '</option>';
                }
                $main .= '</select>';
                array_push($user_ids, $row['UserID']);
            }
            $main .= '</td><td>Last Login: '******'LastLogin']) ? 'Never' : date('j F Y H:i', strtotime($row['LastLogin']))) . '</td></tr></table></li></a>';
        } while ($row = $result->fetchArray());
        $main .= '</ul> &nbsp; <input type="hidden" name="update_user_levels" value="' . implode(',', $user_ids) . '" /> <input name="submit" value="Update User Levels" type="submit" /></form>
				</div>
			</div>';
        $main .= '<hr /><form action="' . $_SERVER['REQUEST_URI'] . '" name="add_user" id="add_user" method="post" onsubmit="return validate_new_user();"><h2>Create Additional Account</h2>
			<p>Administrators can create extra accounts to be associated with this account\'s systems, schedules, and test data.</p>
			<h3>User</h3>
			<p><input type="text" name="username" /></p>
			<h3>Password</h3>
			<p><input type="password" name="password" /></p>
			<h3>Confirm Password</h3>
			<p><input type="password" name="confirm_password" /></p>
			<h3>Email</h3>
			<p><input type="text" name="email" /></p>
			<h3>Administration Level</h3>
			<p><select name="admin_level">';
        if ($_SESSION['AdminLevel'] == 1) {
            $main .= '<option value="2">Administrator</option>';
        }
        if ($_SESSION['AdminLevel'] <= 2) {
            $main .= '<option value="3">Power User</option>';
        }
        if ($_SESSION['AdminLevel'] <= 3) {
            $main .= '<option value="10">Viewer</option>';
        }
        $main .= '
			</select></p>
			<p><input name="submit" value="Add User" type="submit" /></p>
			</form>';
        $group_name = phoromatic_account_id_to_group_name($_SESSION['AccountID']);
        $main .= '<hr /><form action="' . $_SERVER['REQUEST_URI'] . '" name="group_name" id="group_name" method="post"><h2>Group Name</h2>
			<p>A group name is an alternative, user-facing name for this set of accounts. The group name feature is primarily useful for being able to better distinguish results between groups when sharing of data within a large organization, etc. The group name is showed next to test results when viewing results from multiple groups/accounts.</p>
			<h3>Group Name</h3>
			<p><input type="text" name="group_name" value="' . $group_name . '" /></p>
			<p><input name="submit" value="Update Group Name" type="submit" /></p>
			</form>';
        echo phoromatic_webui_header_logged_in();
        echo '<div id="pts_phoromatic_main_area">' . $main . '</div>';
        echo phoromatic_webui_footer();
    }