aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Dockerfile6
-rw-r--r--docker-compose.yaml2
-rw-r--r--go.mod1
-rw-r--r--go.sum2
-rw-r--r--main.go63
5 files changed, 69 insertions, 5 deletions
diff --git a/Dockerfile b/Dockerfile
index e014703..86c18bb 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM alpine:3.18 as builder
+FROM alpine:3.19 as builder
RUN apk update && apk upgrade && \
apk add go git
RUN git clone https://github.com/terminaldweller/sms-webhook
@@ -9,12 +9,12 @@ RUN go mod download
ENV CGO_ENABLED=0
RUN go build
-FROM alpine:3.18 as certbuilder
+FROM alpine:3.19 as certbuilder
RUN apk add openssl
WORKDIR /certs
RUN openssl req -nodes -new -x509 -subj="/C=US/ST=Denial/L=springfield/O=Dis/CN=sms-webhook" -keyout server.key -out server.cert
-FROM alpine:3.18
+FROM alpine:3.19
COPY --from=certbuilder /certs /certs
COPY --from=builder /sms-webhook/sms-webhook /sms-webhook/
ENTRYPOINT ["/sms-webhook/sms-webhook"]
diff --git a/docker-compose.yaml b/docker-compose.yaml
index b019e9e..a9b5dfb 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -31,7 +31,7 @@ services:
volumes:
- pb-vault:/sms-webhook/pb_data
redis:
- image: redis:7.2-alpine
+ image: redis:7.2.3-alpine3.18
deploy:
resources:
limits:
diff --git a/go.mod b/go.mod
index 4587516..07874bc 100644
--- a/go.mod
+++ b/go.mod
@@ -5,6 +5,7 @@ go 1.21
require (
github.com/go-redis/redis/v8 v8.11.5
github.com/labstack/echo/v5 v5.0.0-20230722203903-ec5b858dab61
+ github.com/lrstanley/girc v0.0.0-20230911164840-f47717952bf9
github.com/pocketbase/pocketbase v0.18.9
)
diff --git a/go.sum b/go.sum
index 850151c..1f0c1eb 100644
--- a/go.sum
+++ b/go.sum
@@ -164,6 +164,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/labstack/echo/v5 v5.0.0-20230722203903-ec5b858dab61 h1:FwuzbVh87iLiUQj1+uQUsuw9x5t9m5n5g7rG7o4svW4=
github.com/labstack/echo/v5 v5.0.0-20230722203903-ec5b858dab61/go.mod h1:paQfF1YtHe+GrGg5fOgjsjoCX/UKDr9bc1DoWpZfns8=
+github.com/lrstanley/girc v0.0.0-20230911164840-f47717952bf9 h1:Kgp9FtxM8VZr2wDmXhCkd/f2EW5NeXJzZSWMYQB4M4s=
+github.com/lrstanley/girc v0.0.0-20230911164840-f47717952bf9/go.mod h1:lgrnhcF8bg/Bd5HA5DOb4Z+uGqUqGnp4skr+J2GwVgI=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
diff --git a/main.go b/main.go
index 41e6bfe..55bf29c 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "crypto/tls"
"flag"
"fmt"
"log"
@@ -8,6 +9,7 @@ import (
"github.com/go-redis/redis/v8"
"github.com/labstack/echo/v5"
+ "github.com/lrstanley/girc"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/core"
)
@@ -28,6 +30,15 @@ type SMSInfo struct {
Sim string `json:"sim"`
}
+type IRCInfo struct {
+ ircServer string
+ ircPort int
+ ircNick string
+ ircSaslUser string
+ ircSaslPass string
+ ircChannel string
+}
+
func postHandler(context echo.Context) error {
smsInfo := new(SMSInfo)
if err := context.Bind(smsInfo); err != nil {
@@ -47,7 +58,55 @@ func postHandler(context echo.Context) error {
return context.JSON(http.StatusOK, smsInfo)
}
+func runIRC(ircInfo IRCInfo) *girc.Client {
+ irc := girc.New(girc.Config{
+ Server: ircInfo.ircServer,
+ Port: ircInfo.ircPort,
+ Nick: ircInfo.ircNick,
+ User: "soulshack",
+ Name: "soulshack",
+ SSL: true,
+ TLSConfig: &tls.Config{InsecureSkipVerify: false},
+ })
+
+ saslUser := ircInfo.ircSaslUser
+ saslPass := ircInfo.ircSaslPass
+ if saslUser != "" && saslPass != "" {
+ irc.Config.SASL = &girc.SASLPlain{
+ User: ircInfo.ircSaslUser,
+ Pass: ircInfo.ircSaslPass,
+ }
+ }
+
+ irc.Handlers.AddBg(girc.PRIVMSG, func(c *girc.Client, e girc.Event) {
+ })
+
+ if err := irc.Connect(); err != nil {
+ log.Fatal(err)
+ return nil
+ }
+ return irc
+}
+
func main() {
+ ircServer := flag.String("ircserver", "irc.terminaldweller.com", "the address of the irc server to connect to")
+ ircPort := flag.Int("ircport", 6697, "the port of the irc server to connect to")
+ ircNick := flag.String("ircnick", "soulhack", "the nick to use on the irc server")
+ ircSaslUser := flag.String("ircsasluser", "soulhack", "the sasl user to use on the irc server")
+ ircSaslPass := flag.String("ircsaslpass", "", "the sasl password to use on the irc server")
+ ircChannel := flag.String("ircchannel", "#soulhack", "the channel to join on the irc server")
+
+ ircInfo := IRCInfo{
+ ircServer: *ircServer,
+ ircPort: *ircPort,
+ ircNick: *ircNick,
+ ircSaslUser: *ircSaslUser,
+ ircSaslPass: *ircSaslPass,
+ ircChannel: *ircChannel,
+ }
+
+ ircClient := runIRC(ircInfo)
+
redisAddress := flag.String("redisaddress", "redis:6379", "determines the address of the redis instance")
redisPassword := flag.String("redispassword", "", "determines the password of the redis db")
redisDB := flag.Int64("redisdb", 0, "determines the db number")
@@ -66,7 +125,9 @@ func main() {
app := pocketbase.New()
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
- e.Router.POST("/sms/*", postHandler)
+ e.Router.POST("/sms", postHandler)
+
+ ircClient.Handlers.AddBg(girc.PRIVMSG, func(c *girc.Client, e girc.Event) {})
return nil
})