From c5a77883946918367382ede8a22a919d056336c1 Mon Sep 17 00:00:00 2001 From: Galonza Peter Date: Sun, 17 Oct 2021 20:00:12 +0300 Subject: [PATCH 1/6] optimized pattern --- src/dashboard.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index 99a4c19..07bb5ca 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -58,8 +58,7 @@ def clean_IP_with_range(ip): # Check IP with range (IPv4 only now) # TODO: Add IPv6 support def check_IP_with_range(ip): - return regex_match("((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|\/)){4}(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|" + - "18|19|20|21|22|23|24|25|26|27|28|29|30|31|32)(,|$)", ip) + return regex_match("((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|\/)){4}([0-9]{1,2})(,|$)", ip) # Check allowed ips list def check_Allowed_IPs(ip): From ffa63b3f82caa6aff75c5fac925611a40a7c23df Mon Sep 17 00:00:00 2001 From: Galonza Peter Date: Sun, 17 Oct 2021 20:22:27 +0300 Subject: [PATCH 2/6] completed todo. Added IPv6 --- src/dashboard.py | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index 07bb5ca..93c2daf 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -42,10 +42,22 @@ def regex_match(regex, text): pattern = re.compile(regex) return pattern.search(text) is not None -# Check IP format (IPv4 only now) -# TODO: Add IPv6 support +# Check IP format def check_IP(ip): - return regex_match("((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}", ip) + ip_patterns = ( + r"((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}", + r"((^|:)([0-9a-fA-F]{0,4})){1,8}$" + ) + + for match_pattern in ip_patterns: + match_result = regex_match(match_pattern, ip) + if match_result: + result = match_result + break + else: + result = None + + return result # Clean IP def clean_IP(ip): @@ -55,10 +67,22 @@ def clean_IP(ip): def clean_IP_with_range(ip): return clean_IP(ip).split(',') -# Check IP with range (IPv4 only now) -# TODO: Add IPv6 support +# Check IP with range def check_IP_with_range(ip): - return regex_match("((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|\/)){4}([0-9]{1,2})(,|$)", ip) + ip_patterns = ( + r"((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|\/)){4}([0-9]{1,2})(,|$)", + r"((^|:)([0-9a-fA-F]{0,4})){1,8}\/([0-9]{1,3})(,|$)" + ) + + for match_pattern in ip_patterns: + match_result = regex_match(match_pattern, ip) + if match_result: + result = match_result + break + else: + result = None + + return result # Check allowed ips list def check_Allowed_IPs(ip): @@ -76,10 +100,10 @@ def check_DNS(dns): return False return True -# Check remote endpoint (Both IPv4 address and valid hostname) -# TODO: Add IPv6 support +# Check remote endpoint def check_remote_endpoint(address): - return (regex_match("((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}", address) or regex_match("(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z]{0,61}[a-z]",address)) + + return (check_IP(address) or regex_match("(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z]{0,61}[a-z]", address)) """ From 62be683dd859496814f705fc67a4f4b712869dc7 Mon Sep 17 00:00:00 2001 From: Galonza Peter Date: Sun, 17 Oct 2021 21:13:18 +0300 Subject: [PATCH 3/6] fixed search ipv6 in the string with comma --- src/dashboard.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index 93c2daf..f742891 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -46,7 +46,7 @@ def regex_match(regex, text): def check_IP(ip): ip_patterns = ( r"((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}", - r"((^|:)([0-9a-fA-F]{0,4})){1,8}$" + r"[0-9a-fA-F]{0,4}(:([0-9a-fA-F]{0,4})){1,7}$" ) for match_pattern in ip_patterns: @@ -71,7 +71,7 @@ def clean_IP_with_range(ip): def check_IP_with_range(ip): ip_patterns = ( r"((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|\/)){4}([0-9]{1,2})(,|$)", - r"((^|:)([0-9a-fA-F]{0,4})){1,8}\/([0-9]{1,3})(,|$)" + r"[0-9a-fA-F]{0,4}(:([0-9a-fA-F]{0,4})){1,7}\/([0-9]{1,3})(,|$)" ) for match_pattern in ip_patterns: From caa9a904763ad4232205b7c8e547a065a392f6a9 Mon Sep 17 00:00:00 2001 From: Galonza Peter Date: Sun, 17 Oct 2021 22:55:08 +0300 Subject: [PATCH 4/6] added dual-stack --- src/dashboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dashboard.py b/src/dashboard.py index f742891..9addd11 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -1139,7 +1139,7 @@ def init_dashboard(): if 'wg_conf_path' not in config['Server']: config['Server']['wg_conf_path'] = '/etc/wireguard' if 'app_ip' not in config['Server']: - config['Server']['app_ip'] = '0.0.0.0' + config['Server']['app_ip'] = '::' if 'app_port' not in config['Server']: config['Server']['app_port'] = '10086' if 'auth_req' not in config['Server']: From b3dc60b7ca08a38b7612796a4000557f8f15f28c Mon Sep 17 00:00:00 2001 From: Galonza Peter Date: Sun, 24 Oct 2021 12:05:14 +0300 Subject: [PATCH 5/6] fixed check ipv6 dns --- src/dashboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dashboard.py b/src/dashboard.py index 9addd11..15b7572 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -96,7 +96,7 @@ def check_DNS(dns): dns = dns.replace(' ','').split(',') status = True for i in dns: - if not (regex_match("((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}", i) or regex_match("(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z]{0,61}[a-z]",i)): + if not (check_IP(dns) or regex_match("(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z]{0,61}[a-z]",i)): return False return True From bdfc260dd2b7cda4eec10bd1531744687908f0d4 Mon Sep 17 00:00:00 2001 From: Galonza Peter Date: Sun, 24 Oct 2021 13:32:21 +0300 Subject: [PATCH 6/6] fixed --- src/dashboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dashboard.py b/src/dashboard.py index 15b7572..ce49d81 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -96,7 +96,7 @@ def check_DNS(dns): dns = dns.replace(' ','').split(',') status = True for i in dns: - if not (check_IP(dns) or regex_match("(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z]{0,61}[a-z]",i)): + if not (check_IP(i) or regex_match("(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z]{0,61}[a-z]",i)): return False return True