Project

General

Profile

Download (21.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("guiconfig.inc");
44
require("xmlparse_pkg.inc");
45

    
46
$pfSense_config = $config; // copy this since we will be parsing
47
                           // another xml file which will be clobbered.
48

    
49
function gentitle_pkg($pgname) {
50
	global $pfSense_config;
51
	return $pfSense_config['system']['hostname'] . "." . $pfSense_config['system']['domain'] . " - " . $pgname;
52
}
53

    
54
// XXX: Make this input safe.
55
$xml = $_GET['xml'];
56
if($_POST['xml']) $xml = $_POST['xml'];
57

    
58
if($xml == "") {
59
            $xml = "not_defined";
60
            print_info_box_np("ERROR:  Could not open " . $xml . ".");
61
            die;
62
} else {
63
            $pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
64
}
65

    
66
$package_name = $pkg['menu'][0]['name'];
67
$section      = $pkg['menu'][0]['section'];
68
$config_path  = $pkg['configpath'];
69
$name         = $pkg['name'];
70
$title        = $section . ": " . $package_name;
71

    
72
$id = $_GET['id'];
73
if (isset($_POST['id']))
74
	$id = $_POST['id'];
75

    
76
if($pkg['custom_php_global_functions'] <> "")
77
        eval($pkg['custom_php_global_functions']);
78

    
79
// grab the installedpackages->package_name section.
80
$toeval = "\$a_pkg = &\$config['installedpackages']['" . $name . "']['config'];";
81
eval($toeval);
82

    
83
$toeval = "if (!is_array(\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'])) \$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'] = array();";
84
eval($toeval);
85

    
86
$toeval = "\$a_pkg = &\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'];";
87
eval($toeval);
88

    
89

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

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

    
119
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
120
<?php
121
include("fbegin.inc");
122

    
123
?>
124
<p class="pgtitle"><?=$title?></p>
125
				<?php
126
			}
127
			if($pkg['preoutput']) echo "<pre>";
128
			eval($pkg['custom_add_php_command']);
129
			if($pkg['preoutput']) echo "</pre>";
130
		}
131
	}
132

    
133
	// donotsave is enabled.  lets simply exit.
134
	if($pkg['donotsave'] <> "") exit;
135

    
136
	$firstfield = "";
137
	$rows = 0;
138

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

    
168
				$fieldname  = $fields['fieldname'];
169
				$fieldvalue = $_POST[$fieldname];
170
				$toeval = "\$pkgarr['" . $fieldname . "'] 	= \"" . $fieldvalue . "\";";
171
				eval($toeval);
172
			}
173
		}
174

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

    
180
		write_config();
181

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

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

    
192
		parse_package_templates();
193

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

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

    
202
		if($pkg['aftersaveredirect'] <> "") {
203
		    header("Location:  " . $pkg['aftersaveredirect']);
204
		} else {
205
		    if(!$pkg['preoutput'])
206
			header("Location:  pkg.php?xml=" . $xml);
207
		}
208
		exit;
209
	}
210
}
211

    
212
?>
213
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
214
<html>
215
<head>
216
<?php
217
    if($pkg['title'] <> "") $title = $pkg['title'];
218
?>
219
<title><?=gentitle_pkg($title);?></title>
220
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
221
<link href="gui.css" rel="stylesheet" type="text/css">
222
</head>
223

    
224
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
225

    
226
<script type="text/javascript" language="javascript" src="row_helper_dynamic.js">
227
</script>
228

    
229
<?php
230
$config_tmp = $config;
231
$config = $pfSense_config;
232
include("fbegin.inc");
233
$config = $config_tmp;
234
?>
235
<p class="pgtitle"><?=$title?></p>
236
<form action="pkg_edit.php" method="post">
237
<input type="hidden" name="xml" value="<?= $xml ?>">
238
<?php if ($savemsg) print_info_box($savemsg); ?>
239

    
240
<?php
241
if ($pkg['tabs'] <> "") {
242
    echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
243
    echo "<tr><td>";
244
    echo "  <ul id=\"tabnav\">";
245
    foreach($pkg['tabs']['tab'] as $tab) {
246
	$active = "tabinact";
247
	if(isset($tab['active'])) $active = "tabact";
248

    
249
	$urltmp = "";
250
	$title = $tab['text'];
251
	if($tab['url'] <> "") $urltmp = $tab['url'];
252
	if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml'];
253

    
254
	$toeval = "\$myurl = \"" . getenv("HTTP_HOST") . "\"; \n";
255
	eval($toeval);
256
	// eval url so that above $myurl item can be processed if need be.
257
	$toeval = "\$url = \"" . $urltmp . "\"; \n";
258
	eval($toeval);
259

    
260
	if($active == "tabinact") {
261
	    echo "<li class=\"{$active}\">";
262
	    echo "<a href=\"";
263
	    echo $url;
264
	    echo "\">";
265
	    echo $title;
266
	    echo "</a>";
267
	    echo "</li>";
268
	} else {
269
	    echo "<li class=\"{$active}\">";
270
	    echo $title;
271
	    echo "</li>";
272
	}
273
    }
274
    echo "  </ul>";
275
    echo "</td></tr>";
276
    echo "<tr>";
277
    echo "<td class=\"tabcont\">";
278
}
279
?>
280

    
281
<table width="100%" border="0" cellpadding="6" cellspacing="0">
282
  <?php
283
  $cols = 0;
284
  $savevalue = "Save";
285
  if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
286
  foreach ($pkg['fields']['field'] as $pkga) { ?>
287

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

    
290
	  <?php
291
	  if(!$pkga['dontdisplayname']) {
292
		echo "<td width=\"22%\" class=\"vncellreq\">";
293
		echo fixup_string($pkga['fielddescr']);
294
		echo "</td>";
295
	  }
296

    
297
	  if(!$pkga['dontcombinecells'])
298
		echo "<td class=\"vtable\">";
299

    
300
		// if user is editing a record, load in the data.
301
		if (isset($id) && $a_pkg[$id]) {
302
			$fieldname = $pkga['fieldname'];
303
			$toeval = "\$value = \$a_pkg[" . $id . "]['" . $fieldname . "'];";
304
			echo "<!-- eval: " . $toeval . "-->\n";
305
			eval($toeval);
306
		}
307

    
308
	      if($pkga['type'] == "input") {
309
			if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
310
			echo "<input " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
311
			echo "<br>" . fixup_string($pkga['description']) . "\n";
312
	      } else if($pkga['type'] == "password") {
313
			echo "<input type='password' " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
314
			echo "<br>" . fixup_string($pkga['description']) . "\n";
315
	      } else if($pkga['type'] == "select") {
316
		  // XXX: TODO: set $selected
317
                  if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
318
		  if($pkga['multiple'] == "yes") $multiple = "MULTIPLE ";
319
		    echo "<select " . $multiple . $size . "id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "'>\n";
320
		    foreach ($pkga['options']['option'] as $opt) {
321
			  $selected = "";
322
			  if($opt['value'] == $value) $selected = " SELECTED";
323
			  echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'" . $selected . ">" . $opt['name'] . "</option>\n";
324
		    }
325
		    echo "</select>\n";
326
		    echo "<br>" . fixup_string($pkga['description']) . "\n";
327
	      } else if($pkga['type'] == "vpn_selection") {
328
		    echo "<select name='" . $vpn['name'] . "'>\n";
329
		    foreach ($config['ipsec']['tunnel'] as $vpn) {
330
			echo "\t<option value=\"" . $vpn['descr'] . "\">" . $vpn['descr'] . "</option>\n";
331
		    }
332
		    echo "</select>\n";
333
		    echo "<br>" . fixup_string($pkga['description']) . "\n";
334
	      } else if($pkga['type'] == "checkbox") {
335
			$checkboxchecked = "";
336
			if($value == "on") $checkboxchecked = " CHECKED";
337
			echo "<input type='checkbox' name='" . $pkga['fieldname'] . "'" . $checkboxchecked . ">\n";
338
			echo "<br>" . fixup_string($pkga['description']) . "\n";
339
	      } else if($pkga['type'] == "textarea") {
340
		  if($pkga['rows']) $rows = " rows='" . $pkga['rows'] . "' ";
341
		  if($pkga['cols']) $cols = " cols='" . $pkga['cols'] . "' ";
342
			echo "<textarea " . $rows . $cols . " name='" . $pkga['fieldname'] . "'>" . $value . "</textarea>\n";
343
			echo "<br>" . fixup_string($pkga['description']) . "\n";
344
		  } else if($pkga['type'] == "interfaces_selection") {
345
			$size = "";
346
			$multiple = "";
347
			$fieldname = $pkga['fieldname'];
348
			if($pkga['size'] <> "") $size = " size=\"" . $pkga['size'] . "\"";
349
			if($pkga['multiple'] <> "" and $pkga['multiple'] <> "0") {
350
			  $multiple = " multiple=\"multiple\"";
351
			  $fieldname .= "[]";
352
			}
353
			echo "<select name='" . $fieldname . "'" . $size . $multiple . ">\n";
354
			foreach ($config['interfaces'] as $ifname => $iface) {
355
			  if ($iface['descr'])
356
				  $ifdescr = $iface['descr'];
357
			  else
358
				  $ifdescr = strtoupper($ifname);
359
			  $ifname = $iface['descr'];
360
			  $SELECTED = "";
361
			  if($value == $ifname) $SELECTED = " SELECTED";
362
			  echo "<option value='" . $ifdescr . "'" . $SELECTED . ">" . $ifdescr . "</option>\n";
363
			}
364
			echo "</select>\n";
365
			echo "<br>" . fixup_string($pkga['description']) . "\n";
366
	      } else if($pkga['type'] == "radio") {
367
			echo "<input type='radio' name='" . $pkga['fieldname'] . "' value='" . $value . "'>";
368
	      } else if($pkga['type'] == "rowhelper") {
369
		?>
370
			<script type="text/javascript" language='javascript'>
371
			<!--
372

    
373
			<?php
374
				$rowcounter = 0;
375
				$fieldcounter = 0;
376
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
377
					echo "rowname[" . $fieldcounter . "] = \"" . $rowhelper['fieldname'] . "\";\n";
378
					echo "rowtype[" . $fieldcounter . "] = \"" . $rowhelper['type'] . "\";\n";
379
					$fieldcounter++;
380
				}
381
			?>
382

    
383
			-->
384
			</script>
385

    
386
			<table name="maintable" id="maintable">
387
			<tr>
388
			<?php
389
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
390
				  echo "<td><b>" . fixup_string($rowhelper['fielddescr']) . "</td>\n";
391
				}
392
				echo "</tr>";
393
				echo "<tbody>";
394

    
395
				echo "<tr>";
396
				  // XXX: traverse saved fields, add back needed rows.
397
				echo "</tr>";
398

    
399
				echo "<tr>\n";
400
				$rowcounter = 0;
401
				$trc = 0;
402
				if(isset($a_pkg[$id]['row'])) {
403
					foreach($a_pkg[$id]['row'] as $row) {
404
					/*
405
					 * loop through saved data for record if it exists, populating rowhelper
406
					 */
407
						foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
408
							if($rowhelper['value'] <> "") $value = $rowhelper['value'];
409
							$fieldname = $rowhelper['fieldname'];
410
							// if user is editing a record, load in the data.
411
							if (isset($id) && $a_pkg[$id]) {
412
								$toeval = "\$value = \$row['" . $fieldname . "'];";
413
								echo "<!-- eval: " . $toeval . "-->\n";
414
								eval($toeval);
415
								echo "<!-- value: " . $value . "-->\n";
416
							}
417
							$options = "";
418
							$type = $rowhelper['type'];
419
							$fieldname = $rowhelper['fieldname'];
420
							if($type == "option") $options = &$rowhelper['options']['option'];
421
							$size = "8";
422
							if($rowhelper['size'] <> "") $size = $rowhelper['size'];
423
							display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
424
							// javascript helpers for row_helper_dynamic.js
425
							echo "</td>\n";
426
							echo "<script language=\"JavaScript\">\n";
427
							echo "<!--\n";
428
							echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
429
							echo "-->\n";
430
							echo "</script>\n";
431
							$text = "";
432
							$trc++;
433
						}
434

    
435
						$rowcounter++;
436
						echo "<td>";
437
						echo "<input type=\"image\" src=\"/x.gif\" onclick=\"removeRow(this); return false;\" value=\"Delete\">";
438
						echo "</td>\n";
439
						echo "</tr>\n";
440
					}
441
				}
442
				if($trc == 0) {
443
					/*
444
					 *  no records loaded.
445
                                         *  just show a generic line non-populated with saved data
446
                                         */
447
                                        foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
448
						if($rowhelper['value'] <> "") $value = $rowhelper['value'];
449
						$fieldname = $rowhelper['fieldname'];
450
						$options = "";
451
						$type = $rowhelper['type'];
452
						$fieldname = $rowhelper['fieldname'];
453
						if($type == "option") $options = &$rowhelper['options']['option'];
454
						$size = "8";
455
						if($rowhelper['size'] <> "") $size = $rowhelper['size'];
456
						display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
457
						// javascript helpers for row_helper_dynamic.js
458
						echo "</td>\n";
459
						echo "<script language=\"JavaScript\">\n";
460
						echo "<!--\n";
461
						echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
462
						echo "-->\n";
463
						echo "</script>\n";
464
						$text = "";
465
						$trc++;
466
					}
467

    
468
					$rowcounter++;
469
				}
470
			?>
471

    
472
			  </tbody>
473
			</table>
474

    
475
		<br><a onClick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="/plus.gif"></a>
476
		<script language="JavaScript">
477
		<!--
478
		field_counter_js = <?= $fieldcounter ?>;
479
		rows = <?= $rowcounter ?>;
480
		totalrows = <?php echo $rowcounter; ?>;
481
		loaded = <?php echo $rowcounter; ?>;
482
		//typesel_change();
483
		//-->
484
		</script>
485

    
486
		<?php
487
	      }
488
	      if($pkga['typehint']) echo " " . $pkga['typehint'];
489
	     ?>
490

    
491
      <?php
492
	  if(!$pkga['combinefieldsbegin']) echo "</td></tr>";
493
      $i++;
494
  }
495
 ?>
496
  <tr>
497
	<td>&nbsp;</td>
498
  </tr>
499
  <tr>
500
    <td width="22%" valign="top">&nbsp;</td>
501
    <td width="78%">
502
      <input name="Submit" type="submit" class="formbtn" value="<?= $savevalue ?>">
503
      <?php if (isset($id) && $a_pkg[$id]): ?>
504
      <input name="id" type="hidden" value="<?=$id;?>">
505
      <?php endif; ?>
506
    </td>
507
  </tr>
508
</table>
509

    
510
<?php
511
if ($pkg['tabs'] <> "") {
512
    echo "</td></tr></table>";
513
}
514
?>
515

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

    
518
</form>
519
<?php include("fend.inc"); ?>
520
</body>
521
</html>
522

    
523
<?php
524

    
525
/*
526
 * ROW Helpers function
527
 */
528
function display_row($trc, $value, $fieldname, $type, $rowhelper, $size) {
529
	global $text;
530
	echo "<td>\n";
531
	if($type == "input") {
532
		echo "<input size='" . $size . "' name='" . $fieldname . $trc . "' value='" . $value . "'>\n";
533
	} else if($type == "password") {
534
		echo "<input size='" . $size . "' type='password' name='" . $fieldname . $trc . "' value='" . $value . "'>\n";
535
	} else if($type == "textarea") {
536
		echo "<textarea rows='2' cols='12' name='" . $fieldname . $trc . "'>" . $value . "</textarea>\n";
537
	} else if($type == "select") {
538
		echo "<select name='" . $fieldname . $trc . "'>\n";
539
		foreach($rowhelper['options']['option'] as $rowopt) {
540
			$selected = "";
541
			if($rowopt['value'] == $value) $selected = " SELECTED";
542
			$text .= "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>";
543
			echo "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>\n";
544
		}
545
		echo "</select>\n";
546
	}
547
}
548

    
549
function fixup_string($string) {
550
	global $config;
551
	// fixup #1: $myurl -> http[s]://ip_address:port/
552
	$https = "";
553
	$port = "";
554
	$urlport = "";
555
	$port = $config['system']['webguiport'];
556
	if($port <> "443" and $port <> "80") $urlport = ":" . $port;
557
	if($config['system']['webguiproto'] == "https") $https = "s";
558
	$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlportport;
559
	$newstring = str_replace("\$myurl", $myurl, $string);
560
	$string = $newstring;
561
	// fixup #2: $wanip
562
	$curwanip = get_current_wan_address();
563
	$newstring = str_replace("\$wanip", $curwanip, $string);
564
	$string = $newstring;
565
	// fixup #3: $lanip
566
	$lancfg = $config['interfaces']['lan'];
567
	$lanip = $lancfg['ipaddr'];
568
	$newstring = str_replace("\$lanip", $lanip, $string);
569
	$string = $newstring;
570
	// fixup #4: fix'r'up here.
571
	return $newstring;
572
}
573

    
574
/*
575
 *  Parse templates if they are defined
576
 */
577
function parse_package_templates() {
578
	global $pkg, $config;
579
	if($pkg['templates']['template'] <> "")
580
	    foreach($pkg['templates']['template'] as $pkg_template_row) {
581
		$filename = $pkg_template_row['filename'];
582
		$template_text = $pkg_template_row['templatecontents'];
583

    
584
		/* calculate total row helpers count */
585
		foreach ($pkg['fields']['field'] as $fields) {
586
			if($fields['type'] == "rowhelper") {
587
				// save rowhelper items.
588
                                $row_helper_total_rows = 0;
589
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
590
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
591
						if($firstfield == "")  {
592
						  $firstfield = $rowhelperfield['fieldname'];
593
						} else {
594
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
595
						}
596
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
597
						eval($comd);
598
						if($value <> "") {
599
						    //$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
600
						} else {
601
						    $row_helper_total_rows = $rows;
602
						    break;
603
						}
604
					}
605
				}
606
			}
607
		}
608

    
609
		/* replace $domain_total_rows with total rows */
610
		$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
611

    
612
		/* change fields defined as fieldname_fieldvalue to their value */
613
		foreach ($pkg['fields']['field'] as $fields) {
614
			if($fields['type'] == "rowhelper") {
615
				// save rowhelper items.
616
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
617
					$row_helper_data = "";
618
					$isfirst = 0;
619
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
620
						if($firstfield == "")  {
621
						  $firstfield = $rowhelperfield['fieldname'];
622
						} else {
623
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
624
						}
625
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
626
						eval($comd);
627
						if($value <> "") {
628
						    if($isfirst == 1) $row_helper_data .= "  " ;
629
						    $row_helper_data .= $value;
630
						    $isfirst = 1;
631
						}
632
						ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
633
						foreach ($sep as $se) $seperator = $se;
634
						if($seperator <> "") {
635
						    $row_helper_data = ereg_replace("  ", $seperator, $row_helper_data);
636
						    $template_text = ereg_replace("\[" . $seperator . "\]", "", $template_text);
637
						}
638
						$template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
639
					}
640
				}
641
			} else {
642
				$fieldname  = $fields['fieldname'];
643
				$fieldvalue = $_POST[$fieldname];
644
				$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
645
			}
646
		}
647

    
648
		/* replace cr's */
649
		$template_text = str_replace("\\n", "\n", $template_text);
650

    
651
		/* write out new template file */
652
		$fout = fopen($filename,"w");
653
		fwrite($fout, $template_text);
654
		fclose($fout);
655
	    }
656
}
657

    
658
?>
(58-58/111)