mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-11-29 05:06:09 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a1137ca7a | |||
| 0706ff869e | |||
| ffc17824ec | |||
| abf05a2b21 | |||
| 541b651a41 | |||
| 0772eb3c39 | |||
| 5d9264494a | |||
| a59672bffc | |||
| 8b315c34b4 |
@@ -32,6 +32,8 @@
|
||||
|
||||
You can use the example [docker-compose.yml](docker-compose.yml) file and just run `docker-compose up -d`.
|
||||
|
||||
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.
|
||||
|
||||
## 🔧 Available Env Vars
|
||||
|
||||
| env var | type | info |
|
||||
@@ -52,3 +54,4 @@ You can use the example [docker-compose.yml](docker-compose.yml) file and just r
|
||||
## 📝 Other infos
|
||||
|
||||
* The django 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.
|
||||
* Firefox 92 and below: The datetime picker for wake events will be available with version 93 and above. [see here](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local#browser_compatibility)
|
||||
|
||||
@@ -142,4 +142,4 @@ STATIC_URL = '/static/'
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
||||
|
||||
VERSION = "v1.0.0"
|
||||
VERSION = "v1.0.2"
|
||||
+1
-1
@@ -10,7 +10,7 @@ if [ -n "$DJANGO_SUPERUSER_USER" ] && [ -n "$DJANGO_SUPERUSER_PASSWORD" ]; then
|
||||
fi
|
||||
|
||||
# set visitors to 0
|
||||
python -u manage.py shell -c "from wol.models import Websocket; [i.delete() for i in Websocket.objects.all()]; Websocket.objects.create(visitors=0)"
|
||||
python -u manage.py shell -c "from wol.models import Websocket; [i.delete() for i in Websocket.objects.all()]; Websocket.objects.create(visitors=0)"
|
||||
|
||||
# set notifications
|
||||
if [ -n "$ENABLE_NOTIFICATIONS" ]; then
|
||||
|
||||
@@ -11,3 +11,9 @@ class SettingsForm(forms.Form):
|
||||
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")
|
||||
|
||||
|
||||
class AddCustomDevice(forms.Form):
|
||||
custom_add_name = forms.CharField(label="custom_add_name")
|
||||
custom_add_ip = forms.CharField(label="custom_add_ip")
|
||||
custom_add_mac = forms.CharField(label="custom_add_mac")
|
||||
|
||||
@@ -295,15 +295,15 @@ socket.onmessage = function (event) {
|
||||
|
||||
// set wake by client
|
||||
if ("wake" in message) {
|
||||
document.getElementById(message.wake.id + "-btn-wake").classList.add("is-loading");
|
||||
document.querySelector(`[id="btn-wake"][data-id="${message.wake.id}"]`).classList.add("is-loading");
|
||||
if (enableNotifications) {
|
||||
notif.show("Wake started", message.wake.name + " has been started.", "is-info", 5000);
|
||||
notif.show("Wake started", "Wake command for " + message.wake.name + " has been sent.", "is-info", 5000);
|
||||
}
|
||||
}
|
||||
|
||||
// set wake by schedule
|
||||
if ("wake_schedule" in message) {
|
||||
document.getElementById(message.wake_schedule.id + "-btn-wake").classList.add("is-loading");
|
||||
document.querySelector(`[id="btn-wake"][data-id="${message.wake_schedule.id}"]`).classList.add("is-loading");
|
||||
document.getElementById(message.wake_schedule.id + "-schedule-notice").innerHTML = "";
|
||||
if (enableNotifications) {
|
||||
notif.show("Scheduled wake started", message.wake_schedule.name + " has been started.", "is-info", 5000);
|
||||
|
||||
@@ -66,7 +66,7 @@ async function scan() {
|
||||
|
||||
function add_device(data) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = "/settings/add/";
|
||||
var url = "/settings/scan_add/";
|
||||
xhr.open("POST", url, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.send(data);
|
||||
|
||||
@@ -119,7 +119,27 @@
|
||||
<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 devices</h2>
|
||||
<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 %}
|
||||
@@ -141,7 +161,7 @@
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-full-mobile is-full-tablet is-full-desktop is-full-widescreen is-half-fullhd">
|
||||
<div class="box no-flex">
|
||||
@@ -166,7 +186,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
+2
-1
@@ -7,6 +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/add/", views.settings_add, name="settings_add"),
|
||||
path("settings/scan_add/", views.settings_scan_add, name="settings_scan_add"),
|
||||
path("settings/custom_add/", views.settings_custom_add, name="settings_custom_add"),
|
||||
path("settings/del/", views.settings_del, name="settings_del")
|
||||
]
|
||||
|
||||
+21
-5
@@ -12,7 +12,7 @@ from django.utils.decorators import method_decorator
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django_wol.settings import VERSION as app_version
|
||||
|
||||
from .forms import SettingsForm
|
||||
from .forms import AddCustomDevice, SettingsForm
|
||||
from .models import Device, Settings, Websocket
|
||||
|
||||
|
||||
@@ -74,7 +74,8 @@ def settings_scan(request):
|
||||
if not conf.scan_address:
|
||||
return JsonResponse(data=data)
|
||||
|
||||
p = subprocess.Popen(["nmap", "-sP", conf.scan_address], stdout=subprocess.PIPE)
|
||||
p = subprocess.Popen(
|
||||
["nmap", "-sP", conf.scan_address], stdout=subprocess.PIPE)
|
||||
out = p.communicate()[0].decode("utf-8")
|
||||
ip_line = "Nmap scan report for"
|
||||
mac_line = "MAC Address:"
|
||||
@@ -89,11 +90,11 @@ def settings_scan(request):
|
||||
ip = ip.replace(")", "")
|
||||
else:
|
||||
name = "Unknown"
|
||||
ip = line_splitted[4]
|
||||
ip = line_splitted[4]
|
||||
elif line.startswith(mac_line):
|
||||
line_splitted = line.split()
|
||||
mac = line_splitted[2]
|
||||
|
||||
|
||||
data["devices"].append({
|
||||
"name": name,
|
||||
"ip": ip,
|
||||
@@ -103,8 +104,22 @@ def settings_scan(request):
|
||||
return JsonResponse(data=data)
|
||||
|
||||
|
||||
def settings_custom_add(request):
|
||||
if request.method == "POST":
|
||||
form = AddCustomDevice(request.POST)
|
||||
if form.is_valid():
|
||||
Device.objects.update_or_create(
|
||||
mac=form.cleaned_data["custom_add_mac"],
|
||||
defaults={
|
||||
"name": form.cleaned_data["custom_add_name"],
|
||||
"ip": form.cleaned_data["custom_add_ip"]
|
||||
}
|
||||
)
|
||||
return HttpResponseRedirect('/settings/')
|
||||
|
||||
|
||||
@method_decorator(csrf_exempt, name="dispatch")
|
||||
def settings_add(request):
|
||||
def settings_scan_add(request):
|
||||
data = {}
|
||||
if request.method == "POST":
|
||||
post_body = json.loads(request.body.decode('utf-8'))
|
||||
@@ -131,6 +146,7 @@ def settings_add(request):
|
||||
|
||||
return JsonResponse(data=data)
|
||||
|
||||
|
||||
@method_decorator(csrf_exempt, name="dispatch")
|
||||
def settings_del(request):
|
||||
data = {}
|
||||
|
||||
Reference in New Issue
Block a user