From 862a51764bf7cd8b62d88e89f01e5acf55fbf1cf Mon Sep 17 00:00:00 2001 From: kaiyu Date: Mon, 29 Apr 2019 10:17:23 +0800 Subject: [PATCH 1/3] =?UTF-8?q?1.sql=E6=9F=A5=E8=AF=A2=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9Eredis=E5=B8=AE=E5=8A=A9=E6=96=87=E6=A1=A3=EF=BC=9B?= =?UTF-8?q?=E5=AE=8C=E5=85=A8=E7=A6=81=E6=AD=A2keys=E5=91=BD=E4=BB=A4=202.?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E4=B8=80=E4=BA=9B=E5=B0=8F=E4=B8=9C=E8=A5=BF?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- archery/settings.py | 7 ++---- debug.sh | 4 ++-- sql/admin.py | 2 +- sql/engines/redis.py | 5 ++--- sql/instance.py | 2 +- sql/models.py | 4 ++-- sql/query.py | 6 ++--- sql/templates/instanceuser.html | 2 +- sql/templates/param.html | 4 ++-- sql/templates/sqlquery.html | 40 +++++++++++++++++++++++++++------ 10 files changed, 49 insertions(+), 27 deletions(-) diff --git a/archery/settings.py b/archery/settings.py index 453b7d5e91..3f0ced441e 100644 --- a/archery/settings.py +++ b/archery/settings.py @@ -87,7 +87,7 @@ STATICFILES_DIRS = [os.path.join(BASE_DIR, 'common/static'), ] # 扩展django admin里users字段用到,指定了sql/models.py里的class users -AUTH_USER_MODEL = "sql.users" +AUTH_USER_MODEL = "sql.Users" # 密码校验 AUTH_PASSWORD_VALIDATORS = [ @@ -108,7 +108,7 @@ }, ] -# ##############以下部分需要用户根据自己环境自行修改################### +############### 以下部分需要用户根据自己环境自行修改 ################### # SESSION 设置 SESSION_COOKIE_AGE = 60 * 300 # 300分钟 @@ -175,9 +175,6 @@ # LDAP ENABLE_LDAP = False if ENABLE_LDAP: - import ldap - from django_auth_ldap.config import LDAPSearch - AUTHENTICATION_BACKENDS = ( 'django_auth_ldap.backend.LDAPBackend', # 配置为先使用LDAP认证,如通过认证则不再使用后面的认证方式 'django.contrib.auth.backends.ModelBackend', # django系统中手动创建的用户也可使用,优先级靠后。注意这2行的顺序 diff --git a/debug.sh b/debug.sh index 07d8a33543..3ccc3d795a 100755 --- a/debug.sh +++ b/debug.sh @@ -1,9 +1,9 @@ #!/bin/bash -python3 manage.py runserver 0.0.0.0:9123 --insecure & +nohup python3 manage.py runserver 0.0.0.0:9123 --insecure & # 编译翻译文件 python3 manage.py compilemessages # 启动Django Q cluster -python3 manage.py qcluster & +nohup python3 manage.py qcluster & diff --git a/sql/admin.py b/sql/admin.py index 3b6d81198b..1e087cd8ea 100644 --- a/sql/admin.py +++ b/sql/admin.py @@ -140,7 +140,7 @@ class ParamTemplateAdmin(admin.ModelAdmin): # 实例参数修改历史 @admin.register(ParamHistory) class ParamHistoryAdmin(admin.ModelAdmin): - list_display = ('instance', 'variable_name', 'old_var', 'new_var', 'user_display', 'update_time') + list_display = ('instance', 'variable_name', 'old_var', 'new_var', 'user_display', 'create_time') search_fields = ('variable_name',) list_filter = ('instance', 'user_display') diff --git a/sql/engines/redis.py b/sql/engines/redis.py index 6d1ae5201a..a218cccf0b 100644 --- a/sql/engines/redis.py +++ b/sql/engines/redis.py @@ -45,13 +45,12 @@ def get_all_databases(self): def query_check(self, db_name=None, sql='', limit_num=0): """提交查询前的检查""" - result = {'msg': '', 'bad_query': False, 'filtered_sql': sql, 'has_star': False} - safe_cmd = ["exists", "ttl", "pttl", "type", "get", "mget", "strlen", + result = {'msg': '', 'bad_query': True, 'filtered_sql': sql, 'has_star': False} + safe_cmd = ["scan", "exists", "ttl", "pttl", "type", "get", "mget", "strlen", "hgetall", "hexists", "hget", "hmget", "hkeys", "hvals", "smembers", "scard", "sdiff", "sunion", "sismember", "llen", "lrange", "lindex"] # 命令校验,仅可以执行safe_cmd内的命令 for cmd in safe_cmd: - result['bad_query'] = True if re.match(fr'^{cmd}', sql.strip(), re.I): result['bad_query'] = False break diff --git a/sql/instance.py b/sql/instance.py index a864719861..c91b96f92a 100644 --- a/sql/instance.py +++ b/sql/instance.py @@ -132,7 +132,7 @@ def param_history(request): phs = ParamHistory.objects.filter(variable_name__contains=search) count = phs.count() phs = phs[offset:limit].values("instance__instance_name", "variable_name", "old_var", "new_var", - "user_display", "update_time") + "user_display", "create_time") # QuerySet 序列化 rows = [row for row in phs] diff --git a/sql/models.py b/sql/models.py index dd38dd6a37..d9e8b3a1c0 100644 --- a/sql/models.py +++ b/sql/models.py @@ -440,11 +440,11 @@ class ParamHistory(models.Model): set_sql = models.CharField('在线变更配置执行的SQL语句', max_length=1024) user_name = models.CharField('修改人', max_length=30) user_display = models.CharField('修改人中文名', max_length=50) - update_time = models.DateTimeField('修改时间', auto_now_add=True) + create_time = models.DateTimeField('参数被修改时间点', auto_now_add=True) class Meta: managed = True - ordering = ['-update_time'] + ordering = ['-create_time'] db_table = 'param_history' verbose_name = u'实例参数修改历史' verbose_name_plural = u'实例参数修改历史' diff --git a/sql/query.py b/sql/query.py index b8987b8e51..1296cde70d 100644 --- a/sql/query.py +++ b/sql/query.py @@ -63,8 +63,7 @@ def query(request): result['status'] = 1 result['msg'] = query_check_info.get('msg') return HttpResponse(json.dumps(result), content_type='application/json') - else: - sql_content = query_check_info['filtered_sql'] + sql_content = query_check_info['filtered_sql'] # 查询权限校验,并且获取limit_num priv_check_info = query_priv_check(user, instance, db_name, sql_content, limit_num) @@ -214,4 +213,5 @@ def querylog(request): result = {"total": sql_log_count, "rows": sql_log} # 返回查询结果 - return HttpResponse(json.dumps(result), content_type='application/json') + return HttpResponse(json.dumps(result, cls=ExtendJSONEncoder, bigint_as_string=True), + content_type='application/json') diff --git a/sql/templates/instanceuser.html b/sql/templates/instanceuser.html index 5c21ed8669..4293fb85c0 100644 --- a/sql/templates/instanceuser.html +++ b/sql/templates/instanceuser.html @@ -58,7 +58,7 @@ }, columns: [ { - title: 'user', + title: 'User@Host', field: 'user' }, { title: 'privileges', diff --git a/sql/templates/param.html b/sql/templates/param.html index 87f7ab747f..8367d62849 100755 --- a/sql/templates/param.html +++ b/sql/templates/param.html @@ -19,7 +19,7 @@