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
|
/* make sure nothing is cached */
|
34
|
if (!$omit_nocacheheaders) {
|
35
|
header("Expires: 0");
|
36
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
37
|
header("Cache-Control: no-store, no-cache, must-revalidate");
|
38
|
header("Cache-Control: post-check=0, pre-check=0", false);
|
39
|
header("Pragma: no-cache");
|
40
|
}
|
41
|
|
42
|
/* Include authentication routines */
|
43
|
/* THIS MUST BE ABOVE ALL OTHER CODE */
|
44
|
require_once("auth.inc");
|
45
|
|
46
|
/* parse the configuration and include all configuration functions */
|
47
|
require_once("config.inc");
|
48
|
require_once("functions.inc");
|
49
|
|
50
|
/*
|
51
|
* if user has selected a custom template, use it.
|
52
|
* otherwise default to pfsense tempalte
|
53
|
*/
|
54
|
if($config['theme'] <> "")
|
55
|
$g['theme'] = $config['theme'];
|
56
|
else
|
57
|
$g['theme'] = "pfsense";
|
58
|
|
59
|
$apple_ua = array("iPhone","iPod");
|
60
|
foreach($apple_ua as $useragent)
|
61
|
if(strstr($_SERVER['HTTP_USER_AGENT'], $useragent))
|
62
|
$g['theme'] = "pfsense";
|
63
|
|
64
|
$d_landirty_path = $g['varrun_path'] . "/lan.conf.dirty";
|
65
|
$d_pppoeuserdirty_path = $g['varrun_path'] . "/vpn-pppoe-users-edit.dirty";
|
66
|
$d_hostsdirty_path = $g['varrun_path'] . "/hosts.dirty";
|
67
|
$d_natconfdirty_path = $g['varrun_path'] . "/nat.conf.dirty";
|
68
|
$d_filterconfdirty_path = $g['varrun_path'] . "/filter.conf.dirty";
|
69
|
$d_ipsecconfdirty_path = $g['varrun_path'] . "/ipsec.conf.dirty";
|
70
|
$d_shaperconfdirty_path = $g['varrun_path'] . "/shaper.conf.dirty";
|
71
|
$d_pptpuserdirty_path = $g['varrun_path'] . "/pptpd.user.dirty";
|
72
|
$d_dnsmasqdirty_path = $g['varrun_path'] . "/dnsmasq.dirty";
|
73
|
$d_staticmapsdirty_path = $g['varrun_path'] . "/staticmaps.dirty";
|
74
|
$d_staticroutesdirty_path = $g['varrun_path'] . "/staticroutes.dirty";
|
75
|
$d_aliasesdirty_path = $g['varrun_path'] . "/aliases.dirty";
|
76
|
$d_proxyarpdirty_path = $g['varrun_path'] . "/proxyarp.dirty";
|
77
|
$d_fwupenabled_path = $g['varrun_path'] . "/fwup.enabled";
|
78
|
$d_firmwarelock_path = $g['varrun_path'] . "/firmware.lock";
|
79
|
$d_sysrebootreqd_path = $g['varrun_path'] . "/sysreboot.reqd";
|
80
|
$d_passthrumacsdirty_path = $g['varrun_path'] . "/passthrumacs.dirty";
|
81
|
$d_allowedipsdirty_path = $g['varrun_path'] . "/allowedips.dirty";
|
82
|
$d_ovpnclidirty_path = $g['varrun_path'] . "/ovpnclient.dirty";
|
83
|
$d_vipconfdirty_path = $g['varrun_path'] . "/vip.conf.dirty";
|
84
|
$d_vsconfdirty_path = $g['varrun_path'] . "/vs.conf.dirty";
|
85
|
$d_shaperconfdirty_path = $g['varrun_path'] . "/shaper.conf.dirty";
|
86
|
|
87
|
/* OpenVPN Directories */
|
88
|
$d_ovpnsrvdirty_path = "/tmp/ovpn-srv.dirty";
|
89
|
$d_ovpncrldirty_path = "/tmp/ovpn-crl.dirty";
|
90
|
$d_ovpnclidirty_path = "/tmp/ovpn-cli.dirty";
|
91
|
/* used by progress bar */
|
92
|
$lastseen = "-1";
|
93
|
|
94
|
if (file_exists($d_firmwarelock_path)) {
|
95
|
if (!$d_isfwfile) {
|
96
|
header("Location: system_firmware.php");
|
97
|
exit;
|
98
|
} else {
|
99
|
return;
|
100
|
}
|
101
|
}
|
102
|
|
103
|
/* some well knows ports */
|
104
|
$wkports = array(
|
105
|
5999 => "CVSup",
|
106
|
53 => "DNS",
|
107
|
21 => "FTP",
|
108
|
3000 => "HBCI",
|
109
|
80 => "HTTP",
|
110
|
443 => "HTTPS",
|
111
|
5190 => "ICQ",
|
112
|
113 => "IDENT/AUTH",
|
113
|
143 => "IMAP",
|
114
|
993 => "IMAP/S",
|
115
|
4500 => "IPsec NAT-T",
|
116
|
500 => "ISAKMP",
|
117
|
1701 => "L2TP",
|
118
|
389 => "LDAP",
|
119
|
1755 => "MMS/TCP",
|
120
|
7000 => "MMS/UDP",
|
121
|
445 => "MS DS",
|
122
|
3389 => "MS RDP",
|
123
|
1512 => "MS WINS",
|
124
|
1863 => "MSN",
|
125
|
119 => "NNTP",
|
126
|
123 => "NTP",
|
127
|
138 => "NetBIOS-DGM",
|
128
|
137 => "NetBIOS-NS",
|
129
|
139 => "NetBIOS-SSN",
|
130
|
1194 => "OpenVPN",
|
131
|
110 => "POP3",
|
132
|
995 => "POP3/S",
|
133
|
1723 => "PPTP",
|
134
|
1812 => "RADIUS",
|
135
|
1813 => "RADIUS accounting",
|
136
|
5004 => "RTP",
|
137
|
5060 => "SIP",
|
138
|
25 => "SMTP",
|
139
|
465 => "SMTP/S",
|
140
|
161 => "SNMP",
|
141
|
162 => "SNMP-Trap",
|
142
|
22 => "SSH",
|
143
|
3478 => "STUN",
|
144
|
23 => "Telnet",
|
145
|
69 => "TFTP",
|
146
|
5900 => "VNC");
|
147
|
|
148
|
$specialnets = array("wanip" => "WAN address", "lanip" => "LAN address", "lan" => "LAN net", "pptp" => "PPTP clients");
|
149
|
|
150
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
151
|
$specialnets['opt' . $i] = $config['interfaces']['opt' . $i]['descr'] . " net";
|
152
|
}
|
153
|
|
154
|
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
|
155
|
"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
|
156
|
"10half" => "10BASE-T half-duplex");
|
157
|
|
158
|
/* platforms that support firmware updating */
|
159
|
$fwupplatforms = array('pfSense', 'net45xx', 'net48xx', 'generic-pc', 'embedded', 'wrap', 'nanobsd');
|
160
|
|
161
|
/* IPsec defines */
|
162
|
$my_identifier_list = array('myaddress' => 'My IP address',
|
163
|
'address' => 'IP address',
|
164
|
'fqdn' => 'Domain name',
|
165
|
'user_fqdn' => 'User FQDN',
|
166
|
'dyn_dns' => 'Dynamic DNS');
|
167
|
|
168
|
$p1_ealgos = array('des' => 'DES', '3des' => '3DES', 'blowfish' => 'Blowfish',
|
169
|
'cast128' => 'CAST128','rijndael' => 'Rijndael (AES)', 'aes 256' => 'AES-256');
|
170
|
$p2_ealgos = array('des' => 'DES', '3des' => '3DES', 'blowfish' => 'Blowfish',
|
171
|
'cast128' => 'CAST128', 'rijndael' => 'Rijndael (AES)', 'aes 256' => 'AES-256');
|
172
|
|
173
|
$p1_halgos = array('sha1' => 'SHA1', 'md5' => 'MD5');
|
174
|
$p1_authentication_methods = array('pre_shared_key' => 'Pre-shared key', 'rsasig' => 'RSA signature');
|
175
|
$p2_halgos = array('hmac_sha1' => 'SHA1', 'hmac_md5' => 'MD5');
|
176
|
$p2_protos = array('esp' => 'ESP', 'ah' => 'AH');
|
177
|
$p2_pfskeygroups = array('0' => 'off', '1' => '1', '2' => '2', '5' => '5');
|
178
|
|
179
|
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
|
180
|
|
181
|
/* check for bad control characters */
|
182
|
foreach ($postdata as $pn => $pd) {
|
183
|
if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
|
184
|
$input_errors[] = "The field '" . $pn . "' contains invalid characters.";
|
185
|
}
|
186
|
}
|
187
|
|
188
|
for ($i = 0; $i < count($reqdfields); $i++) {
|
189
|
if ($_POST[$reqdfields[$i]] == "") {
|
190
|
$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
|
191
|
}
|
192
|
}
|
193
|
}
|
194
|
|
195
|
function print_input_errors($input_errors) {
|
196
|
global $g;
|
197
|
echo "<p><table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\">\n";
|
198
|
echo "<tr><td bgcolor=\"#990000\" width=\"36\" align=\"center\" valign=\"top\"><img src=\"./themes/".$g['theme']."/images/icons/icon_error.gif\" width=\"28\" height=\"32\"></td>\n";
|
199
|
echo "<td bgcolor=\"#FFD9D1\" style=\"padding-left: 8px; padding-top: 6px\">";
|
200
|
|
201
|
echo "<span class=\"errmsg\"><p>The following input errors were detected:<ul>\n";
|
202
|
foreach ($input_errors as $ierr) {
|
203
|
echo "<li>" . htmlspecialchars($ierr) . "</li>\n";
|
204
|
}
|
205
|
echo "</ul></span>";
|
206
|
|
207
|
echo "</td></tr></table></p> <br>";
|
208
|
}
|
209
|
|
210
|
function exec_rc_script($scriptname) {
|
211
|
|
212
|
global $d_sysrebootreqd_path;
|
213
|
|
214
|
$execoutput = "";
|
215
|
$retval = "";
|
216
|
exec($scriptname . " >/dev/null 2>&1", $execoutput, $retval);
|
217
|
return $retval;
|
218
|
}
|
219
|
|
220
|
function exec_rc_script_async($scriptname) {
|
221
|
|
222
|
global $d_sysrebootreqd_path;
|
223
|
$execoutput = "";
|
224
|
$retval = "";
|
225
|
|
226
|
exec("nohup " . $scriptname . " >/dev/null 2>&1 &", $execoutput, $retval);
|
227
|
return $retval;
|
228
|
}
|
229
|
|
230
|
function verify_gzip_file($fname) {
|
231
|
|
232
|
$returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
|
233
|
if ($returnvar != 0)
|
234
|
return 0;
|
235
|
else
|
236
|
return 1;
|
237
|
}
|
238
|
|
239
|
function print_info_box_np($msg) {
|
240
|
global $g;
|
241
|
echo "<table height=\"32\" width=\"100%\">\n";
|
242
|
echo " <tr>\n";
|
243
|
echo " <td>\n";
|
244
|
echo " <div style='background-color:#990000' id='redbox'>\n";
|
245
|
echo " <table width='100%'><tr><td width='8%'>\n";
|
246
|
echo " <img style='vertical-align:middle' src=\"/themes/".$g['theme']."/images/icons/icon_exclam.gif\" width=\"28\" height=\"32\">\n";
|
247
|
echo " </td>\n";
|
248
|
echo " <td width='70%'><font color='white'><b>{$msg}</b></font>\n";
|
249
|
echo " </td>";
|
250
|
if(stristr($msg, "apply") == true) {
|
251
|
echo " <td>";
|
252
|
echo " <input name=\"apply\" type=\"submit\" class=\"formbtn\" id=\"apply\" value=\"Apply changes\">\n";
|
253
|
echo " </td>";
|
254
|
}
|
255
|
echo " </tr></table>\n";
|
256
|
echo " </div>\n";
|
257
|
echo " </td>\n";
|
258
|
echo "</table>\n";
|
259
|
echo "<script type=\"text/javascript\">\n";
|
260
|
echo "NiftyCheck();\n";
|
261
|
echo "Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");\n";
|
262
|
echo "Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");\n";
|
263
|
echo "</script>\n";
|
264
|
echo "\n<br>\n";
|
265
|
}
|
266
|
|
267
|
function print_info_box($msg) {
|
268
|
echo "<p>";
|
269
|
print_info_box_np($msg);
|
270
|
echo "</p>";
|
271
|
}
|
272
|
|
273
|
function format_bytes($bytes) {
|
274
|
if ($bytes >= 1073741824) {
|
275
|
return sprintf("%.2f GB", $bytes/1073741824);
|
276
|
} else if ($bytes >= 1048576) {
|
277
|
return sprintf("%.2f MB", $bytes/1048576);
|
278
|
} else if ($bytes >= 1024) {
|
279
|
return sprintf("%.0f KB", $bytes/1024);
|
280
|
} else {
|
281
|
return sprintf("%d bytes", $bytes);
|
282
|
}
|
283
|
}
|
284
|
|
285
|
function get_std_save_message($ok) {
|
286
|
global $d_sysrebootreqd_path;
|
287
|
|
288
|
return "The changes have been applied successfully. You can also <a href='status_filter_reload.php'>monitor</a> the filter reload progress.";
|
289
|
}
|
290
|
|
291
|
function pprint_address($adr) {
|
292
|
global $specialnets;
|
293
|
|
294
|
if (isset($adr['any'])) {
|
295
|
$padr = "*";
|
296
|
} else if ($adr['network']) {
|
297
|
if (preg_match("/opt[0-999]ip/", $adr['network'])) {
|
298
|
$padr = "Interface IP address";
|
299
|
} else {
|
300
|
$padr = $specialnets[$adr['network']];
|
301
|
}
|
302
|
} else {
|
303
|
$padr = $adr['address'];
|
304
|
}
|
305
|
|
306
|
if (isset($adr['not']))
|
307
|
$padr = "! " . $padr;
|
308
|
|
309
|
return $padr;
|
310
|
}
|
311
|
|
312
|
function pprint_port($port) {
|
313
|
global $wkports;
|
314
|
|
315
|
$pport = "";
|
316
|
|
317
|
if (!$port)
|
318
|
return "*";
|
319
|
else {
|
320
|
$srcport = explode("-", $port);
|
321
|
if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
|
322
|
$pport = $srcport[0];
|
323
|
if ($wkports[$srcport[0]]) {
|
324
|
$pport .= " (" . $wkports[$srcport[0]] . ")";
|
325
|
}
|
326
|
} else
|
327
|
$pport .= $srcport[0] . " - " . $srcport[1];
|
328
|
}
|
329
|
|
330
|
return $pport;
|
331
|
}
|
332
|
|
333
|
function captiveportal_users_sort() {
|
334
|
global $g, $config;
|
335
|
|
336
|
function cpusercmp($a, $b) {
|
337
|
return strcasecmp($a['name'], $b['name']);
|
338
|
}
|
339
|
|
340
|
usort($config['captiveportal']['user'], "cpusercmp");
|
341
|
}
|
342
|
|
343
|
/* sort by interface only, retain the original order of rules that apply to
|
344
|
the same interface */
|
345
|
function filter_rules_sort() {
|
346
|
global $config;
|
347
|
|
348
|
/* mark each rule with the sequence number (to retain the order while sorting) */
|
349
|
for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
|
350
|
$config['filter']['rule'][$i]['seq'] = $i;
|
351
|
|
352
|
function filtercmp($a, $b) {
|
353
|
if ($a['interface'] == $b['interface'])
|
354
|
return $a['seq'] - $b['seq'];
|
355
|
else
|
356
|
return -strcmp($a['interface'], $b['interface']);
|
357
|
}
|
358
|
|
359
|
usort($config['filter']['rule'], "filtercmp");
|
360
|
|
361
|
/* strip the sequence numbers again */
|
362
|
for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
|
363
|
unset($config['filter']['rule'][$i]['seq']);
|
364
|
}
|
365
|
|
366
|
function nat_rules_sort() {
|
367
|
global $config;
|
368
|
|
369
|
function natcmp($a, $b) {
|
370
|
if ($a['external-address'] == $b['external-address']) {
|
371
|
if ($a['protocol'] == $b['protocol']) {
|
372
|
if ($a['external-port'] == $b['external-port']) {
|
373
|
return 0;
|
374
|
} else {
|
375
|
return ($a['external-port'] - $b['external-port']);
|
376
|
}
|
377
|
} else {
|
378
|
return strcmp($a['protocol'], $b['protocol']);
|
379
|
}
|
380
|
} else if (!$a['external-address'])
|
381
|
return 1;
|
382
|
else if (!$b['external-address'])
|
383
|
return -1;
|
384
|
else
|
385
|
return ipcmp($a['external-address'], $b['external-address']);
|
386
|
}
|
387
|
|
388
|
usort($config['nat']['rule'], "natcmp");
|
389
|
}
|
390
|
|
391
|
function nat_1to1_rules_sort() {
|
392
|
global $g, $config;
|
393
|
|
394
|
function nat1to1cmp($a, $b) {
|
395
|
return ipcmp($a['external'], $b['external']);
|
396
|
}
|
397
|
|
398
|
usort($config['nat']['onetoone'], "nat1to1cmp");
|
399
|
}
|
400
|
|
401
|
function nat_server_rules_sort() {
|
402
|
global $g, $config;
|
403
|
|
404
|
function natservercmp($a, $b) {
|
405
|
return ipcmp($a['ipaddr'], $b['ipaddr']);
|
406
|
}
|
407
|
|
408
|
usort($config['nat']['servernat'], "natservercmp");
|
409
|
}
|
410
|
|
411
|
function nat_out_rules_sort() {
|
412
|
global $g, $config;
|
413
|
|
414
|
function natoutcmp($a, $b) {
|
415
|
return strcmp($a['source']['network'], $b['source']['network']);
|
416
|
}
|
417
|
|
418
|
usort($config['nat']['advancedoutbound']['rule'], "natoutcmp");
|
419
|
}
|
420
|
|
421
|
function pptpd_users_sort() {
|
422
|
global $g, $config;
|
423
|
|
424
|
function usercmp($a, $b) {
|
425
|
return strcasecmp($a['name'], $b['name']);
|
426
|
}
|
427
|
|
428
|
usort($config['pptpd']['user'], "usercmp");
|
429
|
}
|
430
|
|
431
|
function pppoe_users_sort() {
|
432
|
global $g, $config;
|
433
|
|
434
|
function usercmp($a, $b) {
|
435
|
return strcasecmp($a['name'], $b['name']);
|
436
|
}
|
437
|
|
438
|
usort($config['pppoe']['user'], "usercmp");
|
439
|
}
|
440
|
|
441
|
function staticroutes_sort() {
|
442
|
global $g, $config;
|
443
|
|
444
|
function staticroutecmp($a, $b) {
|
445
|
return strcmp($a['network'], $b['network']);
|
446
|
}
|
447
|
|
448
|
usort($config['staticroutes']['route'], "staticroutecmp");
|
449
|
}
|
450
|
|
451
|
function hosts_sort() {
|
452
|
global $g, $config;
|
453
|
|
454
|
function hostcmp($a, $b) {
|
455
|
return strcasecmp($a['host'], $b['host']);
|
456
|
}
|
457
|
|
458
|
usort($config['dnsmasq']['hosts'], "hostcmp");
|
459
|
}
|
460
|
|
461
|
function staticmaps_sort($if) {
|
462
|
global $g, $config;
|
463
|
|
464
|
function staticmapcmp($a, $b) {
|
465
|
return ipcmp($a['ipaddr'], $b['ipaddr']);
|
466
|
}
|
467
|
|
468
|
usort($config['dhcpd'][$if]['staticmap'], "staticmapcmp");
|
469
|
}
|
470
|
|
471
|
function aliases_sort() {
|
472
|
global $g, $config;
|
473
|
|
474
|
function aliascmp($a, $b) {
|
475
|
return strcmp($a['name'], $b['name']);
|
476
|
}
|
477
|
|
478
|
usort($config['aliases']['alias'], "aliascmp");
|
479
|
}
|
480
|
|
481
|
function schedule_sort(){
|
482
|
global $g, $config;
|
483
|
|
484
|
function schedulecmp($a, $b) {
|
485
|
return strcmp($a['name'], $b['name']);
|
486
|
}
|
487
|
|
488
|
usort($config['schedules']['schedule'], "schedulecmp");
|
489
|
|
490
|
}
|
491
|
|
492
|
function ipsec_mobilekey_sort() {
|
493
|
global $g, $config;
|
494
|
|
495
|
function mobilekeycmp($a, $b) {
|
496
|
return strcmp($a['ident'][0], $b['ident'][0]);
|
497
|
}
|
498
|
|
499
|
usort($config['ipsec']['mobilekey'], "mobilekeycmp");
|
500
|
}
|
501
|
|
502
|
function proxyarp_sort() {
|
503
|
global $g, $config;
|
504
|
|
505
|
function proxyarpcmp($a, $b) {
|
506
|
if (isset($a['network']))
|
507
|
list($ast,$asn) = explode("/", $a['network']);
|
508
|
else if (isset($a['range'])) {
|
509
|
$ast = $a['range']['from'];
|
510
|
$asn = 32;
|
511
|
}
|
512
|
if (isset($b['network']))
|
513
|
list($bst,$bsn) = explode("/", $b['network']);
|
514
|
else if (isset($b['range'])) {
|
515
|
$bst = $b['range']['from'];
|
516
|
$bsn = 32;
|
517
|
}
|
518
|
if (ipcmp($ast, $bst) == 0)
|
519
|
return ($asn - $bsn);
|
520
|
else
|
521
|
return ipcmp($ast, $bst);
|
522
|
}
|
523
|
|
524
|
usort($config['proxyarp']['proxyarpnet'], "proxyarpcmp");
|
525
|
}
|
526
|
|
527
|
function passthrumacs_sort() {
|
528
|
global $g, $config;
|
529
|
|
530
|
function passthrumacscmp($a, $b) {
|
531
|
return strcmp($a['mac'], $b['mac']);
|
532
|
}
|
533
|
|
534
|
usort($config['captiveportal']['passthrumac'],"passthrumacscmp");
|
535
|
}
|
536
|
|
537
|
function cpelements_sort() {
|
538
|
global $g, $config;
|
539
|
|
540
|
function cpelementscmp($a, $b) {
|
541
|
return strcasecmp($a['name'], $b['name']);
|
542
|
}
|
543
|
|
544
|
usort($config['captiveportal']['element'],"cpelementscmp");
|
545
|
}
|
546
|
|
547
|
function allowedips_sort() {
|
548
|
global $g, $config;
|
549
|
|
550
|
function allowedipscmp($a, $b) {
|
551
|
return strcmp($a['ip'], $b['ip']);
|
552
|
}
|
553
|
|
554
|
usort($config['captiveportal']['allowedip'],"allowedipscmp");
|
555
|
}
|
556
|
|
557
|
function wol_sort() {
|
558
|
global $g, $config;
|
559
|
|
560
|
function wolcmp($a, $b) {
|
561
|
return strcmp($a['descr'], $b['descr']);
|
562
|
}
|
563
|
|
564
|
usort($config['wol']['wolentry'], "wolcmp");
|
565
|
}
|
566
|
|
567
|
function sort_rule_by_queue_priority() {
|
568
|
global $g, $config;
|
569
|
global $queues;
|
570
|
|
571
|
function rqpcmp($a, $b) {
|
572
|
global $queues;
|
573
|
|
574
|
$ra = $queues[$a['outqueue']];
|
575
|
$rb = $queues[$b['outqueue']];
|
576
|
|
577
|
if ($ra == $rb)
|
578
|
return 0;
|
579
|
/* reverse sort - we want higher priority first */
|
580
|
return ($ra < $rb) ? 1 : -1;
|
581
|
}
|
582
|
|
583
|
foreach($config['shaper']['queue'] as $q) {
|
584
|
$queues[$q['name']] = $q['priority'];
|
585
|
}
|
586
|
|
587
|
usort($config['shaper']['rule'], "rqpcmp");
|
588
|
}
|
589
|
function gentitle($pgname) {
|
590
|
global $config;
|
591
|
return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
|
592
|
}
|
593
|
|
594
|
/* update the changedesc and changecount(er) variables */
|
595
|
function update_changedesc($update) {
|
596
|
global $changedesc;
|
597
|
global $changecount;
|
598
|
|
599
|
$changedesc .= " {$update}";
|
600
|
$changecount++;
|
601
|
}
|
602
|
|
603
|
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
|
604
|
global $g, $config;
|
605
|
$sor = isset($config['syslog']['reverse']) ? "-r" : "";
|
606
|
$logarr = "";
|
607
|
$grepline = " ";
|
608
|
if(is_array($grepfor))
|
609
|
foreach($grepfor as $agrep)
|
610
|
$grepline .= " | grep \"$agrep\"";
|
611
|
if(is_array($grepinvert))
|
612
|
foreach($grepinvert as $agrep)
|
613
|
$grepline .= " | grep -v \"$agrep\"";
|
614
|
exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
|
615
|
/* comment out debug code
|
616
|
echo "<!-- /usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail} -->";
|
617
|
*/
|
618
|
foreach ($logarr as $logent) {
|
619
|
$logent = preg_split("/\s+/", $logent, 6);
|
620
|
echo "<tr valign=\"top\">\n";
|
621
|
if ($withorig) {
|
622
|
$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
|
623
|
echo "<td class=\"listlr\" nowrap>" . $entry_date_time . "</td>\n";
|
624
|
echo "<td class=\"listr\">" . htmlspecialchars($logent[4] . " " . $logent[5]) . "</td>\n";
|
625
|
} else {
|
626
|
echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
|
627
|
}
|
628
|
echo "</tr>\n";
|
629
|
}
|
630
|
}
|
631
|
|
632
|
function return_clog($logfile, $tail, $grepfor = "", $grepinvert = "", $grepreverse = false) {
|
633
|
global $g, $config;
|
634
|
$sor = isset($config['syslog']['reverse']) ? "-r" : "";
|
635
|
$sor = isset($grepreverse) ? "-r" : "";
|
636
|
$logarr = "";
|
637
|
$grepline = " ";
|
638
|
if(is_array($grepfor))
|
639
|
foreach($grepfor as $agrep)
|
640
|
$grepline .= " | grep \"$agrep\"";
|
641
|
if(is_array($grepinvert))
|
642
|
foreach($grepinvert as $agrep)
|
643
|
$grepline .= " | grep -v \"$agrep\"";
|
644
|
/* comment out debug code
|
645
|
echo "<!-- /usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail} -->";
|
646
|
*/
|
647
|
exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
|
648
|
return($logarr);
|
649
|
}
|
650
|
|
651
|
/* Check if variable has changed, update and log if it has
|
652
|
* returns true if var changed
|
653
|
* varname = variable name in plain text
|
654
|
* orig = original value
|
655
|
* new = new value
|
656
|
*/
|
657
|
function update_if_changed($varname, & $orig, $new) {
|
658
|
if (is_array($orig) && is_array($new)) {
|
659
|
$a_diff = array_diff($orig, $new);
|
660
|
foreach ($a_diff as $diff) {
|
661
|
update_changedesc("removed {$varname}: \"{$diff}\"");
|
662
|
}
|
663
|
$a_diff = array_diff($new, $orig);
|
664
|
foreach ($a_diff as $diff) {
|
665
|
update_changedesc("added {$varname}: \"{$diff}\"");
|
666
|
}
|
667
|
$orig = $new;
|
668
|
return true;
|
669
|
|
670
|
} else {
|
671
|
if ($orig != $new) {
|
672
|
update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
|
673
|
$orig = $new;
|
674
|
return true;
|
675
|
}
|
676
|
}
|
677
|
return false;
|
678
|
}
|
679
|
|
680
|
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
|
681
|
|
682
|
if (isset($adr['any']))
|
683
|
$padr = "any";
|
684
|
else if ($adr['network'])
|
685
|
$padr = $adr['network'];
|
686
|
else if ($adr['address']) {
|
687
|
list($padr, $pmask) = explode("/", $adr['address']);
|
688
|
if (!$pmask)
|
689
|
$pmask = 32;
|
690
|
}
|
691
|
|
692
|
if (isset($adr['not']))
|
693
|
$pnot = 1;
|
694
|
else
|
695
|
$pnot = 0;
|
696
|
|
697
|
if ($adr['port']) {
|
698
|
list($pbeginport, $pendport) = explode("-", $adr['port']);
|
699
|
if (!$pendport)
|
700
|
$pendport = $pbeginport;
|
701
|
} else {
|
702
|
if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
|
703
|
/* Item is a port alias */
|
704
|
} else {
|
705
|
$pbeginport = "any";
|
706
|
$pendport = "any";
|
707
|
}
|
708
|
}
|
709
|
}
|
710
|
|
711
|
function pconfig_to_address(&$adr, $padr, $pmask, $pnot=false, $pbeginport=0, $pendport=0) {
|
712
|
|
713
|
$adr = array();
|
714
|
|
715
|
if ($padr == "any")
|
716
|
$adr['any'] = true;
|
717
|
else if (is_specialnet($padr))
|
718
|
$adr['network'] = $padr;
|
719
|
else {
|
720
|
$adr['address'] = $padr;
|
721
|
if ($pmask != 32)
|
722
|
$adr['address'] .= "/" . $pmask;
|
723
|
}
|
724
|
|
725
|
if ($pnot)
|
726
|
$adr['not'] = true;
|
727
|
else
|
728
|
unset($adr['not']);
|
729
|
|
730
|
if (($pbeginport != 0) && ($pbeginport != "any")) {
|
731
|
if ($pbeginport != $pendport)
|
732
|
$adr['port'] = $pbeginport . "-" . $pendport;
|
733
|
else
|
734
|
$adr['port'] = $pbeginport;
|
735
|
}
|
736
|
|
737
|
if(alias_expand($pbeginport)) {
|
738
|
$adr['port'] = $pbeginport;
|
739
|
}
|
740
|
}
|
741
|
|
742
|
function is_specialnet($net) {
|
743
|
global $specialsrcdst;
|
744
|
|
745
|
if (in_array($net, $specialsrcdst) || strstr($net, "opt"))
|
746
|
return true;
|
747
|
else
|
748
|
return false;
|
749
|
}
|
750
|
|
751
|
function ipsec_ca_sort() {
|
752
|
global $g, $config;
|
753
|
|
754
|
function ipseccacmp($a, $b) {
|
755
|
return strcmp($a['ident'], $b['ident']);
|
756
|
}
|
757
|
|
758
|
usort($config['ipsec']['cacert'], "ipseccacmp");
|
759
|
}
|
760
|
|
761
|
|
762
|
?>
|