From 93c9306ea5bd3ea4c29c2fe7ba4031f4d90286cd Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Fri, 9 Oct 2009 08:47:19 -0600 Subject: [PATCH] Tanks now using HTML template --- Makefile | 4 ++ ctf.css | 30 +++++++++++- ctf/config.py | 14 ++++-- tanks/lib/Program.py | 2 +- tanks/lib/docs.py | 5 +- tanks/www/ctf.css | 104 ------------------------------------------ tanks/www/docs.cgi | 16 ++++--- tanks/www/errors.cgi | 15 +++--- tanks/www/grunge.png | Bin 5893 -> 0 bytes tanks/www/head.html | 5 -- tanks/www/links.html | 4 -- tanks/www/results.cgi | 16 +++---- tanks/www/submit.cgi | 27 +++++------ tanks/www/submit.html | 41 ++++++++++++----- 14 files changed, 114 insertions(+), 169 deletions(-) delete mode 100644 tanks/www/ctf.css delete mode 100644 tanks/www/grunge.png delete mode 100644 tanks/www/head.html delete mode 100644 tanks/www/links.html diff --git a/Makefile b/Makefile index d644fd8..e6dd21d 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,10 @@ target: $(PYC) $(INSTALL) -d $(PYCDIR)/ctf $(INSTALL) $(PYC) $(PYCDIR)/ctf + $(INSTALL) -d $(DESTDIR)/usr/lib/python2.6/site-packages/ctf + $(INSTALL) ctf/__init__.py $(DESTDIR)/usr/lib/python2.6/site-packages/ctf + $(INSTALL) ctf/config.py $(DESTDIR)/usr/lib/python2.6/site-packages/ctf + $(INSTALL) -d $(DESTDIR)/usr/sbin $(INSTALL) ctfd.py $(DESTDIR)/usr/sbin $(INSTALL) new-contest $(DESTDIR)/usr/sbin diff --git a/ctf.css b/ctf.css index 433b9c6..0d6ed28 100644 --- a/ctf.css +++ b/ctf.css @@ -7,7 +7,7 @@ html { body { font-family: sans-serif; color: #fff; - margin: 50px 0 0 100px; + margin: 50px 0 0 110px; padding: 10px; max-width: 700px; } @@ -33,7 +33,7 @@ h1:first-child:before { /*** left side bar ***/ #navigation { - position: fixed; + position: absolute; background: #222; opacity: 0.9; top: 80px; @@ -41,6 +41,11 @@ h1:first-child:before { padding: 0; } +#navigation h3 { + font-size: 100%; + border-bottom: 2px solid #444; +} + #navigation ul { list-style: none; padding: 0; @@ -113,6 +118,27 @@ p { color: #f4f4f4; } +hr { + border: 1px solid #444; +} + +dt { + white-space: pre; + background-color: #333; + padding: 5px; + border: 2px solid green; + border-bottom: none; + font-weight: bold; +} + +dd { + border: 2px solid green; + margin: 0px; + padding: 5px; + background-color: #282828; +} + + /**** special cases ****/ .wide { diff --git a/ctf/config.py b/ctf/config.py index 4bdfe25..e39eacc 100755 --- a/ctf/config.py +++ b/ctf/config.py @@ -77,7 +77,7 @@ def datafile(filename): def url(path): return base_url + path -def start_html(title, hdr='', cls=''): +def start_html(title, hdr='', cls='', links=[], links_title=None): ret = [] if os.environ.get('GATEWAY_INTERFACE'): ret.append('Content-type: text/html') @@ -98,16 +98,24 @@ def start_html(title, hdr='', cls=''): - ''' % {'title': title, 'css': css, 'hdr': hdr, 'base': base_url, 'class': cls}) + if links: + if links_title: + ret.append('

%s

' % links_title) + else: + ret.append('
') + for url, name in links: + ret.append('
  • %s
  • ' % (url, name)) + ret.append(' ') return '\n'.join(ret) def end_html(): diff --git a/tanks/lib/Program.py b/tanks/lib/Program.py index ad30b1d..2063d1f 100644 --- a/tanks/lib/Program.py +++ b/tanks/lib/Program.py @@ -7,7 +7,7 @@ skills at designing those wits to survive.

    Programming Your Tank

    Your tanks are programmed using the Super Useful Command and Kontrol language, -the very best in laser tank AI languages. It includes amazing feature such +the very best in laser tank AI languages. It includes amazing features such as comments (Started by a #, ended at EOL), logic, versatility, and semi-colons (all lines must end in one). As with all new military systems it utilizes only integers; we must never rest in our diff --git a/tanks/lib/docs.py b/tanks/lib/docs.py index 1724d52..0318250 100644 --- a/tanks/lib/docs.py +++ b/tanks/lib/docs.py @@ -4,9 +4,8 @@ def mkDocTable(objects): objects.sort(lambda o1, o2: cmp(o1.__doc__, o2.__doc__)) for object in objects: - print '' if object.__doc__ is None: - print '
    %s
    Bad object' % \ + print '
    %s
    Bad object
    ' % \ xml.sax.saxutils.escape(str(object)) continue text = object.__doc__ @@ -23,5 +22,5 @@ def mkDocTable(objects): body = '\n'.join(body) print '
    %s
    %s
    ' % (head, body) #print '
    %sIntentionally blank
    %s' % (head, body) - print '
    ' + diff --git a/tanks/www/ctf.css b/tanks/www/ctf.css deleted file mode 100644 index cf21d76..0000000 --- a/tanks/www/ctf.css +++ /dev/null @@ -1,104 +0,0 @@ -/**** document ****/ - -html { - background: #222 url(grunge.png) repeat-x; -} - -body { - font-family: sans-serif; - color: #eee; - margin: 50px 0 0 100px; - padding: 10px; - max-width: 700px; -} - -/**** heading ****/ - -h1:first-child { - text-transform: lowercase; - font-size: 1.6em; -/* background-color: #222; */ -/* opacity: 0.9; */ - padding: 3px; - color: #2a2; - margin: 0 0 1em 70px; -} - -h1:first-child:before { - color: #fff; - letter-spacing: -0.1em; - content: "Capture The Flag: "; -} - -/**** body ****/ - -a img { - border: 0px; -} - -a { - text-decoration: none; - color: #2a2; - font-weight: bold; -} - -a:hover { - color: #fff; - background: #2a2; - font-weight: bold; -} - - -h1, h2, h3 { - color: #999; - letter-spacing: -0.05em; -} - -code, pre, .readme, div.errors { - color: #fff; - background-color: #555; - margin: 1em; -} - -th, td { - vertical-align: top; -} - -.scoreboard td { - height: 400px; -} - -p { - line-height: 1.4em; - margin-bottom: 20px; - color: #f4f4f4; -} - -dt { - white-space: pre; -} - -dt div.tab { - background-color: #333; - display: inline-block; - padding: 5px; - border: 3px solid green; - border-bottom: none; - font-weight: bold; -} - -dd { - border: 3px solid green; - margin: 0px; - padding: 5px; - background-color: #282828; -} - -fieldset * { - margin: 3px; -} - -table.results td, th{ - padding : 3px; - font-weight : bold; -} diff --git a/tanks/www/docs.cgi b/tanks/www/docs.cgi index 26306e3..6a6b514 100755 --- a/tanks/www/docs.cgi +++ b/tanks/www/docs.cgi @@ -1,10 +1,9 @@ #!/usr/bin/python -print """Content-Type: text/html\n\n""" -print """\n\n""" import cgitb; cgitb.enable() import os import sys +from ctf import config try: from tanks import Program, setup, conditions, actions, docs @@ -15,10 +14,13 @@ except: sys.path.append(os.path.join('/', *path)) import Program, setup, conditions, actions, docs -print open('head.html').read() % "Documentation" -print '' -print '

    Pflanzarr Documentation

    ' -print open('links.html').read() +print(config.start_html('Tanks Documentation', + links_title='Tanks', + links=[('docs.cgi', 'Docs'), + ('results.cgi', 'Results'), + ('submit.html', 'Submit'), + ('errors.cgi', 'My Errors')])) + print Program.__doc__ print '

    Setup Actions:

    ' @@ -34,4 +36,4 @@ print '

    Actions:

    ' print 'These actions are not for cowards. Remember, if actions contradict, your tank will simply do the last thing it was told in a turn. If ordered to hop on a plane to hell it will gladly do so. If order to make tea shortly afterwards, it will serve it politely and with cookies instead.

    ' docs.mkDocTable(actions.actions.values()) -print '' +print(config.end_html()) diff --git a/tanks/www/errors.cgi b/tanks/www/errors.cgi index 821082a..5f6adf5 100755 --- a/tanks/www/errors.cgi +++ b/tanks/www/errors.cgi @@ -1,7 +1,5 @@ #!/usr/bin/python3 -print("""Content-Type: text/html\n\n""") -print("""\n\n""") import cgi import cgitb; cgitb.enable() import sys @@ -20,15 +18,18 @@ except: path = '/home/pflarr/repos/gctf/' sys.path.append(path) from ctf import teams +from ctf import config teams.build_teams() -head = open('head.html').read() % "Error Report" -print(head) -print('

    Your Errors

    ') -print(open('links.html').read()) +print(config.start_html('Tanks Errors', + links_title='Tanks', + links=[('docs.cgi', 'Docs'), + ('results.cgi', 'Results'), + ('submit.html', 'Submit'), + ('errors.cgi', 'My Errors')])) def done(): - print('') + print(config.end_html()) sys.exit(0) fields = cgi.FieldStorage() diff --git a/tanks/www/grunge.png b/tanks/www/grunge.png deleted file mode 100644 index 2b98730b0354a8305ea9eb33e64d65ab7de8a393..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5893 zcmV+g7y9UlP)bBnN00006P)t-s00RL3 z|Nr87b z9s6*82w2C3WPFj;0$(nHK;p*)!g+!NehL}mK*m^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L$NE0880LsU<)x9^J6r8AWJEeS>XF>u#E_Q5X z6*R}z!{h+sQ*0tgYBETg+yTIM#W!nZ01QYviW!*!z#Roh>aUs72MYxxJnMtRy3f__ zXPp%eh|8-Iu$BNuCWh{>3?^3hvouYa7#E_GrvsFNdQo}C^drE!O4Rt-AH16Z1O+vx zz$i|pl%mw(6l7RIzfi!XOsT^MK01+;kB8mc74 z0SW~j)z}Ch#GTv1#Pzrq8^tv{R*ZpHC}1}O z*hawe1c@KSPd7@y8L<>RoMyc1g#j)tW)+-ij{-tBQ&_v@ciT}vNR$uaj*t-r8wK%^ zevo{IgamZ-(I6=fkZuNXM@_}eMALl?6zmQwSXehh{Sm-dK*3IF0CD4cHqD5&qq$N6 z&Sn6QM*)q30oxfsT)%v`G2Cty2e?Gqoe{uRW2BoYP(jvCngzA({JpvIDAt zs9>Rhvl&2RS1Oo%_70?(TES^1<%40o&uFm}dGOhj0h2_%USJ+fw7DVEOfU*q*PJ>j zei)I0L$|XDscB9L_*5mKfysyey#`$`1)!=VffODnL?J1^=Fv5-?e}Rv#WcQCbB_$pFLrC@vLX z*2HRkxM0A=VZdM*uvQKQLt89;*rO&c7_glNB%#gylKJ3VRzZt@oS6xfCrCnZQkJ3tMFd1RpFhplDe2J0%4qo;0y>r%_VCj;bVYmsP$6%c(L&x(+!JwaN!86IXy$9<17}%EVPI zt`w{)NoC?n!3wYftS0XNkNd&O2df~dYVl7ypk8(p>y?QwsvxNVuR37aeb8W)f)!u| zSVeJV;>yHVx)wiHb_Gj69wIxgb00000NkvXXu0mjf^hJvx diff --git a/tanks/www/head.html b/tanks/www/head.html deleted file mode 100644 index f2b66ea..0000000 --- a/tanks/www/head.html +++ /dev/null @@ -1,5 +0,0 @@ - - - - %s - diff --git a/tanks/www/links.html b/tanks/www/links.html deleted file mode 100644 index 1615bf7..0000000 --- a/tanks/www/links.html +++ /dev/null @@ -1,4 +0,0 @@ -Documentation | -Results | -Submit | -My Errors diff --git a/tanks/www/results.cgi b/tanks/www/results.cgi index 3055cf7..0edbf7c 100755 --- a/tanks/www/results.cgi +++ b/tanks/www/results.cgi @@ -2,16 +2,16 @@ import cgitb; cgitb.enable() import os +from ctf import config import Config -print """Content-Type: text/html\n\n""" -print """\n\n""" -head = open('head.html').read() % "Pflanzarr Results" -print head -print "

    Results

    " -print open('links.html').read() - +print(config.start_html('Tanks Results', + links_title='Tanks', + links=[('docs.cgi', 'Docs'), + ('results.cgi', 'Results'), + ('submit.html', 'Submit'), + ('errors.cgi', 'My Errors')])) try: winner = open(os.path.join(Config.DATA_PATH, 'winner')).read() except: @@ -52,4 +52,4 @@ for num in gameNums: print 'v' % num, print 'r' % num -print '' +print(config.end_html()) diff --git a/tanks/www/submit.cgi b/tanks/www/submit.cgi index 5dad944..ded20f7 100755 --- a/tanks/www/submit.cgi +++ b/tanks/www/submit.cgi @@ -1,7 +1,5 @@ #!/usr/bin/python3 -print("Content-Type: text/html\n\n") -print("""\n\n""") import cgi import cgitb; cgitb.enable() import os @@ -20,15 +18,18 @@ except: path = '/home/pflarr/repos/gctf/' sys.path.append(path) from ctf import teams +from ctf import config teams.build_teams() -head = open('head.html').read() % "Submission Results" -print(head) -print("

    Results

    ") -print(open('links.html').read()) +print(config.start_html('Tanks Submission', + links_title='Tanks', + links=[('docs.cgi', 'Docs'), + ('results.cgi', 'Results'), + ('submit.html', 'Submit'), + ('errors.cgi', 'My Errors')])) def done(): - print('') + print(config.end_html()) sys.exit(0) fields = cgi.FieldStorage() @@ -36,23 +37,23 @@ team = fields.getfirst('team', '').strip() passwd = fields.getfirst('passwd', '').strip() code = fields.getfirst('code', '') if not team: - print('

    No team specified'); done() + print('

    No team specified

    '); done() elif not passwd: - print('

    No password given'); done() + print('

    No password given

    '); done() elif not code: - print('

    No program given.'); done() + print('

    No program given.

    '); done() if team not in teams.teams: - print('

    Team is not registered.'); done() + print('

    Team is not registered.

    '); done() if passwd != teams.teams[team][0]: - print('

    Invalid password.'); done() + print('

    Invalid password.

    '); done() path = os.path.join(Config.DATA_PATH, 'ai/players', quote(team) ) file = open(path, 'w') file.write(code) file.close() -print("

    Submission Successful") +print("

    Submission successful.

    ") done() diff --git a/tanks/www/submit.html b/tanks/www/submit.html index f538d5d..d5528a1 100644 --- a/tanks/www/submit.html +++ b/tanks/www/submit.html @@ -1,16 +1,33 @@ - - - ' - Program Submission" - + + + + + Tanks Submission + + + + +

    Tanks Submission

    + + - -

    Program Submission

    -

    - Documentation | - Results | - Submit | - My Errors

    Your program: