Project

General

Profile

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