mirror of https://github.com/dirtbags/moth.git
Merge cfl:/var/projects/gctf
This commit is contained in:
commit
db646f244e
|
@ -40,6 +40,7 @@ class Gyopi(irc.Bot):
|
||||||
self._lvl = 0
|
self._lvl = 0
|
||||||
self._flag.set_flag( self.FLAG_DEFAULT )
|
self._flag.set_flag( self.FLAG_DEFAULT )
|
||||||
|
|
||||||
|
self._tokens = []
|
||||||
self._lastAttempt = {}
|
self._lastAttempt = {}
|
||||||
self._affiliations = {}
|
self._affiliations = {}
|
||||||
self._newPuzzle()
|
self._newPuzzle()
|
||||||
|
@ -62,7 +63,7 @@ class Gyopi(irc.Bot):
|
||||||
self.last_tb = '%s %s %s' % (t, v, infostr)
|
self.last_tb = '%s %s %s' % (t, v, infostr)
|
||||||
print(self.last_tb)
|
print(self.last_tb)
|
||||||
|
|
||||||
def cmd_join(self, sender, forum, addl):
|
def cmd_JOIN(self, sender, forum, addl):
|
||||||
"""On join, announce who has the flag."""
|
"""On join, announce who has the flag."""
|
||||||
if sender.name() in self.nicks:
|
if sender.name() in self.nicks:
|
||||||
self._tellFlag(forum)
|
self._tellFlag(forum)
|
||||||
|
@ -150,11 +151,11 @@ class Gyopi(irc.Bot):
|
||||||
self._tokens[user].remove(token)
|
self._tokens[user].remove(token)
|
||||||
|
|
||||||
|
|
||||||
def cmd_privmsg(self, sender, forum, addl):
|
def cmd_PRIVMSG(self, sender, forum, addl):
|
||||||
text = addl[0]
|
text = addl[0]
|
||||||
who = sender.name()
|
who = sender.name()
|
||||||
if text.startswith('!'):
|
if text.startswith('!'):
|
||||||
parts = text[1:].lower().split(' ', 1)
|
parts = text[1:].split(' ', 1)
|
||||||
cmd = parts[0]
|
cmd = parts[0]
|
||||||
if len(parts) > 1:
|
if len(parts) > 1:
|
||||||
args = parts[1]
|
args = parts[1]
|
||||||
|
@ -179,6 +180,7 @@ class Gyopi(irc.Bot):
|
||||||
elif cmd.startswith('h'):
|
elif cmd.startswith('h'):
|
||||||
# Help
|
# Help
|
||||||
forum.msg('Goal: Help me with my math homework, FROM ANOTHER DIMENSION!')
|
forum.msg('Goal: Help me with my math homework, FROM ANOTHER DIMENSION!')
|
||||||
|
forum.msg('Order of operations is always left to right.')
|
||||||
#forum.msg('Goal: The current winner gets to control the contest music.')
|
#forum.msg('Goal: The current winner gets to control the contest music.')
|
||||||
forum.msg('Commands: !help, !flag, !register [TEAM], !solve SOLUTION,!? EQUATION, !ops, !problem, !who')
|
forum.msg('Commands: !help, !flag, !register [TEAM], !solve SOLUTION,!? EQUATION, !ops, !problem, !who')
|
||||||
elif cmd.startswith('prob'):
|
elif cmd.startswith('prob'):
|
||||||
|
@ -208,11 +210,15 @@ class Gyopi(irc.Bot):
|
||||||
# self._giveToken(who, sender)
|
# self._giveToken(who, sender)
|
||||||
self._saveState()
|
self._saveState()
|
||||||
else:
|
else:
|
||||||
forum.msg('%s: %s != %s' % (who, attempt, answer))
|
|
||||||
forum.msg('%s: That is not correct.' % who)
|
forum.msg('%s: That is not correct.' % who)
|
||||||
|
|
||||||
# Test a simple one op command.
|
# Test a simple one op command.
|
||||||
elif cmd.startswith('?'):
|
elif cmd.startswith('?'):
|
||||||
|
if not args:
|
||||||
|
forum.msg('%s: Give me an easier problem, and I\'ll '
|
||||||
|
'give you the answer.' % who)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tokens = badmath.parse(''.join(args))
|
tokens = badmath.parse(''.join(args))
|
||||||
except (ValueError) as msg:
|
except (ValueError) as msg:
|
||||||
|
@ -253,7 +259,7 @@ if __name__ == '__main__':
|
||||||
help='Flag server password')
|
help='Flag server password')
|
||||||
p.add_option('-d', '--path', dest='path', default='/var/lib/badmath',
|
p.add_option('-d', '--path', dest='path', default='/var/lib/badmath',
|
||||||
help='Path to where we can store state info.')
|
help='Path to where we can store state info.')
|
||||||
p.add_option('-c', '--channel', dest='channel', default='+badmath',
|
p.add_option('-c', '--channel', dest='channel', default='#badmath',
|
||||||
help='Which channel to join')
|
help='Which channel to join')
|
||||||
|
|
||||||
opts, args = p.parse_args()
|
opts, args = p.parse_args()
|
||||||
|
|
Binary file not shown.
|
@ -10,5 +10,6 @@ dev=16,ino=87557238,mode=40755,uid=0,gid=0,nlink=2,rdev=0
|
||||||
dev=16,ino=87557239,mode=40755,uid=0,gid=0,nlink=2,rdev=0
|
dev=16,ino=87557239,mode=40755,uid=0,gid=0,nlink=2,rdev=0
|
||||||
dev=16,ino=87557240,mode=40755,uid=0,gid=0,nlink=2,rdev=0
|
dev=16,ino=87557240,mode=40755,uid=0,gid=0,nlink=2,rdev=0
|
||||||
dev=16,ino=87573208,mode=100755,uid=0,gid=0,nlink=1,rdev=0
|
dev=16,ino=87573208,mode=100755,uid=0,gid=0,nlink=1,rdev=0
|
||||||
|
dev=16,ino=87573213,mode=100755,uid=0,gid=0,nlink=1,rdev=0
|
||||||
|
dev=16,ino=87573285,mode=100755,uid=0,gid=0,nlink=1,rdev=0
|
||||||
dev=16,ino=87573433,mode=100755,uid=0,gid=0,nlink=1,rdev=0
|
dev=16,ino=87573433,mode=100755,uid=0,gid=0,nlink=1,rdev=0
|
||||||
dev=16,ino=87573456,mode=100755,uid=0,gid=0,nlink=1,rdev=0
|
|
||||||
|
|
|
@ -5,4 +5,4 @@
|
||||||
DATA_PATH=/var/lib/badmath
|
DATA_PATH=/var/lib/badmath
|
||||||
mkdir -p $DATA_PATH
|
mkdir -p $DATA_PATH
|
||||||
|
|
||||||
exec envuidgid ctf python3.0 usr/lib/ctf/badmath/Gyopi.py --data=$DATA_PATH
|
exec envuidgid ctf python3 /usr/lib/ctf/badmath/Gyopi.py --path=$DATA_PATH
|
||||||
|
|
14
ctf/teams.py
14
ctf/teams.py
|
@ -28,9 +28,7 @@ def build_teams():
|
||||||
f = open(passwdfn)
|
f = open(passwdfn)
|
||||||
for line in f:
|
for line in f:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
team, passwd = [unquote(v) for v in line.strip().split('\t')]
|
team, passwd, color = map(unquote, line.strip().split('\t'))
|
||||||
color = team_colors.pop(0)
|
|
||||||
team_colors.append(color)
|
|
||||||
teams[team] = (passwd, color)
|
teams[team] = (passwd, color)
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
|
@ -53,10 +51,15 @@ def exists(team):
|
||||||
return team in teams
|
return team in teams
|
||||||
|
|
||||||
def add(team, passwd):
|
def add(team, passwd):
|
||||||
|
build_teams()
|
||||||
|
color = team_colors[len(teams)%len(team_colors)]
|
||||||
|
|
||||||
|
assert team not in teams, "Team already exists."
|
||||||
|
|
||||||
f = open(passwdfn, 'a')
|
f = open(passwdfn, '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' % (quote(team), quote(passwd)))
|
f.write('%s\t%s\t%s\n' % (quote(team), quote(passwd), quote(color)))
|
||||||
|
|
||||||
def color(team):
|
def color(team):
|
||||||
t = teams.get(team)
|
t = teams.get(team)
|
||||||
|
@ -66,6 +69,3 @@ def color(team):
|
||||||
if not t:
|
if not t:
|
||||||
return '888888'
|
return '888888'
|
||||||
return t[1]
|
return t[1]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,8 @@ target:
|
||||||
$(INSTALL) AI/medium/* target/var/lib/tanks/ai/medium/
|
$(INSTALL) AI/medium/* target/var/lib/tanks/ai/medium/
|
||||||
$(INSTALL) AI/hard/* target/var/lib/tanks/ai/hard/
|
$(INSTALL) AI/hard/* target/var/lib/tanks/ai/hard/
|
||||||
|
|
||||||
$(INSTALL) -d target/var/lib/www/tanks/
|
$(INSTALL) -d target/usr/lib/www/tanks/
|
||||||
$(INSTALL) www/* target/var/lib/www/tanks/
|
$(INSTALL) www/* target/usr/lib/www/tanks/
|
||||||
$(FAKE) ln -s target/var/lib/tanks/ target/var/lib/www/data
|
|
||||||
|
|
||||||
$(INSTALL) -d target/usr/lib/python2.6/site-packages/tanks/
|
$(INSTALL) -d target/usr/lib/python2.6/site-packages/tanks/
|
||||||
$(INSTALL) lib/* target/usr/lib/python2.6/site-packages/tanks/
|
$(INSTALL) lib/* target/usr/lib/python2.6/site-packages/tanks/
|
||||||
|
|
|
@ -2,5 +2,7 @@
|
||||||
|
|
||||||
[ -f /var/lib/ctf/disabled/tanks ] && exit 0
|
[ -f /var/lib/ctf/disabled/tanks ] && exit 0
|
||||||
|
|
||||||
envuidgid ctf python2.6 run_tanks.py /var/lib/tanks/ easy 100 &
|
ln -s /var/lib/tanks /usr/lib/www/tanks/results
|
||||||
envuidgid ctf report_score.py
|
|
||||||
|
envuidgid ctf python2.6 run_tanks.py /var/lib/tanks/ easy 100 2>&1 &
|
||||||
|
envuidgid ctf report_score.py 2>&1
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
import sys
|
||||||
|
|
||||||
|
print >> sys.stderr, 'hello'
|
|
@ -7,7 +7,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from Tanks import Program, setup, conditions, actions, docs
|
from tanks import Program, setup, conditions, actions, docs
|
||||||
except:
|
except:
|
||||||
path = os.getcwd().split('/')
|
path = os.getcwd().split('/')
|
||||||
path.pop()
|
path.pop()
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python3
|
||||||
|
|
||||||
print """Content-Type: text/html\n\n"""
|
print("""Content-Type: text/html\n\n""")
|
||||||
print """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">\n\n"""
|
print("""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">\n\n""")
|
||||||
import cgi
|
import cgi
|
||||||
import cgitb; cgitb.enable()
|
import cgitb; cgitb.enable()
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import Config
|
import Config
|
||||||
|
@ -16,18 +17,17 @@ except:
|
||||||
try:
|
try:
|
||||||
from ctf import teams
|
from ctf import teams
|
||||||
except:
|
except:
|
||||||
import sys
|
|
||||||
path = '/home/pflarr/repos/gctf/'
|
path = '/home/pflarr/repos/gctf/'
|
||||||
sys.path.append(path)
|
sys.path.append(path)
|
||||||
from ctf import teams
|
from ctf import teams
|
||||||
teams.build_teams()
|
teams.build_teams()
|
||||||
|
|
||||||
head = open('head.html').read() % "Error Report"
|
head = open('head.html').read() % "Error Report"
|
||||||
print head
|
print(head)
|
||||||
print open('links.html').read()
|
print(open('links.html').read())
|
||||||
|
|
||||||
def done():
|
def done():
|
||||||
print '</body></html>'
|
print('</body></html>')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
fields = cgi.FieldStorage()
|
fields = cgi.FieldStorage()
|
||||||
|
@ -38,25 +38,25 @@ if team and passwd and \
|
||||||
path = os.path.join(Config.DATA_PATH, 'errors', quote(team))
|
path = os.path.join(Config.DATA_PATH, 'errors', quote(team))
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
errors = open(path).readlines()
|
errors = open(path).readlines()
|
||||||
print '<p>Your latest errors:'
|
print('<p>Your latest errors:')
|
||||||
print '<div class=errors>'
|
print('<div class=errors>')
|
||||||
if errors:
|
if errors:
|
||||||
print '<BR>\n'.join(errors)
|
print('<BR>\n'.join(errors))
|
||||||
else:
|
else:
|
||||||
print 'There were no errors.'
|
print('There were no errors.')
|
||||||
print '</div>'
|
print('</div>')
|
||||||
else:
|
else:
|
||||||
print '<p>No error file found.'
|
print('<p>No error file found.')
|
||||||
|
|
||||||
done()
|
done()
|
||||||
|
|
||||||
if team and team not in teams.teams:
|
if team and team not in teams.teams:
|
||||||
print '<p>Invalid team.'
|
print('<p>Invalid team.')
|
||||||
|
|
||||||
if team and team in teams.teams and passwd != teams.teams[team][0]:
|
if team and team in teams.teams and passwd != teams.teams[team][0]:
|
||||||
print '<p>Invalid password.'
|
print('<p>Invalid password.')
|
||||||
|
|
||||||
print '''
|
print('''
|
||||||
<form action="errors.cgi" method="get">
|
<form action="errors.cgi" method="get">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Error report request:</legend>
|
<legend>Error report request:</legend>
|
||||||
|
@ -64,6 +64,6 @@ print '''
|
||||||
Password: <input type="text" name="passwd"><BR>
|
Password: <input type="text" name="passwd"><BR>
|
||||||
<button type="get my errors">Submit</button>
|
<button type="get my errors">Submit</button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>'''
|
</form>''')
|
||||||
|
|
||||||
done()
|
done()
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
print("Content-Type: text/html\n\n")
|
||||||
|
print("""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">\n\n""")
|
||||||
import cgi
|
import cgi
|
||||||
import cgitb; cgitb.enable()
|
import cgitb; cgitb.enable()
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
import Config
|
import Config
|
||||||
|
|
||||||
|
@ -14,21 +17,18 @@ except:
|
||||||
try:
|
try:
|
||||||
from ctf import teams
|
from ctf import teams
|
||||||
except:
|
except:
|
||||||
import sys
|
|
||||||
path = '/home/pflarr/repos/gctf/'
|
path = '/home/pflarr/repos/gctf/'
|
||||||
sys.path.append(path)
|
sys.path.append(path)
|
||||||
from ctf import teams
|
from ctf import teams
|
||||||
teams.build_teams()
|
teams.build_teams()
|
||||||
|
|
||||||
print """Content-Type: text/html\n\n"""
|
|
||||||
print """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">\n\n"""
|
|
||||||
head = open('head.html').read() % "Submission Results"
|
head = open('head.html').read() % "Submission Results"
|
||||||
print head
|
print(head)
|
||||||
print "<H1>Results</H1>"
|
print("<H1>Results</H1>")
|
||||||
print open('links.html').read()
|
print(open('links.html').read())
|
||||||
|
|
||||||
def done():
|
def done():
|
||||||
print '</body></html>'
|
print('</body></html>')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
fields = cgi.FieldStorage()
|
fields = cgi.FieldStorage()
|
||||||
|
@ -36,21 +36,23 @@ team = fields.getfirst('team', '').strip()
|
||||||
passwd = fields.getfirst('passwd', '').strip()
|
passwd = fields.getfirst('passwd', '').strip()
|
||||||
code = fields.getfirst('code', '')
|
code = fields.getfirst('code', '')
|
||||||
if not team:
|
if not team:
|
||||||
print '<p>No team specified'; done()
|
print('<p>No team specified'); done()
|
||||||
elif not passwd:
|
elif not passwd:
|
||||||
print '<p>No password given'; done()
|
print('<p>No password given'); done()
|
||||||
elif not code:
|
elif not code:
|
||||||
print '<p>No program given.'; done()
|
print('<p>No program given.'); done()
|
||||||
|
|
||||||
if team not in teams.teams:
|
if team not in teams.teams:
|
||||||
print '<p>Team is not registered.'; done()
|
print('<p>Team is not registered.'); done()
|
||||||
|
|
||||||
if passwd != teams.teams[team][0]:
|
if passwd != teams.teams[team][0]:
|
||||||
print '<p>Invalid password.'; done()
|
print('<p>Invalid password.'); done()
|
||||||
|
|
||||||
path = os.path.join(Config.DATA_PATH, 'ai/players', encode(team) )
|
path = os.path.join(Config.DATA_PATH, 'ai/players', quote(team) )
|
||||||
file = open(path, 'w')
|
file = open(path, 'w')
|
||||||
file.write(code)
|
file.write(code)
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
print("<P>Submission Successful")
|
||||||
|
|
||||||
done()
|
done()
|
||||||
|
|
Loading…
Reference in New Issue