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