Exemplo n.º 1
0
def new():
    Session.KillOld()
    if (not Session.CheckCount()):
        return render_template('error.html',
                               title='Error',
                               quizdb=QuizDB.Instance(),
                               errcode=ERROR_TOOMANY_SESSIONS_OPENNED)

    s = Session(str(request.remote_addr))
    return redirect(url_for('quiz', sid=s.sid))
Exemplo n.º 2
0
def result(sid):
    s = Session.Get(sid)
    if (s == None):
        return render_template('error.html',
                               title='404',
                               quizdb=QuizDB.Instance(),
                               errcode=ERROR_SESSION_ID_NOT_FOUND,
                               errortext=sid)
    if (s.quiz.state != Quiz.DONE):
        s.Kill()
        return render_template('error.html',
                               title='Error',
                               quizsession=s,
                               quizdb=QuizDB.Instance(),
                               errcode=ERROR_SESSION_ERROR)
    else:
        s.Save()
        s.Kill()
        return render_template('result.html',
                               title='Result',
                               quizsession=s,
                               quizdb=QuizDB.Instance())
Exemplo n.º 3
0
def quiz(sid):
    s = Session.Get(sid)
    if (s == None):
        return render_template('error.html',
                               title='404',
                               quizdb=QuizDB.Instance(),
                               errcode=ERROR_SESSION_ID_NOT_FOUND,
                               errortext=sid)
    f = forms.file_list_form_builder(s, QuizCFG.ISDEBUG)

    if f.validate_on_submit():
        rids = forms.rspids_from_form(f)
        if (len(rids) != 0):
            rc = s.quiz.Answer(rids)
            if (rc != Quiz.OK):
                return redirect(url_for('result', sid=s.sid))
            return redirect(url_for('quiz', sid=s.sid))

    return render_template('question.html',
                           form=f,
                           title='Quiz',
                           quizsession=s,
                           quizdb=QuizDB.Instance())
Exemplo n.º 4
0
 def __init__(self, clientip):
     Session.lock.acquire()
     while True:
         self.sid = "%08X" % random.randint(
             0, 0xFFFFFFFF)  #uuid.uuid4().hex #str(Session.counter)
         if (not (self.sid in Session.list)):
             break
     Session.counter += 1
     Session.list[self.sid] = self
     Session.lock.release()
     self.quiz = QuizDB.Instance().MakeNewQuizQuestionSet(
         QuizCFG.QUESTIONSCOUNT)
     self.ip = clientip
     self.timestamp = datetime.datetime.now()
     print("Session %s opened" % self.sid)
Exemplo n.º 5
0
    def ReportText():
        db = QuizDB.Instance()
        Session.lock.acquire()
        txt = ""
        txt += "uptime = %s\r\n" % str(datetime.datetime.now() - db.timestamp)
        txt += "session counter = %i\r\n" % Session.counter
        txt += "db key = '%s'\r\n" % db.key
        txt += "db version  = '%s'\r\n" % db.version
        txt += "db date  = '%s'\r\n" % db.date
        txt += "db timestamp  = '%s'\r\n" % str(db.timestamp)
        if (len(Session.list) == 0):
            txt += "No sessions opened\r\n"
        else:
            txt += "Sessions:\r\n"
            for (k, v) in Session.list.items():
                age = datetime.datetime.now() - v.timestamp
                txt += " '%s' at %i, %s, %s, %s\r\n" % (
                    k, v.quiz.pos, str(v.quiz.state), str(age), v.ip)
        Session.lock.release()

        return txt
Exemplo n.º 6
0
def admin():
    return render_template('admin.html',
                           title='Admin',
                           quizdb=QuizDB.Instance(),
                           report=Session.ToHTML(None, Session.ReportText()),
                           QuizCFG=QuizCFG)
Exemplo n.º 7
0
def home():
    return render_template('home.html', quizdb=QuizDB.Instance())
Exemplo n.º 8
0
from flask import Flask, render_template, url_for, flash, redirect, request
from session import Session
from quiz import Quiz, QuizCFG, QuizDB
import forms

QuizCFG.ISDEBUG = False

app = Flask(__name__)

app.config['SECRET_KEY'] = 'DEBUG'

ERROR_TOOMANY_SESSIONS_OPENNED = 100
ERROR_SESSION_ID_NOT_FOUND = 101
ERROR_SESSION_ERROR = 102

QuizDB.Instance()


@app.route("/")
@app.route("/h")
def home():
    return render_template('home.html', quizdb=QuizDB.Instance())


#@app.route("/a")
@app.route("/myextremelysecureadminpage")
def admin():
    return render_template('admin.html',
                           title='Admin',
                           quizdb=QuizDB.Instance(),
                           report=Session.ToHTML(None, Session.ReportText()),
Exemplo n.º 9
0
 def Save(self):
     self.quiz.Save(QuizDB.Instance().dir + ("/%s.txt" % self.sid),
                    "Client ip: %s" % self.ip)