Initial commit

This commit is contained in:
MDS
2025-09-28 08:44:46 +02:00
commit d7e150294d
3 changed files with 32 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/.clj-kondo/
/.lsp/

2
bb.edn Normal file
View File

@@ -0,0 +1,2 @@
{:path ["src"]
:deps {org.babashka/http-client {:mvn/version "0.4.22"}}}

28
src/bunny2realip/core.clj Normal file
View File

@@ -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 $))))