コード例 #1
0
    def update_ug_and_vol(g_id, gfields, vol1_id, vol2_id):
        db.update_user_gateway(g_id, **gfields)
        attrs = {"UG_version": 1}

        # Force update of UG version
        db.update_volume(vol1_id, **attrs)
        db.update_volume(vol2_id, **attrs)
コード例 #2
0
def deactivatevolume(request, volume_id):
    session = request.session
    username = session['login_email']
    vol = db.read_volume(volume_id)
    if not vol:
        return redirect('django_volume.views.viewvolume', volume_id)

    if request.method == "POST":

        form = libforms.Password(request.POST)
        if not form.is_valid():
            session['message'] = "Password required."
            return redirect('django_volume.views.volumesettings',
                            vol.volume_id)
        # Check password hash
        hash_check = Volume.generate_password_hash(
            form.cleaned_data['password'], vol.volume_secret_salt)
        if hash_check != vol.volume_secret_salted_hash:
            session['message'] = "Incorrect password."
            return redirect('django_volume.views.volumesettings',
                            vol.volume_id)
        fields = {'active': False}
        db.update_volume(vol.volume_id, **fields)
        session['new_change'] = "We've deactivated your volume."
        session['next_url'] = '/syn/volume/' + str(vol.volume_id)
        session['next_message'] = "Click here to go back to your volume."
        return redirect('/syn/thanks')
    return redirect("/syn/volume/" + str(vol.volume_id))
コード例 #3
0
ファイル: views.py プロジェクト: etherparty/syndicate
 def delete_and_update(rg_id, attached_volume_ids):
     db.delete_replica_gateway(rg_id)
     for v in attached_volume_ids:
         vol = db.read_volume(v)
         if not vol:
             continue
         new_rg_ids = vol.rg_ids
         new_rg_ids.remove(rg_id)
         attrs = {"rg_ids":new_rg_ids}
         db.update_volume(v, **attrs)
     session.pop("rg_initial_data" + str(g_id), None)
コード例 #4
0
 def delete_and_update(rg_id, attached_volume_ids):
     db.delete_replica_gateway(rg_id)
     for v in attached_volume_ids:
         vol = db.read_volume(v)
         if not vol:
             continue
         new_rg_ids = vol.rg_ids
         new_rg_ids.remove(rg_id)
         attrs = {"rg_ids": new_rg_ids}
         db.update_volume(v, **attrs)
     session.pop("rg_initial_data" + str(g_id), None)
コード例 #5
0
ファイル: views.py プロジェクト: etherparty/syndicate
 def delete_and_update(ag_id, attached_volume_ids):
     db.delete_acquisition_gateway(ag_id)
     for v in attached_volume_ids:
         vol = db.read_volume(v)
         if not vol:
             continue
         new_ag_ids = vol.ag_ids
         new_ag_ids.remove(ag_id)
         attrs = {"ag_ids":new_ag_ids}
         db.update_volume(v, **attrs)
     session.pop("ag_initial_data", None)
コード例 #6
0
 def delete_and_update(ag_id, attached_volume_ids):
     db.delete_acquisition_gateway(ag_id)
     for v in attached_volume_ids:
         vol = db.read_volume(v)
         if not vol:
             continue
         new_ag_ids = vol.ag_ids
         new_ag_ids.remove(ag_id)
         attrs = {"ag_ids": new_ag_ids}
         db.update_volume(v, **attrs)
     session.pop("ag_initial_data", None)
コード例 #7
0
def changedesc(request, volume_id):
    session = request.session
    username = session['login_email']
    vol = db.read_volume(volume_id)
    if not vol:
        return redirect('django_volume.views.viewvolume', volume_id)

    if request.method != "POST":
        return redirect('/syn/volume/' + str(vol.volume_id) + '/settings')

    form = libforms.Password(request.POST)
    desc_form = forms.ChangeVolumeD(request.POST)
    old_data = {}

    if not form.is_valid():
        session['message'] = "Password required."
        desc_form.is_valid()
        if desc_form.errors:
            session['old_data' + str(volume_id)] = ""
        else:
            session['old_data' +
                    str(volume_id)] = desc_form.cleaned_data['description']
        return redirect('django_volume.views.volumesettings', volume_id)

    # Check password hash
    hash_check = Volume.generate_password_hash(form.cleaned_data['password'],
                                               vol.volume_secret_salt)
    if hash_check != vol.volume_secret_salted_hash:
        session['message'] = "Incorrect password."
        desc_form.is_valid()
        if desc_form.errors:
            session['old_data' + str(volume_id)] = ""
        else:
            session['old_data' +
                    str(volume_id)] = desc_form.cleaned_data['description']
        return redirect('django_volume.views.volumesettings', volume_id)

    if not desc_form.is_valid():
        session['message'] = "Invalid description field entries."
        return redirect('django_volume.views.volumesettings', volume_id)

    kwargs = {}
    if desc_form.cleaned_data['description']:
        kwargs['description'] = desc_form.cleaned_data['description']
    db.update_volume(vol.volume_id, **kwargs)
    session.pop('old_data' + str(volume_id), None)
    session['new_change'] = "We've changed your volume description."
    session['next_url'] = '/syn/volume/' + str(vol.volume_id)
    session['next_message'] = "Click here to go back to your volume."
    return redirect('/syn/thanks')
コード例 #8
0
def changevolumepassword(request, volume_id):
    session = request.session
    username = session['login_email']
    vol = db.read_volume(volume_id)
    if not vol:
        return redirect('django_volume.views.viewvolume', volume_id)

    if request.method != "POST":
        return redirect('/syn/volume/' + str(volume_id) + '/settings')

    form = libforms.ChangePassword(request.POST)
    if not form.is_valid():
        session['message'] = "You must fill out all password fields."
        return redirect('django_volume.views.volumesettings', volume_id)
    else:

        # Check password hash
        hash_check = Volume.generate_password_hash(
            form.cleaned_data['oldpassword'], vol.volume_secret_salt)
        if hash_check != vol.volume_secret_salted_hash:
            session['message'] = "Incorrect password."
            return redirect('django_volume.views.volumesettings', volume_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_volume.views.volumesettings', volume_id)

        # Ok change password
        kwargs = {}
        new_volume_secret_salt, new_volume_secret_salted_hash = Volume.generate_volume_secret(
            form.cleaned_data['newpassword_1'])
        kwargs['volume_secret_salted_hash'] = new_volume_secret_salted_hash
        kwargs['volume_secret_salt'] = new_volume_secret_salt
        db.update_volume(vol.volume_id, **kwargs)

        session['new_change'] = "We've changed your volume's password."
        session['next_url'] = '/syn/volume/' + str(vol.volume_id)
        session['next_message'] = "Click here to go back to your volume."
        return redirect('/syn/thanks')
コード例 #9
0
def update_volume(name, **attrs):
    """
   Update a Volume.
   
   Positional arguments:
      name (str):
         The name of the Volume to update.
      
   Optional keyword arguments:
      description=str:
         The human-readable description of what this Volume is
         used for.
      
      private=bool:
         If True, Gateways must authenticate and prove that they
         are assigned to the Volume before they can access it.
         If False, Gateways can access Volume metadata without 
         authenticating first.
      
      file_quota=int:
         The soft limit on the number of files and directories 
         that can exist in this Volume.  Pass -1 for infinte.
      
   Returns:
      If successful, returns True.  Raises an exception on failure.
   
   Authorization:
      An administrator can update any Volume.
      A user can only update Volumes (s)he owns.
      
   Remakrs:
      In implementation, Syndicate will send along 'volume_cert_b64' and 
      'cert_bundle_b64' as keywords.  The former is a protobuf'ed ms_gateway_metadata 
      structure containing the above keywords, signed by the volume owner.  The 
      latter is the current version vector for all gateway and volume certs, signed 
      by the volume owner.
   """
    return storage.update_volume(name, **attrs)
コード例 #10
0
ファイル: api.py プロジェクト: syndicate-storage/syndicate
def update_volume(name, **attrs):
    """
   Update a Volume.
   
   Positional arguments:
      name (str):
         The name of the Volume to update.
      
   Optional keyword arguments:
      description=str:
         The human-readable description of what this Volume is
         used for.
      
      private=bool:
         If True, Gateways must authenticate and prove that they
         are assigned to the Volume before they can access it.
         If False, Gateways can access Volume metadata without 
         authenticating first.
      
      file_quota=int:
         The soft limit on the number of files and directories 
         that can exist in this Volume.  Pass -1 for infinte.
      
   Returns:
      If successful, returns True.  Raises an exception on failure.
   
   Authorization:
      An administrator can update any Volume.
      A user can only update Volumes (s)he owns.
      
   Remakrs:
      In implementation, Syndicate will send along 'volume_cert_b64' and 
      'cert_bundle_b64' as keywords.  The former is a protobuf'ed ms_gateway_metadata 
      structure containing the above keywords, signed by the volume owner.  The 
      latter is the current version vector for all gateway and volume certs, signed 
      by the volume owner.
   """
    return storage.update_volume(name, **attrs)
コード例 #11
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_acquisition_gateway(g_id, **gfields)
     session.pop('ag_initial_data' + str(g_id))
コード例 #12
0
def create(request):
    '''
    View for creating UG's
    '''
    session = request.session
    username = session['login_email']
    user = db.read_user(username)

    # Helper method that simplifies returning forms after user error.
    def give_create_form(username, session):
        message = session.pop('message', "")
        form = gatewayforms.CreateUG()
        t = loader.get_template('gateway_templates/create_user_gateway.html')
        c = RequestContext(request, {
            'username': username,
            'form': form,
            'message': message
        })
        return HttpResponse(t.render(c))

    if request.POST:
        # Validate input forms
        form = gatewayforms.CreateUG(request.POST)
        if form.is_valid():
            if not form.cleaned_data['volume_name']:
                logging.info("DLFKJSDF")
                vol = None
            else:
                attrs = {
                    "Volume.name ==":
                    form.cleaned_data['volume_name'].strip().replace(" ", "_")
                }
                vols = db.list_volumes(attrs, limit=1)
                if vols:
                    vol = vols[0]
                else:
                    session[
                        'message'] = "No volume %s exists." % form.cleaned_data[
                            'volume_name']
                    return give_create_form(username, session)
                if (vol.volume_id
                        not in user.volumes_r) and (vol.volume_id
                                                    not in user.volumes_rw):
                    session[
                        'message'] = "Must have read rights to volume %s to create UG for it." % form.cleaned_data[
                            'volume_name']
                    return give_create_form(username, session)
                # Force update of UG version
                attrs = {"UG_version": 1}

                try:
                    transaction(
                        lambda: db.update_volume(vol.volume_id, **attrs))
                except Exception as E:
                    session['message'] = "UG creation error: %s" % E
                    return give_create_form(username, session)

            try:
                # Prep kwargs
                kwargs = {}
                kwargs['read_write'] = form.cleaned_data['read_write']
                kwargs['ms_username'] = form.cleaned_data['g_name']
                kwargs['port'] = form.cleaned_data['port']
                kwargs['host'] = form.cleaned_data['host']
                kwargs['ms_password'] = form.cleaned_data['g_password']

                # Create
                new_ug = db.create_user_gateway(user, vol, **kwargs)
            except Exception as E:
                session['message'] = "UG creation error: %s" % E
                return give_create_form(username, session)

            session['new_change'] = "Your new gateway is ready."
            session['next_url'] = '/syn/UG/mygateways'
            session['next_message'] = "Click here to see your gateways."
            return HttpResponseRedirect('/syn/thanks/')
        else:
            # Prep returned form values (so they don't have to re-enter stuff)

            if 'g_name' in form.errors:
                oldname = ""
            else:
                oldname = request.POST['g_name']
            if 'volume_name' in form.errors:
                oldvolume_name = ""
            else:
                oldvolume_name = request.POST['volume_name']
            if 'host' in form.errors:
                oldhost = ""
            else:
                oldhost = request.POST['host']
            if 'port' in form.errors:
                oldport = ""
            else:
                oldport = request.POST['port']

            # Prep error message
            message = "Invalid form entry: "

            for k, v in form.errors.items():
                message = message + "\"" + k + "\"" + " -> "
                for m in v:
                    message = message + m + " "

            # Give then the form again
            form = gatewayforms.CreateUG(
                initial={
                    'g_name': oldname,
                    'volume_name': oldvolume_name,
                    'host': oldhost,
                    'port': oldport,
                })
            t = loader.get_template(
                'gateway_templates/create_user_gateway.html')
            c = RequestContext(request, {
                'username': username,
                'form': form,
                'message': message
            })
            return HttpResponse(t.render(c))

    else:
        # Not a POST, give them blank form
        return give_create_form(username, session)
コード例 #13
0
 def update(v_id, g_id, vfields, gfields):
     db.update_volume(v_id, **vfields)
     db.update_acquisition_gateway(g_id, **gfields)
     session.pop('ag_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)
コード例 #15
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))
コード例 #16
0
def changevolume(request, g_id):
    '''
    View to enable changing volume attached to UG
    '''
    session = request.session
    username = session['login_email']
    user = db.read_user(username)
    g_id = int(g_id)
    g = db.read_user_gateway(g_id)

    # Isolate DB calls to allow roll-backs via transactions
    @transactional(xg=True)
    def update_ug_and_vol(g_id, gfields, vol1_id, vol2_id):
        db.update_user_gateway(g_id, **gfields)
        attrs = {"UG_version": 1}

        # Force update of UG version
        db.update_volume(vol1_id, **attrs)
        db.update_volume(vol2_id, **attrs)

    form = gatewayforms.ChangeVolume(request.POST)
    if form.is_valid():
        attrs = {
            "Volume.name ==":
            form.cleaned_data['volume_name'].strip().replace(" ", "_")
        }
        vols = db.list_volumes(attrs, limit=1)
        if vols:
            new_vol = vols[0]
        else:
            session['message'] = "No volume %s exists." % form.cleaned_data[
                'volume_name']
            return redirect('django_ug.views.viewgateway', g_id)
        if (new_vol.volume_id
                not in user.volumes_r) and (new_vol.volume_id
                                            not in user.volumes_rw):
            session[
                'message'] = "Must have read rights to volume %s to assign UG to it." % form.cleaned_data[
                    'volume_name']
            return redirect('django_ug.views.viewgateway', g_id)

        old_vol = g.volume_id
        #fields = {"volume_id":new_vol.volume_id, "cert_version": True}
        try:

            db.update_user_gateway(g_id,
                                   volume_id=new_vol.volume_id,
                                   cert_version=True)

            db.update_volume(new_vol.volume_id,
                             version=True,
                             cert_version=True)

            if g.is_bound_to_volume():
                # update the old Volume
                db.update_volume(old_vol, version=True, cert_version=True)

            #update_ug_and_vol(g_id, fields, old_vol, new_vol.volume_id)
        except Exception, e:
            logging.error("Unable to update UG with ID %s. Error was %s." %
                          (g_id, e))
            session['message'] = "Error. Unable to change user gateway."
            return redirect('django_ug.views.viewgateway', g_id)
        session['new_change'] = "We've updated your UG."
        session['next_url'] = '/syn/UG/viewgateway/' + str(g_id)
        session['next_message'] = "Click here to go back to your gateway."
        return HttpResponseRedirect('/syn/thanks')
コード例 #17
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))
コード例 #18
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))
コード例 #19
0
ファイル: views.py プロジェクト: etherparty/syndicate
 def update(v_id, g_id, vfields, gfields):
     db.update_volume(v_id, **vfields)
     db.update_acquisition_gateway(g_id, **gfields)
     session.pop('ag_initial_data' + str(g_id))