fix: tune up

This commit is contained in:
Urko 2023-08-09 19:30:07 +02:00
parent ee99e81991
commit 33ed5d6af5
3 changed files with 1 additions and 15 deletions

View File

@ -2,7 +2,6 @@ package handler
import ( import (
"fmt" "fmt"
"log"
"gitea.urkob.com/urko/prosody-password/internal/services/fail2ban" "gitea.urkob.com/urko/prosody-password/internal/services/fail2ban"
"gitea.urkob.com/urko/prosody-password/internal/services/prosody" "gitea.urkob.com/urko/prosody-password/internal/services/prosody"
@ -28,16 +27,10 @@ type changePasswordReq struct {
} }
func (handler ProsodyHandler) Post(c *fiber.Ctx) error { func (handler ProsodyHandler) Post(c *fiber.Ctx) error {
log.Println("body", string(c.Body()))
req := changePasswordReq{} req := changePasswordReq{}
if err := c.BodyParser(&req); err != nil { if err := c.BodyParser(&req); err != nil {
return RenderError(c, fmt.Errorf(" c.BodyParser(&req): %w", err), defaultErrMessage) return RenderError(c, fmt.Errorf(" c.BodyParser(&req): %w", err), defaultErrMessage)
} }
// req := changePasswordReq{
// CurrentPassword: c.FormValue("current_password", ""),
// NewPassword: c.FormValue("new_password", ""),
// User: c.FormValue("user", ""),
// }
if err := handler.prosodyService.ChangePassword(req.User, req.CurrentPassword, req.NewPassword); err != nil { if err := handler.prosodyService.ChangePassword(req.User, req.CurrentPassword, req.NewPassword); err != nil {
// for _, ip := range c.IPs() { // for _, ip := range c.IPs() {
// handler.fail2banSrv.FailedAttempt(ip) // handler.fail2banSrv.FailedAttempt(ip)

View File

@ -1,7 +1,6 @@
package prosody package prosody
import ( import (
"log"
"os" "os"
"reflect" "reflect"
"strings" "strings"
@ -28,12 +27,10 @@ func (acc *account) unmarshal(data map[string]interface{}) {
// loadAccount read the user .dat file and retrieves the data store in it // loadAccount read the user .dat file and retrieves the data store in it
func (p *Prosody) loadAccount(username string) (*account, error) { func (p *Prosody) loadAccount(username string) (*account, error) {
if strings.HasSuffix(username, p.plainDomain) { if strings.Contains(username, "@") && strings.HasSuffix(username, p.plainDomain) {
username = strings.Replace(username, p.plainDomain, "", -1) username = strings.Replace(username, p.plainDomain, "", -1)
} }
log.Println("username", username)
data, err := os.ReadFile(p.accountsPath + username + ".dat") data, err := os.ReadFile(p.accountsPath + username + ".dat")
if err != nil { if err != nil {
return nil, err return nil, err
@ -44,7 +41,6 @@ func (p *Prosody) loadAccount(username string) (*account, error) {
if strings.Contains(line, "=") { if strings.Contains(line, "=") {
parts := strings.Split(line, "=") parts := strings.Split(line, "=")
key := strings.Trim(strings.TrimSpace(parts[0]), "[]\"") key := strings.Trim(strings.TrimSpace(parts[0]), "[]\"")
log.Println("key", key)
value := strings.TrimSpace(strings.Trim(parts[1], "\"; ")) value := strings.TrimSpace(strings.Trim(parts[1], "\"; "))
mapValues[key] = value mapValues[key] = value
} }

View File

@ -2,7 +2,6 @@ package prosody
import ( import (
"fmt" "fmt"
"log"
"net/url" "net/url"
) )
@ -18,8 +17,6 @@ func NewProsody(domain string) *Prosody {
if err != nil { if err != nil {
panic(fmt.Errorf("urlQueryUnescape %w", err)) panic(fmt.Errorf("urlQueryUnescape %w", err))
} }
log.Println("/var/lib/prosody/" + domain + "/accounts/")
log.Println(plainDomain)
return &Prosody{ return &Prosody{
binPath: "/usr/bin/prosodyctl", binPath: "/usr/bin/prosodyctl",
accountsPath: "/var/lib/prosody/" + domain + "/accounts/", accountsPath: "/var/lib/prosody/" + domain + "/accounts/",