diff options
author | maride <maride@darknebu.la> | 2018-08-22 20:38:57 +0200 |
---|---|---|
committer | maride <maride@darknebu.la> | 2018-08-22 20:38:57 +0200 |
commit | 0a40e8487cb9e1ce4c21fbd6ba84ea5044a0db45 (patch) | |
tree | 4074f28479e0398de932ec50d1bff90b9a2b9fa9 | |
parent | ff1b1fba7a49011088a05c65309f14b5e7b8892e (diff) |
Generate config file and host it on a local port
-rw-r--r-- | Dockerfile | 6 | ||||
-rw-r--r-- | chainloader.sh | 22 | ||||
-rw-r--r-- | host.go | 17 |
3 files changed, 32 insertions, 13 deletions
diff --git a/Dockerfile b/Dockerfile index c9532aa..2330bd5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.8 +FROM golang:alpine # Set up workdir RUN mkdir -p /prod/persist @@ -16,6 +16,10 @@ RUN chmod +x /prod/chainloader.sh COPY server.conf /prod/server.conf COPY client.conf /prod/client.conf +# Copy client config host code and compile it +COPY host.go /tmp/host.go +RUN go build -o /prod/confhost /tmp/host.go + # Create jail user # (We're dropping it to this user in the chainloader script) RUN adduser -u 1337 -D jail diff --git a/chainloader.sh b/chainloader.sh index 15fee02..98558b2 100644 --- a/chainloader.sh +++ b/chainloader.sh @@ -1,17 +1,15 @@ #!/bin/sh -if [ "$action" == "generate" ]; then - # Generate PSK - openvpn --genkey --secret /prod/persist/static.key +# Generate PSK +openvpn --genkey --secret /prod/persist/static.key - # Generate client.conf - cat /prod/client.conf - echo "<secret>" - cat /prod/persist/static.key - echo "</secret>" -fi +# Generate client.conf +cat /prod/client.conf > /tmp/client.conf +echo "<secret>" >> /tmp/client.conf +cat /prod/persist/static.key >> /tmp/client.conf +echo "</secret>" >> /tmp/client.conf -if [ "$action" == "run" ]; then - openvpn --config /prod/server.conf -fi +./confhost & + +openvpn --config /prod/server.conf diff --git a/host.go b/host.go new file mode 100644 index 0000000..9f98607 --- /dev/null +++ b/host.go @@ -0,0 +1,17 @@ +package main + +import ( + "net/http" + "io/ioutil" +) + +func main() { + mux := http.NewServeMux() + mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { + content, error := ioutil.ReadFile("/tmp/client.conf") + if error == nil { + w.Write(content) + } + }) + http.ListenAndServe(":9999", mux) +} \ No newline at end of file |