Skip to content
Snippets Groups Projects
Unverified Commit 486a75bb authored by Max Adamo's avatar Max Adamo
Browse files

add API url

parent 5b6512d3
No related branches found
No related tags found
No related merge requests found
...@@ -29,6 +29,24 @@ func init() { ...@@ -29,6 +29,24 @@ func init() {
ErrorLogger = log.New(os.Stdout, "ERROR: ", log.Ldate|log.Ltime) ErrorLogger = log.New(os.Stdout, "ERROR: ", log.Ldate|log.Ltime)
} }
// serve certificates list
func renderJSON(w http.ResponseWriter, req *http.Request) {
provider := strings.Split(req.URL.Path, "/")[2]
serveFile := fmt.Sprintf("%v/%v/%v.json", webDir, provider, provider)
cmd := exec.Command(jsonConverter, "-p", provider)
err := cmd.Run()
if err != nil {
WarningLogger.Println(err)
w.WriteHeader(http.StatusServiceUnavailable)
} else {
if verboseBool {
InfoLogger.Printf("HTTP Status %v", http.StatusOK)
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
}
http.ServeFile(w, req, serveFile)
}
// serve certificates list // serve certificates list
func renderPage(w http.ResponseWriter, req *http.Request) { func renderPage(w http.ResponseWriter, req *http.Request) {
provider := strings.Split(req.URL.Path, "/") provider := strings.Split(req.URL.Path, "/")
...@@ -42,7 +60,7 @@ func renderPage(w http.ResponseWriter, req *http.Request) { ...@@ -42,7 +60,7 @@ func renderPage(w http.ResponseWriter, req *http.Request) {
if verboseBool { if verboseBool {
InfoLogger.Printf("HTTP Status %v", http.StatusOK) InfoLogger.Printf("HTTP Status %v", http.StatusOK)
} }
w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "text/html; charset=utf-8")
} }
http.ServeFile(w, req, serveFile) http.ServeFile(w, req, serveFile)
} }
...@@ -90,23 +108,23 @@ Options: ...@@ -90,23 +108,23 @@ Options:
listenPort := arguments["--listen-port"].(string) listenPort := arguments["--listen-port"].(string)
baseURLs := [6]string{"/sectigo_ev", "/sectigo_ov", "/letsencrypt", "/sectigo_ev/", "/sectigo_ov/", "/letsencrypt/"} baseURLs := [6]string{"/sectigo_ev", "/sectigo_ov", "/letsencrypt", "/sectigo_ev/", "/sectigo_ov/", "/letsencrypt/"}
otherURLs := [12]string{"/letsencrypt/by_name.html", "/letsencrypt/by_date.html", apiURLs := [6]string{"/api/sectigo_ev", "/api/sectigo_ov", "/api/letsencrypt",
"/letsencrypt/letsencrypt.json", "/letsencrypt/letsencrypt_expired.json", "/api/sectigo_ev/", "/api/sectigo_ov/", "/api/letsencrypt/"}
otherURLs := [6]string{"/letsencrypt/by_name.html", "/letsencrypt/by_date.html",
"/sectigo_ov/by_name.html", "/sectigo_ov/by_date.html", "/sectigo_ov/by_name.html", "/sectigo_ov/by_date.html",
"/sectigo_ov/sectigo_ov.json", "/sectigo_ov/sectigo_ov_expired.json", "/sectigo_ev/by_name.html", "/sectigo_ev/by_date.html"}
"/sectigo_ev/by_name.html", "/sectigo_ev/by_date.html",
"/sectigo_ev/sectigo_ev.json", "/sectigo_ev/sectigo_ev_expired.json"}
fs := http.FileServer(http.Dir("/var/www/acme_web/static")) fs := http.FileServer(http.Dir("/var/www/acme_web/static"))
http.Handle("/static/", http.StripPrefix("/static/", fs)) http.Handle("/static/", http.StripPrefix("/static/", fs))
//http.HandleFunc("index.html", func(res http.ResponseWriter, req *http.Request) {
// http.ServeFile(res, req, filepath.Join(webDir, "index.html"))
//})
http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) { http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
http.ServeFile(res, req, filepath.Join(webDir, "index.html")) http.ServeFile(res, req, filepath.Join(webDir, "index.html"))
}) })
for _, apiElement := range apiURLs {
http.HandleFunc(apiElement, renderJSON)
}
for _, element := range baseURLs { for _, element := range baseURLs {
http.HandleFunc(element, redirect) http.HandleFunc(element, redirect)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment