mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-11-29 05:06:09 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0f0a0ac98b | |||
| 36cef610c3 | |||
| fdb19e5cfb | |||
| 705008898f | |||
| 2e251f309c | |||
| 21218ef91a | |||
| d08b8b3722 | |||
| e02ecbc639 | |||
| 42bb71a017 | |||
| 20a3ddea1a | |||
| 4906ce722b | |||
| f36be22e46 | |||
| b1e8eaf864 |
@@ -38,6 +38,10 @@ The website will be available at [localhost:8000](http://localhost:8000). If you
|
||||
|
||||
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.
|
||||
|
||||
@@ -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.4"
|
||||
VERSION = "v2.0.6"
|
||||
|
||||
@@ -84,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":
|
||||
@@ -168,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)
|
||||
@@ -187,7 +197,7 @@ class WSConsumer(AsyncWebsocketConsumer):
|
||||
"name": data["name"],
|
||||
"ip": data["ip"],
|
||||
"netmask": data["netmask"],
|
||||
"link": data["link"],
|
||||
"link": data["link"] if data.get("link") else "",
|
||||
"shutdown_cmd": data["shutdown"]["command"] if data.get("shutdown") else ""
|
||||
}
|
||||
)
|
||||
|
||||
+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
|
||||
})
|
||||
|
||||
@@ -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"
|
||||
})
|
||||
}
|
||||
@@ -161,12 +162,11 @@
|
||||
<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 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">
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import {
|
||||
writable
|
||||
} from 'svelte/store';
|
||||
|
||||
const status = writable('');
|
||||
const message = writable('');
|
||||
let socket;
|
||||
|
||||
function initSocket() {
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user