Commit 42fee31a authored by Jason Frisvold's avatar Jason Frisvold
Browse files

- Build each config in a temp file

- Upload configuration files to the right directory
- Handle non-unicode shlex.split() command for python < 2.7.3
parent 3422889b
......@@ -325,8 +325,14 @@ def spawn_process(spawnlist):
fd, tmpfile = tempfile.mkstemp()
optionlist = shlex.split(cfg['nmap_binary'] + ' -oX ' + tmpfile + ' ' +
nmap_options[1] + ' ' + nmap_options[0])
cmdline = cfg['nmap_binary'] + ' -oX ' + tmpfile + ' ' + \
nmap_options[1] + ' ' + nmap_options[0]
# Prior to 2.7.3, shlex wouldn't handle unicode.
if (sys.version_info < (2, 7, 3)):
cmdline = cmdline.encode('ascii')
optionlist = shlex.split(cmdline)
logger.debug('Will spawn with options {0}'.format(str(optionlist)))
......
......@@ -29,6 +29,7 @@ import re
import MySQLdb
from netaddr import IPAddress
import paramiko
import tempfile
# Global Variables
verbose = False
......@@ -125,7 +126,8 @@ def main(argv):
server['config_dir'])
# Get results from server
get_results(dbhandle, server_conn, str(server['id']))
get_results(dbhandle, server_conn, server['output_dir'],
str(server['id']))
server_conn.close()
......@@ -247,11 +249,34 @@ def build_configs(dbhandle, server_id):
def push_configs(server_conn, configlist, config_path):
logger.info('Pushing server configuration')
server_conn.chdir(config_path)
def get_results(dbhandle, server_conn, server_id):
for config in configlist:
tmpfile = tempfile.NamedTemporaryFile(delete=False)
tmpfile.write("modify\n")
tmpfile.write(str(config['id']) + "\n")
tmpfile.write(config['minute'] + "\n")
tmpfile.write(config['hour'] + "\n")
tmpfile.write(config['day'] + "\n")
tmpfile.write(config['month'] + "\n")
tmpfile.write(str(config['override']) + "\n")
tmpfile.write(config['ip'] + "\n")
tmpfile.write(config['options'] + "\n")
tmpfile.close()
logger.debug('Uploading {0} to {1}'
.format(tmpfile.name, config_path + '/' +
os.path.basename(tmpfile.name) + '.skynet'))
server_conn.put(tmpfile.name,
config_path + '/' +
os.path.basename(tmpfile.name) + '.skynet')
os.remove(tmpfile.name)
def get_results(dbhandle, server_conn, output_dir, server_id):
logger.info('Retrieving results from server')
files = server_conn.listdir(output_dir)
logger.info('Retrieved list of files - {0}'.format(files))
logger.info('Updating last_contacted for server {0}'.format(server_id))
sql = '''UPDATE cloud SET last_contacted = NOW() WHERE id = %s'''
......
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