Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.sql查询 新增redis帮助文档;完全禁止keys命令 #157

Merged
merged 3 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions archery/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -108,7 +108,7 @@
},
]

# ##############以下部分需要用户根据自己环境自行修改###################
############### 以下部分需要用户根据自己环境自行修改 ###################

# SESSION 设置
SESSION_COOKIE_AGE = 60 * 300 # 300分钟
Expand Down Expand Up @@ -175,9 +175,6 @@
# LDAP
ENABLE_LDAP = False
if ENABLE_LDAP:
import ldap
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里去除验证过么有影响的吧

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import ldap 这个没用的。我们一直在用ldap的。

from django_auth_ldap.config import LDAPSearch

AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend', # 配置为先使用LDAP认证,如通过认证则不再使用后面的认证方式
'django.contrib.auth.backends.ModelBackend', # django系统中手动创建的用户也可使用,优先级靠后。注意这2行的顺序
Expand Down
1 change: 1 addition & 0 deletions common/static/toastr/toastr.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions common/static/toastr/toastr.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions debug.sh
Original file line number Diff line number Diff line change
@@ -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 &
2 changes: 1 addition & 1 deletion sql/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
5 changes: 2 additions & 3 deletions sql/engines/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sql/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
4 changes: 2 additions & 2 deletions sql/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model定义的变更都需要提供变更语句,目前版本v1.5.3,新SQL文件定义为v1.5.3_v1.5.4.sql,放在init_sql目录下

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'实例参数修改历史'
Expand Down
6 changes: 3 additions & 3 deletions sql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
2 changes: 1 addition & 1 deletion sql/templates/instanceuser.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
columns: [
{
title: 'user',
title: 'User@Host',
field: 'user'
}, {
title: 'privileges',
Expand Down
4 changes: 2 additions & 2 deletions sql/templates/param.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</div>
<div id="editable-div" style="display: none" class="form-group">
<select id=editable class="form-control selectpicker" data-live-search="true">
<option value="is-empty" disabled="">是否支持修改</option>
<option value="is-empty" disabled="">允许修改</option>
<option value="true" selected="selected">是</option>
<option value=''>否</option>
</select>
Expand Down Expand Up @@ -222,7 +222,7 @@
field: 'user_display'
}, {
title: '修改时间',
field: 'update_time'
field: 'create_time'
}],
onLoadSuccess: function () {
},
Expand Down
Loading