diff --git a/.gitea/workflows/dockerimage.yaml b/.gitea/workflows/dockerimage.yaml index c46725b..e4b96c8 100644 --- a/.gitea/workflows/dockerimage.yaml +++ b/.gitea/workflows/dockerimage.yaml @@ -3,6 +3,7 @@ name: Docker Build on: + workflow_dispatch: {} push: branches: - main diff --git a/.gitea/workflows/vault.yaml b/.gitea/workflows/vault.yaml index c0229a6..c3d4659 100644 --- a/.gitea/workflows/vault.yaml +++ b/.gitea/workflows/vault.yaml @@ -3,6 +3,7 @@ name: Hashicorp Vault on: #[push,pull_request] + workflow_dispatch: {} push: &vaultPaths paths: - 'iac/*.tf' diff --git a/main.go b/main.go index fbeec1a..1c3da60 100644 --- a/main.go +++ b/main.go @@ -372,6 +372,87 @@ func test_oauth2_callback(w http.ResponseWriter, r *http.Request) { w.Write([]byte(html)) } +// Handler pour afficher les cookies et le client +func displayInfoHandler(w http.ResponseWriter, r *http.Request) { + // Get the cookies + cookies := r.Cookies() + + // Get the user IP + userIP, _, err := net.SplitHostPort(r.RemoteAddr) + if err != nil { + log.Printf("Failed to get user IP: %v", err) + } + + // Get the headers + headers := map[string]string{} + for name, values := range r.Header { + headers[name] = strings.Join(values, ", ") + } + + // Display the information in a simple HTML page + tmpl := ` + + +
+{{.UserIP}}
+ +
+ {{range $key, $value := .Headers}}
+ {{$key}}: {{$value}}
+ {{end}}
+
+
+
+ `
+
+ data := struct {
+ Cookies []string
+ UserIP string
+ Headers map[string]string
+ }{
+ Cookies: []string{},
+ UserIP: userIP,
+ Headers: headers,
+ }
+
+ for _, cookie := range cookies {
+ data.Cookies = append(data.Cookies, fmt.Sprintf("%s=%s", cookie.Name, cookie.Value))
+ }
+
+ w.Header().Set("Content-Type", "text/html")
+ tmplBytes, err := template.New("info").Parse(tmpl)
+ if err != nil {
+ http.Error(w, "Error parsing template", http.StatusInternalServerError)
+ fmt.Printf("%+v\n", err)
+ return
+ }
+ err = tmplBytes.Execute(w, data)
+ if err != nil {
+ http.Error(w, "Error rendering template", http.StatusInternalServerError)
+ fmt.Printf("%+v\n", err)
+ return
+ }
+}
+
func main() {
var err error
@@ -394,6 +475,8 @@ func main() {
// Define the handler for the `/readiness` probe
http.HandleFunc("/readiness", readinessHandler)
+ http.HandleFunc("/display-info", displayInfoHandler)
+
/*
Gitea doesn't come with device flow # https://github.com/go-gitea/gitea/issues/27309
https://gitea.arcodange.duckdns.org/.well-known/openid-configuration
@@ -410,6 +493,7 @@ func main() {
http.HandleFunc("/retrieve", retrieveHandler)
http.HandleFunc("/test-oauth-callback", test_oauth2_callback)
+
// Start the HTTP server
port := ":8080"
log.Printf("Server starting on port %s\n", port)