sshportal/main.go

116 lines
2.7 KiB
Go
Raw Normal View History

package main // import "moul.io/sshportal"
2017-09-30 19:12:43 +08:00
import (
"log"
2017-11-14 08:29:25 +08:00
"math/rand"
2017-09-30 19:12:43 +08:00
"os"
"path"
"github.com/urfave/cli"
2020-02-25 18:49:38 +08:00
"moul.io/srand"
2017-09-30 19:12:43 +08:00
)
2017-11-14 07:38:23 +08:00
var (
2017-12-04 01:18:17 +08:00
// GitTag will be overwritten automatically by the build system
GitTag = "n/a"
2017-12-04 01:18:17 +08:00
// GitSha will be overwritten automatically by the build system
GitSha = "n/a"
2017-11-14 07:38:23 +08:00
)
2017-11-02 05:09:08 +08:00
2017-09-30 19:12:43 +08:00
func main() {
2020-10-04 16:18:07 +08:00
rand.Seed(srand.MustSecure())
2017-11-14 08:29:25 +08:00
2017-09-30 19:12:43 +08:00
app := cli.NewApp()
app.Name = path.Base(os.Args[0])
app.Author = "Manfred Touron"
app.Version = GitTag + " (" + GitSha + ")"
app.Email = "https://moul.io/sshportal"
app.Commands = []cli.Command{
{
Name: "server",
Usage: "Start sshportal server",
Action: func(c *cli.Context) error {
if err := ensureLogDirectory(c.String("logs-location")); err != nil {
return err
}
cfg, err := parseServerConfig(c)
if err != nil {
return err
}
return server(cfg)
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "bind-address, b",
EnvVar: "SSHPORTAL_BIND",
Value: ":2222",
Usage: "SSH server bind address",
},
cli.StringFlag{
Name: "db-driver",
EnvVar: "SSHPORTAL_DB_DRIVER",
Value: "sqlite3",
Usage: "GORM driver (sqlite3)",
},
cli.StringFlag{
Name: "db-conn",
EnvVar: "SSHPORTAL_DATABASE_URL",
Value: "./sshportal.db",
Usage: "GORM connection string",
},
cli.BoolFlag{
Name: "debug, D",
EnvVar: "SSHPORTAL_DEBUG",
Usage: "Display debug information",
},
cli.StringFlag{
Name: "aes-key",
EnvVar: "SSHPORTAL_AES_KEY",
Usage: "Encrypt sensitive data in database (length: 16, 24 or 32)",
},
2018-01-02 23:31:34 +08:00
cli.StringFlag{
Name: "logs-location",
EnvVar: "SSHPORTAL_LOGS_LOCATION",
Value: "./log",
Usage: "Store user session files",
2018-01-02 23:31:34 +08:00
},
2018-11-16 02:38:18 +08:00
cli.DurationFlag{
Name: "idle-timeout",
Value: 0,
Usage: "Duration before an inactive connection is timed out (0 to disable)",
},
2020-09-18 02:24:51 +08:00
cli.StringFlag{
Name: "acl-check-cmd",
EnvVar: "SSHPORTAL_ACL_CHECK_CMD",
Usage: "Execute external command to check ACL",
},
},
2018-01-01 17:41:21 +08:00
}, {
Name: "healthcheck",
Action: func(c *cli.Context) error { return healthcheck(c.String("addr"), c.Bool("wait"), c.Bool("quiet")) },
2018-01-01 17:41:21 +08:00
Flags: []cli.Flag{
cli.StringFlag{
Name: "addr, a",
Value: "localhost:2222",
Usage: "sshportal server address",
},
cli.BoolFlag{
Name: "wait, w",
Usage: "Loop indefinitely until sshportal is ready",
},
cli.BoolFlag{
Name: "quiet, q",
Usage: "Do not print errors, if any",
2018-01-01 17:41:21 +08:00
},
},
2018-01-02 17:57:18 +08:00
}, {
Name: "_test_server",
Hidden: true,
Action: testServer,
2017-11-24 21:29:41 +08:00
},
2017-09-30 19:12:43 +08:00
}
if err := app.Run(os.Args); err != nil {
log.Fatalf("error: %v", err)
}
2017-09-30 19:12:43 +08:00
}