add download

This commit is contained in:
wh1te909 2023-10-24 05:18:47 +00:00
parent 0c3e9f7824
commit 6b010f76ea
5 changed files with 77 additions and 13 deletions

View File

@ -0,0 +1,59 @@
import urllib.parse
from time import sleep
from typing import Any, Optional
import requests
from django.conf import settings
from django.core.management.base import BaseCommand
from core.models import CodeSignToken
class Command(BaseCommand):
help = "Get webtar url"
def handle(self, *args: tuple[Any, Any], **kwargs: dict[str, Any]) -> None:
webtar = f"trmm-web-v{settings.WEB_VERSION}.tar.gz"
url = f"https://github.com/amidaware/tacticalrmm-web/releases/download/v{settings.WEB_VERSION}/{webtar}"
t: "Optional[CodeSignToken]" = CodeSignToken.objects.first()
if not t or not t.token:
self.stdout.write(url)
return
attempts = 0
while 1:
try:
r = requests.post(
settings.REPORTING_CHECK_URL,
json={"token": t.token, "api": settings.ALLOWED_HOSTS[0]},
headers={"Content-type": "application/json"},
timeout=15,
)
except Exception as e:
self.stderr.write(str(e))
attempts += 1
sleep(3)
else:
if r.status_code // 100 in [3, 5]:
self.stderr.write(f"Error getting web tarball: {r.status_code}")
attempts += 1
sleep(3)
else:
attempts = 0
if attempts == 0:
break
elif attempts > 5:
self.stdout.write(url)
return
if r.status_code == 200: # type: ignore
params = {
"token": t.token,
"webver": settings.WEB_VERSION,
"api": settings.ALLOWED_HOSTS[0],
}
url = settings.REPORTING_DL_URL + urllib.parse.urlencode(params)
self.stdout.write(url)

View File

@ -77,6 +77,8 @@ with suppress(ImportError):
CHECK_TOKEN_URL = f"{AGENT_BASE_URL}/api/v2/checktoken"
AGENTS_URL = f"{AGENT_BASE_URL}/api/v2/agents/?"
EXE_GEN_URL = f"{AGENT_BASE_URL}/api/v2/exe"
REPORTING_CHECK_URL = f"{AGENT_BASE_URL}/api/v2/reporting/check"
REPORTING_DL_URL = f"{AGENT_BASE_URL}/api/v2/reporting/download/?"
if "GHACTIONS" in os.environ:
DEBUG = False

View File

@ -4,16 +4,16 @@ REPO=amidaware
BRANCH=master
while [[ $# -gt 0 ]]; do
case $1 in
-r|--repo)
REPO="$2"
shift # past argument
shift # past value
;;
-b|--branch)
BRANCH="$2"
shift # past argument
shift # past value
;;
-r | --repo)
REPO="$2"
shift # past argument
shift # past value
;;
-b | --branch)
BRANCH="$2"
shift # past argument
shift # past value
;;
esac
done
@ -509,6 +509,7 @@ python manage.py create_uwsgi_conf
python manage.py load_chocos
python manage.py load_community_scripts
WEB_VERSION=$(python manage.py get_config webversion)
WEBTAR_URL=$(python manage.py get_webtar_url)
printf >&2 "${YELLOW}%0.s*${NC}" {1..80}
printf >&2 "\n"
printf >&2 "${YELLOW}Please create your login for the RMM website${NC}\n"
@ -860,7 +861,7 @@ fi
print_green 'Installing the frontend'
webtar="trmm-web-v${WEB_VERSION}.tar.gz"
wget -q https://github.com/amidaware/tacticalrmm-web/releases/download/v${WEB_VERSION}/${webtar} -O /tmp/${webtar}
wget -q ${WEBTAR_URL} -O /tmp/${webtar}
sudo mkdir -p /var/www/rmm
sudo tar -xzf /tmp/${webtar} -C /var/www/rmm
echo "window._env_ = {PROD_URL: \"https://${rmmdomain}\"}" | sudo tee /var/www/rmm/dist/env-config.js >/dev/null

View File

@ -439,6 +439,7 @@ API=$(python manage.py get_config api)
WEB_VERSION=$(python manage.py get_config webversion)
webdomain=$(python manage.py get_config webdomain)
meshdomain=$(python manage.py get_config meshdomain)
WEBTAR_URL=$(python manage.py get_webtar_url)
deactivate
print_green 'Restoring hosts file'
@ -462,7 +463,7 @@ sudo systemctl start nats.service
print_green 'Restoring the frontend'
webtar="trmm-web-v${WEB_VERSION}.tar.gz"
wget -q https://github.com/amidaware/tacticalrmm-web/releases/download/v${WEB_VERSION}/${webtar} -O /tmp/${webtar}
wget -q ${WEBTAR_URL} -O /tmp/${webtar}
sudo mkdir -p /var/www/rmm
sudo tar -xzf /tmp/${webtar} -C /var/www/rmm
echo "window._env_ = {PROD_URL: \"https://${API}\"}" | sudo tee /var/www/rmm/dist/env-config.js >/dev/null

View File

@ -390,6 +390,7 @@ API=$(python manage.py get_config api)
WEB_VERSION=$(python manage.py get_config webversion)
FRONTEND=$(python manage.py get_config webdomain)
MESHDOMAIN=$(python manage.py get_config meshdomain)
WEBTAR_URL=$(python manage.py get_webtar_url)
deactivate
if grep -q manage_etc_hosts /etc/hosts; then
@ -420,7 +421,7 @@ if [ ! -d /var/www/rmm ]; then
fi
webtar="trmm-web-v${WEB_VERSION}.tar.gz"
wget -q https://github.com/amidaware/tacticalrmm-web/releases/download/v${WEB_VERSION}/${webtar} -O /tmp/${webtar}
wget -q ${WEBTAR_URL} -O /tmp/${webtar}
sudo rm -rf /var/www/rmm/dist
sudo tar -xzf /tmp/${webtar} -C /var/www/rmm
echo "window._env_ = {PROD_URL: \"https://${API}\"}" | sudo tee /var/www/rmm/dist/env-config.js >/dev/null