Project

General

Profile

Download (21.7 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-2025 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_get('disablecrashreporter') != true) && (system_has_crash_data() || system_has_php_errors())) {
63
	$savemsg = sprintf(gettext("%s has detected a crash report or programming bug."), g_get('product_label')) . " ";
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

    
106
if (!is_array($user_settings['widgets'])) {
107
	$user_settings['widgets'] = array();
108
}
109

    
110
if ($_POST && $_POST['sequence']) {
111

    
112
	// Start with the user's widget settings.
113
	$widget_settings = $user_settings['widgets'];
114

    
115
	$widget_sep = ',';
116
	$widget_seq_array = explode($widget_sep, rtrim($_POST['sequence'], $widget_sep));
117
	$widget_counter_array = array();
118
	$widget_sep = '';
119

    
120
	// Make a record of the counter of each widget that is in use.
121
	foreach ($widget_seq_array as $widget_seq_data) {
122
		list($basename, $col, $display, $widget_counter) = explode(':', $widget_seq_data);
123

    
124
		if ($widget_counter != 'next') {
125
			if (!is_numeric($widget_counter)) {
126
				continue;
127
			}
128
			$widget_counter_array[$basename][$widget_counter] = true;
129
			$widget_sequence .= $widget_sep . $widget_seq_data;
130
			$widget_sep = ',';
131
		}
132
	}
133

    
134
	// Find any new entry (and do not assume there is only 1 new entry)
135
	foreach ($widget_seq_array as $widget_seq_data) {
136
		list($basename, $col, $display, $widget_counter) = explode(':', $widget_seq_data);
137

    
138
		if ($widget_counter == 'next') {
139
			// Construct the widget counter of the new widget instance by finding
140
			// the first non-negative integer that is not in use.
141
			// The reasoning here is that if you just deleted a widget instance,
142
			// e.g. had System Information 0,1,2 and deleted 1,
143
			// then when you add System Information again it will become instance 1,
144
			// which will bring back whatever filter selections happened to be on
145
			// the previous instance 1.
146
			$instance_num = 0;
147

    
148
			while (isset($widget_counter_array[$basename][$instance_num])) {
149
				$instance_num++;
150
			}
151

    
152
			$widget_sequence .= $widget_sep . $basename . ':' . $col . ':' . $display . ':' . $instance_num;
153
			$widget_counter_array[$basename][$instance_num] = true;
154
			$widget_sep = ',';
155
		}
156
	}
157

    
158
	$widget_settings['sequence'] = $widget_sequence;
159

    
160
	foreach ($widget_counter_array as $basename => $instances) {
161
		foreach ($instances as $instance => $value) {
162
			$widgetconfigname = $basename . '-' . $instance . '-config';
163
			if ($_POST[$widgetconfigname]) {
164
				$widget_settings[$widgetconfigname] = $_POST[$widgetconfigname];
165
			}
166
		}
167
	}
168

    
169
	save_widget_settings($_SESSION['Username'], $widget_settings);
170
	header("Location: /");
171
	exit;
172
}
173

    
174
## Load Functions Files
175
require_once('includes/functions.inc.php');
176

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

    
184
## If it is the first time webConfigurator has been
185
## accessed since initial install show this stuff.
186
if (file_exists('/conf/trigger_initial_wizard')) {
187
?>
188
<!DOCTYPE html>
189
<html lang="en">
190
	<head>
191
		<link rel="stylesheet" href="/css/pfSense.css" />
192
		<title><?=g_get('product_label')?>.home.arpa - <?=g_get('product_label')?> first time setup</title>
193
		<meta http-equiv="refresh" content="1;url=wizard.php?xml=setup_wizard.xml" />
194
	</head>
195
	<body id="loading-wizard" class="no-menu">
196
		<div id="jumbotron">
197
			<div class="container">
198
				<div class="col-sm-offset-3 col-sm-6 col-xs-12">
199
					<font color="white">
200
					<p><h3><?=sprintf(gettext("Welcome to %s!") . "\n", g_get('product_label'))?></h3></p>
201
					<p><?=gettext("One moment while the initial setup wizard starts.")?></p>
202
					<p><?=gettext("Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal GUI.")?></p>
203
					<p><?=sprintf(gettext("To bypass the wizard, click on the %s logo on the initial page."), g_get('product_label'))?></p>
204
					</font>
205
				</div>
206
			</div>
207
		</div>
208
	</body>
209
</html>
210
<?php
211
	exit;
212
}
213

    
214
##build widget saved list information
215
if ($user_settings['widgets']['sequence'] != "") {
216
	$dashboardcolumns = isset($user_settings['webgui']['dashboardcolumns']) ? (int) $user_settings['webgui']['dashboardcolumns'] : 2;
217
	$pconfig['sequence'] = $user_settings['widgets']['sequence'];
218
	$widgetsfromconfig = array();
219

    
220
	foreach (explode(',', $pconfig['sequence']) as $line) {
221
		$line_items = explode(':', $line);
222
		if (count($line_items) == 3) {
223
			// There can be multiple copies of a widget on the dashboard.
224
			// Default the copy number if it is not present (e.g. from old configs)
225
			$line_items[] = 0;
226
		}
227

    
228
		list($basename, $col, $display, $copynum) = $line_items;
229
		if (!is_numeric($copynum)) {
230
			continue;
231
		}
232

    
233
		// be backwards compatible
234
		// If the display column information is missing, we will assign a temporary
235
		// column here. Next time the user saves the dashboard it will fix itself
236
		if ($col == "") {
237
			if ($basename == "system_information") {
238
				$col = "col1";
239
			} else {
240
				$col = "col2";
241
			}
242
		}
243

    
244
		// Limit the column to the current dashboard columns.
245
		if (substr($col, 3) > $dashboardcolumns) {
246
			$col = "col" . $dashboardcolumns;
247
		}
248

    
249
		$offset = strpos($basename, '-container');
250
		if (false !== $offset) {
251
			$basename = substr($basename, 0, $offset);
252
		}
253
		$widgetkey = $basename . '-' . $copynum;
254

    
255
		if (isset($user_settings['widgets'][$widgetkey]['descr'])) {
256
			$widgettitle = htmlentities($user_settings['widgets'][$widgetkey]['descr']);
257
		} else {
258
			// Get the widget title that should be in a var defined in the widget's inc file.
259
			$widgettitle = ${$basename . '_title'};
260

    
261
			if (empty(trim($widgettitle))) {
262
				// Fall back to constructing a title from the file name of the widget.
263
				$widgettitle = ucwords(str_replace('_', ' ', $basename));
264
			}
265
		}
266

    
267
		$widgetsfromconfig[$widgetkey] = array(
268
			'basename' => $basename,
269
			'title' => $widgettitle,
270
			'col' => $col,
271
			'display' => $display,
272
			'copynum' => $copynum,
273
			'multicopy' => ${$basename . '_allow_multiple_widget_copies'}
274
		);
275

    
276
		// Update the known_widgets entry so we know if any copy of the widget is being displayed
277
		$known_widgets[$basename . '-0']['display'] = $display;
278
	}
279

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

    
283
	##find custom configurations of a particular widget and load its info to $pconfig
284
	$widgets_config = config_get_path('widgets', []);
285
	foreach ($widgets as $widgetname => $widgetconfig) {
286
		if ($widgets_config["{$widgetname}-config"]) {
287
			$pconfig["{$widgetname}-config"] = $widgets_config["{$widgetname}-config"];
288
		}
289
	}
290
}
291

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

    
295
if ($dashboard_available_widgets_hidden) {
296
	$panel_state = 'out';
297
	$panel_body_state = 'in';
298
} else {
299
	$panel_state = 'in';
300
	$panel_body_state = 'out';
301
}
302

    
303
## Set Page Title and Include Header
304
$pgtitle = array(gettext("Status"), gettext("Dashboard"));
305
include("head.inc");
306

    
307
if ($savemsg) {
308
	print_info_box($savemsg, $class);
309
}
310

    
311
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
312

    
313
?>
314

    
315
<div class="panel panel-default collapse <?=$panel_state?>" id="widget-available">
316
	<div class="panel-heading">
317
		<h2 class="panel-title"><?=gettext("Available Widgets"); ?>
318
			<span class="widget-heading-icon">
319
				<a data-toggle="collapse" href="#widget-available_panel-body" id="widgets-available">
320
					<i class="fa-solid fa-plus-circle"></i>
321
				</a>
322
			</span>
323
		</h2>
324
	</div>
325
	<div id="widget-available_panel-body" class="panel-body collapse <?=$panel_body_state?>">
326
		<div class="content">
327
			<div class="row">
328
<?php
329

    
330
// Build the Available Widgets table using a sorted copy of the $known_widgets array
331
$available = $known_widgets;
332
uasort($available, function($a, $b){ return strcasecmp($a['title'], $b['title']); });
333

    
334
foreach ($available as $widgetconfig):
335
	// If the widget supports multiple copies, or no copies are displayed yet, then it is available to add
336
	if (($widgetconfig['multicopy']) || ($widgetconfig['display'] == 'none')):
337
?>
338
		<div class="col-sm-3"><a href="#" id="btnadd-<?=$widgetconfig['basename']?>"><i class="fa-solid fa-plus"></i> <?=$widgetconfig['title']?></a></div>
339
	<?php endif; ?>
340
<?php
341
endforeach;
342
?>
343
			</div>
344
<p style="text-align:center"><?=sprintf(gettext('Other dashboard settings are available from the <a href="%s">General Setup</a> page.'), '/system.php')?></p>
345
		</div>
346
	</div>
347
</div>
348

    
349
<div class="hidden" id="widgetSequence">
350
	<form action="/" method="post" id="widgetSequence_form" name="widgetForm">
351
		<input type="hidden" name="sequence" value="" />
352
	</form>
353
</div>
354

    
355
<?php
356
$widgets_found = [];
357
$widgetColumns = array();
358
foreach ($widgets as $widgetkey => $widgetconfig) {
359
	if ($widgetconfig['display'] != 'none' && file_exists("/usr/local/www/widgets/widgets/{$widgetconfig['basename']}.widget.php")) {
360
		if (!isset($widgetColumns[$widgetconfig['col']])) {
361
			$widgetColumns[$widgetconfig['col']] = array();
362
		}
363
		$widgetColumns[$widgetconfig['col']][$widgetkey] = $widgetconfig;
364
	}
365
}
366
?>
367

    
368
<div class="row">
369
<?php
370
	$columnWidth = (int) (12 / $numColumns);
371

    
372
	for ($currentColumnNumber = 1; $currentColumnNumber <= $numColumns; $currentColumnNumber++) {
373

    
374

    
375
		//if col$currentColumnNumber exists
376
		if (isset($widgetColumns['col'.$currentColumnNumber])) {
377
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '">';
378
			$columnWidgets = $widgetColumns['col'.$currentColumnNumber];
379

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

    
387
				// Compose the widget title and include the title link if available
388
				$widgetlink = ${$widgetconfig['basename'] . '_title_link'};
389

    
390
				if ((strlen($widgetlink) > 0)) {
391
					$wtitle = '<a href="' . $widgetlink . '"> ' . $widgetconfig['title'] . '</a>';
392
				} else {
393
					$wtitle = $widgetconfig['title'];
394
				}
395
				?>
396
				<div class="panel panel-default" id="widget-<?=$widgetkey?>">
397
					<div class="panel-heading">
398
						<h2 class="panel-title">
399
							<?=$wtitle?>
400
							<span class="widget-heading-icon">
401
								<a data-toggle="collapse" href="#<?=$widget_panel_footer_id?>" class="config hidden">
402
									<i class="fa-solid fa-wrench"></i>
403
								</a>
404
								<a data-toggle="collapse" href="#<?=$widget_panel_body_id?>">
405
									<!--  actual icon is determined in css based on state of body -->
406
									<i class="fa-solid fa-plus-circle"></i>
407
								</a>
408
								<a data-toggle="close" href="#widget-<?=$widgetkey?>">
409
									<i class="fa-solid fa-times-circle"></i>
410
								</a>
411
							</span>
412
						</h2>
413
					</div>
414
					<div id="<?=$widget_panel_body_id?>" class="panel-body collapse<?=($widgetconfig['display'] == 'close' ? '' : ' in')?>">
415
						<?php
416
							// For backward compatibility, included *.widget.php code needs the var $widgetname
417
							$widgetname = $widgetkey;
418
							// Determine if this is the first instance of this particular widget.
419
							// Provide the $widget_first_instance var, to make it easy for the included widget code
420
							// to be able to know if it is being included for the first time.
421
							if ($widgets_found[$widgetconfig['basename']]) {
422
								$widget_first_instance = false;
423
							} else {
424
								$widget_first_instance = true;
425
								$widgets_found[$widgetconfig['basename']] = true;
426
							}
427
							include('/usr/local/www/widgets/widgets/' . $widgetconfig['basename'] . '.widget.php');
428
						?>
429
					</div>
430
				</div>
431
				<?php
432
			}
433
			echo "</div>";
434
		} else {
435
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '"></div>';
436
		}
437

    
438
	}
439
?>
440

    
441
</div>
442

    
443
<?php
444
/*
445
 * Import the modal form used to display the copyright/usage information
446
 * when trigger file exists. Trigger file is created during upgrade process
447
 * when /etc/version changes
448
 */
449
require_once("copyget.inc");
450

    
451
if (file_exists("{$g['cf_conf_path']}/copynotice_display")) {
452
	require_once("copynotice.inc");
453
	@unlink("{$g['cf_conf_path']}/copynotice_display");
454
}
455

    
456
/*
457
 * Import the modal form used to display any HTML text a package may want to display
458
 * on installation or removal
459
 */
460
$ui_notice = "/tmp/package_ui_notice";
461
if (file_exists($ui_notice)) {
462
	require_once("{$g['www_path']}/upgrnotice.inc");
463
}
464
?>
465

    
466
<script type="text/javascript">
467
//<![CDATA[
468

    
469
dirty = false;
470
function updateWidgets(newWidget) {
471
	var sequence = '';
472

    
473
	$('.container .col-md-<?=$columnWidth?>').each(function(idx, col) {
474
		$('.panel', col).each(function(idx, widget) {
475
			var isOpen = $('.panel-body', widget).hasClass('in');
476
			var widget_basename = widget.id.split('-')[1];
477

    
478
			// Only save details for panels that have id's like 'widget-*'
479
			// Some widgets create other panels, so ignore any of those.
480
			if ((widget.id.split('-')[0] == 'widget') && (typeof widget_basename !== 'undefined')) {
481
				sequence += widget_basename + ':' + col.id.split('-')[1] + ':' + (isOpen ? 'open' : 'close') + ':' + widget.id.split('-')[2] + ',';
482
			}
483
		});
484
	});
485

    
486
	if (typeof newWidget !== 'undefined') {
487
		// The system_information widget is always added to column one. Others go in column two
488
		if (newWidget == "system_information") {
489
			sequence += newWidget.split('-')[0] + ':' + 'col1:open:next';
490
		} else {
491
			sequence += newWidget.split('-')[0] + ':' + 'col2:open:next';
492
		}
493
	}
494

    
495
	$('input[name=sequence]', $('#widgetSequence_form')).val(sequence);
496
}
497

    
498
// Determine if all the checkboxes are checked
499
function are_all_checked(checkbox_panel_ref) {
500
	var allBoxesChecked = true;
501
	$(checkbox_panel_ref).each(function() {
502
		if ((this.type == 'checkbox') && !this.checked) {
503
			allBoxesChecked = false;
504
		}
505
	});
506
	return allBoxesChecked;
507
}
508

    
509
// If the checkboxes are all checked, then clear them all.
510
// Otherwise set them all.
511
function set_clear_checkboxes(checkbox_panel_ref) {
512
	checkTheBoxes = !are_all_checked(checkbox_panel_ref);
513

    
514
	$(checkbox_panel_ref).each(function() {
515
		$(this).prop("checked", checkTheBoxes);
516
	});
517
}
518

    
519
// Set the given id to All or None button depending if the checkboxes are all checked.
520
function set_all_none_button(checkbox_panel_ref, all_none_button_id) {
521
	if (are_all_checked(checkbox_panel_ref)) {
522
		text = "<?=gettext('None')?>";
523
	} else {
524
		text = "<?=gettext('All')?>";
525
	}
526

    
527
	$("#" + all_none_button_id).html('<i class="fa-solid fa-undo icon-embed-btn"></i>' + text);
528
}
529

    
530
// Setup the necessary events to manage the All/None button and included checkboxes
531
// used for selecting the items to show on a widget.
532
function set_widget_checkbox_events(checkbox_panel_ref, all_none_button_id) {
533
		set_all_none_button(checkbox_panel_ref, all_none_button_id);
534

    
535
		$(checkbox_panel_ref).change(function() {
536
			set_all_none_button(checkbox_panel_ref, all_none_button_id);
537
		});
538

    
539
		$("#" + all_none_button_id).click(function() {
540
			set_clear_checkboxes(checkbox_panel_ref);
541
			set_all_none_button(checkbox_panel_ref, all_none_button_id);
542
		});
543
}
544

    
545
// ---------------------Centralized widget refresh system -------------------------------------------
546
// These need to live outside of the events.push() function to enable the widgets to see them
547
var ajaxspecs = new Array();	// Array to hold widget refresh specifications (objects )
548
var ajaxcntr = 0;
549

    
550
// Add a widget refresh object to the array list
551
function register_ajax(ws) {
552
  ajaxspecs.push(ws);
553
}
554
// ---------------------------------------------------------------------------------------------------
555

    
556
events.push(function() {
557
	// Make panels destroyable
558
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el) {
559
		$(el).on('click', function(e) {
560
			$(el).parents('.panel').remove();
561
			updateWidgets();
562
			// Submit the form save/display all selected widgets
563
			$('[name=widgetForm]').submit();
564
		})
565
	});
566

    
567
	// Make panels sortable
568
	$('.container .col-md-<?=$columnWidth?>').sortable({
569
		handle: '.panel-heading',
570
		cursor: 'grabbing',
571
		connectWith: '.container .col-md-<?=$columnWidth?>',
572
		update: function(){
573
			dirty = true;
574
			$('#btnstore').removeClass('invisible');
575
		}
576
	});
577

    
578
	// On clicking a widget to install . .
579
	$('[id^=btnadd-]').click(function(event) {
580
		// Add the widget name to the list of displayed widgets
581
		updateWidgets(this.id.replace('btnadd-', ''));
582

    
583
		// Submit the form save/display all selected widgets
584
		$('[name=widgetForm]').submit();
585
	});
586

    
587

    
588
	$('#btnstore').click(function() {
589
		updateWidgets();
590
		dirty = false;
591
		$(this).addClass('invisible');
592
		$('[name=widgetForm]').submit();
593
	});
594

    
595
	// provide a warning message if the user tries to change page before saving
596
	$(window).bind('beforeunload', function(){
597
		if (dirty) {
598
			return ("<?=gettext('One or more widgets have been moved but have not yet been saved')?>");
599
		} else {
600
			return undefined;
601
		}
602
	});
603

    
604
	// 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)
605
	// (Sometimes this will cause us to see the icon when we don't need it, but better that than the other way round)
606
	$('.panel').on('hidden.bs.collapse shown.bs.collapse', function (e) {
607
	    if (e.currentTarget.id != 'widget-available') {
608
			$('#btnstore').removeClass("invisible");
609
		}
610
	});
611

    
612
	// --------------------- Centralized widget refresh system ------------------------------
613
	ajaxtimeout = false;
614

    
615
	function make_ajax_call(wd) {
616
		$.ajax({
617
			type: 'POST',
618
			url: wd.url,
619
			dataType: 'html',
620
			data: wd.parms,
621

    
622
			success: function(data){
623
				if (data.length > 0 ) {
624
					// If the session has timed out, display a pop-up
625
					if (data.indexOf("SESSION_TIMEOUT") === -1) {
626
						wd.callback(data);
627
					} else {
628
						if (ajaxtimeout === false) {
629
							ajaxtimeout = true;
630
							alert("<?=$timeoutmessage?>");
631
						}
632
					}
633
				}
634

    
635
			},
636

    
637
			error: function(e){
638
				console.log("Error: " + e);
639
			}
640
		});
641
	}
642

    
643
	function execute_ajax_call(item){
644
		if ((ajaxcntr % item.freq) === 0) {
645
			make_ajax_call(item);
646
		}
647
	}
648

    
649
	// Loop through each AJAX widget refresh object, make the AJAX call and pass the
650
	// results back to the widget's callback function
651
	function executewidget() {
652
		ajaxspecs.forEach(execute_ajax_call);
653

    
654
		if (++ajaxcntr >= 4096) {
655
			ajaxcntr = 0;
656
		}
657

    
658
		setTimeout(function() { executewidget(); }, 1000);
659
	}
660

    
661
	// Kick it off
662
	executewidget();
663

    
664
	//----------------------------------------------------------------------------------------------------
665
});
666
//]]>
667
</script>
668

    
669
<?php
670
//build list of javascript include files
671
foreach (glob('widgets/javascript/*.js') as $file) {
672
	if (!array_key_exists(basename($file, '.js'), $widgets_found)) {
673
		continue;
674
	}
675
	$mtime = filemtime("/usr/local/www/{$file}");
676
	echo '<script src="'.$file.'?v='.$mtime.'"></script>';
677
}
678

    
679
include("foot.inc");
(72-72/233)