Project

General

Profile

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