Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2bc7bab5f7 | |||
| 4eed2bf31b | |||
| 326a7f359f | |||
| cbbd0f301e | |||
| fdf125d071 | |||
| 72e3d3d343 | |||
| 3331b53d39 | |||
| 1faae16e18 | |||
| 28cc52f6c1 | |||
| 6a388229dd | |||
| 014e6785be | |||
| 2fed755948 | |||
| 9106d25b95 | |||
| 8e9ba1503c | |||
| 9e83416848 | |||
| 054f60ee48 | |||
| 469d480988 | |||
| 87bf05528c | |||
| 93a72207cc | |||
| df9f549d65 | |||
| c43bcbd299 | |||
| 79a70b6053 | |||
| f061c7d00a | |||
| 59bc936237 | |||
| 1b299aa3a3 | |||
| 327b47c2a1 | |||
| d7c4a922e2 |
@@ -0,0 +1,19 @@
|
||||
# Sync repo to the Codeberg mirror
|
||||
name: Mirror Sync
|
||||
on:
|
||||
push:
|
||||
branches: ["master"]
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: "0 */24 * * *"
|
||||
jobs:
|
||||
codeberg:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: pixta-dev/repository-mirroring-action@v1
|
||||
with:
|
||||
target_repo_url: "git@codeberg.org:seriousm4x/UpSnap.git"
|
||||
ssh_private_key: ${{ secrets.CODEBERG_SSH }}
|
||||
@@ -90,7 +90,7 @@ jobs:
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
|
||||
builder: ${{ steps.buildx.outputs.name }}
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
|
||||
@@ -199,3 +199,4 @@ backend/pb_public/*
|
||||
!backend/pb_public/.gitkeep
|
||||
|
||||
dist/
|
||||
vite.config.js.timestamp*
|
||||
|
||||
@@ -12,7 +12,7 @@ RUN wget https://github.com/seriousm4x/UpSnap/releases/download/${VERSION}/UpSna
|
||||
|
||||
FROM alpine:3
|
||||
RUN apk update &&\
|
||||
apk add --no-cache tzdata ca-certificates nmap samba-common-tools openssh sshpass curl &&\
|
||||
apk add --no-cache tzdata ca-certificates nmap samba samba-common-tools openssh sshpass curl &&\
|
||||
rm -rf /var/cache/apk/*
|
||||
WORKDIR /app
|
||||
COPY --from=downloader /app/upsnap upsnap
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<div align="center" width="100%">
|
||||
<img src="frontend/static/favicon.png" width="128" />
|
||||
<img src="frontend/static/gopher.svg" width="150" />
|
||||
</div>
|
||||
|
||||
<div align="center" width="100%">
|
||||
@@ -21,7 +21,7 @@
|
||||
- Discover devices by scanning network
|
||||
- User/Password protected login
|
||||
- Dark/light or system prefered color scheme
|
||||
- [Docker images](https://github.com/seriousm4x/UpSnap/pkgs/container/upsnap) for amd64, arm64, arm/v7
|
||||
- [Docker images](https://github.com/seriousm4x/UpSnap/pkgs/container/upsnap) for amd64, arm64, arm/v7, arm/v6
|
||||
|
||||
## 📸 Screenshots
|
||||
|
||||
@@ -113,8 +113,6 @@ go mod tidy
|
||||
go run main.go serve
|
||||
```
|
||||
|
||||
Log in to [http://localhost:8090/\_/](http://localhost:8090/_/), create an admin user and add some devices.
|
||||
|
||||
2. Start frontend
|
||||
|
||||
```sh
|
||||
@@ -123,4 +121,4 @@ pnpm i
|
||||
pnpm run dev
|
||||
```
|
||||
|
||||
Open up [http://localhost:5173/](http://localhost:5173/)
|
||||
Open up [http://localhost:5173/](http://localhost:5173/), create an admin user and add some devices.
|
||||
|
||||
|
Before Width: | Height: | Size: 161 KiB After Width: | Height: | Size: 326 KiB |
|
Before Width: | Height: | Size: 163 KiB After Width: | Height: | Size: 324 KiB |
|
Before Width: | Height: | Size: 139 KiB After Width: | Height: | Size: 230 KiB |
|
Before Width: | Height: | Size: 138 KiB After Width: | Height: | Size: 223 KiB |
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 150 KiB |
|
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 151 KiB |
|
Before Width: | Height: | Size: 289 KiB After Width: | Height: | Size: 690 KiB |
|
Before Width: | Height: | Size: 292 KiB After Width: | Height: | Size: 696 KiB |
@@ -19,6 +19,7 @@ builds:
|
||||
- arm64
|
||||
- arm
|
||||
goarm:
|
||||
- 6
|
||||
- 7
|
||||
ignore:
|
||||
- goos: windows
|
||||
|
||||
@@ -13,14 +13,14 @@ var CronPing *cron.Cron
|
||||
var CronWakeShutdown *cron.Cron
|
||||
|
||||
func RunPing(app *pocketbase.PocketBase) {
|
||||
settingsRecords, err := app.Dao().FindRecordsByExpr("settings")
|
||||
settingsPrivateRecords, err := app.Dao().FindRecordsByExpr("settings_private")
|
||||
if err != nil {
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
|
||||
// init cronjob
|
||||
CronPing = cron.New()
|
||||
CronPing.AddFunc(settingsRecords[0].GetString("interval"), func() {
|
||||
CronPing.AddFunc(settingsPrivateRecords[0].GetString("interval"), func() {
|
||||
// skip cron if no realtime clients connected
|
||||
realtimeClients := len(app.SubscriptionsBroker().Clients())
|
||||
if realtimeClients == 0 {
|
||||
|
||||
@@ -6,7 +6,7 @@ require (
|
||||
github.com/labstack/echo/v5 v5.0.0-20220201181537-ed2888cfa198
|
||||
github.com/mdlayher/wol v0.0.0-20220221231636-b763a792253a
|
||||
github.com/pocketbase/dbx v1.10.0
|
||||
github.com/pocketbase/pocketbase v0.13.0
|
||||
github.com/pocketbase/pocketbase v0.16.3
|
||||
github.com/prometheus-community/pro-bing v0.1.0
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
)
|
||||
@@ -14,83 +14,84 @@ require (
|
||||
require (
|
||||
github.com/AlecAivazis/survey/v2 v2.3.6 // indirect
|
||||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
|
||||
github.com/aws/aws-sdk-go v1.44.214 // indirect
|
||||
github.com/aws/aws-sdk-go-v2 v1.17.5 // indirect
|
||||
github.com/aws/aws-sdk-go v1.44.273 // indirect
|
||||
github.com/aws/aws-sdk-go-v2 v1.18.0 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/config v1.18.15 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.13.15 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.23 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.55 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.29 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.23 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.30 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.21 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/config v1.18.25 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.13.24 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.67 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.25 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.24 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.23 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.23 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.30.5 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.12.4 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.4 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.18.5 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.28 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.14.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.33.1 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.12.10 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.19.0 // indirect
|
||||
github.com/aws/smithy-go v1.13.5 // indirect
|
||||
github.com/disintegration/imaging v1.6.2 // indirect
|
||||
github.com/domodwyer/mailyak/v3 v3.4.0 // indirect
|
||||
github.com/domodwyer/mailyak/v3 v3.6.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/fatih/color v1.14.1 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.1 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||
github.com/ganigeorgiev/fexpr v0.3.0 // indirect
|
||||
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 // indirect
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/google/wire v0.5.0 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.10.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/jmespath/go-jmespath v0.4.0 // 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.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.16 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.17 // indirect
|
||||
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118 // indirect
|
||||
github.com/mdlayher/packet v1.1.1 // indirect
|
||||
github.com/mdlayher/socket v0.4.0 // indirect
|
||||
github.com/mdlayher/packet v1.1.2 // indirect
|
||||
github.com/mdlayher/socket v0.4.1 // indirect
|
||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/spf13/cast v1.5.0 // indirect
|
||||
github.com/spf13/cobra v1.6.1 // indirect
|
||||
github.com/spf13/cast v1.5.1 // indirect
|
||||
github.com/spf13/cobra v1.7.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
gocloud.dev v0.28.0 // indirect
|
||||
golang.org/x/crypto v0.6.0 // indirect
|
||||
golang.org/x/image v0.5.0 // indirect
|
||||
golang.org/x/mod v0.8.0 // indirect
|
||||
golang.org/x/net v0.7.0 // indirect
|
||||
golang.org/x/oauth2 v0.5.0 // indirect
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
golang.org/x/term v0.5.0 // indirect
|
||||
golang.org/x/text v0.7.0 // indirect
|
||||
gocloud.dev v0.29.0 // indirect
|
||||
golang.org/x/crypto v0.9.0 // indirect
|
||||
golang.org/x/image v0.7.0 // indirect
|
||||
golang.org/x/mod v0.10.0 // indirect
|
||||
golang.org/x/net v0.10.0 // indirect
|
||||
golang.org/x/oauth2 v0.8.0 // indirect
|
||||
golang.org/x/sync v0.2.0 // indirect
|
||||
golang.org/x/sys v0.8.0 // indirect
|
||||
golang.org/x/term v0.8.0 // indirect
|
||||
golang.org/x/text v0.9.0 // indirect
|
||||
golang.org/x/time v0.3.0 // indirect
|
||||
golang.org/x/tools v0.6.0 // indirect
|
||||
golang.org/x/tools v0.9.2 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
|
||||
google.golang.org/api v0.111.0 // indirect
|
||||
google.golang.org/api v0.125.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20230303212802-e74f57abe488 // indirect
|
||||
google.golang.org/grpc v1.53.0 // indirect
|
||||
google.golang.org/protobuf v1.28.1 // indirect
|
||||
lukechampine.com/uint128 v1.2.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
|
||||
google.golang.org/grpc v1.55.0 // indirect
|
||||
google.golang.org/protobuf v1.30.0 // indirect
|
||||
lukechampine.com/uint128 v1.3.0 // indirect
|
||||
modernc.org/cc/v3 v3.40.0 // indirect
|
||||
modernc.org/ccgo/v3 v3.16.13 // indirect
|
||||
modernc.org/libc v1.22.3 // indirect
|
||||
modernc.org/libc v1.22.6 // indirect
|
||||
modernc.org/mathutil v1.5.0 // indirect
|
||||
modernc.org/memory v1.5.0 // indirect
|
||||
modernc.org/opt v0.1.3 // indirect
|
||||
modernc.org/sqlite v1.21.0 // indirect
|
||||
modernc.org/sqlite v1.22.1 // indirect
|
||||
modernc.org/strutil v1.1.3 // indirect
|
||||
modernc.org/token v1.1.0 // indirect
|
||||
)
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/daos"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(db dbx.Builder) error {
|
||||
jsonData := `{
|
||||
"id": "t1rajoyzl6691g3",
|
||||
"created": "2023-03-09 22:17:29.463Z",
|
||||
"updated": "2023-03-09 22:17:29.463Z",
|
||||
"name": "settings_public",
|
||||
"type": "base",
|
||||
"system": false,
|
||||
"schema": [
|
||||
{
|
||||
"system": false,
|
||||
"id": "s1grje98",
|
||||
"name": "website_title",
|
||||
"type": "text",
|
||||
"required": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"min": null,
|
||||
"max": null,
|
||||
"pattern": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"system": false,
|
||||
"id": "tlzz87pj",
|
||||
"name": "favicon",
|
||||
"type": "file",
|
||||
"required": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSelect": 1,
|
||||
"maxSize": 5242880,
|
||||
"mimeTypes": [
|
||||
"image/x-icon",
|
||||
"image/png",
|
||||
"image/svg+xml",
|
||||
"image/gif",
|
||||
"image/jpeg"
|
||||
],
|
||||
"thumbs": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"listRule": "",
|
||||
"viewRule": "",
|
||||
"createRule": null,
|
||||
"updateRule": null,
|
||||
"deleteRule": null,
|
||||
"options": {}
|
||||
}`
|
||||
|
||||
collection := &models.Collection{}
|
||||
if err := json.Unmarshal([]byte(jsonData), &collection); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return daos.New(db).SaveCollection(collection)
|
||||
}, func(db dbx.Builder) error {
|
||||
dao := daos.New(db);
|
||||
|
||||
collection, err := dao.FindCollectionByNameOrId("t1rajoyzl6691g3")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return dao.DeleteCollection(collection)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/daos"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/models/schema"
|
||||
"github.com/pocketbase/pocketbase/tools/types"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(db dbx.Builder) error {
|
||||
dao := daos.New(db);
|
||||
|
||||
collection, err := dao.FindCollectionByNameOrId("nmj3ko20gzkg8n3")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
collection.Name = "settings_private"
|
||||
|
||||
collection.ListRule = nil
|
||||
|
||||
collection.ViewRule = nil
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("slrjkipw")
|
||||
|
||||
return dao.SaveCollection(collection)
|
||||
}, func(db dbx.Builder) error {
|
||||
dao := daos.New(db);
|
||||
|
||||
collection, err := dao.FindCollectionByNameOrId("nmj3ko20gzkg8n3")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
collection.Name = "settings"
|
||||
|
||||
collection.ListRule = types.Pointer("@request.auth.id != \"\"")
|
||||
|
||||
collection.ViewRule = types.Pointer("@request.auth.id != \"\"")
|
||||
|
||||
// add
|
||||
del_website_title := &schema.SchemaField{}
|
||||
json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "slrjkipw",
|
||||
"name": "website_title",
|
||||
"type": "text",
|
||||
"required": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"min": null,
|
||||
"max": null,
|
||||
"pattern": ""
|
||||
}
|
||||
}`), del_website_title)
|
||||
collection.Schema.AddField(del_website_title)
|
||||
|
||||
return dao.SaveCollection(collection)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/daos"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/models/schema"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(db dbx.Builder) error {
|
||||
dao := daos.New(db);
|
||||
|
||||
collection, err := dao.FindCollectionByNameOrId("t1rajoyzl6691g3")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add
|
||||
new_setup_completed := &schema.SchemaField{}
|
||||
json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "vrxqcsnv",
|
||||
"name": "setup_completed",
|
||||
"type": "bool",
|
||||
"required": false,
|
||||
"unique": false,
|
||||
"options": {}
|
||||
}`), new_setup_completed)
|
||||
collection.Schema.AddField(new_setup_completed)
|
||||
|
||||
return dao.SaveCollection(collection)
|
||||
}, func(db dbx.Builder) error {
|
||||
dao := daos.New(db);
|
||||
|
||||
collection, err := dao.FindCollectionByNameOrId("t1rajoyzl6691g3")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("vrxqcsnv")
|
||||
|
||||
return dao.SaveCollection(collection)
|
||||
})
|
||||
}
|
||||
@@ -70,12 +70,12 @@ func HandlerScan(c echo.Context) error {
|
||||
}
|
||||
|
||||
// check if scan range is valid
|
||||
allSettings, err := App.Dao().FindRecordsByExpr("settings")
|
||||
allPrivateSettings, err := App.Dao().FindRecordsByExpr("settings_private")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
settings := allSettings[0]
|
||||
scanRange := settings.GetString("scan_range")
|
||||
settingsPrivate := allPrivateSettings[0]
|
||||
scanRange := settingsPrivate.GetString("scan_range")
|
||||
_, ipNet, err := net.ParseCIDR(scanRange)
|
||||
if err != nil {
|
||||
return apis.NewBadRequestError(err.Error(), nil)
|
||||
|
||||
@@ -85,13 +85,16 @@ func StartPocketBase(distDirFS fs.FS) {
|
||||
// add event hook before starting server.
|
||||
// using this outside App.OnBeforeServe() would not work
|
||||
App.OnModelAfterUpdate().Add(func(e *core.ModelEvent) error {
|
||||
if e.Model.TableName() == "settings" {
|
||||
if e.Model.TableName() == "settings_private" {
|
||||
for _, job := range cronjobs.CronPing.Entries() {
|
||||
cronjobs.CronPing.Remove(job.ID)
|
||||
}
|
||||
go cronjobs.RunPing(App)
|
||||
} else if e.Model.TableName() == "devices" {
|
||||
refreshDeviceList()
|
||||
if err := refreshDeviceList(); err != nil {
|
||||
logger.Error.Println(err)
|
||||
return err
|
||||
}
|
||||
for _, job := range cronjobs.CronWakeShutdown.Entries() {
|
||||
cronjobs.CronWakeShutdown.Remove(job.ID)
|
||||
}
|
||||
@@ -104,11 +107,31 @@ func StartPocketBase(distDirFS fs.FS) {
|
||||
|
||||
// refresh the device list on database events
|
||||
App.OnModelAfterCreate().Add(func(e *core.ModelEvent) error {
|
||||
refreshDeviceList()
|
||||
if e.Model.TableName() == "_admins" {
|
||||
if err := setSetupCompleted(); err != nil {
|
||||
logger.Error.Println(err)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := refreshDeviceList(); err != nil {
|
||||
logger.Error.Println(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
App.OnModelAfterDelete().Add(func(e *core.ModelEvent) error {
|
||||
refreshDeviceList()
|
||||
if e.Model.TableName() == "_admins" {
|
||||
if err := setSetupCompleted(); err != nil {
|
||||
logger.Error.Println(err)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := refreshDeviceList(); err != nil {
|
||||
logger.Error.Println(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -119,18 +142,32 @@ func StartPocketBase(distDirFS fs.FS) {
|
||||
}
|
||||
|
||||
func importSettings() error {
|
||||
// get first settings record
|
||||
settingsRecords, err := App.Dao().FindRecordsByExpr("settings")
|
||||
// get first settingsPrivate record
|
||||
settingsPrivateRecords, err := App.Dao().FindRecordsByExpr("settings_private")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
settingsCollection, err := App.Dao().FindCollectionByNameOrId("settings")
|
||||
settingsPrivateCollection, err := App.Dao().FindCollectionByNameOrId("settings_private")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
settings := models.NewRecord(settingsCollection)
|
||||
if len(settingsRecords) > 0 {
|
||||
settings = settingsRecords[0]
|
||||
settingsPrivate := models.NewRecord(settingsPrivateCollection)
|
||||
if len(settingsPrivateRecords) > 0 {
|
||||
settingsPrivate = settingsPrivateRecords[0]
|
||||
}
|
||||
|
||||
// get first settingsPublic record
|
||||
settingsPublicRecords, err := App.Dao().FindRecordsByExpr("settings_public")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
settingsPublicCollection, err := App.Dao().FindCollectionByNameOrId("settings_public")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
settingsPublic := models.NewRecord(settingsPublicCollection)
|
||||
if len(settingsPublicRecords) > 0 {
|
||||
settingsPublic = settingsPublicRecords[0]
|
||||
}
|
||||
|
||||
// set ping interval settings. priority:
|
||||
@@ -138,22 +175,33 @@ func importSettings() error {
|
||||
// 2nd: database entry
|
||||
// 3rd: default values
|
||||
interval := "@every 3s"
|
||||
if settings.GetString("interval") != "" {
|
||||
interval = settings.GetString("interval")
|
||||
if settingsPrivate.GetString("interval") != "" {
|
||||
interval = settingsPrivate.GetString("interval")
|
||||
}
|
||||
if os.Getenv("UPSNAP_INTERVAL") != "" {
|
||||
interval = os.Getenv("UPSNAP_INTERVAL")
|
||||
}
|
||||
|
||||
// save settings to db
|
||||
settings.Set("interval", interval)
|
||||
// set private settings
|
||||
settingsPrivate.Set("interval", interval)
|
||||
if scanRange := os.Getenv("UPSNAP_SCAN_RANGE"); scanRange != "" {
|
||||
settings.Set("scan_range", scanRange)
|
||||
settingsPrivate.Set("scan_range", scanRange)
|
||||
}
|
||||
if scanRange := os.Getenv("UPSNAP_WEBSITE_TITLE"); scanRange != "" {
|
||||
settings.Set("website_title", scanRange)
|
||||
|
||||
// set public settings
|
||||
if websiteTitle := os.Getenv("UPSNAP_WEBSITE_TITLE"); websiteTitle != "" {
|
||||
settingsPublic.Set("website_title", websiteTitle)
|
||||
}
|
||||
if err := App.Dao().SaveRecord(settings); err != nil {
|
||||
|
||||
// save records
|
||||
if err := App.Dao().SaveRecord(settingsPrivate); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := App.Dao().SaveRecord(settingsPublic); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := setSetupCompleted(); err != nil {
|
||||
logger.Error.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -176,10 +224,30 @@ func resetDeviceStates() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func refreshDeviceList() {
|
||||
func refreshDeviceList() error {
|
||||
var err error
|
||||
cronjobs.Devices, err = App.Dao().FindRecordsByExpr("devices")
|
||||
if err != nil {
|
||||
logger.Error.Println(err)
|
||||
if cronjobs.Devices, err = App.Dao().FindRecordsByExpr("devices"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setSetupCompleted() error {
|
||||
totalAdmins, err := App.Dao().TotalAdmins()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
settingsPublicRecords, err := App.Dao().FindRecordsByExpr("settings_public")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if totalAdmins > 0 {
|
||||
settingsPublicRecords[0].Set("setup_completed", true)
|
||||
} else {
|
||||
settingsPublicRecords[0].Set("setup_completed", false)
|
||||
}
|
||||
if err := App.Dao().SaveRecord(settingsPublicRecords[0]); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -12,30 +12,30 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-static": "^1.0.6",
|
||||
"@sveltejs/kit": "^1.10.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
||||
"@typescript-eslint/parser": "^5.54.0",
|
||||
"eslint": "^8.35.0",
|
||||
"eslint-config-prettier": "^8.6.0",
|
||||
"@sveltejs/kit": "^1.20.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.8",
|
||||
"@typescript-eslint/parser": "^5.59.8",
|
||||
"eslint": "^8.41.0",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-svelte3": "^4.0.0",
|
||||
"husky": "^8.0.3",
|
||||
"lint-staged": "^13.1.2",
|
||||
"prettier": "^2.8.4",
|
||||
"prettier-plugin-svelte": "^2.9.0",
|
||||
"svelte": "^3.55.1",
|
||||
"svelte-preprocess": "^5.0.1",
|
||||
"lint-staged": "^13.2.2",
|
||||
"prettier": "^2.8.8",
|
||||
"prettier-plugin-svelte": "^2.10.1",
|
||||
"svelte": "^3.59.1",
|
||||
"svelte-preprocess": "^5.0.4",
|
||||
"typescript": "^4.9.5",
|
||||
"vite": "^4.1.4"
|
||||
"vite": "^4.3.9"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@fortawesome/free-solid-svg-icons": "^6.3.0",
|
||||
"@popperjs/core": "^2.11.6",
|
||||
"bootstrap": "5.3.0-alpha1",
|
||||
"date-fns": "^2.29.3",
|
||||
"@fortawesome/free-solid-svg-icons": "^6.4.0",
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"bootstrap": "5.3.0",
|
||||
"date-fns": "^2.30.0",
|
||||
"pocketbase": "^0.10.2",
|
||||
"sass": "^1.58.3",
|
||||
"svelte-fa": "^3.0.3"
|
||||
"sass": "^1.62.1",
|
||||
"svelte-fa": "^3.0.4"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{js,svelte}": "eslint --fix --ignore-path ../.gitignore .",
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
<html lang="en" class="h-100">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
|
||||
<body data-sveltekit-preload-data="hover" class="h-100">
|
||||
<div style="display: contents">%sveltekit.body%</div>
|
||||
</body>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { dev } from '$app/environment';
|
||||
import { parseISO, formatDistance } from 'date-fns';
|
||||
import { pocketbase } from '@stores/pocketbase';
|
||||
import Fa from 'svelte-fa/src/fa.svelte';
|
||||
import {
|
||||
faPowerOff,
|
||||
faEllipsisVertical,
|
||||
@@ -10,7 +11,6 @@
|
||||
faCircleDown,
|
||||
faLock
|
||||
} from '@fortawesome/free-solid-svg-icons';
|
||||
import Fa from 'svelte-fa';
|
||||
import { sortPorts } from '../sorts';
|
||||
|
||||
export let device;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<script>
|
||||
import { goto } from '$app/navigation';
|
||||
import { pocketbase, devices } from '@stores/pocketbase';
|
||||
import Fa from 'svelte-fa/src/fa.svelte';
|
||||
import { faEye, faEyeSlash, faPlus, faTrashCan } from '@fortawesome/free-solid-svg-icons';
|
||||
import Fa from 'svelte-fa';
|
||||
|
||||
export let device;
|
||||
export let mode;
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
<script>
|
||||
import { pocketbase, authorizedStore } from '@stores/pocketbase';
|
||||
import { dev } from '$app/environment';
|
||||
import { pocketbase, authorizedStore, settings_public } from '@stores/pocketbase';
|
||||
|
||||
let username;
|
||||
let password;
|
||||
let passwordConfirm;
|
||||
let isAdmin;
|
||||
let error = {
|
||||
let callout = {
|
||||
hidden: true,
|
||||
level: 'danger',
|
||||
title: '',
|
||||
msg: ''
|
||||
};
|
||||
|
||||
$: if ($settings_public.setup_completed === false) {
|
||||
callout.title = '';
|
||||
callout.msg = 'No admin account has been set up. Please create one.';
|
||||
callout.level = 'info';
|
||||
callout.hidden = false;
|
||||
}
|
||||
|
||||
async function login() {
|
||||
if (isAdmin) {
|
||||
$pocketbase.admins
|
||||
@@ -19,9 +29,10 @@
|
||||
})
|
||||
.catch((err) => {
|
||||
authorizedStore.set(false);
|
||||
error.title = err.status;
|
||||
error.msg = err.message;
|
||||
error.hidden = false;
|
||||
callout.level = 'danger';
|
||||
callout.title = err.status;
|
||||
callout.msg = err.message;
|
||||
callout.hidden = false;
|
||||
});
|
||||
} else {
|
||||
$pocketbase
|
||||
@@ -32,75 +43,170 @@
|
||||
})
|
||||
.catch((err) => {
|
||||
authorizedStore.set(false);
|
||||
error.title = err.status;
|
||||
error.msg = err.message;
|
||||
error.hidden = false;
|
||||
callout.level = 'danger';
|
||||
callout.title = err.status;
|
||||
callout.msg = err.message;
|
||||
callout.hidden = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function register() {
|
||||
if (password !== passwordConfirm) {
|
||||
callout.level = 'danger';
|
||||
callout.title = "Passwords don't match";
|
||||
callout.msg = 'Please try again';
|
||||
callout.hidden = false;
|
||||
return;
|
||||
} else {
|
||||
callout.hidden = true;
|
||||
}
|
||||
$pocketbase.admins
|
||||
.create({
|
||||
email: username,
|
||||
password: password,
|
||||
passwordConfirm: passwordConfirm
|
||||
})
|
||||
.then(() => {
|
||||
$pocketbase.admins
|
||||
.authWithPassword(username, password)
|
||||
.then(() => {
|
||||
authorizedStore.set(true);
|
||||
})
|
||||
.catch((err) => {
|
||||
return err;
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
authorizedStore.set(false);
|
||||
callout.level = 'danger';
|
||||
callout.title = err.status;
|
||||
callout.msg = err.message;
|
||||
callout.hidden = false;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="container text-dark-emphasis">
|
||||
<div class="row justify-content-center align-items-center">
|
||||
<div class="col text-center p-3 p-md-5">
|
||||
<img src="/favicon.png" alt="Logo" class="logo pe-none user-select-none" />
|
||||
<h2 class="text-dark-emphasis fw-bold text-center mt-3">Login</h2>
|
||||
<img
|
||||
src={$settings_public.favicon !== ''
|
||||
? `${dev ? $pocketbase.baseUrl : ''}/api/files/settings_public/${
|
||||
$settings_public.id
|
||||
}/${$settings_public.favicon}`
|
||||
: '/gopher.svg'}
|
||||
alt={$settings_public.website_title ? $settings_public.website_title : 'UpSnap'}
|
||||
class="logo pe-none user-select-none"
|
||||
/>
|
||||
<h2 class="text-dark-emphasis fw-bold text-center mt-3">
|
||||
{$settings_public.setup_completed === true ? 'Login' : 'Register'}
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row justify-content-center align-items-center p-2">
|
||||
<div class="col-md-6 col-lg-5 p-4 login rounded-5 shadow-sm">
|
||||
<form class="w-100" on:submit|preventDefault={login}>
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Username or email address</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="username"
|
||||
placeholder="user@example.com"
|
||||
bind:value={username}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input
|
||||
type="password"
|
||||
class="form-control"
|
||||
id="password"
|
||||
placeholder="secret-password"
|
||||
bind:value={password}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div class="form-check form-switch mb-3">
|
||||
<input
|
||||
class="form-check-input"
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
id="flexSwitchCheckChecked"
|
||||
bind:checked={isAdmin}
|
||||
/>
|
||||
<label class="form-check-label" for="flexSwitchCheckChecked">Admin login</label>
|
||||
</div>
|
||||
<div class="callout callout-danger" class:d-none={error.hidden}>
|
||||
<h5>Error {error.title}</h5>
|
||||
<p class="m-0">{error.msg}</p>
|
||||
</div>
|
||||
<button class="btn btn-secondary w-100" type="submit">Login</button>
|
||||
</form>
|
||||
<p class="text-center m-0 mt-3">
|
||||
<!-- hacky way of linking a non existing route in svelte -->
|
||||
<a href="/_/" rel="external" class="text-muted cursor-pointer">Manage users</a>
|
||||
</p>
|
||||
<div class="callout callout-{callout.level} mt-0" class:d-none={callout.hidden}>
|
||||
{#if callout.title !== ''}
|
||||
<h5>{callout.title}</h5>
|
||||
{/if}
|
||||
{#if callout.msg !== ''}
|
||||
<p class="m-0">{callout.msg}</p>
|
||||
{/if}
|
||||
</div>
|
||||
{#if $settings_public.setup_completed === true}
|
||||
<form class="w-100" on:submit|preventDefault={login}>
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Username or email</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="username"
|
||||
placeholder="user@example.com"
|
||||
bind:value={username}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input
|
||||
type="password"
|
||||
class="form-control"
|
||||
id="password"
|
||||
placeholder="secret-password"
|
||||
bind:value={password}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div class="form-check form-switch mb-3">
|
||||
<input
|
||||
class="form-check-input"
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
id="flexSwitchCheckChecked"
|
||||
bind:checked={isAdmin}
|
||||
/>
|
||||
<label class="form-check-label" for="flexSwitchCheckChecked"
|
||||
>Admin login</label
|
||||
>
|
||||
</div>
|
||||
<button class="btn btn-secondary w-100" type="submit">Login</button>
|
||||
</form>
|
||||
<p class="text-center m-0 mt-3">
|
||||
<!-- hacky way of linking a non existing route in svelte -->
|
||||
<a href="/_/" rel="external" class="text-muted cursor-pointer">Manage users</a>
|
||||
</p>
|
||||
{:else}
|
||||
<form class="w-100" on:submit|preventDefault={register}>
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Email</label>
|
||||
<input
|
||||
type="email"
|
||||
class="form-control"
|
||||
id="username"
|
||||
placeholder="user@example.com"
|
||||
bind:value={username}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label"
|
||||
>Password (min. 10 characters)</label
|
||||
>
|
||||
<input
|
||||
type="password"
|
||||
class="form-control"
|
||||
id="password"
|
||||
placeholder="secret-password"
|
||||
minlength="10"
|
||||
bind:value={password}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="passwordConfirm" class="form-label">Password confirm</label>
|
||||
<input
|
||||
type="password"
|
||||
class="form-control"
|
||||
id="passwordConfirm"
|
||||
placeholder="secret-password"
|
||||
minlength="10"
|
||||
bind:value={passwordConfirm}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<button class="btn btn-secondary w-100" type="submit">Create and login</button>
|
||||
</form>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.logo {
|
||||
width: 100%;
|
||||
width: 40%;
|
||||
min-width: 50px;
|
||||
max-width: 100px;
|
||||
max-width: 200px;
|
||||
}
|
||||
|
||||
.cursor-pointer {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<script>
|
||||
import { dev } from '$app/environment';
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { theme } from '@stores/theme';
|
||||
import { pocketbase, authorizedStore, settings } from '@stores/pocketbase';
|
||||
import { pocketbase, authorizedStore, settings_public } from '@stores/pocketbase';
|
||||
import Fa from 'svelte-fa/src/fa.svelte';
|
||||
import {
|
||||
faSun,
|
||||
faMoon,
|
||||
@@ -10,7 +12,6 @@
|
||||
faBrush,
|
||||
faRightFromBracket
|
||||
} from '@fortawesome/free-solid-svg-icons';
|
||||
import Fa from 'svelte-fa';
|
||||
|
||||
let userInfo = {
|
||||
usernameOrEmail: '',
|
||||
@@ -18,11 +19,6 @@
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
$pocketbase.collection('settings').subscribe('*', function (e) {
|
||||
settings.set(e.record);
|
||||
document.title = $settings.website_title;
|
||||
});
|
||||
|
||||
if ($pocketbase.authStore.baseModel?.collectionName === 'users') {
|
||||
userInfo.role = 'user';
|
||||
} else {
|
||||
@@ -41,24 +37,20 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
{#if $settings.website_title !== ''}
|
||||
<title>{$settings.website_title}</title>
|
||||
{:else}
|
||||
<title>UpSnap</title>
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
<nav class="navbar navbar-expand-sm">
|
||||
<nav class="navbar navbar-expand-sm pt-0">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/">
|
||||
<img
|
||||
src="/favicon.png"
|
||||
alt="UpSnap"
|
||||
width="30"
|
||||
height="30"
|
||||
class:me-2={$settings.website_title !== ''}
|
||||
/>{$settings.website_title ? $settings.website_title : ''}
|
||||
src={$settings_public.favicon !== ''
|
||||
? `${dev ? $pocketbase.baseUrl : ''}/api/files/settings_public/${
|
||||
$settings_public.id
|
||||
}/${$settings_public.favicon}`
|
||||
: '/gopher.svg'}
|
||||
alt={$settings_public.website_title ? $settings_public.website_title : 'UpSnap'}
|
||||
width="45"
|
||||
height="45"
|
||||
class:me-2={$settings_public.website_title !== ''}
|
||||
/>{$settings_public.website_title ? $settings_public.website_title : ''}
|
||||
</a>
|
||||
<button
|
||||
class="navbar-toggler border-0"
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
<script>
|
||||
import { dev } from '$app/environment';
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import Navbar from '@components/Navbar.svelte';
|
||||
import Login from '@components/Login.svelte';
|
||||
import Transition from '@components/Transition.svelte';
|
||||
import { theme } from '@stores/theme';
|
||||
import { pocketbase, authorizedStore, devices, settings } from '@stores/pocketbase';
|
||||
import {
|
||||
pocketbase,
|
||||
authorizedStore,
|
||||
devices,
|
||||
settings_private,
|
||||
settings_public
|
||||
} from '@stores/pocketbase';
|
||||
|
||||
let favicon;
|
||||
let preferesDark;
|
||||
let isAuth = false;
|
||||
|
||||
@@ -38,6 +46,15 @@
|
||||
isAuth = state;
|
||||
});
|
||||
|
||||
// load public settings and subscribe to changes and change favicon
|
||||
const settingsPublicRes = await $pocketbase.collection('settings_public').getList(1, 1);
|
||||
settings_public.set(settingsPublicRes.items[0]);
|
||||
updateSettingsPublic();
|
||||
$pocketbase.collection('settings_public').subscribe('*', function (e) {
|
||||
settings_public.set(e.record);
|
||||
updateSettingsPublic();
|
||||
});
|
||||
|
||||
// load auth from localstorage
|
||||
const pbCookie = localStorage.getItem('pocketbase_auth');
|
||||
if (pbCookie) {
|
||||
@@ -55,10 +72,24 @@
|
||||
}
|
||||
});
|
||||
|
||||
async function getSettingsAndDevices() {
|
||||
let settingsRes = {};
|
||||
settingsRes = await $pocketbase.collection('settings').getList(1, 1);
|
||||
settings.set(settingsRes.items[0]);
|
||||
function updateSettingsPublic() {
|
||||
favicon.href =
|
||||
$settings_public.favicon === ''
|
||||
? '/gopher.svg'
|
||||
: `${dev ? $pocketbase.baseUrl : ''}/api/files/settings_public/${
|
||||
$settings_public.id
|
||||
}/${$settings_public.favicon}`;
|
||||
document.title =
|
||||
$settings_public.website_title === '' ? 'UpSnap' : $settings_public.website_title;
|
||||
}
|
||||
|
||||
async function getSettingsPrivateAndDevices() {
|
||||
if ($pocketbase.authStore.model?.collectionName !== 'users') {
|
||||
const settingsPrivateRes = await $pocketbase
|
||||
.collection('settings_private')
|
||||
.getList(1, 1);
|
||||
settings_private.set(settingsPrivateRes.items[0]);
|
||||
}
|
||||
|
||||
let tempDevices = {};
|
||||
const devicesRes = await $pocketbase.collection('devices').getFullList(200, {
|
||||
@@ -72,11 +103,12 @@
|
||||
}
|
||||
|
||||
$: if (isAuth) {
|
||||
getSettingsAndDevices();
|
||||
getSettingsPrivateAndDevices();
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<link rel="shortcut icon" href="/gopher.svg" bind:this={favicon} />
|
||||
<script>
|
||||
if (document) {
|
||||
preferesDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
<script>
|
||||
import { dev } from '$app/environment';
|
||||
import { pocketbase, settings, devices } from '@stores/pocketbase';
|
||||
import { pocketbase, settings_private, settings_public, devices } from '@stores/pocketbase';
|
||||
import UnauthorizedMsg from '@components/UnauthorizedMsg.svelte';
|
||||
import DeviceForm from '@components/DeviceForm.svelte';
|
||||
import Fa from 'svelte-fa/src/fa.svelte';
|
||||
import { faPlus } from '@fortawesome/free-solid-svg-icons';
|
||||
import Fa from 'svelte-fa';
|
||||
|
||||
let version = import.meta.env.UPSNAP_VERSION;
|
||||
|
||||
let files;
|
||||
let iconFiles = [];
|
||||
let iconPreview;
|
||||
let timeout;
|
||||
let buttons = {
|
||||
settings: {
|
||||
state: 'none',
|
||||
error: ''
|
||||
},
|
||||
restore: {
|
||||
state: 'none',
|
||||
error: ''
|
||||
},
|
||||
scan: {
|
||||
state: 'none',
|
||||
error: ''
|
||||
@@ -43,13 +40,40 @@
|
||||
};
|
||||
let scannedDevices = {};
|
||||
|
||||
$: if (iconPreview && iconFiles.length > 0) {
|
||||
iconPreview.src = URL.createObjectURL(iconFiles[0]);
|
||||
} else if (iconPreview && $settings_public.favicon !== '') {
|
||||
iconPreview.src = `${dev ? $pocketbase.baseUrl : ''}/api/files/settings_public/${
|
||||
$settings_public.id
|
||||
}/${$settings_public.favicon}`;
|
||||
} else if (iconPreview) {
|
||||
iconPreview.src = '/gopher.svg';
|
||||
}
|
||||
|
||||
async function saveSettings() {
|
||||
buttons.settings.state = 'waiting';
|
||||
try {
|
||||
if ($settings.interval === '') {
|
||||
$settings.interval = '@every 3s';
|
||||
// update settings private
|
||||
if ($settings_private.interval === '') {
|
||||
$settings_private.interval = '@every 3s';
|
||||
}
|
||||
await $pocketbase.collection('settings').update($settings.id, $settings);
|
||||
await $pocketbase
|
||||
.collection('settings_private')
|
||||
.update($settings_private.id, $settings_private);
|
||||
|
||||
// update settings public
|
||||
if (iconFiles.length > 0) {
|
||||
const formData = new FormData();
|
||||
formData.append('favicon', iconFiles[0]);
|
||||
await $pocketbase
|
||||
.collection('settings_public')
|
||||
.update($settings_public.id, formData);
|
||||
}
|
||||
await $pocketbase
|
||||
.collection('settings_public')
|
||||
.update($settings_public.id, $settings_public);
|
||||
|
||||
//set button
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
buttons.settings.state = 'none';
|
||||
@@ -69,8 +93,8 @@
|
||||
async function scanDevices() {
|
||||
buttons.scan.state = 'waiting';
|
||||
await $pocketbase
|
||||
.collection('settings')
|
||||
.update($settings.id, $settings)
|
||||
.collection('settings_private')
|
||||
.update($settings_private.id, $settings_private)
|
||||
.catch((err) => {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
@@ -81,7 +105,11 @@
|
||||
buttons.scan.state = 'failed';
|
||||
});
|
||||
|
||||
fetch(`${dev ? 'http://localhost:8090' : ''}/api/upsnap/scan`)
|
||||
fetch(`${dev ? 'http://localhost:8090' : ''}/api/upsnap/scan`, {
|
||||
headers: {
|
||||
Authorization: $pocketbase.authStore.baseToken
|
||||
}
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
if (data.message) {
|
||||
@@ -116,84 +144,15 @@
|
||||
await $pocketbase.collection('devices').create(device);
|
||||
$devices[device.id] = device;
|
||||
}
|
||||
|
||||
async function restoreV2Backup() {
|
||||
buttons.restore.state = 'waiting';
|
||||
|
||||
try {
|
||||
// delete all devices in pocketbase
|
||||
let result = await $pocketbase.collection('devices').getFullList();
|
||||
for (let index = 0; index < result.length; index++) {
|
||||
$pocketbase.collection('devices').delete(result[index].id);
|
||||
}
|
||||
// delete all ports in pocketbase
|
||||
result = await $pocketbase.collection('ports').getFullList();
|
||||
for (let index = 0; index < result.length; index++) {
|
||||
await $pocketbase.collection('ports').delete(result[index].id);
|
||||
}
|
||||
|
||||
let reader = new FileReader();
|
||||
reader.readAsText(files[0]);
|
||||
reader.onload = async (e) => {
|
||||
// parse uploaded file
|
||||
let data = JSON.parse(e.target.result);
|
||||
if (!Array.isArray(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// loop devices
|
||||
for (let index = 0; index < data.length; index++) {
|
||||
const device = data[index];
|
||||
|
||||
// create ports
|
||||
let thisDevicePorts = [];
|
||||
for (let index = 0; index < device.ports.length; index++) {
|
||||
const port = device.ports[index];
|
||||
const record = await $pocketbase.collection('ports').create({
|
||||
name: port.name,
|
||||
number: port.number
|
||||
});
|
||||
thisDevicePorts.push(record.id);
|
||||
}
|
||||
|
||||
// create device
|
||||
await $pocketbase.collection('devices').create({
|
||||
name: device.name,
|
||||
ip: device.ip,
|
||||
mac: device.mac,
|
||||
netmask: device.netmask,
|
||||
ports: thisDevicePorts,
|
||||
link: device.link,
|
||||
wake_cron: device.wake.cron,
|
||||
wake_cron_enabled: device.wake.enabled,
|
||||
shutdown_cron: device.shutdown.cron,
|
||||
shutdown_cron_enabled: device.shutdown.cron.enabled,
|
||||
shutdown_cmd: device.shutdown.command
|
||||
});
|
||||
}
|
||||
};
|
||||
setTimeout(() => {
|
||||
buttons.restore.state = 'none';
|
||||
}, 3000);
|
||||
buttons.restore.state = 'success';
|
||||
} catch (error) {
|
||||
setTimeout(() => {
|
||||
buttons.restore.error = '';
|
||||
buttons.restore.state = 'none';
|
||||
}, 3000);
|
||||
buttons.restore.error = error;
|
||||
buttons.restore.state = 'failed';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<UnauthorizedMsg />
|
||||
<section class="m-0 mt-4 p-4 shadow-sm">
|
||||
<form on:submit|preventDefault={saveSettings}>
|
||||
<h3 class="mb-3">Ping interval</h3>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<h3 class="mb-3">Ping interval</h3>
|
||||
<p>Sets the interval in which the devices are pinged.</p>
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">Cron</span>
|
||||
@@ -203,11 +162,11 @@
|
||||
aria-label="Interval"
|
||||
aria-describedby="addon-wrapping"
|
||||
type="text"
|
||||
bind:value={$settings.interval}
|
||||
bind:value={$settings_private.interval}
|
||||
/>
|
||||
</div>
|
||||
<h3 class="my-3">Website title</h3>
|
||||
<p>Set the website title in the navbar.</p>
|
||||
<h3 class="my-3">Title</h3>
|
||||
<p>Sets the title of the website and in the browser tab.</p>
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text" id="website-title">Title</span>
|
||||
<input
|
||||
@@ -216,13 +175,41 @@
|
||||
placeholder="e.g. 'UpSnap'"
|
||||
aria-label="Website title"
|
||||
aria-describedby="website-title"
|
||||
bind:value={$settings.website_title}
|
||||
bind:value={$settings_public.website_title}
|
||||
/>
|
||||
</div>
|
||||
<h3 class="my-3">Icon</h3>
|
||||
<img
|
||||
src=""
|
||||
alt=""
|
||||
class="img-fluid icon-preview mb-3"
|
||||
bind:this={iconPreview}
|
||||
/>
|
||||
<div class="mb-3">
|
||||
<label for="iconInput" class="form-label">Set a custom favicon.</label>
|
||||
<div class="input-group">
|
||||
<input
|
||||
class="form-control"
|
||||
type="file"
|
||||
id="iconInput"
|
||||
accept=".ico,.png,.svg,.gif,.jpg,.jpeg"
|
||||
bind:files={iconFiles}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline-danger"
|
||||
on:click={() => {
|
||||
iconFiles = [];
|
||||
$settings_public.favicon = '';
|
||||
}}>Back to Gopher</button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="callout callout-info m-0">
|
||||
<p class="m-0">
|
||||
<h5>Ping interval:</h5>
|
||||
<p>
|
||||
Leave blank to use default value of <span class="fw-bold"
|
||||
>"@every 3s"</span
|
||||
>. Learn more about the correct syntax for cron on
|
||||
@@ -239,6 +226,15 @@
|
||||
>package documentation</a
|
||||
>
|
||||
</p>
|
||||
<h5>Icon:</h5>
|
||||
<p class="m-0">
|
||||
Supported file types are
|
||||
<span class="badge text-bg-secondary">.ico</span>,
|
||||
<span class="badge text-bg-secondary">.png</span>,
|
||||
<span class="badge text-bg-secondary">.svg</span>,
|
||||
<span class="badge text-bg-secondary">.gif</span> and
|
||||
<span class="badge text-bg-secondary">.jpg/.jpeg</span>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -277,7 +273,7 @@
|
||||
placeholder="e.g. '192.168.1.0/24'"
|
||||
aria-label="ip-range"
|
||||
aria-describedby="ip-range"
|
||||
bind:value={$settings.scan_range}
|
||||
bind:value={$settings_private.scan_range}
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
@@ -286,7 +282,8 @@
|
||||
class:btn-success={buttons.scan.state === 'success' ? true : false}
|
||||
class:btn-warning={buttons.scan.state === 'waiting' ? true : false}
|
||||
class:btn-danger={buttons.scan.state === 'failed' ? true : false}
|
||||
disabled={$settings.scan_range === '' || buttons.scan.state !== 'none'
|
||||
disabled={$settings_private.scan_range === '' ||
|
||||
buttons.scan.state !== 'none'
|
||||
? true
|
||||
: false}
|
||||
>
|
||||
@@ -358,41 +355,6 @@
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
<section class="m-0 my-4 p-4 shadow-sm">
|
||||
<h3 class="mb-3">Restore</h3>
|
||||
<p>
|
||||
If you had UpSnap >=2.3.2 and <3.0.0 running before, you can restore your devices
|
||||
here.
|
||||
</p>
|
||||
<div class="callout callout-danger fw-bold">This will wipe the existing database!</div>
|
||||
<input
|
||||
class="form-control mb-3"
|
||||
aria-label="Restore"
|
||||
aria-describedby="Restore"
|
||||
type="file"
|
||||
accept=".json"
|
||||
bind:files
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-secondary"
|
||||
class:btn-success={buttons.restore.state === 'success' ? true : false}
|
||||
class:btn-warning={buttons.restore.state === 'waiting' ? true : false}
|
||||
class:btn-danger={buttons.restore.state === 'failed' ? true : false}
|
||||
disabled={files ? false : true}
|
||||
on:click={() => restoreV2Backup()}
|
||||
>
|
||||
{#if buttons.restore.state === 'none'}
|
||||
Restore
|
||||
{:else if buttons.restore.state === 'success'}
|
||||
Restored
|
||||
{:else if buttons.restore.state === 'waiting'}
|
||||
Waiting
|
||||
{:else if buttons.restore.state === 'failed'}
|
||||
Failed: {buttons.restore.error}
|
||||
{/if}
|
||||
</button>
|
||||
</section>
|
||||
<p class="m-0 my-4 p-4 text-center text-muted">
|
||||
{#if version !== undefined}
|
||||
UpSnap version: <a
|
||||
@@ -404,3 +366,9 @@
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.icon-preview {
|
||||
height: 130px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -10,8 +10,13 @@ pb.autoCancellation(false);
|
||||
|
||||
// export stores
|
||||
export const pocketbase = writable(pb);
|
||||
export const settings = writable({
|
||||
website_title: ''
|
||||
export const settings_private = writable({
|
||||
interal: '',
|
||||
scan_range: ''
|
||||
});
|
||||
export const settings_public = writable({
|
||||
website_title: '',
|
||||
favicon: ''
|
||||
});
|
||||
export const devices = writable({});
|
||||
export const authorizedStore = writable(false);
|
||||
|
||||
|
Before Width: | Height: | Size: 8.5 KiB |
|
After Width: | Height: | Size: 54 KiB |