Begin Main...
(logger=None)
| 56 | |
| 57 | |
| 58 | def main(logger=None): |
| 59 | """ |
| 60 | Begin Main... |
| 61 | """ |
| 62 | if logger is None: |
| 63 | logger = LoggingUtil.create_log(__name__) |
| 64 | |
| 65 | now = datetime.now() |
| 66 | print("Starting: " + str(now)) |
| 67 | logger.info("Starting...") |
| 68 | |
| 69 | # Obtain the list of known email addresses from the config collection |
| 70 | mongo_connector = MongoConnector.MongoConnector() |
| 71 | whois_collection = mongo_connector.get_whois_connection() |
| 72 | all_dns_collection = mongo_connector.get_all_dns_connection() |
| 73 | zones_collection = mongo_connector.get_zone_connection() |
| 74 | jobs_manager = JobsManager.JobsManager(mongo_connector, "mark_expired") |
| 75 | jobs_manager.record_job_start() |
| 76 | |
| 77 | # Grab all zones that are not expired or false_positives |
| 78 | # Also exclude any that were recently updated since they still resolve |
| 79 | date_delta = datetime.today() - timedelta(days=90) |
| 80 | zones = zones_collection.distinct( |
| 81 | "zone", |
| 82 | { |
| 83 | "updated": {"$lt": date_delta}, |
| 84 | "status": {"$nin": [ZoneManager.EXPIRED, ZoneManager.FALSE_POSITIVE]}, |
| 85 | }, |
| 86 | ) |
| 87 | |
| 88 | # The Python Whois library is hit and miss with some international zones. |
| 89 | # For now, this script focuses on the most popular TLDs. |
| 90 | new_zones = get_primary_zones(logger, zones) |
| 91 | |
| 92 | expired_list = [] |
| 93 | for zone in new_zones: |
| 94 | if whois_collection.count_documents({"zone": zone}) == 0: |
| 95 | # Assume it is expired if there is no longer a whois record present |
| 96 | expired_list.append(zone) |
| 97 | |
| 98 | for zone in expired_list: |
| 99 | if all_dns_collection.count_documents({"zone": zone}) > 0: |
| 100 | # This may be a case where the Python Whois library failed |
| 101 | # and the zone is still active. |
| 102 | logger.debug("DNS records still exist for " + zone) |
| 103 | expired_list.remove(zone) |
| 104 | |
| 105 | zone_manager = ZoneManager(mongo_connector) |
| 106 | |
| 107 | # Need to get this list before setting zones to expired in order to avoid a recursion problem. |
| 108 | already_expired = zone_manager.get_zones_by_status(ZoneManager.EXPIRED) |
| 109 | |
| 110 | possibly_renewed = [] |
| 111 | for zone in already_expired: |
| 112 | if whois_collection.count_documents({"zone": zone}) == 1: |
| 113 | possibly_renewed.append(zone) |
| 114 | |
| 115 | for zone in expired_list: |
no test coverage detected