Project

General

Profile

Download (15.1 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
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

    
26
##|+PRIV
27
##|*IDENT=page-system-login-logout
28
##|*NAME=System: Login / Logout / Dashboard
29
##|*DESCR=Allow access to the 'System: Login / Logout' page and Dashboard.
30
##|*MATCH=index.php*
31
##|-PRIV
32

    
33
// Turn on buffering to speed up rendering
34
ini_set('output_buffering', 'true');
35

    
36
// Start buffering with a cache size of 100000
37
ob_start(null, "1000");
38

    
39
## Load Essential Includes
40
require_once('guiconfig.inc');
41
require_once('functions.inc');
42
require_once('notices.inc');
43
require_once("pkg-utils.inc");
44

    
45
if (isset($_POST['closenotice'])) {
46
	close_notice($_POST['closenotice']);
47
	sleep(1);
48
	exit;
49
}
50

    
51
if (isset($_GET['closenotice'])) {
52
	close_notice($_GET['closenotice']);
53
	sleep(1);
54
}
55

    
56
if ($g['disablecrashreporter'] != true) {
57
	// Check to see if we have a crash report
58
	$x = 0;
59
	if (file_exists("/tmp/PHP_errors.log")) {
60
		$total = `/bin/cat /tmp/PHP_errors.log | /usr/bin/wc -l | /usr/bin/awk '{ print $1 }'`;
61
		if ($total > 0) {
62
			$x++;
63
		}
64
	}
65

    
66
	$crash = glob("/var/crash/*");
67
	$skip_files = array(".", "..", "minfree", "");
68

    
69
	if (is_array($crash)) {
70
		foreach ($crash as $c) {
71
			if (!in_array(basename($c), $skip_files)) {
72
				$x++;
73
			}
74
		}
75

    
76
		if ($x > 0) {
77
			$savemsg = sprintf(gettext("%s has detected a crash report or programming bug."), $g['product_name']) . " ";
78
			if (isAllowedPage("/crash_reporter.php")) {
79
				$savemsg .= sprintf(gettext("Click <a href='crash_reporter.php'>here</a> for more information."));
80
			} else {
81
				$savemsg .= sprintf(gettext("Contact a firewall administrator for more information."));
82
			}
83
			$class = "warning";
84
		}
85
	}
86
}
87

    
88
##build list of php include files
89
$phpincludefiles = array();
90
$directory = "/usr/local/www/widgets/include/";
91
$dirhandle = opendir($directory);
92
$filename = "";
93

    
94
while (false !== ($filename = readdir($dirhandle))) {
95
	if (!stristr($filename, ".inc")) {
96
		continue;
97
	}
98
	$phpincludefiles[] = $filename;
99
}
100

    
101
## Include each widget include file.
102
## These define vars that specify the widget title and title link.
103
foreach ($phpincludefiles as $includename) {
104
	if (file_exists($directory . $includename)) {
105
		include_once($directory . $includename);
106
	}
107
}
108

    
109
##build list of widgets
110
foreach (glob("/usr/local/www/widgets/widgets/*.widget.php") as $file) {
111
	$name = basename($file, '.widget.php');
112
	// Get the widget title that should be in a var defined in the widget's inc file.
113
	$widgettitle = ${$name . '_title'};
114

    
115
	if (empty(trim($widgettitle))) {
116
		// Fall back to constructing a title from the file name of the widget.
117
		$widgettitle = ucwords(str_replace('_', ' ', $name));
118
	}
119

    
120
	$widgets[ $name ] = array('name' => $widgettitle, 'display' => 'none');
121
}
122

    
123
##if no config entry found, initialize config entry
124
if (!is_array($config['widgets'])) {
125
	$config['widgets'] = array();
126
}
127
if (!is_array($user_settings['widgets'])) {
128
	$user_settings['widgets'] = array();
129
}
130

    
131
if ($_POST && $_POST['sequence']) {
132

    
133
	// Start with the user's widget settings.
134
	$widget_settings = $user_settings['widgets'];
135

    
136
	$widget_settings['sequence'] = rtrim($_POST['sequence'], ',');
137

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

    
144
	save_widget_settings($_SESSION['Username'], $widget_settings);
145
	header("Location: /");
146
	exit;
147
}
148

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

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

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

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

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

    
226
##build widget saved list information
227
if ($user_settings['widgets']['sequence'] != "") {
228
	$dashboardcolumns = isset($user_settings['webgui']['dashboardcolumns']) ? $user_settings['webgui']['dashboardcolumns'] : 2;
229
	$pconfig['sequence'] = $user_settings['widgets']['sequence'];
230
	$widgetsfromconfig = array();
231

    
232
	foreach (explode(',', $pconfig['sequence']) as $line) {
233
		list($file, $col, $display) = explode(':', $line);
234

    
235
		// be backwards compatible
236
		// If the display column information is missing, we will assign a temporary
237
		// column here. Next time the user saves the dashboard it will fix itself
238
		if ($col == "") {
239
			if ($file == "system_information") {
240
				$col = "col1";
241
			} else {
242
				$col = "col2";
243
			}
244
		}
245

    
246
		// Limit the column to the current dashboard columns.
247
		if (substr($col, 3) > $dashboardcolumns) {
248
			$col = "col" . $dashboardcolumns;
249
		}
250

    
251
		$offset = strpos($file, '-container');
252
		if (false !== $offset) {
253
			$file = substr($file, 0, $offset);
254
		}
255

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

    
259
		if (empty(trim($widgettitle))) {
260
			// Fall back to constructing a title from the file name of the widget.
261
			$widgettitle = ucwords(str_replace('_', ' ', $file));
262
		}
263

    
264
		$widgetsfromconfig[ $file ] = array(
265
			'name' => $widgettitle,
266
			'col' => $col,
267
			'display' => $display,
268
		);
269
	}
270

    
271
	// add widgets that may not be in the saved configuration, in case they are to be displayed later
272
	$widgets = $widgetsfromconfig + $widgets;
273

    
274
	##find custom configurations of a particular widget and load its info to $pconfig
275
	foreach ($widgets as $widgetname => $widgetconfig) {
276
		if ($config['widgets'][$widgetname . '-config']) {
277
			$pconfig[$widgetname . '-config'] = $config['widgets'][$widgetname . '-config'];
278
		}
279
	}
280
}
281

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

    
285
if ($dashboard_available_widgets_hidden) {
286
	$panel_state = 'out';
287
	$panel_body_state = 'in';
288
} else {
289
	$panel_state = 'in';
290
	$panel_body_state = 'out';
291
}
292

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

    
297
if ($savemsg) {
298
	print_info_box($savemsg, $class);
299
}
300

    
301
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
302

    
303
?>
304

    
305
<div class="panel panel-default collapse <?=$panel_state?>" id="widget-available">
306
	<div class="panel-heading">
307
		<h2 class="panel-title"><?=gettext("Available Widgets"); ?>
308
			<span class="widget-heading-icon">
309
				<a data-toggle="collapse" href="#widget-available_panel-body" id="widgets-available">
310
					<i class="fa fa-plus-circle"></i>
311
				</a>
312
			</span>
313
		</h2>
314
	</div>
315
	<div id="widget-available_panel-body" class="panel-body collapse <?=$panel_body_state?>">
316
		<div class="content">
317
			<div class="row">
318
<?php
319

    
320
// Build the Available Widgets table using a sorted copy of the $widgets array
321
$available = $widgets;
322
uasort($available, function($a, $b){ return strcasecmp($a['name'], $b['name']); });
323

    
324
foreach ($available as $widgetname => $widgetconfig):
325
	if ($widgetconfig['display'] == 'none'):
326
?>
327
		<div class="col-sm-3"><a href="#" id="btnadd-<?=$widgetname?>"><i class="fa fa-plus"></i> <?=$widgetconfig['name']?></a></div>
328
	<?php endif; ?>
329
<?php endforeach; ?>
330
			</div>
331
		</div>
332
	</div>
333
</div>
334

    
335
<div class="hidden" id="widgetSequence">
336
	<form action="/" method="post" id="widgetSequence_form" name="widgetForm">
337
		<input type="hidden" name="sequence" value="" />
338
	</form>
339
</div>
340

    
341
<?php
342
$widgetColumns = array();
343
foreach ($widgets as $widgetname => $widgetconfig) {
344
	if ($widgetconfig['display'] == 'none') {
345
		continue;
346
	}
347

    
348
	if (!file_exists('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php')) {
349
		continue;
350
	}
351

    
352
	if (!isset($widgetColumns[ $widgetconfig['col'] ])) {
353
		$widgetColumns[ $widgetconfig['col'] ] = array();
354
	}
355

    
356
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
357
}
358
?>
359

    
360
<div class="row">
361
<?php
362
	$columnWidth = 12 / $numColumns;
363

    
364
	for ($currentColumnNumber = 1; $currentColumnNumber <= $numColumns; $currentColumnNumber++) {
365

    
366

    
367
		//if col$currentColumnNumber exists
368
		if (isset($widgetColumns['col'.$currentColumnNumber])) {
369
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '">';
370
			$columnWidgets = $widgetColumns['col'.$currentColumnNumber];
371

    
372
			foreach ($columnWidgets as $widgetname => $widgetconfig) {
373
				// Compose the widget title and include the title link if available
374
				$widgetlink = ${$widgetname . '_title_link'};
375

    
376
				if ((strlen($widgetlink) > 0)) {
377
					$wtitle = '<a href="' . $widgetlink . '"> ' . $widgetconfig['name'] . '</a>';
378
				} else {
379
					$wtitle = $widgetconfig['name'];
380
				}
381
				?>
382
					<div class="panel panel-default" id="widget-<?=$widgetname?>">
383
					<div class="panel-heading">
384
						<h2 class="panel-title">
385
							<?=$wtitle?>
386
							<span class="widget-heading-icon">
387
								<a data-toggle="collapse" href="#widget-<?=$widgetname?>_panel-footer" class="config hidden">
388
									<i class="fa fa-wrench"></i>
389
								</a>
390
								<a data-toggle="collapse" href="#widget-<?=$widgetname?>_panel-body">
391
									<!--  actual icon is determined in css based on state of body -->
392
									<i class="fa fa-plus-circle"></i>
393
								</a>
394
								<a data-toggle="close" href="#widget-<?=$widgetname?>">
395
									<i class="fa fa-times-circle"></i>
396
								</a>
397
							</span>
398
						</h2>
399
					</div>
400
					<div id="widget-<?=$widgetname?>_panel-body" class="panel-body collapse<?=($widgetconfig['display'] == 'close' ? '' : ' in')?>">
401
						<?php include_once('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php'); ?>
402
					</div>
403
				</div>
404
				<?php
405
			}
406
			echo "</div>";
407
		} else {
408
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '"></div>';
409
		}
410

    
411
	}
412
?>
413

    
414
</div>
415

    
416
<script type="text/javascript">
417
//<![CDATA[
418

    
419
dirty = false;
420
function updateWidgets(newWidget) {
421
	var sequence = '';
422

    
423
	$('.container .col-md-<?=$columnWidth?>').each(function(idx, col) {
424
		$('.panel', col).each(function(idx, widget) {
425
			var isOpen = $('.panel-body', widget).hasClass('in');
426

    
427
			sequence += widget.id.split('-')[1] + ':' + col.id.split('-')[1] + ':' + (isOpen ? 'open' : 'close') + ',';
428
		});
429
	});
430

    
431
	if (typeof newWidget !== 'undefined') {
432
		// The system_information widget is always added to column one. Others go in column two
433
		if (newWidget == "system_information") {
434
			sequence += newWidget + ':' + 'col1:open';
435
		} else {
436
		sequence += newWidget + ':' + 'col2:open';
437
		}
438
	}
439

    
440
	$('input[name=sequence]', $('#widgetSequence_form')).val(sequence);
441
}
442

    
443
events.push(function() {
444

    
445
	// Make panels destroyable
446
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el) {
447
		$(el).on('click', function(e) {
448
			$(el).parents('.panel').remove();
449
			updateWidgets();
450
			// Submit the form save/display all selected widgets
451
			$('[name=widgetForm]').submit();
452
		})
453
	});
454

    
455
	// Make panels sortable
456
	$('.container .col-md-<?=$columnWidth?>').sortable({
457
		handle: '.panel-heading',
458
		cursor: 'grabbing',
459
		connectWith: '.container .col-md-<?=$columnWidth?>',
460
		update: function(){
461
			dirty = true;
462
			$('#btnstore').removeClass('invisible');
463
		}
464
	});
465

    
466
	// On clicking a widget to install . .
467
	$('[id^=btnadd-]').click(function(event) {
468
		// Add the widget name to the list of displayed widgets
469
		updateWidgets(this.id.replace('btnadd-', ''));
470

    
471
		// Submit the form save/display all selected widgets
472
		$('[name=widgetForm]').submit();
473
	});
474

    
475

    
476
	$('#btnstore').click(function() {
477
		updateWidgets();
478
		dirty = false;
479
		$(this).addClass('invisible');
480
		$('[name=widgetForm]').submit();
481
	});
482

    
483
	// provide a warning message if the user tries to change page before saving
484
	$(window).bind('beforeunload', function(){
485
		if (dirty) {
486
			return ("<?=gettext('One or more widgets have been moved but have not yet been saved')?>");
487
		} else {
488
			return undefined;
489
		}
490
	});
491

    
492
	// 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)
493
	// (Sometimes this will cause us to see the icon when we don't need it, but better that than the other way round)
494
	$('.panel').on('hidden.bs.collapse shown.bs.collapse', function (e) {
495
	    if (e.currentTarget.id != 'widget-available') {
496
			$('#btnstore').removeClass("invisible");
497
		}
498
	});
499
});
500
//]]>
501
</script>
502
<?php
503
//build list of javascript include files
504
foreach (glob('widgets/javascript/*.js') as $file) {
505
	echo '<script src="'.$file.'"></script>';
506
}
507

    
508
include("foot.inc");
(66-66/225)