Project

General

Profile

Download (16.1 KB) Statistics
| Branch: | Tag: | Revision:
1 2cd6010c Scott Ullrich
<?php
2 5b237745 Scott Ullrich
/*
3 757733b5 Renato Botelho
	index.php
4 5b237745 Scott Ullrich
*/
5 fd9ebcd5 Stephen Beaver
/* ====================================================================
6 40547fe4 Stephen Beaver
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7 9da2cf1c Stephen Beaver
 *
8 cb41dd63 Renato Botelho
 *	Some or all of this file is based on the m0n0wall project which is
9
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
10 fd9ebcd5 Stephen Beaver
 *
11 40547fe4 Stephen Beaver
 *	Redistribution and use in source and binary forms, with or without modification,
12
 *	are permitted provided that the following conditions are met:
13 fd9ebcd5 Stephen Beaver
 *
14 40547fe4 Stephen Beaver
 *	1. Redistributions of source code must retain the above copyright notice,
15
 *		this list of conditions and the following disclaimer.
16 fd9ebcd5 Stephen Beaver
 *
17 40547fe4 Stephen Beaver
 *	2. Redistributions in binary form must reproduce the above copyright
18
 *		notice, this list of conditions and the following disclaimer in
19
 *		the documentation and/or other materials provided with the
20
 *		distribution.
21 fd9ebcd5 Stephen Beaver
 *
22 40547fe4 Stephen Beaver
 *	3. All advertising materials mentioning features or use of this software
23
 *		must display the following acknowledgment:
24
 *		"This product includes software developed by the pfSense Project
25
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
26 fd9ebcd5 Stephen Beaver
 *
27 40547fe4 Stephen Beaver
 *	4. The names "pfSense" and "pfSense Project" must not be used to
28
 *		 endorse or promote products derived from this software without
29
 *		 prior written permission. For written permission, please contact
30
 *		 coreteam@pfsense.org.
31 fd9ebcd5 Stephen Beaver
 *
32 40547fe4 Stephen Beaver
 *	5. Products derived from this software may not be called "pfSense"
33
 *		nor may "pfSense" appear in their names without prior written
34
 *		permission of the Electric Sheep Fencing, LLC.
35 fd9ebcd5 Stephen Beaver
 *
36 40547fe4 Stephen Beaver
 *	6. Redistributions of any form whatsoever must retain the following
37
 *		acknowledgment:
38 fd9ebcd5 Stephen Beaver
 *
39 40547fe4 Stephen Beaver
 *	"This product includes software developed by the pfSense Project
40
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
41 fd9ebcd5 Stephen Beaver
 *
42 40547fe4 Stephen Beaver
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
54 fd9ebcd5 Stephen Beaver
 *
55 40547fe4 Stephen Beaver
 *	====================================================================
56 fd9ebcd5 Stephen Beaver
 *
57
 */
58 5b237745 Scott Ullrich
59 6b07c15a Matthew Grooms
##|+PRIV
60
##|*IDENT=page-system-login/logout
61 5230f468 jim-p
##|*NAME=System: Login / Logout / Dashboard
62 b7ccf315 Erik Fonnesbeck
##|*DESCR=Allow access to the 'System: Login / Logout' page and Dashboard.
63 6b07c15a Matthew Grooms
##|*MATCH=index.php*
64
##|-PRIV
65
66 acc5dd59 jim-p
// Turn on buffering to speed up rendering
67 6c07db48 Phil Davis
ini_set('output_buffering', 'true');
68 acc5dd59 jim-p
69
// Start buffering with a cache size of 100000
70
ob_start(null, "1000");
71 880637d2 Scott Ullrich
72 acc5dd59 jim-p
## Load Essential Includes
73
require_once('guiconfig.inc');
74 32e834ff Ermal LUÇI
require_once('functions.inc');
75 acc5dd59 jim-p
require_once('notices.inc');
76 7c8f3711 jim-p
require_once("pkg-utils.inc");
77 acc5dd59 jim-p
78 329a1cd5 Stephen Beaver
if (isset($_POST['closenotice'])) {
79
	close_notice($_POST['closenotice']);
80
	sleep(1);
81 005ac3ca Marcello Coutinho
	exit;
82
}
83
84 0206483d Stephen Beaver
if (isset($_GET['closenotice'])) {
85
	close_notice($_GET['closenotice']);
86
	sleep(1);
87
}
88
89 41b1ff89 Phil Davis
if ($g['disablecrashreporter'] != true) {
90 36365f49 Scott Ullrich
	// Check to see if we have a crash report
91 eac584f3 Scott Ullrich
	$x = 0;
92 41b1ff89 Phil Davis
	if (file_exists("/tmp/PHP_errors.log")) {
93 dc43ff1e jim-p
		$total = `/usr/bin/grep -vi warning /tmp/PHP_errors.log | /usr/bin/wc -l | /usr/bin/awk '{ print $1 }'`;
94 41b1ff89 Phil Davis
		if ($total > 0) {
95 a9ee006d Scott Ullrich
			$x++;
96 41b1ff89 Phil Davis
		}
97 a9ee006d Scott Ullrich
	}
98 60e27eb0 Stephen Beaver
99 a9ee006d Scott Ullrich
	$crash = glob("/var/crash/*");
100 36365f49 Scott Ullrich
	$skip_files = array(".", "..", "minfree", "");
101 60e27eb0 Stephen Beaver
102 41b1ff89 Phil Davis
	if (is_array($crash)) {
103
		foreach ($crash as $c) {
104
			if (!in_array(basename($c), $skip_files)) {
105 36365f49 Scott Ullrich
				$x++;
106 41b1ff89 Phil Davis
			}
107 36365f49 Scott Ullrich
		}
108 60e27eb0 Stephen Beaver
109 41b1ff89 Phil Davis
		if ($x > 0) {
110 f49cd725 Phil Davis
			$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']);
111 c8532336 Phil Davis
			$class = "warning";
112 41b1ff89 Phil Davis
		}
113 104faa07 Scott Ullrich
	}
114
}
115
116 ef325a6c Phil Davis
##build list of php include files
117
$phpincludefiles = array();
118
$directory = "/usr/local/www/widgets/include/";
119
$dirhandle = opendir($directory);
120
$filename = "";
121
122
while (false !== ($filename = readdir($dirhandle))) {
123 dffe24be NewEraCracker
	if (!stristr($filename, ".inc")) {
124
		continue;
125
	}
126 ef325a6c Phil Davis
	$phpincludefiles[] = $filename;
127
}
128
129
## Include each widget include file.
130
## These define vars that specify the widget title and title link.
131
foreach ($phpincludefiles as $includename) {
132
	if (file_exists($directory . $includename)) {
133
		include($directory . $includename);
134
	}
135
}
136
137 acc5dd59 jim-p
##build list of widgets
138 aa82505e Phil Davis
foreach (glob("/usr/local/www/widgets/widgets/*.widget.php") as $file) {
139 41ea4cf3 Sjon Hortensius
	$name = basename($file, '.widget.php');
140 ef325a6c Phil Davis
	// Get the widget title that should be in a var defined in the widget's inc file.
141
	$widgettitle = ${$name . '_title'};
142
143 dffe24be NewEraCracker
	if (empty(trim($widgettitle))) {
144 ef325a6c Phil Davis
		// Fall back to constructing a title from the file name of the widget.
145
		$widgettitle = ucwords(str_replace('_', ' ', $name));
146
	}
147
148
	$widgets[ $name ] = array('name' => $widgettitle, 'display' => 'none');
149 acc5dd59 jim-p
}
150
151
##if no config entry found, initialize config entry
152
if (!is_array($config['widgets'])) {
153
	$config['widgets'] = array();
154
}
155 d772ac32 Erik Kristensen
156 41ea4cf3 Sjon Hortensius
if ($_POST && $_POST['sequence']) {
157 60e27eb0 Stephen Beaver
158 69b397dd Sjon Hortensius
	$config['widgets']['sequence'] = rtrim($_POST['sequence'], ',');
159 8191b36e Scott Ullrich
160 1c428d53 Phil Davis
	foreach ($widgets as $widgetname => $widgetconfig) {
161
		if ($_POST[$widgetname . '-config']) {
162 75ae3d1c Phil Davis
			$config['widgets'][$widgetname . '-config'] = $_POST[$widgetname . '-config'];
163 8191b36e Scott Ullrich
		}
164
	}
165
166 1180e4f0 Sjon Hortensius
	write_config(gettext("Widget configuration has been changed."));
167 69b397dd Sjon Hortensius
	header("Location: /");
168 1180e4f0 Sjon Hortensius
	exit;
169
}
170 757733b5 Renato Botelho
171 1180e4f0 Sjon Hortensius
## Load Functions Files
172
require_once('includes/functions.inc.php');
173 d772ac32 Erik Kristensen
174 1180e4f0 Sjon Hortensius
## Check to see if we have a swap space,
175
## if true, display, if false, hide it ...
176 1c428d53 Phil Davis
if (file_exists("/usr/sbin/swapinfo")) {
177 1180e4f0 Sjon Hortensius
	$swapinfo = `/usr/sbin/swapinfo`;
178 1c428d53 Phil Davis
	if (stristr($swapinfo, '%') == true) $showswap=true;
179 1180e4f0 Sjon Hortensius
}
180
181
## User recently restored his config.
182
## If packages are installed lets resync
183 1c428d53 Phil Davis
if (file_exists('/conf/needs_package_sync')) {
184
	if ($config['installedpackages'] <> '' && is_array($config['installedpackages']['package'])) {
185 2344bed4 Renato Botelho
		if ($g['platform'] == $g['product_name'] || $g['platform'] == "nanobsd") {
186 1180e4f0 Sjon Hortensius
			## If the user has logged into webGUI quickly while the system is booting then do not redirect them to
187
			## the package reinstall page. That is about to be done by the boot script anyway.
188 31f03b6c Sjon Hortensius
			## The code in head.inc will put up a notice to the user.
189 1180e4f0 Sjon Hortensius
			if (!platform_booting()) {
190
				header('Location: pkg_mgr_install.php?mode=reinstallall');
191
				exit;
192 6cc843c3 Scott Ullrich
			}
193 1df0159c Erik Kristensen
		}
194 1180e4f0 Sjon Hortensius
	} else {
195
		conf_mount_rw();
196
		@unlink('/conf/needs_package_sync');
197
		conf_mount_ro();
198 1df0159c Erik Kristensen
	}
199 1180e4f0 Sjon Hortensius
}
200 8fecad11 Scott Ullrich
201 1180e4f0 Sjon Hortensius
## If it is the first time webConfigurator has been
202
## accessed since initial install show this stuff.
203 1c428d53 Phil Davis
if (file_exists('/conf/trigger_initial_wizard')) {
204 1180e4f0 Sjon Hortensius
?>
205
<!DOCTYPE html>
206
<html lang="en">
207 702b324e Scott Ullrich
<head>
208 1180e4f0 Sjon Hortensius
	<link rel="stylesheet" href="/bootstrap/css/pfSense.css" />
209 5bca8df4 Stephen Beaver
	<title><?=$g['product_name']?>.localdomain - <?=$g['product_name']?> first time setup</title>
210 1180e4f0 Sjon Hortensius
	<meta http-equiv="refresh" content="1;url=wizard.php?xml=setup_wizard.xml" />
211
</head>
212
<body id="loading-wizard" class="no-menu">
213
	<div id="jumbotron">
214
		<div class="container">
215 c7d61071 Sander van Leeuwen
			<div class="col-sm-offset-3 col-sm-6 col-xs-12">
216 40547fe4 Stephen Beaver
				<font color="white">
217
				<p><h3><?=sprintf(gettext("Welcome to %s!\n"), $g['product_name'])?></h3></p>
218 c7d61071 Sander van Leeuwen
				<p><?=gettext("One moment while we start the initial setup wizard.")?></p>
219
				<p><?=gettext("Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal GUI.")?></p>
220 1c428d53 Phil Davis
				<p><?=sprintf(gettext("To bypass the wizard, click on the %s logo on the initial page."), $g['product_name'])?></p>
221 40547fe4 Stephen Beaver
				</font>
222 c7d61071 Sander van Leeuwen
			</div>
223 1180e4f0 Sjon Hortensius
		</div>
224
	</div>
225
</body>
226
</html>
227
<?php
228
	exit;
229
}
230 bf787c0a Scott Ullrich
231 1180e4f0 Sjon Hortensius
## Find out whether there's hardware encryption or not
232
unset($hwcrypto);
233
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
234
if ($fd) {
235
	while (!feof($fd)) {
236
		$dmesgl = fgets($fd);
237
		if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)
238
			or preg_match("/.*(VIA Padlock)/", $dmesgl, $matches)
239
			or preg_match("/^safe.: (\w.*)/", $dmesgl, $matches)
240
			or preg_match("/^ubsec.: (.*?),/", $dmesgl, $matches)
241
			or preg_match("/^padlock.: <(.*?)>,/", $dmesgl, $matches)
242 a2e6d7f8 Luiz Otavio O Souza
			or preg_match("/^glxsb.: (.*?),/", $dmesgl, $matches)) {
243 1180e4f0 Sjon Hortensius
			$hwcrypto = $matches[1];
244
			break;
245 5b237745 Scott Ullrich
		}
246
	}
247 1180e4f0 Sjon Hortensius
	fclose($fd);
248 aa82505e Phil Davis
	if (!isset($hwcrypto) && get_single_sysctl("dev.aesni.0.%desc")) {
249 a2e6d7f8 Luiz Otavio O Souza
		$hwcrypto = get_single_sysctl("dev.aesni.0.%desc");
250 aa82505e Phil Davis
	}
251 1180e4f0 Sjon Hortensius
}
252 45ee90ed Matthew Grooms
253 7abf7db5 Scott Dale
##build widget saved list information
254 019a94df Scott Dale
if ($config['widgets'] && $config['widgets']['sequence'] != "") {
255
	$pconfig['sequence'] = $config['widgets']['sequence'];
256 1180e4f0 Sjon Hortensius
	$widgetsfromconfig = array();
257 757733b5 Renato Botelho
258 aa82505e Phil Davis
	foreach (explode(',', $pconfig['sequence']) as $line) {
259 1180e4f0 Sjon Hortensius
		list($file, $col, $display) = explode(':', $line);
260
261
		// be backwards compatible
262 72eaefaf Stephen Beaver
		// If the display column information is missing, we will assign a temporary
263
		// column here. Next time the user saves the dashboard it will fix itself
264
		if ($col == "") {
265
			if ($file == "system_information") {
266
				$col = "col1";
267
			} else {
268
				$col = "col2";
269
			}
270
		}
271
272 1180e4f0 Sjon Hortensius
		$offset = strpos($file, '-container');
273 94704bc6 Phil Davis
		if (false !== $offset) {
274 1180e4f0 Sjon Hortensius
			$file = substr($file, 0, $offset);
275 94704bc6 Phil Davis
		}
276 1180e4f0 Sjon Hortensius
277 ef325a6c Phil Davis
		// Get the widget title that should be in a var defined in the widget's inc file.
278
		$widgettitle = ${$file . '_title'};
279
280 dffe24be NewEraCracker
		if (empty(trim($widgettitle))) {
281 ef325a6c Phil Davis
			// Fall back to constructing a title from the file name of the widget.
282
			$widgettitle = ucwords(str_replace('_', ' ', $file));
283
		}
284
285 1180e4f0 Sjon Hortensius
		$widgetsfromconfig[ $file ] = array(
286 ef325a6c Phil Davis
			'name' => $widgettitle,
287 1180e4f0 Sjon Hortensius
			'col' => $col,
288
			'display' => $display,
289
		);
290 1db766df Scott Dale
	}
291 757733b5 Renato Botelho
292 5c7657d6 Renato Botelho
	// add widgets that may not be in the saved configuration, in case they are to be displayed later
293 69b397dd Sjon Hortensius
	$widgets = $widgetsfromconfig + $widgets;
294 757733b5 Renato Botelho
295 019a94df Scott Dale
	##find custom configurations of a particular widget and load its info to $pconfig
296 1c428d53 Phil Davis
	foreach ($widgets as $widgetname => $widgetconfig) {
297 75ae3d1c Phil Davis
		if ($config['widgets'][$widgetname . '-config']) {
298
			$pconfig[$widgetname . '-config'] = $config['widgets'][$widgetname . '-config'];
299 757733b5 Renato Botelho
		}
300
	}
301 3e4e94ce Scott Dale
}
302
303 c05363c8 NOYB
## Get the configured options for Show/Hide available widgets panel.
304
$dashboard_available_widgets_hidden = isset($config['system']['webgui']['dashboardavailablewidgetspanel']) ? false : true;
305
306
if ($dashboard_available_widgets_hidden) {
307
	$panel_state = 'out';
308
	$panel_body_state = 'in';
309
} else {
310
	$panel_state = 'in';
311
	$panel_body_state = 'out';
312
}
313
314 1db766df Scott Dale
## Set Page Title and Include Header
315 2734d2db Jared Dillard
$pgtitle = array(gettext("Status"), gettext("Dashboard"));
316 1db766df Scott Dale
include("head.inc");
317 f6f6947e Scott Ullrich
318 41b1ff89 Phil Davis
if ($savemsg) {
319 c8532336 Phil Davis
	print_info_box($savemsg, $class);
320 41b1ff89 Phil Davis
}
321 fca795f8 Scott Ullrich
322 810a11bc Scott Ullrich
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
323 c69c58e2 Vinicius Coque
324 0682e26b Colin Smith
?>
325 1180e4f0 Sjon Hortensius
326 c05363c8 NOYB
<div class="panel panel-default collapse <?=$panel_state?>" id="widget-available">
327 95fa5cce Phil Davis
	<div class="panel-heading">
328
		<h2 class="panel-title"><?=gettext("Available Widgets"); ?>
329
			<span class="widget-heading-icon">
330
				<a data-toggle="collapse" href="#widget-available_panel-body" id="widgets-available">
331
					<i class="fa fa-plus-circle"></i>
332
				</a>
333
			</span>
334
		</h2>
335 166b0099 Stephen Beaver
	</div>
336 c05363c8 NOYB
	<div id="widget-available_panel-body" class="panel-body collapse <?=$panel_body_state?>">
337 9239f765 Jared Dillard
		<div class="content">
338
			<div class="row">
339 60e27eb0 Stephen Beaver
<?php
340 e76931e2 Stephen Beaver
341
// Build the Available Widgets table using a sorted copy of the $widgets array
342
$available = $widgets;
343 dffe24be NewEraCracker
uasort($available, function($a, $b){ return strcasecmp($a['name'], $b['name']); });
344 e76931e2 Stephen Beaver
345
foreach ($available as $widgetname => $widgetconfig):
346 60e27eb0 Stephen Beaver
	if ($widgetconfig['display'] == 'none'):
347
?>
348 a508c6e4 NOYB
		<div class="col-sm-3"><a href="#" id="btnadd-<?=$widgetname?>"><i class="fa fa-plus"></i> <?=$widgetconfig['name']?></a></div>
349 a2faa388 Sander van Leeuwen
	<?php endif; ?>
350
<?php endforeach; ?>
351 9239f765 Jared Dillard
			</div>
352
		</div>
353 1db766df Scott Dale
	</div>
354
</div>
355
356 a2faa388 Sander van Leeuwen
<div class="hidden" id="widgetSequence">
357 a508c6e4 NOYB
	<form action="/" method="post" id="widgetSequence_form" name="widgetForm">
358 41ea4cf3 Sjon Hortensius
		<input type="hidden" name="sequence" value="" />
359
	</form>
360
</div>
361
362 1180e4f0 Sjon Hortensius
<?php
363 41ea4cf3 Sjon Hortensius
$widgetColumns = array();
364 aa82505e Phil Davis
foreach ($widgets as $widgetname => $widgetconfig) {
365
	if ($widgetconfig['display'] == 'none') {
366 41ea4cf3 Sjon Hortensius
		continue;
367 aa82505e Phil Davis
	}
368 41ea4cf3 Sjon Hortensius
369 e8bd1464 Renato Botelho
	if (!file_exists('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php')) {
370
		continue;
371
	}
372
373 aa82505e Phil Davis
	if (!isset($widgetColumns[ $widgetconfig['col'] ])) {
374 41ea4cf3 Sjon Hortensius
		$widgetColumns[ $widgetconfig['col'] ] = array();
375 aa82505e Phil Davis
	}
376 41ea4cf3 Sjon Hortensius
377
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
378
}
379 1180e4f0 Sjon Hortensius
?>
380 41ea4cf3 Sjon Hortensius
381 a2faa388 Sander van Leeuwen
<div class="row">
382 2063a534 Jared Dillard
<?php
383 477db933 Jared Dillard
	$columnWidth = 12 / $numColumns;
384 a54d69c8 Stephen Beaver
385 e3843a08 Phil Davis
	for ($currentColumnNumber = 1; $currentColumnNumber <= $numColumns; $currentColumnNumber++) {
386
		echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '">';
387 2063a534 Jared Dillard
388 e3843a08 Phil Davis
		//if col$currentColumnNumber exists
389
		if (isset($widgetColumns['col'.$currentColumnNumber])) {
390
			$columnWidgets = $widgetColumns['col'.$currentColumnNumber];
391 2063a534 Jared Dillard
392
			foreach ($columnWidgets as $widgetname => $widgetconfig) {
393
				// Compose the widget title and include the title link if available
394
				$widgetlink = ${$widgetname . '_title_link'};
395
396
				if ((strlen($widgetlink) > 0)) {
397
					$wtitle = '<a href="' . $widgetlink . '"> ' . $widgetconfig['name'] . '</a>';
398
				} else {
399
					$wtitle = $widgetconfig['name'];
400
				}
401
				?>
402
					<div class="panel panel-default" id="widget-<?=$widgetname?>">
403
					<div class="panel-heading">
404 95fa5cce Phil Davis
						<h2 class="panel-title">
405
							<?=$wtitle?>
406
							<span class="widget-heading-icon">
407
								<a data-toggle="collapse" href="#widget-<?=$widgetname?>_panel-footer" class="config hidden">
408
									<i class="fa fa-wrench"></i>
409
								</a>
410
								<a data-toggle="collapse" href="#widget-<?=$widgetname?>_panel-body">
411
									<!--  actual icon is determined in css based on state of body -->
412
									<i class="fa fa-plus-circle"></i>
413
								</a>
414
								<a data-toggle="close" href="#widget-<?=$widgetname?>">
415
									<i class="fa fa-times-circle"></i>
416
								</a>
417
							</span>
418
						</h2>
419 2063a534 Jared Dillard
					</div>
420
					<div id="widget-<?=$widgetname?>_panel-body" class="panel-body collapse<?=($widgetconfig['display'] == 'close' ? '' : ' in')?>">
421
						<?php include('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php'); ?>
422
					</div>
423
				</div>
424
				<?php
425
			}
426 a54d69c8 Stephen Beaver
		} else {
427 e3843a08 Phil Davis
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '"></div>';
428 a54d69c8 Stephen Beaver
		}
429 2063a534 Jared Dillard
		echo "</div>";
430 477db933 Jared Dillard
	}
431
?>
432 2063a534 Jared Dillard
433 a2faa388 Sander van Leeuwen
</div>
434 561d55ff Erik Kristensen
435 8fd9052f Colin Fleming
<script type="text/javascript">
436
//<![CDATA[
437 eae6b58d Stephen Beaver
438
dirty = false;
439 aa82505e Phil Davis
function updateWidgets(newWidget) {
440 7f8f8808 Sjon Hortensius
	var sequence = '';
441
442 aa82505e Phil Davis
	$('.container .col-md-<?=$columnWidth?>').each(function(idx, col) {
443
		$('.panel', col).each(function(idx, widget) {
444 7f8f8808 Sjon Hortensius
			var isOpen = $('.panel-body', widget).hasClass('in');
445
446 94704bc6 Phil Davis
			sequence += widget.id.split('-')[1] + ':' + col.id.split('-')[1] + ':' + (isOpen ? 'open' : 'close') + ',';
447 7f8f8808 Sjon Hortensius
		});
448
	});
449
450 aa82505e Phil Davis
	if (typeof newWidget !== 'undefined') {
451 b5ff58cf Stephen Beaver
		// The system_information widget is always added to column one. Others go in column two
452
		if (newWidget == "system_information") {
453
			sequence += newWidget + ':' + 'col1:open';
454
		} else {
455 f4a15d29 Stephen Beaver
		sequence += newWidget + ':' + 'col2:open';
456 b5ff58cf Stephen Beaver
		}
457 aa82505e Phil Davis
	}
458 60e27eb0 Stephen Beaver
459 a508c6e4 NOYB
	$('input[name=sequence]', $('#widgetSequence_form')).val(sequence);
460 7f8f8808 Sjon Hortensius
}
461
462 dc58b7b3 Sjon Hortensius
events.push(function() {
463
464
	// Make panels destroyable
465 aa82505e Phil Davis
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el) {
466
		$(el).on('click', function(e) {
467 7f8f8808 Sjon Hortensius
			$(el).parents('.panel').remove();
468
			updateWidgets();
469 eae6b58d Stephen Beaver
			// Submit the form save/display all selected widgets
470
			$('[name=widgetForm]').submit();
471 dc58b7b3 Sjon Hortensius
		})
472
	});
473
474
	// Make panels sortable
475 477db933 Jared Dillard
	$('.container .col-md-<?=$columnWidth?>').sortable({
476 dc58b7b3 Sjon Hortensius
		handle: '.panel-heading',
477
		cursor: 'grabbing',
478 477db933 Jared Dillard
		connectWith: '.container .col-md-<?=$columnWidth?>',
479 e94f260c Stephen Beaver
		update: function(){dirty = true;}
480 dc58b7b3 Sjon Hortensius
	});
481 60e27eb0 Stephen Beaver
482
	// On clicking a widget to install . .
483 a508c6e4 NOYB
	$('[id^=btnadd-]').click(function(event) {
484 f4a15d29 Stephen Beaver
		// Add the widget name to the list of displayed widgets
485 a508c6e4 NOYB
		updateWidgets(this.id.replace('btnadd-', ''));
486 60e27eb0 Stephen Beaver
487
		// Submit the form save/display all selected widgets
488
		$('[name=widgetForm]').submit();
489
	});
490
491 eae6b58d Stephen Beaver
492 32e7220f Stephen Beaver
	$('.context-links li:last').prev('li').html('<a href="#" class=help-icon" title="<?=gettext("Save dashboard layout")?>" id="btnstore"><i class="fa fa-save"></i></a>');
493 e94f260c Stephen Beaver
494
	$('#btnstore').click(function() {
495
		updateWidgets();
496
		dirty = false;
497
		$('[name=widgetForm]').submit();
498
	});
499 eae6b58d Stephen Beaver
500
	// provide a warning message if the user tries to change page before saving
501
	$(window).bind('beforeunload', function(){
502
		if (dirty) {
503 228da1c5 Stephen Beaver
			return ("<?=gettext('You have moved one or more widgets but have not yet saved')?>");
504 eae6b58d Stephen Beaver
		} else {
505
			return undefined;
506
		}
507
	});
508 dc58b7b3 Sjon Hortensius
});
509 8fd9052f Colin Fleming
//]]>
510 dc58b7b3 Sjon Hortensius
</script>
511 41ea4cf3 Sjon Hortensius
<?php
512 1180e4f0 Sjon Hortensius
//build list of javascript include files
513 aa82505e Phil Davis
foreach (glob('widgets/javascript/*.js') as $file) {
514 1180e4f0 Sjon Hortensius
	echo '<script src="'.$file.'"></script>';
515 aa82505e Phil Davis
}
516 927ea6e1 jim-p
517 1c428d53 Phil Davis
include("foot.inc");