From 71666578f6a930fc2f38579737b67039a9fcb1d4 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Tue, 4 Jun 2024 20:05:12 -0400 Subject: [PATCH] Server stdin migration: register --- libmuttonserver.go | 18 ++++++++---------- src/sync/init.go | 7 +++++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/libmuttonserver.go b/libmuttonserver.go index a411ea8..7365c55 100644 --- a/libmuttonserver.go +++ b/libmuttonserver.go @@ -11,6 +11,11 @@ import ( "strings" ) +// Field separator key: +// \x1d = path separator +// \x1e = space separator +// \x1f = misc. field separator + func main() { args := os.Args if len(args) < 2 { @@ -28,14 +33,6 @@ func main() { for scanner.Scan() { stdin = append(stdin, scanner.Text()) } - - // TODO debug, remove!! - // write stdin to file - //f, _ := os.Create(backend.ConfigDir + backend.PathSeparator + "stdindebug.txt") - //for _, line := range stdin { - // f.WriteString(line + "\n") - //} - //f.Close() } switch args[1] { @@ -54,9 +51,10 @@ func main() { sync.AddFolderLocal(strings.ReplaceAll(stdin[0], "\x1d", "/")) case "register": // register a new device ID - os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + args[2]) + // stdin[0] is expected to be the device ID + os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + stdin[0]) // print EntryRoot and bool indicating OS type to stdout for client to store in config - fmt.Print(backend.EntryRoot + "\x1d" + strconv.FormatBool(backend.IsWindows)) + fmt.Print(backend.EntryRoot + "\x1f" + strconv.FormatBool(backend.IsWindows)) case "init": // create the necessary directories for libmuttonserver to function backend.DirInit(false) diff --git a/src/sync/init.go b/src/sync/init.go index 090df6b..b8143f0 100644 --- a/src/sync/init.go +++ b/src/sync/init.go @@ -14,8 +14,11 @@ 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) - sshEntryRootSSHIsWindows := strings.Split(GetSSHOutput("libmuttonserver register "+deviceID, "", true), "\x1d") // register device ID with server and fetch remote EntryRoot and OS type; manualSync is true so the user is alerted if device ID registration fails + os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + deviceID) // TODO remove existing device ID file if it exists (from both client and server) + + // register device ID with server and fetch remote EntryRoot and OS type + //manualSync is true so the user is alerted if device ID registration fails + sshEntryRootSSHIsWindows := strings.Split(GetSSHOutput("libmuttonserver register", deviceID, true), "\x1f") return sshEntryRootSSHIsWindows[0], sshEntryRootSSHIsWindows[1] }