Project

General

Profile

Download (34.5 KB) Statistics
| Branch: | Tag: | Revision:
1 667b2b60 Ermal
<?php
2
/*
3
	guiconfig.inc
4
	by Scott Ullrich, Copyright 2004, All rights reserved.
5
	originally based on of m0n0wall (http://m0n0.ch/wall)
6
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*
32
	pfSense_MODULE:	base
33
*/
34
35
/* Include authentication routines */
36
/* THIS MUST BE ABOVE ALL OTHER CODE */
37 64ec1ddf Scott Ullrich
if(!$nocsrf) {
38
	function csrf_startup() {
39
		csrf_conf('rewrite-js', '/csrf/csrf-magic.js');
40 56befec1 jim-p
		$timeout_minutes = isset($config['system']['webgui']['session_timeout']) ?  $config['system']['webgui']['session_timeout'] : 240;
41
		csrf_conf('expires', $timeout_minutes * 60);
42 64ec1ddf Scott Ullrich
	}
43
	require_once("csrf/csrf-magic.php");
44 fafd303e Scott Ullrich
}
45 667b2b60 Ermal
46
/* make sure nothing is cached */
47
if (!$omit_nocacheheaders) {
48
	header("Expires: 0");
49
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
50
	header("Cache-Control: no-store, no-cache, must-revalidate");
51
	header("Cache-Control: post-check=0, pre-check=0", false);
52
	header("Pragma: no-cache");
53
}
54
55 6f3d2063 Renato Botelho
header("X-Frame-Options: SAMEORIGIN");
56 9c59f962 Ermal
require_once("authgui.inc");
57
58 667b2b60 Ermal
/* parse the configuration and include all configuration functions */
59
require_once("functions.inc");
60
61
/* Pull in all the gui related display classes) */
62
foreach (scandir("/usr/local/www/classes/") as $file) {
63 d7a1532b jim-p
	if (substr($file, -4) == ".inc") {
64 667b2b60 Ermal
		require_once("classes/{$file}");
65
	}
66
}
67
68 1e1e1ec8 jim-p
$g['theme'] = get_current_theme();
69 667b2b60 Ermal
70 3e139f90 Vinicius Coque
/* Set the default interface language */
71
if($config['system']['language'] <> "") {
72
	$g['language'] = $config['system']['language'];
73
} elseif ($g['language'] == "") {
74
	$g['language'] = 'en_US';
75
}
76
77
set_language($g['language']);
78
79 667b2b60 Ermal
/* used by progress bar */
80
$lastseen = "-1";
81
82
$navlevelsep = ": ";	/* navigation level separator string */
83
$mandfldhtml = "";		/* display this before mandatory input fields */
84
$mandfldhtmlspc = "";	/* same as above, but with spacing */
85
86
/* Some ajax scripts still need access to GUI */
87
if(!$ignorefirmwarelock) {
88
	if (is_subsystem_dirty('firmwarelock')) {
89
		if (!$d_isfwfile) {
90
			header("Location: system_firmware.php");
91
			exit;
92
		} else {
93
			return;
94
		}
95
	}
96
}
97
98 ee9783e9 Ermal
/* Reserved table names to avoid colision */
99
$reserved_table_names = array(
100
        "bogons",
101
        "bogonsv6",
102
        "negate_networks",
103
        "snort2c",
104
        "sshlockout",
105
        "tonatsubnets",
106
        "virusprot",
107
        "vpn_networks",
108
        "webConfiguratorlockout"
109
);
110
111 96ccd009 Renato Botelho
$firewall_rules_dscp_types = array("af11",
112
				"af12",
113
				"af13",
114
				"af21",
115
				"af22",
116
				"af23",
117
				"af31",
118
				"af32",
119
				"af33",
120
				"af41",
121
				"af42",
122
				"af43",
123 28c49959 Klaws--
				"VA",
124 96ccd009 Renato Botelho
				"EF",
125 dc63650a Klaws--
				"cs1",
126
				"cs2",
127
				"cs3",
128
				"cs4",
129
				"cs5",
130
				"cs6",
131
				"cs7",
132 c15b5ed8 Renato Botelho
				"0x01",
133
				"0x02",
134
				"0x04");
135 667b2b60 Ermal
136
$auth_server_types = array(
137
	'ldap' => "LDAP",
138
	'radius' => "Radius");
139
140
$ldap_urltypes = array(
141
	'TCP - Standard' => 389,
142
	'SSL - Encrypted' => 636);
143
144
$ldap_scopes = array(
145
	'one' => "One Level",
146
	'subtree' => "Entire Subtree");
147
148
$ldap_protvers = array(
149
	2,
150
	3);
151
152
$ldap_templates = array(
153
154
	'open' => array(
155
				'desc' => "OpenLDAP",
156
				'attr_user' => "cn",
157
				'attr_group' => "cn",
158
				'attr_member' => "member"),
159
160
	'msad' => array(
161
				'desc' => "Microsoft AD",
162
				'attr_user' => "samAccountName",
163
				'attr_group' => "cn",
164
				'attr_member' => "memberOf"),
165
166
	'edir' => array(
167
				'desc' => "Novell eDirectory",
168
				'attr_user' => "cn",
169
				'attr_group' => "cn",
170
				'attr_member' => "uniqueMember"));
171
172
$radius_srvcs = array(
173
	'both' => "Authentication and Accounting",
174
	'auth' => "Authentication",
175
	'acct' => "Accounting");
176
177
$netbios_nodetypes = array(
178
	'0' => "none",
179
	'1' => "b-node",
180
	'2' => "p-node",
181
	'4' => "m-node",
182 13ec619c Chris Buechler
	'8' => "h-node");
183 667b2b60 Ermal
184
/* some well knows ports */
185
$wkports = array(
186 96ccd009 Renato Botelho
	5999 => "CVSup",
187 667b2b60 Ermal
	53 => "DNS",
188
	21 => "FTP",
189
	3000 => "HBCI",
190
	80 => "HTTP",
191
	443 => "HTTPS",
192
	5190 => "ICQ",
193
	113 => "IDENT/AUTH",
194
	143 => "IMAP",
195
	993 => "IMAP/S",
196
	4500 => "IPsec NAT-T",
197
	500 => "ISAKMP",
198
	1701 => "L2TP",
199
	389 => "LDAP",
200
	1755 => "MMS/TCP",
201
	7000 => "MMS/UDP",
202
	445 => "MS DS",
203
	3389 => "MS RDP",
204
	1512 => "MS WINS",
205
	1863 => "MSN",
206
	119 => "NNTP",
207
	123 => "NTP",
208
	138 => "NetBIOS-DGM",
209
	137 => "NetBIOS-NS",
210
	139 => "NetBIOS-SSN",
211
	1194 => "OpenVPN",
212
	110 => "POP3",
213
	995 => "POP3/S",
214 96ccd009 Renato Botelho
	1723 => "PPTP",
215 667b2b60 Ermal
	1812 => "RADIUS",
216
	1813 => "RADIUS accounting",
217
	5004 => "RTP",
218
	5060 => "SIP",
219
	25 => "SMTP",
220
	465 => "SMTP/S",
221
	161 => "SNMP",
222
	162 => "SNMP-Trap",
223
	22 => "SSH",
224
	3478 => "STUN",
225 76e91d3f Warren Baker
	587 => "SUBMISSION",
226 667b2b60 Ermal
	3544 => "Teredo",
227
	23 => "Telnet",
228
	69 => "TFTP",
229
	5900 => "VNC");
230
231
/* TCP flags */
232 79cc9e6b bcyrill
$tcpflags = array("fin", "syn", "rst", "psh", "ack", "urg", "ece", "cwr");
233 667b2b60 Ermal
234 0d0c01ca jim-p
$specialnets = array("(self)" => "This Firewall", "pptp" => "PPTP clients", "pppoe" => "PPPoE clients", "l2tp" => "L2TP clients");
235 667b2b60 Ermal
236
$spiflist = get_configured_interface_with_descr(false, true);
237
foreach ($spiflist as $ifgui => $ifdesc) {
238
	$specialnets[$ifgui] = $ifdesc . " net";
239
	$specialnets[$ifgui . 'ip'] = $ifdesc . " address";
240
}
241
242
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
243
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
244
	"10half" => "10BASE-T half-duplex");
245
246
$wlan_modes = array("bss" => "Infrastructure (BSS)", "adhoc" => "Ad-hoc (IBSS)",
247
	"hostap" => "Access Point");
248
249
/* platforms that support firmware updating */
250
$fwupplatforms = array('pfSense', 'net45xx', 'net48xx', 'generic-pc', 'embedded', 'wrap', 'nanobsd');
251
252 eb4ac13e Renato Botelho
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, &$input_errors) {
253 667b2b60 Ermal
254
	/* check for bad control characters */
255
	foreach ($postdata as $pn => $pd) {
256
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
257 41602469 Luiz Gustavo Costa
			$input_errors[] = sprintf(gettext("The field %s contains invalid characters."), $pn);
258 667b2b60 Ermal
		}
259
	}
260
261
	for ($i = 0; $i < count($reqdfields); $i++) {
262
		if ($_POST[$reqdfields[$i]] == "" && $_REQUEST[$reqdfields[$i]] == "") {
263 bd757043 Renato Botelho
			$input_errors[] = sprintf(gettext("The field %s is required."), $reqdfieldsn[$i]);
264 667b2b60 Ermal
		}
265
	}
266
}
267
268
function print_input_errors($input_errors) {
269
	global $g;
270
271
	print <<<EOF
272 f326b978 Colin Fleming
	<div id="inputerrorsdiv">
273
	<table border="0" cellspacing="0" cellpadding="4" width="100%" summary="input errors">
274 667b2b60 Ermal
	<tr>
275
		<td class="inputerrorsleft">
276 f326b978 Colin Fleming
			<img src="/themes/{$g['theme']}/images/icons/icon_error.gif" alt="errors" />
277 667b2b60 Ermal
		</td>
278 e28307d0 Luiz Gustavo Costa
        <td class="inputerrorsright errmsg">
279 667b2b60 Ermal
EOF;
280 e28307d0 Luiz Gustavo Costa
    echo "<p>" . gettext("The following input errors were detected:") . "</p>\n<ul>";
281
	foreach ($input_errors as $ierr) {
282
		echo "<li>" . htmlspecialchars($ierr) . "</li>";
283
	}
284 667b2b60 Ermal
285
	print <<<EOF2
286
				</ul>
287
		</td></tr>
288
	</table>
289 60ccf01c Scott Ullrich
	</div>
290 8cbda52b Colin Fleming
	&nbsp;<br />
291 667b2b60 Ermal
EOF2;
292 f326b978 Colin Fleming
293 667b2b60 Ermal
}
294
295
function verify_gzip_file($fname) {
296 96ccd009 Renato Botelho
	$returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
297 667b2b60 Ermal
	if ($returnvar != 0)
298
		return 0;
299
	else
300
		return 1;
301
}
302
303 c9eb66f6 Vinicius Coque
function print_info_box_np($msg, $name="apply",$value="", $showapply=false) {
304 667b2b60 Ermal
	global $g, $nifty_redbox, $nifty_blackbox, $nifty_background;
305
306 c9eb66f6 Vinicius Coque
	if(empty($value)) {
307
		$value = gettext("Apply changes");
308
	}
309
310 667b2b60 Ermal
	// Set the Nifty background color if one is not set already (defaults to white)
311
	if($nifty_background == "")
312
		$nifty_background = "#FFF";
313
314 c9eb66f6 Vinicius Coque
	if(stristr($msg, gettext("apply")) != false || stristr($msg, gettext("save")) != false || stristr($msg, gettext("create")) != false || $showapply) {
315 f326b978 Colin Fleming
		$savebutton = "<td class=\"infoboxsave\">";
316
		$savebutton .= "<input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\" />";
317 abe430cc jim-p
		if($_POST['if'])
318 f326b978 Colin Fleming
			$savebutton .= "<input type=\"hidden\" name=\"if\" value=\"" . htmlspecialchars($_POST['if']) . "\" />";
319 667b2b60 Ermal
		$savebutton.="</td>";
320
	}
321
	$nifty_redbox = "#990000";
322
	$nifty_blackbox = "#000000";
323 f326b978 Colin Fleming
324 667b2b60 Ermal
	$themename = $g['theme'];
325 f326b978 Colin Fleming
326 667b2b60 Ermal
	if(file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
327
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
328
		eval($toeval);
329
	}
330 f326b978 Colin Fleming
331 667b2b60 Ermal
	if(file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
332
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
333
		eval($toeval);
334 96ccd009 Renato Botelho
	}
335 f326b978 Colin Fleming
336 667b2b60 Ermal
	if(!$savebutton) {
337 370b4666 bruno
		$savebutton = "<td class=\"infoboxsave\"><input value=\"" . gettext("Close") . "\" type=\"button\" onclick=\"jQuery(this).parents('table[id=redboxtable]').hide();\" /></td>";
338 667b2b60 Ermal
	}
339
340
	echo <<<EOFnp
341 f326b978 Colin Fleming
	<table class="infobox" id="redboxtable" summary="red box table">
342 667b2b60 Ermal
		<tr>
343
			<td>
344 f326b978 Colin Fleming
				<div class="infoboxnp" id="redbox">
345
					<table class="infoboxnptable2" summary="message">
346 667b2b60 Ermal
						<tr>
347 f326b978 Colin Fleming
							<td class="infoboxnptd">
348
								&nbsp;&nbsp;&nbsp;<img class="infoboxnpimg" src="/themes/{$g['theme']}/images/icons/icon_exclam.gif" alt="exclamation" />
349 667b2b60 Ermal
							</td>
350 f326b978 Colin Fleming
							<td class="infoboxnptd2">
351 667b2b60 Ermal
								<b>{$msg}</b>
352
							</td>
353
							{$savebutton}
354
						</tr>
355
					</table>
356
				</div>
357
				<div>
358 f326b978 Colin Fleming
					<p>&nbsp;</p>
359 667b2b60 Ermal
				</div>
360
			</td>
361
		</tr>
362
	</table>
363
	<script type="text/javascript">
364 f326b978 Colin Fleming
	//<![CDATA[
365 667b2b60 Ermal
		NiftyCheck();
366
		Rounded("div#redbox","all","{$nifty_background}","{$nifty_redbox}","smooth");
367
		Rounded("td#blackbox","all","{$nifty_background}","{$nifty_blackbox}","smooth");
368 f326b978 Colin Fleming
	//]]>
369 667b2b60 Ermal
	</script>
370
EOFnp;
371
372
}
373
374
function print_info_box_np_undo($msg, $name="apply",$value="Apply changes", $undo) {
375
	global $g;
376 f326b978 Colin Fleming
377 667b2b60 Ermal
	if(stristr($msg, "apply") != false || stristr($msg, "save") != false || stristr($msg, "create") != false) {
378 f326b978 Colin Fleming
		$savebutton = "<td class=\"infoboxsave nowrap\">";
379 e28307d0 Luiz Gustavo Costa
		$savebutton .= "<input type=\"button\" value=\"". gettext("Undo") . "\" onclick=\"document.location='{$undo}'\" />";
380 f326b978 Colin Fleming
		$savebutton .= "<input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\" />";
381
		$savebutton .= "</td>";
382 96ccd009 Renato Botelho
		if($_POST['if'])
383 f326b978 Colin Fleming
			$savebutton .= "<input type=\"hidden\" name=\"if\" value=\"" . htmlspecialchars($_POST['if']) . "\" />";
384 667b2b60 Ermal
	}
385
	$nifty_redbox = "#990000";
386
	$nifty_blackbox = "#000000";
387 f326b978 Colin Fleming
388 667b2b60 Ermal
	$themename = $g['theme'];
389 f326b978 Colin Fleming
390 667b2b60 Ermal
	if(file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
391
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
392
		eval($toeval);
393
	}
394 f326b978 Colin Fleming
395 667b2b60 Ermal
	if(file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
396
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
397
		eval($toeval);
398 96ccd009 Renato Botelho
	}
399 f326b978 Colin Fleming
400
401 667b2b60 Ermal
	if(!$savebutton) {
402 370b4666 bruno
		$savebutton = "<td class=\"infoboxsave\"><input value=\"" . gettext("Close") . "\" type=\"button\" onclick=\"jQuery(this).parents('table[id=redboxtable]').hide();\" /></td>";
403 667b2b60 Ermal
	}
404
405
	echo <<<EOFnp
406 f326b978 Colin Fleming
	<table class="infobox" id="redboxtable" summary="red box table">
407 667b2b60 Ermal
		<tr>
408
			<td>
409 f326b978 Colin Fleming
				<div class="infoboxnp" id="redbox">
410
					<table class="infoboxnptable2" summary="message">
411 667b2b60 Ermal
						<tr>
412 f326b978 Colin Fleming
							<td class="infoboxnptd">
413
								&nbsp;&nbsp;&nbsp;<img class="infoboxnpimg" src="/themes/{$g['theme']}/images/icons/icon_exclam.gif" alt="exclamation" />
414 667b2b60 Ermal
							</td>
415 f326b978 Colin Fleming
							<td class="infoboxnptd2">
416 667b2b60 Ermal
								<b>{$msg}</b>
417
							</td>
418 96ccd009 Renato Botelho
							{$savebutton}
419 667b2b60 Ermal
							{$undobutton}
420
						</tr>
421
					</table>
422
				</div>
423
				<div>
424 f326b978 Colin Fleming
					<p>&nbsp;</p>
425 667b2b60 Ermal
				</div>
426
			</td>
427
		</tr>
428
	</table>
429
	<script type="text/javascript">
430 f326b978 Colin Fleming
	//<![CDATA[
431 667b2b60 Ermal
		NiftyCheck();
432
		Rounded("div#redbox","all","#FFF","{$nifty_redbox}","smooth");
433
		Rounded("td#blackbox","all","#FFF","{$nifty_blackbox}","smooth");
434 f326b978 Colin Fleming
	//]]>
435 667b2b60 Ermal
	</script>
436
EOFnp;
437
438
}
439
440
function print_info_box($msg) {
441
	print_info_box_np($msg);
442
}
443
444
function get_std_save_message($ok) {
445
	global $d_sysrebootreqd_path;
446 cfaf6e69 Scott Ullrich
	$filter_related = false;
447
	$filter_pages = array("nat", "filter");
448 e28307d0 Luiz Gustavo Costa
	$to_return = gettext("The changes have been applied successfully.");
449 96ccd009 Renato Botelho
	foreach($filter_pages as $fp)
450 cfaf6e69 Scott Ullrich
		if(stristr($_SERVER['SCRIPT_FILENAME'], $fp))
451 96ccd009 Renato Botelho
			$filter_related = true;
452 cfaf6e69 Scott Ullrich
	if($filter_related)
453 8cd558b6 ayvis
		$to_return .= "<br />" . gettext("You can also <a href=\"status_filter_reload.php\">monitor</a> the filter reload progress.");
454 cfaf6e69 Scott Ullrich
	return $to_return;
455 667b2b60 Ermal
}
456
457
function pprint_address($adr) {
458
	global $specialnets;
459
460
	if (isset($adr['any'])) {
461
		$padr = "*";
462
	} else if ($adr['network']) {
463
		$padr = $specialnets[$adr['network']];
464
	} else {
465
		$padr = $adr['address'];
466
	}
467
468
	if (isset($adr['not']))
469
		$padr = "! " . $padr;
470
471
	return $padr;
472
}
473
474
function pprint_port($port) {
475
	global $wkports;
476
477
	$pport = "";
478
479
	if (!$port)
480
		return "*";
481
	else {
482
		$srcport = explode("-", $port);
483
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
484
			$pport = $srcport[0];
485
			if ($wkports[$srcport[0]]) {
486
				$pport .= " (" . $wkports[$srcport[0]] . ")";
487
			}
488
		} else
489
			$pport .= $srcport[0] . " - " . $srcport[1];
490
	}
491
492
	return $pport;
493
}
494
495 8e0c3760 Ermal
function firewall_check_for_advanced_options(&$item) {
496 96ccd009 Renato Botelho
	$item_set = "";
497 f0c1ce21 Phil Davis
	if($item['os'])
498
		$item_set .= "os {$item['os']} ";
499
	if($item['dscp'])
500
		$item_set .= "dscp {$item['dscp']} ";
501 96ccd009 Renato Botelho
	if($item['max'])
502
		$item_set .= "max {$item['max']} ";
503
	if($item['max-src-nodes'])
504
		$item_set .= "max-src-nodes {$item['max-src-nodes']} ";
505
	if($item['max-src-conn'])
506
		$item_set .= "max-src-conn {$item['max-src-conn']} ";
507
	if($item['max-src-states'])
508
		$item_set .= "max-src-states {$item['max-src-states']} ";
509 f0c1ce21 Phil Davis
	if(isset($item['nopfsync']))
510
		$item_set .= "nopfsync ";
511 96ccd009 Renato Botelho
	if($item['statetype'] != "keep state" && $item['statetype'] != "")
512
		$item_set .= "statetype {$item['statetype']} ";
513
	if($item['statetimeout'])
514
		$item_set .= "statetimeout {$item['statetimeout']} ";
515 f0c1ce21 Phil Davis
	if(isset($item['nosync']))
516
		$item_set .= "no XMLRPC Sync ";
517 96ccd009 Renato Botelho
	if($item['max-src-conn-rate'])
518
		$item_set .= "max-src-conn-rate {$item['max-src-conn-rate']} ";
519
	if($item['max-src-conn-rates'])
520
		$item_set .= "max-src-conn-rates {$item['max-src-conn-rates']} ";
521 f0c1ce21 Phil Davis
	if($item['vlanprio'])
522
		$item_set .= "vlanprio {$item['vlanprio']} ";
523
	if($item['vlanprioset'])
524
		$item_set .= "vlanprioset {$item['vlanprioset']} ";
525 96ccd009 Renato Botelho
	if($item['gateway'])
526
		$item_set .= "gateway {$item['gateway']} ";
527
	if($item['dnpipe'])
528
		$item_set .= "limiter {$item['dnpipe']} ";
529
	if($item['pdnpipe'])
530
		$item_set .= "limiter {$item['pdnpipe']} ";
531 f0c1ce21 Phil Davis
	if($item['ackqueue'])
532
		$item_set .= "ackqueue {$item['ackqueue']} ";
533
	if($item['defaultqueue'])
534
		$item_set .= "defaultqueue {$item['defaultqueue']} ";
535 96ccd009 Renato Botelho
	if($item['l7container'])
536
		$item_set .= "layer7 {$item['l7container']} ";
537
	if($item['tag'])
538
		$item_set .= "tag {$item['tag']} ";
539
	if($item['tagged'])
540
		$item_set .= "tagged {$item['tagged']} ";
541
	if(isset($item['allowopts']))
542
		$item_set .= "allowopts ";
543
	if(isset($item['disablereplyto']))
544
		$item_set .= "disable reply-to ";
545
	if($item['tcpflags_any'] || $item['tcpflags1'] || $item['tcpflags2'])
546
		$item_set .= "tcpflags set";
547
548
	return $item_set;
549 8e0c3760 Ermal
}
550
551 667b2b60 Ermal
function gentitle($title) {
552
	global $navlevelsep;
553
	if(!is_array($title))
554
		return $title;
555
	else
556
		return join($navlevelsep, $title);
557
}
558
559
function genhtmltitle($title) {
560 96ccd009 Renato Botelho
	global $config;
561
	return gentitle($title);
562 667b2b60 Ermal
}
563
564
/* update the changedesc and changecount(er) variables */
565
function update_changedesc($update) {
566
	global $changedesc;
567
	global $changecount;
568
569
	$changedesc .= " {$update}";
570
	$changecount++;
571
}
572
573 c7a3356e jim-p
function clear_log_file($logfile = "/var/log/system.log", $restart_syslogd = true) {
574 667b2b60 Ermal
	global $config, $g;
575 c7a3356e jim-p
	if ($restart_syslogd)
576
		exec("/usr/bin/killall syslogd");
577 667b2b60 Ermal
	if(isset($config['system']['disablesyslogclog'])) {
578
		unlink($logfile);
579
		touch($logfile);
580
	} else {
581 c7a3356e jim-p
		$log_size = isset($config['syslog']['logfilesize']) ? $config['syslog']['logfilesize'] : "511488";
582 96ccd009 Renato Botelho
		if(isset($config['system']['usefifolog']))
583 d31ca336 Renato Botelho
			exec("/usr/sbin/fifolog_create -s {$log_size} " . escapeshellarg($logfile));
584 667b2b60 Ermal
		else
585 2a50fd8a Renato Botelho
			exec("/usr/local/sbin/clog -i -s {$log_size} " . escapeshellarg($logfile));
586 c7a3356e jim-p
	}
587
	if ($restart_syslogd)
588
		system_syslogd_start();
589
}
590
591
function clear_all_log_files() {
592
	global $g;
593
	exec("/usr/bin/killall syslogd");
594
595
	$log_files = array("system", "filter", "dhcpd", "vpn", "pptps", "poes", "l2tps", "openvpn", "portalauth", "ipsec", "ppp", "relayd", "wireless", "lighttpd", "ntpd", "gateways", "resolver", "routing");
596
	foreach ($log_files as $lfile) {
597
		clear_log_file("{$g['varlog_path']}/{$lfile}.log", false);
598 667b2b60 Ermal
	}
599 c7a3356e jim-p
600 96ccd009 Renato Botelho
	system_syslogd_start();
601 c7a3356e jim-p
	killbyname("dhcpd");
602
	services_dhcpd_configure();
603
	return;
604 667b2b60 Ermal
}
605
606
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
607
	global $g, $config;
608
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
609
	$logarr = "";
610
	$grepline = "  ";
611
	if(is_array($grepfor))
612 7b7ad7f6 Renato Botelho
		$grepline .= " | /usr/bin/egrep " . escapeshellarg(implode("|", $grepfor));
613 667b2b60 Ermal
	if(is_array($grepinvert))
614 7b7ad7f6 Renato Botelho
		$grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert));
615 b67cdd05 Matt Smith
	if (is_dir($logfile)) {
616
		$logarr = array("File $logfile is a directory.");
617 56bd2035 jim-p
	} elseif (file_exists($logfile) && filesize($logfile) == 0) {
618 667b2b60 Ermal
		$logarr = array("Log file started.");
619
	} else {
620
		if($config['system']['disablesyslogclog']) {
621 d31ca336 Renato Botelho
			exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
622 667b2b60 Ermal
		} else {
623
			if(isset($config['system']['usefifolog']))
624 d31ca336 Renato Botelho
				exec("/usr/sbin/fifolog_reader " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
625 667b2b60 Ermal
			else
626 2a50fd8a Renato Botelho
				exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . "{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
627 667b2b60 Ermal
		}
628
	}
629
	foreach ($logarr as $logent) {
630
			$logent = preg_split("/\s+/", $logent, 6);
631
			echo "<tr valign=\"top\">\n";
632
			if ($withorig) {
633
					if(isset($config['system']['usefifolog'])) {
634
						$entry_date_time = htmlspecialchars(date("F j, Y, g:i a","" . $logent[1] . ""));
635
						$entry_text = htmlspecialchars($logent[5]);
636
					} else {
637
						$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
638 fbc723b1 jim-p
						$entry_text = ($logent[3] ==  $config['system']['hostname']) ? "" : $logent[3] . " ";
639
						$entry_text .= htmlspecialchars($logent[4] . " " . $logent[5]);
640 667b2b60 Ermal
					}
641 f326b978 Colin Fleming
					echo "<td class=\"listlr nowrap\">{$entry_date_time}</td>\n";
642 667b2b60 Ermal
					echo "<td class=\"listr\">{$entry_text}</td>\n";
643
644
			} else {
645
					echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
646
			}
647
			echo "</tr>\n";
648
	}
649
}
650
651
function return_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "", $grepreverse = false) {
652
	global $g, $config;
653
	$sor = (isset($config['syslog']['reverse']) || $grepreverse) ? "-r" : "";
654
	$logarr = "";
655
	$grepline = "  ";
656
	if(is_array($grepfor))
657 7b7ad7f6 Renato Botelho
		$grepline .= " | /usr/bin/egrep " . escapeshellarg(implode("|", $grepfor));
658 667b2b60 Ermal
	if(is_array($grepinvert))
659 7b7ad7f6 Renato Botelho
		$grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert));
660 667b2b60 Ermal
	if($config['system']['disablesyslogclog']) {
661 d31ca336 Renato Botelho
		exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
662 667b2b60 Ermal
	} else {
663
		if(isset($config['system']['usefifolog'])) {
664 d31ca336 Renato Botelho
			exec("/usr/sbin/fifolog_reader " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
665 667b2b60 Ermal
		} else {
666 2a50fd8a Renato Botelho
			exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . "{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
667 667b2b60 Ermal
		}
668
	}
669
	return($logarr);
670
}
671
672
/* Check if variable has changed, update and log if it has
673
 * returns true if var changed
674
 * varname = variable name in plain text
675
 * orig = original value
676
 * new = new value
677
 */
678
function update_if_changed($varname, & $orig, $new) {
679
	if (is_array($orig) && is_array($new)) {
680
		$a_diff = array_diff($orig, $new);
681
		foreach ($a_diff as $diff) {
682
			update_changedesc("removed {$varname}: \"{$diff}\"");
683
		}
684
		$a_diff = array_diff($new, $orig);
685
		foreach ($a_diff as $diff) {
686
			update_changedesc("added {$varname}: \"{$diff}\"");
687
		}
688
		$orig = $new;
689
		return true;
690
691
	} else {
692
		if ($orig != $new) {
693
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
694
			$orig = $new;
695
			return true;
696
		}
697
	}
698
	return false;
699
}
700
701
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
702 96ccd009 Renato Botelho
	if (isset($adr['any']))
703
		$padr = "any";
704
	else if ($adr['network'])
705
		$padr = $adr['network'];
706
	else if ($adr['address']) {
707
		list($padr, $pmask) = explode("/", $adr['address']);
708 cb2b59b8 Renato Botelho
		if (!$pmask) {
709
			if (is_ipaddrv6($padr))
710
				$pmask = 128;
711
			else
712
				$pmask = 32;
713
		}
714 96ccd009 Renato Botelho
	}
715 667b2b60 Ermal
716 96ccd009 Renato Botelho
	if (isset($adr['not']))
717
		$pnot = 1;
718
	else
719
		$pnot = 0;
720
721
	if ($adr['port']) {
722
		list($pbeginport, $pendport) = explode("-", $adr['port']);
723
		if (!$pendport)
724
			$pendport = $pbeginport;
725 667b2b60 Ermal
	} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
726
		$pbeginport = "any";
727
		$pendport = "any";
728 96ccd009 Renato Botelho
	}
729 667b2b60 Ermal
}
730
731
function pconfig_to_address(&$adr, $padr, $pmask, $pnot=false, $pbeginport=0, $pendport=0) {
732 96ccd009 Renato Botelho
	$adr = array();
733
734
	if ($padr == "any")
735
		$adr['any'] = true;
736
	else if (is_specialnet($padr))
737
		$adr['network'] = $padr;
738
	else {
739
		$adr['address'] = $padr;
740 cb2b59b8 Renato Botelho
		if (is_ipaddrv6($padr)) {
741
			if ($pmask != 128)
742
				$adr['address'] .= "/" . $pmask;
743
		} else {
744
			if ($pmask != 32)
745
				$adr['address'] .= "/" . $pmask;
746
		}
747 96ccd009 Renato Botelho
	}
748 667b2b60 Ermal
749 96ccd009 Renato Botelho
	if ($pnot)
750
		$adr['not'] = true;
751
	else
752
		unset($adr['not']);
753
754
	if (($pbeginport != 0) && ($pbeginport != "any")) {
755
		if ($pbeginport != $pendport)
756
			$adr['port'] = $pbeginport . "-" . $pendport;
757
		else
758
			$adr['port'] = $pbeginport;
759
	}
760
761
	if(is_alias($pbeginport)) {
762
		$adr['port'] = $pbeginport;
763
	}
764 667b2b60 Ermal
}
765
766
function is_specialnet($net) {
767 96ccd009 Renato Botelho
	global $specialsrcdst;
768 667b2b60 Ermal
769 96ccd009 Renato Botelho
	if(!$net)
770
		return false;
771
	if (in_array($net, $specialsrcdst))
772
		return true;
773
	else
774 667b2b60 Ermal
		return false;
775
}
776
777
//function to create widget tabs when called
778 96ccd009 Renato Botelho
function display_widget_tabs(& $tab_array) {
779 f326b978 Colin Fleming
	echo "<div id=\"tabs\">";
780 667b2b60 Ermal
	$tabscounter = 0;
781
	foreach ($tab_array as $ta) {
782
	$dashpos = strpos($ta[2],'-');
783
	$tabname = $ta[2] . "-tab";
784
	$tabclass = substr($ta[2],0,$dashpos);
785
	$tabclass = $tabclass . "-class";
786
		if ($ta[1] == true) {
787
			$tabActive = "table-cell";
788
			$tabNonActive = "none";
789 96ccd009 Renato Botelho
		}
790 667b2b60 Ermal
		else {
791
			$tabActive = "none";
792
			$tabNonActive = "table-cell";
793
		}
794 f326b978 Colin Fleming
		echo "<div id=\"{$ta[2]}-active\" class=\"{$tabclass}-tabactive\" style=\"display:{$tabActive}; background-color:#EEEEEE; color:black;\">";
795
		echo "<b>&nbsp;&nbsp;&nbsp;{$ta[0]}";
796
		echo "&nbsp;&nbsp;&nbsp;</b>";
797 667b2b60 Ermal
		echo "</div>";
798 f326b978 Colin Fleming
799
		echo "<div id=\"{$ta[2]}-deactive\" class=\"{$tabclass}-tabdeactive\" style=\"display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;\" onclick=\"return changeTabDIV('{$ta[2]}')\">";
800
		echo "<b>&nbsp;&nbsp;&nbsp;{$ta[0]}";
801
		echo "&nbsp;&nbsp;&nbsp;</b>";
802 667b2b60 Ermal
		echo "</div>";
803
	}
804 f326b978 Colin Fleming
805 667b2b60 Ermal
	echo "<script type=\"text/javascript\">";
806 3a2de75a jim-p
	echo "\n//<![CDATA[\n";
807 667b2b60 Ermal
	echo "NiftyCheck();\n";
808
	echo "Rounded(\"div.{$tabclass}-tabactive\",\"top\",\"#CCCCCC\",\"#EEEEEE\",\"smooth\");\n";
809
	echo "Rounded(\"div.{$tabclass}-tabdeactive\",\"top\",\"#CCCCCC\",\"#777777\",\"smooth\");\n";
810 3a2de75a jim-p
	echo "//]]>\n";
811 667b2b60 Ermal
	echo "</script>";
812
	echo "</div>";
813
}
814
815
816 96ccd009 Renato Botelho
// Return inline javascript file or CSS to minimizie
817 667b2b60 Ermal
// request count going back to server.
818
function outputJavaScriptFileInline($javascript) {
819
	if(file_exists($javascript)) {
820
		echo "\n<script type=\"text/javascript\">\n";
821
		include($javascript);
822
		echo "\n</script>\n";
823
	} else {
824
		echo "\n\n<!-- Could not location file:  {$javascript} -->\n\n";
825
	}
826
}
827
828
829
830
function outputCSSPrintFileInline($css) {
831
	if(file_exists($css)) {
832
		echo "\n<style media=\"print\" type=\"text/css\">\n";
833
		include($css);
834
		echo "\n</style>\n";
835
	} else {
836
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
837
	}
838
}
839
840
841
function outputCSSFileInline($css) {
842
	if(file_exists($css)) {
843
		echo "\n<style type=\"text/css\">\n";
844
		include($css);
845
		echo "\n</style>\n";
846
	} else {
847
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
848
	}
849
}
850
851
$rfc2616 = array(
852
	100 => "100 Continue",
853
	101 => "101 Switching Protocols",
854
	200 => "200 OK",
855
	201 => "201 Created",
856
	202 => "202 Accepted",
857
	203 => "203 Non-Authoritative Information",
858
	204 => "204 No Content",
859
	205 => "205 Reset Content",
860
	206 => "206 Partial Content",
861
	300 => "300 Multiple Choices",
862
	301 => "301 Moved Permanently",
863
	302 => "302 Found",
864
	303 => "303 See Other",
865
	304 => "304 Not Modified",
866
	305 => "305 Use Proxy",
867
	306 => "306 (Unused)",
868
	307 => "307 Temporary Redirect",
869
	400 => "400 Bad Request",
870
	401 => "401 Unauthorized",
871
	402 => "402 Payment Required",
872
	403 => "403 Forbidden",
873
	404 => "404 Not Found",
874
	405 => "405 Method Not Allowed",
875
	406 => "406 Not Acceptable",
876
	407 => "407 Proxy Authentication Required",
877
	408 => "408 Request Timeout",
878
	409 => "409 Conflict",
879
	410 => "410 Gone",
880
	411 => "411 Length Required",
881
	412 => "412 Precondition Failed",
882
	413 => "413 Request Entity Too Large",
883
	414 => "414 Request-URI Too Long",
884
	415 => "415 Unsupported Media Type",
885
	416 => "416 Requested Range Not Satisfiable",
886
	417 => "417 Expectation Failed",
887
	500 => "500 Internal Server Error",
888
	501 => "501 Not Implemented",
889
	502 => "502 Bad Gateway",
890
	503 => "503 Service Unavailable",
891
	504 => "504 Gateway Timeout",
892
	505 => "505 HTTP Version Not Supported"
893
);
894
895
function is_rfc2616_code($code) {
896
	global $rfc2616;
897
	if (isset($rfc2616[$code]))
898
		return true;
899
	else
900
		return false;
901
}
902
903
function print_rfc2616_select($tag, $current){
904
	global $rfc2616;
905
906
	/* Default to 200 OK if not set */
907
	if ($current == "")
908
		$current = 200;
909
910 96ccd009 Renato Botelho
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";
911 667b2b60 Ermal
	foreach($rfc2616 as $code => $message) {
912
		if ($code == $current) {
913 f326b978 Colin Fleming
			$sel = " selected=\"selected\"";
914 667b2b60 Ermal
		} else {
915
			$sel = "";
916
		}
917
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
918
	}
919 3f08e7ab Colin Fleming
	echo "</select>\n";
920 667b2b60 Ermal
}
921
922
// Useful debugging function, much cleaner than print_r
923
function echo_array($array,$return_me=false){
924 96ccd009 Renato Botelho
	if(is_array($array) == false){
925
		$return = "The provided variable is not an array.";
926
	}else{
927
		foreach($array as $name=>$value){
928
			if(is_array($value)){
929
				$return .= "";
930
				$return .= "['<b>$name</b>'] {<div style=\"margin-left:10px;\">\n";
931
				$return .= echo_array($value,true);
932
				$return .= "</div>}";
933
				$return .= "\n\n";
934
			}else{
935
				if(is_string($value)){
936
					$value = "\"$value\"";
937
				}
938
				$return .= "['<b>$name</b>'] = $value\n\n";
939
			}
940
		}
941
	}
942
	if($return_me == true){
943
		return $return;
944
	}else{
945
		echo "<pre>".$return."</pre>";
946
	}
947 667b2b60 Ermal
}
948
949
/****f* pfsense-utils/display_top_tabs
950
 * NAME
951
 *   display_top_tabs - display tabs with rounded edges
952
 * INPUTS
953
 *   $text      - array of tabs
954
 * RESULT
955
 *   null
956
 ******/
957 d413cd50 Scott Ullrich
function display_top_tabs(& $tab_array, $no_drop_down = false) {
958 96ccd009 Renato Botelho
	global $config;
959
	global $g;
960
	global $tab_array_indent;
961
	global $tab_array_space;
962
	global $tab_array_char_limit;
963
964
	/*  does the user have access to this tab?
965
	 *  master user has access to everything.
966
	 *  if the user does not have access, simply
967
	 *  unset the tab item.
968
	 */
969
970
	/* empty string code */
971
	if ($tab_array_indent == '') {
972
		$tab_array_indent = 0;
973
	}
974 620ac186 Scott Ullrich
975 96ccd009 Renato Botelho
	if ($tab_array_space == '') {
976
		$tab_array_space = 1;
977
	}
978 620ac186 Scott Ullrich
979 96ccd009 Renato Botelho
	if ($tab_array_char_limit == '') {
980
		$tab_array_char_limit = 92;
981
	}
982 667b2b60 Ermal
983 96ccd009 Renato Botelho
	foreach ($tab_array as $tab_id => $ta){
984
		if(!isAllowedPage($ta[2]))
985
			unset ($tab_array[$tab_id]);
986
	}
987 667b2b60 Ermal
988 96ccd009 Renato Botelho
	$tab_active_bg   = "#EEEEEE";
989
	$tab_inactive_bg = "#777777";
990
	$nifty_tabs_corners = "#FFF";
991
	$font_color = "white";
992
993
	/* if tabcontrols.php exist for a theme, allow it to be overriden */
994
	$themename = $config['theme'];
995
	$filename = "/usr/local/www/themes/{$themename}/tabcontrols.php";
996
	if(file_exists($filename)) {
997
		$eval_code = file_get_contents($filename);
998
		eval($eval_code);
999
	}
1000
1001
	$tabcharcount = 0;
1002
	foreach ($tab_array as $ta)
1003
		$tabcharcount = $tabcharcount + strlen($ta[0]);
1004 620ac186 Scott Ullrich
1005 96ccd009 Renato Botelho
	if($no_drop_down == true) {
1006
		$tabcharcount = 0;
1007
		unset($tab_array_char_limit);
1008
	}
1009
1010
	// If the character count of the tab names is > 670
1011
	// then show a select item dropdown menubox.
1012
	if($tabcharcount > $tab_array_char_limit) {
1013 e28307d0 Luiz Gustavo Costa
		echo gettext("Currently viewing: ");
1014 96ccd009 Renato Botelho
		echo "<select name=\"TabSelect\" onchange=\"tabs_will_go(this)\">\n";
1015
		foreach ($tab_array as $ta) {
1016
			if($ta[1]=="true")
1017
				$selected = " selected=\"selected\"";
1018
			else
1019
				$selected = "";
1020
			// Onclick in option will not work in some browser
1021
			// echo "<option onclick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
1022
			echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
1023
		}
1024
		echo "</select>\n<p>&nbsp;</p>";
1025
		echo "<script type=\"text/javascript\">";
1026
		echo "\n//<![CDATA[\n";
1027
		echo " function tabs_will_go(obj){ document.location = obj.value; }\n";
1028
		echo "//]]>\n";
1029
		echo "</script>";
1030
	}  else {
1031
		echo "<div class=\"newtabmenu\" style=\"margin:{$tab_array_space}px {$tab_array_indent}px; width:775px;\">\n";
1032
		echo "<!-- Tabbed bar code-->\n";
1033
		echo "<ul class=\"newtabmenu\">\n";
1034
		$tabscounter = 0;
1035
		foreach ($tab_array as $ta) {
1036
			if ($ta[1] == true) {
1037
				echo "  <li class=\"newtabmenu_active\"><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
1038
			} else {
1039
				echo "  <li><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
1040
			}
1041
			$tabscounter++;
1042
		}
1043
		echo "</ul>\n</div>\n";
1044
	}
1045 667b2b60 Ermal
}
1046
1047
function add_package_tabs($tabgroup, & $tab_array) {
1048 96ccd009 Renato Botelho
	global $config, $g;
1049
1050
	if(!is_array($config['installedpackages']))
1051
		return;
1052
	if(!is_array($config['installedpackages']['tab']))
1053
		return;
1054
1055
	foreach($config['installedpackages']['tab'] as $tab) {
1056
		if ($tab['group'] !== $group)
1057
			continue;
1058
		$tab_entry = array();
1059
		if($tab['name']) {
1060
			$tab_entry[] = $tab['name'];
1061
			$tab_entry[] = false;
1062
			$tab_entry[] = $tab['url'];
1063
			$tab_array[] = $tab_entry;
1064
		}
1065
	}
1066 667b2b60 Ermal
}
1067
1068 4e8854c6 Charlie Root
function alias_info_popup($alias_id){
1069 667b2b60 Ermal
	global $config;
1070 4e8854c6 Charlie Root
	$maxlength = 60;
1071
	$close_title="title='".gettext('move mouse out this alias to hide')."'";
1072
	if (is_array($config['aliases']['alias'][$alias_id])){
1073
		$alias_name=$config['aliases']['alias'][$alias_id];
1074 f326b978 Colin Fleming
		$alias_objects_with_details = "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" summary=\"alias info popup\">";
1075 4e8854c6 Charlie Root
		if ($alias_name['url']) {
1076 dd042c51 Renato Botelho
			// TODO: Change it when pf supports tables with ports
1077
			if ($alias_name['type'] == "urltable") {
1078
				exec("/sbin/pfctl -t {$alias_name['name']} -T show | wc -l", $total_entries);
1079
				$counter=preg_replace("/\D/","",$total_entries[0]);
1080
				exec("/sbin/pfctl -t {$alias_name['name']} -T show | head -10002", $alias_addresses);
1081
			} else {
1082
				$urlfn = alias_expand_urltable($alias_name['name']);
1083
				$alias_addresses = explode("\n", file_get_contents($urlfn));
1084
				$counter = count($alias_addresses);
1085
			}
1086 f326b978 Colin Fleming
			$alias_objects_with_details .= "<tr><td colspan=\"3\" $close_title class=\"vncell\">{$alias_name['url']}</td></tr>";
1087 4e8854c6 Charlie Root
			$x=0;
1088 d329d587 Darren Embry
			foreach ($alias_addresses as $alias_ports_address ) {
1089
				switch ($x) {
1090
				case 0:
1091
					$x++;
1092 f326b978 Colin Fleming
					$alias_objects_with_details .= "<tr><td $close_title class=\"vncell\" width=\"33%\" style=\"background: #FFFFFF;color: #000000;\">{$alias_ports_address}</td>";
1093 d329d587 Darren Embry
					break;
1094
				case 1:
1095
					$x++;
1096 f326b978 Colin Fleming
					$alias_objects_with_details .= "<td $close_title class=\"vncell\" width=\"33%\" style=\"background: #FFFFFF;color: #000000;\">{$alias_ports_address}</td>";
1097 d329d587 Darren Embry
					break;
1098
				default:
1099
					$x=0;
1100 f326b978 Colin Fleming
					$alias_objects_with_details .= "<td  $close_title class=\"vncell\" width=\"33%\" style=\"background: #FFFFFF;color: #000000;\">{$alias_ports_address}</td><tr>";
1101 d329d587 Darren Embry
					break;
1102 4e8854c6 Charlie Root
				}
1103
			}
1104 d329d587 Darren Embry
			for ($y = $x; $y <= $x; $y++) {
1105 f326b978 Colin Fleming
				$alias_objects_with_details .= "<td $close_title class=\"vncell\" width=\"33%\">&nbsp;</td>";
1106 d329d587 Darren Embry
			}
1107
			if ($x > 0) {
1108
				$alias_objects_with_details .= "</tr>";
1109
			}
1110
			if ($counter > 10002) {
1111 e28307d0 Luiz Gustavo Costa
				$alias_objects_with_details .= "<tr><td colspan=\"3\"> ". gettext("listing only first 10k items") . "</td><tr>";
1112 d329d587 Darren Embry
			}
1113
		}
1114 4e8854c6 Charlie Root
		else{
1115
			$alias_addresses = explode (" ", $alias_name['address']);
1116
			$alias_details = explode ("||", $alias_name['detail']);
1117 d329d587 Darren Embry
			$counter = 0;
1118
			foreach ($alias_addresses as $alias_ports_address) {
1119 f326b978 Colin Fleming
				$alias_objects_with_details .= "<tr><td $close_title width=\"5%\" class=\"vncell\" style=\"background: #FFFFFF;color: #000000;\">{$alias_addresses[$counter]}</td>";
1120 4e8854c6 Charlie Root
				$alias_detail_default = strpos ($alias_details[$counter],"Entry added");
1121
				if ($alias_details[$counter] != "" && $alias_detail_default === False)
1122 f326b978 Colin Fleming
					$alias_objects_with_details .="<td $close_title width=\"95%\" class=\"vncell\" style=\"background: #FFFFFF;color: #000000;\">{$alias_details[$counter]}</td>";
1123 4e8854c6 Charlie Root
				else
1124 f326b978 Colin Fleming
					$alias_objects_with_details .="<td $close_title width=\"95%\" class=\"vncell\" style=\"background: #FFFFFF;color: #000000;\">&nbsp;</td>";
1125 4e8854c6 Charlie Root
				$alias_objects_with_details .= "</tr>";
1126
				$counter++;
1127 d329d587 Darren Embry
			}
1128 4e8854c6 Charlie Root
		}
1129 d329d587 Darren Embry
		$alias_objects_with_details .= "</table>";
1130
	}
1131
	$alias_descr_substr = $alias_name['descr'];
1132
	if ($strlength >= $maxlength)
1133
		$alias_descr_substr = substr($alias_descr_substr, 0, $maxlength) . "...";
1134
	$item_text = ($counter > 1 ? "items" : "item");
1135 f326b978 Colin Fleming
	$alias_caption = "{$alias_descr_substr} - {$counter} {$item_text}<a href=\"/firewall_aliases_edit.php?id={$alias_id}\" title=\"".gettext('edit this alias')."\">&nbsp;&nbsp;edit </a>";
1136 d329d587 Darren Embry
	$strlength = strlen ($alias_caption);
1137
	print "<h1>{$alias_caption}</h1>" . $alias_objects_with_details;
1138 4e8854c6 Charlie Root
}
1139
1140
function rule_popup($src,$srcport,$dst,$dstport){
1141
	global $config,$g;
1142 667b2b60 Ermal
	$aliases_array = array();
1143 d329d587 Darren Embry
	if ($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias'])) {
1144 4e8854c6 Charlie Root
		$descriptions = array ();
1145 d329d587 Darren Embry
		foreach ($config['aliases']['alias'] as $alias_id=>$alias_name){
1146 133bda76 jim-p
			$loading_image="<a><img src=\'/themes/{$g['theme']}/images/misc/loader.gif\' alt=\'loader\' /> " .gettext("loading...")."</a>";
1147 d329d587 Darren Embry
			switch ($alias_name['type']){
1148
			case "port":
1149
				$width="250";
1150
				break;
1151
			case "urltable":
1152
				$width="500";
1153
				break;
1154
			default:
1155
				$width="350";
1156
				break;
1157
			}
1158 fb6c8051 jim-p
			$span_begin = "<span style=\"cursor: help;\" onmouseover=\"var response_html=domTT_activate(this, event, 'id','ttalias_{$alias_id}','content','{$loading_image}', 'trail', true, 'delay', 300, 'fade', 'both', 'fadeMax', 93, 'styleClass', 'niceTitle','type','velcro','width',{$width});alias_popup('{$alias_id}','{$g['theme']}','".gettext('loading...')."');\" onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\"><u>";
1159 c184fa27 Darren Embry
			$span_end = "</u></span>";
1160
			if ($alias_name['name'] == $src) {
1161
				$descriptions['src'] = $span_begin;
1162
				$descriptions['src_end'] = $span_end;
1163
			}
1164
			if ($alias_name['name'] == $srcport) {
1165 d329d587 Darren Embry
				$descriptions['srcport'] = $span_begin;
1166 c184fa27 Darren Embry
				$descriptions['srcport_end'] = $span_end;
1167
			}
1168
			if ($alias_name['name'] == $dst ) {
1169 d329d587 Darren Embry
				$descriptions['dst'] = $span_begin;
1170 c184fa27 Darren Embry
				$descriptions['dst_end'] = $span_end;
1171
			}
1172
			if ($alias_name['name'] == $dstport) {
1173
				$descriptions['dstport'] = $span_begin;
1174
				$descriptions['dstport_end'] = $span_end;
1175
			}
1176 d329d587 Darren Embry
		}
1177
		return $descriptions;
1178 96ccd009 Renato Botelho
	}
1179 667b2b60 Ermal
}
1180
1181 119f89c8 Phil Davis
$timezone = $config['system']['timezone'];
1182 3b49bc25 Scott Ullrich
if (!$timezone)
1183
	$timezone = "Etc/UTC";
1184
1185
date_default_timezone_set($timezone);
1186
1187 667b2b60 Ermal
?>