diff --git a/main.go b/main.go index 76ef16d..abfaa6b 100644 --- a/main.go +++ b/main.go @@ -93,6 +93,30 @@ func wsHandler(w http.ResponseWriter, r *http.Request) { } } +func statusHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/plain; charset=utf-8") + w.Header().Set("Server", "0BSD_FOR_EVERYONE") + + openbsdBirth := time.Date(1995, 10, 1, 0, 0, 0, 0, time.UTC) + now := time.Now() + duration := now.Sub(openbsdBirth) + + years := int(duration.Hours() / 8760) + months := int((duration.Hours() - float64(years*8760)) / 730) + weeks := int((duration.Hours() - float64(years*8760) - float64(months*730)) / 168) + hours := int(duration.Hours() - float64(years*8760) - float64(months*730) - float64(weeks*168)) + minutes := int(duration.Minutes()) % 60 + seconds := int(duration.Seconds()) % 60 + milliseconds := int(duration.Milliseconds()) % 1000 + nanoseconds := int(duration.Nanoseconds()) % 1000000 + + status := fmt.Sprintf("OpenBSD uptime: %d:%d:%d:%d:%d:%d:%d:%d\nTimestamp: %d", + years, months, weeks, hours, minutes, seconds, milliseconds, nanoseconds, + now.Unix()) + + fmt.Fprint(w, status) +} + func handler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("Server", "0BSD_FOR_EVERYONE") @@ -173,6 +197,7 @@ func main() { mux := http.NewServeMux() mux.HandleFunc("/", handler) mux.HandleFunc("/ws", wsHandler) + mux.HandleFunc("/status", statusHandler) server := &http.Server{ Addr: ":" + p,