Project

General

Profile

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