Project

General

Profile

Download (14.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	index.php
5
*/
6
/* ====================================================================
7
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
8
 *	Copyright (c)  2004, 2005 Scott Ullrich
9
 *
10
 *	Redistribution and use in source and binary forms, with or without modification,
11
 *	are permitted provided that the following conditions are met:
12
 *
13
 *	1. Redistributions of source code must retain the above copyright notice,
14
 *		this list of conditions and the following disclaimer.
15
 *
16
 *	2. Redistributions in binary form must reproduce the above copyright
17
 *		notice, this list of conditions and the following disclaimer in
18
 *		the documentation and/or other materials provided with the
19
 *		distribution.
20
 *
21
 *	3. All advertising materials mentioning features or use of this software
22
 *		must display the following acknowledgment:
23
 *		"This product includes software developed by the pfSense Project
24
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
25
 *
26
 *	4. The names "pfSense" and "pfSense Project" must not be used to
27
 *		 endorse or promote products derived from this software without
28
 *		 prior written permission. For written permission, please contact
29
 *		 coreteam@pfsense.org.
30
 *
31
 *	5. Products derived from this software may not be called "pfSense"
32
 *		nor may "pfSense" appear in their names without prior written
33
 *		permission of the Electric Sheep Fencing, LLC.
34
 *
35
 *	6. Redistributions of any form whatsoever must retain the following
36
 *		acknowledgment:
37
 *
38
 *	"This product includes software developed by the pfSense Project
39
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
40
 *
41
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
42
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
45
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
53
 *
54
 *	====================================================================
55
 *
56
 */
57
/*
58
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig
59
	pfSense_MODULE: interfaces
60
*/
61

    
62
##|+PRIV
63
##|*IDENT=page-system-login/logout
64
##|*NAME=System: Login / Logout page / Dashboard
65
##|*DESCR=Allow access to the 'System: Login / Logout' page and Dashboard.
66
##|*MATCH=index.php*
67
##|-PRIV
68

    
69
// Turn on buffering to speed up rendering
70
ini_set('output_buffering', 'true');
71

    
72
// Start buffering with a cache size of 100000
73
ob_start(null, "1000");
74

    
75
## Load Essential Includes
76
require_once('guiconfig.inc');
77
require_once('functions.inc');
78
require_once('notices.inc');
79
require_once("pkg-utils.inc");
80

    
81
if (isset($_GET['closenotice'])) {
82
	close_notice($_GET['closenotice']);
83
	echo get_menu_messages();
84
	exit;
85
}
86

    
87
if ($g['disablecrashreporter'] != true) {
88
	// Check to see if we have a crash report
89
	$x = 0;
90
	if (file_exists("/tmp/PHP_errors.log")) {
91
		$total = `/usr/bin/grep -vi warning /tmp/PHP_errors.log | /usr/bin/wc -l | /usr/bin/awk '{ print $1 }'`;
92
		if ($total > 0) {
93
			$x++;
94
		}
95
	}
96
	$crash = glob("/var/crash/*");
97
	$skip_files = array(".", "..", "minfree", "");
98
	if (is_array($crash)) {
99
		foreach ($crash as $c) {
100
			if (!in_array(basename($c), $skip_files)) {
101
				$x++;
102
			}
103
		}
104
		if ($x > 0) {
105
			$savemsg = "{$g['product_name']} has detected a crash report or programming bug.  Click <a href='crash_reporter.php'>here</a> for more information.";
106
		}
107
	}
108
}
109

    
110
##build list of widgets
111
foreach (glob("/usr/local/www/widgets/widgets/*.widget.php") as $file)
112
{
113
	$name = basename($file, '.widget.php');
114
	$widgets[ $name ] = array('name' => ucwords(str_replace('_', ' ', $name)), 'display' => 'none');
115
}
116

    
117
##insert the system information widget as first, so as to be displayed first
118
unset($widgets['system_information']);
119
$widgets = array_merge(array('system_information' => array('name' => 'System Information')), $widgets);
120

    
121
##if no config entry found, initialize config entry
122
if (!is_array($config['widgets'])) {
123
	$config['widgets'] = array();
124
}
125

    
126
if ($_POST && $_POST['sequence']) {
127
	$config['widgets']['sequence'] = rtrim($_POST['sequence'], ',');
128

    
129
	foreach ($widgets as $widgetname => $widgetconfig) {
130
		if ($_POST[$widgetname . '-config']) {
131
			$config['widgets'][$widgetname . '-config'] = $_POST[$name . '-config'];
132
		}
133
	}
134

    
135
	write_config(gettext("Widget configuration has been changed."));
136
	header("Location: /");
137
	exit;
138
}
139

    
140
## Load Functions Files
141
require_once('includes/functions.inc.php');
142

    
143
## Check to see if we have a swap space,
144
## if true, display, if false, hide it ...
145
if (file_exists("/usr/sbin/swapinfo")) {
146
	$swapinfo = `/usr/sbin/swapinfo`;
147
	if (stristr($swapinfo, '%') == true) $showswap=true;
148
}
149

    
150
## User recently restored his config.
151
## If packages are installed lets resync
152
if (file_exists('/conf/needs_package_sync')) {
153
	if ($config['installedpackages'] <> '' && is_array($config['installedpackages']['package'])) {
154
		if ($g['platform'] == $g['product_name'] || $g['platform'] == "nanobsd") {
155
			## If the user has logged into webGUI quickly while the system is booting then do not redirect them to
156
			## the package reinstall page. That is about to be done by the boot script anyway.
157
			## The code in head.inc will put up a notice to the user.
158
			if (!platform_booting()) {
159
				header('Location: pkg_mgr_install.php?mode=reinstallall');
160
				exit;
161
			}
162
		}
163
	} else {
164
		conf_mount_rw();
165
		@unlink('/conf/needs_package_sync');
166
		conf_mount_ro();
167
	}
168
}
169

    
170
## If it is the first time webConfigurator has been
171
## accessed since initial install show this stuff.
172
if (file_exists('/conf/trigger_initial_wizard')) {
173
?>
174
<!DOCTYPE html>
175
<html lang="en">
176
<head>
177
	<link rel="stylesheet" href="/bootstrap/css/pfSense.css" />
178
	<title><?=$g['product_name']?>.localdomain - <?=$g['product_name']?> first time setup</title>
179
	<meta http-equiv="refresh" content="1;url=wizard.php?xml=setup_wizard.xml" />
180
</head>
181
<body id="loading-wizard" class="no-menu">
182
	<div id="jumbotron">
183
		<div class="container">
184
			<div class="col-sm-offset-3 col-sm-6 col-xs-12">
185
				<font color="white">
186
				<p><h3><?=sprintf(gettext("Welcome to %s!\n"), $g['product_name'])?></h3></p>
187
				<p><?=gettext("One moment while we start the initial setup wizard.")?></p>
188
				<p><?=gettext("Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal GUI.")?></p>
189
				<p><?=sprintf(gettext("To bypass the wizard, click on the %s logo on the initial page."), $g['product_name'])?></p>
190
				</font>
191
			</div>
192
		</div>
193
	</div>
194
</body>
195
</html>
196
<?php
197
	exit;
198
}
199

    
200
## Find out whether there's hardware encryption or not
201
unset($hwcrypto);
202
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
203
if ($fd) {
204
	while (!feof($fd)) {
205
		$dmesgl = fgets($fd);
206
		if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)
207
			or preg_match("/.*(VIA Padlock)/", $dmesgl, $matches)
208
			or preg_match("/^safe.: (\w.*)/", $dmesgl, $matches)
209
			or preg_match("/^ubsec.: (.*?),/", $dmesgl, $matches)
210
			or preg_match("/^padlock.: <(.*?)>,/", $dmesgl, $matches)
211
			or preg_match("/^glxsb.: (.*?),/", $dmesgl, $matches)
212
			or preg_match("/^aesni.: (.*?),/", $dmesgl, $matches)) {
213
			$hwcrypto = $matches[1];
214
			break;
215
		}
216
	}
217
	fclose($fd);
218
}
219

    
220
##build widget saved list information
221
if ($config['widgets'] && $config['widgets']['sequence'] != "") {
222
	$pconfig['sequence'] = $config['widgets']['sequence'];
223
	$widgetsfromconfig = array();
224

    
225
	foreach (explode(',', $pconfig['sequence']) as $line)
226
	{
227
		list($file, $col, $display) = explode(':', $line);
228

    
229
		// be backwards compatible
230
		$offset = strpos($file, '-container');
231
		if (false !== $offset)
232
			$file = substr($file, 0, $offset);
233

    
234
		$widgetsfromconfig[ $file ] = array(
235
			'name' => ucwords(str_replace('_', ' ', $file)),
236
			'col' => $col,
237
			'display' => $display,
238
		);
239
	}
240

    
241
	// add widgets that may not be in the saved configuration, in case they are to be displayed later
242
	$widgets = $widgetsfromconfig + $widgets;
243

    
244
	##find custom configurations of a particular widget and load its info to $pconfig
245
	foreach ($widgets as $widgetname => $widgetconfig) {
246
		if ($config['widgets'][$name . '-config']) {
247
			$pconfig[$name . '-config'] = $config['widgets'][$name . '-config'];
248
		}
249
	}
250
}
251

    
252
##build list of php include files
253
$phpincludefiles = array();
254
$directory = "/usr/local/www/widgets/include/";
255
$dirhandle = opendir($directory);
256
$filename = "";
257
while (false !== ($filename = readdir($dirhandle))) {
258
	$phpincludefiles[] = $filename;
259
}
260
foreach ($phpincludefiles as $includename) {
261
	if (!stristr($includename, ".inc")) {
262
		continue;
263
	}
264
	if (file_exists($directory . $includename)) {
265
		include($directory . $includename);
266
	}
267
}
268

    
269
## Set Page Title and Include Header
270
$pgtitle = array(gettext("Status: Dashboard"));
271
include("head.inc");
272

    
273
/* Print package server mismatch warning. See https://redmine.pfsense.org/issues/484 */
274
if (!verify_all_package_servers()) {
275
	print_info_box(package_server_mismatch_message());
276
}
277

    
278
if ($savemsg) {
279
	print_info_box($savemsg);
280
}
281

    
282
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
283

    
284
?>
285

    
286
<div class="panel panel-default">
287
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Available Widgets"); ?></h2></div>
288
	<div class="panel-body">
289
<?php foreach ($widgets as $widgetname => $widgetconfig): ?>
290
	<?php if ($widgetconfig['display'] == 'none'): ?>
291
		<div class="col-sm-3"><a href="#"><i class="icon icon-plus"></i> <?=$widgetconfig['name']?></a></div>
292
	<?php endif; ?>
293
<?php endforeach; ?>
294
	</div>
295
</div>
296

    
297
<div class="modal fade">
298
	<div class="modal-dialog">
299
		<div class="modal-content">
300
			<div class="modal-header">
301
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
302
				<h4 class="modal-title"><?=gettext("Welcome to the Dashboard page"); ?>!</h4>
303
			</div>
304
			<div class="modal-body">
305
				<p>
306
					<?=gettext("This page allows you to customize the information you want to be displayed!");?>
307
					<?=gettext("To get started click the");?> FIXME <?=gettext("icon to add widgets.");?><br />
308
					<br />
309
					<?=gettext("You can move any widget around by clicking and dragging the title.");?>
310
				</p>
311
			</div>
312
			<div class="modal-footer">
313
				<button type="button" class="btn btn-default btn-primary" data-dismiss="modal">Close</button>
314
			</div>
315
		</div>
316
	</div>
317
</div>
318

    
319
<div class="hidden" id="widgetSequence">
320
	<form action="/" method="post" id="widgetSequence">
321
		<input type="hidden" name="sequence" value="" />
322

    
323
		<button type="submit" class="btn btn-primary">Store widget configuration</button>
324
	</form>
325
</div>
326

    
327
<?php
328
$widgetColumns = array();
329
foreach ($widgets as $widgetname => $widgetconfig)
330
{
331
	if ($widgetconfig['display'] == 'none')
332
		continue;
333

    
334
	if (!file_exists('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php')) {
335
		continue;
336
	}
337

    
338
	if (!isset($widgetColumns[ $widgetconfig['col'] ]))
339
		$widgetColumns[ $widgetconfig['col'] ] = array();
340

    
341
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
342
}
343
?>
344

    
345
<div class="row">
346
<?php foreach ($widgetColumns as $column => $columnWidgets):?>
347
	<div class="col-md-6" id="widgets-<?=$column?>">
348
<?php foreach ($columnWidgets as $widgetname => $widgetconfig):?>
349
		<div class="panel panel-default" id="widget-<?=$widgetname?>">
350
			<div class="panel-heading">
351
				<?=$widgetconfig['name']?>
352
				<span class="icons">
353
					<a data-toggle="collapse" href="#widget-<?=$widgetname?> .panel-footer" class="config hidden">
354
						<i class="icon icon-wrench"></i>
355
					</a>
356
					<a data-toggle="collapse" href="#widget-<?=$widgetname?> .panel-body">
357
						<!--  actual icon is determined in css based on state of body -->
358
						<i class="icon icon-plus-sign"></i>
359
					</a>
360
					<a data-toggle="close" href="#widget-<?=$widgetname?>">
361
						<i class="icon icon-remove-sign"></i>
362
					</a>
363
				</span>
364
			</div>
365
			<div class="panel-body collapse<?=($widgetconfig['display']=='close' ? '' : ' in')?>">
366
				<?php include('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php'); ?>
367
			</div>
368
		</div>
369
<?php endforeach; ?>
370
	</div>
371
<?php endforeach; ?>
372
</div>
373

    
374
<script>
375
function updateWidgets()
376
{
377
	var sequence = '';
378

    
379
	$('.container .col-md-6').each(function(idx, col){
380
		$('.panel', col).each(function(idx, widget){
381
			var isOpen = $('.panel-body', widget).hasClass('in');
382

    
383
			sequence += widget.id.split('-')[1] +':'+ col.id.split('-')[1] +':'+ (isOpen ? 'open' : 'close') +',';
384
		});
385
	});
386

    
387
	$('#widgetSequence').removeClass('hidden');
388
	$('input[name=sequence]', $('#widgetSequence')).val(sequence);
389
}
390

    
391
events.push(function() {
392
	// Hide configuration button for panels without configuration
393
	$('.container .panel-heading a.config').each(function (idx, el){
394
		var config = $(el).parents('.panel').children('.panel-footer');
395
		if (config.length == 1)
396
			$(el).removeClass('hidden');
397
	});
398

    
399
	// Initial state & toggle icons of collapsed panel
400
	$('.container .panel-heading a[data-toggle="collapse"]').each(function (idx, el){
401
		var body = $(el).parents('.panel').children('.panel-body'), isOpen = body.hasClass('in');
402
		$(el).toggleClass('icon-plus-sign', !isOpen);
403
		$(el).toggleClass('icon-minus-sign', isOpen);
404

    
405
		body.on('shown.bs.collapse', function(){
406
			$(el).toggleClass('icon-minus-sign', true);
407
			$(el).toggleClass('icon-plus-sign', false);
408

    
409
			updateWidgets();
410
		});
411

    
412
		body.on('hidden.bs.collapse', function(){
413
			$(el).toggleClass('icon-minus-sign', false);
414
			$(el).toggleClass('icon-plus-sign', true);
415

    
416
			updateWidgets();
417
		});
418
	});
419

    
420
	// Make panels destroyable
421
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el){
422
		$(el).on('click', function(e){
423
			$(el).parents('.panel').remove();
424
			updateWidgets();
425
		})
426
	});
427

    
428
	// Make panels sortable
429
	$('.container .col-md-6').sortable({
430
		handle: '.panel-heading',
431
		cursor: 'grabbing',
432
		connectWith: '.container .col-md-6',
433
		update: updateWidgets
434
	});
435
});
436
</script>
437
<?php
438
//build list of javascript include files
439
foreach (glob('widgets/javascript/*.js') as $file)
440
	echo '<script src="'.$file.'"></script>';
441

    
442
include("foot.inc");
(82-82/235)