add unplug command

This commit is contained in:
Ted Unangst 2019-12-08 19:17:38 -05:00
parent eb3ea156a6
commit ac0d310c92
3 changed files with 22 additions and 0 deletions

View File

@ -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.

View File

@ -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.

14
honk.go
View File

@ -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")