diff options
author | terminaldweller <devi@terminaldweller.com> | 2024-01-28 02:11:19 +0000 |
---|---|---|
committer | terminaldweller <devi@terminaldweller.com> | 2024-01-28 02:11:19 +0000 |
commit | 1c012bdc7526821c45894816a33b9967db508d48 (patch) | |
tree | 6fdae276f51c7e6ce2002266fb7e7fe7c6f05f93 | |
parent | removed exta uselss git clone line (diff) | |
download | sms-webhook-1c012bdc7526821c45894816a33b9967db508d48.tar.gz sms-webhook-1c012bdc7526821c45894816a33b9967db508d48.zip |
added basic http auth
-rw-r--r-- | main.go | 17 | ||||
-rw-r--r-- | nginx.conf | 9 |
2 files changed, 18 insertions, 8 deletions
@@ -28,6 +28,7 @@ const ( type handlerWrapper struct { irc *girc.Client config TomlConfig + app *pocketbase.PocketBase } type SMS struct { @@ -49,6 +50,20 @@ type TomlConfig struct { // curl -X 'POST' 'http://127.0.0.1:8090/sms' -H 'content-type: application/json; charset=utf-8' -d $'{"from":"1234567890","text":"Test"}' func (hw handlerWrapper) postHandler(context echo.Context) error { + user, pass, ok := context.Request().BasicAuth() + if !ok { + return context.JSON(http.StatusUnauthorized, "unauthorized") + } + + userRecord, err := hw.app.Dao().FindAuthRecordByUsername("users", user) + if err != nil { + return context.JSON(http.StatusUnauthorized, "unauthorized") + } + + if userRecord.Get("password") != pass { + return context.JSON(http.StatusUnauthorized, "unauthorized") + } + sms := new(SMS) if err := context.Bind(sms); err != nil { return context.String(http.StatusBadRequest, "bad request") @@ -142,7 +157,7 @@ func main() { app := pocketbase.New() ircChan := make(chan *girc.Client, 1) - hw := handlerWrapper{irc: nil, config: appConfig} + hw := handlerWrapper{irc: nil, config: appConfig, app: app} app.OnBeforeServe().Add(func(e *core.ServeEvent) error { go runIRC(appConfig, ircChan) @@ -17,20 +17,15 @@ http { ssl_session_timeout 1d; ssl_session_tickets off; ssl_prefer_server_ciphers on; - # sendfile on; + sendfile on; tcp_nopush on; add_header X-Content-Type-Options "nosniff" always; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; - add_header Content-Security-Policy "default-src 'self';"; + # add_header Content-Security-Policy "default-src 'none'; base-uri 'self'; form-action 'none'; manifest-src 'self'; connect-src * blob:; script-src 'self' 'unsafe-eval'; style-src 'self'; font-src 'self'; frame-ancestors 'none'; img-src 'self' data: blob:; media-src blob:; object-src blob:; sandbox allow-same-origin allow-scripts allow-forms allow-popups allow-modals allow-downloads"; add_header X-Frame-Options SAMEORIGIN always; add_header X-XSS-Protection "1; mode=block" always; - # add_header Permissions-Policy "geolocation=(self),midi=(self),sync-xhr=(self),microphone=(self),camera=(self),magnetometer=(self),gyroscope=(self),fullscreen=(self),payment=(self),usb=(self)"; add_header Referrer-Policy "no-referrer"; fastcgi_hide_header X-Powered-By; - # resolver 9.9.9.9 208.67.222.222; - # ssl_stapling on; - # ssl_stapling_verify on; - # ssl_trusted_certificate /certs/cert1.pem; error_page 401 403 404 /404.html; location / { |