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