# Path: owade/constants.py
# def checkConstant(dir, isdir=True):
# PROJECT_DIR = "/opt/"
# PROJECT_NAME = "OwadeReborn/"
# TIMELINE_FILE = PROJECT_DIR + PROJECT_NAME + "templates/timeline.html"
# HASHCAT_DIR = PROJECT_DIR + PROJECT_NAME + "owade/fileAnalyze/hashcatLib/hashcat"
# DATABASE_NAME='owade'
# DATABASE_USER='postgres'
# DATABASE_PASSWORD='postgres'
# DATABASE_HOST='localhost'
# DATABASE_PORT='5432'
# EXT_HDRIVE = "/media/hackaton/TOSHIBA EXT/storage"
# IMAGE_DIR = EXT_HDRIVE + "/image"
# IMAGE_FTP = EXT_HDRIVE + "/ftp"
# FILE_DIR = EXT_HDRIVE + "/file"
# DATABASE_DIR = PROJECT_DIR + "OwadeReborn/database/"
# TEMPLATE_DIR = PROJECT_DIR + "OwadeReborn/templates/"
# 
# Path: owade/tools/domainFormater.py
# def format(url):
#     if not re.match(r'^http', url):
#         return None
#     if re.match(r'https?://[^/.]*(:[0-9]{1,5})?(/.*)?$', url):
#         return None
#     match = re.match(r'^https?://([^/]*\.)*([^/.]*\.[^/.]{2}\.[^/.]{2,3})(:[0-9]{1,5})?(/.*)?$', url)
#     if match == None:
#         match = re.match(r'^https?://([^/]*\.)*([^/.]*\.com\.[^/.]{2,3})(:[0-9]{1,5})?(/.*)?$', url)
#         if match == None:
#             match = re.match(r'^https?://([^/]*\.)*([^/.]*\.[^/.]{2,4})(:[0-9]{1,5})?(/.*)?$', url)
#             if match == None:
#                 match = re.match(r'^https?://([^/]*\.)*([^/.]*)(:[0-9]{1,5})?(/.*)?$', url)
#                 if match != None:
#                     return match.group(1) + match.group(2)
#                 raise Exception("One case isn't dealed with: %s" % url)
#     return match.group(2)


import os
import sys
import tempfile
import re
import subprocess as subp
from owade.constants import MSIECF_DIR
from owade.tools.domainFormater import format



class GetIEHistory:
    #indexes is a list of the path :
    #%USERPROFILE%Ashee/Local Settings/History/index.dat
    #%USERPROFILE%Ashee/Local Settings/History/*/index.dat
    def main(self, indexes):
        placeValues = {}
        formValues = {}

        binary = '%s/msiecftools/msiecfexport' % MSIECF_DIR
        if not os.path.isfile(binary):
            print >>sys.stderr, "Binary %s not found" % binary
            return {self.__class__.__name__:{'places':placeValues, 'forms':formValues}}

        i = 0
        for index in indexes:
            temp = tempfile.NamedTemporaryFile()
            subp.call([binary, index], universal_newlines=True, stdout=temp)
            temp.seek(0)
            url = ""
            date = ""
            for line in temp:
                if len(line) != 0 and line[-1] == '\n':
                    line = line[:-1]
                if line == "":
                    if url != "" and date != "":
                        i += 1
                        placeValues['place%d' % i] = {'url':url, 'date':date,

# Path: owade/constants.py
# def checkConstant(dir, isdir=True):
# PROJECT_DIR = "/opt/"
# PROJECT_NAME = "OwadeReborn/"
# TIMELINE_FILE = PROJECT_DIR + PROJECT_NAME + "templates/timeline.html"
# HASHCAT_DIR = PROJECT_DIR + PROJECT_NAME + "owade/fileAnalyze/hashcatLib/hashcat"
# DATABASE_NAME='owade'
# DATABASE_USER='postgres'
# DATABASE_PASSWORD='postgres'
# DATABASE_HOST='localhost'
# DATABASE_PORT='5432'
# EXT_HDRIVE = "/media/hackaton/TOSHIBA EXT/storage"
# IMAGE_DIR = EXT_HDRIVE + "/image"
# IMAGE_FTP = EXT_HDRIVE + "/ftp"
# FILE_DIR = EXT_HDRIVE + "/file"
# DATABASE_DIR = PROJECT_DIR + "OwadeReborn/database/"
# TEMPLATE_DIR = PROJECT_DIR + "OwadeReborn/templates/"
# 
# Path: owade/tools/domainFormater.py
# def format(url):
#     if not re.match(r'^http', url):
#         return None
#     if re.match(r'https?://[^/.]*(:[0-9]{1,5})?(/.*)?$', url):
#         return None
#     match = re.match(r'^https?://([^/]*\.)*([^/.]*\.[^/.]{2}\.[^/.]{2,3})(:[0-9]{1,5})?(/.*)?$', url)
#     if match == None:
#         match = re.match(r'^https?://([^/]*\.)*([^/.]*\.com\.[^/.]{2,3})(:[0-9]{1,5})?(/.*)?$', url)
#         if match == None:
#             match = re.match(r'^https?://([^/]*\.)*([^/.]*\.[^/.]{2,4})(:[0-9]{1,5})?(/.*)?$', url)
#             if match == None:
#                 match = re.match(r'^https?://([^/]*\.)*([^/.]*)(:[0-9]{1,5})?(/.*)?$', url)
#                 if match != None:
#                     return match.group(1) + match.group(2)
#                 raise Exception("One case isn't dealed with: %s" % url)
#     return match.group(2)


# Path: owade/fileAnalyze/historyIE.py
import os
import sys
import tempfile
import re
import subprocess as subp
from owade.constants import MSIECF_DIR
from owade.tools.domainFormater import format




class GetIEHistory:
    #indexes is a list of the path :
    #%USERPROFILE%Ashee/Local Settings/History/index.dat
    #%USERPROFILE%Ashee/Local Settings/History/*/index.dat
    def main(self, indexes):
        placeValues = {}
        formValues = {}

        binary = '%s/msiecftools/msiecfexport' % MSIECF_DIR
        if not os.path.isfile(binary):
            print >>sys.stderr, "Binary %s not found" % binary
            return {self.__class__.__name__:{'places':placeValues, 'forms':formValues}}

        i = 0
        for index in indexes:
            temp = tempfile.NamedTemporaryFile()
            subp.call([binary, index], universal_newlines=True, stdout=temp)
            temp.seek(0)
            url = ""
            date = ""
            for line in temp:
                if len(line) != 0 and line[-1] == '\n':
                    line = line[:-1]
                if line == "":
                    if url != "" and date != "":
                        i += 1
                        placeValues['place%d' % i] = {'url':url, 'date':date,

                            'domain':format(url)}