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 |
|
|
* Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
|
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 |
|
|
* Redistribution and use in source and binary forms, with or without
|
14 |
|
|
* modification, are permitted provided that the following conditions are met:
|
15 |
|
|
*
|
16 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
17 |
|
|
* this list of conditions and the following disclaimer.
|
18 |
|
|
*
|
19 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
20 |
|
|
* notice, this list of conditions and the following disclaimer in
|
21 |
|
|
* the documentation and/or other materials provided with the
|
22 |
|
|
* distribution.
|
23 |
|
|
*
|
24 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
25 |
|
|
* must display the following acknowledgment:
|
26 |
|
|
* "This product includes software developed by the pfSense Project
|
27 |
|
|
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
28 |
|
|
*
|
29 |
|
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
30 |
|
|
* endorse or promote products derived from this software without
|
31 |
|
|
* prior written permission. For written permission, please contact
|
32 |
|
|
* coreteam@pfsense.org.
|
33 |
|
|
*
|
34 |
|
|
* 5. Products derived from this software may not be called "pfSense"
|
35 |
|
|
* nor may "pfSense" appear in their names without prior written
|
36 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
37 |
|
|
*
|
38 |
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
39 |
|
|
* acknowledgment:
|
40 |
|
|
*
|
41 |
|
|
* "This product includes software developed by the pfSense Project
|
42 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
43 |
|
|
*
|
44 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
45 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
46 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
47 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
48 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
49 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
50 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
51 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
52 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
53 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
54 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
55 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
56 |
fd9ebcd5
|
Stephen Beaver
|
*/
|
57 |
5b237745
|
Scott Ullrich
|
|
58 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
59 |
5d916fc7
|
Stephen Beaver
|
##|*IDENT=page-system-login-logout
|
60 |
5230f468
|
jim-p
|
##|*NAME=System: Login / Logout / Dashboard
|
61 |
b7ccf315
|
Erik Fonnesbeck
|
##|*DESCR=Allow access to the 'System: Login / Logout' page and Dashboard.
|
62 |
6b07c15a
|
Matthew Grooms
|
##|*MATCH=index.php*
|
63 |
|
|
##|-PRIV
|
64 |
|
|
|
65 |
acc5dd59
|
jim-p
|
// Turn on buffering to speed up rendering
|
66 |
6c07db48
|
Phil Davis
|
ini_set('output_buffering', 'true');
|
67 |
acc5dd59
|
jim-p
|
|
68 |
|
|
// Start buffering with a cache size of 100000
|
69 |
|
|
ob_start(null, "1000");
|
70 |
880637d2
|
Scott Ullrich
|
|
71 |
acc5dd59
|
jim-p
|
## Load Essential Includes
|
72 |
|
|
require_once('guiconfig.inc');
|
73 |
32e834ff
|
Ermal LUÇI
|
require_once('functions.inc');
|
74 |
acc5dd59
|
jim-p
|
require_once('notices.inc');
|
75 |
7c8f3711
|
jim-p
|
require_once("pkg-utils.inc");
|
76 |
acc5dd59
|
jim-p
|
|
77 |
329a1cd5
|
Stephen Beaver
|
if (isset($_POST['closenotice'])) {
|
78 |
|
|
close_notice($_POST['closenotice']);
|
79 |
|
|
sleep(1);
|
80 |
005ac3ca
|
Marcello Coutinho
|
exit;
|
81 |
|
|
}
|
82 |
|
|
|
83 |
0206483d
|
Stephen Beaver
|
if (isset($_GET['closenotice'])) {
|
84 |
|
|
close_notice($_GET['closenotice']);
|
85 |
|
|
sleep(1);
|
86 |
|
|
}
|
87 |
|
|
|
88 |
41b1ff89
|
Phil Davis
|
if ($g['disablecrashreporter'] != true) {
|
89 |
36365f49
|
Scott Ullrich
|
// Check to see if we have a crash report
|
90 |
eac584f3
|
Scott Ullrich
|
$x = 0;
|
91 |
41b1ff89
|
Phil Davis
|
if (file_exists("/tmp/PHP_errors.log")) {
|
92 |
918f0a94
|
NewEraCracker
|
$total = `/bin/cat /tmp/PHP_errors.log | /usr/bin/wc -l | /usr/bin/awk '{ print $1 }'`;
|
93 |
41b1ff89
|
Phil Davis
|
if ($total > 0) {
|
94 |
a9ee006d
|
Scott Ullrich
|
$x++;
|
95 |
41b1ff89
|
Phil Davis
|
}
|
96 |
a9ee006d
|
Scott Ullrich
|
}
|
97 |
60e27eb0
|
Stephen Beaver
|
|
98 |
a9ee006d
|
Scott Ullrich
|
$crash = glob("/var/crash/*");
|
99 |
36365f49
|
Scott Ullrich
|
$skip_files = array(".", "..", "minfree", "");
|
100 |
60e27eb0
|
Stephen Beaver
|
|
101 |
41b1ff89
|
Phil Davis
|
if (is_array($crash)) {
|
102 |
|
|
foreach ($crash as $c) {
|
103 |
|
|
if (!in_array(basename($c), $skip_files)) {
|
104 |
36365f49
|
Scott Ullrich
|
$x++;
|
105 |
41b1ff89
|
Phil Davis
|
}
|
106 |
36365f49
|
Scott Ullrich
|
}
|
107 |
60e27eb0
|
Stephen Beaver
|
|
108 |
41b1ff89
|
Phil Davis
|
if ($x > 0) {
|
109 |
8545adde
|
k-paulius
|
$savemsg = sprintf(gettext("%s has detected a crash report or programming bug. Click <a href='crash_reporter.php'>here</a> for more information."), $g['product_name']);
|
110 |
c8532336
|
Phil Davis
|
$class = "warning";
|
111 |
41b1ff89
|
Phil Davis
|
}
|
112 |
104faa07
|
Scott Ullrich
|
}
|
113 |
|
|
}
|
114 |
|
|
|
115 |
ef325a6c
|
Phil Davis
|
##build list of php include files
|
116 |
|
|
$phpincludefiles = array();
|
117 |
|
|
$directory = "/usr/local/www/widgets/include/";
|
118 |
|
|
$dirhandle = opendir($directory);
|
119 |
|
|
$filename = "";
|
120 |
|
|
|
121 |
|
|
while (false !== ($filename = readdir($dirhandle))) {
|
122 |
dffe24be
|
NewEraCracker
|
if (!stristr($filename, ".inc")) {
|
123 |
|
|
continue;
|
124 |
|
|
}
|
125 |
ef325a6c
|
Phil Davis
|
$phpincludefiles[] = $filename;
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
## Include each widget include file.
|
129 |
|
|
## These define vars that specify the widget title and title link.
|
130 |
|
|
foreach ($phpincludefiles as $includename) {
|
131 |
|
|
if (file_exists($directory . $includename)) {
|
132 |
86573bb9
|
Phil Davis
|
include_once($directory . $includename);
|
133 |
ef325a6c
|
Phil Davis
|
}
|
134 |
|
|
}
|
135 |
|
|
|
136 |
acc5dd59
|
jim-p
|
##build list of widgets
|
137 |
aa82505e
|
Phil Davis
|
foreach (glob("/usr/local/www/widgets/widgets/*.widget.php") as $file) {
|
138 |
41ea4cf3
|
Sjon Hortensius
|
$name = basename($file, '.widget.php');
|
139 |
ef325a6c
|
Phil Davis
|
// Get the widget title that should be in a var defined in the widget's inc file.
|
140 |
|
|
$widgettitle = ${$name . '_title'};
|
141 |
|
|
|
142 |
dffe24be
|
NewEraCracker
|
if (empty(trim($widgettitle))) {
|
143 |
ef325a6c
|
Phil Davis
|
// Fall back to constructing a title from the file name of the widget.
|
144 |
|
|
$widgettitle = ucwords(str_replace('_', ' ', $name));
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
$widgets[ $name ] = array('name' => $widgettitle, 'display' => 'none');
|
148 |
acc5dd59
|
jim-p
|
}
|
149 |
|
|
|
150 |
|
|
##if no config entry found, initialize config entry
|
151 |
|
|
if (!is_array($config['widgets'])) {
|
152 |
|
|
$config['widgets'] = array();
|
153 |
|
|
}
|
154 |
d772ac32
|
Erik Kristensen
|
|
155 |
41ea4cf3
|
Sjon Hortensius
|
if ($_POST && $_POST['sequence']) {
|
156 |
60e27eb0
|
Stephen Beaver
|
|
157 |
8bab524e
|
Phil Davis
|
$widget_settings = array();
|
158 |
|
|
$widget_settings['sequence'] = rtrim($_POST['sequence'], ',');
|
159 |
8191b36e
|
Scott Ullrich
|
|
160 |
1c428d53
|
Phil Davis
|
foreach ($widgets as $widgetname => $widgetconfig) {
|
161 |
|
|
if ($_POST[$widgetname . '-config']) {
|
162 |
8bab524e
|
Phil Davis
|
$widget_settings[$widgetname . '-config'] = $_POST[$widgetname . '-config'];
|
163 |
8191b36e
|
Scott Ullrich
|
}
|
164 |
|
|
}
|
165 |
|
|
|
166 |
8bab524e
|
Phil Davis
|
save_widget_settings($_SESSION['Username'], $widget_settings);
|
167 |
69b397dd
|
Sjon Hortensius
|
header("Location: /");
|
168 |
1180e4f0
|
Sjon Hortensius
|
exit;
|
169 |
|
|
}
|
170 |
757733b5
|
Renato Botelho
|
|
171 |
1180e4f0
|
Sjon Hortensius
|
## Load Functions Files
|
172 |
|
|
require_once('includes/functions.inc.php');
|
173 |
d772ac32
|
Erik Kristensen
|
|
174 |
1180e4f0
|
Sjon Hortensius
|
## Check to see if we have a swap space,
|
175 |
|
|
## if true, display, if false, hide it ...
|
176 |
1c428d53
|
Phil Davis
|
if (file_exists("/usr/sbin/swapinfo")) {
|
177 |
1180e4f0
|
Sjon Hortensius
|
$swapinfo = `/usr/sbin/swapinfo`;
|
178 |
1c428d53
|
Phil Davis
|
if (stristr($swapinfo, '%') == true) $showswap=true;
|
179 |
1180e4f0
|
Sjon Hortensius
|
}
|
180 |
|
|
|
181 |
|
|
## User recently restored his config.
|
182 |
|
|
## If packages are installed lets resync
|
183 |
1c428d53
|
Phil Davis
|
if (file_exists('/conf/needs_package_sync')) {
|
184 |
|
|
if ($config['installedpackages'] <> '' && is_array($config['installedpackages']['package'])) {
|
185 |
2344bed4
|
Renato Botelho
|
if ($g['platform'] == $g['product_name'] || $g['platform'] == "nanobsd") {
|
186 |
1180e4f0
|
Sjon Hortensius
|
## If the user has logged into webGUI quickly while the system is booting then do not redirect them to
|
187 |
|
|
## the package reinstall page. That is about to be done by the boot script anyway.
|
188 |
31f03b6c
|
Sjon Hortensius
|
## The code in head.inc will put up a notice to the user.
|
189 |
1180e4f0
|
Sjon Hortensius
|
if (!platform_booting()) {
|
190 |
|
|
header('Location: pkg_mgr_install.php?mode=reinstallall');
|
191 |
|
|
exit;
|
192 |
6cc843c3
|
Scott Ullrich
|
}
|
193 |
1df0159c
|
Erik Kristensen
|
}
|
194 |
1180e4f0
|
Sjon Hortensius
|
} else {
|
195 |
|
|
conf_mount_rw();
|
196 |
|
|
@unlink('/conf/needs_package_sync');
|
197 |
|
|
conf_mount_ro();
|
198 |
1df0159c
|
Erik Kristensen
|
}
|
199 |
1180e4f0
|
Sjon Hortensius
|
}
|
200 |
8fecad11
|
Scott Ullrich
|
|
201 |
1180e4f0
|
Sjon Hortensius
|
## If it is the first time webConfigurator has been
|
202 |
|
|
## accessed since initial install show this stuff.
|
203 |
1c428d53
|
Phil Davis
|
if (file_exists('/conf/trigger_initial_wizard')) {
|
204 |
1180e4f0
|
Sjon Hortensius
|
?>
|
205 |
|
|
<!DOCTYPE html>
|
206 |
|
|
<html lang="en">
|
207 |
702b324e
|
Scott Ullrich
|
<head>
|
208 |
f0c5e7c1
|
Jared Dillard
|
<link rel="stylesheet" href="/css/pfSense.css" />
|
209 |
5bca8df4
|
Stephen Beaver
|
<title><?=$g['product_name']?>.localdomain - <?=$g['product_name']?> first time setup</title>
|
210 |
1180e4f0
|
Sjon Hortensius
|
<meta http-equiv="refresh" content="1;url=wizard.php?xml=setup_wizard.xml" />
|
211 |
|
|
</head>
|
212 |
|
|
<body id="loading-wizard" class="no-menu">
|
213 |
|
|
<div id="jumbotron">
|
214 |
|
|
<div class="container">
|
215 |
c7d61071
|
Sander van Leeuwen
|
<div class="col-sm-offset-3 col-sm-6 col-xs-12">
|
216 |
40547fe4
|
Stephen Beaver
|
<font color="white">
|
217 |
|
|
<p><h3><?=sprintf(gettext("Welcome to %s!\n"), $g['product_name'])?></h3></p>
|
218 |
1e87fb3f
|
Phil Davis
|
<p><?=gettext("One moment while the initial setup wizard starts.")?></p>
|
219 |
c7d61071
|
Sander van Leeuwen
|
<p><?=gettext("Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal GUI.")?></p>
|
220 |
1c428d53
|
Phil Davis
|
<p><?=sprintf(gettext("To bypass the wizard, click on the %s logo on the initial page."), $g['product_name'])?></p>
|
221 |
40547fe4
|
Stephen Beaver
|
</font>
|
222 |
c7d61071
|
Sander van Leeuwen
|
</div>
|
223 |
1180e4f0
|
Sjon Hortensius
|
</div>
|
224 |
|
|
</div>
|
225 |
|
|
</body>
|
226 |
|
|
</html>
|
227 |
|
|
<?php
|
228 |
|
|
exit;
|
229 |
|
|
}
|
230 |
bf787c0a
|
Scott Ullrich
|
|
231 |
1180e4f0
|
Sjon Hortensius
|
## Find out whether there's hardware encryption or not
|
232 |
|
|
unset($hwcrypto);
|
233 |
|
|
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
|
234 |
|
|
if ($fd) {
|
235 |
|
|
while (!feof($fd)) {
|
236 |
|
|
$dmesgl = fgets($fd);
|
237 |
|
|
if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)
|
238 |
|
|
or preg_match("/.*(VIA Padlock)/", $dmesgl, $matches)
|
239 |
|
|
or preg_match("/^safe.: (\w.*)/", $dmesgl, $matches)
|
240 |
|
|
or preg_match("/^ubsec.: (.*?),/", $dmesgl, $matches)
|
241 |
|
|
or preg_match("/^padlock.: <(.*?)>,/", $dmesgl, $matches)
|
242 |
a2e6d7f8
|
Luiz Otavio O Souza
|
or preg_match("/^glxsb.: (.*?),/", $dmesgl, $matches)) {
|
243 |
1180e4f0
|
Sjon Hortensius
|
$hwcrypto = $matches[1];
|
244 |
|
|
break;
|
245 |
5b237745
|
Scott Ullrich
|
}
|
246 |
|
|
}
|
247 |
1180e4f0
|
Sjon Hortensius
|
fclose($fd);
|
248 |
aa82505e
|
Phil Davis
|
if (!isset($hwcrypto) && get_single_sysctl("dev.aesni.0.%desc")) {
|
249 |
a2e6d7f8
|
Luiz Otavio O Souza
|
$hwcrypto = get_single_sysctl("dev.aesni.0.%desc");
|
250 |
aa82505e
|
Phil Davis
|
}
|
251 |
1180e4f0
|
Sjon Hortensius
|
}
|
252 |
45ee90ed
|
Matthew Grooms
|
|
253 |
7abf7db5
|
Scott Dale
|
##build widget saved list information
|
254 |
8bab524e
|
Phil Davis
|
if ($user_settings['widgets']['sequence'] != "") {
|
255 |
|
|
$dashboardcolumns = isset($user_settings['webgui']['dashboardcolumns']) ? $user_settings['webgui']['dashboardcolumns'] : 2;
|
256 |
|
|
$pconfig['sequence'] = $user_settings['widgets']['sequence'];
|
257 |
1180e4f0
|
Sjon Hortensius
|
$widgetsfromconfig = array();
|
258 |
757733b5
|
Renato Botelho
|
|
259 |
aa82505e
|
Phil Davis
|
foreach (explode(',', $pconfig['sequence']) as $line) {
|
260 |
1180e4f0
|
Sjon Hortensius
|
list($file, $col, $display) = explode(':', $line);
|
261 |
|
|
|
262 |
|
|
// be backwards compatible
|
263 |
72eaefaf
|
Stephen Beaver
|
// If the display column information is missing, we will assign a temporary
|
264 |
|
|
// column here. Next time the user saves the dashboard it will fix itself
|
265 |
|
|
if ($col == "") {
|
266 |
|
|
if ($file == "system_information") {
|
267 |
|
|
$col = "col1";
|
268 |
|
|
} else {
|
269 |
|
|
$col = "col2";
|
270 |
|
|
}
|
271 |
|
|
}
|
272 |
|
|
|
273 |
ad51eb90
|
Phil Davis
|
// Limit the column to the current dashboard columns.
|
274 |
|
|
if (substr($col, 3) > $dashboardcolumns) {
|
275 |
|
|
$col = "col" . $dashboardcolumns;
|
276 |
|
|
}
|
277 |
|
|
|
278 |
1180e4f0
|
Sjon Hortensius
|
$offset = strpos($file, '-container');
|
279 |
94704bc6
|
Phil Davis
|
if (false !== $offset) {
|
280 |
1180e4f0
|
Sjon Hortensius
|
$file = substr($file, 0, $offset);
|
281 |
94704bc6
|
Phil Davis
|
}
|
282 |
1180e4f0
|
Sjon Hortensius
|
|
283 |
ef325a6c
|
Phil Davis
|
// Get the widget title that should be in a var defined in the widget's inc file.
|
284 |
|
|
$widgettitle = ${$file . '_title'};
|
285 |
|
|
|
286 |
dffe24be
|
NewEraCracker
|
if (empty(trim($widgettitle))) {
|
287 |
ef325a6c
|
Phil Davis
|
// Fall back to constructing a title from the file name of the widget.
|
288 |
|
|
$widgettitle = ucwords(str_replace('_', ' ', $file));
|
289 |
|
|
}
|
290 |
|
|
|
291 |
1180e4f0
|
Sjon Hortensius
|
$widgetsfromconfig[ $file ] = array(
|
292 |
ef325a6c
|
Phil Davis
|
'name' => $widgettitle,
|
293 |
1180e4f0
|
Sjon Hortensius
|
'col' => $col,
|
294 |
|
|
'display' => $display,
|
295 |
|
|
);
|
296 |
1db766df
|
Scott Dale
|
}
|
297 |
757733b5
|
Renato Botelho
|
|
298 |
5c7657d6
|
Renato Botelho
|
// add widgets that may not be in the saved configuration, in case they are to be displayed later
|
299 |
69b397dd
|
Sjon Hortensius
|
$widgets = $widgetsfromconfig + $widgets;
|
300 |
757733b5
|
Renato Botelho
|
|
301 |
019a94df
|
Scott Dale
|
##find custom configurations of a particular widget and load its info to $pconfig
|
302 |
1c428d53
|
Phil Davis
|
foreach ($widgets as $widgetname => $widgetconfig) {
|
303 |
75ae3d1c
|
Phil Davis
|
if ($config['widgets'][$widgetname . '-config']) {
|
304 |
|
|
$pconfig[$widgetname . '-config'] = $config['widgets'][$widgetname . '-config'];
|
305 |
757733b5
|
Renato Botelho
|
}
|
306 |
|
|
}
|
307 |
3e4e94ce
|
Scott Dale
|
}
|
308 |
|
|
|
309 |
c05363c8
|
NOYB
|
## Get the configured options for Show/Hide available widgets panel.
|
310 |
8bab524e
|
Phil Davis
|
$dashboard_available_widgets_hidden = !$user_settings['webgui']['dashboardavailablewidgetspanel'];
|
311 |
c05363c8
|
NOYB
|
|
312 |
|
|
if ($dashboard_available_widgets_hidden) {
|
313 |
|
|
$panel_state = 'out';
|
314 |
|
|
$panel_body_state = 'in';
|
315 |
|
|
} else {
|
316 |
|
|
$panel_state = 'in';
|
317 |
|
|
$panel_body_state = 'out';
|
318 |
|
|
}
|
319 |
|
|
|
320 |
1db766df
|
Scott Dale
|
## Set Page Title and Include Header
|
321 |
2734d2db
|
Jared Dillard
|
$pgtitle = array(gettext("Status"), gettext("Dashboard"));
|
322 |
1db766df
|
Scott Dale
|
include("head.inc");
|
323 |
f6f6947e
|
Scott Ullrich
|
|
324 |
41b1ff89
|
Phil Davis
|
if ($savemsg) {
|
325 |
c8532336
|
Phil Davis
|
print_info_box($savemsg, $class);
|
326 |
41b1ff89
|
Phil Davis
|
}
|
327 |
fca795f8
|
Scott Ullrich
|
|
328 |
810a11bc
|
Scott Ullrich
|
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
|
329 |
c69c58e2
|
Vinicius Coque
|
|
330 |
0682e26b
|
Colin Smith
|
?>
|
331 |
1180e4f0
|
Sjon Hortensius
|
|
332 |
c05363c8
|
NOYB
|
<div class="panel panel-default collapse <?=$panel_state?>" id="widget-available">
|
333 |
95fa5cce
|
Phil Davis
|
<div class="panel-heading">
|
334 |
|
|
<h2 class="panel-title"><?=gettext("Available Widgets"); ?>
|
335 |
|
|
<span class="widget-heading-icon">
|
336 |
|
|
<a data-toggle="collapse" href="#widget-available_panel-body" id="widgets-available">
|
337 |
|
|
<i class="fa fa-plus-circle"></i>
|
338 |
|
|
</a>
|
339 |
|
|
</span>
|
340 |
|
|
</h2>
|
341 |
166b0099
|
Stephen Beaver
|
</div>
|
342 |
c05363c8
|
NOYB
|
<div id="widget-available_panel-body" class="panel-body collapse <?=$panel_body_state?>">
|
343 |
9239f765
|
Jared Dillard
|
<div class="content">
|
344 |
|
|
<div class="row">
|
345 |
60e27eb0
|
Stephen Beaver
|
<?php
|
346 |
e76931e2
|
Stephen Beaver
|
|
347 |
|
|
// Build the Available Widgets table using a sorted copy of the $widgets array
|
348 |
|
|
$available = $widgets;
|
349 |
dffe24be
|
NewEraCracker
|
uasort($available, function($a, $b){ return strcasecmp($a['name'], $b['name']); });
|
350 |
e76931e2
|
Stephen Beaver
|
|
351 |
|
|
foreach ($available as $widgetname => $widgetconfig):
|
352 |
60e27eb0
|
Stephen Beaver
|
if ($widgetconfig['display'] == 'none'):
|
353 |
|
|
?>
|
354 |
a508c6e4
|
NOYB
|
<div class="col-sm-3"><a href="#" id="btnadd-<?=$widgetname?>"><i class="fa fa-plus"></i> <?=$widgetconfig['name']?></a></div>
|
355 |
a2faa388
|
Sander van Leeuwen
|
<?php endif; ?>
|
356 |
|
|
<?php endforeach; ?>
|
357 |
9239f765
|
Jared Dillard
|
</div>
|
358 |
|
|
</div>
|
359 |
1db766df
|
Scott Dale
|
</div>
|
360 |
|
|
</div>
|
361 |
|
|
|
362 |
a2faa388
|
Sander van Leeuwen
|
<div class="hidden" id="widgetSequence">
|
363 |
a508c6e4
|
NOYB
|
<form action="/" method="post" id="widgetSequence_form" name="widgetForm">
|
364 |
41ea4cf3
|
Sjon Hortensius
|
<input type="hidden" name="sequence" value="" />
|
365 |
|
|
</form>
|
366 |
|
|
</div>
|
367 |
|
|
|
368 |
1180e4f0
|
Sjon Hortensius
|
<?php
|
369 |
41ea4cf3
|
Sjon Hortensius
|
$widgetColumns = array();
|
370 |
aa82505e
|
Phil Davis
|
foreach ($widgets as $widgetname => $widgetconfig) {
|
371 |
|
|
if ($widgetconfig['display'] == 'none') {
|
372 |
41ea4cf3
|
Sjon Hortensius
|
continue;
|
373 |
aa82505e
|
Phil Davis
|
}
|
374 |
41ea4cf3
|
Sjon Hortensius
|
|
375 |
e8bd1464
|
Renato Botelho
|
if (!file_exists('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php')) {
|
376 |
|
|
continue;
|
377 |
|
|
}
|
378 |
|
|
|
379 |
aa82505e
|
Phil Davis
|
if (!isset($widgetColumns[ $widgetconfig['col'] ])) {
|
380 |
41ea4cf3
|
Sjon Hortensius
|
$widgetColumns[ $widgetconfig['col'] ] = array();
|
381 |
aa82505e
|
Phil Davis
|
}
|
382 |
41ea4cf3
|
Sjon Hortensius
|
|
383 |
|
|
$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
|
384 |
|
|
}
|
385 |
1180e4f0
|
Sjon Hortensius
|
?>
|
386 |
41ea4cf3
|
Sjon Hortensius
|
|
387 |
a2faa388
|
Sander van Leeuwen
|
<div class="row">
|
388 |
2063a534
|
Jared Dillard
|
<?php
|
389 |
477db933
|
Jared Dillard
|
$columnWidth = 12 / $numColumns;
|
390 |
a54d69c8
|
Stephen Beaver
|
|
391 |
e3843a08
|
Phil Davis
|
for ($currentColumnNumber = 1; $currentColumnNumber <= $numColumns; $currentColumnNumber++) {
|
392 |
cee365e6
|
Stephen Beaver
|
|
393 |
2063a534
|
Jared Dillard
|
|
394 |
e3843a08
|
Phil Davis
|
//if col$currentColumnNumber exists
|
395 |
|
|
if (isset($widgetColumns['col'.$currentColumnNumber])) {
|
396 |
caf897c8
|
Jared Dillard
|
echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '">';
|
397 |
e3843a08
|
Phil Davis
|
$columnWidgets = $widgetColumns['col'.$currentColumnNumber];
|
398 |
2063a534
|
Jared Dillard
|
|
399 |
|
|
foreach ($columnWidgets as $widgetname => $widgetconfig) {
|
400 |
|
|
// Compose the widget title and include the title link if available
|
401 |
|
|
$widgetlink = ${$widgetname . '_title_link'};
|
402 |
|
|
|
403 |
|
|
if ((strlen($widgetlink) > 0)) {
|
404 |
|
|
$wtitle = '<a href="' . $widgetlink . '"> ' . $widgetconfig['name'] . '</a>';
|
405 |
|
|
} else {
|
406 |
|
|
$wtitle = $widgetconfig['name'];
|
407 |
|
|
}
|
408 |
|
|
?>
|
409 |
|
|
<div class="panel panel-default" id="widget-<?=$widgetname?>">
|
410 |
|
|
<div class="panel-heading">
|
411 |
95fa5cce
|
Phil Davis
|
<h2 class="panel-title">
|
412 |
|
|
<?=$wtitle?>
|
413 |
|
|
<span class="widget-heading-icon">
|
414 |
|
|
<a data-toggle="collapse" href="#widget-<?=$widgetname?>_panel-footer" class="config hidden">
|
415 |
|
|
<i class="fa fa-wrench"></i>
|
416 |
|
|
</a>
|
417 |
|
|
<a data-toggle="collapse" href="#widget-<?=$widgetname?>_panel-body">
|
418 |
|
|
<!-- actual icon is determined in css based on state of body -->
|
419 |
|
|
<i class="fa fa-plus-circle"></i>
|
420 |
|
|
</a>
|
421 |
|
|
<a data-toggle="close" href="#widget-<?=$widgetname?>">
|
422 |
|
|
<i class="fa fa-times-circle"></i>
|
423 |
|
|
</a>
|
424 |
|
|
</span>
|
425 |
|
|
</h2>
|
426 |
2063a534
|
Jared Dillard
|
</div>
|
427 |
|
|
<div id="widget-<?=$widgetname?>_panel-body" class="panel-body collapse<?=($widgetconfig['display'] == 'close' ? '' : ' in')?>">
|
428 |
86573bb9
|
Phil Davis
|
<?php include_once('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php'); ?>
|
429 |
2063a534
|
Jared Dillard
|
</div>
|
430 |
|
|
</div>
|
431 |
|
|
<?php
|
432 |
|
|
}
|
433 |
6fefbd48
|
Jared Dillard
|
echo "</div>";
|
434 |
a54d69c8
|
Stephen Beaver
|
} else {
|
435 |
caf897c8
|
Jared Dillard
|
echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '"></div>';
|
436 |
a54d69c8
|
Stephen Beaver
|
}
|
437 |
cee365e6
|
Stephen Beaver
|
|
438 |
477db933
|
Jared Dillard
|
}
|
439 |
|
|
?>
|
440 |
2063a534
|
Jared Dillard
|
|
441 |
a2faa388
|
Sander van Leeuwen
|
</div>
|
442 |
561d55ff
|
Erik Kristensen
|
|
443 |
8fd9052f
|
Colin Fleming
|
<script type="text/javascript">
|
444 |
|
|
//<![CDATA[
|
445 |
eae6b58d
|
Stephen Beaver
|
|
446 |
|
|
dirty = false;
|
447 |
aa82505e
|
Phil Davis
|
function updateWidgets(newWidget) {
|
448 |
7f8f8808
|
Sjon Hortensius
|
var sequence = '';
|
449 |
|
|
|
450 |
aa82505e
|
Phil Davis
|
$('.container .col-md-<?=$columnWidth?>').each(function(idx, col) {
|
451 |
|
|
$('.panel', col).each(function(idx, widget) {
|
452 |
7f8f8808
|
Sjon Hortensius
|
var isOpen = $('.panel-body', widget).hasClass('in');
|
453 |
|
|
|
454 |
94704bc6
|
Phil Davis
|
sequence += widget.id.split('-')[1] + ':' + col.id.split('-')[1] + ':' + (isOpen ? 'open' : 'close') + ',';
|
455 |
7f8f8808
|
Sjon Hortensius
|
});
|
456 |
|
|
});
|
457 |
|
|
|
458 |
aa82505e
|
Phil Davis
|
if (typeof newWidget !== 'undefined') {
|
459 |
b5ff58cf
|
Stephen Beaver
|
// The system_information widget is always added to column one. Others go in column two
|
460 |
|
|
if (newWidget == "system_information") {
|
461 |
|
|
sequence += newWidget + ':' + 'col1:open';
|
462 |
|
|
} else {
|
463 |
f4a15d29
|
Stephen Beaver
|
sequence += newWidget + ':' + 'col2:open';
|
464 |
b5ff58cf
|
Stephen Beaver
|
}
|
465 |
aa82505e
|
Phil Davis
|
}
|
466 |
60e27eb0
|
Stephen Beaver
|
|
467 |
a508c6e4
|
NOYB
|
$('input[name=sequence]', $('#widgetSequence_form')).val(sequence);
|
468 |
7f8f8808
|
Sjon Hortensius
|
}
|
469 |
|
|
|
470 |
dc58b7b3
|
Sjon Hortensius
|
events.push(function() {
|
471 |
|
|
|
472 |
|
|
// Make panels destroyable
|
473 |
aa82505e
|
Phil Davis
|
$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el) {
|
474 |
|
|
$(el).on('click', function(e) {
|
475 |
7f8f8808
|
Sjon Hortensius
|
$(el).parents('.panel').remove();
|
476 |
|
|
updateWidgets();
|
477 |
eae6b58d
|
Stephen Beaver
|
// Submit the form save/display all selected widgets
|
478 |
|
|
$('[name=widgetForm]').submit();
|
479 |
dc58b7b3
|
Sjon Hortensius
|
})
|
480 |
|
|
});
|
481 |
|
|
|
482 |
|
|
// Make panels sortable
|
483 |
477db933
|
Jared Dillard
|
$('.container .col-md-<?=$columnWidth?>').sortable({
|
484 |
dc58b7b3
|
Sjon Hortensius
|
handle: '.panel-heading',
|
485 |
|
|
cursor: 'grabbing',
|
486 |
477db933
|
Jared Dillard
|
connectWith: '.container .col-md-<?=$columnWidth?>',
|
487 |
91d59881
|
NOYB
|
update: function(){
|
488 |
|
|
dirty = true;
|
489 |
|
|
$('#btnstore').removeClass('invisible');
|
490 |
|
|
}
|
491 |
dc58b7b3
|
Sjon Hortensius
|
});
|
492 |
60e27eb0
|
Stephen Beaver
|
|
493 |
|
|
// On clicking a widget to install . .
|
494 |
a508c6e4
|
NOYB
|
$('[id^=btnadd-]').click(function(event) {
|
495 |
f4a15d29
|
Stephen Beaver
|
// Add the widget name to the list of displayed widgets
|
496 |
a508c6e4
|
NOYB
|
updateWidgets(this.id.replace('btnadd-', ''));
|
497 |
60e27eb0
|
Stephen Beaver
|
|
498 |
|
|
// Submit the form save/display all selected widgets
|
499 |
|
|
$('[name=widgetForm]').submit();
|
500 |
|
|
});
|
501 |
|
|
|
502 |
eae6b58d
|
Stephen Beaver
|
|
503 |
e94f260c
|
Stephen Beaver
|
$('#btnstore').click(function() {
|
504 |
|
|
updateWidgets();
|
505 |
|
|
dirty = false;
|
506 |
91d59881
|
NOYB
|
$(this).addClass('invisible');
|
507 |
e94f260c
|
Stephen Beaver
|
$('[name=widgetForm]').submit();
|
508 |
|
|
});
|
509 |
eae6b58d
|
Stephen Beaver
|
|
510 |
|
|
// provide a warning message if the user tries to change page before saving
|
511 |
|
|
$(window).bind('beforeunload', function(){
|
512 |
|
|
if (dirty) {
|
513 |
530c7ccf
|
NOYB
|
return ("<?=gettext('One or more widgets have been moved but have not yet been saved')?>");
|
514 |
eae6b58d
|
Stephen Beaver
|
} else {
|
515 |
|
|
return undefined;
|
516 |
|
|
}
|
517 |
|
|
});
|
518 |
cee365e6
|
Stephen Beaver
|
|
519 |
|
|
// 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)
|
520 |
|
|
// (Sometimes this will cause us to see the icon when we don't need it, but better that than the other way round)
|
521 |
|
|
$('.panel').on('hidden.bs.collapse shown.bs.collapse', function (e) {
|
522 |
|
|
if (e.currentTarget.id != 'widget-available') {
|
523 |
|
|
$('#btnstore').removeClass("invisible");
|
524 |
|
|
}
|
525 |
|
|
});
|
526 |
dc58b7b3
|
Sjon Hortensius
|
});
|
527 |
8fd9052f
|
Colin Fleming
|
//]]>
|
528 |
dc58b7b3
|
Sjon Hortensius
|
</script>
|
529 |
41ea4cf3
|
Sjon Hortensius
|
<?php
|
530 |
1180e4f0
|
Sjon Hortensius
|
//build list of javascript include files
|
531 |
aa82505e
|
Phil Davis
|
foreach (glob('widgets/javascript/*.js') as $file) {
|
532 |
1180e4f0
|
Sjon Hortensius
|
echo '<script src="'.$file.'"></script>';
|
533 |
aa82505e
|
Phil Davis
|
}
|
534 |
927ea6e1
|
jim-p
|
|
535 |
1c428d53
|
Phil Davis
|
include("foot.inc");
|