Project

General

Profile

Download (15.3 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

    
97
	$crash = glob("/var/crash/*");
98
	$skip_files = array(".", "..", "minfree", "");
99

    
100
	if (is_array($crash)) {
101
		foreach ($crash as $c) {
102
			if (!in_array(basename($c), $skip_files)) {
103
				$x++;
104
			}
105
		}
106

    
107
		if ($x > 0) {
108
			$savemsg = "{$g['product_name']} has detected a crash report or programming bug.  Click <a href='crash_reporter.php'>here</a> for more information.";
109
		}
110
	}
111
}
112

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

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

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

    
129
if ($_POST && $_POST['sequence']) {
130

    
131
	$config['widgets']['sequence'] = rtrim($_POST['sequence'], ',');
132

    
133
	foreach ($widgets as $widgetname => $widgetconfig) {
134
		if ($_POST[$widgetname . '-config']) {
135
			$config['widgets'][$widgetname . '-config'] = $_POST[$name . '-config'];
136
		}
137
	}
138

    
139
	write_config(gettext("Widget configuration has been changed."));
140
	header("Location: /");
141
	exit;
142
}
143

    
144
## Load Functions Files
145
require_once('includes/functions.inc.php');
146

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

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

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

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

    
224
##build widget saved list information
225
if ($config['widgets'] && $config['widgets']['sequence'] != "") {
226
	$pconfig['sequence'] = $config['widgets']['sequence'];
227
	$widgetsfromconfig = array();
228

    
229
	foreach (explode(',', $pconfig['sequence']) as $line)
230
	{
231
		list($file, $col, $display) = explode(':', $line);
232

    
233
		// be backwards compatible
234
		$offset = strpos($file, '-container');
235
		if (false !== $offset)
236
			$file = substr($file, 0, $offset);
237

    
238
		$widgetsfromconfig[ $file ] = array(
239
			'name' => ucwords(str_replace('_', ' ', $file)),
240
			'col' => $col,
241
			'display' => $display,
242
		);
243
	}
244

    
245
	// add widgets that may not be in the saved configuration, in case they are to be displayed later
246
	$widgets = $widgetsfromconfig + $widgets;
247

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

    
256
##build list of php include files
257
$phpincludefiles = array();
258
$directory = "/usr/local/www/widgets/include/";
259
$dirhandle = opendir($directory);
260
$filename = "";
261

    
262
while (false !== ($filename = readdir($dirhandle))) {
263
	$phpincludefiles[] = $filename;
264
}
265

    
266
foreach ($phpincludefiles as $includename) {
267
	if (!stristr($includename, ".inc")) {
268
		continue;
269
	}
270
	if (file_exists($directory . $includename)) {
271
		include($directory . $includename);
272
	}
273
}
274

    
275
## Set Page Title and Include Header
276
$pgtitle = array(gettext("Status: Dashboard"));
277
include("head.inc");
278

    
279
/* Print package server mismatch warning. See https://redmine.pfsense.org/issues/484 */
280
if (!verify_all_package_servers()) {
281
	print_info_box(package_server_mismatch_message());
282
}
283

    
284
if ($savemsg) {
285
	print_info_box($savemsg);
286
}
287

    
288
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
289

    
290
?>
291

    
292
<div class="panel panel-default" id="widget-available">
293
	<div class="panel-heading"><?=gettext("Available Widgets"); ?>
294
		<span class="icons">
295
			<a data-toggle="collapse" href="#widget-available .panel-body" name="widgets-available">
296
				<i class="icon-white icon-plus-sign"></i>
297
			</a>
298
		</span>
299
	</div>
300
	<div class="panel-body collapse out">
301
		<div class="content">
302
			<div class="row">
303
<?php
304
foreach ($widgets as $widgetname => $widgetconfig):
305
	if ($widgetconfig['display'] == 'none'):
306
?>
307
		<div class="col-sm-3"><a href="#" name="btnadd-<?=$widgetname?>"><i class="icon icon-plus"></i> <?=$widgetconfig['name']?></a></div>
308
	<?php endif; ?>
309
<?php endforeach; ?>
310
			</div>
311
		</div>
312
	</div>
313
</div>
314

    
315
<div class="modal fade">
316
	<div class="modal-dialog">
317
		<div class="modal-content">
318
			<div class="modal-header">
319
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
320
				<h4 class="modal-title"><?=gettext("Welcome to the Dashboard page"); ?>!</h4>
321
			</div>
322
			<div class="modal-body">
323
				<p>
324
					<?=gettext("This page allows you to customize the information you want to be displayed!");?>
325
					<?=gettext("To get started click the ");?> FIXME <?=gettext(" icon to add widgets.");?><br />
326
					<br />
327
					<?=gettext("You can move any widget around by clicking and dragging the title.");?>
328
				</p>
329
			</div>
330
			<div class="modal-footer">
331
				<button type="button" class="btn btn-default btn-primary" data-dismiss="modal">Close</button>
332
			</div>
333
		</div>
334
	</div>
335
</div>
336

    
337
<div class="hidden" id="widgetSequence">
338
	<form action="/" method="post" id="widgetSequence" name="widgetForm">
339
		<input type="hidden" name="sequence" value="" />
340

    
341
		<button type="submit" id="btnstore" class="btn btn-primary">Store widget configuration</button>
342
	</form>
343
</div>
344

    
345
<?php
346
$widgetColumns = array();
347
foreach ($widgets as $widgetname => $widgetconfig)
348
{
349
	if ($widgetconfig['display'] == 'none')
350
		continue;
351

    
352
	if (!file_exists('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php')) {
353
		continue;
354
	}
355

    
356
	if (!isset($widgetColumns[ $widgetconfig['col'] ]))
357
		$widgetColumns[ $widgetconfig['col'] ] = array();
358

    
359
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
360
}
361
?>
362

    
363
<div class="row">
364
<?php foreach ($widgetColumns as $column => $columnWidgets):?>
365
	<div class="col-md-6" id="widgets-<?=$column?>">
366
<?php foreach ($columnWidgets as $widgetname => $widgetconfig):?>
367
		<div class="panel panel-default" id="widget-<?=$widgetname?>">
368
			<div class="panel-heading">
369
				<?=$widgetconfig['name']?>
370
				<span class="icons">
371
					<a data-toggle="collapse" href="#widget-<?=$widgetname?> .panel-footer" class="config hidden">
372
						<i class="icon-white icon-wrench"></i>
373
					</a>
374
					<a data-toggle="collapse" href="#widget-<?=$widgetname?> .panel-body">
375
						<!--  actual icon is determined in css based on state of body -->
376
						<i class="icon-white icon-plus-sign"></i>
377
					</a>
378
					<a data-toggle="close" href="#widget-<?=$widgetname?>">
379
						<i class="icon-white icon-remove-sign"></i>
380
					</a>
381
				</span>
382
			</div>
383
			<div class="panel-body collapse<?=($widgetconfig['display']=='close' ? '' : ' in')?>">
384
				<?php include('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php'); ?>
385
			</div>
386
		</div>
387
<?php endforeach; ?>
388
	</div>
389
<?php endforeach; ?>
390
</div>
391

    
392
<script>
393
function updateWidgets(newWidget)
394
{
395
	var sequence = '';
396

    
397
	$('.container .col-md-6').each(function(idx, col){
398
		$('.panel', col).each(function(idx, widget){
399
			var isOpen = $('.panel-body', widget).hasClass('in');
400

    
401
			sequence += widget.id.split('-')[1] +':'+ col.id.split('-')[1] +':'+ (isOpen ? 'open' : 'close') +',';
402
		});
403
	});
404

    
405
	if (typeof newWidget !== 'undefined')
406
		sequence += newWidget + ':' + 'col2:close';
407

    
408
	$('#widgetSequence').removeClass('hidden');
409
	$('input[name=sequence]', $('#widgetSequence')).val(sequence);
410
}
411

    
412
events.push(function() {
413
	// Hide configuration button for panels without configuration
414
	$('.container .panel-heading a.config').each(function (idx, el){
415
		var config = $(el).parents('.panel').children('.panel-footer');
416
		if (config.length == 1)
417
			$(el).removeClass('hidden');
418
	});
419

    
420
	// Initial state & toggle icons of collapsed panel
421
	$('.container .panel-heading a[data-toggle="collapse"]').each(function (idx, el){
422
		var body = $(el).parents('.panel').children('.panel-body')
423
		var isOpen = body.hasClass('in');
424

    
425
		$(el).children('i').toggleClass('icon-plus-sign', !isOpen);
426
		$(el).children('i').toggleClass('icon-minus-sign', isOpen);
427

    
428
		body.on('shown.bs.collapse', function(){
429
			$(el).children('i').toggleClass('icon-minus-sign', true);
430
			$(el).children('i').toggleClass('icon-plus-sign', false);
431

    
432
			if($(el).closest('a').attr('name') != 'widgets-available') {
433
				updateWidgets();
434
			}
435
		});
436

    
437
		body.on('hidden.bs.collapse', function(){
438
			$(el).children('i').toggleClass('icon-minus-sign', false);
439
			$(el).children('i').toggleClass('icon-plus-sign', true);
440

    
441
			if($(el).closest('a').attr('name') != 'widgets-available') {
442
				updateWidgets();
443
			}
444
		});
445
	});
446

    
447
	// Make panels destroyable
448
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el){
449
		$(el).on('click', function(e){
450
			$(el).parents('.panel').remove();
451
			updateWidgets();
452
		})
453
	});
454

    
455
	// Make panels sortable
456
	$('.container .col-md-6').sortable({
457
		handle: '.panel-heading',
458
		cursor: 'grabbing',
459
		connectWith: '.container .col-md-6',
460
		update: updateWidgets
461
	});
462

    
463
	// On clicking a widget to install . .
464
	$('[name^=btnadd-]').click(function(event) {
465
		// Extract the widget name from the button name that got us here
466
		var widgetToAdd = this.name.replace('btnadd-', '');
467

    
468
		// Set its display type to 'close'
469
		<?php $widgets[widgetToAdd]['display'] = 'close'; ?>
470

    
471
		// Add it to the list of displayed widgets
472
		updateWidgets(widgetToAdd);
473

    
474
		// We don't want to see the "Store" button because we are doing that automatically
475
		$('#btnstore').hide();
476

    
477
		// Submit the form save/display all selected widgets
478
		$('[name=widgetForm]').submit();
479
	});
480

    
481
});
482
</script>
483
<?php
484
//build list of javascript include files
485
foreach (glob('widgets/javascript/*.js') as $file)
486
	echo '<script src="'.$file.'"></script>';
487

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