コード例 #1
0
def changelocation(request, g_id):
    '''
    Handler for changing the host:port of the gateway.
    '''
    session = request.session
    username = session['login_email']
    g_id = int(g_id)

    form = gatewayforms.ModifyGatewayLocation(request.POST)
    if form.is_valid():
        new_host = form.cleaned_data['host']
        new_port = form.cleaned_data['port']
        fields = {'host': new_host, 'port': new_port}

        # update and redirect
        try:
            db.update_replica_gateway(g_id, **fields)
        except Exception as e:
            logging.error("Unable to update RG: %d. Error was %s." % (g_id, e))
            session['message'] = "Error. Unable to change replica gateway."
            return redirect('django_rg.views.viewgateway', g_id)
        session['new_change'] = "We've updated your RG."
        session['next_url'] = '/syn/RG/viewgateway/' + str(g_id)
        session['next_message'] = "Click here to go back to your gateway."
        return redirect('/syn/thanks')
    else:
        session['message'] = "Invalid form entries for gateway location."
        return redirect('django_rg.views.viewgateway', g_id)
コード例 #2
0
ファイル: views.py プロジェクト: etherparty/syndicate
def changelocation(request, g_id):
    '''
    Handler for changing the host:port of the gateway.
    '''
    session = request.session
    username = session['login_email']
    g_id = int(g_id)

    form = gatewayforms.ModifyGatewayLocation(request.POST)
    if form.is_valid():
        new_host = form.cleaned_data['host']
        new_port = form.cleaned_data['port']
        fields = {'host':new_host, 'port':new_port}

        # update and redirect
        try:
            db.update_replica_gateway(g_id, **fields)
        except Exception as e:
            logging.error("Unable to update RG: %d. Error was %s." % (g_id, e))
            session['message'] = "Error. Unable to change replica gateway."
            return redirect('django_rg.views.viewgateway', g_id)
        session['new_change'] = "We've updated your RG."
        session['next_url'] = '/syn/RG/viewgateway/' + str(g_id)
        session['next_message'] = "Click here to go back to your gateway."
        return redirect('/syn/thanks')
    else:
        session['message'] = "Invalid form entries for gateway location."
        return redirect('django_rg.views.viewgateway', g_id)
コード例 #3
0
def changeprivacy(request, g_id):
    '''
    Handler for changing privacy settings.
    '''
    session = request.session
    username = session['login_email']
    g_id = int(g_id)

    g = db.read_replica_gateway(g_id)
    if g.private:
        fields = {'private': False}
    else:
        fields = {'private': True}
    try:
        db.update_replica_gateway(g_id, **fields)
        session[
            'new_change'] = "We've changed your gateways's privacy setting."
        session['next_url'] = '/syn/RG/viewgateway/' + str(g_id)
        session['next_message'] = "Click here to go back to your gateway."
        return redirect('/syn/thanks')
    except Exception as e:
        session['message'] = "Unable to update gateway."
        logging.info(message)
        logging.info(e)
        return redirect('django_rg.views.viewgateway', g_id)
コード例 #4
0
    def multi_update(vol, users, usergateways, acquisitiongateways,
                     replicagateways):
        v_id = vol.volume_id
        db.delete_volume(v_id)
        logging.info(users)

        for user in users:
            fields = {}

            if v_id in user.volumes_o:
                new_volumes_o = user.volumes_o
                new_volumes_o.remove(v_id)
                fields['volumes_o'] = new_volumes_o

            if v_id in user.volumes_rw:
                new_volumes_rw = user.volumes_rw
                new_volumes_rw.remove(v_id)
                fields['volumes_rw'] = new_volumes_rw

            if v_id in user.volumes_r:
                new_volumes_r = user.volumes_r
                new_volumes_r.remove(v_id)
                fields['volumes_r'] = new_volumes_r

            if fields:
                db.update_user(user.email, **fields)

        for ug in usergateways:
            fields = {}
            fields['volume_id'] = 0
            db.update_user_gateway(ug.g_id, **fields)

        for ag in acquisitiongateways:
            logging.info(ag)
            fields = {}
            new_ids = ag.volume_ids.remove(v_id)
            if not new_ids:
                fields['volume_ids'] = []
            else:
                fields['volume_ids'] = new_ids
            db.update_acquisition_gateway(ag.g_id, **fields)

        for rg in replicagateways:
            fields = {}
            new_ids = rg.volume_ids.remove(v_id)
            if not new_ids:
                fields['volume_ids'] = []
            else:
                fields['volume_ids'] = new_ids
            db.update_replica_gateway(rg.g_id, **fields)

        # Clear initial data session variable to prevent stale tables in ag.views.viewgateway and rg.views.viewgateway
        session.pop("rg_initial_data" + str(v_id), None)
        session.pop("ag_initial_data" + str(v_id), None)
        # Clear initial data session variable to prevent stale data in volume settings, change rgs, and change ags.
        session.pop("volume_initial_ags" + str(v_id), None)
        session.pop("volume_initial_rgs" + str(v_id), None)
コード例 #5
0
def changepassword(request, g_id):
    '''
    Handler for changing gateway password. Since it can't use precheck because of password reasons,
    must verify POST-ness itself.
    '''
    session = request.session
    username = session['login_email']
    g_id = int(g_id)

    # Precheck
    if request.method != "POST":
        return redirect('/syn/RG/viewgateway/' + str(g_id))

    try:
        g = db.read_replica_gateway(g_id)
        if not g:
            raise Exception("No gateway exists.")
    except Exception as e:
        logging.error("Error reading gateway %d : Exception: %s" % (g_id, e))
        message = "No replica gateway with the ID %d exists." % g_id
        t = loader.get_template("gateway_templates/viewgateway_failure.html")
        c = Context({'message': message, 'username': username})
        return HttpResponse(t.render(c))

    form = libforms.ChangePassword(request.POST)
    if not form.is_valid():
        session['message'] = "You must fill out all password fields."
        return redirect('django_rg.views.viewgateway', g_id)
    else:
        # Check password hash
        if not RG.authenticate(g, form.cleaned_data['oldpassword']):
            session['message'] = "Incorrect password."
            return redirect('django_rg.views.viewgateway', g_id)
        elif form.cleaned_data['newpassword_1'] != form.cleaned_data[
                'newpassword_2']:
            session['message'] = "Your new passwords did not match each other."
            return redirect('django_rg.views.viewgateway', g_id)
        # Ok to change password
        else:
            new_hash = RG.generate_password_hash(
                form.cleaned_data['newpassword_1'])
            fields = {'ms_password_hash': new_hash}
            try:
                db.update_replica_gateway(g_id, **fields)
            except Exception as e:
                logging.error(
                    "Unable to update replica gateway %d. Exception %s" %
                    (g_id, e))
                session['message'] = "Unable to update gateway."
                return redirect('django_rg.views.viewgateway', g_id)

            session['new_change'] = "We've changed your gateways's password."
            session['next_url'] = '/syn/RG/viewgateway/' + str(g_id)
            session['next_message'] = "Click here to go back to your volume."
            return redirect('/syn/thanks')
コード例 #6
0
ファイル: views.py プロジェクト: etherparty/syndicate
def changepassword(request, g_id):
    '''
    Handler for changing gateway password. Since it can't use precheck because of password reasons,
    must verify POST-ness itself.
    '''
    session = request.session
    username = session['login_email']
    g_id = int(g_id)

    # Precheck
    if request.method != "POST":
        return redirect('/syn/RG/viewgateway/' + str(g_id))

    try:
        g = db.read_replica_gateway(g_id)
        if not g:
            raise Exception("No gateway exists.")
    except Exception as e:
        logging.error("Error reading gateway %d : Exception: %s" % (g_id, e))
        message = "No replica gateway with the ID %d exists." % g_id
        t = loader.get_template("gateway_templates/viewgateway_failure.html")
        c = Context({'message':message, 'username':username})
        return HttpResponse(t.render(c))



    form = libforms.ChangePassword(request.POST)
    if not form.is_valid():
        session['message'] = "You must fill out all password fields."
        return redirect('django_rg.views.viewgateway', g_id)
    else:
        # Check password hash
        if not RG.authenticate(g, form.cleaned_data['oldpassword']):
            session['message'] = "Incorrect password."
            return redirect('django_rg.views.viewgateway', g_id)
        elif form.cleaned_data['newpassword_1'] != form.cleaned_data['newpassword_2']:
            session['message'] = "Your new passwords did not match each other."
            return redirect('django_rg.views.viewgateway', g_id)
        # Ok to change password
        else:
            new_hash = RG.generate_password_hash(form.cleaned_data['newpassword_1'])
            fields = {'ms_password_hash':new_hash}
            try:
                db.update_replica_gateway(g_id, **fields)
            except Exception as e:
                logging.error("Unable to update replica gateway %d. Exception %s" % (g_id, e))
                session['message'] = "Unable to update gateway."
                return redirect('django_rg.views.viewgateway', g_id)

            session['new_change'] = "We've changed your gateways's password."
            session['next_url'] = '/syn/RG/viewgateway/' + str(g_id)
            session['next_message'] = "Click here to go back to your volume."
            return redirect('/syn/thanks')
コード例 #7
0
def changejson(request, g_id):
    '''
    Handler for changing json config file.
    '''
    session = request.session
    username = session['login_email']
    g_id = int(g_id)

    form = gatewayforms.ModifyGatewayConfig(request.POST)
    if form.is_valid():
        logging.info(request.FILES)
        if 'json_config' not in request.FILES:
            session['message'] = "No uploaded file."
            return redirect('django_rg.views.viewgateway', g_id)
        if request.FILES['json_config'].multiple_chunks():
            session[
                'message'] = "Uploaded file too large; please make smaller than 2.5M"
            return redirect('django_rg.views.viewgateway', g_id)
        config = request.FILES['json_config'].read()
        fields = {}
        try:
            fields['json_config'] = json.loads(config)
        except Exception as e:
            logging.info("Possible JSON load error: %s" % e)
            try:
                fields['json_config'] = json.loads("\"" + config + "\"")
            except Exception as e:
                logging.error("Definite JSON load error %s" % e)
                session['message'] = "Error parsing given JSON text."
                return redirect('django_rg.views.viewgateway', g_id)
        db.update_replica_gateway(g_id, **fields)
        session[
            'new_change'] = "We've changed your gateways's JSON configuration."
        session['next_url'] = '/syn/RG/viewgateway/' + str(g_id)
        session['next_message'] = "Click here to go back to your gateway."
        return redirect('/syn/thanks')
    else:
        session['message'] = "Invalid form. Did you upload a file?"
        return redirect('django_rg.views.viewgateway', g_id)
コード例 #8
0
ファイル: views.py プロジェクト: etherparty/syndicate
def changejson(request, g_id):
    '''
    Handler for changing json config file.
    '''
    session = request.session
    username = session['login_email']
    g_id = int(g_id)

    form = gatewayforms.ModifyGatewayConfig(request.POST)
    if form.is_valid():
        logging.info(request.FILES)
        if 'json_config' not in request.FILES:
            session['message'] = "No uploaded file."
            return redirect('django_rg.views.viewgateway', g_id)
        if request.FILES['json_config'].multiple_chunks():
            session['message'] = "Uploaded file too large; please make smaller than 2.5M"
            return redirect('django_rg.views.viewgateway', g_id)
        config = request.FILES['json_config'].read()
        fields = {}
        try:
            fields['json_config'] = json.loads(config)
        except Exception as e:
            logging.info("Possible JSON load error: %s" % e)
            try:
                fields['json_config'] = json.loads("\"" + config + "\"")
            except Exception as e:
                logging.error("Definite JSON load error %s" % e)
                session['message'] = "Error parsing given JSON text."
                return redirect('django_rg.views.viewgateway', g_id)
        db.update_replica_gateway(g_id, **fields)
        session['new_change'] = "We've changed your gateways's JSON configuration."
        session['next_url'] = '/syn/RG/viewgateway/' + str(g_id)
        session['next_message'] = "Click here to go back to your gateway."
        return redirect('/syn/thanks')
    else:
        session['message'] = "Invalid form. Did you upload a file?"
        return redirect('django_rg.views.viewgateway', g_id)
コード例 #9
0
ファイル: views.py プロジェクト: etherparty/syndicate
def changeprivacy(request, g_id):
    '''
    Handler for changing privacy settings.
    '''
    session = request.session
    username = session['login_email']
    g_id = int(g_id)

    g = db.read_replica_gateway(g_id)
    if g.private:
        fields = {'private':False}
    else:
        fields = {'private':True}
    try:
        db.update_replica_gateway(g_id, **fields)
        session['new_change'] = "We've changed your gateways's privacy setting."
        session['next_url'] = '/syn/RG/viewgateway/' + str(g_id)
        session['next_message'] = "Click here to go back to your gateway."
        return redirect('/syn/thanks')
    except Exception as e:
        session['message'] = "Unable to update gateway."
        logging.info(message)
        logging.info(e)
        return redirect('django_rg.views.viewgateway', g_id)
コード例 #10
0
    def multi_update(v_ids, g_id, vfields, gfields):

        for v_id, vfield in zip(v_ids, vfields):
            db.update_volume(v_id, **vfield)
        db.update_replica_gateway(g_id, **gfields)
        session.pop('rg_initial_data' + str(g_id))
コード例 #11
0
 def update(v_id, g_id, vfields, gfields):
     db.update_volume(v_id, **vfields)
     db.update_replica_gateway(g_id, **gfields)
     session.pop('rg_initial_data' + str(g_id))
コード例 #12
0
ファイル: views.py プロジェクト: etherparty/syndicate
    def multi_update(v_ids, g_id, vfields, gfields):

        for v_id, vfield in zip(v_ids, vfields):
            db.update_volume(v_id, **vfield)
        db.update_replica_gateway(g_id, **gfields)
        session.pop('rg_initial_data' + str(g_id))
コード例 #13
0
ファイル: views.py プロジェクト: etherparty/syndicate
 def update(v_id, g_id, vfields, gfields):
     db.update_volume(v_id, **vfields)
     db.update_replica_gateway(g_id, **gfields)
     session.pop('rg_initial_data' + str(g_id))
コード例 #14
0
 def update(v_id, gnames, vfields, gfields):
     db.update_volume(v_id, **vfields)
     for g, gfield in zip(gnames, gfields):
         db.update_replica_gateway(g, **gfield)
     session.pop('volume_initial_rgs' + str(volume_id), None)