taler-mailbox

Service for asynchronous wallet-to-wallet payment messages
Log | Files | Refs | Submodules | README | LICENSE

commit 505661d5f5f2d5255249c4ef31d93d611dd24757
parent cc6012c0ceaa6373fc4e8400dab62976c7e27309
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Tue, 17 Feb 2026 12:01:02 +0100

add config CLI tool and DBconf tool

Diffstat:
MMakefile.in | 11+++++++++--
Acmd/mailbox-config/main.go | 122+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcmd/mailbox-server/main_test.go | 2+-
Mpkg/rest/db.go | 6+-----
4 files changed, 133 insertions(+), 8 deletions(-)

diff --git a/Makefile.in b/Makefile.in @@ -1,4 +1,4 @@ -all: server +all: server tools TALER_MAILBOX_HOME=${datadir}/taler-mailbox TALER_MAILBOX_CONFDIR=${sysconfdir}/taler-mailbox @@ -7,6 +7,9 @@ GITVER=`git describe --tags | sed 's/v//'` server: ${GO} build -ldflags "-X main.ltversion=${LT_VERSION} -X main.version=${VERSION} -X main.mailboxdatahome=${TALER_MAILBOX_HOME} -X main.mailboxconfdir=${TALER_MAILBOX_CONFDIR}" -o taler-mailbox ./cmd/mailbox-server + +tools: + ${GO} build -ldflags "-X main.ltversion=${LT_VERSION} -X main.version=${VERSION} -X main.mailboxdatahome=${TALER_MAILBOX_HOME} -X main.mailboxconfdir=${TALER_MAILBOX_CONFDIR}" -o taler-mailbox-config ./cmd/mailbox-config ${GO} build -ldflags "-X main.ltversion=${LT_VERSION} -X main.version=${VERSION} -X main.mailboxdatahome=${TALER_MAILBOX_HOME} -X main.mailboxconfdir=${TALER_MAILBOX_CONFDIR}" -o taler-mailbox-dbinit ./cmd/mailbox-dbinit #cli: @@ -17,6 +20,9 @@ install: server -mkdir -p ${DESTDIR}${TALER_MAILBOX_HOME} install ./taler-mailbox ${DESTDIR}${bindir} install ./taler-mailbox-dbinit ${DESTDIR}${bindir} + install ./taler-directory-config ${DESTDIR}${bindir} + chmod +x ./contrib/taler-mailbox-dbconfig + install ./contrib/taler-mailbox-dbconfig ${DESTDIR}${bindir} cp mailbox.conf.example ${DESTDIR}${TALER_MAILBOX_HOME} -mkdir -p ${DESTDIR}${mandir}/man1 cp doc/man/taler-mailbox.1 ${DESTDIR}${mandir}/man1/ @@ -30,6 +36,7 @@ check: format: ${GO} fmt ./cmd/mailbox-server/*.go + ${GO} fmt ./cmd/mailbox-config/*.go ${GO} fmt ./cmd/mailbox-dbinit/*.go ${GO} fmt ./pkg/rest/*.go @@ -39,4 +46,4 @@ gana: dist: git archive --format=tar.gz -o taler-mailbox-${GITVER}.tar.gz --prefix=taler-mailbox-${GITVER}/ HEAD -.PHONY: all gana format check uninstall install server dist +.PHONY: all gana format check uninstall install server tools dist diff --git a/cmd/mailbox-config/main.go b/cmd/mailbox-config/main.go @@ -0,0 +1,122 @@ +// This file is part of mailbox, the Taler mailbox implementation. +// Copyright (C) 2025 Martin Schanzenbach +// +// mailbox is free software: you can redistribute it and/or modify it +// under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, +// or (at your option) any later version. +// +// mailbox is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// +// SPDX-License-Identifier: AGPL3.0-or-later + +package main + +import ( + "flag" + "fmt" + "os" + "path" + + "rsc.io/getopt" + + "gopkg.in/ini.v1" +) + +var ( + version string + mailboxdatahome string + mailboxconfdir string + verbose bool // FIXME do something with this? +) + +func printHelp() { + fmt.Print("taler-mailbox-config\n\n") + getopt.PrintDefaults() + fmt.Print("\nReport bugs to gnunet-developers@gnu.org.\n", + "Home page: https://taler.net\n", + "General help using GNU software: http://www.gnu.org/gethelp/\n") +} + +func printKey(key *ini.Key, onlyValue bool) { + if onlyValue { + fmt.Printf("%s\n", key.String()) + return + } + fmt.Printf("%s = %s\n", key.Name(), key.String()) +} + +func printCfgOptions(sec *ini.Section, option *string, onlyValue *bool) { + if len(*option) == 0 { + for _, key := range sec.Keys() { + printKey(key, *onlyValue) + } + return + } + if !sec.HasKey(*option) { + fmt.Printf("Section `%s' does not have option `%s'!\n", sec.Name(), *option) + os.Exit(1) + } + key := sec.Key(*option) + printKey(key, *onlyValue) +} + +func printCfgSections(f *ini.File) { + for _, sec := range f.Sections() { + fmt.Println(sec.Name()) + } +} + +func main() { + var cfg *ini.File + var err error + var sectionFlag = flag.String("s", "", "Section to use") + getopt.Alias("s", "section") + var listSectionFlag = flag.Bool("S", false, "List all sections") + getopt.Alias("S", "list-sections") + var optionFlag = flag.String("o", "", "Option to output") + getopt.Alias("o", "option") + var onlyValueFlag = flag.Bool("O", false, "Output only value") + getopt.Alias("O", "only-value") + var cfgFlag = flag.String("c", "", "Configuration file to use") + getopt.Alias("c", "config") + var helpFlag = flag.Bool("h", false, "Print help") + getopt.Alias("h", "help") + + getopt.Parse() + if *helpFlag { + printHelp() + return + } + cfgfile := path.Join(mailboxconfdir, "mailbox.conf") + if len(*cfgFlag) != 0 { + cfg, err = ini.Load(*cfgFlag) + if err != nil { + fmt.Printf("Failed to read config: %v\n", err) + os.Exit(1) + } + } else { + // FIXME also try in datahome + cfg, err = ini.LooseLoad(cfgfile) + if err != nil { + fmt.Printf("Failed to read config: %v\n", err) + os.Exit(1) + } + } + if *listSectionFlag { + printCfgSections(cfg) + return + } + if len(*sectionFlag) == 0 { + fmt.Println("No section given!") + os.Exit(1) + } + sec := cfg.Section(*sectionFlag) + printCfgOptions(sec, optionFlag, onlyValueFlag) +} diff --git a/cmd/mailbox-server/main_test.go b/cmd/mailbox-server/main_test.go @@ -232,7 +232,7 @@ func TestMailboxRegistration(t *testing.T) { aliceSigningKey := util.Base32CrockfordEncode(testAliceSigningKey) msg.MailboxMetadata.EncryptionKey = util.Base32CrockfordEncode(encKey) msg.MailboxMetadata.EncryptionKeyType = "X25519" - msg.MailboxMetadata.Expiration.Seconds = uint64(time.Now().Add(time.Hour*24*365).Unix()) + msg.MailboxMetadata.Expiration.Seconds = uint64(time.Now().Add(time.Hour * 24 * 365).Unix()) msg.MailboxMetadata.SigningKey = aliceSigningKey msg.MailboxMetadata.SigningKeyType = "EdDSA" expNbo := make([]byte, 8) diff --git a/pkg/rest/db.go b/pkg/rest/db.go @@ -70,7 +70,7 @@ type PendingMailboxRegistration struct { // ORM Serial int64 `json:"-"` - // Created timestamp (in Seconds / UNIX Epoch) + // Created timestamp (in Seconds / UNIX Epoch) CreatedAt int64 // Hash of the inbox for this entry @@ -409,7 +409,6 @@ func DeleteAllPendingRegistrationsFromDatabase(db *sql.DB) (int64, error) { return rows, nil } - func DeleteAllMailboxesFromDatabase(db *sql.DB) (int64, error) { var ctx context.Context ctx, stop := context.WithCancel(context.Background()) @@ -436,7 +435,6 @@ func DeleteAllMailboxesFromDatabase(db *sql.DB) (int64, error) { return rows, nil } - func DeleteAllInboxEntriesFromDatabase(db *sql.DB) (int64, error) { var ctx context.Context ctx, stop := context.WithCancel(context.Background()) @@ -462,5 +460,3 @@ func DeleteAllInboxEntriesFromDatabase(db *sql.DB) (int64, error) { } return rows, nil } - -