feat(server,client): remote install mode, install survives missing systemd

This commit is contained in:
hh committed 2026-10-02 22:09:50 +00:00
1 parent c2e9284a63
commit e89cf7864a
6 files changed
+83 -18

No files matched your search

+15 -11
View File
@@ -59,7 +59,8 @@ type machineKey struct{}
func New(store *Store, config Config) http.Handler {
s := &Server{config: config, store: store, subscribers: map[chan protocol.Event]struct{}{}, streams: map[int64]int{}, seen: map[int64]int64{}}
mux := http.NewServeMux()
mux.HandleFunc("GET /i/{code}", s.install)
mux.HandleFunc("GET /i/{code}", s.install("login"))
mux.HandleFunc("GET /i/{code}/remote", s.install("remote"))
mux.Handle("GET /dl/", http.StripPrefix("/dl/", http.FileServer(http.Dir(config.ClientsDir))))
mux.HandleFunc("POST /api/claim", s.claim)
mux.HandleFunc("POST /api/session", s.login)
@@ -159,14 +160,16 @@ func (s *Server) publicURL(r *http.Request) string {
return scheme + "://" + r.Host
}
func (s *Server) install(w http.ResponseWriter, r *http.Request) {
code := r.PathValue("code")
if !codePattern.MatchString(code) || !s.store.CodeValid(r.Context(), code) {
http.Error(w, "echo 'lodge: this install link has expired, create a new one' >&2; exit 1", http.StatusNotFound)
return
func (s *Server) install(mode string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
code := r.PathValue("code")
if !codePattern.MatchString(code) || !s.store.CodeValid(r.Context(), code) {
http.Error(w, "echo 'lodge: this install link has expired, create a new one' >&2; exit 1", http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "text/x-shellscript")
_, _ = strings.NewReplacer("{{URL}}", s.publicURL(r), "{{CODE}}", code, "{{MODE}}", mode).WriteString(w, installScript)
}
w.Header().Set("Content-Type", "text/x-shellscript")
_, _ = strings.NewReplacer("{{URL}}", s.publicURL(r), "{{CODE}}", code).WriteString(w, installScript)
}
func (s *Server) setSession(w http.ResponseWriter, r *http.Request, token string, expires time.Time) {
@@ -264,9 +267,10 @@ func (s *Server) createCode(w http.ResponseWriter, r *http.Request) {
return
}
writeJSON(w, http.StatusCreated, protocol.CodeResponse{
Code: code,
Command: fmt.Sprintf("curl -fsSL %s/i/%s | sh", s.publicURL(r), code),
ExpiresAt: expires.UnixMilli(),
Code: code,
Command: fmt.Sprintf("curl -fsSL %s/i/%s | sh", s.publicURL(r), code),
RemoteCommand: fmt.Sprintf("curl -fsSL %s/i/%s/remote | sh", s.publicURL(r), code),
ExpiresAt: expires.UnixMilli(),
})
}