From ac55cff6189b88fbf3fae974d225cae076da46c9 Mon Sep 17 00:00:00 2001 From: bijingrui Date: Sun, 6 Nov 2022 23:09:34 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=E5=81=9C=E6=AD=A2=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- polls/apis.py | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/polls/apis.py b/polls/apis.py index fcbb559..01400b2 100644 --- a/polls/apis.py +++ b/polls/apis.py @@ -16,24 +16,33 @@ class Meta: fields = '__all__' +def get_running_ins(redis_type): + if redis_type == 'sentinel': + running_ins_time = RunningInsSentinel.objects.all() + elif redis_type == 'standalone': + running_ins_time = RunningInsStandalone.objects.all() + elif redis_type == 'cluster': + running_ins_time = RunningInsCluster.objects.all() + else: + running_ins_time = "default" + return running_ins_time + + @api_view(['GET']) @permission_classes((permissions.IsAuthenticated,)) def redisstop(request, redis_type, ins_id): """ + TODO:硬编码密码 API接口,停止redis实例。 授权模式,当前平台内部用户 """ - if redis_type == 'sentinel': - running_ins_time = RunningInsSentinel.objects.all() - elif redis_type == 'standalone': - running_ins_time = RunningInsStandalone.objects.all() - elif redis_type == 'cluster': - running_ins_time = RunningInsCluster.objects.all() + running_ins_time = get_running_ins(redis_type) running_ins = running_ins_time.filter(id=ins_id) running_ins_ip = running_ins.values('redis_ip').first() running_ins_port = running_ins.values('running_ins_port').first() redisins = RedisStartClass(host=running_ins_ip['redis_ip'], - redis_server_ctl="/opt/repoll/redis/src/redis-cli -p {0} shutdown".format(running_ins_port['running_ins_port'])) + redis_server_ctl="/opt/repoll/redis/src/redis-cli -a qZr3pet -p {0} shutdown".format( + running_ins_port['running_ins_port'])) serializer = RunningInsTimeSerializer(running_ins, many=True) result = serializer.data[0] if redisins.start_server(): @@ -62,12 +71,7 @@ def redisstart(request, redis_type, ins_id): API接口,启动redis实例。 授权模式,当前平台内部用户 """ - if redis_type == 'sentinel': - running_ins_time = RunningInsSentinel.objects.all() - elif redis_type == 'standalone': - running_ins_time = RunningInsStandalone.objects.all() - elif redis_type == 'cluster': - running_ins_time = RunningInsCluster.objects.all() + running_ins_time = get_running_ins(redis_type) running_ins = running_ins_time.filter(id=ins_id) running_ins_ip = running_ins.values('redis_ip').first() running_ins_port = running_ins.values('running_ins_port').first() @@ -75,12 +79,14 @@ def redisstart(request, redis_type, ins_id): running_ins_type = c.__dict__['redis_type'] if running_ins_type == 'Redis-Sentinel': redisins = RedisStartClass(host=running_ins_ip['redis_ip'], - redis_server_ctl="/opt/repoll/redis/src/redis-server /opt/repoll/conf/{0}-sentinel.conf --sentinel".format( + redis_server_ctl="/opt/repoll/redis/src/redis-server /opt/repoll/conf/" + "{0}-sentinel.conf --sentinel".format( running_ins_port['running_ins_port'])) else: if redis_type == 'cluster': redisins = RedisStartClass(host=running_ins_ip['redis_ip'], - redis_server_ctl="/opt/repoll/redis/src/redis-server /opt/repoll/conf/{0}-cluster.conf".format( + redis_server_ctl="/opt/repoll/redis/src/redis-server /opt/repoll/conf/" + "{0}-cluster.conf".format( running_ins_port['running_ins_port'])) else: redisins = RedisStartClass(host=running_ins_ip['redis_ip'], @@ -121,7 +127,7 @@ def allredisins(request, redis_type=None): try: if redis_type == "all": sentinel_ins = sentinel_ins_time.values('redis_ip', 'running_ins_port', 'redis_ins_alive', - 'redis_ins_mem', 'redis_type', 'running_ins_name',) + 'redis_ins_mem', 'redis_type', 'running_ins_name', ) stanalone_ins = stanalone_ins_time.values('redis_ip', 'running_ins_port', 'redis_ins_alive', 'redis_ins_mem', 'redis_type', 'running_ins_name') cluster_ins = cluster_ins_time.values('redis_ip', 'running_ins_port', 'redis_ins_alive', @@ -324,4 +330,4 @@ def import_ext_ins(request): except IOError as e: result['redis_status'] = False return Response(result) - return Response(result) \ No newline at end of file + return Response(result) From 00abbd8021b5d411523323be4a9c68719b106973 Mon Sep 17 00:00:00 2001 From: bijingrui Date: Tue, 11 Jul 2023 14:48:11 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9demo=E6=BC=94=E7=A4=BA?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 47b1f68..255ed89 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ sh repoll-init.sh repoll # 密码自定义 * 管理员(dba角色)进行配置上线 # demo演示 -http://repoll.club:8091/ +http://43.143.240.39/ admin/admin From 5eef2b16a1091d033bab6c97f2719d48540bb2be Mon Sep 17 00:00:00 2001 From: bijingrui Date: Sun, 15 Oct 2023 20:03:15 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- polls/tools.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/polls/tools.py b/polls/tools.py index 4eaca21..41cf7e4 100644 --- a/polls/tools.py +++ b/polls/tools.py @@ -1,3 +1,5 @@ +import ipaddress + from django.core.exceptions import ValidationError from django.utils.html import format_html from IPy import IP @@ -16,7 +18,8 @@ def my_custom_sql(): row_list = [] cursor = connection.cursor() db_name = settings.DATABASES - cursor.execute(f"SELECT ip FROM {db_name['default']['NAME']}.polls_ipaddr") + # cursor.execute(f"SELECT ip FROM {db_name['default']['NAME']}.polls_ipaddr") + cursor.execute(f"SELECT ip FROM 'polls_ipaddr'") row = cursor.fetchall() for i in row: row_list.append(i[0]) @@ -29,10 +32,10 @@ def judge_legal_ip(ip): :param ip: :return: """ - compile_ip = re.compile('^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$') - if compile_ip.match(ip): + try: + ipaddress.IPv4Network(ip) return True - else: + except ValueError: return False