Example #1
0
def add_torrent_page(target):
    if request.method == 'POST':
        if 'torrent_file' in request.files:

            torrent_raw = request.files['torrent_file'].read()

            torrent_raw_bin = xmlrpclib.Binary(torrent_raw)

            rtorrent = RTorrent(target)
            return_code = rtorrent.add_torrent_raw_start(torrent_raw_bin)
        elif 'torrent_url' in request.form:

            torrent_url = request.form['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_start(torrent_raw_bin)
        elif 'magnet' in request.form:
            magnet_link = request.form['magnet']

            torrent = 'd10:magnet-uri' + str(len(magnet_link)) + ':' + magnet_link + 'e'

            rtorrent = RTorrent(target)
            return_code = rtorrent.add_torrent_raw(torrent)

        flash('Succesfully added torrent' if return_code == 0 else 'Failed to add torrent')

    rtorrent_data = fetch_global_info()

    return pyro_render_template('torrent_add.html',
            rtorrent_data=rtorrent_data, target=target['name'])
Example #2
0
def handle_login():
    print 'Handle das login'
    #tmpl = jinjaenv.get_template('loginform.html')
    _login_fail = lambda: pyro_render_template('loginform.html',
                                               loginfail=True)
    print 'Request method:', request.method

    if request.method == 'POST':
        if 'user' not in request.form or 'pass' not in request.form:
            return _login_fail()

        user = request.form['user']
        passwd = request.form['pass']

        #        pass = hashlib.sha256(pass).hexdigest()
        u = lookup_user(user)
        if u is None:
            return _login_fail()

        if u.password == passwd:
            print 'Login succes.'
            session['user_name'] = user

            # Redirect user to original page, or if not possible
            # to the main page.
            redir_url = session.pop('login_redirect_url', None)
            if redir_url:
                print 'Redirecting to:', redir_url
                return redirect_client_prg(url=redir_url)

            return redirect_client_prg('main_view_page')

        else:
            return _login_fail()

    # Not logged in?
    # Render login page, and store
    # current URL in beaker session.
    if not loggedin():
        print 'Not logged in, storing session data:', request.base_url
        session['login_redirect_url'] = request.base_url

        return pyro_render_template('loginform.html')

    # User already loggedin, redirect to main page.
    else:
        return redirect_client('main_view_page')
Example #3
0
def handle_login():
    print 'Handle das login'
    #tmpl = jinjaenv.get_template('loginform.html')
    _login_fail = lambda: pyro_render_template('loginform.html', loginfail=True)
    print 'Request method:', request.method

    if request.method == 'POST':
        if 'user' not in request.form or 'pass' not in request.form:
            return _login_fail()

        user = request.form['user']
        passwd = request.form['pass']

#        pass = hashlib.sha256(pass).hexdigest()
        u = lookup_user(user)
        if u is None:
            return _login_fail()

        if u.password == passwd:
            print 'Login succes.'
            session['user_name'] = user

            # Redirect user to original page, or if not possible
            # to the main page.
            redir_url = session.pop('login_redirect_url', None)
            if redir_url:
                print 'Redirecting to:', redir_url
                return redirect_client_prg(url=redir_url)

            return redirect_client_prg('main_view_page')

        else:
            return _login_fail()

    # Not logged in?
    # Render login page, and store
    # current URL in beaker session.
    if not loggedin():
        print 'Not logged in, storing session data:', request.base_url
        session['login_redirect_url'] = request.base_url

        return pyro_render_template('loginform.html')

    # User already loggedin, redirect to main page.
    else:
        return redirect_client('main_view_page')
Example #4
0
def style_serve():
    """
    TODO: Re-add user lookup and user specific image:

    if user and user.background_image != None:
        background = user.background_image

    """
    background = BACKGROUND_IMAGE

    return Response(pyro_render_template('style.css', trans=0.6),
                    mimetype='text/css')
Example #5
0
def style_serve():
    """
    TODO: Re-add user lookup and user specific image:

    if user and user.background_image != None:
        background = user.background_image

    """
    background = BACKGROUND_IMAGE

    return Response(pyro_render_template('style.css',
        trans=0.6),
        mimetype='text/css')
Example #6
0
def add_torrent_page(target):
    if request.method == 'POST':
        if 'torrent_file' in request.files:

            torrent_raw = request.files['torrent_file'].read()

            torrent_raw_bin = xmlrpclib.Binary(torrent_raw)

            rtorrent = RTorrent(target)
            return_code = rtorrent.add_torrent_raw_start(torrent_raw_bin)
        elif 'torrent_url' in request.form:

            torrent_url = request.form['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_start(torrent_raw_bin)
        elif 'magnet' in request.form:
            magnet_link = request.form['magnet']

            torrent = 'd10:magnet-uri' + str(
                len(magnet_link)) + ':' + magnet_link + 'e'

            rtorrent = RTorrent(target)
            return_code = rtorrent.add_torrent_raw(torrent)

        flash('Succesfully added torrent' if return_code ==
              0 else 'Failed to add torrent')

    rtorrent_data = fetch_global_info()

    return pyro_render_template('torrent_add.html',
                                rtorrent_data=rtorrent_data,
                                target=target['name'])
Example #7
0
            torrents[target['name']] = cache.get(target['name'])

            if torrents[target['name']] is not None:
                continue

            torrents[target['name']] = t.all()

            cache.set(h, torrents[target['name']], timeout=CACHE_TIMEOUT)

        except InvalidTorrentException, e:
            return error_page(env, str(e))

    return pyro_render_template('download_list.html',
                                torrents_list=torrents,
                                rtorrent_data=rtorrent_data,
                                view=view
                                # TODO
                                )


@app.route('/target/<target>/torrent/<torrent>')
@app.route('/target/<target>/torrent/<torrent>/<action>')
@pyroview
@require_target
@require_torrent
def torrent_info(target, torrent, action=None):
    print torrent, action
    if action in ('open', 'close', 'start', 'stop', 'pause', 'resume'):
        print 'Executing action', action
        print getattr(torrent, action)()
        flash('Executed %s on torrent %s' % (action, torrent.get_name()))
Example #8
0
                continue

            torrents[target['name']] = cache.get(target['name'])

            if torrents[target['name']] is not None:
                continue

            torrents[target['name']] = t.all()

            cache.set(h, torrents[target['name']], timeout=CACHE_TIMEOUT)

        except InvalidTorrentException, e:
            return error_page(env, str(e))

    return pyro_render_template('download_list.html',
            torrents_list=torrents, rtorrent_data=rtorrent_data, view=view
            # TODO
            )

@app.route('/target/<target>/torrent/<torrent>')
@app.route('/target/<target>/torrent/<torrent>/<action>')
@pyroview
@require_target
@require_torrent
def torrent_info(target, torrent, action=None):
    print torrent, action
    if action in ('open', 'close', 'start', 'stop', 'pause', 'resume'):
        print 'Executing action', action
        print getattr(torrent, action)()
        flash('Executed %s on torrent %s' % (action, torrent.get_name()))

    try: