version: "2.4"


services:
  # key value store
  redis:
    env_file: .env
    container_name: redis
    image: redis:alpine
    restart: unless-stopped
    command: redis-server --requirepass ${TWVPN_REDIS_PASSWORD:?err}
    #networks:
    #  - redis-network
    ports:
      - "127.0.0.1:16379:6379"
    volumes:
      - ./volumes/redis/config/redis.conf:/usr/local/etc/redis/redis.conf
      - ./volumes/redis/config:/usr/local/etc/redis
      - ./volumes/redis/data:/data

  # monitor of teeworlds servers
  econ-vpn-detection:
    env_file: .env
    container_name: econ-vpn-detection
    image: ghcr.io/jxsl13/teeworldseconvpndetection:master
    #build: . # uncomment if you want to build the image yourself
    restart: unless-stopped
    volumes:
    - ./volumes/vpn-detection/data/nutsdata:/data/nutsdata
    - ./volumes/vpn-detection/blacklists/blacklist.txt:/data/blacklists/blacklist.txt
    - ./volumes/vpn-detection/whitelists/whitelist.txt:/data/whitelists/whitelist.txt
    network_mode: host
    #extra_hosts:
    #- "host.docker.internal:host-gateway"
    depends_on:
      - redis
    environment:
      # preconfigured
      TWVPN_REDIS_ADDRESS: localhost:16379
      TWVPN_NUTSDB_DIR: /data/nutsdata
      TWVPN_IP_WHITELIST: /data/whitelists/whitelist.txt
      TWVPN_IP_BLACKLIST: /data/blacklists/blacklist.txt

      # mandatory
      TWVPN_ECON_ADDRESSES: ${TWVPN_ECON_ADDRESSES:?err}
      TWVPN_ECON_PASSWORDS: ${TWVPN_ECON_PASSWORDS:?err}
      TWVPN_REDIS_PASSWORD: ${TWVPN_REDIS_PASSWORD:?err}
      # optional
      TWVPN_IPHUB_TOKEN: ${TWVPN_IPHUB_TOKEN:-}
      TWVPN_PROXYCHECK_TOKEN: ${TWVPN_PROXYCHECK_TOKEN:-}
      TWVPN_VPNAPI_TOKEN: ${TWVPN_VPNAPI_TOKEN:-}
      TWVPN_OFFLINE: ${TWVPN_OFFLINE:?false}
      TWVPN_PERMABAN_THRESHOLD: ${TWVPN_PERMABAN_THRESHOLD:-0.6}

      TWVPN_REDIS_DB_VPN: ${TWVPN_REDIS_DB_VPN:-0}
      TWVPN_VPN_BAN_DURATION: ${TWVPN_VPN_BAN_DURATION:-24h}
      TWVPN_VPN_BAN_REASON: ${TWVPN_VPN_BAN_REASON:-VPN}

networks:
  redis-network:
    external: false