示例#1
0
    def __init__(self, *args, **kwargs):
        super(JailCreateForm, self).__init__(*args, **kwargs)
        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
        types = ((jt.jt_name, jt.jt_name) for jt in JailTemplate.objects.all())

        self.fields['jail_type'].choices = types
        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();"
        )

        addrs = guess_addresses()

        if addrs['high_ipv4']:
            parts = str(addrs['high_ipv4']).split('/')
            self.fields['jail_ipv4'].initial = parts[0]
            if len(parts) > 1:
                self.fields['jail_ipv4_netmask'].initial = parts[1]

        if addrs['high_ipv6']:
            parts = str(addrs['high_ipv6']).split('/')
            self.fields['jail_ipv6'].initial = parts[0]
            if len(parts) > 1:
                self.fields['jail_ipv6_prefix'].initial = parts[1]

        if addrs['bridge_ipv4']:
            parts = str(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]

        if addrs['bridge_ipv6']:
            parts = str(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]
示例#2
0
    def __init__(self, *args, **kwargs):
        super(JailCreateForm, self).__init__(*args, **kwargs)
        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
        types = ((jt.jt_name, jt.jt_name) for jt in JailTemplate.objects.all())

        self.fields['jail_type'].choices = types
        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();"
        )

        addrs = guess_addresses()

        if addrs['high_ipv4']:
            parts = str(addrs['high_ipv4']).split('/')
            self.fields['jail_ipv4'].initial = parts[0]
            if len(parts) > 1:
                self.fields['jail_ipv4_netmask'].initial = parts[1]

        if addrs['high_ipv6']:
            parts = str(addrs['high_ipv6']).split('/')
            self.fields['jail_ipv6'].initial = parts[0]
            if len(parts) > 1:
                self.fields['jail_ipv6_prefix'].initial = parts[1]

        if addrs['bridge_ipv4']:
            parts = str(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]

        if addrs['bridge_ipv6']:
            parts = str(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]
示例#3
0
文件: views.py 项目: jgehrcke/freenas
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})
示例#4
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,
        })
示例#5
0
文件: views.py 项目: jgehrcke/freenas
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})
示例#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,
        })
示例#7
0
文件: views.py 项目: sjagoe/freenas
def install_available(request, oid):
    try:
        if not jail_path_configured():
            jail_auto_configure()
        addrs = guess_addresses()
        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,
        })
示例#8
0
文件: views.py 项目: sjagoe/freenas
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(_(
                "You must configure your network interface and a default "
                "gateway"))
    except MiddlewareError, e:
        return render(request, "plugins/install_error.html", {
            'error': e.value,
        })
示例#9
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,
        })
示例#10
0
    def __init__(self, *args, **kwargs):
        super(JailCreateForm, self).__init__(*args, **kwargs)
        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

        os.environ['EXTRACT_TARBALL_STATUSFILE'] = self.statusfile
        types = ((jt.jt_name, jt.jt_name) for jt in JailTemplate.objects.all())

        self.fields['jail_type'].choices = types
        self.fields['jail_type'].widget.attrs['onChange'] = (
            "jail_type_toggle();"
        )
        self.fields['jail_32bit'].widget.attrs['onChange'] = (
            "jail_32bit_toggle();"
        )
        self.fields['jail_vnet'].widget.attrs['onChange'] = (
            "jail_vnet_toggle();"
        )
        self.fields['jail_nat'].widget.attrs['onChange'] = (
            "jail_nat_toggle();"
        )

        addrs = guess_addresses()

        if addrs['high_ipv6']:
            self.fields['jail_ipv6'].initial = addrs['high_ipv6']

        if addrs['high_ipv4']:
            self.fields['jail_ipv4'].initial = addrs['high_ipv4']

        if addrs['bridge_ipv4']:
            self.fields['jail_bridge_ipv4'].initial = addrs['bridge_ipv4']

        if addrs['bridge_ipv6']:
            self.fields['jail_bridge_ipv6'].initial = addrs['bridge_ipv6']
示例#11
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,
        })
示例#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,
        })
示例#13
0
文件: forms.py 项目: noprobs/freenas
    def __init__(self, *args, **kwargs):
        super(JailCreateForm, self).__init__(*args, **kwargs)
        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

        os.environ['EXTRACT_TARBALL_STATUSFILE'] = self.statusfile
        types = ((jt.jt_name, jt.jt_name) for jt in JailTemplate.objects.all())

        self.fields['jail_type'].choices = types
        self.fields['jail_type'].widget.attrs['onChange'] = (
            "jail_type_toggle();")
        self.fields['jail_32bit'].widget.attrs['onChange'] = (
            "jail_32bit_toggle();")
        self.fields['jail_vnet'].widget.attrs['onChange'] = (
            "jail_vnet_toggle();")
        self.fields['jail_nat'].widget.attrs['onChange'] = (
            "jail_nat_toggle();")

        addrs = guess_addresses()

        if addrs['high_ipv6']:
            self.fields['jail_ipv6'].initial = addrs['high_ipv6']

        if addrs['high_ipv4']:
            self.fields['jail_ipv4'].initial = addrs['high_ipv4']

        if addrs['bridge_ipv4']:
            self.fields['jail_bridge_ipv4'].initial = addrs['bridge_ipv4']

        if addrs['bridge_ipv6']:
            self.fields['jail_bridge_ipv6'].initial = addrs['bridge_ipv6']
示例#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,
        })
示例#15
0
文件: views.py 项目: binzyw/freenas
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,
    })
示例#16
0
文件: views.py 项目: binzyw/freenas
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,
    })
示例#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,
    })
示例#18
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,
    })