Project

General

Profile

Download (22.7 KB) Statistics
| Branch: | Tag: | Revision:
1 2cd6010c Scott Ullrich
<?php
2 5b237745 Scott Ullrich
/*
3 c5d81585 Renato Botelho
 * index.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * 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 b12ea3fb Renato Botelho
 * 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 c5d81585 Renato Botelho
 *
17 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
18 c5d81585 Renato Botelho
 *
19 b12ea3fb Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 */
25 5b237745 Scott Ullrich
26 6b07c15a Matthew Grooms
##|+PRIV
27 5d916fc7 Stephen Beaver
##|*IDENT=page-system-login-logout
28 5230f468 jim-p
##|*NAME=System: Login / Logout / Dashboard
29 b7ccf315 Erik Fonnesbeck
##|*DESCR=Allow access to the 'System: Login / Logout' page and Dashboard.
30 6b07c15a Matthew Grooms
##|*MATCH=index.php*
31
##|-PRIV
32
33 acc5dd59 jim-p
// Turn on buffering to speed up rendering
34 6c07db48 Phil Davis
ini_set('output_buffering', 'true');
35 acc5dd59 jim-p
36
// Start buffering with a cache size of 100000
37
ob_start(null, "1000");
38 880637d2 Scott Ullrich
39 acc5dd59 jim-p
## Load Essential Includes
40
require_once('guiconfig.inc');
41 32e834ff Ermal LUÇI
require_once('functions.inc');
42 acc5dd59 jim-p
require_once('notices.inc');
43 7c8f3711 jim-p
require_once("pkg-utils.inc");
44 acc5dd59 jim-p
45 329a1cd5 Stephen Beaver
if (isset($_POST['closenotice'])) {
46
	close_notice($_POST['closenotice']);
47
	sleep(1);
48 005ac3ca Marcello Coutinho
	exit;
49
}
50
51 cbb82e6b Steve Beaver
if (isset($_REQUEST['closenotice'])) {
52
	close_notice($_REQUEST['closenotice']);
53 0206483d Stephen Beaver
	sleep(1);
54
}
55
56 41b1ff89 Phil Davis
if ($g['disablecrashreporter'] != true) {
57 36365f49 Scott Ullrich
	// Check to see if we have a crash report
58 eac584f3 Scott Ullrich
	$x = 0;
59 41b1ff89 Phil Davis
	if (file_exists("/tmp/PHP_errors.log")) {
60 918f0a94 NewEraCracker
		$total = `/bin/cat /tmp/PHP_errors.log | /usr/bin/wc -l | /usr/bin/awk '{ print $1 }'`;
61 41b1ff89 Phil Davis
		if ($total > 0) {
62 a9ee006d Scott Ullrich
			$x++;
63 41b1ff89 Phil Davis
		}
64 a9ee006d Scott Ullrich
	}
65 60e27eb0 Stephen Beaver
66 a9ee006d Scott Ullrich
	$crash = glob("/var/crash/*");
67 36365f49 Scott Ullrich
	$skip_files = array(".", "..", "minfree", "");
68 60e27eb0 Stephen Beaver
69 41b1ff89 Phil Davis
	if (is_array($crash)) {
70
		foreach ($crash as $c) {
71
			if (!in_array(basename($c), $skip_files)) {
72 36365f49 Scott Ullrich
				$x++;
73 41b1ff89 Phil Davis
			}
74 36365f49 Scott Ullrich
		}
75 60e27eb0 Stephen Beaver
76 41b1ff89 Phil Davis
		if ($x > 0) {
77 c87eeb08 Phil Davis
			$savemsg = sprintf(gettext("%s has detected a crash report or programming bug."), $g['product_name']) . " ";
78
			if (isAllowedPage("/crash_reporter.php")) {
79 7ae1b34f Phil Davis
				$savemsg .= sprintf(gettext('Click %1$shere%2$s for more information.'), '<a href="crash_reporter.php">', '</a>');
80 c87eeb08 Phil Davis
			} else {
81 6f4323f3 Phil Davis
				$savemsg .= sprintf(gettext("Contact a firewall administrator for more information."));
82 c87eeb08 Phil Davis
			}
83 c8532336 Phil Davis
			$class = "warning";
84 41b1ff89 Phil Davis
		}
85 104faa07 Scott Ullrich
	}
86
}
87
88 8452bfc2 stilez
## Include each widget php include file.
89
## These define vars that specify the widget title and title link.
90
91 ef325a6c Phil Davis
$directory = "/usr/local/www/widgets/include/";
92
$dirhandle = opendir($directory);
93
$filename = "";
94
95 8452bfc2 stilez
while (($filename = readdir($dirhandle)) !== false) {
96
	if (strtolower(substr($filename, -4)) == ".inc" && file_exists($directory . $filename)) {
97
		include_once($directory . $filename);
98 ef325a6c Phil Davis
	}
99
}
100
101 acc5dd59 jim-p
##build list of widgets
102 aa82505e Phil Davis
foreach (glob("/usr/local/www/widgets/widgets/*.widget.php") as $file) {
103 0172a197 Phil Davis
	$basename = basename($file, '.widget.php');
104 ef325a6c Phil Davis
	// Get the widget title that should be in a var defined in the widget's inc file.
105 0172a197 Phil Davis
	$widgettitle = ${$basename . '_title'};
106 ef325a6c Phil Davis
107 dffe24be NewEraCracker
	if (empty(trim($widgettitle))) {
108 ef325a6c Phil Davis
		// Fall back to constructing a title from the file name of the widget.
109 0172a197 Phil Davis
		$widgettitle = ucwords(str_replace('_', ' ', $basename));
110 ef325a6c Phil Davis
	}
111
112 f14e891d Phil Davis
	$known_widgets[$basename . '-0'] = array(
113
		'basename' => $basename,
114
		'title' => $widgettitle,
115
		'display' => 'none',
116
		'multicopy' => ${$basename . '_allow_multiple_widget_copies'}
117
	);
118 acc5dd59 jim-p
}
119
120
##if no config entry found, initialize config entry
121
if (!is_array($config['widgets'])) {
122
	$config['widgets'] = array();
123
}
124 d7c2f4fe Steve Beaver
125 5aad7323 NewEraCracker
if (!is_array($user_settings['widgets'])) {
126
	$user_settings['widgets'] = array();
127
}
128 d772ac32 Erik Kristensen
129 41ea4cf3 Sjon Hortensius
if ($_POST && $_POST['sequence']) {
130 60e27eb0 Stephen Beaver
131 2b7d0520 Phil Davis
	// Start with the user's widget settings.
132
	$widget_settings = $user_settings['widgets'];
133 236e6a54 Stephen Beaver
134 0172a197 Phil Davis
	$widget_sep = ',';
135
	$widget_seq_array = explode($widget_sep, rtrim($_POST['sequence'], $widget_sep));
136
	$widget_counter_array = array();
137
	$widget_sep = '';
138 8191b36e Scott Ullrich
139 0172a197 Phil Davis
	// Make a record of the counter of each widget that is in use.
140
	foreach ($widget_seq_array as $widget_seq_data) {
141
		list($basename, $col, $display, $widget_counter) = explode(':', $widget_seq_data);
142
143
		if ($widget_counter != 'next') {
144
			$widget_counter_array[$basename][$widget_counter] = true;
145
			$widget_sequence .= $widget_sep . $widget_seq_data;
146
			$widget_sep = ',';
147
		}
148
	}
149
150
	// Find any new entry (and do not assume there is only 1 new entry)
151
	foreach ($widget_seq_array as $widget_seq_data) {
152
		list($basename, $col, $display, $widget_counter) = explode(':', $widget_seq_data);
153
154
		if ($widget_counter == 'next') {
155
			// Construct the widget counter of the new widget instance by finding
156
			// the first non-negative integer that is not in use.
157
			// The reasoning here is that if you just deleted a widget instance,
158
			// e.g. had System Information 0,1,2 and deleted 1,
159
			// then when you add System Information again it will become instance 1,
160
			// which will bring back whatever filter selections happened to be on
161
			// the previous instance 1.
162
			$instance_num = 0;
163
164
			while (isset($widget_counter_array[$basename][$instance_num])) {
165
				$instance_num++;
166
			}
167
168
			$widget_sequence .= $widget_sep . $basename . ':' . $col . ':' . $display . ':' . $instance_num;
169
			$widget_counter_array[$basename][$instance_num] = true;
170
			$widget_sep = ',';
171
		}
172
	}
173
174
	$widget_settings['sequence'] = $widget_sequence;
175
176
	foreach ($widget_counter_array as $basename => $instances) {
177
		foreach ($instances as $instance => $value) {
178
			$widgetconfigname = $basename . '-' . $instance . '-config';
179
			if ($_POST[$widgetconfigname]) {
180
				$widget_settings[$widgetconfigname] = $_POST[$widgetconfigname];
181
			}
182 8191b36e Scott Ullrich
		}
183
	}
184
185 8bab524e Phil Davis
	save_widget_settings($_SESSION['Username'], $widget_settings);
186 69b397dd Sjon Hortensius
	header("Location: /");
187 1180e4f0 Sjon Hortensius
	exit;
188
}
189 757733b5 Renato Botelho
190 1180e4f0 Sjon Hortensius
## Load Functions Files
191
require_once('includes/functions.inc.php');
192 d772ac32 Erik Kristensen
193 1180e4f0 Sjon Hortensius
## Check to see if we have a swap space,
194
## if true, display, if false, hide it ...
195 1c428d53 Phil Davis
if (file_exists("/usr/sbin/swapinfo")) {
196 1180e4f0 Sjon Hortensius
	$swapinfo = `/usr/sbin/swapinfo`;
197 1c428d53 Phil Davis
	if (stristr($swapinfo, '%') == true) $showswap=true;
198 1180e4f0 Sjon Hortensius
}
199
200
## User recently restored his config.
201
## If packages are installed lets resync
202 1c428d53 Phil Davis
if (file_exists('/conf/needs_package_sync')) {
203
	if ($config['installedpackages'] <> '' && is_array($config['installedpackages']['package'])) {
204 dc61252a Renato Botelho
		## If the user has logged into webGUI quickly while the system is booting then do not redirect them to
205
		## the package reinstall page. That is about to be done by the boot script anyway.
206
		## The code in head.inc will put up a notice to the user.
207
		if (!platform_booting()) {
208
			header('Location: pkg_mgr_install.php?mode=reinstallall');
209
			exit;
210 1df0159c Erik Kristensen
		}
211 1180e4f0 Sjon Hortensius
	} else {
212
		@unlink('/conf/needs_package_sync');
213 1df0159c Erik Kristensen
	}
214 1180e4f0 Sjon Hortensius
}
215 8fecad11 Scott Ullrich
216 1180e4f0 Sjon Hortensius
## If it is the first time webConfigurator has been
217
## accessed since initial install show this stuff.
218 1c428d53 Phil Davis
if (file_exists('/conf/trigger_initial_wizard')) {
219 1180e4f0 Sjon Hortensius
?>
220
<!DOCTYPE html>
221
<html lang="en">
222 de5c66b5 Steve Beaver
	<head>
223
		<link rel="stylesheet" href="/css/pfSense.css" />
224
		<title><?=$g['product_name']?>.localdomain - <?=$g['product_name']?> first time setup</title>
225
		<meta http-equiv="refresh" content="1;url=wizard.php?xml=setup_wizard.xml" />
226
	</head>
227
	<body id="loading-wizard" class="no-menu">
228
		<div id="jumbotron">
229
			<div class="container">
230
				<div class="col-sm-offset-3 col-sm-6 col-xs-12">
231
					<font color="white">
232
					<p><h3><?=sprintf(gettext("Welcome to %s!") . "\n", $g['product_name'])?></h3></p>
233
					<p><?=gettext("One moment while the initial setup wizard starts.")?></p>
234
					<p><?=gettext("Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal GUI.")?></p>
235
					<p><?=sprintf(gettext("To bypass the wizard, click on the %s logo on the initial page."), $g['product_name'])?></p>
236
					</font>
237
				</div>
238 c7d61071 Sander van Leeuwen
			</div>
239 1180e4f0 Sjon Hortensius
		</div>
240 de5c66b5 Steve Beaver
	</body>
241 1180e4f0 Sjon Hortensius
</html>
242
<?php
243
	exit;
244
}
245 bf787c0a Scott Ullrich
246 1180e4f0 Sjon Hortensius
## Find out whether there's hardware encryption or not
247
unset($hwcrypto);
248
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
249
if ($fd) {
250
	while (!feof($fd)) {
251
		$dmesgl = fgets($fd);
252
		if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)
253
			or preg_match("/.*(VIA Padlock)/", $dmesgl, $matches)
254
			or preg_match("/^safe.: (\w.*)/", $dmesgl, $matches)
255
			or preg_match("/^ubsec.: (.*?),/", $dmesgl, $matches)
256 2ce5cd33 jim-p
			or preg_match("/^padlock.: <(.*?)>,/", $dmesgl, $matches)) {
257 1180e4f0 Sjon Hortensius
			$hwcrypto = $matches[1];
258
			break;
259 5b237745 Scott Ullrich
		}
260
	}
261 1180e4f0 Sjon Hortensius
	fclose($fd);
262 aa82505e Phil Davis
	if (!isset($hwcrypto) && get_single_sysctl("dev.aesni.0.%desc")) {
263 a2e6d7f8 Luiz Otavio O Souza
		$hwcrypto = get_single_sysctl("dev.aesni.0.%desc");
264 aa82505e Phil Davis
	}
265 1180e4f0 Sjon Hortensius
}
266 45ee90ed Matthew Grooms
267 7abf7db5 Scott Dale
##build widget saved list information
268 8bab524e Phil Davis
if ($user_settings['widgets']['sequence'] != "") {
269
	$dashboardcolumns = isset($user_settings['webgui']['dashboardcolumns']) ? $user_settings['webgui']['dashboardcolumns'] : 2;
270
	$pconfig['sequence'] = $user_settings['widgets']['sequence'];
271 1180e4f0 Sjon Hortensius
	$widgetsfromconfig = array();
272 757733b5 Renato Botelho
273 aa82505e Phil Davis
	foreach (explode(',', $pconfig['sequence']) as $line) {
274 0172a197 Phil Davis
		$line_items = explode(':', $line);
275
		if (count($line_items) == 3) {
276
			// There can be multiple copies of a widget on the dashboard.
277
			// Default the copy number if it is not present (e.g. from old configs)
278
			$line_items[] = 0;
279
		}
280
281
		list($basename, $col, $display, $copynum) = $line_items;
282 1180e4f0 Sjon Hortensius
283
		// be backwards compatible
284 72eaefaf Stephen Beaver
		// If the display column information is missing, we will assign a temporary
285
		// column here. Next time the user saves the dashboard it will fix itself
286
		if ($col == "") {
287 0172a197 Phil Davis
			if ($basename == "system_information") {
288 72eaefaf Stephen Beaver
				$col = "col1";
289
			} else {
290
				$col = "col2";
291
			}
292
		}
293
294 ad51eb90 Phil Davis
		// Limit the column to the current dashboard columns.
295
		if (substr($col, 3) > $dashboardcolumns) {
296
			$col = "col" . $dashboardcolumns;
297
		}
298
299 0172a197 Phil Davis
		$offset = strpos($basename, '-container');
300 94704bc6 Phil Davis
		if (false !== $offset) {
301 0172a197 Phil Davis
			$basename = substr($basename, 0, $offset);
302 94704bc6 Phil Davis
		}
303 0fc6d49d Phil Davis
		$widgetkey = $basename . '-' . $copynum;
304 1180e4f0 Sjon Hortensius
305 0fc6d49d Phil Davis
		if (isset($user_settings['widgets'][$widgetkey]['descr'])) {
306
			$widgettitle = htmlentities($user_settings['widgets'][$widgetkey]['descr']);
307
		} else {
308
			// Get the widget title that should be in a var defined in the widget's inc file.
309
			$widgettitle = ${$basename . '_title'};
310 ef325a6c Phil Davis
311 0fc6d49d Phil Davis
			if (empty(trim($widgettitle))) {
312
				// Fall back to constructing a title from the file name of the widget.
313
				$widgettitle = ucwords(str_replace('_', ' ', $basename));
314
			}
315 ef325a6c Phil Davis
		}
316
317 0172a197 Phil Davis
		$widgetsfromconfig[$widgetkey] = array(
318
			'basename' => $basename,
319
			'title' => $widgettitle,
320 1180e4f0 Sjon Hortensius
			'col' => $col,
321
			'display' => $display,
322 0172a197 Phil Davis
			'copynum' => $copynum,
323 f14e891d Phil Davis
			'multicopy' => ${$basename . '_allow_multiple_widget_copies'}
324 1180e4f0 Sjon Hortensius
		);
325 f14e891d Phil Davis
326
		// Update the known_widgets entry so we know if any copy of the widget is being displayed
327
		$known_widgets[$basename . '-0']['display'] = $display;
328 1db766df Scott Dale
	}
329 757733b5 Renato Botelho
330 5c7657d6 Renato Botelho
	// add widgets that may not be in the saved configuration, in case they are to be displayed later
331 0172a197 Phil Davis
	$widgets = $widgetsfromconfig + $known_widgets;
332 757733b5 Renato Botelho
333 019a94df Scott Dale
	##find custom configurations of a particular widget and load its info to $pconfig
334 1c428d53 Phil Davis
	foreach ($widgets as $widgetname => $widgetconfig) {
335 75ae3d1c Phil Davis
		if ($config['widgets'][$widgetname . '-config']) {
336
			$pconfig[$widgetname . '-config'] = $config['widgets'][$widgetname . '-config'];
337 757733b5 Renato Botelho
		}
338
	}
339 3e4e94ce Scott Dale
}
340
341 c05363c8 NOYB
## Get the configured options for Show/Hide available widgets panel.
342 8bab524e Phil Davis
$dashboard_available_widgets_hidden = !$user_settings['webgui']['dashboardavailablewidgetspanel'];
343 c05363c8 NOYB
344
if ($dashboard_available_widgets_hidden) {
345
	$panel_state = 'out';
346
	$panel_body_state = 'in';
347
} else {
348
	$panel_state = 'in';
349
	$panel_body_state = 'out';
350
}
351
352 1db766df Scott Dale
## Set Page Title and Include Header
353 2734d2db Jared Dillard
$pgtitle = array(gettext("Status"), gettext("Dashboard"));
354 1db766df Scott Dale
include("head.inc");
355 f6f6947e Scott Ullrich
356 41b1ff89 Phil Davis
if ($savemsg) {
357 c8532336 Phil Davis
	print_info_box($savemsg, $class);
358 41b1ff89 Phil Davis
}
359 fca795f8 Scott Ullrich
360 810a11bc Scott Ullrich
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
361 c69c58e2 Vinicius Coque
362 0682e26b Colin Smith
?>
363 1180e4f0 Sjon Hortensius
364 c05363c8 NOYB
<div class="panel panel-default collapse <?=$panel_state?>" id="widget-available">
365 95fa5cce Phil Davis
	<div class="panel-heading">
366
		<h2 class="panel-title"><?=gettext("Available Widgets"); ?>
367
			<span class="widget-heading-icon">
368
				<a data-toggle="collapse" href="#widget-available_panel-body" id="widgets-available">
369
					<i class="fa fa-plus-circle"></i>
370
				</a>
371
			</span>
372
		</h2>
373 166b0099 Stephen Beaver
	</div>
374 c05363c8 NOYB
	<div id="widget-available_panel-body" class="panel-body collapse <?=$panel_body_state?>">
375 9239f765 Jared Dillard
		<div class="content">
376
			<div class="row">
377 60e27eb0 Stephen Beaver
<?php
378 e76931e2 Stephen Beaver
379 0172a197 Phil Davis
// Build the Available Widgets table using a sorted copy of the $known_widgets array
380
$available = $known_widgets;
381
uasort($available, function($a, $b){ return strcasecmp($a['title'], $b['title']); });
382 e76931e2 Stephen Beaver
383 0172a197 Phil Davis
foreach ($available as $widgetkey => $widgetconfig):
384 f14e891d Phil Davis
	// If the widget supports multiple copies, or no copies are displayed yet, then it is available to add
385
	if (($widgetconfig['multicopy']) || ($widgetconfig['display'] == 'none')):
386 60e27eb0 Stephen Beaver
?>
387 0172a197 Phil Davis
		<div class="col-sm-3"><a href="#" id="btnadd-<?=$widgetconfig['basename']?>"><i class="fa fa-plus"></i> <?=$widgetconfig['title']?></a></div>
388 f14e891d Phil Davis
	<?php endif; ?>
389 d7c2f4fe Steve Beaver
<?php
390 8452bfc2 stilez
endforeach;
391
?>
392 9239f765 Jared Dillard
			</div>
393 8452bfc2 stilez
<p style="text-align:center"><?=sprintf(gettext('Other dashboard settings are available from the <a href="%s">General Setup</a> page.'), '/system.php')?></p>
394 9239f765 Jared Dillard
		</div>
395 1db766df Scott Dale
	</div>
396
</div>
397
398 a2faa388 Sander van Leeuwen
<div class="hidden" id="widgetSequence">
399 a508c6e4 NOYB
	<form action="/" method="post" id="widgetSequence_form" name="widgetForm">
400 41ea4cf3 Sjon Hortensius
		<input type="hidden" name="sequence" value="" />
401
	</form>
402
</div>
403
404 1180e4f0 Sjon Hortensius
<?php
405 41ea4cf3 Sjon Hortensius
$widgetColumns = array();
406 0172a197 Phil Davis
foreach ($widgets as $widgetkey => $widgetconfig) {
407 8452bfc2 stilez
	if ($widgetconfig['display'] != 'none' && file_exists("/usr/local/www/widgets/widgets/{$widgetconfig['basename']}.widget.php")) {
408
		if (!isset($widgetColumns[$widgetconfig['col']])) {
409
			$widgetColumns[$widgetconfig['col']] = array();
410
		}
411
		$widgetColumns[$widgetconfig['col']][$widgetkey] = $widgetconfig;
412 aa82505e Phil Davis
	}
413 41ea4cf3 Sjon Hortensius
}
414 1180e4f0 Sjon Hortensius
?>
415 41ea4cf3 Sjon Hortensius
416 a2faa388 Sander van Leeuwen
<div class="row">
417 2063a534 Jared Dillard
<?php
418 d86cff7f Phil Davis
	$columnWidth = (int) (12 / $numColumns);
419 a54d69c8 Stephen Beaver
420 e3843a08 Phil Davis
	for ($currentColumnNumber = 1; $currentColumnNumber <= $numColumns; $currentColumnNumber++) {
421 cee365e6 Stephen Beaver
422 2063a534 Jared Dillard
423 e3843a08 Phil Davis
		//if col$currentColumnNumber exists
424
		if (isset($widgetColumns['col'.$currentColumnNumber])) {
425 caf897c8 Jared Dillard
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '">';
426 e3843a08 Phil Davis
			$columnWidgets = $widgetColumns['col'.$currentColumnNumber];
427 2063a534 Jared Dillard
428 0172a197 Phil Davis
			foreach ($columnWidgets as $widgetkey => $widgetconfig) {
429
				// Construct some standard names for the ids this widget will use for its commonly-used elements.
430
				// Included widget.php code can rely on and use these, so the format does not have to be repeated in every widget.php
431
				$widget_panel_body_id = 'widget-' . $widgetkey . '_panel-body';
432
				$widget_panel_footer_id = 'widget-' . $widgetkey . '_panel-footer';
433
				$widget_showallnone_id = 'widget-' . $widgetkey . '_showallnone';
434
435 2063a534 Jared Dillard
				// Compose the widget title and include the title link if available
436 0172a197 Phil Davis
				$widgetlink = ${$widgetconfig['basename'] . '_title_link'};
437 2063a534 Jared Dillard
438
				if ((strlen($widgetlink) > 0)) {
439 0172a197 Phil Davis
					$wtitle = '<a href="' . $widgetlink . '"> ' . $widgetconfig['title'] . '</a>';
440 2063a534 Jared Dillard
				} else {
441 0172a197 Phil Davis
					$wtitle = $widgetconfig['title'];
442 2063a534 Jared Dillard
				}
443
				?>
444 0172a197 Phil Davis
				<div class="panel panel-default" id="widget-<?=$widgetkey?>">
445 2063a534 Jared Dillard
					<div class="panel-heading">
446 95fa5cce Phil Davis
						<h2 class="panel-title">
447
							<?=$wtitle?>
448
							<span class="widget-heading-icon">
449 0172a197 Phil Davis
								<a data-toggle="collapse" href="#<?=$widget_panel_footer_id?>" class="config hidden">
450 95fa5cce Phil Davis
									<i class="fa fa-wrench"></i>
451
								</a>
452 0172a197 Phil Davis
								<a data-toggle="collapse" href="#<?=$widget_panel_body_id?>">
453 95fa5cce Phil Davis
									<!--  actual icon is determined in css based on state of body -->
454
									<i class="fa fa-plus-circle"></i>
455
								</a>
456 0172a197 Phil Davis
								<a data-toggle="close" href="#widget-<?=$widgetkey?>">
457 95fa5cce Phil Davis
									<i class="fa fa-times-circle"></i>
458
								</a>
459
							</span>
460
						</h2>
461 2063a534 Jared Dillard
					</div>
462 0172a197 Phil Davis
					<div id="<?=$widget_panel_body_id?>" class="panel-body collapse<?=($widgetconfig['display'] == 'close' ? '' : ' in')?>">
463
						<?php
464
							// For backward compatibility, included *.widget.php code needs the var $widgetname
465
							$widgetname = $widgetkey;
466
							// Determine if this is the first instance of this particular widget.
467
							// Provide the $widget_first_instance var, to make it easy for the included widget code
468
							// to be able to know if it is being included for the first time.
469
							if ($widgets_found[$widgetconfig['basename']]) {
470
								$widget_first_instance = false;
471
							} else {
472
								$widget_first_instance = true;
473
								$widgets_found[$widgetconfig['basename']] = true;
474
							}
475
							include('/usr/local/www/widgets/widgets/' . $widgetconfig['basename'] . '.widget.php');
476
						?>
477 2063a534 Jared Dillard
					</div>
478
				</div>
479
				<?php
480
			}
481 6fefbd48 Jared Dillard
			echo "</div>";
482 a54d69c8 Stephen Beaver
		} else {
483 caf897c8 Jared Dillard
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '"></div>';
484 a54d69c8 Stephen Beaver
		}
485 cee365e6 Stephen Beaver
486 477db933 Jared Dillard
	}
487
?>
488 2063a534 Jared Dillard
489 a2faa388 Sander van Leeuwen
</div>
490 561d55ff Erik Kristensen
491 de5c66b5 Steve Beaver
<?php
492
// Import the modal form used to display the copyright/usage information, then rename it
493
// THis should cause it to display only once per install or update
494
if (file_exists('/usr/local/www/copynotice.inc')) {
495
	require_once('/usr/local/www/copynotice.inc');
496
	rename('/usr/local/www/copynotice.inc', '/usr/local/www/copynotice.old');
497
}
498
?>
499
500 8fd9052f Colin Fleming
<script type="text/javascript">
501
//<![CDATA[
502 eae6b58d Stephen Beaver
503
dirty = false;
504 aa82505e Phil Davis
function updateWidgets(newWidget) {
505 7f8f8808 Sjon Hortensius
	var sequence = '';
506
507 aa82505e Phil Davis
	$('.container .col-md-<?=$columnWidth?>').each(function(idx, col) {
508
		$('.panel', col).each(function(idx, widget) {
509 7f8f8808 Sjon Hortensius
			var isOpen = $('.panel-body', widget).hasClass('in');
510 621dd536 Phil Davis
			var widget_basename = widget.id.split('-')[1];
511 7f8f8808 Sjon Hortensius
512 621dd536 Phil Davis
			// Only save details for panels that have id's like'widget-*'
513
			// Some widgets create other panels, so ignore any of those.
514
			if ((widget.id.split('-')[0] == 'widget') && (typeof widget_basename !== 'undefined')) {
515 0172a197 Phil Davis
				sequence += widget_basename + ':' + col.id.split('-')[1] + ':' + (isOpen ? 'open' : 'close') + ':' + widget.id.split('-')[2] + ',';
516 621dd536 Phil Davis
			}
517 7f8f8808 Sjon Hortensius
		});
518
	});
519
520 aa82505e Phil Davis
	if (typeof newWidget !== 'undefined') {
521 b5ff58cf Stephen Beaver
		// The system_information widget is always added to column one. Others go in column two
522
		if (newWidget == "system_information") {
523 0172a197 Phil Davis
			sequence += newWidget.split('-')[0] + ':' + 'col1:open:next';
524 b5ff58cf Stephen Beaver
		} else {
525 0172a197 Phil Davis
			sequence += newWidget.split('-')[0] + ':' + 'col2:open:next';
526 b5ff58cf Stephen Beaver
		}
527 aa82505e Phil Davis
	}
528 60e27eb0 Stephen Beaver
529 a508c6e4 NOYB
	$('input[name=sequence]', $('#widgetSequence_form')).val(sequence);
530 7f8f8808 Sjon Hortensius
}
531
532 fba53b43 Phil Davis
// Determine if all the checkboxes are checked
533
function are_all_checked(checkbox_panel_ref) {
534
	var allBoxesChecked = true;
535
	$(checkbox_panel_ref).each(function() {
536
		if ((this.type == 'checkbox') && !this.checked) {
537
			allBoxesChecked = false;
538
		}
539
	});
540
	return allBoxesChecked;
541
}
542
543
// If the checkboxes are all checked, then clear them all.
544
// Otherwise set them all.
545
function set_clear_checkboxes(checkbox_panel_ref) {
546
	checkTheBoxes = !are_all_checked(checkbox_panel_ref);
547
548
	$(checkbox_panel_ref).each(function() {
549
		$(this).prop("checked", checkTheBoxes);
550
	});
551
}
552
553
// Set the given id to All or None button depending if the checkboxes are all checked.
554
function set_all_none_button(checkbox_panel_ref, all_none_button_id) {
555
	if (are_all_checked(checkbox_panel_ref)) {
556
		text = "<?=gettext('None')?>";
557
	} else {
558
		text = "<?=gettext('All')?>";
559
	}
560
561
	$("#" + all_none_button_id).html('<i class="fa fa-undo icon-embed-btn"></i>' + text);
562
}
563
564
// Setup the necessary events to manage the All/None button and included checkboxes
565
// used for selecting the items to show on a widget.
566
function set_widget_checkbox_events(checkbox_panel_ref, all_none_button_id) {
567
		set_all_none_button(checkbox_panel_ref, all_none_button_id);
568
569
		$(checkbox_panel_ref).change(function() {
570
			set_all_none_button(checkbox_panel_ref, all_none_button_id);
571
		});
572
573
		$("#" + all_none_button_id).click(function() {
574
			set_clear_checkboxes(checkbox_panel_ref);
575
			set_all_none_button(checkbox_panel_ref, all_none_button_id);
576
		});
577
}
578
579 de5c66b5 Steve Beaver
// ---------------------Centralized widget refresh system -------------------------------------------
580 d7c2f4fe Steve Beaver
// These need to live outsie of the events.push() function to enable the widgets to see them
581 53547a05 Steve Beaver
var ajaxspecs = new Array();	// Array to hold widget refresh specifications (objects )
582 d7c2f4fe Steve Beaver
var ajaxidx = 0;
583
var ajaxmutex = false;
584 67dd6c11 Steve Beaver
var ajaxcntr = 0;
585 d7c2f4fe Steve Beaver
586
// Add a widget refresh object to the array list
587
function register_ajax(ws) {
588
  ajaxspecs.push(ws);
589
}
590
// ---------------------------------------------------------------------------------------------------
591 dc58b7b3 Sjon Hortensius
592 d7c2f4fe Steve Beaver
events.push(function() {
593 dc58b7b3 Sjon Hortensius
	// Make panels destroyable
594 aa82505e Phil Davis
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el) {
595
		$(el).on('click', function(e) {
596 7f8f8808 Sjon Hortensius
			$(el).parents('.panel').remove();
597
			updateWidgets();
598 eae6b58d Stephen Beaver
			// Submit the form save/display all selected widgets
599
			$('[name=widgetForm]').submit();
600 dc58b7b3 Sjon Hortensius
		})
601
	});
602
603
	// Make panels sortable
604 477db933 Jared Dillard
	$('.container .col-md-<?=$columnWidth?>').sortable({
605 dc58b7b3 Sjon Hortensius
		handle: '.panel-heading',
606
		cursor: 'grabbing',
607 477db933 Jared Dillard
		connectWith: '.container .col-md-<?=$columnWidth?>',
608 91d59881 NOYB
		update: function(){
609
			dirty = true;
610
			$('#btnstore').removeClass('invisible');
611
		}
612 dc58b7b3 Sjon Hortensius
	});
613 60e27eb0 Stephen Beaver
614
	// On clicking a widget to install . .
615 a508c6e4 NOYB
	$('[id^=btnadd-]').click(function(event) {
616 f4a15d29 Stephen Beaver
		// Add the widget name to the list of displayed widgets
617 a508c6e4 NOYB
		updateWidgets(this.id.replace('btnadd-', ''));
618 60e27eb0 Stephen Beaver
619
		// Submit the form save/display all selected widgets
620
		$('[name=widgetForm]').submit();
621
	});
622
623 eae6b58d Stephen Beaver
624 e94f260c Stephen Beaver
	$('#btnstore').click(function() {
625
		updateWidgets();
626
		dirty = false;
627 91d59881 NOYB
		$(this).addClass('invisible');
628 e94f260c Stephen Beaver
		$('[name=widgetForm]').submit();
629
	});
630 eae6b58d Stephen Beaver
631
	// provide a warning message if the user tries to change page before saving
632
	$(window).bind('beforeunload', function(){
633
		if (dirty) {
634 530c7ccf NOYB
			return ("<?=gettext('One or more widgets have been moved but have not yet been saved')?>");
635 eae6b58d Stephen Beaver
		} else {
636
			return undefined;
637
		}
638
	});
639 cee365e6 Stephen Beaver
640
	// 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)
641
	// (Sometimes this will cause us to see the icon when we don't need it, but better that than the other way round)
642
	$('.panel').on('hidden.bs.collapse shown.bs.collapse', function (e) {
643
	    if (e.currentTarget.id != 'widget-available') {
644
			$('#btnstore').removeClass("invisible");
645
		}
646
	});
647 d7c2f4fe Steve Beaver
648
	// --------------------- EXPERIMENTAL centralized widget refresh system ------------------------------
649
	function make_ajax_call(wd) {
650
		ajaxmutex = true;
651
652
		$.ajax({
653
			type: 'POST',
654
			url: wd.url,
655
			dataType: 'html',
656
			data: wd.parms,
657
658
			success: function(data){
659 352f422c Steve Beaver
				if (data.length > 0 ) {
660
					wd.callback(data);
661
				}
662
663 d7c2f4fe Steve Beaver
				ajaxmutex = false;
664
			},
665
666
			error: function(e){
667 8bf4cf1f Steve Beaver
//				alert("Error: " + e);
668 d7c2f4fe Steve Beaver
				ajaxmutex = false;
669
			}
670
		});
671
	}
672
673
	// Loop through each AJAX widget refresh object, make the AJAX call and pass the
674 53547a05 Steve Beaver
	// results back to the widget's callback function
675 d7c2f4fe Steve Beaver
	function executewidget() {
676
		if (ajaxspecs.length > 0) {
677 67dd6c11 Steve Beaver
			var freq = ajaxspecs[ajaxidx].freq;	// widget can specifify it should be called freq times around hte loop
678
679 d7c2f4fe Steve Beaver
			if (!ajaxmutex) {
680 e78d5940 Steve Beaver
				if (((ajaxcntr % freq) === 0) && (typeof ajaxspecs[ajaxidx].callback === "function" )) {
681 67dd6c11 Steve Beaver
				    make_ajax_call(ajaxspecs[ajaxidx]);
682
				}
683
684
			    if (++ajaxidx >= ajaxspecs.length) {
685
					ajaxidx = 0;
686
687
					if (++ajaxcntr >= 4096) {
688
						ajaxcntr = 0;
689
					}
690
			    }
691 d7c2f4fe Steve Beaver
			}
692
693 8bf4cf1f Steve Beaver
		    setTimeout(function() { executewidget(); }, 1000);
694 d7c2f4fe Steve Beaver
	  	}
695
	}
696
697
	// Kick it off
698
	executewidget();
699
700
	//----------------------------------------------------------------------------------------------------
701 dc58b7b3 Sjon Hortensius
});
702 8fd9052f Colin Fleming
//]]>
703 dc58b7b3 Sjon Hortensius
</script>
704 d7c2f4fe Steve Beaver
705 41ea4cf3 Sjon Hortensius
<?php
706 1180e4f0 Sjon Hortensius
//build list of javascript include files
707 aa82505e Phil Davis
foreach (glob('widgets/javascript/*.js') as $file) {
708 d8837d57 PiBa-NL
	$mtime = filemtime("/usr/local/www/{$file}");
709
	echo '<script src="'.$file.'?v='.$mtime.'"></script>';
710 aa82505e Phil Davis
}
711 927ea6e1 jim-p
712 1c428d53 Phil Davis
include("foot.inc");