mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-11 05:00:25 +08:00
优化代码
This commit is contained in:
1
internal/firewalls/.gitignore
vendored
Normal file
1
internal/firewalls/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
firewall_nftables_test.go
|
||||
@@ -1,10 +1,13 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build !plus
|
||||
// +build !plus
|
||||
|
||||
package firewalls
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/events"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
var currentFirewall FirewallInterface
|
||||
@@ -13,9 +16,7 @@ var currentFirewall FirewallInterface
|
||||
func init() {
|
||||
events.On(events.EventLoaded, func() {
|
||||
var firewall = Firewall()
|
||||
if firewall.Name() == "mock" {
|
||||
remotelogs.Warn("FIREWALL", "'firewalld' on this system should be enabled to block attackers more effectively")
|
||||
} else {
|
||||
if firewall.Name() != "mock" {
|
||||
remotelogs.Println("FIREWALL", "found local firewall '"+firewall.Name()+"'")
|
||||
}
|
||||
})
|
||||
@@ -28,7 +29,7 @@ func Firewall() FirewallInterface {
|
||||
}
|
||||
|
||||
// firewalld
|
||||
{
|
||||
if runtime.GOOS == "linux" {
|
||||
var firewalld = NewFirewalld()
|
||||
if firewalld.IsReady() {
|
||||
currentFirewall = firewalld
|
||||
|
||||
@@ -27,6 +27,8 @@ func NewFirewalld() *Firewalld {
|
||||
err := cmd.Run()
|
||||
if err == nil {
|
||||
firewalld.exe = path
|
||||
// TODO check firewalld status with 'firewall-cmd --state' (running or not running),
|
||||
// but we should recover the state when firewalld state changes, maybe check it every minutes
|
||||
firewalld.isReady = true
|
||||
firewalld.init()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user