Project

General

Profile

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