register api auth errors/success in the host record, display auth success/failure in host view, partially fixes #176
This commit is contained in:
parent
11f9e8b3bf
commit
b8e37e904d
@ -139,9 +139,14 @@ def check_api_auth(username, password):
|
|||||||
host = Host.get_by_fqdn(fqdn)
|
host = Host.get_by_fqdn(fqdn)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return None
|
return None
|
||||||
if host is None or not check_password(password, host.update_secret):
|
if host is not None:
|
||||||
return None
|
ok = check_password(password, host.update_secret)
|
||||||
return host
|
success_msg = ('failure', 'success')[ok]
|
||||||
|
msg = "api authentication %s. [hostname: %s (given in basic auth)]" % (success_msg, fqdn, )
|
||||||
|
host.register_api_auth_result(msg, fault=not ok)
|
||||||
|
if ok:
|
||||||
|
return host
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def check_session_auth(user, hostname):
|
def check_session_auth(user, hostname):
|
||||||
|
26
nsupdate/main/migrations/0004_auto_20141115_2349.py
Normal file
26
nsupdate/main/migrations/0004_auto_20141115_2349.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0003_auto_20141115_2230'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='host',
|
||||||
|
name='api_auth_faults',
|
||||||
|
field=models.PositiveIntegerField(default=0, verbose_name='api auth faults'),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='host',
|
||||||
|
name='api_auth_result_msg',
|
||||||
|
field=models.CharField(default=b'', max_length=255, blank=True, help_text='Latest result message relating to api authentication', null=True, verbose_name='api auth result msg'),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
|
]
|
@ -220,6 +220,14 @@ class Host(models.Model):
|
|||||||
default='', blank=True, null=True,
|
default='', blank=True, null=True,
|
||||||
help_text=_("Latest result message relating to the server"))
|
help_text=_("Latest result message relating to the server"))
|
||||||
|
|
||||||
|
# count api auth errors - maybe caused by host owner (misconfigured update client)
|
||||||
|
api_auth_faults = models.PositiveIntegerField(_("api auth faults"), default=0)
|
||||||
|
api_auth_result_msg = models.CharField(
|
||||||
|
_("api auth result msg"),
|
||||||
|
max_length=RESULT_MSG_LEN,
|
||||||
|
default='', blank=True, null=True,
|
||||||
|
help_text=_("Latest result message relating to api authentication"))
|
||||||
|
|
||||||
# when we received the last update for v4/v6 addr
|
# when we received the last update for v4/v6 addr
|
||||||
last_update_ipv4 = models.DateTimeField(_("last update IPv4"), blank=True, null=True)
|
last_update_ipv4 = models.DateTimeField(_("last update IPv4"), blank=True, null=True)
|
||||||
last_update_ipv6 = models.DateTimeField(_("last update IPv6"), blank=True, null=True)
|
last_update_ipv6 = models.DateTimeField(_("last update IPv6"), blank=True, null=True)
|
||||||
@ -296,6 +304,12 @@ class Host(models.Model):
|
|||||||
self.server_result_msg = result_fmt(msg)
|
self.server_result_msg = result_fmt(msg)
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
def register_api_auth_result(self, msg, fault=False):
|
||||||
|
if fault:
|
||||||
|
self.api_auth_faults += 1
|
||||||
|
self.api_auth_result_msg = result_fmt(msg)
|
||||||
|
self.save()
|
||||||
|
|
||||||
def generate_secret(self, secret=None):
|
def generate_secret(self, secret=None):
|
||||||
# note: we use a quick hasher for the update_secret as expensive
|
# note: we use a quick hasher for the update_secret as expensive
|
||||||
# more modern hashes might put too much load on the servers. also
|
# more modern hashes might put too much load on the servers. also
|
||||||
|
@ -131,6 +131,8 @@
|
|||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h3>{% trans "Result Messages" %}</h3>
|
<h3>{% trans "Result Messages" %}</h3>
|
||||||
<form>
|
<form>
|
||||||
|
<label for="api_auth_result_msg">{% trans "API Authentication Result Message" %}</label>
|
||||||
|
<input class="form-control" type="text" maxlength="255" id="api_auth_result_msg" value="{{ host.api_auth_result_msg }}" disabled>
|
||||||
<label for="client_result_msg">{% trans "Client Result Message" %}</label>
|
<label for="client_result_msg">{% trans "Client Result Message" %}</label>
|
||||||
<input class="form-control" type="text" maxlength="255" id="client_result_msg" value="{{ host.client_result_msg }}" disabled>
|
<input class="form-control" type="text" maxlength="255" id="client_result_msg" value="{{ host.client_result_msg }}" disabled>
|
||||||
<label for="server_result_msg">{% trans "Server Result Message" %}</label>
|
<label for="server_result_msg">{% trans "Server Result Message" %}</label>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user