mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-11-27 12:21:56 +00:00
Compare commits
78 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b00f3a1c72 | |||
| 4c03494807 | |||
| 4610b54c93 | |||
| 105ae4f6bc | |||
| 85b49defa9 | |||
| 66e08ade4e | |||
| 285f8dcacf | |||
| 9c0f6e114e | |||
| d31a6ef254 | |||
| c2bf398a69 | |||
| 9dac3e982e | |||
| 48a8c736b2 | |||
| 1d361e3f8b | |||
| 611c4d29c5 | |||
| d6604b2df3 | |||
| 52f00c4847 | |||
| 2e69ba9b61 | |||
| 9bed4f4c74 | |||
| c5613a5272 | |||
| 3caa62b609 | |||
| ed83590a62 | |||
| 5c5b908d37 | |||
| 88d333d79e | |||
| 9f00286931 | |||
| b39857b653 | |||
| e09b96813c | |||
| 1273d1b907 | |||
| faeed49bc5 | |||
| 0acba76481 | |||
| 07664829ba | |||
| 78068c1042 | |||
| 3bf1ba517b | |||
| 457a17c259 | |||
| 29c99eda93 | |||
| cddad0f756 | |||
| 84a362a361 | |||
| 190f87d1fa | |||
| f794681ee0 | |||
| ca3fb1c42d | |||
| 7f3020d975 | |||
| 6cf9539871 | |||
| b09510f5e4 | |||
| 07d7becaf8 | |||
| 8301cadba1 | |||
| c57adf8548 | |||
| e6d2992de2 | |||
| 969ded61e6 | |||
| d6300e819d | |||
| ebd3e01af1 | |||
| 13a06a5037 | |||
| 06b46266f2 | |||
| fb0f9f0d0f | |||
| 4f1ec6c90f | |||
| ad36a40f17 | |||
| db528a9b9b | |||
| 7498a699d7 | |||
| 81e252b8a5 | |||
| d99d19b3a0 | |||
| 1e168d473c | |||
| 835f5b9957 | |||
| be94f35455 | |||
| a2d6d7305c | |||
| 2d55e9f168 | |||
| 0232a43e71 | |||
| 6819248815 | |||
| cea0136f83 | |||
| 01dcca3a5d | |||
| 0b7c4a61e7 | |||
| 745094b03a | |||
| 0bead881ef | |||
| 58136f2da3 | |||
| f299c9dd32 | |||
| e4ab3c37ca | |||
| e997211a15 | |||
| 20e25201d0 | |||
| 91eab529ef | |||
| 28ef84db36 | |||
| 288deda98b |
@@ -33,7 +33,7 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- uses: pnpm/action-setup@v4
|
||||
- uses: pnpm/action-setup@v5
|
||||
with:
|
||||
version: latest
|
||||
|
||||
@@ -61,7 +61,7 @@ jobs:
|
||||
tar -czf frontend-dist.tar.gz -C frontend/build .
|
||||
|
||||
- name: Upload frontend artifact
|
||||
uses: actions/upload-artifact@v6
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: frontend-dist
|
||||
path: frontend-dist.tar.gz
|
||||
@@ -77,7 +77,7 @@ jobs:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Download frontend artifact
|
||||
uses: actions/download-artifact@v7
|
||||
uses: actions/download-artifact@v8
|
||||
with:
|
||||
name: frontend-dist
|
||||
|
||||
@@ -105,7 +105,7 @@ jobs:
|
||||
${{ runner.os }}-go-
|
||||
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v6
|
||||
uses: goreleaser/goreleaser-action@v7
|
||||
with:
|
||||
distribution: goreleaser
|
||||
version: "~> v2"
|
||||
@@ -116,7 +116,7 @@ jobs:
|
||||
AUR_KEY: ${{ secrets.AUR_KEY }}
|
||||
|
||||
- name: Upload backend artifact
|
||||
uses: actions/upload-artifact@v6
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: backend-dist
|
||||
path: backend/dist
|
||||
@@ -133,14 +133,14 @@ jobs:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Download backend artifact
|
||||
uses: actions/download-artifact@v7
|
||||
uses: actions/download-artifact@v8
|
||||
with:
|
||||
name: backend-dist
|
||||
path: backend/dist
|
||||
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
uses: docker/metadata-action@v6
|
||||
with:
|
||||
images: |
|
||||
ghcr.io/seriousm4x/UpSnap
|
||||
@@ -152,27 +152,27 @@ jobs:
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
uses: docker/setup-qemu-action@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Log in to GHCR
|
||||
uses: docker/login-action@v3
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
username: ${{ vars.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
|
||||
|
||||
+3
-2
@@ -11,7 +11,7 @@ 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=+ep' ./upsnap
|
||||
setcap 'cap_net_raw=+p' ./upsnap
|
||||
|
||||
FROM alpine:3
|
||||
ARG UPSNAP_HTTP_LISTEN=0.0.0.0:8090
|
||||
@@ -23,4 +23,5 @@ WORKDIR /app
|
||||
COPY --from=downloader /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 ["serve","--http","${UPSNAP_HTTP_LISTEN}"]
|
||||
ENTRYPOINT ["/app/upsnap"]
|
||||
@@ -61,10 +61,10 @@ Just download the latest binary from the [release page](https://github.com/serio
|
||||
sudo ./upsnap serve --http=0.0.0.0:8090
|
||||
```
|
||||
|
||||
### Non-root:
|
||||
### Non-root on linux only:
|
||||
|
||||
```bash
|
||||
sudo setcap cap_net_raw=+ep ./upsnap # only once after downloading
|
||||
sudo setcap cap_net_raw=+p ./upsnap # only once after downloading to allow for pinging devices
|
||||
./upsnap serve --http=0.0.0.0:8090
|
||||
```
|
||||
|
||||
|
||||
+12
-11
@@ -5,10 +5,11 @@ go 1.25.0
|
||||
require (
|
||||
github.com/mdlayher/wol v0.0.0-20220221231636-b763a792253a
|
||||
github.com/pocketbase/dbx v1.12.0
|
||||
github.com/pocketbase/pocketbase v0.36.2
|
||||
github.com/pocketbase/pocketbase v0.36.7
|
||||
github.com/prometheus-community/pro-bing v0.8.0
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
golang.org/x/sys v0.41.0
|
||||
golang.org/x/sys v0.42.0
|
||||
kernel.org/pub/linux/libs/security/libcap/cap v1.2.77
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -37,15 +38,15 @@ require (
|
||||
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.48.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20260212183809-81e46e3db34a // indirect
|
||||
golang.org/x/image v0.36.0 // indirect
|
||||
golang.org/x/net v0.50.0 // indirect
|
||||
golang.org/x/oauth2 v0.35.0 // indirect
|
||||
golang.org/x/sync v0.19.0 // indirect
|
||||
golang.org/x/text v0.34.0 // indirect
|
||||
modernc.org/libc v1.67.6 // indirect
|
||||
golang.org/x/crypto v0.49.0 // indirect
|
||||
golang.org/x/image v0.37.0 // indirect
|
||||
golang.org/x/net v0.52.0 // indirect
|
||||
golang.org/x/oauth2 v0.36.0 // indirect
|
||||
golang.org/x/sync v0.20.0 // indirect
|
||||
golang.org/x/text v0.35.0 // indirect
|
||||
kernel.org/pub/linux/libs/security/libcap/psx v1.2.77 // indirect
|
||||
modernc.org/libc v1.70.0 // indirect
|
||||
modernc.org/mathutil v1.7.1 // indirect
|
||||
modernc.org/memory v1.11.0 // indirect
|
||||
modernc.org/sqlite v1.44.3 // indirect
|
||||
modernc.org/sqlite v1.46.2 // indirect
|
||||
)
|
||||
|
||||
+30
-28
@@ -71,8 +71,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pocketbase/dbx v1.12.0 h1:/oLErM+A0b4xI0PWTGPqSDVjzix48PqI/bng2l0PzoA=
|
||||
github.com/pocketbase/dbx v1.12.0/go.mod h1:xXRCIAKTHMgUCyCKZm55pUOdvFziJjQfXaWKhu2vhMs=
|
||||
github.com/pocketbase/pocketbase v0.36.2 h1:mzrxnvXKc3yxKlvZdbwoYXkH8kfIETteD0hWdgj0VI4=
|
||||
github.com/pocketbase/pocketbase v0.36.2/go.mod h1:71vSF8whUDzC8mcLFE10+Qatf9JQdeOGIRWawOuLLKM=
|
||||
github.com/pocketbase/pocketbase v0.36.7 h1:MrViB7BptPYrf2Nt25pJEYBqUdFjuhRKu1p5GTrkvPA=
|
||||
github.com/pocketbase/pocketbase v0.36.7/go.mod h1:qX4HuVjoKXtEg41fSJVM0JLfGWXbBmHxVv/FaE446r4=
|
||||
github.com/prometheus-community/pro-bing v0.8.0 h1:CEY/g1/AgERRDjxw5P32ikcOgmrSuXs7xon7ovx6mNc=
|
||||
github.com/prometheus-community/pro-bing v0.8.0/go.mod h1:Idyxz8raDO6TgkUN6ByiEGvWJNyQd40kN9ZUeho3lN0=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
@@ -95,36 +95,34 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
|
||||
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=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
|
||||
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
|
||||
golang.org/x/exp v0.0.0-20260212183809-81e46e3db34a h1:ovFr6Z0MNmU7nH8VaX5xqw+05ST2uO1exVfZPVqRC5o=
|
||||
golang.org/x/exp v0.0.0-20260212183809-81e46e3db34a/go.mod h1:K79w1Vqn7PoiZn+TkNpx3BUWUQksGO3JcVX6qIjytmA=
|
||||
golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4=
|
||||
golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA=
|
||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.36.0 h1:Iknbfm1afbgtwPTmHnS2gTM/6PPZfH+z2EFuOkSbqwc=
|
||||
golang.org/x/image v0.36.0/go.mod h1:YsWD2TyyGKiIX1kZlu9QfKIsQ4nAAK9bdgdrIsE7xy4=
|
||||
golang.org/x/image v0.37.0 h1:ZiRjArKI8GwxZOoEtUfhrBtaCN+4b/7709dlT6SSnQA=
|
||||
golang.org/x/image v0.37.0/go.mod h1:/3f6vaXC+6CEanU4KJxbcUZyEePbyKbaLoDOe4ehFYY=
|
||||
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
|
||||
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
|
||||
golang.org/x/net v0.0.0-20190313220215-9f648a60d977/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.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
|
||||
golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
|
||||
golang.org/x/oauth2 v0.35.0 h1:Mv2mzuHuZuY2+bkyWXIHMfhNdJAdwW3FuWeCPYN5GVQ=
|
||||
golang.org/x/oauth2 v0.35.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
|
||||
golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0=
|
||||
golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw=
|
||||
golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
|
||||
golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/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-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.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
|
||||
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
|
||||
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
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.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
|
||||
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
|
||||
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
|
||||
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
|
||||
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
|
||||
@@ -134,20 +132,24 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
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.77 h1:iQtQTjFUOcTT19fI8sTCzYXsjeVs56et3D8AbKS2Uks=
|
||||
kernel.org/pub/linux/libs/security/libcap/cap v1.2.77/go.mod h1:oV+IO8kGh0B7TxErbydDe2+BRmi9g/W0CkpVV+QBTJU=
|
||||
kernel.org/pub/linux/libs/security/libcap/psx v1.2.77 h1:Z06sMOzc0GNCwp6efaVrIrz4ywGJ1v+DP0pjVkOfDuA=
|
||||
kernel.org/pub/linux/libs/security/libcap/psx v1.2.77/go.mod h1:+l6Ee2F59XiJ2I6WR5ObpC1utCQJZ/VLsEbQCD8RG24=
|
||||
modernc.org/cc/v4 v4.27.1 h1:9W30zRlYrefrDV2JE2O8VDtJ1yPGownxciz5rrbQZis=
|
||||
modernc.org/cc/v4 v4.27.1/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
|
||||
modernc.org/ccgo/v4 v4.30.1 h1:4r4U1J6Fhj98NKfSjnPUN7Ze2c6MnAdL0hWw6+LrJpc=
|
||||
modernc.org/ccgo/v4 v4.30.1/go.mod h1:bIOeI1JL54Utlxn+LwrFyjCx2n2RDiYEaJVSrgdrRfM=
|
||||
modernc.org/fileutil v1.3.40 h1:ZGMswMNc9JOCrcrakF1HrvmergNLAmxOPjizirpfqBA=
|
||||
modernc.org/fileutil v1.3.40/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc=
|
||||
modernc.org/ccgo/v4 v4.32.0 h1:hjG66bI/kqIPX1b2yT6fr/jt+QedtP2fqojG2VrFuVw=
|
||||
modernc.org/ccgo/v4 v4.32.0/go.mod h1:6F08EBCx5uQc38kMGl+0Nm0oWczoo1c7cgpzEry7Uc0=
|
||||
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.1 h1:k8T3gkXWY9sEiytKhcgyiZ2L0DTyCQ/nvX+LoCljoRE=
|
||||
modernc.org/gc/v3 v3.1.1/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
|
||||
modernc.org/gc/v3 v3.1.2 h1:ZtDCnhonXSZexk/AYsegNRV1lJGgaNZJuKjJSWKyEqo=
|
||||
modernc.org/gc/v3 v3.1.2/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.67.6 h1:eVOQvpModVLKOdT+LvBPjdQqfrZq+pC39BygcT+E7OI=
|
||||
modernc.org/libc v1.67.6/go.mod h1:JAhxUVlolfYDErnwiqaLvUqc8nfb2r6S6slAgZOnaiE=
|
||||
modernc.org/libc v1.70.0 h1:U58NawXqXbgpZ/dcdS9kMshu08aiA6b7gusEusqzNkw=
|
||||
modernc.org/libc v1.70.0/go.mod h1:OVmxFGP1CI/Z4L3E0Q3Mf1PDE0BucwMkcXjjLntvHJo=
|
||||
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.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
|
||||
@@ -156,8 +158,8 @@ modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
|
||||
modernc.org/opt v0.1.4/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.44.3 h1:+39JvV/HWMcYslAwRxHb8067w+2zowvFOUrOWIy9PjY=
|
||||
modernc.org/sqlite v1.44.3/go.mod h1:CzbrU2lSB1DKUusvwGz7rqEKIq+NUd8GWuBBZDs9/nA=
|
||||
modernc.org/sqlite v1.46.2 h1:gkXQ6R0+AjxFC/fTDaeIVLbNLNrRoOK7YYVz5BKhTcE=
|
||||
modernc.org/sqlite v1.46.2/go.mod h1:hWjRO6Tj/5Ik8ieqxQybiEOUXy0NJFNp2tpvVpKlvig=
|
||||
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=
|
||||
|
||||
@@ -4,14 +4,8 @@ import (
|
||||
"errors"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
probing "github.com/prometheus-community/pro-bing"
|
||||
)
|
||||
|
||||
func isNoRouteOrDownError(err error) bool {
|
||||
@@ -26,53 +20,6 @@ func isNoRouteOrDownError(err error) bool {
|
||||
return syscallErr.Err == syscall.EHOSTUNREACH || syscallErr.Err == syscall.EHOSTDOWN
|
||||
}
|
||||
|
||||
func PingDevice(device *core.Record) (bool, error) {
|
||||
ping_cmd := device.GetString("ping_cmd")
|
||||
if ping_cmd == "" {
|
||||
pinger, err := probing.NewPinger(device.GetString("ip"))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
pinger.Count = 1
|
||||
pinger.Timeout = 500 * time.Millisecond
|
||||
|
||||
privileged := isRoot()
|
||||
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()
|
||||
|
||||
return err == nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func CheckPort(host string, port string) (bool, error) {
|
||||
timeout := 500 * time.Millisecond
|
||||
conn, err := net.DialTimeout("tcp", net.JoinHostPort(host, port), timeout)
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
//go:build linux
|
||||
|
||||
package networking
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.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 == "" {
|
||||
pinger, err := probing.NewPinger(device.GetString("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()
|
||||
|
||||
return err == nil, err
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
//go:build !linux
|
||||
|
||||
package networking
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.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 == "" {
|
||||
pinger, err := probing.NewPinger(device.GetString("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()
|
||||
|
||||
return err == nil, err
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
//go:build !windows
|
||||
|
||||
package networking
|
||||
|
||||
import "os"
|
||||
|
||||
func isRoot() bool {
|
||||
return os.Geteuid() == 0
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
//go:build windows
|
||||
|
||||
package networking
|
||||
|
||||
import "golang.org/x/sys/windows"
|
||||
|
||||
func isRoot() bool {
|
||||
var sid *windows.SID
|
||||
sid, err := windows.CreateWellKnownSid(windows.WinBuiltinAdministratorsSid)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
token := windows.GetCurrentProcessToken()
|
||||
isAdmin, err := token.IsMember(sid)
|
||||
return err == nil && isAdmin
|
||||
}
|
||||
@@ -44,7 +44,7 @@ func ShutdownDevice(device *core.Record) error {
|
||||
cmd.Stderr = &stderr
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
logger.Error.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
done := make(chan error, 1)
|
||||
@@ -61,31 +61,46 @@ func ShutdownDevice(device *core.Record) error {
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-time.After(1 * time.Second):
|
||||
case err := <-done:
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s", stderr.String())
|
||||
} else {
|
||||
for {
|
||||
isOnline, err := PingDevice(device)
|
||||
if err != nil {
|
||||
logger.Error.Println(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)
|
||||
}
|
||||
}
|
||||
default:
|
||||
isOnline, err := PingDevice(device)
|
||||
if err != nil {
|
||||
logger.Error.Println(err)
|
||||
return err
|
||||
}
|
||||
if time.Since(start) >= time.Duration(shutdownTimeout)*time.Second {
|
||||
if err := KillProcess(cmd.Process); err != nil {
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
return fmt.Errorf("%s not offline after %d seconds", device.GetString("name"), shutdownTimeout)
|
||||
}
|
||||
isOnline, err := PingDevice(device)
|
||||
if err != nil {
|
||||
logger.Error.Println(err)
|
||||
return err
|
||||
}
|
||||
if !isOnline {
|
||||
if err := KillProcess(cmd.Process); err != nil {
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
case err := <-done:
|
||||
if err != nil {
|
||||
if err := KillProcess(cmd.Process); err != nil {
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
return fmt.Errorf("%s", stderr.String())
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package networking
|
||||
|
||||
@@ -29,7 +28,5 @@ func KillProcess(process *os.Process) error {
|
||||
return unix.Kill(-pgid, unix.SIGKILL)
|
||||
}
|
||||
|
||||
_, err = process.Wait()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package networking
|
||||
|
||||
|
||||
+1
-96
@@ -2,12 +2,8 @@ package pb
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -151,7 +147,7 @@ func HandlerShutdown(e *core.RequestEvent) error {
|
||||
|
||||
if err := asyncCall(e, func() *router.ApiError {
|
||||
if err := networking.ShutdownDevice(record); err != nil {
|
||||
logger.Error.Println(err)
|
||||
logger.Error.Println(strings.ReplaceAll(err.Error(), "\n", ""))
|
||||
record.Set("status", "online")
|
||||
if err := e.App.Save(record); err != nil {
|
||||
logger.Error.Println("Failed to save record:", err)
|
||||
@@ -216,97 +212,6 @@ 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 {
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
//go:build linux
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pocketbase/pocketbase/apis"
|
||||
"github.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)
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
//go:build !linux
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pocketbase/pocketbase/apis"
|
||||
"github.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)
|
||||
}
|
||||
@@ -69,7 +69,6 @@ func StartPocketBase(distDirFS fs.FS) {
|
||||
// event hooks
|
||||
app.OnServe().BindFunc(func(se *core.ServeEvent) error {
|
||||
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())
|
||||
|
||||
+10
-2
@@ -1,8 +1,12 @@
|
||||
services:
|
||||
upsnap:
|
||||
cap_add:
|
||||
- NET_RAW # NET_RAW is required for privileged ping
|
||||
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
|
||||
network_mode: host # host is required for WOL magic packets
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./data:/app/pb_data
|
||||
@@ -14,8 +18,12 @@ services:
|
||||
# - UPSNAP_INTERVAL=*/10 * * * * * # 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 # Set to false if non-root user and no NET_RAW capability *requires host setting net.ipv4.ping_group_range="0 2147483647"
|
||||
# - 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_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
|
||||
|
||||
+22
-20
@@ -15,29 +15,29 @@
|
||||
"machine-translate": "inlang machine translate --project project.inlang"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^1.4.1",
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@inlang/cli": "^3.1.6",
|
||||
"@inlang/paraglide-js": "2.11.0",
|
||||
"@eslint/compat": "^2.0.3",
|
||||
"@eslint/js": "^10.0.1",
|
||||
"@inlang/cli": "^3.1.9",
|
||||
"@inlang/paraglide-js": "2.15.1",
|
||||
"@sveltejs/adapter-static": "^3.0.10",
|
||||
"@sveltejs/kit": "^2.51.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^5.1.1",
|
||||
"daisyui": "^5.5.18",
|
||||
"eslint": "^9.39.2",
|
||||
"@sveltejs/kit": "^2.55.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
||||
"daisyui": "^5.5.19",
|
||||
"eslint": "^10.1.0",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-plugin-svelte": "^3.15.0",
|
||||
"globals": "^16.5.0",
|
||||
"eslint-plugin-svelte": "^3.15.2",
|
||||
"globals": "^17.4.0",
|
||||
"husky": "^9.1.7",
|
||||
"prettier": "^3.8.1",
|
||||
"prettier-plugin-svelte": "^3.4.1",
|
||||
"prettier-plugin-svelte": "^3.5.1",
|
||||
"prettier-plugin-tailwindcss": "^0.7.2",
|
||||
"svelte": "^5.50.3",
|
||||
"svelte-check": "^4.3.6",
|
||||
"tailwindcss": "^4.1.18",
|
||||
"svelte": "^5.54.0",
|
||||
"svelte-check": "^4.4.5",
|
||||
"tailwindcss": "^4.2.2",
|
||||
"tslib": "^2.8.1",
|
||||
"typescript": "^5.9.3",
|
||||
"typescript-eslint": "^8.55.0",
|
||||
"vite": "^6.4.1"
|
||||
"typescript-eslint": "^8.57.1",
|
||||
"vite": "^7.3.1"
|
||||
},
|
||||
"type": "module",
|
||||
"lint-staged": {
|
||||
@@ -45,12 +45,11 @@
|
||||
"*.{js,css,md,svelte,scss}": "prettier --write --cache --cache-strategy content --ignore-path ../.gitignore ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@fortawesome/free-solid-svg-icons": "^6.7.2",
|
||||
"@tailwindcss/postcss": "^4.1.18",
|
||||
"@fortawesome/free-solid-svg-icons": "^7.2.0",
|
||||
"@tailwindcss/vite": "^4.2.2",
|
||||
"cron-parser": "^5.5.0",
|
||||
"date-fns": "^4.1.0",
|
||||
"pocketbase": "^0.26.8",
|
||||
"postcss": "^8.5.6",
|
||||
"svelte-fa": "^4.0.4",
|
||||
"svelte-french-toast": "github:seriousm4x/svelte-french-toast#fix-72-build",
|
||||
"theme-change": "^2.5.0"
|
||||
@@ -60,6 +59,9 @@
|
||||
"@tailwindcss/oxide",
|
||||
"esbuild",
|
||||
"svelte-french-toast@2.0.0-alpha.0"
|
||||
]
|
||||
],
|
||||
"overrides": {
|
||||
"cookie@<0.7.0": ">=0.7.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+1888
-1183
File diff suppressed because it is too large
Load Diff
@@ -1,5 +0,0 @@
|
||||
export default {
|
||||
plugins: {
|
||||
'@tailwindcss/postcss': {}
|
||||
}
|
||||
};
|
||||
@@ -44,7 +44,7 @@
|
||||
{
|
||||
text: m.device_card_btn_more_edit(),
|
||||
icon: faPen,
|
||||
onClick: () => goto(resolve(`/device/${device.id}`)),
|
||||
onClick: () => goto(resolve(`/device?id=${device.id}`)),
|
||||
requires: $pocketbase.authStore.isSuperuser || $permission.update?.includes(device.id)
|
||||
}
|
||||
]);
|
||||
|
||||
@@ -181,7 +181,7 @@
|
||||
</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.mac)}
|
||||
{#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">
|
||||
<input type="radio" name="scanned-devices" checked={index === 0} />
|
||||
<div class="collapse-title font-bold">
|
||||
@@ -220,16 +220,14 @@
|
||||
</div>
|
||||
{/each}
|
||||
<h2 class="card-title mt-4">{m.device_network_scan_add_all()}</h2>
|
||||
<div class="max-w-fit">
|
||||
<div class="flex max-w-fit flex-col gap-2">
|
||||
<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
|
||||
>
|
||||
</label>
|
||||
</div>
|
||||
{#if replaceNetmaskCheckbox}
|
||||
<div class="max-w-fit">
|
||||
{#if replaceNetmaskCheckbox}
|
||||
<label class="label cursor-pointer" for="replaceNetmaskInput">
|
||||
<span class="ms-2">{m.device_network_scan_new_netmask()}</span>
|
||||
</label>
|
||||
@@ -240,10 +238,8 @@
|
||||
placeholder="255.255.255.0"
|
||||
bind:value={replaceNetmask}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
{#if scanResponse.devices.find((dev) => dev.name === 'Unknown')}
|
||||
<div class="max-w-fit">
|
||||
{/if}
|
||||
{#if scanResponse.devices.find((dev) => dev.name === 'Unknown')}
|
||||
<label class="label cursor-pointer">
|
||||
<input type="checkbox" class="checkbox" bind:checked={addAllCheckbox} />
|
||||
<span class="ms-2 text-wrap wrap-break-word"
|
||||
@@ -271,9 +267,7 @@
|
||||
).length})
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="max-w-fit">
|
||||
{:else}
|
||||
<button
|
||||
class="btn btn-success"
|
||||
onclick={() => addAll()}
|
||||
@@ -282,8 +276,8 @@
|
||||
<Fa icon={faPlus} />
|
||||
{m.device_network_scan_add_all()} ({scanResponse.devices.length})
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
}
|
||||
|
||||
// redirect to welcome page if setup is not completed
|
||||
if ($settingsPub.setup_completed === false && page.url.pathname !== '/welcome') {
|
||||
if ($settingsPub.setup_completed === false && page.url.pathname !== '/welcome/') {
|
||||
$pocketbase.authStore.clear();
|
||||
goto(resolve('/welcome'));
|
||||
return;
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@
|
||||
|
||||
$effect(() => {
|
||||
if (Object.hasOwn($permission, 'update')) {
|
||||
const id = page.params.id;
|
||||
const id = page.url.searchParams.get('id');
|
||||
if (!$pocketbase.authStore.isSuperuser && !$permission.update.includes(id || '')) {
|
||||
toast(m.toasts_no_permission({ url: page.url.pathname }), {
|
||||
icon: '⛔'
|
||||
@@ -22,7 +22,7 @@
|
||||
});
|
||||
|
||||
async function getDevice(): Promise<Device> {
|
||||
const id = page.params.id;
|
||||
const id = page.url.searchParams.get('id');
|
||||
if (!id) throw new Error('No device ID provided');
|
||||
|
||||
const resp = await $pocketbase.collection('devices').getOne(id, { expand: 'ports,groups' });
|
||||
@@ -18,7 +18,7 @@ const config = {
|
||||
'/login',
|
||||
'/account',
|
||||
'/welcome',
|
||||
'/device/[id]',
|
||||
'/device',
|
||||
'/device/new',
|
||||
'/users',
|
||||
'/settings'
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { paraglideVitePlugin } from '@inlang/paraglide-js';
|
||||
import { sveltekit } from '@sveltejs/kit/vite';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
tailwindcss(),
|
||||
paraglideVitePlugin({ project: './project.inlang', outdir: './src/lib/paraglide' }),
|
||||
sveltekit()
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user