Project

General

Profile

Download (15 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. Click <a href='crash_reporter.php'>here</a> for more information."), $g['product_name']);
78
			$class = "warning";
79
		}
80
	}
81
}
82

    
83
##build list of php include files
84
$phpincludefiles = array();
85
$directory = "/usr/local/www/widgets/include/";
86
$dirhandle = opendir($directory);
87
$filename = "";
88

    
89
while (false !== ($filename = readdir($dirhandle))) {
90
	if (!stristr($filename, ".inc")) {
91
		continue;
92
	}
93
	$phpincludefiles[] = $filename;
94
}
95

    
96
## Include each widget include file.
97
## These define vars that specify the widget title and title link.
98
foreach ($phpincludefiles as $includename) {
99
	if (file_exists($directory . $includename)) {
100
		include_once($directory . $includename);
101
	}
102
}
103

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

    
110
	if (empty(trim($widgettitle))) {
111
		// Fall back to constructing a title from the file name of the widget.
112
		$widgettitle = ucwords(str_replace('_', ' ', $name));
113
	}
114

    
115
	$widgets[ $name ] = array('name' => $widgettitle, 'display' => 'none');
116
}
117

    
118
##if no config entry found, initialize config entry
119
if (!is_array($config['widgets'])) {
120
	$config['widgets'] = array();
121
}
122
if (!is_array($user_settings['widgets'])) {
123
	$user_settings['widgets'] = array();
124
}
125

    
126
if ($_POST && $_POST['sequence']) {
127

    
128
	// Start with the user's widget settings.
129
	$widget_settings = $user_settings['widgets'];
130

    
131
	$widget_settings['sequence'] = rtrim($_POST['sequence'], ',');
132

    
133
	foreach ($widgets as $widgetname => $widgetconfig) {
134
		if ($_POST[$widgetname . '-config']) {
135
			$widget_settings[$widgetname . '-config'] = $_POST[$widgetname . '-config'];
136
		}
137
	}
138

    
139
	save_widget_settings($_SESSION['Username'], $widget_settings);
140
	header("Location: /");
141
	exit;
142
}
143

    
144
## Load Functions Files
145
require_once('includes/functions.inc.php');
146

    
147
## Check to see if we have a swap space,
148
## if true, display, if false, hide it ...
149
if (file_exists("/usr/sbin/swapinfo")) {
150
	$swapinfo = `/usr/sbin/swapinfo`;
151
	if (stristr($swapinfo, '%') == true) $showswap=true;
152
}
153

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
302
?>
303

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

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

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

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

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

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

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

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

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

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

    
365

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

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

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

    
410
	}
411
?>
412

    
413
</div>
414

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

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

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

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

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

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

    
442
events.push(function() {
443

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

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

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

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

    
474

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

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

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

    
507
include("foot.inc");
(66-66/226)