Project

General

Profile

Download (39 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 da95bdcd Renato Botelho
				$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 da95bdcd Renato Botelho
				$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 f82cbe49 Marcello Coutinho
							$iface_description=($iface_value['descr'] !="" ? strtoupper($iface_value['descr']) : strtoupper($iface_key));
723
							if (isset($pkga['showips']))
724
								$iface_description .= " address";
725 e14fbca4 Marcello Coutinho
							$ips[]=array('ip'=> $iface_key, 'description'=> $iface_description);
726
							}
727
					}
728
				if (is_array($config['virtualip']) && isset($pkga['showvirtualips']))
729
					foreach ($config['virtualip']['vip'] as $vip){
730
						if (! preg_match("/$interface_regex/",$vip['interface']))
731
						$vip_description=($vip['descr'] !="" ? " ({$vip['descr']}) " : " ");
732
						  switch ($vip['mode']){
733
							case "ipalias":
734
							case "carp":
735
									$ips[]=array(   'ip'=> $vip['subnet'],'description' => "{$vip['subnet']} $vip_description");
736
								break;
737
							case "proxyarp":
738
								if ($vip['type']=="network"){
739
									$start = ip2long32(gen_subnet($vip['subnet'], $vip['subnet_bits']));
740
									$end = ip2long32(gen_subnet_max($vip['subnet'], $vip['subnet_bits']));
741
									$len = $end - $start;
742
									for ($i = 0; $i <= $len; $i++)
743
										$ips[]= array('ip'=>long2ip32($start+$i),'description'=> long2ip32($start+$i)." from {$vip['subnet']}/{$vip['subnet_bits']} {$vip_description}");
744
									}
745
								else{
746
									$ips[]= array('ip'=>$vip['subnet'],'description'=> "{$vip['subnet']} $vip_description");
747
									}
748
								break;
749
							}
750
					}
751
				sort($ips);
752
				if (isset($pkga['showlistenall']))
753
					array_unshift($ips,array('ip'=> 'All', 'description'=> 'Listen on All interfaces/ip addresses '));
754
				if (! preg_match("/$interface_regex/","loopback")){
755
					$iface_description=(isset($pkga['showips']) ? "127.0.0.1 (loopback)" : "loopback");
756
					array_push($ips,array('ip'=> 'lo0', 'description'=> $iface_description));
757
					}
758
759
				#show interfaces array on gui
760 55c846c4 Marcello Coutinho
				$size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
761
				$multiple = '';
762
				$fieldname = $pkga['fieldname'];
763
				if (isset($pkga['multiple'])) {
764
					$fieldname .= '[]';
765 2e606955 Colin Fleming
					$multiple = 'multiple="multiple"';
766 e14fbca4 Marcello Coutinho
					}
767 55c846c4 Marcello Coutinho
				$input = "<select id='{$pkga['fieldname']}' name=\"{$fieldname}\" {$size} {$multiple}>\n";
768
				if(is_array($value))
769
					$values = $value;
770 e11aa161 Warren Baker
				else
771 55c846c4 Marcello Coutinho
					$values  =  explode(',',  $value);
772 e14fbca4 Marcello Coutinho
				foreach($ips as $iface){
773 2e606955 Colin Fleming
					$selected = (in_array($iface['ip'], $values) ? 'selected="selected"' : '');
774 e14fbca4 Marcello Coutinho
					$input .= "<option value=\"{$iface['ip']}\" {$selected}>{$iface['description']}</option>\n";
775
					}
776
				$input .= "</select>\n<br />" . fixup_string($pkga['description']) . "\n";
777 55c846c4 Marcello Coutinho
				if(isset($pkga['advancedfield']) && isset($adv_filed_count))
778 e14fbca4 Marcello Coutinho
					$advanced .= $input;
779 55c846c4 Marcello Coutinho
				else
780
					echo $input;
781
				break;
782 1624b5f1 Marcello Coutinho
783 55c846c4 Marcello Coutinho
			case "radio":
784 2e606955 Colin Fleming
				$input = "<input type='radio' id='{$pkga['fieldname']}' name='{$pkga['fieldname']}' value='{$value}' />";
785 55c846c4 Marcello Coutinho
				if(isset($pkga['advancedfield']) && isset($adv_filed_count))
786
					$advanced .= $input;
787
				else
788
					echo $input;
789
					break;
790 1624b5f1 Marcello Coutinho
791 55c846c4 Marcello Coutinho
			case "button":
792 2e606955 Colin Fleming
				$input = "<input type='submit' id='{$pkga['fieldname']}' name='{$pkga['fieldname']}' class='formbtn' value='{$pkga['fieldname']}' />\n";
793 55c846c4 Marcello Coutinho
				if(isset($pkga['placeonbottom']))
794
					$pkg_buttons .= $input;
795
				else
796 befa8be0 Colin Fleming
					echo $input ."\n<br/>" . fixup_string($pkga['description']) . "\n";;
797 55c846c4 Marcello Coutinho
				break;
798 1624b5f1 Marcello Coutinho
799 55c846c4 Marcello Coutinho
			case "rowhelper":
800
				#$rowhelpername=($fields['fieldname'] ? $fields['fieldname'] : "row");
801
				$rowhelpername="row";
802
				?>
803 befa8be0 Colin Fleming
				<script type="text/javascript">
804
				//<![CDATA[
805 55c846c4 Marcello Coutinho
				<?php
806
					$rowcounter = 0;
807
					$fieldcounter = 0;
808
					foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
809
						echo "rowname[{$fieldcounter}] = \"{$rowhelper['fieldname']}\";\n";
810
						echo "rowtype[{$fieldcounter}] = \"{$rowhelper['type']}\";\n";
811
						echo "rowsize[{$fieldcounter}] = \"{$rowhelper['size']}\";\n";
812
						$fieldcounter++;
813
					}
814
				?>
815 befa8be0 Colin Fleming
				//]]>
816 55c846c4 Marcello Coutinho
				</script>
817 2a83d2bd Colin Fleming
				<table id="maintable" summary="main table">
818 55c846c4 Marcello Coutinho
				<tr id='<?="tr_{$pkga['fieldname']}";?>'>
819
				<?php
820
					foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
821 8612c539 Colin Fleming
					  echo "<td ".domTT_title($rowhelper['description'])."><b>" . fixup_string($rowhelper['fielddescr']) . "</b></td>\n";
822 55c846c4 Marcello Coutinho
					}
823 1624b5f1 Marcello Coutinho
824 55c846c4 Marcello Coutinho
					$rowcounter = 0;
825
					$trc = 0;
826 1624b5f1 Marcello Coutinho
827 55c846c4 Marcello Coutinho
					//Use assigned $a_pkg or create an empty array to enter loop
828
					if(isset($a_pkg[$id][$rowhelpername]))
829
						$saved_rows=$a_pkg[$id][$rowhelpername];
830
					else
831
						$saved_rows[]=array();
832 1624b5f1 Marcello Coutinho
833 55c846c4 Marcello Coutinho
					foreach($saved_rows as $row) {
834
						echo "</tr>\n<tr class=\"sortable\" id=\"id_{$rowcounter}\">\n";
835 31d27c6c Scott Ullrich
						foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
836 0c8cdb25 Warren Baker
							unset($value);
837 31d27c6c Scott Ullrich
							if($rowhelper['value'] <> "") $value = $rowhelper['value'];
838
							$fieldname = $rowhelper['fieldname'];
839
							// if user is editing a record, load in the data.
840 bb940538 Scott Ullrich
							if (isset($id) && $a_pkg[$id]) {
841 7db8ff99 Colin Smith
								$value = $row[$fieldname];
842 bb940538 Scott Ullrich
							}
843 31d27c6c Scott Ullrich
							$options = "";
844
							$type = $rowhelper['type'];
845 55c846c4 Marcello Coutinho
							$description = $rowhelper['description'];
846 31d27c6c Scott Ullrich
							$fieldname = $rowhelper['fieldname'];
847 e54626e2 Ermal Lu?i
							if($type == "option")
848
								$options = &$rowhelper['options']['option'];
849 7e542bd1 Scott Ullrich
							if($rowhelper['size']) 
850 4c09b655 Scott Ullrich
								$size = $rowhelper['size'];
851 e54626e2 Ermal Lu?i
							else if ($pkga['size'])
852
								$size = $pkga['size'];
853 4c09b655 Scott Ullrich
							else
854
								$size = "8";
855 e70e0b76 Scott Ullrich
							display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
856 1624b5f1 Marcello Coutinho
857 bb940538 Scott Ullrich
							$text = "";
858
							$trc++;
859 55c846c4 Marcello Coutinho
							}
860 31d27c6c Scott Ullrich
						$rowcounter++;
861
						echo "<td>";
862 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>";
863
						echo "<a class='delete' href=\"#\"><img border='0' src='./themes/{$g['theme']}/images/icons/icon_x.gif' alt='delete' /></a>";
864 eec70f21 Scott Ullrich
						echo "</td>\n";
865 55c846c4 Marcello Coutinho
						}
866
				?>
867 81ecdc6c Colin Fleming
				</tr>
868 55c846c4 Marcello Coutinho
				<tbody></tbody>
869
				</table>
870
	
871 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>-->
872 befa8be0 Colin Fleming
				<br/><a class="add" href="#"><img border="0" src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="add" /></a>
873
				<br/><?php if($pkga['description'] != "") echo $pkga['description']; ?>
874
				<script type="text/javascript">
875
				//<![CDATA[
876 55c846c4 Marcello Coutinho
				field_counter_js = <?= $fieldcounter ?>;
877
				rows = <?= $rowcounter ?>;
878
				totalrows = <?php echo $rowcounter; ?>;
879
				loaded = <?php echo $rowcounter; ?>;
880
				//typesel_change();
881 befa8be0 Colin Fleming
				//]]>
882 55c846c4 Marcello Coutinho
				</script>
883
		
884
				<?php
885
				break;
886
		    }
887
		#check typehint value
888
	   	if($pkga['typehint'])
889
	   		echo " " . $pkga['typehint'];
890
	   	#check combinefields options
891
     	if (isset($pkga['combinefields'])){
892
     		$input="</td>";
893
			if ($pkga['combinefields']=="end")
894
           		$input.="</table></td></tr>";
895
      		}
896
     	else{
897
			$input= "</td></tr>";
898
			if($pkga['usecolspan2'])
899 befa8be0 Colin Fleming
				$input.= "</tr><br/>";
900 55c846c4 Marcello Coutinho
	     	}
901
   	 	if(isset($pkga['advancedfield']) && isset($adv_filed_count))
902
			$advanced .= "{$input}\n";
903
		else
904
			echo "{$input}\n";
905
		#increment counter
906
		$i++;
907
  		}
908
909
  	#print advanced settings if any after reading all fields
910
	if (isset($advanced) && $adv_filed_count > 0)
911
		echo $advanced;
912
  
913
	?>
914 b6e87566 Scott Ullrich
  <tr>
915
	<td>&nbsp;</td>
916
  </tr>
917 d47013e1 Scott Ullrich
  <tr>
918
    <td width="22%" valign="top">&nbsp;</td>
919
    <td width="78%">
920 2e606955 Colin Fleming
    <div id="buttons">
921 55c846c4 Marcello Coutinho
		<?php
922
		if($pkg['note'] != ""){
923
			echo "<p><span class=\"red\"><strong>" . gettext("Note") . ":</strong></span> {$pkg['note']}</p>";
924
			}
925
		//if (isset($id) && $a_pkg[$id]) // We'll always have a valid ID in our hands
926 da95bdcd Renato Botelho
		echo "<input name='id' type='hidden' value=\"" . htmlspecialchars($id) . "\" />";
927
		echo "<input name='Submit' type='submit' class='formbtn' value=\"" . htmlspecialchars($savevalue) . "\" />\n{$pkg_buttons}\n";
928 55c846c4 Marcello Coutinho
		if (!$only_edit){
929 2e606955 Colin Fleming
			echo "<input class='formbtn' type='button' value='".gettext("Cancel")."' onclick='history.back()' />";
930 55c846c4 Marcello Coutinho
			}
931
		?>
932
	</div>
933 d47013e1 Scott Ullrich
    </td>
934
  </tr>
935 55c846c4 Marcello Coutinho
936 e11aa161 Warren Baker
</table>
937 098686af bcyrill
</div></td></tr>
938 d47013e1 Scott Ullrich
</table>
939 7c172009 Scott Ullrich
</form>
940 7c061036 Scott Ullrich
941 7c172009 Scott Ullrich
<?php if ($pkg['custom_php_after_form_command']) eval($pkg['custom_php_after_form_command']); ?>
942 95736b54 Scott Ullrich
943 e11aa161 Warren Baker
<?php
944
	/* JavaScript to handle the advanced fields. */
945 d92b3311 Warren Baker
	if ($pkg['advanced_options'] == "enabled") {
946 e11aa161 Warren Baker
		echo "<script type=\"text/javascript\">\n";
947 befa8be0 Colin Fleming
		echo "//<![CDATA[\n";
948 e11aa161 Warren Baker
		foreach($js_array as $advfieldname) {
949
			echo "function show_" . $advfieldname . "() {\n";
950 55c846c4 Marcello Coutinho
			echo "\tjQuery('#showadv_{$advfieldname}').empty();\n";
951
			echo "\tjQuery('#show_{$advfieldname}').css('display', 'block');\n";
952 e11aa161 Warren Baker
			echo "}\n\n";
953
		}
954 befa8be0 Colin Fleming
		echo "//]]>\n";
955 e11aa161 Warren Baker
		echo "</script>\n";
956
	}
957
?>
958
959 d47013e1 Scott Ullrich
<?php include("fend.inc"); ?>
960
</body>
961
</html>
962
963 31d27c6c Scott Ullrich
<?php
964
/*
965
 * ROW Helpers function
966
 */
967 e70e0b76 Scott Ullrich
function display_row($trc, $value, $fieldname, $type, $rowhelper, $size) {
968 db3829e1 Scott Ullrich
	global $text, $config;
969 31d27c6c Scott Ullrich
	echo "<td>\n";
970 55c846c4 Marcello Coutinho
	switch($type){
971
		case "input":
972 da95bdcd Renato Botelho
			echo "<input size='{$size}' name='{$fieldname}{$trc}' id='{$fieldname}{$trc}' class='formfld unknown' value=\"" . htmlspecialchars($value) . "\" />\n";
973 55c846c4 Marcello Coutinho
			break;
974
		case "checkbox":
975 2e606955 Colin Fleming
			echo "<input size='{$size}' type='checkbox' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' value='ON' ".($value?"CHECKED":"")." />\n";
976 55c846c4 Marcello Coutinho
			break;
977
		case "password":
978 da95bdcd Renato Botelho
			echo "<input size='{$size}' type='password' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' class='formfld pwd' value=\"" . htmlspecialchars($value) . "\" />\n";
979 55c846c4 Marcello Coutinho
			break;
980
		case "textarea":
981
			echo "<textarea rows='2' cols='12' id='{$fieldname}{$trc}' class='formfld unknown' name='{$fieldname}{$trc}'>{$value}</textarea>\n";
982
		case "select":
983
			echo "<select style='height:22px;'  id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' {$title}>\n";
984
			foreach($rowhelper['options']['option'] as $rowopt) {
985
				$text .= "<option value='{$rowopt['value']}'>{$rowopt['name']}</option>";
986 2e606955 Colin Fleming
				echo "<option value='{$rowopt['value']}'".($rowopt['value'] == $value?" selected=\"selected\"":"").">{$rowopt['name']}</option>\n";
987 55c846c4 Marcello Coutinho
				}
988
			echo "</select>\n";
989
			break;
990
		case "interfaces_selection":
991 85a46fbd whizkidzz
			$size = ($size ? "size=\"{$size}\"" : '');
992
			$multiple = '';
993
			if (isset($rowhelper['multiple'])) {
994
				$fieldname .= '[]';
995 2e606955 Colin Fleming
				$multiple = 'multiple="multiple';
996 85a46fbd whizkidzz
			}
997 504a57b2 Charlie Root
			echo "<select style='height:22px;' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' {$size} {$multiple}>\n";
998 85a46fbd whizkidzz
			$ifaces = get_configured_interface_with_descr();
999
			$additional_ifaces = $rowhelper['add_to_interfaces_selection'];
1000
			if (!empty($additional_ifaces))
1001
				$ifaces = array_merge($ifaces, explode(',', $additional_ifaces));
1002
			if(is_array($value))
1003
				$values = $value;
1004
			else
1005
				$values  =  explode(',',  $value);
1006
			$ifaces["lo0"] = "loopback";
1007
			echo "<option><name></name><value></value></option>/n";
1008
			foreach($ifaces as $ifname => $iface) {
1009
				$text .="<option value=\\\"$ifname\\\">$iface</option>";
1010 2e606955 Colin Fleming
				echo "<option value=\"{$ifname}\" ".(in_array($ifname, $values) ? 'selected="selected"' : '').">{$iface}</option>\n";
1011 55c846c4 Marcello Coutinho
				}
1012 85a46fbd whizkidzz
			echo "</select>\n";
1013 55c846c4 Marcello Coutinho
			break;
1014
		case "select_source":
1015 504a57b2 Charlie Root
			echo "<select style='height:22px;' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}'>\n";
1016
			if(isset($rowhelper['show_disable_value']))
1017
				echo "<option value='{$rowhelper['show_disable_value']}'>{$rowhelper['show_disable_value']}</option>\n";
1018 55c846c4 Marcello Coutinho
			$source_url = $rowhelper['source'];
1019
			eval("\$pkg_source_txt = &$source_url;");
1020
			foreach($pkg_source_txt as $opt) {
1021
				$source_name = ($rowhelper['source_name'] ? $opt[$rowhelper['source_name']] : $opt[$rowhelper['name']]);
1022
				$source_value = ($rowhelper['source_value'] ? $opt[$rowhelper['source_value']] : $opt[$rowhelper['value']]);
1023
				$text .= "<option value='{$source_value}'>{$source_name}</option>";
1024 2e606955 Colin Fleming
				echo "<option value='{$source_value}'".($source_value == $value?" selected=\"selected\"":"").">{$source_name}</option>\n";
1025 55c846c4 Marcello Coutinho
				}
1026
			echo "</select>\n";
1027
			break;		
1028 db3829e1 Scott Ullrich
		}
1029 8612c539 Colin Fleming
	echo "</td>\n";
1030 31d27c6c Scott Ullrich
}
1031
1032 d51f86e0 Scott Ullrich
function fixup_string($string) {
1033 d2133701 Scott Ullrich
	global $config;
1034 d51f86e0 Scott Ullrich
	// fixup #1: $myurl -> http[s]://ip_address:port/
1035
	$https = "";
1036
	$port = $config['system']['webguiport'];
1037 63637de9 Bill Marquette
	if($port <> "443" and $port <> "80")
1038
		$urlport = ":" . $port;
1039
	else
1040
		$urlport = "";
1041 3c616886 Scott Ullrich
1042 58362f9d jim-p
	if($config['system']['webgui']['protocol'] == "https") $https = "s";
1043 63637de9 Bill Marquette
	$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlport;
1044 d51f86e0 Scott Ullrich
	$newstring = str_replace("\$myurl", $myurl, $string);
1045 d2133701 Scott Ullrich
	$string = $newstring;
1046
	// fixup #2: $wanip
1047 85a5da13 Ermal Luçi
	$curwanip = get_interface_ip();
1048 d2133701 Scott Ullrich
	$newstring = str_replace("\$wanip", $curwanip, $string);
1049
	$string = $newstring;
1050
	// fixup #3: $lanip
1051
	$lancfg = $config['interfaces']['lan'];
1052
	$lanip = $lancfg['ipaddr'];
1053
	$newstring = str_replace("\$lanip", $lanip, $string);
1054
	$string = $newstring;
1055
	// fixup #4: fix'r'up here.
1056 d51f86e0 Scott Ullrich
	return $newstring;
1057
}
1058
1059 dcbe6f52 Scott Ullrich
/*
1060
 *  Parse templates if they are defined
1061
 */
1062
function parse_package_templates() {
1063
	global $pkg, $config;
1064 767a716e Scott Ullrich
	$rows = 0;
1065 dcbe6f52 Scott Ullrich
	if($pkg['templates']['template'] <> "")
1066
	    foreach($pkg['templates']['template'] as $pkg_template_row) {
1067 55c846c4 Marcello Coutinho
			$filename = $pkg_template_row['filename'];
1068
			$template_text = $pkg_template_row['templatecontents'];
1069
			$firstfield = "";
1070
			/* calculate total row helpers count and */
1071
			/* change fields defined as fieldname_fieldvalue to their value */
1072
			foreach ($pkg['fields']['field'] as $fields) {
1073
				switch($fields['type']){
1074
					case "rowhelper":
1075
					// save rowhelper items.
1076
					$row_helper_total_rows = 0;
1077
					$row_helper_data = "";
1078
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield)
1079
						foreach($_POST as $key => $value){
1080
							if (preg_match("/^{$rowhelperfield['fieldname']}(\d+)$/",$key,$matches)){
1081
								$row_helper_total_rows++;
1082
								$row_helper_data .= $value;
1083
								$sep = "";
1084
								ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
1085 eab652e4 Renato Botelho
								foreach ($sep as $se) $separator = $se;
1086
								if($separator <> "") {
1087
							    	$row_helper_data = ereg_replace("  ", $separator, $row_helper_data);
1088
							    	$template_text = ereg_replace("\[{$separator}\]", "", $template_text);
1089 55c846c4 Marcello Coutinho
									}
1090
								$template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
1091
								}
1092
							}
1093
					break;
1094
				default:
1095
					$fieldname  = $fields['fieldname'];
1096
					$fieldvalue = $_POST[$fieldname];
1097
					$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
1098 dcbe6f52 Scott Ullrich
				}
1099
			}
1100
		/* replace $domain_total_rows with total rows */
1101
		$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
1102 1624b5f1 Marcello Coutinho
1103 dcbe6f52 Scott Ullrich
		/* replace cr's */
1104
		$template_text = str_replace("\\n", "\n", $template_text);
1105
1106
		/* write out new template file */
1107
		$fout = fopen($filename,"w");
1108
		fwrite($fout, $template_text);
1109
		fclose($fout);
1110
	    }
1111
}
1112
1113 e11aa161 Warren Baker
/* Return html div fields */
1114
function display_advanced_field($fieldname) {
1115 55c846c4 Marcello Coutinho
	$div = "<div id='showadv_{$fieldname}'>\n";
1116 2e606955 Colin Fleming
	$div .= "<input type='button' onclick='show_{$fieldname}()' value='" . gettext("Advanced") . "' /> - " . gettext("Show advanced option") ."</div>\n";
1117 55c846c4 Marcello Coutinho
	$div .= "<div id='show_{$fieldname}' style='display:none'>\n";
1118 e11aa161 Warren Baker
	return $div;
1119
}
1120
1121 b89a8cbc bruno
?>