Compare commits

...

45 Commits

Author SHA1 Message Date
seriousm4x 24916af042 Run on GitHub Ubuntu 2023-01-16 23:51:28 +01:00
Maxi Quoß fe273013a7 json backup: only add relevant ports to device 2023-01-16 20:19:31 +01:00
Maxi Quoß c0b055ed1b temp fix for #31 2022-12-15 22:02:53 +01:00
Maxi Quoß a7dd5ab74c v2.3.0 2022-12-04 11:29:01 +01:00
Maxi Quoß 2aabf0f0c5 add custom website title, close #29 2022-12-04 11:26:24 +01:00
Maxi Quoß 87915b2dd3 add option for custom nmap args #28 2022-12-04 11:00:46 +01:00
Maxi Quoß 375abd0c42 code formatting and remove regex 2022-12-04 10:53:11 +01:00
Maxi Quoß f5a9a480d4 v2.2.3 2022-08-23 20:42:28 +02:00
Maxi Quoß ddbe52918c add curl to docker image, close #24 2022-08-23 20:41:01 +02:00
Maxi Quoß ba806970a0 exclude db directory 2022-08-04 20:37:21 +02:00
Maxi Quoß 0d9f3ecb04 v2.2.2 2022-07-31 12:20:58 +02:00
Maxi Quoß 7c483d99c8 mount db dir for persistent sqlite #23 2022-07-31 12:19:06 +02:00
Maxi Quoß 6b076b5009 v2.2.1 2022-07-26 14:02:35 +02:00
Maxi Quoß f8e1ede7cb stringify bool correctly 2022-07-26 13:59:39 +02:00
Maxi Quoß 4eecbe3cff fix convert bool for BACKEND_IS_PROXIED
!!'false' converts into true. comparing the string fixes the bool
2022-07-26 13:50:46 +02:00
Maxi Quoß 78dd8e3b23 add popperjs to fix dropdowns 2022-07-26 13:23:31 +02:00
Maxi Quoß 63d8e2c285 update version info 2022-07-23 12:34:10 +02:00
seriousm4x 4571b46353 Delete package-lock.json 2022-07-23 11:57:08 +02:00
Maxi Quoß 2d33ada47c npm update 2022-07-23 11:15:14 +02:00
Maxi Quoß bc5c9497a1 add reverse proxy to docker-comopse and readme 2022-07-23 11:13:46 +02:00
seriousm4x 6a472beaee Merge pull request #22 from jarrettgilliam/master
Add reverse proxy support
2022-07-23 11:05:52 +02:00
Jarrett Gilliam a34c419fd9 Use relative resource paths for better reverse proxy support
The app can now be proxied under a subfolder as well as a subdomain. Something like: http://example.com/upsnap/
2022-07-22 16:09:26 -05:00
Jarrett Gilliam 221cb86000 The frontend and backend can now be reverse proxied together 2022-07-22 14:45:50 -05:00
Jarrett Gilliam d4aac95fcd Ignore the JetBrains WebStorm .idea folder 2022-07-22 14:03:28 -05:00
Maxi Quoß 0f0a0ac98b define socket outside of func 2022-06-02 12:34:06 +02:00
Maxi Quoß 36cef610c3 add windows notice #20 2022-05-31 22:24:40 +02:00
Maxi Quoß fdb19e5cfb websocket: add notifications and reconnect on error 2022-05-31 21:31:56 +02:00
Maxi Quoß 705008898f close #19 2022-05-31 20:28:20 +02:00
seriousm4x 2e251f309c fix cron order 2022-05-31 18:01:30 +02:00
Maxi Quoß 21218ef91a no exception var needed here #18 2022-05-24 23:19:01 +02:00
Maxi Quoß d08b8b3722 add notifications for device updates #18 2022-05-24 23:17:47 +02:00
Maxi Quoß e02ecbc639 v2.0.6 2022-05-03 18:55:26 +02:00
Maxi Quoß 42bb71a017 also fix key error in consumers, just to make sure 2022-04-30 22:01:01 +02:00
Maxi Quoß 20a3ddea1a v2.0.5 2022-04-30 17:58:27 +02:00
Maxi Quoß 4906ce722b fix key error link when restoring from v1 #17 2022-04-30 17:57:27 +02:00
Maxi Quoß f36be22e46 remove row 2022-04-22 21:24:12 +02:00
Maxi Quoß b1e8eaf864 close div 2022-04-22 21:19:53 +02:00
Maxi Quoß 01afbd1919 v2.0.4 2022-04-22 11:40:57 +02:00
Maxi Quoß 97e0d94d24 add clickable link for devices, close #13 2022-04-21 20:20:33 +02:00
Maxi Quoß 35df2757fd less verbose redis logs 2022-04-21 19:43:37 +02:00
Maxi Quoß ccc53c5349 fix #15 2022-04-21 19:41:59 +02:00
Maxi Quoß 5f1a68ab36 v2.0.3 2022-04-01 22:23:58 +02:00
Maxi Quoß daff99510f use mariadb for arm64 support 2022-04-01 22:18:17 +02:00
Maxi Quoß cff1705a9f npm update 2022-03-28 22:47:39 +02:00
Maxi Quoß d15810d8b2 replace node-sass with sass #11
node-sass is deprecated and doesn't work on arm64 https://sass-lang.com/blog/libsass-is-deprecated
2022-03-28 22:46:27 +02:00
26 changed files with 1526 additions and 4332 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ on:
jobs:
build:
runs-on: self-hosted
runs-on: ubuntu-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v2
+7
View File
@@ -285,3 +285,10 @@ $RECYCLE.BIN/
.vscode
staticfiles
# JetBrains WebStorm
.idea/
# custom
docker-compose.yml
db/
+1 -1
View File
@@ -24,7 +24,7 @@ WORKDIR /app
ENV PYTHONUNBUFFERED 1
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update &&\
apt-get install -y --no-install-recommends default-mysql-client nodejs npm iputils-ping nmap samba-common-bin openssh-client sshpass &&\
apt-get install -y --no-install-recommends default-mysql-client nodejs npm iputils-ping nmap samba-common-bin openssh-client sshpass curl &&\
apt-get clean &&\
rm -rf /var/lib/{apt,dpkg,cache,log}/
COPY --from=python-build /opt/venv /opt/venv
+16
View File
@@ -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.
+1
View File
@@ -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()
+3 -3
View File
@@ -116,11 +116,11 @@ elif os.getenv("DB_TYPE") == "sqlite":
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME" : "db.sqlite3",
"NAME": "/app/backend/db/db.sqlite3",
}
}
CHANNEL_LAYERS = {
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
@@ -174,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.2"
VERSION = "v2.3.2"
+1 -1
View File
@@ -1,6 +1,6 @@
celery[redis]
channels
channels-redis
channels-redis==3.4.1
django
django-celery-beat
gunicorn
+7 -1
View File
@@ -1,7 +1,7 @@
import os
from django.contrib.auth.models import User
from django_celery_beat.models import IntervalSchedule, PeriodicTask
from django_celery_beat.models import IntervalSchedule, PeriodicTask, PeriodicTasks
from wol.models import Settings, Websocket
@@ -43,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)
+23 -8
View File
@@ -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,
@@ -149,12 +162,10 @@ class WSConsumer(AsyncWebsocketConsumer):
"command": dev.shutdown_cmd
}
}
for p in Port.objects.all().order_by("number"):
for p in dev.port.order_by("number"):
data["ports"].append({
"number": p.number,
"name": p.name,
"checked": False,
"open": False
"name": p.name
})
for action in ["wake", "shutdown"]:
try:
@@ -165,7 +176,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 +195,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 +222,9 @@ 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}",
@@ -282,7 +296,7 @@ class WSConsumer(AsyncWebsocketConsumer):
return
p = subprocess.Popen(
["nmap", "-sP", conf.scan_address], stdout=subprocess.PIPE)
["nmap", os.getenv("NMAP_ARGS", "-sP"), conf.scan_address], stdout=subprocess.PIPE)
out = p.communicate()[0].decode("utf-8")
ip_line = "Nmap scan report for"
mac_line = "MAC Address:"
@@ -306,6 +320,7 @@ class WSConsumer(AsyncWebsocketConsumer):
"ip": ip,
"netmask": netmask,
"mac": mac,
"link": "",
"ports": [],
"wake": {
"enabled": False,
+1
View File
@@ -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)
+1
View File
@@ -37,6 +37,7 @@ class WolDevice:
"mac": dev.mac,
"netmask": dev.netmask,
"up": False,
"link": dev.link,
"ports": [],
"wake": {
"enabled": False,
+496 -3991
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -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"
}
+8 -7
View File
@@ -1,19 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<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>
</body>
</html>
+5 -1
View File
@@ -52,6 +52,8 @@ export default {
}),
replace({
BACKEND_PORT: JSON.stringify(process.env.BACKEND_PORT),
BACKEND_IS_PROXIED: JSON.stringify(process.env.BACKEND_IS_PROXIED.toLowerCase() === 'true'),
PAGE_TITLE: JSON.stringify(process.env.PAGE_TITLE),
preventAssignment: true
}),
// we'll extract any component CSS out into
@@ -63,7 +65,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/"
}
+3 -3
View File
@@ -3,7 +3,7 @@
/** This script modifies the project to support TS code in .svelte files like:
<script lang="ts">
export let name: string;
export let name: string;
</script>
As well as validating the code for CI.
@@ -82,11 +82,11 @@ const tsconfig = `{
"include": ["src/**/*"],
"exclude": ["node_modules/*", "__sapper__/*", "public/*"]
}`
const tsconfigPath = path.join(projectRoot, "tsconfig.json")
const tsconfigPath = path.join(projectRoot, "tsconfig.json")
fs.writeFileSync(tsconfigPath, tsconfig)
// Add global.d.ts
const dtsPath = path.join(projectRoot, "src", "global.d.ts")
const dtsPath = path.join(projectRoot, "src", "global.d.ts")
fs.writeFileSync(dtsPath, `/// <reference types="svelte" />`)
// Delete this script, but not during testing
+119 -83
View File
@@ -1,38 +1,58 @@
<script>
import { onMount } from 'svelte';
import store from './store.js';
import { onMount } from "svelte";
import socketStore from "./socketStore.js";
import Navbar from "./components/Navbar.svelte";
import DeviceCard from "./components/DeviceCard.svelte";
import Toast from "./components/Toast.svelte";
let visitors = 0;
let devices = [];
let settings = {}
let settings = {};
let toast = {
title: "",
message: "",
color: "",
show: false
}
show: false,
};
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]
devices = [...currentMessage.message.devices];
devices = devices;
devices.sort(compare);
settings = currentMessage.message.settings;
} else if (currentMessage.type == "status") {
// set device array and sort
const index = devices.findIndex(x => x.id == currentMessage.message.id);
const index = devices.findIndex(
(x) => x.id == currentMessage.message.id
);
if (devices.length === 0 || index === -1) {
devices.push(currentMessage.message);
devices = devices;
} else {
devices[index] = currentMessage.message;
}
devices.sort(compare)
devices.sort(compare);
// set device status
if (currentMessage.message.up == true) {
setUp(currentMessage.message);
@@ -41,22 +61,25 @@
}
} else if (currentMessage.type == "pending") {
// set device pending
setPending(currentMessage.message)
setPending(currentMessage.message);
} else if (currentMessage.type == "visitor") {
// update visitor count
visitors = currentMessage.message;
} else if (currentMessage.type == "delete") {
// delete device
const devCol = document.querySelector(`#device-col-${currentMessage.message}`);
const devCol = document.querySelector(
`#device-col-${currentMessage.message}`
);
devCol.remove();
} else if (currentMessage.type == "scan_network") {
// set scanned network devices
if (!currentMessage.message) {
return
return;
}
settings["scan_network"] = currentMessage.message;
const btnScan = document.querySelector("#btnScan");
const btnScanSpinner = document.querySelector("#btnScanSpinner");
const btnScanSpinner =
document.querySelector("#btnScanSpinner");
const btnScanText = document.querySelector("#btnScanText");
btnScan.disabled = false;
btnScanSpinner.classList.add("d-none");
@@ -64,31 +87,46 @@
} else if (currentMessage.type == "backup") {
// download backup file
const now = new Date();
const fileName = `upsnap_backup_${now.toISOString()}.json`
const fileName = `upsnap_backup_${now.toISOString()}.json`;
const a = document.createElement("a");
const file = new Blob([JSON.stringify(currentMessage.message)], { type: "text/plain" });
const file = new Blob(
[JSON.stringify(currentMessage.message)],
{ type: "text/plain" }
);
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"
);
}
}
})
})
});
});
function setUp(device) {
const dot = document.querySelector(`#dot-${device.id}`)
const dot = document.querySelector(`#dot-${device.id}`);
const spinner = document.querySelector(`#spinner-${device.id}`);
if (dot) {
if (dot.classList.contains("danger")) {
showToast(device.name, "Device is up!", "success")
showToast(device.name, "Device is up!", "success");
}
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";
}
@@ -96,20 +134,18 @@
}
function setDown(device) {
const dot = document.querySelector(`#dot-${device.id}`)
const dot = document.querySelector(`#dot-${device.id}`);
const spinner = document.querySelector(`#spinner-${device.id}`);
if (dot) {
if (dot.classList.contains("success")) {
showToast(device.name, "Device is down!", "danger")
showToast(device.name, "Device is down!", "danger");
}
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";
}
@@ -125,7 +161,7 @@
function showToast(title, message, color) {
if (settings.notifications === false) {
return
return;
}
toast.title = title;
toast.message = message;
@@ -133,31 +169,30 @@
toast.show = true;
setTimeout(() => {
toast.show = false;
}, 4000)
}, 4000);
}
function compare(a, b) {
if (a.name < b.name){
if (a.name < b.name) {
return -1;
}
if (a.name > b.name){
if (a.name > b.name) {
return 1;
}
return 0;
}
</script>
<main>
<Navbar settings={settings} visitors={visitors} />
<Navbar {settings} {visitors} />
<div class="container mb-3">
<div class="row">
{#each devices as device}
<DeviceCard device={device}/>
<DeviceCard {device} />
{/each}
</div>
</div>
<Toast toast={toast} />
<Toast {toast} />
</main>
<style lang="scss" global>
@@ -189,29 +224,30 @@
border-top: 1px solid var(--color-text);
}
.btn, button {
.btn,
button {
&.btn-light {
color: var(--color-text);
background-color: var(--bg-lighter);
border-width: 0px;
}
&.btn-outline-success {
border-color: $success;
&:hover {
background-color: $success;
}
}
&.btn-outline-success {
border-color: $success;
&:hover {
background-color: $success;
}
}
&.btn-outline-danger {
border-color: $danger;
&:hover {
background-color: $danger;
}
}
}
&.btn-outline-danger {
border-color: $danger;
&:hover {
background-color: $danger;
}
}
}
.form-control{
.form-control {
&:focus {
border-color: inherit;
box-shadow: none;
@@ -219,48 +255,48 @@
}
.callout {
padding: 1rem;
border-left-width: 0.25rem;
border-radius: 0.25rem;
padding: 1rem;
border-left-width: 0.25rem;
border-radius: 0.25rem;
&.callout-info {
&.callout-info {
background-color: var(--info-dark-transparent);
border: 1px solid var(--info-dark-transparent);
border-left: 5px solid var(--info);
}
}
&.callout-danger {
&.callout-danger {
background-color: var(--danger-dark-transparent);
border: 1px solid var(--danger-dark-transparent);
border-left: 5px solid var(--danger);
}
}
}
}
@keyframes on-pulse {
0% {
box-shadow: 0 0 0 0 $success;
}
0% {
box-shadow: 0 0 0 0 $success;
}
70% {
box-shadow: 0 0 0 15px rgba(0, 0, 0, 0);
}
70% {
box-shadow: 0 0 0 15px rgba(0, 0, 0, 0);
}
100% {
box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
}
}
100% {
box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
}
}
@keyframes off-pulse {
0% {
box-shadow: 0 0 0 0 $danger;
}
@keyframes off-pulse {
0% {
box-shadow: 0 0 0 0 $danger;
}
70% {
box-shadow: 0 0 0 15px rgba(0, 0, 0, 0);
}
70% {
box-shadow: 0 0 0 15px rgba(0, 0, 0, 0);
}
100% {
box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
}
}
100% {
box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
}
}
</style>
+19 -12
View File
@@ -1,10 +1,9 @@
<script>
const preferesDark = window.matchMedia("(prefers-color-scheme: dark)");
preferesDark.addEventListener("change", e => {
preferesDark.addEventListener("change", (e) => {
setTheme(e.matches ? "dark" : "light");
})
});
if (localStorage.getItem("data-theme") === null) {
setTheme(preferesDark.matches ? "dark" : "light");
@@ -12,36 +11,44 @@
setTheme(localStorage.getItem("data-theme"));
}
function setTheme(color) {
function setTheme(color) {
if (color == "system") {
document.documentElement.setAttribute("data-theme", preferesDark ? "dark" : "light");
document.documentElement.setAttribute(
"data-theme",
preferesDark ? "dark" : "light"
);
localStorage.setItem("data-theme", preferesDark ? "dark" : "light");
} else {
document.documentElement.setAttribute("data-theme", color);
localStorage.setItem("data-theme", color);
}
}
}
</script>
<div class="dropdown">
<button class="btn btn-light dropdown-toggle px-3 me-2 py-2" type="button" id="darkModeButton" data-bs-toggle="dropdown" aria-expanded="false">
<i class="fa-solid fa-palette me-2"></i>Theme
<button
class="btn btn-light dropdown-toggle px-3 me-2 py-2"
type="button"
id="darkModeButton"
data-bs-toggle="dropdown"
aria-expanded="false"
>
<i class="fa-solid fa-palette me-2" />Theme
</button>
<ul class="dropdown-menu" aria-labelledby="darkModeButton">
<li>
<button class="dropdown-item" on:click={() => setTheme("dark")}>
<i class="fa-solid fa-moon me-2"></i>Dark
<i class="fa-solid fa-moon me-2" />Dark
</button>
</li>
<li>
<button class="dropdown-item" on:click={() => setTheme("light")}>
<i class="fa-solid fa-sun me-2"></i>Light
<i class="fa-solid fa-sun me-2" />Light
</button>
</li>
<li>
<button class="dropdown-item" on:click={() => setTheme("system")}>
<i class="fa-solid fa-desktop me-2"></i>System
<i class="fa-solid fa-desktop me-2" />System
</button>
</li>
</ul>
+449 -108
View File
@@ -1,44 +1,46 @@
<script>
import store from '../store.js';
import socketStore from "../socketStore.js";
export let device;
let modalDevice = JSON.parse(JSON.stringify(device));
let customPort = {}
let customPort = {};
function wake(id) {
store.sendMessage({
function wake(id) {
socketStore.sendMessage({
type: "wake",
id: id
})
}
id: id,
});
}
function shutdown(id) {
store.sendMessage({
socketStore.sendMessage({
type: "shutdown",
id: id
})
}
id: id,
});
}
function deleteDevice() {
store.sendMessage({
function deleteDevice() {
socketStore.sendMessage({
type: "delete_device",
id: modalDevice.id
})
}
id: modalDevice.id,
});
}
function updateDevice() {
device = modalDevice;
store.sendMessage({
socketStore.sendMessage({
type: "update_device",
data: modalDevice
})
data: modalDevice,
});
}
function updatePort() {
if (!customPort.number) {
return
return;
}
const index = modalDevice.ports.findIndex(x => x.number == customPort.number);
const index = modalDevice.ports.findIndex(
(x) => x.number == customPort.number
);
if (customPort.name) {
// add port
if (index === -1) {
@@ -46,81 +48,142 @@
modalDevice.ports.push(JSON.parse(JSON.stringify(customPort)));
} else {
customPort.checked = modalDevice.ports[index].checked;
modalDevice.ports[index] = JSON.parse(JSON.stringify(customPort));
modalDevice.ports[index] = JSON.parse(
JSON.stringify(customPort)
);
}
} else {
// delete port
if (index >= 0) {
modalDevice.ports.splice(index, 1)
modalDevice.ports.splice(index, 1);
}
}
modalDevice = modalDevice;
// send to backend
store.sendMessage({
socketStore.sendMessage({
type: "update_port",
data: customPort
})
data: customPort,
});
}
function openModal() {
modalDevice = Object.assign({}, device)
modalDevice = Object.assign({}, device);
}
function validatePort() {
if (typeof customPort.number != "number") {
customPort.number = 1
customPort.number = 1;
} else if (customPort.number > 65535) {
customPort.number = 65535
customPort.number = 65535;
}
}
</script>
<div id="device-col-{device.id}" class="col-xs-12 col-sm-6 col-md-4 col-lg-3 g-4">
<div
id="device-col-{device.id}"
class="col-xs-12 col-sm-6 col-md-4 col-lg-3 g-4"
>
<div class="card border-0 p-3 pt-2">
<div class="card-body">
<div class="row">
<div class="col-auto me-auto">
<div id="spinner-{device.id}" class="spinner-border warning d-none" role="status"></div>
<div
id="spinner-{device.id}"
class="spinner-border warning d-none"
role="status"
/>
{#if device.up === true}
{#if device.shutdown.command}
<div class="hover" on:click="{() => shutdown(device.id)}" data-bs-toggle="tooltip" title="Shutdown command: {device.shutdown.command}" role="button">
<i id="dot-{device.id}" class="fa-solid fa-power-off fa-2x success"></i>
</div>
<div
class="hover"
on:click={() => shutdown(device.id)}
on:keydown={() => shutdown(device.id)}
data-bs-toggle="tooltip"
title="Shutdown command: {device.shutdown
.command}"
role="button"
>
<i
id="dot-{device.id}"
class="fa-solid fa-power-off fa-2x success"
/>
</div>
{:else}
<i id="dot-{device.id}" class="fa-solid fa-power-off fa-2x success"></i>
<i
id="dot-{device.id}"
class="fa-solid fa-power-off fa-2x success"
/>
{/if}
{:else if device.up === false}
<div class="hover" on:click="{() => wake(device.id)}" role="button">
<i id="dot-{device.id}" class="fa-solid fa-power-off fa-2x danger"></i>
<div
class="hover"
on:click={() => wake(device.id)}
on:keydown={() => wake(device.id)}
role="button"
>
<i
id="dot-{device.id}"
class="fa-solid fa-power-off fa-2x danger"
/>
</div>
{:else}
<div class="hover" role="button">
<i id="dot-{device.id}" class="fa-solid fa-power-off fa-2x text-muted"></i>
<i
id="dot-{device.id}"
class="fa-solid fa-power-off fa-2x text-muted"
/>
</div>
{/if}
</div>
{#if device.wake.enabled}
<div class="col-auto px-2" data-bs-toggle="tooltip" title="Wake cron: {device.wake.cron}">
<i class="fa-solid fa-circle-play fa-2x text-muted"></i>
<div
class="col-auto px-2"
data-bs-toggle="tooltip"
title="Wake cron: {device.wake.cron}"
>
<i class="fa-solid fa-circle-play fa-2x text-muted" />
</div>
{/if}
{#if device.shutdown.enabled}
<div class="col-auto px-2" data-bs-toggle="tooltip" title="Shutdown cron: {device.wake.cron}">
<i class="fa-solid fa-circle-stop fa-2x text-muted"></i>
<div
class="col-auto px-2"
data-bs-toggle="tooltip"
title="Shutdown cron: {device.wake.cron}"
>
<i class="fa-solid fa-circle-stop fa-2x text-muted" />
</div>
{/if}
<div class="col-auto hover" data-bs-toggle="modal" data-bs-target="#device-modal-{device.id}" role="button" on:click="{() => openModal()}">
<i class="fa-solid fa-ellipsis-vertical fa-2x"></i>
<div
class="col-auto hover"
data-bs-toggle="modal"
data-bs-target="#device-modal-{device.id}"
role="button"
on:click={() => openModal()}
on:keydown={() => openModal()}
>
<i class="fa-solid fa-ellipsis-vertical fa-2x" />
</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}
{#if port.checked === true}
<li class="list-group-item">
<i class="fa-solid fa-circle align-middle {port.open ? 'success' : 'danger'}"></i>
{port.name} <span class="text-muted">({port.number})</span>
<i
class="fa-solid fa-circle align-middle {port.open
? 'success'
: 'danger'}"
/>
{port.name}
<span class="text-muted">({port.number})</span>
</li>
{/if}
{/each}
@@ -128,111 +191,328 @@
</div>
</div>
<div class="modal fade" id="device-modal-{device.id}" tabindex="-1" aria-labelledby="device-modal-{device.id}-label" aria-hidden="true">
<div
class="modal fade"
id="device-modal-{device.id}"
tabindex="-1"
aria-labelledby="device-modal-{device.id}-label"
aria-hidden="true"
>
<div class="modal-dialog modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title fw-bold" id="device-modal-{modalDevice.id}-label">{modalDevice.name}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
<h5
class="modal-title fw-bold"
id="device-modal-{modalDevice.id}-label"
>
{modalDevice.name}
</h5>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
/>
</div>
<div class="modal-body">
<form id="form-{modalDevice.id}" on:submit|preventDefault={updateDevice}>
<form
id="form-{modalDevice.id}"
on:submit|preventDefault={updateDevice}
>
<!-- general -->
<h5 class="fw-bold">General</h5>
<div class="row mb-2">
<div class="col-sm">
<label for="inputName{modalDevice.id}" class="form-label">Device name</label>
<input type="text" class="form-control" id="inputName{modalDevice.id}" bind:value="{modalDevice.name}" required>
<label
for="inputName{modalDevice.id}"
class="form-label">Device name</label
>
<input
type="text"
class="form-control"
id="inputName{modalDevice.id}"
bind:value={modalDevice.name}
required
/>
</div>
<div class="col-sm">
<label for="inputMac{modalDevice.id}" class="form-label">Mac address</label>
<input type="text" class="form-control" id="inputMac{modalDevice.mac}" bind:value="{modalDevice.mac}" required>
<label
for="inputMac{modalDevice.id}"
class="form-label">Mac address</label
>
<input
type="text"
class="form-control"
id="inputMac{modalDevice.mac}"
bind:value={modalDevice.mac}
required
/>
</div>
</div>
<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}
required
/>
</div>
<div class="col-sm">
<label
for="inputNetmask{modalDevice.id}"
class="form-label">Netmask</label
>
<input
type="text"
class="form-control"
id="inputNetmask{modalDevice.id}"
bind:value={modalDevice.netmask}
required
/>
</div>
</div>
<div class="row">
<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>
</div>
<div class="col-sm">
<label for="inputNetmask{modalDevice.id}" class="form-label">Netmask</label>
<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 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>
<p class="mb-2">
Select ports to check if they are open.
</p>
{#if modalDevice.ports.length === 0}
<p class="mb-0">No ports available. Add ports below.</p>
<p class="mb-0">
No ports available. Add ports below.
</p>
{/if}
{#each modalDevice.ports as port}
<div class="form-check">
<input type="checkbox" class="form-check-input" id="{device.id}-port-{port.number}" bind:checked="{port['checked']}">
<label class="form-check-label" for="{device.id}-port-{port.number}">{port.name} <span class="text-muted">({port.number})</span></label>
<input
type="checkbox"
class="form-check-input"
id="{device.id}-port-{port.number}"
bind:checked={port["checked"]}
/>
<label
class="form-check-label"
for="{device.id}-port-{port.number}"
>{port.name}
<span class="text-muted"
>({port.number})</span
></label
>
</div>
{/each}
<label class="form-label mt-2" for="{device.id}-custom-port">Custom port</label>
<label
class="form-label mt-2"
for="{device.id}-custom-port">Custom port</label
>
<div class="input-group mb-2">
<input type="text" id="{device.id}-custom-port" class="form-control rounded-0 rounded-start" placeholder="Name" aria-label="Name" aria-describedby="button-addon2" bind:value={customPort.name}>
<input type="number" min="1" max="65535" class="form-control rounded-0" placeholder="Port" aria-label="Port" aria-describedby="button-addon2" bind:value={customPort.number} on:input={validatePort}>
<button class="btn btn-secondary" type="button" id="button-addon2" on:click="{updatePort}">Update Port</button>
<input
type="text"
id="{device.id}-custom-port"
class="form-control rounded-0 rounded-start"
placeholder="Name"
aria-label="Name"
aria-describedby="button-addon2"
bind:value={customPort.name}
/>
<input
type="number"
min="1"
max="65535"
class="form-control rounded-0"
placeholder="Port"
aria-label="Port"
aria-describedby="button-addon2"
bind:value={customPort.number}
on:input={validatePort}
/>
<button
class="btn btn-secondary"
type="button"
id="button-addon2"
on:click={updatePort}>Update Port</button
>
</div>
<button class="btn btn-secondary mt-2" type="button" data-bs-toggle="collapse" data-bs-target="#info-ports" aria-expanded="false" aria-controls="info-ports">
<i class="fa-solid fa-angle-down me-2"></i>How to use
<button
class="btn btn-secondary mt-2"
type="button"
data-bs-toggle="collapse"
data-bs-target="#info-ports"
aria-expanded="false"
aria-controls="info-ports"
>
<i class="fa-solid fa-angle-down me-2" />How to use
</button>
<div class="collapse mt-3" id="info-ports">
<div class="callout callout-info">
<p class="mb-0">Ports must be between 1 and 65535. Enter the same port with a differen name to change it. Leave name empty to delete port.</p>
<p class="mb-0">
Ports must be between 1 and 65535. Enter the
same port with a differen name to change it.
Leave name empty to delete port.
</p>
</div>
</div>
<!-- scheduled wake -->
<h5 class="fw-bold mt-4">Scheduled wake</h5>
<p class="mb-2">Wake your device at a given time.</p>
<div class="form-check">
<input class="form-check-input" type="radio" name="wake-disable" id="wake-radio-disabled-{modalDevice.id}"
bind:group={modalDevice["wake"]["enabled"]} value={false} checked={!modalDevice["wake"]["enabled"]}>
<label class="form-check-label" for="wake-radio-disabled-{modalDevice.id}">
<input
class="form-check-input"
type="radio"
name="wake-disable"
id="wake-radio-disabled-{modalDevice.id}"
bind:group={modalDevice["wake"]["enabled"]}
value={false}
checked={!modalDevice["wake"]["enabled"]}
/>
<label
class="form-check-label"
for="wake-radio-disabled-{modalDevice.id}"
>
Disabled
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="wake-cron" id="wake-radio-cron-{modalDevice.id}"
bind:group={modalDevice["wake"]["enabled"]} value={true} checked={modalDevice["wake"]["enabled"]}>
<label class="form-check-label" for="wake-radio-cron-{modalDevice.id}">
<input
class="form-check-input"
type="radio"
name="wake-cron"
id="wake-radio-cron-{modalDevice.id}"
bind:group={modalDevice["wake"]["enabled"]}
value={true}
checked={modalDevice["wake"]["enabled"]}
/>
<label
class="form-check-label"
for="wake-radio-cron-{modalDevice.id}"
>
Enabled
</label>
</div>
<div class="input-group my-1" hidden={!modalDevice["wake"]["enabled"]}>
<span class="input-group-text rounded-0 rounded-start" id="wake-cron-{modalDevice.id}">Cron</span>
<input type="text" class="form-control rounded-0 rounded-end" placeholder="* /4 * * *" aria-label="Crontab" aria-describedby="wake-cron-{modalDevice.id}" bind:value={modalDevice["wake"]["cron"]}>
<div
class="input-group my-1"
hidden={!modalDevice["wake"]["enabled"]}
>
<span
class="input-group-text rounded-0 rounded-start"
id="wake-cron-{modalDevice.id}">Cron</span
>
<input
type="text"
class="form-control rounded-0 rounded-end"
placeholder="* /4 * * *"
aria-label="Crontab"
aria-describedby="wake-cron-{modalDevice.id}"
bind:value={modalDevice["wake"]["cron"]}
/>
</div>
<button class="btn btn-secondary mt-2" type="button" data-bs-toggle="collapse" data-bs-target="#info-wake" aria-expanded="false" aria-controls="info-wake">
<i class="fa-solid fa-angle-down me-2"></i>How to use
<button
class="btn btn-secondary mt-2"
type="button"
data-bs-toggle="collapse"
data-bs-target="#info-wake"
aria-expanded="false"
aria-controls="info-wake"
>
<i class="fa-solid fa-angle-down me-2" />How to use
</button>
<div class="collapse mt-3" id="info-wake">
<div class="callout callout-info">
<p class="mb-2">Cron is a syntax describing a time pattern when to execute jobs. The above field uses common cron syntax. Examples:</p>
<pre class="mb-2">Minute Hour DayOfMonth Month DayOfWeek
<p class="mb-2">
Cron is a syntax describing a time pattern
when to execute jobs. The above field uses
common cron syntax. Examples:
</p>
<pre
class="mb-2">Minute Hour DayOfMonth Month DayOfWeek
* /4 * * * (Wake every 4 hours)
0 9 * * 1-5 (Wake from Mo-Fr at 9 a.m.)
</pre>
<p class="mb-0">Read more about <a href="https://linux.die.net/man/5/crontab" target="_blank">valid syntax here</a> or <a href="https://crontab.guru/" target="_blank">use a generator</a>. Expressions starting with "@..." are not supported.</p>
<p class="mb-0">
Read more about <a
href="https://linux.die.net/man/5/crontab"
target="_blank"
rel="noreferrer">valid syntax here</a
>
or
<a
href="https://crontab.guru/"
target="_blank"
rel="noreferrer">use a generator</a
>. Expressions starting with "@..." are not
supported.
</p>
</div>
</div>
<!-- scheduled shutdown -->
<h5 class="fw-bold mt-4">Shutdown</h5>
<p class="mb-2">Set the shutdown command here. This shell command will be executed when clicking the power button on the device card. You can use cron below, which will then execute the command at the given time.</p>
<p class="mb-2">
Set the shutdown command here. This shell command
will be executed when clicking the power button on
the device card. You can use cron below, which will
then execute the command at the given time.
</p>
<div class="input-group">
<span class="input-group-text rounded-0 rounded-start" id="shutdown-command-{modalDevice.id}">Command</span>
<input type="text" class="form-control rounded-0 rounded-end" placeholder="sshpass -p your_password ssh -o 'StrictHostKeyChecking=no' user@hostname 'sudo shutdown'" aria-label="Ccommand" aria-describedby="shutdown-command-{modalDevice.id}" bind:value={modalDevice["shutdown"]["command"]}>
<span
class="input-group-text rounded-0 rounded-start"
id="shutdown-command-{modalDevice.id}"
>Command</span
>
<input
type="text"
class="form-control rounded-0 rounded-end"
placeholder="sshpass -p your_password ssh -o 'StrictHostKeyChecking=no' user@hostname 'sudo shutdown'"
aria-label="Ccommand"
aria-describedby="shutdown-command-{modalDevice.id}"
bind:value={modalDevice["shutdown"]["command"]}
/>
</div>
<button class="btn btn-secondary mt-2" type="button" data-bs-toggle="collapse" data-bs-target="#info-shutdown" aria-expanded="false" aria-controls="info-shutdown">
<i class="fa-solid fa-angle-down me-2"></i>How to use
<button
class="btn btn-secondary mt-2"
type="button"
data-bs-toggle="collapse"
data-bs-target="#info-shutdown"
aria-expanded="false"
aria-controls="info-shutdown"
>
<i class="fa-solid fa-angle-down me-2" />How to use
</button>
<div class="collapse mt-3" id="info-shutdown">
<div class="callout callout-info">
<p class="mb-2">This field takes a shell command to trigger the shutdown. You can use <code>sshpass</code> for Linux or <code>net rpc</code> for Windows hosts.</p>
<div class="callout callout-danger mb-2">Note: This command is safed as cleartext. Meaning, passwords are clearly visible in the database.</div>
<p class="mb-2">
This field takes a shell command to trigger
the shutdown. You can use <code
>sshpass</code
>
for Linux or <code>net rpc</code> for Windows
hosts.
</p>
<div class="callout callout-danger mb-2">
Note: This command is safed as cleartext.
Meaning, passwords are clearly visible in
the database.
</div>
<p class="mb-2">Examples:</p>
<pre class="mb-2"># wake linux hosts
sshpass -p your_password ssh -o 'StrictHostKeyChecking=no' user@hostname 'sudo shutdown'
@@ -240,35 +520,92 @@
# wake windows hosts
net rpc shutdown --ipaddress 192.168.1.1 --user user%password
</pre>
<p class="mb-0">Read more about <a href="https://linux.die.net/man/1/sshpass" target="_blank">sshpass</a> or <a href="https://linux.die.net/man/8/net" target="_blank">net rpc</a>.</p>
<p class="mb-0">
Read more about <a
href="https://linux.die.net/man/1/sshpass"
target="_blank"
rel="noreferrer">sshpass</a
>
or
<a
href="https://linux.die.net/man/8/net"
target="_blank"
rel="noreferrer">net rpc</a
>.
</p>
</div>
</div>
<div>
<label class="form-label mt-2" for="{device.id}-shutdown-cron">Use cron</label>
<label
class="form-label mt-2"
for="{device.id}-shutdown-cron">Use cron</label
>
</div>
<div class="form-check" id="{device.id}-shutdown-cron">
<input class="form-check-input" type="radio" name="shutdown-disable" id="shutdown-radio-disabled-{modalDevice.id}"
bind:group={modalDevice["shutdown"]["enabled"]} value={false} checked={!modalDevice["shutdown"]["enabled"]}>
<label class="form-check-label" for="shutdown-radio-disabled-{modalDevice.id}">
<input
class="form-check-input"
type="radio"
name="shutdown-disable"
id="shutdown-radio-disabled-{modalDevice.id}"
bind:group={modalDevice["shutdown"]["enabled"]}
value={false}
checked={!modalDevice["shutdown"]["enabled"]}
/>
<label
class="form-check-label"
for="shutdown-radio-disabled-{modalDevice.id}"
>
Disabled
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="shutdown-enable" id="shutdown-radio-enabled-{modalDevice.id}"
bind:group={modalDevice["shutdown"]["enabled"]} value={true} checked={modalDevice["shutdown"]["enabled"]}>
<label class="form-check-label" for="shutdown-radio-enabled-{modalDevice.id}">
<input
class="form-check-input"
type="radio"
name="shutdown-enable"
id="shutdown-radio-enabled-{modalDevice.id}"
bind:group={modalDevice["shutdown"]["enabled"]}
value={true}
checked={modalDevice["shutdown"]["enabled"]}
/>
<label
class="form-check-label"
for="shutdown-radio-enabled-{modalDevice.id}"
>
Enabled
</label>
</div>
<div class="input-group my-1" hidden={!modalDevice["shutdown"]["enabled"]}>
<span class="input-group-text rounded-0 rounded-start" id="shutdown-cron-{modalDevice.id}">Cron</span>
<input type="text" class="form-control rounded-0 rounded-end" placeholder="* /4 * * *" aria-label="Crontab" aria-describedby="shutdown-cron-{modalDevice.id}" bind:value={modalDevice["shutdown"]["cron"]}>
<div
class="input-group my-1"
hidden={!modalDevice["shutdown"]["enabled"]}
>
<span
class="input-group-text rounded-0 rounded-start"
id="shutdown-cron-{modalDevice.id}">Cron</span
>
<input
type="text"
class="form-control rounded-0 rounded-end"
placeholder="* /4 * * *"
aria-label="Crontab"
aria-describedby="shutdown-cron-{modalDevice.id}"
bind:value={modalDevice["shutdown"]["cron"]}
/>
</div>
</form>
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-outline-danger" data-bs-dismiss="modal" on:click={deleteDevice}>Delete</button>
<button type="submit" form="form-{modalDevice.id}" class="btn btn-outline-success">Save changes</button>
<button
type="button"
class="btn btn-outline-danger"
data-bs-dismiss="modal"
on:click={deleteDevice}>Delete</button
>
<button
type="submit"
form="form-{modalDevice.id}"
class="btn btn-outline-success">Save changes</button
>
</div>
</div>
</div>
@@ -297,7 +634,7 @@
.card {
border-radius: 2em;
background-color: var(--bg-lighter);
background-color: var(--bg-lighter);
}
.spinner-border {
@@ -327,4 +664,8 @@
.list-group-item {
color: var(--color-text);
}
.inherit-color {
color: inherit;
}
</style>
+273 -75
View File
@@ -1,43 +1,44 @@
<script>
import store from '../store.js';
import socketStore from "../socketStore.js";
import DarkToggle from "./DarkToggle.svelte";
export let visitors;
export let settings;
const pagetitle = PAGE_TITLE ? PAGE_TITLE : "UpSnap";
let addDevice = {
wake: {
enabled: false,
cron: ""
cron: "",
},
shutdown: {
enabled: false,
cron: "",
command: ""
}
}
command: "",
},
};
function updateDevice(data) {
if (Object.keys(data).length < 4) {
return
return;
}
store.sendMessage({
socketStore.sendMessage({
type: "update_device",
data: data
})
data: data,
});
}
function updateSettings() {
store.sendMessage({
socketStore.sendMessage({
type: "update_settings",
data: settings
})
data: settings,
});
hideModal("settings");
}
function scanNetwork() {
store.sendMessage({
type: "scan_network"
})
socketStore.sendMessage({
type: "scan_network",
});
const btnScan = document.querySelector("#btnScan");
const btnScanSpinner = document.querySelector("#btnScanSpinner");
const btnScanText = document.querySelector("#btnScanText");
@@ -52,32 +53,33 @@
updateDevice(dev);
}
const restoreFromFile = (e) => {
const restoreFromFile = (e) => {
let file = e.target.files[0];
let reader = new FileReader();
reader.readAsText(file);
reader.onload = e => {
reader.onload = (e) => {
let data = JSON.parse(e.target.result);
if (Array.isArray(data)) {
// v2 file restore
data.forEach((device) => {
updateDevice(device)
})
updateDevice(device);
});
} else {
// v1 file restore
for (const [key, value] of Object.entries(data)) {
value["mac"] = key
updateDevice(value)
value["mac"] = key;
value["link"] = "";
updateDevice(value);
}
}
}
};
hideModal("settings");
}
};
function backupToFile() {
store.sendMessage({
type: "backup"
})
socketStore.sendMessage({
type: "backup",
});
}
function hideModal(id) {
@@ -85,96 +87,223 @@
const modal = bootstrap.Modal.getInstance(modalEl);
modal.hide();
}
</script>
<svelte:head>
<title>{pagetitle}</title>
</svelte:head>
<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">
UpSnap
<img
src="favicon.png"
alt="Logo"
width="24"
height="24"
class="me-2"
/>
{pagetitle}
</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">
<span class="navbar-toggler-icon"></span>
<button
class="navbar-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#navbarNavAltMarkup"
aria-controls="navbarNavAltMarkup"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon" />
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<span class="ms-auto d-flex">
<DarkToggle />
<div class="dropdown">
<button class="btn btn-light dropdown-toggle px-3 me-2 py-2" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
<i class="fa-solid fa-wrench me-2"></i>More
<button
class="btn btn-light dropdown-toggle px-3 me-2 py-2"
type="button"
id="dropdownMenuButton1"
data-bs-toggle="dropdown"
aria-expanded="false"
>
<i class="fa-solid fa-wrench me-2" />More
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<ul
class="dropdown-menu"
aria-labelledby="dropdownMenuButton1"
>
<li>
<button class="dropdown-item" data-bs-toggle="modal" data-bs-target="#addDevice">
<i class="fa-solid fa-plus me-2"></i>Add device
<button
class="dropdown-item"
data-bs-toggle="modal"
data-bs-target="#addDevice"
>
<i class="fa-solid fa-plus me-2" />Add device
</button>
</li>
<li>
<button class="dropdown-item" data-bs-toggle="modal" data-bs-target="#settings">
<i class="fa-solid fa-sliders me-2"></i>Settings
<button
class="dropdown-item"
data-bs-toggle="modal"
data-bs-target="#settings"
>
<i class="fa-solid fa-sliders me-2" />Settings
</button>
</li>
</ul>
</div>
<div class="btn btn-light px-3 me-2 py-2 pe-none">
<i class="me-2 fa-solid {visitors === 1 ? "fa-user" : "fa-user-group"}"></i>{visitors} {visitors === 1 ? "Visitor" : "Visitors"}
<i
class="me-2 fa-solid {visitors === 1
? 'fa-user'
: 'fa-user-group'}"
/>{visitors}
{visitors === 1 ? "Visitor" : "Visitors"}
</div>
</span>
</div>
</div>
</nav>
<div class="modal fade" id="addDevice" tabindex="-1" aria-labelledby="addDeviceLabel" aria-hidden="true">
<div
class="modal fade"
id="addDevice"
tabindex="-1"
aria-labelledby="addDeviceLabel"
aria-hidden="true"
>
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title fw-bold" id="addDeviceLabel">Add device</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
<h5 class="modal-title fw-bold" id="addDeviceLabel">
Add device
</h5>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
/>
</div>
<div class="modal-body">
<form id="addForm" on:submit|preventDefault={() => updateDevice(addDevice)}>
<form
id="addForm"
on:submit|preventDefault={() => updateDevice(addDevice)}
>
<div class="row">
<div class="col-sm">
<div class="mb-3">
<label for="inputNameAddDevice" class="form-label">Device name</label>
<input type="text" class="form-control" id="inputNameAddDevice" placeholder="Max PC" bind:value="{addDevice.name}" required>
<label
for="inputNameAddDevice"
class="form-label">Device name</label
>
<input
type="text"
class="form-control"
id="inputNameAddDevice"
placeholder="Max PC"
bind:value={addDevice.name}
required
/>
</div>
</div>
<div class="col-sm">
<div class="mb-3">
<label for="inputMacAddDevice" class="form-label">Mac address</label>
<input type="text" class="form-control" id="inputMacAddDevice" placeholder="aa:aa:aa:aa:aa:aa" bind:value="{addDevice.mac}" pattern="^([0-9A-Fa-f]{'{'}2{'}'}[:-]){'{'}5{'}'}([0-9A-Fa-f]{'{'}2{'}'})|([0-9a-fA-F]{'{'}4{'}'}\\.[0-9a-fA-F]{'{'}4{'}'}\\.[0-9a-fA-F]{'{'}4{'}'})$" required>
<label
for="inputMacAddDevice"
class="form-label">Mac address</label
>
<input
type="text"
class="form-control"
id="inputMacAddDevice"
placeholder="aa:aa:aa:aa:aa:aa"
bind:value={addDevice.mac}
required
/>
</div>
</div>
</div>
<div class="row">
<div class="col-sm">
<div class="mb-3">
<label for="inputIpAddDevice" class="form-label">IP address</label>
<input type="text" class="form-control" id="inputIpAddDevice" placeholder="192.168.1.1" bind:value="{addDevice.ip}" pattern="^([01]?\d\d?|2[0-4]\d|25[0-5])(?:\.(?:[01]?\d\d?|2[0-4]\d|25[0-5])){'{'}3{'}'}$" required>
<label for="inputIpAddDevice" class="form-label"
>IP address</label
>
<input
type="text"
class="form-control"
id="inputIpAddDevice"
placeholder="192.168.1.1"
bind:value={addDevice.ip}
required
/>
</div>
</div>
<div class="col-sm">
<div class="mb-3">
<label for="inputNetmaskAddDevice" class="form-label">Netmask</label>
<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>
<label
for="inputNetmaskAddDevice"
class="form-label">Netmask</label
>
<input
type="text"
class="form-control"
id="inputNetmaskAddDevice"
placeholder="255.255.255.0"
bind:value={addDevice.netmask}
required
/>
</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>
<button
type="submit"
form="addForm"
class="btn btn-outline-success"
>Add device</button
>
</div>
</div>
<h5 class="fw-bold">Network discovery</h5>
{#if !settings.discovery}
<div class="callout callout-danger mb-2">
<p class="m-0">To enable this option, please enter your network address in the settings.</p>
<p class="m-0">
To enable this option, please enter your network
address in the settings.
</p>
</div>
{/if}
<button id="btnScan" class="btn btn-secondary" type="button" on:click={scanNetwork} disabled={!settings.discovery}>
<span id="btnScanSpinner" class="spinner-grow spinner-grow-sm d-none" role="status" aria-hidden="true"></span>
<button
id="btnScan"
class="btn btn-secondary"
type="button"
on:click={scanNetwork}
disabled={!settings.discovery}
>
<span
id="btnScanSpinner"
class="spinner-grow spinner-grow-sm d-none"
role="status"
aria-hidden="true"
/>
<span id="btnScanText">Scan</span>
</button>
{#if settings.scan_network?.length}
@@ -196,8 +325,15 @@
<td>{device.netmask}</td>
<td>{device.mac}</td>
<td>
<button type="button" id="btnAdd{i}" class="btn btn-outline-secondary py-0" on:click={() => addScan(i)}>
<i class="fa-solid fa-plus fa-sm"></i>
<button
type="button"
id="btnAdd{i}"
class="btn btn-outline-secondary py-0"
on:click={() => addScan(i)}
>
<i
class="fa-solid fa-plus fa-sm"
/>
</button>
</td>
</tr>
@@ -211,57 +347,119 @@
</div>
</div>
<div class="modal fade" id="settings" tabindex="-1" aria-labelledby="settingsLabel" aria-hidden="true">
<div
class="modal fade"
id="settings"
tabindex="-1"
aria-labelledby="settingsLabel"
aria-hidden="true"
>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title fw-bold" id="settingsLabel">Settings</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
/>
</div>
<div class="modal-body">
<form id="settingsForm" on:submit|preventDefault={updateSettings}>
<form
id="settingsForm"
on:submit|preventDefault={updateSettings}
>
<h5 class="fw-bold">General</h5>
<div class="row">
<div class="col-sm-8">
<div class="mb-3">
<label for="inputNetworkDiscovery" class="form-label">Network discovery address</label>
<input type="text" class="form-control" id="inputNetworkDiscovery" placeholder="192.168.1.0/24" bind:value="{settings.discovery}" pattern="^([01]?\d\d?|2[0-4]\d|25[0-5])(?:\.(?:[01]?\d\d?|2[0-4]\d|25[0-5])){'{'}2{'}'}(?:\.(?:0))(?:/[0-2]\d|/3[0-2])$">
<label
for="inputNetworkDiscovery"
class="form-label"
>Network discovery address</label
>
<input
type="text"
class="form-control"
id="inputNetworkDiscovery"
placeholder="192.168.1.0/24"
bind:value={settings.discovery}
/>
</div>
</div>
<div class="col-sm-4">
<div class="mb-3">
<label for="inputIntervalSettings" class="form-label">Interval (seconds)</label>
<input type="number" class="form-control" id="inputIntervalSettings" min="5" bind:value="{settings.interval}" required>
<label
for="inputIntervalSettings"
class="form-label">Interval (seconds)</label
>
<input
type="number"
class="form-control"
id="inputIntervalSettings"
min="5"
bind:value={settings.interval}
required
/>
</div>
</div>
</div>
<div class="row">
<div class="col-sm">
<div class="form-check">
<label class="form-check-label" for="flexCheckDefault">
<label
class="form-check-label"
for="flexCheckDefault"
>
Enable notifications
</label>
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault" bind:checked={settings.notifications}>
<input
class="form-check-input"
type="checkbox"
value=""
id="flexCheckDefault"
bind:checked={settings.notifications}
/>
</div>
</div>
</div>
</form>
<div class="row mb-3">
<div class="col-auto ms-auto">
<button type="submit" form="settingsForm" class="btn btn-outline-success">Save</button>
<button
type="submit"
form="settingsForm"
class="btn btn-outline-success">Save</button
>
</div>
</div>
<h5 class="fw-bold">Backup/Restore</h5>
<div class="callout callout-info mb-2">
<p class="m-0">Backup file structure has changed in v2. You can still restore both versions with this file upload.</p>
<p class="m-0">
Backup file structure has changed in v2. You can still
restore both versions with this file upload.
</p>
</div>
<div class="mb-3">
<label for="inputRestore" class="form-label">Restore from .json</label>
<input id="inputRestore" type="file" class="form-control" accept=".json" on:change={(e) => restoreFromFile(e)}>
<label for="inputRestore" class="form-label"
>Restore from .json</label
>
<input
id="inputRestore"
type="file"
class="form-control"
accept=".json"
on:change={(e) => restoreFromFile(e)}
/>
</div>
<div class="mb-3">
<button type="button" class="btn btn-secondary" on:click={backupToFile}>
<i class="fa-solid fa-download me-2"></i>
<button
type="button"
class="btn btn-secondary"
on:click={backupToFile}
>
<i class="fa-solid fa-download me-2" />
Export .json
</button>
</div>
@@ -282,15 +480,15 @@
.dropdown-menu {
background-color: var(--bg-lighter);
li:first-child>button {
li:first-child > button {
border-radius: 0.5rem 0.5rem 0rem 0rem;
}
li:last-child>button {
li:last-child > button {
border-radius: 0rem 0rem 0.5rem 0.5rem;
}
li:only-child>button {
li:only-child > button {
border-radius: 0.5rem;
}
}
+18 -8
View File
@@ -3,10 +3,20 @@
</script>
<div class="position-fixed bottom-0 end-0 p-3 toast-container">
<div class="toast fade {toast.show ? 'show' : 'hide'} {toast.color}-bg" role="alert" aria-live="assertive" aria-atomic="true">
<div
class="toast fade {toast.show ? 'show' : 'hide'} {toast.color}-bg"
role="alert"
aria-live="assertive"
aria-atomic="true"
>
<div class="toast-header">
<strong id="toast-title" class="me-auto">{toast.title}</strong>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
<button
type="button"
class="btn-close"
data-bs-dismiss="toast"
aria-label="Close"
/>
</div>
<div class="toast-body fw-bold">
{toast.message}
@@ -18,19 +28,19 @@
@import "../variables.scss";
.toast-container {
z-index: 11;
border-radius: $toast-border-radius;
z-index: 11;
border-radius: $toast-border-radius;
div>.toast-body {
div > .toast-body {
color: $dark-lighter;
}
}
}
.success-bg {
.success-bg {
background-color: var(--success);
}
.danger-bg {
.danger-bg {
background-color: var(--danger);
}
</style>
+57
View File
@@ -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
}
-27
View File
@@ -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
}
+5 -1
View File
@@ -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)
@@ -23,6 +24,8 @@ services:
#- DJANGO_DEBUG=True # optional (default: False)
#- DJANGO_LANGUAGE_CODE=de # optional (default: en)
#- DJANGO_TIME_ZONE=Europe/Berlin # optional (default: UTC)
#- NMAP_ARGS=-sP # optional, set this if your devices need special nmap args so they can be found (default: -sP)
#- PAGE_TITLE=Custom Title # optional, set a custom page title (default: UpSnap)
depends_on:
redis:
condition: service_healthy
@@ -34,12 +37,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"
+4
View File
@@ -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)
@@ -23,6 +24,8 @@ services:
#- DJANGO_DEBUG=True # optional (default: False)
#- DJANGO_LANGUAGE_CODE=de # optional (default: en)
#- DJANGO_TIME_ZONE=Europe/Berlin # optional (default: UTC)
#- NMAP_ARGS=-sP # optional, set this if your devices need special nmap args so they can be found (default: -sP)
#- PAGE_TITLE=Custom Title # optional, set a custom page title (default: UpSnap)
depends_on:
redis:
condition: service_healthy
@@ -34,6 +37,7 @@ services:
ports:
- "6379:6379"
restart: unless-stopped
command: redis-server --loglevel warning
healthcheck:
test: redis-cli ping
interval: 10s
+6
View File
@@ -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,10 @@ services:
#- DJANGO_DEBUG=True # optional (default: False)
#- DJANGO_LANGUAGE_CODE=de # optional (default: en)
#- DJANGO_TIME_ZONE=Europe/Berlin # optional (default: UTC)
#- NMAP_ARGS=-sP # optional, set this if your devices need special nmap args so they can be found (default: -sP)
#- PAGE_TITLE=Custom Title # optional, set a custom page title (default: UpSnap)
volumes:
- ./db/:/app/backend/db/
depends_on:
redis:
condition: service_healthy
@@ -27,6 +32,7 @@ services:
ports:
- "6379:6379"
restart: unless-stopped
command: redis-server --loglevel warning
healthcheck:
test: redis-cli ping
interval: 10s