Project

General

Profile

Download (15.5 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
##|+PRIV
60
##|*IDENT=page-system-login/logout
61
##|*NAME=System: Login / Logout / Dashboard
62
##|*DESCR=Allow access to the 'System: Login / Logout' page and Dashboard.
63
##|*MATCH=index.php*
64
##|-PRIV
65

    
66
// Turn on buffering to speed up rendering
67
ini_set('output_buffering', 'true');
68

    
69
// Start buffering with a cache size of 100000
70
ob_start(null, "1000");
71

    
72
## Load Essential Includes
73
require_once('guiconfig.inc');
74
require_once('functions.inc');
75
require_once('notices.inc');
76
require_once("pkg-utils.inc");
77

    
78
if (isset($_POST['closenotice'])) {
79
	close_notice($_POST['closenotice']);
80
	sleep(1);
81
	exit;
82
}
83

    
84
if (isset($_GET['closenotice'])) {
85
	close_notice($_GET['closenotice']);
86
	sleep(1);
87
}
88

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

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

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

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

    
115
##build list of php include files
116
$phpincludefiles = array();
117
$directory = "/usr/local/www/widgets/include/";
118
$dirhandle = opendir($directory);
119
$filename = "";
120

    
121
while (false !== ($filename = readdir($dirhandle))) {
122
	$phpincludefiles[] = $filename;
123
}
124

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

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

    
142
	if ((strlen($widgettitle) == 0)) {
143
		// Fall back to constructing a title from the file name of the widget.
144
		$widgettitle = ucwords(str_replace('_', ' ', $name));
145
	}
146

    
147
	$widgets[ $name ] = array('name' => $widgettitle, 'display' => 'none');
148
}
149

    
150
##insert the system information widget as first, so as to be displayed first
151
unset($widgets['system_information']);
152
$widgets = array_merge(array('system_information' => array('name' => 'System Information')), $widgets);
153

    
154
##if no config entry found, initialize config entry
155
if (!is_array($config['widgets'])) {
156
	$config['widgets'] = array();
157
}
158

    
159
if ($_POST && $_POST['sequence']) {
160

    
161
	$config['widgets']['sequence'] = rtrim($_POST['sequence'], ',');
162

    
163
	foreach ($widgets as $widgetname => $widgetconfig) {
164
		if ($_POST[$widgetname . '-config']) {
165
			$config['widgets'][$widgetname . '-config'] = $_POST[$widgetname . '-config'];
166
		}
167
	}
168

    
169
	write_config(gettext("Widget configuration has been changed."));
170
	header("Location: /");
171
	exit;
172
}
173

    
174
## Load Functions Files
175
require_once('includes/functions.inc.php');
176

    
177
## Check to see if we have a swap space,
178
## if true, display, if false, hide it ...
179
if (file_exists("/usr/sbin/swapinfo")) {
180
	$swapinfo = `/usr/sbin/swapinfo`;
181
	if (stristr($swapinfo, '%') == true) $showswap=true;
182
}
183

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

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

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

    
256
##build widget saved list information
257
if ($config['widgets'] && $config['widgets']['sequence'] != "") {
258
	$pconfig['sequence'] = $config['widgets']['sequence'];
259
	$widgetsfromconfig = array();
260

    
261
	foreach (explode(',', $pconfig['sequence']) as $line) {
262
		list($file, $col, $display) = explode(':', $line);
263

    
264
		// be backwards compatible
265
		$offset = strpos($file, '-container');
266
		if (false !== $offset) {
267
			$file = substr($file, 0, $offset);
268
		}
269

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

    
273
		if ((strlen($widgettitle) == 0)) {
274
			// Fall back to constructing a title from the file name of the widget.
275
			$widgettitle = ucwords(str_replace('_', ' ', $file));
276
		}
277

    
278
		$widgetsfromconfig[ $file ] = array(
279
			'name' => $widgettitle,
280
			'col' => $col,
281
			'display' => $display,
282
		);
283
	}
284

    
285
	// add widgets that may not be in the saved configuration, in case they are to be displayed later
286
	$widgets = $widgetsfromconfig + $widgets;
287

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

    
296
## Set Page Title and Include Header
297
$pgtitle = array(gettext("Status"), gettext("Dashboard"));
298
include("head.inc");
299

    
300
if ($savemsg) {
301
	print_info_box($savemsg);
302
}
303

    
304
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
305

    
306
?>
307

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

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

    
353
<div class="hidden" id="widgetSequence">
354
	<form action="/" method="post" id="widgetSequence_form" name="widgetForm">
355
		<input type="hidden" name="sequence" value="" />
356

    
357
		<button type="submit" id="btnstore" class="btn btn-primary">Store widget configuration</button>
358
	</form>
359
</div>
360

    
361
<?php
362
$widgetColumns = array();
363
foreach ($widgets as $widgetname => $widgetconfig) {
364
	if ($widgetconfig['display'] == 'none') {
365
		continue;
366
	}
367

    
368
	if (!file_exists('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php')) {
369
		continue;
370
	}
371

    
372
	if (!isset($widgetColumns[ $widgetconfig['col'] ])) {
373
		$widgetColumns[ $widgetconfig['col'] ] = array();
374
	}
375

    
376
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
377
}
378
?>
379

    
380
<div class="row">
381
<?php
382
	$columnWidth = 12 / $numColumns;
383

    
384
	for ($currentColumnNumber = 1; $currentColumnNumber <= $numColumns; $currentColumnNumber++) {
385
		echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '">';
386

    
387
		//if col$currentColumnNumber exists
388
		if (isset($widgetColumns['col'.$currentColumnNumber])) {
389
			$columnWidgets = $widgetColumns['col'.$currentColumnNumber];
390

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

    
430
</div>
431

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

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

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

    
445
	if (typeof newWidget !== 'undefined') {
446
		sequence += newWidget + ':' + 'col2:open';
447
	}
448

    
449
	$('#widgetSequence').removeClass('hidden');
450
	$('input[name=sequence]', $('#widgetSequence_form')).val(sequence);
451
}
452

    
453
events.push(function() {
454

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

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

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

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

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

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

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