diff --git a/apps/develop/urls.py b/apps/develop/urls.py index 2a0f80de..a6ebb7ad 100755 --- a/apps/develop/urls.py +++ b/apps/develop/urls.py @@ -1,5 +1,6 @@ from django.urls import path, include -from apps.develop.views import BackupDatabase, BackupMedia, ReloadClientGit, ReloadServerGit, ReloadServerOnly, TestViewSet, CorrectViewSet, testScanHtml +from apps.develop.views import (BackupDatabase, BackupMedia, ReloadClientGit, +ReloadServerGit, ReloadServerOnly, TestViewSet, CorrectViewSet, testScanHtml, ChangeServerDate) from rest_framework.routers import DefaultRouter API_BASE_URL = 'api/develop/' @@ -14,6 +15,7 @@ urlpatterns = [ path(API_BASE_URL + 'reload_server_only/', ReloadServerOnly.as_view()), path(API_BASE_URL + 'backup_database/', BackupDatabase.as_view()), path(API_BASE_URL + 'backup_media/', BackupMedia.as_view()), + path(API_BASE_URL + 'change_server_date/', ChangeServerDate.as_view()), path(API_BASE_URL, include(router.urls)), path(HTML_BASE_URL + "testscan/", testScanHtml) ] diff --git a/apps/develop/views.py b/apps/develop/views.py index 3dd2d692..fe7fa83f 100755 --- a/apps/develop/views.py +++ b/apps/develop/views.py @@ -19,7 +19,6 @@ from apps.opm.models import Opl from apps.third.dahua import dhClient from apps.third.speaker import spClient from apps.third.models import TDevice -from apps.utils.permission import RbacPermission from apps.utils.sms import send_sms from apps.utils.speech import generate_voice from apps.utils.tools import get_info_from_id @@ -29,15 +28,33 @@ from rest_framework.authentication import BasicAuthentication, SessionAuthentica from apps.utils.viewsets import CustomGenericViewSet from apps.utils.wx import wxClient -from apps.wf.models import State, Transition, Workflow +from apps.wf.models import Transition from django.db import transaction -from apps.utils.snowflake import idWorker from django.core.cache import cache -import json -from apps.utils.decorators import auto_log, idempotent +from apps.utils.decorators import auto_log from django.http import HttpResponse +from server.settings import SD_PWD +import subprocess +from drf_yasg.utils import swagger_auto_schema # Create your views here. +class ChangeServerDate(APIView): + permission_classes = [IsAdminUser] + + @swagger_auto_schema(request_body=Serializer) + def post(self, request): + """ + 修改服务器时间 + + 修改服务器时间 + """ + command = 'echo "{}" | sudo -s date "{}"'.format( + SD_PWD, request.data["date"] + ) + completed = subprocess.run(command, shell=True, capture_output=True, text=True) + if completed.returncode != 0: + raise ParseError(completed.stderr) + return Response() class ReloadServerGit(APIView): permission_classes = [IsAdminUser]