Project

General

Profile

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