Project

General

Profile

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