Add POSTMOOGLE_ADMINS
This commit is contained in:
@@ -44,6 +44,7 @@ env vars
|
||||
* **POSTMOOGLE_DB_DIALECT** - database dialect (postgres, sqlite3)
|
||||
* **POSTMOOGLE_MAXSIZE** - max email size (including attachments) in megabytes
|
||||
* **POSTMOOGLE_USERS** - a space-separated list of whitelisted users allowed to use the bridge. If not defined, everyone is allowed. Example rule: `@someone:example.com @another:example.com @bot.*:example.com @*:another.com`
|
||||
* **POSTMOOGLE_ADMINS** - a space-separated list of admin users. See `POSTMOOGLE_USERS` for syntax examples
|
||||
|
||||
You can find default values in [config/defaults.go](config/defaults.go)
|
||||
|
||||
|
||||
29
bot/bot.go
29
bot/bot.go
@@ -21,6 +21,7 @@ type Bot struct {
|
||||
prefix string
|
||||
domain string
|
||||
allowedUsers []*regexp.Regexp
|
||||
allowedAdmins []*regexp.Regexp
|
||||
rooms sync.Map
|
||||
log *logger.Logger
|
||||
lp *linkpearl.Linkpearl
|
||||
@@ -29,17 +30,25 @@ type Bot struct {
|
||||
}
|
||||
|
||||
// New creates a new matrix bot
|
||||
func New(lp *linkpearl.Linkpearl, log *logger.Logger, prefix, domain string, noowner, federation bool, allowedUsers []*regexp.Regexp) *Bot {
|
||||
func New(
|
||||
lp *linkpearl.Linkpearl,
|
||||
log *logger.Logger,
|
||||
prefix, domain string,
|
||||
noowner, federation bool,
|
||||
allowedUsers []*regexp.Regexp,
|
||||
allowedAdmins []*regexp.Regexp,
|
||||
) *Bot {
|
||||
return &Bot{
|
||||
noowner: noowner,
|
||||
federation: federation,
|
||||
prefix: prefix,
|
||||
domain: domain,
|
||||
allowedUsers: allowedUsers,
|
||||
rooms: sync.Map{},
|
||||
log: log,
|
||||
lp: lp,
|
||||
mu: map[id.RoomID]*sync.Mutex{},
|
||||
noowner: noowner,
|
||||
federation: federation,
|
||||
prefix: prefix,
|
||||
domain: domain,
|
||||
allowedUsers: allowedUsers,
|
||||
allowedAdmins: allowedAdmins,
|
||||
rooms: sync.Map{},
|
||||
log: log,
|
||||
lp: lp,
|
||||
mu: map[id.RoomID]*sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ func initBot(cfg *config.Config) {
|
||||
// nolint // Fatal = panic, not os.Exit()
|
||||
log.Fatal("cannot initialize matrix bot: %v", err)
|
||||
}
|
||||
mxb = bot.New(lp, mxlog, cfg.Prefix, cfg.Domain, cfg.NoOwner, cfg.Federation, cfg.Users)
|
||||
mxb = bot.New(lp, mxlog, cfg.Prefix, cfg.Domain, cfg.NoOwner, cfg.Federation, cfg.Users, cfg.Admins)
|
||||
log.Debug("bot has been created")
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"gitlab.com/etke.cc/go/env"
|
||||
|
||||
@@ -14,14 +15,14 @@ const prefix = "postmoogle"
|
||||
func New() (*Config, error) {
|
||||
env.SetPrefix(prefix)
|
||||
|
||||
mxidPatterns := env.Slice("users")
|
||||
regexPatterns, err := utils.WildcardMXIDsToRegexes(mxidPatterns)
|
||||
userPatterns, err := getUserRegexPatterns("users")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"failed to convert wildcard user patterns (`%s`) to regular expression: %s",
|
||||
mxidPatterns,
|
||||
err,
|
||||
)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
adminPatterns, err := getUserRegexPatterns("admins")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg := &Config{
|
||||
@@ -36,7 +37,8 @@ func New() (*Config, error) {
|
||||
Federation: env.Bool("federation"),
|
||||
MaxSize: env.Int("maxsize", defaultConfig.MaxSize),
|
||||
StatusMsg: env.String("statusmsg", defaultConfig.StatusMsg),
|
||||
Users: *regexPatterns,
|
||||
Users: *userPatterns,
|
||||
Admins: *adminPatterns,
|
||||
Sentry: Sentry{
|
||||
DSN: env.String("sentry.dsn", defaultConfig.Sentry.DSN),
|
||||
},
|
||||
@@ -49,3 +51,17 @@ func New() (*Config, error) {
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func getUserRegexPatterns(key string) (*[]*regexp.Regexp, error) {
|
||||
mxidPatterns := env.Slice(key)
|
||||
regexPatterns, err := utils.WildcardMXIDsToRegexes(mxidPatterns)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"failed to convert wildcard %s patterns (`%s`) to regular expression: %s",
|
||||
key,
|
||||
mxidPatterns,
|
||||
err,
|
||||
)
|
||||
}
|
||||
return regexPatterns, nil
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ type Config struct {
|
||||
StatusMsg string
|
||||
// Users holds list of allowed users (wildcards supported), e.g.: @*:example.com, @bot.*:example.com, @admin:*. Empty = *
|
||||
Users []*regexp.Regexp
|
||||
// Admins holds list of admin users (wildcards supported), e.g.: @*:example.com, @bot.*:example.com, @admin:*. Empty = *
|
||||
Admins []*regexp.Regexp
|
||||
|
||||
// DB config
|
||||
DB DB
|
||||
|
||||
Reference in New Issue
Block a user