Compare commits

..

No commits in common. "83b9dd8f214c8e5e13e5c87a8fb65b3762a1fc9b" and "ca33731826c7774c6781e5a701c89ee5fb1ddb05" have entirely different histories.

5 changed files with 27 additions and 158 deletions

View File

@ -1,7 +1,6 @@
all: cmds external
install: all
cp bin/tma /town/bin/
cp bin/launcher /usr/local/bin/town
cp bin/stats /town/bin/
cp bin/contrib /town/bin/
@ -13,7 +12,6 @@ install: all
cp bin/help /town/bin/external/
cp bin/welcome /town/bin/external/
cp bin/signup /town/bin/external/
cp bin/review /town/bin/
clean:
rm -rf bin
@ -43,7 +41,7 @@ bin/emailtouser: external/cmd/helpers/emailtouser/main.go bin
bin/registeruser: external/cmd/helpers/registeruser/main.go bin
go build -o bin/registeruser ./external/cmd/helpers/registeruser
cmds: bin/launcher bin/stats bin/contrib bin/request bin/review bin/tma
cmds: bin/launcher bin/stats bin/contrib bin/request
bin/launcher: cmd/launcher/main.go bin
go build -o bin/launcher ./cmd/launcher
@ -57,11 +55,5 @@ bin/contrib: cmd/contrib/main.go bin
bin/request: cmd/request/main.go bin
go build -o bin/request ./cmd/request
bin/review: cmd/review/main.go bin
go build -o bin/review ./cmd/review
bin/tma: cmd/tma/main.go bin
go build -o bin/tma ./cmd/tma
bin:
mkdir -p bin

View File

@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"os"
"strings"
"git.tilde.town/tildetown/town/email"
"git.tilde.town/tildetown/town/invites"
@ -45,7 +44,7 @@ func loadPassword() (string, error) {
return "", errors.New("smtp password file was empty")
}
return strings.TrimSpace(string(pw[0:n])), nil
return string(pw[0:n]), nil
}
func sendInviteEmail(invite invites.Invite) error {

View File

@ -1,101 +0,0 @@
package main
import (
"errors"
"fmt"
"os"
"strconv"
"time"
"database/sql"
"git.tilde.town/tildetown/town/towndb"
_ "github.com/mattn/go-sqlite3"
)
type dbs struct {
Invites *sql.DB
Signups *sql.DB
Users *sql.DB
}
func connect() (*dbs, error) {
users, err := sql.Open("sqlite3", "/town/var/town.db?mode=r")
if err != nil {
return nil, err
}
signups, err := sql.Open("sqlite3", "/town/var/signups/signups.db?mode=r")
if err != nil {
return nil, err
}
invites, err := sql.Open("sqlite3", "/town/var/invites/invites.db?mode=r")
if err != nil {
return nil, err
}
return &dbs{
Invites: invites,
Signups: signups,
Users: users,
}, nil
}
func _main(argv []string) error {
if len(argv) < 3 {
return errors.New("want two args (user|email) <lookup>")
}
switch argv[1] {
case "user":
return userLookup(argv[2])
case "email":
return emailLookup(argv[2])
default:
return fmt.Errorf("idk %s", argv[2])
}
}
func userLookup(username string) error {
dbs, err := connect()
if err != nil {
return err
}
stmt, err := dbs.Users.Prepare("SELECT id,created,username,state,admin FROM users WHERE username = ?")
if err != nil {
return fmt.Errorf("user select prepare failed: %w", err)
}
var created string
tu := towndb.TownUser{}
err = stmt.QueryRow(username).Scan(&tu.ID, &created, &tu.Username, &tu.State, &tu.IsAdmin)
if err != nil {
return fmt.Errorf("failed to select user: %w", err)
}
i, err := strconv.ParseInt(created, 10, 64)
if err != nil {
return fmt.Errorf("time what? %w", err)
}
tu.Created = time.Unix(i, 0)
fmt.Println("id,created,username,state,admin")
fmt.Printf("%d,%s,%s,%s,%v\n", tu.ID, tu.Created, tu.Username, tu.State, tu.IsAdmin)
// TODO rest
return nil
}
func emailLookup(address string) error {
// TODO
return nil
}
func main() {
if err := _main(os.Args); err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err.Error())
os.Exit(1)
}
}

View File

@ -4,15 +4,13 @@ import (
"bytes"
"crypto/tls"
"fmt"
"net"
"net/mail"
"net/smtp"
"os/exec"
)
const (
SMTPHost = "smtp.migadu.com"
from = "root@tilde.town"
SMTPHost = "smtp.zoho.com"
SMTPPort = 465
)
@ -40,79 +38,61 @@ func NewExternalMailer(pw string) *ExternalMailer {
}
}
func (m *ExternalMailer) Send(address, subj, body string) error {
from := mail.Address{"Tilde Town Admins", "root@tilde.town"}
to := mail.Address{"", address}
func (m *ExternalMailer) Send(address, subject, body string) error {
headers := map[string]string{
"From": from,
"To": address,
"Subject": subject,
}
// Setup headers
headers := make(map[string]string)
headers["From"] = from.String()
headers["To"] = to.String()
headers["Subject"] = subj
// Setup message
message := ""
for k, v := range headers {
message += fmt.Sprintf("%s: %s\r\n", k, v)
}
message += "\r\n" + body
// Connect to the SMTP Server
servername := fmt.Sprintf("%s:%d", SMTPHost, SMTPPort)
auth := smtp.PlainAuth("", from, m.Password, SMTPHost)
host, _, _ := net.SplitHostPort(servername)
server := fmt.Sprintf("%s:%d", SMTPHost, SMTPPort)
auth := smtp.PlainAuth("", "root@tilde.town", m.Password, host)
// TLS config
tlsconfig := &tls.Config{
tlsconf := &tls.Config{
InsecureSkipVerify: true,
ServerName: host,
ServerName: server,
}
// Here is the key, you need to call tls.Dial instead of smtp.Dial
// for smtp servers running on 465 that require an ssl connection
// from the very beginning (no starttls)
conn, err := tls.Dial("tcp", servername, tlsconfig)
conn, err := tls.Dial("tcp", server, tlsconf)
if err != nil {
return fmt.Errorf("failed dial: %w", err)
return err
}
c, err := smtp.NewClient(conn, host)
c, err := smtp.NewClient(conn, SMTPHost)
if err != nil {
return fmt.Errorf("failed to make smtp client: %w", err)
return err
}
// Auth
if err = c.Auth(auth); err != nil {
return fmt.Errorf("failed to make auth: %w", err)
return fmt.Errorf("auth failed for smtp: %w", err)
}
// To && From
if err = c.Mail(from.Address); err != nil {
return fmt.Errorf("failed to create mail: %w", err)
if err = c.Mail(from); err != nil {
return err
}
if err = c.Rcpt(to.Address); err != nil {
return fmt.Errorf("failed to add rcpt: %w", err)
if err = c.Rcpt(address); err != nil {
return err
}
// Data
w, err := c.Data()
if err != nil {
return fmt.Errorf("failed to send data: %w", err)
return err
}
_, err = w.Write([]byte(message))
if err != nil {
return fmt.Errorf("failed to write: %w", err)
}
err = w.Close()
if err != nil {
return fmt.Errorf("failed to close: %w", err)
return err
}
w.Close()
c.Quit()
return nil

View File

@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"os"
"strings"
"git.tilde.town/tildetown/town/email"
)
@ -42,7 +41,7 @@ func loadPassword() (string, error) {
return "", errors.New("smtp password file was empty")
}
return strings.TrimSpace(string(pw[0:n])), nil
return string(pw[0:n]), nil
}
func sendAuthCodeEmail(ac AuthCode) error {