Project

General

Profile

Download (26.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
/* 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
$netbios_nodetypes = array(
151
	'0' => "none",
152
	'1' => "b-node",
153
	'2' => "p-node",
154
	'4' => "m-node",
155
	'5' => "h-node");
156

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

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

    
204
$spiflist = get_configured_interface_with_descr(true, true);
205
foreach ($spiflist as $ifgui => $ifdesc) {
206
	$specialnets[$ifgui] = $ifdesc . " net";
207
}
208

    
209
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
210
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
211
	"10half" => "10BASE-T half-duplex");
212

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

    
216
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
217

    
218
	/* check for bad control characters */
219
	foreach ($postdata as $pn => $pd) {
220
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
221
			$input_errors[] = "The field '" . $pn . "' contains invalid characters.";
222
		}
223
	}
224

    
225
	for ($i = 0; $i < count($reqdfields); $i++) {
226
		if ($_POST[$reqdfields[$i]] == "") {
227
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
228
		}
229
	}
230
}
231

    
232
function print_input_errors($input_errors) {
233
	global $g;
234
	echo "<p><table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\">\n";
235
	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";
236
	echo "<td bgcolor=\"#FFD9D1\" style=\"padding-left: 8px; padding-top: 6px\">";
237

    
238
	echo "<span class=\"errmsg\"><p>The following input errors were detected:<ul>\n";
239
	foreach ($input_errors as $ierr) {
240
		echo "<li>" . htmlspecialchars($ierr) . "</li>\n";
241
	}
242
	echo "</ul></span>";
243

    
244
	echo "</td></tr></table></p>&nbsp;<br>";
245
}
246

    
247
function exec_rc_script($scriptname) {
248

    
249
	global $d_sysrebootreqd_path;
250

    
251
	$execoutput = "";
252
	$retval = "";
253
	exec($scriptname . " >/dev/null 2>&1", $execoutput, $retval);
254
	return $retval;
255
}
256

    
257
function exec_rc_script_async($scriptname) {
258

    
259
	global $d_sysrebootreqd_path;
260
	$execoutput = "";
261
	$retval = "";
262

    
263
	exec("nohup " . $scriptname . " >/dev/null 2>&1 &", $execoutput, $retval);
264
	return $retval;
265
}
266

    
267
function verify_gzip_file($fname) {
268

    
269
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
270
	if ($returnvar != 0)
271
		return 0;
272
	else
273
		return 1;
274
}
275

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

    
304
function print_info_box($msg) {
305
	echo "<p>";
306
	print_info_box_np($msg);
307
	echo "</p>";
308
}
309

    
310
function get_std_save_message($ok) {
311
	global $d_sysrebootreqd_path;
312

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

    
316
function pprint_address($adr) {
317
	global $specialnets;
318

    
319
	if (isset($adr['any'])) {
320
		$padr = "*";
321
	} else if ($adr['network']) {
322
		if (preg_match("/opt[0-999]ip/", $adr['network'])) {
323
			$padr = "Interface IP address";
324
		} else {
325
			$padr = $specialnets[$adr['network']];
326
		}
327
	} else {
328
		$padr = $adr['address'];
329
	}
330

    
331
	if (isset($adr['not']))
332
		$padr = "! " . $padr;
333

    
334
	return $padr;
335
}
336

    
337
function pprint_port($port) {
338
	global $wkports;
339

    
340
	$pport = "";
341

    
342
	if (!$port)
343
		return "*";
344
	else {
345
		$srcport = explode("-", $port);
346
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
347
			$pport = $srcport[0];
348
			if ($wkports[$srcport[0]]) {
349
				$pport .= " (" . $wkports[$srcport[0]] . ")";
350
			}
351
		} else
352
			$pport .= $srcport[0] . " - " . $srcport[1];
353
	}
354

    
355
	return $pport;
356
}
357

    
358
function captiveportal_users_sort() {
359
	global $g, $config;
360

    
361
	function cpusercmp($a, $b) {
362
		return strcasecmp($a['name'], $b['name']);
363
	}
364

    
365
	usort($config['captiveportal']['user'], "cpusercmp");
366
}
367

    
368
function admin_groups_sort() {
369
	global $g, $config;
370

    
371
	function cpusercmp($a, $b) {
372
		return strcasecmp($a['name'], $b['name']);
373
	}
374

    
375
	usort($config['system']['group'], "cpusercmp");
376
}
377

    
378
function admin_users_sort() {
379
	global $g, $config;
380

    
381
	function cpusercmp($a, $b) {
382
		return strcasecmp($a['name'], $b['name']);
383
	}
384

    
385
	usort($config['system']['user'], "cpusercmp");
386
}
387

    
388
/* sort by interface only, retain the original order of rules that apply to
389
   the same interface */
390
function filter_rules_sort() {
391
	global $config;
392

    
393
	/* mark each rule with the sequence number (to retain the order while sorting) */
394
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
395
		$config['filter']['rule'][$i]['seq'] = $i;
396

    
397
	function filtercmp($a, $b) {
398
		if ($a['interface'] == $b['interface'])
399
			return $a['seq'] - $b['seq'];
400
		else
401
			return -strcmp($a['interface'], $b['interface']);
402
	}
403

    
404
	usort($config['filter']['rule'], "filtercmp");
405

    
406
	/* strip the sequence numbers again */
407
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
408
		unset($config['filter']['rule'][$i]['seq']);
409
}
410

    
411
function nat_rules_sort() {
412
	global $config;
413

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

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

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

    
439
	function nat1to1cmp($a, $b) {
440
		return ipcmp($a['external'], $b['external']);
441
	}
442

    
443
	usort($config['nat']['onetoone'], "nat1to1cmp");
444
}
445

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

    
449
	function natservercmp($a, $b) {
450
		return ipcmp($a['ipaddr'], $b['ipaddr']);
451
	}
452

    
453
	usort($config['nat']['servernat'], "natservercmp");
454
}
455

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

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

    
463
	usort($config['nat']['advancedoutbound']['rule'], "natoutcmp");
464
}
465

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

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

    
473
	usort($config['pptpd']['user'], "usercmp");
474
}
475

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

    
479
	function usercmp($a, $b) {
480
		return strcasecmp($a['name'], $b['name']);
481
	}
482

    
483
	usort($config['openvpn']['user'], "usercmp");
484
}
485

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

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

    
493
	usort($config['pppoe']['user'], "usercmp");
494
}
495

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

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

    
503
	usort($config['staticroutes']['route'], "staticroutecmp");
504
}
505

    
506
function hosts_sort() {
507
	global $g, $config;
508

    
509
	function hostcmp($a, $b) {
510
		return strcasecmp($a['host'], $b['host']);
511
	}
512

    
513
	usort($config['dnsmasq']['hosts'], "hostcmp");
514
}
515

    
516
function staticmaps_sort($ifgui) {
517
	global $g, $config;
518

    
519
	function staticmapcmp($a, $b) {
520
		return ipcmp($a['ipaddr'], $b['ipaddr']);
521
	}
522

    
523
	usort($config['dhcpd'][$ifgui]['staticmap'], "staticmapcmp");
524
}
525

    
526
function aliases_sort() {
527
	global $g, $config;
528

    
529
	function aliascmp($a, $b) {
530
		return strcmp($a['name'], $b['name']);
531
	}
532

    
533
	usort($config['aliases']['alias'], "aliascmp");
534
}
535

    
536
function schedule_sort(){
537
	global $g, $config;
538

    
539
	function schedulecmp($a, $b) {
540
		return strcmp($a['name'], $b['name']);
541
	}
542

    
543
	usort($config['schedules']['schedule'], "schedulecmp");
544

    
545
}
546

    
547
function ipsec_mobilekey_sort() {
548
	global $g, $config;
549

    
550
	function mobilekeycmp($a, $b) {
551
		return strcmp($a['ident'][0], $b['ident'][0]);
552
	}
553

    
554
	usort($config['ipsec']['mobilekey'], "mobilekeycmp");
555
}
556

    
557
function proxyarp_sort() {
558
	global $g, $config;
559

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

    
579
	usort($config['proxyarp']['proxyarpnet'], "proxyarpcmp");
580
}
581

    
582
function passthrumacs_sort() {
583
	global $g, $config;
584

    
585
	function passthrumacscmp($a, $b) {
586
		return strcmp($a['mac'], $b['mac']);
587
	}
588

    
589
	usort($config['captiveportal']['passthrumac'],"passthrumacscmp");
590
}
591

    
592
function cpelements_sort() {
593
	global $g, $config;
594

    
595
	function cpelementscmp($a, $b) {
596
		return strcasecmp($a['name'], $b['name']);
597
	}
598

    
599
	usort($config['captiveportal']['element'],"cpelementscmp");
600
}
601

    
602
function allowedips_sort() {
603
	global $g, $config;
604

    
605
	function allowedipscmp($a, $b) {
606
		return strcmp($a['ip'], $b['ip']);
607
	}
608

    
609
	usort($config['captiveportal']['allowedip'],"allowedipscmp");
610
}
611

    
612
function wol_sort() {
613
	global $g, $config;
614

    
615
	function wolcmp($a, $b) {
616
		return strcmp($a['descr'], $b['descr']);
617
	}
618

    
619
	usort($config['wol']['wolentry'], "wolcmp");
620
}
621

    
622
function gentitle($title) {
623
	global $navlevelsep;
624
	if(!is_array($title))
625
		return $title;
626
	else
627
		return join($navlevelsep, $title); 
628
}
629

    
630
function genhtmltitle($title) {
631
        global $config;
632
        return gentitle($title);
633
}
634

    
635
/* update the changedesc and changecount(er) variables */
636
function update_changedesc($update) {
637
	global $changedesc;
638
	global $changecount;
639

    
640
	$changedesc .= " {$update}";
641
	$changecount++;
642
}
643

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

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

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

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

    
726
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
727

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

    
738
        if (isset($adr['not']))
739
                $pnot = 1;
740
        else
741
                $pnot = 0;
742

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

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

    
759
        $adr = array();
760

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

    
771
        if ($pnot)
772
                $adr['not'] = true;
773
        else
774
                unset($adr['not']);
775

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

    
783
        if(alias_expand($pbeginport)) {
784
                $adr['port'] = $pbeginport;
785
        }
786
}
787

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

    
798
function ipsec_ca_sort() {
799
        global $g, $config;
800

    
801
        function ipseccacmp($a, $b) {
802
                return strcmp($a['ident'], $b['ident']);
803
        }
804

    
805
        usort($config['ipsec']['cacert'], "ipseccacmp");
806
}
807

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

    
844

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

    
857

    
858

    
859
function outputCSSPrintFileInline($css) {
860
	if(file_exists($css)) {
861
		echo "\n<style media=\"print\" type=\"text/css\">\n";
862
		include($css);
863
		echo "\n</style>\n";
864
	} else {
865
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
866
	}
867
}
868

    
869

    
870
function outputCSSFileInline($css) {
871
	if(file_exists($css)) {
872
		echo "\n<style type=\"text/css\">\n";
873
		include($css);
874
		echo "\n</style>\n";
875
	} else {
876
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
877
	}
878
}
879

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

    
924
function is_rfc2616_code($code) {
925
	global $rfc2616;
926
	if (isset($rfc2616[$code]))
927
		return true;
928
	else
929
		return false;
930
}
931

    
932
function print_rfc2616_select($tag, $current){
933
	global $rfc2616;
934

    
935
	/* Default to 200 OK if not set */
936
	if ($current == "")
937
		$current = 200;
938

    
939
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";	
940
	foreach($rfc2616 as $code => $message) {
941
		if ($code == $current) {
942
			$sel = " selected";
943
		} else {
944
			$sel = "";
945
		}
946
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
947
	}
948
}
949

    
950
// Useful debugging function, much cleaner than print_r
951
function echo_array($array,$return_me=false){
952
    if(is_array($array) == false){
953
        $return = "The provided variable is not an array.";
954
    }else{
955
        foreach($array as $name=>$value){
956
            if(is_array($value)){
957
                $return .= "";
958
                $return .= "['<b>$name</b>'] {<div style='margin-left:10px;'>\n";
959
                $return .= echo_array($value,true);
960
                $return .= "</div>}";
961
                $return .= "\n\n";
962
            }else{
963
                if(is_string($value)){
964
                    $value = "\"$value\"";
965
                }
966
                $return .= "['<b>$name</b>'] = $value\n\n";
967
            }
968
        }
969
    }
970
    if($return_me == true){
971
        return $return;
972
    }else{
973
        echo "<pre>".$return."</pre>";
974
    }
975
}
976

    
977

    
978
?>
(68-68/210)