Project

General

Profile

Download (16.6 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 = `/bin/cat /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 = sprintf(gettext("%s has detected a crash report or programming bug. Click <a href='crash_reporter.php'>here</a> for more information."), $g['product_name']);
111
			$class = "warning";
112
		}
113
	}
114
}
115

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

    
122
while (false !== ($filename = readdir($dirhandle))) {
123
	if (!stristr($filename, ".inc")) {
124
		continue;
125
	}
126
	$phpincludefiles[] = $filename;
127
}
128

    
129
## Include each widget include file.
130
## These define vars that specify the widget title and title link.
131
foreach ($phpincludefiles as $includename) {
132
	if (file_exists($directory . $includename)) {
133
		include_once($directory . $includename);
134
	}
135
}
136

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

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

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

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

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

    
158
	$widget_settings = array();
159
	$widget_settings['sequence'] = rtrim($_POST['sequence'], ',');
160

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

    
167
	save_widget_settings($_SESSION['Username'], $widget_settings);
168
	header("Location: /");
169
	exit;
170
}
171

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

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

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

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

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

    
254
##build widget saved list information
255
if ($user_settings['widgets']['sequence'] != "") {
256
	$dashboardcolumns = isset($user_settings['webgui']['dashboardcolumns']) ? $user_settings['webgui']['dashboardcolumns'] : 2;
257
	$pconfig['sequence'] = $user_settings['widgets']['sequence'];
258
	$widgetsfromconfig = array();
259

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

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

    
274
		// Limit the column to the current dashboard columns.
275
		if (substr($col, 3) > $dashboardcolumns) {
276
			$col = "col" . $dashboardcolumns;
277
		}
278

    
279
		$offset = strpos($file, '-container');
280
		if (false !== $offset) {
281
			$file = substr($file, 0, $offset);
282
		}
283

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

    
287
		if (empty(trim($widgettitle))) {
288
			// Fall back to constructing a title from the file name of the widget.
289
			$widgettitle = ucwords(str_replace('_', ' ', $file));
290
		}
291

    
292
		$widgetsfromconfig[ $file ] = array(
293
			'name' => $widgettitle,
294
			'col' => $col,
295
			'display' => $display,
296
		);
297
	}
298

    
299
	// add widgets that may not be in the saved configuration, in case they are to be displayed later
300
	$widgets = $widgetsfromconfig + $widgets;
301

    
302
	##find custom configurations of a particular widget and load its info to $pconfig
303
	foreach ($widgets as $widgetname => $widgetconfig) {
304
		if ($config['widgets'][$widgetname . '-config']) {
305
			$pconfig[$widgetname . '-config'] = $config['widgets'][$widgetname . '-config'];
306
		}
307
	}
308
}
309

    
310
## Get the configured options for Show/Hide available widgets panel.
311
$dashboard_available_widgets_hidden = !$user_settings['webgui']['dashboardavailablewidgetspanel'];
312

    
313
if ($dashboard_available_widgets_hidden) {
314
	$panel_state = 'out';
315
	$panel_body_state = 'in';
316
} else {
317
	$panel_state = 'in';
318
	$panel_body_state = 'out';
319
}
320

    
321
## Set Page Title and Include Header
322
$pgtitle = array(gettext("Status"), gettext("Dashboard"));
323
include("head.inc");
324

    
325
if ($savemsg) {
326
	print_info_box($savemsg, $class);
327
}
328

    
329
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
330

    
331
?>
332

    
333
<div class="panel panel-default collapse <?=$panel_state?>" id="widget-available">
334
	<div class="panel-heading">
335
		<h2 class="panel-title"><?=gettext("Available Widgets"); ?>
336
			<span class="widget-heading-icon">
337
				<a data-toggle="collapse" href="#widget-available_panel-body" id="widgets-available">
338
					<i class="fa fa-plus-circle"></i>
339
				</a>
340
			</span>
341
		</h2>
342
	</div>
343
	<div id="widget-available_panel-body" class="panel-body collapse <?=$panel_body_state?>">
344
		<div class="content">
345
			<div class="row">
346
<?php
347

    
348
// Build the Available Widgets table using a sorted copy of the $widgets array
349
$available = $widgets;
350
uasort($available, function($a, $b){ return strcasecmp($a['name'], $b['name']); });
351

    
352
foreach ($available as $widgetname => $widgetconfig):
353
	if ($widgetconfig['display'] == 'none'):
354
?>
355
		<div class="col-sm-3"><a href="#" id="btnadd-<?=$widgetname?>"><i class="fa fa-plus"></i> <?=$widgetconfig['name']?></a></div>
356
	<?php endif; ?>
357
<?php endforeach; ?>
358
			</div>
359
		</div>
360
	</div>
361
</div>
362

    
363
<div class="hidden" id="widgetSequence">
364
	<form action="/" method="post" id="widgetSequence_form" name="widgetForm">
365
		<input type="hidden" name="sequence" value="" />
366
	</form>
367
</div>
368

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

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

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

    
384
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
385
}
386
?>
387

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

    
392
	for ($currentColumnNumber = 1; $currentColumnNumber <= $numColumns; $currentColumnNumber++) {
393

    
394

    
395
		//if col$currentColumnNumber exists
396
		if (isset($widgetColumns['col'.$currentColumnNumber])) {
397
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '">';
398
			$columnWidgets = $widgetColumns['col'.$currentColumnNumber];
399

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

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

    
439
	}
440
?>
441

    
442
</div>
443

    
444
<script type="text/javascript">
445
//<![CDATA[
446

    
447
dirty = false;
448
function updateWidgets(newWidget) {
449
	var sequence = '';
450

    
451
	$('.container .col-md-<?=$columnWidth?>').each(function(idx, col) {
452
		$('.panel', col).each(function(idx, widget) {
453
			var isOpen = $('.panel-body', widget).hasClass('in');
454

    
455
			sequence += widget.id.split('-')[1] + ':' + col.id.split('-')[1] + ':' + (isOpen ? 'open' : 'close') + ',';
456
		});
457
	});
458

    
459
	if (typeof newWidget !== 'undefined') {
460
		// The system_information widget is always added to column one. Others go in column two
461
		if (newWidget == "system_information") {
462
			sequence += newWidget + ':' + 'col1:open';
463
		} else {
464
		sequence += newWidget + ':' + 'col2:open';
465
		}
466
	}
467

    
468
	$('input[name=sequence]', $('#widgetSequence_form')).val(sequence);
469
}
470

    
471
events.push(function() {
472

    
473
	// Make panels destroyable
474
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el) {
475
		$(el).on('click', function(e) {
476
			$(el).parents('.panel').remove();
477
			updateWidgets();
478
			// Submit the form save/display all selected widgets
479
			$('[name=widgetForm]').submit();
480
		})
481
	});
482

    
483
	// Make panels sortable
484
	$('.container .col-md-<?=$columnWidth?>').sortable({
485
		handle: '.panel-heading',
486
		cursor: 'grabbing',
487
		connectWith: '.container .col-md-<?=$columnWidth?>',
488
		update: function(){
489
			dirty = true;
490
			$('#btnstore').removeClass('invisible');
491
		}
492
	});
493

    
494
	// On clicking a widget to install . .
495
	$('[id^=btnadd-]').click(function(event) {
496
		// Add the widget name to the list of displayed widgets
497
		updateWidgets(this.id.replace('btnadd-', ''));
498

    
499
		// Submit the form save/display all selected widgets
500
		$('[name=widgetForm]').submit();
501
	});
502

    
503

    
504
	$('#btnstore').click(function() {
505
		updateWidgets();
506
		dirty = false;
507
		$(this).addClass('invisible');
508
		$('[name=widgetForm]').submit();
509
	});
510

    
511
	// provide a warning message if the user tries to change page before saving
512
	$(window).bind('beforeunload', function(){
513
		if (dirty) {
514
			return ("<?=gettext('One or more widgets have been moved but have not yet been saved')?>");
515
		} else {
516
			return undefined;
517
		}
518
	});
519

    
520
	// Show the fa-save icon in the breadcrumb bar if the user opens or closes a panel (In case he/she wants to save the new state)
521
	// (Sometimes this will cause us to see the icon when we don't need it, but better that than the other way round)
522
	$('.panel').on('hidden.bs.collapse shown.bs.collapse', function (e) {
523
	    if (e.currentTarget.id != 'widget-available') {
524
			$('#btnstore').removeClass("invisible");
525
		}
526
	});
527
});
528
//]]>
529
</script>
530
<?php
531
//build list of javascript include files
532
foreach (glob('widgets/javascript/*.js') as $file) {
533
	echo '<script src="'.$file.'"></script>';
534
}
535

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