A few path changes for easier local testing

This commit is contained in:
Neale Pickett 2009-10-01 18:33:21 -06:00
parent 35725ee3e5
commit 36a430e9a1
10 changed files with 78 additions and 41 deletions

View File

@ -6,10 +6,11 @@ WWWDIR = $(DESTDIR)/usr/lib/www
FAKE = fakeroot -s fake -i fake FAKE = fakeroot -s fake -i fake
INSTALL = $(FAKE) install INSTALL = $(FAKE) install
PYC = config.pyc points.pyc game.pyc teams.pyc PYC = config.pyc points.pyc teams.pyc
PYC += register.pyc scoreboard.pyc puzzler.pyc PYC += register.pyc scoreboard.pyc puzzler.pyc
PYC += flagd.pyc pointsd.pyc pointscli.pyc PYC += flagd.pyc pointsd.pyc pointscli.pyc
PYC += roshambo.pyc histogram.pyc PYC += histogram.pyc
#PYC += roshambo.pyc game.pyc
all: ctf.tce all: ctf.tce

View File

@ -12,8 +12,8 @@ if 'home' in os.environ.get('SCRIPT_FILENAME', ''):
config = {'global': config = {'global':
{'data_dir': '.', {'data_dir': '.',
'base_url': '.', 'base_url': '.',
'css_url': 'ctf.css', 'css_url': '/~neale/ctf/ctf.css',
'diasbled_dir': 'disabled', 'disabled_dir': 'disabled',
'flags_dir': 'flags', 'flags_dir': 'flags',
'house_team': 'dirtbags', 'house_team': 'dirtbags',
'passwd': 'passwd', 'passwd': 'passwd',

51
ctf.css
View File

@ -12,6 +12,26 @@ body {
max-width: 700px; max-width: 700px;
} }
/**** heading ****/
h1:first-child {
text-transform: lowercase;
font-size: 1.6em;
/* background-color: #222; */
/* opacity: 0.9; */
padding: 3px;
color: #2a2;
margin: 0 0 1em 70px;
}
h1:first-child:before {
color: #fff;
letter-spacing: -0.1em;
content: "Capture The Flag: ";
}
/**** body ****/
a img { a img {
border: 0px; border: 0px;
} }
@ -28,6 +48,12 @@ a:hover {
font-weight: bold; font-weight: bold;
} }
h1, h2, h3 {
color: #999;
letter-spacing: -0.05em;
}
code, pre, .readme { code, pre, .readme {
color: #fff; color: #fff;
background-color: #555; background-color: #555;
@ -42,33 +68,12 @@ th, td {
height: 400px; height: 400px;
} }
/**** heading ****/
h1:first-child {
text-transform: lowercase;
font-size: 1.6em;
background-color: #222;
opacity: 0.9;
padding: 3px;
color: #2a2;
margin: 0 0 1em 70px;
}
h1:first-child:before {
color: #fff;
letter-spacing: -0.1em;
content: "Capture The Flag: ";
}
/*** body ***/
p { p {
line-height: 1.4em; line-height: 1.4em;
margin-bottom: 20px; margin-bottom: 20px;
color: #f4f4f4; color: #f4f4f4;
} }
h1, h2, h3 { .center {
color: #999; text-align: center;
letter-spacing: -0.05em;
} }

27
ctfd.py
View File

@ -6,21 +6,38 @@ import game
import flagd import flagd
import histogram import histogram
import config import config
import os
import sys
do_reap = False
def chart(s):
if not os.fork():
histogram.main(s)
sys.exit(0)
def reap():
try:
while True:
os.waitpid(0, os.WNOHANG)
except OSError:
pass
def sigchld(signum, frame):
do_reap = True
def main(): def main():
pointsrv = pointsd.start() pointsrv = pointsd.start()
flagsrv = flagd.start() flagsrv = flagd.start()
if config.enabled('roshambo'):
import roshambo
roshambosrv = roshambo.start()
s = pointsrv.store s = pointsrv.store
slen = 0 slen = 0
while True: while True:
if do_reap:
reap()
asyncore.loop(timeout=30, use_poll=True, count=1) asyncore.loop(timeout=30, use_poll=True, count=1)
if len(s) > slen: if len(s) > slen:
slen = len(s) slen = len(s)
histogram.main(s) chart(s)
main() main()

View File

@ -21,7 +21,7 @@ def hexdigest(data):
flags_dir = config.get('global', 'flags_dir') flags_dir = config.get('global', 'flags_dir')
class Submitter(asyncore.dispatcher): class Submitter(asyncore.dispatcher):
def __init__(self, host='localhost', port=6667): def __init__(self, host='', port=6667):
asyncore.dispatcher.__init__(self) asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_DGRAM) self.create_socket(socket.AF_INET, socket.SOCK_DGRAM)
self.connect((host, port)) self.connect((host, port))
@ -70,6 +70,8 @@ class Submitter(asyncore.dispatcher):
raise ValueError(txt) raise ValueError(txt)
def set_flag(self, cat, team): def set_flag(self, cat, team):
if not cat:
return
now = int(time.time()) now = int(time.time())
team = team or teams.house team = team or teams.house

View File

@ -17,7 +17,6 @@ def main(s=None):
s = points.Storage() s = points.Storage()
plotparts = [] plotparts = []
teams = s.teams
catscores = {} catscores = {}
for cat in s.categories(): for cat in s.categories():
@ -26,14 +25,14 @@ def main(s=None):
scoresfile = tempfile.NamedTemporaryFile('w') scoresfile = tempfile.NamedTemporaryFile('w')
fn = scoresfile.name fn = scoresfile.name
i = 2 i = 2
for team in teams: for team in s.teams:
plotparts.append('"%s" using 1:%d with lines linewidth 2 linetype rgb "#%s"' % (fn, i, teams.color(team))) plotparts.append('"%s" using 1:%d with lines linewidth 2 linetype rgb "#%s"' % (fn, i, teams.color(team)))
scores[team] = 0 scores[team] = 0
i += 1 i += 1
def write_scores(t): def write_scores(t):
scoresfile.write('%d' % t) scoresfile.write('%d' % t)
for team in teams: for team in s.teams:
scoresfile.write('\t%f' % (scores[team])) scoresfile.write('\t%f' % (scores[team]))
scoresfile.write('\n') scoresfile.write('\n')
@ -65,7 +64,7 @@ plot %(plot)s\n''' % {'plot': ','.join(plotparts),
'pngout': pngout}) 'pngout': pngout})
instructions.flush() instructions.flush()
gp = os.system('gnuplot %s 2>/dev/null' % instructions.name) gp = os.system('gnuplot %s 2>/dev/null </dev/null' % instructions.name)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -22,7 +22,10 @@ for cat in os.listdir(opts.puzzles):
for points in os.listdir(dirname): for points in os.listdir(dirname):
pointsdir = os.path.join(dirname, points) pointsdir = os.path.join(dirname, points)
outdir = os.path.join(opts.htmldir, cat, points) outdir = os.path.join(opts.htmldir, cat, points)
os.makedirs(outdir) try:
os.makedirs(outdir)
except OSError:
pass
readme = '' readme = ''
files = [] files = []
@ -33,6 +36,8 @@ for cat in os.listdir(opts.puzzles):
keys.append((cat, points, key)) keys.append((cat, points, key))
elif fn == 'index.html': elif fn == 'index.html':
readme = open(path, encoding='utf-8').read() readme = open(path, encoding='utf-8').read()
elif fn.endswith('~'):
pass
else: else:
files.append((fn, path)) files.append((fn, path))

View File

@ -28,6 +28,10 @@ def main():
<body> <body>
<h1>Team Registration</h1> <h1>Team Registration</h1>
<p>
Pick a short team name: you'll be typing it a lot.
</p>
<form method="post" action="%s"> <form method="post" action="%s">
<fieldset> <fieldset>
<legend>Registration information:</legend> <legend>Registration information:</legend>

View File

@ -1,4 +1,4 @@
#! /bin/sh #! /bin/sh
exec /usr/lib/ctf/ctfd.py exec envuidgid ctf /usr/lib/ctf/ctfd.py 2>&1

View File

@ -15,6 +15,7 @@ def main():
categories = [(cat, s.cat_points(cat)) for cat in s.categories()] categories = [(cat, s.cat_points(cat)) for cat in s.categories()]
print('Content-type: text/html') print('Content-type: text/html')
print('Refresh: 10')
print() print()
print('''<?xml version="1.0" encoding="UTF-8" ?> print('''<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
@ -24,7 +25,7 @@ def main():
<title>Scoreboard</title> <title>Scoreboard</title>
<link rel="stylesheet" href="%sctf.css" type="text/css" /> <link rel="stylesheet" href="%sctf.css" type="text/css" />
</head> </head>
<body> <body style="max-width: inherit;">
<h1>Scoreboard</h1> <h1>Scoreboard</h1>
''' % config.base_url) ''' % config.base_url)
print('<table class="scoreboard">') print('<table class="scoreboard">')
@ -66,7 +67,10 @@ def main():
print('</tr>') print('</tr>')
print('''</table> print('''</table>
<img src="histogram.png" alt=""/> <p class="center">
<img src="histogram.png" alt="scores over time" />
</p>
</body> </body>
</html>''') </html>''')