Files
wecom_it_smart_desk/deploy-server/fix_nginx.py
T

32 lines
768 B
Python
Raw Normal View History

import re
# 读取nginx.conf
with open('/etc/nginx/nginx.conf', 'r') as f:
content = f.read()
# 找到/itadmin/ location块并替换
old_block = '''location /itadmin/ {
# IP 白名单:仅允许内网网段
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
allow 10.212.0.0/16; # VPN 网段
deny all;'''
new_block = '''location /itadmin/ {
# IP 白名单:仅允许内网网段 + 临时公网IP
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
allow 10.212.0.0/16; # VPN 网段
allow 43.174.152.34; # 临时添加 (2026-07-06)
deny all;'''
content = content.replace(old_block, new_block)
# 写回
with open('/etc/nginx/nginx.conf', 'w') as f:
f.write(content)
print('Done')