Project

General

Profile

Download (15.3 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 page / 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($_GET['closenotice'])) {
83
	close_notice($_GET['closenotice']);
84
	echo get_menu_messages();
85
	exit;
86
}
87

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
281
if ($savemsg) {
282
	print_info_box($savemsg);
283
}
284

    
285
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
286

    
287
?>
288

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

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

    
334
<div class="hidden" id="widgetSequence">
335
	<form action="/" method="post" id="widgetSequence" name="widgetForm">
336
		<input type="hidden" name="sequence" value="" />
337

    
338
		<button type="submit" id="btnstore" class="btn btn-primary">Store widget configuration</button>
339
	</form>
340
</div>
341

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

    
349
	if (!file_exists('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php')) {
350
		continue;
351
	}
352

    
353
	if (!isset($widgetColumns[ $widgetconfig['col'] ]))
354
		$widgetColumns[ $widgetconfig['col'] ] = array();
355

    
356
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
357
}
358
?>
359

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

    
389
<script>
390
function updateWidgets(newWidget)
391
{
392
	var sequence = '';
393

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

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

    
402
	if (typeof newWidget !== 'undefined')
403
		sequence += newWidget + ':' + 'col2:close';
404

    
405
	$('#widgetSequence').removeClass('hidden');
406
	$('input[name=sequence]', $('#widgetSequence')).val(sequence);
407
}
408

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

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

    
422
		$(el).children('i').toggleClass('icon-plus-sign', !isOpen);
423
		$(el).children('i').toggleClass('icon-minus-sign', isOpen);
424

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

    
429
			if($(el).closest('a').attr('name') != 'widgets-available') {
430
				updateWidgets();
431
			}
432
		});
433

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

    
438
			if($(el).closest('a').attr('name') != 'widgets-available') {
439
				updateWidgets();
440
			}
441
		});
442
	});
443

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

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

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

    
465
		// Set its display type to 'close'
466
		<?php $widgets[widgetToAdd]['display'] = 'close'; ?>
467

    
468
		// Add it to the list of displayed widgets
469
		updateWidgets(widgetToAdd);
470

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

    
474
		// Submit the form save/display all selected widgets
475
		$('[name=widgetForm]').submit();
476
	});
477

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

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