Project

General

Profile

Download (25.5 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
/* Pull in all the gui related display classes) */
51
foreach (scandir("/usr/local/www/classes/") as $file) {
52
	if (stristr($file, ".inc") !== false) {
53
		require_once("classes/{$file}");
54
	}
55
}
56
/*
57
 *   if user has selected a custom template, use it.
58
 *   otherwise default to pfsense tempalte
59
 */
60
if($config['theme'] <> "")
61
        $g['theme'] = $config['theme'];
62
else
63
        $g['theme'] = "pfsense";
64

    
65
$d_landirty_path = $g['varrun_path'] . "/lan.conf.dirty";
66
$d_pppoeuserdirty_path = $g['varrun_path'] . "/vpn-pppoe-users-edit.dirty";
67
$d_hostsdirty_path = $g['varrun_path'] . "/hosts.dirty";
68
$d_natconfdirty_path = $g['varrun_path'] . "/nat.conf.dirty";
69
$d_filterconfdirty_path = $g['varrun_path'] . "/filter.conf.dirty";
70
$d_ipsecconfdirty_path = $g['varrun_path'] . "/ipsec.conf.dirty";
71
$d_shaperconfdirty_path = $g['varrun_path'] . "/shaper.conf.dirty";
72
$d_pptpuserdirty_path = $g['varrun_path'] . "/pptpd.user.dirty";
73
$d_dnsmasqdirty_path = $g['varrun_path'] . "/dnsmasq.dirty";
74
$d_staticmapsdirty_path = $g['varrun_path'] . "/staticmaps.dirty";
75
$d_staticroutesdirty_path = $g['varrun_path'] . "/staticroutes.dirty";
76
$d_aliasesdirty_path = $g['varrun_path'] . "/aliases.dirty";
77
$d_proxyarpdirty_path = $g['varrun_path'] . "/proxyarp.dirty";
78
$d_fwupenabled_path = $g['varrun_path'] . "/fwup.enabled";
79
$d_firmwarelock_path = $g['varrun_path'] . "/firmware.lock";
80
$d_sysrebootreqd_path = $g['varrun_path'] . "/sysreboot.reqd";
81
$d_passthrumacsdirty_path = $g['varrun_path'] . "/passthrumacs.dirty";
82
$d_allowedipsdirty_path = $g['varrun_path'] . "/allowedips.dirty";
83
$d_ovpnclidirty_path = $g['varrun_path'] . "/ovpnclient.dirty";
84
$d_vipconfdirty_path = $g['varrun_path'] . "/vip.conf.dirty";
85
$d_sysctldirty_path = $g['varrun_path'] . "/sysctl.conf.dirty";
86
$d_vsconfdirty_path = $g['varrun_path'] . "/vs.conf.dirty";
87
$d_shaperconfdirty_path = $g['varrun_path'] . "/shaper.conf.dirty";
88

    
89
/* OpenVPN Directories */
90
$d_ovpnsrvdirty_path = "/tmp/ovpn-srv.dirty";
91
$d_ovpncrldirty_path = "/tmp/ovpn-crl.dirty";
92
$d_ovpnclidirty_path = "/tmp/ovpn-cli.dirty";
93
/* used by progress bar */
94
$lastseen = "-1";
95

    
96
$navlevelsep = ": ";	/* navigation level separator string */
97
$mandfldhtml = "";		/* display this before mandatory input fields */
98
$mandfldhtmlspc = "";	/* same as above, but with spacing */
99

    
100
if (file_exists($d_firmwarelock_path)) {
101
	if (!$d_isfwfile) {
102
		header("Location: system_firmware.php");
103
		exit;
104
	} else {
105
		return;
106
	}
107
}
108

    
109
$auth_server_types = array(
110
	'ldap' => "LDAP",
111
	'radius' => "Radius");
112

    
113
$ldap_urltypes = array(
114
	'TCP - Standard' => 389,
115
	'SSL - Encrypted' => 636);
116

    
117
$ldap_scopes = array(
118
	'one' => "One Level",
119
	'subtree' => "Entire Subtree");
120

    
121
$ldap_protvers = array(
122
	2,
123
	3);
124

    
125
$ldap_templates = array(
126

    
127
	'open' => array(
128
				'desc' => "OpenLDAP",
129
				'attr_user' => "cn",
130
				'attr_group' => "cn",
131
				'attr_member' => "member"),
132

    
133
	'msad' => array(
134
				'desc' => "Microsoft AD",
135
				'attr_user' => "samAccountNAme",
136
				'attr_group' => "cn",
137
				'attr_member' => "member"),
138

    
139
	'edir' => array(
140
				'desc' => "Novell eDirectory",
141
				'attr_user' => "cn",
142
				'attr_group' => "cn",
143
				'attr_member' => "uniqueMember"));
144

    
145
$radius_srvcs = array(
146
	'both' => "Authentication and Accounting",
147
	'auth' => "Authentication",
148
	'acct' => "Accounting");
149

    
150
/* some well knows ports */
151
$wkports = array(
152
	3389 => "MS RDP",
153
	21 => "FTP",
154
	22 => "SSH",
155
	23 => "Telnet",
156
	25 => "SMTP",
157
	53 => "DNS",
158
	69 => "TFTP",
159
	80 => "HTTP",
160
	110 => "POP3",
161
	113 => "IDENT/AUTH",
162
	119 => "NNTP",
163
	123 => "NTP",
164
	137 => "NetBIOS-NS",
165
	138 => "NetBIOS-DGM",
166
	139 => "NetBIOS-SSN",
167
	143 => "IMAP",
168
	161 => "SNMP",
169
	162 => "SNMP-Trap",
170
	389 => "LDAP",
171
	443 => "HTTPS",
172
	445 => "MS DS",
173
	465 => "SMTP/S",
174
	500 => "isakmp",
175
	993 => "IMAP/S",
176
	995 => "POP3/S",
177
	1194 => "OpenVPN",
178
	1512 => "MS WINS",
179
	1701 => "L2TP",
180
	1723 => "PPTP",
181
	1755 => "MMS/TCP",
182
	1812 => "Radius",
183
	1813 => "Radius-accounting",
184
	1863 => "MSN",
185
	3000 => "HBCI",
186
	3478 => "STUN",
187
	4500 => "IPsec NAT-T",
188
	5004 => "RTP",
189
	5060 => "SIP",
190
	5190 => "ICQ",
191
	5900 => "VNC",
192
	5999 => "CVSup",
193
	7000 => "MMS/UDP");
194

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

    
197
$spiflist = get_configured_interface_with_descr(true, true);
198
foreach ($spiflist as $if => $ifdesc) {
199
	$specialnets[$if] = $ifdesc . " net";
200
}
201

    
202
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
203
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
204
	"10half" => "10BASE-T half-duplex");
205

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

    
209
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
210

    
211
	/* check for bad control characters */
212
	foreach ($postdata as $pn => $pd) {
213
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
214
			$input_errors[] = "The field '" . $pn . "' contains invalid characters.";
215
		}
216
	}
217

    
218
	for ($i = 0; $i < count($reqdfields); $i++) {
219
		if ($_POST[$reqdfields[$i]] == "") {
220
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
221
		}
222
	}
223
}
224

    
225
function print_input_errors($input_errors) {
226
	global $g;
227
	echo "<p><table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\">\n";
228
	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";
229
	echo "<td bgcolor=\"#FFD9D1\" style=\"padding-left: 8px; padding-top: 6px\">";
230

    
231
	echo "<span class=\"errmsg\"><p>The following input errors were detected:<ul>\n";
232
	foreach ($input_errors as $ierr) {
233
		echo "<li>" . htmlspecialchars($ierr) . "</li>\n";
234
	}
235
	echo "</ul></span>";
236

    
237
	echo "</td></tr></table></p>&nbsp;<br>";
238
}
239

    
240
function exec_rc_script($scriptname) {
241

    
242
	global $d_sysrebootreqd_path;
243

    
244
	$execoutput = "";
245
	$retval = "";
246
	exec($scriptname . " >/dev/null 2>&1", $execoutput, $retval);
247
	return $retval;
248
}
249

    
250
function exec_rc_script_async($scriptname) {
251

    
252
	global $d_sysrebootreqd_path;
253
	$execoutput = "";
254
	$retval = "";
255

    
256
	exec("nohup " . $scriptname . " >/dev/null 2>&1 &", $execoutput, $retval);
257
	return $retval;
258
}
259

    
260
function verify_gzip_file($fname) {
261

    
262
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
263
	if ($returnvar != 0)
264
		return 0;
265
	else
266
		return 1;
267
}
268

    
269
function print_info_box_np($msg, $name="apply",$value="Apply changes") {
270
	global $g;
271
	echo "<table height=\"32\" width=\"100%\">\n";
272
	echo "  <tr>\n";
273
	echo "   <td>\n";
274
	echo "      <div style='background-color:#990000' id='redbox'>\n";
275
	echo "       <table width='100%'><tr><td width='8%'>\n";
276
	echo "        &nbsp;&nbsp;&nbsp;<img style='vertical-align:middle' src=\"/themes/".$g['theme']."/images/icons/icon_exclam.gif\" width=\"28\" height=\"32\">\n";
277
	echo "        </td>\n";
278
	echo "        <td width='70%'><font color='white'><b>{$msg}</b></font>\n";
279
	echo "        </td>";
280
	if(stristr($msg, "apply") == true || stristr($msg, "save") || stristr($msg, "create")) {
281
		echo "         <td>";
282
		echo "           <input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\">\n";
283
		echo "         </td>";
284
	}
285
	echo "        </tr></table>\n";
286
	echo "       </div>\n";
287
	echo "    </td>\n";
288
	echo "</table>\n";
289
	echo "<script type=\"text/javascript\">\n";
290
	echo "NiftyCheck();\n";
291
	echo "Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");\n";
292
	echo "Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");\n";
293
	echo "</script>\n";
294
	echo "\n<br>\n";
295
}
296

    
297
function print_info_box($msg) {
298
	echo "<p>";
299
	print_info_box_np($msg);
300
	echo "</p>";
301
}
302

    
303
function format_bytes($bytes) {
304
	if ($bytes >= 1073741824) {
305
		return sprintf("%.2f GB", $bytes/1073741824);
306
	} else if ($bytes >= 1048576) {
307
		return sprintf("%.2f MB", $bytes/1048576);
308
	} else if ($bytes >= 1024) {
309
		return sprintf("%.0f KB", $bytes/1024);
310
	} else {
311
		return sprintf("%d bytes", $bytes);
312
	}
313
}
314

    
315
function get_std_save_message($ok) {
316
	global $d_sysrebootreqd_path;
317

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

    
321
function pprint_address($adr) {
322
	global $specialnets;
323

    
324
	if (isset($adr['any'])) {
325
		$padr = "*";
326
	} else if ($adr['network']) {
327
		if (preg_match("/opt[0-999]ip/", $adr['network'])) {
328
			$padr = "Interface IP address";
329
		} else {
330
			$padr = $specialnets[$adr['network']];
331
		}
332
	} else {
333
		$padr = $adr['address'];
334
	}
335

    
336
	if (isset($adr['not']))
337
		$padr = "! " . $padr;
338

    
339
	return $padr;
340
}
341

    
342
function pprint_port($port) {
343
	global $wkports;
344

    
345
	$pport = "";
346

    
347
	if (!$port)
348
		return "*";
349
	else {
350
		$srcport = explode("-", $port);
351
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
352
			$pport = $srcport[0];
353
			if ($wkports[$srcport[0]]) {
354
				$pport .= " (" . $wkports[$srcport[0]] . ")";
355
			}
356
		} else
357
			$pport .= $srcport[0] . " - " . $srcport[1];
358
	}
359

    
360
	return $pport;
361
}
362

    
363
function captiveportal_users_sort() {
364
	global $g, $config;
365

    
366
	function cpusercmp($a, $b) {
367
		return strcasecmp($a['name'], $b['name']);
368
	}
369

    
370
	usort($config['captiveportal']['user'], "cpusercmp");
371
}
372

    
373
function admin_groups_sort() {
374
	global $g, $config;
375

    
376
	function cpusercmp($a, $b) {
377
		return strcasecmp($a['name'], $b['name']);
378
	}
379

    
380
	usort($config['system']['group'], "cpusercmp");
381
}
382

    
383
function admin_users_sort() {
384
	global $g, $config;
385

    
386
	function cpusercmp($a, $b) {
387
		return strcasecmp($a['name'], $b['name']);
388
	}
389

    
390
	usort($config['system']['user'], "cpusercmp");
391
}
392

    
393
/* sort by interface only, retain the original order of rules that apply to
394
   the same interface */
395
function filter_rules_sort() {
396
	global $config;
397

    
398
	/* mark each rule with the sequence number (to retain the order while sorting) */
399
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
400
		$config['filter']['rule'][$i]['seq'] = $i;
401

    
402
	function filtercmp($a, $b) {
403
		if ($a['interface'] == $b['interface'])
404
			return $a['seq'] - $b['seq'];
405
		else
406
			return -strcmp($a['interface'], $b['interface']);
407
	}
408

    
409
	usort($config['filter']['rule'], "filtercmp");
410

    
411
	/* strip the sequence numbers again */
412
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
413
		unset($config['filter']['rule'][$i]['seq']);
414
}
415

    
416
function nat_rules_sort() {
417
	global $config;
418

    
419
	function natcmp($a, $b) {
420
		if ($a['external-address'] == $b['external-address']) {
421
			if ($a['protocol'] == $b['protocol']) {
422
				if ($a['external-port'] == $b['external-port']) {
423
					return 0;
424
				} else {
425
					return ($a['external-port'] - $b['external-port']);
426
				}
427
			} else {
428
				return strcmp($a['protocol'], $b['protocol']);
429
			}
430
		} else if (!$a['external-address'])
431
			return 1;
432
		else if (!$b['external-address'])
433
			return -1;
434
		else
435
			return ipcmp($a['external-address'], $b['external-address']);
436
	}
437

    
438
	usort($config['nat']['rule'], "natcmp");
439
}
440

    
441
function nat_1to1_rules_sort() {
442
	global $g, $config;
443

    
444
	function nat1to1cmp($a, $b) {
445
		return ipcmp($a['external'], $b['external']);
446
	}
447

    
448
	usort($config['nat']['onetoone'], "nat1to1cmp");
449
}
450

    
451
function nat_server_rules_sort() {
452
	global $g, $config;
453

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

    
458
	usort($config['nat']['servernat'], "natservercmp");
459
}
460

    
461
function nat_out_rules_sort() {
462
	global $g, $config;
463

    
464
	function natoutcmp($a, $b) {
465
		return strcmp($a['source']['network'], $b['source']['network']);
466
	}
467

    
468
	usort($config['nat']['advancedoutbound']['rule'], "natoutcmp");
469
}
470

    
471
function pptpd_users_sort() {
472
	global $g, $config;
473

    
474
	function usercmp($a, $b) {
475
		return strcasecmp($a['name'], $b['name']);
476
	}
477

    
478
	usort($config['pptpd']['user'], "usercmp");
479
}
480

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

    
484
	function usercmp($a, $b) {
485
		return strcasecmp($a['name'], $b['name']);
486
	}
487

    
488
	usort($config['openvpn']['user'], "usercmp");
489
}
490

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

    
494
	function usercmp($a, $b) {
495
		return strcasecmp($a['name'], $b['name']);
496
	}
497

    
498
	usort($config['pppoe']['user'], "usercmp");
499
}
500

    
501
function staticroutes_sort() {
502
	global $g, $config;
503

    
504
	function staticroutecmp($a, $b) {
505
		return strcmp($a['network'], $b['network']);
506
	}
507

    
508
	usort($config['staticroutes']['route'], "staticroutecmp");
509
}
510

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

    
514
	function hostcmp($a, $b) {
515
		return strcasecmp($a['host'], $b['host']);
516
	}
517

    
518
	usort($config['dnsmasq']['hosts'], "hostcmp");
519
}
520

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

    
524
	function staticmapcmp($a, $b) {
525
		return ipcmp($a['ipaddr'], $b['ipaddr']);
526
	}
527

    
528
	usort($config['dhcpd'][$if]['staticmap'], "staticmapcmp");
529
}
530

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

    
534
	function aliascmp($a, $b) {
535
		return strcmp($a['name'], $b['name']);
536
	}
537

    
538
	usort($config['aliases']['alias'], "aliascmp");
539
}
540

    
541
function schedule_sort(){
542
	global $g, $config;
543

    
544
	function schedulecmp($a, $b) {
545
		return strcmp($a['name'], $b['name']);
546
	}
547

    
548
	usort($config['schedules']['schedule'], "schedulecmp");
549

    
550
}
551

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

    
555
	function mobilekeycmp($a, $b) {
556
		return strcmp($a['ident'][0], $b['ident'][0]);
557
	}
558

    
559
	usort($config['ipsec']['mobilekey'], "mobilekeycmp");
560
}
561

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

    
565
	function proxyarpcmp($a, $b) {
566
		if (isset($a['network']))
567
			list($ast,$asn) = explode("/", $a['network']);
568
		else if (isset($a['range'])) {
569
			$ast = $a['range']['from'];
570
			$asn = 32;
571
		}
572
		if (isset($b['network']))
573
			list($bst,$bsn) = explode("/", $b['network']);
574
		else if (isset($b['range'])) {
575
			$bst = $b['range']['from'];
576
			$bsn = 32;
577
		}
578
		if (ipcmp($ast, $bst) == 0)
579
			return ($asn - $bsn);
580
		else
581
			return ipcmp($ast, $bst);
582
	}
583

    
584
	usort($config['proxyarp']['proxyarpnet'], "proxyarpcmp");
585
}
586

    
587
function passthrumacs_sort() {
588
	global $g, $config;
589

    
590
	function passthrumacscmp($a, $b) {
591
		return strcmp($a['mac'], $b['mac']);
592
	}
593

    
594
	usort($config['captiveportal']['passthrumac'],"passthrumacscmp");
595
}
596

    
597
function cpelements_sort() {
598
	global $g, $config;
599

    
600
	function cpelementscmp($a, $b) {
601
		return strcasecmp($a['name'], $b['name']);
602
	}
603

    
604
	usort($config['captiveportal']['element'],"cpelementscmp");
605
}
606

    
607
function allowedips_sort() {
608
	global $g, $config;
609

    
610
	function allowedipscmp($a, $b) {
611
		return strcmp($a['ip'], $b['ip']);
612
	}
613

    
614
	usort($config['captiveportal']['allowedip'],"allowedipscmp");
615
}
616

    
617
function wol_sort() {
618
	global $g, $config;
619

    
620
	function wolcmp($a, $b) {
621
		return strcmp($a['descr'], $b['descr']);
622
	}
623

    
624
	usort($config['wol']['wolentry'], "wolcmp");
625
}
626

    
627
function gentitle($title) {
628
	global $navlevelsep;
629
	if(!is_array($title))
630
		return $title;
631
	else
632
		return join($navlevelsep, $title); 
633
}
634

    
635
function genhtmltitle($title) {
636
        global $config;
637
        return gentitle($title);
638
}
639

    
640
/* update the changedesc and changecount(er) variables */
641
function update_changedesc($update) {
642
	global $changedesc;
643
	global $changecount;
644

    
645
	$changedesc .= " {$update}";
646
	$changecount++;
647
}
648

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

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

    
702
/* Check if variable has changed, update and log if it has
703
 * returns true if var changed
704
 * varname = variable name in plain text
705
 * orig = original value
706
 * new = new value
707
 */
708
function update_if_changed($varname, & $orig, $new) {
709
	if (is_array($orig) && is_array($new)) {
710
		$a_diff = array_diff($orig, $new);
711
		foreach ($a_diff as $diff) {
712
			update_changedesc("removed {$varname}: \"{$diff}\"");
713
		}
714
		$a_diff = array_diff($new, $orig);
715
		foreach ($a_diff as $diff) {
716
			update_changedesc("added {$varname}: \"{$diff}\"");
717
		}
718
		$orig = $new;
719
		return true;
720

    
721
	} else {
722
		if ($orig != $new) {
723
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
724
			$orig = $new;
725
			return true;
726
		}
727
	}
728
	return false;
729
}
730

    
731
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
732

    
733
        if (isset($adr['any']))
734
                $padr = "any";
735
        else if ($adr['network'])
736
                $padr = $adr['network'];
737
        else if ($adr['address']) {
738
                list($padr, $pmask) = explode("/", $adr['address']);
739
                if (!$pmask)
740
                        $pmask = 32;
741
        }
742

    
743
        if (isset($adr['not']))
744
                $pnot = 1;
745
        else
746
                $pnot = 0;
747

    
748
        if ($adr['port']) {
749
                list($pbeginport, $pendport) = explode("-", $adr['port']);
750
                if (!$pendport)
751
                        $pendport = $pbeginport;
752
        } else {
753
                if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
754
                        /* Item is a port alias */
755
                } else {
756
                        $pbeginport = "any";
757
                        $pendport = "any";
758
                }
759
        }
760
}
761

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

    
764
        $adr = array();
765

    
766
        if ($padr == "any")
767
                $adr['any'] = true;
768
        else if (is_specialnet($padr))
769
                $adr['network'] = $padr;
770
        else {
771
                $adr['address'] = $padr;
772
                if ($pmask != 32)
773
                        $adr['address'] .= "/" . $pmask;
774
        }
775

    
776
        if ($pnot)
777
                $adr['not'] = true;
778
        else
779
                unset($adr['not']);
780

    
781
        if (($pbeginport != 0) && ($pbeginport != "any")) {
782
                if ($pbeginport != $pendport)
783
                        $adr['port'] = $pbeginport . "-" . $pendport;
784
                else
785
                        $adr['port'] = $pbeginport;
786
        }
787

    
788
        if(alias_expand($pbeginport)) {
789
                $adr['port'] = $pbeginport;
790
        }
791
}
792

    
793
function is_specialnet($net) {
794
        global $specialsrcdst;
795
		if(!$net) 
796
			return false;
797
        if (in_array($net, $specialsrcdst) || strstr($net, "opt"))
798
                return true;
799
        else
800
                return false;
801
}
802

    
803
function ipsec_ca_sort() {
804
        global $g, $config;
805

    
806
        function ipseccacmp($a, $b) {
807
                return strcmp($a['ident'], $b['ident']);
808
        }
809

    
810
        usort($config['ipsec']['cacert'], "ipseccacmp");
811
}
812

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

    
849

    
850
// Return inline javascript file or CSS to minimizie 
851
// request count going back to server.
852
function outputJavaScriptFileInline($javascript) {
853
	if(file_exists($javascript)) {
854
		echo "\n<script type=\"text/javascript\">\n";
855
		include($javascript);
856
		echo "\n</script>\n";
857
	} else {
858
		echo "\n\n<!-- Could not location file:  {$javascript} -->\n\n";
859
	}
860
}
861

    
862

    
863

    
864
function outputCSSPrintFileInline($css) {
865
	if(file_exists($css)) {
866
		echo "\n<style media=\"print\" type=\"text/css\">\n";
867
		include($css);
868
		echo "\n</style>\n";
869
	} else {
870
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
871
	}
872
}
873

    
874

    
875
function outputCSSFileInline($css) {
876
	if(file_exists($css)) {
877
		echo "\n<style type=\"text/css\">\n";
878
		include($css);
879
		echo "\n</style>\n";
880
	} else {
881
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
882
	}
883
}
884

    
885
$rfc2616 = array(
886
	100 => "100 Continue",
887
	101 => "101 Switching Protocols",
888
	200 => "200 OK",
889
	201 => "201 Created",
890
	202 => "202 Accepted",
891
	203 => "203 Non-Authoritative Information",
892
	204 => "204 No Content",
893
	205 => "205 Reset Content",
894
	206 => "206 Partial Content",
895
	300 => "300 Multiple Choices",
896
	301 => "301 Moved Permanently",
897
	302 => "302 Found",
898
	303 => "303 See Other",
899
	304 => "304 Not Modified",
900
	305 => "305 Use Proxy",
901
	306 => "306 (Unused)",
902
	307 => "307 Temporary Redirect",
903
	400 => "400 Bad Request",
904
	401 => "401 Unauthorized",
905
	402 => "402 Payment Required",
906
	403 => "403 Forbidden",
907
	404 => "404 Not Found",
908
	405 => "405 Method Not Allowed",
909
	406 => "406 Not Acceptable",
910
	407 => "407 Proxy Authentication Required",
911
	408 => "408 Request Timeout",
912
	409 => "409 Conflict",
913
	410 => "410 Gone",
914
	411 => "411 Length Required",
915
	412 => "412 Precondition Failed",
916
	413 => "413 Request Entity Too Large",
917
	414 => "414 Request-URI Too Long",
918
	415 => "415 Unsupported Media Type",
919
	416 => "416 Requested Range Not Satisfiable",
920
	417 => "417 Expectation Failed",
921
	500 => "500 Internal Server Error",
922
	501 => "501 Not Implemented",
923
	502 => "502 Bad Gateway",
924
	503 => "503 Service Unavailable",
925
	504 => "504 Gateway Timeout",
926
	505 => "505 HTTP Version Not Supported"
927
);
928

    
929
function is_rfc2616_code($code) {
930
	global $rfc2616;
931
	if (isset($rfc2616[$code]))
932
		return true;
933
	else
934
		return false;
935
}
936

    
937
function print_rfc2616_select($tag, $current){
938
	global $rfc2616;
939

    
940
	/* Default to 200 OK if not set */
941
	if ($current == "")
942
		$current = 200;
943

    
944
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";	
945
	foreach($rfc2616 as $code => $message) {
946
		if ($code == $current) {
947
			$sel = " selected";
948
		} else {
949
			$sel = "";
950
		}
951
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
952
	}
953
}
954

    
955
?>
(68-68/215)