From 987afe8502cba73becdbd845d48e6e1fdc1e77b8 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Sun, 15 Oct 2017 18:29:48 +0000 Subject: [PATCH] firewall: different approach to geoip selection #1860 --- src/www/firewall_aliases_edit.php | 145 ++++++++++++++++-------------- 1 file changed, 78 insertions(+), 67 deletions(-) diff --git a/src/www/firewall_aliases_edit.php b/src/www/firewall_aliases_edit.php index 800071bdc..53ab50e79 100644 --- a/src/www/firewall_aliases_edit.php +++ b/src/www/firewall_aliases_edit.php @@ -182,36 +182,41 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (isset($pconfig['submit'])) { $input_errors = array(); // validate data - $country_codes = array_keys(geoip_countries()); - foreach ($pconfig['host_url'] as &$detail_entry) { - $ipaddr_count = 0; - $domain_alias_count = 0; - foreach (explode('-', $detail_entry) as $tmpaddr) { - if (is_ipaddr($tmpaddr)) { - $ipaddr_count++; - } elseif (trim($tmpaddr) != "") { - $domain_alias_count++; + + if (empty($pconfig['host_url'])) { + $input_errors[] = gettext('At least one alias entry must be supplied.'); + } else { + $country_codes = array_keys(geoip_countries()); + foreach ($pconfig['host_url'] as &$detail_entry) { + $ipaddr_count = 0; + $domain_alias_count = 0; + foreach (explode('-', $detail_entry) as $tmpaddr) { + if (is_ipaddr($tmpaddr)) { + $ipaddr_count++; + } elseif (trim($tmpaddr) != "") { + $domain_alias_count++; + } } - } - if ($pconfig['type'] == 'host') { - if ($ipaddr_count > 1) { - $input_errors[] = sprintf(gettext('Entry "%s" seems to contain a list of addresses, please use a network type alias to define ranges.'), $detail_entry) ; - } elseif (!is_domain($detail_entry) && !is_ipaddr($detail_entry) && !is_alias($detail_entry)) { - $input_errors[] = sprintf(gettext('Entry "%s" is not a valid hostname or IP address.'), $detail_entry) ; - } - } elseif ($pconfig['type'] == 'port') { - $detail_entry = str_replace("-", ":", $detail_entry); - if (!is_port($detail_entry) && !is_portrange($detail_entry) && !is_alias($detail_entry)) { - $input_errors[] = sprintf(gettext('Entry "%s" is not a valid port number.'), $detail_entry) ; - } - } elseif ($pconfig['type'] == 'geoip') { - if (!in_array($detail_entry, $country_codes)) { - $input_errors[] = sprintf(gettext('Entry "%s" is not a valid country code.'), $detail_entry) ; - } - } elseif ($pconfig['type'] == 'network') { - if (!is_alias($detail_entry) && !is_ipaddr($detail_entry) && !is_subnet($detail_entry) - && !($ipaddr_count == 2 && $domain_alias_count == 0)) { - $input_errors[] = sprintf(gettext('Entry "%s" is not a valid network or IP address.'), $detail_entry) ; + if ($pconfig['type'] == 'host') { + if ($ipaddr_count > 1) { + $input_errors[] = sprintf(gettext('Entry "%s" seems to contain a list of addresses, please use a network type alias to define ranges.'), $detail_entry); + } elseif (!is_domain($detail_entry) && !is_ipaddr($detail_entry) && !is_alias($detail_entry)) { + $input_errors[] = sprintf(gettext('Entry "%s" is not a valid hostname or IP address.'), $detail_entry); + } + } elseif ($pconfig['type'] == 'port') { + $detail_entry = str_replace("-", ":", $detail_entry); + if (!is_port($detail_entry) && !is_portrange($detail_entry) && !is_alias($detail_entry)) { + $input_errors[] = sprintf(gettext('Entry "%s" is not a valid port number.'), $detail_entry); + } + } elseif ($pconfig['type'] == 'geoip') { + if (!in_array($detail_entry, $country_codes)) { + $input_errors[] = sprintf(gettext('Entry "%s" is not a valid country code.'), $detail_entry); + } + } elseif ($pconfig['type'] == 'network') { + if (!is_alias($detail_entry) && !is_ipaddr($detail_entry) && !is_subnet($detail_entry) + && !($ipaddr_count == 2 && $domain_alias_count == 0)) { + $input_errors[] = sprintf(gettext('Entry "%s" is not a valid network or IP address.'), $detail_entry); + } } } } @@ -406,19 +411,9 @@ include("head.inc"); $('#detailTable > tbody > tr:last > td > input').each(function(){ $(this).val(""); }); - // cloned a selectpicker, move original select tag out of container and remove selectpicker - $('#detailTable > tbody > tr:last > td > div.btn-group').each(function(){ - $(this).find('select').detach().appendTo($(this).parent()); - $(this).remove(); - }); $(".act-removerow").click(removeRow); // link typeahead to new item addFieldTypeAhead(); - // link geoip list to new item - $(".geoip_list").change(function(){ - $(this).parent().parent().find('input').val($(this).val()); - }); - $('.selectpicker').selectpicker(); }); $(".act-removerow").click(removeRow); @@ -437,9 +432,9 @@ include("head.inc"); $('.act-removerow').removeClass('hidden'); } $("#proto").addClass("hidden"); - $(".geoip_list").addClass("hidden"); + $(".geoip_table").addClass("hidden"); + $(".not_geoip_table").removeClass("hidden"); $(".host_url").removeClass("hidden"); - $(".geoip_list > option").remove(); switch($("#typeSelect").val()) { case 'urltable': $("#detailsHeading1").html(""); @@ -464,17 +459,9 @@ include("head.inc"); break; case 'geoip': $("#proto").removeClass("hidden"); - $(".geoip_list").removeClass("hidden"); + $(".geoip_table").removeClass("hidden"); + $(".not_geoip_table").addClass("hidden"); $(".host_url").addClass("hidden"); - $("#detailsHeading1").html(""); - $("#countries > option").clone().appendTo('.geoip_list'); - $('.geoip_list').each(function(){ - var url_item = $(this).parent().find('input').val(); - $(this).val(url_item); - }); - $('.geoip_list').change(function(){ - $(this).parent().find('input').val($(this).val()); - }); break; } $(".fld_detail").typeahead("destroy"); @@ -494,6 +481,10 @@ include("head.inc"); document.all_aliases[$(this).data('type')].push($(this).val()) }); + $('.region_toggle').click(function () { + $('.region_' + $(this).attr('data')).click(); + }); + toggleType(); }); @@ -509,16 +500,6 @@ include("head.inc"); endforeach; endif; ?> - - - -
@@ -612,7 +593,7 @@ endforeach;
- +
@@ -628,11 +609,6 @@ endforeach; - @@ -655,6 +631,41 @@ endforeach;
- - - ">
+ + + + + + + $name): + if ($region == $where[$code]): ?> + + + + + + + + +
+ + () +
+ /> + +
+ +
+
+