Save server EntryRoot and OS type during init, use to progress toward Windows server support

This commit is contained in:
2024-05-30 22:57:05 -04:00
parent 1571e0a53b
commit c3dd0ae737
2 changed files with 23 additions and 13 deletions
+7 -3
View File
@@ -4,14 +4,18 @@ import (
"github.com/rwinkhart/MUTN/src/backend"
"math/rand"
"os"
"strings"
)
// DeviceIDGen generates a new client device ID and registers it with the server
// device IDs are only needed for online synchronization
func DeviceIDGen() {
// returns the remote EntryRoot and OS type (OS type is a bool: backend.IsWindows)
func DeviceIDGen() (string, string) {
deviceIDPrefix, _ := os.Hostname()
deviceIDSuffix := backend.StringGen(rand.Intn(48)+48, false, 0) // TODO consider using complex string generator and removing unsafe characters manually
deviceID := deviceIDPrefix + "-" + deviceIDSuffix
os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + deviceID) // TODO remove existing device ID file if it exists (from both client and server)
GetSSHOutput("libmuttonserver register "+deviceID, false) // register device ID with server
os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + deviceID) // TODO remove existing device ID file if it exists (from both client and server)
sshEntryRootSSHIsWindows := strings.Split(GetSSHOutput("libmuttonserver register "+deviceID, false), "\x1d") // register device ID with server and fetch remote EntryRoot and OS type
return sshEntryRootSSHIsWindows[0], sshEntryRootSSHIsWindows[1]
}