Project

General

Profile

Download (16.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * index.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12
 *
13
 * Redistribution and use in source and binary forms, with or without
14
 * modification, are permitted provided that the following conditions are met:
15
 *
16
 * 1. Redistributions of source code must retain the above copyright notice,
17
 *    this list of conditions and the following disclaimer.
18
 *
19
 * 2. Redistributions in binary form must reproduce the above copyright
20
 *    notice, this list of conditions and the following disclaimer in
21
 *    the documentation and/or other materials provided with the
22
 *    distribution.
23
 *
24
 * 3. All advertising materials mentioning features or use of this software
25
 *    must display the following acknowledgment:
26
 *    "This product includes software developed by the pfSense Project
27
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
28
 *
29
 * 4. The names "pfSense" and "pfSense Project" must not be used to
30
 *    endorse or promote products derived from this software without
31
 *    prior written permission. For written permission, please contact
32
 *    coreteam@pfsense.org.
33
 *
34
 * 5. Products derived from this software may not be called "pfSense"
35
 *    nor may "pfSense" appear in their names without prior written
36
 *    permission of the Electric Sheep Fencing, LLC.
37
 *
38
 * 6. Redistributions of any form whatsoever must retain the following
39
 *    acknowledgment:
40
 *
41
 * "This product includes software developed by the pfSense Project
42
 * for use in the pfSense software distribution (http://www.pfsense.org/).
43
 *
44
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
45
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
48
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55
 * OF THE POSSIBILITY OF SUCH DAMAGE.
56
 */
57

    
58
##|+PRIV
59
##|*IDENT=page-system-login-logout
60
##|*NAME=System: Login / Logout / Dashboard
61
##|*DESCR=Allow access to the 'System: Login / Logout' page and Dashboard.
62
##|*MATCH=index.php*
63
##|-PRIV
64

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

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

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

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

    
83
if (isset($_GET['closenotice'])) {
84
	close_notice($_GET['closenotice']);
85
	sleep(1);
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 = `/bin/cat /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 = 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']);
110
			$class = "warning";
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
	if (!stristr($filename, ".inc")) {
123
		continue;
124
	}
125
	$phpincludefiles[] = $filename;
126
}
127

    
128
## Include each widget include file.
129
## These define vars that specify the widget title and title link.
130
foreach ($phpincludefiles as $includename) {
131
	if (file_exists($directory . $includename)) {
132
		include_once($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 (empty(trim($widgettitle))) {
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
if (!is_array($user_settings['widgets'])) {
155
	$user_settings['widgets'] = array();
156
}
157

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

    
160
	// Start with the user's widget settings.
161
	$widget_settings = $user_settings['widgets'];
162

    
163
	$widget_settings['sequence'] = rtrim($_POST['sequence'], ',');
164

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

    
171
	save_widget_settings($_SESSION['Username'], $widget_settings);
172
	header("Location: /");
173
	exit;
174
}
175

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

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

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

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

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

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

    
264
	foreach (explode(',', $pconfig['sequence']) as $line) {
265
		list($file, $col, $display) = explode(':', $line);
266

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

    
278
		// Limit the column to the current dashboard columns.
279
		if (substr($col, 3) > $dashboardcolumns) {
280
			$col = "col" . $dashboardcolumns;
281
		}
282

    
283
		$offset = strpos($file, '-container');
284
		if (false !== $offset) {
285
			$file = substr($file, 0, $offset);
286
		}
287

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

    
291
		if (empty(trim($widgettitle))) {
292
			// Fall back to constructing a title from the file name of the widget.
293
			$widgettitle = ucwords(str_replace('_', ' ', $file));
294
		}
295

    
296
		$widgetsfromconfig[ $file ] = array(
297
			'name' => $widgettitle,
298
			'col' => $col,
299
			'display' => $display,
300
		);
301
	}
302

    
303
	// add widgets that may not be in the saved configuration, in case they are to be displayed later
304
	$widgets = $widgetsfromconfig + $widgets;
305

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

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

    
317
if ($dashboard_available_widgets_hidden) {
318
	$panel_state = 'out';
319
	$panel_body_state = 'in';
320
} else {
321
	$panel_state = 'in';
322
	$panel_body_state = 'out';
323
}
324

    
325
## Set Page Title and Include Header
326
$pgtitle = array(gettext("Status"), gettext("Dashboard"));
327
include("head.inc");
328

    
329
if ($savemsg) {
330
	print_info_box($savemsg, $class);
331
}
332

    
333
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
334

    
335
?>
336

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

    
352
// Build the Available Widgets table using a sorted copy of the $widgets array
353
$available = $widgets;
354
uasort($available, function($a, $b){ return strcasecmp($a['name'], $b['name']); });
355

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

    
367
<div class="hidden" id="widgetSequence">
368
	<form action="/" method="post" id="widgetSequence_form" name="widgetForm">
369
		<input type="hidden" name="sequence" value="" />
370
	</form>
371
</div>
372

    
373
<?php
374
$widgetColumns = array();
375
foreach ($widgets as $widgetname => $widgetconfig) {
376
	if ($widgetconfig['display'] == 'none') {
377
		continue;
378
	}
379

    
380
	if (!file_exists('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php')) {
381
		continue;
382
	}
383

    
384
	if (!isset($widgetColumns[ $widgetconfig['col'] ])) {
385
		$widgetColumns[ $widgetconfig['col'] ] = array();
386
	}
387

    
388
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
389
}
390
?>
391

    
392
<div class="row">
393
<?php
394
	$columnWidth = 12 / $numColumns;
395

    
396
	for ($currentColumnNumber = 1; $currentColumnNumber <= $numColumns; $currentColumnNumber++) {
397

    
398

    
399
		//if col$currentColumnNumber exists
400
		if (isset($widgetColumns['col'.$currentColumnNumber])) {
401
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '">';
402
			$columnWidgets = $widgetColumns['col'.$currentColumnNumber];
403

    
404
			foreach ($columnWidgets as $widgetname => $widgetconfig) {
405
				// Compose the widget title and include the title link if available
406
				$widgetlink = ${$widgetname . '_title_link'};
407

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

    
443
	}
444
?>
445

    
446
</div>
447

    
448
<script type="text/javascript">
449
//<![CDATA[
450

    
451
dirty = false;
452
function updateWidgets(newWidget) {
453
	var sequence = '';
454

    
455
	$('.container .col-md-<?=$columnWidth?>').each(function(idx, col) {
456
		$('.panel', col).each(function(idx, widget) {
457
			var isOpen = $('.panel-body', widget).hasClass('in');
458

    
459
			sequence += widget.id.split('-')[1] + ':' + col.id.split('-')[1] + ':' + (isOpen ? 'open' : 'close') + ',';
460
		});
461
	});
462

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

    
472
	$('input[name=sequence]', $('#widgetSequence_form')).val(sequence);
473
}
474

    
475
events.push(function() {
476

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

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

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

    
503
		// Submit the form save/display all selected widgets
504
		$('[name=widgetForm]').submit();
505
	});
506

    
507

    
508
	$('#btnstore').click(function() {
509
		updateWidgets();
510
		dirty = false;
511
		$(this).addClass('invisible');
512
		$('[name=widgetForm]').submit();
513
	});
514

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

    
524
	// 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)
525
	// (Sometimes this will cause us to see the icon when we don't need it, but better that than the other way round)
526
	$('.panel').on('hidden.bs.collapse shown.bs.collapse', function (e) {
527
	    if (e.currentTarget.id != 'widget-available') {
528
			$('#btnstore').removeClass("invisible");
529
		}
530
	});
531
});
532
//]]>
533
</script>
534
<?php
535
//build list of javascript include files
536
foreach (glob('widgets/javascript/*.js') as $file) {
537
	echo '<script src="'.$file.'"></script>';
538
}
539

    
540
include("foot.inc");
(67-67/227)