diff --git a/config.json b/config.json new file mode 100644 index 0000000..648534e --- /dev/null +++ b/config.json @@ -0,0 +1,7 @@ +{ + "username": "deinBenutzername", + "password": "deinPasswort", + "domain": "domain", + "server": "server", + "multimon": true +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..2d85445 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module freerdp-go + +go 1.23.6 + +require github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..43a2db6 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e h1:wSQCJiig/QkoUnpvelSPbLiZNWvh2yMqQTQvIQqSUkU= +github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e/go.mod h1:5G2EjwzgZUPnnReoKvPWVneT8APYbyKkihDVAHUi0II= diff --git a/main.go b/main.go new file mode 100644 index 0000000..d1dfc3f --- /dev/null +++ b/main.go @@ -0,0 +1,107 @@ +package main + +import ( + "encoding/json" + "flag" + "fmt" + "log" + "os" + "os/exec" + + "github.com/andlabs/ui" +) + +type Config struct { + Username string `json:"username"` + Password string `json:"password"` + Domain string `json:"domain"` + Server string `json:"server"` + Multimon bool `json:"multimon"` +} + +func main() { + // Argument für die Konfigurationsdatei hinzufügen + configFile := flag.String("config", "config.json", "Pfad zur Konfigurationsdatei") + flag.Parse() + + config, err := loadConfig(*configFile) + if err != nil { + log.Fatal(err) + } + + err = ui.Main(func() { + window := ui.NewWindow("Server Verbindung 1.0", 400, 250, false) + + serverLabel := ui.NewLabel("\nVerbindung zu:\n " + config.Server + "\n") + + usernameEntry := ui.NewEntry() + usernameEntry.SetText(config.Username) + passwordEntry := ui.NewPasswordEntry() + passwordEntry.SetText(config.Password) + connectButton := ui.NewButton("Verbinden") + exitButton := ui.NewButton("Beenden") + + box := ui.NewVerticalBox() + box.SetPadded(true) // Setzt den gepolsterten Modus für die Box + + box.Append(serverLabel, false) + box.Append(ui.NewLabel("Benutzername:"), false) + box.Append(usernameEntry, false) + box.Append(ui.NewLabel("Passwort:"), false) + box.Append(passwordEntry, false) + box.Append(connectButton, false) + box.Append(exitButton, false) + + paddedBox := ui.NewHorizontalBox() + paddedBox.SetPadded(true) + paddedBox.Append(box, true) + + window.SetChild(paddedBox) + + connectButton.OnClicked(func(*ui.Button) { + username := usernameEntry.Text() + password := passwordEntry.Text() + connectToServer(username, password, config.Domain, config.Multimon, config.Server) + }) + + exitButton.OnClicked(func(*ui.Button) { + ui.Quit() + }) + + window.OnClosing(func(*ui.Window) bool { + ui.Quit() + return true + }) + window.Show() + }) + if err != nil { + log.Fatal(err) + } +} + +func loadConfig(filename string) (*Config, error) { + data, err := os.ReadFile(filename) + if err != nil { + return nil, err + } + var config Config + err = json.Unmarshal(data, &config) + if err != nil { + return nil, err + } + return &config, nil +} + +func connectToServer(username, password, domain string, multimon bool, server string) { + args := []string{"/u:" + username, "/p:" + password, "/d:" + domain, "/v:" + server, "/cert:ignore", "/floatbar:sticky:off,default:visible,show:always"} + if multimon { + args = append(args, "/multimon") + } + cmd := exec.Command("xfreerdp", args...) + err := cmd.Run() + if err != nil { + log.Fatal(err) + } else { + fmt.Println("Erfolgreich verbunden!") + } +}