优化代码

This commit is contained in:
GoEdgeLab
2022-04-12 21:43:19 +08:00
parent 8a0ef47a64
commit d286cb25bc
3 changed files with 8 additions and 4 deletions

1
internal/firewalls/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
firewall_nftables_test.go

View File

@@ -1,10 +1,13 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build !plus
// +build !plus
package firewalls package firewalls
import ( import (
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"runtime"
) )
var currentFirewall FirewallInterface var currentFirewall FirewallInterface
@@ -13,9 +16,7 @@ var currentFirewall FirewallInterface
func init() { func init() {
events.On(events.EventLoaded, func() { events.On(events.EventLoaded, func() {
var firewall = Firewall() var firewall = Firewall()
if firewall.Name() == "mock" { if firewall.Name() != "mock" {
remotelogs.Warn("FIREWALL", "'firewalld' on this system should be enabled to block attackers more effectively")
} else {
remotelogs.Println("FIREWALL", "found local firewall '"+firewall.Name()+"'") remotelogs.Println("FIREWALL", "found local firewall '"+firewall.Name()+"'")
} }
}) })
@@ -28,7 +29,7 @@ func Firewall() FirewallInterface {
} }
// firewalld // firewalld
{ if runtime.GOOS == "linux" {
var firewalld = NewFirewalld() var firewalld = NewFirewalld()
if firewalld.IsReady() { if firewalld.IsReady() {
currentFirewall = firewalld currentFirewall = firewalld

View File

@@ -27,6 +27,8 @@ func NewFirewalld() *Firewalld {
err := cmd.Run() err := cmd.Run()
if err == nil { if err == nil {
firewalld.exe = path 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.isReady = true
firewalld.init() firewalld.init()
} }