From d7e150294dff215e7db76a4dff1282cdc2b71187 Mon Sep 17 00:00:00 2001 From: Marco Dalla Stella Date: Sun, 28 Sep 2025 08:44:46 +0200 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ bb.edn | 2 ++ src/bunny2realip/core.clj | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 .gitignore create mode 100644 bb.edn create mode 100644 src/bunny2realip/core.clj diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..19934ab --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.clj-kondo/ +/.lsp/ diff --git a/bb.edn b/bb.edn new file mode 100644 index 0000000..4928e23 --- /dev/null +++ b/bb.edn @@ -0,0 +1,2 @@ +{:path ["src"] + :deps {org.babashka/http-client {:mvn/version "0.4.22"}}} diff --git a/src/bunny2realip/core.clj b/src/bunny2realip/core.clj new file mode 100644 index 0000000..d69155d --- /dev/null +++ b/src/bunny2realip/core.clj @@ -0,0 +1,28 @@ +(ns bunny2realip.core + (:require [babashka.http-client :as http] + [cheshire.core :as json] + [clojure.string :as s] + [clojure.string :as str])) + +(defonce ip-lists ["https://bunnycdn.com/api/system/edgeserverlist/" + "https://bunnycdn.com/api/system/cdnserverlist/"]) +(defonce realip-dest "/etc/nginx/conf.d/bunny.conf") + +(defn get-list + [url] + (-> url + http/get + :body + json/parse-string)) + +(defn format-ips + [ip] + (str "set_real_ip_from " ip ";")) + +(defn -main [& args] + (let [ips (set (mapcat get-list ip-lists)) + realips (map format-ips (sort ips))] + (as-> realips $ + (concat $ ["real_ip_header X-Real-IP;" "real_ip_recursive on;"]) + (str/join "\n" $) + (spit realip-dest $))))