44 lines
940 B
Go
44 lines
940 B
Go
package app
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
func handleGetStatus(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet {
|
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
|
|
data, err := os.ReadFile(statusFilePath)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
http.Error(w, "status file not found", http.StatusNotFound)
|
|
return
|
|
}
|
|
http.Error(w, "failed to read status file", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
var st Status
|
|
if err := json.Unmarshal(data, &st); err != nil {
|
|
http.Error(w, "invalid status.json", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
if st.Iface != "" && st.Iface != "-" && st.Table != "" && st.Table != "-" {
|
|
ok, err := checkPolicyRoute(st.Iface, st.Table)
|
|
if err != nil {
|
|
log.Printf("checkPolicyRoute error: %v", err)
|
|
} else {
|
|
st.PolicyRouteOK = &ok
|
|
st.RouteOK = &ok
|
|
}
|
|
}
|
|
|
|
writeJSON(w, http.StatusOK, st)
|
|
}
|