Example #1
0
def key_list(request, secret=True):
    msg_queue = Queue(queue_name='gpg_msg_queue')
    while True:
        msg_data = msg_queue.pull()
        if not msg_data:
            break;
        messages.add_message(request, msg_data.get('tag', messages.INFO), msg_data['message'])
        
    if secret:
        object_list = Key.get_all(gpg, secret=True, exclude=LocalNode().get().public_key)
        title = _(u'Private key list')
    else:
        object_list = Key.get_all(gpg)
        title = _(u'Public key list')

    return render_to_response('key_list.html', {
        'object_list': object_list,
        'title': title,
    }, context_instance=RequestContext(request))
Example #2
0
def key_delete(request, fingerprint, key_type):
    if request.method == 'POST':
        try:
            secret = key_type == 'sec'
            key = Key.get(gpg, fingerprint, secret=secret)
            gpg.delete_key(key)
            messages.success(request, _(u'Key: %s, deleted successfully.') % fingerprint)
            return HttpResponseRedirect(reverse('home_view'))
        except Exception, msg:
            messages.error(request, msg)
            return HttpResponseRedirect(reverse('home_view'))
Example #3
0
def resource_upload(request):
    if request.method == 'POST':
        form = ResourceForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                resource = Resource()
                resource.save(
                    file=request.FILES['file'],
                    key=Key.get(gpg, form.cleaned_data['key']),
                    name=form.cleaned_data['name'],
                    label=form.cleaned_data['label'],
                    description=form.cleaned_data['description'],
                    filter_html=form.cleaned_data['filter_html']
                )
                messages.success(request, _(u'Resource: %s, created successfully.') % resource)
                return HttpResponseRedirect(reverse('resource_upload'))
            except GPGSigningError, msg:
                messages.error(request, msg)
                return HttpResponseRedirect(reverse('resource_upload'))
Example #4
0
def key_publish(request):
    if request.method == 'POST':
        form = KeySelectionForm(request.POST)
        if form.is_valid():
            try:
                network = NetworkCall()
                key = Key.get(gpg, form.cleaned_data['key'])
                network.publish_key(key)
                messages.success(request, _(u'Key publish request for key: %s, has been sent') % key)
                return HttpResponseRedirect(reverse('home_view'))
            except AnnounceClientError:
                messages.error(request, _(u'Unable to send key publish call'))
                return HttpResponseRedirect(reverse('key_publish'))
    else:
        form = KeySelectionForm()

    return render_to_response('generic_form.html', {
        'form': form,
        'title': _(u'Publish a key to the OpenRelay network'),
    }, context_instance=RequestContext(request))       
Example #5
0
 def __init__(self, *args, **kwargs):
     super(ResourceForm, self).__init__(*args, **kwargs)
     self.fields['key'].choices = [(key.fingerprint, key) for key in Key.get_all(gpg, secret=True, exclude=LocalNode().get().public_key)]
     self.fields['key'].widget.attrs = {'style': 'width: auto;'}
Example #6
0
 def __init__(self, *args, **kwargs):
     super(KeySelectionForm, self).__init__(*args, **kwargs)
     self.fields['key'].choices = [(key.fingerprint, key) for key in Key.get_all(gpg, secret=True)]
     self.fields['key'].widget.attrs = {'style': 'width: auto;'}
Example #7
0
 def public_key(self):
     return Key.get(gpg, self.uuid, secret=False, search_keyservers=True)
Example #8
0
def key_delete(request, fingerprint, key_type):
    if request.method == 'POST':
        try:
            secret = key_type == 'sec'
            key = Key.get(gpg, fingerprint, secret=secret)
            gpg.delete_key(key)
            messages.success(request, _(u'Key: %s, deleted successfully.') % fingerprint)
            return HttpResponseRedirect(reverse('home_view'))
        except Exception, msg:
            messages.error(request, msg)
            return HttpResponseRedirect(reverse('home_view'))

    return render_to_response('generic_confirm.html', {
        'title': _(u'Delete key'),
        'message': _(u'Are you sure you wish to delete key:%s?  If you try to delete a public key that is part of a public/private pair the private key will be deleted as well.') % Key.get(gpg, fingerprint)
    }, context_instance=RequestContext(request))

    
def key_publish(request):
    if request.method == 'POST':
        form = KeySelectionForm(request.POST)
        if form.is_valid():
            try:
                network = NetworkCall()
                key = Key.get(gpg, form.cleaned_data['key'])
                network.publish_key(key)
                messages.success(request, _(u'Key publish request for key: %s, has been sent') % key)
                return HttpResponseRedirect(reverse('home_view'))
            except AnnounceClientError:
                messages.error(request, _(u'Unable to send key publish call'))