2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 11:27:17 +08:00

feat: 优化防火墙启停流程

This commit is contained in:
耗子
2024-06-18 10:09:53 +08:00
parent 0a3d3828c8
commit eb2c6cab81
2 changed files with 20 additions and 0 deletions

View File

@@ -39,14 +39,32 @@ func (r *SafeController) SetFirewallStatus(ctx http.Context) http.Response {
if ctx.Request().InputBool("status") {
if tools.IsRHEL() {
err = tools.ServiceStart("firewalld")
if err == nil {
err = tools.ServiceEnable("firewalld")
}
} else {
_, err = tools.Exec("echo y | ufw enable")
if err == nil {
err = tools.ServiceStart("ufw")
}
if err == nil {
err = tools.ServiceEnable("ufw")
}
}
} else {
if tools.IsRHEL() {
err = tools.ServiceStop("firewalld")
if err == nil {
err = tools.ServiceDisable("firewalld")
}
} else {
_, err = tools.Exec("ufw disable")
if err == nil {
err = tools.ServiceStop("ufw")
}
if err == nil {
err = tools.ServiceDisable("ufw")
}
}
}

View File

@@ -289,6 +289,8 @@ Init_Panel() {
elif [ "${OS}" == "debian" ]; then
apt-get install ufw -y
echo y | ufw enable
systemctl enable ufw
systemctl start ufw
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp