Project

General

Profile

Download (42.3 KB) Statistics
| Branch: | Tag: | Revision:
1 d47013e1 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 d47013e1 Scott Ullrich
/*
4 f8ac4407 Phil Davis
	pkg_edit.php
5
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6
	Copyright (C) 2004-2012 Scott Ullrich <sullrich@gmail.com>
7
	All rights reserved.
8
9
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11
12
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14
15
	2. Redistributions in binary form must reproduce the above copyright
16
	   notice, this list of conditions and the following disclaimer in the
17
	   documentation and/or other materials provided with the distribution.
18
19
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29 d47013e1 Scott Ullrich
*/
30 1d333258 Scott Ullrich
/*
31
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig
32
	pfSense_MODULE:	pkgs
33
*/
34 d47013e1 Scott Ullrich
35 6b07c15a Matthew Grooms
##|+PRIV
36
##|*IDENT=page-package-edit
37
##|*NAME=Package: Edit page
38
##|*DESCR=Allow access to the 'Package: Edit' page.
39
##|*MATCH=pkg_edit.php*
40
##|-PRIV
41
42 0089af7c Scott Ullrich
ini_set('max_execution_time', '0');
43
44 7a927e67 Scott Ullrich
require("guiconfig.inc");
45
require_once("functions.inc");
46
require_once("filter.inc");
47
require_once("shaper.inc");
48 f8e335a3 Scott Ullrich
require_once("pkg-utils.inc");
49 d47013e1 Scott Ullrich
50 14db714e Scott Ullrich
/* dummy stubs needed by some code that was MFC'd */
51 f8ac4407 Phil Davis
function pfSenseHeader($location) {
52
	header("Location: " . $location);
53
}
54 14db714e Scott Ullrich
55 d47013e1 Scott Ullrich
function gentitle_pkg($pgname) {
56
	global $pfSense_config;
57
	return $pfSense_config['system']['hostname'] . "." . $pfSense_config['system']['domain'] . " - " . $pgname;
58
}
59
60 f8ac4407 Phil Davis
function domTT_title($title_msg) {
61
	if (!empty($title_msg)) {
62 6c07db48 Phil Davis
		$title_msg = preg_replace("/\s+/", " ", $title_msg);
63
		$title_msg = preg_replace("/'/", "\'", $title_msg);
64
		return "onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\" onmouseover=\"domTT_activate(this, event, 'content', '{$title_msg}', 'trail', true, 'delay', 0, 'fade', 'both', 'fadeMax', 93, 'delay', 300, 'styleClass', 'niceTitle');\"";
65 55c846c4 Marcello Coutinho
	}
66
}
67
68 d8c1a6c5 Scott Ullrich
$xml = htmlspecialchars($_GET['xml']);
69 f8ac4407 Phil Davis
if ($_POST['xml']) {
70
	$xml = htmlspecialchars($_POST['xml']);
71
}
72 d47013e1 Scott Ullrich
73 bef9f697 Renato Botelho
$xml_fullpath = realpath('/usr/local/pkg/' . $xml);
74 69eb2e29 Renato Botelho
75 bef9f697 Renato Botelho
if ($xml == "" || $xml_fullpath === false ||
76
    substr($xml_fullpath, 0, strlen('/usr/local/pkg/')) != '/usr/local/pkg/') {
77 f8ac4407 Phil Davis
	print_info_box_np(gettext("ERROR: No valid package defined."));
78
	die;
79 d47013e1 Scott Ullrich
} else {
80 f8ac4407 Phil Davis
	$pkg = parse_xml_config_pkg($xml_fullpath, "packagegui");
81 d47013e1 Scott Ullrich
}
82 7c172009 Scott Ullrich
83 f8ac4407 Phil Davis
if ($pkg['include_file'] <> "") {
84 7c172009 Scott Ullrich
	require_once($pkg['include_file']);
85
}
86
87 f8ac4407 Phil Davis
if (!isset($pkg['adddeleteeditpagefields'])) {
88 b91540da Scott Ullrich
	$only_edit = true;
89 f8ac4407 Phil Davis
} else {
90 b91540da Scott Ullrich
	$only_edit = false;
91 f8ac4407 Phil Davis
}
92 b91540da Scott Ullrich
93 a28c8b59 Scott Ullrich
$package_name = $pkg['menu'][0]['name'];
94
$section      = $pkg['menu'][0]['section'];
95 d47013e1 Scott Ullrich
$config_path  = $pkg['configpath'];
96 bb940538 Scott Ullrich
$name         = $pkg['name'];
97 b91540da Scott Ullrich
$title        = $pkg['title'];
98 96d9f5c9 Bill Marquette
$pgtitle      = $title;
99 d47013e1 Scott Ullrich
100 da7bf505 Scott Ullrich
$id = $_GET['id'];
101 f8ac4407 Phil Davis
if (isset($_POST['id'])) {
102 d8c1a6c5 Scott Ullrich
	$id = htmlspecialchars($_POST['id']);
103 f8ac4407 Phil Davis
}
104 98bcf1f8 Scott Ullrich
105 916b74c6 Scott Ullrich
// Not posting?  Then user is editing a record. There must be a valid id
106
// when editing a record.
107 f8ac4407 Phil Davis
if (!$id && !$_POST) {
108 916b74c6 Scott Ullrich
	$id = "0";
109 f8ac4407 Phil Davis
}
110 5a61331a jim-p
111 f8ac4407 Phil Davis
if (!is_numeric($id)) {
112 6f3d2063 Renato Botelho
	header("Location: /");
113 5a61331a jim-p
	exit;
114
}
115
116 f8ac4407 Phil Davis
if ($pkg['custom_php_global_functions'] <> "") {
117
	eval($pkg['custom_php_global_functions']);
118
}
119 529ffadb Bill Marquette
120 31d27c6c Scott Ullrich
// grab the installedpackages->package_name section.
121 f8ac4407 Phil Davis
if ($config['installedpackages'] && !is_array($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'])) {
122 7db8ff99 Colin Smith
	$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'] = array();
123 f8ac4407 Phil Davis
}
124 da7bf505 Scott Ullrich
125 a2a7f74d jim-p
// If the first entry in the array is an empty <config/> tag, kill it.
126 f8ac4407 Phil Davis
if ($config['installedpackages'] && (count($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']) > 0)
127
    && ($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'][0] == "")) {
128 a2a7f74d jim-p
	array_shift($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']);
129 f8ac4407 Phil Davis
}
130 a2a7f74d jim-p
131 7db8ff99 Colin Smith
$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
132 da7bf505 Scott Ullrich
133 f8ac4407 Phil Davis
if ($_GET['savemsg'] <> "") {
134 d8c1a6c5 Scott Ullrich
	$savemsg = htmlspecialchars($_GET['savemsg']);
135 f8ac4407 Phil Davis
}
136 f9a91638 Scott Ullrich
137 f8ac4407 Phil Davis
if ($pkg['custom_php_command_before_form'] <> "") {
138 194b4e0a Colin Smith
	eval($pkg['custom_php_command_before_form']);
139 f8ac4407 Phil Davis
}
140 f9a91638 Scott Ullrich
141 6483da5d Scott Ullrich
if ($_POST) {
142 2c51f293 jim-p
	$firstfield = "";
143
	$rows = 0;
144
145
	$input_errors = array();
146
	$reqfields = array();
147
	$reqfieldsn = array();
148
	foreach ($pkg['fields']['field'] as $field) {
149
		if (($field['type'] == 'input') && isset($field['required'])) {
150 f8ac4407 Phil Davis
			if ($field['fieldname']) {
151 2c51f293 jim-p
				$reqfields[] = $field['fieldname'];
152 f8ac4407 Phil Davis
			}
153
			if ($field['fielddescr']) {
154 2c51f293 jim-p
				$reqfieldsn[] = $field['fielddescr'];
155 f8ac4407 Phil Davis
			}
156 2c51f293 jim-p
		}
157
	}
158 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqfields, $reqfieldsn, $input_errors);
159 2c51f293 jim-p
160 f8ac4407 Phil Davis
	if ($pkg['custom_php_validation_command']) {
161 2c51f293 jim-p
		eval($pkg['custom_php_validation_command']);
162 f8ac4407 Phil Davis
	}
163 2c51f293 jim-p
164 f8ac4407 Phil Davis
	if ($_POST['act'] == "del") {
165
		if ($pkg['custom_delete_php_command']) {
166
			if ($pkg['custom_php_command_before_form'] <> "") {
167
				eval($pkg['custom_php_command_before_form']);
168
			}
169
			eval($pkg['custom_delete_php_command']);
170 b3235baa Scott Ullrich
		}
171 7c172009 Scott Ullrich
		write_config($pkg['delete_string']);
172 facd08f9 Scott Ullrich
		// resync the configuration file code if defined.
173 f8ac4407 Phil Davis
		if ($pkg['custom_php_resync_config_command'] <> "") {
174
			if ($pkg['custom_php_command_before_form'] <> "") {
175 86f3fc00 Scott Ullrich
				eval($pkg['custom_php_command_before_form']);
176 f8ac4407 Phil Davis
			}
177 86f3fc00 Scott Ullrich
			eval($pkg['custom_php_resync_config_command']);
178 facd08f9 Scott Ullrich
		}
179 b3235baa Scott Ullrich
	} else {
180 f8ac4407 Phil Davis
		if (!$input_errors && $pkg['custom_add_php_command']) {
181
			if ($pkg['donotsave'] <> "" or $pkg['preoutput'] <> "") {
182 12123e25 Colin Smith
			?>
183 afe4a7d3 Erik Kristensen
184 539b4c44 Colin Smith
<?php include("head.inc"); ?>
185 3eaeb703 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
186 2fe6c52b Colin Smith
<?php include("fbegin.inc"); ?>
187 fbd14b13 Scott Ullrich
<?php
188 3eaeb703 Scott Ullrich
			}
189 f8ac4407 Phil Davis
			if ($pkg['preoutput']) {
190
				echo "<pre>";
191
			}
192 3eaeb703 Scott Ullrich
			eval($pkg['custom_add_php_command']);
193 f8ac4407 Phil Davis
			if ($pkg['preoutput']) {
194
				echo "</pre>";
195
			}
196 b3235baa Scott Ullrich
		}
197 6483da5d Scott Ullrich
	}
198 e3c4b6b7 Scott Ullrich
199 eec70f21 Scott Ullrich
	// donotsave is enabled.  lets simply exit.
200 f8ac4407 Phil Davis
	if (empty($pkg['donotsave'])) {
201 2c51f293 jim-p
202 f8ac4407 Phil Davis
		// store values in xml configuration file.
203 2c51f293 jim-p
		if (!$input_errors) {
204
			$pkgarr = array();
205
			foreach ($pkg['fields']['field'] as $fields) {
206 f8ac4407 Phil Davis
				switch ($fields['type']) {
207 2c51f293 jim-p
					case "rowhelper":
208
						// save rowhelper items.
209
						#$rowhelpername=($fields['fieldname'] ? $fields['fieldname'] : "row");
210
						$rowhelpername="row";
211 f8ac4407 Phil Davis
						foreach ($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
212
							foreach ($_POST as $key => $value) {
213 6c07db48 Phil Davis
								if (preg_match("/^{$rowhelperfield['fieldname']}(\d+)$/", $key, $matches)) {
214
									$pkgarr[$rowhelpername][$matches[1]][$rowhelperfield['fieldname']] = $value;
215
								}
216 2c51f293 jim-p
							}
217 f8ac4407 Phil Davis
						}
218 2c51f293 jim-p
						break;
219
					default:
220 6c07db48 Phil Davis
						$fieldname = $fields['fieldname'];
221 2c51f293 jim-p
						if ($fieldname == "interface_array") {
222
							$fieldvalue = $_POST[$fieldname];
223
						} elseif (is_array($_POST[$fieldname])) {
224
							$fieldvalue = implode(',', $_POST[$fieldname]);
225
						} else {
226
							$fieldvalue = trim($_POST[$fieldname]);
227 f8ac4407 Phil Davis
							if ($fields['encoding'] == 'base64') {
228 2c51f293 jim-p
								$fieldvalue = base64_encode($fieldvalue);
229 f8ac4407 Phil Davis
							}
230 eec70f21 Scott Ullrich
						}
231 f8ac4407 Phil Davis
						if ($fieldname) {
232 2c51f293 jim-p
							$pkgarr[$fieldname] = $fieldvalue;
233 f8ac4407 Phil Davis
						}
234 eec70f21 Scott Ullrich
					}
235 2c51f293 jim-p
			}
236 0e730fee Scott Ullrich
237 f8ac4407 Phil Davis
			if (isset($id) && $a_pkg[$id]) {
238 2c51f293 jim-p
				$a_pkg[$id] = $pkgarr;
239 f8ac4407 Phil Davis
			} else {
240 2c51f293 jim-p
				$a_pkg[] = $pkgarr;
241 f8ac4407 Phil Davis
			}
242 0e730fee Scott Ullrich
243 2c51f293 jim-p
			write_config($pkg['addedit_string']);
244
			// late running code
245 f8ac4407 Phil Davis
			if ($pkg['custom_add_php_command_late'] <> "") {
246
				eval($pkg['custom_add_php_command_late']);
247 2c51f293 jim-p
			}
248 0e730fee Scott Ullrich
249 f8ac4407 Phil Davis
			if (isset($pkg['filter_rules_needed'])) {
250 2c51f293 jim-p
				filter_configure();
251 f8ac4407 Phil Davis
			}
252 a9b2e638 Ermal Lu?i
253 2c51f293 jim-p
			// resync the configuration file code if defined.
254 f8ac4407 Phil Davis
			if ($pkg['custom_php_resync_config_command'] <> "") {
255
				eval($pkg['custom_php_resync_config_command']);
256 2c51f293 jim-p
			}
257 facd08f9 Scott Ullrich
258 2c51f293 jim-p
			parse_package_templates();
259 dcbe6f52 Scott Ullrich
260 2c51f293 jim-p
			/* if start_command is defined, restart w/ this */
261 f8ac4407 Phil Davis
			if ($pkg['start_command'] <> "") {
262
				exec($pkg['start_command'] . ">/dev/null 2&>1");
263
			}
264 a485a6f5 Scott Ullrich
265 2c51f293 jim-p
			/* if restart_command is defined, restart w/ this */
266 f8ac4407 Phil Davis
			if ($pkg['restart_command'] <> "") {
267
				exec($pkg['restart_command'] . ">/dev/null 2&>1");
268
			}
269
270
			if ($pkg['aftersaveredirect'] <> "") {
271
				pfSenseHeader($pkg['aftersaveredirect']);
272
			} elseif (!$pkg['adddeleteeditpagefields']) {
273
				pfSenseHeader("pkg_edit.php?xml={$xml}&amp;id=0");
274
			} elseif (!$pkg['preoutput']) {
275
				pfSenseHeader("pkg.php?xml=" . $xml);
276 2c51f293 jim-p
			}
277
			exit;
278
		} else {
279
			$get_from_post = true;
280 dcbe6f52 Scott Ullrich
		}
281 2c51f293 jim-p
	} elseif (!$input_errors) {
282 0e730fee Scott Ullrich
		exit;
283 e11aa161 Warren Baker
	}
284 da7bf505 Scott Ullrich
}
285
286 f8ac4407 Phil Davis
if ($pkg['title'] <> "") {
287 6c07db48 Phil Davis
	$edit = ($only_edit ? '' : ": " . gettext("Edit"));
288 b91540da Scott Ullrich
	$title = $pkg['title'] . $edit;
289 f8ac4407 Phil Davis
} else {
290 b91540da Scott Ullrich
	$title = gettext("Package Editor");
291 f8ac4407 Phil Davis
}
292 83ddedcd Scott Ullrich
293
$pgtitle = $title;
294
295 2690afba Colin Fleming
if ($pkg['custom_php_after_head_command']) {
296
	$closehead = false;
297
	include("head.inc");
298 7c172009 Scott Ullrich
	eval($pkg['custom_php_after_head_command']);
299 2690afba Colin Fleming
	echo "</head>\n";
300 f8ac4407 Phil Davis
} else {
301 2690afba Colin Fleming
	include("head.inc");
302 f8ac4407 Phil Davis
}
303 7c172009 Scott Ullrich
304 d47013e1 Scott Ullrich
?>
305
306 cf6a1f80 Warren Baker
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
307 b89a8cbc bruno
308 befa8be0 Colin Fleming
<?php include("fbegin.inc"); ?>
309
310 6672609b Renato Botelho
<script type="text/javascript" src="/javascript/autosuggest.js?rev=1"></script>
311 b89a8cbc bruno
<script type="text/javascript" src="/javascript/suggestions.js"></script>
312
313 f8ac4407 Phil Davis
<?php if ($pkg['fields']['field'] <> "") { ?>
314 befa8be0 Colin Fleming
<script type="text/javascript">
315
//<![CDATA[
316 55c846c4 Marcello Coutinho
	//Everything inside it will load as soon as the DOM is loaded and before the page contents are loaded
317
	jQuery(document).ready(function() {
318 f8ac4407 Phil Davis
319 55c846c4 Marcello Coutinho
		//Sortable function
320
		jQuery('#mainarea table tbody').sortable({
321
			items: 'tr.sortable',
322
			cursor: 'move',
323
			distance: 10,
324
			opacity: 0.8,
325 6c07db48 Phil Davis
			helper: function(e, ui) {
326 f8ac4407 Phil Davis
				ui.children().each(function() {
327
					jQuery(this).width(jQuery(this).width());
328 55c846c4 Marcello Coutinho
				});
329 f8ac4407 Phil Davis
			return ui;
330 55c846c4 Marcello Coutinho
			},
331
		});
332 f8ac4407 Phil Davis
333 55c846c4 Marcello Coutinho
		//delete current line jQuery function
334
		jQuery('#maintable td .delete').live('click', function() {
335
			//do not remove first line
336 f8ac4407 Phil Davis
			if (jQuery("#maintable tr").length > 2) {
337 55c846c4 Marcello Coutinho
				jQuery(this).parent().parent().remove();
338 2c0dd263 Marcello Coutinho
				return false;
339
			}
340 f8ac4407 Phil Davis
		});
341
342 55c846c4 Marcello Coutinho
		//add new line jQuery function
343
		jQuery('#mainarea table .add').click(function() {
344
			//get table size and assign as new id
345
			var c_id=jQuery("#maintable tr").length;
346
			var new_row=jQuery("table#maintable tr:last").html().replace(/(name|id)="(\w+)(\d+)"/g,"$1='$2"+c_id+"'");
347
			//apply new id to created line rowhelperid
348 befa8be0 Colin Fleming
			jQuery("table#maintable tr:last").after("<tr>"+new_row+"<\/tr>");
349 2c0dd263 Marcello Coutinho
			return false;
350 f8ac4407 Phil Davis
		});
351 55c846c4 Marcello Coutinho
		// Call enablechange function
352
		enablechange();
353
	});
354
355
	function enablechange() {
356
	<?php
357
	foreach ($pkg['fields']['field'] as $field) {
358
		if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
359
			echo "\tif (jQuery('form[name=\"iform\"] input[name=\"{$field['fieldname']}\"]').prop('checked') == false) {\n";
360
361
			if (isset($field['enablefields'])) {
362
				foreach (explode(',', $field['enablefields']) as $enablefield) {
363
					echo "\t\tif (jQuery('form[name=\"iform\"] input[name=\"{$enablefield}\"]').length > 0) {\n";
364
					echo "\t\t\tjQuery('form[name=\"iform\"] input[name=\"{$enablefield}\"]').prop('disabled',true);\n";
365
					echo "\t\t}\n";
366
				}
367 dcf6d563 Manoel Carvalho
			}
368 fbd14b13 Scott Ullrich
369 55c846c4 Marcello Coutinho
			if (isset($field['checkenablefields'])) {
370
				foreach (explode(',', $field['checkenablefields']) as $checkenablefield) {
371
					echo "\t\tif (jQuery('form[name=\"iform\"] input[name=\"{$checkenablefield}\"]').length > 0) {\n";
372
					echo "\t\t\tjQuery('form[name=\"iform\"] input[name=\"{$checkenablefield}\"]').prop('checked',true);\n";
373
					echo "\t\t}\n";
374
				}
375 dcf6d563 Manoel Carvalho
			}
376 fbd14b13 Scott Ullrich
377 55c846c4 Marcello Coutinho
			echo "\t}\n\telse {\n";
378 fbd14b13 Scott Ullrich
379 55c846c4 Marcello Coutinho
			if (isset($field['enablefields'])) {
380
				foreach (explode(',', $field['enablefields']) as $enablefield) {
381
					echo "\t\tif (jQuery('form[name=\"iform\"] input[name=\"{$enablefield}\"]').length > 0) {\n";
382
					echo "\t\t\tjQuery('form[name=\"iform\"] input[name=\"{$enablefield}\"]').prop('disabled',false);\n";
383
					echo "\t\t}\n";
384
				}
385 dcf6d563 Manoel Carvalho
			}
386 fbd14b13 Scott Ullrich
387 55c846c4 Marcello Coutinho
			if (isset($field['checkenablefields'])) {
388 f8ac4407 Phil Davis
				foreach (explode(',', $field['checkenablefields']) as $checkenablefield) {
389 55c846c4 Marcello Coutinho
					echo "\t\tif (jQuery('form[name=\"iform\"] input[name=\"{$checkenablefield}\"]').length > 0) {\n";
390
					echo "\t\t\tjQuery('form[name=\"iform\"] input[name=\"{$checkenablefield}\"]').prop('checked',false);\n";
391
					echo "\t\t}\n";
392
				}
393 dcf6d563 Manoel Carvalho
			}
394 fbd14b13 Scott Ullrich
395 55c846c4 Marcello Coutinho
			echo "\t}\n";
396
		}
397 fbd14b13 Scott Ullrich
	}
398 55c846c4 Marcello Coutinho
	?>
399 f8ac4407 Phil Davis
	}
400 7c8bce79 Colin Fleming
//]]>
401 2fe6c52b Colin Smith
</script>
402
<?php } ?>
403 55c846c4 Marcello Coutinho
<script type="text/javascript" src="javascript/domTT/domLib.js"></script>
404
<script type="text/javascript" src="javascript/domTT/domTT.js"></script>
405
<script type="text/javascript" src="javascript/domTT/behaviour.js"></script>
406
<script type="text/javascript" src="javascript/domTT/fadomatic.js"></script>
407 befa8be0 Colin Fleming
<script type="text/javascript" src="/javascript/row_helper_dynamic.js"></script>
408 eec70f21 Scott Ullrich
409 7c172009 Scott Ullrich
<?php if (!empty($input_errors)) print_input_errors($input_errors); ?>
410
<form name="iform" action="pkg_edit.php" method="post">
411 2e606955 Colin Fleming
<input type="hidden" name="xml" value="<?= htmlspecialchars($xml) ?>" />
412 d47013e1 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
413 2a83d2bd Colin Fleming
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="package edit">
414 7c061036 Scott Ullrich
<?php
415
if ($pkg['tabs'] <> "") {
416 e11aa161 Warren Baker
	$tab_array = array();
417 f8ac4407 Phil Davis
	foreach ($pkg['tabs']['tab'] as $tab) {
418
		if ($tab['tab_level']) {
419 90551807 Warren Baker
			$tab_level = $tab['tab_level'];
420 f8ac4407 Phil Davis
		} else {
421 90551807 Warren Baker
			$tab_level = 1;
422 f8ac4407 Phil Davis
		}
423
		if (isset($tab['active'])) {
424 90551807 Warren Baker
			$active = true;
425
		} else {
426
			$active = false;
427
		}
428 f8ac4407 Phil Davis
		if (isset($tab['no_drop_down'])) {
429 f8c462dd Warren Baker
			$no_drop_down = true;
430 f8ac4407 Phil Davis
		}
431 90551807 Warren Baker
		$urltmp = "";
432 f8ac4407 Phil Davis
		if ($tab['url'] <> "") {
433
			$urltmp = $tab['url'];
434
		}
435
		if ($tab['xml'] <> "") {
436
			$urltmp = "pkg_edit.php?xml=" . $tab['xml'];
437
		}
438 90551807 Warren Baker
439 f8ac4407 Phil Davis
		$addresswithport = getenv("HTTP_HOST");
440 90551807 Warren Baker
		$colonpos = strpos($addresswithport, ":");
441
		if ($colonpos !== False) {
442
			//my url is actually just the IP address of the pfsense box
443
			$myurl = substr($addresswithport, 0, $colonpos);
444
		} else {
445
			$myurl = $addresswithport;
446
		}
447
		// eval url so that above $myurl item can be processed if need be.
448
		$url = str_replace('$myurl', $myurl, $urltmp);
449
450
		$tab_array[$tab_level][] = array(
451 f8ac4407 Phil Davis
			$tab['text'],
452
			$active,
453
			$url
454
		);
455
	}
456 90551807 Warren Baker
457
	ksort($tab_array);
458 f8ac4407 Phil Davis
	foreach ($tab_array as $tabid => $tab) {
459 f8c462dd Warren Baker
		echo '<tr><td>';
460 e14fbca4 Marcello Coutinho
		display_top_tabs($tab, $no_drop_down, $tabid);
461 f8c462dd Warren Baker
		echo '</td></tr>';
462 90551807 Warren Baker
	}
463 7c061036 Scott Ullrich
}
464 55c846c4 Marcello Coutinho
465 7c061036 Scott Ullrich
?>
466 2a83d2bd Colin Fleming
<tr><td><div id="mainarea"><table id="t" class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
467 e11aa161 Warren Baker
<?php
468
	$cols = 0;
469
	$savevalue = gettext("Save");
470 3b1525f9 Phil Davis
	if ($pkg['savetext'] <> "") {
471 f8ac4407 Phil Davis
		$savevalue = $pkg['savetext'];
472
	}
473
	/* If a package's XML has <advanced_options/> configured, then setup
474 e11aa161 Warren Baker
	 * the table rows for the fields that have <advancedfield/> set.
475 f8ac4407 Phil Davis
	 * These fields will be placed below other fields in a separate area titled 'Advanced Features'.
476 e11aa161 Warren Baker
	 * These advanced fields are not normally configured and generally left to default to 'default settings'.
477
	 */
478 55c846c4 Marcello Coutinho
479 e11aa161 Warren Baker
	if ($pkg['advanced_options'] == "enabled") {
480 55c846c4 Marcello Coutinho
		$adv_filed_count = 0;
481
		$advanced = "<td>&nbsp;</td>";
482 8cd558b6 ayvis
		$advanced .= "<tr><td colspan=\"2\" class=\"listtopic\">". gettext("Advanced features") . "<br /></td></tr>\n";
483 f8ac4407 Phil Davis
	}
484 e11aa161 Warren Baker
	foreach ($pkg['fields']['field'] as $pkga) {
485 f8ac4407 Phil Davis
		if ($pkga['type'] == "sorting") {
486 969a36ce Scott Ullrich
			continue;
487 f8ac4407 Phil Davis
		}
488 32487e42 Scott Ullrich
489
		if ($pkga['type'] == "listtopic") {
490 55c846c4 Marcello Coutinho
			$input = "<tr id='td_{$pkga['fieldname']}'><td>&nbsp;</td></tr>";
491 8cd558b6 ayvis
			$input .= "<tr id='tr_{$pkga['fieldname']}'><td colspan=\"2\" class=\"listtopic\">{$pkga['name']}<br /></td></tr>\n";
492 f8ac4407 Phil Davis
			if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
493 55c846c4 Marcello Coutinho
				$advanced .= $input;
494
				$adv_filed_count++;
495 f8ac4407 Phil Davis
			} else {
496 55c846c4 Marcello Coutinho
				echo $input;
497 f8ac4407 Phil Davis
			}
498 55c846c4 Marcello Coutinho
			continue;
499 e11aa161 Warren Baker
		}
500 1624b5f1 Marcello Coutinho
501 6c07db48 Phil Davis
		if ($pkga['combinefields'] == "begin") {
502 55c846c4 Marcello Coutinho
			$input="<tr valign='top' id='tr_{$pkga['fieldname']}'>";
503 f8ac4407 Phil Davis
			if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
504 55c846c4 Marcello Coutinho
				$advanced .= $input;
505 f8ac4407 Phil Davis
			} else {
506
				echo $input;
507 55c846c4 Marcello Coutinho
			}
508 f8ac4407 Phil Davis
		}
509 1624b5f1 Marcello Coutinho
510 e11aa161 Warren Baker
		$size = "";
511 26d785bb Phil Davis
		$colspan="";
512 f8ac4407 Phil Davis
		if (isset($pkga['dontdisplayname'])) {
513 55c846c4 Marcello Coutinho
			$input="";
514 8d610380 Phil Davis
			// If this is in a set of combined fields and;
515
			// - it is a "begin" (case already handled above) or
516
			// - usecolspan2 is in effect (so we want to spread all the combined fields horizontally)
517
			// then we do not want this "tr" to be inserted.
518
			// Thus only insert the "tr" if the not (!) of the above condition.
519
			if (!((isset($pkga['combinefields'])) && (($pkga['combinefields'] == "begin") || (isset($pkga['usecolspan2']))))) {
520 55c846c4 Marcello Coutinho
				$input .= "<tr valign='top' id='tr_{$pkga['fieldname']}'>";
521 f8ac4407 Phil Davis
			}
522
			if (isset($pkga['usecolspan2'])) {
523 55c846c4 Marcello Coutinho
				$colspan="colspan='2'";
524 f8ac4407 Phil Davis
			} else {
525 55c846c4 Marcello Coutinho
				$input .= "<td width='22%' class='vncell{$req}'>&nbsp;</td>";
526 f8ac4407 Phil Davis
			}
527
			if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
528 55c846c4 Marcello Coutinho
				$advanced .= $input;
529
				$adv_filed_count++;
530 f8ac4407 Phil Davis
			} else {
531 55c846c4 Marcello Coutinho
				echo $input;
532
			}
533 f8ac4407 Phil Davis
		} else if (!isset($pkga['placeonbottom'])) {
534 e11aa161 Warren Baker
			unset($req);
535 f8ac4407 Phil Davis
			if (isset($pkga['required'])) {
536 e11aa161 Warren Baker
				$req = 'req';
537 f8ac4407 Phil Davis
			}
538 b021e2c6 Phil Davis
			$input="";
539 8d610380 Phil Davis
			// If this is in a set of combined fields and;
540
			// - it is a "begin" (case already handled above) or
541
			// - usecolspan2 is in effect (so we want to spread all the combined fields horizontally)
542
			// then we do not want this "tr" to be inserted.
543
			// Thus only insert the "tr" if the not (!) of the above condition.
544
			if (!((isset($pkga['combinefields'])) && (($pkga['combinefields'] == "begin") || (isset($pkga['usecolspan2']))))) {
545 b021e2c6 Phil Davis
				$input .= "<tr>";
546
			}
547
			$input .= "<td valign='top' width=\"22%\" class=\"vncell{$req}\">";
548 55c846c4 Marcello Coutinho
			$input .= fixup_string($pkga['fielddescr']);
549
			$input .= "</td>";
550 f8ac4407 Phil Davis
			if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
551 55c846c4 Marcello Coutinho
				$advanced .= $input;
552
				$adv_filed_count++;
553 f8ac4407 Phil Davis
			} else {
554 55c846c4 Marcello Coutinho
				echo $input;
555 f8ac4407 Phil Davis
			}
556 e11aa161 Warren Baker
		}
557 6c07db48 Phil Davis
		if ($pkga['combinefields'] == "begin") {
558 b021e2c6 Phil Davis
			$input="<td class=\"vncell\"><table summary=\"advanced\"><tr>";
559 f8ac4407 Phil Davis
			if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
560 55c846c4 Marcello Coutinho
				$advanced .= $input;
561 f8ac4407 Phil Davis
			} else {
562
				echo $input;
563 55c846c4 Marcello Coutinho
			}
564 f8ac4407 Phil Davis
		}
565 1624b5f1 Marcello Coutinho
566 55c846c4 Marcello Coutinho
		$class=(isset($pkga['combinefields']) ? '' : 'class="vtable"');
567 f8ac4407 Phil Davis
		if (!isset($pkga['placeonbottom'])) {
568 55c846c4 Marcello Coutinho
			$input="<td valign='top' {$colspan} {$class}>";
569 f8ac4407 Phil Davis
			if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
570 55c846c4 Marcello Coutinho
				$advanced .= $input;
571
				$adv_filed_count++;
572 f8ac4407 Phil Davis
			} else {
573 55c846c4 Marcello Coutinho
				echo $input;
574 f8ac4407 Phil Davis
			}
575 55c846c4 Marcello Coutinho
		}
576 1624b5f1 Marcello Coutinho
577 31d27c6c Scott Ullrich
		// if user is editing a record, load in the data.
578 7c172009 Scott Ullrich
		$fieldname = $pkga['fieldname'];
579 fbd14b13 Scott Ullrich
		if ($get_from_post) {
580 7c172009 Scott Ullrich
			$value = $_POST[$fieldname];
581 f8ac4407 Phil Davis
			if (is_array($value)) {
582
				$value = implode(',', $value);
583
			}
584 e11aa161 Warren Baker
		} else {
585 f8ac4407 Phil Davis
			if (isset($id) && $a_pkg[$id]) {
586 7c172009 Scott Ullrich
				$value = $a_pkg[$id][$fieldname];
587 f8ac4407 Phil Davis
			} else {
588 b91540da Scott Ullrich
				$value = $pkga['default_value'];
589 f8ac4407 Phil Davis
			}
590 31d27c6c Scott Ullrich
		}
591 f8ac4407 Phil Davis
		switch ($pkga['type']) {
592 55c846c4 Marcello Coutinho
			case "input":
593
				$size = ($pkga['size'] ? " size='{$pkga['size']}' " : "");
594 605ae553 Renato Botelho
				$input = "<input {$size} id='{$pkga['fieldname']}' name='{$pkga['fieldname']}' class='formfld unknown' value=\"" . htmlspecialchars($value) ."\" />\n";
595 8cd558b6 ayvis
				$input .= "<br />" . fixup_string($pkga['description']) . "\n";
596 f8ac4407 Phil Davis
				if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
597 55c846c4 Marcello Coutinho
					$js_array[] = $pkga['fieldname'];
598
					$advanced .= display_advanced_field($pkga['fieldname']).$input ."</div>\n";
599 f8ac4407 Phil Davis
				} else {
600 55c846c4 Marcello Coutinho
					echo $input;
601 f8ac4407 Phil Davis
				}
602 55c846c4 Marcello Coutinho
				break;
603 1624b5f1 Marcello Coutinho
604 55c846c4 Marcello Coutinho
			case "password":
605
				$size = ($pkga['size'] ? " size='{$pkga['size']}' " : "");
606 605ae553 Renato Botelho
				$input = "<input " . $size . " id='" . $pkga['fieldname'] . "' type='password' name='" . $pkga['fieldname'] . "' class='formfld pwd' value=\"" . htmlspecialchars($value) . "\" />\n";
607 8cd558b6 ayvis
				$input .= "<br />" . fixup_string($pkga['description']) . "\n";
608 f8ac4407 Phil Davis
				if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
609 55c846c4 Marcello Coutinho
					$js_array[] = $pkga['fieldname'];
610
					$advanced .= display_advanced_field($pkga['fieldname']).$input ."</div>\n";
611 f8ac4407 Phil Davis
				} else {
612 55c846c4 Marcello Coutinho
					echo $input;
613 f8ac4407 Phil Davis
				}
614 55c846c4 Marcello Coutinho
				break;
615 1624b5f1 Marcello Coutinho
616 55c846c4 Marcello Coutinho
			case "info":
617
				$input = fixup_string($pkga['description']) . "\n";
618 f8ac4407 Phil Davis
				if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
619 55c846c4 Marcello Coutinho
					$js_array[] = $pkga['fieldname'];
620
					$advanced .= display_advanced_field($pkga['fieldname']).$input ."</div>\n";
621 f8ac4407 Phil Davis
				} else {
622 55c846c4 Marcello Coutinho
					echo $input;
623 f8ac4407 Phil Davis
				}
624 55c846c4 Marcello Coutinho
				break;
625 1624b5f1 Marcello Coutinho
626 55c846c4 Marcello Coutinho
			case "select":
627
				$fieldname = $pkga['fieldname'];
628
				if (isset($pkga['multiple'])) {
629
					$multiple = 'multiple="multiple"';
630
					$items = explode(',', $value);
631
					$fieldname .= "[]";
632
				} else {
633
					$multiple = '';
634
					$items = array($value);
635 e11aa161 Warren Baker
				}
636 55c846c4 Marcello Coutinho
				$size = ($pkga['size'] ? " size='{$pkga['size']}' " : "");
637
				$onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
638 2e606955 Colin Fleming
				$input = "<select id='" . $pkga['fieldname'] . "' $multiple $size $onchange name=\"$fieldname\">\n";
639 e11aa161 Warren Baker
				foreach ($pkga['options']['option'] as $opt) {
640 55c846c4 Marcello Coutinho
					$selected = (in_array($opt['value'], $items) ? 'selected="selected"' : '');
641 2e606955 Colin Fleming
					$input .= "\t<option value=\"{$opt['value']}\" {$selected}>{$opt['name']}</option>\n";
642 f8ac4407 Phil Davis
				}
643 55c846c4 Marcello Coutinho
				$input .= "</select>\n<br />\n" . fixup_string($pkga['description']) . "\n";
644 f8ac4407 Phil Davis
				if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
645 55c846c4 Marcello Coutinho
					$js_array[] = $pkga['fieldname'];
646
					$advanced .= display_advanced_field($pkga['fieldname']).$input;
647
					$advanced .= "</div>\n";
648 f8ac4407 Phil Davis
				} else {
649 55c846c4 Marcello Coutinho
					echo $input;
650 f8ac4407 Phil Davis
				}
651 55c846c4 Marcello Coutinho
				break;
652 1624b5f1 Marcello Coutinho
653 55c846c4 Marcello Coutinho
			case "select_source":
654
				$fieldname = $pkga['fieldname'];
655
				if (isset($pkga['multiple'])) {
656
					$multiple = 'multiple="multiple"';
657
					$items = explode(',', $value);
658
					$fieldname .= "[]";
659 e11aa161 Warren Baker
				} else {
660 55c846c4 Marcello Coutinho
					$multiple = '';
661
					$items = array($value);
662 e11aa161 Warren Baker
				}
663 55c846c4 Marcello Coutinho
				$size = (isset($pkga['size']) ? "size=\"{$pkga['size']}\"" : '');
664
				$onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
665 2e606955 Colin Fleming
				$input = "<select id='{$pkga['fieldname']}' {$multiple} {$size} {$onchange} name=\"{$fieldname}\">\n";
666 55c846c4 Marcello Coutinho
667 f8ac4407 Phil Davis
				if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
668 55c846c4 Marcello Coutinho
					$js_array[] = $pkga['fieldname'];
669
					$advanced .= display_advanced_field($pkga['fieldname']) .$input;
670
					$advanced .= "</div>\n";
671 e11aa161 Warren Baker
				} else {
672 55c846c4 Marcello Coutinho
					echo $input;
673 e11aa161 Warren Baker
				}
674 55c846c4 Marcello Coutinho
				$source_url = $pkga['source'];
675
				eval("\$pkg_source_txt = &$source_url;");
676 1624b5f1 Marcello Coutinho
				$input="";
677 504a57b2 Charlie Root
				#check if show disable option is present on xml
678 f8ac4407 Phil Davis
				if (isset($pkga['show_disable_value'])) {
679
					array_push($pkg_source_txt,
680
						array(($pkga['source_name']? $pkga['source_name'] : $pkga['name'])=> $pkga['show_disable_value'], ($pkga['source_value']? $pkga['source_value'] : $pkga['value'])=> $pkga['show_disable_value']));
681
				}
682 55c846c4 Marcello Coutinho
				foreach ($pkg_source_txt as $opt) {
683
					$source_name =($pkga['source_name']? $opt[$pkga['source_name']] : $opt[$pkga['name']]);
684
					$source_value =($pkga['source_value'] ? $opt[$pkga['source_value']] : $opt[$pkga['value']]);
685 f8ac4407 Phil Davis
					$selected = (in_array($source_value, $items)? 'selected="selected"' : '');
686 6c07db48 Phil Davis
					$input .= "\t<option value=\"{$source_value}\" $selected>{$source_name}</option>\n";
687 f8ac4407 Phil Davis
				}
688 1624b5f1 Marcello Coutinho
				$input .= "</select>\n<br />\n" . fixup_string($pkga['description']) . "\n";
689 f8ac4407 Phil Davis
				if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
690 1624b5f1 Marcello Coutinho
					$advanced .= $input;
691 f8ac4407 Phil Davis
				} else {
692 1624b5f1 Marcello Coutinho
					echo $input;
693 f8ac4407 Phil Davis
				}
694 55c846c4 Marcello Coutinho
				break;
695 1624b5f1 Marcello Coutinho
696 55c846c4 Marcello Coutinho
			case "vpn_selection" :
697
				$input = "<select id='{$pkga['fieldname']}' name='{$vpn['name']}'>\n";
698 e11aa161 Warren Baker
				foreach ($config['ipsec']['phase1'] as $vpn) {
699 55c846c4 Marcello Coutinho
					$input .= "\t<option value=\"{$vpn['descr']}\">{$vpn['descr']}</option>\n";
700 f8ac4407 Phil Davis
				}
701 55c846c4 Marcello Coutinho
				$input .= "</select>\n";
702 8cd558b6 ayvis
				$input .= "<br />" . fixup_string($pkga['description']) . "\n";
703 55c846c4 Marcello Coutinho
704 f8ac4407 Phil Davis
				if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
705 55c846c4 Marcello Coutinho
					$js_array[] = $pkga['fieldname'];
706
					$advanced .= display_advanced_field($pkga['fieldname']).$input;
707
					$advanced .= "</div>\n";
708 f8ac4407 Phil Davis
				} else {
709 55c846c4 Marcello Coutinho
					echo $input;
710 f8ac4407 Phil Davis
				}
711 55c846c4 Marcello Coutinho
				break;
712 1624b5f1 Marcello Coutinho
713 55c846c4 Marcello Coutinho
			case "checkbox":
714 2e606955 Colin Fleming
				$checkboxchecked =($value == "on" ? " checked=\"checked\"" : "");
715 cfa845a9 Luiz Gustavo Costa (gugabsd)
				$onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
716 f8ac4407 Phil Davis
				if (isset($pkga['enablefields']) || isset($pkga['checkenablefields'])) {
717 55c846c4 Marcello Coutinho
					$onclick = ' onclick="javascript:enablechange();"';
718 f8ac4407 Phil Davis
				}
719 2e606955 Colin Fleming
				$input = "<input id='{$pkga['fieldname']}' type='checkbox' name='{$pkga['fieldname']}' {$checkboxchecked} {$onclick} {$onchange} />\n";
720 8cd558b6 ayvis
				$input .= "<br />" . fixup_string($pkga['description']) . "\n";
721 55c846c4 Marcello Coutinho
722 f8ac4407 Phil Davis
				if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
723 55c846c4 Marcello Coutinho
					$js_array[] = $pkga['fieldname'];
724
					$advanced .= display_advanced_field($pkga['fieldname']).$input;
725
					$advanced .= "</div>\n";
726 f8ac4407 Phil Davis
				} else {
727 55c846c4 Marcello Coutinho
					echo $input;
728 f8ac4407 Phil Davis
				}
729 55c846c4 Marcello Coutinho
				break;
730 1624b5f1 Marcello Coutinho
731 55c846c4 Marcello Coutinho
			case "textarea":
732 f8ac4407 Phil Davis
				if ($pkga['rows']) {
733 55c846c4 Marcello Coutinho
					$rows = " rows='{$pkga['rows']}' ";
734 f8ac4407 Phil Davis
				}
735
				if ($pkga['cols']) {
736 55c846c4 Marcello Coutinho
					$cols = " cols='{$pkga['cols']}' ";
737 f8ac4407 Phil Davis
				}
738
				if (($pkga['encoding'] == 'base64') && !$get_from_post && !empty($value)) {
739 55c846c4 Marcello Coutinho
					$value = base64_decode($value);
740 f8ac4407 Phil Davis
				}
741
				$wrap =($pkga['wrap'] == "off" ? 'wrap="off" style="white-space:nowrap;"' : '');
742 55c846c4 Marcello Coutinho
				$input = "<textarea {$rows} {$cols} name='{$pkga['fieldname']}'{$wrap}>{$value}</textarea>\n";
743 8cd558b6 ayvis
				$input .= "<br />" . fixup_string($pkga['description']) . "\n";
744 f8ac4407 Phil Davis
				if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
745 55c846c4 Marcello Coutinho
					$js_array[] = $pkga['fieldname'];
746
					$advanced .= display_advanced_field($pkga['fieldname']).$input;
747
					$advanced .= "</div>\n";
748 f8ac4407 Phil Davis
				} else {
749 55c846c4 Marcello Coutinho
					echo $input;
750 f8ac4407 Phil Davis
				}
751 55c846c4 Marcello Coutinho
				break;
752 b89a8cbc bruno
753
			case "aliases":
754
				// Use xml tag <typealiases> to filter type aliases
755
				$size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
756
				$fieldname = $pkga['fieldname'];
757
				$a_aliases = &$config['aliases']['alias'];
758
				$addrisfirst = 0;
759
				$aliasesaddr = "";
760
				$value = "value='{$value}'";
761
762 f8ac4407 Phil Davis
				if (isset($a_aliases)) {
763
					if (!empty($pkga['typealiases'])) {
764
						foreach ($a_aliases as $alias) {
765
							if ($alias['type'] == $pkga['typealiases']) {
766 6c07db48 Phil Davis
								if ($addrisfirst == 1) {
767 f8ac4407 Phil Davis
									$aliasesaddr .= ",";
768
								}
769 b89a8cbc bruno
								$aliasesaddr .= "'" . $alias['name'] . "'";
770
								$addrisfirst = 1;
771
							}
772 f8ac4407 Phil Davis
						}
773 b89a8cbc bruno
					} else {
774 f8ac4407 Phil Davis
						foreach ($a_aliases as $alias) {
775
							if ($addrisfirst == 1) {
776
								$aliasesaddr .= ",";
777
							}
778 b89a8cbc bruno
							$aliasesaddr .= "'" . $alias['name'] . "'";
779
							$addrisfirst = 1;
780
						}
781
					}
782
				}
783
784 2e606955 Colin Fleming
				$input = "<input name='{$fieldname}' type='text' class='formfldalias' id='{$fieldname}' {$size} {$value} />\n<br />";
785 b89a8cbc bruno
				$input .= fixup_string($pkga['description']) . "\n";
786
787
				$script = "<script type='text/javascript'>\n";
788 8df076fe Colin Fleming
				$script .= "//<![CDATA[\n";
789 b89a8cbc bruno
				$script .= "var aliasarray = new Array({$aliasesaddr})\n";
790
				$script .= "var oTextbox1 = new AutoSuggestControl(document.getElementById('{$fieldname}'), new StateSuggestions(aliasarray))\n";
791 befa8be0 Colin Fleming
				$script .= "//]]>\n";
792 b89a8cbc bruno
				$script .= "</script>";
793
794
				echo $input;
795
				echo $script;
796 f8ac4407 Phil Davis
				break;
797 b89a8cbc bruno
798 55c846c4 Marcello Coutinho
			case "interfaces_selection":
799 6c07db48 Phil Davis
				$ips = array();
800 e14fbca4 Marcello Coutinho
				$interface_regex=(isset($pkga['hideinterfaceregex']) ? $pkga['hideinterfaceregex'] : "nointerfacestohide");
801 f8ac4407 Phil Davis
				if (is_array($config['interfaces'])) {
802
					foreach ($config['interfaces'] as $iface_key=>$iface_value) {
803 6c07db48 Phil Davis
						if (isset($iface_value['enable']) && !preg_match("/$interface_regex/", $iface_key)) {
804 2d9063af ccesario
							$iface_description=($iface_value['descr'] !="" ? strtoupper($iface_value['descr']) : strtoupper($iface_key));
805 f8ac4407 Phil Davis
							if (isset($pkga['showips'])) {
806 2d9063af ccesario
								$iface_description .= " address";
807 e14fbca4 Marcello Coutinho
							}
808 6c07db48 Phil Davis
							$ips[] = array('ip'=> $iface_key, 'description'=> $iface_description);
809 f8ac4407 Phil Davis
						}
810 e14fbca4 Marcello Coutinho
					}
811 f8ac4407 Phil Davis
				}
812
				if (is_array($config['virtualip']) && isset($pkga['showvirtualips'])) {
813
					foreach ($config['virtualip']['vip'] as $vip) {
814 6c07db48 Phil Davis
						if (!preg_match("/$interface_regex/", $vip['interface'])) {
815 f8ac4407 Phil Davis
							$vip_description=($vip['descr'] !="" ? " ({$vip['descr']}) " : " ");
816
						}
817
						switch ($vip['mode']) {
818 e14fbca4 Marcello Coutinho
							case "ipalias":
819
							case "carp":
820 6c07db48 Phil Davis
								$ips[] = array('ip' => $vip['subnet'], 'description' => "{$vip['subnet']} $vip_description");
821 e14fbca4 Marcello Coutinho
								break;
822
							case "proxyarp":
823 6c07db48 Phil Davis
								if ($vip['type'] == "network") {
824 e14fbca4 Marcello Coutinho
									$start = ip2long32(gen_subnet($vip['subnet'], $vip['subnet_bits']));
825
									$end = ip2long32(gen_subnet_max($vip['subnet'], $vip['subnet_bits']));
826
									$len = $end - $start;
827 f8ac4407 Phil Davis
									for ($i = 0; $i <= $len; $i++) {
828 6c07db48 Phil Davis
										$ips[]= array('ip' => long2ip32($start+$i), 'description' => long2ip32($start+$i)." from {$vip['subnet']}/{$vip['subnet_bits']} {$vip_description}");
829 e14fbca4 Marcello Coutinho
									}
830 f8ac4407 Phil Davis
								} else {
831 6c07db48 Phil Davis
									$ips[]= array('ip' => $vip['subnet'], 'description' => "{$vip['subnet']} $vip_description");
832 f8ac4407 Phil Davis
								}
833 e14fbca4 Marcello Coutinho
								break;
834 f8ac4407 Phil Davis
						}
835 e14fbca4 Marcello Coutinho
					}
836 f8ac4407 Phil Davis
				}
837 e14fbca4 Marcello Coutinho
				sort($ips);
838 f8ac4407 Phil Davis
				if (isset($pkga['showlistenall'])) {
839 6c07db48 Phil Davis
					array_unshift($ips, array('ip' => 'All', 'description' => 'Listen on All interfaces/ip addresses '));
840 f8ac4407 Phil Davis
				}
841 6c07db48 Phil Davis
				if (!preg_match("/$interface_regex/", "loopback")) {
842 e14fbca4 Marcello Coutinho
					$iface_description=(isset($pkga['showips']) ? "127.0.0.1 (loopback)" : "loopback");
843 6c07db48 Phil Davis
					array_push($ips, array('ip' => 'lo0', 'description' => $iface_description));
844 f8ac4407 Phil Davis
				}
845 e14fbca4 Marcello Coutinho
846
				#show interfaces array on gui
847 55c846c4 Marcello Coutinho
				$size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
848
				$multiple = '';
849
				$fieldname = $pkga['fieldname'];
850
				if (isset($pkga['multiple'])) {
851
					$fieldname .= '[]';
852 2e606955 Colin Fleming
					$multiple = 'multiple="multiple"';
853 f8ac4407 Phil Davis
				}
854 55c846c4 Marcello Coutinho
				$input = "<select id='{$pkga['fieldname']}' name=\"{$fieldname}\" {$size} {$multiple}>\n";
855 f8ac4407 Phil Davis
				if (is_array($value)) {
856 55c846c4 Marcello Coutinho
					$values = $value;
857 f8ac4407 Phil Davis
				} else {
858 6c07db48 Phil Davis
					$values = explode(',', $value);
859 f8ac4407 Phil Davis
				}
860
				foreach ($ips as $iface) {
861 2e606955 Colin Fleming
					$selected = (in_array($iface['ip'], $values) ? 'selected="selected"' : '');
862 e14fbca4 Marcello Coutinho
					$input .= "<option value=\"{$iface['ip']}\" {$selected}>{$iface['description']}</option>\n";
863 f8ac4407 Phil Davis
				}
864 e14fbca4 Marcello Coutinho
				$input .= "</select>\n<br />" . fixup_string($pkga['description']) . "\n";
865 f8ac4407 Phil Davis
				if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
866 e14fbca4 Marcello Coutinho
					$advanced .= $input;
867 f8ac4407 Phil Davis
				} else {
868 55c846c4 Marcello Coutinho
					echo $input;
869 f8ac4407 Phil Davis
				}
870 55c846c4 Marcello Coutinho
				break;
871 1624b5f1 Marcello Coutinho
872 55c846c4 Marcello Coutinho
			case "radio":
873 2e606955 Colin Fleming
				$input = "<input type='radio' id='{$pkga['fieldname']}' name='{$pkga['fieldname']}' value='{$value}' />";
874 f8ac4407 Phil Davis
				if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
875 55c846c4 Marcello Coutinho
					$advanced .= $input;
876 f8ac4407 Phil Davis
				} else {
877 55c846c4 Marcello Coutinho
					echo $input;
878 f8ac4407 Phil Davis
				}
879
				break;
880 1624b5f1 Marcello Coutinho
881 55c846c4 Marcello Coutinho
			case "button":
882 2e606955 Colin Fleming
				$input = "<input type='submit' id='{$pkga['fieldname']}' name='{$pkga['fieldname']}' class='formbtn' value='{$pkga['fieldname']}' />\n";
883 f8ac4407 Phil Davis
				if (isset($pkga['placeonbottom'])) {
884 55c846c4 Marcello Coutinho
					$pkg_buttons .= $input;
885 f8ac4407 Phil Davis
				} else {
886 91f026b0 ayvis
					echo $input ."\n<br />" . fixup_string($pkga['description']) . "\n";
887 f8ac4407 Phil Davis
				}
888 55c846c4 Marcello Coutinho
				break;
889 1624b5f1 Marcello Coutinho
890 c67b75d1 xbipin
			case "schedule_selection":
891
				$input = "<select id='{$pkga['fieldname']}' name='{$pkga['fieldname']}'>\n";
892
				$schedules = array();
893 f55ef2e7 xbipin
				$schedules[] = "none";
894 f8ac4407 Phil Davis
				if (is_array($config['schedules']['schedule'])) {
895 c67b75d1 xbipin
					foreach ($config['schedules']['schedule'] as $schedule) {
896 f8ac4407 Phil Davis
						if ($schedule['name'] <> "") {
897 c67b75d1 xbipin
							$schedules[] = $schedule['name'];
898 f8ac4407 Phil Davis
						}
899 c67b75d1 xbipin
					}
900 c6c71b36 xbipin
				}
901 f8ac4407 Phil Davis
				foreach ($schedules as $schedule) {
902 c67b75d1 xbipin
					$selected = ($value == $schedule ? "selected=\"selected\"" : "");
903 f8ac4407 Phil Davis
					if ($schedule == "none") {
904 c67b75d1 xbipin
						$input .= "<option value=\"\" {$selected}>{$schedule}</option>\n";
905 f8ac4407 Phil Davis
					} else {
906 c67b75d1 xbipin
						$input .= "<option value=\"{$schedule}\" {$selected}>{$schedule}</option>\n";
907 f8ac4407 Phil Davis
					}
908 c6c71b36 xbipin
				}
909 c67b75d1 xbipin
				$input .= "</select>\n<br />\n" . fixup_string($pkga['description']) . "\n";
910 f8ac4407 Phil Davis
				if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
911 c67b75d1 xbipin
					$js_array[] = $pkga['fieldname'];
912
					$advanced .= display_advanced_field($pkga['fieldname']).$input;
913
					$advanced .= "</div>\n";
914 f8ac4407 Phil Davis
				} else {
915 c67b75d1 xbipin
					echo $input;
916 f8ac4407 Phil Davis
				}
917 c67b75d1 xbipin
				break;
918 f8ac4407 Phil Davis
919 55c846c4 Marcello Coutinho
			case "rowhelper":
920
				#$rowhelpername=($fields['fieldname'] ? $fields['fieldname'] : "row");
921
				$rowhelpername="row";
922
				?>
923 befa8be0 Colin Fleming
				<script type="text/javascript">
924
				//<![CDATA[
925 55c846c4 Marcello Coutinho
				<?php
926
					$rowcounter = 0;
927
					$fieldcounter = 0;
928 f8ac4407 Phil Davis
					foreach ($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
929 55c846c4 Marcello Coutinho
						echo "rowname[{$fieldcounter}] = \"{$rowhelper['fieldname']}\";\n";
930
						echo "rowtype[{$fieldcounter}] = \"{$rowhelper['type']}\";\n";
931
						echo "rowsize[{$fieldcounter}] = \"{$rowhelper['size']}\";\n";
932
						$fieldcounter++;
933
					}
934
				?>
935 befa8be0 Colin Fleming
				//]]>
936 55c846c4 Marcello Coutinho
				</script>
937 2a83d2bd Colin Fleming
				<table id="maintable" summary="main table">
938 55c846c4 Marcello Coutinho
				<tr id='<?="tr_{$pkga['fieldname']}";?>'>
939
				<?php
940 f8ac4407 Phil Davis
					foreach ($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
941
						echo "<td ".domTT_title($rowhelper['description'])."><b>" . fixup_string($rowhelper['fielddescr']) . "</b></td>\n";
942 55c846c4 Marcello Coutinho
					}
943 1624b5f1 Marcello Coutinho
944 55c846c4 Marcello Coutinho
					$rowcounter = 0;
945
					$trc = 0;
946 1624b5f1 Marcello Coutinho
947 55c846c4 Marcello Coutinho
					//Use assigned $a_pkg or create an empty array to enter loop
948 f8ac4407 Phil Davis
					if (isset($a_pkg[$id][$rowhelpername])) {
949 55c846c4 Marcello Coutinho
						$saved_rows=$a_pkg[$id][$rowhelpername];
950 f8ac4407 Phil Davis
					} else {
951 6c07db48 Phil Davis
						$saved_rows[] = array();
952 f8ac4407 Phil Davis
					}
953 1624b5f1 Marcello Coutinho
954 f8ac4407 Phil Davis
					foreach ($saved_rows as $row) {
955 55c846c4 Marcello Coutinho
						echo "</tr>\n<tr class=\"sortable\" id=\"id_{$rowcounter}\">\n";
956 f8ac4407 Phil Davis
						foreach ($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
957 0c8cdb25 Warren Baker
							unset($value);
958 f8ac4407 Phil Davis
							if ($rowhelper['value'] <> "") {
959
								$value = $rowhelper['value'];
960
							}
961 31d27c6c Scott Ullrich
							$fieldname = $rowhelper['fieldname'];
962
							// if user is editing a record, load in the data.
963 bb940538 Scott Ullrich
							if (isset($id) && $a_pkg[$id]) {
964 7db8ff99 Colin Smith
								$value = $row[$fieldname];
965 bb940538 Scott Ullrich
							}
966 31d27c6c Scott Ullrich
							$options = "";
967
							$type = $rowhelper['type'];
968 55c846c4 Marcello Coutinho
							$description = $rowhelper['description'];
969 31d27c6c Scott Ullrich
							$fieldname = $rowhelper['fieldname'];
970 f8ac4407 Phil Davis
							if ($type == "option") {
971 e54626e2 Ermal Lu?i
								$options = &$rowhelper['options']['option'];
972 f8ac4407 Phil Davis
							}
973
							if ($rowhelper['size']) {
974 4c09b655 Scott Ullrich
								$size = $rowhelper['size'];
975 f8ac4407 Phil Davis
							} else if ($pkga['size']) {
976 e54626e2 Ermal Lu?i
								$size = $pkga['size'];
977 f8ac4407 Phil Davis
							} else {
978 4c09b655 Scott Ullrich
								$size = "8";
979 f8ac4407 Phil Davis
							}
980 e70e0b76 Scott Ullrich
							display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
981 1624b5f1 Marcello Coutinho
982 bb940538 Scott Ullrich
							$text = "";
983
							$trc++;
984 f8ac4407 Phil Davis
						}
985 31d27c6c Scott Ullrich
						$rowcounter++;
986
						echo "<td>";
987 befa8be0 Colin Fleming
						#echo "<a onclick=\"removeRow(this); return false;\" href=\"#\"><img border=\"0\" src=\"./themes/".$g['theme']."/images/icons/icon_x.gif\" alt=\"remove\" /></a>";
988
						echo "<a class='delete' href=\"#\"><img border='0' src='./themes/{$g['theme']}/images/icons/icon_x.gif' alt='delete' /></a>";
989 eec70f21 Scott Ullrich
						echo "</td>\n";
990 f8ac4407 Phil Davis
					}
991 55c846c4 Marcello Coutinho
				?>
992 81ecdc6c Colin Fleming
				</tr>
993 55c846c4 Marcello Coutinho
				<tbody></tbody>
994
				</table>
995 f8ac4407 Phil Davis
996 8cd558b6 ayvis
				<!-- <br /><a onclick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="./themes/<?#= $g['theme']; ?>/images/icons/icon_plus.gif" alt="add" /></a>-->
997
				<br /><a class="add" href="#"><img border="0" src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="add" /></a>
998 f8ac4407 Phil Davis
				<br /><?php if ($pkga['description'] != "") echo $pkga['description']; ?>
999 befa8be0 Colin Fleming
				<script type="text/javascript">
1000
				//<![CDATA[
1001 55c846c4 Marcello Coutinho
				field_counter_js = <?= $fieldcounter ?>;
1002
				rows = <?= $rowcounter ?>;
1003
				totalrows = <?php echo $rowcounter; ?>;
1004
				loaded = <?php echo $rowcounter; ?>;
1005
				//typesel_change();
1006 befa8be0 Colin Fleming
				//]]>
1007 55c846c4 Marcello Coutinho
				</script>
1008 f8ac4407 Phil Davis
1009 55c846c4 Marcello Coutinho
				<?php
1010
				break;
1011 f8ac4407 Phil Davis
		}
1012 55c846c4 Marcello Coutinho
		#check typehint value
1013 f8ac4407 Phil Davis
		if ($pkga['typehint']) {
1014
			echo " " . $pkga['typehint'];
1015
		}
1016
		#check combinefields options
1017
		if (isset($pkga['combinefields'])) {
1018 8d610380 Phil Davis
			// At the end of each combined-fields field we always want to end a td tag.
1019 26d785bb Phil Davis
			$input = "</td>";
1020 8d610380 Phil Davis
			// The tr tag end is used to end the whole set of combined fields,
1021
			// but also if usecolspan2 is not in effect then we also put each combined field in its own tr.
1022
			if (($pkga['combinefields'] == "end") || (!isset($pkga['usecolspan2']))) {
1023 6c07db48 Phil Davis
				$input .= "</tr>";
1024 8d610380 Phil Davis
			}
1025
			// At the end of the combined fields we finish up the table that encloses the combined fields...
1026
			if ($pkga['combinefields'] == "end") {
1027 6c07db48 Phil Davis
				$input .= "</table></td></tr>";
1028 f8ac4407 Phil Davis
			}
1029
		} else {
1030 26d785bb Phil Davis
			$input = "</td></tr>";
1031 f8ac4407 Phil Davis
			if ($pkga['usecolspan2']) {
1032 6c07db48 Phil Davis
				$input .= "</tr><br />";
1033 f8ac4407 Phil Davis
			}
1034
		}
1035
		if (isset($pkga['advancedfield']) && isset($adv_filed_count)) {
1036 55c846c4 Marcello Coutinho
			$advanced .= "{$input}\n";
1037 f8ac4407 Phil Davis
		} else {
1038 55c846c4 Marcello Coutinho
			echo "{$input}\n";
1039 f8ac4407 Phil Davis
		}
1040 55c846c4 Marcello Coutinho
		#increment counter
1041
		$i++;
1042 f8ac4407 Phil Davis
	}
1043 55c846c4 Marcello Coutinho
1044 f8ac4407 Phil Davis
	#print advanced settings if any after reading all fields
1045
	if (isset($advanced) && $adv_filed_count > 0) {
1046 55c846c4 Marcello Coutinho
		echo $advanced;
1047 f8ac4407 Phil Davis
	}
1048
1049 55c846c4 Marcello Coutinho
	?>
1050 f8ac4407 Phil Davis
	<tr>
1051
		<td>&nbsp;</td>
1052
	</tr>
1053
	<tr>
1054
		<td width="22%" valign="top">&nbsp;</td>
1055
		<td width="78%">
1056
			<div id="buttons">
1057
			<?php
1058
				if ($pkg['note'] != "") {
1059
					echo "<p><span class=\"red\"><strong>" . gettext("Note") . ":</strong></span> {$pkg['note']}</p>";
1060
				}
1061
				//if (isset($id) && $a_pkg[$id]) // We'll always have a valid ID in our hands
1062
				echo "<input name='id' type='hidden' value=\"" . htmlspecialchars($id) . "\" />";
1063
				echo "<input name='Submit' type='submit' class='formbtn' value=\"" . htmlspecialchars($savevalue) . "\" />\n{$pkg_buttons}\n";
1064
				if (!$only_edit) {
1065
					echo "<input class=\"formbtn\" type=\"button\" value=\"".gettext("Cancel")."\" onclick=\"window.location.href='" . $_SERVER['HTTP_REFERER'] . "'\" />";
1066
				}
1067
			?>
1068
			</div>
1069
		</td>
1070
	</tr>
1071 55c846c4 Marcello Coutinho
1072 e11aa161 Warren Baker
</table>
1073 098686af bcyrill
</div></td></tr>
1074 d47013e1 Scott Ullrich
</table>
1075 7c172009 Scott Ullrich
</form>
1076 7c061036 Scott Ullrich
1077 7c172009 Scott Ullrich
<?php if ($pkg['custom_php_after_form_command']) eval($pkg['custom_php_after_form_command']); ?>
1078 95736b54 Scott Ullrich
1079 e11aa161 Warren Baker
<?php
1080
	/* JavaScript to handle the advanced fields. */
1081 d92b3311 Warren Baker
	if ($pkg['advanced_options'] == "enabled") {
1082 e11aa161 Warren Baker
		echo "<script type=\"text/javascript\">\n";
1083 befa8be0 Colin Fleming
		echo "//<![CDATA[\n";
1084 f8ac4407 Phil Davis
		foreach ($js_array as $advfieldname) {
1085 e11aa161 Warren Baker
			echo "function show_" . $advfieldname . "() {\n";
1086 55c846c4 Marcello Coutinho
			echo "\tjQuery('#showadv_{$advfieldname}').empty();\n";
1087
			echo "\tjQuery('#show_{$advfieldname}').css('display', 'block');\n";
1088 e11aa161 Warren Baker
			echo "}\n\n";
1089
		}
1090 befa8be0 Colin Fleming
		echo "//]]>\n";
1091 e11aa161 Warren Baker
		echo "</script>\n";
1092
	}
1093
?>
1094
1095 d47013e1 Scott Ullrich
<?php include("fend.inc"); ?>
1096
</body>
1097
</html>
1098
1099 31d27c6c Scott Ullrich
<?php
1100
/*
1101
 * ROW Helpers function
1102
 */
1103 e70e0b76 Scott Ullrich
function display_row($trc, $value, $fieldname, $type, $rowhelper, $size) {
1104 db3829e1 Scott Ullrich
	global $text, $config;
1105 31d27c6c Scott Ullrich
	echo "<td>\n";
1106 f8ac4407 Phil Davis
	switch ($type) {
1107 55c846c4 Marcello Coutinho
		case "input":
1108 605ae553 Renato Botelho
			echo "<input size='{$size}' name='{$fieldname}{$trc}' id='{$fieldname}{$trc}' class='formfld unknown' value=\"" . htmlspecialchars($value) . "\" />\n";
1109 55c846c4 Marcello Coutinho
			break;
1110
		case "checkbox":
1111 2e606955 Colin Fleming
			echo "<input size='{$size}' type='checkbox' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' value='ON' ".($value?"CHECKED":"")." />\n";
1112 55c846c4 Marcello Coutinho
			break;
1113
		case "password":
1114 605ae553 Renato Botelho
			echo "<input size='{$size}' type='password' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' class='formfld pwd' value=\"" . htmlspecialchars($value) . "\" />\n";
1115 55c846c4 Marcello Coutinho
			break;
1116
		case "textarea":
1117
			echo "<textarea rows='2' cols='12' id='{$fieldname}{$trc}' class='formfld unknown' name='{$fieldname}{$trc}'>{$value}</textarea>\n";
1118
		case "select":
1119 6c07db48 Phil Davis
			echo "<select style='height:22px;' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' {$title}>\n";
1120 f8ac4407 Phil Davis
			foreach ($rowhelper['options']['option'] as $rowopt) {
1121 55c846c4 Marcello Coutinho
				$text .= "<option value='{$rowopt['value']}'>{$rowopt['name']}</option>";
1122 2e606955 Colin Fleming
				echo "<option value='{$rowopt['value']}'".($rowopt['value'] == $value?" selected=\"selected\"":"").">{$rowopt['name']}</option>\n";
1123 f8ac4407 Phil Davis
			}
1124 55c846c4 Marcello Coutinho
			echo "</select>\n";
1125
			break;
1126
		case "interfaces_selection":
1127 85a46fbd whizkidzz
			$size = ($size ? "size=\"{$size}\"" : '');
1128
			$multiple = '';
1129
			if (isset($rowhelper['multiple'])) {
1130
				$fieldname .= '[]';
1131 5655d48b Colin Fleming
				$multiple = "multiple=\"multiple\"";
1132 85a46fbd whizkidzz
			}
1133 504a57b2 Charlie Root
			echo "<select style='height:22px;' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' {$size} {$multiple}>\n";
1134 85a46fbd whizkidzz
			$ifaces = get_configured_interface_with_descr();
1135
			$additional_ifaces = $rowhelper['add_to_interfaces_selection'];
1136 f8ac4407 Phil Davis
			if (!empty($additional_ifaces)) {
1137 85a46fbd whizkidzz
				$ifaces = array_merge($ifaces, explode(',', $additional_ifaces));
1138 f8ac4407 Phil Davis
			}
1139
			if (is_array($value)) {
1140 85a46fbd whizkidzz
				$values = $value;
1141 f8ac4407 Phil Davis
			} else {
1142 6c07db48 Phil Davis
				$values = explode(',', $value);
1143 f8ac4407 Phil Davis
			}
1144 85a46fbd whizkidzz
			$ifaces["lo0"] = "loopback";
1145
			echo "<option><name></name><value></value></option>/n";
1146 f8ac4407 Phil Davis
			foreach ($ifaces as $ifname => $iface) {
1147 5655d48b Colin Fleming
				$text .="<option value=\"{$ifname}\">$iface</option>";
1148 2e606955 Colin Fleming
				echo "<option value=\"{$ifname}\" ".(in_array($ifname, $values) ? 'selected="selected"' : '').">{$iface}</option>\n";
1149 f8ac4407 Phil Davis
			}
1150 85a46fbd whizkidzz
			echo "</select>\n";
1151 55c846c4 Marcello Coutinho
			break;
1152
		case "select_source":
1153 504a57b2 Charlie Root
			echo "<select style='height:22px;' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}'>\n";
1154 f8ac4407 Phil Davis
			if (isset($rowhelper['show_disable_value'])) {
1155 504a57b2 Charlie Root
				echo "<option value='{$rowhelper['show_disable_value']}'>{$rowhelper['show_disable_value']}</option>\n";
1156 f8ac4407 Phil Davis
			}
1157 55c846c4 Marcello Coutinho
			$source_url = $rowhelper['source'];
1158
			eval("\$pkg_source_txt = &$source_url;");
1159 f8ac4407 Phil Davis
			foreach ($pkg_source_txt as $opt) {
1160 55c846c4 Marcello Coutinho
				$source_name = ($rowhelper['source_name'] ? $opt[$rowhelper['source_name']] : $opt[$rowhelper['name']]);
1161
				$source_value = ($rowhelper['source_value'] ? $opt[$rowhelper['source_value']] : $opt[$rowhelper['value']]);
1162
				$text .= "<option value='{$source_value}'>{$source_name}</option>";
1163 2e606955 Colin Fleming
				echo "<option value='{$source_value}'".($source_value == $value?" selected=\"selected\"":"").">{$source_name}</option>\n";
1164 f8ac4407 Phil Davis
			}
1165 55c846c4 Marcello Coutinho
			echo "</select>\n";
1166 f8ac4407 Phil Davis
			break;
1167
	}
1168 8612c539 Colin Fleming
	echo "</td>\n";
1169 31d27c6c Scott Ullrich
}
1170
1171 d51f86e0 Scott Ullrich
function fixup_string($string) {
1172 d2133701 Scott Ullrich
	global $config;
1173 d51f86e0 Scott Ullrich
	// fixup #1: $myurl -> http[s]://ip_address:port/
1174
	$https = "";
1175
	$port = $config['system']['webguiport'];
1176 f8ac4407 Phil Davis
	if ($port <> "443" and $port <> "80") {
1177 63637de9 Bill Marquette
		$urlport = ":" . $port;
1178 f8ac4407 Phil Davis
	} else {
1179 63637de9 Bill Marquette
		$urlport = "";
1180 f8ac4407 Phil Davis
	}
1181 3c616886 Scott Ullrich
1182 f8ac4407 Phil Davis
	if ($config['system']['webgui']['protocol'] == "https") {
1183
		$https = "s";
1184
	}
1185 63637de9 Bill Marquette
	$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlport;
1186 d51f86e0 Scott Ullrich
	$newstring = str_replace("\$myurl", $myurl, $string);
1187 d2133701 Scott Ullrich
	$string = $newstring;
1188
	// fixup #2: $wanip
1189 85a5da13 Ermal Luçi
	$curwanip = get_interface_ip();
1190 d2133701 Scott Ullrich
	$newstring = str_replace("\$wanip", $curwanip, $string);
1191
	$string = $newstring;
1192
	// fixup #3: $lanip
1193
	$lancfg = $config['interfaces']['lan'];
1194
	$lanip = $lancfg['ipaddr'];
1195
	$newstring = str_replace("\$lanip", $lanip, $string);
1196
	$string = $newstring;
1197
	// fixup #4: fix'r'up here.
1198 d51f86e0 Scott Ullrich
	return $newstring;
1199
}
1200
1201 dcbe6f52 Scott Ullrich
/*
1202
 *  Parse templates if they are defined
1203
 */
1204
function parse_package_templates() {
1205
	global $pkg, $config;
1206 767a716e Scott Ullrich
	$rows = 0;
1207 f8ac4407 Phil Davis
	if ($pkg['templates']['template'] <> "") {
1208
		foreach ($pkg['templates']['template'] as $pkg_template_row) {
1209 55c846c4 Marcello Coutinho
			$filename = $pkg_template_row['filename'];
1210
			$template_text = $pkg_template_row['templatecontents'];
1211
			$firstfield = "";
1212
			/* calculate total row helpers count and */
1213
			/* change fields defined as fieldname_fieldvalue to their value */
1214
			foreach ($pkg['fields']['field'] as $fields) {
1215 f8ac4407 Phil Davis
				switch ($fields['type']) {
1216 55c846c4 Marcello Coutinho
					case "rowhelper":
1217 f8ac4407 Phil Davis
						// save rowhelper items.
1218
						$row_helper_total_rows = 0;
1219
						$row_helper_data = "";
1220
						foreach ($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
1221
							foreach ($_POST as $key => $value) {
1222 6c07db48 Phil Davis
								if (preg_match("/^{$rowhelperfield['fieldname']}(\d+)$/", $key, $matches)) {
1223 f8ac4407 Phil Davis
									$row_helper_total_rows++;
1224
									$row_helper_data .= $value;
1225
									$sep = "";
1226
									ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
1227
									foreach ($sep as $se) {
1228
										$separator = $se;
1229
									}
1230
									if ($separator <> "") {
1231
										$row_helper_data = ereg_replace("  ", $separator, $row_helper_data);
1232
										$template_text = ereg_replace("\[{$separator}\]", "", $template_text);
1233 55c846c4 Marcello Coutinho
									}
1234 f8ac4407 Phil Davis
									$template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
1235 55c846c4 Marcello Coutinho
								}
1236
							}
1237 f8ac4407 Phil Davis
						}
1238
						break;
1239
					default:
1240 6c07db48 Phil Davis
						$fieldname = $fields['fieldname'];
1241 f8ac4407 Phil Davis
						$fieldvalue = $_POST[$fieldname];
1242
						$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
1243 dcbe6f52 Scott Ullrich
				}
1244
			}
1245 f8ac4407 Phil Davis
			/* replace $domain_total_rows with total rows */
1246
			$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
1247 1624b5f1 Marcello Coutinho
1248 f8ac4407 Phil Davis
			/* replace cr's */
1249
			$template_text = str_replace("\\n", "\n", $template_text);
1250 dcbe6f52 Scott Ullrich
1251 f8ac4407 Phil Davis
			/* write out new template file */
1252 6c07db48 Phil Davis
			$fout = fopen($filename, "w");
1253 f8ac4407 Phil Davis
			fwrite($fout, $template_text);
1254
			fclose($fout);
1255
		}
1256
	}
1257 dcbe6f52 Scott Ullrich
}
1258
1259 e11aa161 Warren Baker
/* Return html div fields */
1260
function display_advanced_field($fieldname) {
1261 55c846c4 Marcello Coutinho
	$div = "<div id='showadv_{$fieldname}'>\n";
1262 2e606955 Colin Fleming
	$div .= "<input type='button' onclick='show_{$fieldname}()' value='" . gettext("Advanced") . "' /> - " . gettext("Show advanced option") ."</div>\n";
1263 55c846c4 Marcello Coutinho
	$div .= "<div id='show_{$fieldname}' style='display:none'>\n";
1264 e11aa161 Warren Baker
	return $div;
1265
}
1266
1267 b89a8cbc bruno
?>