moth/www/tanks/submit.cgi

43 lines
1.0 KiB
Plaintext
Raw Normal View History

#!/usr/bin/python
import cgi
import cgitb; cgitb.enable()
import os
import sys
from urllib import quote
from ctf import teams, html, paths
basedir = os.path.join(paths.VAR, 'tanks')
links = '''
<h3>Tanks</h3>
<li><a href="docs.html">Docs</a></li>
<li><a href="results.cgi">Results</a></li>
<li><a href="submit.html">Submit</a></li>
<li><a href="errors.cgi">My Errors</a></li>
'''
fields = cgi.FieldStorage()
team = fields.getfirst('team', '').strip()
passwd = fields.getfirst('passwd', '').strip()
code = fields.getfirst('code', '')
if not teams.chkpasswd(team, passwd):
body = '<p>Authentication failed.</p>'
elif not code:
body = '<p>No program given.</p>'
else:
path = os.path.join(basedir, 'ai/players', quote(team, safe=''))
file = open(path, 'w')
2010-05-17 23:11:30 -06:00
file.write('Team: %s\n' % quote(team))
file.write('Color: #%s\n' % teams.color(team))
file.write('\n')
file.write(code)
file.close()
body = ("<p>Submission successful.</p>")
html.serve('Tanks Submission', body, links=links)