\o automatic static file processing o/

master
Fox Wilson 2015-11-29 12:10:38 -05:00
parent 189c01c639
commit df70119229
2 changed files with 34 additions and 1 deletions

View File

@ -8,6 +8,8 @@ proxied_ip_header = "X-Forwarded-For"
flag_rl = 10
teams_on_graph = 10
mail_from = "tjctf@sandbox1431.mailgun.org"
static_prefix = "http://127.0.0.1/tjctf-static/"
static_dir = "/home/fwilson/web/tjctf-static/"
# Don't touch these. Instead, copy secrets.example to secrets and edit that.
import yaml

33
ctftool
View File

@ -1,9 +1,12 @@
#!/usr/bin/python3
from database import *
from datetime import datetime, timedelta
import config
import getpass
import hashlib
import os
import os.path
import shutil
import sys
import yaml
import random
@ -64,11 +67,39 @@ elif operation == "scan":
dirs = [j for j in [os.path.join(path, i) for i in os.listdir(path)] if os.path.isdir(j)]
print(dirs)
n = 0
for d in dirs:
staticpaths = {}
if os.path.exists(os.path.join(d, "static.yml")):
with open(os.path.join(d, "static.yml")) as f:
statics = yaml.load(f)
for static in statics:
h = hashlib.sha256()
with open(os.path.join(d, static), "rb") as staticfile:
while True:
buf = staticfile.read(4096)
h.update(buf)
if not buf:
break
if "." in static:
name, ext = static.split(".", maxsplit=1)
fn = "{}_{}.{}".format(name, h.hexdigest(), ext)
else:
fn = "{}_{}".format(static, h.hexdigest())
staticpaths[static] = fn
shutil.copy(os.path.join(d, static), os.path.join(config.static_dir, fn))
print(fn)
if os.path.exists(os.path.join(d, "problem.yml")):
with open(os.path.join(d, "problem.yml")) as f:
n += 1
Challenge.create(**yaml.load(f))
data = yaml.load(f)
for i in staticpaths:
print("looking for |{}|".format(i))
data["description"] = data["description"].replace("|{}|".format(i), "{}{}".format(config.static_prefix, staticpaths[i]))
Challenge.create(**data)
print(n, "challenges loaded")
# vim: syntax=python:ft=python