try ollama generated display-info handler for http request display
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
name: Docker Build
|
name: Docker Build
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch: {}
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
name: Hashicorp Vault
|
name: Hashicorp Vault
|
||||||
|
|
||||||
on: #[push,pull_request]
|
on: #[push,pull_request]
|
||||||
|
workflow_dispatch: {}
|
||||||
push: &vaultPaths
|
push: &vaultPaths
|
||||||
paths:
|
paths:
|
||||||
- 'iac/*.tf'
|
- 'iac/*.tf'
|
||||||
|
|||||||
84
main.go
84
main.go
@@ -372,6 +372,87 @@ func test_oauth2_callback(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write([]byte(html))
|
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 := `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Info</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
background-color: #f4f4f4;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Cookies:</h1>
|
||||||
|
<ul>
|
||||||
|
{{range .Cookies}}
|
||||||
|
<li>{{.}}</li>
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h1>User IP:</h1>
|
||||||
|
<p>{{.UserIP}}</p>
|
||||||
|
|
||||||
|
<h1>Headers:</h1>
|
||||||
|
<pre>
|
||||||
|
{{range $key, $value := .Headers}}
|
||||||
|
{{$key}}: {{$value}}
|
||||||
|
{{end}}
|
||||||
|
</pre>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`
|
||||||
|
|
||||||
|
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() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@@ -394,6 +475,8 @@ func main() {
|
|||||||
// Define the handler for the `/readiness` probe
|
// Define the handler for the `/readiness` probe
|
||||||
http.HandleFunc("/readiness", readinessHandler)
|
http.HandleFunc("/readiness", readinessHandler)
|
||||||
|
|
||||||
|
http.HandleFunc("/display-info", displayInfoHandler)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Gitea doesn't come with device flow # https://github.com/go-gitea/gitea/issues/27309
|
Gitea doesn't come with device flow # https://github.com/go-gitea/gitea/issues/27309
|
||||||
https://gitea.arcodange.duckdns.org/.well-known/openid-configuration
|
https://gitea.arcodange.duckdns.org/.well-known/openid-configuration
|
||||||
@@ -410,6 +493,7 @@ func main() {
|
|||||||
http.HandleFunc("/retrieve", retrieveHandler)
|
http.HandleFunc("/retrieve", retrieveHandler)
|
||||||
http.HandleFunc("/test-oauth-callback", test_oauth2_callback)
|
http.HandleFunc("/test-oauth-callback", test_oauth2_callback)
|
||||||
|
|
||||||
|
|
||||||
// Start the HTTP server
|
// Start the HTTP server
|
||||||
port := ":8080"
|
port := ":8080"
|
||||||
log.Printf("Server starting on port %s\n", port)
|
log.Printf("Server starting on port %s\n", port)
|
||||||
|
|||||||
Reference in New Issue
Block a user