mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2025-01-07 19:05:39 +00:00
Allow update zone kind the domain setting page
This commit is contained in:
parent
798b7abb5b
commit
1d973d1614
@ -355,6 +355,49 @@ class Domain(db.Model):
|
|||||||
'msg': 'Cannot change soa-edit-api this domain.'
|
'msg': 'Cannot change soa-edit-api this domain.'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def update_kind(self, domain_name, kind, masters=[]):
|
||||||
|
"""
|
||||||
|
Update zone kind: Native / Master / Slave
|
||||||
|
"""
|
||||||
|
domain = Domain.query.filter(Domain.name == domain_name).first()
|
||||||
|
if not domain:
|
||||||
|
return {'status': 'error', 'msg': 'Domain doesnt exist.'}
|
||||||
|
headers = {}
|
||||||
|
headers['X-API-Key'] = self.PDNS_API_KEY
|
||||||
|
|
||||||
|
post_data = {"kind": kind, "masters": masters}
|
||||||
|
|
||||||
|
try:
|
||||||
|
jdata = utils.fetch_json(urljoin(
|
||||||
|
self.PDNS_STATS_URL, self.API_EXTENDED_URL +
|
||||||
|
'/servers/localhost/zones/{0}'.format(domain.name)),
|
||||||
|
headers=headers,
|
||||||
|
timeout=int(
|
||||||
|
Setting().get('pdns_api_timeout')),
|
||||||
|
method='PUT',
|
||||||
|
data=post_data)
|
||||||
|
if 'error' in jdata.keys():
|
||||||
|
current_app.logger.error(jdata['error'])
|
||||||
|
return {'status': 'error', 'msg': jdata['error']}
|
||||||
|
else:
|
||||||
|
current_app.logger.info(
|
||||||
|
'Update domain kind for {0} successfully'.format(
|
||||||
|
domain_name))
|
||||||
|
return {
|
||||||
|
'status': 'ok',
|
||||||
|
'msg': 'Domain kind changed successfully'
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.error(
|
||||||
|
'Cannot update kind for domain {0}. Error: {1}'.format(
|
||||||
|
domain_name, e))
|
||||||
|
current_app.logger.debug(traceback.format_exc())
|
||||||
|
|
||||||
|
return {
|
||||||
|
'status': 'error',
|
||||||
|
'msg': 'Cannot update kind for this domain.'
|
||||||
|
}
|
||||||
|
|
||||||
def create_reverse_domain(self, domain_name, domain_reverse_name):
|
def create_reverse_domain(self, domain_name, domain_reverse_name):
|
||||||
"""
|
"""
|
||||||
Check the existing reverse lookup domain,
|
Check the existing reverse lookup domain,
|
||||||
|
@ -114,6 +114,7 @@ def add():
|
|||||||
'errors/400.html',
|
'errors/400.html',
|
||||||
msg="Please enter a valid domain name"), 400
|
msg="Please enter a valid domain name"), 400
|
||||||
|
|
||||||
|
#TODO: Validate ip addresses input
|
||||||
if domain_type == 'slave':
|
if domain_type == 'slave':
|
||||||
if request.form.getlist('domain_master_address'):
|
if request.form.getlist('domain_master_address'):
|
||||||
domain_master_string = request.form.getlist(
|
domain_master_string = request.form.getlist(
|
||||||
@ -258,6 +259,47 @@ def setting(domain_name):
|
|||||||
return redirect(url_for('domain.setting', domain_name=domain_name))
|
return redirect(url_for('domain.setting', domain_name=domain_name))
|
||||||
|
|
||||||
|
|
||||||
|
@domain_bp.route('/setting/<path:domain_name>/change_type',
|
||||||
|
methods=['POST'])
|
||||||
|
@login_required
|
||||||
|
@operator_role_required
|
||||||
|
def change_type(domain_name):
|
||||||
|
domain = Domain.query.filter(Domain.name == domain_name).first()
|
||||||
|
if not domain:
|
||||||
|
abort(404)
|
||||||
|
domain_type = request.form.get('domain_type')
|
||||||
|
if domain_type is None:
|
||||||
|
abort(500)
|
||||||
|
if domain_type == '0':
|
||||||
|
return redirect(url_for('domain.setting', domain_name=domain_name))
|
||||||
|
|
||||||
|
#TODO: Validate ip addresses input
|
||||||
|
domain_master_ips = []
|
||||||
|
if domain_type == 'slave' and request.form.getlist('domain_master_address'):
|
||||||
|
domain_master_string = request.form.getlist(
|
||||||
|
'domain_master_address')[0]
|
||||||
|
domain_master_string = domain_master_string.replace(
|
||||||
|
' ', '')
|
||||||
|
domain_master_ips = domain_master_string.split(',')
|
||||||
|
|
||||||
|
d = Domain()
|
||||||
|
status = d.update_kind(domain_name=domain_name,
|
||||||
|
kind=domain_type,
|
||||||
|
masters=domain_master_ips)
|
||||||
|
if status['status'] == 'ok':
|
||||||
|
history = History(msg='Update type for domain {0}'.format(domain_name),
|
||||||
|
detail=str({
|
||||||
|
"domain": domain_name,
|
||||||
|
"type": domain_type,
|
||||||
|
"masters": domain_master_ips
|
||||||
|
}),
|
||||||
|
created_by=current_user.username)
|
||||||
|
history.add()
|
||||||
|
return redirect(url_for('domain.setting', domain_name = domain_name))
|
||||||
|
else:
|
||||||
|
abort(500)
|
||||||
|
|
||||||
|
|
||||||
@domain_bp.route('/setting/<path:domain_name>/change_soa_setting',
|
@domain_bp.route('/setting/<path:domain_name>/change_soa_setting',
|
||||||
methods=['POST'])
|
methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
@ -275,18 +317,16 @@ def change_soa_edit_api(domain_name):
|
|||||||
d = Domain()
|
d = Domain()
|
||||||
status = d.update_soa_setting(domain_name=domain_name,
|
status = d.update_soa_setting(domain_name=domain_name,
|
||||||
soa_edit_api=new_setting)
|
soa_edit_api=new_setting)
|
||||||
if status['status'] != None:
|
if status['status'] == 'ok':
|
||||||
users = User.query.all()
|
history = History(
|
||||||
accounts = Account.query.all()
|
msg='Update soa_edit_api for domain {0}'.format(domain_name),
|
||||||
d = Domain(name=domain_name)
|
detail=str({
|
||||||
domain_user_ids = d.get_user()
|
"domain": domain_name,
|
||||||
account = d.get_account()
|
"soa_edit_api": new_setting
|
||||||
return render_template('domain_setting.html',
|
}),
|
||||||
domain=domain,
|
created_by=current_user.username)
|
||||||
users=users,
|
history.add()
|
||||||
domain_user_ids=domain_user_ids,
|
return redirect(url_for('domain.setting', domain_name = domain_name))
|
||||||
accounts=accounts,
|
|
||||||
domain_account=account)
|
|
||||||
else:
|
else:
|
||||||
abort(500)
|
abort(500)
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
Native - PowerDNS will not perform any replication. Use this if you only have one
|
Native - PowerDNS will not perform any replication. Use this if you only have one
|
||||||
PowerDNS server or you handle replication via your backend (MySQL).
|
PowerDNS server or you handle replication via your backend.
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
Master - This PowerDNS server will serve as the master and will send zone transfers
|
Master - This PowerDNS server will serve as the master and will send zone transfers
|
||||||
|
@ -134,6 +134,50 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<div class="box">
|
||||||
|
<div class="box-header">
|
||||||
|
<h3 class="box-title">Change Type</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
<p>The type decides how the domain will be replicated across multiple DNS servers.</p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
Native - PowerDNS will not perform any replication. Use this if you only have one
|
||||||
|
PowerDNS server or you handle replication via your backend.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Master - This PowerDNS server will serve as the master and will send zone transfers
|
||||||
|
(AXFRs) to other servers configured as slaves.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Slave - This PowerDNS server will serve as the slave and will request and receive
|
||||||
|
zone transfers (AXFRs) from other servers configured as masters.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<b>New Domain Type Setting:</b>
|
||||||
|
<form method="post" action="{{ url_for('domain.change_type', domain_name=domain.name) }}">
|
||||||
|
<input type="hidden" name="_csrf_token" value="{{ csrf_token() }}">
|
||||||
|
<select name="domain_type" class="form-control" style="width:15em;">
|
||||||
|
<option selected value="0">- Unchanged -</option>
|
||||||
|
<option value="native">Native</option>
|
||||||
|
<option value="master">Master</option>
|
||||||
|
<option value="slave">Slave</option>
|
||||||
|
</select><br />
|
||||||
|
<div class="form-group" style="display: none;" id="domain_master_address_div">
|
||||||
|
<input type="text" class="form-control" name="domain_master_address"
|
||||||
|
id="domain_master_address"
|
||||||
|
placeholder="Enter valid master ip addresses (separated by commas)">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-flat btn-primary" id="change_type">
|
||||||
|
<i class="fa fa-check"></i> Change type for {{ domain.name }}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
@ -254,8 +298,18 @@
|
|||||||
modal.modal('hide');
|
modal.modal('hide');
|
||||||
})
|
})
|
||||||
modal.modal('show');
|
modal.modal('show');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// domain master address input handeling
|
||||||
|
$("select[name=domain_type]").change(function () {
|
||||||
|
var type = $(this).val();
|
||||||
|
if (type == "slave") {
|
||||||
|
$("#domain_master_address_div").show();
|
||||||
|
} else {
|
||||||
|
$("#domain_master_address_div").hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block modals %}
|
{% block modals %}
|
||||||
|
Loading…
Reference in New Issue
Block a user