Пример #1
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
Пример #2
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