platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
43
selective-vpn-api/app/routes_handlers_status.go
Normal file
43
selective-vpn-api/app/routes_handlers_status.go
Normal file
@@ -0,0 +1,43 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user