Skip to content

Commit

Permalink
return error if disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Jun 14, 2024
1 parent ae16d9d commit dd77a7b
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions api/tacticalrmm/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
import urllib.parse
from base64 import b64encode
from contextlib import suppress
from requests.utils import requote_uri
from typing import TYPE_CHECKING, Optional, cast, Tuple
from typing import TYPE_CHECKING, Optional, cast

import requests
import websockets
from django.apps import apps
from django.conf import settings
from django.core.cache import cache
from django.http import FileResponse
from django.apps import apps
from meshctrl.utils import get_auth_token

from requests.utils import requote_uri
from tacticalrmm.constants import (
AGENT_TBL_PEND_ACTION_CNT_CACHE_PREFIX,
CORESETTINGS_CACHE_KEY,
Expand Down Expand Up @@ -248,7 +247,7 @@ def _run_url_rest_action(*, url: str, method, body: str, headers: str, instance=
)


def run_url_rest_action(*, action_id: int, instance=None) -> Tuple[str, int]:
def run_url_rest_action(*, action_id: int, instance=None) -> tuple[str, int]:
import core.models

action = core.models.URLAction.objects.get(pk=action_id)
Expand Down Expand Up @@ -279,7 +278,7 @@ def run_test_url_rest_action(
headers: str,
instance_type: Optional[str],
instance_id: Optional[int],
) -> Tuple[str, str, str]:
) -> tuple[str, str, str]:
lookup_instance = None
if instance_type and instance_type in lookup_apps and instance_id:
app, model = lookup_apps[instance_type]
Expand All @@ -294,16 +293,21 @@ def run_test_url_rest_action(
url=url, method=method, body=body, headers=headers, instance=lookup_instance
)
except requests.exceptions.ConnectionError as error:
return (str(error), error.request.url, error.request.body)
return (str(error), str(error.request.url), str(error.request.body))

return (response.text, response.request.url, response.request.body)


def run_server_script(
*, body: str, args: list[str], env_vars: list[str], shell: str, timeout: int
):
) -> tuple[str, str, float, int]:
from core.models import CoreSettings
from scripts.models import Script

core = CoreSettings.objects.only("enable_server_scripts").first()
if not core.server_scripts_enabled: # type: ignore
return "", "Error: this feature is disabled", 0.00, 1

parsed_args = Script.parse_script_args(None, shell, args)

parsed_env_vars = Script.parse_script_env_vars(None, shell=shell, env_vars=env_vars)
Expand Down

0 comments on commit dd77a7b

Please sign in to comment.