Project

General

Profile

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