Project

General

Profile

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