Project

General

Profile

Download (6.95 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']['name'];
54
$section      = $pkg['menu']['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 ($_POST) {
69
	if($_POST['act'] == "del") {
70
		if($pkg['custom_delete_php_command']) {
71
		    eval($pkg['custom_delete_php_command']);
72
		}
73
		write_config();
74
	} else {
75
		if($pkg['custom_add_php_command']) {
76
			if($pkg['donotsave'] <> "") {
77
				?>
78
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
79
<html>
80
<head>
81
<title><?=gentitle_pkg($title);?></title>
82
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
83
<link href="gui.css" rel="stylesheet" type="text/css">
84
</head>
85

    
86
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
87
<?php
88
include("fbegin.inc");
89
?>
90
<p class="pgtitle"><?=$title?></p>
91
				<?php
92
			}
93
			if($pkg['preoutput']) echo "<pre>";
94
			eval($pkg['custom_add_php_command']);
95
			if($pkg['preoutput']) echo "</pre>";
96
		}
97
	}
98

    
99
	if($pkg['donotsave'] <> "") exit;
100

    
101
	// store values in xml configration file.
102
	if (!$input_errors) {
103
		$pkgarr = array();
104

    
105
		foreach ($pkg['fields']['field'] as $fields) {
106
			$fieldname  		= $fields['fieldname'];
107
			$fieldvalue 		= $_POST[$fieldname];
108
			$toeval = "\$pkgarr['" . $fieldname . "'] 	= \"" . $fieldvalue . "\";";
109
			eval($toeval);
110
		}
111

    
112
		if (isset($id) && $a_pkg[$id])
113
			$a_pkg[$id] = $pkgarr;
114
		else
115
			$a_pkg[] = $pkgarr;
116

    
117
		write_config();
118

    
119
		header("Location:  pkg.php?xml=" . $xml);
120
	}
121
}
122

    
123
?>
124
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
125
<html>
126
<head>
127
<title><?=gentitle_pkg($title);?></title>
128
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
129
<link href="gui.css" rel="stylesheet" type="text/css">
130
</head>
131

    
132
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
133
<?php
134
$config_tmp = $config;
135
$config = $pfSense_config;
136
include("fbegin.inc");
137
$config = $config_tmp;
138
?>
139
<p class="pgtitle"><?=$title?></p>
140
<form action="pkg_edit.php" method="post">
141
<input type="hidden" name="xml" value="<?= $xml ?>">
142
<?php if ($savemsg) print_info_box($savemsg); ?>
143

    
144
&nbsp;<br>
145

    
146
<table width="100%" border="0" cellpadding="6" cellspacing="0">
147
  <tr>
148
  <?php
149
  $cols = 0;
150
  $savevalue = "Save";
151
  if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
152
  foreach ($pkg['fields']['field'] as $pkga) { ?>
153
      </tr>
154
      <tr valign="top">
155
       <td width="22%" class="vncellreq">
156
	  <?= $pkga['fielddescr'] ?>
157
       </td>
158
       <td class="vtable">
159
	  <?php
160

    
161
	      if($pkga['type'] == "input") {
162
		  // XXX: TODO: set $value
163
                  if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
164
		  echo "<input " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
165
		  echo "<br>" . $pkga['description'] . "\n";
166
	      } else if($pkga['type'] == "password") {
167
		  echo "<input type='password' " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
168
		  echo "<br>" . $pkga['description'] . "\n";
169
	      } else if($pkga['type'] == "select") {
170
		  // XXX: TODO: set $selected
171
                  if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
172
		  if($pkga['multiple'] == "yes") $multiple = "MULTIPLE ";
173
		  echo "<select " . $multiple . $size . "id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "'>\n";
174
		  foreach ($pkga['options']['option'] as $opt) {
175
		      echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'>" . $opt['name'] . "</option>\n";
176
		  }
177
		  echo "</select>\n";
178
		  echo "<br>" . $pkga['description'] . "\n";
179
	      } else if($pkga['type'] == "checkbox") {
180
		  echo "<input type='checkbox' name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
181
		  echo "<br>" . $pkga['description'] . "\n";
182
	      } else if($pkga['type'] == "textarea") {
183
		  if($pkga['rows']) $rows = " rows='" . $pkga['rows'] . "' ";
184
		  if($pkga['cols']) $cols = " cols='" . $pkga['cols'] . "' ";
185
		  echo "<textarea " . $rows . $cols . " name='" . $pkga['fieldname'] . "'>" . $value . "</textarea>\n";
186
		  echo "<br>" . $pkga['description'] . "\n";
187
	      } else if($pkga['type'] == "radio") {
188
		  echo "<input type='radio' name='" . $pkga['fieldname'] . "' value='" . $value . "'>";
189
	      }
190
	      
191
	      if($pkga['typehint']) echo " " . $pkga['typehint'];
192
	  ?>
193
       </td>
194
      </tr>
195
      <?php
196
      $i++;
197
  }
198
 ?>
199
  <tr>
200
    <td width="22%" valign="top">&nbsp;</td>
201
    <td width="78%">
202
      <input name="Submit" type="submit" class="formbtn" value="<?= $savevalue ?>">
203
      <?php if (isset($id) && $a_pkg[$id]): ?>
204
      <input name="id" type="hidden" value="<?=$id;?>">
205
      <?php endif; ?>
206
    </td>
207
  </tr>
208
</table>
209

    
210
</form>
211
<?php include("fend.inc"); ?>
212
</body>
213
</html>
214

    
(52-52/97)