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