Project

General

Profile

Download (24.7 KB) Statistics
| Branch: | Tag: | Revision:
1 d47013e1 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 d47013e1 Scott Ullrich
/*
4
    pkg_edit.php
5
    Copyright (C) 2004 Scott Ullrich
6
    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
30 9f9dcd98 Scott Ullrich
require_once("guiconfig.inc");
31 f8e335a3 Scott Ullrich
require_once("pkg-utils.inc");
32 d47013e1 Scott Ullrich
33 14db714e Scott Ullrich
/* dummy stubs needed by some code that was MFC'd */
34 3c616886 Scott Ullrich
function gettext($text) { return $text; }
35 14db714e Scott Ullrich
function pfSenseHeader($location) { header("Location: $location"); }
36
37 d47013e1 Scott Ullrich
function gentitle_pkg($pgname) {
38
	global $pfSense_config;
39
	return $pfSense_config['system']['hostname'] . "." . $pfSense_config['system']['domain'] . " - " . $pgname;
40
}
41
42
// XXX: Make this input safe.
43
$xml = $_GET['xml'];
44 19fd2947 Scott Ullrich
if($_POST['xml']) $xml = $_POST['xml'];
45 d47013e1 Scott Ullrich
46
if($xml == "") {
47 b91540da Scott Ullrich
            print_info_box_np(gettext("ERROR: No package defined."));
48 d47013e1 Scott Ullrich
            die;
49
} else {
50 19a11678 Colin Smith
            $pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
51 d47013e1 Scott Ullrich
}
52 7c172009 Scott Ullrich
53
if($pkg['include_file'] <> "") {
54
	require_once($pkg['include_file']);
55
}
56
57 b91540da Scott Ullrich
if (!isset($pkg['adddeleteeditpagefields']))
58
	$only_edit = true;
59
else
60
	$only_edit = false;
61
62 a28c8b59 Scott Ullrich
$package_name = $pkg['menu'][0]['name'];
63
$section      = $pkg['menu'][0]['section'];
64 d47013e1 Scott Ullrich
$config_path  = $pkg['configpath'];
65 bb940538 Scott Ullrich
$name         = $pkg['name'];
66 b91540da Scott Ullrich
$title        = $pkg['title'];
67 96d9f5c9 Bill Marquette
$pgtitle      = $title;
68 d47013e1 Scott Ullrich
69 da7bf505 Scott Ullrich
$id = $_GET['id'];
70
if (isset($_POST['id']))
71
	$id = $_POST['id'];
72 9b8837be Scott Ullrich
73 529ffadb Bill Marquette
if($pkg['custom_php_global_functions'] <> "")
74
        eval($pkg['custom_php_global_functions']);
75
76 31d27c6c Scott Ullrich
// grab the installedpackages->package_name section.
77 e315cfa1 Colin Smith
if(!is_array($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']))
78 7db8ff99 Colin Smith
	$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'] = array();
79 da7bf505 Scott Ullrich
80 7db8ff99 Colin Smith
$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
81 da7bf505 Scott Ullrich
82 19d360bf Scott Ullrich
if($_GET['savemsg'] <> "")
83
	$savemsg = $_GET['savemsg'];
84 f9a91638 Scott Ullrich
85 194b4e0a Colin Smith
if($pkg['custom_php_command_before_form'] <> "")
86
	eval($pkg['custom_php_command_before_form']);
87 f9a91638 Scott Ullrich
88 6483da5d Scott Ullrich
if ($_POST) {
89 b3235baa Scott Ullrich
	if($_POST['act'] == "del") {
90
		if($pkg['custom_delete_php_command']) {
91 5cd30ac3 Scott Ullrich
		    if($pkg['custom_php_command_before_form'] <> "")
92
			    eval($pkg['custom_php_command_before_form']);
93 b3235baa Scott Ullrich
		    eval($pkg['custom_delete_php_command']);
94
		}
95 7c172009 Scott Ullrich
		write_config($pkg['delete_string']);
96 facd08f9 Scott Ullrich
		// resync the configuration file code if defined.
97
		if($pkg['custom_php_resync_config_command'] <> "") {
98 86f3fc00 Scott Ullrich
			if($pkg['custom_php_command_before_form'] <> "")
99
				eval($pkg['custom_php_command_before_form']);
100
			eval($pkg['custom_php_resync_config_command']);
101 facd08f9 Scott Ullrich
		}
102 b3235baa Scott Ullrich
	} else {
103
		if($pkg['custom_add_php_command']) {
104 90779bf7 Scott Ullrich
			if($pkg['donotsave'] <> "" or $pkg['preoutput'] <> "") {
105 12123e25 Colin Smith
			?>
106 afe4a7d3 Erik Kristensen
107 539b4c44 Colin Smith
<?php include("head.inc"); ?>
108 3eaeb703 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
109 2fe6c52b Colin Smith
<?php include("fbegin.inc"); ?>
110 fbd14b13 Scott Ullrich
<?php
111 3eaeb703 Scott Ullrich
			}
112
			if($pkg['preoutput']) echo "<pre>";
113
			eval($pkg['custom_add_php_command']);
114
			if($pkg['preoutput']) echo "</pre>";
115 b3235baa Scott Ullrich
		}
116 6483da5d Scott Ullrich
	}
117 e3c4b6b7 Scott Ullrich
118 eec70f21 Scott Ullrich
	// donotsave is enabled.  lets simply exit.
119 3eaeb703 Scott Ullrich
	if($pkg['donotsave'] <> "") exit;
120
121 b6e87566 Scott Ullrich
	$firstfield = "";
122
	$rows = 0;
123
124 7c172009 Scott Ullrich
	$input_errors = array();
125
	$reqfields = array();
126
	$reqfieldsn = array();
127
	foreach ($pkg['fields']['field'] as $field) {
128 b91540da Scott Ullrich
		if (($field['type'] == 'input') && isset($field['required'])) {
129 7c172009 Scott Ullrich
			$reqfields[] = $field['fieldname'];
130
			$reqfieldsn[] = $field['fielddescr'];
131
		}
132
	}
133
	do_input_validation($_POST, $reqfields, $reqfieldsn, &$input_errors);
134
135
	if ($pkg['custom_php_validation_command'])
136
		eval($pkg['custom_php_validation_command']);
137
138 b3235baa Scott Ullrich
	// store values in xml configration file.
139
	if (!$input_errors) {
140
		$pkgarr = array();
141
		foreach ($pkg['fields']['field'] as $fields) {
142 eec70f21 Scott Ullrich
			if($fields['type'] == "rowhelper") {
143
				// save rowhelper items.
144
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
145 628b33c1 Scott Ullrich
				                         // XXX: this really is not helping embedded platforms.
146 0e730fee Scott Ullrich
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
147 b6e87566 Scott Ullrich
						if($firstfield == "")  {
148
						  $firstfield = $rowhelperfield['fieldname'];
149
						} else {
150
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
151
						}
152 a93310c3 Scott Ullrich
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
153 eec70f21 Scott Ullrich
						eval($comd);
154
						if($value <> "") {
155 b6e87566 Scott Ullrich
							$comd = "\$pkgarr['row'][" . $x . "]['" . $rowhelperfield['fieldname'] . "'] = \"" . $value . "\";";
156
							//echo($comd . "<br>");
157 eec70f21 Scott Ullrich
							eval($comd);
158
						}
159
					}
160
				}
161
			} else {
162
				$fieldname  = $fields['fieldname'];
163 fbd14b13 Scott Ullrich
				$fieldvalue = $_POST[$fieldname];
164
				if (is_array($fieldvalue))
165
					$fieldvalue = implode(',', $fieldvalue);
166
				else {
167
					$fieldvalue = trim($fieldvalue);
168
					if ($fields['encoding'] == 'base64')
169
						$fieldvalue = base64_encode($fieldvalue);
170
				}
171 7db8ff99 Colin Smith
				$pkgarr[$fieldname] = $fieldvalue;
172 eec70f21 Scott Ullrich
			}
173 b3235baa Scott Ullrich
		}
174 0e730fee Scott Ullrich
175 e3c4b6b7 Scott Ullrich
		if (isset($id) && $a_pkg[$id])
176
			$a_pkg[$id] = $pkgarr;
177
		else
178
			$a_pkg[] = $pkgarr;
179 0e730fee Scott Ullrich
180 7c172009 Scott Ullrich
		write_config($pkg['addedit_string']);
181 934ab6a2 Scott Ullrich
182 facd08f9 Scott Ullrich
		// late running code
183 2a520a0a Scott Ullrich
		if($pkg['custom_add_php_command_late'] <> "") {
184
		    eval($pkg['custom_add_php_command_late']);
185
		}
186 0e730fee Scott Ullrich
187 facd08f9 Scott Ullrich
		// resync the configuration file code if defined.
188
		if($pkg['custom_php_resync_config_command'] <> "") {
189
		    eval($pkg['custom_php_resync_config_command']);
190
		}
191
192 dcbe6f52 Scott Ullrich
		parse_package_templates();
193
194 a485a6f5 Scott Ullrich
		/* if start_command is defined, restart w/ this */
195
		if($pkg['start_command'] <> "")
196
		    exec($pkg['start_command'] . ">/dev/null 2&>1");
197
198
		/* if restart_command is defined, restart w/ this */
199
		if($pkg['restart_command'] <> "")
200
		    exec($pkg['restart_command'] . ">/dev/null 2&>1");
201
202 dcbe6f52 Scott Ullrich
		if($pkg['aftersaveredirect'] <> "") {
203 fbd14b13 Scott Ullrich
		    pfSenseHeader($pkg['aftersaveredirect']);
204 3089059e Colin Smith
		} elseif(!$pkg['adddeleteeditpagefields']) {
205 fbd14b13 Scott Ullrich
		    pfSenseHeader("pkg_edit.php?xml={$xml}&id=0");
206 3089059e Colin Smith
		} elseif(!$pkg['preoutput']) {
207 fbd14b13 Scott Ullrich
		    pfSenseHeader("pkg.php?xml=" . $xml);
208 dcbe6f52 Scott Ullrich
		}
209 0e730fee Scott Ullrich
		exit;
210 e3c4b6b7 Scott Ullrich
	}
211 7c172009 Scott Ullrich
	else
212
		$get_from_post = true;
213 da7bf505 Scott Ullrich
}
214
215 b91540da Scott Ullrich
if($pkg['title'] <> "") {
216
	$edit = ($only_edit ? '' : ': Edit');
217
	$title = $pkg['title'] . $edit;
218
}
219 83ddedcd Scott Ullrich
else
220 b91540da Scott Ullrich
	$title = gettext("Package Editor");
221 83ddedcd Scott Ullrich
222
$pgtitle = $title;
223
include("head.inc");
224
225 7c172009 Scott Ullrich
if ($pkg['custom_php_after_head_command'])
226
	eval($pkg['custom_php_after_head_command']);
227
228 d47013e1 Scott Ullrich
?>
229
230 2fe6c52b Colin Smith
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onLoad="enablechange();">
231
<?php if($pkg['fields']['field'] <> "") { ?>
232
<script language="JavaScript">
233
<!--
234
function enablechange() {
235 3c616886 Scott Ullrich
<?php
236 fbd14b13 Scott Ullrich
foreach ($pkg['fields']['field'] as $field) {
237
	if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
238
		print("\tif (document.iform.elements[\"{$field['fieldname']}\"].checked == false) {\n");
239
240
		if (isset($field['enablefields'])) {
241
			foreach (explode(',', $field['enablefields']) as $enablefield)
242
				print("\t\tdocument.iform.elements[\"$enablefield\"].disabled = 1;\n");
243
		}
244
245
		if (isset($field['checkenablefields'])) {
246
			foreach (explode(',', $field['checkenablefields']) as $checkenablefield)
247
				print("\t\tdocument.iform.elements[\"$checkenablefield\"].checked = 0;\n");
248
		}
249
250
		print("\t}\n\telse {\n");
251
252
		if (isset($field['enablefields'])) {
253
			foreach (explode(',', $field['enablefields']) as $enablefield)
254
				print("\t\tdocument.iform.elements[\"$enablefield\"].disabled = 0;\n");
255
		}
256
257
		if (isset($field['checkenablefields'])) {
258
			foreach(explode(',', $field['checkenablefields']) as $checkenablefield)
259
				print("\t\tdocument.iform.elements[\"$checkenablefield\"].checked = 1;\n");
260
		}
261
262
		print("\t}\n");
263
	}
264
}
265 2fe6c52b Colin Smith
?>
266
}
267
//-->
268
</script>
269
<?php } ?>
270 eec70f21 Scott Ullrich
<script type="text/javascript" language="javascript" src="row_helper_dynamic.js">
271
</script>
272
273 96d9f5c9 Bill Marquette
<?php include("fbegin.inc"); ?>
274 d012cff4 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
275 7c172009 Scott Ullrich
<?php if (!empty($input_errors)) print_input_errors($input_errors); ?>
276
<form name="iform" action="pkg_edit.php" method="post">
277 fbd14b13 Scott Ullrich
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
278
<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
279 19fd2947 Scott Ullrich
<input type="hidden" name="xml" value="<?= $xml ?>">
280 d47013e1 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
281 f4cb26b7 Colin Smith
<table width="100%" border="0" cellpadding="0" cellspacing="0">
282 7c061036 Scott Ullrich
<?php
283
if ($pkg['tabs'] <> "") {
284 f4cb26b7 Colin Smith
    echo '<tr><td>';
285
    $tab_array = array();
286 7c061036 Scott Ullrich
    foreach($pkg['tabs']['tab'] as $tab) {
287 f4cb26b7 Colin Smith
	if(isset($tab['active'])) {
288
		$active = true;
289
	} else {
290
		$active = false;
291
	}
292 e17ce934 Scott Ullrich
	$urltmp = "";
293
	if($tab['url'] <> "") $urltmp = $tab['url'];
294
	if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml'];
295
296 656a2fea Seth Mos
 	$addresswithport = getenv("HTTP_HOST");
297
	$colonpos = strpos($addresswithport, ":");
298
	if ($colonpos !== False){
299
		//my url is actually just the IP address of the pfsense box
300
		$myurl = substr($addresswithport, 0, $colonpos);
301
	}
302
	else
303
	{
304
		$myurl = $addresswithport;
305
	}
306 e17ce934 Scott Ullrich
	// eval url so that above $myurl item can be processed if need be.
307 f4cb26b7 Colin Smith
	$url = str_replace('$myurl', $myurl, $urltmp);
308 656a2fea Seth Mos
309 f4cb26b7 Colin Smith
	$tab_array[] = array(
310
				$tab['text'],
311
				$active,
312
				$url
313
			);
314 7c061036 Scott Ullrich
    }
315 f4cb26b7 Colin Smith
    display_top_tabs($tab_array);
316
    echo '</td></tr>';
317 7c061036 Scott Ullrich
}
318
?>
319 f4cb26b7 Colin Smith
<tr><td><div id="mainarea"><table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
320 d47013e1 Scott Ullrich
  <?php
321
  $cols = 0;
322 b91540da Scott Ullrich
  $savevalue = gettext("Save");
323 3eaeb703 Scott Ullrich
  if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
324
  foreach ($pkg['fields']['field'] as $pkga) { ?>
325 3c616886 Scott Ullrich
326 facd08f9 Scott Ullrich
	  <?php if(!$pkga['combinefieldsend']) echo "<tr valign=\"top\">"; ?>
327
328 d47013e1 Scott Ullrich
	  <?php
329 3c616886 Scott Ullrich
330 5c74f339 Scott Ullrich
	  $size = "";
331 3c616886 Scott Ullrich
332 facd08f9 Scott Ullrich
	  if(!$pkga['dontdisplayname']) {
333 7c172009 Scott Ullrich
		unset($req);
334 b91540da Scott Ullrich
		if (isset($pkga['required']))
335 7c172009 Scott Ullrich
			$req = 'req';
336
		echo "<td width=\"22%\" class=\"vncell{$req}\">";
337 d51f86e0 Scott Ullrich
		echo fixup_string($pkga['fielddescr']);
338 31d27c6c Scott Ullrich
		echo "</td>";
339 facd08f9 Scott Ullrich
	  }
340
341
	  if(!$pkga['dontcombinecells'])
342
		echo "<td class=\"vtable\">";
343 31d27c6c Scott Ullrich
		// if user is editing a record, load in the data.
344 7c172009 Scott Ullrich
		$fieldname = $pkga['fieldname'];
345 fbd14b13 Scott Ullrich
		if ($get_from_post) {
346 7c172009 Scott Ullrich
			$value = $_POST[$fieldname];
347 fbd14b13 Scott Ullrich
			if (is_array($value)) $value = implode(',', $value);
348
		}
349 7c172009 Scott Ullrich
		else {
350
			if (isset($id) && $a_pkg[$id])
351
				$value = $a_pkg[$id][$fieldname];
352 b91540da Scott Ullrich
			else
353
				$value = $pkga['default_value'];
354 31d27c6c Scott Ullrich
		}
355
356 3eaeb703 Scott Ullrich
	      if($pkga['type'] == "input") {
357 b6e87566 Scott Ullrich
			if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
358 ae2ea68c Scott Ullrich
			echo "<input " . $size . " id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
359 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
360 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "password") {
361 ae2ea68c Scott Ullrich
			echo "<input id='" . $pkga['fieldname'] . "' type='password' " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
362 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
363 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "select") {
364 fbd14b13 Scott Ullrich
                  $fieldname = $pkga['fieldname'];
365
                  if (isset($pkga['multiple'])) {
366 67fa245a Scott Ullrich
                    $multiple = 'multiple="multiple"';
367 fbd14b13 Scott Ullrich
                    $items = explode(',', $value);
368 67fa245a Scott Ullrich
                    $fieldname .= "[]";
369 fbd14b13 Scott Ullrich
                  }
370
                  else {
371
                    $multiple = '';
372
                    $items = array($value);
373
                  }
374
                  $size = (isset($pkga['size']) ? "size=\"{$pkga['size']}\"" : '');
375
                  $onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
376
377 ae2ea68c Scott Ullrich
                  print("<select id='" . $pkga['fieldname'] . "' $multiple $size $onchange id=\"$fieldname\" name=\"$fieldname\">\n");
378 fbd14b13 Scott Ullrich
                  foreach ($pkga['options']['option'] as $opt) {
379
                      $selected = '';
380 67fa245a Scott Ullrich
                      if (in_array($opt['value'], $items)) $selected = 'selected="selected"';
381 fbd14b13 Scott Ullrich
                      print("\t<option name=\"{$opt['name']}\" value=\"{$opt['value']}\" $selected>{$opt['name']}</option>\n");
382
                  }
383
384
                  print("</select>\n<br />\n" . fixup_string($pkga['description']) . "\n");
385 2c634bdd Scott Ullrich
	      } else if($pkga['type'] == "vpn_selection") {
386 ae2ea68c Scott Ullrich
		    echo "<select id='" . $pkga['fieldname'] . "' name='" . $vpn['name'] . "'>\n";
387 2c634bdd Scott Ullrich
		    foreach ($config['ipsec']['tunnel'] as $vpn) {
388
			echo "\t<option value=\"" . $vpn['descr'] . "\">" . $vpn['descr'] . "</option>\n";
389
		    }
390
		    echo "</select>\n";
391 03f0bfe7 Scott Ullrich
		    echo "<br>" . fixup_string($pkga['description']) . "\n";
392 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "checkbox") {
393 64c1ebbb Scott Ullrich
			$checkboxchecked = "";
394 34865da0 Scott Ullrich
			if($value == "on") $checkboxchecked = " CHECKED";
395 b91540da Scott Ullrich
			if (isset($pkga['enablefields']) || isset($pkga['checkenablefields']))
396
				$onclick = ' onclick="javascript:enablechange();"';
397 ae2ea68c Scott Ullrich
			echo "<input id='" . $pkga['fieldname'] . "' type='checkbox' name='" . $pkga['fieldname'] . "'" . $checkboxchecked . $onclick . ">\n";
398 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
399 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "textarea") {
400
		  if($pkga['rows']) $rows = " rows='" . $pkga['rows'] . "' ";
401
		  if($pkga['cols']) $cols = " cols='" . $pkga['cols'] . "' ";
402 7c172009 Scott Ullrich
                  if (($pkga['encoding'] == 'base64') && !$get_from_post && !empty($value)) $value = base64_decode($value);
403 b6e87566 Scott Ullrich
			echo "<textarea " . $rows . $cols . " name='" . $pkga['fieldname'] . "'>" . $value . "</textarea>\n";
404 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
405 ab73789e Scott Ullrich
		  } else if($pkga['type'] == "interfaces_selection") {
406 fbd14b13 Scott Ullrich
			$size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
407
			$multiple = '';
408 7502342a Scott Ullrich
			$fieldname = $pkga['fieldname'];
409 fbd14b13 Scott Ullrich
			if (isset($pkga['multiple'])) {
410
				$fieldname .= '[]';
411
				$multiple = 'multiple';
412 e4a72146 Scott Ullrich
			}
413 ae2ea68c Scott Ullrich
			print("<select id='" . $pkga['fieldname'] . "' name=\"$fieldname\" $size $multiple>\n");
414 fbd14b13 Scott Ullrich
415
			if (isset($pkga['all_interfaces']))
416
				$ifaces = explode(' ', trim(shell_exec('ifconfig -l')));
417
			else
418
				$ifaces = $config['interfaces'];
419
420
			$additional_ifaces = $pkga['add_to_interfaces_selection'];
421
			if (!empty($additional_ifaces))
422
				$ifaces = array_merge($ifaces, explode(',', $additional_ifaces));
423 9996eff6 Scott Ullrich
			if(is_array($value))
424
				$values = $value;
425
			else
426
				$values  =  explode(',',  $value);
427 fbd14b13 Scott Ullrich
428
			foreach($ifaces as $ifname => $iface) {
429
				if (isset($iface['descr']))
430
					$ifdescr = $iface['descr'];
431
				else
432
					$ifdescr = strtoupper($ifname);
433
				if ($ip = find_interface_ip($iface))
434
					$ip = " ($ip)";
435
				$selected = (in_array($ifname, $values) ? 'selected' : '');
436
				print("<option value=\"$ifname\" $selected>$ifdescr</option>\n");
437 ab73789e Scott Ullrich
			}
438 fbd14b13 Scott Ullrich
439
			print("</select>\n<br />" . fixup_string($pkga['description']) . "\n");
440 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "radio") {
441 ae2ea68c Scott Ullrich
			echo "<input type='radio' id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "' value='" . $value . "'>";
442 eec70f21 Scott Ullrich
	      } else if($pkga['type'] == "rowhelper") {
443
		?>
444
			<script type="text/javascript" language='javascript'>
445
			<!--
446 0e730fee Scott Ullrich
447 eec70f21 Scott Ullrich
			<?php
448
				$rowcounter = 0;
449
				$fieldcounter = 0;
450
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
451
					echo "rowname[" . $fieldcounter . "] = \"" . $rowhelper['fieldname'] . "\";\n";
452
					echo "rowtype[" . $fieldcounter . "] = \"" . $rowhelper['type'] . "\";\n";
453
					$fieldcounter++;
454
				}
455
			?>
456 0e730fee Scott Ullrich
457 eec70f21 Scott Ullrich
			-->
458
			</script>
459 0e730fee Scott Ullrich
460 eec70f21 Scott Ullrich
			<table name="maintable" id="maintable">
461 b6e87566 Scott Ullrich
			<tr>
462 eec70f21 Scott Ullrich
			<?php
463 31d27c6c Scott Ullrich
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
464 d51f86e0 Scott Ullrich
				  echo "<td><b>" . fixup_string($rowhelper['fielddescr']) . "</td>\n";
465 31d27c6c Scott Ullrich
				}
466 b6e87566 Scott Ullrich
				echo "</tr>";
467
468 eec70f21 Scott Ullrich
				echo "<tr>";
469
				  // XXX: traverse saved fields, add back needed rows.
470
				echo "</tr>";
471 0e730fee Scott Ullrich
472 31d27c6c Scott Ullrich
				echo "<tr>\n";
473
				$rowcounter = 0;
474
				$trc = 0;
475
				if(isset($a_pkg[$id]['row'])) {
476
					foreach($a_pkg[$id]['row'] as $row) {
477
					/*
478
					 * loop through saved data for record if it exists, populating rowhelper
479 bb940538 Scott Ullrich
					 */
480 31d27c6c Scott Ullrich
						foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
481
							if($rowhelper['value'] <> "") $value = $rowhelper['value'];
482
							$fieldname = $rowhelper['fieldname'];
483
							// if user is editing a record, load in the data.
484 bb940538 Scott Ullrich
							if (isset($id) && $a_pkg[$id]) {
485 7db8ff99 Colin Smith
								$value = $row[$fieldname];
486 bb940538 Scott Ullrich
							}
487 31d27c6c Scott Ullrich
							$options = "";
488
							$type = $rowhelper['type'];
489
							$fieldname = $rowhelper['fieldname'];
490
							if($type == "option") $options = &$rowhelper['options']['option'];
491 e70e0b76 Scott Ullrich
							$size = "8";
492
							if($rowhelper['size'] <> "") $size = $rowhelper['size'];
493
							display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
494 bb940538 Scott Ullrich
							// javascript helpers for row_helper_dynamic.js
495
							echo "</td>\n";
496
							echo "<script language=\"JavaScript\">\n";
497
							echo "<!--\n";
498
							echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
499
							echo "-->\n";
500
							echo "</script>\n";
501
							$text = "";
502
							$trc++;
503 eec70f21 Scott Ullrich
						}
504 bb940538 Scott Ullrich
505 31d27c6c Scott Ullrich
						$rowcounter++;
506
						echo "<td>";
507 b91540da Scott Ullrich
						echo "<input type=\"image\" src=\"./themes/".$g['theme']."/images/icons/icon_x.gif\" onclick=\"removeRow(this); return false;\" value=\"" . gettext("Delete") . "\">";
508 eec70f21 Scott Ullrich
						echo "</td>\n";
509 31d27c6c Scott Ullrich
						echo "</tr>\n";
510
					}
511
				}
512
				if($trc == 0) {
513
					/*
514
					 *  no records loaded.
515
                                         *  just show a generic line non-populated with saved data
516
                                         */
517
                                        foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
518
						if($rowhelper['value'] <> "") $value = $rowhelper['value'];
519 bb940538 Scott Ullrich
						$fieldname = $rowhelper['fieldname'];
520 31d27c6c Scott Ullrich
						$options = "";
521
						$type = $rowhelper['type'];
522
						$fieldname = $rowhelper['fieldname'];
523
						if($type == "option") $options = &$rowhelper['options']['option'];
524 e70e0b76 Scott Ullrich
						$size = "8";
525
						if($rowhelper['size'] <> "") $size = $rowhelper['size'];
526
						display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
527 bb940538 Scott Ullrich
						// javascript helpers for row_helper_dynamic.js
528
						echo "</td>\n";
529
						echo "<script language=\"JavaScript\">\n";
530
						echo "<!--\n";
531
						echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
532
						echo "-->\n";
533
						echo "</script>\n";
534
						$text = "";
535 eec70f21 Scott Ullrich
						$trc++;
536
					}
537 bb940538 Scott Ullrich
538
					$rowcounter++;
539 eec70f21 Scott Ullrich
				}
540
			?>
541 0e730fee Scott Ullrich
542 03664f64 Scott Ullrich
			  <tbody></tbody>
543 eec70f21 Scott Ullrich
			</table>
544 0e730fee Scott Ullrich
545 677c0869 Erik Kristensen
		<br><a onClick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif"></a>
546 eec70f21 Scott Ullrich
		<script language="JavaScript">
547
		<!--
548
		field_counter_js = <?= $fieldcounter ?>;
549
		rows = <?= $rowcounter ?>;
550
		totalrows = <?php echo $rowcounter; ?>;
551
		loaded = <?php echo $rowcounter; ?>;
552 e02a6839 Scott Ullrich
		//typesel_change();
553 eec70f21 Scott Ullrich
		//-->
554
		</script>
555
556
		<?php
557 d47013e1 Scott Ullrich
	      }
558 3eaeb703 Scott Ullrich
	      if($pkga['typehint']) echo " " . $pkga['typehint'];
559 facd08f9 Scott Ullrich
	     ?>
560
561 d47013e1 Scott Ullrich
      <?php
562 facd08f9 Scott Ullrich
	  if(!$pkga['combinefieldsbegin']) echo "</td></tr>";
563 d47013e1 Scott Ullrich
      $i++;
564
  }
565
 ?>
566 b6e87566 Scott Ullrich
  <tr>
567
	<td>&nbsp;</td>
568
  </tr>
569 d47013e1 Scott Ullrich
  <tr>
570
    <td width="22%" valign="top">&nbsp;</td>
571
    <td width="78%">
572 7c172009 Scott Ullrich
<?php
573
if($pkg['note'] != "")
574 b91540da Scott Ullrich
	print("<p><span class=\"red\"><strong>" . gettext("Note") . ":</strong></span> {$pkg['note']}</p>");
575
//if (isset($id) && $a_pkg[$id]) // We'll always have a valid ID in our hands
576 7c172009 Scott Ullrich
      print("<input name=\"id\" type=\"hidden\" value=\"$id\">");
577
?>
578
      <input name="Submit" type="submit" class="formbtn" value="<?= $savevalue ?>">
579 b91540da Scott Ullrich
<?php if (!$only_edit): ?>
580
      <input class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()">
581
<?php endif; ?>
582 d47013e1 Scott Ullrich
    </td>
583
  </tr>
584
</table>
585 f4cb26b7 Colin Smith
</div></tr></td></table>
586 7c172009 Scott Ullrich
</form>
587 7c061036 Scott Ullrich
588 7c172009 Scott Ullrich
<?php if ($pkg['custom_php_after_form_command']) eval($pkg['custom_php_after_form_command']); ?>
589 95736b54 Scott Ullrich
590 d47013e1 Scott Ullrich
<?php include("fend.inc"); ?>
591
</body>
592
</html>
593
594 31d27c6c Scott Ullrich
<?php
595
/*
596
 * ROW Helpers function
597
 */
598 e70e0b76 Scott Ullrich
function display_row($trc, $value, $fieldname, $type, $rowhelper, $size) {
599 bb940538 Scott Ullrich
	global $text;
600 31d27c6c Scott Ullrich
	echo "<td>\n";
601
	if($type == "input") {
602 ae2ea68c Scott Ullrich
		echo "<input size='" . $size . "' name='" . $fieldname . $trc . "' id='" . $fieldname . $trc . "' value='" . $value . "'>\n";
603 855cab21 Scott Ullrich
	} else if($type == "checkbox") {
604
		if($value)
605 ae2ea68c Scott Ullrich
			echo "<input size='" . $size . "' type='checkbox' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "' value='ON' CHECKED>\n";
606 855cab21 Scott Ullrich
		else
607 ae2ea68c Scott Ullrich
			echo "<input size='" . $size . "' type='checkbox' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "' value='ON'>\n";
608 31d27c6c Scott Ullrich
	} else if($type == "password") {
609 ae2ea68c Scott Ullrich
		echo "<input size='" . $size . "' type='password' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "' value='" . $value . "'>\n";
610 31d27c6c Scott Ullrich
	} else if($type == "textarea") {
611 ae2ea68c Scott Ullrich
		echo "<textarea rows='2' cols='12' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "'>" . $value . "</textarea>\n";
612 31d27c6c Scott Ullrich
	} else if($type == "select") {
613 ae2ea68c Scott Ullrich
		echo "<select id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "'>\n";
614 31d27c6c Scott Ullrich
		foreach($rowhelper['options']['option'] as $rowopt) {
615
			$selected = "";
616
			if($rowopt['value'] == $value) $selected = " SELECTED";
617
			$text .= "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>";
618
			echo "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>\n";
619
		}
620
		echo "</select>\n";
621
	}
622
}
623
624 d51f86e0 Scott Ullrich
function fixup_string($string) {
625 d2133701 Scott Ullrich
	global $config;
626 d51f86e0 Scott Ullrich
	// fixup #1: $myurl -> http[s]://ip_address:port/
627
	$https = "";
628
	$port = $config['system']['webguiport'];
629 63637de9 Bill Marquette
	if($port <> "443" and $port <> "80")
630
		$urlport = ":" . $port;
631
	else
632
		$urlport = "";
633 3c616886 Scott Ullrich
634 d51f86e0 Scott Ullrich
	if($config['system']['webguiproto'] == "https") $https = "s";
635 63637de9 Bill Marquette
	$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlport;
636 d51f86e0 Scott Ullrich
	$newstring = str_replace("\$myurl", $myurl, $string);
637 d2133701 Scott Ullrich
	$string = $newstring;
638
	// fixup #2: $wanip
639
	$curwanip = get_current_wan_address();
640
	$newstring = str_replace("\$wanip", $curwanip, $string);
641
	$string = $newstring;
642
	// fixup #3: $lanip
643
	$lancfg = $config['interfaces']['lan'];
644
	$lanip = $lancfg['ipaddr'];
645
	$newstring = str_replace("\$lanip", $lanip, $string);
646
	$string = $newstring;
647
	// fixup #4: fix'r'up here.
648 d51f86e0 Scott Ullrich
	return $newstring;
649
}
650
651 dcbe6f52 Scott Ullrich
/*
652
 *  Parse templates if they are defined
653
 */
654
function parse_package_templates() {
655
	global $pkg, $config;
656 767a716e Scott Ullrich
	$rows = 0;
657 dcbe6f52 Scott Ullrich
	if($pkg['templates']['template'] <> "")
658
	    foreach($pkg['templates']['template'] as $pkg_template_row) {
659
		$filename = $pkg_template_row['filename'];
660
		$template_text = $pkg_template_row['templatecontents'];
661 767a716e Scott Ullrich
		$firstfield = "";
662 dcbe6f52 Scott Ullrich
		/* calculate total row helpers count */
663
		foreach ($pkg['fields']['field'] as $fields) {
664
			if($fields['type'] == "rowhelper") {
665
				// save rowhelper items.
666
                                $row_helper_total_rows = 0;
667
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
668
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
669
						if($firstfield == "")  {
670
						  $firstfield = $rowhelperfield['fieldname'];
671
						} else {
672
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
673
						}
674
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
675 767a716e Scott Ullrich
						$value = "";
676 dcbe6f52 Scott Ullrich
						eval($comd);
677
						if($value <> "") {
678
						    //$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
679
						} else {
680
						    $row_helper_total_rows = $rows;
681
						    break;
682
						}
683
					}
684
				}
685
			}
686
		}
687
688
		/* replace $domain_total_rows with total rows */
689
		$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
690
691
		/* change fields defined as fieldname_fieldvalue to their value */
692
		foreach ($pkg['fields']['field'] as $fields) {
693
			if($fields['type'] == "rowhelper") {
694
				// save rowhelper items.
695
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
696
					$row_helper_data = "";
697 1be00369 Scott Ullrich
					$isfirst = 0;
698 dcbe6f52 Scott Ullrich
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
699
						if($firstfield == "")  {
700
						  $firstfield = $rowhelperfield['fieldname'];
701
						} else {
702
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
703
						}
704
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
705
						eval($comd);
706
						if($value <> "") {
707 1be00369 Scott Ullrich
						    if($isfirst == 1) $row_helper_data .= "  " ;
708
						    $row_helper_data .= $value;
709
						    $isfirst = 1;
710 dcbe6f52 Scott Ullrich
						}
711 767a716e Scott Ullrich
						$sep = "";
712 dcbe6f52 Scott Ullrich
						ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
713
						foreach ($sep as $se) $seperator = $se;
714
						if($seperator <> "") {
715
						    $row_helper_data = ereg_replace("  ", $seperator, $row_helper_data);
716
						    $template_text = ereg_replace("\[" . $seperator . "\]", "", $template_text);
717
						}
718
						$template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
719
					}
720
				}
721
			} else {
722
				$fieldname  = $fields['fieldname'];
723
				$fieldvalue = $_POST[$fieldname];
724
				$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
725
			}
726
		}
727
728
		/* replace cr's */
729
		$template_text = str_replace("\\n", "\n", $template_text);
730
731
		/* write out new template file */
732
		$fout = fopen($filename,"w");
733
		fwrite($fout, $template_text);
734
		fclose($fout);
735
	    }
736
}
737
738 4fd34cce Scott Ullrich
?>