Compare commits

...

20 Commits

Author SHA1 Message Date
Maxi Quoß 3b9decd572 add container_name, fix health whitespace 2023-02-11 22:54:19 +01:00
Maxi Quoß 9a1a816f25 change error messages 2023-02-11 22:49:23 +01:00
Maxi Quoß 8d43554e0e check if To4() == nil 2023-02-11 22:48:16 +01:00
Maxi Quoß b88f567d9f move healthcheck to dockerfile 2023-02-11 22:24:50 +01:00
Maxi Quoß cb168f2f47 remove magicpacket log 2023-02-11 22:24:23 +01:00
Maxi Quoß 376220c557 natural sort devices by name
meaning, 1-2-10 instead of 1-10-2
2023-02-11 22:08:39 +01:00
Maxi Quoß ef064e9335 shutdown: print stderr to log 2023-02-11 21:53:57 +01:00
Maxi Quoß 67870d8114 add go version badge 2023-02-09 01:12:54 +01:00
Maxi Quoß 7bd4712ddd get correct broadcast for netmask 0.0.0.0, #46 2023-02-09 00:40:04 +01:00
seriousm4x f3b740d092 Create FUNDING.yml 2023-02-05 00:52:25 +01:00
Maxi Quoß a721af02b4 add info about custom packages in container 2023-02-04 14:43:15 +01:00
seriousm4x b9aa9feb1d Update issue templates 2023-02-04 13:27:27 +01:00
seriousm4x 59770cf013 Update issue templates 2023-02-04 13:27:05 +01:00
seriousm4x 8b65cd69bc Update issue templates 2023-02-04 13:24:56 +01:00
seriousm4x 0f7026f3d0 Update issue templates 2023-02-04 13:22:49 +01:00
Maxi Quoß 66b41170e8 rename workflow 2023-02-01 20:20:53 +01:00
Maxi Quoß 27b1a10e86 goreleaser: -rm-dist has been deprecated 2023-02-01 17:56:59 +01:00
Maxi Quoß 482a9884a4 add some error logging 2023-02-01 17:51:34 +01:00
Maxi Quoß ed285f502e fix openssh not working, close #37 2023-02-01 17:06:59 +01:00
Maxi Quoß b6f76c55c9 replace go-ping/ping (deprecated) 2023-01-31 13:47:13 +01:00
15 changed files with 115 additions and 39 deletions
+2
View File
@@ -0,0 +1,2 @@
github: seriousm4x
ko_fi: seriousm4x
@@ -0,0 +1,17 @@
---
name: "⭐ Feature request"
about: Suggest an idea for this project
title: "[REQUEST]"
labels: ''
assignees: ''
---
**The problem you currently have with this project**
A clear and concise description of what the problem is.
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Additional context**
Add any other context or screenshots about the feature request here.
@@ -0,0 +1,41 @@
---
name: "\U0001F577️ Bug report"
about: Create a report to help the project improve
title: "[BUG]"
labels: ''
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Logs**
```
formatted logs here
```
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Host OS (and version)**
eg. Windows 10, Ubuntu 22.10, macOS 13
**Host Architecture**
e.g. amd64/arm64/arm7
**Brower (if relevant)**
e.g. Firefox 109.0.1
**Additional context**
Add any other context about the problem here.
+3 -3
View File
@@ -1,4 +1,4 @@
name: Deploy release
name: v3 build
on:
push:
@@ -26,7 +26,7 @@ jobs:
- name: Build frontend
run: |
npm --prefix=./frontend i
UPSNAP_VERSION=${GITHUB_REF##*/} npm --prefix=./frontend run build
UPSNAP_VERSION=${GITHUB_REF##*/} npm --prefix=./frontend run build
cp -r ./frontend/build/* ./backend/pb_public/
# setup go
@@ -41,7 +41,7 @@ jobs:
with:
distribution: goreleaser
version: latest
args: release --rm-dist
args: release --clean
workdir: backend
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+3 -1
View File
@@ -12,8 +12,10 @@ RUN wget https://github.com/seriousm4x/UpSnap/releases/download/${VERSION}/UpSna
FROM alpine:3
RUN apk update &&\
apk add --no-cache tzdata ca-certificates nmap samba-common-tools sshpass curl &&\
apk add --no-cache tzdata ca-certificates nmap samba-common-tools openssh sshpass curl &&\
rm -rf /var/cache/apk/*
WORKDIR /app
COPY --from=downloader /app/upsnap upsnap
HEALTHCHECK --interval=10s \
CMD curl -fs "http://localhost:8090/api/health" || exit 1
ENTRYPOINT ["./upsnap", "serve", "--http=0.0.0.0:8090"]
+3
View File
@@ -7,6 +7,7 @@
<p>A simple wake on lan app written with SvelteKit, Go, PocketBase and nmap.</p>
<a target="_blank" href="https://github.com/seriousm4x/upsnap"><img src="https://img.shields.io/github/stars/seriousm4x/upsnap" /></a>
<a target="_blank" href="https://github.com/seriousm4x/UpSnap/releases"><img src="https://img.shields.io/github/downloads/seriousm4x/upsnap/total" /></a>
<a target="_blank" href="https://github.com/seriousm4x/UpSnap/releases"><img src="https://img.shields.io/github/go-mod/go-version/seriousm4x/UpSnap?filename=backend/go.mod" /></a>
<a target="_blank" href="https://github.com/seriousm4x/UpSnap/releases"><img src="https://img.shields.io/github/v/release/seriousm4x/upsnap?display_name=tag" /></a>
<a target="_blank" href="https://github.com/seriousm4x/UpSnap/actions"><img src="https://github.com/seriousm4x/upsnap/actions/workflows/deploy.yml/badge.svg?event=push" /></a>
<a target="_blank" href="https://github.com/seriousm4x/UpSnap/commits/master"><img src="https://img.shields.io/github/last-commit/seriousm4x/upsnap" /></a>
@@ -42,6 +43,8 @@ If you need network discovery, make sure to have `nmap` installed and run upsnap
Alternatively use the [docker-compose](docker-compose.yml) example. See the comments in the file for customization.
If you need additional packages inside the container, uncomment the `entrypoint` inside the compose file. You can search for your needed package [here](https://pkgs.alpinelinux.org/packages).
### Reverse Proxy
**Caddy example**
+1 -1
View File
@@ -3,11 +3,11 @@ module github.com/seriousm4x/upsnap
go 1.19
require (
github.com/go-ping/ping v1.1.0
github.com/labstack/echo/v5 v5.0.0-20220201181537-ed2888cfa198
github.com/mdlayher/wol v0.0.0-20220221231636-b763a792253a
github.com/pocketbase/dbx v1.9.0
github.com/pocketbase/pocketbase v0.12.0
github.com/prometheus-community/pro-bing v0.1.0
github.com/robfig/cron/v3 v3.0.1
)
+2 -2
View File
@@ -934,8 +934,6 @@ github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/e
github.com/go-openapi/validate v0.21.0/go.mod h1:rjnrwK57VJ7A8xqfpAOEKRH8yQSGUriMu5/zuPSQ1hg=
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 h1:byhDUpfEwjsVQb1vBunvIjh2BHQ9ead57VkAEY4V+Es=
github.com/go-ozzo/ozzo-validation/v4 v4.3.0/go.mod h1:2NKgrcHl3z6cJs+3Oo940FPRiTzuqKbvfrL2RxCj6Ew=
github.com/go-ping/ping v1.1.0 h1:3MCGhVX4fyEUuhsfwPrsEdQw6xspHkv5zHsiSoDFZYw=
github.com/go-ping/ping v1.1.0/go.mod h1:xIFjORFzTxqIV/tDVGO4eDy/bLuSyawEeojSm3GfRGk=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
@@ -1583,6 +1581,8 @@ github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndr
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA=
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
github.com/prometheus-community/pro-bing v0.1.0 h1:zjzLGhfNPP0bP1OlzGB+SJcguOViw7df12LPg2vUJh8=
github.com/prometheus-community/pro-bing v0.1.0/go.mod h1:BpWlHurD9flHtzq8wrh8QGWYz9ka9z9ZJAyOel8ej58=
github.com/prometheus/alertmanager v0.24.0/go.mod h1:r6fy/D7FRuZh5YbnX6J3MBY0eI4Pb5yPYS7/bPSXXqI=
github.com/prometheus/client_golang v0.0.0-20180209125602-c332b6f63c06/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
+26 -20
View File
@@ -1,7 +1,6 @@
package networking
import (
"encoding/binary"
"errors"
"fmt"
"net"
@@ -17,18 +16,10 @@ func SendMagicPacket(device *models.Record) error {
password := device.GetString("password")
// parse inputs
parsedIP := net.ParseIP(ip)
if parsedIP == nil {
return fmt.Errorf("error: invalid ip address")
}
parsedMac, err := net.ParseMAC(mac)
if err != nil {
return err
}
parsedNetmask := net.ParseIP(netmask)
if parsedNetmask == nil {
return fmt.Errorf("error: invalid netmask")
}
var bytePassword []byte
if len(password) == 0 || len(password) == 4 || len(password) == 6 {
bytePassword = []byte(password)
@@ -37,11 +28,7 @@ func SendMagicPacket(device *models.Record) error {
}
// get target addr
ipNet := &net.IPNet{
IP: parsedIP,
Mask: parsedNetmask.DefaultMask(),
}
broadcastIp, err := getBroadcastIp(ipNet)
broadcastIp, err := getBroadcastIp(ip, netmask)
if err != nil {
return err
}
@@ -64,11 +51,30 @@ func wakeUDP(addr string, target net.HardwareAddr, password []byte) error {
return c.WakePassword(addr, target, password)
}
func getBroadcastIp(n *net.IPNet) (net.IP, error) {
if n.IP.To4() == nil {
return net.IP{}, errors.New("does not support IPv6 addresses")
func getBroadcastIp(ipStr, maskStr string) (string, error) {
ip := net.ParseIP(ipStr)
if ip == nil {
return "", errors.New("ip not a valid ipv4 address")
}
ip := make(net.IP, len(n.IP.To4()))
binary.BigEndian.PutUint32(ip, binary.BigEndian.Uint32(n.IP.To4())|^binary.BigEndian.Uint32(net.IP(n.Mask).To4()))
return ip, nil
ip = ip.To4()
if ip == nil {
return "", errors.New("ip not a valid ipv4 address")
}
mask := net.ParseIP(maskStr)
if mask == nil {
return "", errors.New("subnet mask not a valid ipv4 address")
}
mask = mask.To4()
ip = ip.To4()
if ip == nil {
return "", errors.New("subnet mask not a valid ipv4 address")
}
broadcast := make(net.IP, 4)
for i := range ip {
broadcast[i] = ip[i] | ^mask[i]
}
return broadcast.String(), nil
}
+2 -2
View File
@@ -4,13 +4,13 @@ import (
"net"
"time"
"github.com/go-ping/ping"
"github.com/pocketbase/pocketbase/models"
probing "github.com/prometheus-community/pro-bing"
"github.com/seriousm4x/upsnap/logger"
)
func PingDevice(device *models.Record) bool {
pinger, err := ping.NewPinger(device.GetString("ip"))
pinger, err := probing.NewPinger(device.GetString("ip"))
if err != nil {
logger.Error.Println(err)
return false
+4 -1
View File
@@ -1,6 +1,7 @@
package networking
import (
"bytes"
"fmt"
"os/exec"
"runtime"
@@ -28,8 +29,10 @@ func ShutdownDevice(device *models.Record) error {
}
cmd := exec.Command(shell, shell_arg, shutdown_cmd)
var stderr bytes.Buffer
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return err
return fmt.Errorf("%s", stderr.String())
}
// check state every second for 2 min
+3
View File
@@ -11,6 +11,7 @@ import (
"github.com/labstack/echo/v5"
"github.com/pocketbase/pocketbase/apis"
"github.com/pocketbase/pocketbase/models"
"github.com/seriousm4x/upsnap/logger"
"github.com/seriousm4x/upsnap/networking"
)
@@ -23,6 +24,7 @@ func HandlerWake(c echo.Context) error {
record.Set("status", "pending")
App.Dao().SaveRecord(record)
if err := networking.WakeDevice(record); err != nil {
logger.Error.Println(err)
record.Set("status", "offline")
} else {
record.Set("status", "online")
@@ -41,6 +43,7 @@ func HandlerShutdown(c echo.Context) error {
record.Set("status", "pending")
App.Dao().SaveRecord(record)
if err := networking.ShutdownDevice(record); err != nil {
logger.Error.Println(err)
record.Set("status", "online")
} else {
record.Set("status", "offline")
+1 -2
View File
@@ -2,7 +2,6 @@ package pb
import (
"io/fs"
"log"
"net/http"
"os"
@@ -112,7 +111,7 @@ func StartPocketBase(distDirFS fs.FS) {
// start pocketbase
if err := App.Start(); err != nil {
log.Fatal(err)
logger.Error.Fatalln(err)
}
}
+3 -6
View File
@@ -1,19 +1,16 @@
version: "3"
services:
upsnap:
container_name: upsnap
image: ghcr.io/seriousm4x/upsnap:3
network_mode: host
restart: unless-stopped
volumes:
- ./data:/app/pb_data
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:8090/api/health || exit 1
interval: 1m
timeout: 10s
retries: 3
# environment:
# - TZ=Europe/Berlin # Set container timezone for cron schedules
# - UPSNAP_INTERVAL=@every 10s # Sets the interval in which the devices are pinged
# - UPSNAP_SCAN_RANGE=192.168.1.0/24 # Scan range is used for device discovery on local network
# - UPSNAP_WEBSITE_TITLE=Custom name # Custom website title
# command: ["./upsnap", "serve", "--http", "0.0.0.0:8090"] # Uncomment this if you want to change the port for example
# # you can change the listen ip:port inside the container or install custom packages for shutdown via a custom entrypoint
# entrypoint: /bin/sh -c "apk update && apk add --no-cache ipmitool && rm -rf /var/cache/apk/* && ./upsnap serve --http 0.0.0.0:8090"
+4 -1
View File
@@ -1,5 +1,8 @@
export function sortDevices(a, b) {
return a.name > b.name;
return a.name.localeCompare(b.name, undefined, {
numeric: true,
sensitivity: 'base'
});
}
export function sortPorts(a, b) {