log.debug("Failed to get jail %d: %s", jail_id, repr(e)) jail = None if request.method == "POST": jc = JailsConfiguration.objects.order_by("-id")[0] logfile = '%s/warden.log' % jc.jc_path if os.path.exists(logfile): os.unlink(logfile) if os.path.exists(WARDEN_EXTRACT_STATUS_FILE): os.unlink(WARDEN_EXTRACT_STATUS_FILE) if os.path.exists("/tmp/.plugin_upload_install"): os.unlink("/tmp/.plugin_upload_install") if os.path.exists("/tmp/.jailcreate"): os.unlink("/tmp/.jailcreate") form = forms.PBIUploadForm(request.POST, request.FILES, jail=jail) if form.is_valid(): form.done() return JsonResp( request, message=_('Plugin successfully installed'), events=['reloadHttpd()'], ) else: resp = render(request, "plugins/upload.html", { 'form': form, }) resp.content = ("<html><body><textarea>" + resp.content + "</textarea></boby></html>") return resp else:
def upload(request, jail_id=-1): try: jc = JailsConfiguration.objects.all()[0] except: jc = None # FIXME: duplicated code with available_install try: if not jail_path_configured(): jail_auto_configure() if not jc: jc = JailsConfiguration.objects.all()[0] if not jc.jc_ipv4_dhcp: addrs = guess_addresses() if not addrs['high_ipv4']: raise MiddlewareError(_("No available IP addresses")) except MiddlewareError as e: return render(request, "plugins/install_error.html", { 'error': e.value, }) plugin_upload_path = notifier().get_plugin_upload_path() notifier().change_upload_location(plugin_upload_path) jail = None if jail_id > 0: try: jail = Jails.objects.filter(pk=jail_id)[0] except Exception as e: log.debug("Failed to get jail %d: %s", jail_id, repr(e)) jail = None if request.method == "POST": jc = JailsConfiguration.objects.order_by("-id")[0] logfile = '%s/warden.log' % jc.jc_path if os.path.exists(logfile): os.unlink(logfile) if os.path.exists(WARDEN_EXTRACT_STATUS_FILE): os.unlink(WARDEN_EXTRACT_STATUS_FILE) if os.path.exists("/tmp/.plugin_upload_install"): os.unlink("/tmp/.plugin_upload_install") if os.path.exists("/tmp/.jailcreate"): os.unlink("/tmp/.jailcreate") form = forms.PBIUploadForm(request.POST, request.FILES, jail=jail) if form.is_valid(): form.done() return JsonResp( request, message=_('Plugin successfully installed'), events=['reloadHttpd()'], ) else: resp = render(request, "plugins/upload.html", { 'form': form, }) resp.content = ("<html><body><textarea>" + resp.content + "</textarea></boby></html>") return resp else: form = forms.PBIUploadForm(jail=jail) return render(request, "plugins/upload.html", { 'form': form, })