Project

General

Profile

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

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

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

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

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

    
30
require("guiconfig.inc");
31
require("xmlparse_pkg.inc");
32

    
33
$pfSense_config = $config; // copy this since we will be parsing
34
                           // another xml file which will be clobbered.
35

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

    
41
// XXX: Make this input safe.
42
$xml = $_GET['xml'];
43
if($_POST['xml']) $xml = $_POST['xml'];
44

    
45
if($xml == "") {
46
            $xml = "not_defined";
47
            print_info_box_np("ERROR:  Could not open " . $xml . ".");
48
            die;
49
} else {
50
            $pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
51
}
52

    
53
$package_name = $pkg['menu'][0]['name'];
54
$section      = $pkg['menu'][0]['section'];
55
$config_path  = $pkg['configpath'];
56
$title        = $section . ": " . $package_name;
57

    
58
$id = $_GET['id'];
59
if (isset($_POST['id']))
60
	$id = $_POST['id'];
61

    
62
$toeval = "if (!is_array(\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'])) \$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'] = array();";
63
eval($toeval);
64

    
65
$toeval = "\$a_pkg = &\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'];";
66
eval($toeval);
67

    
68
if($pkg['custom_php_command_before_form'] <> "")
69
  eval($pkg['custom_php_command_before_form']);
70

    
71

    
72
if ($_POST) {
73
	if($_POST['act'] == "del") {
74
		if($pkg['custom_delete_php_command']) {
75
		    eval($pkg['custom_delete_php_command']);
76
		}
77
		write_config();
78
		// resync the configuration file code if defined.
79
		if($pkg['custom_php_resync_config_command'] <> "") {
80
		    eval($pkg['custom_php_resync_config_command']);
81
		}
82
	} else {
83
		if($pkg['custom_add_php_command']) {
84
			if($pkg['donotsave'] <> "") {
85
				?>
86
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
87
<html>
88
<head>
89
<title><?=gentitle_pkg($title);?></title>
90
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
91
<link href="gui.css" rel="stylesheet" type="text/css">
92
</head>
93

    
94
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
95
<?php
96
include("fbegin.inc");
97
?>
98
<p class="pgtitle"><?=$title?></p>
99
				<?php
100
			}
101
			if($pkg['preoutput']) echo "<pre>";
102
			eval($pkg['custom_add_php_command']);
103
			if($pkg['preoutput']) echo "</pre>";
104
		}
105
	}
106

    
107
	// donotsave is enabled.  lets simply exit.
108
	if($pkg['donotsave'] <> "") exit;
109

    
110
	$firstfield = "";
111
	$rows = 0;
112

    
113
	// store values in xml configration file.
114
	if (!$input_errors) {
115
		$pkgarr = array();
116
		foreach ($pkg['fields']['field'] as $fields) {
117
			if($fields['type'] == "rowhelper") {
118
				// save rowhelper items.
119
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
120
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
121
						if($firstfield == "")  {
122
						  $firstfield = $rowhelperfield['fieldname'];
123
						} else {
124
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
125
						}
126
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
127
						//echo($comd . "<br>");
128
						eval($comd);
129
						if($value <> "") {
130
							$comd = "\$pkgarr['row'][" . $x . "]['" . $rowhelperfield['fieldname'] . "'] = \"" . $value . "\";";
131
							//echo($comd . "<br>");
132
							eval($comd);
133
						}
134
					}
135
				}
136
			} else {
137
				// simply loop through all field names looking for posted
138
				// values matching the fieldnames.  if found, save to package
139
				// configuration area.
140
				$fieldname  = $fields['fieldname'];
141
				$fieldvalue = $_POST[$fieldname];
142
				$toeval = "\$pkgarr['" . $fieldname . "'] 	= \"" . $fieldvalue . "\";";
143
				eval($toeval);
144
			}
145
		}
146

    
147
		if (isset($id) && $a_pkg[$id])
148
			$a_pkg[$id] = $pkgarr;
149
		else
150
			$a_pkg[] = $pkgarr;
151

    
152
		write_config();
153

    
154
		// late running code
155
		if($pkg['custom_add_php_command_late'] <> "") {
156
		    eval($pkg['custom_add_php_command_late']);
157
		}
158

    
159
		// resync the configuration file code if defined.
160
		if($pkg['custom_php_resync_config_command'] <> "") {
161
		    eval($pkg['custom_php_resync_config_command']);
162
		}
163

    
164
		header("Location:  pkg.php?xml=" . $xml);
165
		exit;
166
	}
167
}
168

    
169
?>
170
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
171
<html>
172
<head>
173
<title><?=gentitle_pkg($title);?></title>
174
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
175
<link href="gui.css" rel="stylesheet" type="text/css">
176
</head>
177

    
178
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
179

    
180
<script type="text/javascript" language="javascript" src="row_helper_dynamic.js">
181
</script>
182

    
183
<?php
184
$config_tmp = $config;
185
$config = $pfSense_config;
186
include("fbegin.inc");
187
$config = $config_tmp;
188
?>
189
<p class="pgtitle"><?=$title?></p>
190
<form action="pkg_edit.php" method="post">
191
<input type="hidden" name="xml" value="<?= $xml ?>">
192
<?php if ($savemsg) print_info_box($savemsg); ?>
193

    
194
&nbsp;<br>
195

    
196
<table width="100%" border="0" cellpadding="6" cellspacing="0">
197
  <?php
198
  $cols = 0;
199
  $savevalue = "Save";
200
  if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
201
  foreach ($pkg['fields']['field'] as $pkga) { ?>
202

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

    
205
	  <?php
206
	  if(!$pkga['dontdisplayname']) {
207
       echo "<td width=\"22%\" class=\"vncellreq\">";
208
	   echo $pkga['fielddescr'];
209
       echo "</td>";
210
	  }
211

    
212
	  if(!$pkga['dontcombinecells'])
213
		echo "<td class=\"vtable\">";
214

    
215
	      if($pkga['type'] == "input") {
216
			if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
217
			echo "<input " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
218
			echo "<br>" . $pkga['description'] . "\n";
219
	      } else if($pkga['type'] == "password") {
220
			echo "<input type='password' " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
221
			echo "<br>" . $pkga['description'] . "\n";
222
	      } else if($pkga['type'] == "select") {
223
		  // XXX: TODO: set $selected
224
                  if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
225
		  if($pkga['multiple'] == "yes") $multiple = "MULTIPLE ";
226
			echo "<select " . $multiple . $size . "id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "'>\n";
227
		  foreach ($pkga['options']['option'] as $opt) {
228
		      echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'>" . $opt['name'] . "</option>\n";
229
		  }
230
		   echo "</select>\n";
231
		   echo "<br>" . $pkga['description'] . "\n";
232
	      } else if($pkga['type'] == "checkbox") {
233
			echo "<input type='checkbox' name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
234
			echo "<br>" . $pkga['description'] . "\n";
235
	      } else if($pkga['type'] == "textarea") {
236
		  if($pkga['rows']) $rows = " rows='" . $pkga['rows'] . "' ";
237
		  if($pkga['cols']) $cols = " cols='" . $pkga['cols'] . "' ";
238
			echo "<textarea " . $rows . $cols . " name='" . $pkga['fieldname'] . "'>" . $value . "</textarea>\n";
239
			echo "<br>" . $pkga['description'] . "\n";
240
		  } else if($pkga['type'] == "interfaces_selection") {
241
			$size = "";
242
			$multiple = "";
243
			$fieldname = $pkga['fieldname'];
244
			if($pkga['size'] <> "") $size = " size=\"" . $pkga['size'] . "\"";
245
			if($pkga['multiple'] <> "") {
246
			  $multiple = " multiple=\"multiple\"";
247
			  $fieldname .= "[]";
248
			}
249
			echo "<select name='" . $fieldname . "'" . $size . $multiple . ">\n";
250
			foreach ($config['interfaces'] as $ifname => $iface) {
251
			  if ($iface['descr'])
252
				  $ifdescr = $iface['descr'];
253
			  else
254
				  $ifdescr = strtoupper($ifname);
255
				$ifname = $iface['if'];
256
				echo "<option value='" . $ifname . "'>" . $ifdescr . "</option>\n";
257
			}
258
			echo "</select>\n";
259
	      } else if($pkga['type'] == "radio") {
260
			echo "<input type='radio' name='" . $pkga['fieldname'] . "' value='" . $value . "'>";
261
	      } else if($pkga['type'] == "rowhelper") {
262
		?>
263
			<script type="text/javascript" language='javascript'>
264
			<!--
265

    
266
			<?php
267
				$rowcounter = 0;
268
				$fieldcounter = 0;
269
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
270
					echo "rowname[" . $fieldcounter . "] = \"" . $rowhelper['fieldname'] . "\";\n";
271
					echo "rowtype[" . $fieldcounter . "] = \"" . $rowhelper['type'] . "\";\n";
272
					$fieldcounter++;
273
				}
274
			?>
275

    
276
			-->
277
			</script>
278

    
279
			<table name="maintable" id="maintable">
280
			<tr>
281
			<?php
282
			foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
283
			  echo "<td><b>" . $rowhelper['fielddescr'] . "</td>\n";
284
			}
285
				echo "</tr>";
286
				echo "<tbody>";
287

    
288
				echo "<tr>";
289
				  // XXX: traverse saved fields, add back needed rows.
290
				echo "</tr>";
291

    
292
				if($rowcounter == 0) {
293
					// nothing saved.  manually add the first row.
294
                                        echo "<tr>\n";
295
					$rowcounter = 0;
296
					$trc = 0;
297
					foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
298
						$temp = "";
299
						$text = "";
300
						$value = "";
301
						if($rowhelper['value'] <> "") $value = $rowhelper['value'];
302
						echo "<td>\n";
303
						if($rowhelper['type'] == "input") {
304
							echo "<input size='8' name='" . $rowhelper['fieldname'] . "0" . "' value='" . $value . "'>\n";
305
						} else if($rowhelper['type'] == "password") {
306
							echo "<input type='password' name='" . $rowhelper['fieldname'] . "0" . "' value='" . $value . "'>\n";
307
						} else if($rowhelper['type'] == "textarea") {
308
							echo "<textarea name='" . $rowhelper['fieldname'] . "0" . "'>" . $value . "</textarea>\n";
309
						} else if($rowhelper['type'] == "select") {
310
							echo "<select name='" . $rowhelper['fieldname'] . "0" . "'>\n";
311
							foreach($rowhelper['options']['option'] as $rowopt) {
312
								$text .= "<option value='" . $rowopt['value'] . "'>" . $rowopt['name'] . "</option>";
313
								echo "<option value='" . $rowopt['value'] . "'>" . $rowopt['name'] . "</option>\n";
314
							}
315
							echo "</select>\n";
316
						}
317
						echo "</td>\n";
318
						echo "<script language=\"JavaScript\">\n";
319
						echo "<!--\n";
320
						echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
321
						echo "-->\n";
322
						echo "</script>\n";
323
						$trc++;
324
					}
325
					$rowcounter=0;
326
					echo "<td>";
327
					echo "<input type=\"button\" onclick=\"removeRow(this); typesel_change();\" value=\"Delete\">";
328
					echo "</td>\n";
329
					echo "</tr>\n";
330
				}
331
			?>
332

    
333
			  </tbody>
334
			</table>
335

    
336
		<br><input type="button" onclick="addRowTo('maintable'); typesel_change();" value="Add">
337

    
338
		<script language="JavaScript">
339
		<!--
340
		field_counter_js = <?= $fieldcounter ?>;
341
		rows = <?= $rowcounter ?>;
342
		totalrows = <?php echo $rowcounter; ?>;
343
		loaded = <?php echo $rowcounter; ?>;
344
		typesel_change();
345
		//-->
346
		</script>
347

    
348
		<?php
349
	      }
350
	      if($pkga['typehint']) echo " " . $pkga['typehint'];
351
	     ?>
352

    
353
      <?php
354
	  if(!$pkga['combinefieldsbegin']) echo "</td></tr>";
355
      $i++;
356
  }
357
 ?>
358
  <tr>
359
	<td>&nbsp;</td>
360
  </tr>
361
  <tr>
362
    <td width="22%" valign="top">&nbsp;</td>
363
    <td width="78%">
364
      <input name="Submit" type="submit" class="formbtn" value="<?= $savevalue ?>">
365
      <?php if (isset($id) && $a_pkg[$id]): ?>
366
      <input name="id" type="hidden" value="<?=$id;?>">
367
      <?php endif; ?>
368
    </td>
369
  </tr>
370
</table>
371

    
372
</form>
373
<?php include("fend.inc"); ?>
374
</body>
375
</html>
376

    
(53-53/99)