Commit 82b9c251 authored by ibuler's avatar ibuler

[Update] Merge it

parents 66b8e59a d563a11a
...@@ -44,4 +44,4 @@ class GatewayTestConnectionApi(SingleObjectMixin, APIView): ...@@ -44,4 +44,4 @@ class GatewayTestConnectionApi(SingleObjectMixin, APIView):
if ok: if ok:
return Response("ok") return Response("ok")
else: else:
return Response({"failed": e}, status=404) return Response({"error": e}, status=400)
...@@ -38,6 +38,9 @@ class AssetUserQuerySet(list): ...@@ -38,6 +38,9 @@ class AssetUserQuerySet(list):
if len(v) == 0: if len(v) == 0:
return self return self
if k.find("__in") >= 0: if k.find("__in") >= 0:
_k = k.split('__')[0]
in_kwargs[_k] = v
else:
in_kwargs[k] = v in_kwargs[k] = v
for k in in_kwargs: for k in in_kwargs:
kwargs.pop(k) kwargs.pop(k)
...@@ -45,17 +48,16 @@ class AssetUserQuerySet(list): ...@@ -45,17 +48,16 @@ class AssetUserQuerySet(list):
if len(in_kwargs) == 0: if len(in_kwargs) == 0:
return self return self
for i in self: for i in self:
matched = True matched = False
for k, v in in_kwargs.items(): for k, v in in_kwargs.items():
key = k.split('__')[0] attr = getattr(i, k, None)
attr = getattr(i, key, None)
# 如果属性或者value中是uuid,则转换成string # 如果属性或者value中是uuid,则转换成string
if isinstance(v[0], uuid.UUID): if isinstance(v[0], uuid.UUID):
v = [str(i) for i in v] v = [str(i) for i in v]
if isinstance(attr, uuid.UUID): if isinstance(attr, uuid.UUID):
attr = str(attr) attr = str(attr)
if attr not in v: if v in attr:
matched = False matched = True
if matched: if matched:
queryset.append(i) queryset.append(i)
return AssetUserQuerySet(queryset) return AssetUserQuerySet(queryset)
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
import uuid import uuid
import random import random
import re
import paramiko import paramiko
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
...@@ -63,6 +63,9 @@ class Gateway(AssetUser): ...@@ -63,6 +63,9 @@ class Gateway(AssetUser):
def test_connective(self, local_port=None): def test_connective(self, local_port=None):
if local_port is None: if local_port is None:
local_port = self.port local_port = self.port
if not re.match(r'\w+$', self.password):
return False, _("Password should not contain special characters")
client = paramiko.SSHClient() client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
proxy = paramiko.SSHClient() proxy = paramiko.SSHClient()
......
...@@ -139,7 +139,7 @@ $(document).ready(function(){ ...@@ -139,7 +139,7 @@ $(document).ready(function(){
method: "POST", method: "POST",
body: JSON.stringify({'port': parseInt(data.port)}), body: JSON.stringify({'port': parseInt(data.port)}),
success_message: "{% trans 'Can be connected' %}", success_message: "{% trans 'Can be connected' %}",
fail_message: "{% trans 'The connection fails' %}" {#fail_message: "{% trans 'The connection fails' %}"#}
}) })
}); });
</script> </script>
......
This diff is collapsed.
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
from rest_framework import viewsets, generics from rest_framework import viewsets, generics
from rest_framework import status from rest_framework import status
from rest_framework.response import Response from rest_framework.response import Response
from django.conf import settings
from common.permissions import IsSuperUser, WithBootstrapToken from common.permissions import IsSuperUser, WithBootstrapToken
...@@ -17,6 +18,9 @@ class TerminalViewSet(viewsets.ModelViewSet): ...@@ -17,6 +18,9 @@ class TerminalViewSet(viewsets.ModelViewSet):
queryset = Terminal.objects.filter(is_deleted=False) queryset = Terminal.objects.filter(is_deleted=False)
serializer_class = serializers.TerminalSerializer serializer_class = serializers.TerminalSerializer
permission_classes = [IsSuperUser] permission_classes = [IsSuperUser]
http_method_names = [
'get', 'put', 'patch', 'delete', 'head', 'options', 'trace'
]
class TerminalRegistrationApi(generics.CreateAPIView): class TerminalRegistrationApi(generics.CreateAPIView):
...@@ -29,6 +33,9 @@ class TerminalRegistrationApi(generics.CreateAPIView): ...@@ -29,6 +33,9 @@ class TerminalRegistrationApi(generics.CreateAPIView):
serializer = serializers.TerminalSerializer( serializer = serializers.TerminalSerializer(
data=data, context={'request': request} data=data, context={'request': request}
) )
if not settings.SECURITY_SERVICE_ACCOUNT_REGISTRATION:
data = {"error": "service account registration disabled"}
return Response(data=data, status=status.HTTP_400_BAD_REQUEST)
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
terminal = serializer.save() terminal = serializer.save()
sa_serializer = serializer.sa_serializer_class(instance=terminal.user) sa_serializer = serializer.sa_serializer_class(instance=terminal.user)
......
...@@ -28,9 +28,6 @@ class TerminalSerializer(serializers.ModelSerializer): ...@@ -28,9 +28,6 @@ class TerminalSerializer(serializers.ModelSerializer):
valid = super().is_valid(raise_exception=raise_exception) valid = super().is_valid(raise_exception=raise_exception)
if not valid: if not valid:
return valid return valid
if not settings.SECURITY_SERVICE_ACCOUNT_REGISTRATION:
error = {"error": "service account registration disabled"}
raise serializers.ValidationError(error)
data = {'name': self.validated_data.get('name')} data = {'name': self.validated_data.get('name')}
kwargs = {'data': data} kwargs = {'data': data}
if self.instance and self.instance.user: if self.instance and self.instance.user:
......
...@@ -114,7 +114,7 @@ def check_pid(pid): ...@@ -114,7 +114,7 @@ def check_pid(pid):
""" Check For the existence of a unix pid. """ """ Check For the existence of a unix pid. """
try: try:
os.kill(pid, 0) os.kill(pid, 0)
except OSError: except (OSError, ProcessLookupError):
return False return False
else: else:
return True return True
...@@ -231,6 +231,9 @@ def get_start_worker_kwargs(queue, num): ...@@ -231,6 +231,9 @@ def get_start_worker_kwargs(queue, num):
if os.getuid() == 0: if os.getuid() == 0:
os.environ.setdefault('C_FORCE_ROOT', '1') os.environ.setdefault('C_FORCE_ROOT', '1')
server_hostname = os.environ.get("SERVER_HOSTNAME")
if not server_hostname:
server_hostname = '%h'
cmd = [ cmd = [
'celery', 'worker', 'celery', 'worker',
...@@ -238,7 +241,7 @@ def get_start_worker_kwargs(queue, num): ...@@ -238,7 +241,7 @@ def get_start_worker_kwargs(queue, num):
'-l', 'INFO', '-l', 'INFO',
'-c', str(num), '-c', str(num),
'-Q', queue, '-Q', queue,
'-n', '{}@%h'.format(queue) '-n', '{}@{}'.format(queue, server_hostname)
] ]
return {"cmd": cmd, "cwd": APPS_DIR} return {"cmd": cmd, "cwd": APPS_DIR}
...@@ -437,6 +440,12 @@ def stop_service(srv, sig=15): ...@@ -437,6 +440,12 @@ def stop_service(srv, sig=15):
print("Stop service: {}".format(s), end='') print("Stop service: {}".format(s), end='')
pid = get_pid(s) pid = get_pid(s)
os.kill(pid, sig) os.kill(pid, sig)
with LOCK:
process = processes.pop(s, None)
if process is None:
print("\033[31m No process found\033[0m")
continue
process.wait(1)
for i in range(STOP_TIMEOUT): for i in range(STOP_TIMEOUT):
if i == STOP_TIMEOUT - 1: if i == STOP_TIMEOUT - 1:
print("\033[31m Error\033[0m") print("\033[31m Error\033[0m")
...@@ -447,9 +456,6 @@ def stop_service(srv, sig=15): ...@@ -447,9 +456,6 @@ def stop_service(srv, sig=15):
time.sleep(1) time.sleep(1)
continue continue
with LOCK:
processes.pop(s, None)
if srv == "all": if srv == "all":
stop_daemon_service() stop_daemon_service()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment