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