Marinus collects DNS information from multiple sources. In the original version of Marinus, there was a separate table for each source. Maintaining separate tables makes it difficult to search. Therefore, the tables have been merged into "all_dns". This class acts as the interfa
| 22 | |
| 23 | |
| 24 | class DNSManager(object): |
| 25 | """ |
| 26 | Marinus collects DNS information from multiple sources. |
| 27 | In the original version of Marinus, there was a separate table for each source. |
| 28 | Maintaining separate tables makes it difficult to search. |
| 29 | Therefore, the tables have been merged into "all_dns". |
| 30 | This class acts as the interface for translating a DNS record into the all_dns format. |
| 31 | When submitting a DNS record, a "source" must be provided. |
| 32 | The approved sources are "virustotal", "common_crawl", "sonar_dns", and "ssl". |
| 33 | These will eventually be saved as constants. |
| 34 | """ |
| 35 | |
| 36 | all_dns_collection = None |
| 37 | _mongo_connector = None |
| 38 | _ip_manager = None |
| 39 | _logger = None |
| 40 | |
| 41 | def _log(self): |
| 42 | """ |
| 43 | Get the log |
| 44 | """ |
| 45 | return logging.getLogger(__name__) |
| 46 | |
| 47 | def __init__(self, mongo_connector, alternative_collection=None): |
| 48 | """ |
| 49 | Initialize the object with the necessary database configurations |
| 50 | """ |
| 51 | self._logger = self._log() |
| 52 | self._mongo_connector = mongo_connector |
| 53 | if alternative_collection is not None: |
| 54 | try: |
| 55 | self.all_dns_collection = getattr( |
| 56 | mongo_connector, alternative_collection |
| 57 | )() |
| 58 | except: |
| 59 | self._logger.error( |
| 60 | "FATAL: Could not fetch dynamic collection in DNS Manager" |
| 61 | ) |
| 62 | exit(1) |
| 63 | else: |
| 64 | self.all_dns_collection = mongo_connector.get_all_dns_connection() |
| 65 | |
| 66 | @staticmethod |
| 67 | def monthdelta(date, delta): |
| 68 | """ |
| 69 | Return the date from the given delta |
| 70 | |
| 71 | :param date: The original date |
| 72 | :param delta: The change from the original date that is to be calculated. |
| 73 | """ |
| 74 | m, y = (date.month + delta) % 12, date.year + ((date.month) + delta - 1) // 12 |
| 75 | if not m: |
| 76 | m = 12 |
| 77 | d = min( |
| 78 | date.day, |
| 79 | [ |
| 80 | 31, |
| 81 | 29 if y % 4 == 0 and not y % 400 == 0 else 28, |
nothing calls this directly
no outgoing calls
no test coverage detected