Skip to content

Commit

Permalink
massive cleanup of files and restructure of integrations design
Browse files Browse the repository at this point in the history
  • Loading branch information
subzdev committed Jan 7, 2022
1 parent 8c9a386 commit 8d41f2b
Show file tree
Hide file tree
Showing 179 changed files with 24,640 additions and 3,465 deletions.
33 changes: 17 additions & 16 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
build:
context: ..
dockerfile: .devcontainer/api.dockerfile
command: ["tactical-api"]
command: [ "tactical-api" ]
environment:
API_PORT: ${API_PORT}
ports:
Expand All @@ -18,22 +18,23 @@ services:
- ..:/workspace:cached
networks:
dev:
aliases:
aliases:
- tactical-backend

app-dev:
container_name: trmm-app-dev
image: node:14-alpine
restart: always
command: /bin/sh -c "npm install npm@latest -g && npm install && npm run serve -- --host 0.0.0.0 --port ${APP_PORT}"
command: /bin/sh -c "npm install npm@latest -g && npm install && npm run serve
-- --host 0.0.0.0 --port ${APP_PORT}"
working_dir: /workspace/web
volumes:
- ..:/workspace:cached
ports:
- "8080:${APP_PORT}"
networks:
dev:
aliases:
aliases:
- tactical-frontend

# nats
Expand Down Expand Up @@ -61,7 +62,7 @@ services:
container_name: trmm-meshcentral-dev
image: ${IMAGE_REPO}tactical-meshcentral:${VERSION}
restart: always
environment:
environment:
MESH_HOST: ${MESH_HOST}
MESH_USER: ${MESH_USER}
MESH_PASS: ${MESH_PASS}
Expand Down Expand Up @@ -117,7 +118,7 @@ services:
restart: always
command: redis-server --appendonly yes
image: redis:6.0-alpine
volumes:
volumes:
- redis-data-dev:/data
networks:
dev:
Expand All @@ -128,7 +129,7 @@ services:
container_name: trmm-init-dev
image: api-dev
restart: on-failure
command: ["tactical-init-dev"]
command: [ "tactical-init-dev" ]
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASS: ${POSTGRES_PASS}
Expand All @@ -153,7 +154,7 @@ services:
celery-dev:
container_name: trmm-celery-dev
image: api-dev
command: ["tactical-celery-dev"]
command: [ "tactical-celery-dev" ]
restart: always
networks:
- dev
Expand All @@ -168,7 +169,7 @@ services:
celerybeat-dev:
container_name: trmm-celerybeat-dev
image: api-dev
command: ["tactical-celerybeat-dev"]
command: [ "tactical-celerybeat-dev" ]
restart: always
networks:
- dev
Expand All @@ -183,7 +184,7 @@ services:
websockets-dev:
container_name: trmm-websockets-dev
image: api-dev
command: ["tactical-websockets-dev"]
command: [ "tactical-websockets-dev" ]
restart: always
networks:
dev:
Expand Down Expand Up @@ -223,7 +224,7 @@ services:
container_name: trmm-mkdocs-dev
image: api-dev
restart: always
command: ["tactical-mkdocs-dev"]
command: [ "tactical-mkdocs-dev" ]
ports:
- "8005:8005"
volumes:
Expand All @@ -232,11 +233,11 @@ services:
- dev

volumes:
tactical-data-dev:
postgres-data-dev:
mongo-dev-data:
mesh-data-dev:
redis-data-dev:
tactical-data-dev: null
postgres-data-dev: null
mongo-dev-data: null
mesh-data-dev: null
redis-data-dev: null

networks:
dev:
Expand Down
15 changes: 11 additions & 4 deletions .devcontainer/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ set -e
: "${POSTGRES_USER:=tactical}"
: "${POSTGRES_PASS:=tactical}"
: "${POSTGRES_DB:=tacticalrmm}"
: "${MESH_CONTAINER:=tactical-meshcentral}"
: "${MESH_SERVICE:=tactical-meshcentral}"
: "${MESH_WS_URL:=ws://${MESH_SERVICE}:443}"
: "${MESH_USER:=meshcentral}"
: "${MESH_PASS:=meshcentralpass}"
: "${MESH_HOST:=tactical-meshcentral}"
Expand All @@ -20,6 +21,9 @@ set -e
: "${APP_PORT:=8080}"
: "${API_PORT:=8000}"

: "${CERT_PRIV_PATH:=${TACTICAL_DIR}/certs/privkey.pem}"
: "${CERT_PUB_PATH:=${TACTICAL_DIR}/certs/fullchain.pem}"

# Add python venv to path
export PATH="${VIRTUAL_ENV}/bin:$PATH"

Expand All @@ -37,7 +41,7 @@ function django_setup {
sleep 5
done

until (echo > /dev/tcp/"${MESH_CONTAINER}"/443) &> /dev/null; do
until (echo > /dev/tcp/"${MESH_SERVICE}"/443) &> /dev/null; do
echo "waiting for meshcentral container to be ready..."
sleep 5
done
Expand All @@ -56,8 +60,8 @@ DEBUG = True
DOCKER_BUILD = True
CERT_FILE = '/opt/tactical/certs/fullchain.pem'
KEY_FILE = '/opt/tactical/certs/privkey.pem'
CERT_FILE = '${CERT_PUB_PATH}'
KEY_FILE = '${CERT_PRIV_PATH}'
SCRIPTS_DIR = '${WORKSPACE_DIR}/scripts'
Expand All @@ -82,6 +86,7 @@ MESH_USERNAME = '${MESH_USER}'
MESH_SITE = 'https://${MESH_HOST}'
MESH_TOKEN_KEY = '${MESH_TOKEN}'
REDIS_HOST = '${REDIS_HOST}'
MESH_WS_URL = '${MESH_WS_URL}'
ADMIN_ENABLED = True
EOF
)"
Expand All @@ -98,6 +103,8 @@ EOF
"${VIRTUAL_ENV}"/bin/python manage.py reload_nats
"${VIRTUAL_ENV}"/bin/python manage.py create_natsapi_conf
"${VIRTUAL_ENV}"/bin/python manage.py create_installer_user
"${VIRTUAL_ENV}"/bin/python manage.py post_update_tasks


# create super user
echo "from accounts.models import User; User.objects.create_superuser('${TRMM_USER}', 'admin@example.com', '${TRMM_PASS}') if not User.objects.filter(username='${TRMM_USER}').exists() else 0;" | python manage.py shell
Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ celery
channels
channels_redis
django-ipware
Django
Django==3.2.10
django-cors-headers
django-rest-knox
djangorestframework
Expand Down Expand Up @@ -36,3 +36,4 @@ mypy
pysnooper
isort
drf_spectacular
pandas
2 changes: 2 additions & 0 deletions api/tacticalrmm/.coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ omit =
*/tests.py
*/test.py
checks/utils.py
*/asgi.py
*/demo_views.py

8 changes: 7 additions & 1 deletion api/tacticalrmm/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@


def _is_root_user(request, user) -> bool:
return (
root = (
hasattr(settings, "ROOT_USER")
and request.user != user
and user.username == settings.ROOT_USER
)
demo = (
getattr(settings, "DEMO", False) and request.user.username == settings.ROOT_USER
)
return root or demo


class CheckCreds(KnoxLoginView):
Expand Down Expand Up @@ -80,6 +84,8 @@ def post(self, request, format=None):

if settings.DEBUG and token == "sekret":
valid = True
elif getattr(settings, "DEMO", False):
valid = True
elif totp.verify(token, valid_window=10):
valid = True

Expand Down
37 changes: 37 additions & 0 deletions api/tacticalrmm/agents/management/commands/demo_cron.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# import datetime as dt
import random

from django.core.management.base import BaseCommand
from django.utils import timezone as djangotime
from agents.models import Agent


class Command(BaseCommand):
help = "stuff for demo site in cron"

def handle(self, *args, **kwargs):

random_dates = []

for _ in range(20):
rand = djangotime.now() - djangotime.timedelta(minutes=random.randint(1, 2))
random_dates.append(rand)

for _ in range(5):
rand = djangotime.now() - djangotime.timedelta(
minutes=random.randint(10, 20)
)
random_dates.append(rand)

""" for _ in range(5):
rand = djangotime.now() - djangotime.timedelta(hours=random.randint(1, 10))
random_dates.append(rand)
for _ in range(5):
rand = djangotime.now() - djangotime.timedelta(days=random.randint(40, 90))
random_dates.append(rand) """

agents = Agent.objects.only("last_seen")
for agent in agents:
agent.last_seen = random.choice(random_dates)
agent.save(update_fields=["last_seen"])

0 comments on commit 8d41f2b

Please sign in to comment.