mirror of https://github.com/dirtbags/moth.git
Merge branch 'master' of ssh://cfl.lanl.gov/var/projects/gctf
This commit is contained in:
commit
147e3835e5
|
@ -37,6 +37,10 @@ else:
|
||||||
'house_team': 'dirtbags',
|
'house_team': 'dirtbags',
|
||||||
'passwd': '/var/lib/ctf/passwd',
|
'passwd': '/var/lib/ctf/passwd',
|
||||||
'team_colors': team_colors,
|
'team_colors': team_colors,
|
||||||
|
'poll_interval': 60,
|
||||||
|
'poll_timeout': 0.5,
|
||||||
|
'heartbeat_dir': '/var/lib/pollster',
|
||||||
|
'poll_dir': '/var/lib/www',
|
||||||
},
|
},
|
||||||
'puzzler':
|
'puzzler':
|
||||||
{'dir': '/usr/lib/www/puzzler',
|
{'dir': '/usr/lib/www/puzzler',
|
||||||
|
|
|
@ -6,16 +6,37 @@ import sys
|
||||||
import time
|
import time
|
||||||
import socket
|
import socket
|
||||||
import traceback
|
import traceback
|
||||||
|
import threading
|
||||||
|
import queue
|
||||||
|
|
||||||
# TODO:
|
from ctf import config
|
||||||
# scoring interface
|
from ctf import pointscli
|
||||||
# config interface
|
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
POLL_INTERVAL = 60
|
POLL_INTERVAL = config.get('poll_interval')
|
||||||
IP_DIR = 'iptest/'
|
IP_DIR = config.get('heartbeat_dir')
|
||||||
REPORT_PATH = 'iptest/pollster.html'
|
REPORT_PATH = config.get('poll_dir')
|
||||||
SOCK_TIMEOUT = 0.5
|
SOCK_TIMEOUT = config.get('poll_timeout')
|
||||||
|
|
||||||
|
class PointSubmitter(threading.Thread):
|
||||||
|
''' Pulls point allocations from the queue and submits them. '''
|
||||||
|
def __init__(self, point_queue):
|
||||||
|
threading.Thread.__init__(self)
|
||||||
|
self.point_queue = point_queue
|
||||||
|
self.sock = pointscli.makesock('localhost')
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
# loop forever
|
||||||
|
while(True):
|
||||||
|
cat, team, score = self.point_queue.get()
|
||||||
|
if None in [cat, team, score]:
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
pointscli.submit(cat, team, score, sock=self.sock)
|
||||||
|
except ValueError:
|
||||||
|
print('pollster: error submitting score (%s, %s, %d)' % (cat, team, score))
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
def socket_poll(ip, port, msg, prot, max_recv=1):
|
def socket_poll(ip, port, msg, prot, max_recv=1):
|
||||||
''' Connect via socket to the specified <ip>:<port> using the
|
''' Connect via socket to the specified <ip>:<port> using the
|
||||||
|
@ -137,6 +158,11 @@ POLLS = {
|
||||||
|
|
||||||
ip_re = re.compile('(\d{1,3}\.){3}\d{1,3}')
|
ip_re = re.compile('(\d{1,3}\.){3}\d{1,3}')
|
||||||
|
|
||||||
|
# start point submitter thread
|
||||||
|
point_queue = queue.Queue()
|
||||||
|
t = PointSubmitter(point_queue)
|
||||||
|
t.start()
|
||||||
|
|
||||||
# loop forever
|
# loop forever
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
@ -154,7 +180,13 @@ while True:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
out = open(REPORT_PATH, 'w')
|
out = open(REPORT_PATH, 'w')
|
||||||
|
except Exception as e:
|
||||||
|
out = None
|
||||||
|
pass
|
||||||
|
|
||||||
|
if out is not None:
|
||||||
out.write('<html>\n<head>\n')
|
out.write('<html>\n<head>\n')
|
||||||
out.write('<title>Pollster Results</title>\n')
|
out.write('<title>Pollster Results</title>\n')
|
||||||
out.write('<link rel="stylesheet" href="ctf.css" type="text/css" media="all" />\n')
|
out.write('<link rel="stylesheet" href="ctf.css" type="text/css" media="all" />\n')
|
||||||
|
@ -178,6 +210,7 @@ while True:
|
||||||
if DEBUG is True:
|
if DEBUG is True:
|
||||||
print('ip: %s' % ip)
|
print('ip: %s' % ip)
|
||||||
|
|
||||||
|
if out is not None:
|
||||||
out.write('<h2>%s</h2>\n' % ip)
|
out.write('<h2>%s</h2>\n' % ip)
|
||||||
out.write('<table class="pollster">\n<thead><tr><td>Service Name</td></td>')
|
out.write('<table class="pollster">\n<thead><tr><td>Service Name</td></td>')
|
||||||
out.write('<td>Flag Holder</td></tr></thead>\n')
|
out.write('<td>Flag Holder</td></tr></thead>\n')
|
||||||
|
@ -191,8 +224,12 @@ while True:
|
||||||
if DEBUG is True:
|
if DEBUG is True:
|
||||||
print('\t%s - %s' % (service, team))
|
print('\t%s - %s' % (service, team))
|
||||||
|
|
||||||
|
if out is not None:
|
||||||
out.write('<tr><td>%s</td><td>%s</td>\n' % (service, team))
|
out.write('<tr><td>%s</td><td>%s</td>\n' % (service, team))
|
||||||
|
|
||||||
|
point_queue.put((service, team, 1))
|
||||||
|
|
||||||
|
if out is not None:
|
||||||
out.write('</table>\n')
|
out.write('</table>\n')
|
||||||
|
|
||||||
if DEBUG is True:
|
if DEBUG is True:
|
||||||
|
@ -202,6 +239,7 @@ while True:
|
||||||
exec_time = int(t_end - t_start)
|
exec_time = int(t_end - t_start)
|
||||||
sleep_time = POLL_INTERVAL - exec_time
|
sleep_time = POLL_INTERVAL - exec_time
|
||||||
|
|
||||||
|
if out is not None:
|
||||||
out.write('<p><b>Next poll in: %ds</b></p>\n' % sleep_time)
|
out.write('<p><b>Next poll in: %ds</b></p>\n' % sleep_time)
|
||||||
out.write('</body>\n</html>\n')
|
out.write('</body>\n</html>\n')
|
||||||
out.close()
|
out.close()
|
||||||
|
|
Loading…
Reference in New Issue