Ejemplo n.º 1
0
def signup():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        #user = User(form.username.data, form.email.data,
        #            form.password.data)
        t1 = Email()
        recp=form.email.data
        if t1(recp):
            prefix = request.url_root.split('/')[2].split('.')[0]
            if prefix == "localhost:5000":
                prefix = "asdf"
            keyid=get_val('corp.cf.zone',":%s" % prefix, second)[:-(len(prefix)+1)]
            add_state(keyid, 'corp-userdata', json.dumps({'name':form.name.data,
                                                          'email':form.email.data,
                                                          'country':form.country.data,
                                                          'address':form.address.data,
                                                          'company':form.company.data,
                                                          'dept':form.dept.data,
                                                          'pos':form.pos.data,
                                                          'serno':form.serno.data,
                                                          'password':form.password.data,
                                                          }))
            #flash("Thanks for registering, you will receive further instruction at %s." % recp)
            msg = Message("registration successful, welcome at Corporation.",
                          sender = "*****@*****.**",
                          recipients = [recp])
            msg.body = render_template('welcome.txt', name=form.name.data, host=request.url_root.split('/')[2])
            mail.send(msg)
            return redirect(url_for('login'))
    return render_template('register.html', form=form)
Ejemplo n.º 2
0
def myproducts():
  if request.cookies['login']:
      prefix = request.url_root.split('/')[2].split('.')[0]
      if prefix == "localhost:5000":
          prefix = "asdf"
      keyid=get_val('corp.cf.zone',":%s" % prefix, second)[:-(len(prefix)+1)]
      rec=json.loads(get_state(keyid, 'corp-userdata') or '')
      return render_template('myproducts.html', serno=rec['serno'])
  return render_template('base.html')
Ejemplo n.º 3
0
def login():
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        prefix = request.url_root.split('/')[2].split('.')[0]
        if prefix == "localhost:5000":
            prefix = "asdf"
        keyid=get_val('corp.cf.zone',":%s" % prefix, second)[:-(len(prefix)+1)]
        rec=json.loads(get_state(keyid, 'corp-userdata') or '')
        if(form.email.data==rec['email'] and form.password.data==rec['password']): # f**k yeah plaintext passwords ftw!
            add_state(keyid, 'corp-login', '')
            response = make_response(redirect('/'))
            response.set_cookie('login', True)
            return response
    return render_template('login.html', form=form)
Ejemplo n.º 4
0
def aimove(s, direct):
    backward = direct == 1 or direct == 2
    vert = direct == 0 or direct == 2

    r2args = (size - 1, -1, -1) if backward else (0, size, 1)
    movements = 0
    ecells = emptycells(s)
    folds, foldsum, failpoints = 0, 0, 0
    for c1 in range(size):
        point = size - 1 if backward else 0
        last = None
        jumps = 0
        for c2 in range(*r2args):
            x, y = (c1, c2) if vert else (c2, c1)

            v = get_val(s, x, y)
            if v == 0:
                jumps += 1
                continue

            set_val(s, x, y, 0)

            if v == last:  # fold!
                point -= -1 if backward else 1
                v += last
                folds += 1
                xval = foldweight(v)
                foldsum += xval
                failpoints = xval * failcoeff(jumps, ecells)
                last = None
            else:
                last = v

            jumps = 0

            if vert:
                set_val(s, x, point, v)
            else:
                set_val(s, point, y, v)

            if point != c2:
                movements += 1

            point += -1 if backward else 1
    return movements, folds, foldsum, failpoints
Ejemplo n.º 5
0
def doxer(msg, mailid=None, host=None):
    try:
        keyid=get_val('dox-mailid',":%s" % mailid, second)[:-(len(mailid)+1)]
    except TypeError:
        #print >>sys.stderr, 'nomailid'
        return # no such mailid
    pwd=get_state(keyid, 'prod.pdf.pass')
    #logging.info("pwd "+pwd)
    if not pwd:
        add_state(keyid, 'prod.pdf.err',"I got a mail, but i was not aware of the password at that time. try to resend it after telling me the password please.")
        return
    err = None
    for mpart in msg.walk():
        part=to_message(mpart)
        #if part.get_content_maintype() == 'multipart' or len(part.get_payload(decode=True)) < 268125:
        if part.get_content_maintype() == 'multipart':
            #print >>sys.stderr, 'skip', len(part.get_payload(decode=True) or ''), part.get_content_maintype()
            continue
        size = len(part.get_payload(decode=True))
        if (size < 200000 or size > 310000):
            continue
        hash=hashlib.sha256()
        def hupdate(data): # workaround for http://bugs.python.org/issue17481
            hash.update(data)
        ret=gpg('-d',
                '--passphrase', pwd,
                _ok_code=[0,2],
                _in=part.get_payload(decode=True),
                _out=hupdate)
        if ret.exit_code!=0:
            add_state(keyid, 'prod.pdf.err',"got a mail, but gpg had problems, try fixing the problem and resend the mail. gpg said this\n"+err)
            break
        #logging.info('ret '+str(ret))
        #logging.info('stderr '+ret.stderr)
        err=str(ret.stderr) # for flushing the process?
        #print >>sys.stderr, 'err', err
        if hash.hexdigest() == '658be96015645fe1d646fd167c1ac3bd372360530191d574ace5870c5aeb132f':
            add_state(keyid, 'prod.pdf.done','1')
            break
        else:
            add_state(keyid, 'prod.pdf.err',"got a mail, but it wasn't quite what i expected, so i dropped it.")
            break
    else:
        add_state(keyid, 'prod.pdf.err',"got a mail, but there was nothing found that looked like a reasonably sized pgp payload")