nemanjaslijepcevic/public_ip_updater

By nemanjaslijepcevic

Updated 3 months ago

Project works with public_ip_tracker to track changes in your public IP and update a YAML configs,

Image
Networking
0

87

Public IP Tracker with YAML Update

This program works in conjunction with public_ip_tracker, developed by me. It tracks the server's public IP address, compares it with the previously stored value, and updates a YAML configuration file if the IP changes. Additionally, it logs events and can integrate with an API for external access. By default, the app works with Traefik's white IP address rule file.

Features

  • Periodically checks the server's public IP address.
  • Updates the IP address in a YAML file.
  • Supports logging of application activity, both to a file and to standard output.
  • Runs continuously, checking the IP in specified frequency.

How It Works

  1. Fetch the Current IP: The program fetches the current public IP address using an API endpoint (NODE_IP_DOMAIN) secured with a Bearer token (API_IP_TOKEN).
  2. Compare with Previous IP: It reads the previously stored IP from current_ip.txt. If the IP has changed, it updates the data list in the specified YAML file (configuration.yml).
  3. Update YAML File: If the IP has changed, it replaces the old IP or appends the new one to the data list in the YAML file.
  4. Log Activities: All actions are logged, and any errors or HTTP failures are reported.

Configuration

Environment Variables

To configure this program, the following environment variables are required:

  • NODE_IP_DOMAIN: The API URL to fetch the current IP address.
  • API_IP_TOKEN: The Bearer token for authenticating API requests.
  • LOG_LEVEL: The level of logging. Defaults to INFO.
  • CHECK_FREQUENCY: Task execution frequency in seconds (default: 60).
  • FILE_DATA_PATH: Path to the data in the YAML file (default: http.middlewares.default-whitelist.ipAllowList.sourceRange).
Files
  • current_ip.txt: Stores the previous public IP address.
  • configuration.yml: The YAML file containing the sourceRange list for updating the IP.

Docker

You can run the application in a Docker container using the provided Dockerfile. The latest Docker image for this application is available at nemanjaslijepcevic/public_ip_updater:latest.

Using Pre-Built Docker Image
  1. Pull the latest image from GitHub Container Registry (GHCR):
docker pull nemanjaslijepcevic/public_ip_updater:latest
  1. Run the Docker container:
docker run -d \
  --name public_ip_updater \
  -e NODE_IP_DOMAIN="https://your-api-domain.com/api/ip" \
  -e FILE_DATA_PATH="file.path.to.the.variable" \
  -e API_IP_TOKEN="api_token" \
  -e TZ="Europe/Belgrade" \
  -e LOG_LEVEL="DEBUG" \
  -v /path/to/public_ip_updater/current_ip.txt:/app/current_ip.txt:rw \
  -v /path/to/yaml/you/need/to/update.yml:/app/configuration.yml:rw \
  --restart unless-stopped \
  nemanja_slijepcevic/public_ip_updater
Docker Compose

For easier management of Docker containers and environment configuration, you can use Docker Compose.

  1. Create a docker-compose.yml file in the root of your project:
version: '3'

services:
  public_ip_updater:
    image: nemanja_slijepcevic/public_ip_updater
    container_name: public_ip_updater
    environment:
      NODE_IP_DOMAIN: "https://your-api-domain.com/api/ip"
      FILE_DATA_PATH: "file.path.to.the.variable"
      API_IP_TOKEN: "api_token"
      TZ: "Europe/Belgrade"
      LOG_LEVEL: "DEBUG"
    volumes:
      - /path/to/public_ip_updater/current_ip.txt:/app/current_ip.txt:rw
      - /path/to/yaml/you/need/to/update.yml:/app/configuration.yml:rw
    restart: unless-stopped
  1. Build and run with Docker Compose:
docker-compose up --build -d
  1. Stopping the app:
docker-compose down

Docker Pull Command

docker pull nemanjaslijepcevic/public_ip_updater