Project

General

Profile

Download (14.9 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 the user has logged into webGUI quickly while the system is booting then do not redirect them to
159
		## the package reinstall page. That is about to be done by the boot script anyway.
160
		## The code in head.inc will put up a notice to the user.
161
		if (!platform_booting()) {
162
			header('Location: pkg_mgr_install.php?mode=reinstallall');
163
			exit;
164
		}
165
	} else {
166
		@unlink('/conf/needs_package_sync');
167
	}
168
}
169

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

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

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

    
227
	foreach (explode(',', $pconfig['sequence']) as $line) {
228
		list($file, $col, $display) = explode(':', $line);
229

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

    
241
		// Limit the column to the current dashboard columns.
242
		if (substr($col, 3) > $dashboardcolumns) {
243
			$col = "col" . $dashboardcolumns;
244
		}
245

    
246
		$offset = strpos($file, '-container');
247
		if (false !== $offset) {
248
			$file = substr($file, 0, $offset);
249
		}
250

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

    
254
		if (empty(trim($widgettitle))) {
255
			// Fall back to constructing a title from the file name of the widget.
256
			$widgettitle = ucwords(str_replace('_', ' ', $file));
257
		}
258

    
259
		$widgetsfromconfig[ $file ] = array(
260
			'name' => $widgettitle,
261
			'col' => $col,
262
			'display' => $display,
263
		);
264
	}
265

    
266
	// add widgets that may not be in the saved configuration, in case they are to be displayed later
267
	$widgets = $widgetsfromconfig + $widgets;
268

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

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

    
280
if ($dashboard_available_widgets_hidden) {
281
	$panel_state = 'out';
282
	$panel_body_state = 'in';
283
} else {
284
	$panel_state = 'in';
285
	$panel_body_state = 'out';
286
}
287

    
288
## Set Page Title and Include Header
289
$pgtitle = array(gettext("Status"), gettext("Dashboard"));
290
include("head.inc");
291

    
292
if ($savemsg) {
293
	print_info_box($savemsg, $class);
294
}
295

    
296
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
297

    
298
?>
299

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

    
315
// Build the Available Widgets table using a sorted copy of the $widgets array
316
$available = $widgets;
317
uasort($available, function($a, $b){ return strcasecmp($a['name'], $b['name']); });
318

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

    
330
<div class="hidden" id="widgetSequence">
331
	<form action="/" method="post" id="widgetSequence_form" name="widgetForm">
332
		<input type="hidden" name="sequence" value="" />
333
	</form>
334
</div>
335

    
336
<?php
337
$widgetColumns = array();
338
foreach ($widgets as $widgetname => $widgetconfig) {
339
	if ($widgetconfig['display'] == 'none') {
340
		continue;
341
	}
342

    
343
	if (!file_exists('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php')) {
344
		continue;
345
	}
346

    
347
	if (!isset($widgetColumns[ $widgetconfig['col'] ])) {
348
		$widgetColumns[ $widgetconfig['col'] ] = array();
349
	}
350

    
351
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
352
}
353
?>
354

    
355
<div class="row">
356
<?php
357
	$columnWidth = 12 / $numColumns;
358

    
359
	for ($currentColumnNumber = 1; $currentColumnNumber <= $numColumns; $currentColumnNumber++) {
360

    
361

    
362
		//if col$currentColumnNumber exists
363
		if (isset($widgetColumns['col'.$currentColumnNumber])) {
364
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '">';
365
			$columnWidgets = $widgetColumns['col'.$currentColumnNumber];
366

    
367
			foreach ($columnWidgets as $widgetname => $widgetconfig) {
368
				// Compose the widget title and include the title link if available
369
				$widgetlink = ${$widgetname . '_title_link'};
370

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

    
406
	}
407
?>
408

    
409
</div>
410

    
411
<script type="text/javascript">
412
//<![CDATA[
413

    
414
dirty = false;
415
function updateWidgets(newWidget) {
416
	var sequence = '';
417

    
418
	$('.container .col-md-<?=$columnWidth?>').each(function(idx, col) {
419
		$('.panel', col).each(function(idx, widget) {
420
			var isOpen = $('.panel-body', widget).hasClass('in');
421

    
422
			sequence += widget.id.split('-')[1] + ':' + col.id.split('-')[1] + ':' + (isOpen ? 'open' : 'close') + ',';
423
		});
424
	});
425

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

    
435
	$('input[name=sequence]', $('#widgetSequence_form')).val(sequence);
436
}
437

    
438
events.push(function() {
439

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

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

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

    
466
		// Submit the form save/display all selected widgets
467
		$('[name=widgetForm]').submit();
468
	});
469

    
470

    
471
	$('#btnstore').click(function() {
472
		updateWidgets();
473
		dirty = false;
474
		$(this).addClass('invisible');
475
		$('[name=widgetForm]').submit();
476
	});
477

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

    
487
	// 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)
488
	// (Sometimes this will cause us to see the icon when we don't need it, but better that than the other way round)
489
	$('.panel').on('hidden.bs.collapse shown.bs.collapse', function (e) {
490
	    if (e.currentTarget.id != 'widget-available') {
491
			$('#btnstore').removeClass("invisible");
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");
(66-66/225)