require shebang for linux/mac scripts, refactor middleware/posix
This commit is contained in:
@@ -123,9 +123,13 @@ class Agent(BaseAuditModel):
|
||||
|
||||
return CoreSettings.objects.first().default_time_zone # type: ignore
|
||||
|
||||
@property
|
||||
def is_posix(self):
|
||||
return self.plat == "linux" or self.plat == "darwin"
|
||||
|
||||
@property
|
||||
def arch(self):
|
||||
if self.plat != "windows":
|
||||
if self.is_posix:
|
||||
return self.goarch
|
||||
|
||||
if self.operating_system is not None:
|
||||
@@ -195,7 +199,7 @@ class Agent(BaseAuditModel):
|
||||
|
||||
@property
|
||||
def cpu_model(self):
|
||||
if self.plat == "linux":
|
||||
if self.is_posix:
|
||||
try:
|
||||
return self.wmi_detail["cpus"]
|
||||
except:
|
||||
@@ -212,7 +216,7 @@ class Agent(BaseAuditModel):
|
||||
|
||||
@property
|
||||
def graphics(self):
|
||||
if self.plat == "linux":
|
||||
if self.is_posix:
|
||||
try:
|
||||
if not self.wmi_detail["gpus"]:
|
||||
return "No graphics cards"
|
||||
@@ -241,7 +245,7 @@ class Agent(BaseAuditModel):
|
||||
|
||||
@property
|
||||
def local_ips(self):
|
||||
if self.plat == "linux":
|
||||
if self.is_posix:
|
||||
try:
|
||||
return ", ".join(self.wmi_detail["local_ips"])
|
||||
except:
|
||||
@@ -273,7 +277,7 @@ class Agent(BaseAuditModel):
|
||||
|
||||
@property
|
||||
def make_model(self):
|
||||
if self.plat == "linux":
|
||||
if self.is_posix:
|
||||
try:
|
||||
return self.wmi_detail["make_model"]
|
||||
except:
|
||||
@@ -309,7 +313,7 @@ class Agent(BaseAuditModel):
|
||||
|
||||
@property
|
||||
def physical_disks(self):
|
||||
if self.plat == "linux":
|
||||
if self.is_posix:
|
||||
try:
|
||||
return self.wmi_detail["disks"]
|
||||
except:
|
||||
|
||||
@@ -51,3 +51,37 @@ WEEKS = {
|
||||
|
||||
MONTH_DAYS = {f"{b}": 0x1 << a for a, b in enumerate(range(1, 32))}
|
||||
MONTH_DAYS["Last Day"] = 0x80000000
|
||||
|
||||
DEMO_NOT_ALLOWED = [
|
||||
{"name": "AgentProcesses", "methods": ["DELETE"]},
|
||||
{"name": "AgentMeshCentral", "methods": ["GET", "POST"]},
|
||||
{"name": "update_agents", "methods": ["POST"]},
|
||||
{"name": "send_raw_cmd", "methods": ["POST"]},
|
||||
{"name": "install_agent", "methods": ["POST"]},
|
||||
{"name": "GenerateAgent", "methods": ["GET"]},
|
||||
{"name": "email_test", "methods": ["POST"]},
|
||||
{"name": "server_maintenance", "methods": ["POST"]},
|
||||
{"name": "CodeSign", "methods": ["PATCH", "POST"]},
|
||||
{"name": "TwilioSMSTest", "methods": ["POST"]},
|
||||
{"name": "GetEditActionService", "methods": ["PUT", "POST"]},
|
||||
{"name": "TestScript", "methods": ["POST"]},
|
||||
{"name": "GetUpdateDeleteAgent", "methods": ["DELETE"]},
|
||||
{"name": "Reboot", "methods": ["POST", "PATCH"]},
|
||||
{"name": "recover", "methods": ["POST"]},
|
||||
{"name": "run_script", "methods": ["POST"]},
|
||||
{"name": "bulk", "methods": ["POST"]},
|
||||
{"name": "WMI", "methods": ["POST"]},
|
||||
{"name": "PolicyAutoTask", "methods": ["POST"]},
|
||||
{"name": "RunAutoTask", "methods": ["POST"]},
|
||||
{"name": "run_checks", "methods": ["POST"]},
|
||||
{"name": "GetSoftware", "methods": ["POST", "PUT"]},
|
||||
{"name": "ScanWindowsUpdates", "methods": ["POST"]},
|
||||
{"name": "InstallWindowsUpdates", "methods": ["POST"]},
|
||||
{"name": "PendingActions", "methods": ["DELETE"]},
|
||||
]
|
||||
|
||||
LINUX_NOT_IMPLEMENTED = [
|
||||
{"name": "ScanWindowsUpdates", "methods": ["POST"]},
|
||||
{"name": "GetSoftware", "methods": ["POST", "PUT"]},
|
||||
{"name": "Reboot", "methods": ["PATCH"]}, # TODO implement reboot later
|
||||
]
|
||||
|
||||
@@ -3,6 +3,7 @@ import threading
|
||||
from django.conf import settings
|
||||
from rest_framework.exceptions import AuthenticationFailed
|
||||
from ipware import get_client_ip
|
||||
from tacticalrmm.constants import DEMO_NOT_ALLOWED, LINUX_NOT_IMPLEMENTED
|
||||
|
||||
request_local = threading.local()
|
||||
|
||||
@@ -99,33 +100,7 @@ class DemoMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
self.not_allowed = [
|
||||
{"name": "AgentProcesses", "methods": ["DELETE"]},
|
||||
{"name": "AgentMeshCentral", "methods": ["GET", "POST"]},
|
||||
{"name": "update_agents", "methods": ["POST"]},
|
||||
{"name": "send_raw_cmd", "methods": ["POST"]},
|
||||
{"name": "install_agent", "methods": ["POST"]},
|
||||
{"name": "GenerateAgent", "methods": ["GET"]},
|
||||
{"name": "email_test", "methods": ["POST"]},
|
||||
{"name": "server_maintenance", "methods": ["POST"]},
|
||||
{"name": "CodeSign", "methods": ["PATCH", "POST"]},
|
||||
{"name": "TwilioSMSTest", "methods": ["POST"]},
|
||||
{"name": "GetEditActionService", "methods": ["PUT", "POST"]},
|
||||
{"name": "TestScript", "methods": ["POST"]},
|
||||
{"name": "GetUpdateDeleteAgent", "methods": ["DELETE"]},
|
||||
{"name": "Reboot", "methods": ["POST", "PATCH"]},
|
||||
{"name": "recover", "methods": ["POST"]},
|
||||
{"name": "run_script", "methods": ["POST"]},
|
||||
{"name": "bulk", "methods": ["POST"]},
|
||||
{"name": "WMI", "methods": ["POST"]},
|
||||
{"name": "PolicyAutoTask", "methods": ["POST"]},
|
||||
{"name": "RunAutoTask", "methods": ["POST"]},
|
||||
{"name": "run_checks", "methods": ["POST"]},
|
||||
{"name": "GetSoftware", "methods": ["POST", "PUT"]},
|
||||
{"name": "ScanWindowsUpdates", "methods": ["POST"]},
|
||||
{"name": "InstallWindowsUpdates", "methods": ["POST"]},
|
||||
{"name": "PendingActions", "methods": ["DELETE"]},
|
||||
]
|
||||
self.not_allowed = DEMO_NOT_ALLOWED
|
||||
|
||||
def __call__(self, request):
|
||||
return self.get_response(request)
|
||||
@@ -155,10 +130,7 @@ class LinuxMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
self.not_implemented = [
|
||||
{"name": "ScanWindowsUpdates", "methods": ["POST"]},
|
||||
{"name": "GetSoftware", "methods": ["POST", "PUT"]},
|
||||
]
|
||||
self.not_implemented = LINUX_NOT_IMPLEMENTED
|
||||
|
||||
def __call__(self, request):
|
||||
return self.get_response(request)
|
||||
|
||||
@@ -15,6 +15,11 @@
|
||||
</q-btn>
|
||||
</q-bar>
|
||||
<q-form @submit="submitForm">
|
||||
<q-banner v-if="missingShebang" dense inline-actions class="text-black bg-warning">
|
||||
<template v-slot:avatar> <q-icon class="text-center" name="warning" color="black" /> </template>Shell/Python
|
||||
scripts on Linux/Mac need a shebang at the top of the script e.g. <code>#!/bin/bash</code> or
|
||||
<code>#!/usr/bin/python3</code><br />Add one to get rid of this warning. Ignore if windows.
|
||||
</q-banner>
|
||||
<div class="row q-pa-sm">
|
||||
<div class="col-4 q-gutter-sm q-pr-sm">
|
||||
<q-input
|
||||
@@ -196,6 +201,12 @@ export default {
|
||||
const loading = ref(false);
|
||||
const agentLoading = ref(false);
|
||||
|
||||
const missingShebang = computed(() => {
|
||||
if (script.value.shell === "shell" || script.value.shell === "python") {
|
||||
return !script.value.script_body.includes("#!");
|
||||
}
|
||||
});
|
||||
|
||||
const title = computed(() => {
|
||||
if (props.script) {
|
||||
return props.readonly
|
||||
@@ -271,6 +282,7 @@ export default {
|
||||
agent,
|
||||
agentLoading,
|
||||
lang,
|
||||
missingShebang,
|
||||
|
||||
// non-reactive data
|
||||
shellOptions,
|
||||
|
||||
Reference in New Issue
Block a user