Project

General

Profile

Download (14.1 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
## Load Essential Includes
76
require_once('guiconfig.inc');
77
require_once('functions.inc');
78
require_once('notices.inc');
79
require_once("pkg-utils.inc");
80

    
81
if (isset($_GET['closenotice'])) {
82
	close_notice($_GET['closenotice']);
83
	echo get_menu_messages();
84
	exit;
85
}
86

    
87
if ($g['disablecrashreporter'] != true) {
88
	// Check to see if we have a crash report
89
	$x = 0;
90
	if (file_exists("/tmp/PHP_errors.log")) {
91
		$total = `/usr/bin/grep -vi warning /tmp/PHP_errors.log | /usr/bin/wc -l | /usr/bin/awk '{ print $1 }'`;
92
		if ($total > 0) {
93
			$x++;
94
		}
95
	}
96
	$crash = glob("/var/crash/*");
97
	$skip_files = array(".", "..", "minfree", "");
98
	if (is_array($crash)) {
99
		foreach ($crash as $c) {
100
			if (!in_array(basename($c), $skip_files)) {
101
				$x++;
102
			}
103
		}
104
		if ($x > 0) {
105
			$savemsg = "{$g['product_name']} has detected a crash report or programming bug.  Click <a href='crash_reporter.php'>here</a> for more information.";
106
		}
107
	}
108
}
109

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

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

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

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

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

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

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

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

    
150
## User recently restored his config.
151
## If packages are installed lets resync
152
if (file_exists('/conf/needs_package_sync')) {
153
	if ($config['installedpackages'] <> '' && is_array($config['installedpackages']['package'])) {
154
		if ($g['platform'] == "pfSense" || $g['platform'] == "nanobsd") {
155
			## If the user has logged into webGUI quickly while the system is booting then do not redirect them to
156
			## the package reinstall page. That is about to be done by the boot script anyway.
157
			## The code in head.inc will put up a notice to the user.
158
			if (!platform_booting()) {
159
				header('Location: pkg_mgr_install.php?mode=reinstallall');
160
				exit;
161
			}
162
		}
163
	} else {
164
		conf_mount_rw();
165
		@unlink('/conf/needs_package_sync');
166
		conf_mount_ro();
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="/bootstrap/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
				<p><?=sprintf(gettext("Welcome to %s!\n"), $g['product_name'])?></p>
186
				<p><?=gettext("One moment while we start the initial setup wizard.")?></p>
187
				<p><?=gettext("Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal GUI.")?></p>
188
				<p><?=sprintf(gettext("To bypass the wizard, click on the %s logo on the initial page."), $g['product_name'])?></p>
189
			</div>
190
		</div>
191
	</div>
192
</body>
193
</html>
194
<?php
195
	exit;
196
}
197

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

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

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

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

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

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

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

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

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

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

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

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

    
282
?>
283

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

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

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

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

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

    
332
	if (!file_exists('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php')) {
333
		continue;
334
	}
335

    
336
	if (!isset($widgetColumns[ $widgetconfig['col'] ]))
337
		$widgetColumns[ $widgetconfig['col'] ] = array();
338

    
339
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
340
}
341
?>
342

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

    
372
<script>
373
function updateWidgets()
374
{
375
	var sequence = '';
376

    
377
	$('.container .col-md-6').each(function(idx, col){
378
		$('.panel', col).each(function(idx, widget){
379
			var isOpen = $('.panel-body', widget).hasClass('in');
380

    
381
			sequence += widget.id.split('-')[1] +':'+ col.id.split('-')[1] +':'+ (isOpen ? 'open' : 'close') +',';
382
		});
383
	});
384

    
385
	$('#widgetSequence').removeClass('hidden');
386
	$('input[name=sequence]', $('#widgetSequence')).val(sequence);
387
}
388

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

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

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

    
407
			updateWidgets();
408
		});
409

    
410
		body.on('hidden.bs.collapse', function(){
411
			$(el).toggleClass('icon-minus-sign', false);
412
			$(el).toggleClass('icon-plus-sign', true);
413

    
414
			updateWidgets();
415
		});
416
	});
417

    
418
	// Make panels destroyable
419
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el){
420
		$(el).on('click', function(e){
421
			$(el).parents('.panel').remove();
422
			updateWidgets();
423
		})
424
	});
425

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

    
440
include("foot.inc");
(82-82/235)