new installer fixes

This commit is contained in:
wh1te909 2020-08-25 00:24:59 +00:00
parent 413e0fab9f
commit da3ad567e7
4 changed files with 51 additions and 15 deletions

View File

@ -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):

View File

@ -127,4 +127,9 @@ func main() {
fmt.Fprintln(os.Stderr, err)
return
}
e := os.Remove(agentBinary)
if e != nil {
fmt.Println(e)
}
}

View File

@ -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"

View File

@ -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";