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