This commit is contained in:
wh1te909 2024-06-21 00:58:10 +00:00
parent 8394a263c4
commit 364cf362f4
3 changed files with 15 additions and 16 deletions

View File

@ -11,22 +11,23 @@ from django.shortcuts import get_object_or_404
from django.utils import timezone as djangotime from django.utils import timezone as djangotime
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from redis import from_url from redis import from_url
from rest_framework import serializers
from rest_framework import status as drf_status
from rest_framework.decorators import api_view, permission_classes from rest_framework.decorators import api_view, permission_classes
from rest_framework.exceptions import PermissionDenied from rest_framework.exceptions import PermissionDenied
from rest_framework.permissions import AllowAny, IsAuthenticated from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.request import Request from rest_framework.request import Request
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework import serializers, status as drf_status
from core.decorators import monitoring_view from core.decorators import monitoring_view
from core.tasks import sync_mesh_perms_task from core.tasks import sync_mesh_perms_task
from core.utils import ( from core.utils import (
get_core_settings, get_core_settings,
sysd_svc_is_running,
token_is_valid,
run_server_script, run_server_script,
run_test_url_rest_action, run_test_url_rest_action,
sysd_svc_is_running,
token_is_valid,
) )
from logs.models import AuditLog from logs.models import AuditLog
from tacticalrmm.constants import AuditActionType, PAStatus from tacticalrmm.constants import AuditActionType, PAStatus
@ -38,14 +39,13 @@ from tacticalrmm.permissions import (
) )
from .models import CodeSignToken, CoreSettings, CustomField, GlobalKVStore, URLAction from .models import CodeSignToken, CoreSettings, CustomField, GlobalKVStore, URLAction
from .permissions import ( from .permissions import (
CodeSignPerms, CodeSignPerms,
CoreSettingsPerms, CoreSettingsPerms,
CustomFieldPerms, CustomFieldPerms,
RunServerScriptPerms,
ServerMaintPerms, ServerMaintPerms,
URLActionPerms, URLActionPerms,
RunServerScriptPerms,
WebTerminalPerms, WebTerminalPerms,
) )
from .serializers import ( from .serializers import (
@ -383,7 +383,7 @@ class RunURLAction(APIView):
from agents.models import Agent from agents.models import Agent
from clients.models import Client, Site from clients.models import Client, Site
from tacticalrmm.utils import get_db_value, RE_DB_VALUE from tacticalrmm.utils import RE_DB_VALUE, get_db_value
if "agent_id" in request.data.keys(): if "agent_id" in request.data.keys():
if not _has_perm_on_agent(request.user, request.data["agent_id"]): if not _has_perm_on_agent(request.user, request.data["agent_id"]):
@ -456,7 +456,7 @@ class RunTestURLAction(APIView):
elif instance_type == "site": elif instance_type == "site":
if not _has_perm_on_site(request.user, instance_id): if not _has_perm_on_site(request.user, instance_id):
raise PermissionDenied() raise PermissionDenied()
elif instance_type == "client": elif instance_type == "client":
if not _has_perm_on_client(request.user, instance_id): if not _has_perm_on_client(request.user, instance_id):
raise PermissionDenied() raise PermissionDenied()
@ -480,7 +480,6 @@ class RunTestURLAction(APIView):
debug_info={"ip": request._client_ip}, debug_info={"ip": request._client_ip},
) )
return Response({"url": replaced_url, "result": result, "body": replaced_body}) return Response({"url": replaced_url, "result": result, "body": replaced_body})

View File

@ -1,5 +1,5 @@
from abc import abstractmethod from abc import abstractmethod
from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, Union, cast, Literal from typing import TYPE_CHECKING, Any, Dict, Literal, Optional, Tuple, Union, cast
from django.db import models from django.db import models
@ -166,9 +166,9 @@ class AuditLog(models.Model):
agent: Optional["Agent"], agent: Optional["Agent"],
debug_info: Dict[Any, Any] = {}, debug_info: Dict[Any, Any] = {},
) -> None: ) -> None:
debug_info["script_body"] = script_body debug_info["script_body"] = script_body
AuditLog.objects.create( AuditLog.objects.create(
agent=agent.hostname if agent else "Tactical RMM Server", agent=agent.hostname if agent else "Tactical RMM Server",
agent_id=agent.agent_id if agent else "N/A", agent_id=agent.agent_id if agent else "N/A",
@ -254,10 +254,10 @@ class AuditLog(models.Model):
elif instance_type == "site": elif instance_type == "site":
instance = Site.objects.get(pk=instance_id) instance = Site.objects.get(pk=instance_id)
elif instance_type == "client": elif instance_type == "client":
instance = Client.objects.get(pk=instance_id) instance = Client.objects.get(pk=instance_id)
name = instance.hostname if isinstance(instance, Agent) else instance.name name = instance.hostname if isinstance(instance, Agent) else instance.name
classname = type(instance).__name__ classname = type(instance).__name__
AuditLog.objects.create( AuditLog.objects.create(

View File

@ -1,25 +1,25 @@
import asyncio import asyncio
from django.conf import settings
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from rest_framework.decorators import api_view, permission_classes from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAuthenticated from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.views import APIView from rest_framework.views import APIView
from django.conf import settings
from agents.permissions import RunScriptPerms from agents.permissions import RunScriptPerms
from core.utils import clear_entire_cache
from logs.models import AuditLog
from tacticalrmm.constants import ScriptShell, ScriptType from tacticalrmm.constants import ScriptShell, ScriptType
from tacticalrmm.helpers import notify_error from tacticalrmm.helpers import notify_error
from .models import Script, ScriptSnippet from .models import Script, ScriptSnippet
from logs.models import AuditLog
from .permissions import ScriptsPerms from .permissions import ScriptsPerms
from .serializers import ( from .serializers import (
ScriptSerializer, ScriptSerializer,
ScriptSnippetSerializer, ScriptSnippetSerializer,
ScriptTableSerializer, ScriptTableSerializer,
) )
from core.utils import clear_entire_cache
class GetAddScripts(APIView): class GetAddScripts(APIView):