mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-11-28 12:53:04 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 01afbd1919 | |||
| 97e0d94d24 | |||
| 35df2757fd | |||
| ccc53c5349 | |||
| 5f1a68ab36 | |||
| daff99510f | |||
| cff1705a9f | |||
| d15810d8b2 | |||
| 9e9fed767e | |||
| 58fedcec48 | |||
| 39f59b99ae | |||
| 767e3e0436 |
@@ -5,5 +5,6 @@ from celery import Celery
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")
|
||||
|
||||
app = Celery("dango_wol")
|
||||
app.conf.timezone = os.getenv("DJANGO_TIME_ZONE", "UTC")
|
||||
app.config_from_object("django.conf:settings", namespace="CELERY")
|
||||
app.autodiscover_tasks()
|
||||
|
||||
@@ -10,9 +10,11 @@ For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.0/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
from django.core.management.utils import get_random_secret_key
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
@@ -21,7 +23,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = os.getenv('DJANGO_SECRET_KEY')
|
||||
SECRET_KEY = os.getenv('DJANGO_SECRET_KEY', get_random_secret_key())
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = os.getenv('DJANGO_DEBUG', 'False') == 'True'
|
||||
@@ -172,4 +174,4 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
||||
VERSION = "v2.0.0"
|
||||
VERSION = "v2.0.4"
|
||||
|
||||
+12
-3
@@ -1,8 +1,7 @@
|
||||
import os
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.management.utils import get_random_secret_key
|
||||
from django_celery_beat.models import IntervalSchedule, PeriodicTask
|
||||
from django_celery_beat.models import IntervalSchedule, PeriodicTask, PeriodicTasks
|
||||
|
||||
from wol.models import Settings, Websocket
|
||||
|
||||
@@ -19,7 +18,11 @@ Websocket.objects.create(visitors=0)
|
||||
|
||||
# ping interval
|
||||
if os.environ.get("PING_INTERVAL"):
|
||||
ping_interval = os.environ.get("PING_INTERVAL")
|
||||
if int(os.environ.get("PING_INTERVAL")) < 5:
|
||||
print("Ping interval lower than 5 seconds is not recommended. Please use an interval of 5 seconds or higher. Automatically set to 5 seconds.")
|
||||
ping_interval = 5
|
||||
else:
|
||||
ping_interval = int(os.environ.get("PING_INTERVAL"))
|
||||
else:
|
||||
ping_interval = 5
|
||||
Settings.objects.update_or_create(
|
||||
@@ -40,3 +43,9 @@ if created:
|
||||
name="Ping all devices",
|
||||
task="wol.tasks.ping_all_devices"
|
||||
)
|
||||
|
||||
# reset last run to fix time zone changes
|
||||
# https://django-celery-beat.readthedocs.io/en/latest/#important-warning-about-time-zones
|
||||
PeriodicTask.objects.update(last_run_at=None)
|
||||
for task in PeriodicTask.objects.all():
|
||||
PeriodicTasks.changed(task)
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import ipaddress
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
import pytz
|
||||
from channels.db import database_sync_to_async
|
||||
from channels.generic.websocket import AsyncWebsocketConsumer
|
||||
from django_celery_beat.models import (CrontabSchedule, IntervalSchedule,
|
||||
@@ -138,6 +140,7 @@ class WSConsumer(AsyncWebsocketConsumer):
|
||||
"ip": dev.ip,
|
||||
"mac": dev.mac,
|
||||
"netmask": dev.netmask,
|
||||
"link": dev.link,
|
||||
"ports": [],
|
||||
"wake": {
|
||||
"enabled": False,
|
||||
@@ -184,6 +187,7 @@ class WSConsumer(AsyncWebsocketConsumer):
|
||||
"name": data["name"],
|
||||
"ip": data["ip"],
|
||||
"netmask": data["netmask"],
|
||||
"link": data["link"],
|
||||
"shutdown_cmd": data["shutdown"]["command"] if data.get("shutdown") else ""
|
||||
}
|
||||
)
|
||||
@@ -210,7 +214,8 @@ class WSConsumer(AsyncWebsocketConsumer):
|
||||
hour=hour,
|
||||
day_of_week=dow,
|
||||
day_of_month=dom,
|
||||
month_of_year=month
|
||||
month_of_year=month,
|
||||
timezone = pytz.timezone(os.getenv("DJANGO_TIME_ZONE", "UTC"))
|
||||
)
|
||||
PeriodicTask.objects.update_or_create(
|
||||
name=f"{data['name']}-{action}",
|
||||
@@ -306,6 +311,7 @@ class WSConsumer(AsyncWebsocketConsumer):
|
||||
"ip": ip,
|
||||
"netmask": netmask,
|
||||
"mac": mac,
|
||||
"link": "",
|
||||
"ports": [],
|
||||
"wake": {
|
||||
"enabled": False,
|
||||
|
||||
@@ -13,6 +13,7 @@ class Device(models.Model):
|
||||
ip = models.GenericIPAddressField()
|
||||
mac = models.CharField(max_length=17)
|
||||
netmask = models.CharField(max_length=15, default="255.255.255.0", blank=False, null=False)
|
||||
link = models.URLField(blank=True, null=True)
|
||||
port = models.ManyToManyField(Port, blank=True)
|
||||
shutdown_cmd = models.TextField(null=True, blank=True)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import threading
|
||||
from asgiref.sync import async_to_sync
|
||||
from celery import shared_task
|
||||
from channels.layers import get_channel_layer
|
||||
from django.db import connection
|
||||
from django_celery_beat.models import CrontabSchedule, PeriodicTask
|
||||
|
||||
from wol.commands import shutdown, wake
|
||||
@@ -36,6 +37,7 @@ class WolDevice:
|
||||
"mac": dev.mac,
|
||||
"netmask": dev.netmask,
|
||||
"up": False,
|
||||
"link": dev.link,
|
||||
"ports": [],
|
||||
"wake": {
|
||||
"enabled": False,
|
||||
@@ -90,6 +92,8 @@ class WolDevice:
|
||||
"message": data
|
||||
}})
|
||||
|
||||
connection.close()
|
||||
|
||||
|
||||
@shared_task
|
||||
def ping_all_devices():
|
||||
|
||||
Generated
+202
-3797
File diff suppressed because it is too large
Load Diff
@@ -23,8 +23,8 @@
|
||||
"@rollup/plugin-replace": "^4.0.0",
|
||||
"bootstrap": "^5.1.3",
|
||||
"dotenv": "^16.0.0",
|
||||
"node-sass": "^7.0.1",
|
||||
"postcss": "^8.4.6",
|
||||
"sass": "^1.49.9",
|
||||
"sirv-cli": "^2.0.0",
|
||||
"svelte-preprocess": "^4.10.3"
|
||||
}
|
||||
|
||||
@@ -113,7 +113,11 @@
|
||||
<i class="fa-solid fa-ellipsis-vertical fa-2x"></i>
|
||||
</div>
|
||||
</div>
|
||||
<h5 class="card-title fw-bold my-2">{device.name}</h5>
|
||||
{#if device.link}
|
||||
<h5 class="card-title fw-bold my-2"><a class="inherit-color" href={device.link}>{device.name}</a></h5>
|
||||
{:else}
|
||||
<h5 class="card-title fw-bold my-2">{device.name}</h5>
|
||||
{/if}
|
||||
<h6 class="card-subtitle mb-2 text-muted">{device.ip}</h6>
|
||||
<ul class="list-group">
|
||||
{#each device.ports as port}
|
||||
@@ -149,7 +153,7 @@
|
||||
<input type="text" class="form-control" id="inputMac{modalDevice.mac}" bind:value="{modalDevice.mac}" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="row mb-2">
|
||||
<div class="col-sm">
|
||||
<label for="inputIp{modalDevice.id}" class="form-label">IP address</label>
|
||||
<input type="text" class="form-control" id="inputIp{modalDevice.id}" bind:value="{modalDevice.ip}" pattern="^([01]?\d\d?|2[0-4]\d|25[0-5])(?:\.(?:[01]?\d\d?|2[0-4]\d|25[0-5])){'{'}3{'}'}$" required>
|
||||
@@ -159,6 +163,14 @@
|
||||
<input type="text" class="form-control" id="inputNetmask{modalDevice.id}" bind:value="{modalDevice.netmask}" pattern="^(((255\.){'{'}3{'}'}(255|254|252|248|240|224|192|128|0+))|((255\.){'{'}2{'}'}(255|254|252|248|240|224|192|128|0+)\.0)|((255\.)(255|254|252|248|240|224|192|128|0+)(\.0+){'{'}2{'}'})|((255|254|252|248|240|224|192|128|0+)(\.0+){'{'}3{'}'}))$" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="mb-3">
|
||||
<label for="inputLinkAddDevice" class="form-label">Web link</label>
|
||||
<input type="text" class="form-control" id="inputILinkAddDevice" placeholder="http://...." bind:value="{modalDevice.link}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ports -->
|
||||
<h5 class="fw-bold mt-4">Ports</h5>
|
||||
<p class="mb-2">Select ports to check if they are open.</p>
|
||||
@@ -327,4 +339,8 @@
|
||||
.list-group-item {
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.inherit-color {
|
||||
color: inherit;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -161,6 +161,13 @@
|
||||
<input type="text" class="form-control" id="inputNetmaskAddDevice" placeholder="255.255.255.0" bind:value="{addDevice.netmask}" pattern="^(((255\.){'{'}3{'}'}(255|254|252|248|240|224|192|128|0+))|((255\.){'{'}2{'}'}(255|254|252|248|240|224|192|128|0+)\.0)|((255\.)(255|254|252|248|240|224|192|128|0+)(\.0+){'{'}2{'}'})|((255|254|252|248|240|224|192|128|0+)(\.0+){'{'}3{'}'}))$" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="mb-3">
|
||||
<label for="inputLinkAddDevice" class="form-label">Web link</label>
|
||||
<input type="text" class="form-control" id="inputILinkAddDevice" placeholder="http://...." bind:value="{addDevice.link}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-auto ms-auto">
|
||||
|
||||
+1
-17
@@ -1,23 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
# set ping interval
|
||||
if [ -z "$PING_INTERVAL" ]; then
|
||||
PING_INTERVAL=5
|
||||
elif [ "$PING_INTERVAL" -lt 5 ]; then
|
||||
echo ""
|
||||
echo "Ping interval lower than 5 seconds is not recommended. Please use an interval of 5 seconds or higher. Automatically set to 5 seconds."
|
||||
echo ""
|
||||
PING_INTERVAL=5
|
||||
fi
|
||||
|
||||
# create django secret key
|
||||
cd /app/backend/ || exit
|
||||
if [ -z "$DJANGO_SECRET_KEY" ]; then
|
||||
DJANGO_SECRET_KEY=$(python3 -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())')
|
||||
export DJANGO_SECRET_KEY
|
||||
fi
|
||||
|
||||
# init django
|
||||
cd /app/backend/ || exit
|
||||
python3 manage.py makemigrations
|
||||
python3 manage.py migrate
|
||||
python3 manage.py collectstatic --noinput
|
||||
|
||||
@@ -34,12 +34,13 @@ services:
|
||||
ports:
|
||||
- "6379:6379"
|
||||
restart: unless-stopped
|
||||
command: redis-server --loglevel warning
|
||||
healthcheck:
|
||||
test: redis-cli ping
|
||||
interval: 10s
|
||||
mysql:
|
||||
container_name: upsnap_mysql
|
||||
image: mysql
|
||||
image: mariadb
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "3306:3306"
|
||||
|
||||
@@ -34,6 +34,7 @@ services:
|
||||
ports:
|
||||
- "6379:6379"
|
||||
restart: unless-stopped
|
||||
command: redis-server --loglevel warning
|
||||
healthcheck:
|
||||
test: redis-cli ping
|
||||
interval: 10s
|
||||
|
||||
@@ -27,6 +27,7 @@ services:
|
||||
ports:
|
||||
- "6379:6379"
|
||||
restart: unless-stopped
|
||||
command: redis-server --loglevel warning
|
||||
healthcheck:
|
||||
test: redis-cli ping
|
||||
interval: 10s
|
||||
|
||||
Reference in New Issue
Block a user