Skip to content

Commit

Permalink
switch to localhost to download mesh exe
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Jun 8, 2024
1 parent d32b834 commit c2eb93a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
4 changes: 2 additions & 2 deletions api/tacticalrmm/apiv3/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ def post(self, request):

try:
return download_mesh_agent(dl_url)
except:
return notify_error("Unable to download mesh agent exe")
except Exception as e:
return notify_error(f"Unable to download mesh agent: {e}")


class NewAgent(APIView):
Expand Down
36 changes: 30 additions & 6 deletions api/tacticalrmm/core/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def test_get_meshagent_url_standard(self):
)
self.assertEqual(
r,
"https://mesh.example.com/meshagents?id=abc123&installflags=2&meshinstall=10005",
"http://127.0.0.1:4430/meshagents?id=abc123&installflags=2&meshinstall=10005",
)

r = get_meshagent_url(
Expand All @@ -594,7 +594,7 @@ def test_get_meshagent_url_standard(self):
)
self.assertEqual(
r,
"https://mesh.example.com/meshagents?id=4&meshid=abc123&installflags=0",
"http://127.0.0.1:4430/meshagents?id=4&meshid=abc123&installflags=0",
)

@override_settings(DOCKER_BUILD=True)
Expand Down Expand Up @@ -622,8 +622,32 @@ def test_get_meshagent_url_docker(self):
"http://tactical-meshcentral:4443/meshagents?id=4&meshid=abc123&installflags=0",
)

@override_settings(TRMM_INSECURE=True)
def test_get_meshagent_url_insecure(self):
@override_settings(USE_EXTERNAL_MESH=True)
def test_get_meshagent_url_external_mesh(self):
r = get_meshagent_url(
ident=MeshAgentIdent.DARWIN_UNIVERSAL,
plat="darwin",
mesh_site="https://mesh.example.com",
mesh_device_id="abc123",
)
self.assertEqual(
r,
"https://mesh.example.com/meshagents?id=abc123&installflags=2&meshinstall=10005",
)

r = get_meshagent_url(
ident=MeshAgentIdent.WIN64,
plat="windows",
mesh_site="https://mesh.example.com",
mesh_device_id="abc123",
)
self.assertEqual(
r,
"https://mesh.example.com/meshagents?id=4&meshid=abc123&installflags=0",
)

@override_settings(MESH_PORT=8653)
def test_get_meshagent_url_mesh_port(self):
r = get_meshagent_url(
ident=MeshAgentIdent.DARWIN_UNIVERSAL,
plat="darwin",
Expand All @@ -632,7 +656,7 @@ def test_get_meshagent_url_insecure(self):
)
self.assertEqual(
r,
"http://mesh.example.com:4430/meshagents?id=abc123&installflags=2&meshinstall=10005",
"http://127.0.0.1:8653/meshagents?id=abc123&installflags=2&meshinstall=10005",
)

r = get_meshagent_url(
Expand All @@ -643,5 +667,5 @@ def test_get_meshagent_url_insecure(self):
)
self.assertEqual(
r,
"http://mesh.example.com:4430/meshagents?id=4&meshid=abc123&installflags=0",
"http://127.0.0.1:8653/meshagents?id=4&meshid=abc123&installflags=0",
)
9 changes: 5 additions & 4 deletions api/tacticalrmm/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async def get_mesh_device_id(uri: str, device_group: str) -> None:

def download_mesh_agent(dl_url: str) -> FileResponse:
with tempfile.NamedTemporaryFile(prefix="mesh-", dir=settings.EXE_DIR) as fp:
r = requests.get(dl_url, stream=True, timeout=15)
r = requests.get(dl_url, stream=True, timeout=15, verify=False)
with open(fp.name, "wb") as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
Expand Down Expand Up @@ -186,10 +186,11 @@ def get_meshagent_url(
) -> str:
if settings.DOCKER_BUILD:
base = settings.MESH_WS_URL.replace("ws://", "http://")
elif getattr(settings, "TRMM_INSECURE", False):
base = mesh_site.replace("https", "http") + ":4430"
else:
elif getattr(settings, "USE_EXTERNAL_MESH", False):
base = mesh_site
else:
mesh_port = getattr(settings, "MESH_PORT", 4430)
base = f"http://127.0.0.1:{mesh_port}"

if plat == AgentPlat.WINDOWS:
params = {
Expand Down

0 comments on commit c2eb93a

Please sign in to comment.