Project

General

Profile

Download (22.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * index.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2019 Rubicon Communications, LLC (Netgate)
9
 * 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
 * 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
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * 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
 */
27

    
28
##|+PRIV
29
##|*IDENT=page-system-login-logout
30
##|*NAME=System: Login / Logout / Dashboard
31
##|*DESCR=Allow access to the 'System: Login / Logout' page and Dashboard.
32
##|*MATCH=index.php*
33
##|-PRIV
34

    
35
// Message to display if the session times out and an AJAX call is made
36
$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

    
39
// Turn on buffering to speed up rendering
40
ini_set('output_buffering', 'true');
41

    
42
// Start buffering with a cache size of 100000
43
ob_start(null, "1000");
44

    
45
## Load Essential Includes
46
require_once('guiconfig.inc');
47
require_once('functions.inc');
48
require_once('notices.inc');
49
require_once("pkg-utils.inc");
50

    
51
if (isset($_POST['closenotice'])) {
52
	close_notice($_POST['closenotice']);
53
	sleep(1);
54
	exit;
55
}
56

    
57
if (isset($_REQUEST['closenotice'])) {
58
	close_notice($_REQUEST['closenotice']);
59
	sleep(1);
60
}
61

    
62
if (($g['disablecrashreporter'] != true) && (system_has_crash_data() || system_has_php_errors())) {
63
	$savemsg = sprintf(gettext("%s has detected a crash report or programming bug."), $g['product_name']) . " ";
64
	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
	}
69
	$class = "warning";
70
}
71

    
72
## Include each widget php include file.
73
## These define vars that specify the widget title and title link.
74

    
75
$directory = "/usr/local/www/widgets/include/";
76
$dirhandle = opendir($directory);
77
$filename = "";
78

    
79
while (($filename = readdir($dirhandle)) !== false) {
80
	if (strtolower(substr($filename, -4)) == ".inc" && file_exists($directory . $filename)) {
81
		include_once($directory . $filename);
82
	}
83
}
84

    
85
##build list of widgets
86
foreach (glob("/usr/local/www/widgets/widgets/*.widget.php") as $file) {
87
	$basename = basename($file, '.widget.php');
88
	// Get the widget title that should be in a var defined in the widget's inc file.
89
	$widgettitle = ${$basename . '_title'};
90

    
91
	if (empty(trim($widgettitle))) {
92
		// Fall back to constructing a title from the file name of the widget.
93
		$widgettitle = ucwords(str_replace('_', ' ', $basename));
94
	}
95

    
96
	$known_widgets[$basename . '-0'] = array(
97
		'basename' => $basename,
98
		'title' => $widgettitle,
99
		'display' => 'none',
100
		'multicopy' => ${$basename . '_allow_multiple_widget_copies'}
101
	);
102
}
103

    
104
##if no config entry found, initialize config entry
105
if (!is_array($config['widgets'])) {
106
	$config['widgets'] = array();
107
}
108

    
109
if (!is_array($user_settings['widgets'])) {
110
	$user_settings['widgets'] = array();
111
}
112

    
113
if ($_POST && $_POST['sequence']) {
114

    
115
	// Start with the user's widget settings.
116
	$widget_settings = $user_settings['widgets'];
117

    
118
	$widget_sep = ',';
119
	$widget_seq_array = explode($widget_sep, rtrim($_POST['sequence'], $widget_sep));
120
	$widget_counter_array = array();
121
	$widget_sep = '';
122

    
123
	// 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
			if (!is_numeric($widget_counter)) {
129
				continue;
130
			}
131
			$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
		}
170
	}
171

    
172
	save_widget_settings($_SESSION['Username'], $widget_settings);
173
	header("Location: /");
174
	exit;
175
}
176

    
177
## Load Functions Files
178
require_once('includes/functions.inc.php');
179

    
180
## Check to see if we have a swap space,
181
## if true, display, if false, hide it ...
182
if (file_exists("/usr/sbin/swapinfo")) {
183
	$swapinfo = `/usr/sbin/swapinfo`;
184
	if (stristr($swapinfo, '%') == true) $showswap=true;
185
}
186

    
187
## If it is the first time webConfigurator has been
188
## accessed since initial install show this stuff.
189
if (file_exists('/conf/trigger_initial_wizard')) {
190
?>
191
<!DOCTYPE html>
192
<html lang="en">
193
	<head>
194
		<link rel="stylesheet" href="/css/pfSense.css" />
195
		<title><?=$g['product_name']?>.localdomain - <?=$g['product_name']?> first time setup</title>
196
		<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
					<p><h3><?=sprintf(gettext("Welcome to %s!") . "\n", $g['product_name'])?></h3></p>
204
					<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
					<p><?=sprintf(gettext("To bypass the wizard, click on the %s logo on the initial page."), $g['product_name'])?></p>
207
					</font>
208
				</div>
209
			</div>
210
		</div>
211
	</body>
212
</html>
213
<?php
214
	exit;
215
}
216

    
217
## Find out whether there's hardware encryption or not
218
unset($hwcrypto);
219
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
220
if ($fd) {
221
	while (!feof($fd)) {
222
		$dmesgl = fgets($fd);
223
		if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)
224
			or preg_match("/.*(VIA Padlock)/", $dmesgl, $matches)
225
			or preg_match("/^safe.: (\w.*)/", $dmesgl, $matches)
226
			or preg_match("/^ubsec.: (.*?),/", $dmesgl, $matches)
227
			or preg_match("/^padlock.: <(.*?)>,/", $dmesgl, $matches)) {
228
			$hwcrypto = $matches[1];
229
			break;
230
		}
231
	}
232
	fclose($fd);
233
	if (!isset($hwcrypto) && get_single_sysctl("dev.aesni.0.%desc")) {
234
		$hwcrypto = get_single_sysctl("dev.aesni.0.%desc");
235
	}
236
}
237

    
238
##build widget saved list information
239
if ($user_settings['widgets']['sequence'] != "") {
240
	$dashboardcolumns = isset($user_settings['webgui']['dashboardcolumns']) ? (int) $user_settings['webgui']['dashboardcolumns'] : 2;
241
	$pconfig['sequence'] = $user_settings['widgets']['sequence'];
242
	$widgetsfromconfig = array();
243

    
244
	foreach (explode(',', $pconfig['sequence']) as $line) {
245
		$line_items = explode(':', $line);
246
		if (count($line_items) == 3) {
247
			// There can be multiple copies of a widget on the dashboard.
248
			// Default the copy number if it is not present (e.g. from old configs)
249
			$line_items[] = 0;
250
		}
251

    
252
		list($basename, $col, $display, $copynum) = $line_items;
253
		if (!is_numeric($copynum)) {
254
			continue;
255
		}
256

    
257
		// be backwards compatible
258
		// If the display column information is missing, we will assign a temporary
259
		// column here. Next time the user saves the dashboard it will fix itself
260
		if ($col == "") {
261
			if ($basename == "system_information") {
262
				$col = "col1";
263
			} else {
264
				$col = "col2";
265
			}
266
		}
267

    
268
		// Limit the column to the current dashboard columns.
269
		if (substr($col, 3) > $dashboardcolumns) {
270
			$col = "col" . $dashboardcolumns;
271
		}
272

    
273
		$offset = strpos($basename, '-container');
274
		if (false !== $offset) {
275
			$basename = substr($basename, 0, $offset);
276
		}
277
		$widgetkey = $basename . '-' . $copynum;
278

    
279
		if (isset($user_settings['widgets'][$widgetkey]['descr'])) {
280
			$widgettitle = htmlentities($user_settings['widgets'][$widgetkey]['descr']);
281
		} else {
282
			// Get the widget title that should be in a var defined in the widget's inc file.
283
			$widgettitle = ${$basename . '_title'};
284

    
285
			if (empty(trim($widgettitle))) {
286
				// Fall back to constructing a title from the file name of the widget.
287
				$widgettitle = ucwords(str_replace('_', ' ', $basename));
288
			}
289
		}
290

    
291
		$widgetsfromconfig[$widgetkey] = array(
292
			'basename' => $basename,
293
			'title' => $widgettitle,
294
			'col' => $col,
295
			'display' => $display,
296
			'copynum' => $copynum,
297
			'multicopy' => ${$basename . '_allow_multiple_widget_copies'}
298
		);
299

    
300
		// Update the known_widgets entry so we know if any copy of the widget is being displayed
301
		$known_widgets[$basename . '-0']['display'] = $display;
302
	}
303

    
304
	// add widgets that may not be in the saved configuration, in case they are to be displayed later
305
	$widgets = $widgetsfromconfig + $known_widgets;
306

    
307
	##find custom configurations of a particular widget and load its info to $pconfig
308
	foreach ($widgets as $widgetname => $widgetconfig) {
309
		if ($config['widgets'][$widgetname . '-config']) {
310
			$pconfig[$widgetname . '-config'] = $config['widgets'][$widgetname . '-config'];
311
		}
312
	}
313
}
314

    
315
## Get the configured options for Show/Hide available widgets panel.
316
$dashboard_available_widgets_hidden = !$user_settings['webgui']['dashboardavailablewidgetspanel'];
317

    
318
if ($dashboard_available_widgets_hidden) {
319
	$panel_state = 'out';
320
	$panel_body_state = 'in';
321
} else {
322
	$panel_state = 'in';
323
	$panel_body_state = 'out';
324
}
325

    
326
## Set Page Title and Include Header
327
$pgtitle = array(gettext("Status"), gettext("Dashboard"));
328
include("head.inc");
329

    
330
if ($savemsg) {
331
	print_info_box($savemsg, $class);
332
}
333

    
334
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
335

    
336
?>
337

    
338
<div class="panel panel-default collapse <?=$panel_state?>" id="widget-available">
339
	<div class="panel-heading">
340
		<h2 class="panel-title"><?=gettext("Available Widgets"); ?>
341
			<span class="widget-heading-icon">
342
				<a data-toggle="collapse" href="#widget-available_panel-body" id="widgets-available">
343
					<i class="fa fa-plus-circle"></i>
344
				</a>
345
			</span>
346
		</h2>
347
	</div>
348
	<div id="widget-available_panel-body" class="panel-body collapse <?=$panel_body_state?>">
349
		<div class="content">
350
			<div class="row">
351
<?php
352

    
353
// Build the Available Widgets table using a sorted copy of the $known_widgets array
354
$available = $known_widgets;
355
uasort($available, function($a, $b){ return strcasecmp($a['title'], $b['title']); });
356

    
357
foreach ($available as $widgetkey => $widgetconfig):
358
	// If the widget supports multiple copies, or no copies are displayed yet, then it is available to add
359
	if (($widgetconfig['multicopy']) || ($widgetconfig['display'] == 'none')):
360
?>
361
		<div class="col-sm-3"><a href="#" id="btnadd-<?=$widgetconfig['basename']?>"><i class="fa fa-plus"></i> <?=$widgetconfig['title']?></a></div>
362
	<?php endif; ?>
363
<?php
364
endforeach;
365
?>
366
			</div>
367
<p style="text-align:center"><?=sprintf(gettext('Other dashboard settings are available from the <a href="%s">General Setup</a> page.'), '/system.php')?></p>
368
		</div>
369
	</div>
370
</div>
371

    
372
<div class="hidden" id="widgetSequence">
373
	<form action="/" method="post" id="widgetSequence_form" name="widgetForm">
374
		<input type="hidden" name="sequence" value="" />
375
	</form>
376
</div>
377

    
378
<?php
379
$widgetColumns = array();
380
foreach ($widgets as $widgetkey => $widgetconfig) {
381
	if ($widgetconfig['display'] != 'none' && file_exists("/usr/local/www/widgets/widgets/{$widgetconfig['basename']}.widget.php")) {
382
		if (!isset($widgetColumns[$widgetconfig['col']])) {
383
			$widgetColumns[$widgetconfig['col']] = array();
384
		}
385
		$widgetColumns[$widgetconfig['col']][$widgetkey] = $widgetconfig;
386
	}
387
}
388
?>
389

    
390
<div class="row">
391
<?php
392
	$columnWidth = (int) (12 / $numColumns);
393

    
394
	for ($currentColumnNumber = 1; $currentColumnNumber <= $numColumns; $currentColumnNumber++) {
395

    
396

    
397
		//if col$currentColumnNumber exists
398
		if (isset($widgetColumns['col'.$currentColumnNumber])) {
399
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '">';
400
			$columnWidgets = $widgetColumns['col'.$currentColumnNumber];
401

    
402
			foreach ($columnWidgets as $widgetkey => $widgetconfig) {
403
				// Construct some standard names for the ids this widget will use for its commonly-used elements.
404
				// Included widget.php code can rely on and use these, so the format does not have to be repeated in every widget.php
405
				$widget_panel_body_id = 'widget-' . $widgetkey . '_panel-body';
406
				$widget_panel_footer_id = 'widget-' . $widgetkey . '_panel-footer';
407
				$widget_showallnone_id = 'widget-' . $widgetkey . '_showallnone';
408

    
409
				// Compose the widget title and include the title link if available
410
				$widgetlink = ${$widgetconfig['basename'] . '_title_link'};
411

    
412
				if ((strlen($widgetlink) > 0)) {
413
					$wtitle = '<a href="' . $widgetlink . '"> ' . $widgetconfig['title'] . '</a>';
414
				} else {
415
					$wtitle = $widgetconfig['title'];
416
				}
417
				?>
418
				<div class="panel panel-default" id="widget-<?=$widgetkey?>">
419
					<div class="panel-heading">
420
						<h2 class="panel-title">
421
							<?=$wtitle?>
422
							<span class="widget-heading-icon">
423
								<a data-toggle="collapse" href="#<?=$widget_panel_footer_id?>" class="config hidden">
424
									<i class="fa fa-wrench"></i>
425
								</a>
426
								<a data-toggle="collapse" href="#<?=$widget_panel_body_id?>">
427
									<!--  actual icon is determined in css based on state of body -->
428
									<i class="fa fa-plus-circle"></i>
429
								</a>
430
								<a data-toggle="close" href="#widget-<?=$widgetkey?>">
431
									<i class="fa fa-times-circle"></i>
432
								</a>
433
							</span>
434
						</h2>
435
					</div>
436
					<div id="<?=$widget_panel_body_id?>" class="panel-body collapse<?=($widgetconfig['display'] == 'close' ? '' : ' in')?>">
437
						<?php
438
							// For backward compatibility, included *.widget.php code needs the var $widgetname
439
							$widgetname = $widgetkey;
440
							// Determine if this is the first instance of this particular widget.
441
							// Provide the $widget_first_instance var, to make it easy for the included widget code
442
							// to be able to know if it is being included for the first time.
443
							if ($widgets_found[$widgetconfig['basename']]) {
444
								$widget_first_instance = false;
445
							} else {
446
								$widget_first_instance = true;
447
								$widgets_found[$widgetconfig['basename']] = true;
448
							}
449
							include('/usr/local/www/widgets/widgets/' . $widgetconfig['basename'] . '.widget.php');
450
						?>
451
					</div>
452
				</div>
453
				<?php
454
			}
455
			echo "</div>";
456
		} else {
457
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '"></div>';
458
		}
459

    
460
	}
461
?>
462

    
463
</div>
464

    
465
<?php
466
/*
467
 * Import the modal form used to display the copyright/usage information
468
 * when trigger file exists. Trigger file is created during upgrade process
469
 * when /etc/version changes
470
 */
471
require_once("copyget.inc");
472

    
473
if (file_exists("{$g['cf_conf_path']}/copynotice_display")) {
474
	require_once("copynotice.inc");
475
	@unlink("{$g['cf_conf_path']}/copynotice_display");
476
}
477

    
478
/*
479
 * Import the modal form used to display any HTML text a package may want to display
480
 * on installation or removal
481
 */
482
$ui_notice = "/tmp/package_ui_notice";
483
if (file_exists($ui_notice)) {
484
	require_once("{$g['www_path']}/upgrnotice.inc");
485
}
486
?>
487

    
488
<script type="text/javascript">
489
//<![CDATA[
490

    
491
dirty = false;
492
function updateWidgets(newWidget) {
493
	var sequence = '';
494

    
495
	$('.container .col-md-<?=$columnWidth?>').each(function(idx, col) {
496
		$('.panel', col).each(function(idx, widget) {
497
			var isOpen = $('.panel-body', widget).hasClass('in');
498
			var widget_basename = widget.id.split('-')[1];
499

    
500
			// Only save details for panels that have id's like'widget-*'
501
			// Some widgets create other panels, so ignore any of those.
502
			if ((widget.id.split('-')[0] == 'widget') && (typeof widget_basename !== 'undefined')) {
503
				sequence += widget_basename + ':' + col.id.split('-')[1] + ':' + (isOpen ? 'open' : 'close') + ':' + widget.id.split('-')[2] + ',';
504
			}
505
		});
506
	});
507

    
508
	if (typeof newWidget !== 'undefined') {
509
		// The system_information widget is always added to column one. Others go in column two
510
		if (newWidget == "system_information") {
511
			sequence += newWidget.split('-')[0] + ':' + 'col1:open:next';
512
		} else {
513
			sequence += newWidget.split('-')[0] + ':' + 'col2:open:next';
514
		}
515
	}
516

    
517
	$('input[name=sequence]', $('#widgetSequence_form')).val(sequence);
518
}
519

    
520
// Determine if all the checkboxes are checked
521
function are_all_checked(checkbox_panel_ref) {
522
	var allBoxesChecked = true;
523
	$(checkbox_panel_ref).each(function() {
524
		if ((this.type == 'checkbox') && !this.checked) {
525
			allBoxesChecked = false;
526
		}
527
	});
528
	return allBoxesChecked;
529
}
530

    
531
// If the checkboxes are all checked, then clear them all.
532
// Otherwise set them all.
533
function set_clear_checkboxes(checkbox_panel_ref) {
534
	checkTheBoxes = !are_all_checked(checkbox_panel_ref);
535

    
536
	$(checkbox_panel_ref).each(function() {
537
		$(this).prop("checked", checkTheBoxes);
538
	});
539
}
540

    
541
// Set the given id to All or None button depending if the checkboxes are all checked.
542
function set_all_none_button(checkbox_panel_ref, all_none_button_id) {
543
	if (are_all_checked(checkbox_panel_ref)) {
544
		text = "<?=gettext('None')?>";
545
	} else {
546
		text = "<?=gettext('All')?>";
547
	}
548

    
549
	$("#" + all_none_button_id).html('<i class="fa fa-undo icon-embed-btn"></i>' + text);
550
}
551

    
552
// Setup the necessary events to manage the All/None button and included checkboxes
553
// used for selecting the items to show on a widget.
554
function set_widget_checkbox_events(checkbox_panel_ref, all_none_button_id) {
555
		set_all_none_button(checkbox_panel_ref, all_none_button_id);
556

    
557
		$(checkbox_panel_ref).change(function() {
558
			set_all_none_button(checkbox_panel_ref, all_none_button_id);
559
		});
560

    
561
		$("#" + all_none_button_id).click(function() {
562
			set_clear_checkboxes(checkbox_panel_ref);
563
			set_all_none_button(checkbox_panel_ref, all_none_button_id);
564
		});
565
}
566

    
567
// ---------------------Centralized widget refresh system -------------------------------------------
568
// These need to live outside of the events.push() function to enable the widgets to see them
569
var ajaxspecs = new Array();	// Array to hold widget refresh specifications (objects )
570
var ajaxidx = 0;
571
var ajaxmutex = false;
572
var ajaxcntr = 0;
573

    
574
// Add a widget refresh object to the array list
575
function register_ajax(ws) {
576
  ajaxspecs.push(ws);
577
}
578
// ---------------------------------------------------------------------------------------------------
579

    
580
events.push(function() {
581
	// Make panels destroyable
582
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el) {
583
		$(el).on('click', function(e) {
584
			$(el).parents('.panel').remove();
585
			updateWidgets();
586
			// Submit the form save/display all selected widgets
587
			$('[name=widgetForm]').submit();
588
		})
589
	});
590

    
591
	// Make panels sortable
592
	$('.container .col-md-<?=$columnWidth?>').sortable({
593
		handle: '.panel-heading',
594
		cursor: 'grabbing',
595
		connectWith: '.container .col-md-<?=$columnWidth?>',
596
		update: function(){
597
			dirty = true;
598
			$('#btnstore').removeClass('invisible');
599
		}
600
	});
601

    
602
	// On clicking a widget to install . .
603
	$('[id^=btnadd-]').click(function(event) {
604
		// Add the widget name to the list of displayed widgets
605
		updateWidgets(this.id.replace('btnadd-', ''));
606

    
607
		// Submit the form save/display all selected widgets
608
		$('[name=widgetForm]').submit();
609
	});
610

    
611

    
612
	$('#btnstore').click(function() {
613
		updateWidgets();
614
		dirty = false;
615
		$(this).addClass('invisible');
616
		$('[name=widgetForm]').submit();
617
	});
618

    
619
	// provide a warning message if the user tries to change page before saving
620
	$(window).bind('beforeunload', function(){
621
		if (dirty) {
622
			return ("<?=gettext('One or more widgets have been moved but have not yet been saved')?>");
623
		} else {
624
			return undefined;
625
		}
626
	});
627

    
628
	// 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)
629
	// (Sometimes this will cause us to see the icon when we don't need it, but better that than the other way round)
630
	$('.panel').on('hidden.bs.collapse shown.bs.collapse', function (e) {
631
	    if (e.currentTarget.id != 'widget-available') {
632
			$('#btnstore').removeClass("invisible");
633
		}
634
	});
635

    
636
	// --------------------- Centralized widget refresh system ------------------------------
637
	ajaxtimeout = false;
638

    
639
	function make_ajax_call(wd) {
640
		ajaxmutex = true;
641

    
642
		$.ajax({
643
			type: 'POST',
644
			url: wd.url,
645
			dataType: 'html',
646
			data: wd.parms,
647

    
648
			success: function(data){
649
				if (data.length > 0 ) {
650
					// If the session has timed out, display a pop-up
651
					if (data.indexOf("SESSION_TIMEOUT") === -1) {
652
						wd.callback(data);
653
					} else {
654
						if (ajaxtimeout === false) {
655
							ajaxtimeout = true;
656
							alert("<?=$timeoutmessage?>");
657
						}
658
					}
659
				}
660

    
661
				ajaxmutex = false;
662
			},
663

    
664
			error: function(e){
665
//				alert("Error: " + e);
666
				ajaxmutex = false;
667
			}
668
		});
669
	}
670

    
671
	// Loop through each AJAX widget refresh object, make the AJAX call and pass the
672
	// results back to the widget's callback function
673
	function executewidget() {
674
		if (ajaxspecs.length > 0) {
675
			var freq = ajaxspecs[ajaxidx].freq;	// widget can specify it should be called freq times around the loop
676

    
677
			if (!ajaxmutex) {
678
				if (((ajaxcntr % freq) === 0) && (typeof ajaxspecs[ajaxidx].callback === "function" )) {
679
				    make_ajax_call(ajaxspecs[ajaxidx]);
680
				}
681

    
682
			    if (++ajaxidx >= ajaxspecs.length) {
683
					ajaxidx = 0;
684

    
685
					if (++ajaxcntr >= 4096) {
686
						ajaxcntr = 0;
687
					}
688
			    }
689
			}
690

    
691
		    setTimeout(function() { executewidget(); }, 1000);
692
	  	}
693
	}
694

    
695
	// Kick it off
696
	executewidget();
697

    
698
	//----------------------------------------------------------------------------------------------------
699
});
700
//]]>
701
</script>
702

    
703
<?php
704
//build list of javascript include files
705
foreach (glob('widgets/javascript/*.js') as $file) {
706
	$mtime = filemtime("/usr/local/www/{$file}");
707
	echo '<script src="'.$file.'?v='.$mtime.'"></script>';
708
}
709

    
710
include("foot.inc");
(71-71/227)