add signup ip support

This commit is contained in:
Arya 2023-02-18 15:20:24 +05:30
parent ae4397250e
commit bba3d72d95
Signed by untrusted user: arya
GPG Key ID: 842D12BDA50DF120
2 changed files with 9 additions and 1 deletions

View File

@ -18,6 +18,8 @@ By default publapi listens on 127.0.0.1:3000. You can change the port with the e
Additionally, you need to set the variable PUBLAPI_EMAIL_SHOUTRRRURL and PUBLAPI_NOTIFY_SHOUTRRRURL in order for signup notifications to work. URL Format can be found at https://containrrr.dev/shoutrrr/v0.5. Additionally, you need to set the variable PUBLAPI_EMAIL_SHOUTRRRURL and PUBLAPI_NOTIFY_SHOUTRRRURL in order for signup notifications to work. URL Format can be found at https://containrrr.dev/shoutrrr/v0.5.
You can also set PUBLAPI_SIGNUP_IP to make sure signup requests can only be made from one IP.
## Usage ## Usage
Currently, PublAPI has only two routes, /users and /signup. Currently, PublAPI has only two routes, /users and /signup.

View File

@ -11,7 +11,13 @@ import (
// SignupPage is the signup page handler // SignupPage is the signup page handler
func SignupPage(c *fiber.Ctx) error { func SignupPage(c *fiber.Ctx) error {
SignupIP, SignupIPExists := os.LookupEnv("PUBLAPI_SIGNUP_IP")
if SignupIPExists == true {
if c.IP() != SignupIP {
log.Info("Request made from invalid IP: ", c.IP())
return c.SendStatus(fiber.StatusForbidden)
}
}
username := c.FormValue("username") username := c.FormValue("username")
email := c.FormValue("email") email := c.FormValue("email")
ssh := c.FormValue("ssh") ssh := c.FormValue("ssh")