diff --git a/daemon/tester.go b/daemon/tester.go index d0beea6..a46006d 100644 --- a/daemon/tester.go +++ b/daemon/tester.go @@ -1,15 +1,12 @@ package daemon import ( - "crypto/tls" - "net/http" "os" "os/signal" "syscall" "time" log "github.com/sirupsen/logrus" - "golang.org/x/crypto/acme/autocert" "dev.sum7.eu/genofire/golang-lib/file" "dev.sum7.eu/genofire/golang-lib/worker" @@ -43,29 +40,6 @@ var TesterCMD = &cobra.Command{ log.Warn("unable to load state file:", err) } - // https server to handle acme (by letsencrypt) - hs := &http.Server{ - Addr: configTester.Webserver, - } - if configTester.TLSDir != "" { - m := autocert.Manager{ - Cache: autocert.DirCache(configTester.TLSDir), - Prompt: autocert.AcceptTOS, - } - hs.TLSConfig = &tls.Config{GetCertificate: m.GetCertificate} - go func(hs *http.Server) { - if err := hs.ListenAndServeTLS("", ""); err != http.ErrServerClosed { - log.Errorf("webserver with addr %s: %s", hs.Addr, err) - } - }(hs) - } else { - go func(hs *http.Server) { - if err := hs.ListenAndServe(); err != http.ErrServerClosed { - log.Errorf("webserver with addr %s: %s", hs.Addr, err) - } - }(hs) - } - mainClient, err := client.NewClient(configTester.Client.JID, configTester.Client.Password) if err != nil { log.Fatal("unable to connect with main jabber client: ", err) diff --git a/daemon/tester/account.go b/daemon/tester/account.go new file mode 100644 index 0000000..6ebad80 --- /dev/null +++ b/daemon/tester/account.go @@ -0,0 +1,8 @@ +package tester + +import "dev.sum7.eu/genofire/yaja/model" + +type Account struct { + JID *model.JID `json:"jid"` + Password string `json:"password"` +} diff --git a/daemon/tester/config.go b/daemon/tester/config.go index 23da6a3..4a45718 100644 --- a/daemon/tester/config.go +++ b/daemon/tester/config.go @@ -10,7 +10,6 @@ type Config struct { AccountsPath string `toml:"accounts_path"` OutputPath string `toml:"output_path"` Logging log.Level `toml:"logging"` - Webserver string `toml:"webserver"` Admins []*model.JID `toml:"admins"` Client struct { JID *model.JID `toml:"jid"` diff --git a/daemon/tester/output.go b/daemon/tester/output.go index be52a50..53deb74 100644 --- a/daemon/tester/output.go +++ b/daemon/tester/output.go @@ -16,7 +16,9 @@ type Output struct { type Link struct { Source string `json:"source"` + SourceJID string `json:"source_jid"` Target string `json:"target"` + TargetJID string `json:"target_jid"` FromSource bool `json:"from_source"` FromTarget bool `json:"from_target"` } @@ -52,13 +54,17 @@ func (t *Tester) Output() *Output { toJID := model.NewJID(to) link := &Link{ Source: status.JID.Domain, + SourceJID: status.JID.Bare(), Target: toJID.Domain, + TargetJID: toJID.Bare(), FromSource: linkOK, FromTarget: false, } if switchSourceTarget { link.Source = toJID.Domain + link.SourceJID = toJID.Bare() link.Target = status.JID.Domain + link.TargetJID = status.JID.Bare() link.FromSource = false link.FromTarget = linkOK } diff --git a/daemon/tester/status.go b/daemon/tester/status.go index 1b05ac5..769a5e6 100644 --- a/daemon/tester/status.go +++ b/daemon/tester/status.go @@ -9,7 +9,7 @@ import ( type Status struct { client *client.Client - password string + account *Account JID *model.JID `json:"jid"` Domain string `json:"domain"` Login bool `json:"is_online"` @@ -18,10 +18,11 @@ type Status struct { TLSVersion string `json:"tls_version"` } -func NewStatus(jid *model.JID, password string) *Status { +func NewStatus(acc *Account) *Status { return &Status{ - JID: jid, - Domain: jid.Domain, + account: acc, + JID: acc.JID, + Domain: acc.JID.Domain, MessageForConnection: make(map[string]string), Connections: make(map[string]bool), } diff --git a/daemon/tester/tester.go b/daemon/tester/tester.go index 9b7643d..4a46867 100644 --- a/daemon/tester/tester.go +++ b/daemon/tester/tester.go @@ -11,13 +11,13 @@ import ( type Tester struct { mainClient *client.Client - Accounts map[string]string `json:"accounts"` - Status map[string]*Status `json:"-"` + Accounts map[string]*Account `json:"accounts"` + Status map[string]*Status `json:"-"` } func NewTester() *Tester { return &Tester{ - Accounts: make(map[string]string), + Accounts: make(map[string]*Account), Status: make(map[string]*Status), } } @@ -26,16 +26,19 @@ func (t *Tester) Start(mainClient *client.Client, password string) { t.mainClient = mainClient - status := NewStatus(mainClient.JID, password) + status := NewStatus(&Account{ + JID: mainClient.JID, + Password: password, + }) status.client = mainClient status.Login = true status.Update() - t.Status[mainClient.JID.Bare()] = status + t.Status[mainClient.JID.Domain] = status go t.StartBot(status) - for jidString, passwd := range t.Accounts { - t.Connect(jidString, passwd) + for _, acc := range t.Accounts { + t.Connect(acc) } } func (t *Tester) Close() { @@ -45,27 +48,28 @@ func (t *Tester) Close() { } } -func (t *Tester) Connect(jidString, password string) { - logCTX := log.WithField("jid", jidString) - jid := model.NewJID(jidString) - status, ok := t.Status[jidString] +func (t *Tester) Connect(acc *Account) { + logCTX := log.WithField("jid", acc.JID.Full()) + status, ok := t.Status[acc.JID.Bare()] if !ok { - status = NewStatus(jid, password) - t.Status[jidString] = status + status = NewStatus(acc) + t.Status[acc.JID.Bare()] = status } else if status.JID == nil { - status.JID = jid + status.JID = acc.JID } if status.Login { logCTX.Warn("is already loggedin") return } - c, err := client.NewClient(jid, password) + c, err := client.NewClient(acc.JID, acc.Password) if err != nil { logCTX.Warnf("could not connect client: %s", err) } else { logCTX.Info("client connected") status.Login = true status.client = c + status.account.JID = c.JID + status.JID = c.JID status.Update() go t.StartBot(status) } @@ -102,9 +106,9 @@ func (t *Tester) CheckStatus() { for ownJID, own := range t.Status { logCTX := log.WithField("jid", ownJID) if !own.Login { - pass, ok := t.Accounts[ownJID] + acc, ok := t.Accounts[ownJID] if ok { - t.Connect(ownJID, pass) + t.Connect(acc) } if !own.Login { continue