mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2025-06-14 20:16:05 +00:00
Migrate more config values to db
This commit is contained in:
@ -2,7 +2,7 @@ from functools import wraps
|
||||
from flask import g, request, redirect, url_for
|
||||
|
||||
from app import app
|
||||
from app.models import Role
|
||||
from app.models import Role, Setting
|
||||
|
||||
|
||||
def admin_role_required(f):
|
||||
@ -31,7 +31,7 @@ def can_access_domain(f):
|
||||
def can_configure_dnssec(f):
|
||||
@wraps(f)
|
||||
def decorated_function(*args, **kwargs):
|
||||
if g.user.role.name != 'Administrator' and app.config['DNSSEC_ADMINS_ONLY']:
|
||||
if g.user.role.name != 'Administrator' and Setting().get('dnssec_admins_only'):
|
||||
return redirect(url_for('error', code=401))
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
@ -9,6 +9,8 @@ import traceback
|
||||
import pyotp
|
||||
import re
|
||||
import dns.reversename
|
||||
import dns.inet
|
||||
import dns.name
|
||||
import sys
|
||||
import logging as logger
|
||||
|
||||
@ -24,14 +26,6 @@ from app.lib import utils
|
||||
logging = logger.getLogger(__name__)
|
||||
|
||||
|
||||
if 'PRETTY_IPV6_PTR' in app.config.keys():
|
||||
import dns.inet
|
||||
import dns.name
|
||||
PRETTY_IPV6_PTR = app.config['PRETTY_IPV6_PTR']
|
||||
else:
|
||||
PRETTY_IPV6_PTR = False
|
||||
|
||||
|
||||
class Anonymous(AnonymousUserMixin):
|
||||
def __init__(self):
|
||||
self.username = 'Anonymous'
|
||||
@ -1244,6 +1238,7 @@ class Record(object):
|
||||
self.PDNS_API_KEY = Setting().get('pdns_api_key')
|
||||
self.PDNS_VERSION = Setting().get('pdns_version')
|
||||
self.API_EXTENDED_URL = utils.pdns_api_extended_uri(self.PDNS_VERSION)
|
||||
self.PRETTY_IPV6_PTR = Setting().get('pretty_ipv6_ptr')
|
||||
|
||||
if StrictVersion(self.PDNS_VERSION) >= StrictVersion('4.0.0'):
|
||||
self.NEW_SCHEMA = True
|
||||
@ -1266,7 +1261,7 @@ class Record(object):
|
||||
rrsets = jdata['rrsets']
|
||||
for rrset in rrsets:
|
||||
r_name = rrset['name'].rstrip('.')
|
||||
if PRETTY_IPV6_PTR: # only if activated
|
||||
if self.PRETTY_IPV6_PTR: # only if activated
|
||||
if rrset['type'] == 'PTR': # only ptr
|
||||
if 'ip6.arpa' in r_name: # only if v6-ptr
|
||||
r_name = dns.reversename.to_address(dns.name.from_text(r_name))
|
||||
@ -1371,7 +1366,7 @@ class Record(object):
|
||||
for r in post_records:
|
||||
r_name = domain if r['record_name'] in ['@', ''] else r['record_name'] + '.' + domain
|
||||
r_type = r['record_type']
|
||||
if PRETTY_IPV6_PTR: # only if activated
|
||||
if self.PRETTY_IPV6_PTR: # only if activated
|
||||
if self.NEW_SCHEMA: # only if new schema
|
||||
if r_type == 'PTR': # only ptr
|
||||
if ':' in r['record_name']: # dirty ipv6 check
|
||||
@ -1392,7 +1387,7 @@ class Record(object):
|
||||
for r in deleted_records:
|
||||
r_name = r['name'].rstrip('.') + '.' if self.NEW_SCHEMA else r['name']
|
||||
r_type = r['type']
|
||||
if PRETTY_IPV6_PTR: # only if activated
|
||||
if self.PRETTY_IPV6_PTR: # only if activated
|
||||
if self.NEW_SCHEMA: # only if new schema
|
||||
if r_type == 'PTR': # only ptr
|
||||
if ':' in r['name']: # dirty ipv6 check
|
||||
@ -1414,7 +1409,7 @@ class Record(object):
|
||||
if self.NEW_SCHEMA:
|
||||
r_name = r['name'].rstrip('.') + '.'
|
||||
r_type = r['type']
|
||||
if PRETTY_IPV6_PTR: # only if activated
|
||||
if self.PRETTY_IPV6_PTR: # only if activated
|
||||
if r_type == 'PTR': # only ptr
|
||||
if ':' in r['name']: # dirty ipv6 check
|
||||
r_name = r['name']
|
||||
@ -1459,7 +1454,7 @@ class Record(object):
|
||||
r_type = key[1]
|
||||
r_changetype = key[2]
|
||||
|
||||
if PRETTY_IPV6_PTR: # only if activated
|
||||
if self.PRETTY_IPV6_PTR: # only if activated
|
||||
if r_type == 'PTR': # only ptr
|
||||
if ':' in r_name: # dirty ipv6 check
|
||||
r_name = dns.reversename.from_address(r_name).to_text()
|
||||
@ -1792,6 +1787,9 @@ class Setting(db.Model):
|
||||
'default_domain_table_size': 10,
|
||||
'auto_ptr': False,
|
||||
'allow_quick_edit': True,
|
||||
'pretty_ipv6_ptr': False,
|
||||
'dnssec_admins_only': False,
|
||||
'bg_domain_updates': False,
|
||||
'site_name': 'PowerDNS-Admin',
|
||||
'pdns_api_url': '',
|
||||
'pdns_api_key': '',
|
||||
|
@ -236,7 +236,7 @@
|
||||
modal.modal('show');
|
||||
});
|
||||
|
||||
{% if current_user.role.name == 'Administrator' or dnssec_adm_only == false %}
|
||||
{% if current_user.role.name == 'Administrator' or not SETTING.get('dnssec_admins_only') %}
|
||||
$(document.body).on("click", ".button_dnssec", function() {
|
||||
var domain = $(this).prop('id');
|
||||
getdnssec($SCRIPT_ROOT + '/domain/' + domain + '/dnssec', domain);
|
||||
|
@ -442,7 +442,8 @@ def dashboard():
|
||||
if not Setting().get('pdns_api_url') or not Setting().get('pdns_api_key') or not Setting().get('pdns_version'):
|
||||
return redirect(url_for('admin_setting_pdns'))
|
||||
|
||||
if not app.config.get('BG_DOMAIN_UPDATES'):
|
||||
BG_DOMAIN_UPDATE = Setting().get('bg_domain_updates')
|
||||
if not BG_DOMAIN_UPDATE:
|
||||
logging.debug('Update domains in foreground')
|
||||
d = Domain().update()
|
||||
else:
|
||||
@ -460,7 +461,7 @@ def dashboard():
|
||||
else:
|
||||
uptime = 0
|
||||
|
||||
return render_template('dashboard.html', domain_count=domain_count, users=users, history_number=history_number, uptime=uptime, histories=history, dnssec_adm_only=app.config['DNSSEC_ADMINS_ONLY'], show_bg_domain_button=app.config['BG_DOMAIN_UPDATES'])
|
||||
return render_template('dashboard.html', domain_count=domain_count, users=users, history_number=history_number, uptime=uptime, histories=history, show_bg_domain_button=BG_DOMAIN_UPDATE)
|
||||
|
||||
|
||||
@app.route('/dashboard-domains', methods=['GET'])
|
||||
@ -573,7 +574,7 @@ def domain(domain_name):
|
||||
record = Record(name=jr['name'], type=jr['type'], status='Disabled' if subrecord['disabled'] else 'Active', ttl=jr['ttl'], data=subrecord['content'])
|
||||
records.append(record)
|
||||
if not re.search('ip6\.arpa|in-addr\.arpa$', domain_name):
|
||||
editable_records = app.config['RECORDS_ALLOW_EDIT']
|
||||
editable_records = app.config['FORWARD_RECORDS_ALLOW_EDIT']
|
||||
else:
|
||||
editable_records = app.config['REVERSE_RECORDS_ALLOW_EDIT']
|
||||
return render_template('domain.html', domain=domain, records=records, editable_records=editable_records, quick_edit=quick_edit)
|
||||
|
Reference in New Issue
Block a user