summaryrefslogtreecommitdiffstats
path: root/endpoints/lib/config.php
blob: 0a2eb24d1fdad3f4af8a323ccc68547085a0bc44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
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', '6.1-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'];
	}

}