Compare commits

...

14 Commits

Author SHA1 Message Date
Maxi Quoß c628832632 v1.4..1 2022-02-01 20:49:54 +01:00
Maxi Quoß 0ddece6786 v1.4.0 2022-02-01 19:54:21 +01:00
Maxi Quoß 53e2beaf52 close #8 2022-02-01 19:44:48 +01:00
Maxi Quoß e9e4e5b548 v1.3.0 2022-01-16 17:48:00 +01:00
Maxi Quoß 60704ae333 support postgres, mysql and sqlite #7 2022-01-16 17:46:22 +01:00
Maxi Quoß 3f0487ef6a v1.2.2 2022-01-15 15:35:43 +01:00
Maxi Quoß d965d17d54 use alpine image to fix #3 2022-01-15 15:29:30 +01:00
Maxi Quoß 4c406227b5 v1.2.1 2022-01-14 18:55:22 +01:00
Maxi Quoß 963a38bc8b fix couple js errors, remove visitors notification 2022-01-14 18:55:16 +01:00
Maxi Quoß 79739dc1b3 settings: make devices editable #5 2022-01-14 18:20:28 +01:00
Maxi Quoß c1b6f6bd9f settings: sort delete devices table by user conf 2022-01-14 16:15:23 +01:00
Maxi Quoß f738cd7c59 settings: make network address field optional 2022-01-14 16:14:54 +01:00
Maxi Quoß 4a3b959176 v1.1.2 2022-01-14 15:53:02 +01:00
Maxi Quoß 4aebc5fb1f changed: env vars for redis and portgres 2022-01-14 15:52:25 +01:00
16 changed files with 391 additions and 111 deletions
+1
View File
@@ -284,3 +284,4 @@ $RECYCLE.BIN/
# End of https://www.toptal.com/developers/gitignore/api/windows,linux,macos,python,django
.vscode
app/staticfiles
+9 -9
View File
@@ -1,26 +1,26 @@
FROM python:3.10-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 mariadb-dev cargo &&\
rm -rf /var/cache/apk/* &&\
mkdir /install
WORKDIR /install
COPY requirements.txt .
RUN python -m pip 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 curl && \
rm -rf /var/lib/apt/lists/*
RUN apk update &&\
apk add iputils nmap curl bash mariadb-dev &&\
rm -rf /var/cache/apk/*
HEALTHCHECK --interval=10s \
CMD curl -fs "http://localhost:$DJANGO_PORT/health/" || exit 1
+13 -4
View File
@@ -30,10 +30,14 @@
## 🐳 Run your own instance
You can use the example [docker-compose.yml](docker-compose.yml) file and just run `docker-compose up -d`.
There are 3 example docker-compose files to choose from. The simplest is [docker-compose-sqlite.yml](docker-compose-sqlite.yml).
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.
### 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
## 🔧 Available Env Vars
| env var | type | info |
@@ -45,9 +49,14 @@ The website will be available at [localhost:8000](http://localhost:8000). If you
| DJANGO_LANGUAGE_CODE | Str | Language code in RFC 3066 (e.g. "en-us" or "de") |
| DJANGO_TIME_ZONE | Str | e.g. Europe/Berlin |
| DJANGO_PORT | Int | Web port |
| POSTGRES_USER | Str | Database user |
| POSTGRES_PASSWORD | Str | Database password |
| POSTGRES_DB | Str | Database name |
| REDIS_HOST | Str | The ip redis runs on |
| REDIS_PORT | Int | The port redis runs on |
| DB_TYPE | Str | Database type. Can be "postgres", "mysql" or "sqlite" |
| DB_HOST | Str | The ip the database runs on |
| DB_PORT | Str | The port the database runs on|
| DB_NAME | Str | Database name |
| DB_USER | Str | Database user |
| DB_PASSWORD | Str | Database password |
| PING_INTERVAL | Int | Time between pings |
| ENABLE_NOTIFICATIONS | Bool | Show notifications in the bottom right corner |
+37 -13
View File
@@ -73,23 +73,47 @@ TEMPLATES = [
WSGI_APPLICATION = 'django_wol.wsgi.application'
ASGI_APPLICATION = 'django_wol.asgi.application'
CELERY_BROKER_URL = "redis://127.0.0.1:6379"
CELERY_BROKER_URL = f"redis://{os.getenv('REDIS_HOST', '127.0.0.1')}:{os.getenv('REDIS_PORT', 6379)}"
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": os.getenv("POSTGRES_DB", "upsnap"),
"USER": os.getenv("POSTGRES_USER", "upsnap"),
"PASSWORD": os.getenv("POSTGRES_PASSWORD", "upsnap"),
"HOST": "127.0.0.1",
"PORT": 5432,
"OPTIONS": {"connect_timeout": 5},
if os.getenv("DB_TYPE") == "postgres":
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": os.getenv("DB_NAME", "upsnap"),
"USER": os.getenv("DB_USER", "upsnap"),
"PASSWORD": os.getenv("DB_PASSWORD", "upsnap"),
"HOST": os.getenv("DB_HOST", "127.0.0.1"),
"PORT": os.getenv("DB_PORT", 5432),
"OPTIONS": {
"connect_timeout": 30
}
}
}
elif os.getenv("DB_TYPE") == "mysql":
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": os.getenv("DB_NAME", "upsnap"),
"USER": os.getenv("DB_USER", "upsnap"),
"PASSWORD": os.getenv("DB_PASSWORD", "upsnap"),
"HOST": os.getenv("DB_HOST", "127.0.0.1"),
"PORT": os.getenv("DB_PORT", 3306),
"OPTIONS": {
"connect_timeout": 30
}
}
}
elif os.getenv("DB_TYPE") == "sqlite":
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME" : "db.sqlite3",
}
}
}
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
@@ -97,7 +121,7 @@ CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [("127.0.0.1", 6379)]
"hosts": [(os.getenv("REDIS_HOST", "127.0.0.1"), os.getenv("REDIS_PORT", 6379))]
}
}
}
@@ -142,4 +166,4 @@ STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
VERSION = "v1.1.1"
VERSION = "v1.4.1"
+5 -2
View File
@@ -1,8 +1,11 @@
#!/bin/sh
# wait for db and redis
/usr/bin/env bash ./wait-for-it.sh 127.0.0.1:5432 -t 300 -s
/usr/bin/env bash ./wait-for-it.sh 127.0.0.1:6379 -t 300 -s
if [ "${DB_TYPE}" != "sqlite" ]; then
/usr/bin/env bash ./wait-for-it.sh "${DB_HOST}":"${DB_PORT}" -t 300 -s
sleep 20
fi
/usr/bin/env bash ./wait-for-it.sh "${REDIS_HOST}":"${REDIS_PORT}" -t 300 -s
python manage.py makemigrations
python manage.py migrate
+2 -1
View File
@@ -10,10 +10,11 @@ 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):
custom_add_name = forms.CharField(label="custom_add_name")
custom_add_ip = forms.CharField(label="custom_add_ip")
custom_add_netmask = forms.CharField(label="custom_add_netmask")
custom_add_mac = forms.CharField(label="custom_add_mac")
+9 -1
View File
@@ -80,6 +80,14 @@
flex-direction: unset;
}
.w-20 {
width: 20%;
}
.w-30 {
width: 30%;
}
@media (prefers-color-scheme: dark) {
.box {
background-color: var(--box-bg);
@@ -102,7 +110,7 @@
.navbar-menu.is-active {
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.2)
}
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
filter: invert(1);
}
+4 -7
View File
@@ -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) {
+103 -29
View File
@@ -5,11 +5,82 @@
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 devNetmaskLabelContainer = document.querySelector(`[id=dev-netmask-label-container][data-id="${element.dataset.id}"]`)
const devNetmaskInputContainer = document.querySelector(`[id=dev-netmask-input-container][data-id="${element.dataset.id}"]`)
const devNetmaskInput = document.querySelector(`[id=dev-netmask-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");
devNetmaskLabelContainer.innerText = devNetmaskInput.value;
devNetmaskInputContainer.classList.toggle("is-hidden");
devNetmaskLabelContainer.classList.toggle("is-hidden");
post_settings("/settings/update/", JSON.stringify({
"name": devNameInput.value,
"ip": devIpInput.value,
"netmask": devNetmaskInput.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");
const devINetmaskLabelContainer = document.querySelector(`[id=dev-netmask-label-container][data-id="${element.dataset.id}"]`)
devINetmaskLabelContainer.classList.toggle("is-hidden");
const devNetmaskInputContainer = document.querySelector(`[id=dev-netmask-input-container][data-id="${element.dataset.id}"]`)
devNetmaskInputContainer.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,45 +108,48 @@ 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();
const td5 = 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");
td3.appendChild(document.createTextNode(device.netmask));
td4.appendChild(document.createTextNode(device.mac));
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";
});
td4.appendChild(button);
td5.appendChild(button);
td1.classList.add("is-vcentered", "w-20");
td2.classList.add("is-vcentered", "w-20");
td3.classList.add("is-vcentered", "w-20");
td4.classList.add("is-vcentered", "w-20");
td5.classList.add("is-vcentered", "w-20");
}
document.getElementById("scan-button").classList.remove("is-loading");
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);
}
+86 -29
View File
@@ -107,7 +107,14 @@
<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>
@@ -130,22 +137,39 @@
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>
<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 custom</h3>
<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>
<th class="w-20">Name</th>
<th class="w-20">IP</th>
<th class="w-20">Netmask</th>
<th class="w-20">MAC</th>
<th class="w-20">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">
<input type="text" class="input" name="custom_add_name">
</td>
<td class="is-vcentered">
<input type="text" class="input" name="custom_add_ip">
</td>
<td class="is-vcentered">
<input type="text" class="input" name="custom_add_netmask" value="{{ netmask }}">
</td>
<td class="is-vcentered">
<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>
@@ -154,36 +178,69 @@
</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>
<h3 class="title is-size-4 my-5">Delete devices</h3>
<div id="delete-table-container" class="table-container">
<table id="delete-table" class="table is-fullwidth">
{% if devices %}
<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>
<th class="w-20">Name</th>
<th class="w-20">IP</th>
<th class="w-20">Netmask</th>
<th class="w-20">MAC</th>
<th class="w-20">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>
<td id="dev-name" data-id="{{ dev.id }}" class="is-vcentered">
<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 }}" class="is-vcentered">
<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-netmask" data-id="{{ dev.id }}" class="is-vcentered">
<div id="dev-netmask-label-container" data-id="{{ dev.id }}">
{{ dev.netmask }}
</div>
<div id="dev-netmask-input-container" data-id="{{ dev.id }}" class="is-hidden">
<input id="dev-netmask-input" data-id="{{ dev.id }}" type="text" class="input" value="{{ dev.netmask }}">
</div>
</td>
<td id="dev-mac" data-id="{{ dev.id }}" class="is-vcentered">
{{ 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>
{% endif %}
<h3 class="title is-size-4 my-5">Backup / Restore</h3>
<div class="columns is-tablet">
<div class="column is-narrow">
@@ -215,7 +272,7 @@
</div>
</div>
</section>
<section class="section py-3">
<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">
@@ -316,4 +373,4 @@
<script src="{% static 'js/settings.js' %}"></script>
</footer>
</html>
</html>
+1 -1
View File
@@ -7,7 +7,7 @@ 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/export/", views.settings_export, name="settings_export"),
+14 -4
View File
@@ -1,3 +1,4 @@
import ipaddress
import json
import os
import platform
@@ -36,11 +37,16 @@ def index(request):
def settings(request):
conf = Settings.objects.first()
devices = Device.objects.all()
if conf.scan_address:
netmask = str(ipaddress.ip_network(conf.scan_address).netmask)
else:
netmask = ""
devices = Device.objects.all().order_by(conf.sort_by)
visitors = Websocket.objects.first().visitors
context = {
"settings": conf,
"netmask": netmask,
"ping_interval": os.getenv("PING_INTERVAL"),
"devices": devices,
"platform": platform.uname(),
@@ -74,6 +80,7 @@ def settings_scan(request):
}
conf = Settings.objects.filter(id=1).get()
netmask = str(ipaddress.ip_network(conf.scan_address).netmask)
if not conf.scan_address:
return JsonResponse(data=data)
@@ -102,6 +109,7 @@ def settings_scan(request):
data["devices"].append({
"name": name,
"ip": ip,
"netmask": netmask,
"mac": mac
})
@@ -116,14 +124,15 @@ def settings_custom_add(request):
mac=form.cleaned_data["custom_add_mac"],
defaults={
"name": form.cleaned_data["custom_add_name"],
"ip": form.cleaned_data["custom_add_ip"]
"ip": form.cleaned_data["custom_add_ip"],
"netmask": form.cleaned_data["custom_add_netmask"]
}
)
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"))
@@ -135,7 +144,8 @@ def settings_scan_add(request):
mac=post_body["mac"],
defaults={
"name": name,
"ip": post_body["ip"]
"ip": post_body["ip"],
"netmask": post_body["netmask"]
}
)
data["status"] = 200
+57
View File
@@ -0,0 +1,57 @@
version: "3"
services:
upsnap_django:
container_name: upsnap_django
image: seriousm4x/upsnap:latest
network_mode: host
restart: unless-stopped
environment:
- DJANGO_SUPERUSER_USER=admin
- DJANGO_SUPERUSER_PASSWORD=admin
- DJANGO_SECRET_KEY=secret
- DJANGO_DEBUG=False
- DJANGO_LANGUAGE_CODE=de
- DJANGO_TIME_ZONE=Europe/Berlin
- DJANGO_PORT=8000
- REDIS_HOST=127.0.0.1
- REDIS_PORT=6379
- DB_TYPE=mysql
- DB_HOST=127.0.0.1
- DB_PORT=3306
- DB_NAME=upsnap
- DB_USER=upsnap
- DB_PASSWORD=upsnap
- PING_INTERVAL=5
- ENABLE_NOTIFICATIONS=True
depends_on:
- upsnap_redis
- upsnap_mysql
upsnap_redis:
container_name: upsnap_redis
image: redis:alpine
ports:
- "6379:6379"
restart: unless-stopped
healthcheck:
test: redis-cli ping
interval: 10s
upsnap_mysql:
container_name: upsnap_mysql
image: mysql
restart: unless-stopped
ports:
- "3306:3306"
environment:
- MYSQL_DATABASE=upsnap
- MYSQL_USER=upsnap
- MYSQL_PASSWORD=upsnap
- MYSQL_ROOT_PASSWORD=upsnap
cap_add:
- SYS_NICE
volumes:
- upsnap_db:/var/lib/mysql
healthcheck:
test: mysqladmin ping -h localhost -u $$MYSQL_USER -p$$MYSQL_PASSWORD
interval: 10s
volumes:
upsnap_db:
@@ -13,9 +13,14 @@ services:
- DJANGO_LANGUAGE_CODE=de
- DJANGO_TIME_ZONE=Europe/Berlin
- DJANGO_PORT=8000
- POSTGRES_USER=upsnap
- POSTGRES_PASSWORD=upsnap
- POSTGRES_DB=upsnap
- REDIS_HOST=127.0.0.1
- REDIS_PORT=6379
- DB_TYPE=postgres
- DB_HOST=127.0.0.1
- DB_PORT=5432
- DB_NAME=upsnap
- DB_USER=upsnap
- DB_PASSWORD=upsnap
- PING_INTERVAL=5
- ENABLE_NOTIFICATIONS=True
depends_on:
@@ -23,8 +28,9 @@ services:
- upsnap_postgres
upsnap_redis:
container_name: upsnap_redis
image: redis:6
network_mode: host
image: redis:alpine
ports:
- "6379:6379"
restart: unless-stopped
healthcheck:
test: redis-cli ping
@@ -32,7 +38,8 @@ services:
upsnap_postgres:
container_name: upsnap_postgres
image: postgres:14-alpine
network_mode: host
ports:
- "5432:5432"
restart: unless-stopped
environment:
- "POSTGRES_USER=upsnap"
+31
View File
@@ -0,0 +1,31 @@
version: "3"
services:
upsnap_django:
container_name: upsnap_django
image: seriousm4x/upsnap:latest
network_mode: host
restart: unless-stopped
environment:
- DJANGO_SUPERUSER_USER=admin
- DJANGO_SUPERUSER_PASSWORD=admin
- DJANGO_SECRET_KEY=secret
- DJANGO_DEBUG=False
- DJANGO_LANGUAGE_CODE=de
- DJANGO_TIME_ZONE=Europe/Berlin
- DJANGO_PORT=8000
- REDIS_HOST=127.0.0.1
- REDIS_PORT=6379
- DB_TYPE=sqlite
- PING_INTERVAL=5
- ENABLE_NOTIFICATIONS=True
depends_on:
- upsnap_redis
upsnap_redis:
container_name: upsnap_redis
image: redis:alpine
ports:
- "6379:6379"
restart: unless-stopped
healthcheck:
test: redis-cli ping
interval: 10s
+6 -5
View File
@@ -1,9 +1,10 @@
django
wakeonlan
celery[redis]
channels
channels-redis
celery[redis]
psycopg2-binary
whitenoise
django
gunicorn
mysqlclient
psycopg2-binary
uvicorn[standard]
wakeonlan
whitenoise