You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

config.php 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. /**
  3. * phpVirtualBox configuration class. Parses user configuration, applies
  4. * defaults, and sanitizes user values.
  5. *
  6. * @author Ian Moore (imoore76 at yahoo dot com)
  7. * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
  8. * @version $Id: config.php 595 2015-04-17 09:50:36Z imoore76 $
  9. * @package phpVirtualBox
  10. * @see config.php-example
  11. *
  12. */
  13. /*
  14. * This version of phpVirtualBox
  15. */
  16. define('PHPVBOX_VER', '5.2-1');
  17. class phpVBoxConfigClass {
  18. /* DEFAULTS */
  19. /**
  20. * Default language
  21. * @var string
  22. */
  23. var $language = 'en';
  24. /**
  25. * Exclusively use phpVirtualBox groups rather than
  26. * VirtualBox groups
  27. */
  28. var $phpVboxGroups = false;
  29. /**
  30. * Preview screen width
  31. * @var integer
  32. */
  33. var $previewWidth = 180;
  34. /**
  35. * Aspect ratio of preview screen
  36. * @var float
  37. */
  38. var $previewAspectRatio = 1.6;
  39. /**
  40. * Allow users to delete media when it is removed
  41. * @var boolean
  42. */
  43. var $deleteOnRemove = true;
  44. /**
  45. * Restrict file / folder browsers to files ending in extensions found in this array
  46. * @var array
  47. */
  48. var $browserRestrictFiles = array('.iso','.vdi','.vmdk','.img','.bin','.vhd','.hdd','.ovf','.ova','.xml','.vbox','.cdr','.dmg','.ima','.dsk','.vfd');
  49. /**
  50. * Force file / folder browser to use local PHP functions rather than VirtualBox's IVFSExplorer.
  51. * If this is set to true, the assumption is made that the web server is on the same host as VirtualBox.
  52. * @var boolean
  53. */
  54. var $browserLocal = false;
  55. /**
  56. * List of console resolutions available on console tab
  57. * @var array
  58. */
  59. var $consoleResolutions = array('640x480','800x600','1024x768','1280x720','1440x900');
  60. /**
  61. * Maximum number of NICs displayed per VM
  62. * @var integer
  63. */
  64. var $nicMax = 4;
  65. /**
  66. * Max number of operations to keep in progress list
  67. * @var integer
  68. */
  69. var $maxProgressList = 5;
  70. /**
  71. * Enable custom icon per VM
  72. * @var boolean
  73. */
  74. var $enableCustomIcons = false;
  75. /**
  76. * true if there is no user supplied config.php found.
  77. * @var boolean
  78. */
  79. var $warnDefault = false;
  80. /**
  81. * Set the standard VRDE port number range to be used when
  82. * creating new VMs
  83. * @var string
  84. */
  85. var $vrdeports = '9000-9100';
  86. /**
  87. * Key used to uniquely identify the current server in this
  88. * instantiation of phpVBoxConfigClass.
  89. * Set in __construct()
  90. * @var string
  91. */
  92. var $key = null;
  93. /**
  94. * Auth library object instance. See lib/auth for classes.
  95. * Set in __construct() based on authLib config setting value.
  96. * @var phpvbAuth
  97. */
  98. var $auth = null;
  99. /**
  100. * Enable VirtualBox start / stop configuration.
  101. * Only available in Linux (I beleive)
  102. * @var boolean
  103. */
  104. var $vboxAutostartConfig = false;
  105. /**
  106. * Authentication capabilities provided by authentication module.
  107. * Set in __construct
  108. * @var phpvbAuthBuiltin::authCapabilities
  109. */
  110. var $authCapabilities = null;
  111. /**
  112. * Configuration passed to authentication module
  113. * @var array
  114. */
  115. var $authConfig = array();
  116. /**
  117. * Event listener timeout in seconds.
  118. * @var integer
  119. */
  120. var $eventListenerTimeout = 20;
  121. /**
  122. * Read user configuration, apply defaults, and do some sanity checking
  123. * @see vboxconnector
  124. */
  125. function __construct() {
  126. @include_once(dirname(dirname(dirname(__FILE__))).'/config.php');
  127. $ep = error_reporting(0);
  128. /* Apply object vars of configuration class to this class */
  129. if(class_exists('phpVBoxConfig')) {
  130. $c = new phpVBoxConfig();
  131. foreach(get_object_vars($c) as $k => $v) {
  132. // Safety checks
  133. if($k == 'browserRestrictFiles' && !is_array($v)) continue;
  134. if($k == 'consoleResolutions' && !is_array($v)) continue;
  135. if($k == 'browserRestrictFolders' && !is_array($v)) continue;
  136. $this->$k = $v;
  137. }
  138. /* User config.php does not exist. Send warning */
  139. } else {
  140. $this->warnDefault = true;
  141. }
  142. // Ignore any server settings if we have servers
  143. // in the servers array
  144. if(isset($this->servers) && is_array($this->servers) && count($this->servers) && is_array($this->servers[0])) {
  145. unset($this->location);
  146. unset($this->user);
  147. unset($this->pass);
  148. }
  149. // Set to selected server based on browser cookie
  150. if(isset($_COOKIE['vboxServer']) && isset($this->servers) && is_array($this->servers) && count($this->servers)) {
  151. foreach($this->servers as $s) {
  152. if($s['name'] == $_COOKIE['vboxServer']) {
  153. foreach($s as $k=>$v) $this->$k = $v;
  154. break;
  155. }
  156. }
  157. // If servers is not an array, set to empty array
  158. } elseif(!isset($this->servers) || !is_array($this->servers)) {
  159. $this->servers = array();
  160. }
  161. // We still have no server set, use the first one from
  162. // the servers array
  163. if(empty($this->location) && count($this->servers)) {
  164. foreach($this->servers[0] as $k=>$v) $this->$k = $v;
  165. }
  166. // Make sure name is set
  167. if(!isset($this->name) || !$this->name) {
  168. $this->name = parse_url($this->location);
  169. $this->name = $this->name['host'];
  170. }
  171. // Key used to uniquely identify this server in this
  172. // phpvirtualbox installation
  173. $this->setKey();
  174. // legacy rdpHost setting
  175. if(!empty($this->rdpHost) && empty($this->consoleHost))
  176. $this->consoleHost = $this->rdpHost;
  177. // Ensure authlib is set
  178. if(empty($this->authLib)) $this->authLib = 'Builtin';
  179. // include interface
  180. include_once(dirname(__FILE__).'/authinterface.php');
  181. include_once(dirname(__FILE__).'/auth/'.str_replace(array('.','/','\\'),'',$this->authLib).'.php');
  182. // Check for session functionality
  183. if(!function_exists('session_start')) $this->noAuth = true;
  184. $alib = "phpvbAuth{$this->authLib}";
  185. $this->auth = new $alib(@$this->authConfig);
  186. $this->authCapabilities = $this->auth->capabilities;
  187. /* Sanity checks */
  188. if(!@$this->nicMax)
  189. $this->nicMax = 4;
  190. $this->previewUpdateInterval = max(3, @$this->previewUpdateInterval);
  191. error_reporting($ep);
  192. }
  193. /**
  194. * Set VirtualBox server to use
  195. * @param string $server server from config.php $servers array
  196. */
  197. function setServer($server) {
  198. // do nothing if we are already using this server
  199. if($server == $this->name) return;
  200. foreach($this->servers as $s) {
  201. if($s['name'] == $server) {
  202. foreach($s as $k=>$v) $this->$k = $v;
  203. $this->setKey();
  204. break;
  205. }
  206. }
  207. }
  208. /**
  209. * Generate a key for current server settings and populate $this->key
  210. */
  211. function setKey() {
  212. $this->key = md5($this->location);
  213. }
  214. /**
  215. * Return the name of the server marked as the authentication master
  216. * @return string name of server marked as authMaster
  217. */
  218. function getServerAuthMaster() {
  219. foreach($this->servers as $s) {
  220. if($s['authMaster']) {
  221. return $s['name'];
  222. }
  223. }
  224. return @$this->servers[0]['name'];
  225. }
  226. }