108 lines
2.5 KiB
Go
108 lines
2.5 KiB
Go
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!")
|
|
}
|
|
}
|