Project

General

Profile

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