Project

General

Profile

Download (21 KB) Statistics
| Branch: | Tag: | Revision:
1 d47013e1 Scott Ullrich
#!/usr/local/bin/php
2
<?php
3
/*
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 628b33c1 Scott Ullrich
29
 <tabs>
30
 	<tab>
31
 		<text>Testing Tab</text>
32
 		<url>url to go to</url>
33
 	</tab>
34
 	<tab>
35
 		<text>Testing Tab 2</text>
36
 		<xml>filename of xml</xml>
37
 	</tab>
38
 </tabs>
39
40 d47013e1 Scott Ullrich
*/
41
42
require("guiconfig.inc");
43
require("xmlparse_pkg.inc");
44
45
$pfSense_config = $config; // copy this since we will be parsing
46
                           // another xml file which will be clobbered.
47
48
function gentitle_pkg($pgname) {
49
	global $pfSense_config;
50
	return $pfSense_config['system']['hostname'] . "." . $pfSense_config['system']['domain'] . " - " . $pgname;
51
}
52
53
// XXX: Make this input safe.
54
$xml = $_GET['xml'];
55 19fd2947 Scott Ullrich
if($_POST['xml']) $xml = $_POST['xml'];
56 d47013e1 Scott Ullrich
57
if($xml == "") {
58
            $xml = "not_defined";
59
            print_info_box_np("ERROR:  Could not open " . $xml . ".");
60
            die;
61
} else {
62 b3235baa Scott Ullrich
            $pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
63 d47013e1 Scott Ullrich
}
64
65 a28c8b59 Scott Ullrich
$package_name = $pkg['menu'][0]['name'];
66
$section      = $pkg['menu'][0]['section'];
67 d47013e1 Scott Ullrich
$config_path  = $pkg['configpath'];
68 bb940538 Scott Ullrich
$name         = $pkg['name'];
69 3eaeb703 Scott Ullrich
$title        = $section . ": " . $package_name;
70 d47013e1 Scott Ullrich
71 da7bf505 Scott Ullrich
$id = $_GET['id'];
72
if (isset($_POST['id']))
73
	$id = $_POST['id'];
74 9b8837be Scott Ullrich
75 31d27c6c Scott Ullrich
// grab the installedpackages->package_name section.
76 bb940538 Scott Ullrich
$toeval = "\$a_pkg = &\$config['installedpackages']['" . $name . "']['config'];";
77 31d27c6c Scott Ullrich
eval($toeval);
78
79 e3c4b6b7 Scott Ullrich
$toeval = "if (!is_array(\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'])) \$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'] = array();";
80 b3235baa Scott Ullrich
eval($toeval);
81 da7bf505 Scott Ullrich
82 e3c4b6b7 Scott Ullrich
$toeval = "\$a_pkg = &\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'];";
83
eval($toeval);
84 da7bf505 Scott Ullrich
85 f9a91638 Scott Ullrich
if($pkg['custom_php_command_before_form'] <> "")
86
  eval($pkg['custom_php_command_before_form']);
87
88
89 6483da5d Scott Ullrich
if ($_POST) {
90 b3235baa Scott Ullrich
	if($_POST['act'] == "del") {
91
		if($pkg['custom_delete_php_command']) {
92 5cd30ac3 Scott Ullrich
		    if($pkg['custom_php_command_before_form'] <> "")
93
			    eval($pkg['custom_php_command_before_form']);
94 b3235baa Scott Ullrich
		    eval($pkg['custom_delete_php_command']);
95
		}
96 e3c4b6b7 Scott Ullrich
		write_config();
97 facd08f9 Scott Ullrich
		// resync the configuration file code if defined.
98
		if($pkg['custom_php_resync_config_command'] <> "") {
99 86f3fc00 Scott Ullrich
			if($pkg['custom_php_command_before_form'] <> "")
100
				eval($pkg['custom_php_command_before_form']);
101
			eval($pkg['custom_php_resync_config_command']);
102 facd08f9 Scott Ullrich
		}
103 b3235baa Scott Ullrich
	} else {
104
		if($pkg['custom_add_php_command']) {
105 3eaeb703 Scott Ullrich
			if($pkg['donotsave'] <> "") {
106
				?>
107
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
108
<html>
109
<head>
110
<title><?=gentitle_pkg($title);?></title>
111
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
112
<link href="gui.css" rel="stylesheet" type="text/css">
113
</head>
114
115
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
116
<?php
117
include("fbegin.inc");
118 7c061036 Scott Ullrich
119 3eaeb703 Scott Ullrich
?>
120
<p class="pgtitle"><?=$title?></p>
121
				<?php
122
			}
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 b3235baa Scott Ullrich
	// store values in xml configration file.
136
	if (!$input_errors) {
137
		$pkgarr = array();
138
		foreach ($pkg['fields']['field'] as $fields) {
139 eec70f21 Scott Ullrich
			if($fields['type'] == "rowhelper") {
140
				// save rowhelper items.
141
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
142 628b33c1 Scott Ullrich
				                         // XXX: this really is not helping embedded platforms.
143 0e730fee Scott Ullrich
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
144 b6e87566 Scott Ullrich
						if($firstfield == "")  {
145
						  $firstfield = $rowhelperfield['fieldname'];
146
						} else {
147
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
148
						}
149 0e730fee Scott Ullrich
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
150 b6e87566 Scott Ullrich
						//echo($comd . "<br>");
151 eec70f21 Scott Ullrich
						eval($comd);
152
						if($value <> "") {
153 b6e87566 Scott Ullrich
							$comd = "\$pkgarr['row'][" . $x . "]['" . $rowhelperfield['fieldname'] . "'] = \"" . $value . "\";";
154
							//echo($comd . "<br>");
155 eec70f21 Scott Ullrich
							eval($comd);
156
						}
157
					}
158
				}
159
			} else {
160
				// simply loop through all field names looking for posted
161 0e730fee Scott Ullrich
				// values matching the fieldnames.  if found, save to package
162
				// configuration area.
163 6778d452 Scott Ullrich
164 eec70f21 Scott Ullrich
				$fieldname  = $fields['fieldname'];
165
				$fieldvalue = $_POST[$fieldname];
166
				$toeval = "\$pkgarr['" . $fieldname . "'] 	= \"" . $fieldvalue . "\";";
167
				eval($toeval);
168
			}
169 b3235baa Scott Ullrich
		}
170 0e730fee Scott Ullrich
171 e3c4b6b7 Scott Ullrich
		if (isset($id) && $a_pkg[$id])
172
			$a_pkg[$id] = $pkgarr;
173
		else
174
			$a_pkg[] = $pkgarr;
175 0e730fee Scott Ullrich
176 b3235baa Scott Ullrich
		write_config();
177 0e730fee Scott Ullrich
178 facd08f9 Scott Ullrich
		// late running code
179 2a520a0a Scott Ullrich
		if($pkg['custom_add_php_command_late'] <> "") {
180
		    eval($pkg['custom_add_php_command_late']);
181
		}
182 0e730fee Scott Ullrich
183 facd08f9 Scott Ullrich
		// resync the configuration file code if defined.
184
		if($pkg['custom_php_resync_config_command'] <> "") {
185
		    eval($pkg['custom_php_resync_config_command']);
186
		}
187
188 dcbe6f52 Scott Ullrich
		parse_package_templates();
189
190 a485a6f5 Scott Ullrich
		/* if start_command is defined, restart w/ this */
191
		if($pkg['start_command'] <> "")
192
		    exec($pkg['start_command'] . ">/dev/null 2&>1");
193
194
		/* if restart_command is defined, restart w/ this */
195
		if($pkg['restart_command'] <> "")
196
		    exec($pkg['restart_command'] . ">/dev/null 2&>1");
197
198 dcbe6f52 Scott Ullrich
		if($pkg['aftersaveredirect'] <> "") {
199
		    header("Location:  " . $pkg['aftersaveredirect']);
200
		} else {
201
		    header("Location:  pkg.php?xml=" . $xml);
202
		}
203 0e730fee Scott Ullrich
		exit;
204 e3c4b6b7 Scott Ullrich
	}
205 da7bf505 Scott Ullrich
}
206
207 d47013e1 Scott Ullrich
?>
208
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
209
<html>
210
<head>
211 64fba011 Scott Ullrich
<?php
212
    if($pkg['title'] <> "") $title = $pkg['title'];
213
?>
214 d47013e1 Scott Ullrich
<title><?=gentitle_pkg($title);?></title>
215
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
216
<link href="gui.css" rel="stylesheet" type="text/css">
217
</head>
218
219
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
220 eec70f21 Scott Ullrich
221
<script type="text/javascript" language="javascript" src="row_helper_dynamic.js">
222
</script>
223
224 d47013e1 Scott Ullrich
<?php
225
$config_tmp = $config;
226
$config = $pfSense_config;
227
include("fbegin.inc");
228
$config = $config_tmp;
229
?>
230
<p class="pgtitle"><?=$title?></p>
231 19fd2947 Scott Ullrich
<form action="pkg_edit.php" method="post">
232
<input type="hidden" name="xml" value="<?= $xml ?>">
233 d47013e1 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
234
235 7c061036 Scott Ullrich
<?php
236
if ($pkg['tabs'] <> "") {
237
    echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
238
    echo "<tr><td>";
239
    echo "  <ul id=\"tabnav\">";
240
    foreach($pkg['tabs']['tab'] as $tab) {
241
	$active = "tabinact";
242
	if(isset($tab['active'])) $active = "tabact";
243 e17ce934 Scott Ullrich
244
	$urltmp = "";
245 3d335c4d Scott Ullrich
	$title = $tab['text'];
246 e17ce934 Scott Ullrich
	if($tab['url'] <> "") $urltmp = $tab['url'];
247
	if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml'];
248
249
	$toeval = "\$myurl = \"" . getenv("HTTP_HOST") . "\"; \n";
250
	eval($toeval);
251
	// eval url so that above $myurl item can be processed if need be.
252
	$toeval = "\$url = \"" . $urltmp . "\"; \n";
253
	eval($toeval);
254
255 3d335c4d Scott Ullrich
	if($active == "tabinact") {
256
	    echo "<li class=\"{$active}\">";
257
	    echo "<a href=\"";
258
	    echo $url;
259
	    echo "\">";
260
	    echo $title;
261
	    echo "</a>";
262
	    echo "</li>";
263
	} else {
264
	    echo "<li class=\"{$active}\">";
265
	    echo $title;
266
	    echo "</li>";
267
	}
268 7c061036 Scott Ullrich
    }
269
    echo "  </ul>";
270
    echo "</td></tr>";
271
    echo "<tr>";
272
    echo "<td class=\"tabcont\">";
273
}
274
?>
275
276 d47013e1 Scott Ullrich
<table width="100%" border="0" cellpadding="6" cellspacing="0">
277
  <?php
278
  $cols = 0;
279 3eaeb703 Scott Ullrich
  $savevalue = "Save";
280
  if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
281
  foreach ($pkg['fields']['field'] as $pkga) { ?>
282 facd08f9 Scott Ullrich
283
	  <?php if(!$pkga['combinefieldsend']) echo "<tr valign=\"top\">"; ?>
284
285 d47013e1 Scott Ullrich
	  <?php
286 facd08f9 Scott Ullrich
	  if(!$pkga['dontdisplayname']) {
287 31d27c6c Scott Ullrich
		echo "<td width=\"22%\" class=\"vncellreq\">";
288 d51f86e0 Scott Ullrich
		echo fixup_string($pkga['fielddescr']);
289 31d27c6c Scott Ullrich
		echo "</td>";
290 facd08f9 Scott Ullrich
	  }
291
292
	  if(!$pkga['dontcombinecells'])
293
		echo "<td class=\"vtable\">";
294 3eaeb703 Scott Ullrich
295 31d27c6c Scott Ullrich
		// if user is editing a record, load in the data.
296
		if (isset($id) && $a_pkg[$id]) {
297
			$fieldname = $pkga['fieldname'];
298
			$toeval = "\$value = \$a_pkg[" . $id . "]['" . $fieldname . "'];";
299
			echo "<!-- eval: " . $toeval . "-->\n";
300
			eval($toeval);
301
		}
302
303 3eaeb703 Scott Ullrich
	      if($pkga['type'] == "input") {
304 b6e87566 Scott Ullrich
			if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
305
			echo "<input " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
306 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
307 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "password") {
308 b6e87566 Scott Ullrich
			echo "<input type='password' " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
309 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
310 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "select") {
311 d47013e1 Scott Ullrich
		  // XXX: TODO: set $selected
312 3eaeb703 Scott Ullrich
                  if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
313
		  if($pkga['multiple'] == "yes") $multiple = "MULTIPLE ";
314 2c634bdd Scott Ullrich
		    echo "<select " . $multiple . $size . "id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "'>\n";
315
		    foreach ($pkga['options']['option'] as $opt) {
316
			  $selected = "";
317
			  if($opt['value'] == $value) $selected = " SELECTED";
318
			  echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'" . $selected . ">" . $opt['name'] . "</option>\n";
319
		    }
320
		    echo "</select>\n";
321
		    echo "<br>" . fixup_string($pkga['description']) . "\n";
322
	      } else if($pkga['type'] == "vpn_selection") {
323
		    echo "<select name='" . $vpn['name'] . "'>\n";
324
		    foreach ($config['ipsec']['tunnel'] as $vpn) {
325
			echo "\t<option value=\"" . $vpn['descr'] . "\">" . $vpn['descr'] . "</option>\n";
326
		    }
327
		    echo "</select>\n";
328 03f0bfe7 Scott Ullrich
		    echo "<br>" . fixup_string($pkga['description']) . "\n";
329 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "checkbox") {
330 64c1ebbb Scott Ullrich
			$checkboxchecked = "";
331 34865da0 Scott Ullrich
			if($value == "on") $checkboxchecked = " CHECKED";
332 64c1ebbb Scott Ullrich
			echo "<input type='checkbox' name='" . $pkga['fieldname'] . "'" . $checkboxchecked . ">\n";
333 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
334 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "textarea") {
335
		  if($pkga['rows']) $rows = " rows='" . $pkga['rows'] . "' ";
336
		  if($pkga['cols']) $cols = " cols='" . $pkga['cols'] . "' ";
337 b6e87566 Scott Ullrich
			echo "<textarea " . $rows . $cols . " name='" . $pkga['fieldname'] . "'>" . $value . "</textarea>\n";
338 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
339 ab73789e Scott Ullrich
		  } else if($pkga['type'] == "interfaces_selection") {
340 76584e25 Scott Ullrich
			$size = "";
341 7502342a Scott Ullrich
			$multiple = "";
342
			$fieldname = $pkga['fieldname'];
343 76584e25 Scott Ullrich
			if($pkga['size'] <> "") $size = " size=\"" . $pkga['size'] . "\"";
344 d6a84c31 Scott Ullrich
			if($pkga['multiple'] <> "" and $pkga['multiple'] <> "0") {
345 7502342a Scott Ullrich
			  $multiple = " multiple=\"multiple\"";
346
			  $fieldname .= "[]";
347
			}
348
			echo "<select name='" . $fieldname . "'" . $size . $multiple . ">\n";
349 ab73789e Scott Ullrich
			foreach ($config['interfaces'] as $ifname => $iface) {
350
			  if ($iface['descr'])
351
				  $ifdescr = $iface['descr'];
352
			  else
353
				  $ifdescr = strtoupper($ifname);
354 378f7d3a Scott Ullrich
			  $ifname = $iface['if'];
355
			  $SELECTED = "";
356
			  if($value == $ifname) $SELECTED = " SELECTED";
357 4831ce13 Scott Ullrich
			  echo "<option value='" . $ifdescr . "'" . $SELECTED . ">" . $ifdescr . "</option>\n";
358 ab73789e Scott Ullrich
			}
359
			echo "</select>\n";
360 03f0bfe7 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
361 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "radio") {
362 b6e87566 Scott Ullrich
			echo "<input type='radio' name='" . $pkga['fieldname'] . "' value='" . $value . "'>";
363 eec70f21 Scott Ullrich
	      } else if($pkga['type'] == "rowhelper") {
364
		?>
365
			<script type="text/javascript" language='javascript'>
366
			<!--
367 0e730fee Scott Ullrich
368 eec70f21 Scott Ullrich
			<?php
369
				$rowcounter = 0;
370
				$fieldcounter = 0;
371
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
372
					echo "rowname[" . $fieldcounter . "] = \"" . $rowhelper['fieldname'] . "\";\n";
373
					echo "rowtype[" . $fieldcounter . "] = \"" . $rowhelper['type'] . "\";\n";
374
					$fieldcounter++;
375
				}
376
			?>
377 0e730fee Scott Ullrich
378 eec70f21 Scott Ullrich
			-->
379
			</script>
380 0e730fee Scott Ullrich
381 eec70f21 Scott Ullrich
			<table name="maintable" id="maintable">
382 b6e87566 Scott Ullrich
			<tr>
383 eec70f21 Scott Ullrich
			<?php
384 31d27c6c Scott Ullrich
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
385 d51f86e0 Scott Ullrich
				  echo "<td><b>" . fixup_string($rowhelper['fielddescr']) . "</td>\n";
386 31d27c6c Scott Ullrich
				}
387 b6e87566 Scott Ullrich
				echo "</tr>";
388
				echo "<tbody>";
389
390 eec70f21 Scott Ullrich
				echo "<tr>";
391
				  // XXX: traverse saved fields, add back needed rows.
392
				echo "</tr>";
393 0e730fee Scott Ullrich
394 31d27c6c Scott Ullrich
				echo "<tr>\n";
395
				$rowcounter = 0;
396
				$trc = 0;
397
				if(isset($a_pkg[$id]['row'])) {
398
					foreach($a_pkg[$id]['row'] as $row) {
399
					/*
400
					 * loop through saved data for record if it exists, populating rowhelper
401 bb940538 Scott Ullrich
					 */
402 31d27c6c Scott Ullrich
						foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
403
							if($rowhelper['value'] <> "") $value = $rowhelper['value'];
404
							$fieldname = $rowhelper['fieldname'];
405
							// if user is editing a record, load in the data.
406 bb940538 Scott Ullrich
							if (isset($id) && $a_pkg[$id]) {
407 31d27c6c Scott Ullrich
								$toeval = "\$value = \$row['" . $fieldname . "'];";
408
								echo "<!-- eval: " . $toeval . "-->\n";
409
								eval($toeval);
410
								echo "<!-- value: " . $value . "-->\n";
411 bb940538 Scott Ullrich
							}
412 31d27c6c Scott Ullrich
							$options = "";
413
							$type = $rowhelper['type'];
414
							$fieldname = $rowhelper['fieldname'];
415
							if($type == "option") $options = &$rowhelper['options']['option'];
416 e70e0b76 Scott Ullrich
							$size = "8";
417
							if($rowhelper['size'] <> "") $size = $rowhelper['size'];
418
							display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
419 bb940538 Scott Ullrich
							// javascript helpers for row_helper_dynamic.js
420
							echo "</td>\n";
421
							echo "<script language=\"JavaScript\">\n";
422
							echo "<!--\n";
423
							echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
424
							echo "-->\n";
425
							echo "</script>\n";
426
							$text = "";
427
							$trc++;
428 eec70f21 Scott Ullrich
						}
429 bb940538 Scott Ullrich
430 31d27c6c Scott Ullrich
						$rowcounter++;
431
						echo "<td>";
432
						echo "<input type=\"image\" src=\"/x.gif\" onclick=\"removeRow(this); return false;\" value=\"Delete\">";
433 eec70f21 Scott Ullrich
						echo "</td>\n";
434 31d27c6c Scott Ullrich
						echo "</tr>\n";
435
					}
436
				}
437
				if($trc == 0) {
438
					/*
439
					 *  no records loaded.
440
                                         *  just show a generic line non-populated with saved data
441
                                         */
442
                                        foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
443
						if($rowhelper['value'] <> "") $value = $rowhelper['value'];
444 bb940538 Scott Ullrich
						$fieldname = $rowhelper['fieldname'];
445 31d27c6c Scott Ullrich
						$options = "";
446
						$type = $rowhelper['type'];
447
						$fieldname = $rowhelper['fieldname'];
448
						if($type == "option") $options = &$rowhelper['options']['option'];
449 e70e0b76 Scott Ullrich
						$size = "8";
450
						if($rowhelper['size'] <> "") $size = $rowhelper['size'];
451
						display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
452 bb940538 Scott Ullrich
						// javascript helpers for row_helper_dynamic.js
453
						echo "</td>\n";
454
						echo "<script language=\"JavaScript\">\n";
455
						echo "<!--\n";
456
						echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
457
						echo "-->\n";
458
						echo "</script>\n";
459
						$text = "";
460 eec70f21 Scott Ullrich
						$trc++;
461
					}
462 bb940538 Scott Ullrich
463
					$rowcounter++;
464 eec70f21 Scott Ullrich
				}
465
			?>
466 0e730fee Scott Ullrich
467 eec70f21 Scott Ullrich
			  </tbody>
468
			</table>
469 0e730fee Scott Ullrich
470 e02a6839 Scott Ullrich
		<br><a onClick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="/plus.gif"></a>
471 eec70f21 Scott Ullrich
		<script language="JavaScript">
472
		<!--
473
		field_counter_js = <?= $fieldcounter ?>;
474
		rows = <?= $rowcounter ?>;
475
		totalrows = <?php echo $rowcounter; ?>;
476
		loaded = <?php echo $rowcounter; ?>;
477 e02a6839 Scott Ullrich
		//typesel_change();
478 eec70f21 Scott Ullrich
		//-->
479
		</script>
480
481
		<?php
482 d47013e1 Scott Ullrich
	      }
483 3eaeb703 Scott Ullrich
	      if($pkga['typehint']) echo " " . $pkga['typehint'];
484 facd08f9 Scott Ullrich
	     ?>
485
486 d47013e1 Scott Ullrich
      <?php
487 facd08f9 Scott Ullrich
	  if(!$pkga['combinefieldsbegin']) echo "</td></tr>";
488 d47013e1 Scott Ullrich
      $i++;
489
  }
490
 ?>
491 b6e87566 Scott Ullrich
  <tr>
492
	<td>&nbsp;</td>
493
  </tr>
494 d47013e1 Scott Ullrich
  <tr>
495
    <td width="22%" valign="top">&nbsp;</td>
496
    <td width="78%">
497 3eaeb703 Scott Ullrich
      <input name="Submit" type="submit" class="formbtn" value="<?= $savevalue ?>">
498 d47013e1 Scott Ullrich
      <?php if (isset($id) && $a_pkg[$id]): ?>
499
      <input name="id" type="hidden" value="<?=$id;?>">
500
      <?php endif; ?>
501
    </td>
502
  </tr>
503
</table>
504
505 7c061036 Scott Ullrich
<?php
506
if ($pkg['tabs'] <> "") {
507
    echo "</td></tr></table>";
508
}
509
?>
510
511 d47013e1 Scott Ullrich
</form>
512
<?php include("fend.inc"); ?>
513
</body>
514
</html>
515
516 31d27c6c Scott Ullrich
<?php
517
518
/*
519
 * ROW Helpers function
520
 */
521 e70e0b76 Scott Ullrich
function display_row($trc, $value, $fieldname, $type, $rowhelper, $size) {
522 bb940538 Scott Ullrich
	global $text;
523 31d27c6c Scott Ullrich
	echo "<td>\n";
524
	if($type == "input") {
525 e70e0b76 Scott Ullrich
		echo "<input size='" . $size . "' name='" . $fieldname . $trc . "' value='" . $value . "'>\n";
526 31d27c6c Scott Ullrich
	} else if($type == "password") {
527 e70e0b76 Scott Ullrich
		echo "<input size='" . $size . "' type='password' name='" . $fieldname . $trc . "' value='" . $value . "'>\n";
528 31d27c6c Scott Ullrich
	} else if($type == "textarea") {
529 e70e0b76 Scott Ullrich
		echo "<textarea rows='2' cols='12' name='" . $fieldname . $trc . "'>" . $value . "</textarea>\n";
530 31d27c6c Scott Ullrich
	} else if($type == "select") {
531
		echo "<select name='" . $fieldname . $trc . "'>\n";
532
		foreach($rowhelper['options']['option'] as $rowopt) {
533
			$selected = "";
534
			if($rowopt['value'] == $value) $selected = " SELECTED";
535
			$text .= "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>";
536
			echo "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>\n";
537
		}
538
		echo "</select>\n";
539
	}
540
}
541
542 d51f86e0 Scott Ullrich
function fixup_string($string) {
543 d2133701 Scott Ullrich
	global $config;
544 d51f86e0 Scott Ullrich
	// fixup #1: $myurl -> http[s]://ip_address:port/
545
	$https = "";
546
	$port = "";
547
	$urlport = "";
548
	$port = $config['system']['webguiport'];
549
	if($port <> "443" and $port <> "80") $urlport = ":" . $port;
550
	if($config['system']['webguiproto'] == "https") $https = "s";
551
	$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlportport;
552
	$newstring = str_replace("\$myurl", $myurl, $string);
553 d2133701 Scott Ullrich
	$string = $newstring;
554
	// fixup #2: $wanip
555
	$curwanip = get_current_wan_address();
556
	$newstring = str_replace("\$wanip", $curwanip, $string);
557
	$string = $newstring;
558
	// fixup #3: $lanip
559
	$lancfg = $config['interfaces']['lan'];
560
	$lanip = $lancfg['ipaddr'];
561
	$newstring = str_replace("\$lanip", $lanip, $string);
562
	$string = $newstring;
563
	// fixup #4: fix'r'up here.
564 d51f86e0 Scott Ullrich
	return $newstring;
565
}
566
567 dcbe6f52 Scott Ullrich
/*
568
 *  Parse templates if they are defined
569
 */
570
function parse_package_templates() {
571
	global $pkg, $config;
572
	if($pkg['templates']['template'] <> "")
573
	    foreach($pkg['templates']['template'] as $pkg_template_row) {
574
		$filename = $pkg_template_row['filename'];
575
		$template_text = $pkg_template_row['templatecontents'];
576
577
		/* calculate total row helpers count */
578
		foreach ($pkg['fields']['field'] as $fields) {
579
			if($fields['type'] == "rowhelper") {
580
				// save rowhelper items.
581
                                $row_helper_total_rows = 0;
582
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
583
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
584
						if($firstfield == "")  {
585
						  $firstfield = $rowhelperfield['fieldname'];
586
						} else {
587
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
588
						}
589
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
590
						eval($comd);
591
						if($value <> "") {
592
						    //$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
593
						} else {
594
						    $row_helper_total_rows = $rows;
595
						    break;
596
						}
597
					}
598
				}
599
			}
600
		}
601
602
		/* replace $domain_total_rows with total rows */
603
		$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
604
605
		/* change fields defined as fieldname_fieldvalue to their value */
606
		foreach ($pkg['fields']['field'] as $fields) {
607
			if($fields['type'] == "rowhelper") {
608
				// save rowhelper items.
609
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
610
					$row_helper_data = "";
611 1be00369 Scott Ullrich
					$isfirst = 0;
612 dcbe6f52 Scott Ullrich
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
613
						if($firstfield == "")  {
614
						  $firstfield = $rowhelperfield['fieldname'];
615
						} else {
616
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
617
						}
618
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
619
						eval($comd);
620
						if($value <> "") {
621 1be00369 Scott Ullrich
						    if($isfirst == 1) $row_helper_data .= "  " ;
622
						    $row_helper_data .= $value;
623
						    $isfirst = 1;
624 dcbe6f52 Scott Ullrich
						}
625
						ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
626
						foreach ($sep as $se) $seperator = $se;
627
						if($seperator <> "") {
628
						    $row_helper_data = ereg_replace("  ", $seperator, $row_helper_data);
629
						    $template_text = ereg_replace("\[" . $seperator . "\]", "", $template_text);
630
						}
631
						$template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
632
					}
633
				}
634
			} else {
635
				$fieldname  = $fields['fieldname'];
636
				$fieldvalue = $_POST[$fieldname];
637
				$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
638
			}
639
		}
640
641
		/* replace cr's */
642
		$template_text = str_replace("\\n", "\n", $template_text);
643
644
		/* write out new template file */
645
		$fout = fopen($filename,"w");
646
		fwrite($fout, $template_text);
647
		fclose($fout);
648
	    }
649
}
650
651 31d27c6c Scott Ullrich
?>