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