diff --git a/.env.schema b/.env.schema index ae0463f..c3f6427 100644 --- a/.env.schema +++ b/.env.schema @@ -2,5 +2,3 @@ MONGODB_URI=mongodb+srv://... MONGODB_DB=... MONGODB_COLLECTION=... - -PASSWORD=PrOtEdTeD_pAsSwOrD diff --git a/config/env.go b/config/env.go index 0970d84..31c2ee8 100644 --- a/config/env.go +++ b/config/env.go @@ -11,6 +11,4 @@ var ( Mongo_URI = os.Getenv("MONGODB_URI") Mongo_DB = os.Getenv("MONGODB_DB") Mongo_Collection = os.Getenv("MONGODB_COLLECTION") - - Password = os.Getenv("PASSWORD") ) diff --git a/config/toml.go b/config/toml.go index 8f65483..146ec54 100644 --- a/config/toml.go +++ b/config/toml.go @@ -55,7 +55,6 @@ func init() { } func DownloadFile(filepath string, url string) error { - // Get the data resp, err := http.Get(url) if err != nil { return err diff --git a/website/routes/api/api.go b/website/routes/api/api.go index d480084..a5f8350 100644 --- a/website/routes/api/api.go +++ b/website/routes/api/api.go @@ -8,8 +8,6 @@ func ApplyRoutes(r *gin.Engine) { api := r.Group("/api") { api.GET("/url", GetAll) - api.POST("/url", Insert) - api.DELETE("/url/:url", Delete) api.GET("/status", Status) } diff --git a/website/routes/api/delete.go b/website/routes/api/delete.go deleted file mode 100644 index bcbf3e0..0000000 --- a/website/routes/api/delete.go +++ /dev/null @@ -1,64 +0,0 @@ -package api - -import ( - "encoding/base64" - "net/http" - - "github.com/gin-gonic/gin" - "gitlab.com/gaming0skar123/go/pingbot/config" - "gitlab.com/gaming0skar123/go/pingbot/database/mongo" -) - -func Delete(c *gin.Context) { - const BEARER_SCHEMA = "Password" - authHeader := c.GetHeader("Authorization") - passwordString := authHeader[len(BEARER_SCHEMA)+1:] - - if passwordString != config.Password { - c.JSON(http.StatusUnauthorized, json{ - "success": false, - "message": "Unauth!", - }) - - return - } - - url := c.Param("url") - - d, err := base64.StdEncoding.DecodeString(url) - if err != nil { - c.JSON(http.StatusBadRequest, json{ - "success": false, - "message": "Error Parsing Base64!", - }) - - return - } - - url = string(d) - - r, err := mongo.Delete(url) - - if r.DeletedCount <= 0 { - c.JSON(http.StatusNotFound, json{ - "success": false, - "message": "Not Found!", - }) - - return - } - - if err != nil { - c.JSON(http.StatusInternalServerError, json{ - "success": false, - "message": "Error Deleting from Database!", - }) - - return - } - - c.JSON(http.StatusOK, json{ - "success": true, - "message": "Deleted!", - }) -} diff --git a/website/routes/api/insert.go b/website/routes/api/insert.go deleted file mode 100644 index 6548219..0000000 --- a/website/routes/api/insert.go +++ /dev/null @@ -1,62 +0,0 @@ -package api - -import ( - "net/http" - - "github.com/gin-gonic/gin" - "gitlab.com/gaming0skar123/go/pingbot/database/mongo" -) - -func Insert(c *gin.Context) { - var post mongo.URL - err := c.BindJSON(&post) - if err != nil { - c.JSON(http.StatusBadRequest, json{ - "success": false, - "message": "Error Binding JSON!", - }) - - return - } - - if len(post.URL) < 1 { - c.JSON(http.StatusBadRequest, json{ - "success": false, - "message": "URL was not Provided!", - }) - - return - } - - _, err = http.Get(post.URL) - if err != nil { - c.JSON(http.StatusBadRequest, json{ - "success": false, - "message": "Error Pinging URL!", - }) - - return - } - - if post.Cluster == 0 { - post.Cluster = 1 - } - - _, err = mongo.Insert(&mongo.URL{ - URL: post.URL, - Cluster: post.Cluster, - }) - if err != nil { - c.JSON(http.StatusInternalServerError, json{ - "success": false, - "message": "Error Inserting to Database!", - }) - - return - } - - c.JSON(http.StatusOK, json{ - "success": true, - "url": post.URL, - }) -}