Project

General

Profile

Download (23.3 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 openvpn_users_sort() {
451
	global $g, $config;
452

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

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

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

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

    
467
	usort($config['pppoe']['user'], "usercmp");
468
}
469

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

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

    
477
	usort($config['staticroutes']['route'], "staticroutecmp");
478
}
479

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

    
483
	function hostcmp($a, $b) {
484
		return strcasecmp($a['host'], $b['host']);
485
	}
486

    
487
	usort($config['dnsmasq']['hosts'], "hostcmp");
488
}
489

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

    
493
	function staticmapcmp($a, $b) {
494
		return ipcmp($a['ipaddr'], $b['ipaddr']);
495
	}
496

    
497
	usort($config['dhcpd'][$if]['staticmap'], "staticmapcmp");
498
}
499

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

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

    
507
	usort($config['aliases']['alias'], "aliascmp");
508
}
509

    
510
function schedule_sort(){
511
	global $g, $config;
512

    
513
	function schedulecmp($a, $b) {
514
		return strcmp($a['name'], $b['name']);
515
	}
516

    
517
	usort($config['schedules']['schedule'], "schedulecmp");
518

    
519
}
520

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

    
524
	function mobilekeycmp($a, $b) {
525
		return strcmp($a['ident'][0], $b['ident'][0]);
526
	}
527

    
528
	usort($config['ipsec']['mobilekey'], "mobilekeycmp");
529
}
530

    
531
function proxyarp_sort() {
532
	global $g, $config;
533

    
534
	function proxyarpcmp($a, $b) {
535
		if (isset($a['network']))
536
			list($ast,$asn) = explode("/", $a['network']);
537
		else if (isset($a['range'])) {
538
			$ast = $a['range']['from'];
539
			$asn = 32;
540
		}
541
		if (isset($b['network']))
542
			list($bst,$bsn) = explode("/", $b['network']);
543
		else if (isset($b['range'])) {
544
			$bst = $b['range']['from'];
545
			$bsn = 32;
546
		}
547
		if (ipcmp($ast, $bst) == 0)
548
			return ($asn - $bsn);
549
		else
550
			return ipcmp($ast, $bst);
551
	}
552

    
553
	usort($config['proxyarp']['proxyarpnet'], "proxyarpcmp");
554
}
555

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

    
559
	function passthrumacscmp($a, $b) {
560
		return strcmp($a['mac'], $b['mac']);
561
	}
562

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

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

    
569
	function cpelementscmp($a, $b) {
570
		return strcasecmp($a['name'], $b['name']);
571
	}
572

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

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

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

    
583
	usort($config['captiveportal']['allowedip'],"allowedipscmp");
584
}
585

    
586
function wol_sort() {
587
	global $g, $config;
588

    
589
	function wolcmp($a, $b) {
590
		return strcmp($a['descr'], $b['descr']);
591
	}
592

    
593
	usort($config['wol']['wolentry'], "wolcmp");
594
}
595

    
596
function sort_rule_by_queue_priority() {
597
	global $g, $config;
598
	global $queues;
599

    
600
	function rqpcmp($a, $b) {
601
		global $queues;
602

    
603
		$ra = $queues[$a['outqueue']];
604
		$rb = $queues[$b['outqueue']];
605

    
606
		if ($ra == $rb)
607
			return 0;
608
		/* reverse sort - we want higher priority first */
609
		return ($ra < $rb) ? 1 : -1;
610
	}
611

    
612
	foreach($config['shaper']['queue'] as $q) {
613
		$queues[$q['name']] = $q['priority'];
614
	}
615

    
616
	usort($config['shaper']['rule'], "rqpcmp");
617
}
618

    
619
function gentitle($title) {
620
	global $navlevelsep;
621
	if(!is_array($title))
622
		return $title;
623
	else
624
		return join($navlevelsep, $title); 
625
}
626

    
627
function genhtmltitle($title) {
628
        global $config;
629
        return gentitle($title);
630
}
631

    
632
/* update the changedesc and changecount(er) variables */
633
function update_changedesc($update) {
634
	global $changedesc;
635
	global $changecount;
636

    
637
	$changedesc .= " {$update}";
638
	$changecount++;
639
}
640

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

    
673
function return_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "", $grepreverse = false) {
674
	global $g, $config;
675
	$sor = (isset($config['syslog']['reverse']) || $grepreverse) ? "-r" : "";
676
	$logarr = "";
677
	$grepline = "  ";
678
	if(is_array($grepfor))
679
		foreach($grepfor as $agrep)
680
			$grepline .= " | grep \"$agrep\"";
681
	if(is_array($grepinvert))
682
		foreach($grepinvert as $agrep)
683
			$grepline .= " | grep -v \"$agrep\"";
684
	/* comment out debug code
685
	echo "<!-- /usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail} -->";
686
	*/
687
	if($config['system']['disablesyslogclog']) 
688
		exec("cat {$logfile}{$grepline} | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
689
	else 
690
		exec("/usr/sbin/clog {$logfile}{$grepline} | grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
691
	return($logarr);
692
}
693

    
694
/* Check if variable has changed, update and log if it has
695
 * returns true if var changed
696
 * varname = variable name in plain text
697
 * orig = original value
698
 * new = new value
699
 */
700
function update_if_changed($varname, & $orig, $new) {
701
	if (is_array($orig) && is_array($new)) {
702
		$a_diff = array_diff($orig, $new);
703
		foreach ($a_diff as $diff) {
704
			update_changedesc("removed {$varname}: \"{$diff}\"");
705
		}
706
		$a_diff = array_diff($new, $orig);
707
		foreach ($a_diff as $diff) {
708
			update_changedesc("added {$varname}: \"{$diff}\"");
709
		}
710
		$orig = $new;
711
		return true;
712

    
713
	} else {
714
		if ($orig != $new) {
715
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
716
			$orig = $new;
717
			return true;
718
		}
719
	}
720
	return false;
721
}
722

    
723
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
724

    
725
        if (isset($adr['any']))
726
                $padr = "any";
727
        else if ($adr['network'])
728
                $padr = $adr['network'];
729
        else if ($adr['address']) {
730
                list($padr, $pmask) = explode("/", $adr['address']);
731
                if (!$pmask)
732
                        $pmask = 32;
733
        }
734

    
735
        if (isset($adr['not']))
736
                $pnot = 1;
737
        else
738
                $pnot = 0;
739

    
740
        if ($adr['port']) {
741
                list($pbeginport, $pendport) = explode("-", $adr['port']);
742
                if (!$pendport)
743
                        $pendport = $pbeginport;
744
        } else {
745
                if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
746
                        /* Item is a port alias */
747
                } else {
748
                        $pbeginport = "any";
749
                        $pendport = "any";
750
                }
751
        }
752
}
753

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

    
756
        $adr = array();
757

    
758
        if ($padr == "any")
759
                $adr['any'] = true;
760
        else if (is_specialnet($padr))
761
                $adr['network'] = $padr;
762
        else {
763
                $adr['address'] = $padr;
764
                if ($pmask != 32)
765
                        $adr['address'] .= "/" . $pmask;
766
        }
767

    
768
        if ($pnot)
769
                $adr['not'] = true;
770
        else
771
                unset($adr['not']);
772

    
773
        if (($pbeginport != 0) && ($pbeginport != "any")) {
774
                if ($pbeginport != $pendport)
775
                        $adr['port'] = $pbeginport . "-" . $pendport;
776
                else
777
                        $adr['port'] = $pbeginport;
778
        }
779

    
780
        if(alias_expand($pbeginport)) {
781
                $adr['port'] = $pbeginport;
782
        }
783
}
784

    
785
function is_specialnet($net) {
786
        global $specialsrcdst;
787
		if(!$net) 
788
			return false;
789
        if (in_array($net, $specialsrcdst) || strstr($net, "opt"))
790
                return true;
791
        else
792
                return false;
793
}
794

    
795
function ipsec_ca_sort() {
796
        global $g, $config;
797

    
798
        function ipseccacmp($a, $b) {
799
                return strcmp($a['ident'], $b['ident']);
800
        }
801

    
802
        usort($config['ipsec']['cacert'], "ipseccacmp");
803
}
804

    
805
//function to create widget tabs when called
806
function display_widget_tabs(& $tab_array) {	
807
	echo "<div id='tabs'>";
808
	$tabscounter = 0;
809
	foreach ($tab_array as $ta) {
810
	$dashpos = strpos($ta[2],'-');
811
	$tabname = $ta[2] . "-tab";
812
	$tabclass = substr($ta[2],0,$dashpos);
813
	$tabclass = $tabclass . "-class";
814
		if ($ta[1] == true) {
815
			$tabActive = "table-cell";
816
			$tabNonActive = "none";
817
		} 
818
		else {
819
			$tabActive = "none";
820
			$tabNonActive = "table-cell";
821
		}
822
		echo "<div id='{$ta[2]}-active' class='{$tabclass}-tabactive' style='display:{$tabActive}; background-color:#EEEEEE; color:black;'>";
823
		echo "<B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
824
		echo "&nbsp;&nbsp;&nbsp;</B>";
825
		echo "</div>";
826
		
827
		echo "<div id='{$ta[2]}-deactive' class='{$tabclass}-tabdeactive' style='display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;' onClick=\"return changeTabDIV('{$ta[2]}')\">";
828
		echo "<B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
829
		echo "&nbsp;&nbsp;&nbsp;</B>";
830
		echo "</div>";
831
	}
832
	
833
	echo "<script type=\"text/javascript\">";
834
	echo "NiftyCheck();\n";
835
	echo "Rounded(\"div.{$tabclass}-tabactive\",\"top\",\"#CCCCCC\",\"#EEEEEE\",\"smooth\");\n";
836
	echo "Rounded(\"div.{$tabclass}-tabdeactive\",\"top\",\"#CCCCCC\",\"#777777\",\"smooth\");\n";
837
	echo "</script>";
838
	echo "</div>";
839
}
840

    
841
?>
(66-66/193)