Loading HACKING.md +1 −3 Original line number Diff line number Diff line Loading @@ -20,8 +20,6 @@ invoked via an SSH forced command). First-time setup: ```sh ./bulletin -u SYSTEM -b install # create DB, seed SYSTEM user + GENERAL folder ./bulletin -u SYSTEM -b new-user ALICE "Alice Smith" ./bulletin -u ALICE # enter the REPL as ALICE ``` Batch commands (`-b reboot`, `-b expire`) are meant to run from cron. Loading @@ -32,7 +30,7 @@ The install command sets up a crontab for the SYSTEM user automatically. ``` main.go CLI entry point (urfave/cli) ask/ User input helpers (readline-based prompts) batch/ Batch/maintenance commands (install, expire, reboot, new-user) batch/ Batch/maintenance commands (install, expire, reboot) dclish/ DCL-like command parser (types, builder, completer, tests) editor/ Built-in text editor (tview-based) folders/ Higher-level folder and message operations Loading batch/batch.go +0 −38 Original line number Diff line number Diff line Loading @@ -6,7 +6,6 @@ // - `install` does the initial install for bulletin. This will create // and seed the database and create the initial user. It will also // create the user's crontab entries. // - `new-user` creates a new user. // // The non-interactive batch commands are run from the user's crontab. // Loading Loading @@ -283,43 +282,6 @@ Match User %s return 0 } // NewUser creates a new user based on command line arguments. func NewUser(args []string) int { // Make sure we have enough args. if len(args) != 3 { fmt.Println("ERROR: Must supply login, site nickname and site username.") return 1 } // Create a user if missing. login := strings.ToUpper(args[0]) err := users.ValidLogin(login) ask.CheckErr(err) store, err := storage.Open() ask.CheckErr(err) q := storage.New(store.DB) ctx := storage.Context() u, err := q.GetUser(ctx, login) ask.CheckErr(err) if u.Login == "" { u, err = q.AddUser(ctx, storage.AddUserParams{ Login: login, }) ask.CheckErr(err) } if u.Login == "" { fmt.Println("ERROR: Failed to make user.") return 1 } response := key.FetchDB(q, u.Login, args[1], args[2]) fmt.Println(response) if strings.HasPrefix(response, "ERROR") { return 1 } return 0 } // MigrateKeys reads the ~/.ssh/authorized_keys file and migrates // bulletin entries into the ssh_keys database table. func MigrateKeys() int { Loading main.go +2 −4 Original line number Diff line number Diff line Loading @@ -112,9 +112,9 @@ func main() { fmt.Println("ERROR: can only run batch commands as SYSTEM.") os.Exit(1) } // Don't sandbox install/migrate-keys/new-user as they need // Don't sandbox install/migrate-keys as they need // broader filesystem and network access. if batchFlag != "install" && batchFlag != "migrate-keys" && batchFlag != "new-user" && batchFlag != "reseed" { if batchFlag != "install" && batchFlag != "migrate-keys" && batchFlag != "reseed" { if err := security.InitSandbox(); err != nil { fmt.Printf("ERROR: %s.\n", err) os.Exit(1) Loading @@ -128,8 +128,6 @@ func main() { exitcode = batch.Expire() case "install": exitcode = batch.Install() case "new-user": exitcode = batch.NewUser(cmd.Args().Slice()) case "migrate-keys": exitcode = batch.MigrateKeys() case "reseed": Loading onboard/onboard.go +6 −2 Original line number Diff line number Diff line Loading @@ -4,7 +4,9 @@ package onboard import ( "database/sql" "encoding/base64" "errors" "fmt" "os" "strings" Loading Loading @@ -106,9 +108,11 @@ func createAccount(q *storage.Queries, fingerprint, pubkeyStr string) int { // Check if login already exists. existing, err := q.GetUser(ctx, login) if err != nil { if !errors.Is(err, sql.ErrNoRows) { fmt.Printf("ERROR: %s\n", err) return 1 } } if existing.Login != "" { fmt.Println("ERROR: That login is already taken.") return 1 Loading Loading
HACKING.md +1 −3 Original line number Diff line number Diff line Loading @@ -20,8 +20,6 @@ invoked via an SSH forced command). First-time setup: ```sh ./bulletin -u SYSTEM -b install # create DB, seed SYSTEM user + GENERAL folder ./bulletin -u SYSTEM -b new-user ALICE "Alice Smith" ./bulletin -u ALICE # enter the REPL as ALICE ``` Batch commands (`-b reboot`, `-b expire`) are meant to run from cron. Loading @@ -32,7 +30,7 @@ The install command sets up a crontab for the SYSTEM user automatically. ``` main.go CLI entry point (urfave/cli) ask/ User input helpers (readline-based prompts) batch/ Batch/maintenance commands (install, expire, reboot, new-user) batch/ Batch/maintenance commands (install, expire, reboot) dclish/ DCL-like command parser (types, builder, completer, tests) editor/ Built-in text editor (tview-based) folders/ Higher-level folder and message operations Loading
batch/batch.go +0 −38 Original line number Diff line number Diff line Loading @@ -6,7 +6,6 @@ // - `install` does the initial install for bulletin. This will create // and seed the database and create the initial user. It will also // create the user's crontab entries. // - `new-user` creates a new user. // // The non-interactive batch commands are run from the user's crontab. // Loading Loading @@ -283,43 +282,6 @@ Match User %s return 0 } // NewUser creates a new user based on command line arguments. func NewUser(args []string) int { // Make sure we have enough args. if len(args) != 3 { fmt.Println("ERROR: Must supply login, site nickname and site username.") return 1 } // Create a user if missing. login := strings.ToUpper(args[0]) err := users.ValidLogin(login) ask.CheckErr(err) store, err := storage.Open() ask.CheckErr(err) q := storage.New(store.DB) ctx := storage.Context() u, err := q.GetUser(ctx, login) ask.CheckErr(err) if u.Login == "" { u, err = q.AddUser(ctx, storage.AddUserParams{ Login: login, }) ask.CheckErr(err) } if u.Login == "" { fmt.Println("ERROR: Failed to make user.") return 1 } response := key.FetchDB(q, u.Login, args[1], args[2]) fmt.Println(response) if strings.HasPrefix(response, "ERROR") { return 1 } return 0 } // MigrateKeys reads the ~/.ssh/authorized_keys file and migrates // bulletin entries into the ssh_keys database table. func MigrateKeys() int { Loading
main.go +2 −4 Original line number Diff line number Diff line Loading @@ -112,9 +112,9 @@ func main() { fmt.Println("ERROR: can only run batch commands as SYSTEM.") os.Exit(1) } // Don't sandbox install/migrate-keys/new-user as they need // Don't sandbox install/migrate-keys as they need // broader filesystem and network access. if batchFlag != "install" && batchFlag != "migrate-keys" && batchFlag != "new-user" && batchFlag != "reseed" { if batchFlag != "install" && batchFlag != "migrate-keys" && batchFlag != "reseed" { if err := security.InitSandbox(); err != nil { fmt.Printf("ERROR: %s.\n", err) os.Exit(1) Loading @@ -128,8 +128,6 @@ func main() { exitcode = batch.Expire() case "install": exitcode = batch.Install() case "new-user": exitcode = batch.NewUser(cmd.Args().Slice()) case "migrate-keys": exitcode = batch.MigrateKeys() case "reseed": Loading
onboard/onboard.go +6 −2 Original line number Diff line number Diff line Loading @@ -4,7 +4,9 @@ package onboard import ( "database/sql" "encoding/base64" "errors" "fmt" "os" "strings" Loading Loading @@ -106,9 +108,11 @@ func createAccount(q *storage.Queries, fingerprint, pubkeyStr string) int { // Check if login already exists. existing, err := q.GetUser(ctx, login) if err != nil { if !errors.Is(err, sql.ErrNoRows) { fmt.Printf("ERROR: %s\n", err) return 1 } } if existing.Login != "" { fmt.Println("ERROR: That login is already taken.") return 1 Loading