Project

General

Profile

Download (20.6 KB) Statistics
| Branch: | Tag: | Revision:
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_vsconfdirty_path = $g['varrun_path'] . "/vs.conf.dirty";
80
$d_shaperconfdirty_path = $g['varrun_path'] . "/shaper.conf.dirty";
81

    
82
/* OpenVPN Directories */
83
$d_ovpnsrvdirty_path = "/tmp/ovpn-srv.dirty";
84
$d_ovpncrldirty_path = "/tmp/ovpn-crl.dirty";
85
$d_ovpnclidirty_path = "/tmp/ovpn-cli.dirty";
86
/* used by progress bar */
87
$lastseen = "-1";
88

    
89
if (file_exists($d_firmwarelock_path)) {
90
	if (!$d_isfwfile) {
91
		header("Location: system_firmware.php");
92
		exit;
93
	} else {
94
		return;
95
	}
96
}
97

    
98
/* some well knows ports */
99
$wkports = array(3389 => "MS RDP",
100
	21 => "FTP",
101
	22 => "SSH",
102
	23 => "Telnet",
103
	25 => "SMTP",
104
	53 => "DNS",
105
	69 => "TFTP",
106
	80 => "HTTP",
107
	110 => "POP3",
108
	113 => "IDENT/AUTH",
109
	119 => "NNTP",
110
	123 => "NTP",
111
	137 => "NetBIOS-NS",
112
	138 => "NetBIOS-DGM",
113
	139 => "NetBIOS-SSN",
114
	143 => "IMAP",
115
	161 => "SNMP",
116
	162 => "SNMP-Trap",
117
	389 => "LDAP",
118
	443 => "HTTPS",
119
	445 => "MS DS",
120
	465 => "SMTP/S",
121
	500 => "isakmp",
122
	514 => "Syslog",
123
	993 => "IMAP/S",
124
	995 => "POP3/S",
125
	1194 => "OpenVPN",
126
	1512 => "MS WINS",
127
	1701 => "L2TP",
128
	1723 => "PPTP",
129
	1812 => "Radius",
130
	1813 => "Radius-accounting",
131
	3000 => "HBCI",
132
	4500 => "IPSec NAT-T",
133
	5190 => "ICQ",
134
	5900 => "VNC",
135
	5999 => "CVSup");
136

    
137
$specialnets = array("wanip" => "WAN address", "lanip" => "LAN address", "lan" => "LAN net", "pptp" => "PPTP clients");
138

    
139
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
140
	$specialnets['opt' . $i] = $config['interfaces']['opt' . $i]['descr'] . " net";
141
}
142

    
143
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
144
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
145
	"10half" => "10BASE-T half-duplex");
146

    
147
/* platforms that support firmware updating */
148
$fwupplatforms = array('pfSense', 'net45xx', 'net48xx', 'generic-pc', 'embedded', 'wrap');
149

    
150
/* IPsec defines */
151
$my_identifier_list = array('myaddress' => 'My IP address',
152
				'address' => 'IP address',
153
				'fqdn' => 'Domain name',
154
				'user_fqdn' => 'User FQDN',
155
				'dyn_dns' => 'Dynamic DNS');
156

    
157
$p1_ealgos = array('des' => 'DES', '3des' => '3DES', 'blowfish' => 'Blowfish',
158
		'cast128' => 'CAST128','rijndael' => 'Rijndael (AES)', 'rijndael 256' => 'Rijndael 256');
159
$p2_ealgos = array('des' => 'DES', '3des' => '3DES', 'blowfish' => 'Blowfish',
160
		'cast128' => 'CAST128', 'rijndael' => 'Rijndael (AES)', 'rijndael 256' => 'Rijndael 256');
161

    
162
$p1_halgos = array('sha1' => 'SHA1', 'md5' => 'MD5');
163
$p1_authentication_methods = array('pre_shared_key' => 'Pre-shared key', 'rsasig' => 'RSA signature');
164
$p2_halgos = array('hmac_sha1' => 'SHA1', 'hmac_md5' => 'MD5');
165
$p2_protos = array('esp' => 'ESP', 'ah' => 'AH');
166
$p2_pfskeygroups = array('0' => 'off', '1' => '1', '2' => '2', '5' => '5');
167

    
168
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
169

    
170
	/* check for bad control characters */
171
	foreach ($postdata as $pn => $pd) {
172
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
173
			$input_errors[] = "The field '" . $pn . "' contains invalid characters.";
174
		}
175
	}
176

    
177
	for ($i = 0; $i < count($reqdfields); $i++) {
178
		if ($_POST[$reqdfields[$i]] == "") {
179
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
180
		}
181
	}
182
}
183

    
184
function print_input_errors($input_errors) {
185
	global $g;
186
	echo "<p><table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\">\n";
187
	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";
188
	echo "<td bgcolor=\"#FFD9D1\" style=\"padding-left: 8px; padding-top: 6px\">";
189

    
190
	echo "<span class=\"errmsg\"><p>The following input errors were detected:<ul>\n";
191
	foreach ($input_errors as $ierr) {
192
		echo "<li>" . htmlspecialchars($ierr) . "</li>\n";
193
	}
194
	echo "</ul></span>";
195

    
196
	echo "</td></tr></table></p>&nbsp;<br>";
197
}
198

    
199
function exec_rc_script($scriptname) {
200

    
201
	global $d_sysrebootreqd_path;
202

    
203
	$execoutput = "";
204
	$retval = "";
205
	exec($scriptname . " >/dev/null 2>&1", $execoutput, $retval);
206
	return $retval;
207
}
208

    
209
function exec_rc_script_async($scriptname) {
210

    
211
	global $d_sysrebootreqd_path;
212
	$execoutput = "";
213
	$retval = "";
214

    
215
	exec("nohup " . $scriptname . " >/dev/null 2>&1 &", $execoutput, $retval);
216
	return $retval;
217
}
218

    
219
function verify_gzip_file($fname) {
220

    
221
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
222
	if ($returnvar != 0)
223
		return 0;
224
	else
225
		return 1;
226
}
227

    
228
function print_info_box_np($msg) {
229
	global $g;
230
	echo "<table height=\"32\" width=\"100%\">\n";
231
	echo "  <tr>\n";
232
	echo "   <td>\n";
233
	echo "      <div style='background-color:#990000' id='redbox'>\n";
234
	echo "       <table width='100%'><tr><td width='8%'>\n";
235
	echo "        &nbsp;&nbsp;&nbsp;<img style='vertical-align:middle' src=\"/themes/".$g['theme']."/images/icons/icon_exclam.gif\" width=\"28\" height=\"32\">\n";
236
	echo "        </td>\n";
237
	echo "        <td width='70%'><font color='white'><b>{$msg}</b></font>\n";
238
	echo "        </td>";
239
	if(stristr($msg, "apply") == true) {
240
		echo "         <td>";
241
		echo "           <input name=\"apply\" type=\"submit\" class=\"formbtn\" id=\"apply\" value=\"Apply changes\">\n";
242
		echo "         </td>";
243
	}
244
	echo "        </tr></table>\n";
245
	echo "       </div>\n";
246
	echo "    </td>\n";
247
	echo "</table>\n";
248
	echo "<script type=\"text/javascript\">\n";
249
	echo "NiftyCheck();\n";
250
	echo "Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");\n";
251
	echo "Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");\n";
252
	echo "</script>\n";
253
	echo "\n<br>\n";
254
}
255

    
256
function print_info_box($msg) {
257
	echo "<p>";
258
	print_info_box_np($msg);
259
	echo "</p>";
260
}
261

    
262
function format_bytes($bytes) {
263
	if ($bytes >= 1073741824) {
264
		return sprintf("%.2f GB", $bytes/1073741824);
265
	} else if ($bytes >= 1048576) {
266
		return sprintf("%.2f MB", $bytes/1048576);
267
	} else if ($bytes >= 1024) {
268
		return sprintf("%.0f KB", $bytes/1024);
269
	} else {
270
		return sprintf("%d bytes", $bytes);
271
	}
272
}
273

    
274
function get_std_save_message($ok) {
275
	global $d_sysrebootreqd_path;
276

    
277
	return "The changes have been applied successfully.  You can also <a href='status_filter_reload.php'>monitor</a> the filter reload progress.";
278
}
279

    
280
function pprint_address($adr) {
281
	global $specialnets;
282

    
283
	if (isset($adr['any'])) {
284
		$padr = "*";
285
	} else if ($adr['network']) {
286
		if (preg_match("/opt[0-999]ip/", $adr['network'])) {
287
			$padr = "Interface IP address";
288
		} else {
289
			$padr = $specialnets[$adr['network']];
290
		}
291
	} else {
292
		$padr = $adr['address'];
293
	}
294

    
295
	if (isset($adr['not']))
296
		$padr = "! " . $padr;
297

    
298
	return $padr;
299
}
300

    
301
function pprint_port($port) {
302
	global $wkports;
303

    
304
	$pport = "";
305

    
306
	if (!$port)
307
		return "*";
308
	else {
309
		$srcport = explode("-", $port);
310
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
311
			$pport = $srcport[0];
312
			if ($wkports[$srcport[0]]) {
313
				$pport .= " (" . $wkports[$srcport[0]] . ")";
314
			}
315
		} else
316
			$pport .= $srcport[0] . " - " . $srcport[1];
317
	}
318

    
319
	return $pport;
320
}
321

    
322
function captiveportal_users_sort() {
323
	global $g, $config;
324

    
325
	function cpusercmp($a, $b) {
326
		return strcasecmp($a['name'], $b['name']);
327
	}
328

    
329
	usort($config['captiveportal']['user'], "cpusercmp");
330
}
331

    
332
/* sort by interface only, retain the original order of rules that apply to
333
   the same interface */
334
function filter_rules_sort() {
335
	global $config;
336

    
337
	/* mark each rule with the sequence number (to retain the order while sorting) */
338
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
339
		$config['filter']['rule'][$i]['seq'] = $i;
340

    
341
	function filtercmp($a, $b) {
342
		if ($a['interface'] == $b['interface'])
343
			return $a['seq'] - $b['seq'];
344
		else
345
			return -strcmp($a['interface'], $b['interface']);
346
	}
347

    
348
	usort($config['filter']['rule'], "filtercmp");
349

    
350
	/* strip the sequence numbers again */
351
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
352
		unset($config['filter']['rule'][$i]['seq']);
353
}
354

    
355
function nat_rules_sort() {
356
	global $config;
357

    
358
	function natcmp($a, $b) {
359
		if ($a['external-address'] == $b['external-address']) {
360
			if ($a['protocol'] == $b['protocol']) {
361
				if ($a['external-port'] == $b['external-port']) {
362
					return 0;
363
				} else {
364
					return ($a['external-port'] - $b['external-port']);
365
				}
366
			} else {
367
				return strcmp($a['protocol'], $b['protocol']);
368
			}
369
		} else if (!$a['external-address'])
370
			return 1;
371
		else if (!$b['external-address'])
372
			return -1;
373
		else
374
			return ipcmp($a['external-address'], $b['external-address']);
375
	}
376

    
377
	usort($config['nat']['rule'], "natcmp");
378
}
379

    
380
function nat_1to1_rules_sort() {
381
	global $g, $config;
382

    
383
	function nat1to1cmp($a, $b) {
384
		return ipcmp($a['external'], $b['external']);
385
	}
386

    
387
	usort($config['nat']['onetoone'], "nat1to1cmp");
388
}
389

    
390
function nat_server_rules_sort() {
391
	global $g, $config;
392

    
393
	function natservercmp($a, $b) {
394
		return ipcmp($a['ipaddr'], $b['ipaddr']);
395
	}
396

    
397
	usort($config['nat']['servernat'], "natservercmp");
398
}
399

    
400
function nat_out_rules_sort() {
401
	global $g, $config;
402

    
403
	function natoutcmp($a, $b) {
404
		return strcmp($a['source']['network'], $b['source']['network']);
405
	}
406

    
407
	usort($config['nat']['advancedoutbound']['rule'], "natoutcmp");
408
}
409

    
410
function pptpd_users_sort() {
411
	global $g, $config;
412

    
413
	function usercmp($a, $b) {
414
		return strcasecmp($a['name'], $b['name']);
415
	}
416

    
417
	usort($config['pptpd']['user'], "usercmp");
418
}
419

    
420
function pppoe_users_sort() {
421
	global $g, $config;
422

    
423
	function usercmp($a, $b) {
424
		return strcasecmp($a['name'], $b['name']);
425
	}
426

    
427
	usort($config['pppoe']['user'], "usercmp");
428
}
429

    
430
function staticroutes_sort() {
431
	global $g, $config;
432

    
433
	function staticroutecmp($a, $b) {
434
		return strcmp($a['network'], $b['network']);
435
	}
436

    
437
	usort($config['staticroutes']['route'], "staticroutecmp");
438
}
439

    
440
function hosts_sort() {
441
	global $g, $config;
442

    
443
	function hostcmp($a, $b) {
444
		return strcasecmp($a['host'], $b['host']);
445
	}
446

    
447
	usort($config['dnsmasq']['hosts'], "hostcmp");
448
}
449

    
450
function staticmaps_sort($if) {
451
	global $g, $config;
452

    
453
	function staticmapcmp($a, $b) {
454
		return ipcmp($a['ipaddr'], $b['ipaddr']);
455
	}
456

    
457
	usort($config['dhcpd'][$if]['staticmap'], "staticmapcmp");
458
}
459

    
460
function aliases_sort() {
461
	global $g, $config;
462

    
463
	function aliascmp($a, $b) {
464
		return strcmp($a['name'], $b['name']);
465
	}
466

    
467
	usort($config['aliases']['alias'], "aliascmp");
468
}
469

    
470
function schedule_sort(){
471
	global $g, $config;
472

    
473
	function schedulecmp($a, $b) {
474
		return strcmp($a['name'], $b['name']);
475
	}
476

    
477
	usort($config['schedules']['schedule'], "schedulecmp");
478

    
479
}
480

    
481
function ipsec_mobilekey_sort() {
482
	global $g, $config;
483

    
484
	function mobilekeycmp($a, $b) {
485
		return strcmp($a['ident'][0], $b['ident'][0]);
486
	}
487

    
488
	usort($config['ipsec']['mobilekey'], "mobilekeycmp");
489
}
490

    
491
function proxyarp_sort() {
492
	global $g, $config;
493

    
494
	function proxyarpcmp($a, $b) {
495
		if (isset($a['network']))
496
			list($ast,$asn) = explode("/", $a['network']);
497
		else if (isset($a['range'])) {
498
			$ast = $a['range']['from'];
499
			$asn = 32;
500
		}
501
		if (isset($b['network']))
502
			list($bst,$bsn) = explode("/", $b['network']);
503
		else if (isset($b['range'])) {
504
			$bst = $b['range']['from'];
505
			$bsn = 32;
506
		}
507
		if (ipcmp($ast, $bst) == 0)
508
			return ($asn - $bsn);
509
		else
510
			return ipcmp($ast, $bst);
511
	}
512

    
513
	usort($config['proxyarp']['proxyarpnet'], "proxyarpcmp");
514
}
515

    
516
function passthrumacs_sort() {
517
	global $g, $config;
518

    
519
	function passthrumacscmp($a, $b) {
520
		return strcmp($a['mac'], $b['mac']);
521
	}
522

    
523
	usort($config['captiveportal']['passthrumac'],"passthrumacscmp");
524
}
525

    
526
function cpelements_sort() {
527
	global $g, $config;
528

    
529
	function cpelementscmp($a, $b) {
530
		return strcasecmp($a['name'], $b['name']);
531
	}
532

    
533
	usort($config['captiveportal']['element'],"cpelementscmp");
534
}
535

    
536
function allowedips_sort() {
537
	global $g, $config;
538

    
539
	function allowedipscmp($a, $b) {
540
		return strcmp($a['ip'], $b['ip']);
541
	}
542

    
543
	usort($config['captiveportal']['allowedip'],"allowedipscmp");
544
}
545

    
546
function wol_sort() {
547
	global $g, $config;
548

    
549
	function wolcmp($a, $b) {
550
		return strcmp($a['descr'], $b['descr']);
551
	}
552

    
553
	usort($config['wol']['wolentry'], "wolcmp");
554
}
555

    
556
function sort_rule_by_queue_priority() {
557
	global $g, $config;
558
	global $queues;
559

    
560
	function rqpcmp($a, $b) {
561
		global $queues;
562

    
563
		$ra = $queues[$a['outqueue']];
564
		$rb = $queues[$b['outqueue']];
565

    
566
		if ($ra == $rb)
567
			return 0;
568
		/* reverse sort - we want higher priority first */
569
		return ($ra < $rb) ? 1 : -1;
570
	}
571

    
572
	foreach($config['shaper']['queue'] as $q) {
573
		$queues[$q['name']] = $q['priority'];
574
	}
575

    
576
	usort($config['shaper']['rule'], "rqpcmp");
577
}
578
function gentitle($pgname) {
579
	global $config;
580
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
581
}
582

    
583
/* update the changedesc and changecount(er) variables */
584
function update_changedesc($update) {
585
	global $changedesc;
586
	global $changecount;
587

    
588
	$changedesc .= " {$update}";
589
	$changecount++;
590
}
591

    
592
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
593
	global $g, $config;
594
    $sor = isset($config['syslog']['reverse']) ? "-r" : "";
595
    $logarr = "";
596
	$grepline = "  ";
597
	if(is_array($grepfor))
598
		foreach($grepfor as $agrep)
599
			$grepline .= " | grep \"$agrep\"";
600
	if(is_array($grepinvert))
601
		foreach($grepinvert as $agrep)
602
			$grepline .= " | grep -v \"$agrep\"";
603
	exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
604
    echo "<!-- /usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail} -->";
605
    foreach ($logarr as $logent) {
606
            $logent = preg_split("/\s+/", $logent, 6);
607
            echo "<tr valign=\"top\">\n";
608
            if ($withorig) {
609
            		$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
610
                    echo "<td class=\"listlr\" nowrap>" . $entry_date_time  . "</td>\n";
611
                    echo "<td class=\"listr\">" . htmlspecialchars($logent[4] . " " . $logent[5]) . "</td>\n";
612
            } else {
613
                    echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
614
            }
615
            echo "</tr>\n";
616
    }
617
}
618

    
619
function return_clog($logfile, $tail, $grepfor = "", $grepinvert = "", $grepreverse = false) {
620
	global $g, $config;
621
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
622
	$sor = isset($grepreverse) ? "-r" : "";
623
	$logarr = "";
624
	$grepline = "  ";
625
	if(is_array($grepfor))
626
		foreach($grepfor as $agrep)
627
			$grepline .= " | grep \"$agrep\"";
628
	if(is_array($grepinvert))
629
		foreach($grepinvert as $agrep)
630
			$grepline .= " | grep -v \"$agrep\"";
631
	echo "<!-- /usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail} -->";
632
	exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
633
	return($logarr);
634
}
635

    
636
/* Check if variable has changed, update and log if it has
637
 * returns true if var changed
638
 * varname = variable name in plain text
639
 * orig = original value
640
 * new = new value
641
 */
642
function update_if_changed($varname, & $orig, $new) {
643
	if (is_array($orig) && is_array($new)) {
644
		$a_diff = array_diff($orig, $new);
645
		foreach ($a_diff as $diff) {
646
			update_changedesc("removed {$varname}: \"{$diff}\"");
647
		}
648
		$a_diff = array_diff($new, $orig);
649
		foreach ($a_diff as $diff) {
650
			update_changedesc("added {$varname}: \"{$diff}\"");
651
		}
652
		$orig = $new;
653
		return true;
654

    
655
	} else {
656
		if ($orig != $new) {
657
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
658
			$orig = $new;
659
			return true;
660
		}
661
	}
662
	return false;
663
}
664

    
665
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
666

    
667
        if (isset($adr['any']))
668
                $padr = "any";
669
        else if ($adr['network'])
670
                $padr = $adr['network'];
671
        else if ($adr['address']) {
672
                list($padr, $pmask) = explode("/", $adr['address']);
673
                if (!$pmask)
674
                        $pmask = 32;
675
        }
676

    
677
        if (isset($adr['not']))
678
                $pnot = 1;
679
        else
680
                $pnot = 0;
681

    
682
        if ($adr['port']) {
683
                list($pbeginport, $pendport) = explode("-", $adr['port']);
684
                if (!$pendport)
685
                        $pendport = $pbeginport;
686
        } else {
687
                if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
688
                        /* Item is a port alias */
689
                } else {
690
                        $pbeginport = "any";
691
                        $pendport = "any";
692
                }
693
        }
694
}
695

    
696
function pconfig_to_address(&$adr, $padr, $pmask, $pnot=false, $pbeginport=0, $pendport=0) {
697

    
698
        $adr = array();
699

    
700
        if ($padr == "any")
701
                $adr['any'] = true;
702
        else if (is_specialnet($padr))
703
                $adr['network'] = $padr;
704
        else {
705
                $adr['address'] = $padr;
706
                if ($pmask != 32)
707
                        $adr['address'] .= "/" . $pmask;
708
        }
709

    
710
        if ($pnot)
711
                $adr['not'] = true;
712
        else
713
                unset($adr['not']);
714

    
715
        if (($pbeginport != 0) && ($pbeginport != "any")) {
716
                if ($pbeginport != $pendport)
717
                        $adr['port'] = $pbeginport . "-" . $pendport;
718
                else
719
                        $adr['port'] = $pbeginport;
720
        }
721

    
722
        if(alias_expand($pbeginport)) {
723
                $adr['port'] = $pbeginport;
724
        }
725
}
726

    
727
function is_specialnet($net) {
728
        global $specialsrcdst;
729

    
730
        if (in_array($net, $specialsrcdst) || strstr($net, "opt"))
731
                return true;
732
        else
733
                return false;
734
}
735

    
736
function ipsec_ca_sort() {
737
        global $g, $config;
738

    
739
        function ipseccacmp($a, $b) {
740
                return strcmp($a['ident'], $b['ident']);
741
        }
742

    
743
        usort($config['ipsec']['cacert'], "ipseccacmp");
744
}
745

    
746

    
747
?>
(62-62/171)