service updater (host configs): add (give|accept)_(ipv4|ipv6) fields
This commit is contained in:
parent
4589dd512b
commit
2aeb2a61f8
@ -73,6 +73,8 @@ def db_init(db): # note: db is a predefined fixture and required here to have t
|
||||
name='nsupdate',
|
||||
server=SERVER,
|
||||
secure=SECURE,
|
||||
accept_ipv4=True,
|
||||
accept_ipv6=False,
|
||||
created_by=u,
|
||||
)
|
||||
ServiceUpdaterHostConfig.objects.create(
|
||||
@ -81,6 +83,8 @@ def db_init(db): # note: db is a predefined fixture and required here to have t
|
||||
password=_PASSWORD,
|
||||
service=s,
|
||||
host=h,
|
||||
give_ipv4=True,
|
||||
give_ipv6=False,
|
||||
created_by=u,
|
||||
)
|
||||
|
||||
|
@ -264,18 +264,21 @@ def _update(host, hostname, ipaddr, agent='unknown', ssl=False, logger=None):
|
||||
update(hostname, ipaddr)
|
||||
logger.info('%s - received good update -> ip: %s ssl: %r' % (hostname, ipaddr, ssl))
|
||||
# now check if there are other services we shall relay updates to:
|
||||
for uc in host.serviceupdaterhostconfigs.all():
|
||||
kwargs = dict(
|
||||
name=uc.name, password=uc.password,
|
||||
hostname=uc.hostname, myip=ipaddr,
|
||||
server=uc.service.server, path=uc.service.path, secure=uc.service.secure,
|
||||
)
|
||||
try:
|
||||
ddns_client.dyndns2_update(**kwargs)
|
||||
except Exception:
|
||||
# we never want to crash here
|
||||
kwargs.pop('password')
|
||||
logger.exception("the dyndns2 updater raised an exception [%r]" % kwargs)
|
||||
for hc in host.serviceupdaterhostconfigs.all():
|
||||
if (kind == 'ipv4' and hc.give_ipv4 and hc.service.accept_ipv4
|
||||
or
|
||||
kind == 'ipv6' and hc.give_ipv6 and hc.service.accept_ipv6):
|
||||
kwargs = dict(
|
||||
name=hc.name, password=hc.password,
|
||||
hostname=hc.hostname, myip=ipaddr,
|
||||
server=hc.service.server, path=hc.service.path, secure=hc.service.secure,
|
||||
)
|
||||
try:
|
||||
ddns_client.dyndns2_update(**kwargs)
|
||||
except Exception:
|
||||
# we never want to crash here
|
||||
kwargs.pop('password')
|
||||
logger.exception("the dyndns2 updater raised an exception [%r]" % kwargs)
|
||||
return Response('good %s' % ipaddr)
|
||||
except SameIpError:
|
||||
logger.warning('%s - received no-change update, ip: %s ssl: %r' % (hostname, ipaddr, ssl))
|
||||
|
@ -0,0 +1,153 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Adding field 'ServiceUpdater.accept_ipv4'
|
||||
db.add_column(u'main_serviceupdater', 'accept_ipv4',
|
||||
self.gf('django.db.models.fields.BooleanField')(default=False),
|
||||
keep_default=False)
|
||||
|
||||
# Adding field 'ServiceUpdater.accept_ipv6'
|
||||
db.add_column(u'main_serviceupdater', 'accept_ipv6',
|
||||
self.gf('django.db.models.fields.BooleanField')(default=False),
|
||||
keep_default=False)
|
||||
|
||||
# Adding field 'ServiceUpdaterHostConfig.give_ipv4'
|
||||
db.add_column(u'main_serviceupdaterhostconfig', 'give_ipv4',
|
||||
self.gf('django.db.models.fields.BooleanField')(default=False),
|
||||
keep_default=False)
|
||||
|
||||
# Adding field 'ServiceUpdaterHostConfig.give_ipv6'
|
||||
db.add_column(u'main_serviceupdaterhostconfig', 'give_ipv6',
|
||||
self.gf('django.db.models.fields.BooleanField')(default=False),
|
||||
keep_default=False)
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
# Deleting field 'ServiceUpdater.accept_ipv4'
|
||||
db.delete_column(u'main_serviceupdater', 'accept_ipv4')
|
||||
|
||||
# Deleting field 'ServiceUpdater.accept_ipv6'
|
||||
db.delete_column(u'main_serviceupdater', 'accept_ipv6')
|
||||
|
||||
# Deleting field 'ServiceUpdaterHostConfig.give_ipv4'
|
||||
db.delete_column(u'main_serviceupdaterhostconfig', 'give_ipv4')
|
||||
|
||||
# Deleting field 'ServiceUpdaterHostConfig.give_ipv6'
|
||||
db.delete_column(u'main_serviceupdaterhostconfig', 'give_ipv6')
|
||||
|
||||
|
||||
models = {
|
||||
u'auth.group': {
|
||||
'Meta': {'object_name': 'Group'},
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
|
||||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
|
||||
},
|
||||
u'auth.permission': {
|
||||
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
|
||||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
},
|
||||
u'auth.user': {
|
||||
'Meta': {'object_name': 'User'},
|
||||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
|
||||
},
|
||||
u'contenttypes.contenttype': {
|
||||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
|
||||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
|
||||
},
|
||||
u'main.blacklisteddomain': {
|
||||
'Meta': {'object_name': 'BlacklistedDomain'},
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'created_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'blacklisted_domains'", 'to': u"orm['auth.User']"}),
|
||||
'domain': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'last_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
|
||||
},
|
||||
u'main.domain': {
|
||||
'Meta': {'object_name': 'Domain'},
|
||||
'available': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'comment': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True', 'blank': 'True'}),
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'created_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'domains'", 'to': u"orm['auth.User']"}),
|
||||
'domain': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'last_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||
'nameserver_ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}),
|
||||
'nameserver_update_algorithm': ('django.db.models.fields.CharField', [], {'default': "'HMAC_SHA512'", 'max_length': '16'}),
|
||||
'nameserver_update_secret': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '88'}),
|
||||
'public': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
|
||||
},
|
||||
u'main.host': {
|
||||
'Meta': {'unique_together': "(('subdomain', 'domain'),)", 'object_name': 'Host'},
|
||||
'client_faults': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
|
||||
'comment': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True', 'blank': 'True'}),
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'created_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'hosts'", 'to': u"orm['auth.User']"}),
|
||||
'domain': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['main.Domain']"}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'last_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||
'last_update_ipv4': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'last_update_ipv6': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'server_faults': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
|
||||
'ssl_update_ipv4': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'ssl_update_ipv6': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'subdomain': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'update_secret': ('django.db.models.fields.CharField', [], {'max_length': '64'})
|
||||
},
|
||||
u'main.serviceupdater': {
|
||||
'Meta': {'object_name': 'ServiceUpdater'},
|
||||
'accept_ipv4': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'accept_ipv6': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'comment': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True', 'blank': 'True'}),
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'created_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'serviceupdater'", 'to': u"orm['auth.User']"}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'last_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
|
||||
'path': ('django.db.models.fields.CharField', [], {'default': "'/nic/update'", 'max_length': '255'}),
|
||||
'secure': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'server': ('django.db.models.fields.CharField', [], {'max_length': '255'})
|
||||
},
|
||||
u'main.serviceupdaterhostconfig': {
|
||||
'Meta': {'object_name': 'ServiceUpdaterHostConfig'},
|
||||
'comment': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True', 'blank': 'True'}),
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'created_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'serviceupdaterhostconfigs'", 'to': u"orm['auth.User']"}),
|
||||
'give_ipv4': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'give_ipv6': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'host': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'serviceupdaterhostconfigs'", 'to': u"orm['main.Host']"}),
|
||||
'hostname': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True', 'blank': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'last_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'service': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['main.ServiceUpdater']"})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['main']
|
@ -248,6 +248,10 @@ class ServiceUpdater(models.Model):
|
||||
default=True,
|
||||
help_text="Use https / SSL to contact the Update Server?")
|
||||
|
||||
# what kind(s) of IPs is (are) acceptable to this service:
|
||||
accept_ipv4 = models.BooleanField(default=False)
|
||||
accept_ipv6 = models.BooleanField(default=False)
|
||||
|
||||
last_update = models.DateTimeField(auto_now=True)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='serviceupdater')
|
||||
@ -277,6 +281,10 @@ class ServiceUpdaterHostConfig(models.Model):
|
||||
max_length=255, # should be enough
|
||||
help_text="The password/secret for that service (used for http basic auth)")
|
||||
|
||||
# what kind(s) of IPs should be given to this service:
|
||||
give_ipv4 = models.BooleanField(default=False)
|
||||
give_ipv6 = models.BooleanField(default=False)
|
||||
|
||||
host = models.ForeignKey(Host, on_delete=models.CASCADE, related_name='serviceupdaterhostconfigs')
|
||||
|
||||
last_update = models.DateTimeField(auto_now=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user