コード例 #1
0
ファイル: views.py プロジェクト: n5hc/hamwan-portal
    def get_object(self, queryset=None):
        """ Hook to ensure object is owned by request.user. """
        obj = super(RecordDelete, self).get_object()
        subdomain = "%s.nmhamwan.net" % self.request.user.username.lower()
        subnets = Subnet.objects.filter(owner=self.request.user)

        if obj.name != subdomain and not obj.name.endswith(".%s" % subdomain):
            # name doesn't end with user.nmhamwan.net, check reverse
            try:
                ip = IPAddress(reverse(obj.name))
            except ValueError:
                raise Http404
            if not any([(ip in subnet.network) for subnet in subnets]):
                # reverse is not valid either
                raise Http404
        return obj
コード例 #2
0
ファイル: views.py プロジェクト: turnrye/hamwan-portal
    def get_object(self, queryset=None):
        """ Hook to ensure object is owned by request.user. """
        obj = super(RecordDelete, self).get_object()
        subdomain = "%s.%s" % (self.request.user.username.lower(), ROOT_DOMAIN)
        subnets = Subnet.objects.filter(owner=self.request.user)

        if obj.name != subdomain and \
           not obj.name.endswith(".%s" % subdomain):
            # name doesn't end with user.hamwan.net, check reverse
            try:
                ip = IPAddress(reverse(obj.name))
            except ValueError:
                raise Http404
            if not any([(ip in subnet.network) for subnet in subnets]):
                # reverse is not valid either
                raise Http404
        return obj
コード例 #3
0
ファイル: createptr.py プロジェクト: HamWAN/hamwan-portal
    def handle(self, *args, **options):
        if len(args) == 0:
            network, pattern = self.defaultnetwork, self.defaultpattern
        if len(args) == 1:
            network, pattern = IPNetwork(args[0]), self.defaultpattern
        if len(args) == 2:
            network, pattern = IPNetwork(args[0]), args[1]

        for ip in network.iterhosts():
            name = reverse(ip)
            content = pattern % dict(
                [(str(k), v) for k, v in enumerate(str(ip).split('.'))])

            # print "%s\tcreated: %s" % (
            #     Record.objects.get_or_create(domain=self.get_domain(content),
            #         name=content, type='A', defaults={'content': str(ip)}))
            print "%s\t\tcreated: %s" % (
                Record.objects.get_or_create(domain=self.get_domain(name),
                    name=name, type='PTR', defaults={'content': content}))
コード例 #4
0
ファイル: createptr.py プロジェクト: turnrye/hamwan-portal
    def handle(self, *args, **options):
        if len(args) == 0:
            network, pattern = self.defaultnetwork, self.defaultpattern
        if len(args) == 1:
            network, pattern = IPNetwork(args[0]), self.defaultpattern
        if len(args) == 2:
            network, pattern = IPNetwork(args[0]), args[1]

        for ip in network.iterhosts():
            name = reverse(ip)
            content = pattern % dict(
                [(str(k), v) for k, v in enumerate(str(ip).split('.'))])

            # print "%s\tcreated: %s" % (
            #     Record.objects.get_or_create(domain=self.get_domain(content),
            #         name=content, type='A', defaults={'content': str(ip)}))
            print "%s\t\tcreated: %s" % (Record.objects.get_or_create(
                domain=self.get_domain(name),
                name=name,
                type='PTR',
                defaults={'content': content}))