Project

General

Profile

Download (15.2 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
			or preg_match("/^aesni.: (.*?),/", $dmesgl, $matches)) {
218
			$hwcrypto = $matches[1];
219
			break;
220
		}
221
	}
222
	fclose($fd);
223
}
224

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

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

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

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

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

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

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

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

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

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

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

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

    
286
?>
287

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
484
include("foot.inc");
(81-81/234)