#!/usr/bin/python
import sys
import MySQLdb

#
# Reads Nepenthes logged_submissions file and inserts data to mysql table
#

#connect to database
db = MySQLdb.connect( host="localhost", user="neplog", passwd="neplog123", db="nepenthes")

#create cursor
cursor = db.cursor()

#read from stdin
while 1:
	line = sys.stdin.readline()
	if not line:
		break

	logData = line.split(' ');

	timestamp = logData[0].strip('[]')
	date = timestamp.split('T')[0]
	time = timestamp.split('T')[1]
	sourceIP = logData[1]
	sourceMalware = logData[4]
	malwareMD5 = logData[5]

	#Insert row
	cursor.execute("insert into submissions values (\"%s\",\"%s\",\"%s\",\"%s\",\"%s\")" %( date, time, sourceIP, sourceMalware, malwareMD5) )


