def directorassigns_new(request, plugin_id): bacula_key, bacula_secret = utils.get_bacula_oauth_creds() url = utils.get_rpc_url(request) trans = OAuthTransport(url, key=bacula_key, secret=bacula_secret) server = jsonrpclib.Server(url, transport=trans) jail_path = server.plugins.jail.path(plugin_id) if request.method == "POST": form = forms.BaculaSDDirectorAssignmentForm(request.POST) if form.is_valid(): form.save() return JsonResponse( request, message="Director assignment added", events=["refreshTree()"], ) return JsonResponse(request, tpl="directorassigns_new.html", ctx={ 'form': form, }) else: form = forms.BaculaSDDirectorAssignmentForm() return render(request, "directorassigns_new.html", { 'form': form, })
def messagesassigns_edit(request, plugin_id, oid): bacula_key, bacula_secret = utils.get_bacula_oauth_creds() url = utils.get_rpc_url(request) trans = OAuthTransport(url, key=bacula_key, secret=bacula_secret) server = jsonrpclib.Server(url, transport=trans) jail_path = server.plugins.jail.path(plugin_id) instance = models.BaculaSDMessagesAssignment.objects.get(id=oid) delete_url = reverse('bacula_messagesassigns_delete', kwargs={'plugin_id': plugin_id, 'oid': oid}) if request.method == "POST": form = forms.BaculaSDMessagesAssignmentForm(request.POST, instance=instance) if form.is_valid(): form.save() return JsonResponse(request, message="Message assignment updated", events=["refreshTree()"], ) return JsonResponse(request, tpl="messagesassigns_edit.html", ctx={ 'form': form, 'delete_url': delete_url, }) else: form = forms.BaculaSDMessagesAssignmentForm(instance=instance) return render(request, "messagesassigns_edit.html", { 'form': form, 'delete_url': delete_url, })
def messagesassigns_new(request, plugin_id): bacula_key, bacula_secret = utils.get_bacula_oauth_creds() url = utils.get_rpc_url(request) trans = OAuthTransport(url, key=bacula_key, secret=bacula_secret) server = jsonrpclib.Server(url, transport=trans) jail_path = server.plugins.jail.path(plugin_id) if request.method == "POST": form = forms.BaculaSDMessagesAssignmentForm(request.POST) if form.is_valid(): form.save() return JsonResponse(request, message="Message added", events=["refreshTree()"], ) return JsonResponse(request, tpl="messagesassigns_new.html", ctx={ 'form': form, }) else: form = forms.BaculaSDMessagesAssignmentForm() return render(request, "messagesassigns_new.html", { 'form': form, })
def stop(request, plugin_id): bacula_key, bacula_secret = utils.get_bacula_oauth_creds() url = utils.get_rpc_url(request) trans = OAuthTransport(url, key=bacula_key, secret=bacula_secret) server = jsonrpclib.Server(url, transport=trans) auth = server.plugins.is_authenticated( request.COOKIES.get("sessionid", "")) jail_path = server.plugins.jail.path(plugin_id) assert auth try: bacula = models.BaculaSDService.objects.order_by('-id')[0] bacula.enable = False bacula.save() except IndexError: bacula = models.BaculaSDService.objects.create(enable=False) try: form = forms.BaculaSDServiceForm(bacula.__dict__, instance=bacula) form.is_valid() form.save() except ValueError: pass cmd = "%s onestop" % utils.bacula_control pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True, close_fds=True) out = pipe.communicate()[0] return HttpResponse(simplejson.dumps({ 'error': False, 'message': out, }), content_type='application/json')
def start(request, plugin_id): bacula_key, bacula_secret = utils.get_bacula_oauth_creds() url = utils.get_rpc_url(request) trans = OAuthTransport(url, key=bacula_key, secret=bacula_secret) server = jsonrpclib.Server(url, transport=trans) auth = server.plugins.is_authenticated(request.COOKIES.get( "sessionid", "")) jail_path = server.plugins.jail.path(plugin_id) assert auth try: bacula = models.BaculaSDService.objects.order_by('-id')[0] bacula.enable = True bacula.save() except IndexError: bacula = models.BaculaSDService.objects.create(enable=True) try: form = forms.BaculaSDServiceForm(bacula.__dict__, instance=bacula) form.is_valid() form.save() except ValueError: raise return HttpResponse(simplejson.dumps({ 'error': True, 'message': 'Bacula data did not validate, configure it first.', }), content_type='application/json') cmd = "%s onestart" % utils.bacula_control pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True, close_fds=True) out = pipe.communicate()[0] return HttpResponse(simplejson.dumps({ 'error': False, 'message': out, }), content_type='application/json')
def edit(request, plugin_id): bacula_key, bacula_secret = utils.get_bacula_oauth_creds() url = utils.get_rpc_url(request) trans = OAuthTransport(url, key=bacula_key, secret=bacula_secret) """ Get the Bacula object If it does not exist create a new entry """ try: bacula = models.BaculaSDStorage.objects.order_by('-id')[0] except IndexError: bacula = models.BaculaSDStorage.objects.create() try: server = jsonrpclib.Server(url, transport=trans) jail_path = server.plugins.jail.path(plugin_id) auth = server.plugins.is_authenticated( request.COOKIES.get("sessionid", "")) assert auth except Exception: raise if request.method == "GET": form = forms.BaculaSDStorageForm(instance=bacula, jail_path=jail_path) return render(request, "edit.html", { 'form': form, }) if not request.POST: return JsonResponse(request, error=True, message="A problem occurred.") form = forms.BaculaSDStorageForm(request.POST, instance=bacula, jail_path=jail_path) if form.is_valid(): form.save() return JsonResponse(request, error=True, message="Bacula settings successfully saved.") return JsonResponse(request, form=form)
def _generic_delete(request, plugin_id, oid, model): bacula_key, bacula_secret = utils.get_bacula_oauth_creds() url = utils.get_rpc_url(request) trans = OAuthTransport(url, key=bacula_key, secret=bacula_secret) server = jsonrpclib.Server(url, transport=trans) jail_path = server.plugins.jail.path(plugin_id) instance = model.objects.get(id=oid) if request.method == "POST": instance.delete() return JsonResponse( request, message="%s deleted" % (model._meta.verbose_name, ), events=["refreshTree()"], ) return render(request, "generic_delete.html", { 'instance': instance, })
def _generic_delete(request, oid, model): bacula_key, bacula_secret = utils.get_bacula_oauth_creds() url = utils.get_rpc_url(request) trans = OAuthTransport(url, key=bacula_key, secret=bacula_secret) server = jsonrpclib.Server(url, transport=trans) jail_path = server.plugins.jail.path(plugin_id) instance = model.objects.get(id=oid) if request.method == "POST": instance.delete() return JsonResponse(request, message="%s deleted" % (model._meta.verbose_name, ), events=["refreshTree()"], ) return render(request, "generic_delete.html", { 'instance': instance, })
def devices_edit(request, plugin_id, oid): bacula_key, bacula_secret = utils.get_bacula_oauth_creds() url = utils.get_rpc_url(request) trans = OAuthTransport(url, key=bacula_key, secret=bacula_secret) server = jsonrpclib.Server(url, transport=trans) jail_path = server.plugins.jail.path(plugin_id) instance = models.BaculaSDDevice.objects.get(id=oid) delete_url = reverse('bacula_devices_delete', kwargs={ 'plugin_id': plugin_id, 'oid': instance.id }) if request.method == "POST": form = forms.BaculaSDDeviceForm(request.POST, instance=instance, jail_path=jail_path) if form.is_valid(): form.save() return JsonResponse( request, message="Device updated", events=["refreshTree()"], ) return JsonResponse(request, tpl="devices_edit.html", ctx={ 'form': form, 'delete_url': delete_url, }) else: form = forms.BaculaSDDeviceForm(instance=instance, jail_path=jail_path) return render(request, "devices_edit.html", { 'form': form, 'delete_url': delete_url, })