Project

General

Profile

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