mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-11-27 20:32:04 +00:00
Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d9f3ecb04 | |||
| 7c483d99c8 | |||
| 6b076b5009 | |||
| f8e1ede7cb | |||
| 4eecbe3cff | |||
| 78dd8e3b23 | |||
| 63d8e2c285 | |||
| 4571b46353 | |||
| 2d33ada47c | |||
| bc5c9497a1 | |||
| 6a472beaee | |||
| a34c419fd9 | |||
| 221cb86000 | |||
| d4aac95fcd | |||
| 0f0a0ac98b | |||
| 36cef610c3 | |||
| fdb19e5cfb | |||
| 705008898f | |||
| 2e251f309c | |||
| 21218ef91a | |||
| d08b8b3722 | |||
| e02ecbc639 | |||
| 42bb71a017 | |||
| 20a3ddea1a | |||
| 4906ce722b | |||
| f36be22e46 | |||
| b1e8eaf864 | |||
| 01afbd1919 | |||
| 97e0d94d24 | |||
| 35df2757fd | |||
| ccc53c5349 | |||
| 5f1a68ab36 | |||
| daff99510f | |||
| cff1705a9f | |||
| d15810d8b2 | |||
| 9e9fed767e | |||
| 58fedcec48 | |||
| 39f59b99ae | |||
| 767e3e0436 |
@@ -285,3 +285,9 @@ $RECYCLE.BIN/
|
||||
|
||||
.vscode
|
||||
staticfiles
|
||||
|
||||
# JetBrains WebStorm
|
||||
.idea/
|
||||
|
||||
# custom
|
||||
docker-compose.yml
|
||||
|
||||
@@ -34,10 +34,26 @@ There are 3 example docker-compose files to choose from. The simplest is [docker
|
||||
|
||||
The website will be available at [localhost:8000](http://localhost:8000). If you run it on a different pc, it will be `http://<your-ip>:8000`. You can change the port in the docker-compose file.
|
||||
|
||||
### Reverse Proxy
|
||||
|
||||
If you're using a reverse proxy, make sure to set `BACKEND_IS_PROXIED` to true in docker-compose. Set your reverse proxy to the `FRONTEND_PORT` and set `/wol/` to `BACKEND_PORT`.
|
||||
|
||||
**Caddy example**
|
||||
```
|
||||
upsnap.example.com {
|
||||
reverse_proxy localhost:8000
|
||||
reverse_proxy /wol/ localhost:8001
|
||||
}
|
||||
```
|
||||
|
||||
### Databases
|
||||
|
||||
Upsnap supports 3 different databases. Postgres, MySQL and SQLite. If you already have an existing database you want to use, delete the database container from the compose file. Always make sure to set the correct database type environment variable, e.g. DB_TYPE=mysql
|
||||
|
||||
### Windows
|
||||
|
||||
There is a partly working solution in the [issue here](https://github.com/seriousm4x/UpSnap/issues/20#issuecomment-1142593360). Windows has problems with docker networking mode host, which breaks network scan. Sending wol packages works though.
|
||||
|
||||
## 📝 Other infos
|
||||
|
||||
* The app container needs to run in host network mode to send the wakeonlan command on your local network. Therefore all other containers also need to run in host network mode. I don't like it but there is no way around.
|
||||
|
||||
@@ -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'
|
||||
@@ -114,7 +116,7 @@ elif os.getenv("DB_TYPE") == "sqlite":
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME" : "db.sqlite3",
|
||||
"NAME": "/app/backend/db/db.sqlite3",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.2.2"
|
||||
|
||||
+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,
|
||||
@@ -82,7 +84,17 @@ class WSConsumer(AsyncWebsocketConsumer):
|
||||
}
|
||||
)
|
||||
elif received["type"] == "update_device":
|
||||
await self.update_device(received["data"])
|
||||
try:
|
||||
await self.update_device(received["data"])
|
||||
await self.send(text_data=json.dumps({
|
||||
"type": "operationStatus",
|
||||
"message": "Success"
|
||||
}))
|
||||
except Exception:
|
||||
await self.send(text_data=json.dumps({
|
||||
"type": "operationStatus",
|
||||
"message": "Error"
|
||||
}))
|
||||
elif received["type"] == "update_port":
|
||||
await self.update_port(received["data"])
|
||||
elif received["type"] == "update_settings":
|
||||
@@ -138,6 +150,7 @@ class WSConsumer(AsyncWebsocketConsumer):
|
||||
"ip": dev.ip,
|
||||
"mac": dev.mac,
|
||||
"netmask": dev.netmask,
|
||||
"link": dev.link,
|
||||
"ports": [],
|
||||
"wake": {
|
||||
"enabled": False,
|
||||
@@ -165,7 +178,7 @@ class WSConsumer(AsyncWebsocketConsumer):
|
||||
wake = CrontabSchedule.objects.get(id=task.crontab_id)
|
||||
data[action]["enabled"] = task.enabled
|
||||
data[action]["cron"] = " ".join(
|
||||
[wake.minute, wake.hour, wake.day_of_week, wake.day_of_month, wake.month_of_year])
|
||||
[wake.minute, wake.hour, wake.day_of_month, wake.month_of_year, wake.day_of_week])
|
||||
except PeriodicTask.DoesNotExist:
|
||||
pass
|
||||
d.append(data)
|
||||
@@ -184,6 +197,7 @@ class WSConsumer(AsyncWebsocketConsumer):
|
||||
"name": data["name"],
|
||||
"ip": data["ip"],
|
||||
"netmask": data["netmask"],
|
||||
"link": data["link"] if data.get("link") else "",
|
||||
"shutdown_cmd": data["shutdown"]["command"] if data.get("shutdown") else ""
|
||||
}
|
||||
)
|
||||
@@ -210,7 +224,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 +321,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
+459
-3958
File diff suppressed because it is too large
Load Diff
@@ -20,11 +20,12 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-free": "^6.0.0",
|
||||
"@popperjs/core": "^2.11.5",
|
||||
"@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"
|
||||
}
|
||||
|
||||
@@ -6,12 +6,13 @@
|
||||
|
||||
<title>UpSnap</title>
|
||||
|
||||
<link rel='icon' type='image/png' href='/favicon.png'>
|
||||
<link rel='stylesheet' href='/global.css'>
|
||||
<link rel='stylesheet' href='/build/bundle.css'>
|
||||
<link rel='icon' type='image/png' href='favicon.png'>
|
||||
<link rel='stylesheet' href='global.css'>
|
||||
<link rel='stylesheet' href='build/bundle.css'>
|
||||
|
||||
<script defer src='/build/bundle.js'></script>
|
||||
<script defer src='/build/bootstrap.min.js'></script>
|
||||
<script defer src='build/bundle.js'></script>
|
||||
<script defer src='build/popper.min.js'></script>
|
||||
<script defer src='build/bootstrap.min.js'></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@@ -52,6 +52,7 @@ export default {
|
||||
}),
|
||||
replace({
|
||||
BACKEND_PORT: JSON.stringify(process.env.BACKEND_PORT),
|
||||
BACKEND_IS_PROXIED: JSON.stringify(process.env.BACKEND_IS_PROXIED.toLowerCase() === 'true'),
|
||||
preventAssignment: true
|
||||
}),
|
||||
// we'll extract any component CSS out into
|
||||
@@ -63,7 +64,9 @@ export default {
|
||||
src: [
|
||||
"node_modules/@fortawesome/fontawesome-free/webfonts",
|
||||
"node_modules/bootstrap/dist/js/bootstrap.min.js",
|
||||
"node_modules/bootstrap/dist/js/bootstrap.min.js.map"
|
||||
"node_modules/bootstrap/dist/js/bootstrap.min.js.map",
|
||||
"node_modules/@popperjs/core/dist/umd/popper.min.js",
|
||||
"node_modules/@popperjs/core/dist/umd/popper.min.js.map"
|
||||
],
|
||||
dest: "public/build/"
|
||||
}
|
||||
|
||||
+24
-12
@@ -1,6 +1,6 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import store from './store.js';
|
||||
import socketStore from './socketStore.js';
|
||||
import Navbar from "./components/Navbar.svelte";
|
||||
import DeviceCard from "./components/DeviceCard.svelte";
|
||||
import Toast from "./components/Toast.svelte";
|
||||
@@ -16,7 +16,17 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
store.subscribe(currentMessage => {
|
||||
socketStore.subscribeStatus(status => {
|
||||
if (status == "open") {
|
||||
showToast("Websocket", "Connected", "success")
|
||||
} else if (status == "close") {
|
||||
showToast("Websocket", "Connection closed. Trying to reconnect ...", "danger")
|
||||
} else if (status == "error") {
|
||||
showToast("Websocket", "Error when connecting to websocket", "danger")
|
||||
}
|
||||
})
|
||||
|
||||
socketStore.subscribeMsg(currentMessage => {
|
||||
if (currentMessage.type == "init") {
|
||||
// create devices
|
||||
devices = [...currentMessage.message.devices]
|
||||
@@ -70,6 +80,12 @@
|
||||
a.href = URL.createObjectURL(file);
|
||||
a.download = fileName;
|
||||
a.click();
|
||||
} else if (currentMessage.type == "operationStatus") {
|
||||
if (currentMessage.message == "Success") {
|
||||
showToast(currentMessage.message, "Changes were saved", "success")
|
||||
} else if (currentMessage.message == "Error") {
|
||||
showToast(currentMessage.message, "Error while saving the device. Please check the logs.", "danger")
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -84,11 +100,9 @@
|
||||
dot.style.animation = "none";
|
||||
dot.offsetWidth;
|
||||
if (!spinner.classList.contains("d-none")) {
|
||||
if (dot.classList.contains("danger")) {
|
||||
spinner.classList.add("d-none");
|
||||
dot.classList.remove("d-none", "danger");
|
||||
dot.classList.add("success");
|
||||
}
|
||||
spinner.classList.add("d-none");
|
||||
dot.classList.remove("d-none", "danger");
|
||||
dot.classList.add("success");
|
||||
} else {
|
||||
dot.style.animation = "on-pulse 1s normal";
|
||||
}
|
||||
@@ -105,11 +119,9 @@
|
||||
dot.style.animation = "none";
|
||||
dot.offsetWidth;
|
||||
if (!spinner.classList.contains("d-none")) {
|
||||
if (dot.classList.contains("success")) {
|
||||
spinner.classList.add("d-none");
|
||||
dot.classList.remove("d-none", "success");
|
||||
dot.classList.add("danger");
|
||||
}
|
||||
spinner.classList.add("d-none");
|
||||
dot.classList.remove("d-none", "success");
|
||||
dot.classList.add("danger");
|
||||
} else {
|
||||
dot.style.animation = "off-pulse 1s normal";
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
<script>
|
||||
import store from '../store.js';
|
||||
import socketStore from '../socketStore.js';
|
||||
export let device;
|
||||
|
||||
let modalDevice = JSON.parse(JSON.stringify(device));
|
||||
let customPort = {}
|
||||
|
||||
function wake(id) {
|
||||
store.sendMessage({
|
||||
socketStore.sendMessage({
|
||||
type: "wake",
|
||||
id: id
|
||||
})
|
||||
}
|
||||
|
||||
function shutdown(id) {
|
||||
store.sendMessage({
|
||||
socketStore.sendMessage({
|
||||
type: "shutdown",
|
||||
id: id
|
||||
})
|
||||
}
|
||||
|
||||
function deleteDevice() {
|
||||
store.sendMessage({
|
||||
socketStore.sendMessage({
|
||||
type: "delete_device",
|
||||
id: modalDevice.id
|
||||
})
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
function updateDevice() {
|
||||
device = modalDevice;
|
||||
store.sendMessage({
|
||||
socketStore.sendMessage({
|
||||
type: "update_device",
|
||||
data: modalDevice
|
||||
})
|
||||
@@ -56,7 +56,7 @@
|
||||
}
|
||||
modalDevice = modalDevice;
|
||||
// send to backend
|
||||
store.sendMessage({
|
||||
socketStore.sendMessage({
|
||||
type: "update_port",
|
||||
data: customPort
|
||||
})
|
||||
@@ -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>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import store from '../store.js';
|
||||
import socketStore from '../socketStore.js';
|
||||
import DarkToggle from "./DarkToggle.svelte";
|
||||
export let visitors;
|
||||
export let settings;
|
||||
@@ -20,14 +20,14 @@
|
||||
if (Object.keys(data).length < 4) {
|
||||
return
|
||||
}
|
||||
store.sendMessage({
|
||||
socketStore.sendMessage({
|
||||
type: "update_device",
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
function updateSettings() {
|
||||
store.sendMessage({
|
||||
socketStore.sendMessage({
|
||||
type: "update_settings",
|
||||
data: settings
|
||||
})
|
||||
@@ -35,7 +35,7 @@
|
||||
}
|
||||
|
||||
function scanNetwork() {
|
||||
store.sendMessage({
|
||||
socketStore.sendMessage({
|
||||
type: "scan_network"
|
||||
})
|
||||
const btnScan = document.querySelector("#btnScan");
|
||||
@@ -67,6 +67,7 @@
|
||||
// v1 file restore
|
||||
for (const [key, value] of Object.entries(data)) {
|
||||
value["mac"] = key
|
||||
value["link"] = ""
|
||||
updateDevice(value)
|
||||
}
|
||||
}
|
||||
@@ -75,7 +76,7 @@
|
||||
}
|
||||
|
||||
function backupToFile() {
|
||||
store.sendMessage({
|
||||
socketStore.sendMessage({
|
||||
type: "backup"
|
||||
})
|
||||
}
|
||||
@@ -91,7 +92,7 @@
|
||||
<nav class="navbar navbar-expand-sm">
|
||||
<div class="container-fluid">
|
||||
<div class="navbar-brand" href="/">
|
||||
<img src="/favicon.png" alt="Logo" width="24" height="24" class="me-2">
|
||||
<img src="favicon.png" alt="Logo" width="24" height="24" class="me-2">
|
||||
UpSnap
|
||||
</div>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
|
||||
@@ -162,6 +163,12 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<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 class="row">
|
||||
<div class="col-auto ms-auto">
|
||||
<button type="submit" form="addForm" class="btn btn-outline-success">Add device</button>
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import {
|
||||
writable
|
||||
} from 'svelte/store';
|
||||
|
||||
const status = writable('');
|
||||
const message = writable('');
|
||||
let socket;
|
||||
|
||||
function initSocket() {
|
||||
if (BACKEND_IS_PROXIED) {
|
||||
const socketUrl = new URL('wol/', window.location.href);
|
||||
socketUrl.protocol = socketUrl.protocol.replace('http', 'ws');
|
||||
|
||||
socket = new WebSocket(socketUrl);
|
||||
}
|
||||
else {
|
||||
socket = new WebSocket(`ws://${location.hostname}:${BACKEND_PORT}/wol/`);
|
||||
}
|
||||
|
||||
// Connection opened
|
||||
socket.addEventListener('open', function () {
|
||||
status.set("open");
|
||||
});
|
||||
|
||||
// Connection closed
|
||||
socket.addEventListener('close', function () {
|
||||
status.set("close");
|
||||
setTimeout(function () {
|
||||
initSocket();
|
||||
}, 3000);
|
||||
});
|
||||
|
||||
// Connection error
|
||||
socket.addEventListener('error', function () {
|
||||
status.set("error");
|
||||
socket.close()
|
||||
});
|
||||
|
||||
// Listen for messages
|
||||
socket.addEventListener('message', function (event) {
|
||||
message.set(JSON.parse(event.data));
|
||||
});
|
||||
}
|
||||
|
||||
initSocket()
|
||||
|
||||
const sendMessage = (message) => {
|
||||
if (socket.readyState <= 1) {
|
||||
socket.send(JSON.stringify(message));
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
subscribeMsg: message.subscribe,
|
||||
subscribeStatus: status.subscribe,
|
||||
sendMessage
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import {
|
||||
writable
|
||||
} from 'svelte/store';
|
||||
|
||||
const messageStore = writable('');
|
||||
const socket = new WebSocket(`ws://${location.hostname}:${BACKEND_PORT}/wol/`);
|
||||
|
||||
// Connection opened
|
||||
socket.addEventListener('open', function (event) {
|
||||
return
|
||||
});
|
||||
|
||||
// Listen for messages
|
||||
socket.addEventListener('message', function (event) {
|
||||
messageStore.set(JSON.parse(event.data));
|
||||
});
|
||||
|
||||
const sendMessage = (message) => {
|
||||
if (socket.readyState <= 1) {
|
||||
socket.send(JSON.stringify(message));
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
subscribe: messageStore.subscribe,
|
||||
sendMessage
|
||||
}
|
||||
+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
|
||||
|
||||
@@ -8,6 +8,7 @@ services:
|
||||
environment:
|
||||
- FRONTEND_PORT=8000
|
||||
- BACKEND_PORT=8001
|
||||
- BACKEND_IS_PROXIED=false # set this to true, if you use a reverse proxy
|
||||
- DB_TYPE=mysql # required
|
||||
- REDIS_HOST=127.0.0.1 # required (make sure to use the same ip as below)
|
||||
- REDIS_PORT=6379 # required (make sure to use the same port as below)
|
||||
@@ -34,12 +35,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"
|
||||
|
||||
@@ -8,6 +8,7 @@ services:
|
||||
environment:
|
||||
- FRONTEND_PORT=8000
|
||||
- BACKEND_PORT=8001
|
||||
- BACKEND_IS_PROXIED=false # set this to true, if you use a reverse proxy
|
||||
- DB_TYPE=postgres # required
|
||||
- REDIS_HOST=127.0.0.1 # required (make sure to use the same ip as below)
|
||||
- REDIS_PORT=6379 # required (make sure to use the same port as below)
|
||||
@@ -34,6 +35,7 @@ services:
|
||||
ports:
|
||||
- "6379:6379"
|
||||
restart: unless-stopped
|
||||
command: redis-server --loglevel warning
|
||||
healthcheck:
|
||||
test: redis-cli ping
|
||||
interval: 10s
|
||||
|
||||
@@ -8,6 +8,7 @@ services:
|
||||
environment:
|
||||
- FRONTEND_PORT=8000
|
||||
- BACKEND_PORT=8001
|
||||
- BACKEND_IS_PROXIED=false # set this to true, if you use a reverse proxy
|
||||
- DB_TYPE=sqlite # required
|
||||
- REDIS_HOST=127.0.0.1 # required (make sure to use the same ip as below)
|
||||
- REDIS_PORT=6379 # required (make sure to use the same port as below)
|
||||
@@ -18,6 +19,8 @@ services:
|
||||
#- DJANGO_DEBUG=True # optional (default: False)
|
||||
#- DJANGO_LANGUAGE_CODE=de # optional (default: en)
|
||||
#- DJANGO_TIME_ZONE=Europe/Berlin # optional (default: UTC)
|
||||
volumes:
|
||||
- ./db/:/app/backend/db/
|
||||
depends_on:
|
||||
redis:
|
||||
condition: service_healthy
|
||||
@@ -27,6 +30,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