Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e72dbb7621 |
@@ -0,0 +1,30 @@
|
||||
version: 2
|
||||
|
||||
updates:
|
||||
- package-ecosystem: gomod
|
||||
directory: "/backend"
|
||||
schedule:
|
||||
interval: daily
|
||||
open-pull-requests-limit: 10
|
||||
commit-message:
|
||||
prefix: go-dep
|
||||
ignore:
|
||||
- dependency-name: "*"
|
||||
update-types: ["version-update:semver-major"]
|
||||
- package-ecosystem: npm
|
||||
directory: "/frontend"
|
||||
schedule:
|
||||
interval: daily
|
||||
open-pull-requests-limit: 10
|
||||
commit-message:
|
||||
prefix: npm-dep
|
||||
ignore:
|
||||
- dependency-name: "*"
|
||||
update-types: ["version-update:semver-major"]
|
||||
- package-ecosystem: github-actions
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
open-pull-requests-limit: 10
|
||||
commit-message:
|
||||
prefix: gh-action
|
||||
@@ -10,7 +10,7 @@ jobs:
|
||||
codeberg:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: pixta-dev/repository-mirroring-action@v1
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
name: dependabot automerge
|
||||
on:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
dependabot:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.actor == 'dependabot[bot]' }}
|
||||
steps:
|
||||
- name: Dependabot metadata
|
||||
id: metadata
|
||||
uses: dependabot/fetch-metadata@v2
|
||||
with:
|
||||
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
- name: Enable auto-merge for Dependabot PRs
|
||||
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}} || ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}}
|
||||
run: gh pr merge --auto --rebase "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||
@@ -25,9 +25,9 @@ jobs:
|
||||
needs: check-runner
|
||||
runs-on: ${{ needs.check-runner.outputs.runner-label }}
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v6
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: "./backend/go.mod"
|
||||
cache-dependency-path: "./backend/go.sum"
|
||||
|
||||
@@ -15,9 +15,7 @@ jobs:
|
||||
- name: Set runner
|
||||
id: set-runner
|
||||
run: |
|
||||
runners=$(curl -s -H "Accept: application/vnd.github+json" \
|
||||
-H "Authorization: token ${{ secrets.REPO_ACCESS_TOKEN }}" \
|
||||
"https://api.github.com/repos/${{ github.repository }}/actions/runners")
|
||||
runners=$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ secrets.REPO_ACCESS_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/actions/runners")
|
||||
available=$(echo "$runners" | jq '.runners[] | select(.status == "online" and .busy == false and .labels[] .name == "self-hosted")')
|
||||
if [ -n "$available" ]; then
|
||||
echo "runner-label=self-hosted" >> "$GITHUB_OUTPUT"
|
||||
@@ -25,87 +23,41 @@ jobs:
|
||||
echo "runner-label=ubuntu-latest" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
frontend:
|
||||
goreleaser:
|
||||
needs: check-runner
|
||||
runs-on: ${{ needs.check-runner.outputs.runner-label }}
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- uses: pnpm/action-setup@v6
|
||||
with:
|
||||
version: latest
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: latest
|
||||
cache: pnpm
|
||||
cache-dependency-path: frontend/pnpm-lock.yaml
|
||||
|
||||
- name: Cache frontend build
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
frontend/node_modules
|
||||
frontend/.svelte-kit
|
||||
key: ${{ runner.os }}-pnpm-${{ hashFiles('frontend/pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pnpm-
|
||||
|
||||
- name: Build frontend
|
||||
run: |
|
||||
pnpm --prefix=./frontend install --frozen-lockfile --prefer-offline
|
||||
PUBLIC_VERSION=${GITHUB_REF##*/} pnpm --prefix=./frontend run build
|
||||
tar -czf frontend-dist.tar.gz -C frontend/build .
|
||||
|
||||
- name: Upload frontend artifact
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: frontend-dist
|
||||
path: frontend-dist.tar.gz
|
||||
|
||||
goreleaser:
|
||||
needs:
|
||||
- check-runner
|
||||
- frontend
|
||||
runs-on: ${{ needs.check-runner.outputs.runner-label }}
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
# pull code
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Download frontend artifact
|
||||
uses: actions/download-artifact@v8
|
||||
# install latest node
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
name: frontend-dist
|
||||
node-version: latest
|
||||
|
||||
- name: Extract frontend into backend
|
||||
# build sveltekit frontend
|
||||
- name: Build frontend
|
||||
run: |
|
||||
mkdir -p backend/pb_public
|
||||
tar -xzf frontend-dist.tar.gz -C backend/pb_public
|
||||
npm i -g pnpm
|
||||
pnpm --prefix=./frontend i
|
||||
PUBLIC_VERSION=${GITHUB_REF##*/} pnpm --prefix=./frontend run build
|
||||
cp -r ./frontend/build/* ./backend/pb_public/
|
||||
git reset --hard
|
||||
git clean -fd
|
||||
|
||||
# setup go
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v6
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: backend/go.mod
|
||||
cache-dependency-path: backend/go.sum
|
||||
|
||||
- name: Cache Go build
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~/.cache/go-build
|
||||
~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('backend/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
go-version-file: "./backend/go.mod"
|
||||
cache-dependency-path: "./backend/go.sum"
|
||||
|
||||
# build
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v7
|
||||
uses: goreleaser/goreleaser-action@v6
|
||||
with:
|
||||
distribution: goreleaser
|
||||
version: "~> v2"
|
||||
@@ -115,32 +67,20 @@ jobs:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
AUR_KEY: ${{ secrets.AUR_KEY }}
|
||||
|
||||
- name: Upload backend artifact
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: backend-dist
|
||||
path: backend/dist
|
||||
|
||||
docker:
|
||||
needs:
|
||||
- check-runner
|
||||
- frontend
|
||||
- goreleaser
|
||||
- check-runner
|
||||
runs-on: ${{ needs.check-runner.outputs.runner-label }}
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Download backend artifact
|
||||
uses: actions/download-artifact@v8
|
||||
with:
|
||||
name: backend-dist
|
||||
path: backend/dist
|
||||
# pull code
|
||||
- name: Check Out Repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# image tags
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v6
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
ghcr.io/seriousm4x/UpSnap
|
||||
@@ -151,35 +91,39 @@ jobs:
|
||||
type=semver,pattern={{major}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
|
||||
# qemu
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v4
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
# docker buildx
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to GHCR
|
||||
uses: docker/login-action@v4
|
||||
# ghcr.io login
|
||||
- name: Log in to the Container registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v4
|
||||
# ducker hub login
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ vars.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
# build and push
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v7
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
|
||||
builder: ${{ steps.buildx.outputs.name }}
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
build-args: |
|
||||
VERSION=${{ github.ref_name }}
|
||||
VERSION=${{github.ref_name}}
|
||||
|
||||
@@ -60,7 +60,6 @@ Temporary Items
|
||||
### Node ###
|
||||
# Logs
|
||||
logs
|
||||
!frontend/src/routes/logs/
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
@@ -235,5 +234,3 @@ backend/pb_public/*
|
||||
|
||||
dist/
|
||||
vite.config.js.timestamp*
|
||||
|
||||
frontend/src/lib/paraglide
|
||||
|
||||
@@ -11,22 +11,14 @@ RUN wget https://github.com/seriousm4x/UpSnap/releases/download/${VERSION}/UpSna
|
||||
chmod +x upsnap &&\
|
||||
apk update &&\
|
||||
apk add --no-cache libcap &&\
|
||||
setcap 'cap_net_raw=+p' ./upsnap
|
||||
setcap 'cap_net_raw=+ep' ./upsnap
|
||||
|
||||
FROM alpine:3
|
||||
ARG UPSNAP_HTTP_LISTEN=0.0.0.0:8090
|
||||
ENV UPSNAP_HTTP_LISTEN=${UPSNAP_HTTP_LISTEN}
|
||||
RUN apk update &&\
|
||||
apk add --no-cache tzdata ca-certificates nmap samba samba-common-tools openssh sshpass curl &&\
|
||||
rm -rf /var/cache/apk/*
|
||||
RUN addgroup -g 1000 upsnap &&\
|
||||
adduser -G upsnap -D -H -u 1000 upsnap -s /sbin/nologin
|
||||
WORKDIR /app
|
||||
COPY --from=downloader /app/upsnap upsnap
|
||||
LABEL org.opencontainers.image.source="https://github.com/seriousm4x/UpSnap" \
|
||||
org.opencontainers.image.url="https://github.com/seriousm4x/UpSnap" \
|
||||
org.opencontainers.image.licenses="MIT"
|
||||
HEALTHCHECK --interval=10s \
|
||||
CMD curl -fs "http://${UPSNAP_HTTP_LISTEN}/api/health" || exit 1
|
||||
CMD ["serve","--http","${UPSNAP_HTTP_LISTEN}"]
|
||||
ENTRYPOINT ["/app/upsnap"]
|
||||
CMD curl -fs "http://localhost:8090/api/health" || exit 1
|
||||
ENTRYPOINT ["./upsnap", "serve", "--http=0.0.0.0:8090"]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM node:bookworm AS node
|
||||
FROM node:alpine AS node
|
||||
WORKDIR /app
|
||||
COPY frontend/ .
|
||||
RUN npm i -g pnpm &&\
|
||||
@@ -17,13 +17,11 @@ RUN go build -o upsnap main.go &&\
|
||||
setcap 'cap_net_raw=+ep' ./upsnap
|
||||
|
||||
FROM alpine:3
|
||||
ARG UPSNAP_HTTP_LISTEN=0.0.0.0:8090
|
||||
ENV UPSNAP_HTTP_LISTEN=${UPSNAP_HTTP_LISTEN}
|
||||
RUN apk update &&\
|
||||
apk add --no-cache tzdata ca-certificates nmap samba samba-common-tools openssh sshpass curl &&\
|
||||
rm -rf /var/cache/apk/*
|
||||
WORKDIR /app
|
||||
COPY --from=go /app/upsnap upsnap
|
||||
HEALTHCHECK --interval=10s \
|
||||
CMD curl -fs "http://${UPSNAP_HTTP_LISTEN}/api/health" || exit 1
|
||||
ENTRYPOINT ["sh", "-c", "./upsnap serve --http ${UPSNAP_HTTP_LISTEN}"]
|
||||
CMD curl -fs "http://localhost:8090/api/health" || exit 1
|
||||
ENTRYPOINT ["./upsnap", "serve", "--http=0.0.0.0:8090"]
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<p>A simple wake on lan web app written with SvelteKit, Go and PocketBase.</p>
|
||||
<div>
|
||||
<a target="_blank" href="https://github.com/seriousm4x/upsnap"><img src="https://img.shields.io/github/stars/seriousm4x/UpSnap?style=flat&label=Stars" /></a>
|
||||
<a target="_blank" href="https://github.com/seriousm4x/UpSnap/pkgs/container/upsnap"><img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fipitio%2Fbackage%2Findex%2Fseriousm4x%2FUpSnap%2Fupsnap.json&query=downloads&label=ghcr.io%20pulls" /></a>
|
||||
<a target="_blank" href="https://hub.docker.com/r/seriousm4x/upsnap"><img src="https://img.shields.io/docker/pulls/seriousm4x/upsnap?label=docker%20hub%20pulls" /></a>
|
||||
<a target="_blank" href="https://github.com/seriousm4x/UpSnap/releases"><img src="https://img.shields.io/github/downloads/seriousm4x/upsnap/total?label=binary%20downloads" /></a>
|
||||
</div>
|
||||
@@ -24,61 +25,83 @@
|
||||
- ⏰ Timed Events via Cron for Automation
|
||||
- 🔌 Ping Any Port You Choose
|
||||
- 🔍 Discover Devices with Network Scanning (nmap required)
|
||||
- 📌 Optional IP Address Tracking per Device via periodic ARP scan (nmap required, no extra privileges beyond network scanning)
|
||||
- 📡 Support using a Fully Qualified Domain Name for a device (refer to the Wiki: [Use FQDN](https://github.com/seriousm4x/UpSnap/wiki/Use-FQDN))
|
||||
- ❎️ Shutdown Devices with a Custom Command
|
||||
- 👤 Secured User Management
|
||||
- 📋 Superuser Logs Page
|
||||
- 🌐 i18n support for [these](/frontend/translations) languages
|
||||
- 🎨 35 Themes
|
||||
- 🌐 i18n support for [these](https://github.com/seriousm4x/UpSnap/tree/master/frontend/src/lib/i18n) languages
|
||||
- 🎨 29 Themes
|
||||
- 🐳 [Docker images](https://github.com/seriousm4x/UpSnap/pkgs/container/upsnap) for amd64, arm64, arm/v7, arm/v6
|
||||
- 🏠 Self-Hostable
|
||||
|
||||
## 📸 Screenshots
|
||||
|
||||
| Silk | Dim |
|
||||
| ---------------------------------- | --------------------------------- |
|
||||
|  |  |
|
||||
|  |  |
|
||||
|  |  |
|
||||
|  |  |
|
||||
|  |  |
|
||||
|  |  |
|
||||
| Dark | Light |
|
||||
| --------------------------------- | ---------------------------------- |
|
||||
|  |  |
|
||||
|  |  |
|
||||
|  |  |
|
||||
|  |  |
|
||||
|  |  |
|
||||
|  |  |
|
||||
|
||||
## 🐧 Install from the [AUR](https://aur.archlinux.org/packages/upsnap-bin)
|
||||
|
||||
```bash
|
||||
yay -Sy upsnap-bin
|
||||
```
|
||||
|
||||
## 🚀 Run the binary
|
||||
|
||||
Just download the latest binary from the [release page](https://github.com/seriousm4x/UpSnap/releases) and run it.
|
||||
|
||||
### Root:
|
||||
|
||||
```bash
|
||||
sudo ./upsnap serve --http=0.0.0.0:8090
|
||||
```
|
||||
|
||||
To run as non-root (Linux only), refer to the Wiki: [Use non-root user](https://github.com/seriousm4x/UpSnap/wiki/Use-non%E2%80%90root-user)
|
||||
### Non-root:
|
||||
|
||||
```bash
|
||||
sudo setcap cap_net_raw=+ep ./upsnap # only once after downloading
|
||||
./upsnap serve --http=0.0.0.0:8090
|
||||
```
|
||||
|
||||
For more options check `./upsnap --help` or visit [PocketBase documentation](https://pocketbase.io/docs).
|
||||
|
||||
## 🐳 Run in Docker
|
||||
If you want to use network discovery, make sure to have `nmap` installed and run UpSnap as root/admin.
|
||||
|
||||
Just pull and run the image: `docker run --network=host seriousm4x/upsnap:latest` or you can use the [docker-compose](docker-compose.yml) example. See the comments in the file for customization.
|
||||
## 🐳 Run in docker
|
||||
|
||||
To run as non-root, refer to the Wiki: [Use non-root user](https://github.com/seriousm4x/UpSnap/wiki/Use-non%E2%80%90root-user)
|
||||
You can use the [docker-compose](docker-compose.yml) example. See the comments in the file for customization.
|
||||
|
||||
Set `UPSNAP_LOG_LEVEL` to `DEBUG`, `INFO`, `WARN`, `ERROR`, or `OFF` to control UpSnap console logs. Default is `INFO`. PocketBase log persistence and retention remain configurable in PocketBase settings. PocketBase's `--dev` mode prints all logs regardless of this setting.
|
||||
### Non-root docker user:
|
||||
|
||||
### Change port (Docker)
|
||||
Create the mount point first:
|
||||
|
||||
```bash
|
||||
mkdir data
|
||||
```
|
||||
|
||||
Then add `user: 1000:1000` to the docker-compose file (or whatever your $UID:$GID is).
|
||||
|
||||
### Change port
|
||||
|
||||
If you want to change the port from 8090 to something else, change the following (5000 in this case):
|
||||
|
||||
```yml
|
||||
environment:
|
||||
- UPSNAP_HTTP_LISTEN=0.0.0.0:5000
|
||||
entrypoint: /bin/sh -c "./upsnap serve --http 0.0.0.0:5000"
|
||||
healthcheck:
|
||||
test: curl -fs "http://localhost:5000/api/health" || exit 1
|
||||
```
|
||||
|
||||
## ❎️ Shutting Down Devices
|
||||
### Install additional packages for shutdown cmd
|
||||
|
||||
To shutdown devices, refer to the Wiki: [How to use shutdowns](https://github.com/seriousm4x/UpSnap/wiki/How-to-use-shutdowns)
|
||||
```yml
|
||||
entrypoint: /bin/sh -c "apk update && apk add --no-cache <YOUR_PACKAGE> && rm -rf /var/cache/apk/* && ./upsnap serve --http 0.0.0.0:8090"
|
||||
```
|
||||
|
||||
## Reverse Proxy
|
||||
You can search for your needed package [here](https://pkgs.alpinelinux.org/packages).
|
||||
|
||||
### Reverse Proxy
|
||||
|
||||
**Caddy example**
|
||||
|
||||
@@ -88,46 +111,6 @@ upsnap.example.com {
|
||||
}
|
||||
```
|
||||
|
||||
## Run in sub path
|
||||
|
||||
You can run UpSnap on a different path than `/`, e.g. `/upsnap-sub-path/`. To do this in caddy, set the following:
|
||||
|
||||
```
|
||||
http://localhost:8091 {
|
||||
handle /upsnap-sub-path/* {
|
||||
uri strip_prefix /upsnap-sub-path
|
||||
reverse_proxy localhost:8090
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Or nginx:
|
||||
|
||||
```
|
||||
http {
|
||||
server {
|
||||
listen 8091;
|
||||
server_name localhost;
|
||||
location /upsnap-sub-path/ {
|
||||
proxy_pass http://localhost:8090/;
|
||||
proxy_redirect off;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Paths must end with a trailing `/`.
|
||||
|
||||
## 🐧 Install from the [AUR](https://aur.archlinux.org/packages/upsnap-bin)
|
||||
|
||||
```bash
|
||||
yay -Sy upsnap-bin
|
||||
```
|
||||
|
||||
## 🔒 User permissions
|
||||
|
||||
UpSnap offers unique access for each user, per device. While admins have all permissions, they can assign specific rights to users such as displaying/hiding a device, accessing device editing, deleting and powering devices on/off. See the last screenshot in the [📸 Screenshots section](#-screenshots).
|
||||
@@ -136,36 +119,23 @@ UpSnap offers unique access for each user, per device. While admins have all per
|
||||
|
||||
Although UpSnap has user authorisation, it is **not recommended to expose it to the open web** and make it accessible by everyone!
|
||||
|
||||
**Reason**: The shutdown device command is basically a command piped to #sh (possibly as root user). If anyone gains unauthorized access and can abuse this API route in any way, the attacker has access to a (root) shell on your local network.
|
||||
**Reason**: The shutdown device command is basically a command piped to #sh (root if you run docker). If anyone gains unauthorized access and can abuse this api route in any way, the attacker has access to a (root) shell on your local network.
|
||||
|
||||
**Recommended**: If you need access from outside your network, please use a VPN. Wireguard or OpenVPN is your way to go.
|
||||
**Recommended**: If you need access from outside your network, please use a vpn. Wireguard or OpenVPN is your way to go.
|
||||
|
||||
## 🌐 Help translating
|
||||
|
||||
UpSnap is available in the following languages so far:
|
||||
|
||||
- 🇸🇦 **Arabic (Saudi Arabia)** (ar-SA)
|
||||
- 🇧🇬 **Bulgarian (Bulgaria)** (bg-BG)
|
||||
- 🇨🇿 **Czech (Czech republic)** (cs-CZ)
|
||||
- 🇩🇪 **German (Germany)** (de-DE)
|
||||
- 🇬🇷 **Greek (Greece)** (el-GR)
|
||||
- 🇺🇸 **English (United States)** (en-US)
|
||||
- 🇪🇸 **Spanish (Spain)** (es-ES)
|
||||
- 🇫🇷 **French (France)** (fr-FR)
|
||||
- 🇮🇳 **Hindi (India)** (hi-IN)
|
||||
- 🇮🇩 **Bahasa (Indonesia)** (id-ID)
|
||||
- 🇮🇹 **Italian (Italy)** (it-IT)
|
||||
- 🇯🇵 **Japanese (Japan)** (ja-JP)
|
||||
- 🇰🇷 **Korean (Republic of Korea)** (ko-KR)
|
||||
- 🇳🇴 **Norwegian (Norway)** (nb-NO)
|
||||
- 🇳🇱 **Dutch (Netherlands)** (nl-NL)
|
||||
- 🇵🇱 **Polish (Poland)** (pl-PL)
|
||||
- 🇧🇷 **Portuguese (Brazil)** (pt-BR)
|
||||
- 🇵🇹 **Portuguese (Portugal)** (pt-PT)
|
||||
- 🇷🇺 **Russian (Russia)** (ru-RU)
|
||||
- 🇺🇦 **Ukrainian (Ukrain)** (uk-UA)
|
||||
- 🇻🇳 **Vietnamese (Vietnam)** (vi-VN)
|
||||
- 🇨🇳 **Chinese (China)** (zh-CN)
|
||||
- 🇺🇸 **English** (en-US)
|
||||
- 🇩🇪 **German** (de-DE)
|
||||
- 🇪🇸 **Spanish** (es-ES)
|
||||
- 🇫🇷 **French** (fr-FR)
|
||||
- 🇮🇹 **Italian** (it-IT)
|
||||
- 🇯🇵 **Japanese** (ja-JP)
|
||||
- 🇳🇱 **Dutch** (nl-NL)
|
||||
- 🇵🇹 **Portuguese** (pt-PT)
|
||||
- 🇨🇳 **Chinese** (zh-CN)
|
||||
- 🇹🇼 **Chinese (Taiwan)** (zh-TW)
|
||||
|
||||
**If you want to contribute and help translating, check the wiki: [How to add languages](https://github.com/seriousm4x/UpSnap/wiki/How-to-add-languages)**
|
||||
@@ -176,7 +146,7 @@ Fork this branch and clone it.
|
||||
|
||||
1. Start backend
|
||||
|
||||
```bash
|
||||
```sh
|
||||
cd backend
|
||||
go mod tidy
|
||||
go run main.go serve
|
||||
@@ -184,10 +154,14 @@ go run main.go serve
|
||||
|
||||
2. Start frontend
|
||||
|
||||
```bash
|
||||
```sh
|
||||
cd frontend
|
||||
pnpm i
|
||||
pnpm run dev
|
||||
```
|
||||
|
||||
Open up [http://localhost:5173/](http://localhost:5173/), create an admin user and add some devices.
|
||||
|
||||
## 🌟 Star History
|
||||
|
||||
[](https://star-history.com/#seriousm4x/UpSnap&Date)
|
||||
|
||||
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 83 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 124 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 212 KiB After Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 206 KiB After Width: | Height: | Size: 60 KiB |
|
Before Width: | Height: | Size: 212 KiB After Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 65 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 32 KiB |
@@ -20,7 +20,6 @@ builds:
|
||||
- amd64
|
||||
- arm64
|
||||
- arm
|
||||
- riscv64
|
||||
goarm:
|
||||
- "6"
|
||||
- "7"
|
||||
@@ -29,10 +28,8 @@ builds:
|
||||
goarch: arm
|
||||
- goos: darwin
|
||||
goarch: arm
|
||||
- goos: freebsd
|
||||
goarch: arm
|
||||
archives:
|
||||
- formats: ["zip"]
|
||||
- formats: [ 'zip' ]
|
||||
checksum:
|
||||
name_template: "checksums.txt"
|
||||
snapshot:
|
||||
@@ -61,20 +58,20 @@ changelog:
|
||||
git:
|
||||
ignore_tags:
|
||||
- "{{ if not .Prerelease}}*beta*{{ end }}"
|
||||
# aurs:
|
||||
# - name: upsnap-bin
|
||||
# homepage: https://github.com/seriousm4x/UpSnap
|
||||
# description: "A simple wake on lan web app written with SvelteKit, Go and PocketBase."
|
||||
# maintainers:
|
||||
# - "SeriousM4x <maxi at quoss dot org>"
|
||||
# license: "MIT"
|
||||
# private_key: "{{ .Env.AUR_KEY }}"
|
||||
# git_url: "ssh://aur@aur.archlinux.org/upsnap-bin.git"
|
||||
# package: |-
|
||||
# install -Dm755 "./upsnap" "${pkgdir}/usr/bin/upsnap"
|
||||
# skip_upload: auto
|
||||
# optdepends:
|
||||
# - "nmap: to scan for network devices"
|
||||
# commit_author:
|
||||
# name: goreleaserbot
|
||||
# email: bot@goreleaser.com
|
||||
aurs:
|
||||
- name: upsnap-bin
|
||||
homepage: https://github.com/seriousm4x/UpSnap
|
||||
description: "A simple wake on lan web app written with SvelteKit, Go and PocketBase."
|
||||
maintainers:
|
||||
- "SeriousM4x <maxi at quoss dot org>"
|
||||
license: "MIT"
|
||||
private_key: "{{ .Env.AUR_KEY }}"
|
||||
git_url: "ssh://aur@aur.archlinux.org/upsnap-bin.git"
|
||||
package: |-
|
||||
install -Dm755 "./upsnap" "${pkgdir}/usr/bin/upsnap"
|
||||
skip_upload: auto
|
||||
optdepends:
|
||||
- "nmap: to scan for network devices"
|
||||
commit_author:
|
||||
name: goreleaserbot
|
||||
email: bot@goreleaser.com
|
||||
|
||||
@@ -1,26 +1,21 @@
|
||||
package cronjobs
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/robfig/cron/v3"
|
||||
"github.com/seriousm4x/upsnap/iptracking"
|
||||
"github.com/seriousm4x/upsnap/logging"
|
||||
"github.com/seriousm4x/upsnap/logger"
|
||||
"github.com/seriousm4x/upsnap/networking"
|
||||
)
|
||||
|
||||
var (
|
||||
PingRunning = false
|
||||
WakeShutdownRunning = false
|
||||
CronPing = cron.New(cron.WithParser(cron.NewParser(
|
||||
cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow,
|
||||
)))
|
||||
CronWakeShutdown = cron.New(cron.WithParser(cron.NewParser(
|
||||
cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow,
|
||||
)))
|
||||
CronPing = cron.New()
|
||||
CronWakeShutdown = cron.New()
|
||||
)
|
||||
|
||||
func SetPingJobs(app core.App) {
|
||||
log := logging.Logger(app)
|
||||
func SetPingJobs(app *pocketbase.PocketBase) {
|
||||
// remove existing jobs
|
||||
for _, job := range CronPing.Entries() {
|
||||
CronPing.Remove(job.ID)
|
||||
@@ -28,8 +23,7 @@ func SetPingJobs(app core.App) {
|
||||
|
||||
settingsPrivateRecords, err := app.FindAllRecords("settings_private")
|
||||
if err != nil {
|
||||
log.Error("Failed to load private settings", "error", err)
|
||||
return
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
|
||||
CronPing.AddFunc(settingsPrivateRecords[0].GetString("interval"), func() {
|
||||
@@ -41,7 +35,7 @@ func SetPingJobs(app core.App) {
|
||||
|
||||
devices, err := app.FindAllRecords("devices")
|
||||
if err != nil {
|
||||
log.Error("Failed to load devices for ping job", "error", err)
|
||||
logger.Error.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -51,7 +45,6 @@ func SetPingJobs(app core.App) {
|
||||
}
|
||||
merr := app.ExpandRecords(devices, []string{"ports"}, expandFetchFunc)
|
||||
if len(merr) > 0 {
|
||||
log.Error("Failed to expand device ports", "errors", merr)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -62,19 +55,13 @@ func SetPingJobs(app core.App) {
|
||||
if status == "pending" {
|
||||
return
|
||||
}
|
||||
isUp, err := networking.PingDevice(d)
|
||||
if err != nil {
|
||||
log.Error("Failed to ping device", "device", d.GetString("name"), "error", err)
|
||||
}
|
||||
if isUp {
|
||||
if networking.PingDevice(d) {
|
||||
if status == "online" {
|
||||
return
|
||||
}
|
||||
d.Set("status", "online")
|
||||
if err := app.Save(d); err != nil {
|
||||
log.Error("Failed to save device status", "device", d.GetString("name"), "error", err)
|
||||
} else {
|
||||
log.Info("Device turned on", "device", d.GetString("name"))
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
}
|
||||
} else {
|
||||
if status == "offline" {
|
||||
@@ -82,9 +69,7 @@ func SetPingJobs(app core.App) {
|
||||
}
|
||||
d.Set("status", "offline")
|
||||
if err := app.Save(d); err != nil {
|
||||
log.Error("Failed to save device status", "device", d.GetString("name"), "error", err)
|
||||
} else {
|
||||
log.Info("Device turned off", "device", d.GetString("name"))
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
}
|
||||
}
|
||||
}(device)
|
||||
@@ -93,50 +78,23 @@ func SetPingJobs(app core.App) {
|
||||
go func(d *core.Record) {
|
||||
ports, err := app.FindRecordsByIds("ports", d.GetStringSlice("ports"))
|
||||
if err != nil {
|
||||
log.Error("Failed to load device ports", "device", d.GetString("name"), "error", err)
|
||||
return
|
||||
}
|
||||
deviceIP, resolveErr := networking.ResolveToIPAddr(d.GetString("ip"))
|
||||
if resolveErr != nil {
|
||||
log.Error("Failed to resolve device IP", "device", d.GetString("name"), "error", resolveErr)
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
for _, port := range ports {
|
||||
isUp := false
|
||||
// No IP found means the device is down.
|
||||
if resolveErr == nil && deviceIP != "" {
|
||||
var checkErr error
|
||||
isUp, checkErr = networking.CheckPort(deviceIP, port.GetString("number"))
|
||||
if checkErr != nil {
|
||||
log.Error("Failed to check port", "device", d.GetString("name"), "port", port.GetString("number"), "error", checkErr)
|
||||
}
|
||||
}
|
||||
isUp := networking.CheckPort(d.GetString("ip"), port.GetString("number"))
|
||||
if isUp != port.GetBool("status") {
|
||||
port.Set("status", isUp)
|
||||
if err := app.Save(port); err != nil {
|
||||
log.Error("Failed to save port status", "device", d.GetString("name"), "port", port.GetString("number"), "error", err)
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}(device)
|
||||
}
|
||||
})
|
||||
|
||||
// update ip addresses of opted-in devices from a periodic arp scan
|
||||
trackIpInterval := settingsPrivateRecords[0].GetString("track_ip_interval")
|
||||
if trackIpInterval != "" {
|
||||
if _, err := CronPing.AddFunc(trackIpInterval, func() {
|
||||
// pause scans if no realtime clients connected and lazy_ping is
|
||||
// turned on; a catch-up sweep runs when the next client connects
|
||||
realtimeClients := len(app.SubscriptionsBroker().Clients())
|
||||
iptracking.PeriodicSweep(app, realtimeClients == 0 && settingsPrivateRecords[0].GetBool("lazy_ping"))
|
||||
}); err != nil {
|
||||
log.Error("Failed to add IP tracking cron job", "error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func SetWakeShutdownJobs(app core.App) {
|
||||
log := logging.Logger(app)
|
||||
func SetWakeShutdownJobs(app *pocketbase.PocketBase) {
|
||||
// remove existing jobs
|
||||
for _, job := range CronWakeShutdown.Entries() {
|
||||
CronWakeShutdown.Remove(job.ID)
|
||||
@@ -144,7 +102,7 @@ func SetWakeShutdownJobs(app core.App) {
|
||||
|
||||
devices, err := app.FindAllRecords("devices")
|
||||
if err != nil {
|
||||
log.Error("Failed to load devices for wake and shutdown jobs", "error", err)
|
||||
logger.Error.Println(err)
|
||||
return
|
||||
}
|
||||
for _, dev := range devices {
|
||||
@@ -155,79 +113,66 @@ func SetWakeShutdownJobs(app core.App) {
|
||||
|
||||
if wake_cron_enabled && wake_cron != "" {
|
||||
_, err := CronWakeShutdown.AddFunc(wake_cron, func() {
|
||||
isOnline := networking.PingDevice(dev)
|
||||
if isOnline {
|
||||
return
|
||||
}
|
||||
d, err := app.FindRecordById("devices", dev.Id)
|
||||
if err != nil {
|
||||
log.Error("Failed to load device for wake job", "device", dev.GetString("name"), "error", err)
|
||||
return
|
||||
}
|
||||
if d.GetString("status") == "pending" {
|
||||
return
|
||||
}
|
||||
isOnline, err := networking.PingDevice(d)
|
||||
if err != nil {
|
||||
log.Error("Failed to ping device before wake", "device", d.GetString("name"), "error", err)
|
||||
return
|
||||
}
|
||||
if isOnline {
|
||||
logger.Error.Println(err)
|
||||
return
|
||||
}
|
||||
d.Set("status", "pending")
|
||||
if err := app.Save(d); err != nil {
|
||||
log.Error("Failed to save pending device status", "device", d.GetString("name"), "error", err)
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
return
|
||||
}
|
||||
if err := networking.WakeDevice(app, d, "cron"); err != nil {
|
||||
log.Error("Wake job failed", "device", d.GetString("name"), "error", err)
|
||||
if err := networking.WakeDevice(d); err != nil {
|
||||
logger.Error.Println(err)
|
||||
d.Set("status", "offline")
|
||||
} else {
|
||||
d.Set("status", "online")
|
||||
}
|
||||
if err := app.Save(d); err != nil {
|
||||
log.Error("Failed to save device status after wake", "device", d.GetString("name"), "error", err)
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
log.Error("Failed to add wake cron job", "device", dev.GetString("name"), "error", err)
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
if shutdown_cron_enabled && shutdown_cron != "" {
|
||||
_, err := CronWakeShutdown.AddFunc(shutdown_cron, func() {
|
||||
d, err := app.FindRecordById("devices", dev.Id)
|
||||
if err != nil {
|
||||
log.Error("Failed to load device for shutdown job", "device", dev.GetString("name"), "error", err)
|
||||
return
|
||||
}
|
||||
if d.GetString("status") == "pending" {
|
||||
return
|
||||
}
|
||||
isOnline, err := networking.PingDevice(d)
|
||||
if err != nil {
|
||||
log.Error("Failed to ping device before shutdown", "device", d.GetString("name"), "error", err)
|
||||
return
|
||||
}
|
||||
isOnline := networking.PingDevice(dev)
|
||||
if !isOnline {
|
||||
return
|
||||
}
|
||||
// The status can be stale when lazy ping marks devices offline after
|
||||
// the last client disconnects. The reachability check above is the
|
||||
// authoritative signal for whether a shutdown command may run.
|
||||
d, err := app.FindRecordById("devices", dev.Id)
|
||||
if err != nil {
|
||||
logger.Error.Println(err)
|
||||
return
|
||||
}
|
||||
status := d.GetString("status")
|
||||
if status != "online" {
|
||||
return
|
||||
}
|
||||
d.Set("status", "pending")
|
||||
if err := app.Save(d); err != nil {
|
||||
log.Error("Failed to save pending device status", "device", d.GetString("name"), "error", err)
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
}
|
||||
if err := networking.ShutdownDevice(app, d, "cron"); err != nil {
|
||||
log.Error("Shutdown job failed", "device", d.GetString("name"), "error", err)
|
||||
if err := networking.ShutdownDevice(d); err != nil {
|
||||
logger.Error.Println(err)
|
||||
d.Set("status", "online")
|
||||
} else {
|
||||
d.Set("status", "offline")
|
||||
}
|
||||
if err := app.Save(d); err != nil {
|
||||
log.Error("Failed to save device status after shutdown", "device", d.GetString("name"), "error", err)
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
log.Error("Failed to add shutdown cron job", "device", dev.GetString("name"), "error", err)
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,10 +184,11 @@ func StartWakeShutdown() {
|
||||
|
||||
}
|
||||
|
||||
func StopWakeShutdown(app core.App) {
|
||||
func StopWakeShutdown() {
|
||||
if WakeShutdownRunning {
|
||||
logging.Logger(app).Info("Stopping wake and shutdown cron jobs")
|
||||
CronWakeShutdown.Stop()
|
||||
logger.Info.Println("Stopping wake/shutdown cronjob")
|
||||
ctx := CronWakeShutdown.Stop()
|
||||
<-ctx.Done()
|
||||
}
|
||||
WakeShutdownRunning = false
|
||||
}
|
||||
@@ -252,15 +198,16 @@ func StartPing() {
|
||||
go CronPing.Run()
|
||||
}
|
||||
|
||||
func StopPing(app core.App) {
|
||||
func StopPing() {
|
||||
if PingRunning {
|
||||
logging.Logger(app).Info("Stopping ping cron jobs")
|
||||
CronPing.Stop()
|
||||
logger.Info.Println("Stopping wake/shutdown cronjob")
|
||||
ctx := CronPing.Stop()
|
||||
<-ctx.Done()
|
||||
}
|
||||
PingRunning = false
|
||||
}
|
||||
|
||||
func StopAll(app core.App) {
|
||||
StopPing(app)
|
||||
StopWakeShutdown(app)
|
||||
func StopAll() {
|
||||
StopPing()
|
||||
StopWakeShutdown()
|
||||
}
|
||||
|
||||
@@ -1,53 +1,83 @@
|
||||
module github.com/seriousm4x/upsnap
|
||||
|
||||
go 1.27
|
||||
go 1.23.4
|
||||
|
||||
require (
|
||||
ganigeorgiev.com/pocketbase/dbx v1.13.0
|
||||
ganigeorgiev.com/pocketbase/pocketbase v0.41.1
|
||||
github.com/godbus/dbus/v5 v5.2.2
|
||||
github.com/holoplot/go-avahi v1.0.1
|
||||
github.com/mdlayher/wol v0.0.0-20220221231636-b763a792253a
|
||||
github.com/prometheus-community/pro-bing v0.9.1
|
||||
github.com/pocketbase/dbx v1.11.0
|
||||
github.com/pocketbase/pocketbase v0.24.4
|
||||
github.com/prometheus-community/pro-bing v0.6.0
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
golang.org/x/net v0.62.0
|
||||
golang.org/x/sys v0.49.0
|
||||
kernel.org/pub/linux/libs/security/libcap/cap v1.2.78
|
||||
golang.org/x/sys v0.29.0
|
||||
)
|
||||
|
||||
require (
|
||||
ganigeorgiev.com/fexpr v0.7.0 // indirect
|
||||
ganigeorgiev.com/pocketbase/ozzo-validation/v4 v4.4.1 // indirect
|
||||
github.com/AlecAivazis/survey/v2 v2.3.7 // indirect
|
||||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2 v1.33.0 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/config v1.29.0 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.53 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.24 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.51 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.28 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.28 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.28 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.5.1 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.9 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.9 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.73.1 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.24.10 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.9 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.33.8 // indirect
|
||||
github.com/aws/smithy-go v1.22.1 // indirect
|
||||
github.com/disintegration/imaging v1.6.2 // indirect
|
||||
github.com/domodwyer/mailyak/v3 v3.6.2 // indirect
|
||||
github.com/dustin/go-humanize v1.1.0 // indirect
|
||||
github.com/fatih/color v1.19.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.10.1 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.15 // indirect
|
||||
github.com/go-sql-driver/mysql v1.9.3 // indirect
|
||||
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/fatih/color v1.18.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
|
||||
github.com/ganigeorgiev/fexpr v0.4.1 // indirect
|
||||
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 // indirect
|
||||
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.16 // indirect
|
||||
github.com/mattn/go-isatty v0.0.24 // indirect
|
||||
github.com/josharian/native v1.1.0 // indirect
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118 // indirect
|
||||
github.com/mdlayher/packet v1.2.0 // indirect
|
||||
github.com/mdlayher/socket v0.7.0 // indirect
|
||||
github.com/ncruces/go-strftime v1.1.0 // indirect
|
||||
github.com/mdlayher/packet v1.1.2 // indirect
|
||||
github.com/mdlayher/socket v0.5.1 // indirect
|
||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/spf13/cast v1.10.0 // indirect
|
||||
github.com/spf13/cobra v1.10.2 // indirect
|
||||
github.com/spf13/pflag v1.0.10 // indirect
|
||||
github.com/stretchr/testify v1.11.1 // indirect
|
||||
golang.org/x/crypto v0.58.0 // indirect
|
||||
golang.org/x/image v0.47.0 // indirect
|
||||
golang.org/x/oauth2 v0.37.0 // indirect
|
||||
golang.org/x/sync v0.24.0 // indirect
|
||||
golang.org/x/text v0.43.0 // indirect
|
||||
kernel.org/pub/linux/libs/security/libcap/psx v1.2.78 // indirect
|
||||
modernc.org/libc v1.77.1 // indirect
|
||||
github.com/spf13/cast v1.7.1 // indirect
|
||||
github.com/spf13/cobra v1.8.1 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
gocloud.dev v0.40.0 // indirect
|
||||
golang.org/x/crypto v0.32.0 // indirect
|
||||
golang.org/x/image v0.23.0 // indirect
|
||||
golang.org/x/net v0.34.0 // indirect
|
||||
golang.org/x/oauth2 v0.25.0 // indirect
|
||||
golang.org/x/sync v0.10.0 // indirect
|
||||
golang.org/x/term v0.28.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
|
||||
google.golang.org/api v0.217.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
|
||||
google.golang.org/grpc v1.69.4 // indirect
|
||||
google.golang.org/protobuf v1.36.3 // indirect
|
||||
modernc.org/gc/v3 v3.0.0-20250105121824-520be1a3aee6 // indirect
|
||||
modernc.org/libc v1.55.3 // indirect
|
||||
modernc.org/mathutil v1.7.1 // indirect
|
||||
modernc.org/memory v1.12.1 // indirect
|
||||
modernc.org/sqlite v1.60.1 // indirect
|
||||
modernc.org/memory v1.8.2 // indirect
|
||||
modernc.org/sqlite v1.34.4 // indirect
|
||||
modernc.org/strutil v1.2.1 // indirect
|
||||
modernc.org/token v1.1.0 // indirect
|
||||
)
|
||||
|
||||
@@ -1,17 +1,72 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.115.0 h1:CnFSK6Xo3lDYRoBKEcAtia6VSC837/ZkJuRduSFnr14=
|
||||
cloud.google.com/go v0.115.0/go.mod h1:8jIM5vVgoAEoiVxQ/O4BFTfHqulPZgs/ufEzMcFMdWU=
|
||||
cloud.google.com/go/auth v0.14.0 h1:A5C4dKV/Spdvxcl0ggWwWEzzP7AZMJSEIgrkngwhGYM=
|
||||
cloud.google.com/go/auth v0.14.0/go.mod h1:CYsoRL1PdiDuqeQpZE0bP2pnPrGqFcOkI0nldEQis+A=
|
||||
cloud.google.com/go/auth/oauth2adapt v0.2.7 h1:/Lc7xODdqcEw8IrZ9SvwnlLX6j9FHQM74z6cBk9Rw6M=
|
||||
cloud.google.com/go/auth/oauth2adapt v0.2.7/go.mod h1:NTbTTzfvPl1Y3V1nPpOgl2w6d/FjO7NNUQaWSox6ZMc=
|
||||
cloud.google.com/go/compute/metadata v0.6.0 h1:A6hENjEsCDtC1k8byVsgwvVcioamEHvZ4j01OwKxG9I=
|
||||
cloud.google.com/go/compute/metadata v0.6.0/go.mod h1:FjyFAW1MW0C203CEOMDTu3Dk1FlqW3Rga40jzHL4hfg=
|
||||
cloud.google.com/go/iam v1.1.13 h1:7zWBXG9ERbMLrzQBRhFliAV+kjcRToDTgQT3CTwYyv4=
|
||||
cloud.google.com/go/iam v1.1.13/go.mod h1:K8mY0uSXwEXS30KrnVb+j54LB/ntfZu1dr+4zFMNbus=
|
||||
cloud.google.com/go/storage v1.43.0 h1:CcxnSohZwizt4LCzQHWvBf1/kvtHUn7gk9QERXPyXFs=
|
||||
cloud.google.com/go/storage v1.43.0/go.mod h1:ajvxEa7WmZS1PxvKRq4bq0tFT3vMd502JwstCcYv0Q0=
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
ganigeorgiev.com/fexpr v0.7.0 h1:Os5bP9dU13UNo5qDTsTPTTkodLM96kO52WIEmMmCt30=
|
||||
ganigeorgiev.com/fexpr v0.7.0/go.mod h1:XrG5iYw+AGq55zq2+QY1zQvO+ovbEca08u7q0hucPdY=
|
||||
ganigeorgiev.com/pocketbase/dbx v1.13.0 h1:t8S5CaMv93tEOqaOToFaVQ994zldshdhIrVHKmxRjwc=
|
||||
ganigeorgiev.com/pocketbase/dbx v1.13.0/go.mod h1:QefEiWbbE/YoSipLGg33FbNc/GAX/2f3ymz02j2MGKo=
|
||||
ganigeorgiev.com/pocketbase/ozzo-validation/v4 v4.4.1 h1:teL3Lw7HCGZRdIQdqE/gV5DueFaN5Wj+/r4Ewg3M2WA=
|
||||
ganigeorgiev.com/pocketbase/ozzo-validation/v4 v4.4.1/go.mod h1:oV1SPPkS3PlKYYj+r9YDs48ooAWgC736cuFanXDXxbM=
|
||||
ganigeorgiev.com/pocketbase/pocketbase v0.41.1 h1:qIDj5ZE8ysev7LJNcLR4eeYICme5hDF/Ry3bQ9nOcTA=
|
||||
ganigeorgiev.com/pocketbase/pocketbase v0.41.1/go.mod h1:PBkQKVnCfL7Hi9MnXY9bJDME/sfEEbZ6VwAb+8xXQXE=
|
||||
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
|
||||
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
|
||||
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
|
||||
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg=
|
||||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
|
||||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
|
||||
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
|
||||
github.com/aws/aws-sdk-go-v2 v1.33.0 h1:Evgm4DI9imD81V0WwD+TN4DCwjUMdc94TrduMLbgZJs=
|
||||
github.com/aws/aws-sdk-go-v2 v1.33.0/go.mod h1:P5WJBrYqqbWVaOxgH0X/FYYD47/nooaPOZPlQdmiN2U=
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 h1:lL7IfaFzngfx0ZwUGOZdsFFnQ5uLvR0hWqqhyE7Q9M8=
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7/go.mod h1:QraP0UcVlQJsmHfioCrveWOC1nbiWUl3ej08h4mXWoc=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.29.0 h1:Vk/u4jof33or1qAQLdofpjKV7mQQT7DcUpnYx8kdmxY=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.29.0/go.mod h1:iXAZK3Gxvpq3tA+B9WaDYpZis7M8KFgdrDPMmHrgbJM=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.53 h1:lwrVhiEDW5yXsuVKlFVUnR2R50zt2DklhOyeLETqDuE=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.53/go.mod h1:CkqM1bIw/xjEpBMhBnvqUXYZbpCFuj6dnCAyDk2AtAY=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.24 h1:5grmdTdMsovn9kPZPI23Hhvp0ZyNm5cRO+IZFIYiAfw=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.24/go.mod h1:zqi7TVKTswH3Ozq28PkmBmgzG1tona7mo9G2IJg4Cis=
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.51 h1:Q0FNHs6JTGuoBWNQycD5LRSf+/WVHWEl+FwJ0tEDZUE=
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.51/go.mod h1:B9sW5/AD5bStKdTyUdz1xWRKOwnyUwJ4eJ4olQBtZo0=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.28 h1:igORFSiH3bfq4lxKFkTSYDhJEUCYo6C8VKiWJjYwQuQ=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.28/go.mod h1:3So8EA/aAYm36L7XIvCVwLa0s5N0P7o2b1oqnx/2R4g=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.28 h1:1mOW9zAUMhTSrMDssEHS/ajx8JcAj/IcftzcmNlmVLI=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.28/go.mod h1:kGlXVIWDfvt2Ox5zEaNglmq0hXPHgQFNMix33Tw22jA=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc=
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.28 h1:7kpeALOUeThs2kEjlAxlADAVfxKmkYAedlpZ3kdoSJ4=
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.28/go.mod h1:pyaOYEdp1MJWgtXLy6q80r3DhsVdOIOZNB9hdTcJIvI=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 h1:iXtILhvDxB6kPvEXgsDhGaZCSC6LQET5ZHSdJozeI0Y=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1/go.mod h1:9nu0fVANtYiAePIBh2/pFUSwtJ402hLnp854CNoDOeE=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.5.1 h1:mJ9FRktB8v1Ihpqwfk0AWvYEd0FgQtLsshc2Qb2TVc8=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.5.1/go.mod h1:dIW8puxSbYLSPv/ju0d9A3CpwXdtqvJtYKDMVmPLOWE=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.9 h1:TQmKDyETFGiXVhZfQ/I0cCFziqqX58pi4tKJGYGFSz0=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.9/go.mod h1:HVLPK2iHQBUx7HfZeOQSEu3v2ubZaAY2YPbAm5/WUyY=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.9 h1:2aInXbh02XsbO0KobPGMNXyv2QP73VDKsWPNJARj/+4=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.9/go.mod h1:dgXS1i+HgWnYkPXqNoPIPKeUsUUYHaUbThC90aDnNiE=
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.73.1 h1:OzmyfYGiMCOIAq5pa0KWcaZoA9F8FqajOJevh+hhFdY=
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.73.1/go.mod h1:K+0a0kWDHAUXBH8GvYGS3cQRwIuRjO9bMWUz6vpNCaU=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.24.10 h1:DyZUj3xSw3FR3TXSwDhPhuZkkT14QHBiacdbUVcD0Dg=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.24.10/go.mod h1:Ro744S4fKiCCuZECXgOi760TiYylUM8ZBf6OGiZzJtY=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.9 h1:I1TsPEs34vbpOnR81GIcAq4/3Ud+jRHVGwx6qLQUHLs=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.9/go.mod h1:Fzsj6lZEb8AkTE5S68OhcbBqeWPsR8RnGuKPr8Todl8=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.33.8 h1:pqEJQtlKWvnv3B6VRt60ZmsHy3SotlEBvfUBPB1KVcM=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.33.8/go.mod h1:f6vjfZER1M17Fokn0IzssOTMT2N8ZSq+7jnNF0tArvw=
|
||||
github.com/aws/smithy-go v1.22.1 h1:/HPHZQ0g7f4eUeK6HKglFz8uwVfZKgoI25rb/J+dnro=
|
||||
github.com/aws/smithy-go v1.22.1/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
|
||||
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@@ -19,67 +74,122 @@ github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1
|
||||
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
|
||||
github.com/domodwyer/mailyak/v3 v3.6.2 h1:x3tGMsyFhTCaxp6ycgR0FE/bu5QiNp+hetUuCOBXMn8=
|
||||
github.com/domodwyer/mailyak/v3 v3.6.2/go.mod h1:lOm/u9CyCVWHeaAmHIdF4RiKVxKUT/H5XX10lIKAL6c=
|
||||
github.com/dustin/go-humanize v1.1.0 h1:dbKTrvD0klcbBV/h4AWJdMuZogJACoMlvWIWZ5b2xWg=
|
||||
github.com/dustin/go-humanize v1.1.0/go.mod h1:hc1CvRkJMsgxqjmjMQF3QNRAZBwY8AXBAzKYoSX9sFI=
|
||||
github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w=
|
||||
github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.10.1 h1:b0/UzAf9yR5rhf3RPm9gf3ehBPpf0oZKIjtpKrx59Ho=
|
||||
github.com/fsnotify/fsnotify v1.10.1/go.mod h1:TLheqan6HD6GBK6PrDWyDPBaEV8LspOxvPSjC+bVfgo=
|
||||
github.com/gabriel-vasile/mimetype v1.4.15 h1:05iP/CYtZ/w455R/KZM6rZ5ieAdh99UPtd+d3YzLmaI=
|
||||
github.com/gabriel-vasile/mimetype v1.4.15/go.mod h1:azpTcoLcDZRNgFou5j+APrqQx9HqVPWa6ijYQIIVswQ=
|
||||
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
|
||||
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
||||
github.com/ganigeorgiev/fexpr v0.4.1 h1:hpUgbUEEWIZhSDBtf4M9aUNfQQ0BZkGRaMePy7Gcx5k=
|
||||
github.com/ganigeorgiev/fexpr v0.4.1/go.mod h1:RyGiGqmeXhEQ6+mlGdnUleLHgtzzu/VGO2WtJkF5drE=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
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-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
|
||||
github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/godbus/dbus/v5 v5.2.2 h1:TUR3TgtSVDmjiXOgAAyaZbYmIeP3DPkld3jgKGV8mXQ=
|
||||
github.com/godbus/dbus/v5 v5.2.2/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c=
|
||||
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
|
||||
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
|
||||
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
|
||||
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
|
||||
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/pprof v0.0.0-20261016150608-1facf8f91b50 h1:PlNWJRxu5APSV0pWqfIsZ0qt9OOGHSWfZQ4zvx+WgWs=
|
||||
github.com/google/pprof v0.0.0-20261016150608-1facf8f91b50/go.mod h1:yUo1AMMpsPIDFGuwDK8nLcf8+vvAd5l2O6JDZ6hpwrM=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 h1:FKHo8hFI3A+7w0aUQuYXQ+6EN5stWmeY/AZqtM8xk9k=
|
||||
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo=
|
||||
github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0=
|
||||
github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/wire v0.6.0 h1:HBkoIh4BdSxoyo9PveV8giw7ZsaBOvzWKfcg/6MrVwI=
|
||||
github.com/google/wire v0.6.0/go.mod h1:F4QhpQ9EDIdJ1Mbop/NZBRB+5yrR6qg3BnctaoUk6NA=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.4 h1:XYIDZApgAnrN1c855gTgghdIA6Stxb52D5RnLI1SLyw=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.4/go.mod h1:YKe7cfqYXjKGpGvmSg28/fFvhNzinZQm8DGnaburhGA=
|
||||
github.com/googleapis/gax-go/v2 v2.14.1 h1:hb0FFeiPaQskmvakKu5EbCbpntQn48jyHuvrkurSS/Q=
|
||||
github.com/googleapis/gax-go/v2 v2.14.1/go.mod h1:Hb/NubMaVM88SrNkvl8X/o8XWwDJEPqouaLeN2IUxoA=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||
github.com/holoplot/go-avahi v1.0.1 h1:XcqR2keL4qWRnlxHD5CAOdWpLFZJ+EOUK0vEuylfvvk=
|
||||
github.com/holoplot/go-avahi v1.0.1/go.mod h1:qH5psEKb0DK+BRplMfc+RY4VMOlbf6mqfxgpMy6aP0M=
|
||||
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
|
||||
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
|
||||
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
|
||||
github.com/josharian/native v1.0.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
|
||||
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
|
||||
github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mattn/go-colorable v0.1.16 h1:+2YjeAe7xP1OQbZW1jERPWWCDLlNqFNCvjiqGiAt84A=
|
||||
github.com/mattn/go-colorable v0.1.16/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI=
|
||||
github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A=
|
||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mdlayher/ethernet v0.0.0-20190313224307-5b5fc417d966/go.mod h1:5s5p/sMJ6sNsFl6uCh85lkFGV8kLuIYJCRJLavVJwvg=
|
||||
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118 h1:2oDp6OOhLxQ9JBoUuysVz9UZ9uI6oLUbvAZu0x8o+vE=
|
||||
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118/go.mod h1:ZFUnHIVchZ9lJoWoEGUg8Q3M4U8aNNWA3CVSUTkW4og=
|
||||
github.com/mdlayher/packet v1.0.0/go.mod h1:eE7/ctqDhoiRhQ44ko5JZU2zxB88g+JH/6jmnjzPjOU=
|
||||
github.com/mdlayher/packet v1.2.0 h1:SX7/oY0+nkKo7p4Sv30+TIc3YuWgvDEf0eucTXRyPqk=
|
||||
github.com/mdlayher/packet v1.2.0/go.mod h1:UtYVnQt+Zj6UD0F89HfzkqGXaYqys1NwkrS86wlLCv4=
|
||||
github.com/mdlayher/packet v1.1.2 h1:3Up1NG6LZrsgDVn6X4L9Ge/iyRyxFEFD9o6Pr3Q1nQY=
|
||||
github.com/mdlayher/packet v1.1.2/go.mod h1:GEu1+n9sG5VtiRE4SydOmX5GTwyyYlteZiFU+x0kew4=
|
||||
github.com/mdlayher/raw v0.0.0-20190313224157-43dbcdd7739d/go.mod h1:r1fbeITl2xL/zLbVnNHFyOzQJTgr/3fpf1lJX/cjzR8=
|
||||
github.com/mdlayher/socket v0.2.1/go.mod h1:QLlNPkFR88mRUNQIzRBMfXxwKal8H7u1h3bL1CV+f0E=
|
||||
github.com/mdlayher/socket v0.7.0 h1:qVREPVwtUMg17pwvveQxpurq0PVisMxi3FGgpsorMYQ=
|
||||
github.com/mdlayher/socket v0.7.0/go.mod h1:f7iKql2EK/rfsWYDKofKjk2Ig7I+6HQWdMIdn1tO4A4=
|
||||
github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos=
|
||||
github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ=
|
||||
github.com/mdlayher/wol v0.0.0-20220221231636-b763a792253a h1:fpQi42PM6HzbHwNg6a7OvLbh5l49Rgr7GCARozjHwio=
|
||||
github.com/mdlayher/wol v0.0.0-20220221231636-b763a792253a/go.mod h1:XX6nvyQpGc8E4KaQm62FyexOYd36ilpyfYf8wjgMDV8=
|
||||
github.com/ncruces/go-strftime v1.1.0 h1:vtPmPWMkb539RGV9WpWT9EwJGvrOCKvMNI4obWL47Hk=
|
||||
github.com/ncruces/go-strftime v1.1.0/go.mod h1:yVaq7iwCN09vHRrKBrrflXT0M9tTMG2KmZ9Fj7xeG/g=
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
|
||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
|
||||
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus-community/pro-bing v0.9.1 h1:kpuAr6AU2oRtzGihJSUcetHtjc7ku7h6PxeuW9RVrQw=
|
||||
github.com/prometheus-community/pro-bing v0.9.1/go.mod h1:z79wYTxAOf6FpTng0QdIhZ3j/Nd5l3+gnFSCIT+SiSQ=
|
||||
github.com/pocketbase/dbx v1.11.0 h1:LpZezioMfT3K4tLrqA55wWFw1EtH1pM4tzSVa7kgszU=
|
||||
github.com/pocketbase/dbx v1.11.0/go.mod h1:xXRCIAKTHMgUCyCKZm55pUOdvFziJjQfXaWKhu2vhMs=
|
||||
github.com/pocketbase/pocketbase v0.24.4 h1:kw/c23HccoxMV/19U9QlDcvNJgQ66vlUrxGQDZicWKM=
|
||||
github.com/pocketbase/pocketbase v0.24.4/go.mod h1:EfXV/8RUY76jA6g1RPNHjOuW7wTd2bz0QlvAI/RU8YY=
|
||||
github.com/prometheus-community/pro-bing v0.6.0 h1:04SZ/092gONTE1XUFzYFWqgB4mKwcdkqNChLMFedwhg=
|
||||
github.com/prometheus-community/pro-bing v0.6.0/go.mod h1:jNCOI3D7pmTCeaoF41cNS6uaxeFY/Gmc3ffwbuJVzAQ=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
@@ -87,83 +197,182 @@ github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzG
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
|
||||
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
|
||||
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
|
||||
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
|
||||
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
||||
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
|
||||
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
|
||||
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
|
||||
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 h1:r6I7RJCN86bpD/FQwedZ0vSixDpwuWREjW9oRMsmqDc=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0/go.mod h1:B9yO6b04uB80CzjedvewuqDhxJxi11s7/GtiGa8bAjI=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 h1:TT4fX+nBOA/+LUkobKGW1ydGcn+G3vRw9+g5HwCphpk=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0/go.mod h1:L7UH0GbB0p47T4Rri3uHjbpCFYrVrwc1I25QhNPiGK8=
|
||||
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
|
||||
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE=
|
||||
go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE=
|
||||
go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY=
|
||||
go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk=
|
||||
go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08KsbbO5BPT0=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4JjxTeYusH7zMc=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8=
|
||||
go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys=
|
||||
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A=
|
||||
gocloud.dev v0.40.0 h1:f8LgP+4WDqOG/RXoUcyLpeIAGOcAbZrZbDQCUee10ng=
|
||||
gocloud.dev v0.40.0/go.mod h1:drz+VyYNBvrMTW0KZiBAYEdl8lbNZx+OQ7oQvdrFmSQ=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.58.0 h1:COkYLr4k7nDI4r6QtMML2AfzeIswWHAJthLS6K/M/54=
|
||||
golang.org/x/crypto v0.58.0/go.mod h1:Xh+kl5A+M0gMiWDytH2Hhr5Z7WbNCpv/eB/EFgfSk+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
|
||||
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.47.0 h1:za/8gVz++PPZqmZJBNSISICN5Rrj5zixP/8K++fgmqo=
|
||||
golang.org/x/image v0.47.0/go.mod h1:IkN5o4A7vq55vXN8FWjjnhg9Rs2GOtffqsSi9mWAKYE=
|
||||
golang.org/x/mod v0.42.0 h1:ICeL3t2L30ljSPHHxDnR4fqVcBt/zR2zJAb9juavmQg=
|
||||
golang.org/x/mod v0.42.0/go.mod h1:u5fzIrRInkL8MaO1cbRkUHT64v303YIT5KEqpNr7jRs=
|
||||
golang.org/x/image v0.23.0 h1:HseQ7c2OpPKTPVzNjG5fwJsOTCiiwS4QdsYi5XU6H68=
|
||||
golang.org/x/image v0.23.0/go.mod h1:wJJBTdLfCCf3tiHa1fNxpZmUI4mmoZvwMCPP0ddoNKY=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
|
||||
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.62.0 h1:18ELalfM5+XNRwzM2nYqXsZQ9ByS1uhj2O/U7+5jqRY=
|
||||
golang.org/x/net v0.62.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
|
||||
golang.org/x/oauth2 v0.37.0 h1:JUlcxA8oAtauLfiH8FX2/FkAWHAdi0QtGCGc+hofE98=
|
||||
golang.org/x/oauth2 v0.37.0/go.mod h1:IxwZNxUULJmpBFf9K/9NTMSIfZZuvuTy1gGxhigP/58=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
|
||||
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70=
|
||||
golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA=
|
||||
golang.org/x/sync v0.24.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
|
||||
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA=
|
||||
golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
|
||||
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc=
|
||||
golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY=
|
||||
golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.52.0 h1:ryxg4U63oaUYk7uOLTF37n43f4qgtGvqV4Ioit1BaEs=
|
||||
golang.org/x/tools v0.52.0/go.mod h1:ItcP5UNaVGG+Yc4eIYmaFLNJ4soEopkx5Y2d4lcEurs=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE=
|
||||
golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da h1:noIWHXmPHxILtqtCOPIhSt0ABwskkZKjD3bXGnZGpNY=
|
||||
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
|
||||
google.golang.org/api v0.217.0 h1:GYrUtD289o4zl1AhiTZL0jvQGa2RDLyC+kX1N/lfGOU=
|
||||
google.golang.org/api v0.217.0/go.mod h1:qMc2E8cBAbQlRypBTBWHklNJlaZZJBwDv81B1Iu8oSI=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20240812133136-8ffd90a71988 h1:CT2Thj5AuPV9phrYMtzX11k+XkzMGfRAet42PmoTATM=
|
||||
google.golang.org/genproto v0.0.0-20240812133136-8ffd90a71988/go.mod h1:7uvplUBj4RjHAxIZ//98LzOvrQ04JBkaixRmCMI29hc=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 h1:CkkIfIt50+lT6NHAVoRYEyAvQGFM7xEwXUUywFvEb3Q=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576/go.mod h1:1R3kvZ1dtP3+4p4d3G8uJ8rFk/fWlScl38vanWACI08=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f h1:OxYkA3wjPsZyBylwymxSHa7ViiW1Sml4ToBrncvFehI=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f/go.mod h1:+2Yz8+CLJbIfL9z73EW45avw8Lmge3xVElCP9zEKi50=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
|
||||
google.golang.org/grpc v1.69.4 h1:MF5TftSMkd8GLw/m0KM6V8CMOCY6NZ1NQDPGFgbTt4A=
|
||||
google.golang.org/grpc v1.69.4/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU=
|
||||
google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
kernel.org/pub/linux/libs/security/libcap/cap v1.2.78 h1:jgqg4gyu2BaYW9L6uzEtGLf8GNREwk/z4UFdwt5F3pE=
|
||||
kernel.org/pub/linux/libs/security/libcap/cap v1.2.78/go.mod h1:VjuVda6m2qGkpCVfrFkpTGyvkdlZ2N5/yfo89tujlg8=
|
||||
kernel.org/pub/linux/libs/security/libcap/psx v1.2.78 h1:PC3yNs51cX5LZ7U57a7xielBcoXB3xnV+rXD8V0H0DQ=
|
||||
kernel.org/pub/linux/libs/security/libcap/psx v1.2.78/go.mod h1:+l6Ee2F59XiJ2I6WR5ObpC1utCQJZ/VLsEbQCD8RG24=
|
||||
modernc.org/cc/v4 v4.29.7 h1:q+NXGJ0bK3b4TXFYQQVr9pYETGnmwFWkrUzJnMya/Tg=
|
||||
modernc.org/cc/v4 v4.29.7/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
|
||||
modernc.org/ccgo/v4 v4.36.1 h1:ZNIUZAryN0UgnJwtyxrdEzcFc3yD4Cu4AzjfPXsLsIE=
|
||||
modernc.org/ccgo/v4 v4.36.1/go.mod h1:rrtGc2QkS239nYb/mQNuBMyjq3/y3ZXWbBjPoV3wqzA=
|
||||
modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM=
|
||||
modernc.org/fileutil v1.4.0/go.mod h1:EqdKFDxiByqxLk8ozOxObDSfcVOv/54xDs/DUHdvCUU=
|
||||
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
|
||||
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
|
||||
modernc.org/gc/v3 v3.1.5 h1:21ldfPfRYE31Tb7B3mwAK8gy1AxP4+dKjrOQPfqakoc=
|
||||
modernc.org/gc/v3 v3.1.5/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
|
||||
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
|
||||
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
|
||||
modernc.org/libc v1.77.1 h1:Ct8j47QtiZ1Enj2DtFXQtUqrPCAjdCmPjtCuvrYQ0Hs=
|
||||
modernc.org/libc v1.77.1/go.mod h1:87/pZ4L6nD1zqW4nItuS12YO7hN1igAah34xjnQo/W0=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
modernc.org/cc/v4 v4.21.4 h1:3Be/Rdo1fpr8GrQ7IVw9OHtplU4gWbb+wNgeoBMmGLQ=
|
||||
modernc.org/cc/v4 v4.21.4/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ=
|
||||
modernc.org/ccgo/v4 v4.19.2 h1:lwQZgvboKD0jBwdaeVCTouxhxAyN6iawF3STraAal8Y=
|
||||
modernc.org/ccgo/v4 v4.19.2/go.mod h1:ysS3mxiMV38XGRTTcgo0DQTeTmAO4oCmJl1nX9VFI3s=
|
||||
modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE=
|
||||
modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ=
|
||||
modernc.org/gc/v2 v2.4.1 h1:9cNzOqPyMJBvrUipmynX0ZohMhcxPtMccYgGOJdOiBw=
|
||||
modernc.org/gc/v2 v2.4.1/go.mod h1:wzN5dK1AzVGoH6XOzc3YZ+ey/jPgYHLuVckd62P0GYU=
|
||||
modernc.org/gc/v3 v3.0.0-20250105121824-520be1a3aee6 h1:JoKwHjIFumiKrjMbp1cNbC5E9UyCgA/ZcID0xOWQ2N8=
|
||||
modernc.org/gc/v3 v3.0.0-20250105121824-520be1a3aee6/go.mod h1:LG5UO1Ran4OO0JRKz2oNiXhR5nNrgz0PzH7UKhz0aMU=
|
||||
modernc.org/libc v1.55.3 h1:AzcW1mhlPNrRtjS5sS+eW2ISCgSOLLNyFzRh/V3Qj/U=
|
||||
modernc.org/libc v1.55.3/go.mod h1:qFXepLhz+JjFThQ4kzwzOjA/y/artDeg+pcYnY+Q83w=
|
||||
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
||||
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
|
||||
modernc.org/memory v1.12.1 h1:nFMiWrpStgZczNl6XI9GnIk/rWhYIyHGUaR04pGbp9g=
|
||||
modernc.org/memory v1.12.1/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
||||
modernc.org/opt v0.2.0 h1:tGyef5ApycA7FSEOMraay9SaTk5zmbx7Tu+cJs4QKZg=
|
||||
modernc.org/opt v0.2.0/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
|
||||
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
|
||||
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
|
||||
modernc.org/sqlite v1.60.1 h1:/blz53O951KWFOso4QQvEs/Fq6cDBKLtMVrYNSeJVKw=
|
||||
modernc.org/sqlite v1.60.1/go.mod h1:1dIoEagfDE72QytD5scH1lxARtaUgKgHC/NuApA27r0=
|
||||
modernc.org/memory v1.8.2 h1:cL9L4bcoAObu4NkxOlKWBWtNHIsnnACGF/TbqQ6sbcI=
|
||||
modernc.org/memory v1.8.2/go.mod h1:ZbjSvMO5NQ1A2i3bWeDiVMxIorXwdClKE/0SZ+BMotU=
|
||||
modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
|
||||
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
|
||||
modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc=
|
||||
modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss=
|
||||
modernc.org/sqlite v1.34.4 h1:sjdARozcL5KJBvYQvLlZEmctRgW9xqIZc2ncN7PU0P8=
|
||||
modernc.org/sqlite v1.34.4/go.mod h1:3QQFCG2SEMtc2nv+Wq4cQCH7Hjcg+p/RMlS1XK+zwbk=
|
||||
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
||||
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
|
||||
@@ -1,136 +0,0 @@
|
||||
// Package iptracking updates the stored ip addresses of opted-in devices by
|
||||
// scanning their local subnets for their mac addresses.
|
||||
package iptracking
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync/atomic"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
"github.com/seriousm4x/upsnap/logging"
|
||||
"github.com/seriousm4x/upsnap/networking"
|
||||
)
|
||||
|
||||
var sweepRunning atomic.Bool
|
||||
|
||||
// sweepOwed marks that a periodic sweep was skipped while no realtime
|
||||
// clients were connected, so the next client to connect gets a catch-up
|
||||
// sweep. Starts true so the first client after boot gets fresh ips.
|
||||
var sweepOwed atomic.Bool
|
||||
|
||||
func init() {
|
||||
sweepOwed.Store(true)
|
||||
}
|
||||
|
||||
// nmapScan is a seam for tests to stub out the privileged nmap invocation
|
||||
var nmapScan = networking.NmapScan
|
||||
|
||||
// TrackAllSubnets scans the local subnets of devices with ip tracking enabled
|
||||
// and updates their ip address if their mac address is found at a different
|
||||
// one. Non-scannable subnets are silently skipped, but their devices can
|
||||
// still be updated by another subnet's scan that finds their mac address,
|
||||
// as long as the new ip stays within the device's own subnet.
|
||||
func TrackAllSubnets(app core.App) {
|
||||
log := logging.Logger(app)
|
||||
// skip if the previous sweep is still running
|
||||
if !sweepRunning.CompareAndSwap(false, true) {
|
||||
return
|
||||
}
|
||||
defer sweepRunning.Store(false)
|
||||
|
||||
devices, err := app.FindRecordsByFilter("devices", "track_ip = true", "", 0, 0)
|
||||
if err != nil {
|
||||
log.Error("Failed to load devices for IP tracking", "error", err)
|
||||
return
|
||||
}
|
||||
|
||||
// collect the unique scannable subnets of the tracked devices
|
||||
subnets := make(map[string]*net.IPNet)
|
||||
for _, device := range devices {
|
||||
subnet, err := networking.DeviceSubnet(device.GetString("ip"), device.GetString("netmask"))
|
||||
if err != nil {
|
||||
log.Error("Failed to determine device subnet for IP tracking", "device", device.GetString("name"), "error", err)
|
||||
continue
|
||||
}
|
||||
if networking.ValidateScannableSubnet(subnet) != nil {
|
||||
continue
|
||||
}
|
||||
subnets[subnet.String()] = subnet
|
||||
}
|
||||
|
||||
for cidr, subnet := range subnets {
|
||||
if err := TrackOneSubnet(app, subnet); err != nil {
|
||||
log.Error("IP tracking scan failed", "subnet", cidr, "error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PeriodicSweep runs the scheduled sweep, or skips it when paused — no
|
||||
// realtime clients connected while lazy_ping is on — owing a catch-up
|
||||
// sweep to the next client that connects.
|
||||
func PeriodicSweep(app core.App, pause bool) {
|
||||
if pause {
|
||||
sweepOwed.Store(true)
|
||||
return
|
||||
}
|
||||
TrackAllSubnets(app)
|
||||
}
|
||||
|
||||
// CatchUpSweep runs a sweep if one is owed, i.e. the periodic sweep was
|
||||
// skipped while nobody was connected or hasn't run since boot. Clients
|
||||
// connecting while sweeps run on schedule trigger nothing.
|
||||
func CatchUpSweep(app core.App) {
|
||||
if !sweepOwed.CompareAndSwap(true, false) {
|
||||
return
|
||||
}
|
||||
TrackAllSubnets(app)
|
||||
}
|
||||
|
||||
// TrackOneSubnet runs an nmap scan of the given subnet and updates the ip
|
||||
// address of any ip-tracked device whose mac address is found at a new
|
||||
// address within its own subnet. Returns an error for a non-scannable subnet.
|
||||
func TrackOneSubnet(app core.App, subnet *net.IPNet) error {
|
||||
log := logging.Logger(app)
|
||||
if err := networking.ValidateScannableSubnet(subnet); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
scan, err := nmapScan(subnet.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
macToIp := scan.MacToIP()
|
||||
|
||||
devices, err := app.FindRecordsByFilter("devices", "track_ip = true", "", 0, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, device := range devices {
|
||||
parsedMac, err := net.ParseMAC(device.GetString("mac"))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
newIp, ok := macToIp[parsedMac.String()]
|
||||
if !ok || newIp == device.GetString("ip") {
|
||||
continue
|
||||
}
|
||||
// only move a device within its own subnet, so that a scan can't
|
||||
// relocate devices tracked on other subnets that see the same mac
|
||||
deviceSubnet, err := networking.DeviceSubnet(device.GetString("ip"), device.GetString("netmask"))
|
||||
if err != nil || !deviceSubnet.Contains(net.ParseIP(newIp)) {
|
||||
continue
|
||||
}
|
||||
oldIP := device.GetString("ip")
|
||||
device.Set("ip", newIp)
|
||||
// only write the changed ip field to avoid clobbering concurrent
|
||||
// status updates from the ping and wake/shutdown cronjobs
|
||||
device.IgnoreUnchangedFields(true)
|
||||
if err := app.Save(device); err != nil {
|
||||
log.Error("Failed to save tracked device IP", "device", device.GetString("name"), "error", err)
|
||||
} else {
|
||||
log.Info("Device IP changed", "device", device.GetString("name"), "from", oldIP, "to", newIp)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,347 +0,0 @@
|
||||
package iptracking
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/tests"
|
||||
"github.com/seriousm4x/upsnap/networking"
|
||||
|
||||
// register the app migrations so test apps get the real schema
|
||||
_ "github.com/seriousm4x/upsnap/migrations"
|
||||
)
|
||||
|
||||
// newTestApp returns a throwaway app with all migrations applied.
|
||||
func newTestApp(t *testing.T) *tests.TestApp {
|
||||
t.Helper()
|
||||
app, err := tests.NewTestApp(t.TempDir())
|
||||
if err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
t.Cleanup(app.Cleanup)
|
||||
return app
|
||||
}
|
||||
|
||||
func buildDevice(t *testing.T, app core.App, name, ip, netmask, mac string, trackIp bool) *core.Record {
|
||||
t.Helper()
|
||||
collection, err := app.FindCollectionByNameOrId("devices")
|
||||
if err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
device := core.NewRecord(collection)
|
||||
device.Set("name", name)
|
||||
device.Set("ip", ip)
|
||||
device.Set("netmask", netmask)
|
||||
device.Set("mac", mac)
|
||||
device.Set("track_ip", trackIp)
|
||||
return device
|
||||
}
|
||||
|
||||
func newDevice(t *testing.T, app core.App, name, ip, netmask, mac string, trackIp bool) *core.Record {
|
||||
t.Helper()
|
||||
device := buildDevice(t, app, name, ip, netmask, mac, trackIp)
|
||||
if err := app.Save(device); err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
return device
|
||||
}
|
||||
|
||||
// newLegacyDevice saves a device bypassing field validation, like rows
|
||||
// created before the ip and mac format rules existed.
|
||||
func newLegacyDevice(t *testing.T, app core.App, name, ip, netmask, mac string, trackIp bool) *core.Record {
|
||||
t.Helper()
|
||||
device := buildDevice(t, app, name, ip, netmask, mac, trackIp)
|
||||
if err := app.SaveNoValidate(device); err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
return device
|
||||
}
|
||||
|
||||
// stubScan replaces the nmap seam with a canned scan reporting the given
|
||||
// mac addresses at the given ips, and returns the list of scanned ranges.
|
||||
func stubScan(t *testing.T, macToHostIp map[string]string) *[]string {
|
||||
t.Helper()
|
||||
var sample strings.Builder
|
||||
sample.WriteString("<nmaprun>")
|
||||
for mac, ip := range macToHostIp {
|
||||
fmt.Fprintf(&sample, `<host><address addr=%q addrtype="ipv4"/><address addr=%q addrtype="mac"/></host>`, ip, mac)
|
||||
}
|
||||
sample.WriteString("</nmaprun>")
|
||||
scan := networking.Nmaprun{}
|
||||
if err := xml.Unmarshal([]byte(sample.String()), &scan); err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
|
||||
var scanned []string
|
||||
orig := nmapScan
|
||||
nmapScan = func(scanRange string) (networking.Nmaprun, error) {
|
||||
scanned = append(scanned, scanRange)
|
||||
return scan, nil
|
||||
}
|
||||
t.Cleanup(func() { nmapScan = orig })
|
||||
return &scanned
|
||||
}
|
||||
|
||||
func mustSubnet(t *testing.T, cidr string) *net.IPNet {
|
||||
t.Helper()
|
||||
_, subnet, err := net.ParseCIDR(cidr)
|
||||
if err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
return subnet
|
||||
}
|
||||
|
||||
// The loopback /16 passes the scannable checks on any host, making it the
|
||||
// only subnet a test can scan without depending on the environment.
|
||||
const (
|
||||
testSubnet = "127.0.0.0/16"
|
||||
testNetmask = "255.255.0.0"
|
||||
)
|
||||
|
||||
func TestTrackOneSubnetSkipsUntrackedDevices(t *testing.T) {
|
||||
app := newTestApp(t)
|
||||
device := newDevice(t, app, "untracked", "127.0.0.50", testNetmask, "AA:BB:CC:DD:EE:01", false)
|
||||
stubScan(t, map[string]string{"AA:BB:CC:DD:EE:01": "127.0.0.99"})
|
||||
|
||||
if err := TrackOneSubnet(app, mustSubnet(t, testSubnet)); err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
|
||||
fresh, err := app.FindRecordById("devices", device.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
if ip := fresh.GetString("ip"); ip != "127.0.0.50" {
|
||||
t.Errorf("Ip of device without track_ip changed to %s", ip)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrackOneSubnetSkipPaths(t *testing.T) {
|
||||
app := newTestApp(t)
|
||||
saves := 0
|
||||
app.OnRecordUpdate("devices").BindFunc(func(e *core.RecordEvent) error {
|
||||
saves++
|
||||
return e.Next()
|
||||
})
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
ip string
|
||||
mac string
|
||||
legacy bool
|
||||
}{
|
||||
// A device mac that can't be parsed never matches
|
||||
{
|
||||
name: "Invalid Mac",
|
||||
ip: "127.0.0.50",
|
||||
mac: "not-a-mac",
|
||||
legacy: true,
|
||||
},
|
||||
// A device mac missing from the scan results is left alone
|
||||
{
|
||||
name: "Mac Not In Scan",
|
||||
ip: "127.0.0.50",
|
||||
mac: "AA:BB:CC:DD:EE:02",
|
||||
},
|
||||
// A device ip without a computable subnet is never moved
|
||||
{
|
||||
name: "Invalid Device Ip",
|
||||
ip: "999.999.999.999",
|
||||
mac: "AA:BB:CC:DD:EE:01",
|
||||
legacy: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
create := newDevice
|
||||
if tc.legacy {
|
||||
create = newLegacyDevice
|
||||
}
|
||||
device := create(t, app, tc.name, tc.ip, testNetmask, tc.mac, true)
|
||||
stubScan(t, map[string]string{"AA:BB:CC:DD:EE:01": "127.0.0.99"})
|
||||
|
||||
if err := TrackOneSubnet(app, mustSubnet(t, testSubnet)); err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
|
||||
fresh, err := app.FindRecordById("devices", device.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
if ip := fresh.GetString("ip"); ip != tc.ip {
|
||||
t.Errorf("Ip mismatch: expected %s, got %s", tc.ip, ip)
|
||||
}
|
||||
if saves != 0 {
|
||||
t.Errorf("Expected no record updates, got %d", saves)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrackOneSubnetUnscannable(t *testing.T) {
|
||||
app := newTestApp(t)
|
||||
// TEST-NET-1 (RFC 5737) is never assigned to an interface
|
||||
scanned := stubScan(t, nil)
|
||||
|
||||
if err := TrackOneSubnet(app, mustSubnet(t, "192.0.2.0/24")); err == nil {
|
||||
t.Error("Expected error but got none")
|
||||
}
|
||||
if len(*scanned) != 0 {
|
||||
t.Errorf("Expected no scans of an unscannable subnet, got %v", *scanned)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrackOneSubnetSameSubnetGuard(t *testing.T) {
|
||||
app := newTestApp(t)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
ip string
|
||||
netmask string
|
||||
mac string
|
||||
scanMac string
|
||||
foundIp string
|
||||
wantIp string
|
||||
}{
|
||||
// A move within the device's own subnet is applied, with the
|
||||
// stored dashed lower case mac matching the scanned
|
||||
// colon-separated upper case one
|
||||
{
|
||||
name: "Within Own Subnet",
|
||||
ip: "127.0.0.50",
|
||||
netmask: testNetmask,
|
||||
mac: "aa-bb-cc-dd-01-01",
|
||||
scanMac: "AA:BB:CC:DD:01:01",
|
||||
foundIp: "127.0.0.99",
|
||||
wantIp: "127.0.0.99",
|
||||
},
|
||||
// The device's own subnet bounds the move, not the scanned one
|
||||
{
|
||||
name: "Narrower Subnet Within Scan",
|
||||
ip: "127.0.5.5",
|
||||
netmask: "255.255.255.0",
|
||||
mac: "AA:BB:CC:DD:01:02",
|
||||
foundIp: "127.0.5.9",
|
||||
wantIp: "127.0.5.9",
|
||||
},
|
||||
// A found ip outside the device's narrower subnet is not applied,
|
||||
// even though it is inside the scanned subnet
|
||||
{
|
||||
name: "Outside Own Subnet",
|
||||
ip: "127.0.5.5",
|
||||
netmask: "255.255.255.0",
|
||||
mac: "AA:BB:CC:DD:01:03",
|
||||
foundIp: "127.0.6.9",
|
||||
wantIp: "127.0.5.5",
|
||||
},
|
||||
// A device from a disjoint subnet is never moved into the scanned one
|
||||
{
|
||||
name: "Disjoint Subnet",
|
||||
ip: "10.9.9.9",
|
||||
netmask: "255.255.255.0",
|
||||
mac: "AA:BB:CC:DD:01:04",
|
||||
foundIp: "127.0.0.99",
|
||||
wantIp: "10.9.9.9",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
device := newDevice(t, app, tc.name, tc.ip, tc.netmask, tc.mac, true)
|
||||
scanMac := tc.scanMac
|
||||
if scanMac == "" {
|
||||
scanMac = tc.mac
|
||||
}
|
||||
stubScan(t, map[string]string{scanMac: tc.foundIp})
|
||||
|
||||
if err := TrackOneSubnet(app, mustSubnet(t, testSubnet)); err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
|
||||
fresh, err := app.FindRecordById("devices", device.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
if ip := fresh.GetString("ip"); ip != tc.wantIp {
|
||||
t.Errorf("Ip mismatch: expected %s, got %s", tc.wantIp, ip)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A paused periodic sweep scans nothing and owes a catch-up sweep, which
|
||||
// runs at most once until the next pause; an unpaused sweep scans directly.
|
||||
func TestPeriodicSweepAndCatchUp(t *testing.T) {
|
||||
app := newTestApp(t)
|
||||
newDevice(t, app, "tracked", "127.0.0.50", testNetmask, "AA:BB:CC:DD:09:01", true)
|
||||
scanned := stubScan(t, map[string]string{"AA:BB:CC:DD:09:01": "127.0.0.99"})
|
||||
|
||||
PeriodicSweep(app, true)
|
||||
if len(*scanned) != 0 {
|
||||
t.Fatalf("Expected no scans while paused, got %v", *scanned)
|
||||
}
|
||||
|
||||
CatchUpSweep(app)
|
||||
if len(*scanned) != 1 {
|
||||
t.Fatalf("Expected one scan after a paused sweep, got %v", *scanned)
|
||||
}
|
||||
|
||||
CatchUpSweep(app)
|
||||
if len(*scanned) != 1 {
|
||||
t.Errorf("Expected no scan when none is owed, got %v", *scanned)
|
||||
}
|
||||
|
||||
PeriodicSweep(app, false)
|
||||
if len(*scanned) != 2 {
|
||||
t.Errorf("Expected an unpaused sweep to scan, got %v", *scanned)
|
||||
}
|
||||
|
||||
CatchUpSweep(app)
|
||||
if len(*scanned) != 2 {
|
||||
t.Errorf("Expected an unpaused sweep to owe nothing, got %v", *scanned)
|
||||
}
|
||||
}
|
||||
|
||||
// TrackAllSubnets scans each unique scannable subnet once, silently skips the
|
||||
// rest, and updates any tracked device found at a new ip within its own
|
||||
// subnet — even one whose own subnet couldn't be scanned.
|
||||
func TestTrackAllSubnets(t *testing.T) {
|
||||
app := newTestApp(t)
|
||||
first := newDevice(t, app, "first", "127.0.0.10", testNetmask, "AA:BB:CC:DD:02:01", true)
|
||||
second := newDevice(t, app, "second", "127.0.0.20", testNetmask, "AA:BB:CC:DD:02:02", true)
|
||||
// TEST-NET-1 (RFC 5737) is never assigned to an interface
|
||||
unscannable := newDevice(t, app, "unscannable", "192.0.2.5", "255.255.255.0", "AA:BB:CC:DD:02:03", true)
|
||||
// a /8 subnet is too large to scan but contains the found ip
|
||||
wide := newDevice(t, app, "wide", "127.0.0.60", "255.0.0.0", "AA:BB:CC:DD:02:04", true)
|
||||
scanned := stubScan(t, map[string]string{
|
||||
"AA:BB:CC:DD:02:01": "127.0.0.11",
|
||||
"AA:BB:CC:DD:02:02": "127.0.0.21",
|
||||
"AA:BB:CC:DD:02:04": "127.0.0.61",
|
||||
})
|
||||
|
||||
TrackAllSubnets(app)
|
||||
|
||||
if len(*scanned) != 1 || (*scanned)[0] != testSubnet {
|
||||
t.Errorf("Expected a single scan of %s, got %v", testSubnet, *scanned)
|
||||
}
|
||||
wantIps := map[string]string{
|
||||
first.Id: "127.0.0.11",
|
||||
second.Id: "127.0.0.21",
|
||||
unscannable.Id: "192.0.2.5",
|
||||
wide.Id: "127.0.0.61",
|
||||
}
|
||||
for id, wantIp := range wantIps {
|
||||
fresh, err := app.FindRecordById("devices", id)
|
||||
if err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
if ip := fresh.GetString("ip"); ip != wantIp {
|
||||
t.Errorf("Ip mismatch for %s: expected %s, got %s", fresh.GetString("name"), wantIp, ip)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
const (
|
||||
flags = log.Ldate | log.Ltime | log.Lshortfile
|
||||
)
|
||||
|
||||
var (
|
||||
Info = log.New(os.Stdout, "[INFO] ", flags)
|
||||
Debug = log.New(os.Stdout, "[DEBUG] ", flags)
|
||||
Warning = log.New(os.Stdout, "[WARNING] ", flags)
|
||||
Error = log.New(os.Stderr, "[ERROR] ", flags)
|
||||
)
|
||||
|
||||
func init() {
|
||||
// TODO: decide if you want to log to a file to max
|
||||
// output := io.MultiWriter(os.Stdout, logFile)
|
||||
output := os.Stdout
|
||||
Info.SetOutput(output)
|
||||
Error.SetOutput(output)
|
||||
Debug.SetOutput(output)
|
||||
|
||||
log.SetOutput(Debug.Writer())
|
||||
log.SetPrefix("[DEBUG]")
|
||||
log.SetFlags(flags)
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
var consoleHandler slog.Handler
|
||||
|
||||
// ConfigureConsole sets console output for UpSnap logs. PocketBase persistence
|
||||
// remains controlled by PocketBase's built-in log settings.
|
||||
func ConfigureConsole(level string) error {
|
||||
level = strings.TrimSpace(level)
|
||||
if level == "" {
|
||||
level = "INFO"
|
||||
}
|
||||
|
||||
if strings.EqualFold(level, "OFF") {
|
||||
consoleHandler = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
var parsed slog.Level
|
||||
if err := parsed.UnmarshalText([]byte(strings.ToUpper(level))); err != nil {
|
||||
return fmt.Errorf("invalid UPSNAP_LOG_LEVEL %q (expected DEBUG, INFO, WARN, ERROR, or OFF)", level)
|
||||
}
|
||||
|
||||
consoleHandler = slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
|
||||
Level: parsed,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func relativeSource(file string) string {
|
||||
file = strings.ReplaceAll(file, "\\", "/")
|
||||
if index := strings.LastIndex(file, "/backend/"); index >= 0 {
|
||||
return file[index+1:]
|
||||
}
|
||||
return file
|
||||
}
|
||||
|
||||
// Logger writes through PocketBase's logger and mirrors UpSnap logs to stdout.
|
||||
func Logger(app core.App) *slog.Logger {
|
||||
handlers := []slog.Handler{app.Logger().Handler()}
|
||||
if consoleHandler != nil && !app.IsDev() {
|
||||
handlers = append(handlers, consoleHandler)
|
||||
}
|
||||
return slog.New(multiHandler(handlers)).With("upsnap", true)
|
||||
}
|
||||
|
||||
type multiHandler []slog.Handler
|
||||
|
||||
func (h multiHandler) Enabled(ctx context.Context, level slog.Level) bool {
|
||||
for _, handler := range h {
|
||||
if handler.Enabled(ctx, level) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (h multiHandler) Handle(ctx context.Context, record slog.Record) error {
|
||||
if record.PC != 0 {
|
||||
frames := runtime.CallersFrames([]uintptr{record.PC})
|
||||
frame, _ := frames.Next()
|
||||
record.AddAttrs(slog.String(slog.SourceKey, relativeSource(frame.File)+":"+strconv.Itoa(frame.Line)))
|
||||
}
|
||||
|
||||
var errs []error
|
||||
for _, handler := range h {
|
||||
if handler.Enabled(ctx, record.Level) {
|
||||
if err := handler.Handle(ctx, record.Clone()); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
func (h multiHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
|
||||
handlers := make(multiHandler, len(h))
|
||||
for i, handler := range h {
|
||||
handlers[i] = handler.WithAttrs(attrs)
|
||||
}
|
||||
return handlers
|
||||
}
|
||||
|
||||
func (h multiHandler) WithGroup(name string) slog.Handler {
|
||||
handlers := make(multiHandler, len(h))
|
||||
for i, handler := range h {
|
||||
handlers[i] = handler.WithGroup(name)
|
||||
}
|
||||
return handlers
|
||||
}
|
||||
@@ -2,9 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"log"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/apis"
|
||||
"github.com/pocketbase/pocketbase/apis"
|
||||
"github.com/seriousm4x/upsnap/pb"
|
||||
)
|
||||
|
||||
@@ -13,7 +12,5 @@ var distDir embed.FS
|
||||
var distDirFS = apis.MustSubFS(distDir, "pb_public")
|
||||
|
||||
func main() {
|
||||
if err := pb.StartPocketBase(distDirFS); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
pb.StartPocketBase(distDirFS)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -3,8 +3,8 @@ package migrations
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(11, []byte(`{
|
||||
"hidden": false,
|
||||
"id": "number361076486",
|
||||
"max": null,
|
||||
"min": 1,
|
||||
"name": "wake_timeout",
|
||||
"onlyInt": true,
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "number"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// remove field
|
||||
collection.Fields.RemoveById("number361076486")
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(15, []byte(`{
|
||||
"hidden": false,
|
||||
"id": "number2068100152",
|
||||
"max": null,
|
||||
"min": 1,
|
||||
"name": "shutdown_timeout",
|
||||
"onlyInt": true,
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "number"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// remove field
|
||||
collection.Fields.RemoveById("number2068100152")
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "1si6ajha",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "ip",
|
||||
"pattern": "^((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4}$",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(3, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "fyqmpon6",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "mac",
|
||||
"pattern": "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "1si6ajha",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "ip",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(3, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "fyqmpon6",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "mac",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "1si6ajha",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "ip",
|
||||
"pattern": "^(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}$",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "1si6ajha",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "ip",
|
||||
"pattern": "^((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4}$",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(4, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "s8c5z7n0",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "netmask",
|
||||
"pattern": "^(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}$",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(4, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "s8c5z7n0",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "netmask",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(6, []byte(`{
|
||||
"hidden": false,
|
||||
"id": "bool2618032555",
|
||||
"name": "track_ip",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "bool"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// remove field
|
||||
collection.Fields.RemoveById("bool2618032555")
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("nmj3ko20gzkg8n3")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(4, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text3846109882",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "track_ip_interval",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("nmj3ko20gzkg8n3")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// remove field
|
||||
collection.Fields.RemoveById("text3846109882")
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
m "ganigeorgiev.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "1si6ajha",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "ip",
|
||||
"pattern": "^(?:(?:[\\p{L}\\p{N}](?:[\\p{L}\\p{N}-]{0,61}[\\p{L}\\p{N}])?\\.)+[\\p{L}\\p{N}](?:[\\p{L}\\p{N}-]{0,61}[\\p{L}\\p{N}])?|(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})$",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(4, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "s8c5z7n0",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "netmask",
|
||||
"pattern": "^(?:255\\.255\\.255\\.(?:255|254|252|248|240|224|192|128|0)|255\\.255\\.(?:255|254|252|248|240|224|192|128|0)\\.0|255\\.(?:255|254|252|248|240|224|192|128|0)\\.0\\.0|(?:255|254|252|248|240|224|192|128|0)\\.0\\.0\\.0)$",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "1si6ajha",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "ip",
|
||||
"pattern": "^(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}$",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(4, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "s8c5z7n0",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "netmask",
|
||||
"pattern": "^(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}$",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
||||
@@ -5,15 +5,12 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
"github.com/mdlayher/wol"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
func SendMagicPacket(device *core.Record) error {
|
||||
ip, err := ResolveToIPAddr(device.GetString("ip"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ip := device.GetString("ip")
|
||||
mac := device.GetString("mac")
|
||||
netmask := device.GetString("netmask")
|
||||
password := device.GetString("password")
|
||||
@@ -23,100 +20,74 @@ func SendMagicPacket(device *core.Record) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ValidateSubnetMask(netmask) {
|
||||
return fmt.Errorf("%q is not a valid subnet mask", netmask)
|
||||
}
|
||||
|
||||
// calculate broadcast IP, if possible
|
||||
var broadcastIp string
|
||||
// an IP was provided or FQDN resolved to an IP so calculate broadcast destination based on that
|
||||
if ip != "" {
|
||||
broadcastIp, err = getBroadcastIp(ip, netmask)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// No IP available, so no broadcast IP can be calculated. This occurs if FQDN is .local and the device is powered off
|
||||
broadcastIp = ""
|
||||
}
|
||||
|
||||
var bytePassword []byte
|
||||
if len(password) == 0 || len(password) == 4 || len(password) == 6 {
|
||||
bytePassword = []byte(password)
|
||||
} else {
|
||||
return errors.New("error: password must be 0, 4 or 6 characters long")
|
||||
return fmt.Errorf("error: password must be 0, 4 or 6 characters long")
|
||||
}
|
||||
|
||||
// an IP was provided or FQDN resolved to an IP so calculate broadcast destination based on that
|
||||
if ip != "" {
|
||||
broadcastIp, err = getBroadcastIp(ip, netmask)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// No IP available, so no broadcast IP can be calculated. This occurs if FQDN is .local and the device is powered off
|
||||
broadcastIp = ""
|
||||
}
|
||||
|
||||
// send wake
|
||||
if err := wakeUDP(broadcastIp, ip, parsedMac, bytePassword); err != nil {
|
||||
// get target addr
|
||||
broadcastIp, err := getBroadcastIp(ip, netmask)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// send wake via udp port 9
|
||||
if err := wakeUDP(broadcastIp, parsedMac, bytePassword); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func wakeUDP(broadcastIp string, deviceIp string, target net.HardwareAddr, password []byte) error {
|
||||
func wakeUDP(broadcastIp string, target net.HardwareAddr, password []byte) error {
|
||||
c, err := wol.NewClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
var destinations []string
|
||||
|
||||
// Broadcast IP available, add to destinations
|
||||
if broadcastIp != "" {
|
||||
// user-calculated broadcast packet to port 9 and alternative port 7
|
||||
destinations = append(destinations,
|
||||
fmt.Sprintf("%s:9", broadcastIp),
|
||||
fmt.Sprintf("%s:7", broadcastIp),
|
||||
)
|
||||
// send 4 magic packets to different addresses to enhance change of waking up
|
||||
destinations := []string{
|
||||
// default user-calculated broadcast to port 9
|
||||
fmt.Sprintf("%s:9", broadcastIp),
|
||||
// user-calculated broadcast to port alternative port 7
|
||||
fmt.Sprintf("%s:7", broadcastIp),
|
||||
// broadcast to port 9
|
||||
"255.255.255.255:9",
|
||||
// broadcast to alternative port 7
|
||||
"255.255.255.255:7",
|
||||
}
|
||||
|
||||
if deviceIp != "" {
|
||||
// For routed network WOL, send a unicast packet to device IP on port 9 and alternative port 7
|
||||
destinations = append(destinations,
|
||||
fmt.Sprintf("%s:9", deviceIp),
|
||||
fmt.Sprintf("%s:7", deviceIp),
|
||||
)
|
||||
}
|
||||
|
||||
// No IP for the device is available, broadcast WOL packet to all interfaces
|
||||
if deviceIp == "" {
|
||||
allBroadcastDests, err := getAllBroadcastDests()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
destinations = append(destinations, allBroadcastDests...)
|
||||
}
|
||||
for _, dest := range destinations {
|
||||
if err := c.WakePassword(dest, target, password); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getBroadcastIp(ipStr, maskStr string) (string, error) {
|
||||
ip := net.ParseIP(ipStr).To4()
|
||||
ip := net.ParseIP(ipStr)
|
||||
if ip == nil {
|
||||
return "", errors.New("ip not a valid ipv4 address")
|
||||
}
|
||||
ip = ip.To4()
|
||||
if ip == nil {
|
||||
return "", errors.New("ip not a valid ipv4 address")
|
||||
}
|
||||
|
||||
mask := net.ParseIP(maskStr).To4()
|
||||
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 {
|
||||
@@ -125,42 +96,3 @@ func getBroadcastIp(ipStr, maskStr string) (string, error) {
|
||||
|
||||
return broadcast.String(), nil
|
||||
}
|
||||
|
||||
// Returns a slice of all broadcast addresses for ports 9 and 7 using local interfaces
|
||||
func getAllBroadcastDests() ([]string, error) {
|
||||
var allIps []string
|
||||
interfaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Iterate through all the interfaces
|
||||
for _, iface := range interfaces {
|
||||
isRunning := iface.Flags&net.FlagRunning != 0
|
||||
isLoopback := iface.Flags&net.FlagLoopback != 0
|
||||
isNotBroadcast := iface.Flags&net.FlagBroadcast == 0
|
||||
// exclude interfaces that are not running, are loopback, or can't broadcast
|
||||
if !isRunning || isLoopback || isNotBroadcast {
|
||||
continue
|
||||
}
|
||||
addrs, err := iface.Addrs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Iterate through each interface's address
|
||||
for _, addr := range addrs {
|
||||
if ipNet, ok := addr.(*net.IPNet); ok {
|
||||
ip := ipNet.IP
|
||||
// Only use IPv4
|
||||
if ip.To4() != nil {
|
||||
bcastip, err := getBroadcastIp(ip.String(), net.IP(ipNet.Mask).String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
allIps = append(allIps, fmt.Sprintf("%s:9", bcastip), fmt.Sprintf("%s:7", bcastip))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return allIps, nil
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
type Device struct {
|
||||
@@ -16,221 +16,147 @@ type Device struct {
|
||||
}
|
||||
|
||||
func TestSendMagicPacket(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
ip string
|
||||
mac string
|
||||
netmask string
|
||||
password string
|
||||
wantError bool
|
||||
}{
|
||||
// Valid case: all inputs correct
|
||||
collection := &core.Collection{}
|
||||
devices_success := []Device{
|
||||
{
|
||||
name: "Valid Case",
|
||||
ip: "192.168.1.100",
|
||||
mac: "00:11:22:33:44:55",
|
||||
netmask: "255.255.255.0",
|
||||
password: "secret",
|
||||
wantError: false,
|
||||
IP: "8.8.8.8",
|
||||
MAC: "aa:aa:aa:aa:aa:aa",
|
||||
Netmask: "255.0.0.0",
|
||||
Password: "",
|
||||
},
|
||||
// Invalid MAC address
|
||||
{
|
||||
name: "Invalid MAC",
|
||||
ip: "192.168.1.100",
|
||||
mac: "invalid",
|
||||
netmask: "255.255.255.0",
|
||||
password: "secret",
|
||||
wantError: true,
|
||||
},
|
||||
// Password too short
|
||||
{
|
||||
name: "Password Too Short",
|
||||
ip: "192.168.1.100",
|
||||
mac: "00:11:22:33:44:55",
|
||||
netmask: "255.255.255.0",
|
||||
password: "s", // length 1
|
||||
wantError: true,
|
||||
},
|
||||
// Password too long
|
||||
{
|
||||
name: "Password Too Long",
|
||||
ip: "192.168.1.100",
|
||||
mac: "00:11:22:33:44:55",
|
||||
netmask: "255.255.255.0",
|
||||
password: "password", // length 9
|
||||
wantError: true,
|
||||
},
|
||||
// Invalid IP address
|
||||
{
|
||||
name: "Invalid IP",
|
||||
ip: "256.1.1.1", // invalid
|
||||
mac: "00:11:22:33:44:55",
|
||||
netmask: "255.255.255.0",
|
||||
password: "secret",
|
||||
wantError: true,
|
||||
},
|
||||
// Invalid netmask
|
||||
{
|
||||
name: "Invalid Netmask",
|
||||
ip: "192.168.1.100",
|
||||
mac: "00:11:22:33:44:55",
|
||||
netmask: "300.255.255.0", // invalid
|
||||
password: "secret",
|
||||
wantError: true,
|
||||
IP: "1.1.1.1",
|
||||
MAC: "bb:bb:bb:bb:bb:bb",
|
||||
Netmask: "255.255.0.0",
|
||||
Password: "abcd",
|
||||
},
|
||||
}
|
||||
|
||||
collection := &core.Collection{}
|
||||
devices_fail := []Device{
|
||||
{
|
||||
IP: "1.1.1.1",
|
||||
MAC: "aa",
|
||||
Netmask: "255.255.0.0",
|
||||
Password: "abcd",
|
||||
},
|
||||
{
|
||||
IP: "1.1.1.1",
|
||||
MAC: "cc:cc:cc:cc:cc:cc",
|
||||
Netmask: "255.255.0.0",
|
||||
Password: "abcdefg",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
device := core.NewRecord(collection)
|
||||
device.Set("ip", tc.ip)
|
||||
device.Set("mac", tc.mac)
|
||||
device.Set("netmask", tc.netmask)
|
||||
device.Set("password", tc.password)
|
||||
for _, v := range devices_success {
|
||||
device := core.NewRecord(collection)
|
||||
device.Set("ip", v.IP)
|
||||
device.Set("mac", v.MAC)
|
||||
device.Set("netmask", v.Netmask)
|
||||
device.Set("password", v.Password)
|
||||
|
||||
err := SendMagicPacket(device)
|
||||
if tc.wantError {
|
||||
if err == nil {
|
||||
t.Errorf("Expected error but got none")
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Errorf("Got unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
})
|
||||
if err := SendMagicPacket(device); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for _, v := range devices_fail {
|
||||
device := core.NewRecord(collection)
|
||||
device.Set("ip", v.IP)
|
||||
device.Set("mac", v.MAC)
|
||||
device.Set("netmask", v.Netmask)
|
||||
device.Set("password", v.Password)
|
||||
|
||||
if err := SendMagicPacket(device); err == nil {
|
||||
t.Fatal("should have cause an error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWakeUDP(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
ip string
|
||||
broadcastIp string
|
||||
targetMac string
|
||||
password string
|
||||
wantError bool
|
||||
}{
|
||||
// Valid case: all inputs correct
|
||||
devices := []Device{
|
||||
{
|
||||
name: "Valid Case",
|
||||
ip: "192.168.1.10",
|
||||
broadcastIp: "192.168.1.255",
|
||||
targetMac: "00:11:22:33:44:55",
|
||||
password: "secret",
|
||||
wantError: false,
|
||||
IP: "8.8.8.8",
|
||||
MAC: "aa:aa:aa:aa:aa:aa",
|
||||
Netmask: "255.0.0.0",
|
||||
Password: "",
|
||||
ExpectFailPassword: false,
|
||||
},
|
||||
// Invalid MAC address
|
||||
{
|
||||
name: "Invalid MAC",
|
||||
ip: "192.168.1.10",
|
||||
broadcastIp: "192.168.1.255",
|
||||
targetMac: "invalid",
|
||||
password: "secret",
|
||||
wantError: true,
|
||||
IP: "1.1.1.1",
|
||||
MAC: "bb:bb:bb:bb:bb:bb",
|
||||
Netmask: "255.255.0.0",
|
||||
Password: "abcd",
|
||||
ExpectFailPassword: false,
|
||||
},
|
||||
// Password too short
|
||||
{
|
||||
name: "Password Too Short",
|
||||
ip: "192.168.1.10",
|
||||
broadcastIp: "192.168.1.255",
|
||||
targetMac: "00:11:22:33:44:55",
|
||||
password: "s", // length 1
|
||||
wantError: true,
|
||||
IP: "10.10.10.1",
|
||||
MAC: "cc:cc:cc:cc:cc:cc",
|
||||
Netmask: "255.255.0.0",
|
||||
Password: "abcd",
|
||||
ExpectFailPassword: false,
|
||||
},
|
||||
// Password too long
|
||||
{
|
||||
name: "Password Too Long",
|
||||
ip: "192.168.1.10",
|
||||
broadcastIp: "192.168.1.255",
|
||||
targetMac: "00:11:22:33:44:55",
|
||||
password: "password", // length 9
|
||||
wantError: true,
|
||||
IP: "1.1.1.1",
|
||||
MAC: "dd:dd:dd:dd:dd:dd",
|
||||
Netmask: "255.255.0.0",
|
||||
Password: "abcdefg",
|
||||
ExpectFailPassword: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
mac, err := net.ParseMAC(tc.targetMac)
|
||||
if err != nil && !tc.wantError {
|
||||
t.Errorf("Unexpected error parsing MAC: %v", err)
|
||||
} else if err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range devices {
|
||||
parsedMac, err := net.ParseMAC(v.MAC)
|
||||
if err != nil {
|
||||
t.Fatalf(`%v (parsedMac "%v")`, err, parsedMac)
|
||||
}
|
||||
|
||||
// Now test the wakeUDP function
|
||||
err = wakeUDP(tc.broadcastIp, tc.ip, mac, []byte(tc.password))
|
||||
if tc.wantError {
|
||||
if err == nil {
|
||||
t.Errorf("Expected error but got none")
|
||||
}
|
||||
}
|
||||
})
|
||||
var bytePassword []byte
|
||||
if len(v.Password) == 0 || len(v.Password) == 4 || len(v.Password) == 6 {
|
||||
bytePassword = []byte(v.Password)
|
||||
} else if !v.ExpectFailPassword {
|
||||
t.Fatal("password must be 0, 4 or 6 characters long")
|
||||
}
|
||||
|
||||
broadcastIp, err := getBroadcastIp(v.IP, v.Netmask)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := wakeUDP(broadcastIp, parsedMac, bytePassword); err != nil {
|
||||
t.Fatalf(`%v (broadcastIp "%v", parsedMac "%v", bytePassword "%v")`, err, broadcastIp, parsedMac, bytePassword)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetBroadcastIp(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
ip string
|
||||
netmask string
|
||||
wantIp string
|
||||
wantError bool
|
||||
}{
|
||||
// Valid case: all inputs correct
|
||||
type address struct {
|
||||
IP string
|
||||
Netmask string
|
||||
BroadcastResult string
|
||||
}
|
||||
|
||||
addresses := []address{
|
||||
{
|
||||
name: "Valid Case",
|
||||
ip: "192.168.1.100",
|
||||
netmask: "255.255.255.0",
|
||||
wantIp: "192.168.1.255",
|
||||
wantError: false,
|
||||
},
|
||||
// Invalid IP address
|
||||
{
|
||||
name: "Invalid IP",
|
||||
ip: "256.1.1.1", // invalid
|
||||
netmask: "255.255.255.0",
|
||||
wantIp: "",
|
||||
wantError: true,
|
||||
},
|
||||
// Invalid netmask
|
||||
{
|
||||
name: "Invalid Netmask",
|
||||
ip: "192.168.1.100",
|
||||
netmask: "300.255.255.0", // invalid
|
||||
wantIp: "",
|
||||
wantError: true,
|
||||
IP: "192.168.0.1",
|
||||
Netmask: "255.255.255.0",
|
||||
BroadcastResult: "192.168.0.255",
|
||||
}, {
|
||||
IP: "10.1.1.1",
|
||||
Netmask: "255.255.0.0",
|
||||
BroadcastResult: "10.1.255.255",
|
||||
}, {
|
||||
IP: "10.2.3.4",
|
||||
Netmask: "255.0.0.0",
|
||||
BroadcastResult: "10.255.255.255",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
ip := net.ParseIP(tc.ip)
|
||||
if ip == nil && !tc.wantError {
|
||||
t.Errorf("Unexpected error parsing IP: %v", ip)
|
||||
} else if ip == nil {
|
||||
return
|
||||
}
|
||||
|
||||
mask := net.ParseIP(tc.netmask)
|
||||
if mask == nil && !tc.wantError {
|
||||
t.Errorf("Unexpected error parsing netmask: %v", mask)
|
||||
} else if mask == nil {
|
||||
return
|
||||
}
|
||||
|
||||
broadcast, err := getBroadcastIp(tc.ip, tc.netmask)
|
||||
if tc.wantError {
|
||||
if err == nil {
|
||||
t.Errorf("Expected error but got none")
|
||||
}
|
||||
} else {
|
||||
if broadcast != tc.wantIp {
|
||||
t.Errorf("Broadcast IP mismatch: expected %s, got %s", tc.wantIp, broadcast)
|
||||
}
|
||||
}
|
||||
})
|
||||
for _, v := range addresses {
|
||||
broadcast, err := getBroadcastIp(v.IP, v.Netmask)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if broadcast != v.BroadcastResult {
|
||||
t.Fatalf(`getBroadcastIp("%v, %v"), want %v, got %v`, v.IP, v.Netmask, v.BroadcastResult, broadcast)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,68 @@
|
||||
package networking
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"os"
|
||||
"syscall"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
probing "github.com/prometheus-community/pro-bing"
|
||||
"github.com/seriousm4x/upsnap/logger"
|
||||
)
|
||||
|
||||
func isNoRouteOrDownError(err error) bool {
|
||||
opErr, ok := err.(*net.OpError)
|
||||
if !ok {
|
||||
return false
|
||||
func PingDevice(device *core.Record) bool {
|
||||
ping_cmd := device.GetString("ping_cmd")
|
||||
if ping_cmd == "" {
|
||||
pinger, err := probing.NewPinger(device.GetString("ip"))
|
||||
if err != nil {
|
||||
logger.Error.Println(err)
|
||||
return false
|
||||
}
|
||||
pinger.Count = 1
|
||||
pinger.Timeout = 500 * time.Millisecond
|
||||
privileged, err := strconv.ParseBool(os.Getenv("UPSNAP_PING_PRIVILEGED"))
|
||||
if err != nil {
|
||||
privileged = true
|
||||
}
|
||||
pinger.SetPrivileged(privileged)
|
||||
err = pinger.Run()
|
||||
if err != nil {
|
||||
logger.Error.Println(err)
|
||||
return false
|
||||
}
|
||||
stats := pinger.Statistics()
|
||||
if stats.PacketLoss > 0 {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
var shell string
|
||||
var shell_arg string
|
||||
if runtime.GOOS == "windows" {
|
||||
shell = "cmd"
|
||||
shell_arg = "/C"
|
||||
} else {
|
||||
shell = "/bin/sh"
|
||||
shell_arg = "-c"
|
||||
}
|
||||
|
||||
cmd := exec.Command(shell, shell_arg, ping_cmd)
|
||||
err := cmd.Run()
|
||||
|
||||
return err == nil
|
||||
}
|
||||
syscallErr, ok := opErr.Err.(*os.SyscallError)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return syscallErr.Err == syscall.EHOSTUNREACH || syscallErr.Err == syscall.EHOSTDOWN
|
||||
}
|
||||
|
||||
func CheckPort(host string, port string) (bool, error) {
|
||||
func CheckPort(host string, port string) bool {
|
||||
timeout := 500 * time.Millisecond
|
||||
conn, err := net.DialTimeout("tcp", net.JoinHostPort(host, port), timeout)
|
||||
if err != nil {
|
||||
// treat "host unreachable", "connection refused" and "timeout" as no error
|
||||
if netErr, ok := errors.AsType[*net.OpError](err); ok {
|
||||
if errors.Is(netErr.Err, syscall.EHOSTUNREACH) ||
|
||||
errors.Is(netErr.Err, syscall.ECONNREFUSED) ||
|
||||
netErr.Timeout() {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return false, err
|
||||
return false
|
||||
}
|
||||
defer conn.Close()
|
||||
return conn != nil, nil
|
||||
return conn != nil
|
||||
}
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
package networking
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
func TestPingDevice(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
ip string
|
||||
ping_cmd string
|
||||
wantError bool
|
||||
}{
|
||||
// Valid case: all inputs correct
|
||||
{
|
||||
name: "Valid Case",
|
||||
ip: "8.8.8.8",
|
||||
ping_cmd: "exit 0",
|
||||
wantError: false,
|
||||
},
|
||||
// Invalid ping command
|
||||
{
|
||||
name: "Invalid Ping Command",
|
||||
ip: "8.8.8.8",
|
||||
ping_cmd: "exit 1",
|
||||
wantError: false,
|
||||
},
|
||||
}
|
||||
|
||||
collection := &core.Collection{}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
device := core.NewRecord(collection)
|
||||
device.Set("ip", tc.ip)
|
||||
device.Set("ping_cmd", tc.ping_cmd)
|
||||
|
||||
_, err := PingDevice(device)
|
||||
if err == nil && tc.wantError {
|
||||
t.Errorf("Expected error but got none")
|
||||
} else if err != nil && !tc.wantError {
|
||||
t.Errorf("Got unexpected error: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckPort(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
host string
|
||||
port string
|
||||
wantError bool
|
||||
}{
|
||||
// Valid case: all inputs correct
|
||||
{
|
||||
name: "Valid Case",
|
||||
host: "0.0.0.0",
|
||||
port: "443",
|
||||
wantError: false,
|
||||
},
|
||||
// Invalid IP address
|
||||
{
|
||||
name: "Invalid IP",
|
||||
host: "256.1.1.1", // invalid
|
||||
port: "443",
|
||||
wantError: true,
|
||||
},
|
||||
// Invalid port number
|
||||
{
|
||||
name: "Invalid Port",
|
||||
host: "0.0.0.0",
|
||||
port: "70000", // invalid
|
||||
wantError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
_, err := CheckPort(tc.host, tc.port)
|
||||
if err == nil && tc.wantError {
|
||||
t.Errorf("Expected error but got none")
|
||||
} else if err != nil && !tc.wantError {
|
||||
t.Errorf("Got unexpected error: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
//go:build linux
|
||||
|
||||
package networking
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
probing "github.com/prometheus-community/pro-bing"
|
||||
"kernel.org/pub/linux/libs/security/libcap/cap"
|
||||
)
|
||||
|
||||
func PingDevice(device *core.Record) (bool, error) {
|
||||
ping_cmd := device.GetString("ping_cmd")
|
||||
if ping_cmd == "" {
|
||||
ip, err := ResolveToIPAddr(device.GetString("ip"))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if ip == "" {
|
||||
return false, nil
|
||||
}
|
||||
pinger, err := probing.NewPinger(ip)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
pinger.Count = 1
|
||||
pinger.Timeout = 500 * time.Millisecond
|
||||
|
||||
privileged := true
|
||||
privilegedEnv := os.Getenv("UPSNAP_PING_PRIVILEGED")
|
||||
if privilegedEnv != "" {
|
||||
privileged, err = strconv.ParseBool(privilegedEnv)
|
||||
if err != nil {
|
||||
privileged = false
|
||||
}
|
||||
}
|
||||
if privileged {
|
||||
orig := cap.GetProc()
|
||||
defer orig.SetProc() // restore original caps on exit.
|
||||
|
||||
c, err := orig.Dup()
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("Failed to dup existing capabilities: %v", err)
|
||||
}
|
||||
|
||||
if on, _ := c.GetFlag(cap.Permitted, cap.NET_RAW); !on {
|
||||
return false, fmt.Errorf("Privileged ping selected but NET_RAW capability not permitted")
|
||||
}
|
||||
|
||||
if err := c.SetFlag(cap.Effective, true, cap.NET_RAW); err != nil {
|
||||
return false, fmt.Errorf("unable to set NET_RAW capability")
|
||||
}
|
||||
|
||||
if err := c.SetProc(); err != nil {
|
||||
return false, fmt.Errorf("unable to raise NET_RAW capability")
|
||||
}
|
||||
}
|
||||
pinger.SetPrivileged(privileged)
|
||||
|
||||
err = pinger.Run()
|
||||
if err != nil {
|
||||
if isNoRouteOrDownError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
stats := pinger.Statistics()
|
||||
return stats.PacketLoss == 0, nil
|
||||
} else {
|
||||
var shell string
|
||||
var shell_arg string
|
||||
|
||||
shell = "/bin/sh"
|
||||
shell_arg = "-c"
|
||||
|
||||
cmd := exec.Command(shell, shell_arg, ping_cmd)
|
||||
err := cmd.Run()
|
||||
|
||||
if err != nil {
|
||||
if _, ok := err.(*exec.ExitError); ok {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
//go:build !linux
|
||||
|
||||
package networking
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
probing "github.com/prometheus-community/pro-bing"
|
||||
)
|
||||
|
||||
func PingDevice(device *core.Record) (bool, error) {
|
||||
ping_cmd := device.GetString("ping_cmd")
|
||||
if ping_cmd == "" {
|
||||
ip, err := ResolveToIPAddr(device.GetString("ip"))
|
||||
if err != nil || ip == "" {
|
||||
return false, err
|
||||
}
|
||||
pinger, err := probing.NewPinger(ip)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
pinger.Count = 1
|
||||
pinger.Timeout = 500 * time.Millisecond
|
||||
|
||||
privileged := true // default to privileged ping, required by Windows
|
||||
if runtime.GOOS == "darwin" {
|
||||
// macOS pings will fail when using privileged ping as non root, but works with non-privileged.
|
||||
privileged = false
|
||||
}
|
||||
privilegedEnv := os.Getenv("UPSNAP_PING_PRIVILEGED")
|
||||
if privilegedEnv != "" {
|
||||
privileged, err = strconv.ParseBool(privilegedEnv)
|
||||
if err != nil {
|
||||
privileged = false
|
||||
}
|
||||
}
|
||||
pinger.SetPrivileged(privileged)
|
||||
|
||||
err = pinger.Run()
|
||||
if err != nil {
|
||||
if isNoRouteOrDownError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
stats := pinger.Statistics()
|
||||
return stats.PacketLoss == 0, nil
|
||||
} else {
|
||||
var shell string
|
||||
var shell_arg string
|
||||
if runtime.GOOS == "windows" {
|
||||
shell = "cmd"
|
||||
shell_arg = "/C"
|
||||
} else {
|
||||
shell = "/bin/sh"
|
||||
shell_arg = "-c"
|
||||
}
|
||||
|
||||
cmd := exec.Command(shell, shell_arg, ping_cmd)
|
||||
err := cmd.Run()
|
||||
|
||||
if err != nil {
|
||||
if _, ok := err.(*exec.ExitError); ok {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
//go:build windows || darwin
|
||||
|
||||
package networking
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
Takes one parameter 'host' and returns its IP. If 'host' is already formatted
|
||||
as an IP, simply return it. If 'host' is formatted as an FQDN, attempt to
|
||||
resolve it with mDNS (if .local suffix) or else use a DNS lookup with
|
||||
net.DefaultResolver
|
||||
|
||||
Windows and MacOS can resolve mDNS/DNS with one call to net.DefaultResolver
|
||||
*/
|
||||
func ResolveToIPAddr(host string) (string, error) {
|
||||
// If host is already an IP, simply return it
|
||||
addr, err := netip.ParseAddr(host)
|
||||
if err == nil && addr.Is4() {
|
||||
return host, nil
|
||||
}
|
||||
if err := ValidateFQDN(host); err != nil {
|
||||
return "", fmt.Errorf("%q is the host", host)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
ips, err := net.DefaultResolver.LookupNetIP(ctx, "ip4", host)
|
||||
if err != nil {
|
||||
if strings.HasSuffix(strings.ToLower(host), ".local") {
|
||||
var dnsErr *net.DNSError
|
||||
isNotFound := errors.As(err, &dnsErr) && dnsErr.IsNotFound
|
||||
isTimeout := errors.Is(err, context.DeadlineExceeded) || ctx.Err() == context.DeadlineExceeded
|
||||
if isTimeout || isNotFound {
|
||||
return "", nil
|
||||
}
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
if len(ips) > 0 {
|
||||
// only return one result
|
||||
return ips[0].String(), nil
|
||||
}
|
||||
// No results, but it's expected for a .local FQDN device that is offline. Don't return an error.
|
||||
if strings.HasSuffix(strings.ToLower(host), ".local") {
|
||||
return "", nil
|
||||
} else {
|
||||
// No results, but FQDN should have resolved since it's not .local. Return an error.
|
||||
return "", fmt.Errorf("No IP address found for %s", host)
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
//go:build linux || freebsd
|
||||
|
||||
package networking
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/godbus/dbus/v5"
|
||||
"github.com/holoplot/go-avahi"
|
||||
)
|
||||
|
||||
var (
|
||||
avahiServer *avahi.Server
|
||||
avahiErr error
|
||||
avahiOnce sync.Once
|
||||
)
|
||||
|
||||
// getAvahiServer initializes and returns a shared, long-lived Avahi client.
|
||||
// It handles high throughput gracefully by using a single D-Bus socket connection.
|
||||
func getAvahiServer() (*avahi.Server, error) {
|
||||
avahiOnce.Do(func() {
|
||||
// Using the cached system bus here is safe because we never call server.Close() on it.
|
||||
conn, err := dbus.SystemBus()
|
||||
if err != nil {
|
||||
avahiErr = fmt.Errorf("failed to connect to dbus: %w", err)
|
||||
return
|
||||
}
|
||||
server, err := avahi.ServerNew(conn)
|
||||
if err != nil {
|
||||
avahiErr = fmt.Errorf("failed to create avahi server: %w", err)
|
||||
return
|
||||
}
|
||||
avahiServer = server
|
||||
})
|
||||
return avahiServer, avahiErr
|
||||
}
|
||||
|
||||
/*
|
||||
Takes one parameter 'host' and returns its IP. If 'host' is already formatted
|
||||
as an IP, simply return it. If 'host' is formatted as an FQDN, attempt to
|
||||
resolve it with mDNS (if .local suffix) or else use a DNS lookup with
|
||||
net.DefaultResolver
|
||||
|
||||
Linux and FreeBSD require dbus and avahi for mDNS lookups
|
||||
*/
|
||||
func ResolveToIPAddr(host string) (string, error) {
|
||||
// If host is already an IP, simply return it
|
||||
addr, err := netip.ParseAddr(host)
|
||||
if err == nil && addr.Is4() {
|
||||
return host, nil
|
||||
}
|
||||
if err := ValidateFQDN(host); err != nil {
|
||||
return "", err
|
||||
}
|
||||
// attempt mDNS query first
|
||||
if strings.HasSuffix(strings.ToLower(host), ".local") {
|
||||
// conn, err := dbus.Dial("unix:path=/var/run/dbus/system_bus_socket")
|
||||
server, err := getAvahiServer()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Failed to create connection: %w", err)
|
||||
}
|
||||
// defer conn.Close()
|
||||
|
||||
// server, err := avahi.ServerNew(conn)
|
||||
// if err != nil {
|
||||
// return "", fmt.Errorf("Failed to create avahi server: %w", err)
|
||||
// }
|
||||
// defer server.Close()
|
||||
|
||||
// set a context with 2 secs and only wait that long for an mDNS response. otherwise, avahi takes 5 secs
|
||||
ctx1, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
|
||||
type result struct {
|
||||
address string
|
||||
err error
|
||||
}
|
||||
ch := make(chan result, 1)
|
||||
|
||||
go func() {
|
||||
resolved, err := server.ResolveHostName(
|
||||
avahi.InterfaceUnspec,
|
||||
avahi.ProtoInet,
|
||||
host,
|
||||
avahi.ProtoInet,
|
||||
0,
|
||||
)
|
||||
if err != nil {
|
||||
ch <- result{"", err}
|
||||
return
|
||||
}
|
||||
// mDNS result received
|
||||
ch <- result{resolved.Address, nil}
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-ctx1.Done():
|
||||
// 2 second timeout reached,
|
||||
return "", nil
|
||||
|
||||
case res := <-ch:
|
||||
if res.err != nil {
|
||||
var dbusErr *dbus.Error
|
||||
// in theory we shouldn't encounter this error since the 2 second context always beats the race
|
||||
if errors.As(res.err, &dbusErr) && dbusErr.Name == "org.freedesktop.Avahi.TimeoutError" {
|
||||
return "", nil
|
||||
}
|
||||
return "", fmt.Errorf("%s: %w", host, res.err)
|
||||
}
|
||||
return res.address, nil
|
||||
}
|
||||
}
|
||||
// Not .local, attempt unicast (regular) DNS lookup
|
||||
ctx2, cancel2 := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel2()
|
||||
ips, err := net.DefaultResolver.LookupNetIP(ctx2, "ip4", host)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(ips) > 0 {
|
||||
// only return one result
|
||||
return ips[0].String(), nil
|
||||
}
|
||||
// No results, but FQDN should have resolved since it's not .local. Return an error.
|
||||
return "", err
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package networking
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
type Nmaprun struct {
|
||||
Host []struct {
|
||||
Address []struct {
|
||||
Addr string `xml:"addr,attr" binding:"required"`
|
||||
Addrtype string `xml:"addrtype,attr" binding:"required"`
|
||||
Vendor string `xml:"vendor,attr"`
|
||||
} `xml:"address"`
|
||||
} `xml:"host"`
|
||||
}
|
||||
|
||||
// MacToIP maps each scanned host's normalized mac address to its ipv4
|
||||
// address, skipping hosts that lack either.
|
||||
func (n Nmaprun) MacToIP() map[string]string {
|
||||
macToIp := make(map[string]string)
|
||||
for _, host := range n.Host {
|
||||
var hostIp, hostMac string
|
||||
for _, addr := range host.Address {
|
||||
switch addr.Addrtype {
|
||||
case "ipv4":
|
||||
hostIp = addr.Addr
|
||||
case "mac":
|
||||
hostMac = addr.Addr
|
||||
}
|
||||
}
|
||||
if parsedMac, err := net.ParseMAC(hostMac); hostIp != "" && err == nil {
|
||||
macToIp[parsedMac.String()] = hostIp
|
||||
}
|
||||
}
|
||||
return macToIp
|
||||
}
|
||||
|
||||
func runNmap(scanRange string) (Nmaprun, error) {
|
||||
nmapOutput := Nmaprun{}
|
||||
|
||||
nmap, err := exec.LookPath("nmap")
|
||||
if err != nil {
|
||||
return nmapOutput, err
|
||||
}
|
||||
|
||||
timeout := os.Getenv("UPSNAP_SCAN_TIMEOUT")
|
||||
if timeout == "" {
|
||||
timeout = "500ms"
|
||||
}
|
||||
|
||||
cmd := exec.Command(nmap, "-sn", "-oX", "-", scanRange, "--host-timeout", timeout, "--privileged")
|
||||
cmdOutput, err := cmd.Output()
|
||||
if err != nil {
|
||||
return nmapOutput, err
|
||||
}
|
||||
|
||||
if err := xml.Unmarshal(cmdOutput, &nmapOutput); err != nil {
|
||||
return nmapOutput, err
|
||||
}
|
||||
|
||||
return nmapOutput, nil
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
//go:build linux
|
||||
|
||||
package networking
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"kernel.org/pub/linux/libs/security/libcap/cap"
|
||||
)
|
||||
|
||||
func NmapScan(scanRange string) (Nmaprun, error) {
|
||||
orig := cap.GetProc()
|
||||
defer orig.SetProc() // restore original caps on exit.
|
||||
|
||||
c, err := orig.Dup()
|
||||
if err != nil {
|
||||
return Nmaprun{}, fmt.Errorf("Failed to dup existing capabilities: %v", err)
|
||||
}
|
||||
|
||||
if on, _ := c.GetFlag(cap.Permitted, cap.NET_RAW); !on {
|
||||
return Nmaprun{}, fmt.Errorf("unable to get NET_RAW permissions")
|
||||
}
|
||||
|
||||
if err := c.SetFlag(cap.Effective, true, cap.NET_RAW); err != nil {
|
||||
return Nmaprun{}, fmt.Errorf("unable to set NET_RAW capability effective")
|
||||
}
|
||||
|
||||
if err := c.SetFlag(cap.Inheritable, true, cap.NET_RAW); err != nil {
|
||||
return Nmaprun{}, fmt.Errorf("unable to set NET_RAW capability inheritable")
|
||||
}
|
||||
|
||||
if err := c.SetProc(); err != nil {
|
||||
return Nmaprun{}, fmt.Errorf("unable to raise NET_RAW capability")
|
||||
}
|
||||
|
||||
if err := cap.SetAmbient(true, cap.NET_RAW); err != nil {
|
||||
return Nmaprun{}, fmt.Errorf("unable to set NET_RAW capability ambient")
|
||||
}
|
||||
|
||||
return runNmap(scanRange)
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
//go:build !linux
|
||||
|
||||
package networking
|
||||
|
||||
func NmapScan(scanRange string) (Nmaprun, error) {
|
||||
return runNmap(scanRange)
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package networking
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Trimmed from real `nmap -sn -oX -` output: one host with a mac (scanned
|
||||
// with raw socket privileges), one without (the scanning host itself).
|
||||
const nmapSample = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<nmaprun scanner="nmap" args="nmap -sn -oX - 10.1.10.0/24" version="7.94">
|
||||
<host><status state="up" reason="arp-response"/>
|
||||
<address addr="10.1.10.1" addrtype="ipv4"/>
|
||||
<address addr="AA:BB:CC:DD:EE:FF" addrtype="mac" vendor="Ubiquiti Networks"/>
|
||||
<hostnames></hostnames>
|
||||
</host>
|
||||
<host><status state="up" reason="localhost-response"/>
|
||||
<address addr="10.1.10.9" addrtype="ipv4"/>
|
||||
<hostnames></hostnames>
|
||||
</host>
|
||||
<runstats><finished time="1754000000" exit="success"/></runstats>
|
||||
</nmaprun>`
|
||||
|
||||
func TestNmaprunUnmarshal(t *testing.T) {
|
||||
nmapOutput := Nmaprun{}
|
||||
if err := xml.Unmarshal([]byte(nmapSample), &nmapOutput); err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(nmapOutput.Host) != 2 {
|
||||
t.Fatalf("Host count mismatch: expected 2, got %d", len(nmapOutput.Host))
|
||||
}
|
||||
|
||||
first := nmapOutput.Host[0].Address
|
||||
if len(first) != 2 {
|
||||
t.Fatalf("Address count mismatch: expected 2, got %d", len(first))
|
||||
}
|
||||
if first[0].Addrtype != "ipv4" || first[0].Addr != "10.1.10.1" {
|
||||
t.Errorf("Unexpected ipv4 address: %+v", first[0])
|
||||
}
|
||||
if first[1].Addrtype != "mac" || first[1].Addr != "AA:BB:CC:DD:EE:FF" || first[1].Vendor != "Ubiquiti Networks" {
|
||||
t.Errorf("Unexpected mac address: %+v", first[1])
|
||||
}
|
||||
|
||||
second := nmapOutput.Host[1].Address
|
||||
if len(second) != 1 || second[0].Addrtype != "ipv4" {
|
||||
t.Errorf("Unexpected addresses for mac-less host: %+v", second)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNmaprunMacToIP(t *testing.T) {
|
||||
nmapOutput := Nmaprun{}
|
||||
if err := xml.Unmarshal([]byte(nmapSample), &nmapOutput); err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
|
||||
macToIp := nmapOutput.MacToIP()
|
||||
if len(macToIp) != 1 {
|
||||
t.Fatalf("Entry count mismatch: expected 1, got %d", len(macToIp))
|
||||
}
|
||||
// the mac address is normalized to lower case, the mac-less host is skipped
|
||||
if ip := macToIp["aa:bb:cc:dd:ee:ff"]; ip != "10.1.10.1" {
|
||||
t.Errorf("Unexpected ip for aa:bb:cc:dd:ee:ff: %q", ip)
|
||||
}
|
||||
}
|
||||
@@ -4,22 +4,19 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
"github.com/seriousm4x/upsnap/logging"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/seriousm4x/upsnap/logger"
|
||||
)
|
||||
|
||||
func ShutdownDevice(app core.App, device *core.Record, trigger string) error {
|
||||
log := logging.Logger(app)
|
||||
log.Info("Shutdown triggered", "device", device.GetString("name"), "trigger", trigger)
|
||||
func ShutdownDevice(device *core.Record) error {
|
||||
logger.Info.Println("Shutdown triggered for", device.GetString("name"))
|
||||
shutdown_cmd := device.GetString("shutdown_cmd")
|
||||
if shutdown_cmd == "" {
|
||||
return fmt.Errorf("%s: no shutdown_cmd defined", device.GetString("name"))
|
||||
return fmt.Errorf("%s: no shutdown_cmd definded", device.GetString("name"))
|
||||
}
|
||||
|
||||
var shell string
|
||||
@@ -32,20 +29,6 @@ func ShutdownDevice(app core.App, device *core.Record, trigger string) error {
|
||||
shell_arg = "-c"
|
||||
}
|
||||
|
||||
// Validate IP or resolve FQDN to IP
|
||||
deviceIP, err := ResolveToIPAddr(device.GetString("ip"))
|
||||
if err != nil || deviceIP == "" {
|
||||
return fmt.Errorf("Unable to resolve %s to an IP address", device.GetString("ip"))
|
||||
}
|
||||
// Validate MAC address before replacing placeholder to prevent command injection
|
||||
deviceMAC := device.GetString("mac")
|
||||
if _, err := net.ParseMAC(deviceMAC); err != nil {
|
||||
return fmt.Errorf("invalid device MAC address: %q", deviceMAC)
|
||||
}
|
||||
|
||||
shutdown_cmd = strings.ReplaceAll(shutdown_cmd, "{{ DEVICE_IP }}", deviceIP)
|
||||
shutdown_cmd = strings.ReplaceAll(shutdown_cmd, "{{ DEVICE_MAC }}", deviceMAC)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
@@ -57,7 +40,7 @@ func ShutdownDevice(app core.App, device *core.Record, trigger string) error {
|
||||
cmd.Stderr = &stderr
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return err
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
|
||||
done := make(chan error, 1)
|
||||
@@ -65,55 +48,31 @@ func ShutdownDevice(app core.App, device *core.Record, trigger string) error {
|
||||
done <- cmd.Wait()
|
||||
}()
|
||||
|
||||
shutdownTimeout := device.GetInt("shutdown_timeout")
|
||||
if shutdownTimeout <= 0 {
|
||||
shutdownTimeout = 120
|
||||
}
|
||||
|
||||
// check state every seconds for 2 min
|
||||
start := time.Now()
|
||||
|
||||
for {
|
||||
select {
|
||||
case err := <-done:
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s", stderr.String())
|
||||
} else {
|
||||
for {
|
||||
isOnline, err := PingDevice(device)
|
||||
if err != nil {
|
||||
log.Error("Failed to ping device during shutdown", "error", err)
|
||||
return err
|
||||
}
|
||||
if isOnline {
|
||||
if time.Since(start) >= time.Duration(shutdownTimeout)*time.Second {
|
||||
return fmt.Errorf("%s not offline after %d seconds", device.GetString("name"), shutdownTimeout)
|
||||
}
|
||||
}
|
||||
if !isOnline {
|
||||
return nil
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
case <-time.After(1 * time.Second):
|
||||
if time.Since(start) >= 2*time.Minute {
|
||||
if err := KillProcess(cmd.Process); err != nil {
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
return fmt.Errorf("%s not offline after 2 minutes", device.GetString("name"))
|
||||
}
|
||||
default:
|
||||
isOnline, err := PingDevice(device)
|
||||
if err != nil {
|
||||
log.Error("Failed to ping device during shutdown", "error", err)
|
||||
return err
|
||||
}
|
||||
if time.Since(start) >= time.Duration(shutdownTimeout)*time.Second {
|
||||
if err := KillProcess(app, cmd.Process); err != nil {
|
||||
log.Error("Failed to kill shutdown command", "error", err)
|
||||
}
|
||||
return fmt.Errorf("%s not offline after %d seconds", device.GetString("name"), shutdownTimeout)
|
||||
}
|
||||
isOnline := PingDevice(device)
|
||||
if !isOnline {
|
||||
if err := KillProcess(app, cmd.Process); err != nil {
|
||||
log.Error("Failed to kill shutdown command", "error", err)
|
||||
if err := KillProcess(cmd.Process); err != nil {
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
case err := <-done:
|
||||
if err != nil {
|
||||
if err := KillProcess(cmd.Process); err != nil {
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
return fmt.Errorf("%s", stderr.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package networking
|
||||
|
||||
@@ -6,8 +7,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
"github.com/seriousm4x/upsnap/logging"
|
||||
"github.com/seriousm4x/upsnap/logger"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
@@ -17,8 +17,8 @@ func SetProcessAttributes(cmd *exec.Cmd) {
|
||||
}
|
||||
|
||||
// Kills child processes on Linux. Windows doesn't provide a direct way to kill child processes, so we kill just the main process.
|
||||
func KillProcess(app core.App, process *os.Process) error {
|
||||
logging.Logger(app).Warn("Command did not finish in time and will be killed")
|
||||
func KillProcess(process *os.Process) error {
|
||||
logger.Warning.Println("Your shutdown cmd didn't finish in 2 minutes. It will be killed.")
|
||||
pgid, err := unix.Getpgid(process.Pid)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -29,5 +29,7 @@ func KillProcess(app core.App, process *os.Process) error {
|
||||
return unix.Kill(-pgid, unix.SIGKILL)
|
||||
}
|
||||
|
||||
_, err = process.Wait()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package networking
|
||||
|
||||
@@ -6,8 +7,6 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
@@ -15,6 +14,6 @@ import (
|
||||
func SetProcessAttributes(cmd *exec.Cmd) {}
|
||||
|
||||
// Kills child processes on Linux. Windows doesn't provide a direct way to kill child processes, so we kill just the main process.
|
||||
func KillProcess(_ core.App, process *os.Process) error {
|
||||
func KillProcess(process *os.Process) error {
|
||||
return windows.GenerateConsoleCtrlEvent(windows.CTRL_BREAK_EVENT, uint32(process.Pid))
|
||||
}
|
||||
|
||||
@@ -7,29 +7,25 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
"github.com/seriousm4x/upsnap/logging"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/seriousm4x/upsnap/logger"
|
||||
)
|
||||
|
||||
type SolResponse struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func SleepDevice(app core.App, device *core.Record) (SolResponse, error) {
|
||||
logging.Logger(app).Info("Sleep triggered", "device", device.GetString("name"))
|
||||
func SleepDevice(device *core.Record) (SolResponse, error) {
|
||||
logger.Info.Println("Sleep triggered for", device.GetString("name"))
|
||||
|
||||
var solResp SolResponse
|
||||
var url string
|
||||
|
||||
deviceIP, err := ResolveToIPAddr(device.GetString("ip"))
|
||||
if err != nil || deviceIP == "" {
|
||||
return solResp, fmt.Errorf("Unable to resolve %s to an IP address: %w", device.GetString("ip"), err)
|
||||
}
|
||||
if device.GetBool("sol_auth") {
|
||||
url = fmt.Sprintf("http://%s:%s@%s:%d/sleep?format=JSON",
|
||||
device.GetString("sol_user"), device.GetString("sol_password"), deviceIP, device.GetInt("sol_port"))
|
||||
device.GetString("sol_user"), device.GetString("sol_password"), device.GetString("ip"), device.GetInt("sol_port"))
|
||||
} else {
|
||||
url = fmt.Sprintf("http://%s:%d/sleep?format=JSON", deviceIP, device.GetInt("sol_port"))
|
||||
url = fmt.Sprintf("http://%s:%d/sleep?format=JSON", device.GetString("ip"), device.GetInt("sol_port"))
|
||||
}
|
||||
|
||||
resp, err := http.Get(url)
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
package networking
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
)
|
||||
|
||||
// DeviceSubnet returns the device's IPv4 subnet computed from its ip and netmask.
|
||||
func DeviceSubnet(ipStr, maskStr string) (*net.IPNet, error) {
|
||||
ip := net.ParseIP(ipStr)
|
||||
if ip == nil || ip.To4() == nil {
|
||||
return nil, errors.New("ip not a valid ipv4 address")
|
||||
}
|
||||
ip = ip.To4()
|
||||
|
||||
mask := net.ParseIP(maskStr)
|
||||
if mask == nil || mask.To4() == nil {
|
||||
return nil, errors.New("subnet mask not a valid ipv4 address")
|
||||
}
|
||||
ipMask := net.IPMask(mask.To4())
|
||||
|
||||
return &net.IPNet{IP: ip.Mask(ipMask), Mask: ipMask}, nil
|
||||
}
|
||||
|
||||
// ValidateScannableSubnet returns nil if the subnet is suitable for an nmap
|
||||
// scan, or an error explaining why it isn't.
|
||||
func ValidateScannableSubnet(subnet *net.IPNet) error {
|
||||
ones, bits := subnet.Mask.Size()
|
||||
if ones == 0 && bits == 0 {
|
||||
// Size() returns 0,0 for a non-contiguous mask, which has no cidr
|
||||
// notation to hand to nmap
|
||||
return errors.New("netmask is not contiguous")
|
||||
}
|
||||
if ones == bits {
|
||||
return errors.New("a single address has nothing to scan")
|
||||
}
|
||||
if ones < 16 {
|
||||
return errors.New("subnets larger than a /16 take too long to scan")
|
||||
}
|
||||
|
||||
// arp only answers on-link, so the subnet must overlap one of the
|
||||
// host's attached ipv4 networks for a scan to find mac addresses
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, addr := range addrs {
|
||||
attached, ok := addr.(*net.IPNet)
|
||||
if !ok || attached.IP.To4() == nil {
|
||||
continue
|
||||
}
|
||||
// subnets are either disjoint or nested, so checking containment
|
||||
// in both directions covers overlap
|
||||
if attached.Contains(subnet.IP) || subnet.Contains(attached.IP) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New("subnet does not overlap a directly attached network")
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
package networking
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDeviceSubnet(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
ip string
|
||||
netmask string
|
||||
wantCidr string
|
||||
wantError bool
|
||||
}{
|
||||
// Valid case: address is masked down to the network
|
||||
{
|
||||
name: "Valid Case",
|
||||
ip: "192.168.1.100",
|
||||
netmask: "255.255.255.0",
|
||||
wantCidr: "192.168.1.0/24",
|
||||
wantError: false,
|
||||
},
|
||||
// Valid case: wider mask
|
||||
{
|
||||
name: "Valid /16",
|
||||
ip: "10.1.10.142",
|
||||
netmask: "255.255.0.0",
|
||||
wantCidr: "10.1.0.0/16",
|
||||
wantError: false,
|
||||
},
|
||||
// Valid case: host mask
|
||||
{
|
||||
name: "Valid /32",
|
||||
ip: "192.168.1.5",
|
||||
netmask: "255.255.255.255",
|
||||
wantCidr: "192.168.1.5/32",
|
||||
wantError: false,
|
||||
},
|
||||
// Invalid IP address
|
||||
{
|
||||
name: "Invalid IP",
|
||||
ip: "256.1.1.1", // invalid
|
||||
netmask: "255.255.255.0",
|
||||
wantCidr: "",
|
||||
wantError: true,
|
||||
},
|
||||
// Invalid netmask
|
||||
{
|
||||
name: "Invalid Netmask",
|
||||
ip: "192.168.1.100",
|
||||
netmask: "300.255.255.0", // invalid
|
||||
wantCidr: "",
|
||||
wantError: true,
|
||||
},
|
||||
// IPv6 address is not a valid device ip
|
||||
{
|
||||
name: "IPv6 IP",
|
||||
ip: "fe80::1",
|
||||
netmask: "255.255.255.0",
|
||||
wantCidr: "",
|
||||
wantError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
subnet, err := DeviceSubnet(tc.ip, tc.netmask)
|
||||
if tc.wantError {
|
||||
if err == nil {
|
||||
t.Errorf("Expected error but got none")
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Errorf("Got unexpected error: %v", err)
|
||||
} else if subnet.String() != tc.wantCidr {
|
||||
t.Errorf("Subnet mismatch: expected %s, got %s", tc.wantCidr, subnet.String())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateScannableSubnet(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
ip string
|
||||
netmask string
|
||||
wantError bool
|
||||
}{
|
||||
// A /32 has nothing to scan
|
||||
{
|
||||
name: "Host Mask",
|
||||
ip: "192.168.1.5",
|
||||
netmask: "255.255.255.255",
|
||||
wantError: true,
|
||||
},
|
||||
// A non-contiguous mask has no cidr notation to scan
|
||||
{
|
||||
name: "Non-contiguous Mask",
|
||||
ip: "10.0.1.5",
|
||||
netmask: "255.0.255.0",
|
||||
wantError: true,
|
||||
},
|
||||
// Anything larger than a /16 takes too long to scan
|
||||
{
|
||||
name: "Too Large",
|
||||
ip: "10.0.0.1",
|
||||
netmask: "255.0.0.0",
|
||||
wantError: true,
|
||||
},
|
||||
// The loopback address as a /16 is within limits and always attached
|
||||
{
|
||||
name: "Local /16",
|
||||
ip: "127.0.0.1",
|
||||
netmask: "255.255.0.0",
|
||||
wantError: false,
|
||||
},
|
||||
// A sub-block of the attached loopback /8 is on-link even though
|
||||
// it doesn't contain the host's own 127.0.0.1
|
||||
{
|
||||
name: "Nested In Attached",
|
||||
ip: "127.0.1.5",
|
||||
netmask: "255.255.255.0",
|
||||
wantError: false,
|
||||
},
|
||||
// TEST-NET-1 (RFC 5737) is never assigned to an interface
|
||||
{
|
||||
name: "No Overlap",
|
||||
ip: "192.0.2.1",
|
||||
netmask: "255.255.255.0",
|
||||
wantError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
subnet, err := DeviceSubnet(tc.ip, tc.netmask)
|
||||
if err != nil {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
if err := ValidateScannableSubnet(subnet); (err != nil) != tc.wantError {
|
||||
t.Errorf("ValidateScannableSubnet(%s): expected error=%v, got %v", subnet.String(), tc.wantError, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package networking
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/idna"
|
||||
)
|
||||
|
||||
var fqdnRegex = regexp.MustCompile(`^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z0-9-]{2,63}$`)
|
||||
|
||||
/*
|
||||
Validate's FQDN by converting it to Punycode and checking it against several criteria
|
||||
*/
|
||||
func ValidateFQDN(host string) error {
|
||||
// Remove trailing . just in case, but DB and form validation should already prevent that
|
||||
trimmedHost := strings.TrimSuffix(host, ".")
|
||||
if len(trimmedHost) == 0 {
|
||||
return fmt.Errorf("%q: invalid length of 0. original %q", trimmedHost, host)
|
||||
}
|
||||
|
||||
// convert to punycode
|
||||
punycodeHost, err := idna.Lookup.ToASCII(trimmedHost)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%q: failed to convert to punycode - %w", trimmedHost, err)
|
||||
}
|
||||
|
||||
if len(punycodeHost) < 1 || len(punycodeHost) > 253 {
|
||||
return fmt.Errorf("%q -> %q: invalid length %d bytes. Must be 1-253 bytes (chars) after conversion.", trimmedHost, punycodeHost, len(punycodeHost))
|
||||
}
|
||||
|
||||
if !fqdnRegex.MatchString(punycodeHost) {
|
||||
return fmt.Errorf("%q -> %q: Failed validation.", trimmedHost, punycodeHost)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidateSubnetMask(mask string) bool {
|
||||
addr, err := netip.ParseAddr(mask)
|
||||
if err != nil || !addr.Is4() {
|
||||
return false
|
||||
}
|
||||
|
||||
byteArray := addr.As4()
|
||||
maskInt := uint32(byteArray[0])<<24 | uint32(byteArray[1])<<16 | uint32(byteArray[2])<<8 | uint32(byteArray[3])
|
||||
inverted := ^maskInt
|
||||
return (inverted & (inverted + 1)) == 0
|
||||
}
|
||||
@@ -4,24 +4,16 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
"github.com/seriousm4x/upsnap/logging"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/seriousm4x/upsnap/logger"
|
||||
)
|
||||
|
||||
func WakeDevice(app core.App, device *core.Record, trigger string) error {
|
||||
log := logging.Logger(app)
|
||||
log.Info("Wake triggered", "device", device.GetString("name"), "trigger", trigger)
|
||||
|
||||
wakeTimeout := device.GetInt("wake_timeout")
|
||||
if wakeTimeout <= 0 {
|
||||
wakeTimeout = 120
|
||||
}
|
||||
func WakeDevice(device *core.Record) error {
|
||||
logger.Info.Println("Wake triggered for", device.GetString("name"))
|
||||
|
||||
wake_cmd := device.GetString("wake_cmd")
|
||||
if wake_cmd != "" {
|
||||
@@ -35,21 +27,6 @@ func WakeDevice(app core.App, device *core.Record, trigger string) error {
|
||||
shell_arg = "-c"
|
||||
}
|
||||
|
||||
deviceIP, err := ResolveToIPAddr(device.GetString("ip"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if deviceIP == "" {
|
||||
deviceIP = device.GetString("ip")
|
||||
}
|
||||
// Validate MAC address before replacing placeholders to prevent command injection
|
||||
deviceMAC := device.GetString("mac")
|
||||
if _, err := net.ParseMAC(deviceMAC); err != nil {
|
||||
return fmt.Errorf("invalid device MAC address: %q", deviceMAC)
|
||||
}
|
||||
wake_cmd = strings.ReplaceAll(wake_cmd, "{{ DEVICE_IP }}", deviceIP)
|
||||
wake_cmd = strings.ReplaceAll(wake_cmd, "{{ DEVICE_MAC }}", deviceMAC)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
@@ -61,8 +38,7 @@ func WakeDevice(app core.App, device *core.Record, trigger string) error {
|
||||
cmd.Stderr = &stderr
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
log.Error("Failed to start wake command", "error", err)
|
||||
return err
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
|
||||
done := make(chan error, 1)
|
||||
@@ -70,45 +46,31 @@ func WakeDevice(app core.App, device *core.Record, trigger string) error {
|
||||
done <- cmd.Wait()
|
||||
}()
|
||||
|
||||
// check state every seconds for 2 min
|
||||
start := time.Now()
|
||||
commandFinished := false
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-time.After(1 * time.Second):
|
||||
if time.Since(start) >= time.Duration(wakeTimeout)*time.Second {
|
||||
if !commandFinished && cmd.Process != nil {
|
||||
if err := KillProcess(app, cmd.Process); err != nil {
|
||||
log.Error("Failed to kill wake command", "error", err)
|
||||
}
|
||||
if time.Since(start) >= 2*time.Minute {
|
||||
if err := KillProcess(cmd.Process); err != nil {
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
return fmt.Errorf("%s not online after %d seconds", device.GetString("name"), wakeTimeout)
|
||||
}
|
||||
// Reachability alone does not mean a custom wake command has finished.
|
||||
// For example, a Mac can respond to ping while it is still in DarkWake.
|
||||
if !commandFinished {
|
||||
continue
|
||||
}
|
||||
isOnline, err := PingDevice(device)
|
||||
if err != nil {
|
||||
log.Error("Failed to ping device after wake", "error", err)
|
||||
return err
|
||||
return fmt.Errorf("%s not online after 2 minutes", device.GetString("name"))
|
||||
}
|
||||
isOnline := PingDevice(device)
|
||||
if isOnline {
|
||||
if err := KillProcess(cmd.Process); err != nil {
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
case err := <-done:
|
||||
if err != nil {
|
||||
if cmd.Process != nil {
|
||||
if err := KillProcess(app, cmd.Process); err != nil {
|
||||
log.Error("Failed to kill wake command", "error", err)
|
||||
}
|
||||
if err := KillProcess(cmd.Process); err != nil {
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
return fmt.Errorf("%s", stderr.String())
|
||||
}
|
||||
commandFinished = true
|
||||
done = nil
|
||||
// Command finished successfully, but we continue the loop until device is online or timeout
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -117,21 +79,18 @@ func WakeDevice(app core.App, device *core.Record, trigger string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// check state every seconds for 2 min
|
||||
start := time.Now()
|
||||
for {
|
||||
time.Sleep(1 * time.Second)
|
||||
isOnline, err := PingDevice(device)
|
||||
if err != nil {
|
||||
log.Error("Failed to ping device after wake", "error", err)
|
||||
return err
|
||||
}
|
||||
isOnline := PingDevice(device)
|
||||
if isOnline {
|
||||
return nil
|
||||
}
|
||||
if time.Since(start) >= time.Duration(wakeTimeout)*time.Second {
|
||||
if time.Since(start) >= 2*time.Minute {
|
||||
break
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("%s not online after %d seconds", device.GetString("name"), wakeTimeout)
|
||||
return fmt.Errorf(device.GetString("name"), "not online after 2 min")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
//go:build !windows
|
||||
|
||||
package networking
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/tests"
|
||||
)
|
||||
|
||||
func newWakeTestDevice(t *testing.T, command, pingCommand string, timeout int) (core.App, *core.Record) {
|
||||
t.Helper()
|
||||
app, err := tests.NewTestApp(t.TempDir())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(app.Cleanup)
|
||||
device := core.NewRecord(&core.Collection{})
|
||||
device.Set("name", "test-device")
|
||||
device.Set("ip", "127.0.0.1")
|
||||
device.Set("mac", "02:00:00:00:00:01")
|
||||
device.Set("wake_cmd", command)
|
||||
device.Set("ping_cmd", pingCommand)
|
||||
device.Set("wake_timeout", timeout)
|
||||
return app, device
|
||||
}
|
||||
|
||||
func TestCustomWakeWaitsForCommandWhenDeviceIsAlreadyOnline(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
t.Setenv("UPSNAP_WAKE_TEST_DIR", dir)
|
||||
app, device := newWakeTestDevice(t,
|
||||
`sleep 2; printf done > "$UPSNAP_WAKE_TEST_DIR/completed"`, "exit 0", 10)
|
||||
|
||||
if err := WakeDevice(app, device, "test"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := os.ReadFile(filepath.Join(dir, "completed"))
|
||||
if err != nil || string(data) != "done" {
|
||||
t.Fatalf("wake command was interrupted despite successful ping: data=%q err=%v", data, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCustomWakeReturnsFailureWhenDeviceIsAlreadyOnline(t *testing.T) {
|
||||
app, device := newWakeTestDevice(t, "sleep 2; echo wake-failed >&2; exit 7", "exit 0", 10)
|
||||
err := WakeDevice(app, device, "test")
|
||||
if err == nil || !strings.Contains(err.Error(), "wake-failed") {
|
||||
t.Fatalf("expected wake command failure despite successful ping, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCustomWakeStillWaitsForReachabilityAfterCommandFinishes(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
t.Setenv("UPSNAP_WAKE_TEST_DIR", dir)
|
||||
app, device := newWakeTestDevice(t, "exit 0",
|
||||
`if [ -f "$UPSNAP_WAKE_TEST_DIR/pinged" ]; then exit 0; fi; touch "$UPSNAP_WAKE_TEST_DIR/pinged"; exit 1`, 10)
|
||||
|
||||
if err := WakeDevice(app, device, "test"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "pinged")); err != nil {
|
||||
t.Fatalf("wake returned without checking reachability: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCustomWakeTimesOutWhenCommandSucceedsButDeviceStaysOffline(t *testing.T) {
|
||||
app, device := newWakeTestDevice(t, "exit 0", "exit 1", 2)
|
||||
err := WakeDevice(app, device, "test")
|
||||
if err == nil || !strings.Contains(err.Error(), "not online after 2 seconds") {
|
||||
t.Fatalf("expected reachability timeout, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCustomWakeTimeoutStillStopsRunningCommand(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
t.Setenv("UPSNAP_WAKE_TEST_DIR", dir)
|
||||
app, device := newWakeTestDevice(t,
|
||||
`sleep 3; touch "$UPSNAP_WAKE_TEST_DIR/completed"`, "exit 0", 1)
|
||||
err := WakeDevice(app, device, "test")
|
||||
if err == nil || !strings.Contains(err.Error(), "not online after 1 seconds") {
|
||||
t.Fatalf("expected command timeout even though ping succeeds, got %v", err)
|
||||
}
|
||||
// A surviving shell/child would write this file after its sleep finishes.
|
||||
time.Sleep(3 * time.Second)
|
||||
if _, err := os.Stat(filepath.Join(dir, "completed")); !os.IsNotExist(err) {
|
||||
t.Fatalf("timed-out wake command continued running: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,18 @@
|
||||
package pb
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"encoding/xml"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/dbx"
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/apis"
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/tools/router"
|
||||
"github.com/robfig/cron/v3"
|
||||
"github.com/seriousm4x/upsnap/logging"
|
||||
"github.com/pocketbase/pocketbase/apis"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/seriousm4x/upsnap/logger"
|
||||
"github.com/seriousm4x/upsnap/networking"
|
||||
)
|
||||
|
||||
@@ -22,32 +21,21 @@ func HandlerWake(e *core.RequestEvent) error {
|
||||
if err != nil {
|
||||
return apis.NewNotFoundError("The device does not exist.", err)
|
||||
}
|
||||
|
||||
record.Set("status", "pending")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save pending device status", "device", record.GetString("name"), "error", err)
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
}
|
||||
|
||||
if err := asyncCall(e, func() *router.ApiError {
|
||||
if err := networking.WakeDevice(e.App, record, "manual"); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to wake device", "device", record.GetString("name"), "error", err)
|
||||
record.Set("status", "offline")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save device status", "device", record.GetString("name"), "error", err)
|
||||
}
|
||||
return apis.NewBadRequestError(err.Error(), nil)
|
||||
go func(r *core.Record) {
|
||||
if err := networking.WakeDevice(r); err != nil {
|
||||
logger.Error.Println(err)
|
||||
r.Set("status", "offline")
|
||||
} else {
|
||||
r.Set("status", "online")
|
||||
}
|
||||
|
||||
record.Set("status", "online")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save device status", "device", record.GetString("name"), "error", err)
|
||||
if err := e.App.Save(r); err != nil {
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}(record)
|
||||
return e.JSON(http.StatusOK, record)
|
||||
}
|
||||
|
||||
@@ -56,33 +44,23 @@ func HandlerSleep(e *core.RequestEvent) error {
|
||||
if err != nil {
|
||||
return apis.NewNotFoundError("The device does not exist.", err)
|
||||
}
|
||||
|
||||
record.Set("status", "pending")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save pending device status", "device", record.GetString("name"), "error", err)
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
}
|
||||
|
||||
if err := asyncCall(e, func() *router.ApiError {
|
||||
resp, err := networking.SleepDevice(e.App, record)
|
||||
if err != nil {
|
||||
logging.Logger(e.App).Error("Failed to sleep device", "device", record.GetString("name"), "error", err)
|
||||
record.Set("status", "online")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save device status", "device", record.GetString("name"), "error", err)
|
||||
}
|
||||
return apis.NewBadRequestError(resp.Message, nil)
|
||||
}
|
||||
|
||||
record.Set("status", "offline")
|
||||
resp, err := networking.SleepDevice(record)
|
||||
if err != nil {
|
||||
logger.Error.Println(err)
|
||||
record.Set("status", "online")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save device status", "device", record.GetString("name"), "error", err)
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
return apis.NewBadRequestError(resp.Message, nil)
|
||||
}
|
||||
record.Set("status", "offline")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
}
|
||||
|
||||
return e.JSON(http.StatusOK, nil)
|
||||
}
|
||||
|
||||
@@ -91,46 +69,27 @@ func HandlerReboot(e *core.RequestEvent) error {
|
||||
if err != nil {
|
||||
return apis.NewNotFoundError("The device does not exist.", err)
|
||||
}
|
||||
|
||||
record.Set("status", "pending")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save pending device status", "device", record.GetString("name"), "error", err)
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
}
|
||||
|
||||
if err := asyncCall(e, func() *router.ApiError {
|
||||
if err := networking.ShutdownDevice(e.App, record, "manual"); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to shut down device for reboot", "device", record.GetString("name"), "error", err)
|
||||
record.Set("status", "online")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save device status", "device", record.GetString("name"), "error", err)
|
||||
go func(r *core.Record) {
|
||||
if err := networking.ShutdownDevice(r); err != nil {
|
||||
logger.Error.Println(err)
|
||||
r.Set("status", "online")
|
||||
} else {
|
||||
time.Sleep(15 * time.Second) // some devices might not respond to ping but are still shutting down
|
||||
if err := networking.WakeDevice(r); err != nil {
|
||||
logger.Error.Println(err)
|
||||
r.Set("status", "offline")
|
||||
} else {
|
||||
r.Set("status", "online")
|
||||
}
|
||||
return apis.NewBadRequestError(err.Error(), nil)
|
||||
}
|
||||
|
||||
// if this code is reached, the device is shutting down and not responding to pings anymore.
|
||||
// this does not mean it is ready to boot again, it might still be in the process of shutting down.
|
||||
// so we wait a little to make sure the device has shut down completely and is ready to receive wake requests.
|
||||
time.Sleep(15 * time.Second)
|
||||
|
||||
if err := networking.WakeDevice(e.App, record, "manual"); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to wake device after reboot", "device", record.GetString("name"), "error", err)
|
||||
record.Set("status", "offline")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save device status", "device", record.GetString("name"), "error", err)
|
||||
}
|
||||
return apis.NewBadRequestError(err.Error(), nil)
|
||||
if err := e.App.Save(r); err != nil {
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
}
|
||||
|
||||
record.Set("status", "online")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save device status", "device", record.GetString("name"), "error", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}(record)
|
||||
return e.JSON(http.StatusOK, record)
|
||||
}
|
||||
|
||||
@@ -139,103 +98,24 @@ func HandlerShutdown(e *core.RequestEvent) error {
|
||||
if err != nil {
|
||||
return apis.NewNotFoundError("The device does not exist.", err)
|
||||
}
|
||||
|
||||
record.Set("status", "pending")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save pending device status", "device", record.GetString("name"), "error", err)
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
}
|
||||
|
||||
if err := asyncCall(e, func() *router.ApiError {
|
||||
if err := networking.ShutdownDevice(e.App, record, "manual"); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to shut down device", "device", record.GetString("name"), "error", strings.ReplaceAll(err.Error(), "\n", ""))
|
||||
record.Set("status", "online")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save device status", "device", record.GetString("name"), "error", err)
|
||||
}
|
||||
return apis.NewBadRequestError(err.Error(), nil)
|
||||
go func(r *core.Record) {
|
||||
if err := networking.ShutdownDevice(r); err != nil {
|
||||
logger.Error.Println(err)
|
||||
r.Set("status", "online")
|
||||
} else {
|
||||
r.Set("status", "offline")
|
||||
}
|
||||
|
||||
record.Set("status", "offline")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save device status", "device", record.GetString("name"), "error", err)
|
||||
if err := e.App.Save(r); err != nil {
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}(record)
|
||||
return e.JSON(http.StatusOK, record)
|
||||
}
|
||||
|
||||
func HandlerWakeGroup(e *core.RequestEvent) error {
|
||||
records, err := e.App.FindRecordsByFilter("devices", "groups.id ?= {:grpId} && status = 'offline'", "", 0, 0,
|
||||
dbx.Params{"grpId": e.Request.PathValue("id")},
|
||||
)
|
||||
if err != nil {
|
||||
return apis.NewNotFoundError("No devices in group", err)
|
||||
}
|
||||
|
||||
for _, record := range records {
|
||||
go func() {
|
||||
record.Set("status", "pending")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save pending device status", "device", record.GetString("name"), "error", err)
|
||||
}
|
||||
|
||||
if err := networking.WakeDevice(e.App, record, "manual"); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to wake device", "device", record.GetString("name"), "error", err)
|
||||
record.Set("status", "offline")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save device status", "device", record.GetString("name"), "error", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
record.Set("status", "online")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save device status", "device", record.GetString("name"), "error", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return e.JSON(http.StatusOK, records)
|
||||
}
|
||||
|
||||
func HandlerShutdownGroup(e *core.RequestEvent) error {
|
||||
records, err := e.App.FindRecordsByFilter("devices", "groups.id ?= {:grpId} && status = 'online'", "", 0, 0,
|
||||
dbx.Params{"grpId": e.Request.PathValue("id")},
|
||||
)
|
||||
if err != nil {
|
||||
return apis.NewNotFoundError("No devices in group", err)
|
||||
}
|
||||
|
||||
for _, record := range records {
|
||||
go func() {
|
||||
record.Set("status", "pending")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save pending device status", "device", record.GetString("name"), "error", err)
|
||||
}
|
||||
|
||||
if err := networking.ShutdownDevice(e.App, record, "manual"); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to shut down device", "device", record.GetString("name"), "error", err)
|
||||
record.Set("status", "online")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save device status", "device", record.GetString("name"), "error", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
record.Set("status", "offline")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to save device status", "device", record.GetString("name"), "error", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return e.JSON(http.StatusOK, records)
|
||||
}
|
||||
|
||||
type Nmaprun struct {
|
||||
Host []struct {
|
||||
Address []struct {
|
||||
@@ -246,6 +126,97 @@ type Nmaprun struct {
|
||||
} `xml:"host"`
|
||||
}
|
||||
|
||||
func HandlerScan(e *core.RequestEvent) error {
|
||||
// check if nmap installed
|
||||
nmap, err := exec.LookPath("nmap")
|
||||
if err != nil {
|
||||
return apis.NewBadRequestError(err.Error(), nil)
|
||||
}
|
||||
|
||||
// check if scan range is valid
|
||||
allPrivateSettings, err := e.App.FindAllRecords("settings_private")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
settingsPrivate := allPrivateSettings[0]
|
||||
scanRange := settingsPrivate.GetString("scan_range")
|
||||
_, ipNet, err := net.ParseCIDR(scanRange)
|
||||
if err != nil {
|
||||
return apis.NewBadRequestError(err.Error(), nil)
|
||||
}
|
||||
|
||||
// run nmap
|
||||
timeout := os.Getenv("UPSNAP_SCAN_TIMEOUT")
|
||||
if timeout == "" {
|
||||
timeout = "500ms"
|
||||
}
|
||||
cmd := exec.Command(nmap, "-sn", "-oX", "-", scanRange, "--host-timeout", timeout)
|
||||
cmdOutput, err := cmd.Output()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// unmarshal xml
|
||||
nmapOutput := Nmaprun{}
|
||||
if err := xml.Unmarshal(cmdOutput, &nmapOutput); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
Name string `json:"name"`
|
||||
IP string `json:"ip"`
|
||||
MAC string `json:"mac"`
|
||||
MACVendor string `json:"mac_vendor"`
|
||||
}
|
||||
|
||||
// extract info from struct into data
|
||||
type Response struct {
|
||||
Netmask string `json:"netmask"`
|
||||
Devices []Device `json:"devices"`
|
||||
}
|
||||
res := Response{}
|
||||
var nm []string
|
||||
for _, octet := range ipNet.Mask {
|
||||
nm = append(nm, strconv.Itoa(int(octet)))
|
||||
}
|
||||
res.Netmask = strings.Join(nm, ".")
|
||||
|
||||
for _, host := range nmapOutput.Host {
|
||||
dev := Device{}
|
||||
for _, addr := range host.Address {
|
||||
if addr.Addrtype == "ipv4" {
|
||||
dev.IP = addr.Addr
|
||||
} else if addr.Addrtype == "mac" {
|
||||
dev.MAC = addr.Addr
|
||||
}
|
||||
if addr.Vendor != "" {
|
||||
dev.MACVendor = addr.Vendor
|
||||
} else {
|
||||
dev.MACVendor = "Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
if dev.IP == "" || dev.MAC == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
names, err := net.LookupAddr(dev.IP)
|
||||
if err != nil || len(names) == 0 {
|
||||
dev.Name = dev.MACVendor
|
||||
} else {
|
||||
dev.Name = strings.TrimSuffix(names[0], ".")
|
||||
}
|
||||
|
||||
if dev.Name == "" && dev.MACVendor == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
res.Devices = append(res.Devices, dev)
|
||||
}
|
||||
|
||||
return e.JSON(http.StatusOK, res)
|
||||
}
|
||||
|
||||
func HandlerInitSuperuser(e *core.RequestEvent) error {
|
||||
superusersCollection, err := e.App.FindCollectionByNameOrId(core.CollectionNameSuperusers)
|
||||
if err != nil {
|
||||
@@ -285,122 +256,3 @@ func HandlerInitSuperuser(e *core.RequestEvent) error {
|
||||
|
||||
return apis.RecordAuthResponse(e, record, "", nil)
|
||||
}
|
||||
|
||||
type ValidateCronRequest struct {
|
||||
Cron string `json:"cron"`
|
||||
}
|
||||
|
||||
func HandlerValidateCron(e *core.RequestEvent) error {
|
||||
var body ValidateCronRequest
|
||||
|
||||
if err := e.BindBody(&body); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to bind cron validation request", "error", err)
|
||||
return e.BadRequestError("invalid request", err)
|
||||
}
|
||||
|
||||
p := cron.NewParser(cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow)
|
||||
if _, err := p.Parse(body.Cron); err != nil {
|
||||
return e.BadRequestError("failed to parse cron expression", err)
|
||||
}
|
||||
|
||||
return e.JSON(200, "valid")
|
||||
}
|
||||
|
||||
func asyncCall(e *core.RequestEvent, fn func() *router.ApiError) *router.ApiError {
|
||||
isAsync, err := strconv.ParseBool(e.Request.URL.Query().Get("async"))
|
||||
if err != nil {
|
||||
isAsync = false
|
||||
}
|
||||
|
||||
if !isAsync {
|
||||
return fn()
|
||||
}
|
||||
|
||||
go func() {
|
||||
_ = fn()
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func HandlerWebsiteManifest(e *core.RequestEvent) error {
|
||||
scheme := "http"
|
||||
if e.Request.TLS != nil || e.Request.Header.Get("X-Forwarded-Proto") == "https" {
|
||||
scheme = "https"
|
||||
}
|
||||
baseUrl := fmt.Sprintf("%s://%s", scheme, e.Request.Host)
|
||||
|
||||
manifest := map[string]any{
|
||||
"name": "UpSnap",
|
||||
"short_name": "UpSnap",
|
||||
"description": "A simple wake on lan web app written with SvelteKit, Go and PocketBase.",
|
||||
"theme_color": "#55BCD9",
|
||||
"background_color": "#55BCD9",
|
||||
"display": "standalone",
|
||||
"scope": baseUrl,
|
||||
"start_url": baseUrl,
|
||||
"icons": []map[string]string{
|
||||
{
|
||||
"src": "/icon_192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "any",
|
||||
},
|
||||
{
|
||||
"src": "/icon_512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "any",
|
||||
},
|
||||
{
|
||||
"src": "/maskable_192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable",
|
||||
},
|
||||
{
|
||||
"src": "/maskable_512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable",
|
||||
},
|
||||
{
|
||||
"src": "/gopher.svg",
|
||||
"sizes": "any",
|
||||
"type": "image/svg+xml",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
publicSettings, err := e.App.FindFirstRecordByFilter("settings_public", "")
|
||||
if err != nil {
|
||||
return writeManifest(e, manifest)
|
||||
}
|
||||
|
||||
// override title if set
|
||||
if title := publicSettings.GetString("website_title"); title != "" {
|
||||
manifest["name"] = title
|
||||
manifest["short_name"] = title
|
||||
}
|
||||
|
||||
// override icons if set
|
||||
if favicon := publicSettings.GetString("favicon"); favicon != "" {
|
||||
|
||||
manifest["icons"] = []map[string]string{
|
||||
{
|
||||
"src": fmt.Sprintf("%s/api/files/settings_public/%s/%s", baseUrl, publicSettings.Id, favicon),
|
||||
"sizes": "any",
|
||||
"purpose": "any",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return writeManifest(e, manifest)
|
||||
}
|
||||
|
||||
func writeManifest(e *core.RequestEvent, manifest map[string]any) error {
|
||||
e.Response.Header().Set("Content-Type", "application/manifest+json")
|
||||
e.Response.Header().Set("Cache-Control", "no-cache, no-store")
|
||||
enc := json.NewEncoder(e.Response)
|
||||
return enc.Encode(manifest)
|
||||
}
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
//go:build linux
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/apis"
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
"kernel.org/pub/linux/libs/security/libcap/cap"
|
||||
)
|
||||
|
||||
func HandlerScan(e *core.RequestEvent) error {
|
||||
// check if nmap installed
|
||||
nmap, err := exec.LookPath("nmap")
|
||||
if err != nil {
|
||||
return apis.NewBadRequestError(err.Error(), nil)
|
||||
}
|
||||
|
||||
// check if scan range is valid
|
||||
allPrivateSettings, err := e.App.FindAllRecords("settings_private")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
settingsPrivate := allPrivateSettings[0]
|
||||
scanRange := settingsPrivate.GetString("scan_range")
|
||||
_, ipNet, err := net.ParseCIDR(scanRange)
|
||||
if err != nil {
|
||||
return apis.NewBadRequestError(err.Error(), nil)
|
||||
}
|
||||
|
||||
// run nmap
|
||||
timeout := os.Getenv("UPSNAP_SCAN_TIMEOUT")
|
||||
if timeout == "" {
|
||||
timeout = "500ms"
|
||||
}
|
||||
orig := cap.GetProc()
|
||||
defer orig.SetProc() // restore original caps on exit.
|
||||
|
||||
c, err := orig.Dup()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to dup existing capabilities: %v", err)
|
||||
}
|
||||
|
||||
if on, _ := c.GetFlag(cap.Permitted, cap.NET_RAW); !on {
|
||||
return fmt.Errorf("unable to get NET_RAW permissions")
|
||||
}
|
||||
|
||||
if err := c.SetFlag(cap.Effective, true, cap.NET_RAW); err != nil {
|
||||
return fmt.Errorf("unable to set NET_RAW capability effective")
|
||||
}
|
||||
|
||||
if err := c.SetFlag(cap.Inheritable, true, cap.NET_RAW); err != nil {
|
||||
return fmt.Errorf("unable to set NET_RAW capability inheritable")
|
||||
}
|
||||
|
||||
if err := c.SetProc(); err != nil {
|
||||
return fmt.Errorf("unable to raise NET_RAW capability")
|
||||
}
|
||||
|
||||
if err := cap.SetAmbient(true, cap.NET_RAW); err != nil {
|
||||
return fmt.Errorf("unable to set NET_RAW capability ambient")
|
||||
}
|
||||
|
||||
cmd := exec.Command(nmap, "-sn", "-oX", "-", scanRange, "--host-timeout", timeout, "--privileged")
|
||||
cmdOutput, err := cmd.Output()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// unmarshal xml
|
||||
nmapOutput := Nmaprun{}
|
||||
if err := xml.Unmarshal(cmdOutput, &nmapOutput); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
Name string `json:"name"`
|
||||
IP string `json:"ip"`
|
||||
MAC string `json:"mac"`
|
||||
MACVendor string `json:"mac_vendor"`
|
||||
}
|
||||
|
||||
// extract info from struct into data
|
||||
type Response struct {
|
||||
Netmask string `json:"netmask"`
|
||||
Devices []Device `json:"devices"`
|
||||
}
|
||||
res := Response{}
|
||||
var nm []string
|
||||
for _, octet := range ipNet.Mask {
|
||||
nm = append(nm, strconv.Itoa(int(octet)))
|
||||
}
|
||||
res.Netmask = strings.Join(nm, ".")
|
||||
|
||||
for _, host := range nmapOutput.Host {
|
||||
dev := Device{}
|
||||
for _, addr := range host.Address {
|
||||
if addr.Addrtype == "ipv4" {
|
||||
dev.IP = addr.Addr
|
||||
} else if addr.Addrtype == "mac" {
|
||||
dev.MAC = addr.Addr
|
||||
}
|
||||
if addr.Vendor != "" {
|
||||
dev.MACVendor = addr.Vendor
|
||||
} else {
|
||||
dev.MACVendor = "Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
if dev.IP == "" || dev.MAC == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
names, err := net.LookupAddr(dev.IP)
|
||||
if err != nil || len(names) == 0 {
|
||||
dev.Name = dev.MACVendor
|
||||
} else {
|
||||
dev.Name = strings.TrimSuffix(names[0], ".")
|
||||
}
|
||||
|
||||
if dev.Name == "" && dev.MACVendor == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
res.Devices = append(res.Devices, dev)
|
||||
}
|
||||
|
||||
return e.JSON(http.StatusOK, res)
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
//go:build !linux
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/apis"
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
func HandlerScan(e *core.RequestEvent) error {
|
||||
// check if nmap installed
|
||||
nmap, err := exec.LookPath("nmap")
|
||||
if err != nil {
|
||||
return apis.NewBadRequestError(err.Error(), nil)
|
||||
}
|
||||
|
||||
// check if scan range is valid
|
||||
allPrivateSettings, err := e.App.FindAllRecords("settings_private")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
settingsPrivate := allPrivateSettings[0]
|
||||
scanRange := settingsPrivate.GetString("scan_range")
|
||||
_, ipNet, err := net.ParseCIDR(scanRange)
|
||||
if err != nil {
|
||||
return apis.NewBadRequestError(err.Error(), nil)
|
||||
}
|
||||
|
||||
// run nmap
|
||||
timeout := os.Getenv("UPSNAP_SCAN_TIMEOUT")
|
||||
if timeout == "" {
|
||||
timeout = "500ms"
|
||||
}
|
||||
cmd := exec.Command(nmap, "-sn", "-oX", "-", scanRange, "--host-timeout", timeout, "--privileged")
|
||||
cmdOutput, err := cmd.Output()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// unmarshal xml
|
||||
nmapOutput := Nmaprun{}
|
||||
if err := xml.Unmarshal(cmdOutput, &nmapOutput); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
Name string `json:"name"`
|
||||
IP string `json:"ip"`
|
||||
MAC string `json:"mac"`
|
||||
MACVendor string `json:"mac_vendor"`
|
||||
}
|
||||
|
||||
// extract info from struct into data
|
||||
type Response struct {
|
||||
Netmask string `json:"netmask"`
|
||||
Devices []Device `json:"devices"`
|
||||
}
|
||||
res := Response{}
|
||||
var nm []string
|
||||
for _, octet := range ipNet.Mask {
|
||||
nm = append(nm, strconv.Itoa(int(octet)))
|
||||
}
|
||||
res.Netmask = strings.Join(nm, ".")
|
||||
|
||||
for _, host := range nmapOutput.Host {
|
||||
dev := Device{}
|
||||
for _, addr := range host.Address {
|
||||
if addr.Addrtype == "ipv4" {
|
||||
dev.IP = addr.Addr
|
||||
} else if addr.Addrtype == "mac" {
|
||||
dev.MAC = addr.Addr
|
||||
}
|
||||
if addr.Vendor != "" {
|
||||
dev.MACVendor = addr.Vendor
|
||||
} else {
|
||||
dev.MACVendor = "Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
if dev.IP == "" || dev.MAC == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
names, err := net.LookupAddr(dev.IP)
|
||||
if err != nil || len(names) == 0 {
|
||||
dev.Name = dev.MACVendor
|
||||
} else {
|
||||
dev.Name = strings.TrimSuffix(names[0], ".")
|
||||
}
|
||||
|
||||
if dev.Name == "" && dev.MACVendor == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
res.Devices = append(res.Devices, dev)
|
||||
}
|
||||
|
||||
return e.JSON(http.StatusOK, res)
|
||||
}
|
||||
@@ -1,58 +1,23 @@
|
||||
package pb
|
||||
|
||||
import (
|
||||
"ganigeorgiev.com/pocketbase/dbx"
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/apis"
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/tools/hook"
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/apis"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/tools/hook"
|
||||
)
|
||||
|
||||
// SkipSuccessfulHealthCheckLog prevents routine Docker health checks from being
|
||||
// persisted while retaining failed health checks for diagnostics.
|
||||
func SkipSuccessfulHealthCheckLog(e *core.RequestEvent) error {
|
||||
if e.Request.URL.Path == "/api/health" {
|
||||
return apis.SkipSuccessActivityLog().Func(e)
|
||||
}
|
||||
|
||||
return e.Next()
|
||||
}
|
||||
|
||||
func RequireScanDevicesPermission() *hook.Handler[*core.RequestEvent] {
|
||||
return &hook.Handler[*core.RequestEvent]{
|
||||
Func: func(e *core.RequestEvent) error {
|
||||
if e.HasSuperuserAuth() {
|
||||
return e.Next()
|
||||
}
|
||||
|
||||
user := e.Auth
|
||||
if user == nil {
|
||||
return apis.NewUnauthorizedError("The request requires superuser or record authorization token to be set.", nil)
|
||||
}
|
||||
|
||||
res, err := e.App.FindFirstRecordByFilter(
|
||||
"permissions",
|
||||
"user.id = {:userId} && create = true",
|
||||
dbx.Params{"userId": user.Id},
|
||||
)
|
||||
if res == nil || err != nil {
|
||||
return apis.NewForbiddenError("You are not allowed to perform this request.", nil)
|
||||
}
|
||||
|
||||
return e.Next()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func RequireUpSnapPermission() *hook.Handler[*core.RequestEvent] {
|
||||
return &hook.Handler[*core.RequestEvent]{
|
||||
Func: func(e *core.RequestEvent) error {
|
||||
if e.HasSuperuserAuth() {
|
||||
admin := e.HasSuperuserAuth()
|
||||
if admin {
|
||||
return e.Next()
|
||||
}
|
||||
|
||||
user := e.Auth
|
||||
if user == nil {
|
||||
return apis.NewUnauthorizedError("The request requires superuser or record authorization token to be set.", nil)
|
||||
return apis.NewUnauthorizedError("The request requires admin or record authorization token to be set.", nil)
|
||||
}
|
||||
|
||||
deviceId := e.Request.PathValue("id")
|
||||
|
||||
@@ -1,40 +1,31 @@
|
||||
package pb
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"ganigeorgiev.com/pocketbase/dbx"
|
||||
"ganigeorgiev.com/pocketbase/pocketbase"
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/apis"
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/core"
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/plugins/ghupdate"
|
||||
"ganigeorgiev.com/pocketbase/pocketbase/plugins/migratecmd"
|
||||
"github.com/robfig/cron/v3"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/pocketbase/pocketbase/apis"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/plugins/migratecmd"
|
||||
"github.com/seriousm4x/upsnap/cronjobs"
|
||||
"github.com/seriousm4x/upsnap/iptracking"
|
||||
"github.com/seriousm4x/upsnap/logging"
|
||||
"github.com/seriousm4x/upsnap/logger"
|
||||
_ "github.com/seriousm4x/upsnap/migrations"
|
||||
"github.com/seriousm4x/upsnap/networking"
|
||||
)
|
||||
|
||||
var Version = "(untracked)"
|
||||
|
||||
func StartPocketBase(distDirFS fs.FS) error {
|
||||
if err := logging.ConfigureConsole(os.Getenv("UPSNAP_LOG_LEVEL")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func StartPocketBase(distDirFS fs.FS) {
|
||||
// set data dir
|
||||
// use "./pb_data" if it's in the same dir as upsnap binary
|
||||
// else use os.UserConfigDir() / upsnap
|
||||
var dataDir string
|
||||
baseDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
logger.Error.Fatalln(err)
|
||||
}
|
||||
pb_data := path.Join(baseDir, "pb_data")
|
||||
if _, err = os.Stat(pb_data); err == nil {
|
||||
@@ -42,14 +33,14 @@ func StartPocketBase(distDirFS fs.FS) error {
|
||||
} else if os.IsNotExist(err) {
|
||||
userConfigDir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
return err
|
||||
logger.Error.Fatalln(err)
|
||||
}
|
||||
upsnap_data := path.Join(userConfigDir, "upsnap")
|
||||
if _, err = os.Stat(upsnap_data); err == nil {
|
||||
dataDir = upsnap_data
|
||||
} else if os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(upsnap_data, 0700); err != nil {
|
||||
return err
|
||||
logger.Error.Fatalln(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,26 +57,16 @@ func StartPocketBase(distDirFS fs.FS) error {
|
||||
Automigrate: true,
|
||||
})
|
||||
|
||||
// GitHub selfupdate
|
||||
ghupdate.MustRegister(app, app.RootCmd, ghupdate.Config{
|
||||
Owner: "seriousm4x",
|
||||
Repo: "UpSnap",
|
||||
ArchiveExecutable: "upsnap",
|
||||
})
|
||||
|
||||
// event hooks
|
||||
app.OnServe().BindFunc(func(se *core.ServeEvent) error {
|
||||
se.Router.BindFunc(SkipSuccessfulHealthCheckLog)
|
||||
se.Router.GET("/{path...}", apis.Static(distDirFS, true))
|
||||
|
||||
se.Router.GET("/api/upsnap/wake/{id}", HandlerWake).Bind(RequireUpSnapPermission())
|
||||
se.Router.GET("/api/upsnap/wakegroup/{id}", HandlerWakeGroup).Bind(RequireUpSnapPermission())
|
||||
se.Router.GET("/api/upsnap/sleep/{id}", HandlerSleep).Bind(RequireUpSnapPermission())
|
||||
se.Router.GET("/api/upsnap/reboot/{id}", HandlerReboot).Bind(RequireUpSnapPermission())
|
||||
se.Router.GET("/api/upsnap/shutdown/{id}", HandlerShutdown).Bind(RequireUpSnapPermission())
|
||||
se.Router.GET("/api/upsnap/shutdowngroup/{id}", HandlerShutdownGroup).Bind(RequireUpSnapPermission())
|
||||
se.Router.GET("/api/upsnap/scan", HandlerScan).Bind(RequireScanDevicesPermission())
|
||||
se.Router.POST("/api/upsnap/validate-cron", HandlerValidateCron)
|
||||
se.Router.GET("/api/upsnap/manifest.webmanifest", HandlerWebsiteManifest)
|
||||
se.Router.GET("/api/upsnap/scan", HandlerScan).Bind(apis.RequireSuperuserAuth())
|
||||
se.Router.POST("/api/upsnap/init-superuser", HandlerInitSuperuser) // https://github.com/pocketbase/pocketbase/discussions/6198
|
||||
|
||||
if err := importSettings(app); err != nil {
|
||||
return err
|
||||
@@ -126,19 +107,12 @@ func StartPocketBase(distDirFS fs.FS) error {
|
||||
oldShutdownCmd := oldRecord.GetString("shutdown_cmd")
|
||||
oldShutdownCronEnabled := oldRecord.GetBool("shutdown_cron_enabled")
|
||||
|
||||
newIp := newRecord.GetString("ip")
|
||||
oldIp := oldRecord.GetString("ip")
|
||||
newPingCmd := newRecord.GetString("ping_cmd")
|
||||
oldPingCmd := oldRecord.GetString("ping_cmd")
|
||||
|
||||
if newWakeCron != oldWakeCron ||
|
||||
newWakeCmd != oldWakeCmd ||
|
||||
newWakeCronEnabled != oldWakeCronEnabled ||
|
||||
newShutdownCron != oldShutdownCron ||
|
||||
newShutdownCronEnabled != oldShutdownCronEnabled ||
|
||||
newShutdownCmd != oldShutdownCmd ||
|
||||
newIp != oldIp ||
|
||||
newPingCmd != oldPingCmd {
|
||||
newShutdownCmd != oldShutdownCmd {
|
||||
cronjobs.SetWakeShutdownJobs(app)
|
||||
}
|
||||
}
|
||||
@@ -147,14 +121,10 @@ func StartPocketBase(distDirFS fs.FS) error {
|
||||
return se.Next()
|
||||
})
|
||||
|
||||
app.OnModelAfterCreateSuccess("_superusers", "devices").BindFunc(func(e *core.ModelEvent) error {
|
||||
app.OnModelAfterCreateSuccess().BindFunc(func(e *core.ModelEvent) error {
|
||||
if e.Model.TableName() == "_superusers" {
|
||||
// when pocketbase creates it's default superuser, do not trigger setSetupCompleted()
|
||||
if e.Model.(*core.Record).Email() == core.DefaultInstallerEmail {
|
||||
return e.Next()
|
||||
}
|
||||
if err := setSetupCompleted(e.App); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to update setup state", "error", err)
|
||||
logger.Error.Println(err)
|
||||
return err
|
||||
}
|
||||
return e.Next()
|
||||
@@ -167,7 +137,7 @@ func StartPocketBase(distDirFS fs.FS) error {
|
||||
permissionRec, err := app.FindFirstRecordByFilter("permissions",
|
||||
fmt.Sprintf("user.id = '%s'", userId))
|
||||
if err != nil && err.Error() != "sql: no rows in result set" {
|
||||
logging.Logger(e.App).Error("Failed to load permissions for new device", "error", err)
|
||||
logger.Error.Println(err)
|
||||
return err
|
||||
} else if permissionRec != nil {
|
||||
permissionRec.Set("read", append(permissionRec.GetStringSlice("read"), deviceRec.Id))
|
||||
@@ -175,7 +145,7 @@ func StartPocketBase(distDirFS fs.FS) error {
|
||||
permissionRec.Set("delete", append(permissionRec.GetStringSlice("delete"), deviceRec.Id))
|
||||
permissionRec.Set("power", append(permissionRec.GetStringSlice("power"), deviceRec.Id))
|
||||
if err := app.Save(permissionRec); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to grant permissions for new device", "error", err)
|
||||
logger.Error.Println(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -183,120 +153,35 @@ func StartPocketBase(distDirFS fs.FS) error {
|
||||
return e.Next()
|
||||
})
|
||||
|
||||
app.OnModelAfterDeleteSuccess("_superusers").BindFunc(func(e *core.ModelEvent) error {
|
||||
if err := setSetupCompleted(e.App); err != nil {
|
||||
logging.Logger(e.App).Error("Failed to update setup state", "error", err)
|
||||
return err
|
||||
}
|
||||
return e.Next()
|
||||
})
|
||||
|
||||
app.OnRecordValidate("devices").BindFunc(func(e *core.RecordEvent) error {
|
||||
if !networking.ValidateSubnetMask(e.Record.GetString("netmask")) {
|
||||
logging.Logger(e.App).Warn("Device has invalid netmask; using broadcast default", "device", e.Record.GetString("name"), "netmask", "255.255.255.255")
|
||||
e.Record.Set("netmask", "255.255.255.255")
|
||||
saveErr := e.App.Save(e.Record)
|
||||
if saveErr != nil {
|
||||
return saveErr
|
||||
app.OnModelAfterDeleteSuccess().BindFunc(func(e *core.ModelEvent) error {
|
||||
if e.Model.TableName() == "_superusers" {
|
||||
if err := setSetupCompleted(e.App); err != nil {
|
||||
logger.Error.Println(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return e.Next()
|
||||
})
|
||||
|
||||
app.OnRealtimeConnectRequest().BindFunc(func(e *core.RealtimeConnectRequestEvent) error {
|
||||
// a client just became active: catch up on any tracking sweep that
|
||||
// was skipped while nobody was connected
|
||||
settings, err := e.App.FindFirstRecordByFilter("settings_private", "")
|
||||
if err != nil {
|
||||
logging.Logger(e.App).Error("Failed to load private settings on realtime connection", "error", err)
|
||||
} else if settings.GetBool("lazy_ping") && settings.GetString("track_ip_interval") != "" {
|
||||
go iptracking.CatchUpSweep(e.App)
|
||||
// prevent new superuser bahavior introduced in pocketbase 0.23
|
||||
app.OnRecordCreate(core.CollectionNameSuperusers).BindFunc(func(e *core.RecordEvent) error {
|
||||
if e.Record.Email() == core.DefaultInstallerEmail {
|
||||
return errors.New("skip default PocketBase installer")
|
||||
}
|
||||
return e.Next()
|
||||
})
|
||||
|
||||
app.OnRealtimeConnectRequest().BindFunc(func(e *core.RealtimeConnectRequestEvent) error {
|
||||
// PocketBase has no realtime disconnect hook. When a browser refreshes,
|
||||
// the old client may disappear before the new connection is registered.
|
||||
// Delay the offline transition and use the connecting client's id to
|
||||
// distinguish a refresh from a genuine disconnect.
|
||||
clientID := e.Client.Id()
|
||||
defer func() {
|
||||
// with lazy ping disabled the ping cron keeps updating device
|
||||
// statuses while no clients are connected, so there is nothing
|
||||
// to compensate for here
|
||||
settings, err := e.App.FindFirstRecordByFilter("settings_private", "")
|
||||
if err != nil {
|
||||
logging.Logger(e.App).Error("Failed to load private settings for offline transition", "error", err)
|
||||
return
|
||||
}
|
||||
if !settings.GetBool("lazy_ping") {
|
||||
return
|
||||
}
|
||||
if len(e.App.SubscriptionsBroker().Clients()) != 0 {
|
||||
return
|
||||
}
|
||||
time.AfterFunc(2*time.Second, func() {
|
||||
if _, err := e.App.SubscriptionsBroker().ClientById(clientID); err == nil {
|
||||
return
|
||||
}
|
||||
if len(e.App.SubscriptionsBroker().Clients()) != 0 {
|
||||
return
|
||||
}
|
||||
allDevices, err := app.FindAllRecords("devices", dbx.NewExp("shutdown_cmd != ''"))
|
||||
if err != nil {
|
||||
logging.Logger(app).Error("Failed to load devices for offline transition", "error", err)
|
||||
return
|
||||
}
|
||||
marked := 0
|
||||
for _, device := range allDevices {
|
||||
// leave devices that are already offline alone so the
|
||||
// "offline since" timestamp keeps its real meaning
|
||||
if device.GetString("status") == "offline" {
|
||||
continue
|
||||
}
|
||||
device.Set("status", "offline")
|
||||
if err := app.Save(device); err != nil {
|
||||
logging.Logger(app).Error("Failed to save offline device status", "device", device.GetString("name"), "error", err)
|
||||
return
|
||||
}
|
||||
marked++
|
||||
}
|
||||
if marked > 0 {
|
||||
logging.Logger(app).Info("Marked devices offline after the last client disconnected", "count", marked)
|
||||
}
|
||||
})
|
||||
}()
|
||||
return e.Next()
|
||||
})
|
||||
|
||||
app.OnTerminate().BindFunc(func(e *core.TerminateEvent) error {
|
||||
cronjobs.StopAll(e.App)
|
||||
cronjobs.StopAll()
|
||||
return e.Next()
|
||||
})
|
||||
|
||||
// check for custom http listen address in env var, else use default
|
||||
httpListen := os.Getenv("UPSNAP_HTTP_LISTEN")
|
||||
if httpListen != "" {
|
||||
if err := app.Bootstrap(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := apis.Serve(app, apis.ServeConfig{
|
||||
HttpAddr: httpListen,
|
||||
ShowStartBanner: true,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := app.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := app.Start(); err != nil {
|
||||
logger.Error.Fatalln(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func importSettings(app core.App) error {
|
||||
func importSettings(app *pocketbase.PocketBase) error {
|
||||
settingsPrivateRecords, err := app.FindAllRecords("settings_private")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -327,8 +212,7 @@ func importSettings(app core.App) error {
|
||||
// 1st: env var
|
||||
// 2nd: database entry
|
||||
// 3rd: default values
|
||||
defaultInterval := "*/3 * * * * *"
|
||||
interval := defaultInterval
|
||||
interval := "@every 3s"
|
||||
if settingsPrivate.GetString("interval") != "" {
|
||||
interval = settingsPrivate.GetString("interval")
|
||||
}
|
||||
@@ -336,20 +220,6 @@ func importSettings(app core.App) error {
|
||||
interval = os.Getenv("UPSNAP_INTERVAL")
|
||||
}
|
||||
|
||||
// validate interval before saving
|
||||
p := cron.NewParser(cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow)
|
||||
if _, err := p.Parse(interval); err != nil {
|
||||
if interval == "*/3 * * * *" || interval == "@every 3s" {
|
||||
settingsPrivate.Set("interval", defaultInterval)
|
||||
if e := app.Save(settingsPrivate); e != nil {
|
||||
logging.Logger(app).Error("Failed to save default ping interval", "error", e)
|
||||
}
|
||||
} else {
|
||||
logging.Logger(app).Error("Invalid ping interval; using default", "interval", interval, "default", defaultInterval)
|
||||
}
|
||||
interval = defaultInterval
|
||||
}
|
||||
|
||||
settingsPrivate.Set("interval", interval)
|
||||
if scanRange := os.Getenv("UPSNAP_SCAN_RANGE"); scanRange != "" {
|
||||
settingsPrivate.Set("scan_range", scanRange)
|
||||
@@ -366,14 +236,15 @@ func importSettings(app core.App) error {
|
||||
return err
|
||||
}
|
||||
if err := setSetupCompleted(app); err != nil {
|
||||
logging.Logger(app).Error("Failed to update setup state", "error", err)
|
||||
logger.Error.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Info.Println("Ping interval set to", interval)
|
||||
return nil
|
||||
}
|
||||
|
||||
func resetDeviceStates(app core.App) error {
|
||||
func resetDeviceStates(app *pocketbase.PocketBase) error {
|
||||
devices, err := app.FindAllRecords("devices")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -388,22 +259,15 @@ func resetDeviceStates(app core.App) error {
|
||||
}
|
||||
|
||||
func setSetupCompleted(app core.App) error {
|
||||
allSuperusers, err := app.FindAllRecords(core.CollectionNameSuperusers)
|
||||
totalAdmins, err := app.CountRecords(core.CollectionNameSuperusers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
realSuperusers := 0
|
||||
for _, r := range allSuperusers {
|
||||
// exclude the temporary PocketBase installer account from the count
|
||||
if r.Email() != core.DefaultInstallerEmail {
|
||||
realSuperusers++
|
||||
}
|
||||
}
|
||||
settingsPublicRecords, err := app.FindAllRecords("settings_public")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if realSuperusers > 0 {
|
||||
if totalAdmins > 0 {
|
||||
settingsPublicRecords[0].Set("setup_completed", true)
|
||||
} else {
|
||||
settingsPublicRecords[0].Set("setup_completed", false)
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
services:
|
||||
upsnap:
|
||||
cap_add:
|
||||
- NET_RAW # Required for privileged ping, network device scan, and IP address tracking (nmap)
|
||||
cap_drop:
|
||||
- ALL
|
||||
container_name: upsnap
|
||||
build:
|
||||
dockerfile: Dockerfile.dev
|
||||
@@ -11,18 +7,12 @@ services:
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./data:/app/pb_data
|
||||
# # If you want to use FQDN instead of an IP and it is a ".local" domain, avahi and dbus must be installed on
|
||||
# # the host, and the host dbus must be mounted in the container.
|
||||
# # Before uncommmenting, ensure you are familiar with potential security implications of mounting dbus
|
||||
# - /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket:ro
|
||||
# # To use a non-root user, create the mountpoint first before starting
|
||||
# # the container (mkdir data) so that it has the right permissions.
|
||||
# user: 1000:1000
|
||||
# environment:
|
||||
# - TZ=Europe/Berlin # Set container timezone for cron schedules
|
||||
# - UPSNAP_HTTP_LISTEN=127.0.0.1:8090
|
||||
# - UPSNAP_INTERVAL=*/10 * * * * * # Sets the interval in which the devices are pinged
|
||||
# - UPSNAP_LOG_LEVEL=INFO # Console level for UpSnap logs: DEBUG, INFO, WARN, ERROR, or OFF
|
||||
# - 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
|
||||
# # dns is used for name resolution during network scan
|
||||
@@ -35,4 +25,4 @@ services:
|
||||
# test: curl -fs "http://localhost:5000/api/health" || exit 1
|
||||
# interval: 10s
|
||||
# # or install custom packages for shutdown
|
||||
# entrypoint: /bin/sh -c "apk update && apk add --no-cache <YOUR_PACKAGE> && rm -rf /var/cache/apk/* && ./upsnap serve"
|
||||
# entrypoint: /bin/sh -c "apk update && apk add --no-cache <YOUR_PACKAGE> && rm -rf /var/cache/apk/* && ./upsnap serve --http 0.0.0.0:8090"
|
||||
|
||||
@@ -1,36 +1,28 @@
|
||||
services:
|
||||
upsnap:
|
||||
cap_add:
|
||||
- NET_RAW # NET_RAW is required for privileged ping, network device scan and ip address tracking (nmap)
|
||||
cap_drop:
|
||||
- ALL
|
||||
container_name: upsnap
|
||||
image: ghcr.io/seriousm4x/upsnap:5 # images are also available on docker hub: seriousm4x/upsnap:5
|
||||
network_mode: host # host is required for WOL magic packets
|
||||
image: ghcr.io/seriousm4x/upsnap:4 # images are also available on docker hub: seriousm4x/upsnap:4
|
||||
network_mode: host
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./data:/app/pb_data
|
||||
# # If you want to use FQDN instead of an IP and it is a ".local" domain, avahi and dbus must be installed on
|
||||
# # the host, and the host dbus must be mounted in the container.
|
||||
# # Before uncommmenting, ensure you are familiar with potential security implications of mounting dbus
|
||||
# - /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket:ro
|
||||
|
||||
# # To use a non-root user, create the mountpoint first (mkdir data) so that it has the right permission.
|
||||
# user: 1000:1000
|
||||
# environment:
|
||||
# - TZ=Europe/Berlin # Set container timezone for cron schedules
|
||||
# - UPSNAP_HTTP_LISTEN=127.0.0.1:8090
|
||||
# - UPSNAP_INTERVAL=*/10 * * * * * # Sets the interval in which the devices are pinged
|
||||
# - UPSNAP_LOG_LEVEL=INFO # Console level for UpSnap logs: DEBUG, INFO, WARN, ERROR, or OFF
|
||||
# - 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_SCAN_TIMEOUT=500ms # Scan timeout is nmap's --host-timeout value to wait for devices (https://nmap.org/book/man-performance.html)
|
||||
# - UPSNAP_PING_PRIVILEGED=true # Default is true. Set to false for unprivileged ping
|
||||
# For Linux hosts, unprivileged pings REQUIRES the host to set 'sysctl net.ipv4.ping_group_range="0 2147483647"'
|
||||
# or another suitable value to grant the group access to send ping and WOL magic packets.
|
||||
# - UPSNAP_PING_PRIVILEGED=true # Set to false if you don't have root user permissions
|
||||
# - UPSNAP_WEBSITE_TITLE=Custom name # Custom website title
|
||||
# security_opt:
|
||||
# - no-new-privileges=true
|
||||
# # dns is used for name resolution during network scan
|
||||
# dns:
|
||||
# - 192.18.0.1
|
||||
# - 192.18.0.2
|
||||
# # you can change the listen ip:port inside the container like this:
|
||||
# entrypoint: /bin/sh -c "./upsnap serve --http 0.0.0.0:5000"
|
||||
# healthcheck:
|
||||
# test: curl -fs "http://localhost:5000/api/health" || exit 1
|
||||
# interval: 10s
|
||||
# # or install custom packages for shutdown
|
||||
# entrypoint: /bin/sh -c "apk update && apk add --no-cache <YOUR_PACKAGE> && rm -rf /var/cache/apk/* && ./upsnap serve --http 0.0.0.0:8090"
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"adapter": "svelte",
|
||||
"$schema": "https://unpkg.com/typesafe-i18n@5.26.2/schema/typesafe-i18n.json",
|
||||
"outputPath": "./src/lib/i18n/"
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"dev": "npm-run-all --parallel vite typesafe-i18n",
|
||||
"vite": "vite dev",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
@@ -11,33 +11,33 @@
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"lint": "eslint --fix --cache .",
|
||||
"format": "prettier --write --cache --cache-strategy content --ignore-path ../.gitignore .",
|
||||
"prepare": "svelte-kit sync && cd .. && husky frontend/.husky",
|
||||
"machine-translate": "inlang machine translate --project project.inlang"
|
||||
"prepare": "cd .. && husky frontend/.husky",
|
||||
"typesafe-i18n": "typesafe-i18n"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^2.1.1",
|
||||
"@eslint/js": "^10.0.1",
|
||||
"@inlang/cli": "^3.6.0",
|
||||
"@inlang/paraglide-js": "^2.29.3",
|
||||
"@sveltejs/adapter-static": "^3.0.11",
|
||||
"@sveltejs/kit": "^2.70.4",
|
||||
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
||||
"daisyui": "^5.7.50",
|
||||
"eslint": "^10.14.0",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-plugin-svelte": "^3.24.0",
|
||||
"globals": "^17.14.0",
|
||||
"@eslint/compat": "^1.2.5",
|
||||
"@eslint/js": "^9.19.0",
|
||||
"@sveltejs/adapter-static": "^3.0.8",
|
||||
"@sveltejs/kit": "^2.16.1",
|
||||
"@sveltejs/vite-plugin-svelte": "^3.1.2",
|
||||
"autoprefixer": "^10.4.20",
|
||||
"daisyui": "^4.12.23",
|
||||
"eslint": "^9.19.0",
|
||||
"eslint-config-prettier": "^10.0.1",
|
||||
"eslint-plugin-svelte": "^2.46.1",
|
||||
"globals": "^15.14.0",
|
||||
"husky": "^9.1.7",
|
||||
"prettier": "^3.9.10",
|
||||
"prettier-plugin-svelte": "^4.1.1",
|
||||
"prettier-plugin-tailwindcss": "^0.8.1",
|
||||
"svelte": "^5.57.3",
|
||||
"svelte-check": "^4.7.8",
|
||||
"tailwindcss": "^4.3.4",
|
||||
"tslib": "^2.9.1",
|
||||
"typescript": "^6.0.3",
|
||||
"typescript-eslint": "^8.72.1",
|
||||
"vite": "^8.3.6"
|
||||
"postcss": "^8.5.1",
|
||||
"prettier": "^3.4.2",
|
||||
"prettier-plugin-svelte": "^3.3.3",
|
||||
"prettier-plugin-tailwindcss": "^0.6.11",
|
||||
"svelte": "^4.2.19",
|
||||
"svelte-check": "^4.1.4",
|
||||
"tailwindcss": "^3.4.17",
|
||||
"tslib": "^2.8.1",
|
||||
"typescript": "^5.7.3",
|
||||
"typescript-eslint": "^8.22.0",
|
||||
"vite": "^5.4.14"
|
||||
},
|
||||
"type": "module",
|
||||
"lint-staged": {
|
||||
@@ -45,13 +45,14 @@
|
||||
"*.{js,css,md,svelte,scss}": "prettier --write --cache --cache-strategy content --ignore-path ../.gitignore ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@fortawesome/free-solid-svg-icons": "^7.3.1",
|
||||
"@tailwindcss/vite": "^4.3.4",
|
||||
"cron-parser": "^5.10.3",
|
||||
"date-fns": "^4.4.0",
|
||||
"pocketbase": "^0.28.2",
|
||||
"svelte-fa": "^4.0.4",
|
||||
"svelte-french-toast": "github:seriousm4x/svelte-french-toast#fix-72-build",
|
||||
"theme-change": "^2.5.2"
|
||||
"@fortawesome/free-solid-svg-icons": "^6.7.2",
|
||||
"cron-parser": "^4.9.0",
|
||||
"date-fns": "^4.1.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"pocketbase": "^0.25.1",
|
||||
"svelte-fa": "^4.0.3",
|
||||
"svelte-french-toast": "^1.2.0",
|
||||
"theme-change": "^2.5.0",
|
||||
"typesafe-i18n": "^5.26.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
allowBuilds:
|
||||
esbuild: true
|
||||
svelte-french-toast: true
|
||||
svelte-french-toast@https://codeload.github.com/seriousm4x/svelte-french-toast/tar.gz/fbf89b9952cf11e15174b1841a6eb1ad23770349: true
|
||||
@@ -0,0 +1,6 @@
|
||||
export default {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {}
|
||||
}
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
# IF GIT SHOWED THAT THIS FILE CHANGED
|
||||
#
|
||||
# 1. RUN THE FOLLOWING COMMAND
|
||||
#
|
||||
# ---
|
||||
# git rm --cached '**/*.inlang/.gitignore'
|
||||
# ---
|
||||
#
|
||||
# 2. COMMIT THE CHANGE
|
||||
#
|
||||
# ---
|
||||
# git commit -m "fix: remove tracked .gitignore from inlang project"
|
||||
# ---
|
||||
#
|
||||
# Inlang handles the gitignore itself starting with version ^2.5.
|
||||
#
|
||||
# everything is ignored except settings.json and Paraglide configuration
|
||||
*
|
||||
!settings.json
|
||||
!descriptions.json
|
||||
!paraglide.config.js
|
||||
!paraglide.config.mjs
|
||||
!paraglide.config.ts
|
||||
!paraglide.config.cjs
|
||||
@@ -1 +0,0 @@
|
||||
StfXY3tZWvr4FQntlM
|
||||
@@ -1,37 +0,0 @@
|
||||
{
|
||||
"$schema": "https://inlang.com/schema/project-settings",
|
||||
"baseLocale": "en-US",
|
||||
"locales": [
|
||||
"ar-SA",
|
||||
"bg-BG",
|
||||
"cs-CZ",
|
||||
"de-DE",
|
||||
"el-GR",
|
||||
"en-US",
|
||||
"es-ES",
|
||||
"fr-FR",
|
||||
"hi-IN",
|
||||
"id-ID",
|
||||
"it-IT",
|
||||
"ja-JP",
|
||||
"ko-KR",
|
||||
"nl-NL",
|
||||
"nb-NO",
|
||||
"pl-PL",
|
||||
"pt-BR",
|
||||
"pt-PT",
|
||||
"ru-RU",
|
||||
"uk-UA",
|
||||
"vi-VN",
|
||||
"zh-TW",
|
||||
"zh-CN"
|
||||
],
|
||||
"modules": [
|
||||
"https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@4/dist/index.js",
|
||||
"https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@2/dist/index.js"
|
||||
],
|
||||
"plugin.inlang.messageFormat": {
|
||||
"pathPattern": "./translations/{locale}.json"
|
||||
},
|
||||
"telemetry": "off"
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
@import 'tailwindcss';
|
||||
|
||||
@plugin 'daisyui' {
|
||||
themes: all;
|
||||
}
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="%lang%">
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<link rel="manifest" href="/manifest.webmanifest" />
|
||||
%sveltekit.head%
|
||||
<script>
|
||||
const darkTheme = 'dim';
|
||||
const lightTheme = 'silk';
|
||||
const darkTheme = 'dark';
|
||||
const lightTheme = 'cupcake';
|
||||
const preferesDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
const theme = localStorage.getItem('theme')
|
||||
? localStorage.getItem('theme')
|
||||
@@ -24,7 +25,6 @@
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div style="display: contents">%sveltekit.body%</div>
|
||||
</body>
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import { paraglideMiddleware } from '$lib/paraglide/server';
|
||||
import { localeStore } from '$lib/stores/locale';
|
||||
import type { Handle } from '@sveltejs/kit';
|
||||
|
||||
// creating a handle to use the paraglide middleware
|
||||
const paraglideHandle: Handle = ({ event, resolve }) =>
|
||||
paraglideMiddleware(event.request, ({ locale }) => {
|
||||
localeStore.set(locale);
|
||||
return resolve(event, {
|
||||
transformPageChunk: ({ html }) => html.replace('%lang%', locale)
|
||||
});
|
||||
});
|
||||
|
||||
export const handle: Handle = paraglideHandle;
|
||||
@@ -1,6 +0,0 @@
|
||||
import { deLocalizeUrl } from '$lib/paraglide/runtime';
|
||||
import type { Reroute } from '@sveltejs/kit';
|
||||
|
||||
export const reroute: Reroute = (request) => {
|
||||
return deLocalizeUrl(request.url).pathname;
|
||||
};
|
||||
@@ -1,11 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { resolve } from '$app/paths';
|
||||
import { nextCronDate } from '$lib/helpers/cron';
|
||||
import { m } from '$lib/paraglide/messages';
|
||||
import { dateFnsLocale } from '$lib/stores/locale';
|
||||
import LL, { locale } from '$lib/i18n/i18n-svelte';
|
||||
import { backendUrl, permission, pocketbase } from '$lib/stores/pocketbase';
|
||||
import { type Device } from '$lib/types/device';
|
||||
import type { Device } from '$lib/types/device';
|
||||
import { cronRegex } from '$lib/types/device';
|
||||
import {
|
||||
faBed,
|
||||
faCircleArrowDown,
|
||||
@@ -14,17 +12,35 @@
|
||||
faPen,
|
||||
faRotateLeft
|
||||
} from '@fortawesome/free-solid-svg-icons';
|
||||
import { formatDistance, parseISO } from 'date-fns';
|
||||
import cronParser from 'cron-parser';
|
||||
import type { Locale } from 'date-fns';
|
||||
import { formatDistance, formatRelative, parseISO } from 'date-fns';
|
||||
import { de } from 'date-fns/locale/de';
|
||||
import { enUS } from 'date-fns/locale/en-US';
|
||||
import { es } from 'date-fns/locale/es';
|
||||
import { fr } from 'date-fns/locale/fr';
|
||||
import { it } from 'date-fns/locale/it';
|
||||
import { ja } from 'date-fns/locale/ja';
|
||||
import { nl } from 'date-fns/locale/nl';
|
||||
import { pt } from 'date-fns/locale/pt';
|
||||
import { zhCN } from 'date-fns/locale/zh-CN';
|
||||
import { zhTW } from 'date-fns/locale/zh-TW';
|
||||
import Fa from 'svelte-fa';
|
||||
import toast from 'svelte-french-toast';
|
||||
import { scale } from 'svelte/transition';
|
||||
import DeviceCardNic from './DeviceCardNic.svelte';
|
||||
|
||||
let { device = $bindable() }: { device: Device } = $props();
|
||||
let modalReboot: HTMLDialogElement;
|
||||
let moreButtons = $derived([
|
||||
export let device: Device;
|
||||
|
||||
$: moreButtons = [
|
||||
{
|
||||
text: m.device_card_btn_more_sleep(),
|
||||
text: $LL.device.card_btn_more_edit(),
|
||||
icon: faPen,
|
||||
onClick: () => goto(`/device/${device.id}`),
|
||||
requires: $pocketbase.authStore.isSuperuser || $permission.update?.includes(device.id)
|
||||
},
|
||||
{
|
||||
text: $LL.device.card_btn_more_sleep(),
|
||||
icon: faBed,
|
||||
onClick: () => sleep(),
|
||||
requires:
|
||||
@@ -33,31 +49,77 @@
|
||||
device.sol_enabled
|
||||
},
|
||||
{
|
||||
text: m.device_card_btn_more_reboot(),
|
||||
text: $LL.device.card_btn_more_reboot(),
|
||||
icon: faRotateLeft,
|
||||
onClick: () => askRebootConfirmation(),
|
||||
onClick: () => reboot(),
|
||||
requires:
|
||||
($pocketbase.authStore.isSuperuser || $permission.power?.includes(device.id)) &&
|
||||
device.status === 'online' &&
|
||||
device.shutdown_cmd !== ''
|
||||
},
|
||||
{
|
||||
text: m.device_card_btn_more_edit(),
|
||||
icon: faPen,
|
||||
onClick: () => goto(resolve(`/device?id=${device.id}`)),
|
||||
requires: $pocketbase.authStore.isSuperuser || $permission.update?.includes(device.id)
|
||||
}
|
||||
]);
|
||||
];
|
||||
|
||||
// update device status change
|
||||
let now = $state(Date.now());
|
||||
let now = Date.now();
|
||||
let interval: number;
|
||||
$effect(() => {
|
||||
$: {
|
||||
clearInterval(interval);
|
||||
interval = setInterval(() => {
|
||||
now = Date.now();
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
// dynamically import locales
|
||||
// it's ugly but the only working solution i found in ~ 3 hours
|
||||
var dateFnsLocale: Locale;
|
||||
$: if ($locale !== undefined) {
|
||||
(async () => {
|
||||
switch ($locale) {
|
||||
case 'de':
|
||||
case 'de-DE':
|
||||
dateFnsLocale = de;
|
||||
break;
|
||||
case 'en':
|
||||
case 'en-US':
|
||||
dateFnsLocale = enUS;
|
||||
break;
|
||||
case 'fr':
|
||||
case 'fr-FR':
|
||||
dateFnsLocale = fr;
|
||||
break;
|
||||
case 'it':
|
||||
case 'it-IT':
|
||||
dateFnsLocale = it;
|
||||
break;
|
||||
case 'ja':
|
||||
case 'ja-JP':
|
||||
dateFnsLocale = ja;
|
||||
break;
|
||||
case 'es':
|
||||
case 'es-ES':
|
||||
dateFnsLocale = es;
|
||||
break;
|
||||
case 'nl':
|
||||
case 'nl-NL':
|
||||
dateFnsLocale = nl;
|
||||
break;
|
||||
case 'pt':
|
||||
case 'pt-PT':
|
||||
dateFnsLocale = pt;
|
||||
break;
|
||||
case 'zh':
|
||||
case 'zh-CN':
|
||||
dateFnsLocale = zhCN;
|
||||
break;
|
||||
case 'zh-TW':
|
||||
dateFnsLocale = zhTW;
|
||||
break;
|
||||
default:
|
||||
dateFnsLocale = enUS;
|
||||
break;
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
function sleep() {
|
||||
fetch(`${backendUrl}api/upsnap/sleep/${device.id}`, {
|
||||
@@ -79,52 +141,59 @@
|
||||
});
|
||||
}
|
||||
|
||||
function askRebootConfirmation() {
|
||||
if (device.shutdown_confirm) {
|
||||
modalReboot.showModal();
|
||||
} else {
|
||||
reboot();
|
||||
function getNextCronRelativeTime(expression: string, now: number) {
|
||||
if (!cronRegex.test(expression)) {
|
||||
return 'Invalid cron';
|
||||
}
|
||||
|
||||
try {
|
||||
const cron = cronParser.parseExpression(expression);
|
||||
return formatRelative(cron.next().toISOString(), now, {
|
||||
locale: dateFnsLocale
|
||||
});
|
||||
} catch {
|
||||
return 'Invalid cron';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="card bg-base-200 shadow-sm" transition:scale={{ delay: 0, duration: 200 }}>
|
||||
<div class="card rounded-3xl bg-base-300 shadow-md" transition:scale={{ delay: 0, duration: 200 }}>
|
||||
<div class="card-body p-6">
|
||||
{#if device.link !== ''}
|
||||
<!-- eslint-disable-next-line svelte/no-navigation-without-resolve -->
|
||||
<a href={device.link} target="_blank">
|
||||
{#if device.link.toString() !== ''}
|
||||
<a href={device.link.toString()} target="_blank">
|
||||
<h1 class="link card-title">{device.name}</h1>
|
||||
</a>
|
||||
{:else}
|
||||
<h1 class="card-title">{device.name}</h1>
|
||||
{/if}
|
||||
{#if device.description}
|
||||
<p class="grow-0">{device.description}</p>
|
||||
<p>{device.description}</p>
|
||||
{/if}
|
||||
<div class="card rounded-box w-full">
|
||||
<DeviceCardNic bind:device />
|
||||
</div>
|
||||
<ul class="menu rounded-box bg-base-200">
|
||||
<DeviceCardNic {device} />
|
||||
</ul>
|
||||
{#if device.wake_cron_enabled || device.shutdown_cron_enabled || device.password}
|
||||
<div class="mt-1 flex flex-row flex-wrap gap-2">
|
||||
{#if device.wake_cron_enabled}
|
||||
<div class="tooltip" data-tip={m.device_card_tooltip_wake_cron()}>
|
||||
<div class="tooltip" data-tip={$LL.device.card_tooltip_wake_cron()}>
|
||||
<span class="badge badge-success gap-1 p-3"
|
||||
><Fa icon={faCircleArrowUp} />
|
||||
{nextCronDate(device.wake_cron)}
|
||||
</span>
|
||||
><Fa icon={faCircleArrowUp} />{getNextCronRelativeTime(device.wake_cron, now)}</span
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
{#if device.shutdown_cron_enabled}
|
||||
<div class="tooltip" data-tip={m.device_card_tooltip_shutdown_cron()}>
|
||||
<div class="tooltip" data-tip={$LL.device.card_tooltip_shutdown_cron()}>
|
||||
<span class="badge badge-error gap-1 p-3"
|
||||
><Fa icon={faCircleArrowDown} />
|
||||
{nextCronDate(device.shutdown_cron)}
|
||||
</span>
|
||||
><Fa icon={faCircleArrowDown} />{getNextCronRelativeTime(
|
||||
device.shutdown_cron,
|
||||
now
|
||||
)}</span
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
{#if device.password}
|
||||
<div class="tooltip" data-tip={m.device_card_tooltip_wake_password()}>
|
||||
<span class="badge gap-1 p-3"><Fa icon={faLock} />{m.device_card_password()}</span>
|
||||
<div class="tooltip" data-tip={$LL.device.card_tooltip_wake_password()}>
|
||||
<span class="badge gap-1 p-3"><Fa icon={faLock} />{$LL.device.card_password()}</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -132,42 +201,38 @@
|
||||
<div class="card-actions mt-auto items-center">
|
||||
<span
|
||||
class="tooltip"
|
||||
data-tip="{m.device_card_tooltip_last_status_change()}: {device.updated}"
|
||||
data-tip="{$LL.device.card_tooltip_last_status_change()}: {device.updated}"
|
||||
>
|
||||
{formatDistance(parseISO(device.updated), now, {
|
||||
includeSeconds: true,
|
||||
addSuffix: true,
|
||||
locale: $dateFnsLocale
|
||||
})}
|
||||
{#if dateFnsLocale !== undefined}
|
||||
{formatDistance(parseISO(device.updated), now, {
|
||||
includeSeconds: true,
|
||||
addSuffix: true,
|
||||
locale: dateFnsLocale
|
||||
})}
|
||||
{/if}
|
||||
</span>
|
||||
{#if moreButtons.filter((btn) => btn.requires).length > 0}
|
||||
<div class="ms-auto flex flex-row flex-wrap gap-1">
|
||||
{#each moreButtons as btn, i (i)}
|
||||
{#if btn.requires}
|
||||
<div class="tooltip" data-tip={btn.text}>
|
||||
<button class="btn btn-sm btn-circle" onclick={btn.onClick}>
|
||||
<Fa icon={btn.icon} />
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
<div class="dropdown dropdown-end dropdown-top ms-auto bg-base-300">
|
||||
<label tabindex="-1" class="btn btn-sm m-1" for="more-{device.id}"
|
||||
>{$LL.device.card_btn_more()}</label
|
||||
>
|
||||
<ul
|
||||
id="more-{device.id}"
|
||||
tabindex="-1"
|
||||
class="menu dropdown-content z-[1] w-fit rounded-box bg-base-100 p-2 shadow"
|
||||
>
|
||||
{#each moreButtons as btn}
|
||||
{#if btn.requires}
|
||||
<li>
|
||||
<button on:click={btn.onClick}>
|
||||
<Fa icon={btn.icon} />{btn.text}
|
||||
</button>
|
||||
</li>
|
||||
{/if}
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<dialog class="modal" bind:this={modalReboot}>
|
||||
<div class="modal-box">
|
||||
<h3 class="text-lg font-bold">
|
||||
{m.device_modal_confirm_shutdown_title({ device: device.name })}
|
||||
</h3>
|
||||
<p class="py-4">{m.device_modal_confirm_shutdown_desc({ device: device.name })}</p>
|
||||
<div class="modal-action">
|
||||
<form method="dialog">
|
||||
<button class="btn">{m.buttons_cancel()}</button>
|
||||
<button class="btn btn-success" onclick={reboot}>{m.buttons_confirm()}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
@@ -1,56 +1,50 @@
|
||||
<script lang="ts">
|
||||
import { m } from '$lib/paraglide/messages';
|
||||
import LL from '$lib/i18n/i18n-svelte';
|
||||
import { backendUrl, permission, pocketbase } from '$lib/stores/pocketbase';
|
||||
import type { Device } from '$lib/types/device';
|
||||
import { faPowerOff } from '@fortawesome/free-solid-svg-icons';
|
||||
import { faCircle, faPowerOff } from '@fortawesome/free-solid-svg-icons';
|
||||
import Fa from 'svelte-fa';
|
||||
import toast from 'svelte-french-toast';
|
||||
|
||||
let { device = $bindable() }: { device: Device } = $props();
|
||||
let hoverText = $state('');
|
||||
let disabled = $state(false);
|
||||
let timeout = $state(120);
|
||||
let interval: number;
|
||||
export let device: Device;
|
||||
|
||||
let hoverText = '';
|
||||
let disabled = false;
|
||||
let timeout = 120;
|
||||
var interval: number;
|
||||
let modalWake: HTMLDialogElement;
|
||||
let modalShutdown: HTMLDialogElement;
|
||||
let seconds = $derived(timeout % 60);
|
||||
let minutes = $derived(Math.floor(timeout / 60));
|
||||
|
||||
$effect(() => {
|
||||
if (device.status === 'pending' && !interval) {
|
||||
countdown(Date.parse(device.updated), 'wake');
|
||||
}
|
||||
});
|
||||
$effect(() => {
|
||||
if (device.status === 'pending' || device.status === '') {
|
||||
$: if (device.status === 'pending' && !interval) {
|
||||
countdown(Date.parse(device.updated));
|
||||
}
|
||||
$: minutes = Math.floor(timeout / 60);
|
||||
$: seconds = timeout % 60;
|
||||
$: if (device.status === 'pending' || device.status === '') {
|
||||
disabled = true;
|
||||
hoverText = $LL.device.card_nic_tooltip_pending();
|
||||
} else if (device.status === 'online') {
|
||||
if (device.shutdown_cmd === '') {
|
||||
disabled = true;
|
||||
hoverText = m.device_card_nic_tooltip_pending();
|
||||
} else if (device.status === 'online') {
|
||||
if (device.shutdown_cmd === '') {
|
||||
disabled = true;
|
||||
hoverText = m.device_card_nic_tooltip_shutdown_no_cmd();
|
||||
} else if (!$pocketbase.authStore.isSuperuser && !$permission.power?.includes(device.id)) {
|
||||
disabled = true;
|
||||
hoverText = m.device_card_nic_tooltip_shutdown_no_permission();
|
||||
} else {
|
||||
disabled = false;
|
||||
hoverText = m.device_card_nic_tooltip_shutdown();
|
||||
}
|
||||
} else if (device.status === 'offline') {
|
||||
if (!$pocketbase.authStore.isSuperuser && !$permission.power?.includes(device.id)) {
|
||||
disabled = true;
|
||||
hoverText = m.device_card_nic_tooltip_power_no_permission();
|
||||
} else {
|
||||
disabled = false;
|
||||
hoverText = m.device_card_nic_tooltip_power();
|
||||
}
|
||||
hoverText = $LL.device.card_nic_tooltip_shutdown_no_cmd();
|
||||
} else if (!$pocketbase.authStore.isSuperuser && !$permission.power?.includes(device.id)) {
|
||||
disabled = true;
|
||||
hoverText = $LL.device.card_nic_tooltip_shutdown_no_permission();
|
||||
} else {
|
||||
disabled = false;
|
||||
hoverText = $LL.device.card_nic_tooltip_shutdown();
|
||||
}
|
||||
});
|
||||
} else if (device.status === 'offline') {
|
||||
if (!$pocketbase.authStore.isSuperuser && !$permission.power?.includes(device.id)) {
|
||||
disabled = true;
|
||||
hoverText = $LL.device.card_nic_tooltip_power_no_permission();
|
||||
} else {
|
||||
disabled = false;
|
||||
hoverText = $LL.device.card_nic_tooltip_power();
|
||||
}
|
||||
}
|
||||
|
||||
function wake() {
|
||||
countdown(Date.now(), 'wake');
|
||||
device.status = 'pending';
|
||||
|
||||
fetch(`${backendUrl}api/upsnap/wake/${device.id}`, {
|
||||
headers: {
|
||||
Authorization: $pocketbase.authStore.token
|
||||
@@ -58,12 +52,10 @@
|
||||
})
|
||||
.then((resp) => resp.json())
|
||||
.then(async (data) => {
|
||||
if (data.status !== 200) {
|
||||
device.status = 'offline';
|
||||
return;
|
||||
}
|
||||
device = data as Device;
|
||||
await countdown(Date.parse(device.updated));
|
||||
if (device.status === 'online' && device.link && device.link_open !== '') {
|
||||
console.log('here');
|
||||
if (device.link_open === 'new_tab') {
|
||||
window.open(device.link, '_blank');
|
||||
} else {
|
||||
@@ -77,49 +69,45 @@
|
||||
}
|
||||
|
||||
function shutdown() {
|
||||
countdown(Date.now(), 'shutdown');
|
||||
device.status = 'pending';
|
||||
|
||||
fetch(`${backendUrl}api/upsnap/shutdown/${device.id}`, {
|
||||
headers: {
|
||||
Authorization: $pocketbase.authStore.token
|
||||
}
|
||||
})
|
||||
.then((resp) => resp.json())
|
||||
.then(async (data) => {
|
||||
if (data.status !== 200) {
|
||||
device.status = 'online';
|
||||
return;
|
||||
}
|
||||
.then((data) => {
|
||||
device = data as Device;
|
||||
countdown(Date.parse(device.updated));
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.error(err.message);
|
||||
});
|
||||
}
|
||||
|
||||
function countdown(updated: number, action: 'wake' | 'shutdown') {
|
||||
timeout = action === 'wake' ? device.wake_timeout : device.shutdown_timeout;
|
||||
if (timeout <= 0) {
|
||||
timeout = 120;
|
||||
}
|
||||
function countdown(updated: number) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
timeout = 120;
|
||||
const end = updated + 2 * 60 * 1000;
|
||||
|
||||
const end = updated + timeout * 1000;
|
||||
if (interval) {
|
||||
clearInterval(interval);
|
||||
interval = 0;
|
||||
}
|
||||
|
||||
if (interval) {
|
||||
clearInterval(interval);
|
||||
interval = 0;
|
||||
}
|
||||
interval = setInterval(() => {
|
||||
timeout = Math.round((end - Date.now()) / 1000);
|
||||
|
||||
interval = setInterval(() => {
|
||||
timeout = Math.round((end - Date.now()) / 1000);
|
||||
|
||||
if (timeout <= 0 || device.status !== 'pending') {
|
||||
clearInterval(interval);
|
||||
|
||||
interval = 0;
|
||||
if (timeout <= 0 || device.status !== 'pending') {
|
||||
clearInterval(interval);
|
||||
interval = 0;
|
||||
resolve(interval);
|
||||
}
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
function handleClick() {
|
||||
@@ -147,81 +135,72 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
class={`tooltip ${disabled ? 'cursor-not-allowed' : 'hover:bg-base-300 cursor-pointer'} bg-base-100 rounded-box flex items-start gap-4 p-2`}
|
||||
data-tip={hoverText}
|
||||
onclick={disabled ? null : handleClick}
|
||||
onkeydown={disabled ? null : handleClick}
|
||||
role="none"
|
||||
>
|
||||
{#if device.status === 'offline'}
|
||||
<button class="btn btn-error btn-circle size-12"><Fa icon={faPowerOff} /></button>
|
||||
{:else if device.status === 'online'}
|
||||
<button
|
||||
class="btn btn-success btn-circle size-12"
|
||||
class:cursor-not-allowed={device.shutdown_cmd === ''}><Fa icon={faPowerOff} /></button
|
||||
>
|
||||
{:else if device.status === 'pending'}
|
||||
<button class="btn btn-warning">
|
||||
<span class="countdown font-mono tabular-nums">
|
||||
<span style="--value:{minutes};--digits: 2"></span>:
|
||||
<span style="--value:{seconds};--digits: 2"></span>
|
||||
</span>
|
||||
</button>
|
||||
{:else}
|
||||
<div class="btn btn-warning btn-circle size-12">
|
||||
<span class="loading loading-ring loading-sm"></span>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="grow">
|
||||
<div class="text-lg leading-4 font-bold">{device.ip}</div>
|
||||
<div>{device.mac}</div>
|
||||
<div class="flex flex-wrap gap-x-4">
|
||||
{#if device?.expand?.ports}
|
||||
{#each $state
|
||||
.snapshot(device)
|
||||
.expand?.ports.sort((a, b) => a.number - b.number) as port (port.id)}
|
||||
<span class="flex items-center gap-1 break-all">
|
||||
{#if port.status}
|
||||
<div class="inline-grid *:[grid-area:1/1]">
|
||||
<div class="status status-success h-3 w-3 animate-ping"></div>
|
||||
<div class="status status-success h-3 w-3"></div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="inline-grid *:[grid-area:1/1]">
|
||||
<div class="status status-error h-3 w-3 animate-ping"></div>
|
||||
<div class="status status-error h-3 w-3"></div>
|
||||
</div>
|
||||
{/if}
|
||||
{#if port.link}
|
||||
<!-- eslint-disable svelte/no-navigation-without-resolve -->
|
||||
<a
|
||||
href={port.link}
|
||||
target="_blank"
|
||||
class="underline"
|
||||
onclick={(e) => e.stopPropagation()}>{port.name} ({port.number})</a
|
||||
>
|
||||
<!-- eslint-enable svelte/no-navigation-without-resolve -->
|
||||
{:else}
|
||||
{port.name} ({port.number})
|
||||
{/if}
|
||||
</span>
|
||||
{/each}
|
||||
{/if}
|
||||
<li class="tooltip" class:disabled data-tip={hoverText}>
|
||||
<div
|
||||
class="flex items-start gap-4 p-2"
|
||||
on:click={disabled ? null : handleClick}
|
||||
on:keydown={disabled ? null : handleClick}
|
||||
role="none"
|
||||
>
|
||||
{#if device.status === 'offline'}
|
||||
<button class="btn btn-error flex-shrink"><Fa icon={faPowerOff} /></button>
|
||||
{:else if device.status === 'online'}
|
||||
<button
|
||||
class="btn btn-success flex-shrink"
|
||||
class:cursor-not-allowed={device.shutdown_cmd === ''}><Fa icon={faPowerOff} /></button
|
||||
>
|
||||
{:else if device.status === 'pending'}
|
||||
<button class="btn btn-warning flex-shrink">
|
||||
<span class="countdown font-mono">
|
||||
<span style="--value:{minutes};" />:
|
||||
<span style="--value:{seconds};" />
|
||||
</span>
|
||||
</button>
|
||||
{:else}
|
||||
<button class="btn btn-warning flex-shrink">
|
||||
<span class="loading loading-ring loading-sm" />
|
||||
</button>
|
||||
{/if}
|
||||
<div class="grow">
|
||||
<div class="text-lg font-bold leading-4">{device.ip}</div>
|
||||
<div>{device.mac}</div>
|
||||
<div class="flex flex-wrap gap-x-4">
|
||||
{#if device?.expand?.ports}
|
||||
{#each device?.expand?.ports.sort((a, b) => a.number - b.number) as port}
|
||||
<span class="flex items-center gap-1 break-all">
|
||||
{#if port.status}
|
||||
<Fa icon={faCircle} class="text-success" />
|
||||
{:else}
|
||||
<Fa icon={faCircle} class="text-error" />
|
||||
{/if}
|
||||
{#if port.link}
|
||||
<a
|
||||
href={port.link}
|
||||
target="_blank"
|
||||
class="underline"
|
||||
on:click={(e) => e.stopPropagation()}>{port.name} ({port.number})</a
|
||||
>
|
||||
{:else}
|
||||
{port.name} ({port.number})
|
||||
{/if}
|
||||
</span>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<dialog class="modal" bind:this={modalWake}>
|
||||
<div class="modal-box">
|
||||
<h3 class="text-lg font-bold">
|
||||
{m.device_modal_confirm_wake_title({ device: device.name })}
|
||||
{$LL.device.modal_confirm_wake_title({ device: device.name })}
|
||||
</h3>
|
||||
<p class="py-4">{m.device_modal_confirm_wake_desc({ device: device.name })}</p>
|
||||
<p class="py-4">{$LL.device.modal_confirm_wake_desc({ device: device.name })}</p>
|
||||
<div class="modal-action">
|
||||
<form method="dialog">
|
||||
<button class="btn">{m.buttons_cancel()}</button>
|
||||
<button class="btn btn-success" onclick={wake}>{m.buttons_confirm()}</button>
|
||||
<form method="dialog" class="flex flex-row flex-wrap gap-2">
|
||||
<button class="btn btn-neutral">{$LL.buttons.cancel()}</button>
|
||||
<button class="btn btn-success" on:click={wake}>{$LL.buttons.confirm()}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -230,14 +209,20 @@
|
||||
<dialog class="modal" bind:this={modalShutdown}>
|
||||
<div class="modal-box">
|
||||
<h3 class="text-lg font-bold">
|
||||
{m.device_modal_confirm_shutdown_title({ device: device.name })}
|
||||
{$LL.device.modal_confirm_shutdown_title({ device: device.name })}
|
||||
</h3>
|
||||
<p class="py-4">{m.device_modal_confirm_shutdown_desc({ device: device.name })}</p>
|
||||
<p class="py-4">{$LL.device.modal_confirm_shutdown_desc({ device: device.name })}</p>
|
||||
<div class="modal-action">
|
||||
<form method="dialog">
|
||||
<button class="btn">{m.buttons_cancel()}</button>
|
||||
<button class="btn btn-success" onclick={shutdown}>{m.buttons_confirm()}</button>
|
||||
<form method="dialog" class="flex flex-row flex-wrap gap-2">
|
||||
<button class="btn btn-neutral">{$LL.buttons.cancel()}</button>
|
||||
<button class="btn btn-success" on:click={shutdown}>{$LL.buttons.confirm()}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<style>
|
||||
:global(.menu li.disabled) {
|
||||
color: inherit;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { m } from '$lib/paraglide/messages';
|
||||
import LL from '$lib/i18n/i18n-svelte';
|
||||
import { pocketbase } from '$lib/stores/pocketbase';
|
||||
import type { Device, Port } from '$lib/types/device';
|
||||
import { faTrash } from '@fortawesome/free-solid-svg-icons';
|
||||
import type { RecordModel } from 'pocketbase';
|
||||
import Fa from 'svelte-fa';
|
||||
import toast from 'svelte-french-toast';
|
||||
import { scale } from 'svelte/transition';
|
||||
|
||||
export let device: Device;
|
||||
export let index: number;
|
||||
@@ -27,51 +28,57 @@
|
||||
</script>
|
||||
|
||||
{#if device.expand.ports[index]}
|
||||
<fieldset class="fieldset bg-base-100 border-base-300 rounded-box w-xs max-w-full border p-4">
|
||||
<legend class="fieldset-legend"># {device.expand.ports.length}</legend>
|
||||
<div class="flex flex-row gap-2">
|
||||
<fieldset class="fieldset">
|
||||
<label class="floating-label">
|
||||
<span>{m.device_ports_name()} <span class="text-error">*</span></span>
|
||||
<div class="card bg-base-100 shadow-sm" transition:scale={{ delay: 0, duration: 200 }}>
|
||||
<div class="card-body p-3">
|
||||
<div class="flex flex-row gap-2">
|
||||
<div>
|
||||
<label class="label p-0" for="port-name-{index}">
|
||||
<span class="label-text">{$LL.device.ports_name()}</span>
|
||||
</label>
|
||||
<input
|
||||
id="port-name-{index}"
|
||||
type="text"
|
||||
placeholder={m.device_ports_name()}
|
||||
class="input"
|
||||
placeholder="ssh"
|
||||
class="input input-sm input-bordered w-full"
|
||||
required
|
||||
bind:value={device.expand.ports[index].name}
|
||||
/>
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset class="fieldset">
|
||||
<label class="floating-label">
|
||||
<span>{m.device_ports_number()} <span class="text-error">*</span></span>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label p-0" for="port-number-{index}">
|
||||
<span class="label-text">{$LL.device.ports_number()}</span>
|
||||
</label>
|
||||
<input
|
||||
id="port-number-{index}"
|
||||
type="number"
|
||||
placeholder={m.device_ports_number()}
|
||||
class="input"
|
||||
placeholder="22"
|
||||
min="1"
|
||||
max="65535"
|
||||
class="input input-sm input-bordered w-full"
|
||||
required
|
||||
bind:value={device.expand.ports[index].number}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label p-0" for="port-link-{index}">
|
||||
<span class="label-text">{$LL.device.link()}</span>
|
||||
</label>
|
||||
</fieldset>
|
||||
</div>
|
||||
<fieldset class="fieldset">
|
||||
<label class="floating-label">
|
||||
<span>{m.device_link()}</span>
|
||||
<input
|
||||
type="text"
|
||||
placeholder={m.device_link()}
|
||||
class="input"
|
||||
id="port-link-{index}"
|
||||
type="url"
|
||||
placeholder="https:// ..."
|
||||
class="input input-sm input-bordered w-full"
|
||||
bind:value={device.expand.ports[index].link}
|
||||
/>
|
||||
</label>
|
||||
</fieldset>
|
||||
<button
|
||||
class="btn btn-error btn-xs btn-soft ms-auto"
|
||||
onclick={() => deletePort(device.expand.ports[index])}
|
||||
type="button"><Fa icon={faTrash} />{m.buttons_delete()}</button
|
||||
>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="card-actions justify-end">
|
||||
<button
|
||||
class="btn btn-outline btn-error btn-xs"
|
||||
on:click={() => deletePort(device.expand.ports[index])}
|
||||
type="button"><Fa icon={faTrash} />{$LL.buttons.delete()}</button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { asset, resolve } from '$app/paths';
|
||||
import { page } from '$app/state';
|
||||
import { m } from '$lib/paraglide/messages';
|
||||
import { page } from '$app/stores';
|
||||
import LL from '$lib/i18n/i18n-svelte';
|
||||
import { backendUrl, permission, pocketbase } from '$lib/stores/pocketbase';
|
||||
import { settingsPub } from '$lib/stores/settings';
|
||||
import {
|
||||
@@ -11,7 +10,6 @@
|
||||
faCog,
|
||||
faDoorOpen,
|
||||
faHome,
|
||||
faListUl,
|
||||
faPlus,
|
||||
faSwatchbook,
|
||||
faUserGear,
|
||||
@@ -54,12 +52,10 @@
|
||||
'dim',
|
||||
'nord',
|
||||
'sunset',
|
||||
'caramellatte',
|
||||
'abyss',
|
||||
'silk'
|
||||
'colorful'
|
||||
];
|
||||
let activeTheme: string | null = '';
|
||||
let avatar = $pocketbase.authStore.record?.avatar;
|
||||
$: avatar = $pocketbase.authStore.record?.avatar;
|
||||
|
||||
onMount(() => {
|
||||
themeChange(false);
|
||||
@@ -75,7 +71,7 @@
|
||||
await $pocketbase.collection('ports').unsubscribe('*');
|
||||
await $pocketbase.collection('permissions').unsubscribe('*');
|
||||
$pocketbase.authStore.clear();
|
||||
goto(resolve('/login'), { invalidateAll: true });
|
||||
goto('/login', { invalidateAll: true });
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -104,7 +100,7 @@
|
||||
<ul
|
||||
id="mobile-menu"
|
||||
tabindex="-1"
|
||||
class="menu dropdown-content rounded-box bg-base-200 z-1 mt-3 w-max gap-1 p-2 shadow-sm"
|
||||
class="menu dropdown-content z-[1] mt-3 w-max gap-1 rounded-box bg-base-300 p-2 shadow"
|
||||
>
|
||||
{#if $settingsPub?.website_title}
|
||||
<div class="menu-title">
|
||||
@@ -112,33 +108,25 @@
|
||||
</div>
|
||||
{/if}
|
||||
<li>
|
||||
<a href={resolve('/')} class="px-4 py-2" class:active={page.url.pathname === resolve('/')}
|
||||
><Fa icon={faHome} />{m.home_page_title()}</a
|
||||
<a href="/" class="px-4 py-2" class:active={$page.url.pathname === '/'}
|
||||
><Fa icon={faHome} />{$LL.home.page_title()}</a
|
||||
>
|
||||
</li>
|
||||
{#if $pocketbase.authStore.isSuperuser}
|
||||
<li>
|
||||
<a
|
||||
href={resolve('/users')}
|
||||
href="/users"
|
||||
class="px-4 py-2"
|
||||
class:active={page.url.pathname.startsWith(resolve('/users'))}
|
||||
><Fa icon={faUsersGear} />{m.users_page_title()}</a
|
||||
class:active={$page.url.pathname.startsWith('/users')}
|
||||
><Fa icon={faUsersGear} />{$LL.users.page_title()}</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
href={resolve('/settings/')}
|
||||
href="/settings/"
|
||||
class="px-4 py-2"
|
||||
class:active={page.url.pathname.startsWith(resolve('/settings'))}
|
||||
><Fa icon={faCog} />{m.settings_page_title()}</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
href={resolve('/logs/')}
|
||||
class="px-4 py-2"
|
||||
class:active={page.url.pathname.startsWith(resolve('/logs'))}
|
||||
><Fa icon={faListUl} />{m.logs_page_title()}</a
|
||||
class:active={$page.url.pathname.startsWith('/settings')}
|
||||
><Fa icon={faCog} />{$LL.settings.page_title()}</a
|
||||
>
|
||||
</li>
|
||||
{/if}
|
||||
@@ -150,25 +138,36 @@
|
||||
>
|
||||
<ul>
|
||||
<div class="h-fit max-h-72 overflow-scroll">
|
||||
{#each availableThemes as theme (theme)}
|
||||
<li class="w-full">
|
||||
{#each availableThemes as theme}
|
||||
<li>
|
||||
<button
|
||||
class="gap-3 px-2"
|
||||
class="overflow-hidden rounded-lg text-left outline-base-content"
|
||||
data-set-theme={theme}
|
||||
onclick={() => (activeTheme = theme)}
|
||||
onkeydown={() => (activeTheme = theme)}
|
||||
on:click={() => (activeTheme = theme)}
|
||||
on:keydown={() => (activeTheme = theme)}
|
||||
>
|
||||
<div
|
||||
data-theme={theme}
|
||||
class="bg-base-100 grid shrink-0 grid-cols-2 gap-0.5 rounded-md p-1 shadow-sm"
|
||||
class="w-full cursor-pointer rounded bg-base-100 font-sans text-base-content"
|
||||
>
|
||||
<div class="bg-base-content size-1 rounded-full"></div>
|
||||
<div class="bg-primary size-1 rounded-full"></div>
|
||||
<div class="bg-secondary size-1 rounded-full"></div>
|
||||
<div class="bg-accent size-1 rounded-full"></div>
|
||||
<div class="grid grid-cols-5 grid-rows-3">
|
||||
<div
|
||||
class="col-span-5 row-span-3 row-start-1 flex items-center gap-2 px-4 py-3"
|
||||
>
|
||||
<Fa
|
||||
icon={faCheck}
|
||||
class={activeTheme === theme ? 'visible' : 'invisible'}
|
||||
/>
|
||||
<div class="flex-grow text-sm">{theme}</div>
|
||||
<div class="flex h-full flex-shrink-0 flex-wrap gap-1">
|
||||
<div class="w-2 rounded bg-primary" />
|
||||
<div class="w-2 rounded bg-secondary" />
|
||||
<div class="w-2 rounded bg-accent" />
|
||||
<div class="w-2 rounded bg-neutral" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="truncate">{theme}</div>
|
||||
<Fa icon={faCheck} class={activeTheme === theme ? 'visible' : 'invisible'} />
|
||||
</button>
|
||||
</li>
|
||||
{/each}
|
||||
@@ -178,11 +177,11 @@
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<a class="btn btn-ghost h-full border-0 px-2 text-xl" href={resolve('/')}>
|
||||
<a class="btn btn-ghost px-2 text-xl normal-case" href="/">
|
||||
<img
|
||||
src={$settingsPub?.id && $settingsPub?.favicon
|
||||
? `${backendUrl}api/files/settings_public/${$settingsPub?.id}/${$settingsPub?.favicon}`
|
||||
: asset('/gopher.svg')}
|
||||
: '/gopher.svg'}
|
||||
alt={$settingsPub?.website_title ? $settingsPub?.website_title : 'UpSnap'}
|
||||
width="45"
|
||||
height="45"
|
||||
@@ -191,92 +190,84 @@
|
||||
</div>
|
||||
<div class="hidden {$settingsPub?.website_title ? 'lg:flex' : 'md:flex'}">
|
||||
{#if $settingsPub?.website_title}
|
||||
<span class="self-center px-2">{$settingsPub?.website_title}</span>
|
||||
<span class="px-2">{$settingsPub?.website_title}</span>
|
||||
{/if}
|
||||
<ul class="menu menu-horizontal h-full gap-1 px-1">
|
||||
<li class="h-full">
|
||||
<a href={resolve('/')} class="p-2" class:menu-active={page.url.pathname === resolve('/')}
|
||||
><Fa icon={faHome} />{m.home_page_title()}</a
|
||||
<ul class="menu menu-horizontal gap-1 px-1">
|
||||
<li>
|
||||
<a href="/" class="p-2" class:active={$page.url.pathname === '/'}
|
||||
><Fa icon={faHome} />{$LL.home.page_title()}</a
|
||||
>
|
||||
</li>
|
||||
{#if $pocketbase.authStore.isSuperuser}
|
||||
<li class="h-full">
|
||||
<a
|
||||
href={resolve('/users')}
|
||||
class="p-2"
|
||||
class:menu-active={page.url.pathname.startsWith(resolve('/users'))}
|
||||
><Fa icon={faUsersGear} />{m.users_page_title()}</a
|
||||
<li>
|
||||
<a href="/users" class="p-2" class:active={$page.url.pathname.startsWith('/users')}
|
||||
><Fa icon={faUsersGear} />{$LL.users.page_title()}</a
|
||||
>
|
||||
</li>
|
||||
<li class="h-full">
|
||||
<a
|
||||
href={resolve('/settings/')}
|
||||
class="p-2"
|
||||
class:menu-active={page.url.pathname.startsWith(resolve('/settings'))}
|
||||
><Fa icon={faCog} />{m.settings_page_title()}</a
|
||||
>
|
||||
</li>
|
||||
<li class="h-full">
|
||||
<a
|
||||
href={resolve('/logs/')}
|
||||
class="p-2"
|
||||
class:menu-active={page.url.pathname.startsWith(resolve('/logs'))}
|
||||
><Fa icon={faListUl} />{m.logs_page_title()}</a
|
||||
<li>
|
||||
<a href="/settings/" class="p-2" class:active={$page.url.pathname.startsWith('/settings')}
|
||||
><Fa icon={faCog} />{$LL.settings.page_title()}</a
|
||||
>
|
||||
</li>
|
||||
{/if}
|
||||
<div class="dropdown dropdown-end">
|
||||
<button class="btn btn-ghost hover:bg-base-content/10 h-full border-0 p-2" tabindex="0">
|
||||
<Fa icon={faSwatchbook} />
|
||||
<span class="font-normal">{m.navbar_theme()}</span>
|
||||
<Fa icon={faChevronDown} />
|
||||
</button>
|
||||
<div class="dropdown-content bg-base-200 rounded-box z-1 mt-3 w-52 shadow-sm">
|
||||
<ul class="menu menu-horizontal h-fit max-h-96 overflow-y-auto">
|
||||
{#each availableThemes as theme (theme)}
|
||||
<li class="w-full">
|
||||
<button
|
||||
class="gap-3 px-2"
|
||||
data-set-theme={theme}
|
||||
onclick={() => (activeTheme = theme)}
|
||||
onkeydown={() => (activeTheme = theme)}
|
||||
>
|
||||
<div
|
||||
data-theme={theme}
|
||||
class="bg-base-100 grid shrink-0 grid-cols-2 gap-0.5 rounded-md p-1 shadow-sm"
|
||||
>
|
||||
<div class="bg-base-content size-1 rounded-full"></div>
|
||||
<div class="bg-primary size-1 rounded-full"></div>
|
||||
<div class="bg-secondary size-1 rounded-full"></div>
|
||||
<div class="bg-accent size-1 rounded-full"></div>
|
||||
</ul>
|
||||
<div class="dropdown dropdown-end">
|
||||
<div tabindex="-1" class="btn btn-ghost normal-case">
|
||||
<Fa icon={faSwatchbook} />
|
||||
<span class="font-normal">{$LL.navbar.theme()}</span>
|
||||
<Fa icon={faChevronDown} />
|
||||
</div>
|
||||
<div
|
||||
class="dropdown-content z-[1] mt-3 h-fit max-h-96 w-56 overflow-y-auto rounded-box bg-base-200 text-base-content shadow"
|
||||
>
|
||||
<div class="grid grid-cols-1 gap-3 p-3" tabindex="-1">
|
||||
{#each availableThemes as theme}
|
||||
<button
|
||||
class="overflow-hidden rounded-lg text-left outline-base-content"
|
||||
data-set-theme={theme}
|
||||
on:click={() => (activeTheme = theme)}
|
||||
on:keydown={() => (activeTheme = theme)}
|
||||
>
|
||||
<div
|
||||
data-theme={theme}
|
||||
class="w-full cursor-pointer bg-base-100 font-sans text-base-content"
|
||||
>
|
||||
<div class="grid grid-cols-5 grid-rows-3">
|
||||
<div class="col-span-5 row-span-3 row-start-1 flex items-center gap-2 px-4 py-3">
|
||||
<Fa icon={faCheck} class={activeTheme === theme ? 'visible' : 'invisible'} />
|
||||
<div class="flex-grow text-sm">{theme}</div>
|
||||
<div class="flex h-full flex-shrink-0 flex-wrap gap-1">
|
||||
<div class="w-2 rounded bg-primary" />
|
||||
<div class="w-2 rounded bg-secondary" />
|
||||
<div class="w-2 rounded bg-accent" />
|
||||
<div class="w-2 rounded bg-neutral" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="truncate">{theme}</div>
|
||||
<Fa icon={faCheck} class={activeTheme === theme ? 'visible' : 'invisible'} />
|
||||
</button>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ms-auto justify-end">
|
||||
{#if $pocketbase.authStore?.record !== null}
|
||||
{#if $pocketbase.authStore.isSuperuser || $permission.create}
|
||||
<a class="btn btn-success me-4" href={resolve('/device/new')}>
|
||||
<a class="btn btn-success me-4" href="/device/new">
|
||||
<Fa icon={faPlus} />
|
||||
{m.navbar_new()}
|
||||
{$LL.navbar.new()}
|
||||
</a>
|
||||
{/if}
|
||||
<div class="dropdown dropdown-end">
|
||||
<label tabindex="-1" class="avatar btn btn-circle btn-ghost" for="avatar">
|
||||
<div class="w-10 rounded-full" id="avatar">
|
||||
<img src={asset(`/avatars/avatar${avatar}.svg`)} alt="Avatar {avatar}" />
|
||||
<img src="/avatars/avatar{avatar}.svg" alt="Avatar {avatar}" />
|
||||
</div>
|
||||
</label>
|
||||
<ul
|
||||
tabindex="-1"
|
||||
class="menu dropdown-content rounded-box bg-base-200 z-1 mt-3 w-52 p-2 shadow"
|
||||
class="menu dropdown-content z-[1] mt-3 rounded-box bg-base-300 p-2 shadow"
|
||||
>
|
||||
<li class="menu-title">
|
||||
{$pocketbase.authStore.isSuperuser
|
||||
@@ -284,11 +275,11 @@
|
||||
: $pocketbase.authStore.record?.username}
|
||||
</li>
|
||||
<li>
|
||||
<a href={resolve('/account')}><Fa icon={faUserGear} />{m.navbar_edit_account()}</a>
|
||||
<a href="/account"><Fa icon={faUserGear} />{$LL.navbar.edit_account()}</a>
|
||||
</li>
|
||||
<li>
|
||||
<div onclick={async () => logout()} onkeydown={async () => logout()} role="none">
|
||||
<Fa icon={faDoorOpen} />{m.navbar_logout()}
|
||||
<div on:click={async () => logout()} on:keydown={async () => logout()} role="none">
|
||||
<Fa icon={faDoorOpen} />{$LL.navbar.logout()}
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { resolve } from '$app/paths';
|
||||
import PageLoading from '$lib/components/PageLoading.svelte';
|
||||
import { m } from '$lib/paraglide/messages';
|
||||
import { localeStore } from '$lib/stores/locale';
|
||||
import LL from '$lib/i18n/i18n-svelte';
|
||||
import { backendUrl, pocketbase } from '$lib/stores/pocketbase';
|
||||
import { settingsPriv } from '$lib/stores/settings';
|
||||
import type { Device } from '$lib/types/device';
|
||||
@@ -24,8 +22,6 @@
|
||||
let replaceNetmaskCheckbox = false;
|
||||
let replaceNetmask = '';
|
||||
|
||||
let loading = true;
|
||||
|
||||
onMount(() => {
|
||||
if (!$settingsPriv) {
|
||||
$pocketbase
|
||||
@@ -42,7 +38,6 @@
|
||||
} else {
|
||||
scanRange = $settingsPriv.scan_range;
|
||||
}
|
||||
loading = false;
|
||||
});
|
||||
|
||||
function saveSettings() {
|
||||
@@ -53,7 +48,7 @@
|
||||
})
|
||||
.then((res) => {
|
||||
settingsPriv.set(res as SettingsPrivate);
|
||||
toast.success(m.device_network_scan_range_saved());
|
||||
toast.success($LL.device.network_scan_range_saved());
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.error(err.message);
|
||||
@@ -95,7 +90,7 @@
|
||||
async function addSingle(device: ScannedDevice) {
|
||||
await createDevice(device)
|
||||
.then(() => {
|
||||
toast.success(m.toasts_device_created({ device: device.name }));
|
||||
toast.success($LL.toasts.device_created({ device: device.name }));
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.error(err.message);
|
||||
@@ -116,73 +111,63 @@
|
||||
});
|
||||
})
|
||||
);
|
||||
toast.success(m.toasts_devices_created_multiple({ count: count }));
|
||||
goto(resolve('/'));
|
||||
toast.success($LL.toasts.devices_created_multiple({ count: count }));
|
||||
goto('/');
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if !loading}
|
||||
<div class="card bg-base-200 mt-6 w-full shadow-sm">
|
||||
{#if $settingsPriv}
|
||||
<div class="card mt-6 w-full bg-base-300 shadow-xl">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title">{m['device_tabs_0']()}</h2>
|
||||
<h2 class="card-title">{$LL.device.tabs[1]()}</h2>
|
||||
<p class="my-2">
|
||||
{m.device_network_scan_desc()}
|
||||
{$LL.device.network_scan_desc()}
|
||||
</p>
|
||||
<div class="flex flex-row flex-wrap items-end gap-4">
|
||||
{#if $settingsPriv}
|
||||
<form
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault();
|
||||
saveSettings();
|
||||
}}
|
||||
>
|
||||
<fieldset class="fieldset p-0">
|
||||
<label class="floating-label mt-2">
|
||||
<span>{m.device_network_scan_ip_range()}</span>
|
||||
<div class="join max-w-xs">
|
||||
<input
|
||||
id="scan-range"
|
||||
class="input join-item w-full"
|
||||
type="text"
|
||||
placeholder="192.168.1.0/24"
|
||||
bind:value={scanRange}
|
||||
/>
|
||||
<button class="btn btn-neutral join-item" type="submit">{m.buttons_save()}</button
|
||||
>
|
||||
</div>
|
||||
</label>
|
||||
</fieldset>
|
||||
</form>
|
||||
{/if}
|
||||
<form on:submit|preventDefault={saveSettings}>
|
||||
<label class="label" for="scan-range">
|
||||
<span class="label-text">{$LL.device.network_scan_ip_range()}</span>
|
||||
</label>
|
||||
<div class="join max-w-xs">
|
||||
<input
|
||||
id="scan-range"
|
||||
class="input join-item input-bordered w-full"
|
||||
type="text"
|
||||
placeholder="192.168.1.0/24"
|
||||
bind:value={scanRange}
|
||||
/>
|
||||
<button class="btn btn-primary join-item" type="submit">{$LL.buttons.save()}</button>
|
||||
</div>
|
||||
</form>
|
||||
<div>
|
||||
<div>
|
||||
{#if $settingsPriv && !$settingsPriv.scan_range}
|
||||
{#if !$settingsPriv.scan_range}
|
||||
<button class="btn btn-error" disabled>
|
||||
<Fa icon={faX} />
|
||||
{m.device_network_scan_no_range()}
|
||||
{$LL.device.network_scan_no_range()}
|
||||
</button>
|
||||
{:else if $settingsPriv && scanRange !== $settingsPriv.scan_range}
|
||||
{:else if scanRange !== $settingsPriv.scan_range}
|
||||
<button class="btn btn-error" disabled>
|
||||
<Fa icon={faX} />
|
||||
{m.device_network_scan_unsaved_changes()}
|
||||
{$LL.device.network_scan_unsaved_changes()}
|
||||
</button>
|
||||
{:else if scanRunning}
|
||||
<button class="btn no-animation">
|
||||
<span class="loading loading-spinner"></span>
|
||||
{m.device_network_scan_running()}
|
||||
<span class="loading loading-spinner" />
|
||||
{$LL.device.network_scan_running()}
|
||||
</button>
|
||||
{:else}
|
||||
<button class="btn btn-success" onclick={() => scan()}>
|
||||
<button class="btn btn-success" on:click={() => scan()}>
|
||||
<Fa icon={faMagnifyingGlass} />
|
||||
{m.device_network_scan()}
|
||||
{$LL.device.network_scan()}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{#if scanResponse.devices?.length > 0}
|
||||
{#each scanResponse.devices.sort( (a, b) => a.ip.localeCompare( b.ip, $localeStore, { numeric: true } ) ) as device, index (device)}
|
||||
<div class="collapse-arrow bg-base-100 collapse">
|
||||
{#each scanResponse.devices.sort( (a, b) => a.ip.localeCompare( b.ip, undefined, { numeric: true } ) ) as device, index}
|
||||
<div class="collapse collapse-arrow bg-base-200">
|
||||
<input type="radio" name="scanned-devices" checked={index === 0} />
|
||||
<div class="collapse-title font-bold">
|
||||
{device.name} <span class="badge">{device.ip}</span>
|
||||
@@ -190,94 +175,96 @@
|
||||
<div class="collapse-content">
|
||||
<div class="flex flex-row flex-wrap gap-4">
|
||||
<div>
|
||||
<strong>{m.device_network_scan_ip()}</strong><br />
|
||||
<strong>{$LL.device.network_scan_ip()}</strong><br />
|
||||
{device.ip}
|
||||
</div>
|
||||
<div>
|
||||
<strong>{m.device_network_scan_mac()}</strong><br />
|
||||
<strong>{$LL.device.network_scan_mac()}</strong><br />
|
||||
{device.mac}
|
||||
</div>
|
||||
<div>
|
||||
<strong>{m.device_network_scan_mac_vendor()}</strong><br />
|
||||
<strong>{$LL.device.network_scan_mac_vendor()}</strong><br />
|
||||
{device.mac_vendor}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<strong>{m.device_network_scan_netmask()}</strong><br />
|
||||
<strong>{$LL.device.network_scan_netmask()}</strong><br />
|
||||
{scanResponse.netmask}
|
||||
</div>
|
||||
<div class="ms-auto">
|
||||
<button
|
||||
class="btn btn-success btn-sm"
|
||||
onclick={(e) => {
|
||||
on:click={(e) => {
|
||||
addSingle(device);
|
||||
e.currentTarget.disabled = true;
|
||||
}}><Fa icon={faPlus} />{m.buttons_add()}</button
|
||||
}}><Fa icon={faPlus} />{$LL.buttons.add()}</button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
<h2 class="card-title mt-4">{m.device_network_scan_add_all()}</h2>
|
||||
<div class="flex max-w-fit flex-col gap-2">
|
||||
<h2 class="card-title mt-4">{$LL.device.network_scan_add_all()}</h2>
|
||||
<div class="form-control max-w-fit">
|
||||
<label class="label cursor-pointer">
|
||||
<input type="checkbox" class="checkbox" bind:checked={replaceNetmaskCheckbox} />
|
||||
<span class="ms-2 text-wrap wrap-break-word"
|
||||
>{m.device_network_scan_replace_netmask()}</span
|
||||
>
|
||||
<span class="label-text ms-2">{$LL.device.network_scan_replace_netmask()}</span>
|
||||
</label>
|
||||
{#if replaceNetmaskCheckbox}
|
||||
</div>
|
||||
{#if replaceNetmaskCheckbox}
|
||||
<div class="form-control max-w-fit">
|
||||
<label class="label cursor-pointer" for="replaceNetmaskInput">
|
||||
<span class="ms-2">{m.device_network_scan_new_netmask()}</span>
|
||||
<span class="label-text ms-2">{$LL.device.network_scan_new_netmask()}</span>
|
||||
</label>
|
||||
<input
|
||||
id="replaceNetmaskInput"
|
||||
class="input"
|
||||
class="input input-bordered"
|
||||
type="text"
|
||||
placeholder="255.255.255.0"
|
||||
bind:value={replaceNetmask}
|
||||
/>
|
||||
{/if}
|
||||
{#if scanResponse.devices.find((dev) => dev.name === 'Unknown')}
|
||||
</div>
|
||||
{/if}
|
||||
{#if scanResponse.devices.find((dev) => dev.name === 'Unknown')}
|
||||
<div class="form-control max-w-fit">
|
||||
<label class="label cursor-pointer">
|
||||
<input type="checkbox" class="checkbox" bind:checked={addAllCheckbox} />
|
||||
<span class="ms-2 text-wrap wrap-break-word"
|
||||
>{m.device_network_scan_include_unknown()}</span
|
||||
>
|
||||
<span class="label-text ms-2">{$LL.device.network_scan_include_unknown()}</span>
|
||||
</label>
|
||||
{#if addAllCheckbox}
|
||||
<button
|
||||
class="btn btn-success"
|
||||
onclick={() => addAll()}
|
||||
on:click={() => addAll()}
|
||||
disabled={scanResponse.devices.length === 0}
|
||||
>
|
||||
<Fa icon={faPlus} />
|
||||
{m.device_network_scan_add_all()} ({scanResponse.devices.length})
|
||||
{$LL.device.network_scan_add_all()} ({scanResponse.devices.length})
|
||||
</button>
|
||||
{:else}
|
||||
<button
|
||||
class="btn btn-success"
|
||||
onclick={() => addAll()}
|
||||
on:click={() => addAll()}
|
||||
disabled={scanResponse.devices.filter((dev) => dev.name !== 'Unknown').length === 0}
|
||||
>
|
||||
<Fa icon={faPlus} />
|
||||
{m.device_network_scan_add_all()} ({scanResponse.devices.filter(
|
||||
{$LL.device.network_scan_add_all()} ({scanResponse.devices.filter(
|
||||
(dev) => dev.name !== 'Unknown'
|
||||
).length})
|
||||
</button>
|
||||
{/if}
|
||||
{:else}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="form-control max-w-fit">
|
||||
<button
|
||||
class="btn btn-success"
|
||||
onclick={() => addAll()}
|
||||
on:click={() => addAll()}
|
||||
disabled={scanResponse.devices.length === 0}
|
||||
>
|
||||
<Fa icon={faPlus} />
|
||||
{m.device_network_scan_add_all()} ({scanResponse.devices.length})
|
||||
{$LL.device.network_scan_add_all()} ({scanResponse.devices.length})
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<div class="container mx-auto max-w-lg text-center">
|
||||
<span class="loading loading-dots loading-lg"></span>
|
||||
<span class="loading loading-dots loading-lg" />
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { fly } from 'svelte/transition';
|
||||
let { url, children } = $props();
|
||||
export let url: URL;
|
||||
</script>
|
||||
|
||||
{#key url}
|
||||
<div in:fly={{ y: 50, duration: 300 }}>
|
||||
{@render children()}
|
||||
<slot />
|
||||
</div>
|
||||
{/key}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
import { m } from '$lib/paraglide/messages';
|
||||
import { dateFnsLocale } from '$lib/stores/locale';
|
||||
import { backendUrl } from '$lib/stores/pocketbase';
|
||||
import { CronExpressionParser } from 'cron-parser';
|
||||
import { formatDate, type Locale } from 'date-fns';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
export function nextCronDate(expression: string) {
|
||||
try {
|
||||
const cron = CronExpressionParser.parse(expression);
|
||||
const cronStr = cron.next().toISOString();
|
||||
if (!cronStr) {
|
||||
throw new Error(m.settings_invalid_cron());
|
||||
}
|
||||
return formatDate(cronStr, 'PPpp', {
|
||||
locale: get(dateFnsLocale) as unknown as Locale
|
||||
});
|
||||
} catch {
|
||||
return m.settings_invalid_cron();
|
||||
}
|
||||
}
|
||||
|
||||
export function parseCron(expression: string): Promise<boolean> {
|
||||
return fetch(backendUrl + 'api/upsnap/validate-cron', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
cron: expression
|
||||
})
|
||||
})
|
||||
.then((response) => {
|
||||
return response.ok;
|
||||
})
|
||||
.catch(() => {
|
||||
return false;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import de from '../de';
|
||||
import type { Translation } from '../i18n-types';
|
||||
|
||||
const de_DE = {
|
||||
...(de as unknown as Translation)
|
||||
} satisfies Translation;
|
||||
|
||||
export default de_DE;
|
||||
@@ -0,0 +1,232 @@
|
||||
import en from '../en';
|
||||
import type { Translation } from '../i18n-types';
|
||||
|
||||
const de = {
|
||||
...(en as unknown as Translation),
|
||||
home: {
|
||||
page_title: 'Home',
|
||||
order_groups: 'Gruppen',
|
||||
order_name: 'Name',
|
||||
order_ip: 'IP',
|
||||
order_tooltip: 'Sortieren',
|
||||
no_devices: 'Keine Geräte.',
|
||||
add_first_device: 'Füge dein erstes Gerät hinzu',
|
||||
grant_permissions:
|
||||
'Bitte frag den Administrator, dir Berechtigungen für bestehende Geräte zu erteilen oder neue Geräte zu erstellen.'
|
||||
},
|
||||
account: {
|
||||
page_title: 'Account',
|
||||
account_type_admin: 'Admin',
|
||||
account_type_user: 'Benutzer',
|
||||
avatar_title: 'Avatar',
|
||||
language_title: 'Sprache',
|
||||
language_option_auto: 'Automatisch',
|
||||
change_password_title: 'Passwort ändern',
|
||||
change_password_body: 'Nachdem das Passwort geändert wurde, musst du dich neu einloggen.',
|
||||
change_password_label: 'Altes Passwort',
|
||||
change_password_new: 'Neues Password',
|
||||
change_password_confirm: 'Password bestätigen'
|
||||
},
|
||||
device: {
|
||||
page_title: 'Neues Gerät',
|
||||
tabs: ['Manuell', 'Netzwerkscan'],
|
||||
card_btn_more: 'Mehr',
|
||||
card_btn_more_edit: 'Bearbeiten',
|
||||
card_btn_more_sleep: 'Ruhezustand',
|
||||
card_btn_more_reboot: 'Neustart',
|
||||
card_tooltip_wake_cron: 'Einschalten Cron',
|
||||
card_tooltip_shutdown_cron: 'Ausschalten Cron',
|
||||
card_tooltip_wake_password: 'Einschalten Passwort',
|
||||
card_tooltip_last_status_change: 'Letzte Statusänderung',
|
||||
card_password: 'Passwort',
|
||||
card_nic_tooltip_pending: 'Warten',
|
||||
card_nic_tooltip_shutdown: 'Ausschalten',
|
||||
card_nic_tooltip_shutdown_no_cmd: 'Kein Ausschaltbefehl gesetzt',
|
||||
card_nic_tooltip_shutdown_no_permission: 'Keine Berechtigung zum ausschalten',
|
||||
card_nic_tooltip_power: 'Einschalten',
|
||||
card_nic_tooltip_power_no_permission: 'Keine Berechtigung zum einschalten',
|
||||
modal_confirm_wake_title: '{device} einschalten?',
|
||||
modal_confirm_wake_desc: 'Bitte bestätigen, um {device} einzuschalten.',
|
||||
modal_confirm_shutdown_title: '{device} herunterfahren?',
|
||||
modal_confirm_shutdown_desc: 'Bitte bestätigen, um {device} herunterzufahren.',
|
||||
general: 'Allgemein',
|
||||
general_name: 'Name',
|
||||
general_name_placeholder: 'Gerätename',
|
||||
general_ip: 'IP',
|
||||
general_mac: 'Mac',
|
||||
general_netmask: 'Netmask',
|
||||
general_description: 'Beschreibung',
|
||||
general_description_placeholder: 'Eine Beschreibung des Geräts',
|
||||
general_required_field: 'Pflichtfeld',
|
||||
ports: 'Ports',
|
||||
ports_desc: 'UpSnap kann auch prüfen, ob bestimmte Ports offen sind.',
|
||||
ports_add_new: 'Port hinzufügen',
|
||||
ports_name: 'Name',
|
||||
ports_number: 'Nummer',
|
||||
link: 'Link',
|
||||
link_desc:
|
||||
'Macht Ihren Gerätenamen zu einem anklickbaren Link, ideal zum Beispiel für die Verknüpfung eines Dashboards.',
|
||||
link_open: 'Automatisch Link öffnen',
|
||||
link_open_no: 'Nein',
|
||||
link_open_same_tab: 'Selber Tab',
|
||||
link_open_new_tab: 'Neuer Tab',
|
||||
ping: 'Ping',
|
||||
ping_desc:
|
||||
'Du kannst einen benutzerdefinierten Shell-Befehl verwenden, um festzustellen, ob das Gerät eingeschaltet ist. Der Befehl sollte einen Exit-Code von <span class="badge">0</span> zurückgeben, um anzuzeigen, dass das Gerät eingeschaltet ist. Jeder andere Exit-Code setzt den Status auf offline.',
|
||||
ping_cmd: 'Eigener Ping-Befehl',
|
||||
wake: 'Einschalten',
|
||||
wake_desc: 'Du kannst das Gerät mit einem Cron-Job einschalten.',
|
||||
wake_cmd: 'Eigener Einschalt-Befehl',
|
||||
wake_cron: 'Cron',
|
||||
wake_cron_enable: 'Aktivieren',
|
||||
sol: 'Sleep-On-LAN',
|
||||
sol_desc1:
|
||||
'Du kannst Computer mithilfe des Tools <a class="link" href="https://github.com/SR-G/sleep-on-lan" target="_blank">Sleep-On-LAN</a> in den Ruhezustand versetzen. Sleep-On-LAN (SOL) ist ein externes Tool/Daemon, das auf den PCs arbeitet, die du in den Ruhezustand versetzen möchtest, und stellt einen REST-Endpunkt bereit. Für Anweisungen zur Einrichtung von Sleep-On-LAN verweise bitte auf den Abschnitt <a href="https://github.com/SR-G/sleep-on-lan#usage" class="link" target="_blank">Usage</a>.',
|
||||
sol_desc2:
|
||||
'SOL ist so konfiguriert, dass es Anfragen über HTTP statt über UDP sendet, um eine Autorisierung zu ermöglichen und die Zuverlässigkeit der Anfragen zu erhöhen.',
|
||||
sol_desc3:
|
||||
'Daher stell bitte sicher, dass du <span class="badge">HTTP:<DEINPORT></span> im Abschnitt <span class="badge">Listener</span> der <a href="https://github.com/SR-G/sleep-on-lan#configuration" class="link" target="_blank">SOL-Konfiguration</a> hinzufügst.',
|
||||
sol_enable: 'Sleep-On-LAN aktivieren',
|
||||
sol_port: 'SOL Port',
|
||||
sol_authorization: 'Authorisierung',
|
||||
sol_user: 'SOL Benutzer',
|
||||
sol_password: 'SOL Passwort',
|
||||
shutdown: 'Ausschalten',
|
||||
shutdown_desc:
|
||||
'Dieser <strong>Shell-Befehl</strong> wird in deinem Container ausgeführt (wenn du Docker verwendest) oder auf deinem Host (wenn du die Binärdatei verwendest). Um zu überprüfen, ob das funktioniert, kannst du den Befehl zuerst im Container oder auf deiner Host-Shell ausführen. Übliche Befehle sind <span class="badge">net rpc</span> für Windows, <span class="badge">sshpass</span> für Linux oder <span class="badge">curl</span> im Allgemeinen, um Webanfragen durchzuführen.',
|
||||
shutdown_examples: 'Beispiele:',
|
||||
shutdown_examples_windows: 'Entfernten Windows PC ausschalten:',
|
||||
shutdown_examples_linux: 'Entfernten Linux PC ausschalten:',
|
||||
shutdown_cmd: 'Befehl zum ausschalten',
|
||||
shutdown_cron_desc:
|
||||
'Genau wie das Einrichten eines Cron-Jobs, um das Gerät aufzuwecken, kannst du auch einen Cron-Job planen, um dieses Gerät herunterzufahren.',
|
||||
shutdown_cron: 'Cron',
|
||||
shutdown_cron_enable: 'Aktivieren',
|
||||
password: 'Password',
|
||||
password_desc:
|
||||
'Einige Netzwerkkarten bieten die Möglichkeit, ein Passwort für Magic Packets zu setzen, auch <span class="badge">SecureON</span> genannt. Das Passwort kann nur 0, 4 oder 6 Zeichen lang sein.',
|
||||
groups: 'Gruppen',
|
||||
groups_desc:
|
||||
'Du kannst Geräte einer Gruppe hinzufügen, um sie auf dem Dashboard nach Gruppen sortiert anzuzeigen.',
|
||||
groups_placeholder: "z.B. 'Keller' or 'Büro'",
|
||||
network_scan_range_saved: 'Scan-Bereich gespeichert',
|
||||
network_scan_desc:
|
||||
'Automatisches Scannen deines Netzwerks nach Geräten. Damit dies funktioniert, musst du UpSnap als Administrator/root ausführen und nmap installiert und im $PATH verfügbar haben (Für Docker-Benutzer ist das bereits der Fall, und du musst nichts weiter tun). Das Scannen kann einige Sekunden dauern.',
|
||||
network_scan_ip_range: 'IP-Bereich',
|
||||
network_scan_no_range: 'Kein Scan-Bereich',
|
||||
network_scan_unsaved_changes: 'Ungespeicherte Änderungen',
|
||||
network_scan_running: 'Scan läuft',
|
||||
network_scan: 'Scan',
|
||||
network_scan_ip: 'IP:',
|
||||
network_scan_mac: 'Mac:',
|
||||
network_scan_mac_vendor: 'Mac Hersteller:',
|
||||
network_scan_netmask: 'Netmask:',
|
||||
network_scan_add_all: 'Alle Geräte hinzufügen',
|
||||
network_scan_replace_netmask: 'Netmask für alle Geräte ändern?',
|
||||
network_scan_new_netmask: 'Neue Netmask',
|
||||
network_scan_include_unknown: 'Schließe Geräte ein, bei denen der Name "Unknown" ist.',
|
||||
require_confirmation: 'Bestätigung erforderlich'
|
||||
},
|
||||
login: {
|
||||
welcome: 'Willkommen',
|
||||
email_label: 'Email oder Nutzername:',
|
||||
password_label: 'Passwort:',
|
||||
btn_more: 'Mehr',
|
||||
menu_title_auth_providers: 'Andere Login Provider',
|
||||
btn_login: 'Login'
|
||||
},
|
||||
settings: {
|
||||
page_title: 'Einstellungen',
|
||||
ping_interval_title: 'Ping Intervall',
|
||||
ping_interval_desc1:
|
||||
'Legt den Intervall fest, in dem Geräte gepingt werden. Leer lassen um den Standardwert von <span class="badge">@every 3s</span> zu verwenden.',
|
||||
ping_interval_desc2:
|
||||
'Lerne mehr über die korrekte Cron Syntax auf <a class="link" href="https://de.wikipedia.org/wiki/Cron" target="_blank">Wikipedia</a> oder sieh dir die <a class="link" href="https://pkg.go.dev/github.com/robfig/cron/v3" target="_blank">Paketdokumentation</a> an.',
|
||||
lazy_ping_title: 'Lazy Ping',
|
||||
lazy_ping_desc:
|
||||
'Wenn Lazy Ping aktiviert ist, pingt UpSnap die Geräte nur an, wenn ein aktiver Benutzer die Website besucht. Wenn es ausgeschaltet ist, pingt UpSnap die Geräte immer an.',
|
||||
lazy_ping_enable: 'Aktivieren',
|
||||
website_title_title: 'Seitentitel',
|
||||
website_title_desc: 'Setzt den Seiten- und den Tabtitel.',
|
||||
icon_title: 'Icon',
|
||||
icon_desc: 'Eigenes Favicon nutzen. Unterstützte Dateitypen sind:',
|
||||
upsnap_version: 'UpSnap Version'
|
||||
},
|
||||
users: {
|
||||
page_title: 'Benutzer',
|
||||
allow_create_devices:
|
||||
'{username} erlauben neue Geräte zu erstellen und Gerätegruppen zu bearbeiten',
|
||||
device_permissions: 'Geräteberechtigungen',
|
||||
create_new_device: 'Neues Gerät erstellen',
|
||||
read: 'Lesen',
|
||||
update: 'Ändern',
|
||||
delete: 'Löschen',
|
||||
power: 'Power',
|
||||
toggle: 'Toggle',
|
||||
confirm_delete_title: 'Löschen bestätigen',
|
||||
confirm_delete_desc: 'Soll {username} wirklich gelöscht werden?',
|
||||
create_new_user: 'Neuen Benutzer erstellen',
|
||||
username: 'Benutzername',
|
||||
password: 'Passwort',
|
||||
password_confirm: 'Passwort bestätigen',
|
||||
required_field: 'Pflichtfeld'
|
||||
},
|
||||
buttons: {
|
||||
save: 'Speichern',
|
||||
delete: 'Löschen',
|
||||
change: 'Ändern',
|
||||
reset: 'Zurücksetzen',
|
||||
cancel: 'Abbrechen',
|
||||
add: 'Hinzufügen',
|
||||
confirm: 'Bestätigen'
|
||||
},
|
||||
welcome: {
|
||||
step1_page_title: 'Willkommen bei UpSnap 🥳',
|
||||
step1_setup_desc:
|
||||
'Bitte schließe die nachfolgenden Schritte ab, um die Einrichtung abzuschließen.',
|
||||
step1_setup_btn_next: 'Weiter',
|
||||
step2_page_title: 'Erstelle einen Admin Account',
|
||||
step2_label_email: 'Email:',
|
||||
step2_label_password: 'Passwort:',
|
||||
step2_label_min_chars: 'min. 10 Zeichen',
|
||||
step2_label_password_confirm: 'Passwort bestätigen:',
|
||||
step2_btn_create: 'Erstellen',
|
||||
step3_page_title: 'Du bist fertig! 🎉',
|
||||
step3_page_desc: 'Füge Geräte zu deinem Dashboard hinzu.',
|
||||
step3_btn_done: 'Lets go!',
|
||||
not_expected_title: 'Ich hab dich hier nicht erwartet! 🧐',
|
||||
not_expected_desc: 'Du hast die Einrichtung bereits abgeschlossen! Hier gibts nichts zu tun.',
|
||||
not_expected_back: 'Bring mich zurück',
|
||||
progress_step1: 'Willkommen',
|
||||
progress_step2: 'Account erstellen',
|
||||
progress_step3: 'Fertig'
|
||||
},
|
||||
toasts: {
|
||||
admin_saved: 'Admin gespeichert',
|
||||
user_saved: 'Benutzer gespeichert',
|
||||
user_created: 'Benutzer {username} erstellt',
|
||||
user_deleted: 'Benutzer {username} gelöscht',
|
||||
settings_saved: 'Einstellungen gespeichert',
|
||||
password_changed: 'Passwort geändert. Bitte neu einloggen.',
|
||||
passwords_missmatch: 'Passwörter stimmen nicht überein',
|
||||
permissions_created: 'Berechtigungen für {username} erstellt',
|
||||
permissions_deleted: 'Berechtigungen für {username} gelöscht',
|
||||
permissions_updated: 'Berechtigungen für {username} geändert',
|
||||
permissions_updated_personal: 'Deine Berechtigungen wurden geupdated',
|
||||
no_permission: 'Du hast keine Berechtigung für {url}',
|
||||
device_created: '{device} erstellt',
|
||||
devices_created_multiple: '{count|int} Geräte erstellt',
|
||||
device_updated: '{device} geändert',
|
||||
device_deleted: '{device} gelöscht',
|
||||
group_created: 'Gruppe {group} erstellt',
|
||||
group_deleted: 'Gruppe {group} gelöscht'
|
||||
},
|
||||
navbar: {
|
||||
theme: 'Theme',
|
||||
new: 'Neu',
|
||||
edit_account: 'Account bearbeiten',
|
||||
logout: 'Abmelden'
|
||||
}
|
||||
} satisfies Translation;
|
||||
|
||||
export default de;
|
||||
@@ -0,0 +1,8 @@
|
||||
import en from '../en';
|
||||
import type { Translation } from '../i18n-types';
|
||||
|
||||
const en_US = {
|
||||
...(en as unknown as Translation)
|
||||
} satisfies Translation;
|
||||
|
||||
export default en_US;
|
||||
@@ -0,0 +1,227 @@
|
||||
import type { BaseTranslation } from '../i18n-types';
|
||||
|
||||
const en = {
|
||||
home: {
|
||||
page_title: 'Home',
|
||||
order_groups: 'Groups',
|
||||
order_name: 'Name',
|
||||
order_ip: 'IP',
|
||||
order_tooltip: 'Order',
|
||||
no_devices: 'No devices here.',
|
||||
add_first_device: 'Add your first device',
|
||||
grant_permissions:
|
||||
'Please ask the admin to grant you permissions to existing devices or to create new ones.'
|
||||
},
|
||||
account: {
|
||||
page_title: 'Account',
|
||||
account_type_admin: 'Admin',
|
||||
account_type_user: 'User',
|
||||
avatar_title: 'Avatar',
|
||||
language_title: 'Language',
|
||||
language_option_auto: 'Automatic',
|
||||
change_password_title: 'Change password',
|
||||
change_password_body: 'After the password has been changed, you will need to log in again.',
|
||||
change_password_label: 'Old password',
|
||||
change_password_new: 'New password',
|
||||
change_password_confirm: 'Confirm password'
|
||||
},
|
||||
device: {
|
||||
page_title: 'New device',
|
||||
tabs: ['Manual', 'Network Scan'],
|
||||
card_btn_more: 'More',
|
||||
card_btn_more_edit: 'Edit',
|
||||
card_btn_more_sleep: 'Sleep',
|
||||
card_btn_more_reboot: 'Reboot',
|
||||
card_tooltip_wake_cron: 'Wake cron',
|
||||
card_tooltip_shutdown_cron: 'Shutdown cron',
|
||||
card_tooltip_wake_password: 'Wake password',
|
||||
card_tooltip_last_status_change: 'Last status change',
|
||||
card_password: 'Password',
|
||||
card_nic_tooltip_pending: 'Pending',
|
||||
card_nic_tooltip_shutdown: 'Shut down',
|
||||
card_nic_tooltip_shutdown_no_cmd: 'No shutdown command set',
|
||||
card_nic_tooltip_shutdown_no_permission: 'No permission to shut down this device',
|
||||
card_nic_tooltip_power: 'Power on',
|
||||
card_nic_tooltip_power_no_permission: 'No permission to power on this device',
|
||||
modal_confirm_wake_title: 'Wake {device}?',
|
||||
modal_confirm_wake_desc: 'Please confirm to wake {device}.',
|
||||
modal_confirm_shutdown_title: 'Shutdown {device}?',
|
||||
modal_confirm_shutdown_desc: 'Please confirm to shutdown {device}.',
|
||||
general: 'General',
|
||||
general_name: 'Name',
|
||||
general_name_placeholder: 'Device name',
|
||||
general_ip: 'IP',
|
||||
general_mac: 'Mac',
|
||||
general_netmask: 'Netmask',
|
||||
general_description: 'Description',
|
||||
general_description_placeholder: 'Some description of the device',
|
||||
general_required_field: 'required field',
|
||||
ports: 'Ports',
|
||||
ports_desc: 'UpSnap can also check if given ports are open.',
|
||||
ports_add_new: 'Add new port',
|
||||
ports_name: 'Name',
|
||||
ports_number: 'Number',
|
||||
link: 'Link',
|
||||
link_desc:
|
||||
'Makes your device name a clickable link, perfect for linking a dashboard for example.',
|
||||
link_open: 'Automatically open link',
|
||||
link_open_no: 'No',
|
||||
link_open_same_tab: 'Same tab',
|
||||
link_open_new_tab: 'New tab',
|
||||
ping: 'Ping',
|
||||
ping_desc:
|
||||
'You can use a custom shell command to see if the device is powered on. The command should return an exit code of <span class="badge">0</span> to indicate that the device is powered on, any other exit code will mark the device as powered off.',
|
||||
ping_cmd: 'Custom ping command',
|
||||
wake: 'Wake',
|
||||
wake_desc: 'You can power this device using a scheduled cron job.',
|
||||
wake_cmd: 'Custom wake command',
|
||||
wake_cron: 'Wake cron',
|
||||
wake_cron_enable: 'Enable wake cron',
|
||||
sol: 'Sleep-On-LAN',
|
||||
sol_desc1:
|
||||
'You can put computers to sleep using the <a class="link" href="https://github.com/SR-G/sleep-on-lan" target="_blank">Sleep-On-LAN</a> tool. Sleep-On-LAN (SOL) is an external tool/daemon that operates on the PCs you want to put to sleep, providing a REST endpoint. For instructions on setting up Sleep-On-LAN, please refer to the <a href="https://github.com/SR-G/sleep-on-lan#usage" class="link" target="_blank">Usage</a> section.',
|
||||
sol_desc2:
|
||||
'SOL is configured to send requests over HTTP instead of UDP to enable authorization and make requests more reliable.',
|
||||
sol_desc3:
|
||||
'Therefore, please ensure that you include <span class="badge">HTTP:<YOURPORT></span> in the <span class="badge">Listeners</span> section of the <a href="https://github.com/SR-G/sleep-on-lan#configuration" class="link" target="_blank">SOL configuration</a>.',
|
||||
sol_enable: 'Enable Sleep-On-LAN',
|
||||
sol_port: 'SOL Port',
|
||||
sol_authorization: 'Authorization',
|
||||
sol_user: 'SOL User',
|
||||
sol_password: 'SOL Password',
|
||||
shutdown: 'Shutdown',
|
||||
shutdown_desc:
|
||||
'This <strong>shell command</strong> will run inside your container (if you use docker) or on your host (if you use the binary). To verify that it works, you can run the command inside the container or on your host shell first. Common commands are <span class="badge">net rpc</span> for windows, <span class="badge">sshpass</span> for linux or <span class="badge">curl</span> in general to make web requests.',
|
||||
shutdown_examples: 'Examples:',
|
||||
shutdown_examples_windows: 'Shutdown remote windows machine:',
|
||||
shutdown_examples_linux: 'Shutdown remote linux machine:',
|
||||
shutdown_cmd: 'Shutdown command',
|
||||
shutdown_cron_desc:
|
||||
'Just like setting a cron to wake the device, you can also schedule a cron job to shut down this device.',
|
||||
shutdown_cron: 'Shutdown cron',
|
||||
shutdown_cron_enable: 'Enable shutdown cron',
|
||||
password: 'Password',
|
||||
password_desc:
|
||||
'Some network cards have the option to set a password for magic packets, also called <span class="badge">SecureON</span>. Password can only be 0, 4 or 6 characters in length.',
|
||||
groups: 'Groups',
|
||||
groups_desc: 'You can add devices to a group to have them sorted by group on the dashboard.',
|
||||
groups_placeholder: "e.g. 'Basement' or 'Office'",
|
||||
network_scan_range_saved: 'Scan range saved',
|
||||
network_scan_desc:
|
||||
"Automatically scan your network for devices. For this to work, you need to run UpSnap as root/admin and have nmap installed and available in your $PATH (For docker users, thats already the case and you don't need to do anything). Scanning might take some seconds.",
|
||||
network_scan_ip_range: 'IP range',
|
||||
network_scan_no_range: 'No scan range',
|
||||
network_scan_unsaved_changes: 'Unsaved changes',
|
||||
network_scan_running: 'Scan running',
|
||||
network_scan: 'Scan',
|
||||
network_scan_ip: 'IP:',
|
||||
network_scan_mac: 'Mac:',
|
||||
network_scan_mac_vendor: 'Mac vendor:',
|
||||
network_scan_netmask: 'Netmask:',
|
||||
network_scan_add_all: 'Add all devices',
|
||||
network_scan_replace_netmask: 'Replace netmask for all devices?',
|
||||
network_scan_new_netmask: 'New netmask',
|
||||
network_scan_include_unknown: 'Include devices where name is "Unknown"',
|
||||
require_confirmation: 'Require Confirmation'
|
||||
},
|
||||
login: {
|
||||
welcome: 'Welcome',
|
||||
email_label: 'Email or Username:',
|
||||
password_label: 'Password:',
|
||||
btn_more: 'More',
|
||||
menu_title_auth_providers: 'Other Auth Providers',
|
||||
btn_login: 'Login'
|
||||
},
|
||||
settings: {
|
||||
page_title: 'Settings',
|
||||
ping_interval_title: 'Ping interval',
|
||||
ping_interval_desc1:
|
||||
'Sets the interval in which the devices are pinged. Leave blank to use default value of <span class="badge">@every 3s</span>.',
|
||||
ping_interval_desc2:
|
||||
'Learn more about the correct syntax for cron on <a class="link" href="https://en.wikipedia.org/wiki/Cron" target="_blank">Wikipedia</a> or refer to the <a class="link" href="https://pkg.go.dev/github.com/robfig/cron/v3" target="_blank">package documentation</a>.',
|
||||
lazy_ping_title: 'Lazy ping',
|
||||
lazy_ping_desc:
|
||||
"When lazy ping is turned on, UpSnap will only ping devices if there is an active user visiting the website. If it's turned off, UpSnap will always ping devices.",
|
||||
lazy_ping_enable: 'Enable',
|
||||
website_title_title: 'Website title',
|
||||
website_title_desc: 'Sets the title of the website and in the browser tab.',
|
||||
icon_title: 'Icon',
|
||||
icon_desc: 'Set a custom favicon. Supported file types are:',
|
||||
upsnap_version: 'UpSnap version'
|
||||
},
|
||||
users: {
|
||||
page_title: 'Users',
|
||||
allow_create_devices: 'Allow {username} to create new devices and edit device groups',
|
||||
device_permissions: 'Device permissions',
|
||||
create_new_device: 'Create new device',
|
||||
read: 'Read',
|
||||
update: 'Update',
|
||||
delete: 'Delete',
|
||||
power: 'Power',
|
||||
toggle: 'Toggle',
|
||||
confirm_delete_title: 'Confirm delete',
|
||||
confirm_delete_desc: 'Are you sure you want to delete {username}?',
|
||||
create_new_user: 'Create new user',
|
||||
username: 'Username',
|
||||
password: 'Password',
|
||||
password_confirm: 'Password confirm',
|
||||
required_field: 'required field'
|
||||
},
|
||||
buttons: {
|
||||
save: 'Save',
|
||||
delete: 'Delete',
|
||||
change: 'Change',
|
||||
reset: 'Reset',
|
||||
cancel: 'Cancel',
|
||||
add: 'Add',
|
||||
confirm: 'Confirm'
|
||||
},
|
||||
welcome: {
|
||||
step1_page_title: 'Welcome to UpSnap 🥳',
|
||||
step1_setup_desc: 'Please complete the following steps to finish the setup.',
|
||||
step1_setup_btn_next: 'Next',
|
||||
step2_page_title: 'Create an admin account',
|
||||
step2_label_email: 'Email:',
|
||||
step2_label_password: 'Password:',
|
||||
step2_label_min_chars: 'min. 10 characters',
|
||||
step2_label_password_confirm: 'Password confirm:',
|
||||
step2_btn_create: 'Create',
|
||||
step3_page_title: 'You are all set! 🎉',
|
||||
step3_page_desc: 'Go ahead and add some devices to your dashboard.',
|
||||
step3_btn_done: 'Lets go!',
|
||||
not_expected_title: "I didn't expect you here! 🧐",
|
||||
not_expected_desc: 'You are already done with the setup! Nothing to do.',
|
||||
not_expected_back: 'Take me back',
|
||||
progress_step1: 'Welcome',
|
||||
progress_step2: 'Create account',
|
||||
progress_step3: 'Done'
|
||||
},
|
||||
toasts: {
|
||||
admin_saved: 'Admin saved',
|
||||
user_saved: 'User saved',
|
||||
user_created: 'User {username} created',
|
||||
user_deleted: 'User {username} deleted',
|
||||
settings_saved: 'Saved settings',
|
||||
password_changed: 'Password changed. Please login again.',
|
||||
passwords_missmatch: "Passwords don't match",
|
||||
permissions_created: 'Permissions for {username} created',
|
||||
permissions_deleted: 'Permissions for {username} deleted',
|
||||
permissions_updated: 'Permissions for {username} updated',
|
||||
permissions_updated_personal: 'Your permissions have been updated',
|
||||
no_permission: "You don't have permission to visit {url}",
|
||||
device_created: 'Created {device}',
|
||||
devices_created_multiple: 'Created {count|int} devices',
|
||||
device_updated: 'Updated {device}',
|
||||
device_deleted: 'Deleted {device}',
|
||||
group_created: 'Created group {group}',
|
||||
group_deleted: 'Deleted group {group}'
|
||||
},
|
||||
navbar: {
|
||||
theme: 'Theme',
|
||||
new: 'New',
|
||||
edit_account: 'Edit account',
|
||||
logout: 'Logout'
|
||||
}
|
||||
} satisfies BaseTranslation;
|
||||
|
||||
export default en;
|
||||
@@ -0,0 +1,8 @@
|
||||
import es from '../es';
|
||||
import type { Translation } from '../i18n-types';
|
||||
|
||||
const es_ES = {
|
||||
...(es as unknown as Translation)
|
||||
} satisfies Translation;
|
||||
|
||||
export default es_ES;
|
||||