コード例 #1
0
ファイル: views.py プロジェクト: 4ltern4te/RatticWeb
def download(request):
    if request.method == 'POST':  # If the form has been submitted...

        # ContactForm was defined in the the previous section
        form = ExportForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass

            # Get the creds to export
            creds = Cred.objects.accessible(request.user)

            # Make the Audit logs
            auditlogs = []
            for c in creds:
                auditlogs.append(CredAudit(
                    audittype=CredAudit.CREDEXPORT,
                    cred=c,
                    user=request.user,
                ))

            # Create all Audit logs at once
            CredAudit.objects.bulk_create(auditlogs)

            # Give the Keepass file to the user
            return export_keepass(creds, form.cleaned_data['password'])
    else:
        form = ExportForm()  # An unbound form

    return render(request, 'cred_export.html', {
        'form': form,
    })
コード例 #2
0
def download(request):
    if request.method == 'POST':  # If the form has been submitted...

        # ContactForm was defined in the the previous section
        form = ExportForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass

            # Get the creds to export
            creds = Cred.objects.accessible(request.user)

            # Make the Audit logs
            auditlogs = []
            for c in creds:
                auditlogs.append(
                    CredAudit(
                        audittype=CredAudit.CREDEXPORT,
                        cred=c,
                        user=request.user,
                    ))

            # Create all Audit logs at once
            CredAudit.objects.bulk_create(auditlogs)

            # Give the Keepass file to the user
            return export_keepass(creds, form.cleaned_data['password'])
    else:
        form = ExportForm()  # An unbound form

    return render(request, 'cred_export.html', {
        'form': form,
    })
コード例 #3
0
ファイル: views.py プロジェクト: erSitzt/RatticWeb
def download(request, cfilter="special", value="all"):
    if request.method == 'POST':  # If the form has been submitted...

        form = ExportForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass

            # Get the creds to export
            (search_object, creds) = cred_search(request.user, cfilter, value)
            filename = 'RatticExport.kdb'

            # Decide on the filename
            if cfilter == 'tag':
                filename = 'RatticExportTag-%s.kdb' % search_object.name

            elif cfilter == 'group':
                filename = 'RatticExportGroup-%s.kdb' % search_object.name

            elif cfilter == 'search':
                filename = 'RatticExportSearch-%s.kdb' % search_object

            elif cfilter == 'special' and value == 'all':
                filename = 'RatticExportAll.kdb'

            elif cfilter == 'special' and value == 'trash':
                filename = 'RatticExportTrash.kdb'

            else:
                raise Http404

            # Make the Audit logs
            auditlogs = []
            for c in creds:
                auditlogs.append(
                    CredAudit(
                        audittype=CredAudit.CREDEXPORT,
                        cred=c,
                        user=request.user,
                    ))

            # Create all Audit logs at once
            CredAudit.objects.bulk_create(auditlogs)

            # Give the Keepass file to the user
            return export_keepass(creds, form.cleaned_data['password'],
                                  filename)
    else:
        form = ExportForm()  # An unbound form

    return render(request, 'cred_export.html', {
        'form': form,
    })
コード例 #4
0
ファイル: views.py プロジェクト: The1andONLYdave/RatticWeb
def download(request, cfilter="special", value="all"):
    if request.method == 'POST':  # If the form has been submitted...

        form = ExportForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass

            # Get the creds to export
            (search_object, creds) = cred_search(request.user, cfilter, value)
            filename = 'RatticExport.kdb'

            # Decide on the filename
            if cfilter == 'tag':
                filename = 'RatticExportTag-%s.kdb' % search_object.name

            elif cfilter == 'group':
                filename = 'RatticExportGroup-%s.kdb' % search_object.name

            elif cfilter == 'search':
                filename = 'RatticExportSearch-%s.kdb' % search_object

            elif cfilter == 'special' and value == 'all':
                filename = 'RatticExportAll.kdb'

            elif cfilter == 'special' and value == 'trash':
                filename = 'RatticExportTrash.kdb'

            else:
                raise Http404

            # Make the Audit logs
            auditlogs = []
            for c in creds:
                auditlogs.append(CredAudit(
                    audittype=CredAudit.CREDEXPORT,
                    cred=c,
                    user=request.user,
                ))

            # Create all Audit logs at once
            CredAudit.objects.bulk_create(auditlogs)

            # Give the Keepass file to the user
            return export_keepass(creds, form.cleaned_data['password'], filename)
    else:
        form = ExportForm()  # An unbound form

    return render(request, 'cred_export.html', {
        'form': form,
    })
コード例 #5
0
ファイル: views.py プロジェクト: ivanerill/collecTF
def export_tbl_view(request):
    if request.method=="GET":
        form = ExportForm()
        return render(request,
                      'ncbi_export.html',
                      {'form': form},
                      context_instance=RequestContext(request))
    else:
        form = ExportForm(request.POST)
        if form.is_valid():
            tbl_data = export_tbl(form.cleaned_data['TF_instances'],
                                  form.cleaned_data['genomes'])
            return render_to_response('ncbi_export_result.html',
                                      {'tbl': tbl_data,
                                       'TF_instance': form.cleaned_data['TF_instances'],
                                       'genome': form.cleaned_data['genomes'],
                                       },
                                      context_instance=RequestContext(request))
コード例 #6
0
ファイル: views.py プロジェクト: Dinara/collecTF
def export_tbl_view(request):
    if request.method=="GET":
        form = ExportForm()
        return render(request,
                      'ncbi_export.html',
                      {'form': form},
                      context_instance=RequestContext(request))

    # For given TF instance and genome, return all site instances in .tbl format
    form = ExportForm(request.POST)
    if not form.is_valid():
        return render(request, 'ncbi_export.html', {'form':form},
                      context_instance=RequestContext(request))
    
    genome_accession = form.cleaned_data['genome_accession']
    genome = models.Genome.objects.get(genome_accession=genome_accession)
    test_export = form.cleaned_data['is_test_export']
    return generate_zip_response(genome, test_export)
コード例 #7
0
def list(request, cfilter='special', value='all', sortdir='ascending', sort='title', page=1):
    # Setup basic stuff
    viewdict = {
        'credtitle': _('All passwords'),
        'alerts': [],
        'filter': unicode(cfilter).lower(),
        'value': unicode(value).lower(),
        'sort': unicode(sort).lower(),
        'sortdir': unicode(sortdir).lower(),
        'page': unicode(page).lower(),
        'groups': request.user.groups,

        # Default buttons
        'buttons': {
            'add': True,
            'delete': True,
            'changeq': True,
            'tagger': True,
            'export': False,
        }
    }

    # Get groups if required
    get_groups = request.GET.getlist('group')

    if len(get_groups) > 0:
        groups = Group.objects.filter(id__in=get_groups)
    else:
        groups = Group.objects.all()

    # Perform the search
    (search_object, cred_list) = cred_search(request.user, cfilter, value, sortdir, sort, groups)

    # Apply the filters
    if cfilter == 'tag':
        viewdict['credtitle'] = _('Passwords tagged with %(tagname)s') % {'tagname': search_object.name, }
        viewdict['buttons']['export'] = True

    elif cfilter == 'group':
        viewdict['credtitle'] = _('Passwords in group %(groupname)s') % {'groupname': search_object.name, }
        viewdict['buttons']['export'] = True

    elif cfilter == 'search':
        viewdict['credtitle'] = _('Passwords for search "%(searchstring)s"') % {'searchstring': search_object, }
        viewdict['buttons']['export'] = True

    elif cfilter == 'history':
        viewdict['credtitle'] = _('Versions of: "%(credtitle)s"') % {'credtitle': search_object.title, }
        viewdict['buttons']['add'] = False
        viewdict['buttons']['delete'] = False
        viewdict['buttons']['changeq'] = False
        viewdict['buttons']['tagger'] = False

    elif cfilter == 'changeadvice':
        alert = {}
        alert['message'] = _("That user is now disabled. Here is a list of passwords that they have viewed that have not since been changed. You probably want to add them all to the change queue.")
        alert['type'] = 'info'

        viewdict['credtitle'] = _('Changes required for "%(username)s"') % {'username': search_object.username}
        viewdict['buttons']['add'] = False
        viewdict['buttons']['delete'] = True
        viewdict['buttons']['changeq'] = True
        viewdict['buttons']['tagger'] = False
        viewdict['alerts'].append(alert)

    elif cfilter == 'special' and value == 'all':
        viewdict['buttons']['export'] = True

    elif cfilter == 'special' and value == 'trash':
        viewdict['credtitle'] = _('Passwords in the trash')
        viewdict['buttons']['add'] = False
        viewdict['buttons']['undelete'] = True
        viewdict['buttons']['changeq'] = False
        viewdict['buttons']['tagger'] = False
        viewdict['buttons']['export'] = True

    elif cfilter == 'special' and value == 'changeq':
        viewdict['credtitle'] = _('Passwords on the Change Queue')
        viewdict['buttons']['add'] = False
        viewdict['buttons']['delete'] = False
        viewdict['buttons']['changeq'] = False
        viewdict['buttons']['tagger'] = False

    else:
        raise Http404

    # Apply the sorting rules
    if sortdir == 'ascending':
        viewdict['revsortdir'] = 'descending'
    elif sortdir == 'descending':
        viewdict['revsortdir'] = 'ascending'
    else:
        raise Http404

    # Get the page
    paginator = Paginator(cred_list, request.user.profile.items_per_page)
    try:
        cred = paginator.page(page)
    except PageNotAnInteger:
        cred = paginator.page(1)
    except EmptyPage:
        cred = paginator.page(paginator.num_pages)

    # Get variables to give the template
    viewdict['credlist'] = cred

    # Create the form for exporting
    viewdict['exportform'] = ExportForm()

    return render(request, 'cred_list.html', viewdict)
コード例 #8
0
def list(request,
         cfilter='special',
         value='all',
         sortdir='ascending',
         sort='title',
         page=1):
    # Setup basic stuff
    viewdict = {}
    viewdict['credtitle'] = _('All passwords')
    viewdict['alerts'] = []
    viewdict['filter'] = str(cfilter).lower()
    viewdict['value'] = str(value).lower()
    viewdict['sort'] = str(sort).lower()
    viewdict['sortdir'] = str(sortdir).lower()
    viewdict['page'] = str(page).lower()

    # Default buttons
    viewdict['buttons'] = {}
    viewdict['buttons']['add'] = True
    viewdict['buttons']['delete'] = True
    viewdict['buttons']['changeq'] = True
    viewdict['buttons']['tagger'] = True

    # Get every cred the user has access to
    cred_list = Cred.objects.accessible(request.user)

    # Apply the filters
    if cfilter == 'tag':
        tag = get_object_or_404(Tag, pk=value)
        cred_list = cred_list.filter(tags=tag)
        viewdict['credtitle'] = _('Passwords tagged with %(tagname)s') % {
            'tagname': tag.name,
        }

    elif cfilter == 'group':
        group = get_object_or_404(Group, pk=value)
        if group not in request.user.groups.all():
            raise Http404
        cred_list = cred_list.filter(group=group)
        viewdict['credtitle'] = _('Passwords in group %(groupname)s') % {
            'groupname': group.name,
        }

    elif cfilter == 'search':
        cred_list = cred_list.filter(title__icontains=value)
        viewdict['credtitle'] = _(
            'Passwords for search "%(searchstring)s"') % {
                'searchstring': value,
            }

    elif cfilter == 'history':
        cred = get_object_or_404(Cred, pk=value)
        cred_list = Cred.objects.accessible(
            request.user,
            historical=True).filter(Q(latest=value) | Q(id=value))
        viewdict['credtitle'] = _('Versions of: "%(credtitle)s"') % {
            'credtitle': cred.title,
        }
        viewdict['buttons']['add'] = False
        viewdict['buttons']['delete'] = False
        viewdict['buttons']['changeq'] = False
        viewdict['buttons']['tagger'] = False

    elif cfilter == 'changeadvice':
        if not request.user.is_staff:
            raise Http404
        user = get_object_or_404(User, pk=value)
        get_groups = request.GET.getlist('group')

        if len(get_groups) > 0:
            groups = Group.objects.filter(id__in=get_groups)
        else:
            groups = Group.objects.all()

        cred_list = Cred.objects.change_advice(user, groups)

        alert = {}
        alert['message'] = _(
            "That user is now disabled. Here is a list of passwords that they have viewed that have not since been changed. You probably want to add them all to the change queue."
        )
        alert['type'] = 'info'

        viewdict['credtitle'] = _('Changes required for "%(username)s"') % {
            'username': user.username
        }
        viewdict['buttons']['add'] = False
        viewdict['buttons']['delete'] = True
        viewdict['buttons']['changeq'] = True
        viewdict['buttons']['tagger'] = False
        viewdict['alerts'].append(alert)

    elif cfilter == 'special' and value == 'all':
        viewdict['buttons']['export'] = True

    elif cfilter == 'special' and value == 'trash':
        cred_list = Cred.objects.accessible(
            request.user, deleted=True).filter(is_deleted=True)
        viewdict['credtitle'] = _('Passwords in the trash')
        viewdict['buttons']['add'] = False
        viewdict['buttons']['undelete'] = True
        viewdict['buttons']['changeq'] = False
        viewdict['buttons']['tagger'] = False

    elif cfilter == 'special' and value == 'changeq':
        q = Cred.objects.filter(credchangeq__in=CredChangeQ.objects.all())
        cred_list = cred_list.filter(id__in=q)
        viewdict['credtitle'] = _('Passwords on the Change Queue')
        viewdict['buttons']['add'] = False
        viewdict['buttons']['delete'] = False
        viewdict['buttons']['changeq'] = False
        viewdict['buttons']['tagger'] = False

    else:
        raise Http404

    # Apply the sorting rules
    if sortdir == 'ascending' and sort in Cred.SORTABLES:
        cred_list = cred_list.order_by('latest', sort)
        viewdict['revsortdir'] = 'descending'
    elif sortdir == 'descending' and sort in Cred.SORTABLES:
        cred_list = cred_list.order_by('latest', '-' + sort)
        viewdict['revsortdir'] = 'ascending'
    else:
        raise Http404

    # Get the page
    paginator = Paginator(cred_list, request.user.profile.items_per_page)
    try:
        cred = paginator.page(page)
    except PageNotAnInteger:
        cred = paginator.page(1)
    except EmptyPage:
        cred = paginator.page(paginator.num_pages)

    # Get variables to give the template
    viewdict['credlist'] = cred

    # Create the form for exporting
    viewdict['exportform'] = ExportForm()

    return render(request, 'cred_list.html', viewdict)