From 3ea16ce5f394c3e21c74c78934b32dbd88122922 Mon Sep 17 00:00:00 2001 From: jigen Date: Wed, 16 Sep 2020 18:29:50 +0200 Subject: [PATCH] Fixata query per estrarre i domini associati ad un host --- OTcerts.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/OTcerts.py b/OTcerts.py index 08a3b68..87266d0 100644 --- a/OTcerts.py +++ b/OTcerts.py @@ -16,9 +16,10 @@ smtp_list_stmt = "SELECT DISTINCT(name) FROM records WHERE content in ({}) and ( # Get list of defined domains in vhosts configuration database -domains_list_stmt = """SELECT DISTINCT(SUBSTRING_INDEX(urls.dns_name, '.', -2)) AS domain_names -FROM urls INNER JOIN (hosts_urls, hosts, vhosts_features, vhosts) -ON (urls.url_id = hosts_urls.url_id and urls.url_id = vhosts.url_id and vhosts.vhost_id = vhosts_features.vhost_id) +domains_list_stmt = """SELECT DISTINCT(SUBSTRING_INDEX(urls.dns_name, '.', -2)) AS domain_names +FROM hosts INNER JOIN (hosts_urls, urls, vhosts_features, vhosts) +ON (urls.url_id = hosts_urls.url_id and urls.url_id = vhosts.url_id +and vhosts.vhost_id = vhosts_features.vhost_id and hosts.host_id = hosts_urls.host_id) WHERE (hosts_urls.http = 'Y' and hosts.hostname = %(webserver)s) """ @@ -90,7 +91,7 @@ def connect_db(conf_dict): def get_subdomain_list(config, domain, ot_conn, ex_subdomains=tuple()): """ - Return a Python list containing subdomain of domain paramer + Return a Python list containing subdomain of domain parameter eg: ['app.arkiwi.org'] """ result_dict=dict() @@ -103,8 +104,12 @@ def get_subdomain_list(config, domain, ot_conn, ex_subdomains=tuple()): subdomains_res = ot_cursor.fetchall() ot_cursor.close() - subdomains_filtered = [s[0].decode('utf-8') for s in subdomains_res + try: + subdomains_filtered = [s[0].decode('utf-8') for s in subdomains_res if not(s[0].decode('utf-8').startswith(ex_subdomains))] + except AttributeError: + subdomains_filtered = [s[0] for s in subdomains_res + if not(s[0].startswith(ex_subdomains))] return subdomains_filtered @@ -122,7 +127,11 @@ def get_domain_list(config, ot_conn, dns_conn): dns_cursor=dns_conn.cursor() for domain_barr, in ot_cursor: - domain_name = domain_barr.decode("utf-8") + try: + domain_name = domain_barr.decode("utf-8") + except AttributeError: + domain_name = domain_barr; + logger.debug(domain_barr) try: dns_cursor.execute(domain_id_stmt, {'domain':domain_name}) except Exception as e: @@ -296,7 +305,7 @@ if __name__ == '__main__': # Subdomains da escludere ex_subdomains = tuple([s.strip() for s in config['main']['special_subdomains'].split(',') if len(s.strip())>0]) domains_dict = get_domain_list(config, ot_conn, dns_conn) - + logger.debug(domains_dict) for domain_name, domain_feat in domains_dict.items(): domain_feat['subdomains']=get_subdomain_list(config, domain_name, ot_conn, ex_subdomains=ex_subdomains) # Controlla se i nameserver sono gestiti da noi