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/gdamore/tcell/v2"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/rivo/tview" "github.com/rivo/tview"
"golang.org/x/mod/sumdb/note"
) )
const ( const (
@ -203,9 +204,26 @@ func _main(l *log.Logger, db *sql.DB) error {
su.Created = time.Now() su.Created = time.Now()
err := su.Insert(db) err := su.Insert(db)
for _, note := range su.Notes { suspiciousHosts, err := models.SuspiciousHosts(db)
note.SignupID = su.ID if err != nil {
err = note.Insert(db) 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 { if err != nil {
@ -238,26 +256,6 @@ func _main(l *log.Logger, db *sql.DB) error {
newCharacter("wire guy", "a lil homonculus made of discarded computer cables"), newCharacter("wire guy", "a lil homonculus made of discarded computer cables"),
func(s *scene) { func(s *scene) {
su.Email = string(s.Input.Bytes()) 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) { func(s *scene, tv *tview.TextView, msg string) {
// TODO could check and see if it's email shaped and admonish if not // TODO could check and see if it's email shaped and admonish if not

View File

@ -195,14 +195,12 @@ func (s *TownSignup) All(db *sql.DB) ([]*TownSignup, error) {
} }
type SuspiciousHost struct { type SuspiciousHost struct {
ID int64 ID int64
Domain string Domain string
CommonName string
Tier int64
} }
func SuspiciousHosts(db *sql.DB) ([]SuspiciousHost, error) { 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 { if err != nil {
return nil, err return nil, err
} }
@ -214,8 +212,6 @@ func SuspiciousHosts(db *sql.DB) ([]SuspiciousHost, error) {
if err = rows.Scan( if err = rows.Scan(
&sh.ID, &sh.ID,
&sh.Domain, &sh.Domain,
&sh.CommonName,
&sh.Tier,
); err != nil { ); err != nil {
return nil, err return nil, err
} }