mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-11-28 12:53:04 +00:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f0487ef6a | |||
| d965d17d54 | |||
| 4c406227b5 | |||
| 963a38bc8b | |||
| 79739dc1b3 | |||
| c1b6f6bd9f | |||
| f738cd7c59 | |||
| 4a3b959176 | |||
| 4aebc5fb1f | |||
| c0627cb3f8 | |||
| 776c8aae43 | |||
| 4edbfb9398 | |||
| ba9d3a8143 | |||
| bf59ec2fad | |||
| 5e010b29dd | |||
| 1de1d407a3 | |||
| 088eee39e1 | |||
| f179450e3b | |||
| f1a8fe9dbe | |||
| 63beff0bca | |||
| dd2be0946c | |||
| 9484e40815 | |||
| 9c1abb45a8 | |||
| c6286595b8 | |||
| 5a11bb7c58 | |||
| 036c931aef |
+12
-9
@@ -1,25 +1,28 @@
|
||||
FROM python:3-slim-bullseye as base
|
||||
FROM python:3.10-alpine as base
|
||||
|
||||
FROM base as builder
|
||||
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
RUN apt-get update && apt-get -y install build-essential libssl-dev libffi-dev python3-dev cargo libpq-dev && \
|
||||
RUN apk update &&\
|
||||
apk add python3-dev musl-dev build-base gcc libffi-dev libressl-dev postgresql-dev cargo &&\
|
||||
rm -rf /var/cache/apk/* &&\
|
||||
mkdir /install
|
||||
WORKDIR /install
|
||||
COPY requirements.txt .
|
||||
RUN python -m pip install --prefix=/install --no-cache-dir --upgrade pip && \
|
||||
pip install --prefix=/install --no-cache-dir -r requirements.txt && \
|
||||
rm -rf /var/lib/apt/lists/* && \
|
||||
apt-get clean
|
||||
RUN python -m pip install --no-cache-dir --upgrade pip &&\
|
||||
pip install --prefix=/install --no-cache-dir -r requirements.txt
|
||||
|
||||
FROM base
|
||||
|
||||
COPY --from=builder /install /usr/local
|
||||
COPY app /app
|
||||
WORKDIR /app
|
||||
RUN apt-get update && \
|
||||
apt-get -y install iputils-ping nmap && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
RUN apk update &&\
|
||||
apk add iputils nmap curl bash &&\
|
||||
rm -rf /var/cache/apk/*
|
||||
|
||||
HEALTHCHECK --interval=10s \
|
||||
CMD curl -fs "http://localhost:$DJANGO_PORT/health/" || exit 1
|
||||
|
||||
CMD ["./run.sh"]
|
||||
|
||||
@@ -73,7 +73,7 @@ TEMPLATES = [
|
||||
|
||||
WSGI_APPLICATION = 'django_wol.wsgi.application'
|
||||
ASGI_APPLICATION = 'django_wol.asgi.application'
|
||||
CELERY_BROKER_URL = "redis://localhost:6379"
|
||||
CELERY_BROKER_URL = f"redis://{os.getenv('REDIS_HOST', '127.0.0.1')}:{os.getenv('REDIS_PORT', 6379)}"
|
||||
|
||||
|
||||
# Database
|
||||
@@ -85,8 +85,8 @@ DATABASES = {
|
||||
"NAME": os.getenv("POSTGRES_DB", "upsnap"),
|
||||
"USER": os.getenv("POSTGRES_USER", "upsnap"),
|
||||
"PASSWORD": os.getenv("POSTGRES_PASSWORD", "upsnap"),
|
||||
"HOST": "localhost",
|
||||
"PORT": 5432,
|
||||
"HOST": os.getenv("POSTGRES_HOST", "127.0.0.1"),
|
||||
"PORT": os.getenv("POSTGRES_PORT", 5432),
|
||||
"OPTIONS": {"connect_timeout": 5},
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ CHANNEL_LAYERS = {
|
||||
"default": {
|
||||
"BACKEND": "channels_redis.core.RedisChannelLayer",
|
||||
"CONFIG": {
|
||||
"hosts": [("localhost", 6379)]
|
||||
"hosts": [(os.getenv("REDIS_HOST", "127.0.0.1"), os.getenv("REDIS_PORT", 6379))]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,4 +142,4 @@ STATIC_URL = '/static/'
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
||||
|
||||
VERSION = "v1.0.2"
|
||||
VERSION = "v1.2.2"
|
||||
|
||||
+14
@@ -1,5 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
# wait for db and redis
|
||||
/usr/bin/env bash ./wait-for-it.sh "${POSTGRES_HOST}":"${POSTGRES_PORT}" -t 300 -s
|
||||
/usr/bin/env bash ./wait-for-it.sh "${REDIS_HOST}":"${REDIS_PORT}" -t 300 -s
|
||||
|
||||
python manage.py makemigrations
|
||||
python manage.py migrate
|
||||
python manage.py collectstatic --noinput
|
||||
@@ -17,6 +21,16 @@ if [ -n "$ENABLE_NOTIFICATIONS" ]; then
|
||||
python -u manage.py shell -c "from wol.models import Settings; Settings.objects.update_or_create(id=1, defaults={'enable_notifications': '$ENABLE_NOTIFICATIONS'})"
|
||||
fi
|
||||
|
||||
# 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
|
||||
|
||||
celery -A django_wol worker &
|
||||
celery -A django_wol beat &
|
||||
gunicorn --bind 0.0.0.0:"$DJANGO_PORT" --workers 4 django_wol.asgi:application -k uvicorn.workers.UvicornWorker
|
||||
|
||||
Executable
+183
@@ -0,0 +1,183 @@
|
||||
#!/usr/bin/env bash
|
||||
# Use this script to test if a given TCP host/port are available
|
||||
|
||||
WAITFORIT_cmdname=${0##*/}
|
||||
|
||||
echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << USAGE >&2
|
||||
Usage:
|
||||
$WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
|
||||
-h HOST | --host=HOST Host or IP under test
|
||||
-p PORT | --port=PORT TCP port under test
|
||||
Alternatively, you specify the host and port as host:port
|
||||
-s | --strict Only execute subcommand if the test succeeds
|
||||
-q | --quiet Don't output any status messages
|
||||
-t TIMEOUT | --timeout=TIMEOUT
|
||||
Timeout in seconds, zero for no timeout
|
||||
-- COMMAND ARGS Execute command with args after the test finishes
|
||||
USAGE
|
||||
exit 1
|
||||
}
|
||||
|
||||
wait_for()
|
||||
{
|
||||
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
||||
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
||||
else
|
||||
echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
|
||||
fi
|
||||
WAITFORIT_start_ts=$(date +%s)
|
||||
while :
|
||||
do
|
||||
if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
|
||||
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
|
||||
WAITFORIT_result=$?
|
||||
else
|
||||
(echo -n > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
|
||||
WAITFORIT_result=$?
|
||||
fi
|
||||
if [[ $WAITFORIT_result -eq 0 ]]; then
|
||||
WAITFORIT_end_ts=$(date +%s)
|
||||
echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
return $WAITFORIT_result
|
||||
}
|
||||
|
||||
wait_for_wrapper()
|
||||
{
|
||||
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
|
||||
if [[ $WAITFORIT_QUIET -eq 1 ]]; then
|
||||
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
||||
else
|
||||
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
||||
fi
|
||||
WAITFORIT_PID=$!
|
||||
trap "kill -INT -$WAITFORIT_PID" INT
|
||||
wait $WAITFORIT_PID
|
||||
WAITFORIT_RESULT=$?
|
||||
if [[ $WAITFORIT_RESULT -ne 0 ]]; then
|
||||
echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
||||
fi
|
||||
return $WAITFORIT_RESULT
|
||||
}
|
||||
|
||||
# process arguments
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case "$1" in
|
||||
*:* )
|
||||
WAITFORIT_hostport=(${1//:/ })
|
||||
WAITFORIT_HOST=${WAITFORIT_hostport[0]}
|
||||
WAITFORIT_PORT=${WAITFORIT_hostport[1]}
|
||||
shift 1
|
||||
;;
|
||||
--child)
|
||||
WAITFORIT_CHILD=1
|
||||
shift 1
|
||||
;;
|
||||
-q | --quiet)
|
||||
WAITFORIT_QUIET=1
|
||||
shift 1
|
||||
;;
|
||||
-s | --strict)
|
||||
WAITFORIT_STRICT=1
|
||||
shift 1
|
||||
;;
|
||||
-h)
|
||||
WAITFORIT_HOST="$2"
|
||||
if [[ $WAITFORIT_HOST == "" ]]; then break; fi
|
||||
shift 2
|
||||
;;
|
||||
--host=*)
|
||||
WAITFORIT_HOST="${1#*=}"
|
||||
shift 1
|
||||
;;
|
||||
-p)
|
||||
WAITFORIT_PORT="$2"
|
||||
if [[ $WAITFORIT_PORT == "" ]]; then break; fi
|
||||
shift 2
|
||||
;;
|
||||
--port=*)
|
||||
WAITFORIT_PORT="${1#*=}"
|
||||
shift 1
|
||||
;;
|
||||
-t)
|
||||
WAITFORIT_TIMEOUT="$2"
|
||||
if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
|
||||
shift 2
|
||||
;;
|
||||
--timeout=*)
|
||||
WAITFORIT_TIMEOUT="${1#*=}"
|
||||
shift 1
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
WAITFORIT_CLI=("$@")
|
||||
break
|
||||
;;
|
||||
--help)
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
echoerr "Unknown argument: $1"
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
|
||||
echoerr "Error: you need to provide a host and port to test."
|
||||
usage
|
||||
fi
|
||||
|
||||
WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
|
||||
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
|
||||
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
|
||||
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
|
||||
|
||||
# Check to see if timeout is from busybox?
|
||||
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
|
||||
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
|
||||
|
||||
WAITFORIT_BUSYTIMEFLAG=""
|
||||
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
|
||||
WAITFORIT_ISBUSY=1
|
||||
# Check if busybox timeout uses -t flag
|
||||
# (recent Alpine versions don't support -t anymore)
|
||||
if timeout &>/dev/stdout | grep -q -e '-t '; then
|
||||
WAITFORIT_BUSYTIMEFLAG="-t"
|
||||
fi
|
||||
else
|
||||
WAITFORIT_ISBUSY=0
|
||||
fi
|
||||
|
||||
if [[ $WAITFORIT_CHILD -gt 0 ]]; then
|
||||
wait_for
|
||||
WAITFORIT_RESULT=$?
|
||||
exit $WAITFORIT_RESULT
|
||||
else
|
||||
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
||||
wait_for_wrapper
|
||||
WAITFORIT_RESULT=$?
|
||||
else
|
||||
wait_for
|
||||
WAITFORIT_RESULT=$?
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $WAITFORIT_CLI != "" ]]; then
|
||||
if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
|
||||
echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
|
||||
exit $WAITFORIT_RESULT
|
||||
fi
|
||||
exec "${WAITFORIT_CLI[@]}"
|
||||
else
|
||||
exit $WAITFORIT_RESULT
|
||||
fi
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ class SettingsForm(forms.Form):
|
||||
notifications = forms.CharField(widget=forms.RadioSelect, label="notifications")
|
||||
console = forms.CharField(widget=forms.RadioSelect, label="console")
|
||||
sort = forms.ChoiceField(choices=[("name", "name"), ("ip", "ip")], widget=forms.RadioSelect, label="sort")
|
||||
ip_range = forms.CharField(label="ip_range")
|
||||
ip_range = forms.CharField(label="ip_range", required=False)
|
||||
|
||||
|
||||
class AddCustomDevice(forms.Form):
|
||||
|
||||
@@ -108,7 +108,7 @@ window.onload = () => {
|
||||
(hour < 10 ? "0" + hour.toString() : hour) + ":" +
|
||||
(minute < 10 ? "0" + minute.toString() : minute) +
|
||||
utcString.substring(16, 19);
|
||||
|
||||
|
||||
// prepare html elements
|
||||
var datetimeFields = document.querySelectorAll('[id*=-input]');
|
||||
for (let index = 0; index < datetimeFields.length; index++) {
|
||||
@@ -200,10 +200,10 @@ function setDeviceDown(device) {
|
||||
var statusDot = document.getElementById(device.id + "-dot");
|
||||
var statusPorts = document.getElementById(device.id + "-ports");
|
||||
var wakeButton = document.querySelector(`[id="btn-wake"][data-id="${device.id}"]`)
|
||||
var scheduleModalButton = document.getElementById(device.id + "-btn-schedule");
|
||||
var scheduleModalButton = document.getElementById(device.id + "-btn-schedule");
|
||||
|
||||
// check if device was up before
|
||||
if (statusDot.classList.contains("dot-up") && enableNotifications ) {
|
||||
if (statusDot.classList.contains("dot-up") && enableNotifications) {
|
||||
notif.show("Device now down!", device.name + " is now down.", "is-danger", 5000);
|
||||
}
|
||||
|
||||
@@ -287,9 +287,6 @@ socket.onmessage = function (event) {
|
||||
document.getElementById("visitors").innerHTML = message.visitors + ' visitor';
|
||||
} else {
|
||||
document.getElementById("visitors").innerHTML = message.visitors + ' visitors';
|
||||
if (enableNotifications) {
|
||||
notif.show("Visitors updated", "There are currently " + message.visitors + " visitors", "is-info", 5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,7 +327,7 @@ socket.onmessage = function (event) {
|
||||
if ("reload" in message) {
|
||||
window.location.reload(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
socket.onclose = function (event) {
|
||||
if (enableNotifications) {
|
||||
|
||||
@@ -5,11 +5,68 @@
|
||||
window.onload = () => {
|
||||
document.getElementById("scan-button").addEventListener("click", scan);
|
||||
|
||||
var deleteButtons = document.querySelectorAll('[id=delete-button]');
|
||||
// save device buttons
|
||||
const saveButtons = document.querySelectorAll('[id=save-button]');
|
||||
for (let index = 0; index < saveButtons.length; index++) {
|
||||
const element = saveButtons[index];
|
||||
element.addEventListener('click', () => {
|
||||
const devNameLabelContainer = document.querySelector(`[id=dev-name-label-container][data-id="${element.dataset.id}"]`)
|
||||
const devNameInputContainer = document.querySelector(`[id=dev-name-input-container][data-id="${element.dataset.id}"]`)
|
||||
const devNameInput = document.querySelector(`[id=dev-name-input][data-id="${element.dataset.id}"]`)
|
||||
|
||||
const devIpLabelContainer = document.querySelector(`[id=dev-ip-label-container][data-id="${element.dataset.id}"]`)
|
||||
const devIpInputContainer = document.querySelector(`[id=dev-ip-input-container][data-id="${element.dataset.id}"]`)
|
||||
const devIpInput = document.querySelector(`[id=dev-ip-input][data-id="${element.dataset.id}"]`)
|
||||
|
||||
const devMacLabel = document.querySelector(`[id=dev-mac][data-id="${element.dataset.id}"]`)
|
||||
|
||||
devNameLabelContainer.innerText = devNameInput.value;
|
||||
devNameInputContainer.classList.toggle("is-hidden");
|
||||
devNameLabelContainer.classList.toggle("is-hidden");
|
||||
|
||||
devIpLabelContainer.innerText = devIpInput.value;
|
||||
devIpInputContainer.classList.toggle("is-hidden");
|
||||
devIpLabelContainer.classList.toggle("is-hidden");
|
||||
|
||||
post_settings("/settings/update/", JSON.stringify({
|
||||
"name": devNameInput.value,
|
||||
"ip": devIpInput.value,
|
||||
"mac": devMacLabel.innerText
|
||||
}));
|
||||
element.classList.toggle("is-hidden");
|
||||
const editButton = document.querySelector(`[id="edit-button"][data-id="${element.dataset.id}"]`)
|
||||
editButton.classList.toggle("is-hidden");
|
||||
});
|
||||
}
|
||||
|
||||
// edit device buttons
|
||||
const editButtons = document.querySelectorAll('[id=edit-button]');
|
||||
for (let index = 0; index < editButtons.length; index++) {
|
||||
const element = editButtons[index];
|
||||
element.addEventListener('click', () => {
|
||||
element.classList.toggle("is-hidden");
|
||||
const saveButton = document.querySelector(`[id="save-button"][data-id="${element.dataset.id}"]`)
|
||||
saveButton.classList.toggle("is-hidden");
|
||||
|
||||
// Swap table cells with input fields
|
||||
const devNameLabelContainer = document.querySelector(`[id=dev-name-label-container][data-id="${element.dataset.id}"]`)
|
||||
devNameLabelContainer.classList.toggle("is-hidden");
|
||||
const devNameInputContainer = document.querySelector(`[id=dev-name-input-container][data-id="${element.dataset.id}"]`)
|
||||
devNameInputContainer.classList.toggle("is-hidden");
|
||||
|
||||
const devIpLabelContainer = document.querySelector(`[id=dev-ip-label-container][data-id="${element.dataset.id}"]`)
|
||||
devIpLabelContainer.classList.toggle("is-hidden");
|
||||
const devIpInputContainer = document.querySelector(`[id=dev-ip-input-container][data-id="${element.dataset.id}"]`)
|
||||
devIpInputContainer.classList.toggle("is-hidden");
|
||||
});
|
||||
}
|
||||
|
||||
// delete device buttons
|
||||
const deleteButtons = document.querySelectorAll('[id=delete-button]');
|
||||
for (let index = 0; index < deleteButtons.length; index++) {
|
||||
const element = deleteButtons[index];
|
||||
element.addEventListener('click', () => {
|
||||
del_device(element.dataset.id);
|
||||
post_settings("/settings/del/", element.dataset.id);
|
||||
element.disabled = true;
|
||||
element.innerText = "Deleted";
|
||||
});
|
||||
@@ -37,24 +94,23 @@ async function scan() {
|
||||
|
||||
for (let index = 0; index < data.devices.length; index++) {
|
||||
const device = data.devices[index];
|
||||
var row = table.insertRow();
|
||||
var td1 = row.insertCell();
|
||||
var td2 = row.insertCell();
|
||||
var td3 = row.insertCell();
|
||||
var td4 = row.insertCell();
|
||||
if (device.name == "") {
|
||||
var deviceName = "Unknown";
|
||||
} else {
|
||||
var deviceName = device.name;
|
||||
const row = table.insertRow();
|
||||
const td1 = row.insertCell();
|
||||
const td2 = row.insertCell();
|
||||
const td3 = row.insertCell();
|
||||
const td4 = row.insertCell();
|
||||
let deviceName = "Unknown";
|
||||
if (device.name != "") {
|
||||
deviceName = device.name;
|
||||
}
|
||||
td1.appendChild(document.createTextNode(deviceName));
|
||||
td2.appendChild(document.createTextNode(device.ip));
|
||||
td3.appendChild(document.createTextNode(device.mac));
|
||||
var button = document.createElement("button");
|
||||
const button = document.createElement("button");
|
||||
button.classList.add("button", "is-primary", "is-small");
|
||||
button.innerText = "Add";
|
||||
button.addEventListener("click", function (event) {
|
||||
add_device(JSON.stringify(device));
|
||||
post_settings("/settings/update/", JSON.stringify(device));
|
||||
event.target.disabled = true;
|
||||
event.target.innerText = "Added";
|
||||
});
|
||||
@@ -64,18 +120,15 @@ async function scan() {
|
||||
tableContainer.classList.remove("is-hidden");
|
||||
}
|
||||
|
||||
function add_device(data) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = "/settings/scan_add/";
|
||||
xhr.open("POST", url, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.send(data);
|
||||
async function post_settings(url, data) {
|
||||
await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: data
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
})
|
||||
}
|
||||
|
||||
function del_device(devId) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = "/settings/del/";
|
||||
xhr.open("POST", url, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.send(devId);
|
||||
}
|
||||
@@ -40,18 +40,14 @@
|
||||
</nav>
|
||||
<div class="container">
|
||||
<section class="section">
|
||||
<h1 class="title is-size-2">
|
||||
Settings
|
||||
</h1>
|
||||
<p class="subtitle">
|
||||
UpSnap
|
||||
</p>
|
||||
<h1 class="title is-size-2">Settings</h1>
|
||||
<p class="subtitle">UpSnap</p>
|
||||
</section>
|
||||
<section class="section pt-4 pb-3">
|
||||
<section class="section py-3">
|
||||
<h2 class="title is-size-3 my-5">General</h2>
|
||||
<form action="/settings/save/" method="post">
|
||||
{% csrf_token %}
|
||||
<div class="box no-flex">
|
||||
<h2 class="title is-size-3 mb-4">General</h2>
|
||||
<div class="columns">
|
||||
<div class="column is-one-quarter">
|
||||
<span class="mr-2"><strong>Notifications:</strong></span>
|
||||
@@ -111,90 +107,162 @@
|
||||
<input id="ip-range" class="input" type="text" placeholder="192.168.1.0/24" name="ip_range" value="{% if settings.scan_address %}{{ settings.scan_address }}{% endif %}" 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])$">
|
||||
</div>
|
||||
</div>
|
||||
<button class="button is-primary" type="submit" value="Submit">Save</button>
|
||||
<button class="button is-primary" type="submit" value="Submit">
|
||||
<span class="icon is-small">
|
||||
<i class="fas fa-save"></i>
|
||||
</span>
|
||||
<span>
|
||||
Save
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
<section class="section py-3">
|
||||
<div class="columns is-multiline is-mobile">
|
||||
<div class="column is-full-mobile is-full-tablet is-full-desktop is-full-widescreen is-half-fullhd">
|
||||
<div class="box no-flex">
|
||||
<h2 class="title is-size-3 mb-4">Add custom device</h2>
|
||||
<form action="/settings/custom_add/" method="post">
|
||||
{% csrf_token %}
|
||||
<table class="table is-fullwidth">
|
||||
<thead>
|
||||
<th>Name</th>
|
||||
<th>IP</th>
|
||||
<th>MAC</th>
|
||||
<th>Action</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<td><input type="text" class="input" name="custom_add_name"></td>
|
||||
<td><input type="text" class="input" name="custom_add_ip"></td>
|
||||
<td><input type="text" class="input" name="custom_add_mac"></td>
|
||||
<td class="is-vcentered">
|
||||
<button id="btn-custom-add" class="button is-primary is-small" type="submit">Add</button>
|
||||
</td>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
<h2 class="title is-size-3 mb-4">Scan for devices</h2>
|
||||
{% if settings.scan_address %}
|
||||
<button id="scan-button" class="button is-primary">Scan network</button>
|
||||
{% else %}
|
||||
<article class="message is-danger">
|
||||
<div class="message-body">
|
||||
Please enter the network address above and save to use this feature. Network address should look like "192.168.1.0/24".
|
||||
</div>
|
||||
</article>
|
||||
<button id="scan-button" class="button is-primary" disabled>Scan network</button>
|
||||
{% endif %}
|
||||
<div id="scan-table-container" class="table-container py-3 is-hidden">
|
||||
<table id="scan-table" class="table is-fullwidth">
|
||||
<thead>
|
||||
<th>Name</th>
|
||||
<th>IP</th>
|
||||
<th>MAC</th>
|
||||
<th>Action</th>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<h2 class="title is-size-3 my-5">Manage Devices</h2>
|
||||
<div class="box no-flex">
|
||||
<h3 class="title is-size-4 mb-5">Scan network</h3>
|
||||
{% if settings.scan_address %}
|
||||
<button id="scan-button" class="button is-primary">
|
||||
<span class="icon is-small">
|
||||
<i class="fas fa-network-wired"></i>
|
||||
</span>
|
||||
<span>
|
||||
Scan
|
||||
</span>
|
||||
</button>
|
||||
{% else %}
|
||||
<article class="message is-danger">
|
||||
<div class="message-body">
|
||||
Please enter the network address above and save to use this feature. Network address should look like "192.168.1.0/24".
|
||||
</div>
|
||||
</article>
|
||||
<button id="scan-button" class="button is-primary" disabled>
|
||||
<span class="icon is-small">
|
||||
<i class="fas fa-network-wired"></i>
|
||||
</span>
|
||||
<span>
|
||||
Scan
|
||||
</span>
|
||||
</button>
|
||||
{% endif %}
|
||||
<h3 class="title is-size-4 my-5">Add devices</h3>
|
||||
<form action="/settings/custom_add/" method="post">
|
||||
{% csrf_token %}
|
||||
<table class="table is-fullwidth">
|
||||
<thead>
|
||||
<th>Name</th>
|
||||
<th>IP</th>
|
||||
<th>MAC</th>
|
||||
<th>Action</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<td><input type="text" class="input" name="custom_add_name"></td>
|
||||
<td><input type="text" class="input" name="custom_add_ip"></td>
|
||||
<td><input type="text" class="input" name="custom_add_mac"></td>
|
||||
<td class="is-vcentered">
|
||||
<button id="btn-custom-add" class="button is-primary is-small" type="submit">Add</button>
|
||||
</td>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
<div id="scan-table-container" class="table-container is-hidden">
|
||||
<table id="scan-table" class="table is-fullwidth">
|
||||
<thead>
|
||||
<th>Name</th>
|
||||
<th>IP</th>
|
||||
<th>MAC</th>
|
||||
<th>Action</th>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="column is-full-mobile is-full-tablet is-full-desktop is-full-widescreen is-half-fullhd">
|
||||
<div class="box no-flex">
|
||||
<h2 class="title is-size-3 mb-4">Delete devices</h2>
|
||||
<div id="delete-table-container" class="table-container py-3">
|
||||
<table id="delete-table" class="table is-fullwidth">
|
||||
<thead>
|
||||
<th>Name</th>
|
||||
<th>IP</th>
|
||||
<th>MAC</th>
|
||||
<th>Action</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for dev in devices %}
|
||||
<tr>
|
||||
<td>{{ dev.name }}</td>
|
||||
<td>{{ dev.ip }}</td>
|
||||
<td>{{ dev.mac }}</td>
|
||||
<td><button id="delete-button" class="button is-danger is-small" data-id="{{ dev.id }}">Delete</button></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<h3 class="title is-size-4 my-5">Edit devices</h3>
|
||||
<div class="table-container">
|
||||
<table class="table is-fullwidth">
|
||||
<thead>
|
||||
<th>Name</th>
|
||||
<th>IP</th>
|
||||
<th>MAC</th>
|
||||
<th>Action</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for dev in devices %}
|
||||
<tr>
|
||||
<td id="dev-name" data-id="{{ dev.id }}">
|
||||
<div id="dev-name-label-container" data-id="{{ dev.id }}">
|
||||
{{ dev.name }}
|
||||
</div>
|
||||
<div id="dev-name-input-container" data-id="{{ dev.id }}" class="is-hidden">
|
||||
<input id="dev-name-input" data-id="{{ dev.id }}" type="text" class="input" value="{{ dev.name }}">
|
||||
</div>
|
||||
</td>
|
||||
<td id="dev-ip" data-id="{{ dev.id }}">
|
||||
<div id="dev-ip-label-container" data-id="{{ dev.id }}">
|
||||
{{ dev.ip }}
|
||||
</div>
|
||||
<div id="dev-ip-input-container" data-id="{{ dev.id }}" class="is-hidden">
|
||||
<input id="dev-ip-input" data-id="{{ dev.id }}" type="text" class="input" value="{{ dev.ip }}">
|
||||
</div>
|
||||
</td>
|
||||
<td id="dev-mac" data-id="{{ dev.id }}">
|
||||
{{ dev.mac }}
|
||||
</td>
|
||||
<td>
|
||||
<div class="buttons">
|
||||
<button id="save-button" class="button is-primary is-small is-hidden" data-id="{{ dev.id }}">
|
||||
Save
|
||||
</button>
|
||||
<button id="edit-button" class="button is-warning is-small" data-id="{{ dev.id }}">
|
||||
Edit
|
||||
</button>
|
||||
<button id="delete-button" class="button is-danger is-small" data-id="{{ dev.id }}">
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<h3 class="title is-size-4 my-5">Backup / Restore</h3>
|
||||
<div class="columns is-tablet">
|
||||
<div class="column is-narrow">
|
||||
<a class="button is-primary" href="/settings/export/">
|
||||
<span class="icon is-small">
|
||||
<i class="fas fa-download"></i>
|
||||
</span>
|
||||
<span>Backup devices</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="column is-narrow">
|
||||
<form action="/settings/import/" method="post" enctype=multipart/form-data id="restore-form">
|
||||
{% csrf_token %}
|
||||
<div class="file is-primary">
|
||||
<label class="file-label">
|
||||
<input id="restore-input" class="file-input" type="file" name="file" accept=".json" onchange="form.submit()">
|
||||
<span class="file-cta">
|
||||
<span class="file-icon">
|
||||
<i class="fas fa-upload"></i>
|
||||
</span>
|
||||
<span class="file-label">
|
||||
Restore from file…
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="section py-3">
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<div class="box">
|
||||
<h2 class="title is-size-3 mb-4">App info</h2>
|
||||
<section class="section py-3 mb-6">
|
||||
<h2 class="title is-size-3 my-5">Info</h2>
|
||||
<div class="box no-flex">
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<h3 class="title is-size-4 mb-5">App</h3>
|
||||
<div class="columns is-mobile">
|
||||
<div class="column">
|
||||
<span class="mr-2"><strong>App version:</strong></span>
|
||||
@@ -236,10 +304,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="box">
|
||||
<h2 class="title is-size-3 mb-4">System info</h2>
|
||||
<div class="column">
|
||||
<h3 class="title is-size-4 mb-5">System</h3>
|
||||
<div class="columns is-mobile">
|
||||
<div class="column">
|
||||
<span class="mr-2"><strong>System:</strong></span>
|
||||
@@ -292,4 +358,4 @@
|
||||
<script src="{% static 'js/settings.js' %}"></script>
|
||||
</footer>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
+5
-2
@@ -7,7 +7,10 @@ urlpatterns = [
|
||||
path("settings/", views.settings, name="settings"),
|
||||
path("settings/save/", views.settings_save, name="settings_save"),
|
||||
path("settings/scan/", views.settings_scan, name="settings_scan"),
|
||||
path("settings/scan_add/", views.settings_scan_add, name="settings_scan_add"),
|
||||
path("settings/update/", views.settings_update, name="settings_update"),
|
||||
path("settings/custom_add/", views.settings_custom_add, name="settings_custom_add"),
|
||||
path("settings/del/", views.settings_del, name="settings_del")
|
||||
path("settings/del/", views.settings_del, name="settings_del"),
|
||||
path("settings/export/", views.settings_export, name="settings_export"),
|
||||
path("settings/import/", views.settings_import, name="settings_import"),
|
||||
path("health/", views.health, name="health")
|
||||
]
|
||||
|
||||
+52
-7
@@ -2,12 +2,16 @@ import json
|
||||
import os
|
||||
import platform
|
||||
import subprocess
|
||||
from io import StringIO
|
||||
|
||||
from asgiref.sync import async_to_sync
|
||||
from channels.layers import get_channel_layer
|
||||
from django.core import serializers
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.http.response import JsonResponse
|
||||
from django.http.response import (HttpResponse, HttpResponseServerError,
|
||||
JsonResponse)
|
||||
from django.shortcuts import render
|
||||
from django.utils import dateformat, timezone
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django_wol.settings import VERSION as app_version
|
||||
@@ -32,7 +36,7 @@ def index(request):
|
||||
|
||||
def settings(request):
|
||||
conf = Settings.objects.first()
|
||||
devices = Device.objects.all()
|
||||
devices = Device.objects.all().order_by(conf.sort_by)
|
||||
visitors = Websocket.objects.first().visitors
|
||||
|
||||
context = {
|
||||
@@ -61,7 +65,7 @@ def settings_save(request):
|
||||
"scan_address": form.cleaned_data["ip_range"]
|
||||
}
|
||||
)
|
||||
return HttpResponseRedirect('/settings/')
|
||||
return HttpResponseRedirect("/settings/")
|
||||
|
||||
|
||||
def settings_scan(request):
|
||||
@@ -115,14 +119,14 @@ def settings_custom_add(request):
|
||||
"ip": form.cleaned_data["custom_add_ip"]
|
||||
}
|
||||
)
|
||||
return HttpResponseRedirect('/settings/')
|
||||
return HttpResponseRedirect("/settings/")
|
||||
|
||||
|
||||
@method_decorator(csrf_exempt, name="dispatch")
|
||||
def settings_scan_add(request):
|
||||
def settings_update(request):
|
||||
data = {}
|
||||
if request.method == "POST":
|
||||
post_body = json.loads(request.body.decode('utf-8'))
|
||||
post_body = json.loads(request.body.decode("utf-8"))
|
||||
if post_body["name"] == "":
|
||||
name = "Unknown"
|
||||
else:
|
||||
@@ -151,7 +155,7 @@ def settings_scan_add(request):
|
||||
def settings_del(request):
|
||||
data = {}
|
||||
if request.method == "POST":
|
||||
dev_id = int(request.body.decode('utf-8'))
|
||||
dev_id = int(request.body.decode("utf-8"))
|
||||
Device.objects.get(id=dev_id).delete()
|
||||
data["status"] = 200
|
||||
else:
|
||||
@@ -164,3 +168,44 @@ def settings_del(request):
|
||||
})})
|
||||
|
||||
return JsonResponse(data=data)
|
||||
|
||||
|
||||
def settings_export(request):
|
||||
if request.method == "GET":
|
||||
file_data = {}
|
||||
data = serializers.serialize("python", Device.objects.all())
|
||||
for dev in data:
|
||||
file_data[dev["fields"]["mac"]] = {
|
||||
"name": dev["fields"]["name"],
|
||||
"ip": dev["fields"]["ip"],
|
||||
"netmask": dev["fields"]["netmask"]
|
||||
}
|
||||
now = dateformat.format(timezone.now(), "Y-m-d_H-i-s")
|
||||
response = HttpResponse(
|
||||
StringIO(json.dumps(file_data, indent=4)), content_type="application/json")
|
||||
response["Content-Disposition"] = f"attachment;filename=upsnap_backup_{now}.json"
|
||||
return response
|
||||
return HttpResponseRedirect("/settings/")
|
||||
|
||||
|
||||
def settings_import(request):
|
||||
if request.method == "POST":
|
||||
data = json.loads(request.FILES["file"].read())
|
||||
for key, value in data.items():
|
||||
Device.objects.update_or_create(
|
||||
mac=key,
|
||||
defaults={
|
||||
"name": value["name"],
|
||||
"ip": value["ip"],
|
||||
"netmask": value["netmask"],
|
||||
}
|
||||
)
|
||||
return HttpResponseRedirect("/settings/")
|
||||
|
||||
|
||||
def health(request):
|
||||
try:
|
||||
Settings.objects.all()
|
||||
return HttpResponse("Ok")
|
||||
except Exception:
|
||||
return HttpResponseServerError("db: cannot connect to database.")
|
||||
|
||||
+22
-10
@@ -4,10 +4,7 @@ services:
|
||||
container_name: upsnap_django
|
||||
image: seriousm4x/upsnap:latest
|
||||
network_mode: host
|
||||
depends_on:
|
||||
- upsnap_redis
|
||||
- upsnap_postgres
|
||||
restart: always
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- DJANGO_SUPERUSER_USER=admin
|
||||
- DJANGO_SUPERUSER_PASSWORD=admin
|
||||
@@ -16,25 +13,40 @@ services:
|
||||
- DJANGO_LANGUAGE_CODE=de
|
||||
- DJANGO_TIME_ZONE=Europe/Berlin
|
||||
- DJANGO_PORT=8000
|
||||
- REDIS_HOST=127.0.0.1
|
||||
- REDIS_PORT=6379
|
||||
- POSTGRES_HOST=127.0.0.1
|
||||
- POSTGRES_PORT=5432
|
||||
- POSTGRES_DB=upsnap
|
||||
- POSTGRES_USER=upsnap
|
||||
- POSTGRES_PASSWORD=upsnap
|
||||
- PING_INTERVAL=5
|
||||
- ENABLE_NOTIFICATIONS=True
|
||||
depends_on:
|
||||
- upsnap_redis
|
||||
- upsnap_postgres
|
||||
upsnap_redis:
|
||||
container_name: upsnap_redis
|
||||
image: redis:6
|
||||
network_mode: host
|
||||
restart: always
|
||||
image: redis:alpine
|
||||
ports:
|
||||
- "6379:6379"
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: redis-cli ping
|
||||
interval: 10s
|
||||
upsnap_postgres:
|
||||
container_name: upsnap_postgres
|
||||
image: postgres:13-alpine
|
||||
restart: always
|
||||
network_mode: host
|
||||
image: postgres:14-alpine
|
||||
ports:
|
||||
- "5432:5432"
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- "POSTGRES_USER=upsnap"
|
||||
- "POSTGRES_PASSWORD=upsnap"
|
||||
- "POSTGRES_DB=upsnap"
|
||||
healthcheck:
|
||||
test: pg_isready -U upsnap
|
||||
interval: 10s
|
||||
volumes:
|
||||
- upsnap_db:/var/lib/postgresql/data
|
||||
volumes:
|
||||
|
||||
Reference in New Issue
Block a user