Beispiel #1
0
def asset_clone(request, uuid):
    asset = AssetInfo.objects.get(uuid=uuid)

    ## Old method:
    ##    # Use old owners, but make sure cloner is first in the list
    ##    old_owners = asset.owners.split(',')
    ##    new_owners = [request.account.uuid] + filter(lambda owner: owner != request.account.uuid, old_owners)
    new_owners = [request.account.uuid]

    clone_asset = AssetInfo.objects.create(
        location=asset.location,
        hash_value=asset.hash_value,
        type_x=asset.type_x,
        kb_size=asset.kb_size,
        comment='Clone of asset "%s"' % asset.comment,
    )
    clone_asset.owners.add(request.account)
    clone_asset.save()

    # Clone dependencies
    for dep in asset.dependencies.all():
        clone_asset.dependencies.add(dep)
    clone_asset.save()

    # Clone in the storage
    data = singleton_send(retrieve_asset, None, asset_uuid=asset.uuid)
    multiple_send(store_asset, None, asset=clone_asset, asset_file=File(data))

    request.session['message'] = 'Asset successfully cloned.'
    return HttpResponseRedirect('/tracker/asset/view/%s/' % clone_asset.uuid)
Beispiel #2
0
def account(request, uuid=None, message=None):
    if request.user.is_authenticated():
        my_account = UserAccount.objects.get(user=request.user)
        my_uuid = my_account.uuid
    else:
        my_uuid = None

    if uuid is not None:
        if uuid != my_uuid:
            other_account = UserAccount.objects.get(uuid=uuid)
        else:
            other_account = my_account
    else:
        if not request.user.is_authenticated():
            return login_required(account)(request)

        uuid = my_uuid
        other_account = my_account

    if uuid == my_uuid:
        instances = ServerInstance.objects.filter(requisitioner=my_account)
    else:
        instances = []

    multiple_send(list_instances, None, instances = instances, request = request)

    return direct_to_template(request, template="tracker/account.html", extra_context={
        'account': other_account,
        'is_my_account': uuid == my_uuid,
        'instances': instances,
        'message': message,
        'tools': multiple_send(account_tools, None, account = my_account) if uuid == my_uuid else [],
    })
Beispiel #3
0
def asset_clone(request, uuid):
    asset = AssetInfo.objects.get(uuid=uuid)

## Old method:
##    # Use old owners, but make sure cloner is first in the list
##    old_owners = asset.owners.split(',')
##    new_owners = [request.account.uuid] + filter(lambda owner: owner != request.account.uuid, old_owners)
    new_owners = [request.account.uuid]

    clone_asset = AssetInfo.objects.create(
        location = asset.location,
        hash_value = asset.hash_value,
        type_x = asset.type_x,
        kb_size = asset.kb_size,
        comment = 'Clone of asset "%s"' % asset.comment,
    )
    clone_asset.owners.add(request.account)
    clone_asset.save()

    # Clone dependencies
    for dep in asset.dependencies.all():
        clone_asset.dependencies.add(dep)
    clone_asset.save()

    # Clone in the storage
    data = singleton_send(retrieve_asset, None, asset_uuid = asset.uuid)
    multiple_send(store_asset, None, asset = clone_asset, asset_file = File(data))

    request.session['message'] = 'Asset successfully cloned.'
    return HttpResponseRedirect('/tracker/asset/view/%s/' % clone_asset.uuid)
Beispiel #4
0
def instances(request):
    SORTABLES = {
        'user_interface': 'Location',
        'admin_interface': 'Admin',
        'status': 'Status',
        'activity': 'Current Activity',
        'last_update': 'Last Update',
        'requisitioner': 'Requisitioner',
        'players': 'Players',
        'max_players': 'Max. Players'
    }

    objects = sorted_objects(
        request,
        '-last_update',
        SORTABLES,
        ServerInstance.objects
    )

    # Only display listable instances
    objects = filter(lambda instance: instance.listable(), objects)

    multiple_send(list_instances, None, instances = objects, request = request)

    return direct_to_template(request, template="tracker/instances.html", extra_context={
        'instances': objects, 'sortables': SORTABLES,
    })
Beispiel #5
0
def instances(request):
    SORTABLES = {
        'user_interface': 'Location',
        'admin_interface': 'Admin',
        'status': 'Status',
        'activity': 'Current Activity',
        'last_update': 'Last Update',
        'requisitioner': 'Requisitioner',
        'players': 'Players',
        'max_players': 'Max. Players'
    }

    objects = sorted_objects(request, '-last_update', SORTABLES,
                             ServerInstance.objects)

    # Only display listable instances
    objects = filter(lambda instance: instance.listable(), objects)

    multiple_send(list_instances, None, instances=objects, request=request)

    return direct_to_template(request,
                              template="tracker/instances.html",
                              extra_context={
                                  'instances': objects,
                                  'sortables': SORTABLES,
                              })
def create_initial_asset_content(asset):
    short_location = asset.location.replace('base/', '')
    if short_location in INITIAL_ASSET_LOCATIONS:
        INITIAL_ASSET_LOCATIONS.remove(short_location) # Do before send, to prevent recursion

        # Upload fixture data
        data = open(
            os.path.join(os.path.dirname(os.path.abspath(__file__)), short_location),
            'rb'
        )
        multiple_send(store_asset, None, asset = asset, asset_file = File(data))

        return len(INITIAL_ASSET_LOCATIONS) != 0 # Whether we need more
    else:
        return True # For all we know, we do need more
Beispiel #7
0
def create_initial_asset_content(asset):
    short_location = asset.location.replace('base/', '')
    if short_location in INITIAL_ASSET_LOCATIONS:
        INITIAL_ASSET_LOCATIONS.remove(
            short_location)  # Do before send, to prevent recursion

        # Upload fixture data
        data = open(
            os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         short_location), 'rb')
        multiple_send(store_asset, None, asset=asset, asset_file=File(data))

        return len(INITIAL_ASSET_LOCATIONS) != 0  # Whether we need more
    else:
        return True  # For all we know, we do need more
Beispiel #8
0
def inject_asset(location, filename, username = '******'):
    assets = AssetInfo.objects.filter(location=location)
    if len(assets) == 0:
        user = User.objects.get(username=username)
        account = UserAccount.objects.get(user=user)

        asset = AssetInfo.objects.create(
            location = location,
            hash_value = '',
            type_x = AssetInfo.TYPE.Both,
            kb_size = 0,
            comment = '',
        )
        asset.owners.add(account)
        asset.save()
    else:
        asset = assets[0]

    multiple_send(store_asset, None, asset = asset, asset_file = File(open(filename, 'rb')))
Beispiel #9
0
def account(request, uuid=None, message=None):
    if request.user.is_authenticated():
        my_account = UserAccount.objects.get(user=request.user)
        my_uuid = my_account.uuid
    else:
        my_uuid = None

    if uuid is not None:
        if uuid != my_uuid:
            other_account = UserAccount.objects.get(uuid=uuid)
        else:
            other_account = my_account
    else:
        if not request.user.is_authenticated():
            return login_required(account)(request)

        uuid = my_uuid
        other_account = my_account

    if uuid == my_uuid:
        instances = ServerInstance.objects.filter(requisitioner=my_account)
    else:
        instances = []

    multiple_send(list_instances, None, instances=instances, request=request)

    return direct_to_template(
        request,
        template="tracker/account.html",
        extra_context={
            'account':
            other_account,
            'is_my_account':
            uuid == my_uuid,
            'instances':
            instances,
            'message':
            message,
            'tools':
            multiple_send(account_tools, None, account=my_account)
            if uuid == my_uuid else [],
        })
Beispiel #10
0
    def clean(self):
        # Security checks
        verifications = multiple_send(verify_security_check, None, request=self.request)
        security_errors = filter(lambda x: x is not True, verifications)

        self.prepare_security_checks(security_errors) # Not strictly necessary if all other fields were ok

        if len(security_errors) != 0:
            raise forms.ValidationError(_('Security checks not passed. See reasons below.'))

        return super(SecurityCheckedForm, self).clean()
Beispiel #11
0
        def finish_do_login():
            if not success:
                log(logging.ERROR, "Login failure: %d" % (client_number))
                show_client_message(client_number, "Login Failure", "The supplied transaction code was not verified")
                log(logging.WARNING, "Should flush network messages, but not doing so") #CModule.force_network_flush()
                CModule.disconnect_client(client_number, 3) # DISC_KICK... most relevant for now
                return

            if World.scenario_code != curr_scenario_code:
                log(logging.WARNING, "Scenario code has changed since client %d began login" % client_number)
                return fail("Server has begun a new scenario. Try connecting again") # XXX - do we want this?

            user_id = response['user_id']

            if filter(lambda client: client.user_id == user_id, Clients.list()) != []:
                show_client_message(client_number, "Login Failure", "You are already logged into this server. (If you just crashed, wait a little.)")
                CModule.force_network_flush()
                CModule.disconnect_client(client_number, 3) # DISC_KICK... most relevant for now
                return

            username = response['username']
            can_edit = response['can_edit'] == '1'

            # Validate with plugins. String results are error messages, True values are successes

            validation_errors = filter(lambda x: type(x) is str, multiple_send(validate_client, None, **{
                'client_number': client_number,
                'ip_addr': ip_addr,
                'username': username,
                'can_edit': can_edit,
            }))
            if len(validation_errors) > 0:
                for error in validation_errors:
                    log(logging.WARNING, '%s login failure: %s' % (username, error))
                return fail(validation_errors[0]) # Show user only first error. They should fix that and try again

            # Success, proceed

            CModule.update_username(client_number, username)

            if can_edit:
                CModule.set_admin(client_number, True);
                admin = True
            else:
                admin = False

            # Also creates a scripting logic entity
            MessageSystem.send(client_number,
                                CModule.LoginResponse,
                                1, 0); # success, non-local

            Clients.add(client_number, ip_addr, admin, username, user_id)
Beispiel #12
0
def inject_asset(location, filename, username='******'):
    assets = AssetInfo.objects.filter(location=location)
    if len(assets) == 0:
        user = User.objects.get(username=username)
        account = UserAccount.objects.get(user=user)

        asset = AssetInfo.objects.create(
            location=location,
            hash_value='',
            type_x=AssetInfo.TYPE.Both,
            kb_size=0,
            comment='',
        )
        asset.owners.add(account)
        asset.save()
    else:
        asset = assets[0]

    multiple_send(store_asset,
                  None,
                  asset=asset,
                  asset_file=File(open(filename, 'rb')))
def upload(request, uuid):
    asset = AssetInfo.objects.get(uuid=uuid)
    if intensity_conf.get('Instances', 'let_anyone_edit') != '1':
        owner_uuids = [owner.uuid for owner in asset.owners.all()]
        assert request.account.uuid in owner_uuids, 'You must be an owner of this asset to upload content'

    if request.method == 'GET':
        return direct_to_template(request, template="do_upload.html", extra_context = {'asset': asset})
    else:
        # Receive the uploaded file, and hand off reception to the appropriate service provider
        asset_file = request.FILES['file']
        ret = multiple_send(store_asset, None, asset=asset, asset_file=asset_file)
        if reduce(lambda x, y: x and y, ret) is True:
            request.session['message'] = 'Upload was successful.'
            return HttpResponseRedirect('/tracker/asset/view/%s/' % asset.uuid)
        else:
            raise Exception(str(ret))
Beispiel #14
0
def upload(request, uuid):
    asset = AssetInfo.objects.get(uuid=uuid)
    if intensity_conf.get('Instances', 'let_anyone_edit') != '1':
        owner_uuids = [owner.uuid for owner in asset.owners.all()]
        assert request.account.uuid in owner_uuids, 'You must be an owner of this asset to upload content'

    if request.method == 'GET':
        return direct_to_template(request,
                                  template="do_upload.html",
                                  extra_context={'asset': asset})
    else:
        # Receive the uploaded file, and hand off reception to the appropriate service provider
        asset_file = request.FILES['file']
        ret = multiple_send(store_asset,
                            None,
                            asset=asset,
                            asset_file=asset_file)
        if reduce(lambda x, y: x and y, ret) is True:
            request.session['message'] = 'Upload was successful.'
            return HttpResponseRedirect('/tracker/asset/view/%s/' % asset.uuid)
        else:
            raise Exception(str(ret))
Beispiel #15
0
 def check_existing(self, asset_info):
     checks = multiple_send(check_existing, None, asset_info=asset_info)
     return True in checks and False not in checks
Beispiel #16
0
 def check_existing(self, asset_info):
     checks = multiple_send(check_existing, None, asset_info=asset_info)
     return True in checks and False not in checks
Beispiel #17
0
 def prepare_security_checks(self, errors=[]):
     checks = multiple_send(prepare_security_check, None, errors = errors)
     checks_html = '<br>'.join(checks)
     self.security_checks = SafeString(checks_html)