/gluetun-sync

Gluetun-Sync is an open-source utility designed to automatically update your services when the NAT port changes in Gluetun VPN

Primary LanguageGoMIT LicenseMIT

Gluetun-Sync

Build License Version Go Report Card

Gluetun-Sync is an open-source utility designed to automatically update your services when the NAT port changes in Gluetun VPN. Built to run seamlessly alongside Gluetun, this tool monitors port changes and triggers HTTP requests to update the relevant services or send notifications.

Features

  • Auto Monitoring: Continuously watches Gluetun for port changes.
  • Configurable Actions: HTTP requests to update services or send notifications.
  • Authenticated actions: HTTP requests are executed in serie and cookies/authorization headers are carried on
  • Flexible Configuration: Support for JSON, TOML, and YAML configuration files.
  • Docker Friendly: Designed to run in a Docker container.

Installation

Go get

go get -u github.com/afiestas/gluetun-sync

Container/Docker

docker run ...

Configuration

The service can be configured using JSON, TOML, or YAML configuration files. The url and payload fields can be configured using Go template to include either the provided credentials or the port.

  • Username
  • Password
  • Port

Here is an example using YAML for a service that requires login

config.yml

port-file: "/tmp/portfile"
requests:
  - someservice:
      credentials:
        username: "admin"
        password: "password"
      requests:
        - method: "POST"
          url: "http://localhost:8080/api/v2/auth/login"
          payload: "username={{.Username}}&password={{.Password}}"
          content-type: "application/x-www-form-urlencoded"
        - method: "POST"
          url: "http://localhost:8080/api/v2/app/setPreferences"
          payload: "json={\"listen_port\": \"{{.Port}}\"}"
          content-type: "application/x-www-form-urlencoded"

config.toml

Example in TOML for slack webhook

[[requests]]
  [requests.slack]
    [[requests.slack.requests]]
      method = "POST"
      url = "https://hooks.slack.com/services/your/webhook/url"
      payload = "{\"text\":\"New Port: {{.Port}}\"}"
      content-type = "application/json"

If you have some configuration that you want to share please issue a PR and we'll add it to the config/ folder as an example.

Usage

A config file is required for the list of requests, the port file can easily be indicated via arguments

gluetun-sync --port-file /portfile

License

This project is licensed under the MIT License - see the LICENSE.md file for details.