def admin_keys_view(keyid):
        if request.method == 'GET':
            if keyid:
                saved_key = Keys.query.filter_by(id=keyid).first_or_404()
                key_class = get_key_class(saved_key.type)
                json_data = {
                    'id': saved_key.id,
                    'key': saved_key.flag,
                    'data': saved_key.data,
                    'chal': saved_key.chal,
                    'type': saved_key.type,
                    'type_name': key_class.name,
                    'templates': key_class.templates,
                }

                return jsonify(json_data)
        elif request.method == 'POST':
            chal = request.form.get('chal')
            flag = request.form.get('key')
            key_type = request.form.get('key_type')
            if not keyid:
                k = Keys(chal, flag, key_type)
                db.session.add(k)
            else:
                k = Keys.query.filter_by(id=keyid).first()
                k.flag = flag
                k.type = key_type
            db.session.commit()
            db.session.close()
            return '1'
示例#2
0
def admin_keys_view(keyid):
    print repr(keyid)
    if request.method == 'GET':
        if keyid:
            saved_key = Keys.query.filter_by(id=keyid).first_or_404()

            json_data = {
                'id': saved_key.id,
                'key': saved_key.flag,
                'data': saved_key.data,
                'chal': saved_key.chal,
                'type': saved_key.key_type,
                'type_name': get_key_class(saved_key.key_type).name
            }

            return jsonify(json_data)
    elif request.method == 'POST':
        chal = request.form.get('chal')
        flag = request.form.get('key')
        data = request.form.get('keydata')
        key_type = int(request.form.get('key_type'))
        if not keyid:
            k = Keys(chal, flag, key_type)
            k.data = data
            db.session.add(k)
        else:
            k = Keys.query.filter_by(id=keyid).first()
            k.chal = chal
            k.flag = flag
            k.data = data
            k.key_type = key_type
        db.session.commit()
        db.session.close()
        return '1'