Commit 214d92c3 authored by Ad Schellevis's avatar Ad Schellevis

(firewall, alias) move field split to proper location, for...

(firewall, alias) move field split to proper location, for https://github.com/opnsense/core/issues/1109
parent 10c6828e
...@@ -69,10 +69,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -69,10 +69,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig[$fieldname] = null; $pconfig[$fieldname] = null;
} }
} }
// convert to array if only one is provided
if (!empty($pconfig['aliasurl']) && !is_array($pconfig['aliasurl'])) {
$pconfig['aliasurl'] = array($pconfig['aliasurl']);
}
} elseif (isset($_GET['name'])) { } elseif (isset($_GET['name'])) {
// search alias by name // search alias by name
foreach ($a_aliases as $alias_id => $alias_data) { foreach ($a_aliases as $alias_id => $alias_data) {
...@@ -96,22 +92,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -96,22 +92,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig[$fieldname] = null; $pconfig[$fieldname] = null;
} }
} }
// handle different detail input types
if (!empty($pconfig['aliasurl'])) {
$pconfig['host_url'] = is_array($pconfig['aliasurl']) ? $pconfig['aliasurl'] : array($pconfig['aliasurl']);
} elseif (!empty($pconfig['url'])) {
$pconfig['host_url'] = array($pconfig['url']);
} elseif (!empty($pconfig['address'])) {
$pconfig['host_url'] = explode(" ", $pconfig['address']);
} else {
$pconfig['host_url'] = array();
}
$pconfig['detail'] = !empty($pconfig['detail']) ? explode("||", $pconfig['detail']) : array();
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
$pconfig = $_POST; $pconfig = $_POST;
if (isset($_POST['id']) && is_numericint($_POST['id']) && isset($a_aliases[$_POST['id']])) { if (isset($_POST['id']) && is_numericint($_POST['id']) && isset($a_aliases[$_POST['id']])) {
$id = $_POST['id']; $id = $_POST['id'];
} }
// fix form type conversions ( list to string, as saved in config )
// -- fill in default row description and make sure separators are removed
if (strpos($pconfig['type'],'urltable') !== false) {
$pconfig['url'] = $pconfig['host_url'][0];
} elseif (strpos($pconfig['type'],'url') !== false) {
$pconfig['aliasurl'] = $pconfig['host_url'];
} else {
$pconfig['address'] = implode(' ', $pconfig['host_url']);
}
foreach ($pconfig['detail'] as &$detailDescr) { foreach ($pconfig['detail'] as &$detailDescr) {
if (empty($detailDescr)) { if (empty($detailDescr)) {
$detailDescr = sprintf(gettext("Entry added %s"), date('r')); $detailDescr = sprintf(gettext("Entry added %s"), date('r'));
...@@ -120,7 +117,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -120,7 +117,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$detailDescr = trim(str_replace('|',' ' , $detailDescr)); $detailDescr = trim(str_replace('|',' ' , $detailDescr));
} }
} }
$pconfig['detail'] = implode('||', $pconfig['detail']);
if (isset($pconfig['submit'])) { if (isset($pconfig['submit'])) {
$input_errors = array(); $input_errors = array();
...@@ -192,20 +188,30 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -192,20 +188,30 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
} }
if ($pconfig['type'] == 'urltable') { if ($pconfig['type'] == 'urltable') {
if (empty($pconfig['url']) || !is_URL($pconfig['url'])) { if (empty($pconfig['host_url'][0]) || !is_URL($pconfig['host_url'][0])) {
$input_errors[] = gettext("You must provide a valid URL."); $input_errors[] = gettext("You must provide a valid URL.");
} }
} }
if (count($input_errors) == 0) { if (count($input_errors) == 0) {
// save to config // save to config
$copy_fields = array("name", "detail", "address", "type", "descr", "updatefreq", "aliasurl", "url");
$confItem = array(); $confItem = array();
foreach ($copy_fields as $fieldname) { foreach (array("name", "type", "descr", "updatefreq") as $fieldname) {
if (!empty($pconfig[$fieldname])) { if (!empty($pconfig[$fieldname])) {
$confItem[$fieldname] = $pconfig[$fieldname]; $confItem[$fieldname] = $pconfig[$fieldname];
} }
} }
// fix form type conversions ( list to string, as saved in config )
// -- fill in default row description and make sure separators are removed
if (strpos($pconfig['type'],'urltable') !== false) {
$confItem['url'] = $pconfig['host_url'][0];
} elseif (strpos($pconfig['type'],'url') !== false) {
$confItem['aliasurl'] = $pconfig['host_url'];
} else {
$confItem['address'] = implode(' ', $pconfig['host_url']);
}
//
$confItem['detail'] = implode('||', $pconfig['detail']);
// proto is only for geoip selection // proto is only for geoip selection
if ($pconfig['type'] == 'geoip') { if ($pconfig['type'] == 'geoip') {
...@@ -532,19 +538,7 @@ endforeach; ...@@ -532,19 +538,7 @@ endforeach;
</thead> </thead>
<tbody> <tbody>
<?php <?php
if (is_array($pconfig['aliasurl'])) { foreach (!empty($pconfig['host_url']) ? $pconfig['host_url'] : array("") as $aliasid => $aliasurl):?>
$detail_desc = explode("||", $pconfig['detail']);
$aliases = $pconfig['aliasurl'];
} else {
$detail_desc = explode("||", $pconfig['detail']);
if (empty($pconfig['address']) && isset($pconfig['url'])) {
$aliases = array($pconfig['url']);
} else {
$aliases = explode(' ', $pconfig['address']);
}
}
foreach ($aliases as $aliasid => $aliasurl):
?>
<tr> <tr>
<td> <td>
<div style="cursor:pointer;" class="act-removerow btn btn-default btn-xs" alt="remove"><span class="glyphicon glyphicon-minus"></span></div> <div style="cursor:pointer;" class="act-removerow btn btn-default btn-xs" alt="remove"><span class="glyphicon glyphicon-minus"></span></div>
...@@ -555,10 +549,10 @@ endforeach; ...@@ -555,10 +549,10 @@ endforeach;
<input type="text" class="host_url fld_detail" name="host_url[]" value="<?=$aliasurl;?>"/> <input type="text" class="host_url fld_detail" name="host_url[]" value="<?=$aliasurl;?>"/>
</td> </td>
<td> <td>
<input type="text" class="form-control" name="detail[]" value="<?= isset($detail_desc[$aliasid])?$detail_desc[$aliasid]:"";?>"> <input type="text" class="form-control" name="detail[]" value="<?= isset($pconfig['detail'][$aliasid])?$pconfig['detail'][$aliasid]:"";?>">
</td> </td>
<td> <td>
<?php if ($aliasid ==0): <?php if ($aliasid == 0):
?> ?>
<input type="text" class="form-control input-sm" id="updatefreq" name="updatefreq" value="<?=$pconfig['updatefreq'];?>" > <input type="text" class="form-control input-sm" id="updatefreq" name="updatefreq" value="<?=$pconfig['updatefreq'];?>" >
<?php endif; <?php endif;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment