Example #1
0
def install_available(request, oid):
    try:
        if not jail_path_configured():
            jail_auto_configure()
        addrs = guess_addresses()
        if not addrs["high_ipv4"]:
            raise MiddlewareError(_("No available IP addresses"))
    except MiddlewareError, e:
        return render(request, "plugins/install_error.html", {"error": e.value})
Example #2
0
def install_available(request, oid):

    try:
        if not jail_path_configured():
            jail_auto_configure()
        addrs = guess_adresses()
        if not addrs["high_ipv4"]:
            raise MiddlewareError(_("You must configure your network interface and a default " "gateway"))
    except MiddlewareError, e:
        return render(request, "plugins/install_error.html", {"error": e.value})
Example #3
0
def install_available(request, oid):
    try:
        if not jail_path_configured():
            jail_auto_configure()
        addrs = guess_addresses()
        if not addrs['high_ipv4']:
            raise MiddlewareError(_("No available IP addresses"))
    except MiddlewareError, e:
        return render(request, "plugins/install_error.html", {
            'error': e.value,
        })
Example #4
0
def upload(request, jail_id=-1):

    # FIXME: duplicated code with available_install
    try:
        if not jail_path_configured():
            jail_auto_configure()
        addrs = guess_addresses()
        if not addrs["high_ipv4"]:
            raise MiddlewareError(_("No available IP addresses"))
    except MiddlewareError, e:
        return render(request, "plugins/install_error.html", {"error": e.value})
Example #5
0
def upload(request, jail_id=-1):

    # FIXME: duplicated code with available_install
    try:
        if not jail_path_configured():
            jail_auto_configure()
        addrs = guess_adresses()
        if not addrs["high_ipv4"]:
            raise MiddlewareError(_("You must configure your network interface and a default " "gateway"))
    except MiddlewareError, e:
        return render(request, "plugins/install_error.html", {"error": e.value})
Example #6
0
def upload(request, jail_id=-1):

    #FIXME: duplicated code with available_install
    try:
        if not jail_path_configured():
            jail_auto_configure()
        addrs = guess_addresses()
        if not addrs['high_ipv4']:
            raise MiddlewareError(_("No available IP addresses"))
    except MiddlewareError, e:
        return render(request, "plugins/install_error.html", {
            'error': e.value,
        })
Example #7
0
def install_available(request, oid):

    try:
        if not jail_path_configured():
            jail_auto_configure()
        addrs = guess_adresses()
        if not addrs['high_ipv4']:
            raise MiddlewareError(
                _("You must configure your network interface and a default "
                  "gateway"))
    except MiddlewareError, e:
        return render(request, "plugins/install_error.html", {
            'error': e.value,
        })
Example #8
0
def reset_plugin_progress():

    if not jail_path_configured():
        jail_auto_configure()

    jc = JailsConfiguration.objects.order_by("-id")[0]
    logfile = '%s/warden.log' % jc.jc_path

    safe_unlink(logfile)
    safe_unlink(WARDEN_EXTRACT_STATUS_FILE)
    safe_unlink("/tmp/.plugin_upload_install")
    safe_unlink("/tmp/.jailcreate")
    safe_unlink(PROGRESS_FILE)
    safe_unlink("/tmp/.fetchmtree")
    safe_unlink("/tmp/.checkmtree")
Example #9
0
def reset_plugin_progress():

    if not jail_path_configured():
        jail_auto_configure()

    jc = JailsConfiguration.objects.order_by("-id")[0]
    logfile = '%s/warden.log' % jc.jc_path

    safe_unlink(logfile)
    safe_unlink(WARDEN_EXTRACT_STATUS_FILE)
    safe_unlink("/tmp/.plugin_upload_install")
    safe_unlink("/tmp/.jailcreate")
    safe_unlink(PROGRESS_FILE)
    safe_unlink("/tmp/.fetchmtree")
    safe_unlink("/tmp/.checkmtree")
Example #10
0
def upload(request, jail_id=-1):

    #FIXME: duplicated code with available_install
    try:
        if not jail_path_configured():
            jail_auto_configure()
        addrs = guess_adresses()
        if not addrs['high_ipv4']:
            raise MiddlewareError(
                _("You must configure your network interface and a default "
                  "gateway"))
    except MiddlewareError, e:
        return render(request, "plugins/install_error.html", {
            'error': e.value,
        })
Example #11
0
def upload(request, jail_id=-1):
    jc = JailsConfiguration.objects.all()[0]

    #FIXME: duplicated code with available_install
    try:
        if not jail_path_configured():
            jail_auto_configure()

        if not jc.jc_ipv4_dhcp:
            addrs = guess_addresses()
            if not addrs['high_ipv4']:
                raise MiddlewareError(_("No available IP addresses"))

    except MiddlewareError, e:
        return render(request, "plugins/install_error.html", {
            'error': e.value,
        })
Example #12
0
def install_available(request, oid):

    try:
        jc = JailsConfiguration.objects.all()[0]
    except IndexError:
        jc = JailsConfiguration.objects.create()

    try:
        if not jail_path_configured():
            jail_auto_configure()

        if not jc.jc_ipv4_dhcp:
            addrs = guess_addresses()
            if not addrs['high_ipv4']:
                raise MiddlewareError(_("No available IP addresses"))

    except MiddlewareError, e:
        return render(request, "plugins/install_error.html", {
            'error': e.value,
        })
Example #13
0
def install_available(request, oid):

    try:
        jc = JailsConfiguration.objects.all()[0]
    except IndexError:
        jc = JailsConfiguration.objects.create()

    try:
        if not jail_path_configured():
            jail_auto_configure()

        if not jc.jc_ipv4_dhcp:
            addrs = guess_addresses()
            if not addrs['high_ipv4']:
                raise MiddlewareError(_("No available IP addresses"))

    except MiddlewareError, e:
        return render(request, "plugins/install_error.html", {
            'error': e.value,
        })
Example #14
0
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, e:
        return render(request, "plugins/install_error.html", {
            'error': e.value,
        })
Example #15
0
def upload(request, jail_id=-1):
    jail_id = int(jail_id)
    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,
    })
Example #16
0
def install_available(request, oid):

    try:
        jc = JailsConfiguration.objects.all()[0]
    except IndexError:
        jc = JailsConfiguration.objects.create()

    try:
        if not jail_path_configured():
            jail_auto_configure()

        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,
        })

    if os.path.exists("/tmp/.plugin_upload_update"):
        os.unlink("/tmp/.plugin_upload_update")
    if os.path.exists(PROGRESS_FILE):
        os.unlink(PROGRESS_FILE)

    plugin = None
    for p in availablePlugins.get_remote(cache=True):
        if p.id == oid:
            plugin = p
            break

    if not plugin:
        raise MiddlewareError(_("Invalid plugin"))

    if request.method == "POST":

        plugin_upload_path = notifier().get_plugin_upload_path()
        notifier().change_upload_location(plugin_upload_path)

        if not plugin.download("/var/tmp/firmware/pbifile.pbi"):
            raise MiddlewareError(_("Failed to download plugin"))

        try:
            jail = new_default_plugin_jail(plugin.unixname)
        except IOError as e:
            raise MiddlewareError(str(e))
        except MiddlewareError as e:
            raise e
        except Exception as e:
            raise MiddlewareError(str(e))

        newplugin = []
        if notifier().install_pbi(jail.jail_host, newplugin):
            newplugin = newplugin[0]
            notifier()._restart_plugins(
                jail=newplugin.plugin_jail,
                plugin=newplugin.plugin_name,
            )
        else:
            jail.delete()

        return JsonResp(
            request,
            message=_("Plugin successfully installed"),
            events=['reloadHttpd()'],
        )

    return render(request, "plugins/available_install.html", {
        'plugin': plugin,
    })
Example #17
0
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,
    })
Example #18
0
    def __init__(self, *args, **kwargs):
        super(JailCreateForm, self).__init__(*args, **kwargs)

        if not jail_path_configured():
            jail_auto_configure()

        try:
            self.jc = JailsConfiguration.objects.order_by("-id")[0]
        except Exception as e:
            raise MiddlewareError(e)

        self.logfile = "/var/tmp/warden.log"
        self.statusfile = "/var/tmp/status"
        try:
            os.unlink(self.logfile)
        except:
            pass
        try:
            os.unlink(self.statusfile)
        except:
            pass

        arch = platform.architecture()
        if arch[0] == '64bit':
            arch = 'x64'
        else:
            arch = 'x86'
        self.arch = arch

        os.environ['EXTRACT_TARBALL_STATUSFILE'] = self.statusfile
        self.fields['jail_type'].choices = choices.JAIL_TEMPLATE_CHOICES()
        self.fields['jail_type'].widget.attrs['onChange'] = (
            "jail_type_toggle();"
        )
        self.fields['jail_vnet'].widget.attrs['onChange'] = (
            "jail_vnet_toggle();"
        )
        self.fields['jail_nat'].widget.attrs['onChange'] = (
            "jail_nat_toggle();"
        )
        self.fields['jail_ipv4_dhcp'].widget.attrs['onChange'] = (
            "jail_ipv4_dhcp_toggle();"
        )
        self.fields['jail_ipv6_autoconf'].widget.attrs['onChange'] = (
            "jail_ipv6_autoconf_toggle();"
        )

        if not self.jc.jc_ipv4_dhcp:
            ipv4_addrs = guess_ipv4_addresses()
            if ipv4_addrs['high_ipv4']:
                parts = str(ipv4_addrs['high_ipv4']).split('/')
                self.fields['jail_ipv4'].initial = parts[0]
                if len(parts) > 1:
                    self.fields['jail_ipv4_netmask'].initial = parts[1]

            if ipv4_addrs['bridge_ipv4']:
                parts = str(ipv4_addrs['bridge_ipv4']).split('/')
                self.fields['jail_bridge_ipv4'].initial = parts[0]
                if len(parts) > 1:
                    self.fields['jail_bridge_ipv4_netmask'].initial = parts[1]
        else:
            self.fields['jail_ipv4_dhcp'].initial = True

        if not self.jc.jc_ipv6_autoconf:
            ipv6_addrs = guess_ipv6_addresses()
            if ipv6_addrs['high_ipv6']:
                parts = str(ipv6_addrs['high_ipv6']).split('/')
                self.fields['jail_ipv6'].initial = parts[0]
                if len(parts) > 1:
                    self.fields['jail_ipv6_prefix'].initial = parts[1]

            if ipv6_addrs['bridge_ipv6']:
                parts = str(ipv6_addrs['bridge_ipv6']).split('/')
                self.fields['jail_bridge_ipv6'].initial = parts[0]
                if len(parts) > 1:
                    self.fields['jail_bridge_ipv6_prefix'].initial = parts[1]
        else:
            self.fields['jail_ipv6_autoconf'].initial = True
Example #19
0
    def __init__(self, *args, **kwargs):
        super(JailCreateForm, self).__init__(*args, **kwargs)

        if not jail_path_configured():
            jail_auto_configure()

        try:
            self.jc = JailsConfiguration.objects.order_by("-id")[0]
        except Exception as e:
            raise MiddlewareError(e)

        self.logfile = "/var/tmp/warden.log"
        self.statusfile = "/var/tmp/status"
        try:
            os.unlink(self.logfile)
        except:
            pass
        try:
            os.unlink(self.statusfile)
        except:
            pass

        arch = platform.architecture()
        if arch[0] == '64bit':
            arch = 'x64'
        else:
            arch = 'x86'
        self.arch = arch

        os.environ['EXTRACT_TARBALL_STATUSFILE'] = self.statusfile
        self.fields['jail_type'].choices = choices.JAIL_TEMPLATE_CHOICES()
        self.fields['jail_type'].widget.attrs['onChange'] = (
            "jail_type_toggle();"
        )
        self.fields['jail_vnet'].widget.attrs['onChange'] = (
            "jail_vnet_toggle();"
        )
        self.fields['jail_nat'].widget.attrs['onChange'] = (
            "jail_nat_toggle();"
        )
        self.fields['jail_ipv4_dhcp'].widget.attrs['onChange'] = (
            "jail_ipv4_dhcp_toggle();"
        )
        self.fields['jail_ipv6_autoconf'].widget.attrs['onChange'] = (
            "jail_ipv6_autoconf_toggle();"
        )

        if not self.jc.jc_ipv4_dhcp:
            ipv4_addrs = guess_ipv4_addresses()
            if ipv4_addrs['high_ipv4']:
                parts = str(ipv4_addrs['high_ipv4']).split('/')
                self.fields['jail_ipv4'].initial = parts[0]
                if len(parts) > 1:
                    self.fields['jail_ipv4_netmask'].initial = parts[1]

            if ipv4_addrs['bridge_ipv4']:
                parts = str(ipv4_addrs['bridge_ipv4']).split('/')
                self.fields['jail_bridge_ipv4'].initial = parts[0]
                if len(parts) > 1:
                    self.fields['jail_bridge_ipv4_netmask'].initial = parts[1]
        else:
            self.fields['jail_ipv4_dhcp'].initial = True

        if not self.jc.jc_ipv6_autoconf:
            ipv6_addrs = guess_ipv6_addresses()
            if ipv6_addrs['high_ipv6']:
                parts = str(ipv6_addrs['high_ipv6']).split('/')
                self.fields['jail_ipv6'].initial = parts[0]
                if len(parts) > 1:
                    self.fields['jail_ipv6_prefix'].initial = parts[1]

            if ipv6_addrs['bridge_ipv6']:
                parts = str(ipv6_addrs['bridge_ipv6']).split('/')
                self.fields['jail_bridge_ipv6'].initial = parts[0]
                if len(parts) > 1:
                    self.fields['jail_bridge_ipv6_prefix'].initial = parts[1]
        else:
            self.fields['jail_ipv6_autoconf'].initial = True
Example #20
0
def install_available(request, oid):

    try:
        jc = JailsConfiguration.objects.all()[0]
    except IndexError:
        jc = JailsConfiguration.objects.create()

    try:
        if not jail_path_configured():
            jail_auto_configure()

        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,
        })

    if os.path.exists("/tmp/.plugin_upload_update"):
        os.unlink("/tmp/.plugin_upload_update")
    if os.path.exists(PROGRESS_FILE):
        os.unlink(PROGRESS_FILE)

    plugin = None
    for p in availablePlugins.get_remote(cache=True):
        if p.id == oid:
            plugin = p
            break

    if not plugin:
        raise MiddlewareError(_("Invalid plugin"))

    if request.method == "POST":

        plugin_upload_path = notifier().get_plugin_upload_path()
        notifier().change_upload_location(plugin_upload_path)

        if not plugin.download("/var/tmp/firmware/pbifile.pbi"):
            raise MiddlewareError(_("Failed to download plugin"))

        try:
            jail = new_default_plugin_jail(plugin.unixname)
        except IOError as e:
            raise MiddlewareError(str(e))
        except MiddlewareError as e:
            raise e
        except Exception as e:
            raise MiddlewareError(str(e))

        newplugin = []
        if notifier().install_pbi(jail.jail_host, newplugin):
            newplugin = newplugin[0]
            notifier()._restart_plugins(
                jail=newplugin.plugin_jail,
                plugin=newplugin.plugin_name,
            )
        else:
            jail.delete()

        return JsonResp(
            request,
            message=_("Plugin successfully installed"),
            events=['reloadHttpd()'],
        )

    return render(request, "plugins/available_install.html", {
        'plugin': plugin,
    })