From 42fca1fc413db1b0f5d855a22a705a55f093685a Mon Sep 17 00:00:00 2001 From: samuel-p Date: Tue, 23 Feb 2021 22:57:36 +0100 Subject: [PATCH] initially added files --- .drone.yml | 55 +++++++++++++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ Dockerfile | 14 ++++++++++++ README.md | 15 ++++++++++++- entrypoint.sh | 10 +++++++++ nginx.conf.template | 41 +++++++++++++++++++++++++++++++++ renovate.json | 10 +++++++++ 7 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 .drone.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 entrypoint.sh create mode 100644 nginx.conf.template create mode 100644 renovate.json diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..90f01c6 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,55 @@ +kind: pipeline +type: docker +name: linux-amd64 + +platform: + os: linux + arch: amd64 + +steps: + - name: docker + image: plugins/docker + settings: + purge: true + no_cache: true + auto_tag: true + auto_tag_suffix: linux-amd64 + repo: spcodes/unifiedpush-gotify + username: + from_secret: USERNAME + password: + from_secret: PASSWORD + +trigger: + branch: + - main + event: + - push + +--- +kind: pipeline +type: docker +name: manifest + +steps: + - name: publish-latest + image: plugins/manifest + settings: + ignore_missing: true + target: spcodes/unifiedpush-gotify + template: spcodes/unifiedpush-gotify:OS-ARCH + platforms: + - linux/amd64 + username: + from_secret: USERNAME + password: + from_secret: PASSWORD + +depends_on: + - linux-amd64 + +trigger: + branch: + - main + event: + - push diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1062418 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +*.iml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7314314 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM openresty/openresty:1.19.3.1-buster@sha256:1b970e585389f3cbbb4429c00ec6ada0082926ea0db9a2f3a9c105cbb4f437e4 + +COPY nginx.conf.template / +COPY entrypoint.sh / + +ENV RESOLVER=1.1.1.1 + +EXPOSE 80 + +STOPSIGNAL SIGQUIT + +ENTRYPOINT ["bash", "entrypoint.sh"] + +CMD ["openresty", "-g", "daemon off;"] diff --git a/README.md b/README.md index d0dded9..c2a8a5b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ -# unifiedpush-gotify +# [Gotify UnifiedPush Gateway](https://git.sp-codes.de/sp-codes/unifiedpush-gotify) +[![Build Status](https://ci.sp-codes.de/api/badges/sp-codes/unifiedpush-gotify/status.svg)](https://ci.sp-codes.de/sp-codes/unifiedpush-gotify) [![License](https://img.shields.io/badge/license-AGPL--3.0-purple)](#license) [![Docker Pulls](https://img.shields.io/docker/pulls/spcodes/unifiedpush-gotify)](https://hub.docker.com/r/spcodes/unifiedpush-gotify) + +A Docker Image for [UnifiedPush](https://unifiedpush.org). Including the [Proxy](https://unifiedpush.org/users/distributors/gotify/#nginx) and the [Matrix-Gateway](https://github.com/UnifiedPush/contrib/blob/main/gateways/matrix.md#matrix-gateway). The extension to Gotify. + +## Usage + +coming soon + +## License + +[![GNU AGPLv3 Image](https://www.gnu.org/graphics/agplv3-155x51.png)](https://www.gnu.org/licenses/agpl-3.0) + +This project is Free Software: It is licensed under GNU AGPL v3 (See [LICENSE](LICENSE) for more information). diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..d75ecf8 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +if [[ -z "${GOTIFY_URL}" ]]; then + echo "Please set GOTIFY_URL to your gotify instance." + exit 1 +fi + +envsubst '${RESOLVER} ${GOTIFY_URL}' < /nginx.conf.template > /etc/nginx/conf.d/default.conf + +exec "$@" diff --git a/nginx.conf.template b/nginx.conf.template new file mode 100644 index 0000000..44f84de --- /dev/null +++ b/nginx.conf.template @@ -0,0 +1,41 @@ +server { + listen 80; + + resolver ${RESOLVER} ipv6=off; + + location /_matrix/push/v1/notify { + set $target ''; + if ($request_method = GET ) { + return 200 '{"gateway":"matrix"}'; + } + access_by_lua_block { + local cjson = require("cjson") + ngx.req.read_body() + local body = ngx.req.get_body_data() + local parsedBody = cjson.decode(body) + ngx.var.target = parsedBody["notification"]["devices"][1]["pushkey"] + ngx.req.set_body_data(body) + } + proxy_set_header Content-Type application/json; + proxy_set_header Host $host; + proxy_pass $target; + proxy_ssl_server_name on; + } + + location /UP { + access_by_lua_block{ + ngx.req.read_body() + local req = ngx.req.get_body_data() + local newreq, n, err = ngx.re.gsub(req, '\\\\', '\\\\') + local newreq, n, err = ngx.re.gsub(newreq, '"', '\\"') + local newreq, n, err = ngx.re.gsub(newreq, "^", "{\"message\":\"") + local newreq, n, err = ngx.re.gsub(newreq, "$", "\"}") + ngx.req.set_body_data(newreq) + } + + proxy_set_header Content-Type application/json; + proxy_set_header Host $host; + proxy_pass ${GOTIFY_URL}/message; + proxy_ssl_server_name on; + } +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..a5047de --- /dev/null +++ b/renovate.json @@ -0,0 +1,10 @@ +{ + "assignees": [ + "samuel-p" + ], + "baseBranches": [ + "main" + ], + "rangeStrategy": "bump", + "rebaseWhen": "behind-base-branch" +}