Ejemplo n.º 1
0
def handle_login(env):
    tmpl = jinjaenv.get_template('loginform.html')

    if str(env['REQUEST_METHOD']) == 'POST':
        data = read_post_data(env)

        if 'user' not in data or 'pass' not in data:
            return template_render(tmpl, env,
            {   'session' : env['beaker.session'], 'loginfail' : True}  )

        user = urllib.unquote_plus(data['user'].value)
        pass_ = urllib.unquote_plus(data['pass'].value)

#        pass = hashlib.sha256(pass).hexdigest()
        u = lookup_user(user)
        if u is None:
            return template_render(tmpl, env,
            {   'session' : env['beaker.session'], 'loginfail' : True}  )

        if u.password == pass_:
            env['beaker.session']['user_name'] = user
            env['beaker.session'].save()
            return main_page(env)
        else:
            return template_render(tmpl, env,
            {   'session' : env['beaker.session'], 'loginfail' : True}  )

    return template_render(tmpl, env, { })
Ejemplo n.º 2
0
def handle_api(env):
    """
    """
    if str(env['REQUEST_METHOD']) != 'POST':
        return None

    if not loggedin_and_require(env):
        return ['403 Forbidden', [('Content-Type', 'application/json')],
                json.dumps(None, indent=' ' * 4)]

    # Get JSON request via POST data
    data = read_post_data(env)
    request = urllib.unquote_plus(data['request'].value)

    print 'Request:', repr(request)

    d = json.loads(request)
    r = []

    for x in d:
        if 'type' in x:
            print 'Method:', x['type']
            r.append(env, handle_api_method(x['type'], x))

    return ['200 OK', [('Content-Type', 'application/json')], \
            json.dumps(r, indent=' ' * 4)]
Ejemplo n.º 3
0
    try:
        user_name = env['beaker.session']['user_name']
        user = lookup_user(user_name)
    except KeyError, e:
        user = None

    if USE_AUTH:
        if user == None or target['name'] not in user.targets:
            return None # 404

    return_code = None

    # Check for POST vars
    if str(env['REQUEST_METHOD']) == 'POST':
        data = read_post_data(env)

        if 'torrent_url' in data:
            print "It's a URL!"
            torrent_url = data['torrent_url'].value
            if torrent_url:
                print "Loading URL:", torrent_url
                torrent_url = urllib.unquote_plus(torrent_url)
                response = urllib2.urlopen(torrent_url)
                torrent_raw = response.read()

                torrent_raw_bin = xmlrpclib.Binary(torrent_raw)

                rtorrent = RTorrent(target)
                return_code = rtorrent.add_torrent_raw(torrent_raw_bin)
        elif 'torrent_file' in data: