Project

General

Profile

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

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

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

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

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

    
82
if (isset($_POST['closenotice'])) {
83
	close_notice($_POST['closenotice']);
84
	sleep(1);
85
	exit;
86
}
87

    
88
if (isset($_GET['closenotice'])) {
89
	close_notice($_GET['closenotice']);
90
	sleep(1);
91
}
92

    
93
if ($g['disablecrashreporter'] != true) {
94
	// Check to see if we have a crash report
95
	$x = 0;
96
	if (file_exists("/tmp/PHP_errors.log")) {
97
		$total = `/usr/bin/grep -vi warning /tmp/PHP_errors.log | /usr/bin/wc -l | /usr/bin/awk '{ print $1 }'`;
98
		if ($total > 0) {
99
			$x++;
100
		}
101
	}
102

    
103
	$crash = glob("/var/crash/*");
104
	$skip_files = array(".", "..", "minfree", "");
105

    
106
	if (is_array($crash)) {
107
		foreach ($crash as $c) {
108
			if (!in_array(basename($c), $skip_files)) {
109
				$x++;
110
			}
111
		}
112

    
113
		if ($x > 0) {
114
			$savemsg = "{$g['product_name']} has detected a crash report or programming bug.  Click <a href='crash_reporter.php'>here</a> for more information.";
115
		}
116
	}
117
}
118

    
119
##build list of php include files
120
$phpincludefiles = array();
121
$directory = "/usr/local/www/widgets/include/";
122
$dirhandle = opendir($directory);
123
$filename = "";
124

    
125
while (false !== ($filename = readdir($dirhandle))) {
126
	$phpincludefiles[] = $filename;
127
}
128

    
129
## Include each widget include file.
130
## These define vars that specify the widget title and title link.
131
foreach ($phpincludefiles as $includename) {
132
	if (!stristr($includename, ".inc")) {
133
		continue;
134
	}
135
	if (file_exists($directory . $includename)) {
136
		include($directory . $includename);
137
	}
138
}
139

    
140
##build list of widgets
141
foreach (glob("/usr/local/www/widgets/widgets/*.widget.php") as $file)
142
{
143
	$name = basename($file, '.widget.php');
144
	// Get the widget title that should be in a var defined in the widget's inc file.
145
	$widgettitle = ${$name . '_title'};
146

    
147
	if ((strlen($widgettitle) == 0)) {
148
		// Fall back to constructing a title from the file name of the widget.
149
		$widgettitle = ucwords(str_replace('_', ' ', $name));
150
	}
151

    
152
	$widgets[ $name ] = array('name' => $widgettitle, 'display' => 'none');
153
}
154

    
155
##insert the system information widget as first, so as to be displayed first
156
unset($widgets['system_information']);
157
$widgets = array_merge(array('system_information' => array('name' => 'System Information')), $widgets);
158

    
159
##if no config entry found, initialize config entry
160
if (!is_array($config['widgets'])) {
161
	$config['widgets'] = array();
162
}
163

    
164
if ($_POST && $_POST['sequence']) {
165

    
166
	$config['widgets']['sequence'] = rtrim($_POST['sequence'], ',');
167

    
168
	foreach ($widgets as $widgetname => $widgetconfig) {
169
		if ($_POST[$widgetname . '-config']) {
170
			$config['widgets'][$widgetname . '-config'] = $_POST[$widgetname . '-config'];
171
		}
172
	}
173

    
174
	write_config(gettext("Widget configuration has been changed."));
175
	header("Location: /");
176
	exit;
177
}
178

    
179
## Load Functions Files
180
require_once('includes/functions.inc.php');
181

    
182
## Check to see if we have a swap space,
183
## if true, display, if false, hide it ...
184
if (file_exists("/usr/sbin/swapinfo")) {
185
	$swapinfo = `/usr/sbin/swapinfo`;
186
	if (stristr($swapinfo, '%') == true) $showswap=true;
187
}
188

    
189
## User recently restored his config.
190
## If packages are installed lets resync
191
if (file_exists('/conf/needs_package_sync')) {
192
	if ($config['installedpackages'] <> '' && is_array($config['installedpackages']['package'])) {
193
		if ($g['platform'] == $g['product_name'] || $g['platform'] == "nanobsd") {
194
			## If the user has logged into webGUI quickly while the system is booting then do not redirect them to
195
			## the package reinstall page. That is about to be done by the boot script anyway.
196
			## The code in head.inc will put up a notice to the user.
197
			if (!platform_booting()) {
198
				header('Location: pkg_mgr_install.php?mode=reinstallall');
199
				exit;
200
			}
201
		}
202
	} else {
203
		conf_mount_rw();
204
		@unlink('/conf/needs_package_sync');
205
		conf_mount_ro();
206
	}
207
}
208

    
209
## If it is the first time webConfigurator has been
210
## accessed since initial install show this stuff.
211
if (file_exists('/conf/trigger_initial_wizard')) {
212
?>
213
<!DOCTYPE html>
214
<html lang="en">
215
<head>
216
	<link rel="stylesheet" href="/bootstrap/css/pfSense.css" />
217
	<title><?=$g['product_name']?>.localdomain - <?=$g['product_name']?> first time setup</title>
218
	<meta http-equiv="refresh" content="1;url=wizard.php?xml=setup_wizard.xml" />
219
</head>
220
<body id="loading-wizard" class="no-menu">
221
	<div id="jumbotron">
222
		<div class="container">
223
			<div class="col-sm-offset-3 col-sm-6 col-xs-12">
224
				<font color="white">
225
				<p><h3><?=sprintf(gettext("Welcome to %s!\n"), $g['product_name'])?></h3></p>
226
				<p><?=gettext("One moment while we start the initial setup wizard.")?></p>
227
				<p><?=gettext("Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal GUI.")?></p>
228
				<p><?=sprintf(gettext("To bypass the wizard, click on the %s logo on the initial page."), $g['product_name'])?></p>
229
				</font>
230
			</div>
231
		</div>
232
	</div>
233
</body>
234
</html>
235
<?php
236
	exit;
237
}
238

    
239
## Find out whether there's hardware encryption or not
240
unset($hwcrypto);
241
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
242
if ($fd) {
243
	while (!feof($fd)) {
244
		$dmesgl = fgets($fd);
245
		if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)
246
			or preg_match("/.*(VIA Padlock)/", $dmesgl, $matches)
247
			or preg_match("/^safe.: (\w.*)/", $dmesgl, $matches)
248
			or preg_match("/^ubsec.: (.*?),/", $dmesgl, $matches)
249
			or preg_match("/^padlock.: <(.*?)>,/", $dmesgl, $matches)
250
			or preg_match("/^glxsb.: (.*?),/", $dmesgl, $matches)) {
251
			$hwcrypto = $matches[1];
252
			break;
253
		}
254
	}
255
	fclose($fd);
256
	if (!isset($hwcrypto) && get_single_sysctl("dev.aesni.0.%desc"))
257
		$hwcrypto = get_single_sysctl("dev.aesni.0.%desc");
258
}
259

    
260
##build widget saved list information
261
if ($config['widgets'] && $config['widgets']['sequence'] != "") {
262
	$pconfig['sequence'] = $config['widgets']['sequence'];
263
	$widgetsfromconfig = array();
264

    
265
	foreach (explode(',', $pconfig['sequence']) as $line)
266
	{
267
		list($file, $col, $display) = explode(':', $line);
268

    
269
		// be backwards compatible
270
		$offset = strpos($file, '-container');
271
		if (false !== $offset)
272
			$file = substr($file, 0, $offset);
273

    
274
		// Get the widget title that should be in a var defined in the widget's inc file.
275
		$widgettitle = ${$file . '_title'};
276

    
277
		if ((strlen($widgettitle) == 0)) {
278
			// Fall back to constructing a title from the file name of the widget.
279
			$widgettitle = ucwords(str_replace('_', ' ', $file));
280
		}
281

    
282
		$widgetsfromconfig[ $file ] = array(
283
			'name' => $widgettitle,
284
			'col' => $col,
285
			'display' => $display,
286
		);
287
	}
288

    
289
	// add widgets that may not be in the saved configuration, in case they are to be displayed later
290
	$widgets = $widgetsfromconfig + $widgets;
291

    
292
	##find custom configurations of a particular widget and load its info to $pconfig
293
	foreach ($widgets as $widgetname => $widgetconfig) {
294
		if ($config['widgets'][$widgetname . '-config']) {
295
			$pconfig[$widgetname . '-config'] = $config['widgets'][$widgetname . '-config'];
296
		}
297
	}
298
}
299

    
300
## Set Page Title and Include Header
301
$pgtitle = array(gettext("Status"), gettext("Dashboard"));
302
include("head.inc");
303

    
304
if ($savemsg) {
305
	print_info_box($savemsg);
306
}
307

    
308
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
309

    
310
?>
311

    
312
<div class="panel panel-default" id="widget-available">
313
	<div class="panel-heading"><?=gettext("Available Widgets"); ?>
314
		<span class="widget-heading-icon">
315
			<a data-toggle="collapse" href="#widget-available_panel-body" id="widgets-available">
316
				<i class="fa fa-plus-circle"></i>
317
			</a>
318
		</span>
319
	</div>
320
	<div id="widget-available_panel-body" class="panel-body collapse out">
321
		<div class="content">
322
			<div class="row">
323
<?php
324
foreach ($widgets as $widgetname => $widgetconfig):
325
	if ($widgetconfig['display'] == 'none'):
326
?>
327
		<div class="col-sm-3"><a href="#" id="btnadd-<?=$widgetname?>"><i class="fa fa-plus"></i> <?=$widgetconfig['name']?></a></div>
328
	<?php endif; ?>
329
<?php endforeach; ?>
330
			</div>
331
		</div>
332
	</div>
333
</div>
334

    
335
<div class="modal fade">
336
	<div class="modal-dialog">
337
		<div class="modal-content">
338
			<div class="modal-header">
339
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
340
				<h4 class="modal-title"><?=gettext("Welcome to the Dashboard page"); ?>!</h4>
341
			</div>
342
			<div class="modal-body">
343
				<p>
344
					<?=gettext("This page allows you to customize the information you want to be displayed!");?>
345
					<?=gettext("To get started click the ");?> FIXME <?=gettext(" icon to add widgets.");?><br />
346
					<br />
347
					<?=gettext("You can move any widget around by clicking and dragging the title.");?>
348
				</p>
349
			</div>
350
			<div class="modal-footer">
351
				<button type="button" class="btn btn-default btn-primary" data-dismiss="modal">Close</button>
352
			</div>
353
		</div>
354
	</div>
355
</div>
356

    
357
<div class="hidden" id="widgetSequence">
358
	<form action="/" method="post" id="widgetSequence_Form" name="widgetForm">
359
		<input type="hidden" name="sequence" value="" />
360

    
361
		<button type="submit" id="btnstore" class="btn btn-primary">Store widget configuration</button>
362
	</form>
363
</div>
364

    
365
<?php
366
$widgetColumns = array();
367
foreach ($widgets as $widgetname => $widgetconfig)
368
{
369
	if ($widgetconfig['display'] == 'none')
370
		continue;
371

    
372
	if (!file_exists('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php')) {
373
		continue;
374
	}
375

    
376
	if (!isset($widgetColumns[ $widgetconfig['col'] ]))
377
		$widgetColumns[ $widgetconfig['col'] ] = array();
378

    
379
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
380
}
381
?>
382

    
383
<div class="row">
384
	<?php
385
	$columnWidth = 12 / $numColumns;
386
	$columnCounter = 0;
387
	?>
388
<?php foreach ($widgetColumns as $column => $columnWidgets):?>
389
	<div class="col-md-<?=$columnWidth?>" id="widgets-<?=$column?>">
390
<?php foreach ($columnWidgets as $widgetname => $widgetconfig):
391

    
392
		// Compose the widget title and include the title link if available
393
		$widgetlink = ${$widgetname . '_title_link'};
394

    
395
		if ((strlen($widgetlink) > 0)) {
396
			$wtitle = '<a href="' . $widgetlink . '"> ' . $widgetconfig['name'] . '</a>';
397
		} else {
398
			$wtitle = $widgetconfig['name'];
399
		}
400

    
401
?>
402
		<div class="panel panel-default" id="widget-<?=$widgetname?>">
403
			<div class="panel-heading">
404
				<?=$wtitle?>
405
				<span class="widget-heading-icon">
406
					<a data-toggle="collapse" href="#widget-<?=$widgetname?>_panel-footer" class="config hidden">
407
						<i class="fa fa-wrench"></i>
408
					</a>
409
					<a data-toggle="collapse" href="#widget-<?=$widgetname?>_panel-body">
410
						<!--  actual icon is determined in css based on state of body -->
411
						<i class="fa fa-plus-circle"></i>
412
					</a>
413
					<a data-toggle="close" href="#widget-<?=$widgetname?>">
414
						<i class="fa fa-times-circle"></i>
415
					</a>
416
				</span>
417
			</div>
418
			<div id="widget-<?=$widgetname?>_panel-body" class="panel-body collapse<?=($widgetconfig['display']=='close' ? '' : ' in')?>">
419
				<?php include('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php'); ?>
420
			</div>
421
		</div>
422
<?php endforeach;
423
	  $columnCounter++;
424
?>
425
	</div>
426
<?php endforeach; ?>
427
<?php
428
	for($n = 1; $n <= ($numColumns - $columnCounter); $n++) {
429
		echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . ($n + $columnCounter) . '"></div>';
430
	}
431
?>
432
</div>
433

    
434
<script type="text/javascript">
435
//<![CDATA[
436
function updateWidgets(newWidget)
437
{
438
	var sequence = '';
439

    
440
	$('.container .col-md-<?=$columnWidth?>').each(function(idx, col){
441
		$('.panel', col).each(function(idx, widget){
442
			var isOpen = $('.panel-body', widget).hasClass('in');
443

    
444
			sequence += widget.id.split('-')[1] +':'+ col.id.split('-')[1] +':'+ (isOpen ? 'open' : 'close') +',';
445
		});
446
	});
447

    
448
	if (typeof newWidget !== 'undefined')
449
		sequence += newWidget + ':' + 'col2:open';
450

    
451
	$('#widgetSequence').removeClass('hidden');
452
	$('input[name=sequence]', $('#widgetSequence_Form')).val(sequence);
453
}
454

    
455
events.push(function() {
456

    
457
	// Make panels destroyable
458
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el){
459
		$(el).on('click', function(e){
460
			$(el).parents('.panel').remove();
461
			updateWidgets();
462
		})
463
	});
464

    
465
	// Make panels sortable
466
	$('.container .col-md-<?=$columnWidth?>').sortable({
467
		handle: '.panel-heading',
468
		cursor: 'grabbing',
469
		connectWith: '.container .col-md-<?=$columnWidth?>',
470
		update: updateWidgets
471
	});
472

    
473
	// On clicking a widget to install . .
474
	$('[id^=btnadd-]').click(function(event) {
475
		// Add the widget name to the list of displayed widgets
476
		updateWidgets(this.id.replace('btnadd-', ''));
477

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

    
481
		// Submit the form save/display all selected widgets
482
		$('[name=widgetForm]').submit();
483
	});
484

    
485
});
486
//]]>
487
</script>
488
<?php
489
//build list of javascript include files
490
foreach (glob('widgets/javascript/*.js') as $file)
491
	echo '<script src="'.$file.'"></script>';
492

    
493
include("foot.inc");
(68-68/228)