Project

General

Profile

Download (12.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	index.php
5
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6
	Copyright (C) 2004-2012 Scott Ullrich
7
	All rights reserved.
8

    
9
	Originally part of m0n0wall (http://m0n0.ch/wall)
10
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12

    
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15

    
16
	1. Redistributions of source code must retain the above copyright notice,
17
		this list of conditions and the following disclaimer.
18

    
19
	2. Redistributions in binary form must reproduce the above copyright
20
		notice, this list of conditions and the following disclaimer in the
21
		documentation and/or other materials provided with the distribution.
22

    
23
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	oR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34
/*
35
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig
36
	pfSense_MODULE:	interfaces
37
*/
38

    
39
##|+PRIV
40
##|*IDENT=page-system-login/logout
41
##|*NAME=System: Login / Logout page / Dashboard
42
##|*DESCR=Allow access to the 'System: Login / Logout' page and Dashboard.
43
##|*MATCH=index.php*
44
##|-PRIV
45

    
46
// Turn on buffering to speed up rendering
47
ini_set('output_buffering','true');
48

    
49
// Start buffering with a cache size of 100000
50
ob_start(null, "1000");
51

    
52

    
53
## Load Essential Includes
54
require_once('guiconfig.inc');
55
require_once('functions.inc');
56
require_once('notices.inc');
57
require_once("pkg-utils.inc");
58

    
59
if(isset($_REQUEST['closenotice'])){
60
	close_notice($_REQUEST['closenotice']);
61
	echo get_menu_messages();
62
	exit;
63
}
64

    
65
if($g['disablecrashreporter'] != true) {
66
	// Check to see if we have a crash report
67
	$x = 0;
68
	if(file_exists("/tmp/PHP_errors.log")) {
69
		$total = `/usr/bin/grep -vi warning /tmp/PHP_errors.log | /usr/bin/wc -l | /usr/bin/awk '{ print $1 }'`;
70
		if($total > 0)
71
			$x++;
72
	}
73
	$crash = glob("/var/crash/*");
74
	$skip_files = array(".", "..", "minfree", "");
75
	if(is_array($crash)) {
76
		foreach($crash as $c) {
77
			if (!in_array(basename($c), $skip_files))
78
				$x++;
79
		}
80
		if($x > 0)
81
			$savemsg = "{$g['product_name']} has detected a crash report or programming bug.  Click <a href='crash_reporter.php'>here</a> for more information.";
82
	}
83
}
84

    
85
##build list of widgets
86
foreach (glob("/usr/local/www/widgets/widgets/*.widget.php") as $file)
87
{
88
	$name = basename($file, '.widget.php');
89
	$widgets[ $name ] = array('name' => ucwords(str_replace('_', ' ', $name)), 'display' => 'none');
90
}
91

    
92
##insert the system information widget as first, so as to be displayed first
93
unset($widgets['system_information']);
94
$widgets = array_merge(array('system_information' => array('name' => 'System Information')), $widgets);
95

    
96
##if no config entry found, initialize config entry
97
if (!is_array($config['widgets'])) {
98
	$config['widgets'] = array();
99
}
100

    
101
if ($_POST && $_POST['sequence']) {
102
	$config['widgets']['sequence'] = rtrim($_POST['sequence'], ',');
103

    
104
	foreach($widgets as $widgetname => $widgetconfig){
105
		if ($_POST[$widgetname . '-config']){
106
			$config['widgets'][$widgetname . '-config'] = $_POST[$name . '-config'];
107
		}
108
	}
109

    
110
	write_config(gettext("Widget configuration has been changed."));
111
	header("Location: /");
112
	exit;
113
}
114

    
115
## Load Functions Files
116
require_once('includes/functions.inc.php');
117

    
118
## Check to see if we have a swap space,
119
## if true, display, if false, hide it ...
120
if(file_exists("/usr/sbin/swapinfo")) {
121
	$swapinfo = `/usr/sbin/swapinfo`;
122
	if(stristr($swapinfo,'%') == true) $showswap=true;
123
}
124

    
125
## User recently restored his config.
126
## If packages are installed lets resync
127
if(file_exists('/conf/needs_package_sync')) {
128
	if($config['installedpackages'] <> '' && is_array($config['installedpackages']['package'])) {
129
		if($g['platform'] == "pfSense" || $g['platform'] == "nanobsd") {
130
			## If the user has logged into webGUI quickly while the system is booting then do not redirect them to
131
			## the package reinstall page. That is about to be done by the boot script anyway.
132
			## The code in head.inc will put up a notice to the user.
133
			if (!platform_booting()) {
134
				header('Location: pkg_mgr_install.php?mode=reinstallall');
135
				exit;
136
			}
137
		}
138
	} else {
139
		conf_mount_rw();
140
		@unlink('/conf/needs_package_sync');
141
		conf_mount_ro();
142
	}
143
}
144

    
145
## If it is the first time webConfigurator has been
146
## accessed since initial install show this stuff.
147
if(file_exists('/conf/trigger_initial_wizard')) {
148
?>
149
<!DOCTYPE html>
150
<html lang="en">
151
<head>
152
	<link rel="stylesheet" href="/bootstrap/css/pfSense.css" />
153
	<title>{$g['product_name']}.localdomain - {$g['product_name']} first time setup</title>
154
	<meta http-equiv="refresh" content="1;url=wizard.php?xml=setup_wizard.xml" />
155
</head>
156
<body id="loading-wizard" class="no-menu">
157
	<div id="jumbotron">
158
		<div class="container">
159
			<div class="col-sm-offset-3 col-sm-6 col-xs-12">
160
				<p><?=sprintf(gettext("Welcome to %s!\n"),$g['product_name'])?></p>
161
				<p><?=gettext("One moment while we start the initial setup wizard.")?></p>
162
				<p><?=gettext("Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal GUI.")?></p>
163
				<p><?=sprintf(gettext("To bypass the wizard, click on the %s logo on the initial page."),$g['product_name'])?></p>
164
			</div>
165
		</div>
166
	</div>
167
</body>
168
</html>
169
<?php
170
	exit;
171
}
172

    
173
## Find out whether there's hardware encryption or not
174
unset($hwcrypto);
175
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
176
if ($fd) {
177
	while (!feof($fd)) {
178
		$dmesgl = fgets($fd);
179
		if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)
180
			or preg_match("/.*(VIA Padlock)/", $dmesgl, $matches)
181
			or preg_match("/^safe.: (\w.*)/", $dmesgl, $matches)
182
			or preg_match("/^ubsec.: (.*?),/", $dmesgl, $matches)
183
			or preg_match("/^padlock.: <(.*?)>,/", $dmesgl, $matches)
184
			or preg_match("/^glxsb.: (.*?),/", $dmesgl, $matches)
185
			or preg_match("/^aesni.: (.*?),/", $dmesgl, $matches)) {
186
			$hwcrypto = $matches[1];
187
			break;
188
		}
189
	}
190
	fclose($fd);
191
}
192

    
193
##build widget saved list information
194
if ($config['widgets'] && $config['widgets']['sequence'] != "") {
195
	$pconfig['sequence'] = $config['widgets']['sequence'];
196
	$widgetsfromconfig = array();
197

    
198
	foreach (explode(',', $pconfig['sequence']) as $line)
199
	{
200
		list($file, $col, $display) = explode(':', $line);
201

    
202
		// be backwards compatible
203
		$offset = strpos($file, '-container');
204
		if (false !== $offset)
205
			$file = substr($file, 0, $offset);
206

    
207
		$widgetsfromconfig[ $file ] = array(
208
			'name' => ucwords(str_replace('_', ' ', $file)),
209
			'col' => $col,
210
			'display' => $display,
211
		);
212
	}
213

    
214
	##add widgets that may not be in the saved configuration, in case they are to be displayed later
215
	$widgets = $widgetsfromconfig + $widgets;
216

    
217
	##find custom configurations of a particular widget and load its info to $pconfig
218
	foreach($widgets as $widgetname => $widgetconfig){
219
		if ($config['widgets'][$name . '-config']){
220
			$pconfig[$name . '-config'] = $config['widgets'][$name . '-config'];
221
		}
222
	}
223
}
224

    
225
##build list of php include files
226
$phpincludefiles = array();
227
$directory = "/usr/local/www/widgets/include/";
228
$dirhandle  = opendir($directory);
229
$filename = "";
230
while (false !== ($filename = readdir($dirhandle))) {
231
	$phpincludefiles[] = $filename;
232
}
233
foreach($phpincludefiles as $includename) {
234
	if(!stristr($includename, ".inc"))
235
		continue;
236
	include($directory . $includename);
237
}
238

    
239
## Set Page Title and Include Header
240
$pgtitle = array(gettext("Status: Dashboard"));
241
include("head.inc");
242

    
243
/* Print package server mismatch warning. See https://redmine.pfsense.org/issues/484 */
244
if (!verify_all_package_servers())
245
	print_info_box(package_server_mismatch_message());
246

    
247
if ($savemsg)
248
	print_info_box($savemsg);
249

    
250
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
251

    
252
?>
253

    
254
<div class="panel panel-default">
255
	<div class="panel-heading"><?=gettext("Available Widgets"); ?></div>
256
	<div class="panel-body">
257
<?php foreach($widgets as $widgetname => $widgetconfig): ?>
258
	<?php if ($widgetconfig['display'] == 'none'): ?>
259
		<div class="col-sm-3"><a href="#"><i class="icon icon-plus"></i> <?=$widgetconfig['name']?></a></div>
260
	<?php endif; ?>
261
<?php endforeach; ?>
262
	</div>
263
</div>
264

    
265
<div class="modal fade">
266
	<div class="modal-dialog">
267
		<div class="modal-content">
268
			<div class="modal-header">
269
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
270
				<h4 class="modal-title"><?=gettext("Welcome to the Dashboard page"); ?>!</h4>
271
			</div>
272
			<div class="modal-body">
273
				<p>
274
					<?=gettext("This page allows you to customize the information you want to be displayed!");?>
275
					<?=gettext("To get started click the");?> FIXME <?=gettext("icon to add widgets.");?><br />
276
					<br />
277
					<?=gettext("You can move any widget around by clicking and dragging the title.");?>
278
				</p>
279
			</div>
280
			<div class="modal-footer">
281
				<button type="button" class="btn btn-default btn-primary" data-dismiss="modal">Close</button>
282
			</div>
283
		</div>
284
	</div>
285
</div>
286

    
287
<div class="hidden" id="widgetSequence">
288
	<form action="/" method="post" id="widgetSequence">
289
		<input type="hidden" name="sequence" value="" />
290

    
291
		<button type="submit" class="btn btn-default">Store widget configuration</button>
292
	</form>
293
</div>
294

    
295
<?php
296
$widgetColumns = array();
297
foreach ($widgets as $widgetname => $widgetconfig)
298
{
299
	if ($widgetconfig['display'] == 'none')
300
		continue;
301

    
302
	if (!isset($widgetColumns[ $widgetconfig['col'] ]))
303
		$widgetColumns[ $widgetconfig['col'] ] = array();
304

    
305
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
306
}
307
?>
308

    
309
<div class="row">
310
<?php foreach ($widgetColumns as $column => $columnWidgets):?>
311
	<div class="col-md-6" id="widgets-<?=$column?>">
312
<?php foreach ($columnWidgets as $widgetname => $widgetconfig):?>
313
		<div class="panel panel-default" id="widget-<?=$widgetname?>">
314
			<div class="panel-heading">
315
				<?=$widgetconfig['name']?>
316
				<span class="icons">
317
					<a data-toggle="collapse" href="#widget-<?=$widgetname?> .panel-footer" class="config hidden">
318
						<i class="icon icon-wrench"></i>
319
					</a>
320
					<a data-toggle="collapse" href="#widget-<?=$widgetname?> .panel-body">
321
						<!--  actual icon is determined in css based on state of body -->
322
						<i class="icon icon-plus-sign"></i>
323
					</a>
324
					<a data-toggle="close" href="#widget-<?=$widgetname?>">
325
						<i class="icon icon-remove-sign"></i>
326
					</a>
327
				</span>
328
			</div>
329
			<div class="panel-body collapse<?=($widgetconfig['display']=='close' ? '' : ' in')?>">
330
				<?php include('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php'); ?>
331
			</div>
332
		</div>
333
<?php endforeach; ?>
334
	</div>
335
<?php endforeach; ?>
336
</div>
337

    
338
<script>
339
events.push(function() {
340
	// Hide configuration button for panels without configuration
341
	$('.container .panel-heading a.config').each(function (idx, el){
342
		var config = $(el).parents('.panel').children('.panel-footer');
343
		if (config.length == 1)
344
			$(el).removeClass('hidden');
345
	});
346

    
347
	// Initial state & toggle icons of collapsed panel
348
	$('.container .panel-heading a[data-toggle="collapse"] i').each(function (idx, el){
349
		var body = $(el).parents('.panel').children('.panel-body'), isOpen = body.hasClass('in');
350
		$(el).toggleClass('icon-plus-sign', !isOpen);
351
		$(el).toggleClass('icon-minus-sign', isOpen);
352

    
353
		body.on('show.bs.collapse', function(){ $(el).toggleClass('icon-minus-sign', true); $(el).toggleClass('icon-plus-sign', false); });
354
		body.on('hide.bs.collapse', function(){ $(el).toggleClass('icon-minus-sign', false); $(el).toggleClass('icon-plus-sign', true); });
355
	});
356

    
357
	// Make panels destroyable
358
	$('.container .panel-heading a[data-toggle="close"] i').each(function (idx, el){
359
		$(el).on('click', function(e){
360
			$(el).parents('.panel').collapse('hide');
361
		})
362
	});
363

    
364
	// Make panels sortable
365
	$('.container .col-md-6').sortable({
366
		handle: '.panel-heading',
367
		cursor: 'grabbing',
368
		connectWith: '.container .col-md-6',
369
		update: function(event, ui) {
370
			var isOpen, sequence = '';
371

    
372
			$('.container .col-md-6').each(function(idx, col){
373
				$('.panel', col).each(function(idx, widget){
374
					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'))[0].value = sequence;
382
		}
383
	});
384
});
385
</script>
386
<?php
387
//build list of javascript include files
388
foreach (glob('widgets/javascript/*.js') as $file)
389
	echo '<script src="'.$file.'"></script>';
390

    
391
include("foot.inc")?>
(92-92/252)