diff --git a/internal/services/prosody/account.go b/internal/services/prosody/account.go index 2dd969c..b0cc325 100644 --- a/internal/services/prosody/account.go +++ b/internal/services/prosody/account.go @@ -18,7 +18,7 @@ func (acc *account) unmarshal(data map[string]interface{}) { typeOfPerson := valueOfPerson.Type() for i := 0; i < valueOfPerson.NumField(); i++ { field := valueOfPerson.Field(i) - tag := typeOfPerson.Field(i).Tag.Get("mytag") + tag := typeOfPerson.Field(i).Tag.Get("prosody") if val, ok := data[tag]; ok { field.Set(reflect.ValueOf(val)) @@ -28,7 +28,10 @@ func (acc *account) unmarshal(data map[string]interface{}) { // loadAccount read the user .dat file and retrieves the data store in it func (p *Prosody) loadAccount(username string) (*account, error) { - var acc *account + if strings.HasSuffix(username, p.plainDomain) { + username = strings.Replace(username, p.plainDomain, "", -1) + } + data, err := os.ReadFile(p.accountsPath + username + ".dat") if err != nil { return nil, err @@ -45,6 +48,7 @@ func (p *Prosody) loadAccount(username string) (*account, error) { } } + acc := &account{} acc.unmarshal(mapValues) return acc, nil } diff --git a/internal/services/prosody/prosody.go b/internal/services/prosody/prosody.go index e066621..7a9fde4 100644 --- a/internal/services/prosody/prosody.go +++ b/internal/services/prosody/prosody.go @@ -1,15 +1,26 @@ package prosody +import ( + "fmt" + "net/url" +) + type Prosody struct { binPath string + plainDomain string accountsPath string } // /var/lib/prosody/xmpp%%2eurkob%%2ecom/accounts/ func NewProsody(domain string) *Prosody { + plainDomain, err := url.QueryUnescape(domain) + if err != nil { + panic(fmt.Errorf("urlQueryUnescape %w", err)) + } return &Prosody{ binPath: "/usr/bin/prosodyctl", accountsPath: "/var/lib/prosody/" + domain + "/accounts/", + plainDomain: plainDomain, } }