Project

General

Profile

Download (14.9 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 widgets
120
foreach (glob("/usr/local/www/widgets/widgets/*.widget.php") as $file)
121
{
122
	$name = basename($file, '.widget.php');
123
	$widgets[ $name ] = array('name' => ucwords(str_replace('_', ' ', $name)), 'display' => 'none');
124
}
125

    
126
##insert the system information widget as first, so as to be displayed first
127
unset($widgets['system_information']);
128
$widgets = array_merge(array('system_information' => array('name' => 'System Information')), $widgets);
129

    
130
##if no config entry found, initialize config entry
131
if (!is_array($config['widgets'])) {
132
	$config['widgets'] = array();
133
}
134

    
135
if ($_POST && $_POST['sequence']) {
136

    
137
	$config['widgets']['sequence'] = rtrim($_POST['sequence'], ',');
138

    
139
	foreach ($widgets as $widgetname => $widgetconfig) {
140
		if ($_POST[$widgetname . '-config']) {
141
			$config['widgets'][$widgetname . '-config'] = $_POST[$widgetname . '-config'];
142
		}
143
	}
144

    
145
	write_config(gettext("Widget configuration has been changed."));
146
	header("Location: /");
147
	exit;
148
}
149

    
150
## Load Functions Files
151
require_once('includes/functions.inc.php');
152

    
153
## Check to see if we have a swap space,
154
## if true, display, if false, hide it ...
155
if (file_exists("/usr/sbin/swapinfo")) {
156
	$swapinfo = `/usr/sbin/swapinfo`;
157
	if (stristr($swapinfo, '%') == true) $showswap=true;
158
}
159

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

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

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

    
231
##build widget saved list information
232
if ($config['widgets'] && $config['widgets']['sequence'] != "") {
233
	$pconfig['sequence'] = $config['widgets']['sequence'];
234
	$widgetsfromconfig = array();
235

    
236
	foreach (explode(',', $pconfig['sequence']) as $line)
237
	{
238
		list($file, $col, $display) = explode(':', $line);
239

    
240
		// be backwards compatible
241
		$offset = strpos($file, '-container');
242
		if (false !== $offset)
243
			$file = substr($file, 0, $offset);
244

    
245
		$widgetsfromconfig[ $file ] = array(
246
			'name' => ucwords(str_replace('_', ' ', $file)),
247
			'col' => $col,
248
			'display' => $display,
249
		);
250
	}
251

    
252
	// add widgets that may not be in the saved configuration, in case they are to be displayed later
253
	$widgets = $widgetsfromconfig + $widgets;
254

    
255
	##find custom configurations of a particular widget and load its info to $pconfig
256
	foreach ($widgets as $widgetname => $widgetconfig) {
257
		if ($config['widgets'][$widgetname . '-config']) {
258
			$pconfig[$widgetname . '-config'] = $config['widgets'][$widgetname . '-config'];
259
		}
260
	}
261
}
262

    
263
## Replace any known acronyms in widget names with suitable mixed-case forms
264
$input_acronyms = array("carp", "dns", "dyn dns", "gmirror", "ipsec", "ntp", "openvpn", "rss", "smart");
265
$output_acronyms = array("CARP", "DNS", "Dynamic DNS", "gmirror", "IPsec", "NTP", "OpenVPN", "RSS", "SMART");
266
foreach ($widgets as $widgetname => $widgetconfig) {
267
	$widgets[$widgetname]['name'] = str_ireplace($input_acronyms, $output_acronyms, $widgetconfig['name']);
268
}
269

    
270
##build list of php include files
271
$phpincludefiles = array();
272
$directory = "/usr/local/www/widgets/include/";
273
$dirhandle = opendir($directory);
274
$filename = "";
275

    
276
while (false !== ($filename = readdir($dirhandle))) {
277
	$phpincludefiles[] = $filename;
278
}
279

    
280
foreach ($phpincludefiles as $includename) {
281
	if (!stristr($includename, ".inc")) {
282
		continue;
283
	}
284
	if (file_exists($directory . $includename)) {
285
		include($directory . $includename);
286
	}
287
}
288

    
289
## Set Page Title and Include Header
290
$pgtitle = array(gettext("Status"), gettext("Dashboard"));
291
include("head.inc");
292

    
293
if ($savemsg) {
294
	print_info_box($savemsg);
295
}
296

    
297
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
298

    
299
?>
300

    
301
<div class="panel panel-default" id="widget-available">
302
	<div class="panel-heading"><?=gettext("Available Widgets"); ?>
303
		<span class="widget-heading-icon">
304
			<a data-toggle="collapse" href="#widget-available .panel-body" name="widgets-available">
305
				<i class="fa fa-plus-circle"></i>
306
			</a>
307
		</span>
308
	</div>
309
	<div class="panel-body collapse out">
310
		<div class="content">
311
			<div class="row">
312
<?php
313
foreach ($widgets as $widgetname => $widgetconfig):
314
	if ($widgetconfig['display'] == 'none'):
315
?>
316
		<div class="col-sm-3"><a href="#" name="btnadd-<?=$widgetname?>"><i class="fa fa-plus"></i> <?=$widgetconfig['name']?></a></div>
317
	<?php endif; ?>
318
<?php endforeach; ?>
319
			</div>
320
		</div>
321
	</div>
322
</div>
323

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

    
346
<div class="hidden" id="widgetSequence">
347
	<form action="/" method="post" id="widgetSequence" name="widgetForm">
348
		<input type="hidden" name="sequence" value="" />
349

    
350
		<button type="submit" id="btnstore" class="btn btn-primary">Store widget configuration</button>
351
	</form>
352
</div>
353

    
354
<?php
355
$widgetColumns = array();
356
foreach ($widgets as $widgetname => $widgetconfig)
357
{
358
	if ($widgetconfig['display'] == 'none')
359
		continue;
360

    
361
	if (!file_exists('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php')) {
362
		continue;
363
	}
364

    
365
	if (!isset($widgetColumns[ $widgetconfig['col'] ]))
366
		$widgetColumns[ $widgetconfig['col'] ] = array();
367

    
368
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
369
}
370
?>
371

    
372
<div class="row">
373
	<?php
374
	$columnWidth = 12 / $numColumns;
375
	$columnCounter = 0;
376
	?>
377
<?php foreach ($widgetColumns as $column => $columnWidgets):?>
378
	<div class="col-md-<?=$columnWidth?>" id="widgets-<?=$column?>">
379
<?php foreach ($columnWidgets as $widgetname => $widgetconfig):?>
380
		<div class="panel panel-default" id="widget-<?=$widgetname?>">
381
			<div class="panel-heading">
382
				<?=$widgetconfig['name']?>
383
				<span class="widget-heading-icon">
384
					<a data-toggle="collapse" href="#widget-<?=$widgetname?> .panel-footer" class="config hidden">
385
						<i class="fa fa-wrench"></i>
386
					</a>
387
					<a data-toggle="collapse" href="#widget-<?=$widgetname?> .panel-body">
388
						<!--  actual icon is determined in css based on state of body -->
389
						<i class="fa fa-plus-circle"></i>
390
					</a>
391
					<a data-toggle="close" href="#widget-<?=$widgetname?>">
392
						<i class="fa fa-times-circle"></i>
393
					</a>
394
				</span>
395
			</div>
396
			<div class="panel-body collapse<?=($widgetconfig['display']=='close' ? '' : ' in')?>">
397
				<?php include('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php'); ?>
398
			</div>
399
		</div>
400
<?php endforeach; 
401
	  $columnCounter++;
402
?>
403
	</div>
404
<?php endforeach; ?>
405
<?php
406
	for($n = 1; $n <= ($numColumns - $columnCounter); $n++) {
407
		echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . ($n + $columnCounter) . '"></div>';
408
	}
409
?>
410
</div>
411

    
412
<script type="text/javascript">
413
//<![CDATA[
414
function updateWidgets(newWidget)
415
{
416
	var sequence = '';
417

    
418
	$('.container .col-md-<?=$columnWidth?>').each(function(idx, col){
419
		$('.panel', col).each(function(idx, widget){
420
			var isOpen = $('.panel-body', widget).hasClass('in');
421

    
422
			sequence += widget.id.split('-')[1] +':'+ col.id.split('-')[1] +':'+ (isOpen ? 'open' : 'close') +',';
423
		});
424
	});
425

    
426
	if (typeof newWidget !== 'undefined')
427
		sequence += newWidget + ':' + 'col2:open';
428

    
429
	$('#widgetSequence').removeClass('hidden');
430
	$('input[name=sequence]', $('#widgetSequence')).val(sequence);
431
}
432

    
433
events.push(function() {
434

    
435
	// Make panels destroyable
436
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el){
437
		$(el).on('click', function(e){
438
			$(el).parents('.panel').remove();
439
			updateWidgets();
440
		})
441
	});
442

    
443
	// Make panels sortable
444
	$('.container .col-md-<?=$columnWidth?>').sortable({
445
		handle: '.panel-heading',
446
		cursor: 'grabbing',
447
		connectWith: '.container .col-md-<?=$columnWidth?>',
448
		update: updateWidgets
449
	});
450

    
451
	// On clicking a widget to install . .
452
	$('[name^=btnadd-]').click(function(event) {
453
		// Add the widget name to the list of displayed widgets
454
		updateWidgets(this.name.replace('btnadd-', ''));
455

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

    
459
		// Submit the form save/display all selected widgets
460
		$('[name=widgetForm]').submit();
461
	});
462

    
463
});
464
//]]>
465
</script>
466
<?php
467
//build list of javascript include files
468
foreach (glob('widgets/javascript/*.js') as $file)
469
	echo '<script src="'.$file.'"></script>';
470

    
471
include("foot.inc");
(79-79/228)