From ac0d310c927b6b57bdd6dcdb2033521f6e62c2db Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sun, 8 Dec 2019 19:17:38 -0500 Subject: [PATCH] add unplug command --- docs/changelog.txt | 2 ++ docs/honk.8 | 6 ++++++ honk.go | 14 ++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index bb87bf0..7fd9460 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -2,6 +2,8 @@ changelog -- next ++ Add unplug command for servers that have dropped off the net. + + Add notes field to honkers to document their downfall. + Add notes field to filters for record keeping. diff --git a/docs/honk.8 b/docs/honk.8 index a1d88ee..429084e 100644 --- a/docs/honk.8 +++ b/docs/honk.8 @@ -133,6 +133,12 @@ file which is important to backup and restore. The current version of the honk binary may be printed with the .Ic version command. +.Ss unplug +Sometimes servers simply disappear, resulting in many errors trying to deliver +undeliverable messages. +Running +.Ic unplug Ar hostname +will delete all subscriptions and pending deliveries. .Ss Security .Nm is not currently hardened against SSRF, server side request forgery. diff --git a/honk.go b/honk.go index b2c5090..0577f67 100644 --- a/honk.go +++ b/honk.go @@ -210,6 +210,13 @@ var loginMsg template.HTML func ElaborateUnitTests() { } +func unplugserver(hostname string) { + db := opendatabase() + xid := fmt.Sprintf("%%https://%s/%%", hostname) + db.Exec("delete from honkers where xid like ? and flavor = 'dub'", xid) + db.Exec("delete from doovers where rcpt like ?", xid) +} + func main() { flag.StringVar(&dataDir, "datadir", dataDir, "data directory") flag.StringVar(&viewDir, "viewdir", viewDir, "view directory") @@ -271,6 +278,13 @@ func main() { arg = args[1] } cleanupdb(arg) + case "unplug": + if len(args) < 2 { + fmt.Printf("usage: honk unplug servername\n") + return + } + name := args[1] + unplugserver(name) case "ping": if len(args) < 3 { fmt.Printf("usage: honk ping from to\n")