moth/tanks/www/submit.cgi

60 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/usr/bin/python3
2009-10-06 11:50:21 -06:00
import cgi
import cgitb; cgitb.enable()
import os
import sys
2009-10-06 11:50:21 -06:00
2009-10-06 12:47:36 -06:00
import Config
2009-10-06 11:50:21 -06:00
try:
from urllib.parse import quote
except:
from urllib import quote
try:
from ctf import teams
except:
path = '/home/pflarr/repos/gctf/'
sys.path.append(path)
from ctf import teams
2009-10-09 08:47:19 -06:00
from ctf import config
2009-10-06 12:47:36 -06:00
teams.build_teams()
2009-10-06 11:50:21 -06:00
2009-10-09 08:47:19 -06:00
print(config.start_html('Tanks Submission',
links_title='Tanks',
links=[('docs.cgi', 'Docs'),
('results.cgi', 'Results'),
('submit.html', 'Submit'),
('errors.cgi', 'My Errors')]))
2009-10-06 11:50:21 -06:00
def done():
2009-10-09 08:47:19 -06:00
print(config.end_html())
2009-10-06 11:50:21 -06:00
sys.exit(0)
fields = cgi.FieldStorage()
team = fields.getfirst('team', '').strip()
passwd = fields.getfirst('passwd', '').strip()
code = fields.getfirst('code', '')
if not team:
2009-10-09 08:47:19 -06:00
print('<p>No team specified</p>'); done()
2009-10-06 11:50:21 -06:00
elif not passwd:
2009-10-09 08:47:19 -06:00
print('<p>No password given</p>'); done()
2009-10-06 11:50:21 -06:00
elif not code:
2009-10-09 08:47:19 -06:00
print('<p>No program given.</p>'); done()
2009-10-06 11:50:21 -06:00
if team not in teams.teams:
2009-10-09 08:47:19 -06:00
print('<p>Team is not registered.</p>'); done()
2009-10-06 11:50:21 -06:00
if passwd != teams.teams[team][0]:
2009-10-09 08:47:19 -06:00
print('<p>Invalid password.</p>'); done()
2009-10-06 11:50:21 -06:00
2009-12-16 08:00:10 -07:00
path = os.path.join(Config.DATA_PATH, 'ai/players', quote(team, safe='') )
2009-10-06 11:50:21 -06:00
file = open(path, 'w')
file.write(code)
file.close()
2009-10-09 08:47:19 -06:00
print("<p>Submission successful.</p>")
2009-10-06 11:50:21 -06:00
done()