Project

General

Profile

Download (24.2 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
    pkg_edit.php
6
    Copyright (C) 2004 Scott Ullrich
7
    All rights reserved.
8

    
9
    Redistribution and use in source and binary forms, with or without
10
    modification, are permitted provided that the following conditions are met:
11

    
12
    1. Redistributions of source code must retain the above copyright notice,
13
       this list of conditions and the following disclaimer.
14

    
15
    2. Redistributions in binary form must reproduce the above copyright
16
       notice, this list of conditions and the following disclaimer in the
17
       documentation and/or other materials provided with the distribution.
18

    
19
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
    POSSIBILITY OF SUCH DAMAGE.
29

    
30
 <tabs>
31
 	<tab>
32
 		<text>Testing Tab</text>
33
 		<url>url to go to</url>
34
 	</tab>
35
 	<tab>
36
 		<text>Testing Tab 2</text>
37
 		<xml>filename of xml</xml>
38
 	</tab>
39
 </tabs>
40

    
41
*/
42

    
43
require_once("guiconfig.inc");
44
require_once("pkg-utils.inc");
45

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

    
51
// XXX: Make this input safe.
52
$xml = $_GET['xml'];
53
if($_POST['xml']) $xml = $_POST['xml'];
54

    
55
if($xml == "") {
56
            print_info_box_np("ERROR: No package defined.");
57
            die;
58
} else {
59
            $pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
60
}
61
$package_name = $pkg['menu'][0]['name'];
62
$section      = $pkg['menu'][0]['section'];
63
$config_path  = $pkg['configpath'];
64
$name         = $pkg['name'];
65
$title        = $section . ": " . $package_name;
66
$pgtitle      = $title;
67

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

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

    
75
// grab the installedpackages->package_name section.
76
$toeval = "\$a_pkg = &\$config['installedpackages']['" . $name . "']['config'];";
77
eval($toeval);
78

    
79
$toeval = "if (!is_array(\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'])) \$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'] = array();";
80
eval($toeval);
81

    
82
$toeval = "\$a_pkg = &\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'];";
83
eval($toeval);
84

    
85
if($_GET['savemsg'] <> "")
86
	$savemsg = $_GET['savemsg'];
87

    
88
if($pkg['custom_php_command_before_form'] <> "")
89
	eval($pkg['custom_php_command_before_form']);
90

    
91
if ($_POST) {
92
	if($_POST['act'] == "del") {
93
		if($pkg['custom_delete_php_command']) {
94
		    if($pkg['custom_php_command_before_form'] <> "")
95
			    eval($pkg['custom_php_command_before_form']);
96
		    eval($pkg['custom_delete_php_command']);
97
		}
98
		write_config();
99
		// resync the configuration file code if defined.
100
		if($pkg['custom_php_resync_config_command'] <> "") {
101
			if($pkg['custom_php_command_before_form'] <> "")
102
				eval($pkg['custom_php_command_before_form']);
103
			eval($pkg['custom_php_resync_config_command']);
104
		}
105
	} else {
106
		if($pkg['custom_add_php_command']) {
107
			if($pkg['donotsave'] <> "" or $pkg['preoutput'] <> "") {
108
			?>
109
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
110
<html>
111
<head>
112
<title><?=$pgtitle;?></title>
113
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
114
<link href="gui.css" rel="stylesheet" type="text/css">
115
</head>
116

    
117
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
118
<?php include("fbegin.inc"); ?>
119
<p class="pgtitle"><?=$pgtitle?></p>
120
				<?php
121
			}
122
			if($pkg['preoutput']) echo "<pre>";
123
			eval($pkg['custom_add_php_command']);
124
			if($pkg['preoutput']) echo "</pre>";
125
		}
126
	}
127

    
128
	// donotsave is enabled.  lets simply exit.
129
	if($pkg['donotsave'] <> "") exit;
130

    
131
	$firstfield = "";
132
	$rows = 0;
133

    
134
	// store values in xml configration file.
135
	if (!$input_errors) {
136
		$pkgarr = array();
137
		foreach ($pkg['fields']['field'] as $fields) {
138
			if($fields['type'] == "rowhelper") {
139
				// save rowhelper items.
140
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
141
				                         // XXX: this really is not helping embedded platforms.
142
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
143
						if($firstfield == "")  {
144
						  $firstfield = $rowhelperfield['fieldname'];
145
						} else {
146
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
147
						}
148
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
149
						//echo($comd . "<br>");
150
						eval($comd);
151
						if($value <> "") {
152
							$comd = "\$pkgarr['row'][" . $x . "]['" . $rowhelperfield['fieldname'] . "'] = \"" . $value . "\";";
153
							//echo($comd . "<br>");
154
							eval($comd);
155
						}
156
					}
157
				}
158
			} else {
159
				// simply loop through all field names looking for posted
160
				// values matching the fieldnames.  if found, save to package
161
				// configuration area.
162
				$fieldname  = $fields['fieldname'];
163
				$fieldvalue = $_POST[$fieldname];
164
				$toeval = "\$pkgarr['" . $fieldname . "'] 	= \"" . $fieldvalue . "\";";
165
				eval($toeval);
166
			}
167
		}
168

    
169
		if (isset($id) && $a_pkg[$id])
170
			$a_pkg[$id] = $pkgarr;
171
		else
172
			$a_pkg[] = $pkgarr;
173

    
174
		write_config();
175

    
176
		// late running code
177
		if($pkg['custom_add_php_command_late'] <> "") {
178
		    eval($pkg['custom_add_php_command_late']);
179
		}
180

    
181
		// resync the configuration file code if defined.
182
		if($pkg['custom_php_resync_config_command'] <> "") {
183
		    eval($pkg['custom_php_resync_config_command']);
184
		}
185

    
186
		parse_package_templates();
187

    
188
		/* if start_command is defined, restart w/ this */
189
		if($pkg['start_command'] <> "")
190
		    exec($pkg['start_command'] . ">/dev/null 2&>1");
191

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

    
196
		if($pkg['aftersaveredirect'] <> "") {
197
		    header("Location:  " . $pkg['aftersaveredirect']);
198
		} else {
199
		    if(!$pkg['preoutput'])
200
			header("Location:  pkg.php?xml=" . $xml);
201
		}
202
		exit;
203
	}
204
}
205

    
206
if($pkg['title'] <> "")
207
	$title = $pkg['title'];
208
else
209
	$title = "Package Editor";
210

    
211
$pgtitle = $title;
212
include("head.inc");
213

    
214
?>
215

    
216
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onLoad="enablechange();">
217
<?php if($pkg['fields']['field'] <> "") { ?>
218
<script language="JavaScript">
219
<!--
220
function enablechange() {
221
<?php               
222
        foreach($pkg['fields']['field'] as $field) {
223
                if(isset($field['enablefields']) or isset($field['checkenablefields'])) {
224
                        print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked == false) {' . "\n";
225
                        if(isset($field['enablefields'])) {
226
                                $enablefields = explode(',', $field['enablefields']);
227
                                foreach($enablefields as $enablefield) {
228
                                        $enablefield = strtolower($enablefield);
229
                                        print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 1;' . "\n";
230
                                }   
231
                        }
232
                        if(isset($field['checkenablefields'])) {
233
                                $checkenablefields = explode(',', $field['checkenablefields']);
234
                                foreach($checkenablefields as $checkenablefield) {
235
                                        $checkenablefield = strtolower($checkenablefield);
236
                                        print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 0;' . "\n";
237
                                }
238
                        }
239
                        print "\t" . '} else {' . "\n";
240
                        if(isset($field['enablefields'])) { 
241
                                foreach($enablefields as $enablefield) {
242
                                        $enablefield = strtolower($enablefield);
243
                                        print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 0;' . "\n";
244
                                }
245
                        }
246
                        if(isset($field['checkenablefields'])) {
247
                                foreach($checkenablefields as $checkenablefield) {
248
                                        $checkenablefield = strtolower($checkenablefield);
249
                                        print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 1;' . "\n";
250
                                }
251
                        }
252
                        print "\t" . '}' . "\n";
253
                }
254
        }
255
?>
256
}
257
//-->
258
</script>
259
<?php } ?>
260
<script type="text/javascript" language="javascript" src="row_helper_dynamic.js">
261
</script>
262

    
263
<?php include("fbegin.inc"); ?>
264
<p class="pgtitle"><?=$pgtitle?></p>
265
<form action="pkg_edit.php" method="post">
266
<input type="hidden" name="xml" value="<?= $xml ?>">
267
<?php if ($savemsg) print_info_box($savemsg); ?>
268

    
269
<?php
270
if ($pkg['tabs'] <> "") {
271
    echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
272
    echo "<tr><td>";
273
    echo "  <ul id=\"tabnav\">";
274
    foreach($pkg['tabs']['tab'] as $tab) {
275
	$active = "tabinact";
276
	if(isset($tab['active'])) $active = "tabact";
277

    
278
	$urltmp = "";
279
	$title = $tab['text'];
280
	if($tab['url'] <> "") $urltmp = $tab['url'];
281
	if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml'];
282

    
283
	$toeval = "\$myurl = \"" . getenv("HTTP_HOST") . "\"; \n";
284
	eval($toeval);
285
	// eval url so that above $myurl item can be processed if need be.
286
	$toeval = "\$url = \"" . $urltmp . "\"; \n";
287
	eval($toeval);
288

    
289
	if($active == "tabinact") {
290
	    echo "<li class=\"{$active}\">";
291
	    echo "<a href=\"";
292
	    echo $url;
293
	    echo "\">";
294
	    echo $title;
295
	    echo "</a>";
296
	    echo "</li>";
297
	} else {
298
	    echo "<li class=\"{$active}\">";
299
	    echo $title;
300
	    echo "</li>";
301
	}
302
    }
303
    echo "  </ul>";
304
    echo "</td></tr>";
305
    echo "<tr>";
306
    echo "<td class=\"tabcont\">";
307
}
308
?>
309

    
310
<table width="100%" border="0" cellpadding="6" cellspacing="0">
311
  <?php
312
  $cols = 0;
313
  $savevalue = "Save";
314
  if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
315
  foreach ($pkg['fields']['field'] as $pkga) { ?>
316
	  
317
	  <?php if(!$pkga['combinefieldsend']) echo "<tr valign=\"top\">"; ?>
318

    
319
	  <?php
320
	  
321
	  $size = "";
322
	  
323
	  if(!$pkga['dontdisplayname']) {
324
		echo "<td width=\"22%\" class=\"vncellreq\">";
325
		echo fixup_string($pkga['fielddescr']);
326
		echo "</td>";
327
	  }
328

    
329
	  if(!$pkga['dontcombinecells'])
330
		echo "<td class=\"vtable\">";
331

    
332
		// if user is editing a record, load in the data.
333
		if (isset($id) && $a_pkg[$id]) {
334
			$fieldname = $pkga['fieldname'];
335
			$toeval = "\$value = \$a_pkg[" . $id . "]['" . $fieldname . "'];";
336
			echo "<!-- eval: " . $toeval . "-->\n";
337
			eval($toeval);
338
		}
339

    
340
	      if($pkga['type'] == "input") {
341
			if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
342
			echo "<input " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
343
			echo "<br>" . fixup_string($pkga['description']) . "\n";
344
	      } else if($pkga['type'] == "password") {
345
			echo "<input type='password' " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
346
			echo "<br>" . fixup_string($pkga['description']) . "\n";
347
	      } else if($pkga['type'] == "select") {
348
		  // XXX: TODO: set $selected
349
                  if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
350
		  if($pkga['multiple'] == "yes") $multiple = "MULTIPLE ";
351
		    echo "<select " . $multiple . $size . "id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "'>\n";
352
		    foreach ($pkga['options']['option'] as $opt) {
353
			  $selected = "";
354
			  if($opt['value'] == $value) $selected = " SELECTED";
355
			  echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'" . $selected . ">" . $opt['name'] . "</option>\n";
356
		    }
357
		    echo "</select>\n";
358
		    echo "<br>" . fixup_string($pkga['description']) . "\n";
359
	      } else if($pkga['type'] == "vpn_selection") {
360
		    echo "<select name='" . $vpn['name'] . "'>\n";
361
		    foreach ($config['ipsec']['tunnel'] as $vpn) {
362
			echo "\t<option value=\"" . $vpn['descr'] . "\">" . $vpn['descr'] . "</option>\n";
363
		    }
364
		    echo "</select>\n";
365
		    echo "<br>" . fixup_string($pkga['description']) . "\n";
366
	      } else if($pkga['type'] == "checkbox") {
367
			$checkboxchecked = "";
368
			if($value == "on") $checkboxchecked = " CHECKED";
369
			echo "<input type='checkbox' name='" . $pkga['fieldname'] . "'" . $checkboxchecked . ">\n";
370
			echo "<br>" . fixup_string($pkga['description']) . "\n";
371
	      } else if($pkga['type'] == "textarea") {
372
		  if($pkga['rows']) $rows = " rows='" . $pkga['rows'] . "' ";
373
		  if($pkga['cols']) $cols = " cols='" . $pkga['cols'] . "' ";
374
			echo "<textarea " . $rows . $cols . " name='" . $pkga['fieldname'] . "'>" . $value . "</textarea>\n";
375
			echo "<br>" . fixup_string($pkga['description']) . "\n";
376
		  } else if($pkga['type'] == "interfaces_selection") {
377
			$size = "";
378
			$multiple = "";
379
			$fieldname = $pkga['fieldname'];
380
			if($pkga['size'] <> "") $size = " size=\"" . $pkga['size'] . "\"";
381
			if($pkga['multiple'] <> "" and $pkga['multiple'] <> "0") {
382
			  $multiple = " multiple=\"multiple\"";
383
			  $fieldname .= "[]";
384
			}
385
			echo "<select name='" . $fieldname . "'" . $size . $multiple . ">\n";
386
			if($pkga['add_to_interfaces_selection'] <> "") {
387
				$SELECTED = "";
388
				if($pkga['add_to_interfaces_selection'] == $value) $SELECTED = " SELECTED";
389
				echo "<option value='" . $pkga['add_to_interfaces_selection'] . "'" . $SELECTED . ">" . $pkga['add_to_interfaces_selection'] . "</option>\n";
390
			}
391
			$interfaces = &$config['interfaces'];
392
			if($pkga['all_interfaces'] <> "") {
393
				$ints = split(" ", `/sbin/ifconfig -l`);
394
				$interfaces = array();
395
				foreach ($ints as $int) {
396
					$interfaces[]['descr'] = $int;
397
					$interfaces[] = $int;
398
				}
399
			}
400
			foreach ($interfaces as $ifname => $iface) {
401
			  if ($iface['descr'])
402
				  $ifdescr = $iface['descr'];
403
			  else
404
				  $ifdescr = strtoupper($ifname);
405
			  $ifname = $iface['descr'];
406
			  $ip = "";
407
			  if($pkga['all_interfaces'] <> "") {
408
				$ifdescr = $iface;
409
				$ip = " " . find_interface_ip($iface);
410
			  }
411
			  $SELECTED = "";
412
			  if($value == $ifdescr) $SELECTED = " SELECTED";
413
			  $to_echo =  "<option value='" . $ifdescr . "'" . $SELECTED . ">" . $ifdescr . $ip . "</option>\n";
414
			  $to_echo .= "<!-- {$value} -->";
415
			  $to_echo .= "<!-- {$iface} -->";
416
			  $canecho = 0;
417
			  if($pkga['interface_filter'] <> "") {
418
				if(stristr($iface, $pkga['interface_filter']) == true)
419
					$canecho = 1;
420
			  } else {
421
				$canecho = 1;
422
			  }
423
			  if($canecho == 1) 
424
				echo $to_echo;
425
			}
426
			echo "</select>\n<br>" . fixup_string($pkga['description']) . "\n";
427
	      } else if($pkga['type'] == "radio") {
428
			echo "<input type='radio' name='" . $pkga['fieldname'] . "' value='" . $value . "'>";
429
	      } else if($pkga['type'] == "rowhelper") {
430
		?>
431
			<script type="text/javascript" language='javascript'>
432
			<!--
433

    
434
			<?php
435
				$rowcounter = 0;
436
				$fieldcounter = 0;
437
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
438
					echo "rowname[" . $fieldcounter . "] = \"" . $rowhelper['fieldname'] . "\";\n";
439
					echo "rowtype[" . $fieldcounter . "] = \"" . $rowhelper['type'] . "\";\n";
440
					$fieldcounter++;
441
				}
442
			?>
443

    
444
			-->
445
			</script>
446

    
447
			<table name="maintable" id="maintable">
448
			<tr>
449
			<?php
450
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
451
				  echo "<td><b>" . fixup_string($rowhelper['fielddescr']) . "</td>\n";
452
				}
453
				echo "</tr>";
454
				echo "<tbody>";
455

    
456
				echo "<tr>";
457
				  // XXX: traverse saved fields, add back needed rows.
458
				echo "</tr>";
459

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

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

    
529
					$rowcounter++;
530
				}
531
			?>
532

    
533
			  </tbody>
534
			</table>
535

    
536
		<br><a onClick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="/plus.gif"></a>
537
		<script language="JavaScript">
538
		<!--
539
		field_counter_js = <?= $fieldcounter ?>;
540
		rows = <?= $rowcounter ?>;
541
		totalrows = <?php echo $rowcounter; ?>;
542
		loaded = <?php echo $rowcounter; ?>;
543
		//typesel_change();
544
		//-->
545
		</script>
546

    
547
		<?php
548
	      }
549
	      if($pkga['typehint']) echo " " . $pkga['typehint'];
550
	     ?>
551

    
552
      <?php
553
	  if(!$pkga['combinefieldsbegin']) echo "</td></tr>";
554
      $i++;
555
  }
556
 ?>
557
  <tr>
558
	<td>&nbsp;</td>
559
  </tr>
560
  <tr>
561
    <td width="22%" valign="top">&nbsp;</td>
562
    <td width="78%">
563
      <input name="Submit" type="submit" class="formbtn" value="<?= $savevalue ?>"> <input class="formbtn" type="button" value="cancel" onclick="history.back()">
564
      <?php if (isset($id) && $a_pkg[$id]): ?>
565
      <input name="id" type="hidden" value="<?=$id;?>">
566
      <?php endif; ?>
567
    </td>
568
  </tr>
569
</table>
570

    
571
<?php
572
if ($pkg['tabs'] <> "") {
573
    echo "</td></tr></table>";
574
}
575
?>
576

    
577
<?php if($pkga['note'] <> "") echo "<br><center>" . $pkga['note'] . "</center>"; ?>
578

    
579
</form>
580
<?php include("fend.inc"); ?>
581
</body>
582
</html>
583

    
584
<?php
585

    
586
/*
587
 * ROW Helpers function
588
 */
589
function display_row($trc, $value, $fieldname, $type, $rowhelper, $size) {
590
	global $text;
591
	echo "<td>\n";
592
	if($type == "input") {
593
		echo "<input size='" . $size . "' name='" . $fieldname . $trc . "' value='" . $value . "'>\n";
594
	} else if($type == "password") {
595
		echo "<input size='" . $size . "' type='password' name='" . $fieldname . $trc . "' value='" . $value . "'>\n";
596
	} else if($type == "textarea") {
597
		echo "<textarea rows='2' cols='12' name='" . $fieldname . $trc . "'>" . $value . "</textarea>\n";
598
	} else if($type == "select") {
599
		echo "<select name='" . $fieldname . $trc . "'>\n";
600
		foreach($rowhelper['options']['option'] as $rowopt) {
601
			$selected = "";
602
			if($rowopt['value'] == $value) $selected = " SELECTED";
603
			$text .= "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>";
604
			echo "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>\n";
605
		}
606
		echo "</select>\n";
607
	}
608
}
609

    
610
function fixup_string($string) {
611
	global $config;
612
	// fixup #1: $myurl -> http[s]://ip_address:port/
613
	$https = "";
614
	$port = $config['system']['webguiport'];
615
	if($port <> "443" and $port <> "80")
616
		$urlport = ":" . $port;
617
	else
618
		$urlport = "";
619
		
620
	if($config['system']['webguiproto'] == "https") $https = "s";
621
	$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlport;
622
	$newstring = str_replace("\$myurl", $myurl, $string);
623
	$string = $newstring;
624
	// fixup #2: $wanip
625
	$curwanip = get_current_wan_address();
626
	$newstring = str_replace("\$wanip", $curwanip, $string);
627
	$string = $newstring;
628
	// fixup #3: $lanip
629
	$lancfg = $config['interfaces']['lan'];
630
	$lanip = $lancfg['ipaddr'];
631
	$newstring = str_replace("\$lanip", $lanip, $string);
632
	$string = $newstring;
633
	// fixup #4: fix'r'up here.
634
	return $newstring;
635
}
636

    
637
/*
638
 *  Parse templates if they are defined
639
 */
640
function parse_package_templates() {
641
	global $pkg, $config;
642
	if($pkg['templates']['template'] <> "")
643
	    foreach($pkg['templates']['template'] as $pkg_template_row) {
644
		$filename = $pkg_template_row['filename'];
645
		$template_text = $pkg_template_row['templatecontents'];
646

    
647
		/* calculate total row helpers count */
648
		foreach ($pkg['fields']['field'] as $fields) {
649
			if($fields['type'] == "rowhelper") {
650
				// save rowhelper items.
651
                                $row_helper_total_rows = 0;
652
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
653
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
654
						if($firstfield == "")  {
655
						  $firstfield = $rowhelperfield['fieldname'];
656
						} else {
657
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
658
						}
659
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
660
						eval($comd);
661
						if($value <> "") {
662
						    //$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
663
						} else {
664
						    $row_helper_total_rows = $rows;
665
						    break;
666
						}
667
					}
668
				}
669
			}
670
		}
671

    
672
		/* replace $domain_total_rows with total rows */
673
		$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
674

    
675
		/* change fields defined as fieldname_fieldvalue to their value */
676
		foreach ($pkg['fields']['field'] as $fields) {
677
			if($fields['type'] == "rowhelper") {
678
				// save rowhelper items.
679
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
680
					$row_helper_data = "";
681
					$isfirst = 0;
682
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
683
						if($firstfield == "")  {
684
						  $firstfield = $rowhelperfield['fieldname'];
685
						} else {
686
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
687
						}
688
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
689
						eval($comd);
690
						if($value <> "") {
691
						    if($isfirst == 1) $row_helper_data .= "  " ;
692
						    $row_helper_data .= $value;
693
						    $isfirst = 1;
694
						}
695
						ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
696
						foreach ($sep as $se) $seperator = $se;
697
						if($seperator <> "") {
698
						    $row_helper_data = ereg_replace("  ", $seperator, $row_helper_data);
699
						    $template_text = ereg_replace("\[" . $seperator . "\]", "", $template_text);
700
						}
701
						$template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
702
					}
703
				}
704
			} else {
705
				$fieldname  = $fields['fieldname'];
706
				$fieldvalue = $_POST[$fieldname];
707
				$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
708
			}
709
		}
710

    
711
		/* replace cr's */
712
		$template_text = str_replace("\\n", "\n", $template_text);
713

    
714
		/* write out new template file */
715
		$fout = fopen($filename,"w");
716
		fwrite($fout, $template_text);
717
		fclose($fout);
718
	    }
719
}
720

    
721
?>
(66-66/128)