Initial commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/.clj-kondo/
|
||||||
|
/.lsp/
|
||||||
2
bb.edn
Normal file
2
bb.edn
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
{:path ["src"]
|
||||||
|
:deps {org.babashka/http-client {:mvn/version "0.4.22"}}}
|
||||||
28
src/bunny2realip/core.clj
Normal file
28
src/bunny2realip/core.clj
Normal 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 $))))
|
||||||
Reference in New Issue
Block a user