Project

General

Profile

Download (24.9 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
##|+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
require_once("guiconfig.inc");
39
require_once("pkg-utils.inc");
40

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

    
44
function gentitle_pkg($pgname) {
45
	global $pfSense_config;
46
	return $pfSense_config['system']['hostname'] . "." . $pfSense_config['system']['domain'] . " - " . $pgname;
47
}
48

    
49
$xml = htmlspecialchars($_GET['xml']);
50
if($_POST['xml']) $xml = htmlspecialchars($_POST['xml']);
51

    
52
if($xml == "") {
53
            print_info_box_np(gettext("ERROR: No package defined."));
54
            die;
55
} else {
56
            $pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
57
}
58

    
59
if($pkg['include_file'] <> "") {
60
	require_once($pkg['include_file']);
61
}
62

    
63
if (!isset($pkg['adddeleteeditpagefields']))
64
	$only_edit = true;
65
else
66
	$only_edit = false;
67

    
68
$package_name = $pkg['menu'][0]['name'];
69
$section      = $pkg['menu'][0]['section'];
70
$config_path  = $pkg['configpath'];
71
$name         = $pkg['name'];
72
$title        = $pkg['title'];
73
$pgtitle      = $title;
74

    
75
$id = $_GET['id'];
76
if (isset($_POST['id']))
77
	$id = htmlspecialchars($_POST['id']);
78

    
79
if($pkg['custom_php_global_functions'] <> "")
80
        eval($pkg['custom_php_global_functions']);
81

    
82
// grab the installedpackages->package_name section.
83
if(!is_array($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']))
84
	$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'] = array();
85

    
86
$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
87

    
88
if($_GET['savemsg'] <> "")
89
	$savemsg = htmlspecialchars($_GET['savemsg']);
90

    
91
if($pkg['custom_php_command_before_form'] <> "")
92
	eval($pkg['custom_php_command_before_form']);
93

    
94
if ($_POST) {
95
	if($_POST['act'] == "del") {
96
		if($pkg['custom_delete_php_command']) {
97
		    if($pkg['custom_php_command_before_form'] <> "")
98
			    eval($pkg['custom_php_command_before_form']);
99
		    eval($pkg['custom_delete_php_command']);
100
		}
101
		write_config($pkg['delete_string']);
102
		// resync the configuration file code if defined.
103
		if($pkg['custom_php_resync_config_command'] <> "") {
104
			if($pkg['custom_php_command_before_form'] <> "")
105
				eval($pkg['custom_php_command_before_form']);
106
			eval($pkg['custom_php_resync_config_command']);
107
		}
108
	} else {
109
		if($pkg['custom_add_php_command']) {
110
			if($pkg['donotsave'] <> "" or $pkg['preoutput'] <> "") {
111
			?>
112

    
113
<?php include("head.inc"); ?>
114
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
115
<?php include("fbegin.inc"); ?>
116
<?php
117
			}
118
			if($pkg['preoutput']) echo "<pre>";
119
			eval($pkg['custom_add_php_command']);
120
			if($pkg['preoutput']) echo "</pre>";
121
		}
122
	}
123

    
124
	// donotsave is enabled.  lets simply exit.
125
	if($pkg['donotsave'] <> "") exit;
126

    
127
	$firstfield = "";
128
	$rows = 0;
129

    
130
	$input_errors = array();
131
	$reqfields = array();
132
	$reqfieldsn = array();
133
	foreach ($pkg['fields']['field'] as $field) {
134
		if (($field['type'] == 'input') && isset($field['required'])) {
135
			$reqfields[] = $field['fieldname'];
136
			$reqfieldsn[] = $field['fielddescr'];
137
		}
138
	}
139
	do_input_validation($_POST, $reqfields, $reqfieldsn, &$input_errors);
140

    
141
	if ($pkg['custom_php_validation_command'])
142
		eval($pkg['custom_php_validation_command']);
143

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

    
181
		if (isset($id) && $a_pkg[$id])
182
			$a_pkg[$id] = $pkgarr;
183
		else
184
			$a_pkg[] = $pkgarr;
185

    
186
		write_config($pkg['addedit_string']);
187

    
188
		// late running code
189
		if($pkg['custom_add_php_command_late'] <> "") {
190
		    eval($pkg['custom_add_php_command_late']);
191
		}
192

    
193
		// resync the configuration file code if defined.
194
		if($pkg['custom_php_resync_config_command'] <> "") {
195
		    eval($pkg['custom_php_resync_config_command']);
196
		}
197

    
198
		parse_package_templates();
199

    
200
		/* if start_command is defined, restart w/ this */
201
		if($pkg['start_command'] <> "")
202
		    exec($pkg['start_command'] . ">/dev/null 2&>1");
203

    
204
		/* if restart_command is defined, restart w/ this */
205
		if($pkg['restart_command'] <> "")
206
		    exec($pkg['restart_command'] . ">/dev/null 2&>1");
207

    
208
		if($pkg['aftersaveredirect'] <> "") {
209
		    pfSenseHeader($pkg['aftersaveredirect']);
210
		} elseif(!$pkg['adddeleteeditpagefields']) {
211
		    pfSenseHeader("pkg_edit.php?xml={$xml}&id=0");
212
		} elseif(!$pkg['preoutput']) {
213
		    pfSenseHeader("pkg.php?xml=" . $xml);
214
		}
215
		exit;
216
	}
217
	else
218
		$get_from_post = true;
219
}
220

    
221
if($pkg['title'] <> "") {
222
	$edit = ($only_edit ? '' : ': Edit');
223
	$title = $pkg['title'] . $edit;
224
}
225
else
226
	$title = gettext("Package Editor");
227

    
228
$pgtitle = $title;
229
include("head.inc");
230

    
231
if ($pkg['custom_php_after_head_command'])
232
	eval($pkg['custom_php_after_head_command']);
233

    
234
?>
235

    
236
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onLoad="enablechange();">
237
<?php if($pkg['fields']['field'] <> "") { ?>
238
<script language="JavaScript">
239
<!--
240
function enablechange() {
241
<?php
242
foreach ($pkg['fields']['field'] as $field) {
243
	if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
244
		print("\tif (document.iform.elements[\"{$field['fieldname']}\"].checked == false) {\n");
245

    
246
		if (isset($field['enablefields'])) {
247
			foreach (explode(',', $field['enablefields']) as $enablefield)
248
				print("\t\tdocument.iform.elements[\"$enablefield\"].disabled = 1;\n");
249
		}
250

    
251
		if (isset($field['checkenablefields'])) {
252
			foreach (explode(',', $field['checkenablefields']) as $checkenablefield)
253
				print("\t\tdocument.iform.elements[\"$checkenablefield\"].checked = 0;\n");
254
		}
255

    
256
		print("\t}\n\telse {\n");
257

    
258
		if (isset($field['enablefields'])) {
259
			foreach (explode(',', $field['enablefields']) as $enablefield)
260
				print("\t\tdocument.iform.elements[\"$enablefield\"].disabled = 0;\n");
261
		}
262

    
263
		if (isset($field['checkenablefields'])) {
264
			foreach(explode(',', $field['checkenablefields']) as $checkenablefield)
265
				print("\t\tdocument.iform.elements[\"$checkenablefield\"].checked = 1;\n");
266
		}
267

    
268
		print("\t}\n");
269
	}
270
}
271
?>
272
}
273
//-->
274
</script>
275
<?php } ?>
276
<script type="text/javascript" language="javascript" src="row_helper_dynamic.js">
277
</script>
278

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

    
301
 	$addresswithport = getenv("HTTP_HOST");
302
	$colonpos = strpos($addresswithport, ":");
303
	if ($colonpos !== False){
304
		//my url is actually just the IP address of the pfsense box
305
		$myurl = substr($addresswithport, 0, $colonpos);
306
	}
307
	else
308
	{
309
		$myurl = $addresswithport;
310
	}
311
	// eval url so that above $myurl item can be processed if need be.
312
	$url = str_replace('$myurl', $myurl, $urltmp);
313

    
314
	$tab_array[] = array(
315
				$tab['text'],
316
				$active,
317
				$url
318
			);
319
    }
320
    display_top_tabs($tab_array);
321
    echo '</td></tr>';
322
}
323
?>
324
<tr><td><div id="mainarea"><table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
325
  <?php
326
  $cols = 0;
327
  $savevalue = gettext("Save");
328
  if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
329
  foreach ($pkg['fields']['field'] as $pkga) { ?>
330

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

    
333
	  <?php
334

    
335
	  $size = "";
336

    
337
	  if(!$pkga['dontdisplayname']) {
338
		unset($req);
339
		if (isset($pkga['required']))
340
			$req = 'req';
341
		echo "<td width=\"22%\" class=\"vncell{$req}\">";
342
		echo fixup_string($pkga['fielddescr']);
343
		echo "</td>";
344
	  }
345

    
346
	  if(!$pkga['dontcombinecells'])
347
		echo "<td class=\"vtable\">";
348
		// if user is editing a record, load in the data.
349
		$fieldname = $pkga['fieldname'];
350
		if ($get_from_post) {
351
			$value = $_POST[$fieldname];
352
			if (is_array($value)) $value = implode(',', $value);
353
		}
354
		else {
355
			if (isset($id) && $a_pkg[$id])
356
				$value = $a_pkg[$id][$fieldname];
357
			else
358
				$value = $pkga['default_value'];
359
		}
360

    
361
	      if($pkga['type'] == "input") {
362
			if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
363
			echo "<input " . $size . " id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
364
			echo "<br>" . fixup_string($pkga['description']) . "\n";
365
	      } else if($pkga['type'] == "password") {
366
			echo "<input id='" . $pkga['fieldname'] . "' type='password' " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
367
			echo "<br>" . fixup_string($pkga['description']) . "\n";
368
	      } else if($pkga['type'] == "select") {
369
                  $fieldname = $pkga['fieldname'];
370
                  if (isset($pkga['multiple'])) {
371
                    $multiple = 'multiple="multiple"';
372
                    $items = explode(',', $value);
373
                    $fieldname .= "[]";
374
                  }
375
                  else {
376
                    $multiple = '';
377
                    $items = array($value);
378
                  }
379
                  $size = (isset($pkga['size']) ? "size=\"{$pkga['size']}\"" : '');
380
                  $onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
381

    
382
                  print("<select id='" . $pkga['fieldname'] . "' $multiple $size $onchange id=\"$fieldname\" name=\"$fieldname\">\n");
383
                  foreach ($pkga['options']['option'] as $opt) {
384
                      $selected = '';
385
                      if (in_array($opt['value'], $items)) $selected = 'selected="selected"';
386
                      print("\t<option name=\"{$opt['name']}\" value=\"{$opt['value']}\" $selected>{$opt['name']}</option>\n");
387
                  }
388

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

    
420
			if (isset($pkga['all_interfaces']))
421
				$ifaces = explode(' ', trim(shell_exec('ifconfig -l')));
422
			else
423
				$ifaces = $config['interfaces'];
424

    
425
			$additional_ifaces = $pkga['add_to_interfaces_selection'];
426
			if (!empty($additional_ifaces))
427
				$ifaces = array_merge($ifaces, explode(',', $additional_ifaces));
428
			if(is_array($value))
429
				$values = $value;
430
			else
431
				$values  =  explode(',',  $value);
432

    
433
			foreach($ifaces as $ifname => $iface) {
434
				if (isset($iface['descr']))
435
					$ifdescr = $iface['descr'];
436
				else
437
					$ifdescr = strtoupper($ifname);
438
				if ($ip = find_interface_ip($iface))
439
					$ip = " ($ip)";
440
				$selected = (in_array($ifname, $values) ? 'selected' : '');
441
				print("<option value=\"$ifname\" $selected>$ifdescr</option>\n");
442
			}
443

    
444
			print("</select>\n<br />" . fixup_string($pkga['description']) . "\n");
445
	      } else if($pkga['type'] == "radio") {
446
			echo "<input type='radio' id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "' value='" . $value . "'>";
447
	      } else if($pkga['type'] == "rowhelper") {
448
		?>
449
			<script type="text/javascript" language='javascript'>
450
			<!--
451

    
452
			<?php
453
				$rowcounter = 0;
454
				$fieldcounter = 0;
455
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
456
					echo "rowname[" . $fieldcounter . "] = \"" . $rowhelper['fieldname'] . "\";\n";
457
					echo "rowtype[" . $fieldcounter . "] = \"" . $rowhelper['type'] . "\";\n";
458
					$fieldcounter++;
459
				}
460
			?>
461

    
462
			-->
463
			</script>
464

    
465
			<table name="maintable" id="maintable">
466
			<tr>
467
			<?php
468
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
469
				  echo "<td><b>" . fixup_string($rowhelper['fielddescr']) . "</td>\n";
470
				}
471
				echo "</tr>";
472

    
473
				echo "<tr>";
474
				  // XXX: traverse saved fields, add back needed rows.
475
				echo "</tr>";
476

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

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

    
543
					$rowcounter++;
544
				}
545
			?>
546

    
547
			  <tbody></tbody>
548
			</table>
549

    
550
		<br><a onClick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif"></a>
551
		<script language="JavaScript">
552
		<!--
553
		field_counter_js = <?= $fieldcounter ?>;
554
		rows = <?= $rowcounter ?>;
555
		totalrows = <?php echo $rowcounter; ?>;
556
		loaded = <?php echo $rowcounter; ?>;
557
		//typesel_change();
558
		//-->
559
		</script>
560

    
561
		<?php
562
	      }
563
	      if($pkga['typehint']) echo " " . $pkga['typehint'];
564
	     ?>
565

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

    
593
<?php if ($pkg['custom_php_after_form_command']) eval($pkg['custom_php_after_form_command']); ?>
594

    
595
<?php include("fend.inc"); ?>
596
</body>
597
</html>
598

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

    
629
function fixup_string($string) {
630
	global $config;
631
	// fixup #1: $myurl -> http[s]://ip_address:port/
632
	$https = "";
633
	$port = $config['system']['webguiport'];
634
	if($port <> "443" and $port <> "80")
635
		$urlport = ":" . $port;
636
	else
637
		$urlport = "";
638

    
639
	if($config['system']['webguiproto'] == "https") $https = "s";
640
	$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlport;
641
	$newstring = str_replace("\$myurl", $myurl, $string);
642
	$string = $newstring;
643
	// fixup #2: $wanip
644
	$curwanip = get_current_wan_address();
645
	$newstring = str_replace("\$wanip", $curwanip, $string);
646
	$string = $newstring;
647
	// fixup #3: $lanip
648
	$lancfg = $config['interfaces']['lan'];
649
	$lanip = $lancfg['ipaddr'];
650
	$newstring = str_replace("\$lanip", $lanip, $string);
651
	$string = $newstring;
652
	// fixup #4: fix'r'up here.
653
	return $newstring;
654
}
655

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

    
693
		/* replace $domain_total_rows with total rows */
694
		$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
695

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

    
733
		/* replace cr's */
734
		$template_text = str_replace("\\n", "\n", $template_text);
735

    
736
		/* write out new template file */
737
		$fout = fopen($filename,"w");
738
		fwrite($fout, $template_text);
739
		fclose($fout);
740
	    }
741
}
742

    
743
?>
(108-108/210)