Change string to new format

This commit is contained in:
Khanh Ngo 2018-04-01 07:57:41 +07:00
parent 65da9a7a4f
commit 1c54f008f4
2 changed files with 68 additions and 70 deletions

View File

@ -123,10 +123,10 @@ class User(db.Model):
return str(self.id) # python 3 return str(self.id) # python 3
def __repr__(self): def __repr__(self):
return '<User %r>' % (self.username) return '<User {0}>'.format(self.username)
def get_totp_uri(self): def get_totp_uri(self):
return 'otpauth://totp/PowerDNS-Admin:%s?secret=%s&issuer=PowerDNS-Admin' % (self.username, self.otp_secret) return "otpauth://totp/PowerDNS-Admin:{0}?secret={1}&issuer=PowerDNS-Admin".format(self.username, self.otp_secret)
def verify_totp(self, token): def verify_totp(self, token):
totp = pyotp.TOTP(self.otp_secret) totp = pyotp.TOTP(self.otp_secret)
@ -226,11 +226,11 @@ class User(db.Model):
if LDAP_TYPE == 'ldap': if LDAP_TYPE == 'ldap':
ldap_user_dn = ldap.filter.escape_filter_chars(result[0][0][0]) ldap_user_dn = ldap.filter.escape_filter_chars(result[0][0][0])
logging.info(result[0][0][0]) logging.info(result[0][0][0])
if (self.ldap_search('(member=%s)' % ldap_user_dn ,LDAP_ADMIN_GROUP)): if (self.ldap_search('(member={0})'.format(ldap_user_dn) ,LDAP_ADMIN_GROUP)):
allowedlogin = True allowedlogin = True
isadmin = True isadmin = True
logging.info('User {0} is part of the "{1}" group that allows admin access to PowerDNS-Admin'.format(self.username,LDAP_ADMIN_GROUP)) logging.info('User {0} is part of the "{1}" group that allows admin access to PowerDNS-Admin'.format(self.username,LDAP_ADMIN_GROUP))
if (self.ldap_search('(member=%s)' % ldap_user_dn ,LDAP_USER_GROUP)): if (self.ldap_search('(member={0})'.format(ldap_user_dn) ,LDAP_USER_GROUP)):
#if (group == LDAP_USER_GROUP): #if (group == LDAP_USER_GROUP):
allowedlogin = True allowedlogin = True
logging.info('User {0} is part of the "{1}" group that allows user access to PowerDNS-Admin'.format(self.username,LDAP_USER_GROUP)) logging.info('User {0} is part of the "{1}" group that allows user access to PowerDNS-Admin'.format(self.username,LDAP_USER_GROUP))
@ -372,7 +372,7 @@ class User(db.Model):
return True return True
except: except:
db.session.rollback() db.session.rollback()
logging.error('Cannot delete user %s from DB' % self.username) logging.error('Cannot delete user {0} from DB'.format(self.username))
return False return False
def revoke_privilege(self): def revoke_privilege(self):
@ -389,7 +389,7 @@ class User(db.Model):
return True return True
except: except:
db.session.rollback() db.session.rollback()
logging.error('Cannot revoke user %s privielges.' % self.username) logging.error('Cannot revoke user {0} privielges'.format(self.username))
return False return False
return False return False
@ -435,7 +435,7 @@ class Role(db.Model):
self.description = description self.description = description
def __repr__(self): def __repr__(self):
return '<Role %r>' % (self.name) return '<Role {0}r>'.format(self.name)
class DomainSetting(db.Model): class DomainSetting(db.Model):
__tablename__ = 'domain_setting' __tablename__ = 'domain_setting'
@ -451,7 +451,7 @@ class DomainSetting(db.Model):
self.value = value self.value = value
def __repr__(self): def __repr__(self):
return '<DomainSetting %r for $d>' % (setting, self.domain.name) return '<DomainSetting {0} for {1}>'.format(setting, self.domain.name)
def __eq__(self, other): def __eq__(self, other):
return self.setting == other.setting return self.setting == other.setting
@ -489,7 +489,7 @@ class Domain(db.Model):
self.dnssec = dnssec self.dnssec = dnssec
def __repr__(self): def __repr__(self):
return '<Domain %r>' % (self.name) return '<Domain {0}>'.format(self.name)
def add_setting(self, setting, value): def add_setting(self, setting, value):
try: try:
@ -497,7 +497,7 @@ class Domain(db.Model):
db.session.commit() db.session.commit()
return True return True
except Exception as e: except Exception as e:
logging.error('Can not create setting %s for domain %s. %s' % (setting, self.name, e)) logging.error('Can not create setting {0} for domain {1}. {2}'.format(setting, self.name, e))
return False return False
def get_domains(self): def get_domains(self):
@ -646,12 +646,11 @@ class Domain(db.Model):
logging.error(jdata['error']) logging.error(jdata['error'])
return {'status': 'error', 'msg': jdata['error']} return {'status': 'error', 'msg': jdata['error']}
else: else:
logging.info('Added domain %s successfully' % domain_name) logging.info('Added domain {0} successfully'.format(domain_name))
return {'status': 'ok', 'msg': 'Added domain successfully'} return {'status': 'ok', 'msg': 'Added domain successfully'}
except Exception as e: except Exception as e:
traceback.print_exc() logging.error('Cannot add domain {0}'.format(domain_name))
logging.error('Cannot add domain %s' % domain_name) logging.debug(traceback.print_exc())
logging.debug(e)
return {'status': 'error', 'msg': 'Cannot add this domain.'} return {'status': 'error', 'msg': 'Cannot add this domain.'}
def create_reverse_domain(self, domain_name, domain_reverse_name): def create_reverse_domain(self, domain_name, domain_reverse_name):
@ -674,7 +673,7 @@ class Domain(db.Model):
result = self.add(domain_reverse_name, 'Master', 'INCEPTION-INCREMENT', '', '') result = self.add(domain_reverse_name, 'Master', 'INCEPTION-INCREMENT', '', '')
self.update() self.update()
if result['status'] == 'ok': if result['status'] == 'ok':
history = History(msg='Add reverse lookup domain %s' % domain_reverse_name, detail=str({'domain_type': 'Master', 'domain_master_ips': ''}), created_by='System') history = History(msg='Add reverse lookup domain {0}'.format(domain_reverse_name), detail=str({'domain_type': 'Master', 'domain_master_ips': ''}), created_by='System')
history.add() history.add()
else: else:
return {'status': 'error', 'msg': 'Adding reverse lookup domain failed'} return {'status': 'error', 'msg': 'Adding reverse lookup domain failed'}
@ -716,13 +715,12 @@ class Domain(db.Model):
headers = {} headers = {}
headers['X-API-Key'] = PDNS_API_KEY headers['X-API-Key'] = PDNS_API_KEY
try: try:
jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s' % domain_name), headers=headers, method='DELETE') jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/{0}'.format(domain_name)), headers=headers, method='DELETE')
logging.info('Delete domain %s successfully' % domain_name) logging.info('Delete domain {0} successfully'.format(domain_name))
return {'status': 'ok', 'msg': 'Delete domain successfully'} return {'status': 'ok', 'msg': 'Delete domain successfully'}
except Exception as e: except Exception as e:
traceback.print_exc() logging.error('Cannot delete domain {0}'.format(domain_name))
logging.error('Cannot delete domain %s' % domain_name) logging.debug(traceback.print_exc())
logging.debug(e)
return {'status': 'error', 'msg': 'Cannot delete domain'} return {'status': 'error', 'msg': 'Cannot delete domain'}
def get_user(self): def get_user(self):
@ -754,7 +752,7 @@ class Domain(db.Model):
db.session.commit() db.session.commit()
except: except:
db.session.rollback() db.session.rollback()
logging.error('Cannot revoke user privielges on domain %s' % self.name) logging.error('Cannot revoke user privielges on domain {0}'.format(self.name))
try: try:
for uid in added_ids: for uid in added_ids:
@ -763,7 +761,7 @@ class Domain(db.Model):
db.session.commit() db.session.commit()
except: except:
db.session.rollback() db.session.rollback()
logging.error('Cannot grant user privielges to domain %s' % self.name) logging.error('Cannot grant user privielges to domain {0}'.format(self.name))
def update_from_master(self, domain_name): def update_from_master(self, domain_name):
@ -775,7 +773,7 @@ class Domain(db.Model):
headers = {} headers = {}
headers['X-API-Key'] = PDNS_API_KEY headers['X-API-Key'] = PDNS_API_KEY
try: try:
jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s/axfr-retrieve' % domain), headers=headers, method='PUT') jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/{0}/axfr-retrieve'.format(domain)), headers=headers, method='PUT')
return {'status': 'ok', 'msg': 'Update from Master successfully'} return {'status': 'ok', 'msg': 'Update from Master successfully'}
except: except:
return {'status': 'error', 'msg': 'There was something wrong, please contact administrator'} return {'status': 'error', 'msg': 'There was something wrong, please contact administrator'}
@ -791,7 +789,7 @@ class Domain(db.Model):
headers = {} headers = {}
headers['X-API-Key'] = PDNS_API_KEY headers['X-API-Key'] = PDNS_API_KEY
try: try:
jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s/cryptokeys' % domain.name), headers=headers, method='GET') jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/{0}/cryptokeys'.format(domain.name)), headers=headers, method='GET')
if 'error' in jdata: if 'error' in jdata:
return {'status': 'error', 'msg': 'DNSSEC is not enabled for this domain'} return {'status': 'error', 'msg': 'DNSSEC is not enabled for this domain'}
else: else:
@ -813,7 +811,7 @@ class DomainUser(db.Model):
self.user_id = user_id self.user_id = user_id
def __repr__(self): def __repr__(self):
return '<Domain_User %r %r>' % (self.domain_id, self.user_id) return '<Domain_User {0} {1}>'.format(self.domain_id, self.user_id)
class Record(object): class Record(object):
@ -836,7 +834,7 @@ class Record(object):
headers = {} headers = {}
headers['X-API-Key'] = PDNS_API_KEY headers['X-API-Key'] = PDNS_API_KEY
try: try:
jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s' % domain), headers=headers) jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/{0}'.format(domain)), headers=headers)
except: except:
logging.error("Cannot fetch domain's record data from remote powerdns api") logging.error("Cannot fetch domain's record data from remote powerdns api")
return False return False
@ -910,11 +908,11 @@ class Record(object):
} }
try: try:
jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s' % domain), headers=headers, method='PATCH', data=data) jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/{0}'.format(domain)), headers=headers, method='PATCH', data=data)
logging.debug(jdata) logging.debug(jdata)
return {'status': 'ok', 'msg': 'Record was added successfully'} return {'status': 'ok', 'msg': 'Record was added successfully'}
except Exception as e: except Exception as e:
logging.error("Cannot add record %s/%s/%s to domain %s. DETAIL: %s" % (self.name, self.type, self.data, domain, e)) logging.error("Cannot add record {0}/{1}/{2} to domain {3}. DETAIL: {4}".format(self.name, self.type, self.data, domain, e))
return {'status': 'error', 'msg': 'There was something wrong, please contact administrator'} return {'status': 'error', 'msg': 'There was something wrong, please contact administrator'}
@ -1144,7 +1142,7 @@ class Record(object):
self.delete(domain_reverse_name) self.delete(domain_reverse_name)
return {'status': 'ok', 'msg': 'Auto-PTR record was updated successfully'} return {'status': 'ok', 'msg': 'Auto-PTR record was updated successfully'}
except Exception as e: except Exception as e:
logging.error("Cannot update auto-ptr record changes to domain %s. DETAIL: %s" % (e, domain)) logging.error("Cannot update auto-ptr record changes to domain {0}. DETAIL: {1}".format(domain, e))
return {'status': 'error', 'msg': 'Auto-PTR creation failed. There was something wrong, please contact administrator.'} return {'status': 'error', 'msg': 'Auto-PTR creation failed. There was something wrong, please contact administrator.'}
def delete(self, domain): def delete(self, domain):
@ -1164,11 +1162,11 @@ class Record(object):
] ]
} }
try: try:
jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s' % domain), headers=headers, method='PATCH', data=data) jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/{0}'.format(domain)), headers=headers, method='PATCH', data=data)
logging.debug(jdata) logging.debug(jdata)
return {'status': 'ok', 'msg': 'Record was removed successfully'} return {'status': 'ok', 'msg': 'Record was removed successfully'}
except: except:
logging.error("Cannot remove record %s/%s/%s from domain %s" % (self.name, self.type, self.data, domain)) logging.error("Cannot remove record {0}/{1}/{2} from domain {3}".format(self.name, self.type, self.data, domain))
return {'status': 'error', 'msg': 'There was something wrong, please contact administrator'} return {'status': 'error', 'msg': 'There was something wrong, please contact administrator'}
def is_allowed_edit(self): def is_allowed_edit(self):
@ -1244,11 +1242,11 @@ class Record(object):
] ]
} }
try: try:
jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s' % domain), headers=headers, method='PATCH', data=data) jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/{0}'.format(domain)), headers=headers, method='PATCH', data=data)
logging.debug("dyndns data: " % data) logging.debug("dyndns data: {0}".format(data))
return {'status': 'ok', 'msg': 'Record was updated successfully'} return {'status': 'ok', 'msg': 'Record was updated successfully'}
except Exception as e: except Exception as e:
logging.error("Cannot add record %s/%s/%s to domain %s. DETAIL: %s" % (self.name, self.type, self.data, domain, e)) logging.error("Cannot add record {0}/{1}/{2} to domain {3}. DETAIL: {4}".format(self.name, self.type, self.data, domain, e))
return {'status': 'error', 'msg': 'There was something wrong, please contact administrator'} return {'status': 'error', 'msg': 'There was something wrong, please contact administrator'}
@ -1270,7 +1268,7 @@ class Server(object):
headers['X-API-Key'] = PDNS_API_KEY headers['X-API-Key'] = PDNS_API_KEY
try: try:
jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/%s/config' % self.server_id), headers=headers, method='GET') jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/{0}/config'.format(self.server_id)), headers=headers, method='GET')
return jdata return jdata
except: except:
logging.error("Can not get server configuration.") logging.error("Can not get server configuration.")
@ -1285,7 +1283,7 @@ class Server(object):
headers['X-API-Key'] = PDNS_API_KEY headers['X-API-Key'] = PDNS_API_KEY
try: try:
jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/%s/statistics' % self.server_id), headers=headers, method='GET') jdata = utils.fetch_json(urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/{0}/statistics'.format(self.server_id)), headers=headers, method='GET')
return jdata return jdata
except: except:
logging.error("Can not get server statistics.") logging.error("Can not get server statistics.")
@ -1307,7 +1305,7 @@ class History(db.Model):
self.created_by = created_by self.created_by = created_by
def __repr__(self): def __repr__(self):
return '<History %r>' % (self.msg) return '<History {0}>'.format(self.msg)
def add(self): def add(self):
""" """
@ -1369,7 +1367,7 @@ class Setting(db.Model):
db.session.commit() db.session.commit()
return True return True
except: except:
logging.error('Cannot set maintenance to %s' % mode) logging.error('Cannot set maintenance to {0}'.format(mode))
logging.debug(traceback.format_exc()) logging.debug(traceback.format_exc())
db.session.rollback() db.session.rollback()
return False return False
@ -1386,10 +1384,10 @@ class Setting(db.Model):
db.session.commit() db.session.commit()
return True return True
else: else:
logging.error('Setting %s does not exist' % setting) logging.error('Setting {0} does not exist'.format(setting))
return False return False
except: except:
logging.error('Cannot toggle setting %s' % setting) logging.error('Cannot toggle setting {0}'.format(setting))
logging.debug(traceback.format_exec()) logging.debug(traceback.format_exec())
db.session.rollback() db.session.rollback()
return False return False
@ -1404,10 +1402,10 @@ class Setting(db.Model):
db.session.commit() db.session.commit()
return True return True
else: else:
logging.error('Setting %s does not exist' % setting) logging.error('Setting {0} does not exist'.format(setting))
return False return False
except: except:
logging.error('Cannot edit setting %s' % setting) logging.error('Cannot edit setting {0}'.format(setting))
logging.debug(traceback.format_exec()) logging.debug(traceback.format_exec())
db.session.rollback() db.session.rollback()
return False return False
@ -1421,7 +1419,7 @@ class DomainTemplate(db.Model):
records = db.relationship('DomainTemplateRecord', back_populates='template', cascade="all, delete-orphan") records = db.relationship('DomainTemplateRecord', back_populates='template', cascade="all, delete-orphan")
def __repr__(self): def __repr__(self):
return '<DomainTemplate %s>' % self.name return '<DomainTemplate {0}>'.format(self.name)
def __init__(self, name=None, description=None): def __init__(self, name=None, description=None):
self.id = None self.id = None
@ -1474,7 +1472,7 @@ class DomainTemplateRecord(db.Model):
template = db.relationship('DomainTemplate', back_populates='records') template = db.relationship('DomainTemplate', back_populates='records')
def __repr__(self): def __repr__(self):
return '<DomainTemplateRecord %i>' % self.id return '<DomainTemplateRecord {0}>'.format(self.id)
def __init__(self, id=None, name=None, type=None, ttl=None, data=None, status=None): def __init__(self, id=None, name=None, type=None, ttl=None, data=None, status=None):
self.id = id self.id = id

View File

@ -154,7 +154,7 @@ def http_page_not_found(e):
def error(code, msg=None): def error(code, msg=None):
supported_code = ('400', '401', '404', '500') supported_code = ('400', '401', '404', '500')
if code in supported_code: if code in supported_code:
return render_template('errors/%s.html' % code, msg=msg), int(code) return render_template('errors/{0}.html'.format(code), msg=msg), int(code)
else: else:
return render_template('errors/404.html'), 404 return render_template('errors/404.html'), 404
@ -346,8 +346,8 @@ def dashboard_domains():
# History.created_on.desc() # History.created_on.desc()
order_by = [] order_by = []
for i in range(len(columns)): for i in range(len(columns)):
column_index = request.args.get("order[%d][column]" % i) column_index = request.args.get("order[{0}][column]".format(i))
sort_direction = request.args.get("order[%d][dir]" % i) sort_direction = request.args.get("order[{0}][dir]".format(i))
if column_index is None: if column_index is None:
break break
if sort_direction != "asc" and sort_direction != "desc": if sort_direction != "asc" and sort_direction != "desc":
@ -462,7 +462,7 @@ def domain_add():
d = Domain() d = Domain()
result = d.add(domain_name=domain_name, domain_type=domain_type, soa_edit_api=soa_edit_api, domain_master_ips=domain_master_ips) result = d.add(domain_name=domain_name, domain_type=domain_type, soa_edit_api=soa_edit_api, domain_master_ips=domain_master_ips)
if result['status'] == 'ok': if result['status'] == 'ok':
history = History(msg='Add domain %s' % domain_name, detail=str({'domain_type': domain_type, 'domain_master_ips': domain_master_ips}), created_by=current_user.username) history = History(msg='Add domain {0}'.format(domain_name), detail=str({'domain_type': domain_type, 'domain_master_ips': domain_master_ips}), created_by=current_user.username)
history.add() history.add()
if domain_template != '0': if domain_template != '0':
template = DomainTemplate.query.filter(DomainTemplate.id == domain_template).first() template = DomainTemplate.query.filter(DomainTemplate.id == domain_template).first()
@ -474,10 +474,10 @@ def domain_add():
r = Record() r = Record()
result = r.apply(domain_name, record_data) result = r.apply(domain_name, record_data)
if result['status'] == 'ok': if result['status'] == 'ok':
history = History(msg='Applying template %s to %s, created records successfully.' % (template.name, domain_name), detail=str(result), created_by=current_user.username) history = History(msg='Applying template {0} to {1}, created records successfully.'.format(template.name, domain_name), detail=str(result), created_by=current_user.username)
history.add() history.add()
else: else:
history = History(msg='Applying template %s to %s, FAILED to created records.' % (template.name, domain_name), detail=str(result), created_by=current_user.username) history = History(msg='Applying template {0} to {1}, FAILED to created records.'.format(template.name, domain_name), detail=str(result), created_by=current_user.username)
history.add() history.add()
return redirect(url_for('dashboard')) return redirect(url_for('dashboard'))
else: else:
@ -498,7 +498,7 @@ def domain_delete(domain_name):
if result['status'] == 'error': if result['status'] == 'error':
return redirect(url_for('error', code=500)) return redirect(url_for('error', code=500))
history = History(msg='Delete domain %s' % domain_name, created_by=current_user.username) history = History(msg='Delete domain {0}'.format(domain_name), created_by=current_user.username)
history.add() history.add()
return redirect(url_for('dashboard')) return redirect(url_for('dashboard'))
@ -531,7 +531,7 @@ def domain_management(domain_name):
# grant/revoke user privielges # grant/revoke user privielges
d.grant_privielges(new_user_list) d.grant_privielges(new_user_list)
history = History(msg='Change domain %s access control' % domain_name, detail=str({'user_has_access': new_user_list}), created_by=current_user.username) history = History(msg='Change domain {0} access control'.format(domain_name), detail=str({'user_has_access': new_user_list}), created_by=current_user.username)
history.add() history.add()
return redirect(url_for('domain_management', domain_name=domain_name)) return redirect(url_for('domain_management', domain_name=domain_name))
@ -551,7 +551,7 @@ def record_apply(domain_name):
r = Record() r = Record()
result = r.apply(domain_name, jdata) result = r.apply(domain_name, jdata)
if result['status'] == 'ok': if result['status'] == 'ok':
history = History(msg='Apply record changes to domain %s' % domain_name, detail=str(jdata), created_by=current_user.username) history = History(msg='Apply record changes to domain {0}'.format(domain_name), detail=str(jdata), created_by=current_user.username)
history.add() history.add()
return make_response(jsonify( result ), 200) return make_response(jsonify( result ), 200)
else: else:
@ -629,14 +629,14 @@ def admin_setdomainsetting(domain_name):
if setting: if setting:
if setting.set(new_value): if setting.set(new_value):
history = History(msg='Setting %s changed value to %s for %s' % (new_setting, new_value, domain.name), created_by=current_user.username) history = History(msg='Setting {0} changed value to {1} for {2}'.format(new_setting, new_value, domain.name), created_by=current_user.username)
history.add() history.add()
return make_response(jsonify( { 'status': 'ok', 'msg': 'Setting updated.' } )) return make_response(jsonify( { 'status': 'ok', 'msg': 'Setting updated.' } ))
else: else:
return make_response(jsonify( { 'status': 'error', 'msg': 'Unable to set value of setting.' } )) return make_response(jsonify( { 'status': 'error', 'msg': 'Unable to set value of setting.' } ))
else: else:
if domain.add_setting(new_setting, new_value): if domain.add_setting(new_setting, new_value):
history = History(msg='New setting %s with value %s for %s has been created' % (new_setting, new_value, domain.name), created_by=current_user.username) history = History(msg='New setting {0} with value {1} for {2} has been created'.format(new_setting, new_value, domain.name), created_by=current_user.username)
history.add() history.add()
return make_response(jsonify( { 'status': 'ok', 'msg': 'New setting created and updated.' } )) return make_response(jsonify( { 'status': 'ok', 'msg': 'New setting created and updated.' } ))
else: else:
@ -673,12 +673,12 @@ def create_template():
return redirect(url_for('create_template')) return redirect(url_for('create_template'))
if DomainTemplate.query.filter(DomainTemplate.name == name).first(): if DomainTemplate.query.filter(DomainTemplate.name == name).first():
flash("A template with the name %s already exists!" % name, 'error') flash("A template with the name {0} already exists!".format(name), 'error')
return redirect(url_for('create_template')) return redirect(url_for('create_template'))
t = DomainTemplate(name=name, description=description) t = DomainTemplate(name=name, description=description)
result = t.create() result = t.create()
if result['status'] == 'ok': if result['status'] == 'ok':
history = History(msg='Add domain template %s' % name, detail=str({'name': name, 'description': description}), created_by=current_user.username) history = History(msg='Add domain template {0}'.format(name), detail=str({'name': name, 'description': description}), created_by=current_user.username)
history.add() history.add()
return redirect(url_for('templates')) return redirect(url_for('templates'))
else: else:
@ -704,12 +704,12 @@ def create_template_from_zone():
return make_response(jsonify({'status': 'error', 'msg': 'Please correct template name'}), 500) return make_response(jsonify({'status': 'error', 'msg': 'Please correct template name'}), 500)
if DomainTemplate.query.filter(DomainTemplate.name == name).first(): if DomainTemplate.query.filter(DomainTemplate.name == name).first():
return make_response(jsonify({'status': 'error', 'msg': 'A template with the name %s already exists!' % name}), 500) return make_response(jsonify({'status': 'error', 'msg': 'A template with the name {0} already exists!'.format(name)}), 500)
t = DomainTemplate(name=name, description=description) t = DomainTemplate(name=name, description=description)
result = t.create() result = t.create()
if result['status'] == 'ok': if result['status'] == 'ok':
history = History(msg='Add domain template %s' % name, detail=str({'name': name, 'description': description}), created_by=current_user.username) history = History(msg='Add domain template {0}'.format(name), detail=str({'name': name, 'description': description}), created_by=current_user.username)
history.add() history.add()
records = [] records = []
@ -789,7 +789,7 @@ def apply_records(template):
t = DomainTemplate.query.filter(DomainTemplate.name == template).first() t = DomainTemplate.query.filter(DomainTemplate.name == template).first()
result = t.replace_records(records) result = t.replace_records(records)
if result['status'] == 'ok': if result['status'] == 'ok':
history = History(msg='Apply domain template record changes to domain template %s' % template, detail=str(jdata), created_by=current_user.username) history = History(msg='Apply domain template record changes to domain template {0}'.format(template), detail=str(jdata), created_by=current_user.username)
history.add() history.add()
return make_response(jsonify(result), 200) return make_response(jsonify(result), 200)
else: else:
@ -808,7 +808,7 @@ def delete_template(template):
if t is not None: if t is not None:
result = t.delete_template() result = t.delete_template()
if result['status'] == 'ok': if result['status'] == 'ok':
history = History(msg='Deleted domain template %s' % template, detail=str({'name': template}), created_by=current_user.username) history = History(msg='Deleted domain template {0}'.format(template), detail=str({'name': template}), created_by=current_user.username)
history.add() history.add()
return redirect(url_for('templates')) return redirect(url_for('templates'))
else: else:
@ -883,7 +883,7 @@ def admin_manageuser():
user = User(username=data) user = User(username=data)
result = user.delete() result = user.delete()
if result: if result:
history = History(msg='Delete username %s' % data, created_by=current_user.username) history = History(msg='Delete username {0}'.format(data), created_by=current_user.username)
history.add() history.add()
return make_response(jsonify( { 'status': 'ok', 'msg': 'User has been removed.' } ), 200) return make_response(jsonify( { 'status': 'ok', 'msg': 'User has been removed.' } ), 200)
else: else:
@ -893,7 +893,7 @@ def admin_manageuser():
user = User(username=data) user = User(username=data)
result = user.revoke_privilege() result = user.revoke_privilege()
if result: if result:
history = History(msg='Revoke %s user privielges' % data, created_by=current_user.username) history = History(msg='Revoke {0} user privielges'.format(data), created_by=current_user.username)
history.add() history.add()
return make_response(jsonify( { 'status': 'ok', 'msg': 'Revoked user privielges.' } ), 200) return make_response(jsonify( { 'status': 'ok', 'msg': 'Revoked user privielges.' } ), 200)
else: else:
@ -905,7 +905,7 @@ def admin_manageuser():
user = User(username=username) user = User(username=username)
result = user.set_admin(is_admin) result = user.set_admin(is_admin)
if result: if result:
history = History(msg='Change user role of %s' % username, created_by=current_user.username) history = History(msg='Change user role of {0}'.format(username), created_by=current_user.username)
history.add() history.add()
return make_response(jsonify( { 'status': 'ok', 'msg': 'Changed user role successfully.' } ), 200) return make_response(jsonify( { 'status': 'ok', 'msg': 'Changed user role successfully.' } ), 200)
else: else:
@ -991,7 +991,7 @@ def user_profile():
enable_otp = data['enable_otp'] enable_otp = data['enable_otp']
user = User(username=current_user.username) user = User(username=current_user.username)
user.update_profile(enable_otp=enable_otp) user.update_profile(enable_otp=enable_otp)
return make_response(jsonify( { 'status': 'ok', 'msg': 'Change OTP Authentication successfully. Status: %s' % enable_otp } ), 200) return make_response(jsonify( { 'status': 'ok', 'msg': 'Change OTP Authentication successfully. Status: {0}'.format(enable_otp) } ), 200)
# get new avatar # get new avatar
save_file_name = None save_file_name = None
@ -1071,7 +1071,7 @@ def dyndns_update():
break break
if not domain: if not domain:
history = History(msg="DynDNS update: attempted update of %s but it does not exist for this user" % hostname, created_by=current_user.username) history = History(msg="DynDNS update: attempted update of {0} but it does not exist for this user".format(hostname), created_by=current_user.username)
history.add() history.add()
return render_template('dyndns.html', response='nohost'), 200 return render_template('dyndns.html', response='nohost'), 200
@ -1081,14 +1081,14 @@ def dyndns_update():
if r.exists(domain.name) and r.is_allowed_edit(): if r.exists(domain.name) and r.is_allowed_edit():
if r.data == myip: if r.data == myip:
# record content did not change, return 'nochg' # record content did not change, return 'nochg'
history = History(msg="DynDNS update: attempted update of %s but record did not change" % hostname, created_by=current_user.username) history = History(msg="DynDNS update: attempted update of {0} but record did not change".format(hostname), created_by=current_user.username)
history.add() history.add()
return render_template('dyndns.html', response='nochg'), 200 return render_template('dyndns.html', response='nochg'), 200
else: else:
oldip = r.data oldip = r.data
result = r.update(domain.name, myip) result = r.update(domain.name, myip)
if result['status'] == 'ok': if result['status'] == 'ok':
history = History(msg='DynDNS update: updated record %s in zone %s, it changed from %s to %s' % (hostname,domain.name,oldip,myip), detail=str(result), created_by=current_user.username) history = History(msg='DynDNS update: updated record {0} in zone {1}, it changed from {2} to {3}'.format(hostname,domain.name,oldip,myip), detail=str(result), created_by=current_user.username)
history.add() history.add()
return render_template('dyndns.html', response='good'), 200 return render_template('dyndns.html', response='good'), 200
else: else:
@ -1099,11 +1099,11 @@ def dyndns_update():
record = Record(name=hostname,type='A',data=myip,status=False,ttl=3600) record = Record(name=hostname,type='A',data=myip,status=False,ttl=3600)
result = record.add(domain.name) result = record.add(domain.name)
if result['status'] == 'ok': if result['status'] == 'ok':
history = History(msg='DynDNS update: created record %s in zone %s, it now represents %s' % (hostname,domain.name,myip), detail=str(result), created_by=current_user.username) history = History(msg='DynDNS update: created record {0} in zone {1}, it now represents {2}'.format(hostname,domain.name,myip), detail=str(result), created_by=current_user.username)
history.add() history.add()
return render_template('dyndns.html', response='good'), 200 return render_template('dyndns.html', response='good'), 200
history = History(msg="DynDNS update: attempted update of %s but it does not exist for this user" % hostname, created_by=current_user.username) history = History(msg='DynDNS update: attempted update of {0} but it does not exist for this user'.format(hostname), created_by=current_user.username)
history.add() history.add()
return render_template('dyndns.html', response='nohost'), 200 return render_template('dyndns.html', response='nohost'), 200