Ejemplo n.º 1
0
def chat_lobby(request, lobby_id):
    logging.info("djrs.view.chat_lobby")
    template_vars = {}
    template_vars['lobby_id'] = lobby_id

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse('djrs_login'))

    # get this lobby details.
    try:
        (req_id, msg_id) = harness.request_chat_lobby_list("all")
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp
            for lobby in resp_msg.lobbies:
                if lobby.lobby_id == lobby_id:
                    template_vars['lobby_details'] = lobby
    
            # build a list from Lobby List.
            template_vars['sidebar_menu'] = 'Subscribed Lobbies'
            template_vars['sidebar_sublinks'] = []
            for lobby in resp_msg.lobbies:
                if lobby.lobby_state == chat_pb2.ChatLobbyInfo.LOBBYSTATE_JOINED:
                    url = "/lobby/%s/" % lobby.lobby_id
                    template_vars['sidebar_sublinks'].append({ 'url':url , 'name': lobby.lobby_name })

    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 2
0
def login(request):

    template_vars = {}

    if request.method == "POST":  # If the form has been submitted...
        form = LoginForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            logging.info("Hello... we have a form")

            harness = getWebHarness()

            # try to login.
            # wait around until we are logged in.
            user = form.cleaned_data["user"]
            pwd = form.cleaned_data["password"]
            host = form.cleaned_data["host"]
            port = form.cleaned_data["port"]

            try:
                harness.connect_params(user, pwd, host, port)
                return HttpResponseRedirect(reverse("djrs_home"))
            except paramiko.SSHException, e:
                logging.info("Login Exception: %s" % (e))
                error_msg = "Login Error: %s" % e
            except Exception, e:
                error_msg = "Unexpected Error: %s" % e
                logging.info("Unexpected Exception: %s" % (e))
            template_vars["error_message"] = error_msg
Ejemplo n.º 3
0
def lobby_drop(request, lobby_id):
    logging.info("djrs.view.lobby_drop")
    template_vars = {}

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse('djrs_login'))

    try:
        (req_id, msg_id) = harness.request_join_or_leave_lobby(lobby_id, False)
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp

    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 4
0
def transfer_cancel(request, hash):
    logging.info("djrs.view.transfer_cancel")

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse('djrs_login'))

    template_vars = {}
    try:
        (req_id, msg_id) = harness.request_transfer_cancel(hash)
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp

    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 5
0
def search_close(request, search_id):
    logging.info("djrs.view.search_close")

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse('djrs_login'))

    template_vars = {}
    try:
        (req_id, msg_id) = harness.request_close_search(int(search_id))
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp

    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 6
0
def friend_add(request, friend_id):
    logging.info("djrs.view.friend_add")

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse('djrs_login'))

    template_vars = {}
    try:
        (req_id, msg_id) = harness.request_friend_add(friend_id, True)
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp
            # should check the result...

    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 7
0
def friend_details(request, friend_id):
    logging.info("djrs.view.friend_details")

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse("djrs_login"))

    template_vars = {}
    try:
        (req_id, msg_id) = harness.request_peer_list("all")
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp
            template_vars["friend_list"] = resp_msg.peers

    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 8
0
def chat(request):
    logging.info("djrs.view.chat")

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse("djrs_login"))

    template_vars = {}
    try:
        (req_id, msg_id) = harness.request_chat_lobby_list("all")
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp
            template_vars["lobby_list"] = resp_msg.lobbies

    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 9
0
def transfers(request):
    logging.info("djrs.view.transfers")

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse("djrs_login"))

    template_vars = {}
    try:
        (req_id, msg_id) = harness.request_transfer_list(True)  # upload
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp
            template_vars["upload_list"] = resp_msg.transfers

    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 10
0
def transfers(request):
    logging.info("djrs.view.transfers")

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse('djrs_login'))

    template_vars = {}
    try:
        (req_id, msg_id) = harness.request_transfer_list(True) # upload
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp
            dict_msg = protobuf_to_dict(resp_msg)
            template_vars['upload_list'] = files_transferlist(dict_msg['transfers'])

    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 11
0
def search_details(request, search_id):
    logging.info("djrs.view.search_details")

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse('djrs_login'))

    template_vars = {}
    try:
        (req_id, msg_id) = harness.request_search_list(int(search_id))
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp
            dict_msg = protobuf_to_dict(resp_msg)
            template_vars['search_list'] = search_searchlist(dict_msg['searches'])


    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 12
0
def chat_friend(request, peer_id):
    logging.info("djrs.view.chat_friend")
    template_vars = {}
    template_vars['peer_id'] = peer_id

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse('djrs_login'))

    # get peer details.
    # get this lobby details.
    #try:
    #    (req_id, msg_id) = harness.request_chat_lobby_list("all")
    #    resp = harness.specific_response(req_id)
    #    if resp:
    #        (resp_id, resp_msg) = resp
    #        for lobby in resp_msg.lobbies:
    #            if lobby.lobby_id == lobby_id:
    #                template_vars['lobby_details'] = lobby
    #
    #        # build a list from Lobby List.
    #        template_vars['sidebar_menu'] = 'Subscribed Lobbies'
    #        template_vars['sidebar_sublinks'] = []
    #        for lobby in resp_msg.lobbies:
    #            if lobby.lobby_state == chat_pb2.ChatLobbyInfo.LOBBYSTATE_JOINED:
    #                url = "/lobby/%s/" % lobby.lobby_id
    #                template_vars['sidebar_sublinks'].append({ 'url':url , 'name': lobby.lobby_name })
    #
    #except Exception, e:
    #    logging.info("Unexpected Exception: %s" % (e))

    # get chat from lobby.
    try:
        (req_id, msg_id) = harness.request_chat_history('friend', peer_id)
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp
            dict_msg = protobuf_to_dict(resp_msg)
            if 'msgs' in dict_msg:
                template_vars['messages'] = chat_chathistory(dict_msg['msgs'])

    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 13
0
def friend_details(request, friend_id):
    logging.info("djrs.view.friend_details")

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse('djrs_login'))

    template_vars = {}
    try:
        (req_id, msg_id) = harness.request_peer_details(friend_id)
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp
            dict_msg = protobuf_to_dict(resp_msg)
            if 'peers' in dict_msg:
                template_vars['friend_list'] = core_personlist(dict_msg['peers'])


    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 14
0
def chat_send(request, chat_type, chat_id):
    logging.info("djrs.view.chat_send")

    template_vars = {}


    if request.method == 'POST': 
        form = ChatForm(request.POST) 
        if form.is_valid(): 

            harness = getWebHarness()

            message = form.cleaned_data['message']
            # get this lobby details.
            try:
                (req_id, msg_id) = harness.request_send_message(chat_type,  chat_id, message)
                resp = harness.specific_response(req_id)
                if resp:
                    (resp_id, resp_msg) = resp
            except Exception, e:
                logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 15
0
    def process_request(self, request):
        logging.warning("DjRsAuthMiddleware::process_request() url: %s" % request.get_full_path())
        logging.warning("DjRsAuthMiddleware::process_request() path: %s" % request.path)

        request.session['djrs'] = 'offline'
        if request.path == reverse('djrs_busy'):
            logging.warning("DjRsAuthMiddleware::process_request() Going to Busy Anyway")
            return None

        harness = getWebHarness()
        request.session.modified = True
        session_key = request.session.session_key
        active_session = harness.active_session()

        logging.warning("DjRsAuthMiddleware::process_request() active_session: %s" % active_session)
        logging.warning("DjRsAuthMiddleware::process_request() user_session: %s" % session_key)

        if active_session:
            if active_session == session_key:
                logging.warning("DjRsAuthMiddleware::process_request() Session Active and OK")
            else:
                logging.warning("DjRsAuthMiddleware::process_request() Session Invalid => Busy View")
                return HttpResponseRedirect(reverse('djrs_busy'))

        # if webharness is connected, get session id.
        if harness.is_connected() is False or not active_session:
            logging.warning("DjRsAuthMiddleware::process_request() Not Connected or Active")

            # if they are going to login -> let them through.
            if request.path == reverse('djrs_login'):
                logging.warning("DjRsAuthMiddleware::process_request() Going to Login Anyway")
                return None
               
            logging.warning("DjRsAuthMiddleware::process_request() Redirect to login")
            return HttpResponseRedirect(reverse('djrs_login'))

        logging.warning("DjRsAuthMiddleware::process_request() Is Connected")
        harness.keep_session_current()
        request.session['djrs'] = 'online'
        return None
Ejemplo n.º 16
0
def file_listing(request, peer_id='', path=''):
    logging.info("djrs.view.file_listing() peer_id: %s, path: %s " % (peer_id, path))

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse('djrs_login'))

    if path and path[0] != '/':
        # need to have starting /
        path = '/' + path

    template_vars = {}
    try:
        (req_id, msg_id) = harness.request_dirlisting(peer_id, path)
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp
            dict_msg = protobuf_to_dict(resp_msg)
            template_vars['file_listing'] = files_sharedirlist(dict_msg)

    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 17
0
def searches(request):
    logging.info("djrs.view.searches")

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse('djrs_login'))

    template_vars = {}

    if request.method == 'POST': # If the form has been submitted...
        form = SearchForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass

            terms = form.cleaned_data['terms']
            term_list = terms.split(' ')

            logging.info("Completed Search Form. Term_list: %s" % term_list)

            # default...
            template_vars['search_started'] = False
            try:
                # trigger the search...

                (req_id, msg_id) = harness.request_basic_search(term_list)
                resp = harness.specific_response(req_id)
                if resp:
                    (resp_id, resp_msg) = resp
                    template_vars['search_started'] = True
                    template_vars['search_terms'] = term_list

            except Exception, e:
                logging.info("Unexpected Exception: %s" % (e))

            # reset the form for next search.
            # form = SearchForm() # An unbound form
            form = None # disable for more info,
        else:
            # invalid form will return errors.
            pass
Ejemplo n.º 18
0
def pyrs_status(request):
    "Returns context variables for basic status."

    context_extras = {}
    if 'offline' == request.session.get('djrs','offline'):
        return context_extras

    web_harness = getWebHarness()

    # default False...     
    pyrs_status = {'connected':False}

    if web_harness is None:
        # major error - bail out.
        context_extras['pyrs_status'] = pyrs_status
        return context_extras

    try:
        # run requests (System Status)
        (req_id, msg_id) = web_harness.request_system_status()
        resp = web_harness.specific_response(req_id)
        pyrs_status['connection'] = web_harness.connect_state()

        if resp:
            (resp_id, resp_msg) = resp

            pyrs_status['connected'] = True

            pyrs_status['no_peers'] = resp_msg.no_peers
            pyrs_status['no_connected'] = resp_msg.no_connected
            pyrs_status['upload_rate'] = resp_msg.bw_total.up
            pyrs_status['download_rate'] = resp_msg.bw_total.down
            pyrs_status['network_status'] = resp_msg.net_status  # This will need to be translated
        else:
            pyrs_status['connected'] = False
    except Exception, e:
        logging.info("djrs::context_processors.pyrs_status() Exception: %s" % e)
        pass
Ejemplo n.º 19
0
def friends(request, list_type="friends"):
    logging.info("djrs.view.friends")

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse("djrs_login"))

    template_vars = {}
    acceptable_types = ["all", "friends", "connected", "self"]
    if list_type not in acceptable_types:
        template_vars["error_message"] = "Invalid Arguments Friends Listing"
        return render_to_response("djrs_error.dtml", template_vars, context_instance=RequestContext(request))

    try:
        (req_id, msg_id) = harness.request_peer_list(list_type)
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp
            dict_msg = protobuf_to_dict(resp_msg)
            template_vars["friend_list"] = core_personlist(dict_msg["peers"])

    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 20
0
def file_listing(request, peer_id='', path=''):
    logging.info("djrs.view.file_listing() peer_id: %s, path: %s " %
                 (peer_id, path))

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse('djrs_login'))

    if path and path[0] != '/':
        # need to have starting /
        path = '/' + path

    template_vars = {}
    try:
        (req_id, msg_id) = harness.request_dirlisting(peer_id, path)
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp
            dict_msg = protobuf_to_dict(resp_msg)
            template_vars['file_listing'] = files_sharedirlist(dict_msg)

    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 21
0
def friends(request, list_type='friends'):
    logging.info("djrs.view.friends")

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse('djrs_login'))

    template_vars = {}
    acceptable_types = ['all', 'friends', 'connected', 'self']
    if list_type not in acceptable_types:
        template_vars['error_message'] = 'Invalid Arguments Friends Listing'
        return render_to_response('djrs_error.dtml', template_vars, context_instance=RequestContext(request))

    try:
        (req_id, msg_id) = harness.request_peer_list(list_type)
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp
            dict_msg = protobuf_to_dict(resp_msg)
            if 'peers' in dict_msg:
                template_vars['friend_list'] = core_personlist(dict_msg['peers'])

    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 22
0
def transfer_download(request, hash):
    logging.info("djrs.view.transfer_download")

    template_vars = {}
    # parse the extra arguments for the full download details.
    size = request.GET.get('size', None)
    name = request.GET.get('name', None)

    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse('djrs_login'))

    if not size or not name:
        template_vars['error_message'] = 'Missing Arguments for Download Request'
        return render_to_response('djrs_error.dtml', template_vars, context_instance=RequestContext(request))

    try:
        (req_id, msg_id) = harness.request_transfer_download(hash, name, size)
        resp = harness.specific_response(req_id)
        if resp:
            (resp_id, resp_msg) = resp

    except Exception, e:
        logging.info("Unexpected Exception: %s" % (e))
Ejemplo n.º 23
0
def login(request):

    template_vars = {}

    if request.method == 'POST':  # If the form has been submitted...
        form = LoginForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            logging.info("Hello... we have a form")

            harness = getWebHarness()

            # try to login.
            # wait around until we are logged in.
            user = form.cleaned_data['user']
            pwd = form.cleaned_data['password']
            host = form.cleaned_data['host']
            port = form.cleaned_data['port']

            try:
                harness.connect_params(user, pwd, host, port)

                # success! -> save session as active.
                harness.set_session(request.session.session_key)

                # setup
                harness.setup_connection()

                return HttpResponseRedirect(reverse('djrs_home'))

            except paramiko.SSHException, e:
                logging.info("Login Exception: %s" % (e))
                error_msg = "Login Error: %s" % e
            except Exception, e:
                error_msg = "Unexpected Error: %s" % e
                logging.info("Unexpected Exception: %s" % (e))
            template_vars['error_message'] = error_msg
Ejemplo n.º 24
0
def login(request):

    template_vars = {}

    if request.method == 'POST': # If the form has been submitted...
        form = LoginForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            logging.info("Hello... we have a form")

            harness = getWebHarness()

            # try to login.
            # wait around until we are logged in.
            user = form.cleaned_data['user']
            pwd = form.cleaned_data['password']
            host = form.cleaned_data['host']
            port = form.cleaned_data['port']

            try: 
                harness.connect_params(user, pwd, host, port)

                # success! -> save session as active.
                harness.set_session(request.session.session_key)

                # setup 
                harness.setup_connection()

                return HttpResponseRedirect(reverse('djrs_home'))

            except paramiko.SSHException, e:
                logging.info("Login Exception: %s" % (e))
                error_msg = "Login Error: %s" % e
            except Exception, e:
                error_msg = "Unexpected Error: %s" % e
                logging.info("Unexpected Exception: %s" % (e))
            template_vars['error_message'] = error_msg
Ejemplo n.º 25
0
def home(request):
    logging.info("djrs.view.home")
    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse("djrs_login"))
    return render_to_response("djrs_home.dtml", {}, context_instance=RequestContext(request))
Ejemplo n.º 26
0
def home(request):
    logging.info("djrs.view.home")
    harness = getWebHarness()
    if harness.is_connected() is False:
        return HttpResponseRedirect(reverse('djrs_login'))
    return render_to_response('djrs_home.dtml', {}, context_instance=RequestContext(request))