GWM
This commit is contained in:
parent
c1f769e1cf
commit
f4b3beab61
148
main.go
148
main.go
@ -10,6 +10,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"net/mail"
|
||||
@ -641,10 +642,10 @@ func main() {
|
||||
|
||||
e.Router.GET("/api/auth/request-password-reset", func(c echo.Context) error {
|
||||
|
||||
apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
}
|
||||
//apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
// if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
// return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
// }
|
||||
|
||||
email := c.QueryParam("email")
|
||||
if email == "" {
|
||||
@ -776,10 +777,10 @@ func main() {
|
||||
|
||||
e.Router.GET("/api/auth/reset-password", func(c echo.Context) error {
|
||||
|
||||
apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
}
|
||||
//apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
// if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
// return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
// }
|
||||
|
||||
token := c.QueryParam("token")
|
||||
if token == "" {
|
||||
@ -809,10 +810,10 @@ func main() {
|
||||
|
||||
e.Router.GET("/api/login_success", func(c echo.Context) error {
|
||||
|
||||
apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
}
|
||||
//apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
// if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
// return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
// }
|
||||
|
||||
userID := c.QueryParam("id")
|
||||
if userID == "" {
|
||||
@ -854,10 +855,10 @@ func main() {
|
||||
|
||||
e.Router.GET("/api/getNotification", func(c echo.Context) error {
|
||||
|
||||
apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
}
|
||||
//apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
// if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
// return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
// }
|
||||
|
||||
language := c.QueryParam("language")
|
||||
if language == "" {
|
||||
@ -919,10 +920,10 @@ func main() {
|
||||
|
||||
e.Router.GET("/api/removeNotification", func(c echo.Context) error {
|
||||
|
||||
apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
}
|
||||
//apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
// if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
// return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
// }
|
||||
|
||||
userID := c.QueryParam("user_id")
|
||||
notificationID := c.QueryParam("notification_id")
|
||||
@ -977,10 +978,10 @@ func main() {
|
||||
|
||||
e.Router.GET("/api/pushNotification", func(c echo.Context) error {
|
||||
|
||||
apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
}
|
||||
//apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
// if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
// return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
// }
|
||||
|
||||
// type Request struct {
|
||||
// DeviceToken string `json:"device_token"`
|
||||
@ -1035,10 +1036,10 @@ func main() {
|
||||
|
||||
e.Router.POST("/api/getDataSet", func(c echo.Context) error {
|
||||
|
||||
apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
}
|
||||
//apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
// if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
// return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
// }
|
||||
|
||||
type RequestData struct {
|
||||
Dataset string `json:"dataset"`
|
||||
@ -1365,10 +1366,10 @@ func main() {
|
||||
|
||||
e.Router.GET("/api/getHomePageData", func(c echo.Context) error {
|
||||
|
||||
apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
}
|
||||
//apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
// if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
// return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
// }
|
||||
|
||||
language := c.QueryParam("language")
|
||||
colorMode := c.QueryParam("color_mode")
|
||||
@ -1466,10 +1467,10 @@ func main() {
|
||||
|
||||
e.Router.GET("/api/getUAENumbersData", func(c echo.Context) error {
|
||||
|
||||
apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
}
|
||||
//apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
// if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
// return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
// }
|
||||
|
||||
language := c.QueryParam("language")
|
||||
colorMode := c.QueryParam("color_mode")
|
||||
@ -1616,10 +1617,10 @@ func main() {
|
||||
|
||||
e.Router.GET("/api/getUserBookmark", func(c echo.Context) error {
|
||||
|
||||
apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
}
|
||||
//apiKey := c.Request().Header.Get("APP_SIGNATURE")
|
||||
// if apiKey != os.Getenv("APP_SIGNATURE") {
|
||||
// return c.JSON(http.StatusForbidden, map[string]string{"error": "Invalid API Key"})
|
||||
// }
|
||||
|
||||
language := c.QueryParam("language")
|
||||
user_id := c.QueryParam("user_id")
|
||||
@ -1878,7 +1879,74 @@ func main() {
|
||||
})
|
||||
})
|
||||
|
||||
// testing purpose only
|
||||
e.Router.GET("/api/UAE_URL_TEST", func(c echo.Context) error {
|
||||
apiURL := c.QueryParam("url")
|
||||
if apiURL == "" {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{
|
||||
"error": "Missing required query parameter 'url'",
|
||||
})
|
||||
}
|
||||
|
||||
// Call the external API
|
||||
resp, err := http.Get(apiURL)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadGateway, map[string]string{
|
||||
"error": fmt.Sprintf("Failed to reach URL: %v", err),
|
||||
})
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Read the response
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||
"error": fmt.Sprintf("Failed to read response: %v", err),
|
||||
})
|
||||
}
|
||||
|
||||
contentType := resp.Header.Get("Content-Type")
|
||||
|
||||
// 🧠 Detect Cloudflare or HTML error responses
|
||||
if strings.Contains(string(body), "cloudflare") ||
|
||||
strings.Contains(string(body), "<html") ||
|
||||
strings.Contains(strings.ToLower(contentType), "text/html") {
|
||||
return c.JSON(http.StatusBadGateway, map[string]interface{}{
|
||||
"error": "Blocked or invalid response",
|
||||
"status_code": resp.StatusCode,
|
||||
"content_type": contentType,
|
||||
"url": apiURL,
|
||||
"message": "Received HTML instead of XML. Likely blocked by Cloudflare or invalid endpoint.",
|
||||
"body_snippet": string(body[:int(math.Min(float64(len(body)), 300))]), // short preview
|
||||
})
|
||||
}
|
||||
|
||||
// Clean XML namespaces
|
||||
cleanXML := []byte(removeNamespace(body))
|
||||
|
||||
// Parse the XML
|
||||
var data GenericData
|
||||
if err := xml.Unmarshal(cleanXML, &data); err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||
"error": fmt.Sprintf("Failed to parse XML: %v", err),
|
||||
})
|
||||
}
|
||||
|
||||
// Transform data to JSON-friendly structure
|
||||
response := []map[string]interface{}{}
|
||||
for _, obs := range data.DataSet {
|
||||
response = append(response, map[string]interface{}{
|
||||
"ObsKey": mapObsKey(obs.ObsKey),
|
||||
"ObsValue": obs.ObsValue,
|
||||
})
|
||||
}
|
||||
|
||||
// Return final JSON
|
||||
return c.JSONPretty(http.StatusOK, response, " ")
|
||||
})
|
||||
|
||||
return nil
|
||||
|
||||
})
|
||||
|
||||
//send mail while status changed from app admin
|
||||
|
||||
BIN
pb_data/logs.db
BIN
pb_data/logs.db
Binary file not shown.
Loading…
Reference in New Issue
Block a user