From da3ad567e70b8c8cfb1bd4127425382b0fa3c657 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Tue, 25 Aug 2020 00:24:59 +0000 Subject: [PATCH] new installer fixes --- api/tacticalrmm/agents/views.py | 47 ++++++++++++++----- api/tacticalrmm/core/installer.go | 5 ++ api/tacticalrmm/tacticalrmm/settings.py | 2 +- .../components/modals/agents/InstallAgent.vue | 12 +++-- 4 files changed, 51 insertions(+), 15 deletions(-) diff --git a/api/tacticalrmm/agents/views.py b/api/tacticalrmm/agents/views.py index 1bdc86f6..3c0ef570 100644 --- a/api/tacticalrmm/agents/views.py +++ b/api/tacticalrmm/agents/views.py @@ -321,11 +321,14 @@ def install_agent(request): ping = request.data["ping"] power = request.data["power"] - file_name = f"rmm-{''.join(client.client.lower().split())}-{''.join(site.site.lower().split())}.exe" + file_name = "rmm-installer.exe" exe = os.path.join(settings.EXE_DIR, file_name) if os.path.exists(exe): - os.remove(exe) + try: + os.remove(exe) + except Exception as e: + logger.error(str(e)) cmd = [ "env", @@ -347,7 +350,26 @@ def install_agent(request): os.path.join(settings.BASE_DIR, "core/installer.go"), ] - r = subprocess.run(" ".join(cmd), shell=True) + build_error = False + + try: + r = subprocess.run(" ".join(cmd), capture_output=True, shell=True) + except Exception as e: + build_error = True + logger.error(str(e)) + + if r.returncode != 0: + build_error = True + if r.stdout: + logger.error(r.stdout.decode("utf-8", errors="ignore")) + + if r.stderr: + logger.error(r.stderr.decode("utf-8", errors="ignore")) + + logger.error(f"Go build failed with return code {r.returncode}") + + if build_error: + return Response("buildfailed", status=status.HTTP_412_PRECONDITION_FAILED) if settings.DEBUG: with open(exe, "rb") as f: @@ -393,16 +415,21 @@ def install_agent(request): for i, j in replace_dict.items(): text = text.replace(i, j) - file_name = os.path.join(settings.EXE_DIR, "rmm-installer.ps1") - if os.path.exists(file_name): - os.remove(file_name) + file_name = "rmm-installer.ps1" + ps1 = os.path.join(settings.EXE_DIR, file_name) - with open(file_name, "w") as f: + if os.path.exists(ps1): + try: + os.remove(ps1) + except Exception as e: + logger.error(str(e)) + + with open(ps1, "w") as f: f.write(text) if settings.DEBUG: - with open(file_name, "r") as f: - response = HttpResponse(f.read(), content_type="text/plain",) + with open(ps1, "r") as f: + response = HttpResponse(f.read(), content_type="text/plain") response["Content-Disposition"] = f"inline; filename={file_name}" return response else: @@ -411,8 +438,6 @@ def install_agent(request): response["X-Accel-Redirect"] = f"/private/exe/{file_name}" return response - return Response(text) - @api_view(["POST"]) def recover(request): diff --git a/api/tacticalrmm/core/installer.go b/api/tacticalrmm/core/installer.go index 220ad839..a0ba8d69 100644 --- a/api/tacticalrmm/core/installer.go +++ b/api/tacticalrmm/core/installer.go @@ -127,4 +127,9 @@ func main() { fmt.Fprintln(os.Stderr, err) return } + + e := os.Remove(agentBinary) + if e != nil { + fmt.Println(e) + } } diff --git a/api/tacticalrmm/tacticalrmm/settings.py b/api/tacticalrmm/tacticalrmm/settings.py index 643c55f6..cb728ea9 100644 --- a/api/tacticalrmm/tacticalrmm/settings.py +++ b/api/tacticalrmm/tacticalrmm/settings.py @@ -11,7 +11,7 @@ AUTH_USER_MODEL = "accounts.User" # bump this version everytime vue code is changed # to alert user they need to manually refresh their browser -APP_VER = "0.0.27" +APP_VER = "0.0.28" # https://github.com/wh1te909/salt LATEST_SALT_VER = "1.0.3" diff --git a/web/src/components/modals/agents/InstallAgent.vue b/web/src/components/modals/agents/InstallAgent.vue index 6a6adf88..6dc10dd0 100644 --- a/web/src/components/modals/agents/InstallAgent.vue +++ b/web/src/components/modals/agents/InstallAgent.vue @@ -138,8 +138,14 @@ export default { const release = this.github.filter(i => i.name === this.version)[0]; const download = release.assets[0].browser_download_url; const exe = `${release.name}.exe`; - const clientStripped = this.client.replace(/\s/g, "").toLowerCase(); - const siteStripped = this.site.replace(/\s/g, "").toLowerCase(); + const clientStripped = this.client + .replace(/\s/g, "") + .toLowerCase() + .replace(/([^a-zA-Z]+)/g, ""); + const siteStripped = this.site + .replace(/\s/g, "") + .toLowerCase() + .replace(/([^a-zA-Z]+)/g, ""); const data = { installMethod: this.installMethod, @@ -195,7 +201,7 @@ export default { err = "Golang is not installed"; break; case 412: - err = "Golang build failed"; + err = "Golang build failed. Check debug log for the error message"; break; default: err = "Something went wrong";