Project

General

Profile

Download (15.8 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
##if no config entry found, initialize config entry
151
if (!is_array($config['widgets'])) {
152
	$config['widgets'] = array();
153
}
154

    
155
if ($_POST && $_POST['sequence']) {
156

    
157
	$config['widgets']['sequence'] = rtrim($_POST['sequence'], ',');
158

    
159
	foreach ($widgets as $widgetname => $widgetconfig) {
160
		if ($_POST[$widgetname . '-config']) {
161
			$config['widgets'][$widgetname . '-config'] = $_POST[$widgetname . '-config'];
162
		}
163
	}
164

    
165
	write_config(gettext("Widget configuration has been changed."));
166
	header("Location: /");
167
	exit;
168
}
169

    
170
## Load Functions Files
171
require_once('includes/functions.inc.php');
172

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

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

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

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

    
252
##build widget saved list information
253
if ($config['widgets'] && $config['widgets']['sequence'] != "") {
254
	$pconfig['sequence'] = $config['widgets']['sequence'];
255
	$widgetsfromconfig = array();
256

    
257
	foreach (explode(',', $pconfig['sequence']) as $line) {
258
		list($file, $col, $display) = explode(':', $line);
259

    
260
		// be backwards compatible
261
		// If the display column information is missing, we will assign a temporary
262
		// column here. Next time the user saves the dashboard it will fix itself
263
		if ($col == "") {
264
			if ($file == "system_information") {
265
				$col = "col1";
266
			} else {
267
				$col = "col2";
268
			}
269
		}
270

    
271
		$offset = strpos($file, '-container');
272
		if (false !== $offset) {
273
			$file = substr($file, 0, $offset);
274
		}
275

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

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

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

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

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

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

    
306
if ($savemsg) {
307
	print_info_box($savemsg);
308
}
309

    
310
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
311

    
312
?>
313

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

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

    
359
<div class="hidden" id="widgetSequence">
360
	<form action="/" method="post" id="widgetSequence_form" name="widgetForm">
361
		<input type="hidden" name="sequence" value="" />
362

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

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

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

    
378
	if (!isset($widgetColumns[ $widgetconfig['col'] ])) {
379
		$widgetColumns[ $widgetconfig['col'] ] = array();
380
	}
381

    
382
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
383
}
384
?>
385

    
386
<div class="row">
387
<?php
388
	$columnWidth = 12 / $numColumns;
389

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

    
393
		//if col$currentColumnNumber exists
394
		if (isset($widgetColumns['col'.$currentColumnNumber])) {
395
			$columnWidgets = $widgetColumns['col'.$currentColumnNumber];
396

    
397
			foreach ($columnWidgets as $widgetname => $widgetconfig) {
398
				// Compose the widget title and include the title link if available
399
				$widgetlink = ${$widgetname . '_title_link'};
400

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

    
436
</div>
437

    
438
<script type="text/javascript">
439
//<![CDATA[
440
function updateWidgets(newWidget) {
441
	var sequence = '';
442

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

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

    
451
	if (typeof newWidget !== 'undefined') {
452
		// The system_information widget is always added to column one. Others go in column two
453
		if (newWidget == "system_information") {
454
			sequence += newWidget + ':' + 'col1:open';
455
		} else {
456
		sequence += newWidget + ':' + 'col2:open';
457
		}
458
	}
459

    
460
	$('#widgetSequence').removeClass('hidden');
461
	$('input[name=sequence]', $('#widgetSequence_form')).val(sequence);
462
}
463

    
464
events.push(function() {
465

    
466
	// Make panels destroyable
467
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el) {
468
		$(el).on('click', function(e) {
469
			$(el).parents('.panel').remove();
470
			updateWidgets();
471
		})
472
	});
473

    
474
	// Make panels sortable
475
	$('.container .col-md-<?=$columnWidth?>').sortable({
476
		handle: '.panel-heading',
477
		cursor: 'grabbing',
478
		connectWith: '.container .col-md-<?=$columnWidth?>',
479
		update: updateWidgets
480
	});
481

    
482
	// On clicking a widget to install . .
483
	$('[id^=btnadd-]').click(function(event) {
484
		// Add the widget name to the list of displayed widgets
485
		updateWidgets(this.id.replace('btnadd-', ''));
486

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

    
490
		// Submit the form save/display all selected widgets
491
		$('[name=widgetForm]').submit();
492
	});
493

    
494
});
495
//]]>
496
</script>
497
<?php
498
//build list of javascript include files
499
foreach (glob('widgets/javascript/*.js') as $file) {
500
	echo '<script src="'.$file.'"></script>';
501
}
502

    
503
include("foot.inc");
(68-68/229)