# Path: lib/settings.py
# def get_top_domains(dbname):


import socket
import base64
import sqlite3 as lite
import subprocess
import threading
import time
import re
import pickle
import os
import sys
import gc
import json
import fileinput
from struct import unpack
from socket import AF_INET, inet_pton
from lib.logger import *
from lib.settings import homenet, lock
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.ctime = int(time.time())
        self.bro_file_path = '/opt/zeek/logs/current/extract_files/'

    def run(self):

        while 1:
            self.ctime = int(time.time())
            try:
                self.clean_old_host_objects()
            except Exception as e:
                log.debug('FG-WARN: ' + str(e.__doc__) + " - " + str(e))
            time.sleep(600)

    def clean_old_host_objects(self):

        with lock:
            for k in homenet.hosts.keys():
                # Cleaning old DNS entries
                for l in homenet.hosts[k].dns.keys():
                    if (self.ctime - homenet.hosts[k].dns[l].ts) > 86400:
                        del homenet.hosts[k].dns[l]

                # Cleaning old connections
                for l in homenet.hosts[k].conns.keys():
                    if (self.ctime - homenet.hosts[k].conns[l].lseen) > 3600:
                        del homenet.hosts[k].conns[l]

                # Cleaning old files

# Path: lib/settings.py
# def get_top_domains(dbname):


# Path: lib/utils.py
import socket
import base64
import sqlite3 as lite
import subprocess
import threading
import time
import re
import pickle
import os
import sys
import gc
import json
import fileinput
from struct import unpack
from socket import AF_INET, inet_pton
from lib.logger import *
from lib.settings import homenet, lock

        threading.Thread.__init__(self)
        self.threadID = threadID
        self.ctime = int(time.time())
        self.bro_file_path = '/opt/zeek/logs/current/extract_files/'

    def run(self):

        while 1:
            self.ctime = int(time.time())
            try:
                self.clean_old_host_objects()
            except Exception as e:
                log.debug('FG-WARN: ' + str(e.__doc__) + " - " + str(e))
            time.sleep(600)

    def clean_old_host_objects(self):

        with lock:
            for k in homenet.hosts.keys():
                # Cleaning old DNS entries
                for l in homenet.hosts[k].dns.keys():
                    if (self.ctime - homenet.hosts[k].dns[l].ts) > 86400:
                        del homenet.hosts[k].dns[l]

                # Cleaning old connections
                for l in homenet.hosts[k].conns.keys():
                    if (self.ctime - homenet.hosts[k].conns[l].lseen) > 3600:
                        del homenet.hosts[k].conns[l]

                # Cleaning old files

                for l in homenet.hosts[k].files.keys():