Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加命令-修改面板ip #684

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions panel_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ def mwcli(mw_input=0):
'(2) 停止面板服务',
'(3) 启动面板服务',
'(4) 重载面板服务',
'(5) 修改面板端口',
'(6) 关闭安全入口',
'(5) 修改面板IP',
'(6) 修改面板端口',
'(7) 关闭安全入口',
'(10) 查看面板默认信息',
'(11) 修改面板密码',
'(12) 修改面板用户名',
Expand Down Expand Up @@ -99,7 +100,7 @@ def mwcli(mw_input=0):
mw_input = 0

nums = [
1, 2, 3, 4, 5, 6,
1, 2, 3, 4, 5, 6, 7,
10, 11, 12, 13, 14, 15,
20, 21, 22, 23, 24, 25, 26, 27, 28,
100, 101,
Expand All @@ -119,6 +120,16 @@ def mwcli(mw_input=0):
elif mw_input == 4:
os.system(INIT_CMD + " reload")
elif mw_input == 5:
in_ip = mw_input_cmd("请输入设置的面板IP:")
in_ip = in_ip.strip()
ip_text = panel_dir + '/data/iplist.txt'
if not mw.isVaildIp(in_ip):
mw.echoInfo("【"+in_ip+"】: IP不合法")
return
mw.writeFile(ip_text, in_ip)
thisdb.setOption('server_ip', in_ip)
mw.echoInfo("设置面板IP: " + in_ip)
elif mw_input == 6:
in_port = mw_input_cmd("请输入新的面板端口:")
in_port_int = int(in_port.strip())
if in_port_int < 65536 and in_port_int > 0:
Expand All @@ -130,7 +141,7 @@ def mwcli(mw_input=0):
else:
mw.echoInfo("端口范围在0-65536之间")
return
elif mw_input == 6:
elif mw_input == 7:
thisdb.setOption('admin_path', '')
mw.echoInfo("关闭安全入口成功!")
elif mw_input == 10:
Expand Down
32 changes: 32 additions & 0 deletions web/core/mw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,38 @@ def isIpAddr(ip):
else:
return False

def isVaildIpV4(ip):
import ipaddress
try:
ipaddress.IPv4Address(ip)
return True
except ipaddress.AddressValueError:
return False

def isVaildIpV6(ip):
import ipaddress
try:
ipaddress.IPv6Address(ip)
return True
except ipaddress.AddressValueError:
return False

def isVaildIp(ip):
import ipaddress
try:
ipaddress.IPv4Address(ip)
return True
except ipaddress.AddressValueError:
pass

try:
ipaddress.IPv6Address(ip)
return True
except ipaddress.AddressValueError:
pass
return False


def getWebStatus():
pid = getServerDir() + '/openresty/nginx/logs/nginx.pid'
if os.path.exists(pid):
Expand Down
Loading