1 |
667b2b60
|
Ermal
|
<?php
|
2 |
|
|
/*
|
3 |
c5d81585
|
Renato Botelho
|
* guiconfig.inc
|
4 |
|
|
*
|
5 |
|
|
* part of pfSense (https://www.pfsense.org)
|
6 |
38809d47
|
Renato Botelho do Couto
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7 |
|
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8 |
0284d79e
|
jim-p
|
* Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
|
9 |
c5d81585
|
Renato Botelho
|
* All rights reserved.
|
10 |
|
|
*
|
11 |
|
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
12 |
|
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
13 |
|
|
* All rights reserved.
|
14 |
|
|
*
|
15 |
b12ea3fb
|
Renato Botelho
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
16 |
|
|
* you may not use this file except in compliance with the License.
|
17 |
|
|
* You may obtain a copy of the License at
|
18 |
c5d81585
|
Renato Botelho
|
*
|
19 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
20 |
c5d81585
|
Renato Botelho
|
*
|
21 |
b12ea3fb
|
Renato Botelho
|
* Unless required by applicable law or agreed to in writing, software
|
22 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
23 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
24 |
|
|
* See the License for the specific language governing permissions and
|
25 |
|
|
* limitations under the License.
|
26 |
fd9ebcd5
|
Stephen Beaver
|
*/
|
27 |
667b2b60
|
Ermal
|
|
28 |
|
|
/* Include authentication routines */
|
29 |
|
|
/* THIS MUST BE ABOVE ALL OTHER CODE */
|
30 |
c4212dc6
|
Yorick Koster
|
header("X-Frame-Options: SAMEORIGIN");
|
31 |
82cd6022
|
PiBa-NL
|
include_once('phpsessionmanager.inc');
|
32 |
da7384c4
|
jim-p
|
|
33 |
|
|
function pfSense_csrf_callback() {
|
34 |
|
|
include "csrf_error.php";
|
35 |
|
|
}
|
36 |
|
|
|
37 |
45b4ffc6
|
Phil Davis
|
if (!$nocsrf) {
|
38 |
64ec1ddf
|
Scott Ullrich
|
function csrf_startup() {
|
39 |
efa9174a
|
jim-p
|
global $config;
|
40 |
64ec1ddf
|
Scott Ullrich
|
csrf_conf('rewrite-js', '/csrf/csrf-magic.js');
|
41 |
6c07db48
|
Phil Davis
|
$timeout_minutes = isset($config['system']['webgui']['session_timeout']) ? $config['system']['webgui']['session_timeout'] : 240;
|
42 |
56befec1
|
jim-p
|
csrf_conf('expires', $timeout_minutes * 60);
|
43 |
da7384c4
|
jim-p
|
csrf_conf('callback', 'pfSense_csrf_callback');
|
44 |
64ec1ddf
|
Scott Ullrich
|
}
|
45 |
|
|
require_once("csrf/csrf-magic.php");
|
46 |
82cd6022
|
PiBa-NL
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
47 |
|
|
phpsession_end(true);
|
48 |
|
|
}
|
49 |
fafd303e
|
Scott Ullrich
|
}
|
50 |
667b2b60
|
Ermal
|
|
51 |
|
|
/* make sure nothing is cached */
|
52 |
|
|
if (!$omit_nocacheheaders) {
|
53 |
|
|
header("Expires: 0");
|
54 |
|
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
55 |
2ebbb0bc
|
Jose Luis Duran
|
header("Cache-Control: no-cache, no-store, must-revalidate");
|
56 |
667b2b60
|
Ermal
|
header("Pragma: no-cache");
|
57 |
|
|
}
|
58 |
|
|
|
59 |
9c59f962
|
Ermal
|
require_once("authgui.inc");
|
60 |
|
|
|
61 |
667b2b60
|
Ermal
|
/* parse the configuration and include all configuration functions */
|
62 |
|
|
require_once("functions.inc");
|
63 |
|
|
|
64 |
02cc81ef
|
Doug Wollison
|
/* Include the autoloader for all the GUI display classes */
|
65 |
|
|
require_once("classes/autoload.inc.php");
|
66 |
667b2b60
|
Ermal
|
|
67 |
|
|
/* used by progress bar */
|
68 |
|
|
$lastseen = "-1";
|
69 |
|
|
|
70 |
|
|
$navlevelsep = ": "; /* navigation level separator string */
|
71 |
|
|
$mandfldhtml = ""; /* display this before mandatory input fields */
|
72 |
|
|
$mandfldhtmlspc = ""; /* same as above, but with spacing */
|
73 |
|
|
|
74 |
55cbefff
|
Stephen Beaver
|
if (!function_exists('set_language')) {
|
75 |
|
|
require_once("pfsense-utils.inc");
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
set_language();
|
79 |
|
|
|
80 |
667b2b60
|
Ermal
|
/* Some ajax scripts still need access to GUI */
|
81 |
45b4ffc6
|
Phil Davis
|
if (!$ignorefirmwarelock) {
|
82 |
667b2b60
|
Ermal
|
if (is_subsystem_dirty('firmwarelock')) {
|
83 |
|
|
if (!$d_isfwfile) {
|
84 |
4d4eefab
|
Stephen Beaver
|
header("Location: system_update.php");
|
85 |
667b2b60
|
Ermal
|
exit;
|
86 |
|
|
} else {
|
87 |
|
|
return;
|
88 |
|
|
}
|
89 |
|
|
}
|
90 |
|
|
}
|
91 |
|
|
|
92 |
45b4ffc6
|
Phil Davis
|
$firewall_rules_dscp_types = array(
|
93 |
|
|
"af11",
|
94 |
|
|
"af12",
|
95 |
|
|
"af13",
|
96 |
|
|
"af21",
|
97 |
|
|
"af22",
|
98 |
|
|
"af23",
|
99 |
|
|
"af31",
|
100 |
|
|
"af32",
|
101 |
|
|
"af33",
|
102 |
|
|
"af41",
|
103 |
|
|
"af42",
|
104 |
|
|
"af43",
|
105 |
|
|
"VA",
|
106 |
|
|
"EF",
|
107 |
|
|
"cs1",
|
108 |
|
|
"cs2",
|
109 |
|
|
"cs3",
|
110 |
|
|
"cs4",
|
111 |
|
|
"cs5",
|
112 |
|
|
"cs6",
|
113 |
|
|
"cs7",
|
114 |
|
|
"0x01",
|
115 |
|
|
"0x02",
|
116 |
|
|
"0x04");
|
117 |
667b2b60
|
Ermal
|
|
118 |
|
|
$auth_server_types = array(
|
119 |
|
|
'ldap' => "LDAP",
|
120 |
7aaf60a8
|
k-paulius
|
'radius' => "RADIUS");
|
121 |
667b2b60
|
Ermal
|
|
122 |
|
|
$ldap_urltypes = array(
|
123 |
f764f63a
|
jim-p
|
'Standard TCP' => 389,
|
124 |
|
|
'STARTTLS Encrypted' => 389,
|
125 |
|
|
'SSL/TLS Encrypted' => 636);
|
126 |
667b2b60
|
Ermal
|
|
127 |
|
|
$ldap_scopes = array(
|
128 |
f49cd725
|
Phil Davis
|
'one' => gettext("One Level"),
|
129 |
|
|
'subtree' => gettext("Entire Subtree"));
|
130 |
667b2b60
|
Ermal
|
|
131 |
|
|
$ldap_protvers = array(
|
132 |
|
|
2,
|
133 |
|
|
3);
|
134 |
|
|
|
135 |
|
|
$ldap_templates = array(
|
136 |
|
|
|
137 |
|
|
'open' => array(
|
138 |
6c07db48
|
Phil Davis
|
'desc' => "OpenLDAP",
|
139 |
|
|
'attr_user' => "cn",
|
140 |
|
|
'attr_group' => "cn",
|
141 |
eeceb2ca
|
Augustin-FL
|
'attr_member' => "member",
|
142 |
|
|
'allow_unauthenticated' => "true"),
|
143 |
667b2b60
|
Ermal
|
|
144 |
|
|
'msad' => array(
|
145 |
6c07db48
|
Phil Davis
|
'desc' => "Microsoft AD",
|
146 |
|
|
'attr_user' => "samAccountName",
|
147 |
|
|
'attr_group' => "cn",
|
148 |
eeceb2ca
|
Augustin-FL
|
'attr_member' => "memberOf",
|
149 |
|
|
'allow_unauthenticated' => "false"),
|
150 |
667b2b60
|
Ermal
|
|
151 |
|
|
'edir' => array(
|
152 |
6c07db48
|
Phil Davis
|
'desc' => "Novell eDirectory",
|
153 |
|
|
'attr_user' => "cn",
|
154 |
|
|
'attr_group' => "cn",
|
155 |
eeceb2ca
|
Augustin-FL
|
'attr_member' => "uniqueMember",
|
156 |
|
|
'allow_unauthenticated' => "false"));
|
157 |
667b2b60
|
Ermal
|
|
158 |
|
|
$radius_srvcs = array(
|
159 |
f49cd725
|
Phil Davis
|
'both' => gettext("Authentication and Accounting"),
|
160 |
|
|
'auth' => gettext("Authentication"),
|
161 |
|
|
'acct' => gettext("Accounting"));
|
162 |
667b2b60
|
Ermal
|
|
163 |
9da4a575
|
Renato Botelho
|
$radius_protocol = array(
|
164 |
|
|
'PAP' => "PAP",
|
165 |
|
|
'CHAP_MD5' => "MD5-CHAP",
|
166 |
|
|
'MSCHAPv1' => "MS-CHAPv1",
|
167 |
|
|
'MSCHAPv2' => "MS-CHAPv2");
|
168 |
|
|
|
169 |
667b2b60
|
Ermal
|
$netbios_nodetypes = array(
|
170 |
|
|
'0' => "none",
|
171 |
|
|
'1' => "b-node",
|
172 |
|
|
'2' => "p-node",
|
173 |
|
|
'4' => "m-node",
|
174 |
13ec619c
|
Chris Buechler
|
'8' => "h-node");
|
175 |
667b2b60
|
Ermal
|
|
176 |
45b4ffc6
|
Phil Davis
|
/* some well known ports */
|
177 |
667b2b60
|
Ermal
|
$wkports = array(
|
178 |
d2c6e89c
|
jim-p
|
179 => "BGP",
|
179 |
96ccd009
|
Renato Botelho
|
5999 => "CVSup",
|
180 |
667b2b60
|
Ermal
|
53 => "DNS",
|
181 |
d2c6e89c
|
jim-p
|
853 => "DNS over TLS",
|
182 |
667b2b60
|
Ermal
|
21 => "FTP",
|
183 |
|
|
3000 => "HBCI",
|
184 |
|
|
80 => "HTTP",
|
185 |
|
|
443 => "HTTPS",
|
186 |
|
|
5190 => "ICQ",
|
187 |
|
|
113 => "IDENT/AUTH",
|
188 |
|
|
143 => "IMAP",
|
189 |
|
|
993 => "IMAP/S",
|
190 |
|
|
4500 => "IPsec NAT-T",
|
191 |
|
|
500 => "ISAKMP",
|
192 |
|
|
1701 => "L2TP",
|
193 |
|
|
389 => "LDAP",
|
194 |
d2c6e89c
|
jim-p
|
636 => "LDAP/S",
|
195 |
667b2b60
|
Ermal
|
1755 => "MMS/TCP",
|
196 |
|
|
7000 => "MMS/UDP",
|
197 |
|
|
445 => "MS DS",
|
198 |
|
|
3389 => "MS RDP",
|
199 |
|
|
1512 => "MS WINS",
|
200 |
|
|
1863 => "MSN",
|
201 |
|
|
119 => "NNTP",
|
202 |
|
|
123 => "NTP",
|
203 |
|
|
138 => "NetBIOS-DGM",
|
204 |
|
|
137 => "NetBIOS-NS",
|
205 |
|
|
139 => "NetBIOS-SSN",
|
206 |
|
|
1194 => "OpenVPN",
|
207 |
|
|
110 => "POP3",
|
208 |
|
|
995 => "POP3/S",
|
209 |
96ccd009
|
Renato Botelho
|
1723 => "PPTP",
|
210 |
667b2b60
|
Ermal
|
1812 => "RADIUS",
|
211 |
|
|
1813 => "RADIUS accounting",
|
212 |
|
|
5004 => "RTP",
|
213 |
|
|
5060 => "SIP",
|
214 |
|
|
25 => "SMTP",
|
215 |
|
|
465 => "SMTP/S",
|
216 |
|
|
161 => "SNMP",
|
217 |
|
|
162 => "SNMP-Trap",
|
218 |
|
|
22 => "SSH",
|
219 |
|
|
3478 => "STUN",
|
220 |
76e91d3f
|
Warren Baker
|
587 => "SUBMISSION",
|
221 |
d2c6e89c
|
jim-p
|
514 => "Syslog",
|
222 |
667b2b60
|
Ermal
|
3544 => "Teredo",
|
223 |
|
|
23 => "Telnet",
|
224 |
|
|
69 => "TFTP",
|
225 |
|
|
5900 => "VNC");
|
226 |
|
|
|
227 |
|
|
/* TCP flags */
|
228 |
79cc9e6b
|
bcyrill
|
$tcpflags = array("fin", "syn", "rst", "psh", "ack", "urg", "ece", "cwr");
|
229 |
667b2b60
|
Ermal
|
|
230 |
f49cd725
|
Phil Davis
|
$specialnets = array(
|
231 |
|
|
"(self)" => gettext("This Firewall"),
|
232 |
|
|
"pppoe" => gettext("PPPoE clients"),
|
233 |
|
|
"l2tp" => gettext("L2TP clients"));
|
234 |
667b2b60
|
Ermal
|
|
235 |
f593f80b
|
Phil Davis
|
$spiflist = get_configured_interface_with_descr(true);
|
236 |
667b2b60
|
Ermal
|
foreach ($spiflist as $ifgui => $ifdesc) {
|
237 |
|
|
$specialnets[$ifgui] = $ifdesc . " net";
|
238 |
|
|
$specialnets[$ifgui . 'ip'] = $ifdesc . " address";
|
239 |
|
|
}
|
240 |
|
|
|
241 |
45b4ffc6
|
Phil Davis
|
$medias = array(
|
242 |
f49cd725
|
Phil Davis
|
"auto" => gettext("autoselect"),
|
243 |
|
|
"100full" => gettext("100BASE-TX full-duplex"),
|
244 |
|
|
"100half" => gettext("100BASE-TX half-duplex"),
|
245 |
|
|
"10full" => gettext("10BASE-T full-duplex"),
|
246 |
|
|
"10half" => gettext("10BASE-T half-duplex"));
|
247 |
667b2b60
|
Ermal
|
|
248 |
45b4ffc6
|
Phil Davis
|
$wlan_modes = array(
|
249 |
f49cd725
|
Phil Davis
|
"bss" => gettext("Infrastructure (BSS)"),
|
250 |
|
|
"adhoc" => gettext("Ad-hoc (IBSS)"),
|
251 |
|
|
"hostap" => gettext("Access Point"));
|
252 |
667b2b60
|
Ermal
|
|
253 |
eb4ac13e
|
Renato Botelho
|
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, &$input_errors) {
|
254 |
667b2b60
|
Ermal
|
|
255 |
|
|
/* check for bad control characters */
|
256 |
|
|
foreach ($postdata as $pn => $pd) {
|
257 |
|
|
if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
|
258 |
41602469
|
Luiz Gustavo Costa
|
$input_errors[] = sprintf(gettext("The field %s contains invalid characters."), $pn);
|
259 |
667b2b60
|
Ermal
|
}
|
260 |
|
|
}
|
261 |
|
|
|
262 |
b4e2567f
|
Steve Beaver
|
if (is_array($reqdfields)) {
|
263 |
ce04950d
|
Steve Beaver
|
for ($i = 0; $i < count($reqdfields); $i++) {
|
264 |
|
|
if ($postdata[$reqdfields[$i]] == "") {
|
265 |
|
|
$input_errors[] = sprintf(gettext("The field %s is required."), $reqdfieldsn[$i]);
|
266 |
|
|
}
|
267 |
667b2b60
|
Ermal
|
}
|
268 |
|
|
}
|
269 |
|
|
}
|
270 |
|
|
|
271 |
|
|
function print_input_errors($input_errors) {
|
272 |
c4a7740d
|
Sander van Leeuwen
|
echo '<div class="alert alert-danger input-errors">';
|
273 |
|
|
echo '<p>' . gettext('The following input errors were detected:') . '</p>';
|
274 |
|
|
echo '<ul>';
|
275 |
667b2b60
|
Ermal
|
|
276 |
e28307d0
|
Luiz Gustavo Costa
|
foreach ($input_errors as $ierr) {
|
277 |
c4a7740d
|
Sander van Leeuwen
|
echo '<li>' . htmlspecialchars($ierr) . '</li>';
|
278 |
e28307d0
|
Luiz Gustavo Costa
|
}
|
279 |
667b2b60
|
Ermal
|
|
280 |
c4a7740d
|
Sander van Leeuwen
|
echo '</ul>';
|
281 |
|
|
echo '</div>';
|
282 |
667b2b60
|
Ermal
|
}
|
283 |
|
|
|
284 |
|
|
function verify_gzip_file($fname) {
|
285 |
96ccd009
|
Renato Botelho
|
$returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
|
286 |
45b4ffc6
|
Phil Davis
|
if ($returnvar != 0) {
|
287 |
667b2b60
|
Ermal
|
return 0;
|
288 |
45b4ffc6
|
Phil Davis
|
} else {
|
289 |
667b2b60
|
Ermal
|
return 1;
|
290 |
45b4ffc6
|
Phil Davis
|
}
|
291 |
667b2b60
|
Ermal
|
}
|
292 |
|
|
|
293 |
aa64bb65
|
jim-p
|
// sprint_info_box() returns a string with a formatted informational box, it does not print the box.
|
294 |
|
|
// To format and print in one step, call print_info_box() as usual.
|
295 |
|
|
// Any required button is explicitly created, rather than relying on the detection of certain
|
296 |
65e8424e
|
Phil Davis
|
// strings in the message (such as "apply"). print_info_box_np() has been exterminated.
|
297 |
|
|
// $class = the bootstrap style class (default, info, warning, success, danger)
|
298 |
f14ec73c
|
Stephen Beaver
|
// $btnname and btntext describe the optional button and its display text, the default is an 'x' Close button.
|
299 |
65e8424e
|
Phil Davis
|
// Note that there is also a shortcut function print_apply_box here that creates a standard "apply" box for you.
|
300 |
|
|
// In many cases just substitute that for print_info_box_np() to easily get a warning style "Apply changes" box.
|
301 |
aa64bb65
|
jim-p
|
function sprint_info_box($msg, $class="alert-warning", $btnname = "close", $btntext = "", $btnicon = "", $btnclass = "default") {
|
302 |
667b2b60
|
Ermal
|
|
303 |
aa82505e
|
Phil Davis
|
if (strpos($class, "alert-") !== 0) {
|
304 |
0074384f
|
sbeaver
|
$class = 'alert-' . $class;
|
305 |
aa82505e
|
Phil Davis
|
}
|
306 |
153f09b8
|
Stephen Jones
|
|
307 |
ff916cd2
|
Sander van Leeuwen
|
$msg = '<div class="pull-left">' . $msg . '</div>';
|
308 |
|
|
|
309 |
0d711d38
|
Phil Davis
|
if ($btnname === "close") {
|
310 |
|
|
$msg = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' . $msg;
|
311 |
|
|
} else if ($btnname != "") {
|
312 |
|
|
if (empty($btntext)) {
|
313 |
|
|
$btntext = $btnname;
|
314 |
|
|
}
|
315 |
c0367cb8
|
jim-p
|
if (!empty($btnicon)) {
|
316 |
|
|
$btnicon = '<i class="fa ' . $btnicon . ' icon-embed-btn"></i>';
|
317 |
|
|
}
|
318 |
0d711d38
|
Phil Davis
|
|
319 |
c0367cb8
|
jim-p
|
$msg .= '<form method="post" class="pull-right"><button type="submit" class="btn btn-' . $btnclass . '" name="'. $btnname . '" value="' . $btntext . '">' . $btnicon . $btntext . '</button>';
|
320 |
667b2b60
|
Ermal
|
|
321 |
f9b1c128
|
Steve Beaver
|
if ( isset($_POST['if']) && !empty($_POST['if'])) {
|
322 |
01752a98
|
Sjon Hortensius
|
$msg .= "<input type=\"hidden\" name=\"if\" value=\"" . htmlspecialchars($_POST['if']) . "\" />";
|
323 |
aa82505e
|
Phil Davis
|
}
|
324 |
1180e4f0
|
Sjon Hortensius
|
|
325 |
ff916cd2
|
Sander van Leeuwen
|
$msg .= '</form>';
|
326 |
aa82505e
|
Phil Davis
|
}
|
327 |
667b2b60
|
Ermal
|
|
328 |
aa64bb65
|
jim-p
|
return '<div class="alert ' . $class . ' clearfix" role="alert">' . $msg . '</div>';
|
329 |
|
|
}
|
330 |
|
|
|
331 |
|
|
// Format and print an info box. See sprint_info_box() for details.
|
332 |
|
|
function print_info_box($msg, $class="alert-warning", $btnname = "close", $btntext = "", $btnicon = "", $btnclass = "default") {
|
333 |
|
|
echo sprint_info_box($msg, $class, $btnname, $btntext, $btnicon, $btnclass);
|
334 |
667b2b60
|
Ermal
|
}
|
335 |
|
|
|
336 |
3b3a95e5
|
Phil Davis
|
function print_apply_box($msg) {
|
337 |
c0367cb8
|
jim-p
|
print_info_box($msg, "warning", "apply", gettext("Apply Changes"), 'fa-check', 'success');
|
338 |
667b2b60
|
Ermal
|
}
|
339 |
|
|
|
340 |
44c42356
|
Phil Davis
|
// Format and print a box reporting that changes have been applied
|
341 |
|
|
// $retval = status value from the functions called to apply the changes
|
342 |
|
|
// 0 is good
|
343 |
|
|
// non-zero is a problem
|
344 |
|
|
// $extra_text = optional extra text to display after the standard message
|
345 |
|
|
function print_apply_result_box($retval, $extra_text="") {
|
346 |
|
|
$result_msg = get_std_save_message($retval);
|
347 |
|
|
if ($retval === 0) {
|
348 |
|
|
// 0 is success
|
349 |
|
|
$severity = "success";
|
350 |
|
|
} else {
|
351 |
|
|
// non-zero means there was some problem
|
352 |
|
|
$severity = "warning";
|
353 |
|
|
}
|
354 |
|
|
|
355 |
|
|
if (strlen($extra_text) > 0) {
|
356 |
|
|
$result_msg .= " " . $extra_text;
|
357 |
|
|
}
|
358 |
|
|
print_info_box($result_msg, $severity);
|
359 |
|
|
}
|
360 |
|
|
|
361 |
8c9d0b20
|
k-paulius
|
/*
|
362 |
|
|
* Print Bootstrap callout
|
363 |
|
|
*
|
364 |
|
|
* @param string $msg message to display
|
365 |
|
|
* @param string $class contextual class, defaults to info (default | danger | warning | info)
|
366 |
|
|
* @param string $heading optional callout heading
|
367 |
|
|
*/
|
368 |
|
|
function print_callout($msg, $class = 'info', $heading = '') {
|
369 |
|
|
|
370 |
|
|
if ('' == $msg) {
|
371 |
|
|
return;
|
372 |
|
|
}
|
373 |
|
|
$class = strtolower($class);
|
374 |
|
|
$callout = '';
|
375 |
|
|
|
376 |
b8f62ec2
|
Phil Davis
|
if ($class != 'default' && $class != 'danger' && $class != 'warning' && $class != 'info') {
|
377 |
8c9d0b20
|
k-paulius
|
$class = 'info';
|
378 |
|
|
}
|
379 |
|
|
$callout .= '<div class="bs-callout bs-callout-' . $class . '">';
|
380 |
|
|
|
381 |
|
|
if ('' != $heading) {
|
382 |
|
|
$callout .= '<h4>' . $heading . '</h4>';
|
383 |
|
|
}
|
384 |
|
|
$callout .= $msg . '</div>';
|
385 |
|
|
echo $callout;
|
386 |
|
|
}
|
387 |
|
|
|
388 |
44c42356
|
Phil Davis
|
function get_std_save_message($retval) {
|
389 |
cfaf6e69
|
Scott Ullrich
|
$filter_related = false;
|
390 |
815398fb
|
Phil Davis
|
$filter_pages = array("firewall_aliases", "firewall_nat", "firewall_rules", "status_logs_filter");
|
391 |
44c42356
|
Phil Davis
|
if ($retval === 0) {
|
392 |
|
|
// 0 is success
|
393 |
|
|
$to_return = gettext("The changes have been applied successfully.");
|
394 |
|
|
} else {
|
395 |
|
|
// non-zero means there was some problem
|
396 |
9aa103ba
|
PiBa-NL
|
$to_return = sprintf(gettext('There was a problem applying the changes. See the %1$sSystem Logs%2$s.'), '<a href="status_logs.php">', '</a>');
|
397 |
44c42356
|
Phil Davis
|
}
|
398 |
45b4ffc6
|
Phil Davis
|
foreach ($filter_pages as $fp) {
|
399 |
|
|
if (stristr($_SERVER['SCRIPT_FILENAME'], $fp)) {
|
400 |
96ccd009
|
Renato Botelho
|
$filter_related = true;
|
401 |
45b4ffc6
|
Phil Davis
|
}
|
402 |
|
|
}
|
403 |
|
|
if ($filter_related) {
|
404 |
815398fb
|
Phil Davis
|
$to_return .= " " . gettext("The firewall rules are now reloading in the background.") . "<br />" .
|
405 |
702fa4d0
|
Phil Davis
|
sprintf(gettext('%1$sMonitor%2$s the filter reload progress.'), "<a href='status_filter_reload.php'>", "</a>");
|
406 |
45b4ffc6
|
Phil Davis
|
}
|
407 |
cfaf6e69
|
Scott Ullrich
|
return $to_return;
|
408 |
667b2b60
|
Ermal
|
}
|
409 |
|
|
|
410 |
|
|
function pprint_address($adr) {
|
411 |
|
|
global $specialnets;
|
412 |
|
|
|
413 |
|
|
if (isset($adr['any'])) {
|
414 |
|
|
$padr = "*";
|
415 |
|
|
} else if ($adr['network']) {
|
416 |
|
|
$padr = $specialnets[$adr['network']];
|
417 |
|
|
} else {
|
418 |
|
|
$padr = $adr['address'];
|
419 |
|
|
}
|
420 |
|
|
|
421 |
45b4ffc6
|
Phil Davis
|
if (isset($adr['not'])) {
|
422 |
667b2b60
|
Ermal
|
$padr = "! " . $padr;
|
423 |
45b4ffc6
|
Phil Davis
|
}
|
424 |
667b2b60
|
Ermal
|
|
425 |
|
|
return $padr;
|
426 |
|
|
}
|
427 |
|
|
|
428 |
|
|
function pprint_port($port) {
|
429 |
|
|
global $wkports;
|
430 |
|
|
|
431 |
|
|
$pport = "";
|
432 |
|
|
|
433 |
45b4ffc6
|
Phil Davis
|
if (!$port) {
|
434 |
667b2b60
|
Ermal
|
return "*";
|
435 |
45b4ffc6
|
Phil Davis
|
} else {
|
436 |
667b2b60
|
Ermal
|
$srcport = explode("-", $port);
|
437 |
|
|
if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
|
438 |
|
|
$pport = $srcport[0];
|
439 |
|
|
if ($wkports[$srcport[0]]) {
|
440 |
|
|
$pport .= " (" . $wkports[$srcport[0]] . ")";
|
441 |
|
|
}
|
442 |
45b4ffc6
|
Phil Davis
|
} else {
|
443 |
667b2b60
|
Ermal
|
$pport .= $srcport[0] . " - " . $srcport[1];
|
444 |
45b4ffc6
|
Phil Davis
|
}
|
445 |
667b2b60
|
Ermal
|
}
|
446 |
|
|
|
447 |
|
|
return $pport;
|
448 |
|
|
}
|
449 |
|
|
|
450 |
138e79d4
|
Phil Davis
|
function insert_word_breaks_in_domain_name($domain_name) {
|
451 |
81b1b44a
|
Phil Davis
|
return str_replace('.', '<wbr>.', $domain_name);
|
452 |
138e79d4
|
Phil Davis
|
}
|
453 |
|
|
|
454 |
8e0c3760
|
Ermal
|
function firewall_check_for_advanced_options(&$item) {
|
455 |
96ccd009
|
Renato Botelho
|
$item_set = "";
|
456 |
45b4ffc6
|
Phil Davis
|
if ($item['os']) {
|
457 |
62baf077
|
jim-p
|
$item_set .= "os " . htmlspecialchars($item['os']) . " ";
|
458 |
45b4ffc6
|
Phil Davis
|
}
|
459 |
|
|
if ($item['dscp']) {
|
460 |
62baf077
|
jim-p
|
$item_set .= "dscp " . htmlspecialchars($item['dscp']) . " ";
|
461 |
45b4ffc6
|
Phil Davis
|
}
|
462 |
|
|
if ($item['max']) {
|
463 |
62baf077
|
jim-p
|
$item_set .= "max " . htmlspecialchars($item['max']) . " ";
|
464 |
45b4ffc6
|
Phil Davis
|
}
|
465 |
|
|
if ($item['max-src-nodes']) {
|
466 |
62baf077
|
jim-p
|
$item_set .= "max-src-nodes " . htmlspecialchars($item['max-src-nodes']) . " ";
|
467 |
45b4ffc6
|
Phil Davis
|
}
|
468 |
|
|
if ($item['max-src-conn']) {
|
469 |
62baf077
|
jim-p
|
$item_set .= "max-src-conn " . htmlspecialchars($item['max-src-conn']) . " ";
|
470 |
45b4ffc6
|
Phil Davis
|
}
|
471 |
|
|
if ($item['max-src-states']) {
|
472 |
62baf077
|
jim-p
|
$item_set .= "max-src-states " . htmlspecialchars($item['max-src-states']) . " ";
|
473 |
45b4ffc6
|
Phil Davis
|
}
|
474 |
|
|
if (isset($item['nopfsync'])) {
|
475 |
f0c1ce21
|
Phil Davis
|
$item_set .= "nopfsync ";
|
476 |
45b4ffc6
|
Phil Davis
|
}
|
477 |
|
|
if ($item['statetype'] != "keep state" && $item['statetype'] != "") {
|
478 |
62baf077
|
jim-p
|
$item_set .= "statetype " . htmlspecialchars($item['statetype']) . " ";
|
479 |
45b4ffc6
|
Phil Davis
|
}
|
480 |
|
|
if ($item['statetimeout']) {
|
481 |
62baf077
|
jim-p
|
$item_set .= "statetimeout " . htmlspecialchars($item['statetimeout']) . " ";
|
482 |
45b4ffc6
|
Phil Davis
|
}
|
483 |
|
|
if (isset($item['nosync'])) {
|
484 |
f0c1ce21
|
Phil Davis
|
$item_set .= "no XMLRPC Sync ";
|
485 |
45b4ffc6
|
Phil Davis
|
}
|
486 |
|
|
if ($item['max-src-conn-rate']) {
|
487 |
62baf077
|
jim-p
|
$item_set .= "max-src-conn-rate " . htmlspecialchars($item['max-src-conn-rate']) . " ";
|
488 |
45b4ffc6
|
Phil Davis
|
}
|
489 |
|
|
if ($item['max-src-conn-rates']) {
|
490 |
62baf077
|
jim-p
|
$item_set .= "max-src-conn-rates " . htmlspecialchars($item['max-src-conn-rates']) . " ";
|
491 |
45b4ffc6
|
Phil Davis
|
}
|
492 |
|
|
if ($item['vlanprio']) {
|
493 |
62baf077
|
jim-p
|
$item_set .= "vlanprio " . htmlspecialchars($item['vlanprio']) . " ";
|
494 |
45b4ffc6
|
Phil Davis
|
}
|
495 |
|
|
if ($item['vlanprioset']) {
|
496 |
62baf077
|
jim-p
|
$item_set .= "vlanprioset " . htmlspecialchars($item['vlanprioset']) . " ";
|
497 |
45b4ffc6
|
Phil Davis
|
}
|
498 |
|
|
if ($item['gateway']) {
|
499 |
62baf077
|
jim-p
|
$item_set .= "gateway " . htmlspecialchars($item['gateway']) . " ";
|
500 |
45b4ffc6
|
Phil Davis
|
}
|
501 |
|
|
if ($item['dnpipe']) {
|
502 |
62baf077
|
jim-p
|
$item_set .= "limiter " . htmlspecialchars($item['dnpipe']) . " ";
|
503 |
45b4ffc6
|
Phil Davis
|
}
|
504 |
|
|
if ($item['pdnpipe']) {
|
505 |
62baf077
|
jim-p
|
$item_set .= "limiter " . htmlspecialchars($item['pdnpipe']) . " ";
|
506 |
45b4ffc6
|
Phil Davis
|
}
|
507 |
|
|
if ($item['ackqueue']) {
|
508 |
62baf077
|
jim-p
|
$item_set .= "ackqueue " . htmlspecialchars($item['ackqueue']) . " ";
|
509 |
45b4ffc6
|
Phil Davis
|
}
|
510 |
|
|
if ($item['defaultqueue']) {
|
511 |
62baf077
|
jim-p
|
$item_set .= "defaultqueue " . htmlspecialchars($item['defaultqueue']) . " ";
|
512 |
45b4ffc6
|
Phil Davis
|
}
|
513 |
|
|
if ($item['tag']) {
|
514 |
62baf077
|
jim-p
|
$item_set .= "tag " . htmlspecialchars($item['tag']) . " ";
|
515 |
45b4ffc6
|
Phil Davis
|
}
|
516 |
|
|
if ($item['tagged']) {
|
517 |
62baf077
|
jim-p
|
$item_set .= "tagged " . htmlspecialchars($item['tagged']) . " ";
|
518 |
45b4ffc6
|
Phil Davis
|
}
|
519 |
|
|
if (isset($item['allowopts'])) {
|
520 |
96ccd009
|
Renato Botelho
|
$item_set .= "allowopts ";
|
521 |
45b4ffc6
|
Phil Davis
|
}
|
522 |
|
|
if (isset($item['disablereplyto'])) {
|
523 |
96ccd009
|
Renato Botelho
|
$item_set .= "disable reply-to ";
|
524 |
45b4ffc6
|
Phil Davis
|
}
|
525 |
|
|
if ($item['tcpflags_any'] || $item['tcpflags1'] || $item['tcpflags2']) {
|
526 |
96ccd009
|
Renato Botelho
|
$item_set .= "tcpflags set";
|
527 |
45b4ffc6
|
Phil Davis
|
}
|
528 |
96ccd009
|
Renato Botelho
|
|
529 |
|
|
return $item_set;
|
530 |
8e0c3760
|
Ermal
|
}
|
531 |
|
|
|
532 |
667b2b60
|
Ermal
|
function gentitle($title) {
|
533 |
|
|
global $navlevelsep;
|
534 |
45b4ffc6
|
Phil Davis
|
if (!is_array($title)) {
|
535 |
667b2b60
|
Ermal
|
return $title;
|
536 |
45b4ffc6
|
Phil Davis
|
} else {
|
537 |
667b2b60
|
Ermal
|
return join($navlevelsep, $title);
|
538 |
45b4ffc6
|
Phil Davis
|
}
|
539 |
667b2b60
|
Ermal
|
}
|
540 |
|
|
|
541 |
edcd7535
|
Phil Davis
|
function genhtmltitle($title, $links=true) {
|
542 |
5b943d25
|
Steve Beaver
|
if (is_array($title)) {
|
543 |
|
|
$num_crumbs = count($title);
|
544 |
|
|
} else if ($title != NULL) {
|
545 |
|
|
$num_crumbs = 1;
|
546 |
|
|
} else {
|
547 |
|
|
$num_crumbs = 0;
|
548 |
|
|
}
|
549 |
2d26ee5e
|
Sjon Hortensius
|
|
550 |
2f1f9a98
|
Stephen Beaver
|
// If the array contains only one element, there are no breadcrumbs, so don't
|
551 |
|
|
// add anything else
|
552 |
edcd7535
|
Phil Davis
|
if ($num_crumbs > 1) {
|
553 |
2f1f9a98
|
Stephen Beaver
|
$bc = '<ol class="breadcrumb">';
|
554 |
2d26ee5e
|
Sjon Hortensius
|
|
555 |
edcd7535
|
Phil Davis
|
if (!is_array($links)) {
|
556 |
|
|
$gen_default = ($links === true);
|
557 |
|
|
$links = array_fill(0, $num_crumbs, '');
|
558 |
|
|
// If no links passed, then default to a link to self on the last entry.
|
559 |
|
|
if ($gen_default) {
|
560 |
|
|
$links[$num_crumbs-1] = '@self';
|
561 |
|
|
}
|
562 |
|
|
}
|
563 |
|
|
|
564 |
c50f228a
|
Phil Davis
|
foreach ($title as $idx => $el) {
|
565 |
|
|
$href = $links[$idx];
|
566 |
|
|
if (strlen($href) > 0) {
|
567 |
|
|
// For convenience, if the caller specifies '@self' then make a link
|
568 |
|
|
// to the current page, including any query string.
|
569 |
|
|
if ($href == '@self') {
|
570 |
|
|
$href = $_SERVER['REQUEST_URI'];
|
571 |
|
|
}
|
572 |
|
|
if (substr($href, 0, 1) != '/') {
|
573 |
|
|
$href = '/' . $href;
|
574 |
|
|
}
|
575 |
|
|
$bc .= '<li><a href="' . htmlentities($href) . '">' . $el . '</a></li>';
|
576 |
|
|
} else {
|
577 |
|
|
$bc .= '<li>' . $el . '</li>';
|
578 |
|
|
}
|
579 |
aa82505e
|
Phil Davis
|
}
|
580 |
2d26ee5e
|
Sjon Hortensius
|
|
581 |
2f1f9a98
|
Stephen Beaver
|
$bc .= '</ol>';
|
582 |
|
|
} else {
|
583 |
|
|
$bc = "";
|
584 |
|
|
}
|
585 |
2d26ee5e
|
Sjon Hortensius
|
|
586 |
f93e9098
|
Phil Davis
|
return $bc;
|
587 |
667b2b60
|
Ermal
|
}
|
588 |
|
|
|
589 |
0fc6d49d
|
Phil Davis
|
function gen_customwidgettitle_div($widgettitle) {
|
590 |
|
|
$divstr = '<div class="form-group">';
|
591 |
|
|
$divstr .= ' <label for="descr" class="col-sm-4 control-label">' . gettext('Widget title'). '</label>';
|
592 |
|
|
$divstr .= ' <div class="col-sm-4">';
|
593 |
|
|
$divstr .= ' <input type="text" name="descr" id="descr" value="'. $widgettitle . '" class="form-control" />';
|
594 |
|
|
$divstr .= ' </div>';
|
595 |
|
|
$divstr .= '</div>';
|
596 |
|
|
|
597 |
|
|
return $divstr;
|
598 |
|
|
}
|
599 |
|
|
|
600 |
|
|
function set_customwidgettitle(& $user_settings) {
|
601 |
|
|
if ($_POST['descr']) {
|
602 |
|
|
$user_settings['widgets'][$_POST['widgetkey']]['descr'] = trim($_POST['descr']);
|
603 |
|
|
} else {
|
604 |
|
|
unset($user_settings['widgets'][$_POST['widgetkey']]['descr']);
|
605 |
|
|
}
|
606 |
|
|
}
|
607 |
|
|
|
608 |
667b2b60
|
Ermal
|
/* update the changedesc and changecount(er) variables */
|
609 |
|
|
function update_changedesc($update) {
|
610 |
|
|
global $changedesc;
|
611 |
|
|
global $changecount;
|
612 |
|
|
|
613 |
|
|
$changedesc .= " {$update}";
|
614 |
|
|
$changecount++;
|
615 |
|
|
}
|
616 |
|
|
|
617 |
|
|
/* Check if variable has changed, update and log if it has
|
618 |
|
|
* returns true if var changed
|
619 |
|
|
* varname = variable name in plain text
|
620 |
|
|
* orig = original value
|
621 |
|
|
* new = new value
|
622 |
|
|
*/
|
623 |
|
|
function update_if_changed($varname, & $orig, $new) {
|
624 |
|
|
if (is_array($orig) && is_array($new)) {
|
625 |
|
|
$a_diff = array_diff($orig, $new);
|
626 |
|
|
foreach ($a_diff as $diff) {
|
627 |
|
|
update_changedesc("removed {$varname}: \"{$diff}\"");
|
628 |
|
|
}
|
629 |
|
|
$a_diff = array_diff($new, $orig);
|
630 |
|
|
foreach ($a_diff as $diff) {
|
631 |
|
|
update_changedesc("added {$varname}: \"{$diff}\"");
|
632 |
|
|
}
|
633 |
|
|
$orig = $new;
|
634 |
|
|
return true;
|
635 |
|
|
|
636 |
|
|
} else {
|
637 |
|
|
if ($orig != $new) {
|
638 |
|
|
update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
|
639 |
|
|
$orig = $new;
|
640 |
|
|
return true;
|
641 |
|
|
}
|
642 |
|
|
}
|
643 |
|
|
return false;
|
644 |
|
|
}
|
645 |
|
|
|
646 |
|
|
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
|
647 |
45b4ffc6
|
Phil Davis
|
if (isset($adr['any'])) {
|
648 |
96ccd009
|
Renato Botelho
|
$padr = "any";
|
649 |
45b4ffc6
|
Phil Davis
|
} else if ($adr['network']) {
|
650 |
96ccd009
|
Renato Botelho
|
$padr = $adr['network'];
|
651 |
45b4ffc6
|
Phil Davis
|
} else if ($adr['address']) {
|
652 |
96ccd009
|
Renato Botelho
|
list($padr, $pmask) = explode("/", $adr['address']);
|
653 |
cb2b59b8
|
Renato Botelho
|
if (!$pmask) {
|
654 |
45b4ffc6
|
Phil Davis
|
if (is_ipaddrv6($padr)) {
|
655 |
cb2b59b8
|
Renato Botelho
|
$pmask = 128;
|
656 |
45b4ffc6
|
Phil Davis
|
} else {
|
657 |
cb2b59b8
|
Renato Botelho
|
$pmask = 32;
|
658 |
45b4ffc6
|
Phil Davis
|
}
|
659 |
cb2b59b8
|
Renato Botelho
|
}
|
660 |
96ccd009
|
Renato Botelho
|
}
|
661 |
667b2b60
|
Ermal
|
|
662 |
45b4ffc6
|
Phil Davis
|
if (isset($adr['not'])) {
|
663 |
96ccd009
|
Renato Botelho
|
$pnot = 1;
|
664 |
45b4ffc6
|
Phil Davis
|
} else {
|
665 |
96ccd009
|
Renato Botelho
|
$pnot = 0;
|
666 |
45b4ffc6
|
Phil Davis
|
}
|
667 |
96ccd009
|
Renato Botelho
|
|
668 |
|
|
if ($adr['port']) {
|
669 |
|
|
list($pbeginport, $pendport) = explode("-", $adr['port']);
|
670 |
45b4ffc6
|
Phil Davis
|
if (!$pendport) {
|
671 |
96ccd009
|
Renato Botelho
|
$pendport = $pbeginport;
|
672 |
45b4ffc6
|
Phil Davis
|
}
|
673 |
667b2b60
|
Ermal
|
} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
|
674 |
|
|
$pbeginport = "any";
|
675 |
|
|
$pendport = "any";
|
676 |
96ccd009
|
Renato Botelho
|
}
|
677 |
667b2b60
|
Ermal
|
}
|
678 |
|
|
|
679 |
6c07db48
|
Phil Davis
|
function pconfig_to_address(&$adr, $padr, $pmask, $pnot = false, $pbeginport = 0, $pendport = 0) {
|
680 |
96ccd009
|
Renato Botelho
|
$adr = array();
|
681 |
|
|
|
682 |
45b4ffc6
|
Phil Davis
|
if ($padr == "any") {
|
683 |
96ccd009
|
Renato Botelho
|
$adr['any'] = true;
|
684 |
45b4ffc6
|
Phil Davis
|
} else if (is_specialnet($padr)) {
|
685 |
96ccd009
|
Renato Botelho
|
$adr['network'] = $padr;
|
686 |
45b4ffc6
|
Phil Davis
|
} else {
|
687 |
96ccd009
|
Renato Botelho
|
$adr['address'] = $padr;
|
688 |
cb2b59b8
|
Renato Botelho
|
if (is_ipaddrv6($padr)) {
|
689 |
45b4ffc6
|
Phil Davis
|
if ($pmask != 128) {
|
690 |
cb2b59b8
|
Renato Botelho
|
$adr['address'] .= "/" . $pmask;
|
691 |
45b4ffc6
|
Phil Davis
|
}
|
692 |
cb2b59b8
|
Renato Botelho
|
} else {
|
693 |
45b4ffc6
|
Phil Davis
|
if ($pmask != 32) {
|
694 |
cb2b59b8
|
Renato Botelho
|
$adr['address'] .= "/" . $pmask;
|
695 |
45b4ffc6
|
Phil Davis
|
}
|
696 |
cb2b59b8
|
Renato Botelho
|
}
|
697 |
96ccd009
|
Renato Botelho
|
}
|
698 |
667b2b60
|
Ermal
|
|
699 |
45b4ffc6
|
Phil Davis
|
if ($pnot) {
|
700 |
96ccd009
|
Renato Botelho
|
$adr['not'] = true;
|
701 |
45b4ffc6
|
Phil Davis
|
} else {
|
702 |
96ccd009
|
Renato Botelho
|
unset($adr['not']);
|
703 |
45b4ffc6
|
Phil Davis
|
}
|
704 |
96ccd009
|
Renato Botelho
|
|
705 |
|
|
if (($pbeginport != 0) && ($pbeginport != "any")) {
|
706 |
45b4ffc6
|
Phil Davis
|
if ($pbeginport != $pendport) {
|
707 |
96ccd009
|
Renato Botelho
|
$adr['port'] = $pbeginport . "-" . $pendport;
|
708 |
45b4ffc6
|
Phil Davis
|
} else {
|
709 |
96ccd009
|
Renato Botelho
|
$adr['port'] = $pbeginport;
|
710 |
45b4ffc6
|
Phil Davis
|
}
|
711 |
96ccd009
|
Renato Botelho
|
}
|
712 |
|
|
|
713 |
885e9b2a
|
jim-p
|
/*
|
714 |
|
|
* If the port is still unset, then it must not be numeric, but could
|
715 |
|
|
* be an alias or a well-known/registered service.
|
716 |
|
|
* See https://redmine.pfsense.org/issues/8410
|
717 |
|
|
*/
|
718 |
|
|
if (!isset($adr['port']) && is_port_or_alias($pbeginport)) {
|
719 |
96ccd009
|
Renato Botelho
|
$adr['port'] = $pbeginport;
|
720 |
|
|
}
|
721 |
667b2b60
|
Ermal
|
}
|
722 |
|
|
|
723 |
|
|
function is_specialnet($net) {
|
724 |
96ccd009
|
Renato Botelho
|
global $specialsrcdst;
|
725 |
667b2b60
|
Ermal
|
|
726 |
45b4ffc6
|
Phil Davis
|
if (!$net) {
|
727 |
96ccd009
|
Renato Botelho
|
return false;
|
728 |
45b4ffc6
|
Phil Davis
|
}
|
729 |
|
|
if (in_array($net, $specialsrcdst)) {
|
730 |
96ccd009
|
Renato Botelho
|
return true;
|
731 |
45b4ffc6
|
Phil Davis
|
} else {
|
732 |
667b2b60
|
Ermal
|
return false;
|
733 |
45b4ffc6
|
Phil Davis
|
}
|
734 |
667b2b60
|
Ermal
|
}
|
735 |
|
|
|
736 |
|
|
//function to create widget tabs when called
|
737 |
96ccd009
|
Renato Botelho
|
function display_widget_tabs(& $tab_array) {
|
738 |
f326b978
|
Colin Fleming
|
echo "<div id=\"tabs\">";
|
739 |
667b2b60
|
Ermal
|
$tabscounter = 0;
|
740 |
|
|
foreach ($tab_array as $ta) {
|
741 |
6c07db48
|
Phil Davis
|
$dashpos = strpos($ta[2], '-');
|
742 |
45b4ffc6
|
Phil Davis
|
$tabname = $ta[2] . "-tab";
|
743 |
6c07db48
|
Phil Davis
|
$tabclass = substr($ta[2], 0, $dashpos);
|
744 |
45b4ffc6
|
Phil Davis
|
$tabclass = $tabclass . "-class";
|
745 |
667b2b60
|
Ermal
|
if ($ta[1] == true) {
|
746 |
|
|
$tabActive = "table-cell";
|
747 |
|
|
$tabNonActive = "none";
|
748 |
45b4ffc6
|
Phil Davis
|
} else {
|
749 |
667b2b60
|
Ermal
|
$tabActive = "none";
|
750 |
|
|
$tabNonActive = "table-cell";
|
751 |
|
|
}
|
752 |
f326b978
|
Colin Fleming
|
echo "<div id=\"{$ta[2]}-active\" class=\"{$tabclass}-tabactive\" style=\"display:{$tabActive}; background-color:#EEEEEE; color:black;\">";
|
753 |
|
|
echo "<b> {$ta[0]}";
|
754 |
|
|
echo " </b>";
|
755 |
667b2b60
|
Ermal
|
echo "</div>";
|
756 |
f326b978
|
Colin Fleming
|
|
757 |
|
|
echo "<div id=\"{$ta[2]}-deactive\" class=\"{$tabclass}-tabdeactive\" style=\"display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;\" onclick=\"return changeTabDIV('{$ta[2]}')\">";
|
758 |
|
|
echo "<b> {$ta[0]}";
|
759 |
|
|
echo " </b>";
|
760 |
667b2b60
|
Ermal
|
echo "</div>";
|
761 |
|
|
}
|
762 |
|
|
echo "</div>";
|
763 |
|
|
}
|
764 |
|
|
|
765 |
|
|
|
766 |
45b4ffc6
|
Phil Davis
|
// Return inline javascript file or CSS to minimize
|
767 |
667b2b60
|
Ermal
|
// request count going back to server.
|
768 |
|
|
function outputJavaScriptFileInline($javascript) {
|
769 |
45b4ffc6
|
Phil Davis
|
if (file_exists($javascript)) {
|
770 |
667b2b60
|
Ermal
|
echo "\n<script type=\"text/javascript\">\n";
|
771 |
86573bb9
|
Phil Davis
|
include_once($javascript);
|
772 |
667b2b60
|
Ermal
|
echo "\n</script>\n";
|
773 |
|
|
} else {
|
774 |
45b4ffc6
|
Phil Davis
|
echo "\n\n<!-- Could not locate file: {$javascript} -->\n\n";
|
775 |
667b2b60
|
Ermal
|
}
|
776 |
|
|
}
|
777 |
|
|
|
778 |
|
|
|
779 |
|
|
|
780 |
|
|
function outputCSSPrintFileInline($css) {
|
781 |
45b4ffc6
|
Phil Davis
|
if (file_exists($css)) {
|
782 |
667b2b60
|
Ermal
|
echo "\n<style media=\"print\" type=\"text/css\">\n";
|
783 |
86573bb9
|
Phil Davis
|
include_once($css);
|
784 |
667b2b60
|
Ermal
|
echo "\n</style>\n";
|
785 |
|
|
} else {
|
786 |
45b4ffc6
|
Phil Davis
|
echo "\n\n<!-- Could not locate file: {$css} -->\n\n";
|
787 |
667b2b60
|
Ermal
|
}
|
788 |
|
|
}
|
789 |
|
|
|
790 |
|
|
|
791 |
|
|
function outputCSSFileInline($css) {
|
792 |
45b4ffc6
|
Phil Davis
|
if (file_exists($css)) {
|
793 |
667b2b60
|
Ermal
|
echo "\n<style type=\"text/css\">\n";
|
794 |
86573bb9
|
Phil Davis
|
include_once($css);
|
795 |
667b2b60
|
Ermal
|
echo "\n</style>\n";
|
796 |
|
|
} else {
|
797 |
45b4ffc6
|
Phil Davis
|
echo "\n\n<!-- Could not locate file: {$css} -->\n\n";
|
798 |
667b2b60
|
Ermal
|
}
|
799 |
|
|
}
|
800 |
|
|
|
801 |
|
|
$rfc2616 = array(
|
802 |
|
|
100 => "100 Continue",
|
803 |
|
|
101 => "101 Switching Protocols",
|
804 |
|
|
200 => "200 OK",
|
805 |
|
|
201 => "201 Created",
|
806 |
|
|
202 => "202 Accepted",
|
807 |
|
|
203 => "203 Non-Authoritative Information",
|
808 |
|
|
204 => "204 No Content",
|
809 |
|
|
205 => "205 Reset Content",
|
810 |
|
|
206 => "206 Partial Content",
|
811 |
|
|
300 => "300 Multiple Choices",
|
812 |
|
|
301 => "301 Moved Permanently",
|
813 |
|
|
302 => "302 Found",
|
814 |
|
|
303 => "303 See Other",
|
815 |
|
|
304 => "304 Not Modified",
|
816 |
|
|
305 => "305 Use Proxy",
|
817 |
|
|
306 => "306 (Unused)",
|
818 |
|
|
307 => "307 Temporary Redirect",
|
819 |
|
|
400 => "400 Bad Request",
|
820 |
|
|
401 => "401 Unauthorized",
|
821 |
|
|
402 => "402 Payment Required",
|
822 |
|
|
403 => "403 Forbidden",
|
823 |
|
|
404 => "404 Not Found",
|
824 |
|
|
405 => "405 Method Not Allowed",
|
825 |
|
|
406 => "406 Not Acceptable",
|
826 |
|
|
407 => "407 Proxy Authentication Required",
|
827 |
|
|
408 => "408 Request Timeout",
|
828 |
|
|
409 => "409 Conflict",
|
829 |
|
|
410 => "410 Gone",
|
830 |
|
|
411 => "411 Length Required",
|
831 |
|
|
412 => "412 Precondition Failed",
|
832 |
|
|
413 => "413 Request Entity Too Large",
|
833 |
|
|
414 => "414 Request-URI Too Long",
|
834 |
|
|
415 => "415 Unsupported Media Type",
|
835 |
|
|
416 => "416 Requested Range Not Satisfiable",
|
836 |
|
|
417 => "417 Expectation Failed",
|
837 |
|
|
500 => "500 Internal Server Error",
|
838 |
|
|
501 => "501 Not Implemented",
|
839 |
|
|
502 => "502 Bad Gateway",
|
840 |
|
|
503 => "503 Service Unavailable",
|
841 |
|
|
504 => "504 Gateway Timeout",
|
842 |
|
|
505 => "505 HTTP Version Not Supported"
|
843 |
|
|
);
|
844 |
|
|
|
845 |
|
|
function is_rfc2616_code($code) {
|
846 |
|
|
global $rfc2616;
|
847 |
45b4ffc6
|
Phil Davis
|
if (isset($rfc2616[$code])) {
|
848 |
667b2b60
|
Ermal
|
return true;
|
849 |
45b4ffc6
|
Phil Davis
|
} else {
|
850 |
667b2b60
|
Ermal
|
return false;
|
851 |
45b4ffc6
|
Phil Davis
|
}
|
852 |
667b2b60
|
Ermal
|
}
|
853 |
|
|
|
854 |
45b4ffc6
|
Phil Davis
|
function print_rfc2616_select($tag, $current) {
|
855 |
667b2b60
|
Ermal
|
global $rfc2616;
|
856 |
|
|
|
857 |
|
|
/* Default to 200 OK if not set */
|
858 |
45b4ffc6
|
Phil Davis
|
if ($current == "") {
|
859 |
667b2b60
|
Ermal
|
$current = 200;
|
860 |
45b4ffc6
|
Phil Davis
|
}
|
861 |
667b2b60
|
Ermal
|
|
862 |
96ccd009
|
Renato Botelho
|
echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";
|
863 |
45b4ffc6
|
Phil Davis
|
foreach ($rfc2616 as $code => $message) {
|
864 |
667b2b60
|
Ermal
|
if ($code == $current) {
|
865 |
c4b60a9a
|
Colin Fleming
|
$sel = " selected";
|
866 |
667b2b60
|
Ermal
|
} else {
|
867 |
|
|
$sel = "";
|
868 |
|
|
}
|
869 |
|
|
echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
|
870 |
|
|
}
|
871 |
3f08e7ab
|
Colin Fleming
|
echo "</select>\n";
|
872 |
667b2b60
|
Ermal
|
}
|
873 |
|
|
|
874 |
|
|
// Useful debugging function, much cleaner than print_r
|
875 |
6c07db48
|
Phil Davis
|
function echo_array($array, $return_me = false) {
|
876 |
45b4ffc6
|
Phil Davis
|
if (is_array($array) == false) {
|
877 |
96ccd009
|
Renato Botelho
|
$return = "The provided variable is not an array.";
|
878 |
45b4ffc6
|
Phil Davis
|
} else {
|
879 |
|
|
foreach ($array as $name=>$value) {
|
880 |
|
|
if (is_array($value)) {
|
881 |
96ccd009
|
Renato Botelho
|
$return .= "";
|
882 |
|
|
$return .= "['<b>$name</b>'] {<div style=\"margin-left:10px;\">\n";
|
883 |
6c07db48
|
Phil Davis
|
$return .= echo_array($value, true);
|
884 |
96ccd009
|
Renato Botelho
|
$return .= "</div>}";
|
885 |
|
|
$return .= "\n\n";
|
886 |
45b4ffc6
|
Phil Davis
|
} else {
|
887 |
|
|
if (is_string($value)) {
|
888 |
96ccd009
|
Renato Botelho
|
$value = "\"$value\"";
|
889 |
|
|
}
|
890 |
|
|
$return .= "['<b>$name</b>'] = $value\n\n";
|
891 |
|
|
}
|
892 |
|
|
}
|
893 |
|
|
}
|
894 |
45b4ffc6
|
Phil Davis
|
if ($return_me == true) {
|
895 |
96ccd009
|
Renato Botelho
|
return $return;
|
896 |
45b4ffc6
|
Phil Davis
|
} else {
|
897 |
96ccd009
|
Renato Botelho
|
echo "<pre>".$return."</pre>";
|
898 |
|
|
}
|
899 |
667b2b60
|
Ermal
|
}
|
900 |
|
|
|
901 |
|
|
/****f* pfsense-utils/display_top_tabs
|
902 |
|
|
* NAME
|
903 |
0074384f
|
sbeaver
|
* display_top_tabs - display tabs with rounded edges
|
904 |
667b2b60
|
Ermal
|
* INPUTS
|
905 |
0074384f
|
sbeaver
|
* $text - array of tabs
|
906 |
667b2b60
|
Ermal
|
* RESULT
|
907 |
0074384f
|
sbeaver
|
* null
|
908 |
667b2b60
|
Ermal
|
******/
|
909 |
e3947e77
|
Steve Beaver
|
function display_top_tabs(& $tab_array, $no_drop_down = false, $type = 'pills', $usepost = "") {
|
910 |
96ccd009
|
Renato Botelho
|
global $config;
|
911 |
|
|
global $g;
|
912 |
|
|
global $tab_array_indent;
|
913 |
|
|
global $tab_array_space;
|
914 |
|
|
global $tab_array_char_limit;
|
915 |
|
|
|
916 |
0074384f
|
sbeaver
|
/* does the user have access to this tab?
|
917 |
|
|
* master user has access to everything.
|
918 |
|
|
* if the user does not have access, simply
|
919 |
|
|
* unset the tab item.
|
920 |
96ccd009
|
Renato Botelho
|
*/
|
921 |
|
|
|
922 |
|
|
/* empty string code */
|
923 |
|
|
if ($tab_array_indent == '') {
|
924 |
|
|
$tab_array_indent = 0;
|
925 |
|
|
}
|
926 |
620ac186
|
Scott Ullrich
|
|
927 |
96ccd009
|
Renato Botelho
|
if ($tab_array_space == '') {
|
928 |
|
|
$tab_array_space = 1;
|
929 |
|
|
}
|
930 |
620ac186
|
Scott Ullrich
|
|
931 |
96ccd009
|
Renato Botelho
|
if ($tab_array_char_limit == '') {
|
932 |
5f63cb40
|
Steve Beaver
|
$tab_array_char_limit = 256;
|
933 |
96ccd009
|
Renato Botelho
|
}
|
934 |
667b2b60
|
Ermal
|
|
935 |
45b4ffc6
|
Phil Davis
|
foreach ($tab_array as $tab_id => $ta) {
|
936 |
|
|
if (!isAllowedPage($ta[2])) {
|
937 |
96ccd009
|
Renato Botelho
|
unset ($tab_array[$tab_id]);
|
938 |
45b4ffc6
|
Phil Davis
|
}
|
939 |
96ccd009
|
Renato Botelho
|
}
|
940 |
667b2b60
|
Ermal
|
|
941 |
0074384f
|
sbeaver
|
$tab_active_bg = "#EEEEEE";
|
942 |
96ccd009
|
Renato Botelho
|
$tab_inactive_bg = "#777777";
|
943 |
|
|
$nifty_tabs_corners = "#FFF";
|
944 |
|
|
$font_color = "white";
|
945 |
|
|
|
946 |
|
|
$tabcharcount = 0;
|
947 |
aa82505e
|
Phil Davis
|
foreach ($tab_array as $ta) {
|
948 |
96ccd009
|
Renato Botelho
|
$tabcharcount = $tabcharcount + strlen($ta[0]);
|
949 |
aa82505e
|
Phil Davis
|
}
|
950 |
620ac186
|
Scott Ullrich
|
|
951 |
ecffb0bb
|
Phil Davis
|
if ($no_drop_down == true) {
|
952 |
96ccd009
|
Renato Botelho
|
$tabcharcount = 0;
|
953 |
|
|
unset($tab_array_char_limit);
|
954 |
|
|
}
|
955 |
|
|
|
956 |
|
|
// If the character count of the tab names is > 670
|
957 |
|
|
// then show a select item dropdown menubox.
|
958 |
02e2825a
|
Stephen Beaver
|
if ($tabcharcount > $tab_array_char_limit) {
|
959 |
e28307d0
|
Luiz Gustavo Costa
|
echo gettext("Currently viewing: ");
|
960 |
96ccd009
|
Renato Botelho
|
echo "<select name=\"TabSelect\" onchange=\"tabs_will_go(this)\">\n";
|
961 |
02e2825a
|
Stephen Beaver
|
|
962 |
96ccd009
|
Renato Botelho
|
foreach ($tab_array as $ta) {
|
963 |
aa82505e
|
Phil Davis
|
if ($ta[1] == "true") {
|
964 |
c4b60a9a
|
Colin Fleming
|
$selected = " selected";
|
965 |
aa82505e
|
Phil Davis
|
} else {
|
966 |
96ccd009
|
Renato Botelho
|
$selected = "";
|
967 |
aa82505e
|
Phil Davis
|
}
|
968 |
96ccd009
|
Renato Botelho
|
// Onclick in option will not work in some browser
|
969 |
|
|
// echo "<option onclick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
|
970 |
|
|
echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
|
971 |
|
|
}
|
972 |
02e2825a
|
Stephen Beaver
|
|
973 |
96ccd009
|
Renato Botelho
|
echo "</select>\n<p> </p>";
|
974 |
|
|
echo "<script type=\"text/javascript\">";
|
975 |
|
|
echo "\n//<![CDATA[\n";
|
976 |
b8ad7df3
|
Phil Davis
|
if ($usepost == 'usepost') {
|
977 |
|
|
echo " function tabs_will_go(obj){ var target = obj.value.split(\"?\"); postSubmit(get2post(target[1]),target[0]); }\n";
|
978 |
|
|
} else {
|
979 |
|
|
echo " function tabs_will_go(obj){ document.location = obj.value; }\n";
|
980 |
|
|
}
|
981 |
96ccd009
|
Renato Botelho
|
echo "//]]>\n";
|
982 |
|
|
echo "</script>";
|
983 |
02e2825a
|
Stephen Beaver
|
} else {
|
984 |
|
|
echo '<ul class="nav nav-' . $type . '">';
|
985 |
|
|
|
986 |
|
|
foreach ($tab_array as $ta) {
|
987 |
|
|
echo '<li role="presentation"';
|
988 |
|
|
if ($ta[1]) {
|
989 |
|
|
echo ' class="active"';
|
990 |
|
|
}
|
991 |
|
|
|
992 |
e3947e77
|
Steve Beaver
|
echo '><a href="' . $ta[2] . '" ' . $usepost . '>' . $ta[0] . '</a></li>';
|
993 |
02e2825a
|
Stephen Beaver
|
}
|
994 |
|
|
|
995 |
|
|
echo '</ul>';
|
996 |
|
|
}
|
997 |
667b2b60
|
Ermal
|
}
|
998 |
|
|
|
999 |
a2b0d909
|
Renato Botelho
|
function add_package_tabs($tabgroup, &$tab_array) {
|
1000 |
96ccd009
|
Renato Botelho
|
global $config, $g;
|
1001 |
|
|
|
1002 |
a2b0d909
|
Renato Botelho
|
if (!isset($config['installedpackages']['package'])) {
|
1003 |
96ccd009
|
Renato Botelho
|
return;
|
1004 |
45b4ffc6
|
Phil Davis
|
}
|
1005 |
253b37d8
|
Renato Botelho
|
|
1006 |
aa82505e
|
Phil Davis
|
foreach ($config['installedpackages']['package'] as $pkg) {
|
1007 |
bc0661b7
|
PiBa-NL
|
if (!is_array($pkg['tabs']['tab'])) {
|
1008 |
a2b0d909
|
Renato Botelho
|
continue;
|
1009 |
|
|
}
|
1010 |
96ccd009
|
Renato Botelho
|
|
1011 |
bc0661b7
|
PiBa-NL
|
foreach ($pkg['tabs']['tab'] as $tab) {
|
1012 |
|
|
if ($tab['tabgroup'] != $tabgroup) {
|
1013 |
|
|
continue;
|
1014 |
|
|
}
|
1015 |
a2b0d909
|
Renato Botelho
|
$tab_entry = array();
|
1016 |
|
|
if ($tab['name']) {
|
1017 |
|
|
$tab_entry[] = $tab['name'];
|
1018 |
|
|
$tab_entry[] = false;
|
1019 |
|
|
$tab_entry[] = $tab['url'];
|
1020 |
|
|
$tab_array[] = $tab_entry;
|
1021 |
|
|
}
|
1022 |
96ccd009
|
Renato Botelho
|
}
|
1023 |
|
|
}
|
1024 |
667b2b60
|
Ermal
|
}
|
1025 |
|
|
|
1026 |
45b4ffc6
|
Phil Davis
|
function alias_info_popup($alias_id) {
|
1027 |
d9058974
|
Phil Davis
|
global $config, $user_settings;
|
1028 |
3b2c83b8
|
Sjon Hortensius
|
|
1029 |
aa82505e
|
Phil Davis
|
if (!is_array($config['aliases']['alias'][$alias_id])) {
|
1030 |
3b2c83b8
|
Sjon Hortensius
|
return;
|
1031 |
aa82505e
|
Phil Davis
|
}
|
1032 |
3b2c83b8
|
Sjon Hortensius
|
|
1033 |
4e8854c6
|
Charlie Root
|
$maxlength = 60;
|
1034 |
3b2c83b8
|
Sjon Hortensius
|
$alias = $config['aliases']['alias'][$alias_id];
|
1035 |
|
|
$content = "";
|
1036 |
|
|
|
1037 |
d9058974
|
Phil Davis
|
if ($user_settings['webgui']['disablealiaspopupdetail']) {
|
1038 |
|
|
if (strlen($alias['descr']) >= $maxlength) {
|
1039 |
|
|
$alias['descr'] = substr($alias['descr'], 0, $maxlength) . '…';
|
1040 |
|
|
}
|
1041 |
|
|
|
1042 |
|
|
$content .= $alias['descr'];
|
1043 |
|
|
} else if ($alias['url']) {
|
1044 |
3b2c83b8
|
Sjon Hortensius
|
// TODO: Change it when pf supports tables with ports
|
1045 |
|
|
if ($alias['type'] == "urltable") {
|
1046 |
|
|
exec("/sbin/pfctl -t {$alias['name']} -T show | wc -l", $total_entries);
|
1047 |
aa82505e
|
Phil Davis
|
$counter=preg_replace("/\D/", "", $total_entries[0]);
|
1048 |
3b2c83b8
|
Sjon Hortensius
|
exec("/sbin/pfctl -t {$alias['name']} -T show | head -10002", $alias_addresses);
|
1049 |
|
|
} else {
|
1050 |
|
|
$urlfn = alias_expand_urltable($alias['name']);
|
1051 |
|
|
$alias_addresses = explode("\n", file_get_contents($urlfn));
|
1052 |
|
|
$counter = count($alias_addresses);
|
1053 |
4e8854c6
|
Charlie Root
|
}
|
1054 |
aa82505e
|
Phil Davis
|
|
1055 |
abb00412
|
heper
|
$content .= '<h5>'. $alias['url'] .'</h5><ul><li>'. implode('</li><li>', $alias_addresses) .'</li></ul>';
|
1056 |
aa82505e
|
Phil Davis
|
if ($counter > 10002) {
|
1057 |
3b2c83b8
|
Sjon Hortensius
|
$content .= '<i>'. gettext("listing only first 10k items") .'</i>';
|
1058 |
aa82505e
|
Phil Davis
|
}
|
1059 |
|
|
} else {
|
1060 |
3b2c83b8
|
Sjon Hortensius
|
$alias_addresses = explode (" ", $alias['address']);
|
1061 |
|
|
$alias_details = explode ("||", $alias['detail']);
|
1062 |
8b53fe2f
|
Stephen Beaver
|
$idx = 0;
|
1063 |
|
|
|
1064 |
|
|
$content .= "<table>\n";
|
1065 |
|
|
$content .= "<thead>\n";
|
1066 |
|
|
$content .= "<tr>\n";
|
1067 |
|
|
$content .= "<th>" . gettext("Value") . "</th><th style='padding-left: 10px;'>" . gettext("Description") . "</th></tr>\n";
|
1068 |
|
|
$content .= "</thead>\n";
|
1069 |
|
|
$content .= "<tbody>\n";
|
1070 |
|
|
|
1071 |
|
|
foreach ($alias_addresses as $ap) {
|
1072 |
|
|
$content .= " <tr>\n";
|
1073 |
|
|
$content .= " <td>\n";
|
1074 |
c91be02b
|
Viktor G
|
$content .= alias_idn_to_utf8($ap);
|
1075 |
8b53fe2f
|
Stephen Beaver
|
$content .= " </td>\n";
|
1076 |
|
|
$content .= " <td style='padding-left: 10px;'>\n";
|
1077 |
f14ec73c
|
Stephen Beaver
|
$content .= htmlspecialchars($alias_details[$idx]);
|
1078 |
8b53fe2f
|
Stephen Beaver
|
$content .= " </td>\n";
|
1079 |
|
|
$content .= " </tr>\n";
|
1080 |
|
|
$idx++;
|
1081 |
|
|
}
|
1082 |
3b2c83b8
|
Sjon Hortensius
|
|
1083 |
8b53fe2f
|
Stephen Beaver
|
$content .= "</tbody>\n";
|
1084 |
72f4fb2c
|
Steve Beaver
|
$content .= "</table>\n";
|
1085 |
3b2c83b8
|
Sjon Hortensius
|
}
|
1086 |
|
|
|
1087 |
|
|
return $content;
|
1088 |
4e8854c6
|
Charlie Root
|
}
|
1089 |
|
|
|
1090 |
e912f0cf
|
Viktor G
|
function gateway_info_popup($showgw) {
|
1091 |
|
|
global $config, $user_settings;
|
1092 |
|
|
|
1093 |
ad4021d6
|
Viktor G
|
init_config_arr(array('gateways', 'gateway_group'));
|
1094 |
e912f0cf
|
Viktor G
|
$a_gateways = return_gateways_array();
|
1095 |
|
|
$gateways_status = return_gateways_status(true);
|
1096 |
ad4021d6
|
Viktor G
|
|
1097 |
|
|
$content = "";
|
1098 |
e912f0cf
|
Viktor G
|
$gws = array();
|
1099 |
ad4021d6
|
Viktor G
|
$bgdanger = array('force_down', 'down', 'highloss', 'highdelay');
|
1100 |
|
|
$bgwarning = array('loss', 'delay');
|
1101 |
|
|
$bgsuccess = array('none');
|
1102 |
|
|
$bgcolor = "bg-info";
|
1103 |
|
|
|
1104 |
e912f0cf
|
Viktor G
|
if (is_array($a_gateways)) {
|
1105 |
|
|
foreach ($a_gateways as $i => $gateway) {
|
1106 |
|
|
if ($gateway['name'] == $showgw) {
|
1107 |
|
|
$gws[] = $gateway['name'];
|
1108 |
ad4021d6
|
Viktor G
|
}
|
1109 |
|
|
}
|
1110 |
|
|
}
|
1111 |
|
|
if (is_array($config['gateways']['gateway_group'])) {
|
1112 |
|
|
foreach($config['gateways']['gateway_group'] as $gwgroup) {
|
1113 |
e912f0cf
|
Viktor G
|
if ($gwgroup['name'] == $showgw) {
|
1114 |
ad4021d6
|
Viktor G
|
foreach ($gwgroup['item'] as $member) {
|
1115 |
|
|
$membersplit = explode("|", $member);
|
1116 |
96e6e165
|
Viktor G
|
$gws[] = $membersplit[0];
|
1117 |
ad4021d6
|
Viktor G
|
}
|
1118 |
|
|
}
|
1119 |
|
|
}
|
1120 |
|
|
}
|
1121 |
|
|
|
1122 |
e912f0cf
|
Viktor G
|
if (!empty($gws)) {
|
1123 |
ad4021d6
|
Viktor G
|
$content .= "<table>\n";
|
1124 |
|
|
$content .= "<thead>\n";
|
1125 |
|
|
$content .= "<tr>\n";
|
1126 |
|
|
$content .= "<th>" . gettext("Name") . "</th><th style='padding-left: 10px;'>" . gettext("Interface") . "</th>";
|
1127 |
|
|
$content .= "<th style='padding-left: 10px;'>" . gettext("Gateway") . "</th></tr>\n";
|
1128 |
|
|
$content .= "</thead>\n";
|
1129 |
|
|
$content .= "<tbody>\n";
|
1130 |
e912f0cf
|
Viktor G
|
foreach ($gws as $gw) {
|
1131 |
ad4021d6
|
Viktor G
|
foreach ($gateways_status as $gwstatus) {
|
1132 |
|
|
if ($gwstatus['name'] == $gw) {
|
1133 |
|
|
if (in_array($gwstatus['status'], $bgdanger)) {
|
1134 |
|
|
$bgcolor = "bg-danger";
|
1135 |
|
|
} elseif (in_array($gwstatus['status'], $bgwarning)) {
|
1136 |
|
|
$bgcolor = "bg-warning";
|
1137 |
|
|
} elseif (in_array($gwstatus['status'], $bgsuccess)) {
|
1138 |
|
|
$bgcolor = "bg-success";
|
1139 |
|
|
} else {
|
1140 |
|
|
$bgcolor = "bg-info";
|
1141 |
|
|
}
|
1142 |
|
|
}
|
1143 |
|
|
}
|
1144 |
|
|
$content .= " <tr class='{$bgcolor}'>\n";
|
1145 |
|
|
$content .= " <td>\n";
|
1146 |
|
|
$content .= $gw;
|
1147 |
|
|
$content .= " </td>\n";
|
1148 |
|
|
$content .= " <td style='padding-left: 10px;'>\n";
|
1149 |
|
|
$content .= $config['interfaces'][lookup_gateway_interface_by_name($gw)]['descr'];
|
1150 |
|
|
$content .= " </td>\n";
|
1151 |
|
|
$content .= " <td style='padding-left: 10px;'>\n";
|
1152 |
|
|
$content .= lookup_gateway_ip_by_name($gw);
|
1153 |
|
|
$content .= " </td>\n";
|
1154 |
|
|
$content .= " </tr>\n";
|
1155 |
|
|
$idx++;
|
1156 |
|
|
}
|
1157 |
|
|
$content .= "</tbody>\n";
|
1158 |
4e9467ae
|
Steve Beaver
|
$content .= "</table>\n";
|
1159 |
e912f0cf
|
Viktor G
|
} else {
|
1160 |
|
|
return;
|
1161 |
ad4021d6
|
Viktor G
|
}
|
1162 |
|
|
|
1163 |
|
|
return $content;
|
1164 |
|
|
}
|
1165 |
|
|
|
1166 |
7e752d72
|
Phil Davis
|
function rule_columns_with_alias($src, $srcport, $dst, $dstport, $target="", $targetport="") {
|
1167 |
3b2c83b8
|
Sjon Hortensius
|
global $config;
|
1168 |
|
|
|
1169 |
aa82505e
|
Phil Davis
|
if ($config['aliases']['alias'] == "" || !is_array($config['aliases']['alias'])) {
|
1170 |
3b2c83b8
|
Sjon Hortensius
|
return;
|
1171 |
aa82505e
|
Phil Davis
|
}
|
1172 |
3b2c83b8
|
Sjon Hortensius
|
|
1173 |
|
|
$columns = array();
|
1174 |
ecffb0bb
|
Phil Davis
|
foreach ($config['aliases']['alias'] as $alias_id => $alias_name) {
|
1175 |
aa82505e
|
Phil Davis
|
if ($alias_name['name'] == $src) {
|
1176 |
3b2c83b8
|
Sjon Hortensius
|
$columns['src'] = $alias_id;
|
1177 |
aa82505e
|
Phil Davis
|
}
|
1178 |
|
|
if ($alias_name['name'] == $srcport) {
|
1179 |
3b2c83b8
|
Sjon Hortensius
|
$columns['srcport'] = $alias_id;
|
1180 |
aa82505e
|
Phil Davis
|
}
|
1181 |
|
|
if ($alias_name['name'] == $dst) {
|
1182 |
3b2c83b8
|
Sjon Hortensius
|
$columns['dst'] = $alias_id;
|
1183 |
aa82505e
|
Phil Davis
|
}
|
1184 |
|
|
if ($alias_name['name'] == $dstport) {
|
1185 |
3b2c83b8
|
Sjon Hortensius
|
$columns['dstport'] = $alias_id;
|
1186 |
aa82505e
|
Phil Davis
|
}
|
1187 |
474e70a2
|
Stephen Beaver
|
if ($alias_name['name'] == $target) {
|
1188 |
|
|
$columns['target'] = $alias_id;
|
1189 |
|
|
}
|
1190 |
|
|
if ($alias_name['name'] == $targetport) {
|
1191 |
|
|
$columns['targetport'] = $alias_id;
|
1192 |
|
|
}
|
1193 |
96ccd009
|
Renato Botelho
|
}
|
1194 |
e27eac0c
|
Stephen Beaver
|
|
1195 |
|
|
return $columns;
|
1196 |
667b2b60
|
Ermal
|
}
|
1197 |
|
|
|
1198 |
ecffb0bb
|
Phil Davis
|
function form_output_row($name, $label, $content) {
|
1199 |
7d5b007c
|
Sjon Hortensius
|
var_dump($content);die;
|
1200 |
|
|
?>
|
1201 |
|
|
<div class="form-group">
|
1202 |
|
|
<label for="<?=$name?>" class="col-sm-2 control-label"><?=gettext($label); ?></label>
|
1203 |
|
|
<div class="col-sm-10">
|
1204 |
|
|
<?=$content?>
|
1205 |
|
|
</div>
|
1206 |
|
|
</div>
|
1207 |
|
|
<?php
|
1208 |
|
|
}
|
1209 |
|
|
|
1210 |
0b87fcf5
|
bruno
|
function set_flash_message($class, $msg) {
|
1211 |
82cd6022
|
PiBa-NL
|
@phpsession_begin();
|
1212 |
0b87fcf5
|
bruno
|
$_SESSION['flash_messages'][$class][] = $msg;
|
1213 |
82cd6022
|
PiBa-NL
|
@phpsession_end(true);
|
1214 |
0b87fcf5
|
bruno
|
}
|
1215 |
|
|
|
1216 |
|
|
function get_flash_message() {
|
1217 |
82cd6022
|
PiBa-NL
|
@phpsession_begin();
|
1218 |
0b87fcf5
|
bruno
|
if (isset($_SESSION['flash_messages']) && !empty($_SESSION['flash_messages'])) {
|
1219 |
|
|
foreach ($_SESSION['flash_messages'] as $class => $flash_message) {
|
1220 |
0d711d38
|
Phil Davis
|
print_info_box(implode("<br />", $flash_message), $class);
|
1221 |
0b87fcf5
|
bruno
|
}
|
1222 |
|
|
unset($_SESSION['flash_messages']);
|
1223 |
|
|
}
|
1224 |
82cd6022
|
PiBa-NL
|
@phpsession_end(true);
|
1225 |
0b87fcf5
|
bruno
|
}
|
1226 |
|
|
|
1227 |
f9703596
|
NOYB
|
/* Retrieve GET or POST Value/State
|
1228 |
|
|
* Eample Usage:
|
1229 |
|
|
* $value = getGETPOSTsettingvalue('get/post parameter name', "");
|
1230 |
|
|
* $value = getGETPOSTsettingvalue('get/post parameter name', null);
|
1231 |
|
|
* $state = getGETPOSTsettingvalue('get/post parameter name', null);
|
1232 |
|
|
* $state = getGETPOSTsettingvalue('get/post parameter name', false);
|
1233 |
|
|
*/
|
1234 |
|
|
function getGETPOSTsettingvalue($settingname, $default) {
|
1235 |
|
|
$settingvalue = $default;
|
1236 |
|
|
if ($_GET[$settingname]) {
|
1237 |
|
|
$settingvalue = $_GET[$settingname];
|
1238 |
|
|
}
|
1239 |
|
|
if ($_POST[$settingname]) {
|
1240 |
|
|
$settingvalue = $_POST[$settingname];
|
1241 |
|
|
}
|
1242 |
|
|
return $settingvalue;
|
1243 |
|
|
}
|
1244 |
|
|
|
1245 |
ecaca752
|
Renato Botelho
|
/* set timezone */
|
1246 |
|
|
if (isset($config['system']['timezone']) &&
|
1247 |
|
|
!empty($config['system']['timezone'])) {
|
1248 |
|
|
$timezone = $config['system']['timezone'];
|
1249 |
|
|
} elseif (isset($g['default_timezone']) && !empty($g['default_timezone'])) {
|
1250 |
|
|
$timezone = $g['default_timezone'];
|
1251 |
|
|
} else {
|
1252 |
3b49bc25
|
Scott Ullrich
|
$timezone = "Etc/UTC";
|
1253 |
45b4ffc6
|
Phil Davis
|
}
|
1254 |
3b49bc25
|
Scott Ullrich
|
|
1255 |
6e150fc0
|
jim-p
|
/* Remove files we do not want to see in a crash report */
|
1256 |
|
|
function cleanup_crash_file_list() {
|
1257 |
|
|
$files = glob("/var/crash/*");
|
1258 |
|
|
if (!is_array($files) || empty($files)) {
|
1259 |
|
|
return array();
|
1260 |
|
|
}
|
1261 |
|
|
|
1262 |
|
|
$exclude_patterns = array(
|
1263 |
|
|
'.*.last',
|
1264 |
|
|
'bounds',
|
1265 |
|
|
'minfree'
|
1266 |
|
|
);
|
1267 |
|
|
|
1268 |
|
|
foreach ($files as $idx => $fb) {
|
1269 |
|
|
if (preg_match('/' . implode('|', $exclude_patterns) . '/', basename($fb)) == 1) {
|
1270 |
|
|
unset($files[$idx]);
|
1271 |
|
|
}
|
1272 |
|
|
}
|
1273 |
|
|
|
1274 |
|
|
return $files;
|
1275 |
|
|
}
|
1276 |
|
|
|
1277 |
|
|
function system_has_crash_data() {
|
1278 |
|
|
/* Test if there are any crash data files present */
|
1279 |
|
|
return count(cleanup_crash_file_list()) > 0;
|
1280 |
|
|
}
|
1281 |
|
|
|
1282 |
|
|
function system_has_php_errors() {
|
1283 |
|
|
/* Check if the PHP error log is empty. Cast to int in case the file
|
1284 |
|
|
* does not exist and filesize() returns false. */
|
1285 |
|
|
return (int) @filesize("/tmp/PHP_errors.log") > 0;
|
1286 |
|
|
}
|
1287 |
|
|
|
1288 |
3b49bc25
|
Scott Ullrich
|
date_default_timezone_set($timezone);
|
1289 |
|
|
|
1290 |
667b2b60
|
Ermal
|
?>
|