Commit a94b4262 authored by Jason Frisvold's avatar Jason Frisvold
Browse files

- Rename server_id to timer_id in the client

- Add work_dir to config for server
- Add code to download output files to the work_dir
- Delete files after downloading
parent 42fee31a
......@@ -182,11 +182,11 @@ def check_timing(loopstarttime, timingdb):
try:
timingcursor = timingdb.cursor()
sql = '''SELECT t.server_id, td.override_flag FROM timers AS t,
sql = '''SELECT t.timer_id, td.override_flag FROM timers AS t,
timer_details AS td WHERE (t.minute = ? OR t.minute = "*") AND
(t.hour = ? OR t.hour = "*") AND (t.day = ? OR t.day = "*")
AND (t.month = ? OR t.month = "*") AND t.server_id =
td.server_id'''
AND (t.month = ? OR t.month = "*") AND t.timer_id =
td.timer_id'''
timingcursor.execute(sql, (loopstarttime.minute, loopstarttime.hour,
loopstarttime.day, loopstarttime.month))
......@@ -209,7 +209,7 @@ def check_complete(spawnlist, timingdb):
try:
timingcursor = timingdb.cursor()
sql = 'SELECT server_id, start_time, pid FROM spawned'
sql = 'SELECT timer_id, start_time, pid FROM spawned'
timingcursor.execute(sql)
......@@ -228,14 +228,14 @@ def check_complete(spawnlist, timingdb):
logger.debug('PID {0} Still running'.format(str(row[2])))
try:
# If server_id should be spawned, isn't allowed to override,
# If timer_id should be spawned, isn't allowed to override,
# and is still running, then remove it from the spawnlist
# and set overrun = 1
spawnlist.remove((row[0],0))
logger.debug('''ID {0} not allowed to override, removed from
spawn list'''.format(str(row[0])))
sql = '''UPDATE spawned SET overtime = 1 WHERE server_id =
sql = '''UPDATE spawned SET overtime = 1 WHERE timer_id =
? AND pid = ?'''
timingcursor.execute(sql, (row[0], row[2],))
......@@ -245,10 +245,10 @@ def check_complete(spawnlist, timingdb):
logger.debug('PID {0} Completed'.format(str(row[2])))
end_time = int(time.mktime(time.gmtime()))
sql = '''DELETE FROM spawned WHERE server_id = ? AND pid = ?'''
sql = '''DELETE FROM spawned WHERE timer_id = ? AND pid = ?'''
timingcursor.execute(sql, (row[0], row[2]))
sql = '''INSERT INTO spawn_log (server_id, start_time, end_time)
sql = '''INSERT INTO spawn_log (timer_id, start_time, end_time)
VALUES (?, ?, ?)'''
timingcursor.execute(sql, (row[0], row[1], end_time))
......@@ -318,7 +318,7 @@ def spawn_process(spawnlist):
logger.debug('Timer number {0}'.format(str(timer)))
sql = '''SELECT ip_range, nmap_options FROM timer_details WHERE
server_id = ?'''
timer_id = ?'''
timingcursor.execute(sql, (timer,))
nmap_options = timingcursor.fetchone()
......@@ -339,7 +339,7 @@ def spawn_process(spawnlist):
spawned = Popen(optionlist)
logger.debug('Spawned - {0}'.format(str(spawned.pid)))
sql = '''INSERT INTO spawned (server_id, start_time, pid, overtime)
sql = '''INSERT INTO spawned (timer_id, start_time, pid, overtime)
VALUES (?, ?, ?, 0)'''
timingcursor.execute(sql, (timer, start_time, spawned.pid))
......@@ -375,7 +375,7 @@ def open_timing_database():
# Create the tables, if they don't exist already
sql = '''CREATE TABLE IF NOT EXISTS timers
( server_id INT,
( timer_id INT,
minute TEXT,
hour TEXT,
day TEXT,
......@@ -384,7 +384,7 @@ def open_timing_database():
timingcursor.execute(sql)
sql = '''CREATE TABLE IF NOT EXISTS timer_details
( server_id INT,
( timer_id INT,
override_flag BOOLEAN,
ip_range TEXT,
nmap_options TEXT
......@@ -392,7 +392,7 @@ def open_timing_database():
timingcursor.execute(sql)
sql = '''CREATE TABLE IF NOT EXISTS spawned
( server_id INT,
( timer_id INT,
start_time INT,
pid INT,
overtime BOOLEAN
......@@ -400,7 +400,7 @@ def open_timing_database():
timingcursor.execute(sql)
sql = '''CREATE TABLE IF NOT EXISTS spawn_log
(server_id INT,
( timer_id INT,
start_time INT,
end_time INT,
status INT
......
......@@ -36,5 +36,9 @@ dbhost = localhost
# Port where the database can be accessed
dbport = 3306
# Working directory where files are temporarily stored until they can be
# processed
work_dir = /opt/skynet/server/working
# Location of the gpg binary. This should be the full path and binary name.
gpg_binary = /usr/bin/gpg
\ No newline at end of file
......@@ -127,7 +127,7 @@ def main(argv):
# Get results from server
get_results(dbhandle, server_conn, server['output_dir'],
str(server['id']))
cfg['work_dir'], str(server['id']))
server_conn.close()
......@@ -159,6 +159,7 @@ def loadconfig():
cfg['dbport'] = config.get('skynet', 'dbport')
cfg['dbuser'] = config.get('skynet', 'dbuser')
cfg['dbpass'] = config.get('skynet', 'dbpass')
cfg['work_dir'] = config.get('skynet', 'work_dir')
for k, v in cfg.items():
logger.debug('{0} = {1}'.format(k, v))
......@@ -270,12 +271,17 @@ def push_configs(server_conn, configlist, config_path):
os.path.basename(tmpfile.name) + '.skynet')
os.remove(tmpfile.name)
def get_results(dbhandle, server_conn, output_dir, server_id):
def get_results(dbhandle, server_conn, output_dir, work_dir, server_id):
logger.info('Retrieving results from server')
files = server_conn.listdir(output_dir)
file_list = server_conn.listdir(output_dir)
logger.info('Retrieved list of files - {0}'.format(files))
logger.info('Retrieved list of files - {0}'.format(file_list))
for result in file_list:
server_conn.get(output_dir + '/' + result, work_dir)
# TODO : Validate received file prior to deleting remote file
server_conn.remove(output_dir + '/' + result)
logger.info('Updating last_contacted for server {0}'.format(server_id))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment