Project

General

Profile

Download (21.2 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("authgui.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_sysctldirty_path = $g['varrun_path'] . "/sysctl.conf.dirty";
80
$d_vsconfdirty_path = $g['varrun_path'] . "/vs.conf.dirty";
81
$d_shaperconfdirty_path = $g['varrun_path'] . "/shaper.conf.dirty";
82

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

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

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

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

    
144
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
145
	$specialnets['opt' . $i] = $config['interfaces']['opt' . $i]['descr'] . " net";
146
}
147

    
148
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
149
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
150
	"10half" => "10BASE-T half-duplex");
151

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

    
155
/* IPsec defines */
156
$my_identifier_list = array('myaddress' => 'My IP address',
157
				'address' => 'IP address',
158
				'fqdn' => 'Domain name',
159
				'user_fqdn' => 'User FQDN',
160
				'asn1dn' => 'Distinguished Name',
161
				'dyn_dns' => 'Dynamic DNS');
162

    
163
$p1_ealgos = array('des' => 'DES', '3des' => '3DES', 'blowfish' => 'Blowfish',
164
		'cast128' => 'CAST128','rijndael' => 'Rijndael (AES)', 'rijndael 256' => 'Rijndael 256');
165
$p2_ealgos = array('des' => 'DES', '3des' => '3DES', 'blowfish' => 'Blowfish',
166
		'cast128' => 'CAST128', 'rijndael' => 'Rijndael (AES)', 'rijndael 256' => 'Rijndael 256');
167

    
168
$p1_halgos = array('sha1' => 'SHA1', 'md5' => 'MD5');
169
$p1_authentication_methods = array('pre_shared_key' => 'Pre-shared key', 'rsasig' => 'RSA signature');
170
$p2_halgos = array('hmac_sha1' => 'SHA1', 'hmac_md5' => 'MD5');
171
$p2_protos = array('esp' => 'ESP', 'ah' => 'AH');
172
$p2_pfskeygroups = array('0' => 'off', '1' => '1', '2' => '2', '5' => '5');
173

    
174
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
175

    
176
	/* check for bad control characters */
177
	foreach ($postdata as $pn => $pd) {
178
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
179
			$input_errors[] = "The field '" . $pn . "' contains invalid characters.";
180
		}
181
	}
182

    
183
	for ($i = 0; $i < count($reqdfields); $i++) {
184
		if ($_POST[$reqdfields[$i]] == "") {
185
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
186
		}
187
	}
188
}
189

    
190
function print_input_errors($input_errors) {
191
	global $g;
192
	echo "<p><table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\">\n";
193
	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";
194
	echo "<td bgcolor=\"#FFD9D1\" style=\"padding-left: 8px; padding-top: 6px\">";
195

    
196
	echo "<span class=\"errmsg\"><p>The following input errors were detected:<ul>\n";
197
	foreach ($input_errors as $ierr) {
198
		echo "<li>" . htmlspecialchars($ierr) . "</li>\n";
199
	}
200
	echo "</ul></span>";
201

    
202
	echo "</td></tr></table></p>&nbsp;<br>";
203
}
204

    
205
function exec_rc_script($scriptname) {
206

    
207
	global $d_sysrebootreqd_path;
208

    
209
	$execoutput = "";
210
	$retval = "";
211
	exec($scriptname . " >/dev/null 2>&1", $execoutput, $retval);
212
	return $retval;
213
}
214

    
215
function exec_rc_script_async($scriptname) {
216

    
217
	global $d_sysrebootreqd_path;
218
	$execoutput = "";
219
	$retval = "";
220

    
221
	exec("nohup " . $scriptname . " >/dev/null 2>&1 &", $execoutput, $retval);
222
	return $retval;
223
}
224

    
225
function verify_gzip_file($fname) {
226

    
227
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
228
	if ($returnvar != 0)
229
		return 0;
230
	else
231
		return 1;
232
}
233

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

    
262
function print_info_box($msg) {
263
	echo "<p>";
264
	print_info_box_np($msg);
265
	echo "</p>";
266
}
267

    
268
function format_bytes($bytes) {
269
	if ($bytes >= 1073741824) {
270
		return sprintf("%.2f GB", $bytes/1073741824);
271
	} else if ($bytes >= 1048576) {
272
		return sprintf("%.2f MB", $bytes/1048576);
273
	} else if ($bytes >= 1024) {
274
		return sprintf("%.0f KB", $bytes/1024);
275
	} else {
276
		return sprintf("%d bytes", $bytes);
277
	}
278
}
279

    
280
function get_std_save_message($ok) {
281
	global $d_sysrebootreqd_path;
282

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

    
286
function pprint_address($adr) {
287
	global $specialnets;
288

    
289
	if (isset($adr['any'])) {
290
		$padr = "*";
291
	} else if ($adr['network']) {
292
		if (preg_match("/opt[0-999]ip/", $adr['network'])) {
293
			$padr = "Interface IP address";
294
		} else {
295
			$padr = $specialnets[$adr['network']];
296
		}
297
	} else {
298
		$padr = $adr['address'];
299
	}
300

    
301
	if (isset($adr['not']))
302
		$padr = "! " . $padr;
303

    
304
	return $padr;
305
}
306

    
307
function pprint_port($port) {
308
	global $wkports;
309

    
310
	$pport = "";
311

    
312
	if (!$port)
313
		return "*";
314
	else {
315
		$srcport = explode("-", $port);
316
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
317
			$pport = $srcport[0];
318
			if ($wkports[$srcport[0]]) {
319
				$pport .= " (" . $wkports[$srcport[0]] . ")";
320
			}
321
		} else
322
			$pport .= $srcport[0] . " - " . $srcport[1];
323
	}
324

    
325
	return $pport;
326
}
327

    
328
function captiveportal_users_sort() {
329
	global $g, $config;
330

    
331
	function cpusercmp($a, $b) {
332
		return strcasecmp($a['name'], $b['name']);
333
	}
334

    
335
	usort($config['captiveportal']['user'], "cpusercmp");
336
}
337

    
338
function admin_groups_sort() {
339
	global $g, $config;
340

    
341
	function cpusercmp($a, $b) {
342
		return strcasecmp($a['name'], $b['name']);
343
	}
344

    
345
	usort($config['system']['group'], "cpusercmp");
346
}
347

    
348
function admin_users_sort() {
349
	global $g, $config;
350

    
351
	function cpusercmp($a, $b) {
352
		return strcasecmp($a['name'], $b['name']);
353
	}
354

    
355
	usort($config['system']['user'], "cpusercmp");
356
}
357

    
358
/* sort by interface only, retain the original order of rules that apply to
359
   the same interface */
360
function filter_rules_sort() {
361
	global $config;
362

    
363
	/* mark each rule with the sequence number (to retain the order while sorting) */
364
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
365
		$config['filter']['rule'][$i]['seq'] = $i;
366

    
367
	function filtercmp($a, $b) {
368
		if ($a['interface'] == $b['interface'])
369
			return $a['seq'] - $b['seq'];
370
		else
371
			return -strcmp($a['interface'], $b['interface']);
372
	}
373

    
374
	usort($config['filter']['rule'], "filtercmp");
375

    
376
	/* strip the sequence numbers again */
377
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
378
		unset($config['filter']['rule'][$i]['seq']);
379
}
380

    
381
function nat_rules_sort() {
382
	global $config;
383

    
384
	function natcmp($a, $b) {
385
		if ($a['external-address'] == $b['external-address']) {
386
			if ($a['protocol'] == $b['protocol']) {
387
				if ($a['external-port'] == $b['external-port']) {
388
					return 0;
389
				} else {
390
					return ($a['external-port'] - $b['external-port']);
391
				}
392
			} else {
393
				return strcmp($a['protocol'], $b['protocol']);
394
			}
395
		} else if (!$a['external-address'])
396
			return 1;
397
		else if (!$b['external-address'])
398
			return -1;
399
		else
400
			return ipcmp($a['external-address'], $b['external-address']);
401
	}
402

    
403
	usort($config['nat']['rule'], "natcmp");
404
}
405

    
406
function nat_1to1_rules_sort() {
407
	global $g, $config;
408

    
409
	function nat1to1cmp($a, $b) {
410
		return ipcmp($a['external'], $b['external']);
411
	}
412

    
413
	usort($config['nat']['onetoone'], "nat1to1cmp");
414
}
415

    
416
function nat_server_rules_sort() {
417
	global $g, $config;
418

    
419
	function natservercmp($a, $b) {
420
		return ipcmp($a['ipaddr'], $b['ipaddr']);
421
	}
422

    
423
	usort($config['nat']['servernat'], "natservercmp");
424
}
425

    
426
function nat_out_rules_sort() {
427
	global $g, $config;
428

    
429
	function natoutcmp($a, $b) {
430
		return strcmp($a['source']['network'], $b['source']['network']);
431
	}
432

    
433
	usort($config['nat']['advancedoutbound']['rule'], "natoutcmp");
434
}
435

    
436
function pptpd_users_sort() {
437
	global $g, $config;
438

    
439
	function usercmp($a, $b) {
440
		return strcasecmp($a['name'], $b['name']);
441
	}
442

    
443
	usort($config['pptpd']['user'], "usercmp");
444
}
445

    
446
function pppoe_users_sort() {
447
	global $g, $config;
448

    
449
	function usercmp($a, $b) {
450
		return strcasecmp($a['name'], $b['name']);
451
	}
452

    
453
	usort($config['pppoe']['user'], "usercmp");
454
}
455

    
456
function staticroutes_sort() {
457
	global $g, $config;
458

    
459
	function staticroutecmp($a, $b) {
460
		return strcmp($a['network'], $b['network']);
461
	}
462

    
463
	usort($config['staticroutes']['route'], "staticroutecmp");
464
}
465

    
466
function hosts_sort() {
467
	global $g, $config;
468

    
469
	function hostcmp($a, $b) {
470
		return strcasecmp($a['host'], $b['host']);
471
	}
472

    
473
	usort($config['dnsmasq']['hosts'], "hostcmp");
474
}
475

    
476
function staticmaps_sort($if) {
477
	global $g, $config;
478

    
479
	function staticmapcmp($a, $b) {
480
		return ipcmp($a['ipaddr'], $b['ipaddr']);
481
	}
482

    
483
	usort($config['dhcpd'][$if]['staticmap'], "staticmapcmp");
484
}
485

    
486
function aliases_sort() {
487
	global $g, $config;
488

    
489
	function aliascmp($a, $b) {
490
		return strcmp($a['name'], $b['name']);
491
	}
492

    
493
	usort($config['aliases']['alias'], "aliascmp");
494
}
495

    
496
function schedule_sort(){
497
	global $g, $config;
498

    
499
	function schedulecmp($a, $b) {
500
		return strcmp($a['name'], $b['name']);
501
	}
502

    
503
	usort($config['schedules']['schedule'], "schedulecmp");
504

    
505
}
506

    
507
function ipsec_mobilekey_sort() {
508
	global $g, $config;
509

    
510
	function mobilekeycmp($a, $b) {
511
		return strcmp($a['ident'][0], $b['ident'][0]);
512
	}
513

    
514
	usort($config['ipsec']['mobilekey'], "mobilekeycmp");
515
}
516

    
517
function proxyarp_sort() {
518
	global $g, $config;
519

    
520
	function proxyarpcmp($a, $b) {
521
		if (isset($a['network']))
522
			list($ast,$asn) = explode("/", $a['network']);
523
		else if (isset($a['range'])) {
524
			$ast = $a['range']['from'];
525
			$asn = 32;
526
		}
527
		if (isset($b['network']))
528
			list($bst,$bsn) = explode("/", $b['network']);
529
		else if (isset($b['range'])) {
530
			$bst = $b['range']['from'];
531
			$bsn = 32;
532
		}
533
		if (ipcmp($ast, $bst) == 0)
534
			return ($asn - $bsn);
535
		else
536
			return ipcmp($ast, $bst);
537
	}
538

    
539
	usort($config['proxyarp']['proxyarpnet'], "proxyarpcmp");
540
}
541

    
542
function passthrumacs_sort() {
543
	global $g, $config;
544

    
545
	function passthrumacscmp($a, $b) {
546
		return strcmp($a['mac'], $b['mac']);
547
	}
548

    
549
	usort($config['captiveportal']['passthrumac'],"passthrumacscmp");
550
}
551

    
552
function cpelements_sort() {
553
	global $g, $config;
554

    
555
	function cpelementscmp($a, $b) {
556
		return strcasecmp($a['name'], $b['name']);
557
	}
558

    
559
	usort($config['captiveportal']['element'],"cpelementscmp");
560
}
561

    
562
function allowedips_sort() {
563
	global $g, $config;
564

    
565
	function allowedipscmp($a, $b) {
566
		return strcmp($a['ip'], $b['ip']);
567
	}
568

    
569
	usort($config['captiveportal']['allowedip'],"allowedipscmp");
570
}
571

    
572
function wol_sort() {
573
	global $g, $config;
574

    
575
	function wolcmp($a, $b) {
576
		return strcmp($a['descr'], $b['descr']);
577
	}
578

    
579
	usort($config['wol']['wolentry'], "wolcmp");
580
}
581

    
582
function sort_rule_by_queue_priority() {
583
	global $g, $config;
584
	global $queues;
585

    
586
	function rqpcmp($a, $b) {
587
		global $queues;
588

    
589
		$ra = $queues[$a['outqueue']];
590
		$rb = $queues[$b['outqueue']];
591

    
592
		if ($ra == $rb)
593
			return 0;
594
		/* reverse sort - we want higher priority first */
595
		return ($ra < $rb) ? 1 : -1;
596
	}
597

    
598
	foreach($config['shaper']['queue'] as $q) {
599
		$queues[$q['name']] = $q['priority'];
600
	}
601

    
602
	usort($config['shaper']['rule'], "rqpcmp");
603
}
604
function gentitle($pgname) {
605
	global $config;
606
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
607
}
608

    
609
/* update the changedesc and changecount(er) variables */
610
function update_changedesc($update) {
611
	global $changedesc;
612
	global $changecount;
613

    
614
	$changedesc .= " {$update}";
615
	$changecount++;
616
}
617

    
618
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
619
	global $g, $config;
620
    $sor = isset($config['syslog']['reverse']) ? "-r" : "";
621
    $logarr = "";
622
	$grepline = "  ";
623
	if(is_array($grepfor))
624
		foreach($grepfor as $agrep)
625
			$grepline .= " | grep \"$agrep\"";
626
	if(is_array($grepinvert))
627
		foreach($grepinvert as $agrep)
628
			$grepline .= " | grep -v \"$agrep\"";
629
	exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
630
    echo "<!-- /usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail} -->";
631
    foreach ($logarr as $logent) {
632
            $logent = preg_split("/\s+/", $logent, 6);
633
            echo "<tr valign=\"top\">\n";
634
            if ($withorig) {
635
            		$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
636
                    echo "<td class=\"listlr\" nowrap>" . $entry_date_time  . "</td>\n";
637
                    echo "<td class=\"listr\">" . htmlspecialchars($logent[4] . " " . $logent[5]) . "</td>\n";
638
            } else {
639
                    echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
640
            }
641
            echo "</tr>\n";
642
    }
643
}
644

    
645
function return_clog($logfile, $tail, $grepfor = "", $grepinvert = "", $grepreverse = false) {
646
	global $g, $config;
647
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
648
	$sor = isset($grepreverse) ? "-r" : "";
649
	$logarr = "";
650
	$grepline = "  ";
651
	if(is_array($grepfor))
652
		foreach($grepfor as $agrep)
653
			$grepline .= " | grep \"$agrep\"";
654
	if(is_array($grepinvert))
655
		foreach($grepinvert as $agrep)
656
			$grepline .= " | grep -v \"$agrep\"";
657
	echo "<!-- /usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail} -->";
658
	exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
659
	return($logarr);
660
}
661

    
662
/* Check if variable has changed, update and log if it has
663
 * returns true if var changed
664
 * varname = variable name in plain text
665
 * orig = original value
666
 * new = new value
667
 */
668
function update_if_changed($varname, & $orig, $new) {
669
	if (is_array($orig) && is_array($new)) {
670
		$a_diff = array_diff($orig, $new);
671
		foreach ($a_diff as $diff) {
672
			update_changedesc("removed {$varname}: \"{$diff}\"");
673
		}
674
		$a_diff = array_diff($new, $orig);
675
		foreach ($a_diff as $diff) {
676
			update_changedesc("added {$varname}: \"{$diff}\"");
677
		}
678
		$orig = $new;
679
		return true;
680

    
681
	} else {
682
		if ($orig != $new) {
683
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
684
			$orig = $new;
685
			return true;
686
		}
687
	}
688
	return false;
689
}
690

    
691
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
692

    
693
        if (isset($adr['any']))
694
                $padr = "any";
695
        else if ($adr['network'])
696
                $padr = $adr['network'];
697
        else if ($adr['address']) {
698
                list($padr, $pmask) = explode("/", $adr['address']);
699
                if (!$pmask)
700
                        $pmask = 32;
701
        }
702

    
703
        if (isset($adr['not']))
704
                $pnot = 1;
705
        else
706
                $pnot = 0;
707

    
708
        if ($adr['port']) {
709
                list($pbeginport, $pendport) = explode("-", $adr['port']);
710
                if (!$pendport)
711
                        $pendport = $pbeginport;
712
        } else {
713
                if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
714
                        /* Item is a port alias */
715
                } else {
716
                        $pbeginport = "any";
717
                        $pendport = "any";
718
                }
719
        }
720
}
721

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

    
724
        $adr = array();
725

    
726
        if ($padr == "any")
727
                $adr['any'] = true;
728
        else if (is_specialnet($padr))
729
                $adr['network'] = $padr;
730
        else {
731
                $adr['address'] = $padr;
732
                if ($pmask != 32)
733
                        $adr['address'] .= "/" . $pmask;
734
        }
735

    
736
        if ($pnot)
737
                $adr['not'] = true;
738
        else
739
                unset($adr['not']);
740

    
741
        if (($pbeginport != 0) && ($pbeginport != "any")) {
742
                if ($pbeginport != $pendport)
743
                        $adr['port'] = $pbeginport . "-" . $pendport;
744
                else
745
                        $adr['port'] = $pbeginport;
746
        }
747

    
748
        if(alias_expand($pbeginport)) {
749
                $adr['port'] = $pbeginport;
750
        }
751
}
752

    
753
function is_specialnet($net) {
754
        global $specialsrcdst;
755

    
756
        if (in_array($net, $specialsrcdst) || strstr($net, "opt"))
757
                return true;
758
        else
759
                return false;
760
}
761

    
762
function ipsec_ca_sort() {
763
        global $g, $config;
764

    
765
        function ipseccacmp($a, $b) {
766
                return strcmp($a['ident'], $b['ident']);
767
        }
768

    
769
        usort($config['ipsec']['cacert'], "ipseccacmp");
770
}
771

    
772

    
773
?>
(67-67/186)