Project

General

Profile

Download (24.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
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
*/
29

    
30
require_once("guiconfig.inc");
31
require_once("pkg-utils.inc");
32

    
33
/* dummy stubs needed by some code that was MFC'd */
34
function pfSenseHeader($location) { header("Location: $location"); }
35

    
36
function gentitle_pkg($pgname) {
37
	global $pfSense_config;
38
	return $pfSense_config['system']['hostname'] . "." . $pfSense_config['system']['domain'] . " - " . $pgname;
39
}
40

    
41
$xml = htmlspecialchars($_GET['xml']);
42
if($_POST['xml']) $xml = htmlspecialchars($_POST['xml']);
43

    
44
if($xml == "") {
45
            print_info_box_np(gettext("ERROR: No package defined."));
46
            die;
47
} else {
48
            $pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
49
}
50

    
51
if($pkg['include_file'] <> "") {
52
	require_once($pkg['include_file']);
53
}
54

    
55
if (!isset($pkg['adddeleteeditpagefields']))
56
	$only_edit = true;
57
else
58
	$only_edit = false;
59

    
60
$package_name = $pkg['menu'][0]['name'];
61
$section      = $pkg['menu'][0]['section'];
62
$config_path  = $pkg['configpath'];
63
$name         = $pkg['name'];
64
$title        = $pkg['title'];
65
$pgtitle      = $title;
66

    
67
$id = $_GET['id'];
68
if (isset($_POST['id']))
69
	$id = htmlspecialchars($_POST['id']);
70

    
71
if($pkg['custom_php_global_functions'] <> "")
72
        eval($pkg['custom_php_global_functions']);
73

    
74
// grab the installedpackages->package_name section.
75
if(!is_array($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']))
76
	$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'] = array();
77

    
78
$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
79

    
80
if($_GET['savemsg'] <> "")
81
	$savemsg = htmlspecialchars($_GET['savemsg']);
82

    
83
if($pkg['custom_php_command_before_form'] <> "")
84
	eval($pkg['custom_php_command_before_form']);
85

    
86
if ($_POST) {
87
	if($_POST['act'] == "del") {
88
		if($pkg['custom_delete_php_command']) {
89
		    if($pkg['custom_php_command_before_form'] <> "")
90
			    eval($pkg['custom_php_command_before_form']);
91
		    eval($pkg['custom_delete_php_command']);
92
		}
93
		write_config($pkg['delete_string']);
94
		// resync the configuration file code if defined.
95
		if($pkg['custom_php_resync_config_command'] <> "") {
96
			if($pkg['custom_php_command_before_form'] <> "")
97
				eval($pkg['custom_php_command_before_form']);
98
			eval($pkg['custom_php_resync_config_command']);
99
		}
100
	} else {
101
		if($pkg['custom_add_php_command']) {
102
			if($pkg['donotsave'] <> "" or $pkg['preoutput'] <> "") {
103
			?>
104

    
105
<?php include("head.inc"); ?>
106
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
107
<?php include("fbegin.inc"); ?>
108
<?php
109
			}
110
			if($pkg['preoutput']) echo "<pre>";
111
			eval($pkg['custom_add_php_command']);
112
			if($pkg['preoutput']) echo "</pre>";
113
		}
114
	}
115

    
116
	// donotsave is enabled.  lets simply exit.
117
	if($pkg['donotsave'] <> "") exit;
118

    
119
	$firstfield = "";
120
	$rows = 0;
121

    
122
	$input_errors = array();
123
	$reqfields = array();
124
	$reqfieldsn = array();
125
	foreach ($pkg['fields']['field'] as $field) {
126
		if (($field['type'] == 'input') && isset($field['required'])) {
127
			$reqfields[] = $field['fieldname'];
128
			$reqfieldsn[] = $field['fielddescr'];
129
		}
130
	}
131
	do_input_validation($_POST, $reqfields, $reqfieldsn, &$input_errors);
132

    
133
	if ($pkg['custom_php_validation_command'])
134
		eval($pkg['custom_php_validation_command']);
135

    
136
	// store values in xml configration file.
137
	if (!$input_errors) {
138
		$pkgarr = array();
139
		foreach ($pkg['fields']['field'] as $fields) {
140
			if($fields['type'] == "rowhelper") {
141
				// save rowhelper items.
142
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
143
				                         // XXX: this really is not helping embedded platforms.
144
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
145
						if($firstfield == "")  {
146
						  $firstfield = $rowhelperfield['fieldname'];
147
						} else {
148
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
149
						}
150
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
151
						eval($comd);
152
						if($value <> "") {
153
							$comd = "\$pkgarr['row'][" . $x . "]['" . $rowhelperfield['fieldname'] . "'] = \"" . $value . "\";";
154
							//echo($comd . "<br>");
155
							eval($comd);
156
						}
157
					}
158
				}
159
			} else {
160
				$fieldname  = $fields['fieldname'];
161
				$fieldvalue = $_POST[$fieldname];
162
				if (is_array($fieldvalue))
163
					$fieldvalue = implode(',', $fieldvalue);
164
				else {
165
					$fieldvalue = trim($fieldvalue);
166
					if ($fields['encoding'] == 'base64')
167
						$fieldvalue = base64_encode($fieldvalue);
168
				}
169
				$pkgarr[$fieldname] = $fieldvalue;
170
			}
171
		}
172

    
173
		if (isset($id) && $a_pkg[$id])
174
			$a_pkg[$id] = $pkgarr;
175
		else
176
			$a_pkg[] = $pkgarr;
177

    
178
		write_config($pkg['addedit_string']);
179

    
180
		// late running code
181
		if($pkg['custom_add_php_command_late'] <> "") {
182
		    eval($pkg['custom_add_php_command_late']);
183
		}
184

    
185
		// resync the configuration file code if defined.
186
		if($pkg['custom_php_resync_config_command'] <> "") {
187
		    eval($pkg['custom_php_resync_config_command']);
188
		}
189

    
190
		parse_package_templates();
191

    
192
		/* if start_command is defined, restart w/ this */
193
		if($pkg['start_command'] <> "")
194
		    exec($pkg['start_command'] . ">/dev/null 2&>1");
195

    
196
		/* if restart_command is defined, restart w/ this */
197
		if($pkg['restart_command'] <> "")
198
		    exec($pkg['restart_command'] . ">/dev/null 2&>1");
199

    
200
		if($pkg['aftersaveredirect'] <> "") {
201
		    pfSenseHeader($pkg['aftersaveredirect']);
202
		} elseif(!$pkg['adddeleteeditpagefields']) {
203
		    pfSenseHeader("pkg_edit.php?xml={$xml}&id=0");
204
		} elseif(!$pkg['preoutput']) {
205
		    pfSenseHeader("pkg.php?xml=" . $xml);
206
		}
207
		exit;
208
	}
209
	else
210
		$get_from_post = true;
211
}
212

    
213
if($pkg['title'] <> "") {
214
	$edit = ($only_edit ? '' : ': Edit');
215
	$title = $pkg['title'] . $edit;
216
}
217
else
218
	$title = gettext("Package Editor");
219

    
220
$pgtitle = $title;
221
include("head.inc");
222

    
223
if ($pkg['custom_php_after_head_command'])
224
	eval($pkg['custom_php_after_head_command']);
225

    
226
?>
227

    
228
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onLoad="enablechange();">
229
<?php if($pkg['fields']['field'] <> "") { ?>
230
<script language="JavaScript">
231
<!--
232
function enablechange() {
233
<?php
234
foreach ($pkg['fields']['field'] as $field) {
235
	if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
236
		print("\tif (document.iform.elements[\"{$field['fieldname']}\"].checked == false) {\n");
237

    
238
		if (isset($field['enablefields'])) {
239
			foreach (explode(',', $field['enablefields']) as $enablefield)
240
				print("\t\tdocument.iform.elements[\"$enablefield\"].disabled = 1;\n");
241
		}
242

    
243
		if (isset($field['checkenablefields'])) {
244
			foreach (explode(',', $field['checkenablefields']) as $checkenablefield)
245
				print("\t\tdocument.iform.elements[\"$checkenablefield\"].checked = 0;\n");
246
		}
247

    
248
		print("\t}\n\telse {\n");
249

    
250
		if (isset($field['enablefields'])) {
251
			foreach (explode(',', $field['enablefields']) as $enablefield)
252
				print("\t\tdocument.iform.elements[\"$enablefield\"].disabled = 0;\n");
253
		}
254

    
255
		if (isset($field['checkenablefields'])) {
256
			foreach(explode(',', $field['checkenablefields']) as $checkenablefield)
257
				print("\t\tdocument.iform.elements[\"$checkenablefield\"].checked = 1;\n");
258
		}
259

    
260
		print("\t}\n");
261
	}
262
}
263
?>
264
}
265
//-->
266
</script>
267
<?php } ?>
268
<script type="text/javascript" language="javascript" src="row_helper_dynamic.js">
269
</script>
270

    
271
<?php include("fbegin.inc"); ?>
272
<?php if (!empty($input_errors)) print_input_errors($input_errors); ?>
273
<form name="iform" action="pkg_edit.php" method="post">
274
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
275
<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
276
<input type="hidden" name="xml" value="<?= $xml ?>">
277
<?php if ($savemsg) print_info_box($savemsg); ?>
278
<table width="100%" border="0" cellpadding="0" cellspacing="0">
279
<?php
280
if ($pkg['tabs'] <> "") {
281
    echo '<tr><td>';
282
    $tab_array = array();
283
    foreach($pkg['tabs']['tab'] as $tab) {
284
	if(isset($tab['active'])) {
285
		$active = true;
286
	} else {
287
		$active = false;
288
	}
289
	$urltmp = "";
290
	if($tab['url'] <> "") $urltmp = $tab['url'];
291
	if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml'];
292

    
293
 	$addresswithport = getenv("HTTP_HOST");
294
	$colonpos = strpos($addresswithport, ":");
295
	if ($colonpos !== False){
296
		//my url is actually just the IP address of the pfsense box
297
		$myurl = substr($addresswithport, 0, $colonpos);
298
	}
299
	else
300
	{
301
		$myurl = $addresswithport;
302
	}
303
	// eval url so that above $myurl item can be processed if need be.
304
	$url = str_replace('$myurl', $myurl, $urltmp);
305

    
306
	$tab_array[] = array(
307
				$tab['text'],
308
				$active,
309
				$url
310
			);
311
    }
312
    display_top_tabs($tab_array);
313
    echo '</td></tr>';
314
}
315
?>
316
<tr><td><div id="mainarea"><table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
317
  <?php
318
  $cols = 0;
319
  $savevalue = gettext("Save");
320
  if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
321
  foreach ($pkg['fields']['field'] as $pkga) { ?>
322

    
323
	  <?php if(!$pkga['combinefieldsend']) echo "<tr valign=\"top\">"; ?>
324

    
325
	  <?php
326

    
327
	  $size = "";
328

    
329
	  if(!$pkga['dontdisplayname']) {
330
		unset($req);
331
		if (isset($pkga['required']))
332
			$req = 'req';
333
		echo "<td width=\"22%\" class=\"vncell{$req}\">";
334
		echo fixup_string($pkga['fielddescr']);
335
		echo "</td>";
336
	  }
337

    
338
	  if(!$pkga['dontcombinecells'])
339
		echo "<td class=\"vtable\">";
340
		// if user is editing a record, load in the data.
341
		$fieldname = $pkga['fieldname'];
342
		if ($get_from_post) {
343
			$value = $_POST[$fieldname];
344
			if (is_array($value)) $value = implode(',', $value);
345
		}
346
		else {
347
			if (isset($id) && $a_pkg[$id])
348
				$value = $a_pkg[$id][$fieldname];
349
			else
350
				$value = $pkga['default_value'];
351
		}
352

    
353
	      if($pkga['type'] == "input") {
354
			if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
355
			echo "<input " . $size . " id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
356
			echo "<br>" . fixup_string($pkga['description']) . "\n";
357
	      } else if($pkga['type'] == "password") {
358
			echo "<input id='" . $pkga['fieldname'] . "' type='password' " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
359
			echo "<br>" . fixup_string($pkga['description']) . "\n";
360
	      } else if($pkga['type'] == "select") {
361
                  $fieldname = $pkga['fieldname'];
362
                  if (isset($pkga['multiple'])) {
363
                    $multiple = 'multiple="multiple"';
364
                    $items = explode(',', $value);
365
                    $fieldname .= "[]";
366
                  }
367
                  else {
368
                    $multiple = '';
369
                    $items = array($value);
370
                  }
371
                  $size = (isset($pkga['size']) ? "size=\"{$pkga['size']}\"" : '');
372
                  $onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
373

    
374
                  print("<select id='" . $pkga['fieldname'] . "' $multiple $size $onchange id=\"$fieldname\" name=\"$fieldname\">\n");
375
                  foreach ($pkga['options']['option'] as $opt) {
376
                      $selected = '';
377
                      if (in_array($opt['value'], $items)) $selected = 'selected="selected"';
378
                      print("\t<option name=\"{$opt['name']}\" value=\"{$opt['value']}\" $selected>{$opt['name']}</option>\n");
379
                  }
380

    
381
                  print("</select>\n<br />\n" . fixup_string($pkga['description']) . "\n");
382
	      } else if($pkga['type'] == "vpn_selection") {
383
		    echo "<select id='" . $pkga['fieldname'] . "' name='" . $vpn['name'] . "'>\n";
384
		    foreach ($config['ipsec']['phase1'] as $vpn) {
385
			echo "\t<option value=\"" . $vpn['descr'] . "\">" . $vpn['descr'] . "</option>\n";
386
		    }
387
		    echo "</select>\n";
388
		    echo "<br>" . fixup_string($pkga['description']) . "\n";
389
	      } else if($pkga['type'] == "checkbox") {
390
			$checkboxchecked = "";
391
			if($value == "on") $checkboxchecked = " CHECKED";
392
			if (isset($pkga['enablefields']) || isset($pkga['checkenablefields']))
393
				$onclick = ' onclick="javascript:enablechange();"';
394
			echo "<input id='" . $pkga['fieldname'] . "' type='checkbox' name='" . $pkga['fieldname'] . "'" . $checkboxchecked . $onclick . ">\n";
395
			echo "<br>" . fixup_string($pkga['description']) . "\n";
396
	      } else if($pkga['type'] == "textarea") {
397
		  if($pkga['rows']) $rows = " rows='" . $pkga['rows'] . "' ";
398
		  if($pkga['cols']) $cols = " cols='" . $pkga['cols'] . "' ";
399
                  if (($pkga['encoding'] == 'base64') && !$get_from_post && !empty($value)) $value = base64_decode($value);
400
			echo "<textarea " . $rows . $cols . " name='" . $pkga['fieldname'] . "'>" . $value . "</textarea>\n";
401
			echo "<br>" . fixup_string($pkga['description']) . "\n";
402
		  } else if($pkga['type'] == "interfaces_selection") {
403
			$size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
404
			$multiple = '';
405
			$fieldname = $pkga['fieldname'];
406
			if (isset($pkga['multiple'])) {
407
				$fieldname .= '[]';
408
				$multiple = 'multiple';
409
			}
410
			print("<select id='" . $pkga['fieldname'] . "' name=\"$fieldname\" $size $multiple>\n");
411

    
412
			if (isset($pkga['all_interfaces']))
413
				$ifaces = explode(' ', trim(shell_exec('ifconfig -l')));
414
			else
415
				$ifaces = $config['interfaces'];
416

    
417
			$additional_ifaces = $pkga['add_to_interfaces_selection'];
418
			if (!empty($additional_ifaces))
419
				$ifaces = array_merge($ifaces, explode(',', $additional_ifaces));
420
			if(is_array($value))
421
				$values = $value;
422
			else
423
				$values  =  explode(',',  $value);
424

    
425
			foreach($ifaces as $ifname => $iface) {
426
				if (isset($iface['descr']))
427
					$ifdescr = $iface['descr'];
428
				else
429
					$ifdescr = strtoupper($ifname);
430
				if ($ip = find_interface_ip($iface))
431
					$ip = " ($ip)";
432
				$selected = (in_array($ifname, $values) ? 'selected' : '');
433
				print("<option value=\"$ifname\" $selected>$ifdescr</option>\n");
434
			}
435

    
436
			print("</select>\n<br />" . fixup_string($pkga['description']) . "\n");
437
	      } else if($pkga['type'] == "radio") {
438
			echo "<input type='radio' id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "' value='" . $value . "'>";
439
	      } else if($pkga['type'] == "rowhelper") {
440
		?>
441
			<script type="text/javascript" language='javascript'>
442
			<!--
443

    
444
			<?php
445
				$rowcounter = 0;
446
				$fieldcounter = 0;
447
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
448
					echo "rowname[" . $fieldcounter . "] = \"" . $rowhelper['fieldname'] . "\";\n";
449
					echo "rowtype[" . $fieldcounter . "] = \"" . $rowhelper['type'] . "\";\n";
450
					$fieldcounter++;
451
				}
452
			?>
453

    
454
			-->
455
			</script>
456

    
457
			<table name="maintable" id="maintable">
458
			<tr>
459
			<?php
460
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
461
				  echo "<td><b>" . fixup_string($rowhelper['fielddescr']) . "</td>\n";
462
				}
463
				echo "</tr>";
464

    
465
				echo "<tr>";
466
				  // XXX: traverse saved fields, add back needed rows.
467
				echo "</tr>";
468

    
469
				echo "<tr>\n";
470
				$rowcounter = 0;
471
				$trc = 0;
472
				if(isset($a_pkg[$id]['row'])) {
473
					foreach($a_pkg[$id]['row'] as $row) {
474
					/*
475
					 * loop through saved data for record if it exists, populating rowhelper
476
					 */
477
						foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
478
							if($rowhelper['value'] <> "") $value = $rowhelper['value'];
479
							$fieldname = $rowhelper['fieldname'];
480
							// if user is editing a record, load in the data.
481
							if (isset($id) && $a_pkg[$id]) {
482
								$value = $row[$fieldname];
483
							}
484
							$options = "";
485
							$type = $rowhelper['type'];
486
							$fieldname = $rowhelper['fieldname'];
487
							if($type == "option") $options = &$rowhelper['options']['option'];
488
							$size = "8";
489
							if($rowhelper['size'] <> "") $size = $rowhelper['size'];
490
							display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
491
							// javascript helpers for row_helper_dynamic.js
492
							echo "</td>\n";
493
							echo "<script language=\"JavaScript\">\n";
494
							echo "<!--\n";
495
							echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
496
							echo "-->\n";
497
							echo "</script>\n";
498
							$text = "";
499
							$trc++;
500
						}
501

    
502
						$rowcounter++;
503
						echo "<td>";
504
						echo "<input type=\"image\" src=\"./themes/".$g['theme']."/images/icons/icon_x.gif\" onclick=\"removeRow(this); return false;\" value=\"" . gettext("Delete") . "\">";
505
						echo "</td>\n";
506
						echo "</tr>\n";
507
					}
508
				}
509
				if($trc == 0) {
510
					/*
511
					 *  no records loaded.
512
                                         *  just show a generic line non-populated with saved data
513
                                         */
514
                                        foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
515
						if($rowhelper['value'] <> "") $value = $rowhelper['value'];
516
						$fieldname = $rowhelper['fieldname'];
517
						$options = "";
518
						$type = $rowhelper['type'];
519
						$fieldname = $rowhelper['fieldname'];
520
						if($type == "option") $options = &$rowhelper['options']['option'];
521
						$size = "8";
522
						if($rowhelper['size'] <> "") $size = $rowhelper['size'];
523
						display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
524
						// javascript helpers for row_helper_dynamic.js
525
						echo "</td>\n";
526
						echo "<script language=\"JavaScript\">\n";
527
						echo "<!--\n";
528
						echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
529
						echo "-->\n";
530
						echo "</script>\n";
531
						$text = "";
532
						$trc++;
533
					}
534

    
535
					$rowcounter++;
536
				}
537
			?>
538

    
539
			  <tbody></tbody>
540
			</table>
541

    
542
		<br><a onClick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif"></a>
543
		<script language="JavaScript">
544
		<!--
545
		field_counter_js = <?= $fieldcounter ?>;
546
		rows = <?= $rowcounter ?>;
547
		totalrows = <?php echo $rowcounter; ?>;
548
		loaded = <?php echo $rowcounter; ?>;
549
		//typesel_change();
550
		//-->
551
		</script>
552

    
553
		<?php
554
	      }
555
	      if($pkga['typehint']) echo " " . $pkga['typehint'];
556
	     ?>
557

    
558
      <?php
559
	  if(!$pkga['combinefieldsbegin']) echo "</td></tr>";
560
      $i++;
561
  }
562
 ?>
563
  <tr>
564
	<td>&nbsp;</td>
565
  </tr>
566
  <tr>
567
    <td width="22%" valign="top">&nbsp;</td>
568
    <td width="78%">
569
<?php
570
if($pkg['note'] != "")
571
	print("<p><span class=\"red\"><strong>" . gettext("Note") . ":</strong></span> {$pkg['note']}</p>");
572
//if (isset($id) && $a_pkg[$id]) // We'll always have a valid ID in our hands
573
      print("<input name=\"id\" type=\"hidden\" value=\"$id\">");
574
?>
575
      <input name="Submit" type="submit" class="formbtn" value="<?= $savevalue ?>">
576
<?php if (!$only_edit): ?>
577
      <input class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()">
578
<?php endif; ?>
579
    </td>
580
  </tr>
581
</table>
582
</div></tr></td></table>
583
</form>
584

    
585
<?php if ($pkg['custom_php_after_form_command']) eval($pkg['custom_php_after_form_command']); ?>
586

    
587
<?php include("fend.inc"); ?>
588
</body>
589
</html>
590

    
591
<?php
592
/*
593
 * ROW Helpers function
594
 */
595
function display_row($trc, $value, $fieldname, $type, $rowhelper, $size) {
596
	global $text;
597
	echo "<td>\n";
598
	if($type == "input") {
599
		echo "<input size='" . $size . "' name='" . $fieldname . $trc . "' id='" . $fieldname . $trc . "' value='" . $value . "'>\n";
600
	} else if($type == "checkbox") {
601
		if($value)
602
			echo "<input size='" . $size . "' type='checkbox' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "' value='ON' CHECKED>\n";
603
		else
604
			echo "<input size='" . $size . "' type='checkbox' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "' value='ON'>\n";
605
	} else if($type == "password") {
606
		echo "<input size='" . $size . "' type='password' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "' value='" . $value . "'>\n";
607
	} else if($type == "textarea") {
608
		echo "<textarea rows='2' cols='12' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "'>" . $value . "</textarea>\n";
609
	} else if($type == "select") {
610
		echo "<select id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "'>\n";
611
		foreach($rowhelper['options']['option'] as $rowopt) {
612
			$selected = "";
613
			if($rowopt['value'] == $value) $selected = " SELECTED";
614
			$text .= "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>";
615
			echo "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>\n";
616
		}
617
		echo "</select>\n";
618
	}
619
}
620

    
621
function fixup_string($string) {
622
	global $config;
623
	// fixup #1: $myurl -> http[s]://ip_address:port/
624
	$https = "";
625
	$port = $config['system']['webguiport'];
626
	if($port <> "443" and $port <> "80")
627
		$urlport = ":" . $port;
628
	else
629
		$urlport = "";
630

    
631
	if($config['system']['webguiproto'] == "https") $https = "s";
632
	$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlport;
633
	$newstring = str_replace("\$myurl", $myurl, $string);
634
	$string = $newstring;
635
	// fixup #2: $wanip
636
	$curwanip = get_current_wan_address();
637
	$newstring = str_replace("\$wanip", $curwanip, $string);
638
	$string = $newstring;
639
	// fixup #3: $lanip
640
	$lancfg = $config['interfaces']['lan'];
641
	$lanip = $lancfg['ipaddr'];
642
	$newstring = str_replace("\$lanip", $lanip, $string);
643
	$string = $newstring;
644
	// fixup #4: fix'r'up here.
645
	return $newstring;
646
}
647

    
648
/*
649
 *  Parse templates if they are defined
650
 */
651
function parse_package_templates() {
652
	global $pkg, $config;
653
	$rows = 0;
654
	if($pkg['templates']['template'] <> "")
655
	    foreach($pkg['templates']['template'] as $pkg_template_row) {
656
		$filename = $pkg_template_row['filename'];
657
		$template_text = $pkg_template_row['templatecontents'];
658
		$firstfield = "";
659
		/* calculate total row helpers count */
660
		foreach ($pkg['fields']['field'] as $fields) {
661
			if($fields['type'] == "rowhelper") {
662
				// save rowhelper items.
663
                                $row_helper_total_rows = 0;
664
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
665
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
666
						if($firstfield == "")  {
667
						  $firstfield = $rowhelperfield['fieldname'];
668
						} else {
669
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
670
						}
671
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
672
						$value = "";
673
						eval($comd);
674
						if($value <> "") {
675
						    //$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
676
						} else {
677
						    $row_helper_total_rows = $rows;
678
						    break;
679
						}
680
					}
681
				}
682
			}
683
		}
684

    
685
		/* replace $domain_total_rows with total rows */
686
		$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
687

    
688
		/* change fields defined as fieldname_fieldvalue to their value */
689
		foreach ($pkg['fields']['field'] as $fields) {
690
			if($fields['type'] == "rowhelper") {
691
				// save rowhelper items.
692
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
693
					$row_helper_data = "";
694
					$isfirst = 0;
695
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
696
						if($firstfield == "")  {
697
						  $firstfield = $rowhelperfield['fieldname'];
698
						} else {
699
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
700
						}
701
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
702
						eval($comd);
703
						if($value <> "") {
704
						    if($isfirst == 1) $row_helper_data .= "  " ;
705
						    $row_helper_data .= $value;
706
						    $isfirst = 1;
707
						}
708
						$sep = "";
709
						ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
710
						foreach ($sep as $se) $seperator = $se;
711
						if($seperator <> "") {
712
						    $row_helper_data = ereg_replace("  ", $seperator, $row_helper_data);
713
						    $template_text = ereg_replace("\[" . $seperator . "\]", "", $template_text);
714
						}
715
						$template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
716
					}
717
				}
718
			} else {
719
				$fieldname  = $fields['fieldname'];
720
				$fieldvalue = $_POST[$fieldname];
721
				$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
722
			}
723
		}
724

    
725
		/* replace cr's */
726
		$template_text = str_replace("\\n", "\n", $template_text);
727

    
728
		/* write out new template file */
729
		$fout = fopen($filename,"w");
730
		fwrite($fout, $template_text);
731
		fclose($fout);
732
	    }
733
}
734

    
735
?>
(96-96/200)