Zone list page and new zone form
Signed-off-by: Dustin C. Hatch <dustin@hatch.name>master
parent
4f5aa00041
commit
ad70b77db5
|
@ -71,22 +71,36 @@ class ZoneListController(BaseController):
|
||||||
response.content_type = 'application/json'
|
response.content_type = 'application/json'
|
||||||
json.dump(list(map(model.Zone.as_dict, zones)), response.body_file)
|
json.dump(list(map(model.Zone.as_dict, zones)), response.body_file)
|
||||||
else:
|
else:
|
||||||
response.text = self.render('index.html.j2', zones=zones)
|
if 'new' in request.GET:
|
||||||
|
response.text = self.render('new-zone.html.j2')
|
||||||
|
else:
|
||||||
|
response.text = self.render('index.html.j2', zones=zones)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
HEAD = GET
|
HEAD = GET
|
||||||
|
|
||||||
def POST(self, request):
|
def POST(self, request):
|
||||||
response = request.ResponseClass()
|
response = request.ResponseClass()
|
||||||
response.content_type = None
|
if request.content_type == 'application/x-www-form-urlencoded':
|
||||||
data = json.loads(request.text)
|
data = dict(request.POST)
|
||||||
|
elif request.content_type == 'application/json':
|
||||||
|
data = json.loads(request.text)
|
||||||
|
else:
|
||||||
|
raise milla.HTTPUnsupportedMediaType
|
||||||
|
required_fields = ('name', 'contact', 'source')
|
||||||
|
for k in list(data.keys()):
|
||||||
|
if not data[k]:
|
||||||
|
if k not in required_fields:
|
||||||
|
del data[k]
|
||||||
zone = model.Zone(**data)
|
zone = model.Zone(**data)
|
||||||
self.session.add(zone)
|
self.session.add(zone)
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
response.status_int = 201
|
location = request.create_href_full('/zones/{}'.format(zone.name))
|
||||||
response.location = request.create_href_full(
|
if request.want in ('html', 'xhtml'):
|
||||||
'/zones/{}'.format(zone.name)
|
raise milla.HTTPSeeOther(location=location)
|
||||||
)
|
else:
|
||||||
|
response.status_int = 201
|
||||||
|
response.location = location
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
{#- vim: set sw=2 ts=2 sts=2 et : -#}
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<title>{{ page_title }} :: DyNS</title>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link type="text/css" rel="stylesheet"
|
||||||
|
href="//cdnjs.cloudflare.com/ajax/libs/foundation/5.4.7/css/normalize.min.css" />
|
||||||
|
<link type="text/css" rel="stylesheet"
|
||||||
|
href="//cdnjs.cloudflare.com/ajax/libs/foundation/5.4.7/css/foundation.min.css" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<header class="row">
|
||||||
|
<h1 class="site-title">DyNS</h1>
|
||||||
|
<nav>
|
||||||
|
<ul class="breadcrumbs">
|
||||||
|
{%- block breadcrumbs %}{% endblock %}
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<h2>{{ page_title }}</h2>
|
||||||
|
{% block body %}{% endblock -%}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
|
@ -1,13 +1,27 @@
|
||||||
<!DOCTYPE html>
|
{#- vim: set sw=2 ts=2 sts=2 et : -#}
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
|
{% set page_title = 'Zones' -%}
|
||||||
<head>
|
{% extends 'base.html.j2' %}
|
||||||
<meta charset="UTF-8" />
|
{%- block breadcrumbs %}
|
||||||
<title>Zones</title>
|
<li class="current"><a href="{{ url('/zones/') }}">Zones</a></li>
|
||||||
</head>
|
{%- endblock %}
|
||||||
<body>
|
{% block body -%}
|
||||||
<h1>Zones</h1>
|
<a class="tiny button" href="?new">New Zone</a>
|
||||||
|
<table class="pretty" style="width: 100%;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Name</th>
|
||||||
|
<th scope="col">Contact</th>
|
||||||
|
<th scope="col">Serial</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
{% for zone in zones -%}
|
{% for zone in zones -%}
|
||||||
<div><a href="{{ zone.name }}">{{ zone.name }}</a></div>
|
<tr>
|
||||||
|
<td><a href="{{ zone.name }}">{{ zone.name }}</a></td>
|
||||||
|
<td>{{ zone.contact }}</td>
|
||||||
|
<td>{{ zone.serial }}</td>
|
||||||
|
</tr>
|
||||||
{% endfor -%}
|
{% endfor -%}
|
||||||
</body>
|
</tbody>
|
||||||
</html>
|
</table>
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
{#- vim: set sw=2 ts=2 sts=2 et : -#}
|
||||||
|
{% set page_title = 'New Zone' %}
|
||||||
|
{% extends 'base.html.j2' %}
|
||||||
|
{%- block breadcrumbs %}
|
||||||
|
<li><a href="{{ url('/zones/') }}">Zones</a></li>
|
||||||
|
<li class="current"><a href="{{ url('/zones/') }}?new">New Zone</a></li>
|
||||||
|
{%- endblock %}
|
||||||
|
{% block body -%}
|
||||||
|
<form method="post">
|
||||||
|
{% set domain_regex = '(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\\.)+[a-zA-Z]{2,63}$)' %}
|
||||||
|
{% set fqdn_regex = '(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\\.)+[a-zA-Z]{2,63}\\.?$)' %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="columns">
|
||||||
|
<label>Name:
|
||||||
|
<input type="text" name="name" required="requred"
|
||||||
|
pattern="{{ domain_regex }}" placeholder="example.com"
|
||||||
|
x-moz-errormessage="Please enter a valid DNS domain name." />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="medium-4 columns">
|
||||||
|
<label>Contact:
|
||||||
|
<input type="text" name="contact" required="required"
|
||||||
|
pattern="{{ fqdn_regex }}" placeholder="hostmaster.example.com."
|
||||||
|
x-moz-errormessage="Please enter a valid fully-qualified DNS domain name." />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="medium-4 columns">
|
||||||
|
<label>Source:
|
||||||
|
<input type="text" name="source" required="requred"
|
||||||
|
pattern="{{ fqdn_regex }}" placeholder="ns1.example.com."
|
||||||
|
x-moz-errormessage="Please enter a valid fully-qualified DNS domain name." />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="medium-4 columns">
|
||||||
|
<label>Serial:
|
||||||
|
<input type="number" name="serial" placeholder="1024" />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="large-2 medium-4 columns">
|
||||||
|
<label><abbr title="Time To Live">TTL</abbr>:
|
||||||
|
<input type="number" name="ttl" placeholder="3600" />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="large-2 medium-4 columns">
|
||||||
|
<label>Refresh Interval:
|
||||||
|
<input type="number" name="refresh" placeholder="900" />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="large-2 medium-4 columns">
|
||||||
|
<label>Retry Interval:
|
||||||
|
<input type="number" name="retry" placeholder="600" />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="large-2 medium-4 columns">
|
||||||
|
<label>Expiry Time:
|
||||||
|
<input type="number" name="expire" placeholder="86400" />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="large-3 medium-4 columns">
|
||||||
|
<label>Minumum (default) <abbr title="Time To Live">TTL</abbr>:
|
||||||
|
<input type="number" name="minimum" placeholder="3600" />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="large-1 medium-4 columns"></div>
|
||||||
|
</div>
|
||||||
|
<div class="row text-right">
|
||||||
|
<div class="columns">
|
||||||
|
<button class="small button" type="submit">Submit</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
Reference in New Issue