Not worth the technical debt at this point when this situation is best handled with URL aliases.
diff --git a/src/usr/local/www/firewall_aliases.php b/src/usr/local/www/firewall_aliases.php
index f6d13f2cc873ff2bf63958bb61dc6dac9c80a786..069fd7e65e5e28dc075820d1aeca21dba1da4f19 100644
--- a/src/usr/local/www/firewall_aliases.php
+++ b/src/usr/local/www/firewall_aliases.php
@@ -199,7 +199,7 @@ display_top_tabs($tab_array);
<?=gettext("Add");?>
</a>
<?php
-if (($tab == "ip") || ($tab == "port") || ($tab == "all")):
+if (($tab == "ip") || ($tab == "network") || ($tab == "port") || ($tab == "all")):
?>
<a href="firewall_aliases_import.php?tab=<?=$tab?>" role="button" class="btn btn-primary btn-sm">
<i class="fa-solid fa-upload icon-embed-btn"></i>
diff --git a/src/usr/local/www/firewall_aliases_edit.php b/src/usr/local/www/firewall_aliases_edit.php
index add2ae0f3d11845964f2197275f45b35b930716f..1e1b7c2493fca5030de4967e2ac7fbd04e0a96e9 100644
--- a/src/usr/local/www/firewall_aliases_edit.php
+++ b/src/usr/local/www/firewall_aliases_edit.php
@@ -122,6 +122,14 @@ if ($_REQUEST['exportaliases']) {
send_user_download('data', $expdata, "{$_POST['origname']}.txt");
}
+if ($_REQUEST['importaliases']) {
+ $tab = $_REQUEST['type'];
+ if ($tab == 'host'){
+ $tab = 'ip';
+ }
+ header("Location: /firewall_aliases_import.php?tab=" . htmlspecialchars ($tab) . "&update=" . $id);
+}
+
$tab = $_REQUEST['tab'];
if (empty($tab)) {
@@ -359,6 +367,13 @@ if ((isset($id) && config_get_path('aliases/alias/' . $id)) && !preg_match("/url
null,
'fa-solid fa-download'
))->addClass('btn-primary');
+
+ $form->addGlobal(new Form_Button(
+ 'importaliases',
+ 'Bulk Edit',
+ null,
+ 'fa-solid fa-upload'
+ ))->addClass('btn-primary');
}
$form->addGlobal(new Form_Button(
@@ -385,6 +400,14 @@ events.push(function() {
var tab = $('#type').find('option:selected').val();
disable_subnets = (tab == 'host') || (tab == 'port') || (tab == 'url') || (tab == 'url_ports');
+ disable_import = (tab == 'url') || (tab == 'url_ports') || (tab == 'urltable') || (tab == 'urltable_ports');
+
+ // Hide bulk edit button on URL pages
+ if (disable_import) {
+ $('#importaliases').hide();
+ } else {
+ $('#importaliases').show();
+ }
// Enable/disable address_subnet so its value gets POSTed or not, as appropriate.
$("[id^='address_subnet']").prop("disabled", disable_subnets);
diff --git a/src/usr/local/www/firewall_aliases_import.php b/src/usr/local/www/firewall_aliases_import.php
index 86dc28065bb5070baf6e35a02904aeea9e235f21..4c11029129366c579212d3477ecc0677a43158d2 100644
--- a/src/usr/local/www/firewall_aliases_import.php
+++ b/src/usr/local/www/firewall_aliases_import.php
@@ -55,7 +55,7 @@ if ($_POST) {
}
/* check for name duplicates */
- if (is_alias($_POST['name'])) {
+ if (is_alias($_POST['name']) && !(isset($_REQUEST['update']))) {
$input_errors[] = gettext("An alias with this name already exists.");
}
@@ -161,10 +161,15 @@ if ($_POST) {
$alias['descr'] = $_POST['descr'];
unset($imported_ips, $imported_descs);
- $alias_count = 0;
- while (config_get_path('aliases/alias/' . $alias_count)) {
- $alias_count++;
+ if (!isset($_REQUEST['update'])) {
+ $alias_count = 0;
+ while (config_get_path('aliases/alias/' . $alias_count)) {
+ $alias_count++;
+ }
+ } else {
+ $alias_count = $_REQUEST['update'];
}
+
config_set_path('aliases/alias/' . $alias_count, $alias);
if (write_config(gettext("Imported a firewall alias."))) {
@@ -231,13 +236,35 @@ if ($tab == "port") {
'</li></ul><span class="help-block">';
}
+if(isset($_REQUEST['update'])){
+ $thisAlias = config_get_path('aliases/alias/' . $_REQUEST['update']);
+ $form_name = $thisAlias['name'];
+ $form_descr = $thisAlias['descr'];
+
+ $form_addresses = explode(" ", $thisAlias['address']);
+ $form_details = explode("||", $thisAlias['detail']);
+
+ $form_aliasImport = "";
+ foreach ($form_addresses as $i => $address) {
+ if ($i != 0) {
+ $form_aliasImport .= PHP_EOL;
+ }
+
+ $form_aliasImport .= $address . " " . $form_details[$i];
+ }
+} else {
+ $form_name = $_POST['name'];
+ $form_descr = $_POST['descr'];
+ $form_aliasImport = $_POST["aliasimport"];
+}
+
$section = new Form_Section($sectiontext);
$section->addInput(new Form_Input(
'name',
'*Alias Name',
'text',
- $_POST['name']
+ $form_name
))->setPattern('[a-zA-Z0-9_]+')->setHelp('The name of the alias may only consist '.
'of the characters "a-z, A-Z, 0-9 and _".');
@@ -245,13 +272,13 @@ $section->addInput(new Form_Input(
'descr',
'Description',
'text',
- $_POST['descr']
+ $form_descr
))->setHelp('A description may be entered here for administrative reference (not parsed).');
$section->addInput(new Form_Textarea(
'aliasimport',
'*Aliases to import',
- $_POST["aliasimport"]
+ $form_aliasImport
))->setHelp($helptext);
$form->add($section);