Project

General

Profile

Download (22.8 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
$navlevelsep = ": ";	/* navigation level separator string */
91
$mandfldhtml = "";		/* display this before mandatory input fields */
92
$mandfldhtmlspc = "";	/* same as above, but with spacing */
93

    
94
if (file_exists($d_firmwarelock_path)) {
95
	if (!$d_isfwfile) {
96
		header("Location: system_firmware.php");
97
		exit;
98
	} else {
99
		return;
100
	}
101
}
102

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

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

    
148
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
149
	$specialnets['opt' . $i] = $config['interfaces']['opt' . $i]['descr'] . " net";
150
}
151

    
152
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
153
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
154
	"10half" => "10BASE-T half-duplex");
155

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

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

    
167
$p1_ealgos = array('des' => 'DES', '3des' => '3DES', 'blowfish' => 'Blowfish',
168
		'cast128' => 'CAST128','rijndael' => 'Rijndael (AES)', 'rijndael 256' => 'Rijndael 256');
169
$p2_ealgos = array('des' => 'DES', '3des' => '3DES', 'blowfish' => 'Blowfish',
170
		'cast128' => 'CAST128', 'rijndael' => 'Rijndael (AES)', 'rijndael 256' => 'Rijndael 256');
171

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

    
178
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
179

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

    
187
	for ($i = 0; $i < count($reqdfields); $i++) {
188
		if ($_POST[$reqdfields[$i]] == "") {
189
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
190
		}
191
	}
192
}
193

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

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

    
206
	echo "</td></tr></table></p>&nbsp;<br>";
207
}
208

    
209
function exec_rc_script($scriptname) {
210

    
211
	global $d_sysrebootreqd_path;
212

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

    
219
function exec_rc_script_async($scriptname) {
220

    
221
	global $d_sysrebootreqd_path;
222
	$execoutput = "";
223
	$retval = "";
224

    
225
	exec("nohup " . $scriptname . " >/dev/null 2>&1 &", $execoutput, $retval);
226
	return $retval;
227
}
228

    
229
function verify_gzip_file($fname) {
230

    
231
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
232
	if ($returnvar != 0)
233
		return 0;
234
	else
235
		return 1;
236
}
237

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

    
266
function print_info_box($msg) {
267
	echo "<p>";
268
	print_info_box_np($msg);
269
	echo "</p>";
270
}
271

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

    
284
function get_std_save_message($ok) {
285
	global $d_sysrebootreqd_path;
286

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

    
290
function pprint_address($adr) {
291
	global $specialnets;
292

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

    
305
	if (isset($adr['not']))
306
		$padr = "! " . $padr;
307

    
308
	return $padr;
309
}
310

    
311
function pprint_port($port) {
312
	global $wkports;
313

    
314
	$pport = "";
315

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

    
329
	return $pport;
330
}
331

    
332
function captiveportal_users_sort() {
333
	global $g, $config;
334

    
335
	function cpusercmp($a, $b) {
336
		return strcasecmp($a['name'], $b['name']);
337
	}
338

    
339
	usort($config['captiveportal']['user'], "cpusercmp");
340
}
341

    
342
function admin_groups_sort() {
343
	global $g, $config;
344

    
345
	function cpusercmp($a, $b) {
346
		return strcasecmp($a['name'], $b['name']);
347
	}
348

    
349
	usort($config['system']['group'], "cpusercmp");
350
}
351

    
352
function admin_users_sort() {
353
	global $g, $config;
354

    
355
	function cpusercmp($a, $b) {
356
		return strcasecmp($a['name'], $b['name']);
357
	}
358

    
359
	usort($config['system']['user'], "cpusercmp");
360
}
361

    
362
/* sort by interface only, retain the original order of rules that apply to
363
   the same interface */
364
function filter_rules_sort() {
365
	global $config;
366

    
367
	/* mark each rule with the sequence number (to retain the order while sorting) */
368
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
369
		$config['filter']['rule'][$i]['seq'] = $i;
370

    
371
	function filtercmp($a, $b) {
372
		if ($a['interface'] == $b['interface'])
373
			return $a['seq'] - $b['seq'];
374
		else
375
			return -strcmp($a['interface'], $b['interface']);
376
	}
377

    
378
	usort($config['filter']['rule'], "filtercmp");
379

    
380
	/* strip the sequence numbers again */
381
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
382
		unset($config['filter']['rule'][$i]['seq']);
383
}
384

    
385
function nat_rules_sort() {
386
	global $config;
387

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

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

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

    
413
	function nat1to1cmp($a, $b) {
414
		return ipcmp($a['external'], $b['external']);
415
	}
416

    
417
	usort($config['nat']['onetoone'], "nat1to1cmp");
418
}
419

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

    
423
	function natservercmp($a, $b) {
424
		return ipcmp($a['ipaddr'], $b['ipaddr']);
425
	}
426

    
427
	usort($config['nat']['servernat'], "natservercmp");
428
}
429

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

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

    
437
	usort($config['nat']['advancedoutbound']['rule'], "natoutcmp");
438
}
439

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

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

    
447
	usort($config['pptpd']['user'], "usercmp");
448
}
449

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

    
453
	function usercmp($a, $b) {
454
		return strcasecmp($a['name'], $b['name']);
455
	}
456

    
457
	usort($config['pppoe']['user'], "usercmp");
458
}
459

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

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

    
467
	usort($config['staticroutes']['route'], "staticroutecmp");
468
}
469

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

    
473
	function hostcmp($a, $b) {
474
		return strcasecmp($a['host'], $b['host']);
475
	}
476

    
477
	usort($config['dnsmasq']['hosts'], "hostcmp");
478
}
479

    
480
function staticmaps_sort($if) {
481
	global $g, $config;
482

    
483
	function staticmapcmp($a, $b) {
484
		return ipcmp($a['ipaddr'], $b['ipaddr']);
485
	}
486

    
487
	usort($config['dhcpd'][$if]['staticmap'], "staticmapcmp");
488
}
489

    
490
function aliases_sort() {
491
	global $g, $config;
492

    
493
	function aliascmp($a, $b) {
494
		return strcmp($a['name'], $b['name']);
495
	}
496

    
497
	usort($config['aliases']['alias'], "aliascmp");
498
}
499

    
500
function schedule_sort(){
501
	global $g, $config;
502

    
503
	function schedulecmp($a, $b) {
504
		return strcmp($a['name'], $b['name']);
505
	}
506

    
507
	usort($config['schedules']['schedule'], "schedulecmp");
508

    
509
}
510

    
511
function ipsec_mobilekey_sort() {
512
	global $g, $config;
513

    
514
	function mobilekeycmp($a, $b) {
515
		return strcmp($a['ident'][0], $b['ident'][0]);
516
	}
517

    
518
	usort($config['ipsec']['mobilekey'], "mobilekeycmp");
519
}
520

    
521
function proxyarp_sort() {
522
	global $g, $config;
523

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

    
543
	usort($config['proxyarp']['proxyarpnet'], "proxyarpcmp");
544
}
545

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

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

    
553
	usort($config['captiveportal']['passthrumac'],"passthrumacscmp");
554
}
555

    
556
function cpelements_sort() {
557
	global $g, $config;
558

    
559
	function cpelementscmp($a, $b) {
560
		return strcasecmp($a['name'], $b['name']);
561
	}
562

    
563
	usort($config['captiveportal']['element'],"cpelementscmp");
564
}
565

    
566
function allowedips_sort() {
567
	global $g, $config;
568

    
569
	function allowedipscmp($a, $b) {
570
		return strcmp($a['ip'], $b['ip']);
571
	}
572

    
573
	usort($config['captiveportal']['allowedip'],"allowedipscmp");
574
}
575

    
576
function wol_sort() {
577
	global $g, $config;
578

    
579
	function wolcmp($a, $b) {
580
		return strcmp($a['descr'], $b['descr']);
581
	}
582

    
583
	usort($config['wol']['wolentry'], "wolcmp");
584
}
585

    
586
function sort_rule_by_queue_priority() {
587
	global $g, $config;
588
	global $queues;
589

    
590
	function rqpcmp($a, $b) {
591
		global $queues;
592

    
593
		$ra = $queues[$a['outqueue']];
594
		$rb = $queues[$b['outqueue']];
595

    
596
		if ($ra == $rb)
597
			return 0;
598
		/* reverse sort - we want higher priority first */
599
		return ($ra < $rb) ? 1 : -1;
600
	}
601

    
602
	foreach($config['shaper']['queue'] as $q) {
603
		$queues[$q['name']] = $q['priority'];
604
	}
605

    
606
	usort($config['shaper']['rule'], "rqpcmp");
607
}
608

    
609
function gentitle($title) {
610
	global $navlevelsep;
611
	if(!is_array($title))
612
		return $title;
613
	else
614
		return join($navlevelsep, $title); 
615
}
616

    
617
function genhtmltitle($title) {
618
        global $config;
619
        return gentitle($title);
620
}
621

    
622
/* update the changedesc and changecount(er) variables */
623
function update_changedesc($update) {
624
	global $changedesc;
625
	global $changecount;
626

    
627
	$changedesc .= " {$update}";
628
	$changecount++;
629
}
630

    
631
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
632
	global $g, $config;
633
    $sor = isset($config['syslog']['reverse']) ? "-r" : "";
634
    $logarr = "";
635
	$grepline = "  ";
636
	if(is_array($grepfor))
637
		foreach($grepfor as $agrep)
638
			$grepline .= " | grep \"$agrep\"";
639
	if(is_array($grepinvert))
640
		foreach($grepinvert as $agrep)
641
			$grepline .= " | grep -v \"$agrep\"";
642
	exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
643
    /* comment out debug code
644
    echo "<!-- /usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail} -->";
645
    */
646
    foreach ($logarr as $logent) {
647
            $logent = preg_split("/\s+/", $logent, 6);
648
            echo "<tr valign=\"top\">\n";
649
            if ($withorig) {
650
            		$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
651
                    echo "<td class=\"listlr\" nowrap>" . $entry_date_time  . "</td>\n";
652
                    echo "<td class=\"listr\">" . htmlspecialchars($logent[4] . " " . $logent[5]) . "</td>\n";
653
            } else {
654
                    echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
655
            }
656
            echo "</tr>\n";
657
    }
658
}
659

    
660
function return_clog($logfile, $tail, $grepfor = "", $grepinvert = "", $grepreverse = false) {
661
	global $g, $config;
662
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
663
	$sor = isset($grepreverse) ? "-r" : "";
664
	$logarr = "";
665
	$grepline = "  ";
666
	if(is_array($grepfor))
667
		foreach($grepfor as $agrep)
668
			$grepline .= " | grep \"$agrep\"";
669
	if(is_array($grepinvert))
670
		foreach($grepinvert as $agrep)
671
			$grepline .= " | grep -v \"$agrep\"";
672
	/* comment out debug code
673
	echo "<!-- /usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail} -->";
674
	*/
675
	exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
676
	return($logarr);
677
}
678

    
679
/* Check if variable has changed, update and log if it has
680
 * returns true if var changed
681
 * varname = variable name in plain text
682
 * orig = original value
683
 * new = new value
684
 */
685
function update_if_changed($varname, & $orig, $new) {
686
	if (is_array($orig) && is_array($new)) {
687
		$a_diff = array_diff($orig, $new);
688
		foreach ($a_diff as $diff) {
689
			update_changedesc("removed {$varname}: \"{$diff}\"");
690
		}
691
		$a_diff = array_diff($new, $orig);
692
		foreach ($a_diff as $diff) {
693
			update_changedesc("added {$varname}: \"{$diff}\"");
694
		}
695
		$orig = $new;
696
		return true;
697

    
698
	} else {
699
		if ($orig != $new) {
700
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
701
			$orig = $new;
702
			return true;
703
		}
704
	}
705
	return false;
706
}
707

    
708
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
709

    
710
        if (isset($adr['any']))
711
                $padr = "any";
712
        else if ($adr['network'])
713
                $padr = $adr['network'];
714
        else if ($adr['address']) {
715
                list($padr, $pmask) = explode("/", $adr['address']);
716
                if (!$pmask)
717
                        $pmask = 32;
718
        }
719

    
720
        if (isset($adr['not']))
721
                $pnot = 1;
722
        else
723
                $pnot = 0;
724

    
725
        if ($adr['port']) {
726
                list($pbeginport, $pendport) = explode("-", $adr['port']);
727
                if (!$pendport)
728
                        $pendport = $pbeginport;
729
        } else {
730
                if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
731
                        /* Item is a port alias */
732
                } else {
733
                        $pbeginport = "any";
734
                        $pendport = "any";
735
                }
736
        }
737
}
738

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

    
741
        $adr = array();
742

    
743
        if ($padr == "any")
744
                $adr['any'] = true;
745
        else if (is_specialnet($padr))
746
                $adr['network'] = $padr;
747
        else {
748
                $adr['address'] = $padr;
749
                if ($pmask != 32)
750
                        $adr['address'] .= "/" . $pmask;
751
        }
752

    
753
        if ($pnot)
754
                $adr['not'] = true;
755
        else
756
                unset($adr['not']);
757

    
758
        if (($pbeginport != 0) && ($pbeginport != "any")) {
759
                if ($pbeginport != $pendport)
760
                        $adr['port'] = $pbeginport . "-" . $pendport;
761
                else
762
                        $adr['port'] = $pbeginport;
763
        }
764

    
765
        if(alias_expand($pbeginport)) {
766
                $adr['port'] = $pbeginport;
767
        }
768
}
769

    
770
function is_specialnet($net) {
771
        global $specialsrcdst;
772
		if(!$net) 
773
			return false;
774
        if (in_array($net, $specialsrcdst) || strstr($net, "opt"))
775
                return true;
776
        else
777
                return false;
778
}
779

    
780
function ipsec_ca_sort() {
781
        global $g, $config;
782

    
783
        function ipseccacmp($a, $b) {
784
                return strcmp($a['ident'], $b['ident']);
785
        }
786

    
787
        usort($config['ipsec']['cacert'], "ipseccacmp");
788
}
789

    
790
//function to create widget tabs when called
791
function display_widget_tabs(& $tab_array) {	
792
	echo "<div id='tabs'>";
793
	$tabscounter = 0;
794
	foreach ($tab_array as $ta) {
795
	$dashpos = strpos($ta[2],'-');
796
	$tabname = $ta[2] . "-tab";
797
	$tabclass = substr($ta[2],0,$dashpos);
798
	$tabclass = $tabclass . "-class";
799
		if ($ta[1] == true) {
800
			$tabActive = "table-cell";
801
			$tabNonActive = "none";
802
		} 
803
		else {
804
			$tabActive = "none";
805
			$tabNonActive = "table-cell";
806
		}
807
		echo "<div id='{$ta[2]}-active' class='{$tabclass}-tabactive' style='display:{$tabActive}; background-color:#EEEEEE; color:black;'>";
808
		echo "<B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
809
		echo "&nbsp;&nbsp;&nbsp;</B>";
810
		echo "</div>";
811
		
812
		echo "<div id='{$ta[2]}-deactive' class='{$tabclass}-tabdeactive' style='display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;' onClick=\"return changeTabDIV('{$ta[2]}')\">";
813
		echo "<B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
814
		echo "&nbsp;&nbsp;&nbsp;</B>";
815
		echo "</div>";
816
	}
817
	
818
	echo "<script type=\"text/javascript\">";
819
	echo "NiftyCheck();\n";
820
	echo "Rounded(\"div.{$tabclass}-tabactive\",\"top\",\"#CCCCCC\",\"#EEEEEE\",\"smooth\");\n";
821
	echo "Rounded(\"div.{$tabclass}-tabdeactive\",\"top\",\"#CCCCCC\",\"#777777\",\"smooth\");\n";
822
	echo "</script>";
823
	echo "</div>";
824
}
825

    
826

    
827
?>
(65-65/189)