mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-09-05 16:47:20 -04:00
Implement device ID server registration and server-side init
This commit is contained in:
@@ -17,11 +17,20 @@ func main() {
|
|||||||
|
|
||||||
switch args[1] {
|
switch args[1] {
|
||||||
case "fetch":
|
case "fetch":
|
||||||
|
// print all information needed for syncing to stdout for interpretation by the client
|
||||||
sync.GetRemoteDataFromServer()
|
sync.GetRemoteDataFromServer()
|
||||||
case "shear":
|
case "shear":
|
||||||
|
// shear an entry from the server and add it to the deletions directory
|
||||||
deviceIDTargetLocation := strings.Split(args[2], "\x1d")
|
deviceIDTargetLocation := strings.Split(args[2], "\x1d")
|
||||||
targetLocationIncomplete := strings.ReplaceAll(strings.ReplaceAll(deviceIDTargetLocation[1], "\x1f", " "), "\x1e", backend.PathSeparator)
|
targetLocationIncomplete := strings.ReplaceAll(strings.ReplaceAll(deviceIDTargetLocation[1], "\x1f", " "), "\x1e", backend.PathSeparator)
|
||||||
sync.Shear(targetLocationIncomplete, deviceIDTargetLocation[0])
|
sync.Shear(targetLocationIncomplete, deviceIDTargetLocation[0])
|
||||||
|
case "register":
|
||||||
|
// register a new device ID
|
||||||
|
os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + args[2])
|
||||||
|
case "init":
|
||||||
|
// create the necessary directories for libmuttonserver to function TODO consider clearing out old directories first
|
||||||
|
backend.DirInit()
|
||||||
|
os.MkdirAll(backend.ConfigDir+backend.PathSeparator+"deletions", 0700)
|
||||||
default:
|
default:
|
||||||
fmt.Println(backend.AnsiError + "Invalid argument" + backend.AnsiReset) // TODO add server help menu
|
fmt.Println(backend.AnsiError + "Invalid argument" + backend.AnsiReset) // TODO add server help menu
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-6
@@ -3,6 +3,7 @@ package cli
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/rwinkhart/MUTN/src/backend"
|
"github.com/rwinkhart/MUTN/src/backend"
|
||||||
|
"github.com/rwinkhart/MUTN/src/sync"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
@@ -30,12 +31,6 @@ func TempInitCli() {
|
|||||||
// SSH info
|
// SSH info
|
||||||
configSSH := inputBinary("Configure SSH settings (for synchronization)?")
|
configSSH := inputBinary("Configure SSH settings (for synchronization)?")
|
||||||
if configSSH {
|
if configSSH {
|
||||||
// client device ID
|
|
||||||
deviceIDPrefix, _ := os.Hostname()
|
|
||||||
deviceIDSuffix := backend.StringGen(rand.Intn(48)+48, true, 0.2)
|
|
||||||
deviceID := deviceIDPrefix + "-" + deviceIDSuffix
|
|
||||||
os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + deviceID) // TODO remove existing device ID file if it exists, copy device ID to server
|
|
||||||
|
|
||||||
// necessary SSH info
|
// necessary SSH info
|
||||||
sshUser := input("Remote SSH username:")
|
sshUser := input("Remote SSH username:")
|
||||||
sshIP := input("Remote SSH IP address:")
|
sshIP := input("Remote SSH IP address:")
|
||||||
@@ -44,6 +39,13 @@ func TempInitCli() {
|
|||||||
|
|
||||||
// write config file
|
// write config file
|
||||||
backend.TempInit(map[string]string{"textEditor": textEditor, "gpgID": gpgID, "sshUser": sshUser, "sshIP": sshIP, "sshPort": sshPort, "sshIdentity": sshIdentity})
|
backend.TempInit(map[string]string{"textEditor": textEditor, "gpgID": gpgID, "sshUser": sshUser, "sshIP": sshIP, "sshPort": sshPort, "sshIdentity": sshIdentity})
|
||||||
|
|
||||||
|
// client device ID (perform after writing config files, as sync.GetSSHOutput must be able to read it) TODO move to backend
|
||||||
|
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)
|
||||||
|
sync.GetSSHOutput("libmuttonserver register "+deviceID, false) // register device ID with server
|
||||||
} else {
|
} else {
|
||||||
// write config file
|
// write config file
|
||||||
backend.TempInit(map[string]string{"textEditor": textEditor, "gpgID": gpgID})
|
backend.TempInit(map[string]string{"textEditor": textEditor, "gpgID": gpgID})
|
||||||
|
|||||||
Reference in New Issue
Block a user