forked from ninuxorg/nodeshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
executable file
·192 lines (156 loc) · 5.66 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# models for nodeshot DNS (integration with powerDNS).
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.contenttypes import generic
from django.contrib.auth.models import User
from nodeshot.core.base.models import BaseDate
from nodeshot.core.nodes.models import Zone, Node
from nodeshot.core.network.models import Device, Interface
import hashlib
ACCESS_LEVELS = (
('owner', _('owner')),
('manager', _('manager'))
)
DOMAIN_TYPE = (
'NATIVE',
'MASTER',
'SLAVE',
'SUPERSLAVE'
)
RECORD_TYPE = ( #Can be implemented into a table with USER_RECORD_TYPE
'A',
'AAAA',
'AFSDB',
'CERT',
'CNAME',
'DNSKEY',
'DS',
'HINFO',
'KEY',
'LOC',
'MX',
'NAPTR',
'NS',
'NSEC',
'PTR',
'RP',
'RRSIG',
'SOA',
'SPF',
'SSHFP',
'SRV',
'TXT'
)
USER_RECORD_TYPE = (
'A',
'AAAA',
'CNAME',
'MX'
)
class Domain(BaseDate):
"""
Domain PowerDNS table
"""
name = models.CharField(_('name'), max_length=255, unique=True, db_index=True)
type = models.CharField(_('type'),max_length=6, choices=((x,x) for x in DOMAIN_TYPE))
notified_serial = models.PositiveIntegerField(_('notified serial'), null=True, blank=True, default=None)
master = models.CharField(_('master'),max_length=128, null=True,blank=True, default=None)
last_check = models.PositiveIntegerField(_('last check'), null=True, blank=True, default=None)
account = models.CharField(_('account'), max_length=40, null=True, blank=True, default=None)
class Meta:
db_table = 'domains'
ordering = ('name', 'type')
def __unicode__(self):
return self.name
class Record(BaseDate):
"""
Record PowerDNS table
"""
domain = models.ForeignKey('Domain', verbose_name=_('domain'))
name = models.CharField(_('name'), max_length=255, db_index=True)
type = models.CharField(_('type'),max_length=6, db_index=True, choices=((x,x) for x in RECORD_TYPE))
content = models.CharField(_('content'),max_length=255)
ttl = models.PositiveIntegerField()
prio = models.PositiveIntegerField(_('priority'), null=True, blank=True)
change_date = models.PositiveIntegerField(_('change date'), null=True, blank=True)
is_automatized = models.BooleanField(_('is automatized'), default=False)
md5hash = models.CharField(_('hash'), max_length=32, null=True, blank=True)
class Meta:
db_table = 'records'
ordering = ('name', 'type')
unique_together = ('name', 'type', 'content')
def __unicode__(self):
return self.name
def save(self, *args, **kwargs):
id_hash = hashlib.md5(self.name + self.type + self.content).hexdigest()
self.md5hash = id_hash
super(Record, self).save(*args, **kwargs)
class Supermaster(BaseDate):
"""
Supermaster PowerDNS table (deprecated)
"""
nameserver = models.CharField(max_length=255, db_index=True)
account = models.CharField(max_length=40, null=True, blank=True, db_index=True)
class Meta:
db_table = 'supermasters'
ordering = ('nameserver', 'account')
unique_together = ('nameserver', 'account')
def __unicode__(self):
return self.nameserver
"""
OneToOne tables for customize automatic DNS names
"""
class ZoneToDns(models.Model):
zone = models.OneToOneField(Zone, db_index=True, unique=True)
value = models.SlugField(_('value'), max_length=20)
def __unicode__(self):
return self.value
class NodeToDns(models.Model):
node = models.OneToOneField(Node, db_index=True, unique=True)
value = models.SlugField(_('value'), max_length=20)
def __unicode__(self):
return self.value
class DeviceToDns(models.Model):
device = models.OneToOneField(Device, db_index=True, unique=True)
value = models.SlugField(_('value'), max_length=20)
def __unicode__(self):
return self.value
class InterfaceToDns(models.Model):
interface = models.OneToOneField(Interface, db_index=True)
value = models.SlugField(_('value'), max_length=20)
def __unicode__(self):
return self.value
class DomainPolicy(BaseDate):
"""
Domains and Subdomains restrictions and policies for users
"""
name = models.CharField(max_length=255, db_index=True, unique=True)
domain = models.ForeignKey(Domain)
is_automatized = models.BooleanField(default=False)
can_request = models.IntegerField(default=0)
needs_confirmation = models.BooleanField(default=False)
managers = models.ManyToManyField(User, through='DomainManager', verbose_name=_('name'))
def __unicode__(self):
return u'%s' % self.domain.name
class DomainManager(BaseDate):
"""
ManyToMany relation between users and (sub)domains
"""
user = models.ForeignKey(User)
domain = models.ForeignKey(DomainPolicy)
access_level = models.CharField(_('access level'), max_length=10, choices=ACCESS_LEVELS)
class Meta:
unique_together = ('user', 'domain')
class UserRecord(Record):
"""
User's Records table
"""
user = models.ForeignKey(User)
class DNSScriptCache(models.Model):
"""
DNS Script Caching table
name is the domain without the extension
content is the IPv4/IPv6 Address
"""
name = models.CharField(_('name'), max_length=255)
content = models.CharField(max_length=29)