1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
guiconfig.inc
|
5
|
by Scott Ullrich, Copyright 2004, All rights reserved.
|
6
|
originally based on of m0n0wall (http://m0n0.ch/wall)
|
7
|
|
8
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
9
|
All rights reserved.
|
10
|
|
11
|
Redistribution and use in source and binary forms, with or without
|
12
|
modification, are permitted provided that the following conditions are met:
|
13
|
|
14
|
1. Redistributions of source code must retain the above copyright notice,
|
15
|
this list of conditions and the following disclaimer.
|
16
|
|
17
|
2. Redistributions in binary form must reproduce the above copyright
|
18
|
notice, this list of conditions and the following disclaimer in the
|
19
|
documentation and/or other materials provided with the distribution.
|
20
|
|
21
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
POSSIBILITY OF SUCH DAMAGE.
|
31
|
*/
|
32
|
/*
|
33
|
pfSense_MODULE: base
|
34
|
*/
|
35
|
|
36
|
/* Include authentication routines */
|
37
|
/* THIS MUST BE ABOVE ALL OTHER CODE */
|
38
|
require_once("authgui.inc");
|
39
|
|
40
|
/* make sure nothing is cached */
|
41
|
if (!$omit_nocacheheaders) {
|
42
|
header("Expires: 0");
|
43
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
44
|
header("Cache-Control: no-store, no-cache, must-revalidate");
|
45
|
header("Cache-Control: post-check=0, pre-check=0", false);
|
46
|
header("Pragma: no-cache");
|
47
|
}
|
48
|
|
49
|
/* parse the configuration and include all configuration functions */
|
50
|
require_once("functions.inc");
|
51
|
|
52
|
/* Pull in all the gui related display classes) */
|
53
|
foreach (scandir("/usr/local/www/classes/") as $file) {
|
54
|
if (stristr($file, ".inc") !== false) {
|
55
|
require_once("classes/{$file}");
|
56
|
}
|
57
|
}
|
58
|
/*
|
59
|
* if user has selected a custom template, use it.
|
60
|
* otherwise default to pfsense template
|
61
|
*/
|
62
|
if($config['theme'] <> "")
|
63
|
$g['theme'] = $config['theme'];
|
64
|
else
|
65
|
$g['theme'] = "pfsense";
|
66
|
|
67
|
/*
|
68
|
* If this device is an apple ipod/iphone
|
69
|
* switch the theme to one that works with it.
|
70
|
*/
|
71
|
$apple_ua = array("iPhone","iPod", "iPad");
|
72
|
foreach($apple_ua as $useragent)
|
73
|
if(strstr($_SERVER['HTTP_USER_AGENT'], $useragent))
|
74
|
$g['theme'] = "pfsense";
|
75
|
|
76
|
/* used by progress bar */
|
77
|
$lastseen = "-1";
|
78
|
|
79
|
$navlevelsep = ": "; /* navigation level separator string */
|
80
|
$mandfldhtml = ""; /* display this before mandatory input fields */
|
81
|
$mandfldhtmlspc = ""; /* same as above, but with spacing */
|
82
|
|
83
|
/* Some ajax scripts still need access to GUI */
|
84
|
if(!$ignorefirmwarelock) {
|
85
|
if (is_subsystem_dirty('firmwarelock')) {
|
86
|
if (!$d_isfwfile) {
|
87
|
header("Location: system_firmware.php");
|
88
|
exit;
|
89
|
} else {
|
90
|
return;
|
91
|
}
|
92
|
}
|
93
|
}
|
94
|
|
95
|
$firewall_rules_dscp_types = array("af11",
|
96
|
"af12",
|
97
|
"af13",
|
98
|
"af21",
|
99
|
"af22",
|
100
|
"af23",
|
101
|
"af31",
|
102
|
"af32",
|
103
|
"af33",
|
104
|
"af41",
|
105
|
"af42",
|
106
|
"af43",
|
107
|
"EF",
|
108
|
"1-64",
|
109
|
"0x10",
|
110
|
"0x04-0xfc");
|
111
|
|
112
|
$auth_server_types = array(
|
113
|
'ldap' => "LDAP",
|
114
|
'radius' => "Radius");
|
115
|
|
116
|
$ldap_urltypes = array(
|
117
|
'TCP - Standard' => 389,
|
118
|
'SSL - Encrypted' => 636);
|
119
|
|
120
|
$ldap_scopes = array(
|
121
|
'one' => "One Level",
|
122
|
'subtree' => "Entire Subtree");
|
123
|
|
124
|
$ldap_protvers = array(
|
125
|
2,
|
126
|
3);
|
127
|
|
128
|
$ldap_templates = array(
|
129
|
|
130
|
'open' => array(
|
131
|
'desc' => "OpenLDAP",
|
132
|
'attr_user' => "cn",
|
133
|
'attr_group' => "cn",
|
134
|
'attr_member' => "member"),
|
135
|
|
136
|
'msad' => array(
|
137
|
'desc' => "Microsoft AD",
|
138
|
'attr_user' => "samAccountName",
|
139
|
'attr_group' => "cn",
|
140
|
'attr_member' => "memberOf"),
|
141
|
|
142
|
'edir' => array(
|
143
|
'desc' => "Novell eDirectory",
|
144
|
'attr_user' => "cn",
|
145
|
'attr_group' => "cn",
|
146
|
'attr_member' => "uniqueMember"));
|
147
|
|
148
|
$radius_srvcs = array(
|
149
|
'both' => "Authentication and Accounting",
|
150
|
'auth' => "Authentication",
|
151
|
'acct' => "Accounting");
|
152
|
|
153
|
$netbios_nodetypes = array(
|
154
|
'0' => "none",
|
155
|
'1' => "b-node",
|
156
|
'2' => "p-node",
|
157
|
'4' => "m-node",
|
158
|
'5' => "h-node");
|
159
|
|
160
|
/* some well knows ports */
|
161
|
$wkports = array(
|
162
|
5999 => "CVSup",
|
163
|
53 => "DNS",
|
164
|
21 => "FTP",
|
165
|
3000 => "HBCI",
|
166
|
80 => "HTTP",
|
167
|
443 => "HTTPS",
|
168
|
5190 => "ICQ",
|
169
|
113 => "IDENT/AUTH",
|
170
|
143 => "IMAP",
|
171
|
993 => "IMAP/S",
|
172
|
4500 => "IPsec NAT-T",
|
173
|
500 => "ISAKMP",
|
174
|
1701 => "L2TP",
|
175
|
389 => "LDAP",
|
176
|
1755 => "MMS/TCP",
|
177
|
7000 => "MMS/UDP",
|
178
|
445 => "MS DS",
|
179
|
3389 => "MS RDP",
|
180
|
1512 => "MS WINS",
|
181
|
1863 => "MSN",
|
182
|
119 => "NNTP",
|
183
|
123 => "NTP",
|
184
|
138 => "NetBIOS-DGM",
|
185
|
137 => "NetBIOS-NS",
|
186
|
139 => "NetBIOS-SSN",
|
187
|
1194 => "OpenVPN",
|
188
|
110 => "POP3",
|
189
|
995 => "POP3/S",
|
190
|
1723 => "PPTP",
|
191
|
1812 => "RADIUS",
|
192
|
1813 => "RADIUS accounting",
|
193
|
5004 => "RTP",
|
194
|
5060 => "SIP",
|
195
|
25 => "SMTP",
|
196
|
465 => "SMTP/S",
|
197
|
161 => "SNMP",
|
198
|
162 => "SNMP-Trap",
|
199
|
22 => "SSH",
|
200
|
3478 => "STUN",
|
201
|
3544 => "Teredo",
|
202
|
23 => "Telnet",
|
203
|
69 => "TFTP",
|
204
|
5900 => "VNC");
|
205
|
|
206
|
/* TCP flags */
|
207
|
$tcpflags = array("fin", "syn", "rst", "psh", "ack", "urg");
|
208
|
|
209
|
$specialnets = array("wanip" => "WAN address", "lanip" => "LAN address", "lan" => "LAN net", "pptp" => "PPTP clients", "pppoe" => "PPPoE clients", "l2tp" => "L2TP clients");
|
210
|
|
211
|
$spiflist = get_configured_interface_with_descr(true, true);
|
212
|
foreach ($spiflist as $ifgui => $ifdesc) {
|
213
|
$specialnets[$ifgui] = $ifdesc . " net";
|
214
|
}
|
215
|
|
216
|
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
|
217
|
"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
|
218
|
"10half" => "10BASE-T half-duplex");
|
219
|
|
220
|
$wlan_modes = array("bss" => "Infrastructure (BSS)", "adhoc" => "Ad-hoc (IBSS)",
|
221
|
"hostap" => "Access Point");
|
222
|
|
223
|
/* platforms that support firmware updating */
|
224
|
$fwupplatforms = array('pfSense', 'net45xx', 'net48xx', 'generic-pc', 'embedded', 'wrap', 'nanobsd');
|
225
|
|
226
|
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
|
227
|
|
228
|
/* check for bad control characters */
|
229
|
foreach ($postdata as $pn => $pd) {
|
230
|
if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
|
231
|
$input_errors[] = "The field '" . $pn . "' contains invalid characters.";
|
232
|
}
|
233
|
}
|
234
|
|
235
|
for ($i = 0; $i < count($reqdfields); $i++) {
|
236
|
if ($_POST[$reqdfields[$i]] == "" && $_REQUEST[$reqdfields[$i]] == "") {
|
237
|
$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
|
238
|
}
|
239
|
}
|
240
|
}
|
241
|
|
242
|
function print_input_errors($input_errors) {
|
243
|
global $g;
|
244
|
|
245
|
print <<<EOF
|
246
|
<p>
|
247
|
<table border="0" cellspacing="0" cellpadding="4" width="100%">
|
248
|
<tr>
|
249
|
<td class="inputerrorsleft">
|
250
|
<img src="./themes/{$g['theme']}/images/icons/icon_error.gif">
|
251
|
</td>
|
252
|
<td class="inputerrorsright">
|
253
|
<span class="errmsg"><p>
|
254
|
The following input errors were detected:
|
255
|
<ul>
|
256
|
EOF;
|
257
|
foreach ($input_errors as $ierr) {
|
258
|
echo "<li>" . htmlspecialchars($ierr) . "</li>";
|
259
|
}
|
260
|
|
261
|
print <<<EOF2
|
262
|
</ul>
|
263
|
</span>
|
264
|
</td></tr>
|
265
|
</table>
|
266
|
</p> <br>
|
267
|
EOF2;
|
268
|
|
269
|
}
|
270
|
|
271
|
function verify_gzip_file($fname) {
|
272
|
|
273
|
$returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
|
274
|
if ($returnvar != 0)
|
275
|
return 0;
|
276
|
else
|
277
|
return 1;
|
278
|
}
|
279
|
|
280
|
function print_info_box_np($msg, $name="apply",$value="Apply changes") {
|
281
|
global $g;
|
282
|
|
283
|
if(stristr($msg, "apply") != false || stristr($msg, "save") != false || stristr($msg, "create") != false) {
|
284
|
$savebutton = "<td class='infoboxsave'>";
|
285
|
$savebutton .= "<input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\">";
|
286
|
if($_POST['if'])
|
287
|
$savebutton .= "<input type='hidden' name='if' value='{$_POST['if']}'>";
|
288
|
$savebutton.="</td>";
|
289
|
}
|
290
|
$nifty_redbox = "#990000";
|
291
|
$nifty_blackbox = "#000000";
|
292
|
|
293
|
$themename = $g['theme'];
|
294
|
|
295
|
if(file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
|
296
|
$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
|
297
|
eval($toeval);
|
298
|
}
|
299
|
|
300
|
if(file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
|
301
|
$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
|
302
|
eval($toeval);
|
303
|
}
|
304
|
|
305
|
echo <<<EOFnp
|
306
|
<table class='infobox'>
|
307
|
<tr>
|
308
|
<td>
|
309
|
<div class='infoboxnp' id='redbox'>
|
310
|
<table class='infoboxnptable2'>
|
311
|
<tr>
|
312
|
<td class='infoboxnptd'>
|
313
|
<img class='infoboxnpimg' src="/themes/{$g['theme']}/images/icons/icon_exclam.gif" >
|
314
|
</td>
|
315
|
<td class='infoboxnptd2'>
|
316
|
<b>{$msg}</b>
|
317
|
</td>
|
318
|
{$savebutton}
|
319
|
</tr>
|
320
|
</table>
|
321
|
</div>
|
322
|
</td>
|
323
|
</tr>
|
324
|
</table>
|
325
|
<script type="text/javascript">
|
326
|
NiftyCheck();
|
327
|
Rounded("div#redbox","all","#FFF","{$nifty_redbox}","smooth");
|
328
|
Rounded("td#blackbox","all","#FFF","{$nifty_blackbox}","smooth");
|
329
|
</script>
|
330
|
<br/>
|
331
|
EOFnp;
|
332
|
|
333
|
}
|
334
|
|
335
|
function print_info_box($msg) {
|
336
|
echo "<p>";
|
337
|
print_info_box_np($msg);
|
338
|
echo "</p>";
|
339
|
}
|
340
|
|
341
|
function get_std_save_message($ok) {
|
342
|
global $d_sysrebootreqd_path;
|
343
|
|
344
|
return "The changes have been applied successfully. You can also <a href='status_filter_reload.php'>monitor</a> the filter reload progress.";
|
345
|
}
|
346
|
|
347
|
function pprint_address($adr) {
|
348
|
global $specialnets;
|
349
|
|
350
|
if (isset($adr['any'])) {
|
351
|
$padr = "*";
|
352
|
} else if ($adr['network']) {
|
353
|
if (preg_match("/opt[0-999]ip/", $adr['network'])) {
|
354
|
$padr = "Interface IP address";
|
355
|
} else {
|
356
|
$padr = $specialnets[$adr['network']];
|
357
|
}
|
358
|
} else {
|
359
|
$padr = $adr['address'];
|
360
|
}
|
361
|
|
362
|
if (isset($adr['not']))
|
363
|
$padr = "! " . $padr;
|
364
|
|
365
|
return $padr;
|
366
|
}
|
367
|
|
368
|
function pprint_port($port) {
|
369
|
global $wkports;
|
370
|
|
371
|
$pport = "";
|
372
|
|
373
|
if (!$port)
|
374
|
return "*";
|
375
|
else {
|
376
|
$srcport = explode("-", $port);
|
377
|
if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
|
378
|
$pport = $srcport[0];
|
379
|
if ($wkports[$srcport[0]]) {
|
380
|
$pport .= " (" . $wkports[$srcport[0]] . ")";
|
381
|
}
|
382
|
} else
|
383
|
$pport .= $srcport[0] . " - " . $srcport[1];
|
384
|
}
|
385
|
|
386
|
return $pport;
|
387
|
}
|
388
|
|
389
|
/* sort by interface only, retain the original order of rules that apply to
|
390
|
the same interface */
|
391
|
function filter_rules_sort() {
|
392
|
global $config;
|
393
|
|
394
|
/* mark each rule with the sequence number (to retain the order while sorting) */
|
395
|
for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
|
396
|
$config['filter']['rule'][$i]['seq'] = $i;
|
397
|
|
398
|
function filtercmp($a, $b) {
|
399
|
if ($a['interface'] == $b['interface'])
|
400
|
return $a['seq'] - $b['seq'];
|
401
|
else
|
402
|
return -strcmp($a['interface'], $b['interface']);
|
403
|
}
|
404
|
|
405
|
usort($config['filter']['rule'], "filtercmp");
|
406
|
|
407
|
/* strip the sequence numbers again */
|
408
|
for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
|
409
|
unset($config['filter']['rule'][$i]['seq']);
|
410
|
}
|
411
|
|
412
|
function gentitle($title) {
|
413
|
global $navlevelsep;
|
414
|
if(!is_array($title))
|
415
|
return $title;
|
416
|
else
|
417
|
return join($navlevelsep, $title);
|
418
|
}
|
419
|
|
420
|
function genhtmltitle($title) {
|
421
|
global $config;
|
422
|
return gentitle($title);
|
423
|
}
|
424
|
|
425
|
/* update the changedesc and changecount(er) variables */
|
426
|
function update_changedesc($update) {
|
427
|
global $changedesc;
|
428
|
global $changecount;
|
429
|
|
430
|
$changedesc .= " {$update}";
|
431
|
$changecount++;
|
432
|
}
|
433
|
|
434
|
function clear_log_file($logfile = "/var/log/system.log") {
|
435
|
global $config, $g;
|
436
|
exec("/usr/bin/killall syslogd");
|
437
|
if(isset($config['system']['disablesyslogclog'])) {
|
438
|
unlink($logfile);
|
439
|
touch($logfile);
|
440
|
} else {
|
441
|
if(isset($config['system']['usefifolog']))
|
442
|
exec("/usr/sbin/fifolog_create -s 511488 {$logfile}");
|
443
|
else
|
444
|
exec("/usr/sbin/clog -i -s 511488 {$logfile}");
|
445
|
}
|
446
|
system_syslogd_start();
|
447
|
}
|
448
|
|
449
|
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
|
450
|
global $g, $config;
|
451
|
$sor = isset($config['syslog']['reverse']) ? "-r" : "";
|
452
|
$logarr = "";
|
453
|
$grepline = " ";
|
454
|
if(is_array($grepfor))
|
455
|
foreach($grepfor as $agrep)
|
456
|
$grepline .= " | grep \"$agrep\"";
|
457
|
if(is_array($grepinvert))
|
458
|
foreach($grepinvert as $agrep)
|
459
|
$grepline .= " | grep -v \"$agrep\"";
|
460
|
if(file_exists($logfile) && filesize($logfile) == 0) {
|
461
|
$logarr = array("Log file started.");
|
462
|
} else {
|
463
|
if($config['system']['disablesyslogclog']) {
|
464
|
exec("cat {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
|
465
|
} else {
|
466
|
if(isset($config['system']['usefifolog']))
|
467
|
exec("/usr/sbin/fifolog_reader {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
|
468
|
else
|
469
|
exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
|
470
|
}
|
471
|
}
|
472
|
foreach ($logarr as $logent) {
|
473
|
$logent = preg_split("/\s+/", $logent, 6);
|
474
|
echo "<tr valign=\"top\">\n";
|
475
|
if ($withorig) {
|
476
|
if(isset($config['system']['usefifolog'])) {
|
477
|
$entry_date_time = htmlspecialchars(date("F j, Y, g:i a","" . $logent[1] . ""));
|
478
|
$entry_text = htmlspecialchars($logent[5]);
|
479
|
} else {
|
480
|
$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
|
481
|
$entry_text = htmlspecialchars($logent[4] . " " . $logent[5]);
|
482
|
}
|
483
|
echo "<td class=\"listlr\" nowrap>{$entry_date_time}</td>\n";
|
484
|
echo "<td class=\"listr\">{$entry_text}</td>\n";
|
485
|
|
486
|
} else {
|
487
|
echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
|
488
|
}
|
489
|
echo "</tr>\n";
|
490
|
}
|
491
|
}
|
492
|
|
493
|
function return_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "", $grepreverse = false) {
|
494
|
global $g, $config;
|
495
|
$sor = (isset($config['syslog']['reverse']) || $grepreverse) ? "-r" : "";
|
496
|
$logarr = "";
|
497
|
$grepline = " ";
|
498
|
if(is_array($grepfor))
|
499
|
foreach($grepfor as $agrep)
|
500
|
$grepline .= " | grep \"$agrep\"";
|
501
|
if(is_array($grepinvert))
|
502
|
foreach($grepinvert as $agrep)
|
503
|
$grepline .= " | grep -v \"$agrep\"";
|
504
|
if($config['system']['disablesyslogclog']) {
|
505
|
exec("cat {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
|
506
|
} else {
|
507
|
if(isset($config['system']['usefifolog'])) {
|
508
|
exec("/usr/sbin/fifolog_reader {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
|
509
|
} else {
|
510
|
exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
|
511
|
}
|
512
|
}
|
513
|
return($logarr);
|
514
|
}
|
515
|
|
516
|
/* Check if variable has changed, update and log if it has
|
517
|
* returns true if var changed
|
518
|
* varname = variable name in plain text
|
519
|
* orig = original value
|
520
|
* new = new value
|
521
|
*/
|
522
|
function update_if_changed($varname, & $orig, $new) {
|
523
|
if (is_array($orig) && is_array($new)) {
|
524
|
$a_diff = array_diff($orig, $new);
|
525
|
foreach ($a_diff as $diff) {
|
526
|
update_changedesc("removed {$varname}: \"{$diff}\"");
|
527
|
}
|
528
|
$a_diff = array_diff($new, $orig);
|
529
|
foreach ($a_diff as $diff) {
|
530
|
update_changedesc("added {$varname}: \"{$diff}\"");
|
531
|
}
|
532
|
$orig = $new;
|
533
|
return true;
|
534
|
|
535
|
} else {
|
536
|
if ($orig != $new) {
|
537
|
update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
|
538
|
$orig = $new;
|
539
|
return true;
|
540
|
}
|
541
|
}
|
542
|
return false;
|
543
|
}
|
544
|
|
545
|
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
|
546
|
|
547
|
if (isset($adr['any']))
|
548
|
$padr = "any";
|
549
|
else if ($adr['network'])
|
550
|
$padr = $adr['network'];
|
551
|
else if ($adr['address']) {
|
552
|
list($padr, $pmask) = explode("/", $adr['address']);
|
553
|
if (!$pmask)
|
554
|
$pmask = 32;
|
555
|
}
|
556
|
|
557
|
if (isset($adr['not']))
|
558
|
$pnot = 1;
|
559
|
else
|
560
|
$pnot = 0;
|
561
|
|
562
|
if ($adr['port']) {
|
563
|
list($pbeginport, $pendport) = explode("-", $adr['port']);
|
564
|
if (!$pendport)
|
565
|
$pendport = $pbeginport;
|
566
|
} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
|
567
|
$pbeginport = "any";
|
568
|
$pendport = "any";
|
569
|
}
|
570
|
}
|
571
|
|
572
|
function pconfig_to_address(&$adr, $padr, $pmask, $pnot=false, $pbeginport=0, $pendport=0) {
|
573
|
|
574
|
$adr = array();
|
575
|
|
576
|
if ($padr == "any")
|
577
|
$adr['any'] = true;
|
578
|
else if (is_specialnet($padr))
|
579
|
$adr['network'] = $padr;
|
580
|
else {
|
581
|
$adr['address'] = $padr;
|
582
|
if ($pmask != 32)
|
583
|
$adr['address'] .= "/" . $pmask;
|
584
|
}
|
585
|
|
586
|
if ($pnot)
|
587
|
$adr['not'] = true;
|
588
|
else
|
589
|
unset($adr['not']);
|
590
|
|
591
|
if (($pbeginport != 0) && ($pbeginport != "any")) {
|
592
|
if ($pbeginport != $pendport)
|
593
|
$adr['port'] = $pbeginport . "-" . $pendport;
|
594
|
else
|
595
|
$adr['port'] = $pbeginport;
|
596
|
}
|
597
|
|
598
|
if(is_alias($pbeginport)) {
|
599
|
$adr['port'] = $pbeginport;
|
600
|
}
|
601
|
}
|
602
|
|
603
|
function is_specialnet($net) {
|
604
|
global $specialsrcdst;
|
605
|
|
606
|
if(!$net)
|
607
|
return false;
|
608
|
if (in_array($net, $specialsrcdst))
|
609
|
return true;
|
610
|
else
|
611
|
return false;
|
612
|
}
|
613
|
|
614
|
//function to create widget tabs when called
|
615
|
function display_widget_tabs(& $tab_array) {
|
616
|
echo "<div id='tabs'>";
|
617
|
$tabscounter = 0;
|
618
|
foreach ($tab_array as $ta) {
|
619
|
$dashpos = strpos($ta[2],'-');
|
620
|
$tabname = $ta[2] . "-tab";
|
621
|
$tabclass = substr($ta[2],0,$dashpos);
|
622
|
$tabclass = $tabclass . "-class";
|
623
|
if ($ta[1] == true) {
|
624
|
$tabActive = "table-cell";
|
625
|
$tabNonActive = "none";
|
626
|
}
|
627
|
else {
|
628
|
$tabActive = "none";
|
629
|
$tabNonActive = "table-cell";
|
630
|
}
|
631
|
echo "<div id='{$ta[2]}-active' class='{$tabclass}-tabactive' style='display:{$tabActive}; background-color:#EEEEEE; color:black;'>";
|
632
|
echo "<B> {$ta[0]}";
|
633
|
echo " </B>";
|
634
|
echo "</div>";
|
635
|
|
636
|
echo "<div id='{$ta[2]}-deactive' class='{$tabclass}-tabdeactive' style='display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;' onClick=\"return changeTabDIV('{$ta[2]}')\">";
|
637
|
echo "<B> {$ta[0]}";
|
638
|
echo " </B>";
|
639
|
echo "</div>";
|
640
|
}
|
641
|
|
642
|
echo "<script type=\"text/javascript\">";
|
643
|
echo "NiftyCheck();\n";
|
644
|
echo "Rounded(\"div.{$tabclass}-tabactive\",\"top\",\"#CCCCCC\",\"#EEEEEE\",\"smooth\");\n";
|
645
|
echo "Rounded(\"div.{$tabclass}-tabdeactive\",\"top\",\"#CCCCCC\",\"#777777\",\"smooth\");\n";
|
646
|
echo "</script>";
|
647
|
echo "</div>";
|
648
|
}
|
649
|
|
650
|
|
651
|
// Return inline javascript file or CSS to minimizie
|
652
|
// request count going back to server.
|
653
|
function outputJavaScriptFileInline($javascript) {
|
654
|
if(file_exists($javascript)) {
|
655
|
echo "\n<script type=\"text/javascript\">\n";
|
656
|
include($javascript);
|
657
|
echo "\n</script>\n";
|
658
|
} else {
|
659
|
echo "\n\n<!-- Could not location file: {$javascript} -->\n\n";
|
660
|
}
|
661
|
}
|
662
|
|
663
|
|
664
|
|
665
|
function outputCSSPrintFileInline($css) {
|
666
|
if(file_exists($css)) {
|
667
|
echo "\n<style media=\"print\" type=\"text/css\">\n";
|
668
|
include($css);
|
669
|
echo "\n</style>\n";
|
670
|
} else {
|
671
|
echo "\n\n<!-- Could not location file: {$css} -->\n\n";
|
672
|
}
|
673
|
}
|
674
|
|
675
|
|
676
|
function outputCSSFileInline($css) {
|
677
|
if(file_exists($css)) {
|
678
|
echo "\n<style type=\"text/css\">\n";
|
679
|
include($css);
|
680
|
echo "\n</style>\n";
|
681
|
} else {
|
682
|
echo "\n\n<!-- Could not location file: {$css} -->\n\n";
|
683
|
}
|
684
|
}
|
685
|
|
686
|
$rfc2616 = array(
|
687
|
100 => "100 Continue",
|
688
|
101 => "101 Switching Protocols",
|
689
|
200 => "200 OK",
|
690
|
201 => "201 Created",
|
691
|
202 => "202 Accepted",
|
692
|
203 => "203 Non-Authoritative Information",
|
693
|
204 => "204 No Content",
|
694
|
205 => "205 Reset Content",
|
695
|
206 => "206 Partial Content",
|
696
|
300 => "300 Multiple Choices",
|
697
|
301 => "301 Moved Permanently",
|
698
|
302 => "302 Found",
|
699
|
303 => "303 See Other",
|
700
|
304 => "304 Not Modified",
|
701
|
305 => "305 Use Proxy",
|
702
|
306 => "306 (Unused)",
|
703
|
307 => "307 Temporary Redirect",
|
704
|
400 => "400 Bad Request",
|
705
|
401 => "401 Unauthorized",
|
706
|
402 => "402 Payment Required",
|
707
|
403 => "403 Forbidden",
|
708
|
404 => "404 Not Found",
|
709
|
405 => "405 Method Not Allowed",
|
710
|
406 => "406 Not Acceptable",
|
711
|
407 => "407 Proxy Authentication Required",
|
712
|
408 => "408 Request Timeout",
|
713
|
409 => "409 Conflict",
|
714
|
410 => "410 Gone",
|
715
|
411 => "411 Length Required",
|
716
|
412 => "412 Precondition Failed",
|
717
|
413 => "413 Request Entity Too Large",
|
718
|
414 => "414 Request-URI Too Long",
|
719
|
415 => "415 Unsupported Media Type",
|
720
|
416 => "416 Requested Range Not Satisfiable",
|
721
|
417 => "417 Expectation Failed",
|
722
|
500 => "500 Internal Server Error",
|
723
|
501 => "501 Not Implemented",
|
724
|
502 => "502 Bad Gateway",
|
725
|
503 => "503 Service Unavailable",
|
726
|
504 => "504 Gateway Timeout",
|
727
|
505 => "505 HTTP Version Not Supported"
|
728
|
);
|
729
|
|
730
|
function is_rfc2616_code($code) {
|
731
|
global $rfc2616;
|
732
|
if (isset($rfc2616[$code]))
|
733
|
return true;
|
734
|
else
|
735
|
return false;
|
736
|
}
|
737
|
|
738
|
function print_rfc2616_select($tag, $current){
|
739
|
global $rfc2616;
|
740
|
|
741
|
/* Default to 200 OK if not set */
|
742
|
if ($current == "")
|
743
|
$current = 200;
|
744
|
|
745
|
echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";
|
746
|
foreach($rfc2616 as $code => $message) {
|
747
|
if ($code == $current) {
|
748
|
$sel = " selected";
|
749
|
} else {
|
750
|
$sel = "";
|
751
|
}
|
752
|
echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
|
753
|
}
|
754
|
}
|
755
|
|
756
|
// Useful debugging function, much cleaner than print_r
|
757
|
function echo_array($array,$return_me=false){
|
758
|
if(is_array($array) == false){
|
759
|
$return = "The provided variable is not an array.";
|
760
|
}else{
|
761
|
foreach($array as $name=>$value){
|
762
|
if(is_array($value)){
|
763
|
$return .= "";
|
764
|
$return .= "['<b>$name</b>'] {<div style='margin-left:10px;'>\n";
|
765
|
$return .= echo_array($value,true);
|
766
|
$return .= "</div>}";
|
767
|
$return .= "\n\n";
|
768
|
}else{
|
769
|
if(is_string($value)){
|
770
|
$value = "\"$value\"";
|
771
|
}
|
772
|
$return .= "['<b>$name</b>'] = $value\n\n";
|
773
|
}
|
774
|
}
|
775
|
}
|
776
|
if($return_me == true){
|
777
|
return $return;
|
778
|
}else{
|
779
|
echo "<pre>".$return."</pre>";
|
780
|
}
|
781
|
}
|
782
|
|
783
|
/****f* pfsense-utils/display_top_tabs
|
784
|
* NAME
|
785
|
* display_top_tabs - display tabs with rounded edges
|
786
|
* INPUTS
|
787
|
* $text - array of tabs
|
788
|
* RESULT
|
789
|
* null
|
790
|
******/
|
791
|
function display_top_tabs(& $tab_array) {
|
792
|
global $HTTP_SERVER_VARS;
|
793
|
global $config;
|
794
|
global $g;
|
795
|
|
796
|
/* does the user have access to this tab?
|
797
|
* master user has access to everything.
|
798
|
* if the user does not have access, simply
|
799
|
* unset the tab item.
|
800
|
*/
|
801
|
|
802
|
$tab_temp = array ();
|
803
|
foreach ($tab_array as $ta)
|
804
|
if(isAllowedPage($ta[2]))
|
805
|
$tab_temp[] = $ta;
|
806
|
/*
|
807
|
// FIXME : if the checks are not good enough
|
808
|
// in isAllowedPage, it needs to be
|
809
|
// fixed instead of kludging here
|
810
|
|
811
|
// TODO: humm what shall we do with pkg_edit.php and pkg.php?
|
812
|
if ((strpos($link, "pkg.php")) !== false || (strpos($link, "pkg_edit.php")) !== false) {
|
813
|
$pos_equal = strpos($link, "=");
|
814
|
$pos_xmlsuffix = strpos($link, ".xml");
|
815
|
// do we match an absolute url including ?xml= foo
|
816
|
if(!isAllowedPage($link, $allowed))
|
817
|
$link = substr($link, $pos_equal +1, ($pos_xmlsuffix - $pos_equal +3));
|
818
|
}
|
819
|
// next check - what if the basename contains a query string?
|
820
|
if ((strpos($link, "?")) !== false) {
|
821
|
$pos_qmark = strpos($link, "?");
|
822
|
$link = substr($link, 0, $pos_qmark);
|
823
|
}
|
824
|
$authorized_text = print_r($allowed, true);
|
825
|
if(is_array($authorized))
|
826
|
if (in_array(basename($link), $authorized))
|
827
|
*/
|
828
|
|
829
|
unset ($tab_array);
|
830
|
$tab_array = & $tab_temp;
|
831
|
|
832
|
$tab_active_bg = "#EEEEEE";
|
833
|
$tab_inactive_bg = "#777777";
|
834
|
$nifty_tabs_corners = "#FFF";
|
835
|
$font_color = "white";
|
836
|
|
837
|
/* if tabcontrols.php exist for a theme, allow it to be overriden */
|
838
|
$themename = $config['theme'];
|
839
|
$filename = "/usr/local/www/themes/{$themename}/tabcontrols.php";
|
840
|
if(file_exists($filename)) {
|
841
|
$eval_code = file_get_contents($filename);
|
842
|
eval($eval_code);
|
843
|
}
|
844
|
|
845
|
$tabcharcount = 0;
|
846
|
foreach ($tab_array as $ta)
|
847
|
$tabcharcount = $tabcharcount + strlen($ta[0]);
|
848
|
|
849
|
// If the character count of the tab names is > 670
|
850
|
// then show a select item dropdown menubox.
|
851
|
if($tabcharcount > 82) {
|
852
|
echo "Currently viewing: ";
|
853
|
echo "<select name='TabSelect' onchange='tabs_will_go(this)'>\n";
|
854
|
foreach ($tab_array as $ta) {
|
855
|
if($ta[1]=="true")
|
856
|
$selected = " SELECTED";
|
857
|
else
|
858
|
$selected = "";
|
859
|
// Onclick in option will not work in some browser
|
860
|
// echo "<option onClick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
|
861
|
echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
|
862
|
}
|
863
|
echo "</select>\n<p/>";
|
864
|
echo "<script type=\"text/javascript\">";
|
865
|
echo " function tabs_will_go(obj){ document.location = obj.value; }";
|
866
|
echo "</script>";
|
867
|
} else {
|
868
|
echo "<table cellpadding='0' cellspacing='0'>\n";
|
869
|
echo " <tr>\n";
|
870
|
$tabscounter = 0;
|
871
|
foreach ($tab_array as $ta) {
|
872
|
if ($ta[1] == true) {
|
873
|
echo " <td bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><div id='tabactive'></div></td>\n";
|
874
|
} else {
|
875
|
echo " <td bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><div id='tabdeactive{$tabscounter}'></div></td>\n";
|
876
|
}
|
877
|
$tabscounter++;
|
878
|
}
|
879
|
echo "</tr>\n<tr>\n";
|
880
|
foreach ($tab_array as $ta) {
|
881
|
if ($ta[1] == true) {
|
882
|
echo " <td height=\"15\" valign=\"middle\" bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><B> {$ta[0]}";
|
883
|
echo " ";
|
884
|
echo "<font size='-12'> </font></B></td>\n";
|
885
|
} else {
|
886
|
echo " <td height=\"15\" valign=\"middle\" bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><B> <a href='{$ta[
|
887
|
2]}'>";
|
888
|
echo "<font color='{$font_color}'>{$ta[0]}</font></a> ";
|
889
|
echo "<font size='-12'> </font></B></td>\n";
|
890
|
}
|
891
|
}
|
892
|
echo "</tr>\n<tr>\n";
|
893
|
foreach ($tab_array as $ta) {
|
894
|
if ($ta[1] == true) {
|
895
|
echo " <td bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"></td>\n";
|
896
|
} else {
|
897
|
echo " <td bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"></td>\n";
|
898
|
}
|
899
|
$tabscounter++;
|
900
|
}
|
901
|
echo " </tr>\n";
|
902
|
echo "</table>\n";
|
903
|
echo "<script type=\"text/javascript\">";
|
904
|
echo "NiftyCheck();\n";
|
905
|
echo "Rounded(\"div#tabactive\",\"top\",\"{$nifty_tabs_corners}\",\"{$tab_active_bg}\",\"smooth\");\n";
|
906
|
for ($x = 0; $x < $tabscounter; $x++)
|
907
|
echo "Rounded(\"div#tabdeactive{$x}\",\"top\",\"{$nifty_tabs_corners}\",\"{$tab_inactive_bg}\",\"smooth\");\n";
|
908
|
echo "</script>";
|
909
|
}
|
910
|
}
|
911
|
|
912
|
function add_package_tabs($tabgroup, & $tab_array) {
|
913
|
global $config, $g;
|
914
|
|
915
|
if(!is_array($config['installedpackages']))
|
916
|
return;
|
917
|
if(!is_array($config['installedpackages']['tab']))
|
918
|
return;
|
919
|
|
920
|
foreach($config['installedpackages']['tab'] as $tab) {
|
921
|
if ($tab['group'] !== $group)
|
922
|
continue;
|
923
|
$tab_entry = array();
|
924
|
if($tab['name']) {
|
925
|
$tab_entry[] = $tab['name'];
|
926
|
$tab_entry[] = false;
|
927
|
$tab_entry[] = $tab['url'];
|
928
|
$tab_array[] = $tab_entry;
|
929
|
}
|
930
|
}
|
931
|
}
|
932
|
|
933
|
function rule_popup($src,$srcport,$dst,$dstport){
|
934
|
global $config;
|
935
|
$aliases_array = array();
|
936
|
if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
|
937
|
{
|
938
|
$span_begin = "";
|
939
|
$alias_src_span_begin = "";
|
940
|
$alias_src_span_end = "";
|
941
|
$alias_src_port_span_begin = "";
|
942
|
$alias_src_port_span_end = "";
|
943
|
$alias_dst_span_begin = "";
|
944
|
$alias_dst_span_end = "";
|
945
|
$alias_dst_port_span_begin = "";
|
946
|
$alias_dst_port_span_end = "";
|
947
|
$alias_content_text = "";
|
948
|
foreach($config['aliases']['alias'] as $alias_name)
|
949
|
{
|
950
|
$alias_addresses = explode (" ", $alias_name['address']);
|
951
|
$alias_details = explode ("||", $alias_name['detail']);
|
952
|
$alias_objects_with_details = "";
|
953
|
$counter = 0;
|
954
|
if ($alias_name['url']) {
|
955
|
$alias_objects_with_details .= $alias_name['url'] . "<br/>";
|
956
|
}
|
957
|
foreach($alias_addresses as $alias_ports_address)
|
958
|
{
|
959
|
$alias_objects_with_details .= $alias_addresses[$counter];
|
960
|
$alias_detail_default = strpos ($alias_details[$counter],"Entry added");
|
961
|
if ($alias_details[$counter] != "" && $alias_detail_default === False){
|
962
|
$alias_objects_with_details .=" - " . $alias_details[$counter];
|
963
|
}
|
964
|
$alias_objects_with_details .= "<br>";
|
965
|
$counter++;
|
966
|
}
|
967
|
//max character length for caption field
|
968
|
$maxlength = 60;
|
969
|
|
970
|
$alias_descr_substr = $alias_name['descr'];
|
971
|
$alias_content_text = htmlspecialchars($alias_objects_with_details);
|
972
|
$alias_caption = htmlspecialchars($alias_descr_substr . ":");
|
973
|
$strlength = strlen ($alias_caption);
|
974
|
if ($strlength >= $maxlength)
|
975
|
$alias_caption = substr($alias_caption, 0, $maxlength) . "...";
|
976
|
|
977
|
$alias_caption_escaped = str_replace("'", "\'", $alias_caption);
|
978
|
$span_begin = "<span style=\"cursor: help;\" onmouseover=\"domTT_activate(this, event, 'content', '<h1>$alias_caption_escaped</h1><p>$alias_content_text</p>', 'trail', true, 'delay', 0, 'fade', 'both', 'fadeMax', 93, 'styleClass', 'niceTitle');\" onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\"><U>";
|
979
|
|
980
|
if ($alias_name['name'] == $src)
|
981
|
$alias_src_span_begin = $span_begin;
|
982
|
if ($alias_name['name'] == $srcport)
|
983
|
$alias_src_port_span_begin = $span_begin;
|
984
|
if ($alias_name['name'] == $dst)
|
985
|
$alias_dst_span_begin = $span_begin;
|
986
|
if ($alias_name['name'] == $dstport)
|
987
|
$alias_dst_port_span_begin = $span_begin;
|
988
|
}
|
989
|
$descriptions = array ();
|
990
|
$descriptions['src'] = $alias_src_span_begin;
|
991
|
$descriptions['srcport'] = $alias_src_port_span_begin;
|
992
|
$descriptions['dst'] = $alias_dst_span_begin;
|
993
|
$descriptions['dstport'] = $alias_dst_port_span_begin;
|
994
|
|
995
|
return $descriptions;
|
996
|
}
|
997
|
}
|
998
|
|
999
|
?>
|