forked from tildetown/town
move to save step
This commit is contained in:
parent
544a1f6ebd
commit
252e72148e
42
external/cmd/signup/main.go
vendored
42
external/cmd/signup/main.go
vendored
@ -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,10 +204,27 @@ 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 {
|
||||||
|
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)
|
err = note.Insert(db)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Printf("failed to write to db: %s", err.Error())
|
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"),
|
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
|
||||||
|
|||||||
@ -197,12 +197,10 @@ 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
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user