Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac9c27aa32 | ||
|
|
1e9558c1fc | ||
|
|
174930fc90 | ||
|
|
0559978fa2 | ||
|
|
f54b87c1f7 | ||
|
|
2ac6c64d13 |
3
Makefile
3
Makefile
@@ -1,6 +1,7 @@
|
|||||||
### CI vars
|
### CI vars
|
||||||
CI_LOGIN_COMMAND = @echo "Not a CI, skip login"
|
CI_LOGIN_COMMAND = @echo "Not a CI, skip login"
|
||||||
CI_REGISTRY_IMAGE ?= registry.gitlab.com/etke.cc/postmoogle
|
CI_REGISTRY_IMAGE ?= registry.gitlab.com/etke.cc/postmoogle
|
||||||
|
REGISTRY_IMAGE ?= registry.etke.cc/etke.cc/postmoogle
|
||||||
CI_COMMIT_TAG ?= latest
|
CI_COMMIT_TAG ?= latest
|
||||||
# for main branch it must be set explicitly
|
# for main branch it must be set explicitly
|
||||||
ifeq ($(CI_COMMIT_TAG), main)
|
ifeq ($(CI_COMMIT_TAG), main)
|
||||||
@@ -51,4 +52,4 @@ login:
|
|||||||
# docker build
|
# docker build
|
||||||
docker:
|
docker:
|
||||||
docker buildx create --use
|
docker buildx create --use
|
||||||
docker buildx build --platform linux/arm64/v8,linux/amd64 --push -t ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG} .
|
docker buildx build --platform linux/arm64/v8,linux/amd64 --push -t ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG} -t ${REGISTRY_IMAGE}:${CI_COMMIT_TAG} .
|
||||||
|
|||||||
@@ -119,12 +119,14 @@ func (b *Bot) IsTrusted(addr net.Addr) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b.log.Debug("address %s is NOT trusted", ip)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ban an address
|
// Ban an address
|
||||||
func (b *Bot) Ban(addr net.Addr) {
|
func (b *Bot) Ban(addr net.Addr) {
|
||||||
|
if !b.cfg.BanlistEnalbed() {
|
||||||
|
return
|
||||||
|
}
|
||||||
if b.IsTrusted(addr) {
|
if b.IsTrusted(addr) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"maunium.net/go/mautrix/event"
|
||||||
"maunium.net/go/mautrix/format"
|
"maunium.net/go/mautrix/format"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
|
||||||
@@ -284,6 +285,10 @@ func (b *Bot) handle(ctx context.Context) {
|
|||||||
b.Error(ctx, evt.RoomID, "cannot read message")
|
b.Error(ctx, evt.RoomID, "cannot read message")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// ignore any type apart from text (e.g. reactions, redactions, notices, etc)
|
||||||
|
if content.MsgType != event.MsgText {
|
||||||
|
return
|
||||||
|
}
|
||||||
message := strings.TrimSpace(content.Body)
|
message := strings.TrimSpace(content.Body)
|
||||||
commandSlice := b.parseCommand(message, true)
|
commandSlice := b.parseCommand(message, true)
|
||||||
if commandSlice == nil {
|
if commandSlice == nil {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"gitlab.com/etke.cc/go/logger"
|
"gitlab.com/etke.cc/go/logger"
|
||||||
"gitlab.com/etke.cc/linkpearl"
|
"gitlab.com/etke.cc/linkpearl"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
@@ -32,15 +30,24 @@ func New(lp *linkpearl.Linkpearl, log *logger.Logger) *Manager {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BanlistEnalbed or not
|
||||||
|
func (m *Manager) BanlistEnalbed() bool {
|
||||||
|
return m.ble
|
||||||
|
}
|
||||||
|
|
||||||
// GetBot config
|
// GetBot config
|
||||||
func (m *Manager) GetBot() Bot {
|
func (m *Manager) GetBot() Bot {
|
||||||
config, err := m.lp.GetAccountData(acBotKey)
|
var err error
|
||||||
|
var config Bot
|
||||||
|
config, err = m.lp.GetAccountData(acBotKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.log.Error("cannot get bot settings: %v", utils.UnwrapError(err))
|
m.log.Error("cannot get bot settings: %v", utils.UnwrapError(err))
|
||||||
}
|
}
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = make(Bot, 0)
|
config = make(Bot, 0)
|
||||||
|
return config
|
||||||
}
|
}
|
||||||
|
m.ble = config.BanlistEnabled()
|
||||||
|
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
@@ -80,6 +87,7 @@ func (m *Manager) GetBanlist() List {
|
|||||||
}
|
}
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = make(List, 0)
|
config = make(List, 0)
|
||||||
|
return config
|
||||||
}
|
}
|
||||||
m.bl = config
|
m.bl = config
|
||||||
return config
|
return config
|
||||||
@@ -88,7 +96,7 @@ func (m *Manager) GetBanlist() List {
|
|||||||
// SetBanlist config
|
// SetBanlist config
|
||||||
func (m *Manager) SetBanlist(cfg List) error {
|
func (m *Manager) SetBanlist(cfg List) error {
|
||||||
if !m.ble {
|
if !m.ble {
|
||||||
return fmt.Errorf("banlist is disabled, kupo")
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
m.mu.Lock("banlist")
|
m.mu.Lock("banlist")
|
||||||
@@ -109,6 +117,7 @@ func (m *Manager) GetGreylist() List {
|
|||||||
}
|
}
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = make(List, 0)
|
config = make(List, 0)
|
||||||
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|||||||
12
bot/data.go
12
bot/data.go
@@ -38,9 +38,11 @@ func (b *Bot) migrate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bot) syncRooms() error {
|
func (b *Bot) syncRooms() error {
|
||||||
|
adminRooms := []id.RoomID{}
|
||||||
|
|
||||||
adminRoom := b.cfg.GetBot().AdminRoom()
|
adminRoom := b.cfg.GetBot().AdminRoom()
|
||||||
if adminRoom != "" {
|
if adminRoom != "" {
|
||||||
b.adminRooms = append(b.adminRooms, adminRoom)
|
adminRooms = append(adminRooms, adminRoom)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := b.lp.GetClient().JoinedRooms()
|
resp, err := b.lp.GetClient().JoinedRooms()
|
||||||
@@ -60,9 +62,10 @@ func (b *Bot) syncRooms() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Owner() != "" && b.allowAdmin(id.UserID(cfg.Owner()), "") {
|
if cfg.Owner() != "" && b.allowAdmin(id.UserID(cfg.Owner()), "") {
|
||||||
b.adminRooms = append(b.adminRooms, roomID)
|
adminRooms = append(adminRooms, roomID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
b.adminRooms = adminRooms
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -101,3 +104,8 @@ func (b *Bot) initBotUsers() ([]string, error) {
|
|||||||
cfg.Set(config.BotUsers, "@*:"+homeserver)
|
cfg.Set(config.BotUsers, "@*:"+homeserver)
|
||||||
return cfg.Users(), b.cfg.SetBot(cfg)
|
return cfg.Users(), b.cfg.SetBot(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SyncRooms and mailboxes
|
||||||
|
func (b *Bot) SyncRooms() {
|
||||||
|
b.syncRooms() //nolint:errcheck // nothing can be done here
|
||||||
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func (b *Bot) Sendmail(eventID id.EventID, from, to, data string) (bool, error)
|
|||||||
err := b.sendmail(from, to, data)
|
err := b.sendmail(from, to, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.HasPrefix(err.Error(), "4") {
|
if strings.HasPrefix(err.Error(), "4") {
|
||||||
b.log.Debug("email %s (from=%s to=%s) was added to the queue: %v", eventID, from, to, err)
|
b.log.Info("email %s (from=%s to=%s) was added to the queue: %v", eventID, from, to, err)
|
||||||
return true, b.q.Add(eventID.String(), from, to, data)
|
return true, b.q.Add(eventID.String(), from, to, data)
|
||||||
}
|
}
|
||||||
return false, err
|
return false, err
|
||||||
@@ -179,7 +179,7 @@ func (b *Bot) SendEmailReply(ctx context.Context) {
|
|||||||
|
|
||||||
meta.MessageID = email.MessageID(evt.ID, meta.FromDomain)
|
meta.MessageID = email.MessageID(evt.ID, meta.FromDomain)
|
||||||
meta.References = meta.References + " " + meta.MessageID
|
meta.References = meta.References + " " + meta.MessageID
|
||||||
b.log.Debug("send email reply: %+v", meta)
|
b.log.Info("sending email reply: %+v", meta)
|
||||||
eml := email.New(meta.MessageID, meta.InReplyTo, meta.References, meta.Subject, meta.From, meta.To, meta.RcptTo, meta.CC, body, htmlBody, nil)
|
eml := email.New(meta.MessageID, meta.InReplyTo, meta.References, meta.Subject, meta.From, meta.To, meta.RcptTo, meta.CC, body, htmlBody, nil)
|
||||||
data := eml.Compose(b.cfg.GetBot().DKIMPrivateKey())
|
data := eml.Compose(b.cfg.GetBot().DKIMPrivateKey())
|
||||||
if data == "" {
|
if data == "" {
|
||||||
@@ -275,7 +275,7 @@ func (e *parentEmail) fixtofrom(newSenderMailbox string, domains []string) {
|
|||||||
|
|
||||||
// Recipients returns list of recipients (to, cc)
|
// Recipients returns list of recipients (to, cc)
|
||||||
func (e parentEmail) Recipients() []string {
|
func (e parentEmail) Recipients() []string {
|
||||||
return append(email.AddressList(e.CC), e.To)
|
return append(email.AddressList(e.CC), strings.Split(email.Address(e.To), ",")...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bot) getParentEvent(evt *event.Event) (id.EventID, *event.Event) {
|
func (b *Bot) getParentEvent(evt *event.Event) (id.EventID, *event.Event) {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func (q *Queue) Process() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if dequeue := q.try(itemkey, maxRetries); dequeue {
|
if dequeue := q.try(itemkey, maxRetries); dequeue {
|
||||||
q.log.Debug("email %q has been delivered", id)
|
q.log.Info("email %q has been delivered", id)
|
||||||
err = q.Remove(id)
|
err = q.Remove(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
q.log.Error("cannot dequeue email %q: %v", id, err)
|
q.log.Error("cannot dequeue email %q: %v", id, err)
|
||||||
|
|||||||
@@ -85,11 +85,11 @@ func (q *Queue) try(itemkey string, maxRetries int) bool {
|
|||||||
|
|
||||||
err = q.sendmail(item["from"], item["to"], item["data"])
|
err = q.sendmail(item["from"], item["to"], item["data"])
|
||||||
if err == nil {
|
if err == nil {
|
||||||
q.log.Debug("email %q from queue was delivered")
|
q.log.Info("email %q from queue was delivered")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
q.log.Debug("attempted to deliver email id=%q, retry=%q, but it's not ready yet: %v", item["id"], item["attempts"], err)
|
q.log.Info("attempted to deliver email id=%q, retry=%q, but it's not ready yet: %v", item["id"], item["attempts"], err)
|
||||||
attempts++
|
attempts++
|
||||||
item["attempts"] = strconv.Itoa(attempts)
|
item["attempts"] = strconv.Itoa(attempts)
|
||||||
err = q.lp.SetAccountData(itemkey, item)
|
err = q.lp.SetAccountData(itemkey, item)
|
||||||
|
|||||||
@@ -153,6 +153,11 @@ func initCron() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("cannot start queue processing cronjob: %v", err)
|
log.Error("cannot start queue processing cronjob: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = cron.AddJob("*/5 * * * *", mxb.SyncRooms)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("cannot start sync rooms cronjob: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initShutdown(quit chan struct{}) {
|
func initShutdown(quit chan struct{}) {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func New(messageID, inReplyTo, references, subject, from, to, rcptto, cc, text,
|
|||||||
From: Address(from),
|
From: Address(from),
|
||||||
To: Address(to),
|
To: Address(to),
|
||||||
CC: AddressList(cc),
|
CC: AddressList(cc),
|
||||||
RcptTo: rcptto,
|
RcptTo: Address(rcptto),
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
Text: text,
|
Text: text,
|
||||||
HTML: html,
|
HTML: html,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/mail"
|
"net/mail"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
@@ -26,6 +27,10 @@ func MessageID(eventID id.EventID, domain string) string {
|
|||||||
func Address(email string) string {
|
func Address(email string) string {
|
||||||
addr, _ := mail.ParseAddress(email) //nolint:errcheck // if it fails here, nothing will help
|
addr, _ := mail.ParseAddress(email) //nolint:errcheck // if it fails here, nothing will help
|
||||||
if addr == nil {
|
if addr == nil {
|
||||||
|
list := AddressList(email)
|
||||||
|
if len(list) > 0 {
|
||||||
|
return strings.Join(list, ",")
|
||||||
|
}
|
||||||
return email
|
return email
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func (l *Listener) Accept() (net.Conn, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
l.log.Debug("accepted connection from %q", conn.RemoteAddr())
|
l.log.Info("accepted connection from %q", conn.RemoteAddr())
|
||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ func NewManager(cfg *Config) *Manager {
|
|||||||
if len(cfg.Domains) == 1 {
|
if len(cfg.Domains) == 1 {
|
||||||
s.Domain = cfg.Domains[0]
|
s.Domain = cfg.Domains[0]
|
||||||
}
|
}
|
||||||
if log.GetLevel() == "DEBUG" || log.GetLevel() == "TRACE" {
|
if log.GetLevel() == "INFO" || log.GetLevel() == "DEBUG" || log.GetLevel() == "TRACE" {
|
||||||
s.Debug = loggerWriter{func(s string) { log.Debug(s) }}
|
s.Debug = loggerWriter{func(s string) { log.Info(s) }}
|
||||||
}
|
}
|
||||||
|
|
||||||
m := &Manager{
|
m := &Manager{
|
||||||
|
|||||||
Reference in New Issue
Block a user