1
0
forked from tildetown/town

move to save step

This commit is contained in:
aoife cassidy 2025-12-31 01:02:39 +01:00
parent 544a1f6ebd
commit 252e72148e
No known key found for this signature in database
GPG Key ID: 7184AC1C9835CE48
2 changed files with 24 additions and 30 deletions

View File

@ -21,6 +21,7 @@ import (
"github.com/gdamore/tcell/v2"
_ "github.com/mattn/go-sqlite3"
"github.com/rivo/tview"
"golang.org/x/mod/sumdb/note"
)
const (
@ -203,10 +204,27 @@ func _main(l *log.Logger, db *sql.DB) error {
su.Created = time.Now()
err := su.Insert(db)
for _, note := range su.Notes {
note.SignupID = su.ID
suspiciousHosts, err := models.SuspiciousHosts(db)
if err != nil {
l.Println("could not connect to suspicious hosts db:", err)
return
}
var shDomains []string
for _, host := range suspiciousHosts {
shDomains = append(shDomains, host.Domain)
}
if records, err := DigMX(su.Email); err == nil {
for _, record := range records {
if slices.Contains(shDomains, record) {
note := models.SignupNote{
Author: "dns",
Content: fmt.Sprintf("email address has suspicious host %s", record),
SignupID: su.ID,
}
err = note.Insert(db)
}
}
}
if err != nil {
l.Printf("failed to write to db: %s", err.Error())
@ -238,26 +256,6 @@ func _main(l *log.Logger, db *sql.DB) error {
newCharacter("wire guy", "a lil homonculus made of discarded computer cables"),
func(s *scene) {
su.Email = string(s.Input.Bytes())
suspiciousHosts, err := models.SuspiciousHosts(db)
if err != nil {
l.Println("could not connect to suspicious hosts db")
return
}
var shDomains []string
for _, host := range suspiciousHosts {
shDomains = append(shDomains, host.Domain)
}
if records, err := DigMX(su.Email); err == nil {
for _, record := range records {
if slices.Contains(shDomains, record) {
su.Notes = append(su.Notes, models.SignupNote{
Author: "dns",
Content: fmt.Sprintf("email address has suspicious host %s", record),
SignupID: su.ID,
})
}
}
}
},
func(s *scene, tv *tview.TextView, msg string) {
// TODO could check and see if it's email shaped and admonish if not

View File

@ -197,12 +197,10 @@ func (s *TownSignup) All(db *sql.DB) ([]*TownSignup, error) {
type SuspiciousHost struct {
ID int64
Domain string
CommonName string
Tier int64
}
func SuspiciousHosts(db *sql.DB) ([]SuspiciousHost, error) {
rows, err := db.Query(`SELECT id, domain, common_name, tier FROM suspicious_hosts`)
rows, err := db.Query(`SELECT id, domain FROM suspicious_hosts`)
if err != nil {
return nil, err
}
@ -214,8 +212,6 @@ func SuspiciousHosts(db *sql.DB) ([]SuspiciousHost, error) {
if err = rows.Scan(
&sh.ID,
&sh.Domain,
&sh.CommonName,
&sh.Tier,
); err != nil {
return nil, err
}