# Path: config/config.py

# 
# Path: db/logDB.py
# class logDatabase:
# 	def __init__(self, root="."):
# 		
# 		self.conn = MySQLdb.connect("localhost", "tvtLog", "tvtLog", "logDB")
# 		self.cursor = self.conn.cursor()
# 		self.commit = self.conn.commit()
#   	
# 
# 	def searchUser(self,column, term, start, end):
# 		search = str(term)
# 		conn = MySQLdb.connect("localhost", "tvtLog", "tvtLog", "logDB")
# 		cursor = conn.cursor()
# 		cursor.execute('SELECT timestamp, cIP, scStatus, csMethod, csURI, userCredential FROM http WHERE '+ column +'=%s AND timestamp >= %s AND timestamp <= %s ORDER BY timestamp DESC;', (search, start, end))
# 		user = cursor.fetchall()
# 		return user
# 	def insertHTTP(self, logLine):
# 		self.cursor.execute('INSERT INTO http VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);', tuple(logLine))
# 		#self.conn.commit()
# 	def commitData(self):
# 		self.conn.commit()
# 	def countAll(self):
# 		count = self.cursor.execute('SELECT COUNT(*) FROM http;')
# 		print count
# 		
# 		
# 		
# 	def searchEmail(self, column, term, start, end):
# 		search = str(urllib.unquote(term))
# 		conn = MySQLdb.connect("localhost", "tvtLog", "tvtLog", "logDB")
# 		cursor = conn.cursor()
# 		start = datetime.strptime(start, '%Y-%m-%d')
# 		end = datetime.strptime(end, '%Y-%m-%d')
# 		sql = column, search
# 		cursor.execute("SELECT sender, recipient, time_t, relay, msgid, subject, size, action, reason FROM email WHERE "+ column +"=%s AND str_to_date(time_t, '%%Y-%%m-%%d %%T') >= %s AND str_to_date(time_t, '%%Y-%%m-%%d %%T') <= %s ORDER BY time_t DESC;", (search, start, end))
# 		#cursor.execute(sql)
# 		#print sql
# 		emails = cursor.fetchall()
# 		return emails
# 
# 
# 	def compareEmails(self, column, term):
# 		list_of_lists = []
# 		search = str(urllib.unquote(term))
# 		conn = MySQLdb.connect("localhost", "tvtLog", "tvtLog", "logDB")
# 		cursor = conn.cursor()
# 		sql = column, search
# 		cursor.execute('SELECT sender, recipient, time_t, relay, msgid, subject, size, action, reason FROM email WHERE '+ column +'=%s;', search)
# 		emails = cursor.fetchall()
# 		for j in range(len(emails)):
# 			list_of_lists.append([])
# 		counter = 0
# 		
# 		for recipient in emails:
# 			cursor.execute('SELECT sender, recipient, time_t, relay, msgid, subject, size, action, reason FROM email WHERE recipient=%s;', recipient[1])
# 			collects = cursor.fetchall()
# 			for each in collects:
# 				list_of_lists[counter].append(each[5])
# 			counter += 1
# 		match = list(set.intersection(*map(set, list_of_lists)))
# 		return match


import os
import sys
import gzip
import shlex
import time
import MySQLdb
import logging
import db.logDB
	import hashlib
from optparse import OptionParser
from datetime import datetime
from config.config import logTemp
from db.logDB import logDatabase
								except:
									print gzFile
						elif method == 2:
							logEntry = line.split()
							print logEntry
							#db.dbLog.logLine(logEntry)
					conn.commit()
					gz.close()
							
				except IOError as e:
					print e.strerror
				timeCounter = time.time() - startTime
				os.remove((os.path.join(logTemp, gzFile)))
				print "Files %s Processed in %s Seconds" % (fileCounter, timeCounter)
	return httpCounter, fileCounter, timeCounter

def emailParse():
	httpCounter = 0
	httpsCounter = 0
	fileCounter = 0
	timeCounter = 0
	startTime = time.time()
	conn = MySQLdb.connect("localhost", "tvtLog", "tvtLog", "logDB")
	cursor = conn.cursor()	
	for gzFile in os.listdir(logTemp):
		if gzFile.endswith(".gz"): 
			if gzFile.startswith("email"):
				method = 1
				fileCounter += 1
				try:

# Path: config/config.py

# 
# Path: db/logDB.py
# class logDatabase:
# 	def __init__(self, root="."):
# 		
# 		self.conn = MySQLdb.connect("localhost", "tvtLog", "tvtLog", "logDB")
# 		self.cursor = self.conn.cursor()
# 		self.commit = self.conn.commit()
#   	
# 
# 	def searchUser(self,column, term, start, end):
# 		search = str(term)
# 		conn = MySQLdb.connect("localhost", "tvtLog", "tvtLog", "logDB")
# 		cursor = conn.cursor()
# 		cursor.execute('SELECT timestamp, cIP, scStatus, csMethod, csURI, userCredential FROM http WHERE '+ column +'=%s AND timestamp >= %s AND timestamp <= %s ORDER BY timestamp DESC;', (search, start, end))
# 		user = cursor.fetchall()
# 		return user
# 	def insertHTTP(self, logLine):
# 		self.cursor.execute('INSERT INTO http VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);', tuple(logLine))
# 		#self.conn.commit()
# 	def commitData(self):
# 		self.conn.commit()
# 	def countAll(self):
# 		count = self.cursor.execute('SELECT COUNT(*) FROM http;')
# 		print count
# 		
# 		
# 		
# 	def searchEmail(self, column, term, start, end):
# 		search = str(urllib.unquote(term))
# 		conn = MySQLdb.connect("localhost", "tvtLog", "tvtLog", "logDB")
# 		cursor = conn.cursor()
# 		start = datetime.strptime(start, '%Y-%m-%d')
# 		end = datetime.strptime(end, '%Y-%m-%d')
# 		sql = column, search
# 		cursor.execute("SELECT sender, recipient, time_t, relay, msgid, subject, size, action, reason FROM email WHERE "+ column +"=%s AND str_to_date(time_t, '%%Y-%%m-%%d %%T') >= %s AND str_to_date(time_t, '%%Y-%%m-%%d %%T') <= %s ORDER BY time_t DESC;", (search, start, end))
# 		#cursor.execute(sql)
# 		#print sql
# 		emails = cursor.fetchall()
# 		return emails
# 
# 
# 	def compareEmails(self, column, term):
# 		list_of_lists = []
# 		search = str(urllib.unquote(term))
# 		conn = MySQLdb.connect("localhost", "tvtLog", "tvtLog", "logDB")
# 		cursor = conn.cursor()
# 		sql = column, search
# 		cursor.execute('SELECT sender, recipient, time_t, relay, msgid, subject, size, action, reason FROM email WHERE '+ column +'=%s;', search)
# 		emails = cursor.fetchall()
# 		for j in range(len(emails)):
# 			list_of_lists.append([])
# 		counter = 0
# 		
# 		for recipient in emails:
# 			cursor.execute('SELECT sender, recipient, time_t, relay, msgid, subject, size, action, reason FROM email WHERE recipient=%s;', recipient[1])
# 			collects = cursor.fetchall()
# 			for each in collects:
# 				list_of_lists[counter].append(each[5])
# 			counter += 1
# 		match = list(set.intersection(*map(set, list_of_lists)))
# 		return match


# Path: core/logParse.py
import os
import sys
import gzip
import shlex
import time
import MySQLdb
import logging
import db.logDB
	import hashlib
from optparse import OptionParser
from datetime import datetime
from config.config import logTemp
from db.logDB import logDatabase

								except:
									print gzFile
						elif method == 2:
							logEntry = line.split()
							print logEntry
							#db.dbLog.logLine(logEntry)
					conn.commit()
					gz.close()
							
				except IOError as e:
					print e.strerror
				timeCounter = time.time() - startTime
				os.remove((os.path.join(logTemp, gzFile)))
				print "Files %s Processed in %s Seconds" % (fileCounter, timeCounter)
	return httpCounter, fileCounter, timeCounter

def emailParse():
	httpCounter = 0
	httpsCounter = 0
	fileCounter = 0
	timeCounter = 0
	startTime = time.time()
	conn = MySQLdb.connect("localhost", "tvtLog", "tvtLog", "logDB")
	cursor = conn.cursor()	
	for gzFile in os.listdir(logTemp):
		if gzFile.endswith(".gz"): 
			if gzFile.startswith("email"):
				method = 1
				fileCounter += 1
				try:

					gz = gzip.open((os.path.join(logTemp, gzFile)), 'r')