mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-11-08 14:40:27 +00:00
Merge pull request #358 from ngoduykhanh/LGTM
Code adjustment as LGTM.com
This commit is contained in:
commit
a720eaa390
@ -20,7 +20,7 @@ from distutils.util import strtobool
|
||||
from distutils.version import StrictVersion
|
||||
from flask_login import AnonymousUserMixin
|
||||
|
||||
from app import app, db
|
||||
from app import db
|
||||
from app.lib import utils
|
||||
|
||||
logging = logger.getLogger(__name__)
|
||||
@ -95,7 +95,7 @@ class User(db.Model):
|
||||
def get_hashed_password(self, plain_text_password=None):
|
||||
# Hash a password for the first time
|
||||
# (Using bcrypt, the salt is saved into the hash itself)
|
||||
if plain_text_password == None:
|
||||
if plain_text_password is None:
|
||||
return plain_text_password
|
||||
|
||||
pw = plain_text_password if plain_text_password else self.plain_text_password
|
||||
@ -1523,7 +1523,11 @@ class Record(object):
|
||||
jdata1 = utils.fetch_json(urljoin(self.PDNS_STATS_URL, self.API_EXTENDED_URL + '/servers/localhost/zones/{0}'.format(domain)), headers=headers, method='PATCH', data=postdata_for_delete)
|
||||
jdata2 = utils.fetch_json(urljoin(self.PDNS_STATS_URL, self.API_EXTENDED_URL + '/servers/localhost/zones/{0}'.format(domain)), headers=headers, method='PATCH', data=postdata_for_new)
|
||||
|
||||
if 'error' in jdata2.keys():
|
||||
if 'error' in jdata1.keys():
|
||||
logging.error('Cannot apply record changes.')
|
||||
logging.debug(jdata1['error'])
|
||||
return {'status': 'error', 'msg': jdata1['error']}
|
||||
elif 'error' in jdata2.keys():
|
||||
logging.error('Cannot apply record changes.')
|
||||
logging.debug(jdata2['error'])
|
||||
return {'status': 'error', 'msg': jdata2['error']}
|
||||
|
@ -232,7 +232,7 @@ json_library = {
|
||||
return r + (pEnd || '');
|
||||
},
|
||||
prettyPrint: function(obj) {
|
||||
obj = obj.replace(/"/g, "\\\"").replace(/u'/g, "\'").replace(/'/g, "\"").replace(/(False|None)/g, "\"$1\"");
|
||||
obj = obj.replace(/u'/g, "\'").replace(/'/g, "\"").replace(/(False|None)/g, "\"$1\"");
|
||||
var jsonData = JSON.parse(obj);
|
||||
var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg;
|
||||
return JSON.stringify(jsonData, null, 3)
|
||||
|
@ -129,7 +129,7 @@
|
||||
$('.user_role').on('change', function() {
|
||||
var role_name = this.value;
|
||||
var username = $(this).prop('id');
|
||||
postdata = {
|
||||
var postdata = {
|
||||
'action' : 'update_user_role',
|
||||
'data' : {
|
||||
'username' : username,
|
||||
|
63
app/views.py
63
app/views.py
@ -103,7 +103,8 @@ def login_via_authorization_header(request):
|
||||
else:
|
||||
login_user(user, remember = False)
|
||||
return user
|
||||
except:
|
||||
except Exception as e:
|
||||
logging.error('Error: {0}'.format(e))
|
||||
return None
|
||||
return None
|
||||
# END USER AUTHENTICATION HANDLER
|
||||
@ -651,8 +652,9 @@ def domain_add():
|
||||
return redirect(url_for('dashboard'))
|
||||
else:
|
||||
return render_template('errors/400.html', msg=result['msg']), 400
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
except Exception as e:
|
||||
logging.error('Cannot add domain. Error: {0}'.format(e))
|
||||
logging.debug(traceback.format_exc())
|
||||
return redirect(url_for('error', code=500))
|
||||
|
||||
else:
|
||||
@ -784,8 +786,9 @@ def record_apply(domain_name):
|
||||
return make_response(jsonify( result ), 200)
|
||||
else:
|
||||
return make_response(jsonify( result ), 400)
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
except Exception as e:
|
||||
logging.error('Canot apply record changes. Error: {0}'.format(e))
|
||||
logging.debug(traceback.format_exc())
|
||||
return make_response(jsonify( {'status': 'error', 'msg': 'Error when applying new changes'} ), 500)
|
||||
|
||||
|
||||
@ -807,8 +810,9 @@ def record_update(domain_name):
|
||||
return make_response(jsonify( {'status': 'ok', 'msg': result['msg']} ), 200)
|
||||
else:
|
||||
return make_response(jsonify( {'status': 'error', 'msg': result['msg']} ), 500)
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
except Exception as e:
|
||||
logging.error('Cannot update record. Error: {0}'.format(e))
|
||||
logging.debug(traceback.format_exc())
|
||||
return make_response(jsonify( {'status': 'error', 'msg': 'Error when applying new changes'} ), 500)
|
||||
|
||||
|
||||
@ -821,8 +825,9 @@ def record_delete(domain_name, record_name, record_type):
|
||||
result = r.delete(domain=domain_name)
|
||||
if result['status'] == 'error':
|
||||
print(result['msg'])
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
except Exception as e:
|
||||
logging.error('Cannot delete record. Error: {0}'.format(e))
|
||||
logging.debug(traceback.format_exc())
|
||||
return redirect(url_for('error', code=500)), 500
|
||||
return redirect(url_for('domain', domain_name=domain_name))
|
||||
|
||||
@ -904,8 +909,9 @@ def admin_setdomainsetting(domain_name):
|
||||
return make_response(jsonify( { 'status': 'error', 'msg': 'Unable to create new setting.' } ))
|
||||
else:
|
||||
return make_response(jsonify( { 'status': 'error', 'msg': 'Action not supported.' } ), 400)
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
except Exception as e:
|
||||
logging.error('Cannot change domain setting. Error: {0}'.format(e))
|
||||
logging.debug(traceback.format_exc())
|
||||
return make_response(jsonify( { 'status': 'error', 'msg': 'There is something wrong, please contact Administrator.' } ), 400)
|
||||
|
||||
|
||||
@ -946,8 +952,9 @@ def create_template():
|
||||
else:
|
||||
flash(result['msg'], 'error')
|
||||
return redirect(url_for('create_template'))
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
except Exception as e:
|
||||
logging.error('Cannot create domain template. Error: {0}'.format(e))
|
||||
logging.debug(traceback.format_exc())
|
||||
return redirect(url_for('error', code=500))
|
||||
|
||||
|
||||
@ -1006,8 +1013,9 @@ def create_template_from_zone():
|
||||
|
||||
else:
|
||||
return make_response(jsonify({'status': 'error', 'msg': result['msg']}), 500)
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
except Exception as e:
|
||||
logging.error('Cannot create template from zone. Error: {0}'.format(e))
|
||||
logging.debug(traceback.format_exc())
|
||||
return make_response(jsonify({'status': 'error', 'msg': 'Error when applying new changes'}), 500)
|
||||
|
||||
|
||||
@ -1059,8 +1067,9 @@ def apply_records(template):
|
||||
return make_response(jsonify(result), 200)
|
||||
else:
|
||||
return make_response(jsonify(result), 400)
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
except Exception as e:
|
||||
logging.error('Cannot apply record changes to the template. Error: {0}'.format(e))
|
||||
logging.debug(traceback.format_exc())
|
||||
return make_response(jsonify({'status': 'error', 'msg': 'Error when applying new changes'}), 500)
|
||||
|
||||
|
||||
@ -1079,8 +1088,9 @@ def delete_template(template):
|
||||
else:
|
||||
flash(result['msg'], 'error')
|
||||
return redirect(url_for('templates'))
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
except Exception as e:
|
||||
logging.error('Cannot delete template. Error: {0}'.format(e))
|
||||
logging.debug(traceback.format_exc())
|
||||
return redirect(url_for('error', code=500))
|
||||
return redirect(url_for('templates'))
|
||||
|
||||
@ -1225,8 +1235,9 @@ def admin_manageuser():
|
||||
return make_response(jsonify( { 'status': 'error', 'msg': 'Cannot change user role. {0}'.format(result['msg']) } ), 500)
|
||||
else:
|
||||
return make_response(jsonify( { 'status': 'error', 'msg': 'Action not supported.' } ), 400)
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
except Exception as e:
|
||||
logging.error('Cannot update user. Error: {0}'.format(e))
|
||||
logging.debug(traceback.format_exc())
|
||||
return make_response(jsonify( { 'status': 'error', 'msg': 'There is something wrong, please contact Administrator.' } ), 400)
|
||||
|
||||
|
||||
@ -1311,11 +1322,11 @@ def admin_manageaccount():
|
||||
return make_response(jsonify( { 'status': 'ok', 'msg': 'Account has been removed.' } ), 200)
|
||||
else:
|
||||
return make_response(jsonify( { 'status': 'error', 'msg': 'Cannot remove account.' } ), 500)
|
||||
|
||||
else:
|
||||
return make_response(jsonify( { 'status': 'error', 'msg': 'Action not supported.' } ), 400)
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
except Exception as e:
|
||||
logging.error('Cannot update account. Error: {0}'.format(e))
|
||||
logging.debug(traceback.format_exc())
|
||||
return make_response(jsonify( { 'status': 'error', 'msg': 'There is something wrong, please contact Administrator.' } ), 400)
|
||||
|
||||
|
||||
@ -1590,7 +1601,9 @@ def dyndns_update():
|
||||
try:
|
||||
# get all domains owned by the current user
|
||||
domains = User(id=current_user.id).get_domain()
|
||||
except:
|
||||
except Exception as e:
|
||||
logging.error('DynDNS Error: {0}'.format(e))
|
||||
logging.debug(traceback.format_exc())
|
||||
return render_template('dyndns.html', response='911'), 200
|
||||
|
||||
domain = None
|
||||
|
Loading…
Reference in New Issue
Block a user