一、修改获取登录IP
的功能
修改/www/server/panel/class/public.py
中GetClientIp()
函数:
1 2 3 4 5 6 7 8 9 10 11 12 13
| def GetClientIp(): from flask import request headers = ["X-Real-IP", "X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP", "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR"] ipaddr = None for header in headers: ipaddr = request.headers.get(header, None) if ipaddr is not None: break if ipaddr is None: ipaddr = request.remote_addr.replace('::ffff:', '') if not check_ip(ipaddr): ipaddr = '未知IP地址' return ipaddr
|
修改之后,使用Nginx
反向代理宝塔面板链接时,可以正确获取到登录IP
。
这里是反向代理的配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| location ^~ / { proxy_pass http://127.0.0.1:12321; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-Port $remote_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header REMOTE-HOST $remote_addr; proxy_ssl_server_name on; proxy_connect_timeout 60s; proxy_send_timeout 600s; proxy_read_timeout 600s; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; }
|
二、修改DNS和SSL中Clouflare的身份验证方式
1、修改文件/www/server/panel/class/panelDnsapi.py
中CloudFlareDns
类的私有方法_get_auth_headers
为:
1 2 3 4 5
| def _get_auth_headers(self) -> dict: if (self.CLOUDFLARE_EMAIL is None or not self.CLOUDFLARE_EMAIL) and isinstance(self.CLOUDFLARE_API_KEY, str): return {"Authorization": "Bearer " + self.CLOUDFLARE_API_KEY} else: return {"X-Auth-Email": self.CLOUDFLARE_EMAIL, "X-Auth-Key": self.CLOUDFLARE_API_KEY}
|
修改后,在配置Cloudflare
的DNS
接口时,E-Mail
输入空格
,API Key
输入API Token
,这样可以避免使用 Global API Key
。
2、修改文件/www/server/panel/class/sslModel/cloudflareModel.py
中main
类的私有方法__init_data
为:
1 2 3 4 5 6 7 8 9 10
| def __init_data(self, data): self.CLOUDFLARE_EMAIL = data['E-Mail'].strip() self.CLOUDFLARE_API_KEY = data['API Key'] self.CLOUDFLARE_API_BASE_URL = 'https://api.cloudflare.com/client/v4/' self.HTTP_TIMEOUT = 65 if (self.CLOUDFLARE_EMAIL is None or not self.CLOUDFLARE_EMAIL) and isinstance(self.CLOUDFLARE_API_KEY, str): self.headers = {"Authorization": f"Bearer {self.CLOUDFLARE_API_KEY}"} else: self.headers = {"X-Auth-Email": self.CLOUDFLARE_EMAIL, "X-Auth-Key": self.CLOUDFLARE_API_KEY}
|
修改后,在用Cloudflare
的DNS
申请证书时,可以使用API Token
的方式申请。
三、修改生成下载SSL证书时的链接
在使用反向代理宝塔面板时,下载证书会带上端口,这会导致下载不了证书,为了正常下载和更好地隐藏端口,需要修改文件/www/server/panel/class/sslModel/certModel.py
中的download_cert
函数和batch_download_cert
函数:
1 2 3 4
| zfile = '{}://{}:{}/download?filename={}'.format(ssl, host, port, zfile)
zfile = '{}://{}/download?filename={}'.format(ssl, host, zfile)
|
或者像下面这样改:
1 2 3 4 5 6 7 8 9 10 11
|
ssl = "https" if public.is_ssl() else "http" host_port = request.host.split(":") host = host_port[0] if len(host_port) > 1: port = host_port[1] else: port = "443" if public.is_ssl() else "80"
|