Ver Fonte

auto update script executed

Toby Chui há 1 ano atrás
pai
commit
9c0c584f43
1 ficheiros alterados com 14 adições e 0 exclusões
  1. 14 0
      mod/ganserv/authkey.go

+ 14 - 0
mod/ganserv/authkey.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"log"
 	"os"
+	"os/user"
 	"runtime"
 	"strings"
 )
@@ -22,20 +23,25 @@ func TryLoadorAskUserForAuthkey() string {
 	if runtime.GOOS == "windows" {
 		b, err := os.ReadFile("C:\\ProgramData\\ZeroTier\\One\\authtoken.secret")
 		if err == nil {
+			log.Println("Zerotier authkey loaded")
 			authKey = string(b)
 		} else {
 			log.Println("Unable to read authkey at C:\\ProgramData\\ZeroTier\\One\\authtoken.secret: ", err.Error())
 		}
 	} else if runtime.GOOS == "linux" {
+		//Try read from source
 		b, err := os.ReadFile("/var/lib/zerotier-one/authtoken.secret")
 		if err == nil {
+			log.Println("Zerotier authkey loaded")
 			authKey = string(b)
 		} else {
 			log.Println("Unable to read authkey at /var/lib/zerotier-one/authtoken.secret: ", err.Error())
 		}
+
 	} else if runtime.GOOS == "darwin" {
 		b, err := os.ReadFile("/Library/Application Support/ZeroTier/One/authtoken.secret")
 		if err == nil {
+			log.Println("Zerotier authkey loaded")
 			authKey = string(b)
 		} else {
 			log.Println("Unable to read authkey at /Library/Application Support/ZeroTier/One/authtoken.secret ", err.Error())
@@ -52,3 +58,11 @@ func TryLoadorAskUserForAuthkey() string {
 
 	return ""
 }
+
+func isRoot() bool {
+	currentUser, err := user.Current()
+	if err != nil {
+		return false
+	}
+	return currentUser.Username == "root"
+}