feat: refactor configuration + html page template data

This commit is contained in:
2023-09-24 09:33:20 -06:00
parent c2f8be504e
commit bf14a70efe
10 changed files with 59 additions and 43 deletions

View File

@ -80,6 +80,11 @@ func (s *Server) handleRequest(ctx ssh.Context, srv *ssh.Server, req *gossh.Requ
addr := s.getSocketPath(sessionID)
if err := s.ensureFileDir(addr); err != nil {
s.log("[ERROR] %+v", errors.WithStack(err))
return false, []byte("internal server error")
}
ln, err := net.Listen("unix", addr)
if err != nil {
s.log("[ERROR] %+v", errors.WithStack(err))
@ -200,6 +205,15 @@ func (s *Server) getSocketPath(sessionID SessionID) string {
return filepath.Join(s.opts.SockDir, fmt.Sprintf("%s.sock", sessionID))
}
func (s *Server) ensureFileDir(file string) error {
dir := filepath.Dir(file)
if err := os.MkdirAll(dir, os.FileMode(0750)); err != nil {
return errors.WithStack(err)
}
return nil
}
func generateToken(length int) (string, error) {
chars := []rune(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +