Skip to content
Permalink
Browse files

Add new genpw subcommand

  • Loading branch information
subuk committed Nov 24, 2019
1 parent bb3c010 commit 2acbe7b357b1fda03d0283a7099dce4f0f53ca26
Showing with 37 additions and 5 deletions.
  1. +1 −1 README.md
  2. +22 −0 bootstrap/genpw.go
  3. +1 −1 debian/vmango.service
  4. +1 −0 go.sum
  5. +10 −1 main.go
  6. +1 −1 vmango.dist.conf
  7. +1 −1 vmango.service
@@ -85,7 +85,7 @@ Copy vmango.dist.conf to vmango.conf and change configuration if needed.

Run app

make && ./bin/vmango
make && ./bin/vmango web

View it on http://localhost:8080 (login with admin / admin by default)

@@ -0,0 +1,22 @@
package bootstrap

import (
"fmt"
"os"
"strings"

"golang.org/x/crypto/bcrypt"
"golang.org/x/crypto/ssh/terminal"
)

func GenPassword() {
fmt.Fprintf(os.Stderr, "Password: ")
passwordBytes, _ := terminal.ReadPassword(0)
password := strings.TrimSpace(string(passwordBytes))
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
if err != nil {
panic(err)
}
fmt.Printf(string(hashedPassword))
fmt.Fprintf(os.Stderr, "\n")
}
@@ -7,7 +7,7 @@ Type=simple
User=vmango
Group=vmango
EnvironmentFile=-/etc/default/vmango
ExecStart=/usr/bin/vmango --config /etc/vmango.conf
ExecStart=/usr/bin/vmango web --config /etc/vmango.conf

[Install]
WantedBy=multi-user.target
1 go.sum
@@ -40,6 +40,7 @@ github.com/unrolled/render v1.0.1/go.mod h1:gN9T0NhL4Bfbwu8ann7Ry/TGHYfosul+J0ob
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c h1:/nJuwDLoL/zrqY6gf57vxC+Pi+pZ8bfhpPkicO5H7W4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
11 main.go
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"
"subuk/vmango/bootstrap"
"subuk/vmango/util"
@@ -14,8 +15,16 @@ func main() {
Default: util.GetenvDefault("VMANGO_CONFIG", "vmango.conf"),
Help: "Configuration file path",
})
webCommand := parser.NewCommand("web", "Start web server")
genpwCommand := parser.NewCommand("genpw", "Generate password")
if err := parser.Parse(os.Args); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}
bootstrap.Web(*configFilename)
switch {
case webCommand.Happened():
bootstrap.Web(*configFilename)
case genpwCommand.Happened():
bootstrap.GenPassword()
}
}
@@ -13,7 +13,7 @@ web {
listen = ":8080"
session_secret = "changeme"

# Uncomment to set admin / admin password
# Uncomment to set admin / admin password or generate new hash with `vmango genpw`
# user "admin" {
# email = "admin@example.com"
# hashed_password = "$2a$10$igHQGROHntvl05AztpfMeONSBDUsEbZHxayc5DOPTKIFX50WrHURS"
@@ -6,7 +6,7 @@ After=network.target
EnvironmentFile=-/etc/sysconfig/vmango
User=vmango
Group=vmango
ExecStart=/usr/bin/vmango --config /etc/vmango.conf
ExecStart=/usr/bin/vmango web --config /etc/vmango.conf
Restart=on-failure
RestartSec=5s
PrivateTmp=true

0 comments on commit 2acbe7b

Please sign in to comment.
You can’t perform that action at this time.