summaryrefslogtreecommitdiffstats
path: root/endpoints/lib
diff options
context:
space:
mode:
authorTudor Holton <tudor@tudorholton.com>2018-07-13 17:36:48 +1000
committerTudor Holton <tudor@tudorholton.com>2018-07-13 17:36:48 +1000
commit3c61d5eae51e27082945f629d0076edf0c309f96 (patch)
tree01146078eecd1a0fc610ae225192debed7925999 /endpoints/lib
parent013a2e172f2a3bf5cb739dda2c120306918a35d7 (diff)
downloadphpvirtualbox-3c61d5eae51e27082945f629d0076edf0c309f96.zip
phpvirtualbox-3c61d5eae51e27082945f629d0076edf0c309f96.tar.gz
phpvirtualbox-3c61d5eae51e27082945f629d0076edf0c309f96.tar.bz2
Convert from DOS to UNIX format. Update changelog for release.
Diffstat (limited to 'endpoints/lib')
-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
7 files changed, 941 insertions, 941 deletions
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