Project

General

Profile

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