nov showing a message that the rendez-vous id is generated.

This commit is contained in:
Erik Brakkee 2024-08-10 17:49:04 +02:00
parent 8e131c44a3
commit c4bc07b0e0

View File

@ -17,13 +17,11 @@ func generateCLIExammple(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Error parsing form", http.StatusBadRequest) http.Error(w, "Error parsing form", http.StatusBadRequest)
return return
} }
ids := r.Form["rendez-vous-id"] id := r.FormValue("rendez-vous-id")
id := "" generatedId := false
if len(ids) > 0 {
id = strings.TrimSpace(ids[0])
}
if id == "" { if id == "" {
id = strconv.Itoa(rand.Int() % 1000000) id = strconv.Itoa(rand.Int() % 1000000)
generatedId = true
} }
remoteShells := r.Form["remote-shell"] remoteShells := r.Form["remote-shell"]
@ -36,6 +34,9 @@ func generateCLIExammple(w http.ResponseWriter, r *http.Request) {
sshPublicKeys := strings.Split(keysString, "\n") sshPublicKeys := strings.Split(keysString, "\n")
usageInputs := templates.NewUsageInputs(id, sshPublicKeys, remoteShells, localShells, downloadCommand, usageInputs := templates.NewUsageInputs(id, sshPublicKeys, remoteShells, localShells, downloadCommand,
certificateValidation) certificateValidation)
if generatedId {
usageInputs.ErrorMessages = append(usageInputs.ErrorMessages, "rendez-vous id is randomly generated, changes on every page refresh")
}
matched, _ := regexp.MatchString("^[a-zA-Z0-9-_]+$", id) matched, _ := regexp.MatchString("^[a-zA-Z0-9-_]+$", id)
if !matched { if !matched {
usageInputs.ErrorMessages = append(usageInputs.ErrorMessages, "ID may consist only of alphanumeric characters, '-', and '_'") usageInputs.ErrorMessages = append(usageInputs.ErrorMessages, "ID may consist only of alphanumeric characters, '-', and '_'")