Project

General

Profile

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