func hookBefore(c *cli.Context) error { // logrus.SetOutput(os.Stderr) if c.Bool("verbose") { logrus.SetLevel(logrus.DebugLevel) } else { logrus.SetLevel(logrus.InfoLevel) } return nil }
// Action is the default cli action to execute func Action(c *cli.Context) { // Initialize the SSH server server, err := ssh2docker.NewServer() if err != nil { logrus.Fatalf("Cannot create server: %v", err) } // Restrict list of allowed images if c.String("allowed-images") != "" { server.AllowedImages = strings.Split(c.String("allowed-images"), ",") } // Configure server server.DefaultShell = c.String("shell") server.DockerRunArgs = strings.Split(c.String("docker-run-args"), " ") server.NoJoin = c.Bool("no-join") server.CleanOnStartup = c.Bool("clean-on-startup") server.PasswordAuthScript = c.String("password-auth-script") server.PublicKeyAuthScript = c.String("publickey-auth-script") server.LocalUser = c.String("local-user") server.Banner = c.String("banner") // Register the SSH host key hostKey := c.String("host-key") switch hostKey { case "built-in": hostKey = DefaultHostKey case "system": hostKey = "/etc/ssh/ssh_host_rsa_key" } err = server.AddHostKey(hostKey) if err != nil { logrus.Fatalf("Cannot add host key: %v", err) } // Bind TCP socket bindAddress := c.String("bind") listener, err := net.Listen("tcp", bindAddress) if err != nil { logrus.Fatalf("Failed to start listener on %q: %v", bindAddress, err) } logrus.Infof("Listening on %q", bindAddress) // Initialize server if err = server.Init(); err != nil { logrus.Fatalf("Failed to initialize the server: %v", err) } // Accept new clients for { conn, err := listener.Accept() if err != nil { logrus.Error("Accept failed: %v", err) continue } go server.Handle(conn) } }