Compare commits

...

2 Commits

Author SHA1 Message Date
vilmibm be5020ad28 WIP retooling bc of permission issue 2023-10-25 04:39:13 +00:00
vilmibm 9bea4257c1 notes 2023-10-25 03:52:54 +00:00
5 changed files with 41 additions and 14 deletions

2
.gitignore vendored
View File

@ -9,3 +9,5 @@ cmd/welcome/welcome
cmd/createkeyfile/createkeyfile
cmd/registeruser/registeruser
cmd/stats/stats
cmd/appendkeyfile/appendkeyfile
cmd/help/help

View File

@ -0,0 +1,9 @@
package main
import "fmt"
// TODO accept an email as an argument, write out a username associated with it or throw an error
func main() {
fmt.Println("TODO")
}

View File

@ -22,6 +22,15 @@ import (
// TODO put colorscheme, prompting stuff into own packages for use in the other commands. would be good to get off of survey.
func connectDB() (*sql.DB, error) {
db, err := sql.Open("sqlite3", "/town/var/codes/codes.db?mode=rw")
if err != nil {
return nil, err
}
return db, nil
}
type colorScheme struct {
Header func(string) string
Subtitle func(string) string
@ -108,7 +117,7 @@ func (p *Prompter) Select(prompt string, opts []string) (int, error) {
}
func _main(cs colorScheme) error {
db, err := towndb.ConnectDB()
db, err := connectDB()
if err != nil {
return fmt.Errorf("could not connect to database. please let root@tilde.town know about this.")
}
@ -149,6 +158,12 @@ func _main(cs colorScheme) error {
return nil
}
func userToEmail(email string) (string, error) {
// TODO shell out to /town/src/town/cmd/usertoemail
// TODO add to sudoers
return "", nil
}
func collectEmail(db *sql.DB, cs colorScheme, p *Prompter) error {
fmt.Println(cs.Header("We can send a authorization code to an email associated with your town account."))
email, err := p.String("email to send reset code to?")
@ -274,11 +289,6 @@ func redeemCode(db *sql.DB, cs colorScheme, p *Prompter) error {
return errors.New("adding to keys file failed")
}
// TODO add help user
// TODO update sshd_config
// TODO update sudoers
// TODO compile appendkeyfile and add to /town/bin/
err = code.MarkUsed(db)
if err != nil {
// TODO log err
@ -288,6 +298,13 @@ func redeemCode(db *sql.DB, cs colorScheme, p *Prompter) error {
return nil
}
// TODO db plan:
// add new db, codes (modeled after invites)
// add new helper, emailtouser, that can access town.db and report on what user matches a given email
// drop table from town.db
// update sshapps.md
func main() {
cs := newColorScheme()
err := _main(cs)

View File

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS auth_codes (
id INTEGER PRIMARY KEY,
created TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M', 'now', 'localtime')),
code TEXT,
email TEXT,
used INTEGER DEFAULT 0
);

View File

@ -32,11 +32,3 @@ CREATE TABLE IF NOT EXISTS notes (
FOREIGN KEY (author) REFERENCES users(author)
);
CREATE TABLE IF NOT EXISTS auth_codes (
id INTEGER PRIMARY KEY,
created TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M', 'now', 'localtime')),
code TEXT,
email TEXT,
used INTEGER DEFAULT 0
);