Merge cfl:/var/projects/gctf

This commit is contained in:
Neale Pickett 2009-10-07 12:54:03 -06:00
commit db646f244e
11 changed files with 64 additions and 51 deletions

View File

@ -40,6 +40,7 @@ class Gyopi(irc.Bot):
self._lvl = 0
self._flag.set_flag( self.FLAG_DEFAULT )
self._tokens = []
self._lastAttempt = {}
self._affiliations = {}
self._newPuzzle()
@ -62,7 +63,7 @@ class Gyopi(irc.Bot):
self.last_tb = '%s %s %s' % (t, v, infostr)
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."""
if sender.name() in self.nicks:
self._tellFlag(forum)
@ -150,11 +151,11 @@ class Gyopi(irc.Bot):
self._tokens[user].remove(token)
def cmd_privmsg(self, sender, forum, addl):
def cmd_PRIVMSG(self, sender, forum, addl):
text = addl[0]
who = sender.name()
if text.startswith('!'):
parts = text[1:].lower().split(' ', 1)
parts = text[1:].split(' ', 1)
cmd = parts[0]
if len(parts) > 1:
args = parts[1]
@ -179,6 +180,7 @@ class Gyopi(irc.Bot):
elif cmd.startswith('h'):
# Help
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('Commands: !help, !flag, !register [TEAM], !solve SOLUTION,!? EQUATION, !ops, !problem, !who')
elif cmd.startswith('prob'):
@ -208,11 +210,15 @@ class Gyopi(irc.Bot):
# self._giveToken(who, sender)
self._saveState()
else:
forum.msg('%s: %s != %s' % (who, attempt, answer))
forum.msg('%s: That is not correct.' % who)
# Test a simple one op command.
elif cmd.startswith('?'):
if not args:
forum.msg('%s: Give me an easier problem, and I\'ll '
'give you the answer.' % who)
return
try:
tokens = badmath.parse(''.join(args))
except (ValueError) as msg:
@ -253,7 +259,7 @@ if __name__ == '__main__':
help='Flag server password')
p.add_option('-d', '--path', dest='path', default='/var/lib/badmath',
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')
opts, args = p.parse_args()

Binary file not shown.

View File

@ -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=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=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=87573456,mode=100755,uid=0,gid=0,nlink=1,rdev=0

View File

@ -5,4 +5,4 @@
DATA_PATH=/var/lib/badmath
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

View File

@ -28,9 +28,7 @@ def build_teams():
f = open(passwdfn)
for line in f:
line = line.strip()
team, passwd = [unquote(v) for v in line.strip().split('\t')]
color = team_colors.pop(0)
team_colors.append(color)
team, passwd, color = map(unquote, line.strip().split('\t'))
teams[team] = (passwd, color)
except IOError:
pass
@ -53,10 +51,15 @@ def exists(team):
return team in teams
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')
fcntl.lockf(f, fcntl.LOCK_EX)
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):
t = teams.get(team)
@ -66,6 +69,3 @@ def color(team):
if not t:
return '888888'
return t[1]

View File

@ -17,9 +17,8 @@ target:
$(INSTALL) AI/medium/* target/var/lib/tanks/ai/medium/
$(INSTALL) AI/hard/* target/var/lib/tanks/ai/hard/
$(INSTALL) -d target/var/lib/www/tanks/
$(INSTALL) www/* target/var/lib/www/tanks/
$(FAKE) ln -s target/var/lib/tanks/ target/var/lib/www/data
$(INSTALL) -d target/usr/lib/www/tanks/
$(INSTALL) www/* target/usr/lib/www/tanks/
$(INSTALL) -d target/usr/lib/python2.6/site-packages/tanks/
$(INSTALL) lib/* target/usr/lib/python2.6/site-packages/tanks/

View File

@ -2,5 +2,7 @@
[ -f /var/lib/ctf/disabled/tanks ] && exit 0
envuidgid ctf python2.6 run_tanks.py /var/lib/tanks/ easy 100 &
envuidgid ctf report_score.py
ln -s /var/lib/tanks /usr/lib/www/tanks/results
envuidgid ctf python2.6 run_tanks.py /var/lib/tanks/ easy 100 2>&1 &
envuidgid ctf report_score.py 2>&1

3
tanks/t.py Normal file
View File

@ -0,0 +1,3 @@
import sys
print >> sys.stderr, 'hello'

View File

@ -7,7 +7,7 @@ import os
import sys
try:
from Tanks import Program, setup, conditions, actions, docs
from tanks import Program, setup, conditions, actions, docs
except:
path = os.getcwd().split('/')
path.pop()

View File

@ -1,9 +1,10 @@
#!/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"""
print("""Content-Type: text/html\n\n""")
print("""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">\n\n""")
import cgi
import cgitb; cgitb.enable()
import sys
import os
import Config
@ -16,18 +17,17 @@ except:
try:
from ctf import teams
except:
import sys
path = '/home/pflarr/repos/gctf/'
sys.path.append(path)
from ctf import teams
teams.build_teams()
head = open('head.html').read() % "Error Report"
print head
print open('links.html').read()
print(head)
print(open('links.html').read())
def done():
print '</body></html>'
print('</body></html>')
sys.exit(0)
fields = cgi.FieldStorage()
@ -38,25 +38,25 @@ if team and passwd and \
path = os.path.join(Config.DATA_PATH, 'errors', quote(team))
if os.path.isfile(path):
errors = open(path).readlines()
print '<p>Your latest errors:'
print '<div class=errors>'
print('<p>Your latest errors:')
print('<div class=errors>')
if errors:
print '<BR>\n'.join(errors)
print('<BR>\n'.join(errors))
else:
print 'There were no errors.'
print '</div>'
print('There were no errors.')
print('</div>')
else:
print '<p>No error file found.'
print('<p>No error file found.')
done()
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]:
print '<p>Invalid password.'
print('<p>Invalid password.')
print '''
print('''
<form action="errors.cgi" method="get">
<fieldset>
<legend>Error report request:</legend>
@ -64,6 +64,6 @@ print '''
Password: <input type="text" name="passwd"><BR>
<button type="get my errors">Submit</button>
</fieldset>
</form>'''
</form>''')
done()

View File

@ -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 cgitb; cgitb.enable()
import os
import sys
import Config
@ -14,21 +17,18 @@ except:
try:
from ctf import teams
except:
import sys
path = '/home/pflarr/repos/gctf/'
sys.path.append(path)
from ctf import 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"
print head
print "<H1>Results</H1>"
print open('links.html').read()
print(head)
print("<H1>Results</H1>")
print(open('links.html').read())
def done():
print '</body></html>'
print('</body></html>')
sys.exit(0)
fields = cgi.FieldStorage()
@ -36,21 +36,23 @@ team = fields.getfirst('team', '').strip()
passwd = fields.getfirst('passwd', '').strip()
code = fields.getfirst('code', '')
if not team:
print '<p>No team specified'; done()
print('<p>No team specified'); done()
elif not passwd:
print '<p>No password given'; done()
print('<p>No password given'); done()
elif not code:
print '<p>No program given.'; done()
print('<p>No program given.'); done()
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]:
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.write(code)
file.close()
print("<P>Submission Successful")
done()