Project

General

Profile

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