This commit is contained in:
Nico Schottelius 2019-08-26 20:47:15 +02:00
parent 72c632bb93
commit c165b433c2
4 changed files with 69 additions and 48 deletions

22
archive/fun.py Normal file
View file

@ -0,0 +1,22 @@
from flask import Flask, request
from flask_restful import Resource, Api
from sqlalchemy import create_engine
from json import dumps
from flask.json import jsonify
db_connect = create_engine('sqlite:///chinook.db')
app = Flask(__name__)
api = Api(app)
@app.route("/")
def hello():
return """
<pre>
</pre>
"""
if __name__ == '__main__':
app.run(host="::",
port='5002')

37
challenge.py Normal file
View file

@ -0,0 +1,37 @@
def require_args(*args):
parser = reqparse.RequestParser()
for arg in args:
parser.add_argument(arg, required=True)
return parser.parse_args()
class Challenge(object):
""" A sample challenge -- inherit this and overwrite accordingly """
points = 0
provides = []
requires = []
description = None
dependencies_provided_by = {}
def __init__(self, wrapper):
self.db = wrapper
def game(self):
if request.method == 'GET':
return self.describe()
if request.method == 'POST':
return self.solve()
def describe(self):
return self.description
def save_points(self, user):
""" should be called when the challenge was solved successfully"""
key = "points/{}".format(user, type(self).__name__)
self.db.set_user_key(user, key, self.points)
def solve(self):
""" Needs to be implemented per challenge """
pass

9
challenges_ipv6.py Normal file
View file

@ -0,0 +1,9 @@
import ipaddress
import random
def get_random_ip(network):
net = ipaddress.IPv6Network(network)
addr_offset = random.randrange(2**64)
addr = net[0] + addr_offset
return addr

View file

@ -1,63 +1,16 @@
#!/usr/bin/env python3
USERLENGTH = 50
import ipaddress
import random
import sys
import etcd
import json
import datetime
import inspect
from ungleich_game_db import *
from flask import Flask, abort, request, Response
from flask_restful import reqparse
def get_random_ip(network):
net = ipaddress.IPv6Network(network)
addr_offset = random.randrange(2**64)
addr = net[0] + addr_offset
return addr
def require_args(*args):
parser = reqparse.RequestParser()
for arg in args:
parser.add_argument(arg, required=True)
return parser.parse_args()
class Challenge(object):
""" A sample challenge -- inherit this and overwrite accordingly """
points = 0
provides = []
requires = []
description = None
dependencies_provided_by = {}
def __init__(self, wrapper):
self.db = wrapper
def game(self):
if request.method == 'GET':
return self.describe()
if request.method == 'POST':
return self.solve()
def describe(self):
return self.description
def save_points(self, user):
""" should be called when the challenge was solved successfully"""
key = "points/{}".format(user, type(self).__name__)
self.db.set_user_key(user, key, self.points)
def solve(self):
""" Needs to be implemented per challenge """
pass
class RegisterNet(Challenge):
points = 10