Project

General

Profile

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

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

    
69
// Turn on buffering to speed up rendering
70
ini_set('output_buffering', 'true');
71

    
72
// Start buffering with a cache size of 100000
73
ob_start(null, "1000");
74

    
75

    
76
## Load Essential Includes
77
require_once('guiconfig.inc');
78
require_once('functions.inc');
79
require_once('notices.inc');
80
require_once("pkg-utils.inc");
81

    
82
if (isset($_REQUEST['closenotice'])) {
83
	close_notice($_REQUEST['closenotice']);
84
	echo get_menu_messages();
85
	exit;
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 = `/usr/bin/grep -vi warning /tmp/PHP_errors.log | /usr/bin/wc -l | /usr/bin/awk '{ print $1 }'`;
93
		if ($total > 0) {
94
			$x++;
95
		}
96
	}
97
	$crash = glob("/var/crash/*");
98
	$skip_files = array(".", "..", "minfree", "");
99
	if (is_array($crash)) {
100
		foreach ($crash as $c) {
101
			if (!in_array(basename($c), $skip_files)) {
102
				$x++;
103
			}
104
		}
105
		if ($x > 0) {
106
			$savemsg = "{$g['product_name']} has detected a crash report or programming bug.  Click <a href='crash_reporter.php'>here</a> for more information.";
107
		}
108
	}
109
}
110

    
111
##build list of widgets
112
foreach (glob("/usr/local/www/widgets/widgets/*.widget.php") as $file)
113
{
114
	$name = basename($file, '.widget.php');
115
	$widgets[ $name ] = array('name' => ucwords(str_replace('_', ' ', $name)), 'display' => 'none');
116
}
117

    
118
##insert the system information widget as first, so as to be displayed first
119
unset($widgets['system_information']);
120
$widgets = array_merge(array('system_information' => array('name' => 'System Information')), $widgets);
121

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

    
127
if ($_POST && $_POST['sequence']) {
128
	$config['widgets']['sequence'] = rtrim($_POST['sequence'], ',');
129

    
130
	foreach($widgets as $widgetname => $widgetconfig){
131
		if ($_POST[$widgetname . '-config']){
132
			$config['widgets'][$widgetname . '-config'] = $_POST[$name . '-config'];
133
		}
134
	}
135

    
136
	write_config(gettext("Widget configuration has been changed."));
137
	header("Location: /");
138
	exit;
139
}
140

    
141
## Load Functions Files
142
require_once('includes/functions.inc.php');
143

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

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

    
171
## If it is the first time webConfigurator has been
172
## accessed since initial install show this stuff.
173
if(file_exists('/conf/trigger_initial_wizard')) {
174
?>
175
<!DOCTYPE html>
176
<html lang="en">
177
<head>
178
	<link rel="stylesheet" href="/bootstrap/css/pfSense.css" />
179
	<title>{$g['product_name']}.localdomain - {$g['product_name']} first time setup</title>
180
	<meta http-equiv="refresh" content="1;url=wizard.php?xml=setup_wizard.xml" />
181
</head>
182
<body id="loading-wizard" class="no-menu">
183
	<div id="jumbotron">
184
		<div class="container">
185
			<div class="col-sm-offset-3 col-sm-6 col-xs-12">
186
				<p><?=sprintf(gettext("Welcome to %s!\n"),$g['product_name'])?></p>
187
				<p><?=gettext("One moment while we start the initial setup wizard.")?></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
			</div>
191
		</div>
192
	</div>
193
</body>
194
</html>
195
<?php
196
	exit;
197
}
198

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

    
219
##build widget saved list information
220
if ($config['widgets'] && $config['widgets']['sequence'] != "") {
221
	$pconfig['sequence'] = $config['widgets']['sequence'];
222
	$widgetsfromconfig = array();
223

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

    
228
		// be backwards compatible
229
		$offset = strpos($file, '-container');
230
		if (false !== $offset)
231
			$file = substr($file, 0, $offset);
232

    
233
		$widgetsfromconfig[ $file ] = array(
234
			'name' => ucwords(str_replace('_', ' ', $file)),
235
			'col' => $col,
236
			'display' => $display,
237
		);
238
	}
239

    
240
	##add widgets that may not be in the saved configuration, in case they are to be displayed later
241
	$widgets = $widgetsfromconfig + $widgets;
242

    
243
	##find custom configurations of a particular widget and load its info to $pconfig
244
	foreach($widgets as $widgetname => $widgetconfig){
245
		if ($config['widgets'][$name . '-config']){
246
			$pconfig[$name . '-config'] = $config['widgets'][$name . '-config'];
247
		}
248
	}
249
}
250

    
251
##build list of php include files
252
$phpincludefiles = array();
253
$directory = "/usr/local/www/widgets/include/";
254
$dirhandle = opendir($directory);
255
$filename = "";
256
while (false !== ($filename = readdir($dirhandle))) {
257
	$phpincludefiles[] = $filename;
258
}
259
foreach ($phpincludefiles as $includename) {
260
	if (!stristr($includename, ".inc")) {
261
		continue;
262
	}
263
	include($directory . $includename);
264
}
265

    
266
## Set Page Title and Include Header
267
$pgtitle = array(gettext("Status: Dashboard"));
268
include("head.inc");
269

    
270
/* Print package server mismatch warning. See https://redmine.pfsense.org/issues/484 */
271
if (!verify_all_package_servers()) {
272
	print_info_box(package_server_mismatch_message());
273
}
274

    
275
if ($savemsg) {
276
	print_info_box($savemsg);
277
}
278

    
279
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
280

    
281
?>
282

    
283
<div class="panel panel-default">
284
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Available Widgets"); ?></h2></div>
285
	<div class="panel-body">
286
<?php foreach($widgets as $widgetname => $widgetconfig): ?>
287
	<?php if ($widgetconfig['display'] == 'none'): ?>
288
		<div class="col-sm-3"><a href="#"><i class="icon icon-plus"></i> <?=$widgetconfig['name']?></a></div>
289
	<?php endif; ?>
290
<?php endforeach; ?>
291
	</div>
292
</div>
293

    
294
<div class="modal fade">
295
	<div class="modal-dialog">
296
		<div class="modal-content">
297
			<div class="modal-header">
298
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
299
				<h4 class="modal-title"><?=gettext("Welcome to the Dashboard page"); ?>!</h4>
300
			</div>
301
			<div class="modal-body">
302
				<p>
303
					<?=gettext("This page allows you to customize the information you want to be displayed!");?>
304
					<?=gettext("To get started click the");?> FIXME <?=gettext("icon to add widgets.");?><br />
305
					<br />
306
					<?=gettext("You can move any widget around by clicking and dragging the title.");?>
307
				</p>
308
			</div>
309
			<div class="modal-footer">
310
				<button type="button" class="btn btn-default btn-primary" data-dismiss="modal">Close</button>
311
			</div>
312
		</div>
313
	</div>
314
</div>
315

    
316
<div class="hidden" id="widgetSequence">
317
	<form action="/" method="post" id="widgetSequence">
318
		<input type="hidden" name="sequence" value="" />
319

    
320
		<button type="submit" class="btn btn-primary">Store widget configuration</button>
321
	</form>
322
</div>
323

    
324
<?php
325
$widgetColumns = array();
326
foreach ($widgets as $widgetname => $widgetconfig)
327
{
328
	if ($widgetconfig['display'] == 'none')
329
		continue;
330

    
331
	if (!isset($widgetColumns[ $widgetconfig['col'] ]))
332
		$widgetColumns[ $widgetconfig['col'] ] = array();
333

    
334
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
335
}
336
?>
337

    
338
<div class="row">
339
<?php foreach ($widgetColumns as $column => $columnWidgets):?>
340
	<div class="col-md-6" id="widgets-<?=$column?>">
341
<?php foreach ($columnWidgets as $widgetname => $widgetconfig):?>
342
		<div class="panel panel-default" id="widget-<?=$widgetname?>">
343
			<div class="panel-heading">
344
				<?=$widgetconfig['name']?>
345
				<span class="icons">
346
					<a data-toggle="collapse" href="#widget-<?=$widgetname?> .panel-footer" class="config hidden">
347
						<i class="icon icon-wrench"></i>
348
					</a>
349
					<a data-toggle="collapse" href="#widget-<?=$widgetname?> .panel-body">
350
						<!--  actual icon is determined in css based on state of body -->
351
						<i class="icon icon-plus-sign"></i>
352
					</a>
353
					<a data-toggle="close" href="#widget-<?=$widgetname?>">
354
						<i class="icon icon-remove-sign"></i>
355
					</a>
356
				</span>
357
			</div>
358
			<div class="panel-body collapse<?=($widgetconfig['display']=='close' ? '' : ' in')?>">
359
				<?php include('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php'); ?>
360
			</div>
361
		</div>
362
<?php endforeach; ?>
363
	</div>
364
<?php endforeach; ?>
365
</div>
366

    
367
<script>
368
function updateWidgets()
369
{
370
	var sequence = '';
371

    
372
	$('.container .col-md-6').each(function(idx, col){
373
		$('.panel', col).each(function(idx, widget){
374
			var isOpen = $('.panel-body', widget).hasClass('in');
375

    
376
			sequence += widget.id.split('-')[1] +':'+ col.id.split('-')[1] +':'+ (isOpen ? 'open' : 'close') +',';
377
		});
378
	});
379

    
380
	$('#widgetSequence').removeClass('hidden');
381
	$('input[name=sequence]', $('#widgetSequence')).val(sequence);
382
}
383

    
384
events.push(function() {
385
	// Hide configuration button for panels without configuration
386
	$('.container .panel-heading a.config').each(function (idx, el){
387
		var config = $(el).parents('.panel').children('.panel-footer');
388
		if (config.length == 1)
389
			$(el).removeClass('hidden');
390
	});
391

    
392
	// Initial state & toggle icons of collapsed panel
393
	$('.container .panel-heading a[data-toggle="collapse"]').each(function (idx, el){
394
		var body = $(el).parents('.panel').children('.panel-body'), isOpen = body.hasClass('in');
395
		$(el).toggleClass('icon-plus-sign', !isOpen);
396
		$(el).toggleClass('icon-minus-sign', isOpen);
397

    
398
		body.on('shown.bs.collapse', function(){
399
			$(el).toggleClass('icon-minus-sign', true);
400
			$(el).toggleClass('icon-plus-sign', false);
401

    
402
			updateWidgets();
403
		});
404

    
405
		body.on('hidden.bs.collapse', function(){
406
			$(el).toggleClass('icon-minus-sign', false);
407
			$(el).toggleClass('icon-plus-sign', true);
408

    
409
			updateWidgets();
410
		});
411
	});
412

    
413
	// Make panels destroyable
414
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el){
415
		$(el).on('click', function(e){
416
			$(el).parents('.panel').remove();
417
			updateWidgets();
418
		})
419
	});
420

    
421
	// Make panels sortable
422
	$('.container .col-md-6').sortable({
423
		handle: '.panel-heading',
424
		cursor: 'grabbing',
425
		connectWith: '.container .col-md-6',
426
		update: updateWidgets
427
	});
428
});
429
</script>
430
<?php
431
//build list of javascript include files
432
foreach (glob('widgets/javascript/*.js') as $file)
433
	echo '<script src="'.$file.'"></script>';
434

    
435
include("foot.inc");
(81-81/237)