mirror of https://github.com/dirtbags/moth.git
Fix a few puzzler bugs, prettier css
This commit is contained in:
parent
124b327a8e
commit
9b17654d47
5
ctf.css
5
ctf.css
|
@ -19,3 +19,8 @@ a:hover {
|
||||||
color: #000;
|
color: #000;
|
||||||
background: #f00;
|
background: #f00;
|
||||||
}
|
}
|
||||||
|
input {
|
||||||
|
border: 2px solid #088;
|
||||||
|
color: #fff;
|
||||||
|
background: #000;
|
||||||
|
}
|
25
puzzler.cgi
25
puzzler.cgi
|
@ -8,6 +8,13 @@ import re
|
||||||
import sys
|
import sys
|
||||||
import pointscli
|
import pointscli
|
||||||
import teams
|
import teams
|
||||||
|
from urllib.parse import quote, unquote
|
||||||
|
|
||||||
|
##
|
||||||
|
## This allows you to edit the URL and work on puzzles that haven't been
|
||||||
|
## unlocked yet. For now I think that's an okay vulnerability. It's a
|
||||||
|
## hacking contest, after all.
|
||||||
|
##
|
||||||
|
|
||||||
cat_re = re.compile(r'^[a-z]+$')
|
cat_re = re.compile(r'^[a-z]+$')
|
||||||
points_re = re.compile(r'^[0-9]+$')
|
points_re = re.compile(r'^[0-9]+$')
|
||||||
|
@ -21,8 +28,7 @@ points_by_cat = {}
|
||||||
points_by_team = {}
|
points_by_team = {}
|
||||||
try:
|
try:
|
||||||
for line in open('puzzler.dat'):
|
for line in open('puzzler.dat'):
|
||||||
line = line.strip()
|
cat, team, pts = [unquote(v) for v in line.strip().split('\t')]
|
||||||
cat, team, pts = line.split('\t')
|
|
||||||
pts = int(pts)
|
pts = int(pts)
|
||||||
points_by_cat[cat] = max(points_by_cat.get(cat, 0), pts)
|
points_by_cat[cat] = max(points_by_cat.get(cat, 0), pts)
|
||||||
points_by_team.setdefault((team, cat), set()).add(pts)
|
points_by_team.setdefault((team, cat), set()).add(pts)
|
||||||
|
@ -96,10 +102,10 @@ def show_puzzles(cat, cat_dir):
|
||||||
puzzles = sorted([int(v) for v in os.listdir(cat_dir)])
|
puzzles = sorted([int(v) for v in os.listdir(cat_dir)])
|
||||||
if puzzles:
|
if puzzles:
|
||||||
print('<ul>')
|
print('<ul>')
|
||||||
opened = max(opened, puzzles[0])
|
|
||||||
for p in puzzles:
|
for p in puzzles:
|
||||||
if p <= opened:
|
print('<li><a href="puzzler.cgi?c=%s&p=%d">%d</a></li>' % (cat, p, p))
|
||||||
print('<li><a href="puzzler.cgi?c=%s&p=%d">%d</a></li>' % (cat, p, p))
|
if p > opened:
|
||||||
|
break
|
||||||
print('</ul>')
|
print('</ul>')
|
||||||
else:
|
else:
|
||||||
print('<p>None (someone is slacking)</p>')
|
print('<p>None (someone is slacking)</p>')
|
||||||
|
@ -132,11 +138,12 @@ def show_puzzle(cat, points, points_dir):
|
||||||
def win(cat, team, points):
|
def win(cat, team, points):
|
||||||
start_html('Winner!')
|
start_html('Winner!')
|
||||||
points = int(points)
|
points = int(points)
|
||||||
pointscli.submit(cat, team, points)
|
|
||||||
end_html()
|
|
||||||
f = open('puzzler.dat', 'a')
|
f = open('puzzler.dat', 'a')
|
||||||
fctnl.lockf(f, LOCK_EX)
|
fcntl.lockf(f, fcntl.LOCK_EX)
|
||||||
f.write('%s\t%s\t%d\n' % (cat, team, points))
|
f.write('%s\t%s\t%d\n' % (quote(cat), quote(team), points))
|
||||||
|
pointscli.submit(cat, team, points)
|
||||||
|
print('<p>%d points for %s.</p>' % (team, points))
|
||||||
|
end_html()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
cat_dir = safe_join('puzzles', cat)
|
cat_dir = safe_join('puzzles', cat)
|
||||||
|
|
15
teams.py
15
teams.py
|
@ -1,11 +1,11 @@
|
||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
import fcntl
|
import fcntl
|
||||||
|
from urllib.parse import quote, unquote
|
||||||
|
|
||||||
house = 'dirtbags'
|
house = 'dirtbags'
|
||||||
|
|
||||||
teams = None
|
teams = None
|
||||||
|
|
||||||
def build_teams():
|
def build_teams():
|
||||||
global teams
|
global teams
|
||||||
|
|
||||||
|
@ -13,22 +13,25 @@ def build_teams():
|
||||||
try:
|
try:
|
||||||
f = open('passwd')
|
f = open('passwd')
|
||||||
for line in f:
|
for line in f:
|
||||||
team, passwd = line.strip().split('\t')
|
line = line.strip()
|
||||||
|
team, passwd = [unquote(v) for v in line.strip().split('\t')]
|
||||||
teams[team] = passwd
|
teams[team] = passwd
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def chkpasswd(team, passwd):
|
def validate(team):
|
||||||
if teams is None:
|
if teams is None:
|
||||||
build_teams()
|
build_teams()
|
||||||
|
|
||||||
|
def chkpasswd(team, passwd):
|
||||||
|
validate(team)
|
||||||
if teams.get(team) == passwd:
|
if teams.get(team) == passwd:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def exists(team):
|
def exists(team):
|
||||||
if teams is None:
|
validate(team)
|
||||||
build_teams()
|
|
||||||
if team == house:
|
if team == house:
|
||||||
return True
|
return True
|
||||||
return team in teams
|
return team in teams
|
||||||
|
@ -37,4 +40,4 @@ def add(team, passwd):
|
||||||
f = open('passwd', 'a')
|
f = open('passwd', 'a')
|
||||||
fcntl.lockf(f, fcntl.LOCK_EX)
|
fcntl.lockf(f, fcntl.LOCK_EX)
|
||||||
f.seek(0, 2)
|
f.seek(0, 2)
|
||||||
f.write('%s\t%s\n' % (team, passwd))
|
f.write('%s\t%s\n' % (quote(team), quote(passwd)))
|
||||||
|
|
Loading…
Reference in New Issue