def key_receive(request, key_id): check_permissions(request.user, [PERMISSION_KEY_RECEIVE]) post_action_redirect = None previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', '/'))) next = request.POST.get('next', request.GET.get('next', post_action_redirect if post_action_redirect else request.META.get('HTTP_REFERER', '/'))) if request.method == 'POST': try: term = request.GET.get('term') results = gpg.query(term) keys_dict = dict([(key.keyid, key) for key in results]) key = gpg.import_key(keys_dict[key_id].key) messages.success(request, _(u'Key: %s, imported successfully.') % key) return HttpResponseRedirect(next) except (KeyImportError, KeyError, TypeError): messages.error(request, _(u'Unable to import key id: %s') % key_id) return HttpResponseRedirect(previous) return render_to_response('generic_confirm.html', { 'title': _(u'Import key'), 'message': _(u'Are you sure you wish to import key id: %s?') % key_id, 'form_icon': 'key_add.png', 'next': next, 'previous': previous, 'submit_method': 'GET', }, context_instance=RequestContext(request))
def key_receive(request, key_id): check_permissions(request.user, [PERMISSION_KEY_RECEIVE]) post_action_redirect = None previous = request.POST.get( 'previous', request.GET.get('previous', request.META.get('HTTP_REFERER', '/'))) next = request.POST.get( 'next', request.GET.get( 'next', post_action_redirect if post_action_redirect else request.META.get( 'HTTP_REFERER', '/'))) if request.method == 'POST': try: term = request.GET.get('term') results = gpg.query(term) keys_dict = dict([(key.keyid, key) for key in results]) key = gpg.import_key(keys_dict[key_id].key) messages.success(request, _(u'Key: %s, imported successfully.') % key) return HttpResponseRedirect(next) except (KeyImportError, KeyError, TypeError): messages.error(request, _(u'Unable to import key id: %s') % key_id) return HttpResponseRedirect(previous) return render_to_response( 'generic_confirm.html', { 'title': _(u'Import key'), 'message': _(u'Are you sure you wish to import key id: %s?') % key_id, 'form_icon': 'key_add.png', 'next': next, 'previous': previous, 'submit_method': 'GET', }, context_instance=RequestContext(request))
def key_query(request): check_permissions(request.user, [PERMISSION_KEYSERVER_QUERY]) subtemplates_list = [] term = request.GET.get('term') form = KeySearchForm(initial={'term': term}) subtemplates_list.append({ 'name': 'generic_form_subtemplate.html', 'context': { 'title': _(u'Query key server'), 'form': form, 'submit_method': 'GET', }, }) if term: results = gpg.query(term) subtemplates_list.append({ 'name': 'generic_list_subtemplate.html', 'context': { 'title': _(u'results'), 'object_list': results, 'hide_object': True, 'extra_columns': [ { 'name': _(u'ID'), 'attribute': 'keyid', }, { 'name': _(u'type'), 'attribute': 'algo', }, { 'name': _(u'creation date'), 'attribute': 'creation_date', }, { 'name': _(u'disabled'), 'attribute': 'disabled', }, { 'name': _(u'expiration date'), 'attribute': 'expiration_date', }, { 'name': _(u'expired'), 'attribute': 'expired', }, { 'name': _(u'length'), 'attribute': 'key_length', }, { 'name': _(u'revoked'), 'attribute': 'revoked', }, { 'name': _(u'Identifies'), 'attribute': encapsulate(lambda x: u', '.join( [identity.uid for identity in x.identities])), }, ] }, }) return render_to_response('generic_form.html', { 'subtemplates_list': subtemplates_list, }, context_instance=RequestContext(request))
def key_query(request): check_permissions(request.user, [PERMISSION_KEYSERVER_QUERY]) subtemplates_list = [] term = request.GET.get('term') form = KeySearchForm(initial={'term': term}) subtemplates_list.append( { 'name': 'generic_form_subtemplate.html', 'context': { 'title': _(u'Query key server'), 'form': form, 'submit_method': 'GET', }, } ) if term: results = gpg.query(term) subtemplates_list.append( { 'name': 'generic_list_subtemplate.html', 'context': { 'title': _(u'results'), 'object_list': results, 'hide_object': True, 'extra_columns': [ { 'name': _(u'ID'), 'attribute': 'keyid', }, { 'name': _(u'type'), 'attribute': 'algo', }, { 'name': _(u'creation date'), 'attribute': 'creation_date', }, { 'name': _(u'disabled'), 'attribute': 'disabled', }, { 'name': _(u'expiration date'), 'attribute': 'expiration_date', }, { 'name': _(u'expired'), 'attribute': 'expired', }, { 'name': _(u'length'), 'attribute': 'key_length', }, { 'name': _(u'revoked'), 'attribute': 'revoked', }, { 'name': _(u'Identifies'), 'attribute': encapsulate(lambda x: u', '.join([identity.uid for identity in x.identities])), }, ] }, } ) return render_to_response('generic_form.html', { 'subtemplates_list': subtemplates_list, }, context_instance=RequestContext(request))