Exemplo n.º 1
0
def index(request):
    if request.method == "POST":
        form = FlagForm(request.POST, request.FILES)
        if form.is_valid() and (form.cleaned_data['image']
                                or form.cleaned_data['tagline']):
            newflag = Flag()
            newflag.original = form.cleaned_data['image']
            newflag.name = form.cleaned_data['name']
            newflag.email = form.cleaned_data['email']
            newflag.location = form.cleaned_data['location']
            newflag.tagline = form.cleaned_data['tagline']

            newflag.save()

            return HttpResponseRedirect(reverse('flags.views.index'))
    else:
        form = FlagForm()

    flags = Flag.objects.order_by("-id")

    return render_to_response('flags/index.html', {
        'flags': flags,
        'form': form
    },
                              context_instance=RequestContext(request))
Exemplo n.º 2
0
async def post_flag(request, *, text):
    names = text
    for name in names.split():
        print(name)
        flag = Flag(nick=name, tradeId='')
        await flag.save()
    return 'redirect:/flag'
Exemplo n.º 3
0
 def __mkflag__(self, reward):
     ''' Creates a flag in the database '''
     box = Box.by_uuid(self.get_argument('box_uuid'))
     flag = Flag(
         name=unicode(self.get_argument('flag_name')),
         token=unicode(self.get_argument('token')),
         description=unicode(self.get_argument('description')),
         is_file=bool(self.get_argument('is_file', 'false') == 'true'),
         box_id=box.id,
         value=reward,
     )
     dbsession.add(flag)
     dbsession.flush()
Exemplo n.º 4
0
def create_flag(msg_id):
    """need to hook this up properly to the db"""
    user_id = g.user.id
    flag = Flag.query.filter_by(msg_id=msg_id, user_id=user_id).first()
    if flag:
        db.session.delete(flag)
        db.session.commit()

    else:
        new_flag = Flag(msg_id=msg_id, user_id=user_id)
        db.session.add(new_flag)
        db.session.commit()

    return redirect('/flag/new')
Exemplo n.º 5
0
def process_flag_json(flag):
    flag['raw'] = str(flag)
    flag['flagid'] = int(flag['path'].split('.')[0].split('/')[-1])
    flag['userid'] = fetch_userid(flag['username'])
    del flag['username']

    already_fetched = session.query(exists().where(Flag.flagid==flag['flagid'])).scalar()

    session.merge(Flag(**flag))
    session.commit()

    if not already_fetched:
        flag = session.query(Flag).filter(Flag.flagid==flag['flagid']).first()
        process_flag(flag)
        print(flag, session.query(User).count(), session.query(Flag).count())
Exemplo n.º 6
0
def create_flag(name,
                token,
                value,
                box,
                description="No description",
                is_file=False,
                is_regex=False,
                is_hash=False):
    print(INFO + "Create flag: " + bold + name + W)
    flag = Flag(
        name=unicode(name),
        token=unicode(token),
        is_file=is_file,
        is_regex=is_regex,
        is_hash=is_hash,
        description=unicode(description),
        value=value,
        box_id=box.id,
    )
    dbsession.add(flag)
    dbsession.flush()
Exemplo n.º 7
0
def create_flag(name, token, reward, box, description="No description",
                is_file=False):
    if is_file:
        if not os.path.exists(token):
            raise ValueError("Path to flag file does not exist: %s" % token)
        f = open(token, 'r')
        data = f.read()
        f.close()
        _token = Flag.digest(data)
        print(INFO + "Create Flag: " + bold + name + W + " (%s)" % _token)
    else:
        print(INFO + "Create Flag: " + bold + name + W)
        _token = unicode(token)
    flag = Flag(
        name=unicode(name),
        token=_token,
        is_file=is_file,
        description=unicode(description),
        value=reward,
        box_id=box.id,
    )
    dbsession.add(flag)
    dbsession.flush()