summaryrefslogtreecommitdiffstats
path: root/endpoints
diff options
context:
space:
mode:
Diffstat (limited to 'endpoints')
-rw-r--r--endpoints/api.php774
-rw-r--r--endpoints/jqueryFileTree.php770
-rw-r--r--endpoints/language.php234
-rw-r--r--endpoints/lib/auth/ActiveDirectory.php406
-rw-r--r--endpoints/lib/auth/LDAP.php6
-rw-r--r--endpoints/lib/auth/OpenMediaVault.php230
-rw-r--r--endpoints/lib/authinterface.php212
-rw-r--r--endpoints/lib/config.php538
-rw-r--r--endpoints/lib/language.php302
-rw-r--r--endpoints/lib/utils.php188
-rw-r--r--endpoints/rdp.php64
11 files changed, 1862 insertions, 1862 deletions
diff --git a/endpoints/api.php b/endpoints/api.php
index b6d768e..2dff915 100644
--- a/endpoints/api.php
+++ b/endpoints/api.php
@@ -1,387 +1,387 @@
-<?php
-/**
- * Main API interface between JavaScript ajax calls and PHP functions.
- * Accepts JSON, POST data or simple GET requests, and returns JSON data.
- *
- * @author Ian Moore (imoore76 at yahoo dot com)
- * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
- * @version $Id: api.php 596 2015-04-19 11:50:53Z imoore76 $
- * @package phpVirtualBox
- * @see vboxconnector
- * @see vboxAjaxRequest
- *
- * @global array $GLOBALS['response'] resopnse data sent back via json
- * @name $response
-*/
-
-# Turn off PHP errors
-error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING);
-
-
-//Set no caching
-header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
-header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
-header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
-header("Pragma: no-cache");
-
-require_once(dirname(__FILE__).'/lib/config.php');
-require_once(dirname(__FILE__).'/lib/utils.php');
-require_once(dirname(__FILE__).'/lib/vboxconnector.php');
-
-// Init session
-global $_SESSION;
-
-/*
- * Clean request
- */
-$request = clean_request();
-
-
-global $response;
-$response = array('data'=>array('responseData'=>array()),'errors'=>array(),'persist'=>array(),'messages'=>array());
-
-/*
- * Built-in requests
- */
-$vbox = null; // May be set during request handling
-
-/**
- * Main try / catch. Logic dictated by incoming 'fn' request
- * parameter.
- */
-try {
-
- /* Check for password recovery file */
- if(file_exists(dirname(dirname(__FILE__)).'/recovery.php')) {
- throw new Exception('recovery.php exists in phpVirtualBox\'s folder. This is a security hazard. phpVirtualBox will not run until recovery.php has been renamed to a file name that does not end in .php such as <b>recovery.php-disabled</b>.',vboxconnector::PHPVB_ERRNO_FATAL);
- }
-
- /* Check for PHP version */
- if (!version_compare(PHP_VERSION, '5.2.0', '>=')) {
- throw new Exception('phpVirtualBox requires PHP >= 5.2.0, but this server is running version '. PHP_VERSION .'. Please upgrade PHP.');
- }
-
- # Only valid function chars
- $request['fn'] = preg_replace('[^a-zA-Z0-9_-]', '', $request['fn']);
-
- /* Check for function called */
- switch($request['fn']) {
-
- /*
- * No method called
- */
- case '':
- throw new Exception('No method called.');
- break;
-
- /*
- * Return phpVirtualBox's configuration data
- */
- case 'getConfig':
-
- $settings = new phpVBoxConfigClass();
- $response['data']['responseData'] = get_object_vars($settings);
- $response['data']['responseData']['host'] = parse_url($response['data']['responseData']['location']);
- $response['data']['responseData']['host'] = $response['data']['responseData']['host']['host'];
- $response['data']['responseData']['phpvboxver'] = @constant('PHPVBOX_VER');
-
- // Session
- session_init();
-
- // Hide credentials
- unset($response['data']['responseData']['username']);
- unset($response['data']['responseData']['password']);
- foreach($response['data']['responseData']['servers'] as $k => $v)
- $response['data']['responseData']['servers'][$k] = array('name'=>$v['name']);
-
- // Vbox version
- $vbox = new vboxconnector();
- $response['data']['responseData']['version'] = $vbox->getVersion();
- $response['data']['responseData']['hostOS'] = $vbox->vbox->host->operatingSystem;
- $response['data']['responseData']['DSEP'] = $vbox->getDsep();
- $response['data']['responseData']['groupDefinitionKey'] = ($settings->phpVboxGroups ? vboxconnector::phpVboxGroupKey : 'GUI/GroupDefinitions');
-
- $response['data']['success'] = true;
-
- break;
-
- /*
- *
- * USER FUNCTIONS FOLLOW
- *
- */
-
- /*
- * Pass login to authentication module.
- */
- case 'login':
-
-
- // NOTE: Do not break. Fall through to 'getSession
- if(!$request['params']['u'] || !$request['params']['p']) {
- break;
- }
-
- // Session
- session_init(true);
-
- $settings = new phpVBoxConfigClass();
-
- // Try / catch here to hide login credentials
- try {
- $settings->auth->login($request['params']['u'], $request['params']['p']);
- } catch(Exception $e) {
- throw new Exception($e->getMessage(), $e->getCode());
- }
-
- // We're done writing to session
- if(function_exists('session_write_close'))
- @session_write_close();
-
-
-
- /*
- * Return $_SESSION data
- */
- case 'getSession':
-
- $settings = new phpVBoxConfigClass();
- if(method_exists($settings->auth,'autoLoginHook'))
- {
- // Session
- session_init(true);
-
- $settings->auth->autoLoginHook();
-
- // We're done writing to session
- if(function_exists('session_write_close'))
- @session_write_close();
-
- } else {
-
- session_init();
-
- }
-
-
- $response['data']['responseData'] = $_SESSION;
- $response['data']['success'] = true;
- break;
-
- /*
- * Change phpVirtualBox password. Passed to auth module's
- * changePassword method.
- */
- case 'changePassword':
-
- // Session
- session_init(true);
-
- $settings = new phpVBoxConfigClass();
- $response['data']['success'] = $settings->auth->changePassword($request['params']['old'],
- $request['params']['new']);
-
- // We're done writing to session
- if(function_exists('session_write_close'))
- @session_write_close();
-
- break;
-
- /*
- * Get a list of phpVirtualBox users. Passed to auth module's
- * getUsers method.
- */
- case 'getUsers':
-
- // Session
- session_init();
-
- // Must be an admin
- if(!$_SESSION['admin']) break;
-
- $settings = new phpVBoxConfigClass();
- $response['data']['responseData'] = $settings->auth->listUsers();
- $response['date']['success'] = true;
-
- break;
-
- /*
- * Remove a phpVirtualBox user. Passed to auth module's
- * deleteUser method.
- */
- case 'delUser':
-
- // Session
- session_init();
-
- // Must be an admin
- if(!$_SESSION['admin']) break;
-
- $settings = new phpVBoxConfigClass();
- $settings->auth->deleteUser($request['params']['u']);
-
- $response['data']['success'] = true;
- break;
-
- /*
- * Edit a phpVirtualBox user. Passed to auth module's
- * updateUser method.
- */
- case 'editUser':
-
- $skipExistCheck = true;
- // Fall to addUser
-
- /*
- * Add a user to phpVirtualBox. Passed to auth module's
- * updateUser method.
- */
- case 'addUser':
-
- // Session
- session_init();
-
- // Must be an admin
- if(!$_SESSION['admin']) break;
-
- $settings = new phpVBoxConfigClass();
- $settings->auth->updateUser($request['params'], @$skipExistCheck);
-
- $response['data']['success'] = true;
- break;
-
- /*
- * Log out of phpVirtualBox. Passed to auth module's
- * logout method.
- */
- case 'logout':
-
- // Session
- session_init(true);
-
- $vbox = new vboxconnector();
- $vbox->skipSessionCheck = true;
-
- $settings = new phpVBoxConfigClass();
- $settings->auth->logout($response);
-
- session_destroy();
-
- $response['data']['success'] = true;
-
- break;
-
-
- /*
- * If the above cases did not match, assume it is a request
- * that should be passed to vboxconnector.
- */
- default:
-
- $vbox = new vboxconnector();
-
-
- /*
- * Every 1 minute we'll check that the account has not
- * been deleted since login, and update admin credentials.
- */
- if($_SESSION['user'] && ((intval($_SESSION['authCheckHeartbeat'])+60) < time())) {
-
- // init session and keep it open
- session_init(true);
- $vbox->settings->auth->heartbeat($vbox);
-
- // We're done writing to session
- if(function_exists('session_write_close'))
- @session_write_close();
-
- } else {
-
- // init session but close it
- session_init();
-
- }
-
- /*
- * Persistent request data
- */
- if(is_array($request['persist'])) {
- $vbox->persistentRequest = $request['persist'];
- }
-
-
- /*
- * Call to vboxconnector
- */
- $vbox->{$request['fn']}($request['params'],array(&$response));
-
-
- /*
- * Send back persistent request in response
- */
- if(is_array($vbox->persistentRequest) && count($vbox->persistentRequest)) {
- $response['data']['persist'] = $vbox->persistentRequest;
- }
- break;
-
- } // </switch()>
-
-/*
- * Catch all exceptions and populate errors in the
- * JSON response data.
- */
-} catch (Exception $e) {
-
- // Just append to $vbox->errors and let it get
- // taken care of below
- if(!$vbox || !$vbox->errors) {
- $vbox->errors = array();
- }
- $vbox->errors[] = $e;
-}
-
-
-// Add any messages
-if($vbox && count($vbox->messages)) {
- foreach($vbox->messages as $m)
- $response['messages'][] = 'vboxconnector('.$request['fn'] .'): ' . $m;
-}
-// Add other error info
-if($vbox && $vbox->errors) {
-
- foreach($vbox->errors as $e) { /* @var $e Exception */
-
- ob_start();
- print_r($e);
- $d = ob_get_contents();
- ob_end_clean();
-
- # Add connection details to connection errors
- if($e->getCode() == vboxconnector::PHPVB_ERRNO_CONNECT && isset($vbox->settings))
- $d .= "\n\nLocation:" . $vbox->settings->location;
-
- $response['messages'][] = htmlentities($e->getMessage()).' ' . htmlentities($details);
-
- $response['errors'][] = array(
- 'error'=> ($e->getCode() & vboxconnector::PHPVB_ERRNO_HTML ? $e->getMessage() : htmlentities($e->getMessage())),
- 'details'=>htmlentities($d),
- 'errno'=>$e->getCode(),
- // Fatal errors halt all processing
- 'fatal'=>($e->getCode() & vboxconnector::PHPVB_ERRNO_FATAL),
- // Connection errors display alternate servers options
- 'connection'=>($e->getCode() & vboxconnector::PHPVB_ERRNO_CONNECT)
- );
- }
-}
-
-/*
- * Return response as JSON encoded data or use PHP's
- * print_r to dump data to browser.
- */
-if(isset($request['printr'])) {
- print_r($response);
-} else {
- header('Content-type: application/json');
- echo(json_encode($response));
-}
-
+<?php
+/**
+ * Main API interface between JavaScript ajax calls and PHP functions.
+ * Accepts JSON, POST data or simple GET requests, and returns JSON data.
+ *
+ * @author Ian Moore (imoore76 at yahoo dot com)
+ * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
+ * @version $Id: api.php 596 2015-04-19 11:50:53Z imoore76 $
+ * @package phpVirtualBox
+ * @see vboxconnector
+ * @see vboxAjaxRequest
+ *
+ * @global array $GLOBALS['response'] resopnse data sent back via json
+ * @name $response
+*/
+
+# Turn off PHP errors
+error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING);
+
+
+//Set no caching
+header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
+header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
+header("Pragma: no-cache");
+
+require_once(dirname(__FILE__).'/lib/config.php');
+require_once(dirname(__FILE__).'/lib/utils.php');
+require_once(dirname(__FILE__).'/lib/vboxconnector.php');
+
+// Init session
+global $_SESSION;
+
+/*
+ * Clean request
+ */
+$request = clean_request();
+
+
+global $response;
+$response = array('data'=>array('responseData'=>array()),'errors'=>array(),'persist'=>array(),'messages'=>array());
+
+/*
+ * Built-in requests
+ */
+$vbox = null; // May be set during request handling
+
+/**
+ * Main try / catch. Logic dictated by incoming 'fn' request
+ * parameter.
+ */
+try {
+
+ /* Check for password recovery file */
+ if(file_exists(dirname(dirname(__FILE__)).'/recovery.php')) {
+ throw new Exception('recovery.php exists in phpVirtualBox\'s folder. This is a security hazard. phpVirtualBox will not run until recovery.php has been renamed to a file name that does not end in .php such as <b>recovery.php-disabled</b>.',vboxconnector::PHPVB_ERRNO_FATAL);
+ }
+
+ /* Check for PHP version */
+ if (!version_compare(PHP_VERSION, '5.2.0', '>=')) {
+ throw new Exception('phpVirtualBox requires PHP >= 5.2.0, but this server is running version '. PHP_VERSION .'. Please upgrade PHP.');
+ }
+
+ # Only valid function chars
+ $request['fn'] = preg_replace('[^a-zA-Z0-9_-]', '', $request['fn']);
+
+ /* Check for function called */
+ switch($request['fn']) {
+
+ /*
+ * No method called
+ */
+ case '':
+ throw new Exception('No method called.');
+ break;
+
+ /*
+ * Return phpVirtualBox's configuration data
+ */
+ case 'getConfig':
+
+ $settings = new phpVBoxConfigClass();
+ $response['data']['responseData'] = get_object_vars($settings);
+ $response['data']['responseData']['host'] = parse_url($response['data']['responseData']['location']);
+ $response['data']['responseData']['host'] = $response['data']['responseData']['host']['host'];
+ $response['data']['responseData']['phpvboxver'] = @constant('PHPVBOX_VER');
+
+ // Session
+ session_init();
+
+ // Hide credentials
+ unset($response['data']['responseData']['username']);
+ unset($response['data']['responseData']['password']);
+ foreach($response['data']['responseData']['servers'] as $k => $v)
+ $response['data']['responseData']['servers'][$k] = array('name'=>$v['name']);
+
+ // Vbox version
+ $vbox = new vboxconnector();
+ $response['data']['responseData']['version'] = $vbox->getVersion();
+ $response['data']['responseData']['hostOS'] = $vbox->vbox->host->operatingSystem;
+ $response['data']['responseData']['DSEP'] = $vbox->getDsep();
+ $response['data']['responseData']['groupDefinitionKey'] = ($settings->phpVboxGroups ? vboxconnector::phpVboxGroupKey : 'GUI/GroupDefinitions');
+
+ $response['data']['success'] = true;
+
+ break;
+
+ /*
+ *
+ * USER FUNCTIONS FOLLOW
+ *
+ */
+
+ /*
+ * Pass login to authentication module.
+ */
+ case 'login':
+
+
+ // NOTE: Do not break. Fall through to 'getSession
+ if(!$request['params']['u'] || !$request['params']['p']) {
+ break;
+ }
+
+ // Session
+ session_init(true);
+
+ $settings = new phpVBoxConfigClass();
+
+ // Try / catch here to hide login credentials
+ try {
+ $settings->auth->login($request['params']['u'], $request['params']['p']);
+ } catch(Exception $e) {
+ throw new Exception($e->getMessage(), $e->getCode());
+ }
+
+ // We're done writing to session
+ if(function_exists('session_write_close'))
+ @session_write_close();
+
+
+
+ /*
+ * Return $_SESSION data
+ */
+ case 'getSession':
+
+ $settings = new phpVBoxConfigClass();
+ if(method_exists($settings->auth,'autoLoginHook'))
+ {
+ // Session
+ session_init(true);
+
+ $settings->auth->autoLoginHook();
+
+ // We're done writing to session
+ if(function_exists('session_write_close'))
+ @session_write_close();
+
+ } else {
+
+ session_init();
+
+ }
+
+
+ $response['data']['responseData'] = $_SESSION;
+ $response['data']['success'] = true;
+ break;
+
+ /*
+ * Change phpVirtualBox password. Passed to auth module's
+ * changePassword method.
+ */
+ case 'changePassword':
+
+ // Session
+ session_init(true);
+
+ $settings = new phpVBoxConfigClass();
+ $response['data']['success'] = $settings->auth->changePassword($request['params']['old'],
+ $request['params']['new']);
+
+ // We're done writing to session
+ if(function_exists('session_write_close'))
+ @session_write_close();
+
+ break;
+
+ /*
+ * Get a list of phpVirtualBox users. Passed to auth module's
+ * getUsers method.
+ */
+ case 'getUsers':
+
+ // Session
+ session_init();
+
+ // Must be an admin
+ if(!$_SESSION['admin']) break;
+
+ $settings = new phpVBoxConfigClass();
+ $response['data']['responseData'] = $settings->auth->listUsers();
+ $response['date']['success'] = true;
+
+ break;
+
+ /*
+ * Remove a phpVirtualBox user. Passed to auth module's
+ * deleteUser method.
+ */
+ case 'delUser':
+
+ // Session
+ session_init();
+
+ // Must be an admin
+ if(!$_SESSION['admin']) break;
+
+ $settings = new phpVBoxConfigClass();
+ $settings->auth->deleteUser($request['params']['u']);
+
+ $response['data']['success'] = true;
+ break;
+
+ /*
+ * Edit a phpVirtualBox user. Passed to auth module's
+ * updateUser method.
+ */
+ case 'editUser':
+
+ $skipExistCheck = true;
+ // Fall to addUser
+
+ /*
+ * Add a user to phpVirtualBox. Passed to auth module's
+ * updateUser method.
+ */
+ case 'addUser':
+
+ // Session
+ session_init();
+
+ // Must be an admin
+ if(!$_SESSION['admin']) break;
+
+ $settings = new phpVBoxConfigClass();
+ $settings->auth->updateUser($request['params'], @$skipExistCheck);
+
+ $response['data']['success'] = true;
+ break;
+
+ /*
+ * Log out of phpVirtualBox. Passed to auth module's
+ * logout method.
+ */
+ case 'logout':
+
+ // Session
+ session_init(true);
+
+ $vbox = new vboxconnector();
+ $vbox->skipSessionCheck = true;
+
+ $settings = new phpVBoxConfigClass();
+ $settings->auth->logout($response);
+
+ session_destroy();
+
+ $response['data']['success'] = true;
+
+ break;
+
+
+ /*
+ * If the above cases did not match, assume it is a request
+ * that should be passed to vboxconnector.
+ */
+ default:
+
+ $vbox = new vboxconnector();
+
+
+ /*
+ * Every 1 minute we'll check that the account has not
+ * been deleted since login, and update admin credentials.
+ */
+ if($_SESSION['user'] && ((intval($_SESSION['authCheckHeartbeat'])+60) < time())) {
+
+ // init session and keep it open
+ session_init(true);
+ $vbox->settings->auth->heartbeat($vbox);
+
+ // We're done writing to session
+ if(function_exists('session_write_close'))
+ @session_write_close();
+
+ } else {
+
+ // init session but close it
+ session_init();
+
+ }
+
+ /*
+ * Persistent request data
+ */
+ if(is_array($request['persist'])) {
+ $vbox->persistentRequest = $request['persist'];
+ }
+
+
+ /*
+ * Call to vboxconnector
+ */
+ $vbox->{$request['fn']}($request['params'],array(&$response));
+
+
+ /*
+ * Send back persistent request in response
+ */
+ if(is_array($vbox->persistentRequest) && count($vbox->persistentRequest)) {
+ $response['data']['persist'] = $vbox->persistentRequest;
+ }
+ break;
+
+ } // </switch()>
+
+/*
+ * Catch all exceptions and populate errors in the
+ * JSON response data.
+ */
+} catch (Exception $e) {
+
+ // Just append to $vbox->errors and let it get
+ // taken care of below
+ if(!$vbox || !$vbox->errors) {
+ $vbox->errors = array();
+ }
+ $vbox->errors[] = $e;
+}
+
+
+// Add any messages
+if($vbox && count($vbox->messages)) {
+ foreach($vbox->messages as $m)
+ $response['messages'][] = 'vboxconnector('.$request['fn'] .'): ' . $m;
+}
+// Add other error info
+if($vbox && $vbox->errors) {
+
+ foreach($vbox->errors as $e) { /* @var $e Exception */
+
+ ob_start();
+ print_r($e);
+ $d = ob_get_contents();
+ ob_end_clean();
+
+ # Add connection details to connection errors
+ if($e->getCode() == vboxconnector::PHPVB_ERRNO_CONNECT && isset($vbox->settings))
+ $d .= "\n\nLocation:" . $vbox->settings->location;
+
+ $response['messages'][] = htmlentities($e->getMessage()).' ' . htmlentities($details);
+
+ $response['errors'][] = array(
+ 'error'=> ($e->getCode() & vboxconnector::PHPVB_ERRNO_HTML ? $e->getMessage() : htmlentities($e->getMessage())),
+ 'details'=>htmlentities($d),
+ 'errno'=>$e->getCode(),
+ // Fatal errors halt all processing
+ 'fatal'=>($e->getCode() & vboxconnector::PHPVB_ERRNO_FATAL),
+ // Connection errors display alternate servers options
+ 'connection'=>($e->getCode() & vboxconnector::PHPVB_ERRNO_CONNECT)
+ );
+ }
+}
+
+/*
+ * Return response as JSON encoded data or use PHP's
+ * print_r to dump data to browser.
+ */
+if(isset($request['printr'])) {
+ print_r($response);
+} else {
+ header('Content-type: application/json');
+ echo(json_encode($response));
+}
+
diff --git a/endpoints/jqueryFileTree.php b/endpoints/jqueryFileTree.php
index 7c88428..875d3db 100644
--- a/endpoints/jqueryFileTree.php
+++ b/endpoints/jqueryFileTree.php
@@ -1,385 +1,385 @@
-<?php
-//
-// jQuery File Tree PHP Connector
-//
-// Version 1.01
-//
-// Cory S.N. LaViska
-// A Beautiful Site (http://abeautifulsite.net/)
-// 24 March 2008
-//
-// History:
-//
-// 1.01 - updated to work with foreign characters in directory/file names (12 April 2008)
-// 1.00 - released (24 March 2008)
-//
-// Output a list of files for jQuery File Tree
-//
-// ]--- Modified by Ian Moore for phpVirtualBox.
-//
-// $Id: jqueryFileTree.php 592 2015-04-12 19:53:44Z imoore76 $
-//
-//
-
-# Turn off PHP notices
-error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING);
-
-global $vbox, $localbrowser, $allowed;
-
-require_once(dirname(__FILE__).'/lib/config.php');
-require_once(dirname(__FILE__).'/lib/utils.php');
-require_once(dirname(__FILE__).'/lib/vboxconnector.php');
-
-error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING);
-
-session_init();
-if(!$_SESSION['valid']) return;
-
-/*
- * Get Settings
- */
-$settings = new phpVBoxConfigClass();
-
-
-$vbox = new vboxconnector();
-$vbox->connect();
-
-/*
- * Clean request
- */
-global $request;
-$request = clean_request();
-
-/*
- * Determine directory separator
- */
-$localbrowser = @$settings->browserLocal;
-if($localbrowser) {
- define('DSEP', DIRECTORY_SEPARATOR);
-} else {
- define('DSEP',$vbox->getDsep());
-}
-
-/*
- * Compose allowed file types list
- */
-$allowed_exts = $settings->browserRestrictFiles;
-if(is_array($allowed_exts) && count($allowed_exts) > 0) $allowed_exts = array_combine($allowed_exts,$allowed_exts);
-else $allowed_exts = array();
-
-/* Allowed folders list */
-$allowed_folders = @$settings->browserRestrictFolders;
-if(!is_array($allowed_folders))
- $allowed_folders = array();
-
-/*
- * Get a list of windows drives
- */
-function get_windows_drives() {
- $checklist = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $drives = array();
- for($i = 0; $i < strlen($d); $i++) {
- if(is_dir($checklist[$i].':\\')) {
- $drives[] = $checklist[$i].':\\';
- }
- }
- return $drives;
-}
-
-/*
- * Allowed folders in windows if none are set
- */
-if(stripos($vbox->vbox->host->operatingSystem,'win') === 0 && !count($allowed_folders)) {
-
- /*
- * Assumes web server and vbox host are the same physical machine
- */
- if($request['fullpath'] && !$settings->forceWindowsAllDriveList && !$settings->noWindowsDriveList && stripos(PHP_OS,'win') === 0) {
-
-
- $allowed_folders = get_windows_drives();
-
- /*
- * Just show all C-Z drive letters if vboxhost is windows and our web server is not...
- */
- } else if($request['fullpath'] && ($settings->forceWindowsAllDriveList || (!$settings->noWindowsDriveList && stripos(PHP_OS,'win') === false))) {
- $allowed_folders = array();
- for($i = 67; $i < 91; $i++) {
- $allowed_folders[] = chr($i) .':\\';
- }
- }
- $allowed_folders = array_combine($allowed_folders,$allowed_folders);
-
-}
-
-
-/* Deterine target DIR requested.
- * In some cases, "dir" passed is just a file name
- */
-if(strpos($request['dir'],DSEP)===false) {
- $request['dir'] = DSEP;
-}
-
-// Eliminate duplicate DSEPs
-$request['dir'] = str_replace(DSEP.DSEP,DSEP,$request['dir']);
-
-
-/*
- * Check that folder restriction validates if it exists
- */
-if($request['dir'] != DSEP && count($allowed_folders)) {
- $valid = false;
- foreach($allowed_folders as $f) {
- if(strpos(strtoupper($request['dir']),strtoupper($f)) === 0) {
- $valid = true;
- break;
- }
- }
- if(!$valid) {
- $request['dir'] = DSEP;
- }
-}
-
-/*
- * Populate $returnData with directory listing
- */
-$returnData = array();
-
-/* Folder Restriction with root '/' requested */
-if($request['dir'] == DSEP && count($allowed_folders)) {
-
- /* Just return restricted folders */
- foreach($allowed_folders as $f) {
- array_push($returnData, folder_entry($f, true));
-
- }
-
-} else {
-
-
- /* Full, expanded path to $dir */
- if($request['fullpath']) {
-
-
- /* Go through allowed folders if it is set */
- if(count($allowed_folders)) {
-
-
- foreach($allowed_folders as $f) {
-
- /* If this was not exactly the requested folder, but a parent,
- * list everything below it.
- */
- if((strtoupper($request['dir']) != strtoupper($f)) && strpos(strtoupper($request['dir']),strtoupper($f)) === 0) {
-
- // List entries in this folder
- $path = explode(DSEP, substr($request['dir'],strlen($f)));
-
- if($path[0] == '') {
- array_shift($path);
- }
-
- $folder_entry = folder_entry($f, true);
-
- $folder_entry['children'] = getdir($f, $request['dirsOnly'], $path);
- $folder_entry['expanded'] = true;
-
- array_push($returnData, $folder_entry);
-
- } else {
- array_push($returnData, folder_entry($f,true));
- }
-
- }
-
- /* Just get full path */
- } else {
-
- // List entries in this folder
- $path = explode(DSEP,$request['dir']);
- $root = array_shift($path).DSEP;
-
- // Folder entry
- $returnData = getdir($root, $request['dirsOnly'], $path);
-
- }
-
-
- } else {
-
- /* Default action. Return dir requested */
- $returnData = getdir($request['dir'], $request['dirsOnly']);
-
- }
-
-}
-
-header('Content-type: application/json');
-echo(json_encode($returnData));
-
-
-/*
- * Get directory entries
- */
-function getdir($dir, $dirsOnly=false, $recurse=array()) {
-
- if(!$dir) $dir = DSEP;
-
- $entries = getDirEntries($dir, $dirsOnly);
-
- if(!count($entries))
- return array();
-
- $dirents = array();
- foreach($entries as $path => $type) {
-
- if($type == 'folder' && count($recurse) && (strcasecmp($recurse[0],vbox_basename($path)) == 0)) {
-
- $entry = folder_entry($path, false, true);
-
- $entry['children'] = getdir($dir.DSEP.array_shift($recurse), $dirsOnly, $recurse);
-
- array_push($dirents, $entry);
-
- } else {
-
- // Push folder on to stack
- if($type == 'folder') {
-
- array_push($dirents, folder_entry($path));
-
- // Push file on to stack
- } else {
-
- $ext = strtolower(preg_replace('/^.*\./', '', $file));
-
- if(count($allowed) && !$allowed['.'.$ext]) continue;
-
- array_push($dirents, file_entry($path));
- }
- }
-
- }
-
- return $dirents;
-
-}
-
-function vbox_basename($b) { return substr($b,strrpos($b,DSEP)+1); }
-function file_entry($f) {
- $f = str_replace(DSEP.DSEP,DSEP,$f);
- $ext = strtolower(preg_replace('/^.*\./', '', $f));
- return array(
- 'ext' => $ext,
- 'name' => htmlentities(vbox_basename($f), ENT_QUOTES),
- 'path' => htmlentities($f, ENT_QUOTES),
- 'type' => 'file'
- );
-}
-function folder_entry($f,$full=false,$expanded=false) {
- $f = str_replace(DSEP.DSEP,DSEP,$f);
- $selected = (strnatcasecmp(rtrim($f,DSEP),rtrim($GLOBALS['request']['dir'],DSEP)) == 0) && $expanded;
- return array(
- 'expanded' => (bool)$expanded,
- 'selected' => (bool)$selected,
- 'path' => htmlentities($f,ENT_QUOTES),
- 'name' => htmlentities(($full ? $f : vbox_basename($f)),ENT_QUOTES),
- 'type' => 'folder',
- 'children' => array()
- );
-}
-
-
-
-/**
- * Rreturn a list of directory entries
- *
- * @param String $dir
- * @return Array of entries
- */
-
-function getDirEntries($dir, $foldersOnly=false) {
-
- global $localbrowser, $allowed_exts, $vbox;
-
- // Append trailing slash if it isn't here
- if(substr($dir,-1) != DSEP)
- $dir .= DSEP;
-
-
- /*
- * Use local file / folder browser (PHP)
- */
- if($localbrowser) {
-
- // If the dir doesn't exist or we can't scan it, just return
- if(!(file_exists($dir) && ($ents = @scandir($dir))))
- return array();
-
- $newtypes = array();
- $newents = array();
- for($i = 0; $i < count($ents); $i++) {
-
- // Skip . and ..
- if($ents[$i] == '.' || $ents[$i] == '..')
- continue;
-
- $fullpath = $dir.$ents[$i];
- $isdir = @is_dir($fullpath);
-
- if(!$isdir && $foldersOnly)
- continue;
-
- array_push($newtypes, $isdir ? 'folder' : 'file');
- array_push($newents, $fullpath);
- }
- return array_combine($newents, $newtypes);
-
- /*
- * Use remote file / folder browser (vbox)
- */
- } else {
-
- try {
-
-
- $appl = $vbox->vbox->createAppliance();
- $vfs = $appl->createVFSExplorer('file://'.str_replace(DSEP.DSEP,DSEP,$dir));
- $progress = $vfs->update();
- $progress->waitForCompletion(-1);
- $progress->releaseRemote();
- list($ents,$types) = $vfs->entryList();
- $vfs->releaseRemote();
- $appl->releaseRemote();
-
- } catch (Exception $e) {
-
- echo($e->getMessage());
-
- return array();
-
- }
-
- // Convert types to file / folder
- $newtypes = array();
- $newents = array();
- for($i = 0; $i < count($types); $i++) {
-
- // Skip . and ..
- if($ents[$i] == '.' || $ents[$i] == '..')
- continue;
-
- $isdir = $types[$i] == 4;
-
- if(!$isdir && $foldersOnly)
- continue;
-
- array_push($newtypes, $isdir ? 'folder' : 'file');
- array_push($newents, $dir.$ents[$i]);
- }
- return array_combine($newents,$newtypes);
-
- }
-
-
-}
+<?php
+//
+// jQuery File Tree PHP Connector
+//
+// Version 1.01
+//
+// Cory S.N. LaViska
+// A Beautiful Site (http://abeautifulsite.net/)
+// 24 March 2008
+//
+// History:
+//
+// 1.01 - updated to work with foreign characters in directory/file names (12 April 2008)
+// 1.00 - released (24 March 2008)
+//
+// Output a list of files for jQuery File Tree
+//
+// ]--- Modified by Ian Moore for phpVirtualBox.
+//
+// $Id: jqueryFileTree.php 592 2015-04-12 19:53:44Z imoore76 $
+//
+//
+
+# Turn off PHP notices
+error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING);
+
+global $vbox, $localbrowser, $allowed;
+
+require_once(dirname(__FILE__).'/lib/config.php');
+require_once(dirname(__FILE__).'/lib/utils.php');
+require_once(dirname(__FILE__).'/lib/vboxconnector.php');
+
+error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING);
+
+session_init();
+if(!$_SESSION['valid']) return;
+
+/*
+ * Get Settings
+ */
+$settings = new phpVBoxConfigClass();
+
+
+$vbox = new vboxconnector();
+$vbox->connect();
+
+/*
+ * Clean request
+ */
+global $request;
+$request = clean_request();
+
+/*
+ * Determine directory separator
+ */
+$localbrowser = @$settings->browserLocal;
+if($localbrowser) {
+ define('DSEP', DIRECTORY_SEPARATOR);
+} else {
+ define('DSEP',$vbox->getDsep());
+}
+
+/*
+ * Compose allowed file types list
+ */
+$allowed_exts = $settings->browserRestrictFiles;
+if(is_array($allowed_exts) && count($allowed_exts) > 0) $allowed_exts = array_combine($allowed_exts,$allowed_exts);
+else $allowed_exts = array();
+
+/* Allowed folders list */
+$allowed_folders = @$settings->browserRestrictFolders;
+if(!is_array($allowed_folders))
+ $allowed_folders = array();
+
+/*
+ * Get a list of windows drives
+ */
+function get_windows_drives() {
+ $checklist = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ $drives = array();
+ for($i = 0; $i < strlen($d); $i++) {
+ if(is_dir($checklist[$i].':\\')) {
+ $drives[] = $checklist[$i].':\\';
+ }
+ }
+ return $drives;
+}
+
+/*
+ * Allowed folders in windows if none are set
+ */
+if(stripos($vbox->vbox->host->operatingSystem,'win') === 0 && !count($allowed_folders)) {
+
+ /*
+ * Assumes web server and vbox host are the same physical machine
+ */
+ if($request['fullpath'] && !$settings->forceWindowsAllDriveList && !$settings->noWindowsDriveList && stripos(PHP_OS,'win') === 0) {
+
+
+ $allowed_folders = get_windows_drives();
+
+ /*
+ * Just show all C-Z drive letters if vboxhost is windows and our web server is not...
+ */
+ } else if($request['fullpath'] && ($settings->forceWindowsAllDriveList || (!$settings->noWindowsDriveList && stripos(PHP_OS,'win') === false))) {
+ $allowed_folders = array();
+ for($i = 67; $i < 91; $i++) {
+ $allowed_folders[] = chr($i) .':\\';
+ }
+ }
+ $allowed_folders = array_combine($allowed_folders,$allowed_folders);
+
+}
+
+
+/* Deterine target DIR requested.
+ * In some cases, "dir" passed is just a file name
+ */
+if(strpos($request['dir'],DSEP)===false) {
+ $request['dir'] = DSEP;
+}
+
+// Eliminate duplicate DSEPs
+$request['dir'] = str_replace(DSEP.DSEP,DSEP,$request['dir']);
+
+
+/*
+ * Check that folder restriction validates if it exists
+ */
+if($request['dir'] != DSEP && count($allowed_folders)) {
+ $valid = false;
+ foreach($allowed_folders as $f) {
+ if(strpos(strtoupper($request['dir']),strtoupper($f)) === 0) {
+ $valid = true;
+ break;
+ }
+ }
+ if(!$valid) {
+ $request['dir'] = DSEP;
+ }
+}
+
+/*
+ * Populate $returnData with directory listing
+ */
+$returnData = array();
+
+/* Folder Restriction with root '/' requested */
+if($request['dir'] == DSEP && count($allowed_folders)) {
+
+ /* Just return restricted folders */
+ foreach($allowed_folders as $f) {
+ array_push($returnData, folder_entry($f, true));
+
+ }
+
+} else {
+
+
+ /* Full, expanded path to $dir */
+ if($request['fullpath']) {
+
+
+ /* Go through allowed folders if it is set */
+ if(count($allowed_folders)) {
+
+
+ foreach($allowed_folders as $f) {
+
+ /* If this was not exactly the requested folder, but a parent,
+ * list everything below it.
+ */
+ if((strtoupper($request['dir']) != strtoupper($f)) && strpos(strtoupper($request['dir']),strtoupper($f)) === 0) {
+
+ // List entries in this folder
+ $path = explode(DSEP, substr($request['dir'],strlen($f)));
+
+ if($path[0] == '') {
+ array_shift($path);
+ }
+
+ $folder_entry = folder_entry($f, true);
+
+ $folder_entry['children'] = getdir($f, $request['dirsOnly'], $path);
+ $folder_entry['expanded'] = true;
+
+ array_push($returnData, $folder_entry);
+
+ } else {
+ array_push($returnData, folder_entry($f,true));
+ }
+
+ }
+
+ /* Just get full path */
+ } else {
+
+ // List entries in this folder
+ $path = explode(DSEP,$request['dir']);
+ $root = array_shift($path).DSEP;
+
+ // Folder entry
+ $returnData = getdir($root, $request['dirsOnly'], $path);
+
+ }
+
+
+ } else {
+
+ /* Default action. Return dir requested */
+ $returnData = getdir($request['dir'], $request['dirsOnly']);
+
+ }
+
+}
+
+header('Content-type: application/json');
+echo(json_encode($returnData));
+
+
+/*
+ * Get directory entries
+ */
+function getdir($dir, $dirsOnly=false, $recurse=array()) {
+
+ if(!$dir) $dir = DSEP;
+
+ $entries = getDirEntries($dir, $dirsOnly);
+
+ if(!count($entries))
+ return array();
+
+ $dirents = array();
+ foreach($entries as $path => $type) {
+
+ if($type == 'folder' && count($recurse) && (strcasecmp($recurse[0],vbox_basename($path)) == 0)) {
+
+ $entry = folder_entry($path, false, true);
+
+ $entry['children'] = getdir($dir.DSEP.array_shift($recurse), $dirsOnly, $recurse);
+
+ array_push($dirents, $entry);
+
+ } else {
+
+ // Push folder on to stack
+ if($type == 'folder') {
+
+ array_push($dirents, folder_entry($path));
+
+ // Push file on to stack
+ } else {
+
+ $ext = strtolower(preg_replace('/^.*\./', '', $file));
+
+ if(count($allowed) && !$allowed['.'.$ext]) continue;
+
+ array_push($dirents, file_entry($path));
+ }
+ }
+
+ }
+
+ return $dirents;
+
+}
+
+function vbox_basename($b) { return substr($b,strrpos($b,DSEP)+1); }
+function file_entry($f) {
+ $f = str_replace(DSEP.DSEP,DSEP,$f);
+ $ext = strtolower(preg_replace('/^.*\./', '', $f));
+ return array(
+ 'ext' => $ext,
+ 'name' => htmlentities(vbox_basename($f), ENT_QUOTES),
+ 'path' => htmlentities($f, ENT_QUOTES),
+ 'type' => 'file'
+ );
+}
+function folder_entry($f,$full=false,$expanded=false) {
+ $f = str_replace(DSEP.DSEP,DSEP,$f);
+ $selected = (strnatcasecmp(rtrim($f,DSEP),rtrim($GLOBALS['request']['dir'],DSEP)) == 0) && $expanded;
+ return array(
+ 'expanded' => (bool)$expanded,
+ 'selected' => (bool)$selected,
+ 'path' => htmlentities($f,ENT_QUOTES),
+ 'name' => htmlentities(($full ? $f : vbox_basename($f)),ENT_QUOTES),
+ 'type' => 'folder',
+ 'children' => array()
+ );
+}
+
+
+
+/**
+ * Rreturn a list of directory entries
+ *
+ * @param String $dir
+ * @return Array of entries
+ */
+
+function getDirEntries($dir, $foldersOnly=false) {
+
+ global $localbrowser, $allowed_exts, $vbox;
+
+ // Append trailing slash if it isn't here
+ if(substr($dir,-1) != DSEP)
+ $dir .= DSEP;
+
+
+ /*
+ * Use local file / folder browser (PHP)
+ */
+ if($localbrowser) {
+
+ // If the dir doesn't exist or we can't scan it, just return
+ if(!(file_exists($dir) && ($ents = @scandir($dir))))
+ return array();
+
+ $newtypes = array();
+ $newents = array();
+ for($i = 0; $i < count($ents); $i++) {
+
+ // Skip . and ..
+ if($ents[$i] == '.' || $ents[$i] == '..')
+ continue;
+
+ $fullpath = $dir.$ents[$i];
+ $isdir = @is_dir($fullpath);
+
+ if(!$isdir && $foldersOnly)
+ continue;
+
+ array_push($newtypes, $isdir ? 'folder' : 'file');
+ array_push($newents, $fullpath);
+ }
+ return array_combine($newents, $newtypes);
+
+ /*
+ * Use remote file / folder browser (vbox)
+ */
+ } else {
+
+ try {
+
+
+ $appl = $vbox->vbox->createAppliance();
+ $vfs = $appl->createVFSExplorer('file://'.str_replace(DSEP.DSEP,DSEP,$dir));
+ $progress = $vfs->update();
+ $progress->waitForCompletion(-1);
+ $progress->releaseRemote();
+ list($ents,$types) = $vfs->entryList();
+ $vfs->releaseRemote();
+ $appl->releaseRemote();
+
+ } catch (Exception $e) {
+
+ echo($e->getMessage());
+
+ return array();
+
+ }
+
+ // Convert types to file / folder
+ $newtypes = array();
+ $newents = array();
+ for($i = 0; $i < count($types); $i++) {
+
+ // Skip . and ..
+ if($ents[$i] == '.' || $ents[$i] == '..')
+ continue;
+
+ $isdir = $types[$i] == 4;
+
+ if(!$isdir && $foldersOnly)
+ continue;
+
+ array_push($newtypes, $isdir ? 'folder' : 'file');
+ array_push($newents, $dir.$ents[$i]);
+ }
+ return array_combine($newents,$newtypes);
+
+ }
+
+
+}
diff --git a/endpoints/language.php b/endpoints/language.php
index e0769c6..645415a 100644
--- a/endpoints/language.php
+++ b/endpoints/language.php
@@ -1,117 +1,117 @@
-<?php
-/*
- * Injects language translations into phpVirtualBox as a JavaScript object and
- * provides interface translation logic
- * Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
- *
- * $Id: language.php 595 2015-04-17 09:50:36Z imoore76 $
- */
-
-
-error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
-
-require_once(dirname(__FILE__).'/lib/language.php');
-
-if(!is_object($_vbox_language)) $_vbox_language = new __vbox_language();
-
-
-header("Content-type: application/javascript; charset=utf-8", true);
-
-//Set no caching
-header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
-header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
-header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
-header("Pragma: no-cache");
-
-if(isset($_GET['debug']) && $_GET['debug']) {
- print_r(__vbox_language::$langdata);
- return;
-}
-
-/*
- * Dump in JavaScript
- */
-echo('var __vboxLangData = ' . json_encode(__vbox_language::$langdata) .";\n\nvar __vboxLangName = '".constant('VBOXLANG')."';\n\n");
-
-
-?>
-
-
-// Failsafe wrapper
-function trans(s,c,n,h) {
-
- if(s && c && c.constructor === Array) {
- o = c.shift();
- n = c.shift();
- h = c.shift();
- c = o;
- }
- if(!c) c = 'VBoxGlobal';
-
- var r = transreal(s,c,n,h);
-
- if(typeof r != 'string') {
- // console.log('Could not translate ' + s + ' with ' + c);
- return s;
- }
-
- return r;
-}
-
-function transreal(w,context,number,comment) {
-
- try {
-
- if(__vboxLangData['contexts'][context]['messages'][w]['translation']) {
-
- if(__vboxLangData['contexts'][context]['messages'][w]['translation']['numerusform']) {
-
- var t = __vboxLangData['contexts'][context]['messages'][w]['translation']['numerusform'];
-
- if(!number) number = 1;
-
- if(number <= 1 && t[0]) return t[0];
- if(number > 1 && t[1]) return t[1];
- if(t[0]) return t[0];
- return t[1];
- }
- /*
- if (__vboxLangData['contexts'][context]['messages'][w] && __vboxLangData['contexts'][context]['messages'][w]['translation_attr'] && __vboxLangData['contexts'][context]['messages'][w]['translation_attr']['type'] == 'obsolete') {
- console.log(w + ' in ' + context + ' is obsolete');
- }
- */
- return __vboxLangData['contexts'][context]['messages'][w]['translation'];
-
- } else if(__vboxLangData['contexts'][context]['messages'][w][0]) {
-
- if(comment) {
- for(var i in __vboxLangData['contexts'][context]['messages'][w]) {
- if(__vboxLangData['contexts'][context]['messages'][w][i]['comment'] == comment) {
- /*
- if (__vboxLangData['contexts'][context]['messages'][w][i]['translation_attr'] && __vboxLangData['contexts'][context]['messages'][w][i]['translation_attr']['type'] == 'obsolete') {
- console.log(w + ' ' + ' and ' + comment + ' is obsolete');
- }
- */
-
- return __vboxLangData['contexts'][context]['messages'][w][i]['translation'];
- }
- }
- }
- /*
- if (__vboxLangData['contexts'][context]['messages'][w][0] && __vboxLangData['contexts'][context]['messages'][w][0]['translation_attr'] && __vboxLangData['contexts'][context]['messages'][w][0]['translation_attr']['type'] == 'obsolete') {
- console.log(w + ' in ' + context + ' is obsolete');
- }
- */
-
- return __vboxLangData['contexts'][context]['messages'][w][0]['translation'];
-
- } else {
- return w;
- }
-
- } catch(err) {
- // console.log(w + ' - ' + context + ': ' + err);
- return w;
- }
-}
-
+<?php
+/*
+ * Injects language translations into phpVirtualBox as a JavaScript object and
+ * provides interface translation logic
+ * Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
+ *
+ * $Id: language.php 595 2015-04-17 09:50:36Z imoore76 $
+ */
+
+
+error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
+
+require_once(dirname(__FILE__).'/lib/language.php');
+
+if(!is_object($_vbox_language)) $_vbox_language = new __vbox_language();
+
+
+header("Content-type: application/javascript; charset=utf-8", true);
+
+//Set no caching
+header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
+header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
+header("Pragma: no-cache");
+
+if(isset($_GET['debug']) && $_GET['debug']) {
+ print_r(__vbox_language::$langdata);
+ return;
+}
+
+/*
+ * Dump in JavaScript
+ */
+echo('var __vboxLangData = ' . json_encode(__vbox_language::$langdata) .";\n\nvar __vboxLangName = '".constant('VBOXLANG')."';\n\n");
+
+
+?>
+
+
+// Failsafe wrapper
+function trans(s,c,n,h) {
+
+ if(s && c && c.constructor === Array) {
+ o = c.shift();
+ n = c.shift();
+ h = c.shift();
+ c = o;
+ }
+ if(!c) c = 'VBoxGlobal';
+
+ var r = transreal(s,c,n,h);
+
+ if(typeof r != 'string') {
+ // console.log('Could not translate ' + s + ' with ' + c);
+ return s;
+ }
+
+ return r;
+}
+
+function transreal(w,context,number,comment) {
+
+ try {
+
+ if(__vboxLangData['contexts'][context]['messages'][w]['translation']) {
+
+ if(__vboxLangData['contexts'][context]['messages'][w]['translation']['numerusform']) {
+
+ var t = __vboxLangData['contexts'][context]['messages'][w]['translation']['numerusform'];
+
+ if(!number) number = 1;
+
+ if(number <= 1 && t[0]) return t[0];
+ if(number > 1 && t[1]) return t[1];
+ if(t[0]) return t[0];
+ return t[1];
+ }
+ /*
+ if (__vboxLangData['contexts'][context]['messages'][w] && __vboxLangData['contexts'][context]['messages'][w]['translation_attr'] && __vboxLangData['contexts'][context]['messages'][w]['translation_attr']['type'] == 'obsolete') {
+ console.log(w + ' in ' + context + ' is obsolete');
+ }
+ */
+ return __vboxLangData['contexts'][context]['messages'][w]['translation'];
+
+ } else if(__vboxLangData['contexts'][context]['messages'][w][0]) {
+
+ if(comment) {
+ for(var i in __vboxLangData['contexts'][context]['messages'][w]) {
+ if(__vboxLangData['contexts'][context]['messages'][w][i]['comment'] == comment) {
+ /*
+ if (__vboxLangData['contexts'][context]['messages'][w][i]['translation_attr'] && __vboxLangData['contexts'][context]['messages'][w][i]['translation_attr']['type'] == 'obsolete') {
+ console.log(w + ' ' + ' and ' + comment + ' is obsolete');
+ }
+ */
+
+ return __vboxLangData['contexts'][context]['messages'][w][i]['translation'];
+ }
+ }
+ }
+ /*
+ if (__vboxLangData['contexts'][context]['messages'][w][0] && __vboxLangData['contexts'][context]['messages'][w][0]['translation_attr'] && __vboxLangData['contexts'][context]['messages'][w][0]['translation_attr']['type'] == 'obsolete') {
+ console.log(w + ' in ' + context + ' is obsolete');
+ }
+ */
+
+ return __vboxLangData['contexts'][context]['messages'][w][0]['translation'];
+
+ } else {
+ return w;
+ }
+
+ } catch(err) {
+ // console.log(w + ' - ' + context + ': ' + err);
+ return w;
+ }
+}
+
diff --git a/endpoints/lib/auth/ActiveDirectory.php b/endpoints/lib/auth/ActiveDirectory.php
index ce8c4df..cc227dd 100644
--- a/endpoints/lib/auth/ActiveDirectory.php
+++ b/endpoints/lib/auth/ActiveDirectory.php
@@ -1,203 +1,203 @@
-<?php
-/*
- * $Id: ActiveDirectory.php 501 2013-07-11 17:44:37Z imooreyahoo@gmail.com $
-* Experimental!
-*/
-class phpvbAuthActiveDirectory implements phpvbAuth {
-
- var $capabilities = array(
- 'canChangePassword' => false,
- 'canLogout' => true
- );
-
- var $config = array(
- 'host' => '127.0.0.1',
- 'admin_group' => null,
- 'adminUser' => null,
- 'user_group' => null,
- 'container' => 'CN=Users',
- 'domain' => 'internal.local',
- 'filter' => '(&(objectclass=User)(objectCategory=Person))'
- );
-
- /**
- * Constructor
- * @param array $userConfig - user configuration for this module
- */
- function phpvbAuthActiveDirectory($userConfig = null) {
- // Merge user config
- if($userConfig) {
- $this->config = array_merge($this->config,$userConfig);
- }
- }
-
- /**
- * Test log in and set $_SESSION vars
- * @param string $username
- * @param string $password
- * @see phpvbAuth::login()
- */
- function login($username, $password)
- {
- global $_SESSION;
-
-
- /*
- * Check for LDAP functionality and provide some direction
- */
- if(!function_exists('ldap_connect')) {
-
- $ex = 'LDAP support is not enabled in your PHP configuration.';
-
- if(strtolower(substr(PHP_OS, 0, 3)) == 'win') {
-
- ob_start();
- phpinfo(INFO_GENERAL);
- $phpinfo = ob_get_contents();
- ob_end_clean();
- preg_match('/Loaded Configuration File <\/td><td.*?>(.*?)\s*</', $phpinfo, $phpinfo);
-
- $ex .= ' You probably just need to uncomment the line ;extension=php_ldap.dll in php.ini'.
- (count($phpinfo) > 1 ? ' (' .trim($phpinfo[1]).')' : '') . ' by removing the ";" and restart your web server.';
-
- } else if(strtolower(substr(PHP_OS, 0, 5)) == 'Linux') {
-
- $ex .= ' You probably need to install the php5-ldap (or similar depending on your distribution) package and restart your web server.';
-
- }
- throw new Exception($ex);
- }
-
- $_SESSION['valid'] = false;
-
- // Connect to server
- if(!($auth = ldap_connect($this->config['host']))) {
- throw new Exception('Active Directory error ('.ldap_errno($auth).') ' . ldap_error($auth));
- }
-
- // Set relevant LDAP options
- ldap_set_option($auth,LDAP_OPT_PROTOCOL_VERSION, 3);
-
-
- // Main login /bind
- if(!($bind = @ldap_bind($auth, $username . "@" .$this->config['domain'], $password))) {
- if(ldap_errno($auth) == 49) return false;
- throw new Exception('Active Directory error ('.ldap_errno($auth).') ' . ldap_error($auth));
- }
-
-
- // Get user information from AD
- ////////////////////////////////////
-
-
- // Set filter and sanitize username before sending it to AD
- $filter = "(sAMAccountName=" .
- str_replace(array(',','=','+','<','>',';','\\','"','#','(',')','*',chr(0)), '', $username) . ")";
- if($this->config['filter'] && false) {
- $filter = '(&'. $this->config['filter'] .' ('. $filter .'))';
- }
-
- $result = @ldap_search($auth,
- $this->config['container'] . ',DC=' . join(',DC=', explode('.', $this->config['domain'])),
- $filter, array("memberof","useraccountcontrol"));
-
- if(!result) throw new Exception ("Unable to search Active Directory server: " . ldap_error($auth));
- @list($entries) = @ldap_get_entries($auth, $result);
- @ldap_unbind($auth);
- if(!$entries) {
- throw new Exception("Permission denied");
- }
-
-
- // Check for disabled user
- if((intval($entries['useraccountcontrol'][0]) & 2)) {
- throw new Exception('This account is disabled in Active Directory.');
- }
-
- // check for valid admin group
- if($this->config['admin_group']) {
- foreach($entries['memberof'] as $group) {
- list($group) = explode(',', $group);
- if(strtolower($group) == strtolower('cn='.$this->config['admin_group'])) {
- $_SESSION['admin'] = $_SESSION['valid'] = true;
- break;
- }
- }
- }
-
- // Admin user explicitly set?
- if(!$_SESSION['admin'] && $this->config['adminUser']) {
- $_SESSION['admin'] = (strtolower($this->config['adminUser']) == strtolower($username));
- // Admin is ok
- $_SESSION['valid'] = ($_SESSION['admin'] || $_SESSION['valid']);
- }
-
- // check for valid user group
- if($this->config['user_group'] && !$_SESSION['valid']) {
- foreach($entries['memberof'] as $group) {
- list($group) = explode(',', $group);
- if(strtolower($group) == strtolower('cn='.$this->config['user_group'])) {
- $_SESSION['valid'] = true;
- break;
- }
- }
- } else {
- $_SESSION['valid'] = true;
- }
-
- if(!$_SESSION['valid'])
- throw new Exception("Permission denied");
-
- // Admin user explicitly set?
- if(!$_SESSION['admin'] && $this->config['adminUser']) {
- $_SESSION['admin'] = (strtolower($this->config['adminUser']) == strtolower($username));
- }
-
- // No admin information specified makes everyone an admin
- if(!$this->config['adminUser'] && !$this->config['admin_group'])
- $_SESSION['admin'] = true;
-
- // user has permission. establish session variables
- $_SESSION['user'] = $username;
- $_SESSION['authCheckHeartbeat'] = time();
-
-
- return true;
-
- }
-
- function heartbeat($vbox)
- {
- global $_SESSION;
-
- $_SESSION['valid'] = true;
- $_SESSION['authCheckHeartbeat'] = time();
- }
-
- function changePassword($old, $new)
- {
- }
-
- function logout(&$response)
- {
- global $_SESSION;
- if(function_exists('session_destroy')) session_destroy();
- else unset($_SESSION['valid']);
- $response['data']['result'] = 1;
- }
-
- function listUsers()
- {
-
- }
-
- function updateUser($vboxRequest, $skipExistCheck)
- {
-
- }
-
- function deleteUser($user)
- {
-
- }
-}
+<?php
+/*
+ * $Id: ActiveDirectory.php 501 2013-07-11 17:44:37Z imooreyahoo@gmail.com $
+* Experimental!
+*/
+class phpvbAuthActiveDirectory implements phpvbAuth {
+
+ var $capabilities = array(
+ 'canChangePassword' => false,
+ 'canLogout' => true
+ );
+
+ var $config = array(
+ 'host' => '127.0.0.1',
+ 'admin_group' => null,
+ 'adminUser' => null,
+ 'user_group' => null,
+ 'container' => 'CN=Users',
+ 'domain' => 'internal.local',
+ 'filter' => '(&(objectclass=User)(objectCategory=Person))'
+ );
+
+ /**
+ * Constructor
+ * @param array $userConfig - user configuration for this module
+ */
+ function phpvbAuthActiveDirectory($userConfig = null) {
+ // Merge user config
+ if($userConfig) {
+ $this->config = array_merge($this->config,$userConfig);
+ }
+ }
+
+ /**
+ * Test log in and set $_SESSION vars
+ * @param string $username
+ * @param string $password
+ * @see phpvbAuth::login()
+ */
+ function login($username, $password)
+ {
+ global $_SESSION;
+
+
+ /*
+ * Check for LDAP functionality and provide some direction
+ */
+ if(!function_exists('ldap_connect')) {
+
+ $ex = 'LDAP support is not enabled in your PHP configuration.';
+
+ if(strtolower(substr(PHP_OS, 0, 3)) == 'win') {
+
+ ob_start();
+ phpinfo(INFO_GENERAL);
+ $phpinfo = ob_get_contents();
+ ob_end_clean();
+ preg_match('/Loaded Configuration File <\/td><td.*?>(.*?)\s*</', $phpinfo, $phpinfo);
+
+ $ex .= ' You probably just need to uncomment the line ;extension=php_ldap.dll in php.ini'.
+ (count($phpinfo) > 1 ? ' (' .trim($phpinfo[1]).')' : '') . ' by removing the ";" and restart your web server.';
+
+ } else if(strtolower(substr(PHP_OS, 0, 5)) == 'Linux') {
+
+ $ex .= ' You probably need to install the php5-ldap (or similar depending on your distribution) package and restart your web server.';
+
+ }
+ throw new Exception($ex);
+ }
+
+ $_SESSION['valid'] = false;
+
+ // Connect to server
+ if(!($auth = ldap_connect($this->config['host']))) {
+ throw new Exception('Active Directory error ('.ldap_errno($auth).') ' . ldap_error($auth));
+ }
+
+ // Set relevant LDAP options
+ ldap_set_option($auth,LDAP_OPT_PROTOCOL_VERSION, 3);
+
+
+ // Main login /bind
+ if(!($bind = @ldap_bind($auth, $username . "@" .$this->config['domain'], $password))) {
+ if(ldap_errno($auth) == 49) return false;
+ throw new Exception('Active Directory error ('.ldap_errno($auth).') ' . ldap_error($auth));
+ }
+
+
+ // Get user information from AD
+ ////////////////////////////////////
+
+
+ // Set filter and sanitize username before sending it to AD
+ $filter = "(sAMAccountName=" .
+ str_replace(array(',','=','+','<','>',';','\\','"','#','(',')','*',chr(0)), '', $username) . ")";
+ if($this->config['filter'] && false) {
+ $filter = '(&'. $this->config['filter'] .' ('. $filter .'))';
+ }
+
+ $result = @ldap_search($auth,
+ $this->config['container'] . ',DC=' . join(',DC=', explode('.', $this->config['domain'])),
+ $filter, array("memberof","useraccountcontrol"));
+
+ if(!result) throw new Exception ("Unable to search Active Directory server: " . ldap_error($auth));
+ @list($entries) = @ldap_get_entries($auth, $result);
+ @ldap_unbind($auth);
+ if(!$entries) {
+ throw new Exception("Permission denied");
+ }
+
+
+ // Check for disabled user
+ if((intval($entries['useraccountcontrol'][0]) & 2)) {
+ throw new Exception('This account is disabled in Active Directory.');
+ }
+
+ // check for valid admin group
+ if($this->config['admin_group']) {
+ foreach($entries['memberof'] as $group) {
+ list($group) = explode(',', $group);
+ if(strtolower($group) == strtolower('cn='.$this->config['admin_group'])) {
+ $_SESSION['admin'] = $_SESSION['valid'] = true;
+ break;
+ }
+ }
+ }
+
+ // Admin user explicitly set?
+ if(!$_SESSION['admin'] && $this->config['adminUser']) {
+ $_SESSION['admin'] = (strtolower($this->config['adminUser']) == strtolower($username));
+ // Admin is ok
+ $_SESSION['valid'] = ($_SESSION['admin'] || $_SESSION['valid']);
+ }
+
+ // check for valid user group
+ if($this->config['user_group'] && !$_SESSION['valid']) {
+ foreach($entries['memberof'] as $group) {
+ list($group) = explode(',', $group);
+ if(strtolower($group) == strtolower('cn='.$this->config['user_group'])) {
+ $_SESSION['valid'] = true;
+ break;
+ }
+ }
+ } else {
+ $_SESSION['valid'] = true;
+ }
+
+ if(!$_SESSION['valid'])
+ throw new Exception("Permission denied");
+
+ // Admin user explicitly set?
+ if(!$_SESSION['admin'] && $this->config['adminUser']) {
+ $_SESSION['admin'] = (strtolower($this->config['adminUser']) == strtolower($username));
+ }
+
+ // No admin information specified makes everyone an admin
+ if(!$this->config['adminUser'] && !$this->config['admin_group'])
+ $_SESSION['admin'] = true;
+
+ // user has permission. establish session variables
+ $_SESSION['user'] = $username;
+ $_SESSION['authCheckHeartbeat'] = time();
+
+
+ return true;
+
+ }
+
+ function heartbeat($vbox)
+ {
+ global $_SESSION;
+
+ $_SESSION['valid'] = true;
+ $_SESSION['authCheckHeartbeat'] = time();
+ }
+
+ function changePassword($old, $new)
+ {
+ }
+
+ function logout(&$response)
+ {
+ global $_SESSION;
+ if(function_exists('session_destroy')) session_destroy();
+ else unset($_SESSION['valid']);
+ $response['data']['result'] = 1;
+ }
+
+ function listUsers()
+ {
+
+ }
+
+ function updateUser($vboxRequest, $skipExistCheck)
+ {
+
+ }
+
+ function deleteUser($user)
+ {
+
+ }
+}
diff --git a/endpoints/lib/auth/LDAP.php b/endpoints/lib/auth/LDAP.php
index f4b4672..7e7d49e 100644
--- a/endpoints/lib/auth/LDAP.php
+++ b/endpoints/lib/auth/LDAP.php
@@ -60,10 +60,10 @@ class phpvbAuthLDAP implements phpvbAuth {
return false;
- $_SESSION['valid'] = true;
+ $_SESSION['valid'] = true;
$_SESSION['user'] = $username;
- $_SESSION['admin'] = (!$this->config['adminUser']) || ($_SESSION['user'] == $this->config['adminUser']);
- $_SESSION['authCheckHeartbeat'] = time();
+ $_SESSION['admin'] = (!$this->config['adminUser']) || ($_SESSION['user'] == $this->config['adminUser']);
+ $_SESSION['authCheckHeartbeat'] = time();
}
diff --git a/endpoints/lib/auth/OpenMediaVault.php b/endpoints/lib/auth/OpenMediaVault.php
index 71b3d02..991ca3f 100644
--- a/endpoints/lib/auth/OpenMediaVault.php
+++ b/endpoints/lib/auth/OpenMediaVault.php
@@ -1,115 +1,115 @@
-<?php
-/*
- * $Id: OpenMediaVault.php 470 2012-10-24 21:43:25Z imooreyahoo@gmail.com $
-*/
-
-/*
- * OMV Specific
-*/
-try {
-
- // Must be made global or OMV breaks
- global $xmlConfig, $OMV_DEFAULT_FILE;
-
- require_once("openmediavault/globals.inc");
- require_once("openmediavault/session.inc");
- require_once("rpc/authentication.inc");
-
-} catch(Exception $e) {
-
- header("Content-Type: text/html");
- die("Error #".$e->getCode().":<br/>". str_replace("\n", "<br/>",$e->__toString()));
-}
-
-class phpvbAuthOpenMediaVault implements phpvbAuth {
-
- static $session = null;
-
- var $capabilities = array(
- 'canChangePassword' => false,
- 'sessionStart' => 'sessionStart',
- 'canLogout' => true
- );
-
- var $config = array(
- 'allowNonAdmin' => false
- );
-
- function __construct($userConfig = null) {
- if($userConfig) $this->config = array_merge($this->config,$userConfig);
- }
-
- function login($username, $password)
- {
- # Try / catch so that we don't expose
- # usernames / passwords
- require_once("rpc/authentication.inc");
- $a = new AuthenticationRpc();
- try {
-
- $auth = $a->login(array('username'=>$username,'password'=>$password));
-
- self::$session = &OMVSession::getInstance();
-
- if(@$auth["authenticated"] &&
- (self::$session->getRole() !== OMV_ROLE_USER || $this->config['allowNonAdmin'])) {
- $_SESSION['admin'] = (self::$session->getRole() !== OMV_ROLE_USER);
- $_SESSION['user'] = $_SESSION['username'];
- $_SESSION['valid'] = ($_SESSION['admin'] || $this->config['allowNonAdmin']);
- $_SESSION['authCheckHeartbeat'] = time();
-
- }
-
- if(!@$_SESSION['valid']) {
- return false;
- }
- return true;
-
- } catch (Exception $e) {
- return false;
- }
- return false;
- }
-
- function sessionStart($keepopen) {
-
- self::$session = &OMVSession::getInstance();
- self::$session->start();
-
-
- if (self::$session->isAuthenticated() && !self::$session->isTimeout()) {
-
- self::$session->validate();
- self::$session->updateLastAccess();
-
- $_SESSION['admin'] = (self::$session->getRole() !== OMV_ROLE_USER);
- $_SESSION['user'] = $_SESSION['username'];
- $_SESSION['valid'] = (self::$session->getRole() !== OMV_ROLE_USER || $this->config['allowNonAdmin']);
-
- } else {
-
- $_SESSION['admin'] = $_SESSION['user'] = $_SESSION['valid'] = null;
-
- }
-
- if(!$keepopen)
- session_write_close();
-
- }
-
-
- function logout(&$response)
- {
- require_once("rpc/authentication.inc");
- $a = new AuthenticationRpc();
- $a->logout();
- $response['data']['result'] = 1;
- }
-
- /* Defined for compatibility with implemented interface */
- function heartbeat($vbox){}
- function changePassword($old, $new){}
- function listUsers(){}
- function updateUser($vboxRequest, $skipExistCheck){}
- function deleteUser($user){}
-}
+<?php
+/*
+ * $Id: OpenMediaVault.php 470 2012-10-24 21:43:25Z imooreyahoo@gmail.com $
+*/
+
+/*
+ * OMV Specific
+*/
+try {
+
+ // Must be made global or OMV breaks
+ global $xmlConfig, $OMV_DEFAULT_FILE;
+
+ require_once("openmediavault/globals.inc");
+ require_once("openmediavault/session.inc");
+ require_once("rpc/authentication.inc");
+
+} catch(Exception $e) {
+
+ header("Content-Type: text/html");
+ die("Error #".$e->getCode().":<br/>". str_replace("\n", "<br/>",$e->__toString()));
+}
+
+class phpvbAuthOpenMediaVault implements phpvbAuth {
+
+ static $session = null;
+
+ var $capabilities = array(
+ 'canChangePassword' => false,
+ 'sessionStart' => 'sessionStart',
+ 'canLogout' => true
+ );
+
+ var $config = array(
+ 'allowNonAdmin' => false
+ );
+
+ function __construct($userConfig = null) {
+ if($userConfig) $this->config = array_merge($this->config,$userConfig);
+ }
+
+ function login($username, $password)
+ {
+ # Try / catch so that we don't expose
+ # usernames / passwords
+ require_once("rpc/authentication.inc");
+ $a = new AuthenticationRpc();
+ try {
+
+ $auth = $a->login(array('username'=>$username,'password'=>$password));
+
+ self::$session = &OMVSession::getInstance();
+
+ if(@$auth["authenticated"] &&
+ (self::$session->getRole() !== OMV_ROLE_USER || $this->config['allowNonAdmin'])) {
+ $_SESSION['admin'] = (self::$session->getRole() !== OMV_ROLE_USER);
+ $_SESSION['user'] = $_SESSION['username'];
+ $_SESSION['valid'] = ($_SESSION['admin'] || $this->config['allowNonAdmin']);
+ $_SESSION['authCheckHeartbeat'] = time();
+
+ }
+
+ if(!@$_SESSION['valid']) {
+ return false;
+ }
+ return true;
+
+ } catch (Exception $e) {
+ return false;
+ }
+ return false;
+ }
+
+ function sessionStart($keepopen) {
+
+ self::$session = &OMVSession::getInstance();
+ self::$session->start();
+
+
+ if (self::$session->isAuthenticated() && !self::$session->isTimeout()) {
+
+ self::$session->validate();
+ self::$session->updateLastAccess();
+
+ $_SESSION['admin'] = (self::$session->getRole() !== OMV_ROLE_USER);
+ $_SESSION['user'] = $_SESSION['username'];
+ $_SESSION['valid'] = (self::$session->getRole() !== OMV_ROLE_USER || $this->config['allowNonAdmin']);
+
+ } else {
+
+ $_SESSION['admin'] = $_SESSION['user'] = $_SESSION['valid'] = null;
+
+ }
+
+ if(!$keepopen)
+ session_write_close();
+
+ }
+
+
+ function logout(&$response)
+ {
+ require_once("rpc/authentication.inc");
+ $a = new AuthenticationRpc();
+ $a->logout();
+ $response['data']['result'] = 1;
+ }
+
+ /* Defined for compatibility with implemented interface */
+ function heartbeat($vbox){}
+ function changePassword($old, $new){}
+ function listUsers(){}
+ function updateUser($vboxRequest, $skipExistCheck){}
+ function deleteUser($user){}
+}
diff --git a/endpoints/lib/authinterface.php b/endpoints/lib/authinterface.php
index 2905a0e..2b42f9a 100644
--- a/endpoints/lib/authinterface.php
+++ b/endpoints/lib/authinterface.php
@@ -1,107 +1,107 @@
-<?php
-/**
- * Interface for phpVirtualBox authentication modules
- *
- * @author Ian Moore (imoore76 at yahoo dot com)
- * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
- * @version $Id: authinterface.php 595 2015-04-17 09:50:36Z imoore76 $
- * @package phpVirtualBox
- *
- * A class wishing to implement this interface must also contain
- * a list of capabilities describing its capabilities in a public
- * object member array called capabilities.
- *
- * boolean canChangePassword - Users can change passwords
- * boolean canModifyUsers - Users can be modified
- * boolean canLogout - Users can log out
- *
- * E.g.
- * var $capabilities = array(
- * 'canChangePassword' => true,
- * 'canModifyUsers' => true,
- * 'canLogout' => true
- * );
- *
- * The implementing class may also define a public autoLoginHook
- * method that auto-populates $_SESSION. This would automatically
- * log the user in, bypassing the login() function.
- *
- * E.g.
- *
- * function autoLoginHook()
- * {
- * global $_SESSION;
- *
- * // HTTP Authentication passthrough
- * if ( isset($_SERVER['HTTP_X_WEBAUTH_USER']) )
- * {
- * $_SESSION['valid'] = true;
- * $_SESSION['user'] = $_SERVER['HTTP_X_WEBAUTH_USER']];
- * $_SESSION['admin'] = ($_SESSION['user'] === 'bob');
- * $_SESSION['authCheckHeartbeat'] = time();
- * }
- * }
- *
- * Implementing classes should be prefixed with phpvbAuth. E.g.
- * phpvbAuthMySiteAuth. authLib in config.php would then be set
- * to 'MySiteAuth'
- */
-interface phpvbAuth {
-
- /**
- *
- * Log in function. Populates $_SESSION
- * @param string $username user name
- * @param string $password password
- */
- function login($username, $password);
-
- /**
- *
- * Change password function.
- * @param string $old old password
- * @param string $new new password
- * @return boolean true on success
- */
- function changePassword($old, $new);
-
- /**
- *
- * Revalidate login info and set authCheckHeartbeat session variable.
- * @param vboxconnector $vbox vboxconnector object instance
- */
- function heartbeat($vbox);
-
- /**
- *
- * Log out user present in $_SESSION
- * @param array $response response passed byref by API and populated within function
- */
- function logout(&$response);
-
- /**
- *
- * Return a list of users
- * @return array list of users
- */
- function listUsers();
-
- /**
- *
- * Update user information such as password and admin status
- * @param array $vboxRequest request passed from API representing the ajax request. Contains user, password and administration level.
- * @param boolean $skipExistCheck Do not check that the user exists first. Essentially, if this is set and the user does not exist, it is added.
- */
- function updateUser($vboxRequest, $skipExistCheck);
-
-
- /**
- *
- * Remove the user $user
- * @param string $user Username to remove
- */
- function deleteUser($user);
-
-
-
+<?php
+/**
+ * Interface for phpVirtualBox authentication modules
+ *
+ * @author Ian Moore (imoore76 at yahoo dot com)
+ * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
+ * @version $Id: authinterface.php 595 2015-04-17 09:50:36Z imoore76 $
+ * @package phpVirtualBox
+ *
+ * A class wishing to implement this interface must also contain
+ * a list of capabilities describing its capabilities in a public
+ * object member array called capabilities.
+ *
+ * boolean canChangePassword - Users can change passwords
+ * boolean canModifyUsers - Users can be modified
+ * boolean canLogout - Users can log out
+ *
+ * E.g.
+ * var $capabilities = array(
+ * 'canChangePassword' => true,
+ * 'canModifyUsers' => true,
+ * 'canLogout' => true
+ * );
+ *
+ * The implementing class may also define a public autoLoginHook
+ * method that auto-populates $_SESSION. This would automatically
+ * log the user in, bypassing the login() function.
+ *
+ * E.g.
+ *
+ * function autoLoginHook()
+ * {
+ * global $_SESSION;
+ *
+ * // HTTP Authentication passthrough
+ * if ( isset($_SERVER['HTTP_X_WEBAUTH_USER']) )
+ * {
+ * $_SESSION['valid'] = true;
+ * $_SESSION['user'] = $_SERVER['HTTP_X_WEBAUTH_USER']];
+ * $_SESSION['admin'] = ($_SESSION['user'] === 'bob');
+ * $_SESSION['authCheckHeartbeat'] = time();
+ * }
+ * }
+ *
+ * Implementing classes should be prefixed with phpvbAuth. E.g.
+ * phpvbAuthMySiteAuth. authLib in config.php would then be set
+ * to 'MySiteAuth'
+ */
+interface phpvbAuth {
+
+ /**
+ *
+ * Log in function. Populates $_SESSION
+ * @param string $username user name
+ * @param string $password password
+ */
+ function login($username, $password);
+
+ /**
+ *
+ * Change password function.
+ * @param string $old old password
+ * @param string $new new password
+ * @return boolean true on success
+ */
+ function changePassword($old, $new);
+
+ /**
+ *
+ * Revalidate login info and set authCheckHeartbeat session variable.
+ * @param vboxconnector $vbox vboxconnector object instance
+ */
+ function heartbeat($vbox);
+
+ /**
+ *
+ * Log out user present in $_SESSION
+ * @param array $response response passed byref by API and populated within function
+ */
+ function logout(&$response);
+
+ /**
+ *
+ * Return a list of users
+ * @return array list of users
+ */
+ function listUsers();
+
+ /**
+ *
+ * Update user information such as password and admin status
+ * @param array $vboxRequest request passed from API representing the ajax request. Contains user, password and administration level.
+ * @param boolean $skipExistCheck Do not check that the user exists first. Essentially, if this is set and the user does not exist, it is added.
+ */
+ function updateUser($vboxRequest, $skipExistCheck);
+
+
+ /**
+ *
+ * Remove the user $user
+ * @param string $user Username to remove
+ */
+ function deleteUser($user);
+
+
+
} \ No newline at end of file
diff --git a/endpoints/lib/config.php b/endpoints/lib/config.php
index 287bc89..5176416 100644
--- a/endpoints/lib/config.php
+++ b/endpoints/lib/config.php
@@ -1,269 +1,269 @@
-<?php
-/**
- * phpVirtualBox configuration class. Parses user configuration, applies
- * defaults, and sanitizes user values.
- *
- * @author Ian Moore (imoore76 at yahoo dot com)
- * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
- * @version $Id: config.php 595 2015-04-17 09:50:36Z imoore76 $
- * @package phpVirtualBox
- * @see config.php-example
- *
-*/
-
-/*
- * This version of phpVirtualBox
- */
-define('PHPVBOX_VER', '5.2-0');
-
-class phpVBoxConfigClass {
-
- /* DEFAULTS */
-
- /**
- * Default language
- * @var string
- */
- var $language = 'en';
-
- /**
- * Exclusively use phpVirtualBox groups rather than
- * VirtualBox groups
- */
- var $phpVboxGroups = false;
-
- /**
- * Preview screen width
- * @var integer
- */
- var $previewWidth = 180;
-
- /**
- * Aspect ratio of preview screen
- * @var float
- */
- var $previewAspectRatio = 1.6;
-
- /**
- * Allow users to delete media when it is removed
- * @var boolean
- */
- var $deleteOnRemove = true;
-
- /**
- * Restrict file / folder browsers to files ending in extensions found in this array
- * @var array
- */
- var $browserRestrictFiles = array('.iso','.vdi','.vmdk','.img','.bin','.vhd','.hdd','.ovf','.ova','.xml','.vbox','.cdr','.dmg','.ima','.dsk','.vfd');
-
- /**
- * Force file / folder browser to use local PHP functions rather than VirtualBox's IVFSExplorer.
- * If this is set to true, the assumption is made that the web server is on the same host as VirtualBox.
- * @var boolean
- */
- var $browserLocal = false;
-
- /**
- * List of console resolutions available on console tab
- * @var array
- */
- var $consoleResolutions = array('640x480','800x600','1024x768','1280x720','1440x900');
-
- /**
- * Maximum number of NICs displayed per VM
- * @var integer
- */
- var $nicMax = 4;
-
- /**
- * Max number of operations to keep in progress list
- * @var integer
- */
- var $maxProgressList = 5;
-
- /**
- * Enable custom icon per VM
- * @var boolean
- */
- var $enableCustomIcons = false;
-
- /**
- * true if there is no user supplied config.php found.
- * @var boolean
- */
- var $warnDefault = false;
-
- /**
- * Set the standard VRDE port number range to be used when
- * creating new VMs
- * @var string
- */
- var $vrdeports = '9000-9100';
-
- /**
- * Key used to uniquely identify the current server in this
- * instantiation of phpVBoxConfigClass.
- * Set in __construct()
- * @var string
- */
- var $key = null;
-
- /**
- * Auth library object instance. See lib/auth for classes.
- * Set in __construct() based on authLib config setting value.
- * @var phpvbAuth
- */
- var $auth = null;
-
- /**
- * Enable VirtualBox start / stop configuration.
- * Only available in Linux (I beleive)
- * @var boolean
- */
- var $vboxAutostartConfig = false;
-
- /**
- * Authentication capabilities provided by authentication module.
- * Set in __construct
- * @var phpvbAuthBuiltin::authCapabilities
- */
- var $authCapabilities = null;
-
- /**
- * Configuration passed to authentication module
- * @var array
- */
- var $authConfig = array();
-
- /**
- * Event listener timeout in seconds.
- * @var integer
- */
- var $eventListenerTimeout = 20;
-
- /**
- * Read user configuration, apply defaults, and do some sanity checking
- * @see vboxconnector
- */
- function __construct() {
-
- @include_once(dirname(dirname(dirname(__FILE__))).'/config.php');
-
- $ep = error_reporting(0);
-
- /* Apply object vars of configuration class to this class */
- if(class_exists('phpVBoxConfig')) {
- $c = new phpVBoxConfig();
- foreach(get_object_vars($c) as $k => $v) {
- // Safety checks
- if($k == 'browserRestrictFiles' && !is_array($v)) continue;
- if($k == 'consoleResolutions' && !is_array($v)) continue;
- if($k == 'browserRestrictFolders' && !is_array($v)) continue;
- $this->$k = $v;
- }
-
- /* User config.php does not exist. Send warning */
- } else {
- $this->warnDefault = true;
- }
-
- // Ignore any server settings if we have servers
- // in the servers array
- if(isset($this->servers) && is_array($this->servers) && count($this->servers) && is_array($this->servers[0])) {
- unset($this->location);
- unset($this->user);
- unset($this->pass);
- }
- // Set to selected server based on browser cookie
- if(isset($_COOKIE['vboxServer']) && isset($this->servers) && is_array($this->servers) && count($this->servers)) {
- foreach($this->servers as $s) {
- if($s['name'] == $_COOKIE['vboxServer']) {
- foreach($s as $k=>$v) $this->$k = $v;
- break;
- }
- }
- // If servers is not an array, set to empty array
- } elseif(!isset($this->servers) || !is_array($this->servers)) {
- $this->servers = array();
- }
- // We still have no server set, use the first one from
- // the servers array
- if(empty($this->location) && count($this->servers)) {
- foreach($this->servers[0] as $k=>$v) $this->$k = $v;
- }
- // Make sure name is set
- if(!isset($this->name) || !$this->name) {
- $this->name = parse_url($this->location);
- $this->name = $this->name['host'];
- }
-
- // Key used to uniquely identify this server in this
- // phpvirtualbox installation
- $this->setKey();
-
- // legacy rdpHost setting
- if(!empty($this->rdpHost) && empty($this->consoleHost))
- $this->consoleHost = $this->rdpHost;
-
- // Ensure authlib is set
- if(empty($this->authLib)) $this->authLib = 'Builtin';
- // include interface
- include_once(dirname(__FILE__).'/authinterface.php');
- include_once(dirname(__FILE__).'/auth/'.str_replace(array('.','/','\\'),'',$this->authLib).'.php');
-
- // Check for session functionality
- if(!function_exists('session_start')) $this->noAuth = true;
-
- $alib = "phpvbAuth{$this->authLib}";
- $this->auth = new $alib(@$this->authConfig);
- $this->authCapabilities = $this->auth->capabilities;
-
- /* Sanity checks */
- if(!@$this->nicMax)
- $this->nicMax = 4;
-
- $this->previewUpdateInterval = max(3, @$this->previewUpdateInterval);
-
- error_reporting($ep);
- }
-
- /**
- * Set VirtualBox server to use
- * @param string $server server from config.php $servers array
- */
- function setServer($server) {
- // do nothing if we are already using this server
- if($server == $this->name) return;
- foreach($this->servers as $s) {
- if($s['name'] == $server) {
- foreach($s as $k=>$v) $this->$k = $v;
- $this->setKey();
- break;
- }
- }
- }
-
- /**
- * Generate a key for current server settings and populate $this->key
- */
- function setKey() {
- $this->key = md5($this->location);
- }
-
- /**
- * Return the name of the server marked as the authentication master
- * @return string name of server marked as authMaster
- */
- function getServerAuthMaster() {
- foreach($this->servers as $s) {
- if($s['authMaster']) {
- return $s['name'];
- }
- }
- return @$this->servers[0]['name'];
- }
-
-}
-
-
-
+<?php
+/**
+ * phpVirtualBox configuration class. Parses user configuration, applies
+ * defaults, and sanitizes user values.
+ *
+ * @author Ian Moore (imoore76 at yahoo dot com)
+ * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
+ * @version $Id: config.php 595 2015-04-17 09:50:36Z imoore76 $
+ * @package phpVirtualBox
+ * @see config.php-example
+ *
+*/
+
+/*
+ * This version of phpVirtualBox
+ */
+define('PHPVBOX_VER', '5.2-0');
+
+class phpVBoxConfigClass {
+
+ /* DEFAULTS */
+
+ /**
+ * Default language
+ * @var string
+ */
+ var $language = 'en';
+
+ /**
+ * Exclusively use phpVirtualBox groups rather than
+ * VirtualBox groups
+ */
+ var $phpVboxGroups = false;
+
+ /**
+ * Preview screen width
+ * @var integer
+ */
+ var $previewWidth = 180;
+
+ /**
+ * Aspect ratio of preview screen
+ * @var float
+ */
+ var $previewAspectRatio = 1.6;
+
+ /**
+ * Allow users to delete media when it is removed
+ * @var boolean
+ */
+ var $deleteOnRemove = true;
+
+ /**
+ * Restrict file / folder browsers to files ending in extensions found in this array
+ * @var array
+ */
+ var $browserRestrictFiles = array('.iso','.vdi','.vmdk','.img','.bin','.vhd','.hdd','.ovf','.ova','.xml','.vbox','.cdr','.dmg','.ima','.dsk','.vfd');
+
+ /**
+ * Force file / folder browser to use local PHP functions rather than VirtualBox's IVFSExplorer.
+ * If this is set to true, the assumption is made that the web server is on the same host as VirtualBox.
+ * @var boolean
+ */
+ var $browserLocal = false;
+
+ /**
+ * List of console resolutions available on console tab
+ * @var array
+ */
+ var $consoleResolutions = array('640x480','800x600','1024x768','1280x720','1440x900');
+
+ /**
+ * Maximum number of NICs displayed per VM
+ * @var integer
+ */
+ var $nicMax = 4;
+
+ /**
+ * Max number of operations to keep in progress list
+ * @var integer
+ */
+ var $maxProgressList = 5;
+
+ /**
+ * Enable custom icon per VM
+ * @var boolean
+ */
+ var $enableCustomIcons = false;
+
+ /**
+ * true if there is no user supplied config.php found.
+ * @var boolean
+ */
+ var $warnDefault = false;
+
+ /**
+ * Set the standard VRDE port number range to be used when
+ * creating new VMs
+ * @var string
+ */
+ var $vrdeports = '9000-9100';
+
+ /**
+ * Key used to uniquely identify the current server in this
+ * instantiation of phpVBoxConfigClass.
+ * Set in __construct()
+ * @var string
+ */
+ var $key = null;
+
+ /**
+ * Auth library object instance. See lib/auth for classes.
+ * Set in __construct() based on authLib config setting value.
+ * @var phpvbAuth
+ */
+ var $auth = null;
+
+ /**
+ * Enable VirtualBox start / stop configuration.
+ * Only available in Linux (I beleive)
+ * @var boolean
+ */
+ var $vboxAutostartConfig = false;
+
+ /**
+ * Authentication capabilities provided by authentication module.
+ * Set in __construct
+ * @var phpvbAuthBuiltin::authCapabilities
+ */
+ var $authCapabilities = null;
+
+ /**
+ * Configuration passed to authentication module
+ * @var array
+ */
+ var $authConfig = array();
+
+ /**
+ * Event listener timeout in seconds.
+ * @var integer
+ */
+ var $eventListenerTimeout = 20;
+
+ /**
+ * Read user configuration, apply defaults, and do some sanity checking
+ * @see vboxconnector
+ */
+ function __construct() {
+
+ @include_once(dirname(dirname(dirname(__FILE__))).'/config.php');
+
+ $ep = error_reporting(0);
+
+ /* Apply object vars of configuration class to this class */
+ if(class_exists('phpVBoxConfig')) {
+ $c = new phpVBoxConfig();
+ foreach(get_object_vars($c) as $k => $v) {
+ // Safety checks
+ if($k == 'browserRestrictFiles' && !is_array($v)) continue;
+ if($k == 'consoleResolutions' && !is_array($v)) continue;
+ if($k == 'browserRestrictFolders' && !is_array($v)) continue;
+ $this->$k = $v;
+ }
+
+ /* User config.php does not exist. Send warning */
+ } else {
+ $this->warnDefault = true;
+ }
+
+ // Ignore any server settings if we have servers
+ // in the servers array
+ if(isset($this->servers) && is_array($this->servers) && count($this->servers) && is_array($this->servers[0])) {
+ unset($this->location);
+ unset($this->user);
+ unset($this->pass);
+ }
+ // Set to selected server based on browser cookie
+ if(isset($_COOKIE['vboxServer']) && isset($this->servers) && is_array($this->servers) && count($this->servers)) {
+ foreach($this->servers as $s) {
+ if($s['name'] == $_COOKIE['vboxServer']) {
+ foreach($s as $k=>$v) $this->$k = $v;
+ break;
+ }
+ }
+ // If servers is not an array, set to empty array
+ } elseif(!isset($this->servers) || !is_array($this->servers)) {
+ $this->servers = array();
+ }
+ // We still have no server set, use the first one from
+ // the servers array
+ if(empty($this->location) && count($this->servers)) {
+ foreach($this->servers[0] as $k=>$v) $this->$k = $v;
+ }
+ // Make sure name is set
+ if(!isset($this->name) || !$this->name) {
+ $this->name = parse_url($this->location);
+ $this->name = $this->name['host'];
+ }
+
+ // Key used to uniquely identify this server in this
+ // phpvirtualbox installation
+ $this->setKey();
+
+ // legacy rdpHost setting
+ if(!empty($this->rdpHost) && empty($this->consoleHost))
+ $this->consoleHost = $this->rdpHost;
+
+ // Ensure authlib is set
+ if(empty($this->authLib)) $this->authLib = 'Builtin';
+ // include interface
+ include_once(dirname(__FILE__).'/authinterface.php');
+ include_once(dirname(__FILE__).'/auth/'.str_replace(array('.','/','\\'),'',$this->authLib).'.php');
+
+ // Check for session functionality
+ if(!function_exists('session_start')) $this->noAuth = true;
+
+ $alib = "phpvbAuth{$this->authLib}";
+ $this->auth = new $alib(@$this->authConfig);
+ $this->authCapabilities = $this->auth->capabilities;
+
+ /* Sanity checks */
+ if(!@$this->nicMax)
+ $this->nicMax = 4;
+
+ $this->previewUpdateInterval = max(3, @$this->previewUpdateInterval);
+
+ error_reporting($ep);
+ }
+
+ /**
+ * Set VirtualBox server to use
+ * @param string $server server from config.php $servers array
+ */
+ function setServer($server) {
+ // do nothing if we are already using this server
+ if($server == $this->name) return;
+ foreach($this->servers as $s) {
+ if($s['name'] == $server) {
+ foreach($s as $k=>$v) $this->$k = $v;
+ $this->setKey();
+ break;
+ }
+ }
+ }
+
+ /**
+ * Generate a key for current server settings and populate $this->key
+ */
+ function setKey() {
+ $this->key = md5($this->location);
+ }
+
+ /**
+ * Return the name of the server marked as the authentication master
+ * @return string name of server marked as authMaster
+ */
+ function getServerAuthMaster() {
+ foreach($this->servers as $s) {
+ if($s['authMaster']) {
+ return $s['name'];
+ }
+ }
+ return @$this->servers[0]['name'];
+ }
+
+}
+
+
+
diff --git a/endpoints/lib/language.php b/endpoints/lib/language.php
index da8241b..7bb46ee 100644
--- a/endpoints/lib/language.php
+++ b/endpoints/lib/language.php
@@ -1,151 +1,151 @@
-<?php
-/**
- * __vbox_language class and trans() function
- *
- * @author Ian Moore (imoore76 at yahoo dot com)
- * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
- * @version $Id: language.php 591 2015-04-11 22:40:47Z imoore76 $
- * @see languages/languages.txt
- * @package phpVirtualBox
- *
- */
-
-global $_vbox_language;
-
-// Settings contains language
-require_once(dirname(__FILE__).'/config.php');
-require_once(dirname(__FILE__).'/utils.php');
-
-define('VBOX_BASE_LANG_DIR', dirname(dirname(dirname(__FILE__))) .'/languages');
-
-/**
- * Language class. Parses language file and stores translations in an array.
- *
- * @author Ian Moore (imoore76 at yahoo dot com)
- * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
- * @version $Id: language.php 591 2015-04-11 22:40:47Z imoore76 $
- * @package phpVirtualBox
- *
- * @global __vbox_language $GLOBALS['_vbox_language'] global __vbox_language instance
- * @name $_vbox_language
-*/
-class __vbox_language {
-
- /**
- * Static language data used for translations
- * @var array
- */
- static $langdata = null;
-
- /**
- *
- * Constructor parses language file and stores translations.
- */
- function __construct() {
-
- # Already initialized?
- if(is_array(self::$langdata)) return;
-
- self::$langdata = array();
-
- $settings = new phpVBoxConfigClass();
- $lang = strtolower($settings->language);
-
- if(@$_COOKIE['vboxLanguage']) {
- $lang = str_replace(array('/','\\','.'),'',$_COOKIE['vboxLanguage']);
- }
-
- // File as specified
- if($lang && file_exists(VBOX_BASE_LANG_DIR.'/source/'.$lang.'.dat')) {
- @define('VBOXLANG', $lang);
-
- // No lang file found
- } else {
- $lang = 'en';
- @define('VBOXLANG', $lang);
- self::$langdata['contexts'] = array();
- return;
- }
-
-
- self::$langdata = unserialize(@file_get_contents(VBOX_BASE_LANG_DIR.'/source/'.$lang.'.dat'));
-
- $xmlObj = simplexml_load_string(@file_get_contents(VBOX_BASE_LANG_DIR.'/'.$lang.'.xml'));
- $arrXml = $this->objectsIntoArray($xmlObj);
-
- $lang = array();
- if(!@$arrXml['context'][0]) $arrXml['context'] = array($arrXml['context']);
- foreach($arrXml['context'] as $c) {
-
- if(!is_array($c) || !@$c['name']) continue;
- if(!@$c['message'][0]) $c['message'] = array($c['message']);
-
- $lang['contexts'][$c['name']] = array();
- $lang['contexts'][$c['name']]['messages'] = array();
-
- foreach($c['message'] as $m) {
-
- if(!is_array($m)) continue;
-
- $s = $m['source'];
- unset($m['source']);
- $lang['contexts'][$c['name']]['messages'][$s] = $m;
- }
- }
- self::$langdata = array_merge_recursive(self::$langdata, $lang);
- }
-
- /**
- * Translate text.
- * @param string $item message to translate
- * @param string $context context in which the translation should be performed
- */
- function trans($item,$context='phpVirtualBox') {
- $t = @self::$langdata['contexts'][$context]['messages'][$item]['translation'];
- return ($t ? $t : $item);
- }
-
- /**
- *
- * Converts objects into array. Called from class constructor.
- * @param array|object $arrObjData object or array to convert to array
- * @param array $arrSkipIndices array of indices to skip
- * @return array
- */
- function objectsIntoArray($arrObjData, $arrSkipIndices = array())
- {
- $arrData = array();
-
- // if input is object, convert into array
- if (is_object($arrObjData)) {
- $arrObjData = get_object_vars($arrObjData);
- }
-
- if (is_array($arrObjData)) {
- foreach ($arrObjData as $index => $value) {
- if (is_object($value) || is_array($value)) {
- $value = $this->objectsIntoArray($value, $arrSkipIndices); // recursive call
- }
- if (in_array($index, $arrSkipIndices)) {
- continue;
- }
- $arrData[$index] = $value;
- }
- }
- return $arrData;
- }
-
-}
-
-/**
- * Translate text. If $GLOBALS['_vbox_language'] is not set, create a new
- * instance and pass params to its trans() method
- * @param string $msg message to translate
- * @param string $context context in which the translation should be performed
- * @uses $_vbox_language
- * @return string
- */
-function trans($msg,$context='phpVirtualBox') {
- if(!is_object($GLOBALS['_vbox_language'])) $GLOBALS['_vbox_language'] = new __vbox_language();
- return $GLOBALS['_vbox_language']->trans($msg,$context);
-}
+<?php
+/**
+ * __vbox_language class and trans() function
+ *
+ * @author Ian Moore (imoore76 at yahoo dot com)
+ * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
+ * @version $Id: language.php 591 2015-04-11 22:40:47Z imoore76 $
+ * @see languages/languages.txt
+ * @package phpVirtualBox
+ *
+ */
+
+global $_vbox_language;
+
+// Settings contains language
+require_once(dirname(__FILE__).'/config.php');
+require_once(dirname(__FILE__).'/utils.php');
+
+define('VBOX_BASE_LANG_DIR', dirname(dirname(dirname(__FILE__))) .'/languages');
+
+/**
+ * Language class. Parses language file and stores translations in an array.
+ *
+ * @author Ian Moore (imoore76 at yahoo dot com)
+ * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
+ * @version $Id: language.php 591 2015-04-11 22:40:47Z imoore76 $
+ * @package phpVirtualBox
+ *
+ * @global __vbox_language $GLOBALS['_vbox_language'] global __vbox_language instance
+ * @name $_vbox_language
+*/
+class __vbox_language {
+
+ /**
+ * Static language data used for translations
+ * @var array
+ */
+ static $langdata = null;
+
+ /**
+ *
+ * Constructor parses language file and stores translations.
+ */
+ function __construct() {
+
+ # Already initialized?
+ if(is_array(self::$langdata)) return;
+
+ self::$langdata = array();
+
+ $settings = new phpVBoxConfigClass();
+ $lang = strtolower($settings->language);
+
+ if(@$_COOKIE['vboxLanguage']) {
+ $lang = str_replace(array('/','\\','.'),'',$_COOKIE['vboxLanguage']);
+ }
+
+ // File as specified
+ if($lang && file_exists(VBOX_BASE_LANG_DIR.'/source/'.$lang.'.dat')) {
+ @define('VBOXLANG', $lang);
+
+ // No lang file found
+ } else {
+ $lang = 'en';
+ @define('VBOXLANG', $lang);
+ self::$langdata['contexts'] = array();
+ return;
+ }
+
+
+ self::$langdata = unserialize(@file_get_contents(VBOX_BASE_LANG_DIR.'/source/'.$lang.'.dat'));
+
+ $xmlObj = simplexml_load_string(@file_get_contents(VBOX_BASE_LANG_DIR.'/'.$lang.'.xml'));
+ $arrXml = $this->objectsIntoArray($xmlObj);
+
+ $lang = array();
+ if(!@$arrXml['context'][0]) $arrXml['context'] = array($arrXml['context']);
+ foreach($arrXml['context'] as $c) {
+
+ if(!is_array($c) || !@$c['name']) continue;
+ if(!@$c['message'][0]) $c['message'] = array($c['message']);
+
+ $lang['contexts'][$c['name']] = array();
+ $lang['contexts'][$c['name']]['messages'] = array();
+
+ foreach($c['message'] as $m) {
+
+ if(!is_array($m)) continue;
+
+ $s = $m['source'];
+ unset($m['source']);
+ $lang['contexts'][$c['name']]['messages'][$s] = $m;
+ }
+ }
+ self::$langdata = array_merge_recursive(self::$langdata, $lang);
+ }
+
+ /**
+ * Translate text.
+ * @param string $item message to translate
+ * @param string $context context in which the translation should be performed
+ */
+ function trans($item,$context='phpVirtualBox') {
+ $t = @self::$langdata['contexts'][$context]['messages'][$item]['translation'];
+ return ($t ? $t : $item);
+ }
+
+ /**
+ *
+ * Converts objects into array. Called from class constructor.
+ * @param array|object $arrObjData object or array to convert to array
+ * @param array $arrSkipIndices array of indices to skip
+ * @return array
+ */
+ function objectsIntoArray($arrObjData, $arrSkipIndices = array())
+ {
+ $arrData = array();
+
+ // if input is object, convert into array
+ if (is_object($arrObjData)) {
+ $arrObjData = get_object_vars($arrObjData);
+ }
+
+ if (is_array($arrObjData)) {
+ foreach ($arrObjData as $index => $value) {
+ if (is_object($value) || is_array($value)) {
+ $value = $this->objectsIntoArray($value, $arrSkipIndices); // recursive call
+ }
+ if (in_array($index, $arrSkipIndices)) {
+ continue;
+ }
+ $arrData[$index] = $value;
+ }
+ }
+ return $arrData;
+ }
+
+}
+
+/**
+ * Translate text. If $GLOBALS['_vbox_language'] is not set, create a new
+ * instance and pass params to its trans() method
+ * @param string $msg message to translate
+ * @param string $context context in which the translation should be performed
+ * @uses $_vbox_language
+ * @return string
+ */
+function trans($msg,$context='phpVirtualBox') {
+ if(!is_object($GLOBALS['_vbox_language'])) $GLOBALS['_vbox_language'] = new __vbox_language();
+ return $GLOBALS['_vbox_language']->trans($msg,$context);
+}
diff --git a/endpoints/lib/utils.php b/endpoints/lib/utils.php
index 703bdb8..356971a 100644
--- a/endpoints/lib/utils.php
+++ b/endpoints/lib/utils.php
@@ -1,95 +1,95 @@
-<?php
-/**
- * Common PHP utilities.
- *
- * @author Ian Moore (imoore76 at yahoo dot com)
- * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
- * @version $Id: utils.php 592 2015-04-12 19:53:44Z imoore76 $
- * @see phpVBoxConfigClass
- * @package phpVirtualBox
- *
-*/
-
-require_once(dirname(__FILE__).'/config.php');
-
-/**
- * Initialize session.
- * @param boolean $keepopen keep session open? The default is
- * to close the session after $_SESSION has been populated.
- * @uses $_SESSION
- */
-function session_init($keepopen = false) {
-
- $settings = new phpVBoxConfigClass();
-
- // Sessions provided by auth module?
- if(@$settings->auth->capabilities['sessionStart']) {
- call_user_func(array($settings->auth, $settings->auth->capabilities['sessionStart']), $keepopen);
- return;
- }
-
- // No session support? No login...
- if(@$settings->noAuth || !function_exists('session_start')) {
- global $_SESSION;
- $_SESSION['valid'] = true;
- $_SESSION['authCheckHeartbeat'] = time();
- $_SESSION['admin'] = true;
- return;
- }
-
- // Session not is auto-started by PHP
- if(!ini_get('session.auto_start')) {
-
- ini_set('session.use_trans_sid', 0);
- ini_set('session.use_only_cookies', 1);
-
- // Session path
- if(isset($settings->sessionSavePath)) {
- session_save_path($settings->sessionSavePath);
- }
-
- if(isset($settings->session_name)) {
- $session_name = $settings->session_name;
- } else {
- $session_name = md5($_SERVER['DOCUMENT_ROOT'].$_SERVER['HTTP_USER_AGENT'].dirname(__FILE__));
- }
- session_name($session_name);
- session_start();
- }
-
- if(!$keepopen)
- session_write_close();
-
-}
-
-
-/**
- * Clean (strip slashes from if applicable) $_GET and $_POST and return
- * an array containing a merged array of both.
- * @return array
- */
-function clean_request() {
-
- if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
- $json = json_decode(file_get_contents('php://input'), true);
- if(!is_array($json))
- $json = array();
- } else {
- $json = array();
- }
- $req = array_merge_recursive($_GET, $_POST);
- return array_merge_recursive($req, $json);
-
-}
-
-if(!function_exists('hash')) {
-// Lower security, but better than nothing
-/**
- * Return a hash of the passed string. Mimmics PHP's hash() params
- * @param unused $type
- * @param string $str string to hash
- */
-function hash($type,$str='') {
- return sha1(json_encode($str));
-}
+<?php
+/**
+ * Common PHP utilities.
+ *
+ * @author Ian Moore (imoore76 at yahoo dot com)
+ * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
+ * @version $Id: utils.php 592 2015-04-12 19:53:44Z imoore76 $
+ * @see phpVBoxConfigClass
+ * @package phpVirtualBox
+ *
+*/
+
+require_once(dirname(__FILE__).'/config.php');
+
+/**
+ * Initialize session.
+ * @param boolean $keepopen keep session open? The default is
+ * to close the session after $_SESSION has been populated.
+ * @uses $_SESSION
+ */
+function session_init($keepopen = false) {
+
+ $settings = new phpVBoxConfigClass();
+
+ // Sessions provided by auth module?
+ if(@$settings->auth->capabilities['sessionStart']) {
+ call_user_func(array($settings->auth, $settings->auth->capabilities['sessionStart']), $keepopen);
+ return;
+ }
+
+ // No session support? No login...
+ if(@$settings->noAuth || !function_exists('session_start')) {
+ global $_SESSION;
+ $_SESSION['valid'] = true;
+ $_SESSION['authCheckHeartbeat'] = time();
+ $_SESSION['admin'] = true;
+ return;
+ }
+
+ // Session not is auto-started by PHP
+ if(!ini_get('session.auto_start')) {
+
+ ini_set('session.use_trans_sid', 0);
+ ini_set('session.use_only_cookies', 1);
+
+ // Session path
+ if(isset($settings->sessionSavePath)) {
+ session_save_path($settings->sessionSavePath);
+ }
+
+ if(isset($settings->session_name)) {
+ $session_name = $settings->session_name;
+ } else {
+ $session_name = md5($_SERVER['DOCUMENT_ROOT'].$_SERVER['HTTP_USER_AGENT'].dirname(__FILE__));
+ }
+ session_name($session_name);
+ session_start();
+ }
+
+ if(!$keepopen)
+ session_write_close();
+
+}
+
+
+/**
+ * Clean (strip slashes from if applicable) $_GET and $_POST and return
+ * an array containing a merged array of both.
+ * @return array
+ */
+function clean_request() {
+
+ if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
+ $json = json_decode(file_get_contents('php://input'), true);
+ if(!is_array($json))
+ $json = array();
+ } else {
+ $json = array();
+ }
+ $req = array_merge_recursive($_GET, $_POST);
+ return array_merge_recursive($req, $json);
+
+}
+
+if(!function_exists('hash')) {
+// Lower security, but better than nothing
+/**
+ * Return a hash of the passed string. Mimmics PHP's hash() params
+ * @param unused $type
+ * @param string $str string to hash
+ */
+function hash($type,$str='') {
+ return sha1(json_encode($str));
+}
} \ No newline at end of file
diff --git a/endpoints/rdp.php b/endpoints/rdp.php
index 991ec8f..4da62fe 100644
--- a/endpoints/rdp.php
+++ b/endpoints/rdp.php
@@ -1,32 +1,32 @@
-<?php
-/**
- * Simple RDP connection file generator
- *
- * @author Ian Moore (imoore76 at yahoo dot com)
- * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
- * @version $Id: rdp.php 591 2015-04-11 22:40:47Z imoore76 $
- * @package phpVirtualBox
- *
- */
-
-# Turn off PHP notices
-error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING);
-
-require_once(dirname(__FILE__).'/lib/utils.php');
-$_GET = clean_request();
-
-foreach(array('port','host','vm') as $g) {
- @$_GET[$g] = str_replace(array("\n","\r","\0"),'',@$_GET[$g]);
-}
-
-
-header("Content-type: application/x-rdp",true);
-header("Content-disposition: attachment; filename=\"". str_replace(array('"','.'),'_',$_GET['vm']) .".rdp\"",true);
-
-
-echo('
-full address:s:'.@$_GET['host'].(@$_GET['port'] ? ':'.@$_GET['port'] : '').'
-compression:i:1
-displayconnectionbar:i:1
-protocol:i:4
-');
+<?php
+/**
+ * Simple RDP connection file generator
+ *
+ * @author Ian Moore (imoore76 at yahoo dot com)
+ * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
+ * @version $Id: rdp.php 591 2015-04-11 22:40:47Z imoore76 $
+ * @package phpVirtualBox
+ *
+ */
+
+# Turn off PHP notices
+error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING);
+
+require_once(dirname(__FILE__).'/lib/utils.php');
+$_GET = clean_request();
+
+foreach(array('port','host','vm') as $g) {
+ @$_GET[$g] = str_replace(array("\n","\r","\0"),'',@$_GET[$g]);
+}
+
+
+header("Content-type: application/x-rdp",true);
+header("Content-disposition: attachment; filename=\"". str_replace(array('"','.'),'_',$_GET['vm']) .".rdp\"",true);
+
+
+echo('
+full address:s:'.@$_GET['host'].(@$_GET['port'] ? ':'.@$_GET['port'] : '').'
+compression:i:1
+displayconnectionbar:i:1
+protocol:i:4
+');