BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr
Console ip whitelist configuration
lotke0b7317ef6d6
diff --git a/core/internal/controller/middleware/ip_whitelist.go b/core/internal/controller/middleware/ip_whitelist.goindex e3c37b9d..496ebfe5 100644--- a/core/internal/controller/middleware/ip_whitelist.go+++ b/core/internal/controller/middleware/ip_whitelist.go@@ -5,6 +5,7 @@ import ("context""github.com/gogf/gf/v2/frame/g""github.com/gogf/gf/v2/net/ghttp"+ "github.com/gogf/gf/v2/os/gfile""strings")@@ -60,11 +61,28 @@ func getAllowedIPs() []string {return ips}+func appendIPWhitelistEnvIfNotExists() {+ envFile := public.AbsPath("../.env")+ const comment = "# Console ip whitelist Disabled:false Enabled:true"+ const config = "IP_WHITELIST_ENABLE=false"++ content := gfile.GetContents(envFile)++ if !strings.Contains(content, "IP_WHITELIST_ENABLE") {+ appendStr := "\n" + comment + "\n" + config + "\n"+ if err := gfile.PutContentsAppend(envFile, appendStr); err != nil {+ g.Log().Errorf(context.Background(), "[IP Whitelist] Failed to append to .env file: %v", err)+ }+ }+}+// Whether to enable the IP whitelistfunc isIPWhitelistEnabled(envMap map[string]string) bool {- isIPWhite := envMap["IP_WHITELIST_ENABLE"]- if isIPWhite == "" {+ isIPWhite, exists := envMap["IP_WHITELIST_ENABLE"]++ if !exists {+ appendIPWhitelistEnvIfNotExists()return false}diff --git a/env_init b/env_initindex 24d9d6fd..31de0ab5 100644--- a/env_init+++ b/env_init@@ -43,4 +43,7 @@ TZ=Etc/UTCIPV4_NETWORK=172.66.1# Enable fail2ban Access restrictions, specify that the IP exceeds the access limit-FAIL2BAN_INIT=y\ No newline at end of file+FAIL2BAN_INIT=y++# Console ip whitelist Disabled:false Enabled:true+IP_WHITELIST_ENABLE=false\ No newline at end of file