Fix domain is_subdomain

This commit is contained in:
VirtuBox
2019-09-04 16:38:55 +02:00
parent f814bbea5d
commit 5cb2c394b1

View File

@@ -1,6 +1,6 @@
"""WordOps domain validation module.""" """WordOps domain validation module."""
from urllib.parse import urlparse
import os import os
from urllib.parse import urlparse
def ValidateDomain(url): def ValidateDomain(url):
@@ -35,21 +35,17 @@ def GetDomainlevel(domain):
domain_type = '' domain_type = ''
if os.path.isfile("/var/lib/wo/public_suffix_list.dat"): if os.path.isfile("/var/lib/wo/public_suffix_list.dat"):
# Read mode opens a file for reading only. # Read mode opens a file for reading only.
Suffix_file = open( suffix_file = open(
"/var/lib/wo/public_suffix_list.dat", encoding='utf-8', ) "/var/lib/wo/public_suffix_list.dat", encoding='utf-8', )
# Read all the lines into a list. # Read all the lines into a list.
for domain_suffix in Suffix_file: for domain_suffix in suffix_file:
if (str(domain_suffix).strip()) == ('.'.join(domain_name[2:])): if (str(domain_suffix).strip()) == ('.'.join(domain_name[1:])):
domain_type = 'subdomain'
root_domain = ('.'.join(domain_name[1:]))
break
elif (str(domain_suffix).strip()) == ('.'.join(domain_name[1:])):
domain_type = 'domain' domain_type = 'domain'
root_domain = ('.'.join(domain_name)) root_domain = ('.'.join(domain_name[0:]))
break break
else: else:
domain_type = 'domain' domain_type = 'subdomain'
root_domain = ('.'.join(domain_name)) root_domain = ('.'.join(domain_name[1:]))
Suffix_file.close() suffix_file.close()
return (domain_type, root_domain) return (domain_type, root_domain)