# Path: ovizart/modules/traffic/log/logger.py
# class Logger:
# 
#     def __init__(self, log_name, log_mode):
#         logging.basicConfig(format='%(asctime)-6s: %(name)s - %(levelname)s - %(message)s')
#         self.mode = log_mode
#         self.log = logging.getLogger(log_name)
#         self.log.setLevel(log_mode)
# 
#     def set_log_level(self, level="DEBUG"):
#         self.log.setLevel(level)
# 
#     def message(self, message):
#         if self.mode == "DEBUG":
#             self.log.debug(message)
#         if self.mode == "ERROR":
#             self.log.error(message)
#         if self.mode == "INFO":
#             self.log.info(message)
# 
# Path: ovizart/pcap/models.py
# class FlowDetails(models.Model):
#     parent_hash_value = models.CharField(max_length=50)
#     user_id = models.CharField(max_length=100)
#     src_ip = models.IPAddressField()
#     dst_ip = models.IPAddressField()
#     sport = models.IntegerField()
#     dport = models.IntegerField()
#     protocol = models.CharField(max_length=10)
#     timestamp = models.DateTimeField()
# 
#     objects = MongoDBManager()


from ovizart.modules.traffic.log.logger import Logger
from ovizart.pcap.models import FlowDetails
import os
import datetime


class Handler(object):
    def __init__(self):
        super(Handler, self).__init__()

    def get_flow_ips(self, **args):
        result = self.read_conn_log(args['path'], args['parent_hash_value'], args['user_id'])
        return result

    def read_conn_log(self, path, parent_hash_value, user_id):
        result = [] # lets the keys the connection id, values the ts
        conn_log_path = os.path.join(path, "conn.log")
        f = open(conn_log_path, "r")
        for line in f.readlines():
            if line.startswith("#"): continue
            info = line.split()
            tmp = info[2:6]
            dt = datetime.datetime.fromtimestamp(float(info[0]))
            tmp.append(dt)


# Path: ovizart/modules/traffic/log/logger.py
# class Logger:
# 
#     def __init__(self, log_name, log_mode):
#         logging.basicConfig(format='%(asctime)-6s: %(name)s - %(levelname)s - %(message)s')
#         self.mode = log_mode
#         self.log = logging.getLogger(log_name)
#         self.log.setLevel(log_mode)
# 
#     def set_log_level(self, level="DEBUG"):
#         self.log.setLevel(level)
# 
#     def message(self, message):
#         if self.mode == "DEBUG":
#             self.log.debug(message)
#         if self.mode == "ERROR":
#             self.log.error(message)
#         if self.mode == "INFO":
#             self.log.info(message)
# 
# Path: ovizart/pcap/models.py
# class FlowDetails(models.Model):
#     parent_hash_value = models.CharField(max_length=50)
#     user_id = models.CharField(max_length=100)
#     src_ip = models.IPAddressField()
#     dst_ip = models.IPAddressField()
#     sport = models.IntegerField()
#     dport = models.IntegerField()
#     protocol = models.CharField(max_length=10)
#     timestamp = models.DateTimeField()
# 
#     objects = MongoDBManager()


# Path: ovizart/modules/traffic/parser/unknown/handler.py
from ovizart.modules.traffic.log.logger import Logger
from ovizart.pcap.models import FlowDetails
import os
import datetime



class Handler(object):
    def __init__(self):
        super(Handler, self).__init__()

    def get_flow_ips(self, **args):
        result = self.read_conn_log(args['path'], args['parent_hash_value'], args['user_id'])
        return result

    def read_conn_log(self, path, parent_hash_value, user_id):
        result = [] # lets the keys the connection id, values the ts
        conn_log_path = os.path.join(path, "conn.log")
        f = open(conn_log_path, "r")
        for line in f.readlines():
            if line.startswith("#"): continue
            info = line.split()
            tmp = info[2:6]
            dt = datetime.datetime.fromtimestamp(float(info[0]))
            tmp.append(dt)


            check = FlowDetails.objects.filter(parent_hash_value=parent_hash_value, user_id=user_id, src_ip=tmp[0], sport=int(tmp[1]),