diff --git a/go.mod b/go.mod
index b80020eb..8bb3e416 100644
--- a/go.mod
+++ b/go.mod
@@ -47,6 +47,7 @@ require (
github.com/go-ini/ini v1.67.0 // indirect
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
github.com/golang/mock v1.6.0 // indirect
+ github.com/gorilla/schema v1.4.1 // indirect
github.com/invopop/jsonschema v0.13.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
diff --git a/go.sum b/go.sum
index 1270536a..70db511c 100644
--- a/go.sum
+++ b/go.sum
@@ -96,6 +96,8 @@ github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfh
github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E=
+github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM=
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
diff --git a/html/template/sync/sudo.html b/html/template/sync/sudo.html
index fae7566c..ff7c026d 100644
--- a/html/template/sync/sudo.html
+++ b/html/template/sync/sudo.html
@@ -1,6 +1,6 @@
{{ template "sync/layout/authenticated.html" . }}
-{{ define "title" }}Dash{{ end }}
+{{ define "title" }}Sudo{{ end }}
{{ define "extraheader" }}
{{ end }}
{{ define "content" }}
@@ -16,7 +16,7 @@
SMS Testing
diff --git a/sync/routes.go b/sync/routes.go
index 783c4ecd..baecf08e 100644
--- a/sync/routes.go
+++ b/sync/routes.go
@@ -69,6 +69,7 @@ func Router() chi.Router {
r.Method("GET", "/source/{globalid}", auth.NewEnsureAuth(getSource))
r.Method("GET", "/stadia", auth.NewEnsureAuth(getStadia))
r.Method("GET", "/sudo", authenticatedHandler(getSudo))
+ r.Method("POST", "/sudo/sms", auth.NewEnsureAuth(postSudoSMS))
r.Method("GET", "/trap/{globalid}", auth.NewEnsureAuth(getTrap))
r.Method("GET", "/text/{destination}", auth.NewEnsureAuth(getTextMessages))
r.Method("GET", "/upload", authenticatedHandler(getUploadList))
diff --git a/sync/sudo.go b/sync/sudo.go
index 17cbcfe3..79fcadd6 100644
--- a/sync/sudo.go
+++ b/sync/sudo.go
@@ -6,6 +6,8 @@ import (
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
+ "github.com/gorilla/schema"
+ "github.com/rs/zerolog/log"
)
type contentSudo struct{}
@@ -20,3 +22,28 @@ func getSudo(ctx context.Context, user *models.User) (string, interface{}, *erro
content := contentAdminDash{}
return "sync/sudo.html", content, nil
}
+
+var decoder = schema.NewDecoder()
+
+type FormSMS struct {
+ Message string `schema:"smsMessage"`
+ Phone string `schema:"smsPhone"`
+}
+
+func postSudoSMS(w http.ResponseWriter, r *http.Request, u *models.User) {
+ err := r.ParseForm()
+ if err != nil {
+ respondError(w, "Failed to parse form", err, http.StatusInternalServerError)
+ return
+ }
+
+ var sms FormSMS
+
+ err = decoder.Decode(&sms, r.PostForm)
+ if err != nil {
+ respondError(w, "Failed to decode form", err, http.StatusInternalServerError)
+ return
+ }
+ log.Info().Str("msg", sms.Message).Str("phone", sms.Phone).Msg("Got SMS")
+ http.Redirect(w, r, "/sudo", http.StatusFound)
+}