Project

General

Profile

Download (21.1 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
	1812 => "Radius",
130
	1813 => "Radius-accounting",
131
	3000 => "HBCI",
132
	3478 => "STUN",
133
	4500 => "IPSec NAT-T",
134
	5004 => "RTP",
135
	5060 => "SIP",
136
	5190 => "ICQ",
137
	5900 => "VNC",
138
	5999 => "CVSup");
139

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

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

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

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

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

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

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

    
172
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
173

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

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

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

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

    
200
	echo "</td></tr></table></p>&nbsp;<br>";
201
}
202

    
203
function exec_rc_script($scriptname) {
204

    
205
	global $d_sysrebootreqd_path;
206

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

    
213
function exec_rc_script_async($scriptname) {
214

    
215
	global $d_sysrebootreqd_path;
216
	$execoutput = "";
217
	$retval = "";
218

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

    
223
function verify_gzip_file($fname) {
224

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

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

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

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

    
278
function get_std_save_message($ok) {
279
	global $d_sysrebootreqd_path;
280

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

    
284
function pprint_address($adr) {
285
	global $specialnets;
286

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

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

    
302
	return $padr;
303
}
304

    
305
function pprint_port($port) {
306
	global $wkports;
307

    
308
	$pport = "";
309

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

    
323
	return $pport;
324
}
325

    
326
function captiveportal_users_sort() {
327
	global $g, $config;
328

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

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

    
336
function admin_groups_sort() {
337
	global $g, $config;
338

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

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

    
346
function admin_users_sort() {
347
	global $g, $config;
348

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

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

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

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

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

    
372
	usort($config['filter']['rule'], "filtercmp");
373

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

    
379
function nat_rules_sort() {
380
	global $config;
381

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

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

    
404
function nat_1to1_rules_sort() {
405
	global $g, $config;
406

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

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

    
414
function nat_server_rules_sort() {
415
	global $g, $config;
416

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

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

    
424
function nat_out_rules_sort() {
425
	global $g, $config;
426

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

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

    
434
function pptpd_users_sort() {
435
	global $g, $config;
436

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

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

    
444
function pppoe_users_sort() {
445
	global $g, $config;
446

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

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

    
454
function staticroutes_sort() {
455
	global $g, $config;
456

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

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

    
464
function hosts_sort() {
465
	global $g, $config;
466

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

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

    
474
function staticmaps_sort($if) {
475
	global $g, $config;
476

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

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

    
484
function aliases_sort() {
485
	global $g, $config;
486

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

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

    
494
function schedule_sort(){
495
	global $g, $config;
496

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

    
501
	usort($config['schedules']['schedule'], "schedulecmp");
502

    
503
}
504

    
505
function ipsec_mobilekey_sort() {
506
	global $g, $config;
507

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

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

    
515
function proxyarp_sort() {
516
	global $g, $config;
517

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

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

    
540
function passthrumacs_sort() {
541
	global $g, $config;
542

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

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

    
550
function cpelements_sort() {
551
	global $g, $config;
552

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

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

    
560
function allowedips_sort() {
561
	global $g, $config;
562

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

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

    
570
function wol_sort() {
571
	global $g, $config;
572

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

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

    
580
function sort_rule_by_queue_priority() {
581
	global $g, $config;
582
	global $queues;
583

    
584
	function rqpcmp($a, $b) {
585
		global $queues;
586

    
587
		$ra = $queues[$a['outqueue']];
588
		$rb = $queues[$b['outqueue']];
589

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

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

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

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

    
612
	$changedesc .= " {$update}";
613
	$changecount++;
614
}
615

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

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

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

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

    
689
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
690

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

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

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

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

    
722
        $adr = array();
723

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

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

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

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

    
751
function is_specialnet($net) {
752
        global $specialsrcdst;
753

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

    
760
function ipsec_ca_sort() {
761
        global $g, $config;
762

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

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

    
770

    
771
?>
(66-66/182)