feat: add ping privileged env UPSNAP_PING_PRIVILEGED #207

This commit is contained in:
seriousm4x
2023-12-22 09:30:39 +01:00
parent 7bba99fc01
commit 976e808d75
2 changed files with 8 additions and 1 deletions

View File

@@ -2,8 +2,10 @@ package networking
import (
"net"
"os"
"os/exec"
"runtime"
"strconv"
"time"
"github.com/pocketbase/pocketbase/models"
@@ -21,7 +23,11 @@ func PingDevice(device *models.Record) bool {
}
pinger.Count = 1
pinger.Timeout = 500 * time.Millisecond
pinger.SetPrivileged(true)
privileged, err := strconv.ParseBool(os.Getenv("UPSNAP_PING_PRIVILEGED"))
if err != nil {
privileged = true
}
pinger.SetPrivileged(privileged)
err = pinger.Run()
if err != nil {
logger.Error.Println(err)

View File

@@ -14,6 +14,7 @@ services:
# - UPSNAP_INTERVAL=@every 10s # Sets the interval in which the devices are pinged
# - UPSNAP_SCAN_RANGE=192.168.1.0/24 # Scan range is used for device discovery on local network
# - UPSNAP_SCAN_TIMEOUT=500ms # Scan timeout is nmap's --host-timeout value to wait for devices (https://nmap.org/book/man-performance.html)
# - UPSNAP_PING_PRIVILEGED=true # Set to false if you don't have root user permissions
# - UPSNAP_WEBSITE_TITLE=Custom name # Custom website title
# # dns is used for name resolution during network scan
# dns: