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
|
<tabs>
|
30
|
<tab>
|
31
|
<text>Testing Tab</text>
|
32
|
<url>url to go to</url>
|
33
|
</tab>
|
34
|
<tab>
|
35
|
<text>Testing Tab 2</text>
|
36
|
<xml>filename of xml</xml>
|
37
|
</tab>
|
38
|
</tabs>
|
39
|
|
40
|
*/
|
41
|
|
42
|
require("guiconfig.inc");
|
43
|
require("xmlparse_pkg.inc");
|
44
|
|
45
|
$pfSense_config = $config; // copy this since we will be parsing
|
46
|
// another xml file which will be clobbered.
|
47
|
|
48
|
function gentitle_pkg($pgname) {
|
49
|
global $pfSense_config;
|
50
|
return $pfSense_config['system']['hostname'] . "." . $pfSense_config['system']['domain'] . " - " . $pgname;
|
51
|
}
|
52
|
|
53
|
// XXX: Make this input safe.
|
54
|
$xml = $_GET['xml'];
|
55
|
if($_POST['xml']) $xml = $_POST['xml'];
|
56
|
|
57
|
if($xml == "") {
|
58
|
$xml = "not_defined";
|
59
|
print_info_box_np("ERROR: Could not open " . $xml . ".");
|
60
|
die;
|
61
|
} else {
|
62
|
$pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
|
63
|
}
|
64
|
|
65
|
$package_name = $pkg['menu'][0]['name'];
|
66
|
$section = $pkg['menu'][0]['section'];
|
67
|
$config_path = $pkg['configpath'];
|
68
|
$name = $pkg['name'];
|
69
|
$title = $section . ": " . $package_name;
|
70
|
|
71
|
$id = $_GET['id'];
|
72
|
if (isset($_POST['id']))
|
73
|
$id = $_POST['id'];
|
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($pkg['custom_php_command_before_form'] <> "")
|
86
|
eval($pkg['custom_php_command_before_form']);
|
87
|
|
88
|
|
89
|
if ($_POST) {
|
90
|
if($_POST['act'] == "del") {
|
91
|
if($pkg['custom_delete_php_command']) {
|
92
|
if($pkg['custom_php_command_before_form'] <> "")
|
93
|
eval($pkg['custom_php_command_before_form']);
|
94
|
eval($pkg['custom_delete_php_command']);
|
95
|
}
|
96
|
write_config();
|
97
|
// resync the configuration file code if defined.
|
98
|
if($pkg['custom_php_resync_config_command'] <> "") {
|
99
|
if($pkg['custom_php_command_before_form'] <> "")
|
100
|
eval($pkg['custom_php_command_before_form']);
|
101
|
eval($pkg['custom_php_resync_config_command']);
|
102
|
}
|
103
|
} else {
|
104
|
if($pkg['custom_add_php_command']) {
|
105
|
if($pkg['donotsave'] <> "") {
|
106
|
?>
|
107
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
108
|
<html>
|
109
|
<head>
|
110
|
<title><?=gentitle_pkg($title);?></title>
|
111
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
112
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
113
|
</head>
|
114
|
|
115
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
116
|
<?php
|
117
|
include("fbegin.inc");
|
118
|
|
119
|
?>
|
120
|
<p class="pgtitle"><?=$title?></p>
|
121
|
<?php
|
122
|
}
|
123
|
if($pkg['preoutput']) echo "<pre>";
|
124
|
eval($pkg['custom_add_php_command']);
|
125
|
if($pkg['preoutput']) echo "</pre>";
|
126
|
}
|
127
|
}
|
128
|
|
129
|
// donotsave is enabled. lets simply exit.
|
130
|
if($pkg['donotsave'] <> "") exit;
|
131
|
|
132
|
$firstfield = "";
|
133
|
$rows = 0;
|
134
|
|
135
|
// store values in xml configration file.
|
136
|
if (!$input_errors) {
|
137
|
$pkgarr = array();
|
138
|
foreach ($pkg['fields']['field'] as $fields) {
|
139
|
if($fields['type'] == "rowhelper") {
|
140
|
// save rowhelper items.
|
141
|
for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
|
142
|
// XXX: this really is not helping embedded platforms.
|
143
|
foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
|
144
|
if($firstfield == "") {
|
145
|
$firstfield = $rowhelperfield['fieldname'];
|
146
|
} else {
|
147
|
if($firstfield == $rowhelperfield['fieldname']) $rows++;
|
148
|
}
|
149
|
$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
|
150
|
//echo($comd . "<br>");
|
151
|
eval($comd);
|
152
|
if($value <> "") {
|
153
|
$comd = "\$pkgarr['row'][" . $x . "]['" . $rowhelperfield['fieldname'] . "'] = \"" . $value . "\";";
|
154
|
//echo($comd . "<br>");
|
155
|
eval($comd);
|
156
|
}
|
157
|
}
|
158
|
}
|
159
|
} else {
|
160
|
// simply loop through all field names looking for posted
|
161
|
// values matching the fieldnames. if found, save to package
|
162
|
// configuration area.
|
163
|
|
164
|
$fieldname = $fields['fieldname'];
|
165
|
$fieldvalue = $_POST[$fieldname];
|
166
|
$toeval = "\$pkgarr['" . $fieldname . "'] = \"" . $fieldvalue . "\";";
|
167
|
eval($toeval);
|
168
|
}
|
169
|
}
|
170
|
|
171
|
if (isset($id) && $a_pkg[$id])
|
172
|
$a_pkg[$id] = $pkgarr;
|
173
|
else
|
174
|
$a_pkg[] = $pkgarr;
|
175
|
|
176
|
write_config();
|
177
|
|
178
|
// late running code
|
179
|
if($pkg['custom_add_php_command_late'] <> "") {
|
180
|
eval($pkg['custom_add_php_command_late']);
|
181
|
}
|
182
|
|
183
|
// resync the configuration file code if defined.
|
184
|
if($pkg['custom_php_resync_config_command'] <> "") {
|
185
|
eval($pkg['custom_php_resync_config_command']);
|
186
|
}
|
187
|
|
188
|
parse_package_templates();
|
189
|
|
190
|
/* if start_command is defined, restart w/ this */
|
191
|
if($pkg['start_command'] <> "")
|
192
|
exec($pkg['start_command'] . ">/dev/null 2&>1");
|
193
|
|
194
|
/* if restart_command is defined, restart w/ this */
|
195
|
if($pkg['restart_command'] <> "")
|
196
|
exec($pkg['restart_command'] . ">/dev/null 2&>1");
|
197
|
|
198
|
if($pkg['aftersaveredirect'] <> "") {
|
199
|
header("Location: " . $pkg['aftersaveredirect']);
|
200
|
} else {
|
201
|
header("Location: pkg.php?xml=" . $xml);
|
202
|
}
|
203
|
exit;
|
204
|
}
|
205
|
}
|
206
|
|
207
|
?>
|
208
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
209
|
<html>
|
210
|
<head>
|
211
|
<?php
|
212
|
if($pkg['title'] <> "") $title = $pkg['title'];
|
213
|
?>
|
214
|
<title><?=gentitle_pkg($title);?></title>
|
215
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
216
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
217
|
</head>
|
218
|
|
219
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
220
|
|
221
|
<script type="text/javascript" language="javascript" src="row_helper_dynamic.js">
|
222
|
</script>
|
223
|
|
224
|
<?php
|
225
|
$config_tmp = $config;
|
226
|
$config = $pfSense_config;
|
227
|
include("fbegin.inc");
|
228
|
$config = $config_tmp;
|
229
|
?>
|
230
|
<p class="pgtitle"><?=$title?></p>
|
231
|
<form action="pkg_edit.php" method="post">
|
232
|
<input type="hidden" name="xml" value="<?= $xml ?>">
|
233
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
234
|
|
235
|
<?php
|
236
|
if ($pkg['tabs'] <> "") {
|
237
|
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
|
238
|
echo "<tr><td>";
|
239
|
echo " <ul id=\"tabnav\">";
|
240
|
foreach($pkg['tabs']['tab'] as $tab) {
|
241
|
$active = "tabinact";
|
242
|
if(isset($tab['active'])) $active = "tabact";
|
243
|
|
244
|
$urltmp = "";
|
245
|
$title = $tab['text'];
|
246
|
if($tab['url'] <> "") $urltmp = $tab['url'];
|
247
|
if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml'];
|
248
|
|
249
|
$toeval = "\$myurl = \"" . getenv("HTTP_HOST") . "\"; \n";
|
250
|
eval($toeval);
|
251
|
// eval url so that above $myurl item can be processed if need be.
|
252
|
$toeval = "\$url = \"" . $urltmp . "\"; \n";
|
253
|
eval($toeval);
|
254
|
|
255
|
if($active == "tabinact") {
|
256
|
echo "<li class=\"{$active}\">";
|
257
|
echo "<a href=\"";
|
258
|
echo $url;
|
259
|
echo "\">";
|
260
|
echo $title;
|
261
|
echo "</a>";
|
262
|
echo "</li>";
|
263
|
} else {
|
264
|
echo "<li class=\"{$active}\">";
|
265
|
echo $title;
|
266
|
echo "</li>";
|
267
|
}
|
268
|
}
|
269
|
echo " </ul>";
|
270
|
echo "</td></tr>";
|
271
|
echo "<tr>";
|
272
|
echo "<td class=\"tabcont\">";
|
273
|
}
|
274
|
?>
|
275
|
|
276
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
277
|
<?php
|
278
|
$cols = 0;
|
279
|
$savevalue = "Save";
|
280
|
if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
|
281
|
foreach ($pkg['fields']['field'] as $pkga) { ?>
|
282
|
|
283
|
<?php if(!$pkga['combinefieldsend']) echo "<tr valign=\"top\">"; ?>
|
284
|
|
285
|
<?php
|
286
|
if(!$pkga['dontdisplayname']) {
|
287
|
echo "<td width=\"22%\" class=\"vncellreq\">";
|
288
|
echo fixup_string($pkga['fielddescr']);
|
289
|
echo "</td>";
|
290
|
}
|
291
|
|
292
|
if(!$pkga['dontcombinecells'])
|
293
|
echo "<td class=\"vtable\">";
|
294
|
|
295
|
// if user is editing a record, load in the data.
|
296
|
if (isset($id) && $a_pkg[$id]) {
|
297
|
$fieldname = $pkga['fieldname'];
|
298
|
$toeval = "\$value = \$a_pkg[" . $id . "]['" . $fieldname . "'];";
|
299
|
echo "<!-- eval: " . $toeval . "-->\n";
|
300
|
eval($toeval);
|
301
|
}
|
302
|
|
303
|
if($pkga['type'] == "input") {
|
304
|
if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
|
305
|
echo "<input " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
|
306
|
echo "<br>" . fixup_string($pkga['description']) . "\n";
|
307
|
} else if($pkga['type'] == "password") {
|
308
|
echo "<input type='password' " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
|
309
|
echo "<br>" . fixup_string($pkga['description']) . "\n";
|
310
|
} else if($pkga['type'] == "select") {
|
311
|
// XXX: TODO: set $selected
|
312
|
if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
|
313
|
if($pkga['multiple'] == "yes") $multiple = "MULTIPLE ";
|
314
|
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
|
echo "<br>" . fixup_string($pkga['description']) . "\n";
|
329
|
} else if($pkga['type'] == "checkbox") {
|
330
|
$checkboxchecked = "";
|
331
|
if($value == "on") $checkboxchecked = " CHECKED";
|
332
|
echo "<input type='checkbox' name='" . $pkga['fieldname'] . "'" . $checkboxchecked . ">\n";
|
333
|
echo "<br>" . fixup_string($pkga['description']) . "\n";
|
334
|
} else if($pkga['type'] == "textarea") {
|
335
|
if($pkga['rows']) $rows = " rows='" . $pkga['rows'] . "' ";
|
336
|
if($pkga['cols']) $cols = " cols='" . $pkga['cols'] . "' ";
|
337
|
echo "<textarea " . $rows . $cols . " name='" . $pkga['fieldname'] . "'>" . $value . "</textarea>\n";
|
338
|
echo "<br>" . fixup_string($pkga['description']) . "\n";
|
339
|
} else if($pkga['type'] == "interfaces_selection") {
|
340
|
$size = "";
|
341
|
$multiple = "";
|
342
|
$fieldname = $pkga['fieldname'];
|
343
|
if($pkga['size'] <> "") $size = " size=\"" . $pkga['size'] . "\"";
|
344
|
if($pkga['multiple'] <> "" and $pkga['multiple'] <> "0") {
|
345
|
$multiple = " multiple=\"multiple\"";
|
346
|
$fieldname .= "[]";
|
347
|
}
|
348
|
echo "<select name='" . $fieldname . "'" . $size . $multiple . ">\n";
|
349
|
foreach ($config['interfaces'] as $ifname => $iface) {
|
350
|
if ($iface['descr'])
|
351
|
$ifdescr = $iface['descr'];
|
352
|
else
|
353
|
$ifdescr = strtoupper($ifname);
|
354
|
$ifname = $iface['if'];
|
355
|
$SELECTED = "";
|
356
|
if($value == $ifname) $SELECTED = " SELECTED";
|
357
|
echo "<option value='" . $ifdescr . "'" . $SELECTED . ">" . $ifdescr . "</option>\n";
|
358
|
}
|
359
|
echo "</select>\n";
|
360
|
echo "<br>" . fixup_string($pkga['description']) . "\n";
|
361
|
} else if($pkga['type'] == "radio") {
|
362
|
echo "<input type='radio' name='" . $pkga['fieldname'] . "' value='" . $value . "'>";
|
363
|
} else if($pkga['type'] == "rowhelper") {
|
364
|
?>
|
365
|
<script type="text/javascript" language='javascript'>
|
366
|
<!--
|
367
|
|
368
|
<?php
|
369
|
$rowcounter = 0;
|
370
|
$fieldcounter = 0;
|
371
|
foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
|
372
|
echo "rowname[" . $fieldcounter . "] = \"" . $rowhelper['fieldname'] . "\";\n";
|
373
|
echo "rowtype[" . $fieldcounter . "] = \"" . $rowhelper['type'] . "\";\n";
|
374
|
$fieldcounter++;
|
375
|
}
|
376
|
?>
|
377
|
|
378
|
-->
|
379
|
</script>
|
380
|
|
381
|
<table name="maintable" id="maintable">
|
382
|
<tr>
|
383
|
<?php
|
384
|
foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
|
385
|
echo "<td><b>" . fixup_string($rowhelper['fielddescr']) . "</td>\n";
|
386
|
}
|
387
|
echo "</tr>";
|
388
|
echo "<tbody>";
|
389
|
|
390
|
echo "<tr>";
|
391
|
// XXX: traverse saved fields, add back needed rows.
|
392
|
echo "</tr>";
|
393
|
|
394
|
echo "<tr>\n";
|
395
|
$rowcounter = 0;
|
396
|
$trc = 0;
|
397
|
if(isset($a_pkg[$id]['row'])) {
|
398
|
foreach($a_pkg[$id]['row'] as $row) {
|
399
|
/*
|
400
|
* loop through saved data for record if it exists, populating rowhelper
|
401
|
*/
|
402
|
foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
|
403
|
if($rowhelper['value'] <> "") $value = $rowhelper['value'];
|
404
|
$fieldname = $rowhelper['fieldname'];
|
405
|
// if user is editing a record, load in the data.
|
406
|
if (isset($id) && $a_pkg[$id]) {
|
407
|
$toeval = "\$value = \$row['" . $fieldname . "'];";
|
408
|
echo "<!-- eval: " . $toeval . "-->\n";
|
409
|
eval($toeval);
|
410
|
echo "<!-- value: " . $value . "-->\n";
|
411
|
}
|
412
|
$options = "";
|
413
|
$type = $rowhelper['type'];
|
414
|
$fieldname = $rowhelper['fieldname'];
|
415
|
if($type == "option") $options = &$rowhelper['options']['option'];
|
416
|
$size = "8";
|
417
|
if($rowhelper['size'] <> "") $size = $rowhelper['size'];
|
418
|
display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
|
419
|
// javascript helpers for row_helper_dynamic.js
|
420
|
echo "</td>\n";
|
421
|
echo "<script language=\"JavaScript\">\n";
|
422
|
echo "<!--\n";
|
423
|
echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
|
424
|
echo "-->\n";
|
425
|
echo "</script>\n";
|
426
|
$text = "";
|
427
|
$trc++;
|
428
|
}
|
429
|
|
430
|
$rowcounter++;
|
431
|
echo "<td>";
|
432
|
echo "<input type=\"image\" src=\"/x.gif\" onclick=\"removeRow(this); return false;\" value=\"Delete\">";
|
433
|
echo "</td>\n";
|
434
|
echo "</tr>\n";
|
435
|
}
|
436
|
}
|
437
|
if($trc == 0) {
|
438
|
/*
|
439
|
* no records loaded.
|
440
|
* just show a generic line non-populated with saved data
|
441
|
*/
|
442
|
foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
|
443
|
if($rowhelper['value'] <> "") $value = $rowhelper['value'];
|
444
|
$fieldname = $rowhelper['fieldname'];
|
445
|
$options = "";
|
446
|
$type = $rowhelper['type'];
|
447
|
$fieldname = $rowhelper['fieldname'];
|
448
|
if($type == "option") $options = &$rowhelper['options']['option'];
|
449
|
$size = "8";
|
450
|
if($rowhelper['size'] <> "") $size = $rowhelper['size'];
|
451
|
display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
|
452
|
// javascript helpers for row_helper_dynamic.js
|
453
|
echo "</td>\n";
|
454
|
echo "<script language=\"JavaScript\">\n";
|
455
|
echo "<!--\n";
|
456
|
echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
|
457
|
echo "-->\n";
|
458
|
echo "</script>\n";
|
459
|
$text = "";
|
460
|
$trc++;
|
461
|
}
|
462
|
|
463
|
$rowcounter++;
|
464
|
}
|
465
|
?>
|
466
|
|
467
|
</tbody>
|
468
|
</table>
|
469
|
|
470
|
<br><a onClick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="/plus.gif"></a>
|
471
|
<script language="JavaScript">
|
472
|
<!--
|
473
|
field_counter_js = <?= $fieldcounter ?>;
|
474
|
rows = <?= $rowcounter ?>;
|
475
|
totalrows = <?php echo $rowcounter; ?>;
|
476
|
loaded = <?php echo $rowcounter; ?>;
|
477
|
//typesel_change();
|
478
|
//-->
|
479
|
</script>
|
480
|
|
481
|
<?php
|
482
|
}
|
483
|
if($pkga['typehint']) echo " " . $pkga['typehint'];
|
484
|
?>
|
485
|
|
486
|
<?php
|
487
|
if(!$pkga['combinefieldsbegin']) echo "</td></tr>";
|
488
|
$i++;
|
489
|
}
|
490
|
?>
|
491
|
<tr>
|
492
|
<td> </td>
|
493
|
</tr>
|
494
|
<tr>
|
495
|
<td width="22%" valign="top"> </td>
|
496
|
<td width="78%">
|
497
|
<input name="Submit" type="submit" class="formbtn" value="<?= $savevalue ?>">
|
498
|
<?php if (isset($id) && $a_pkg[$id]): ?>
|
499
|
<input name="id" type="hidden" value="<?=$id;?>">
|
500
|
<?php endif; ?>
|
501
|
</td>
|
502
|
</tr>
|
503
|
</table>
|
504
|
|
505
|
<?php
|
506
|
if ($pkg['tabs'] <> "") {
|
507
|
echo "</td></tr></table>";
|
508
|
}
|
509
|
?>
|
510
|
|
511
|
</form>
|
512
|
<?php include("fend.inc"); ?>
|
513
|
</body>
|
514
|
</html>
|
515
|
|
516
|
<?php
|
517
|
|
518
|
/*
|
519
|
* ROW Helpers function
|
520
|
*/
|
521
|
function display_row($trc, $value, $fieldname, $type, $rowhelper, $size) {
|
522
|
global $text;
|
523
|
echo "<td>\n";
|
524
|
if($type == "input") {
|
525
|
echo "<input size='" . $size . "' name='" . $fieldname . $trc . "' value='" . $value . "'>\n";
|
526
|
} else if($type == "password") {
|
527
|
echo "<input size='" . $size . "' type='password' name='" . $fieldname . $trc . "' value='" . $value . "'>\n";
|
528
|
} else if($type == "textarea") {
|
529
|
echo "<textarea rows='2' cols='12' name='" . $fieldname . $trc . "'>" . $value . "</textarea>\n";
|
530
|
} else if($type == "select") {
|
531
|
echo "<select name='" . $fieldname . $trc . "'>\n";
|
532
|
foreach($rowhelper['options']['option'] as $rowopt) {
|
533
|
$selected = "";
|
534
|
if($rowopt['value'] == $value) $selected = " SELECTED";
|
535
|
$text .= "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>";
|
536
|
echo "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>\n";
|
537
|
}
|
538
|
echo "</select>\n";
|
539
|
}
|
540
|
}
|
541
|
|
542
|
function fixup_string($string) {
|
543
|
global $config;
|
544
|
// fixup #1: $myurl -> http[s]://ip_address:port/
|
545
|
$https = "";
|
546
|
$port = "";
|
547
|
$urlport = "";
|
548
|
$port = $config['system']['webguiport'];
|
549
|
if($port <> "443" and $port <> "80") $urlport = ":" . $port;
|
550
|
if($config['system']['webguiproto'] == "https") $https = "s";
|
551
|
$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlportport;
|
552
|
$newstring = str_replace("\$myurl", $myurl, $string);
|
553
|
$string = $newstring;
|
554
|
// fixup #2: $wanip
|
555
|
$curwanip = get_current_wan_address();
|
556
|
$newstring = str_replace("\$wanip", $curwanip, $string);
|
557
|
$string = $newstring;
|
558
|
// fixup #3: $lanip
|
559
|
$lancfg = $config['interfaces']['lan'];
|
560
|
$lanip = $lancfg['ipaddr'];
|
561
|
$newstring = str_replace("\$lanip", $lanip, $string);
|
562
|
$string = $newstring;
|
563
|
// fixup #4: fix'r'up here.
|
564
|
return $newstring;
|
565
|
}
|
566
|
|
567
|
/*
|
568
|
* Parse templates if they are defined
|
569
|
*/
|
570
|
function parse_package_templates() {
|
571
|
global $pkg, $config;
|
572
|
if($pkg['templates']['template'] <> "")
|
573
|
foreach($pkg['templates']['template'] as $pkg_template_row) {
|
574
|
$filename = $pkg_template_row['filename'];
|
575
|
$template_text = $pkg_template_row['templatecontents'];
|
576
|
|
577
|
/* calculate total row helpers count */
|
578
|
foreach ($pkg['fields']['field'] as $fields) {
|
579
|
if($fields['type'] == "rowhelper") {
|
580
|
// save rowhelper items.
|
581
|
$row_helper_total_rows = 0;
|
582
|
for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
|
583
|
foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
|
584
|
if($firstfield == "") {
|
585
|
$firstfield = $rowhelperfield['fieldname'];
|
586
|
} else {
|
587
|
if($firstfield == $rowhelperfield['fieldname']) $rows++;
|
588
|
}
|
589
|
$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
|
590
|
eval($comd);
|
591
|
if($value <> "") {
|
592
|
//$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
|
593
|
} else {
|
594
|
$row_helper_total_rows = $rows;
|
595
|
break;
|
596
|
}
|
597
|
}
|
598
|
}
|
599
|
}
|
600
|
}
|
601
|
|
602
|
/* replace $domain_total_rows with total rows */
|
603
|
$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
|
604
|
|
605
|
/* change fields defined as fieldname_fieldvalue to their value */
|
606
|
foreach ($pkg['fields']['field'] as $fields) {
|
607
|
if($fields['type'] == "rowhelper") {
|
608
|
// save rowhelper items.
|
609
|
for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
|
610
|
$row_helper_data = "";
|
611
|
$isfirst = 0;
|
612
|
foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
|
613
|
if($firstfield == "") {
|
614
|
$firstfield = $rowhelperfield['fieldname'];
|
615
|
} else {
|
616
|
if($firstfield == $rowhelperfield['fieldname']) $rows++;
|
617
|
}
|
618
|
$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
|
619
|
eval($comd);
|
620
|
if($value <> "") {
|
621
|
if($isfirst == 1) $row_helper_data .= " " ;
|
622
|
$row_helper_data .= $value;
|
623
|
$isfirst = 1;
|
624
|
}
|
625
|
ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
|
626
|
foreach ($sep as $se) $seperator = $se;
|
627
|
if($seperator <> "") {
|
628
|
$row_helper_data = ereg_replace(" ", $seperator, $row_helper_data);
|
629
|
$template_text = ereg_replace("\[" . $seperator . "\]", "", $template_text);
|
630
|
}
|
631
|
$template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
|
632
|
}
|
633
|
}
|
634
|
} else {
|
635
|
$fieldname = $fields['fieldname'];
|
636
|
$fieldvalue = $_POST[$fieldname];
|
637
|
$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
|
638
|
}
|
639
|
}
|
640
|
|
641
|
/* replace cr's */
|
642
|
$template_text = str_replace("\\n", "\n", $template_text);
|
643
|
|
644
|
/* write out new template file */
|
645
|
$fout = fopen($filename,"w");
|
646
|
fwrite($fout, $template_text);
|
647
|
fclose($fout);
|
648
|
}
|
649
|
}
|
650
|
|
651
|
?>
|