diff --git a/agent/app/dto/docker.go b/agent/app/dto/docker.go index bfabacc41..6de1926db 100644 --- a/agent/app/dto/docker.go +++ b/agent/app/dto/docker.go @@ -6,7 +6,8 @@ type DaemonJsonUpdateByFile struct { type DaemonJsonConf struct { IsSwarm bool `json:"isSwarm"` - Status string `json:"status"` + IsExist bool `json:"isExist"` + IsActive bool `json:"isActive"` Version string `json:"version"` Mirrors []string `json:"registryMirrors"` Registries []string `json:"insecureRegistries"` diff --git a/agent/app/dto/firewall.go b/agent/app/dto/firewall.go index c3d3646e1..ab1d446ee 100644 --- a/agent/app/dto/firewall.go +++ b/agent/app/dto/firewall.go @@ -2,7 +2,8 @@ package dto type FirewallBaseInfo struct { Name string `json:"name"` - Status string `json:"status"` + IsExist bool `json:"isExist"` + IsActive bool `json:"isActive"` Version string `json:"version"` PingStatus string `json:"pingStatus"` } diff --git a/agent/app/dto/ssh.go b/agent/app/dto/ssh.go index c07a3f4e9..c020ad567 100644 --- a/agent/app/dto/ssh.go +++ b/agent/app/dto/ssh.go @@ -10,7 +10,8 @@ type SSHUpdate struct { type SSHInfo struct { AutoStart bool `json:"autoStart"` - Status string `json:"status"` + IsExist bool `json:"isExist"` + IsActive bool `json:"isActive"` Message string `json:"message"` Port string `json:"port"` ListenAddress string `json:"listenAddress"` diff --git a/agent/app/service/docker.go b/agent/app/service/docker.go index beb6e0b84..d995f947b 100644 --- a/agent/app/service/docker.go +++ b/agent/app/service/docker.go @@ -69,15 +69,19 @@ func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf { ctx := context.Background() var data dto.DaemonJsonConf data.IPTables = true - data.Status = constant.StatusRunning data.Version = "-" + if cmd.Which("docker") { + data.IsExist = false + return &data + } + data.IsExist = true client, err := docker.NewDockerClient() if err != nil { - data.Status = constant.Stopped + data.IsActive = false } else { defer client.Close() if _, err := client.Ping(ctx); err != nil { - data.Status = constant.Stopped + data.IsActive = false } itemVersion, err := client.ServerVersion(ctx) if err == nil { diff --git a/agent/app/service/fail2ban.go b/agent/app/service/fail2ban.go index b0f2af483..4876f543c 100644 --- a/agent/app/service/fail2ban.go +++ b/agent/app/service/fail2ban.go @@ -116,8 +116,8 @@ func (u *Fail2BanService) UpdateConf(req dto.Fail2BanUpdate) error { if client.Name() != itemName { return buserr.WithName("ErrBanAction", itemName) } - status, _ := client.Status() - if status != "running" { + isActive, _ := client.Status() + if !isActive { return buserr.WithName("ErrBanAction", itemName) } } diff --git a/agent/app/service/firewall.go b/agent/app/service/firewall.go index 744adc4d3..820507d75 100644 --- a/agent/app/service/firewall.go +++ b/agent/app/service/firewall.go @@ -43,13 +43,14 @@ func NewIFirewallService() IFirewallService { func (u *FirewallService) LoadBaseInfo() (dto.FirewallBaseInfo, error) { var baseInfo dto.FirewallBaseInfo - baseInfo.Status = "not running" baseInfo.Version = "-" baseInfo.Name = "-" client, err := firewall.NewFirewallClient() if err != nil { + baseInfo.IsExist = false return baseInfo, err } + baseInfo.IsExist = true baseInfo.Name = client.Name() var wg sync.WaitGroup @@ -60,7 +61,7 @@ func (u *FirewallService) LoadBaseInfo() (dto.FirewallBaseInfo, error) { }() go func() { defer wg.Done() - baseInfo.Status, _ = client.Status() + baseInfo.IsActive, _ = client.Status() }() go func() { defer wg.Done() diff --git a/agent/app/service/ssh.go b/agent/app/service/ssh.go index 02e3bf297..8e62b3a46 100644 --- a/agent/app/service/ssh.go +++ b/agent/app/service/ssh.go @@ -45,7 +45,8 @@ func NewISSHService() ISSHService { func (u *SSHService) GetSSHInfo() (*dto.SSHInfo, error) { data := dto.SSHInfo{ AutoStart: true, - Status: constant.StatusEnable, + IsExist: true, + IsActive: true, Message: "", Port: "22", ListenAddress: "", @@ -56,17 +57,13 @@ func (u *SSHService) GetSSHInfo() (*dto.SSHInfo, error) { } serviceName, err := loadServiceName() if err != nil { - data.Status = constant.StatusDisable + data.IsExist = false data.Message = err.Error() } else { active, err := systemctl.IsActive(serviceName) - if !active { - data.Status = constant.StatusDisable - if err != nil { - data.Message = err.Error() - } - } else { - data.Status = constant.StatusEnable + data.IsActive = active + if !active && err != nil { + data.Message = err.Error() } } @@ -84,7 +81,7 @@ func (u *SSHService) GetSSHInfo() (*dto.SSHInfo, error) { sshConf, err := os.ReadFile(sshPath) if err != nil { data.Message = err.Error() - data.Status = constant.StatusDisable + data.IsActive = false } lines := strings.Split(string(sshConf), "\n") for _, line := range lines { diff --git a/agent/utils/firewall/client.go b/agent/utils/firewall/client.go index 80f421962..c106e5654 100644 --- a/agent/utils/firewall/client.go +++ b/agent/utils/firewall/client.go @@ -13,7 +13,7 @@ type FirewallClient interface { Stop() error Restart() error Reload() error - Status() (string, error) // running not running + Status() (bool, error) // running not running Version() (string, error) ListPort() ([]client.FireInfo, error) diff --git a/agent/utils/firewall/client/firewalld.go b/agent/utils/firewall/client/firewalld.go index 84db69373..88c813b5c 100644 --- a/agent/utils/firewall/client/firewalld.go +++ b/agent/utils/firewall/client/firewalld.go @@ -24,12 +24,9 @@ func (f *Firewall) Name() string { return "firewalld" } -func (f *Firewall) Status() (string, error) { +func (f *Firewall) Status() (bool, error) { stdout, _ := cmd.Exec("firewall-cmd --state") - if stdout == "running\n" { - return "running", nil - } - return "not running", nil + return stdout == "running\n", nil } func (f *Firewall) Version() (string, error) { diff --git a/agent/utils/firewall/client/iptables.go b/agent/utils/firewall/client/iptables.go index 5ea38a938..4aa1e1e31 100644 --- a/agent/utils/firewall/client/iptables.go +++ b/agent/utils/firewall/client/iptables.go @@ -27,8 +27,8 @@ func NewIptables() (*Iptables, error) { return iptables, nil } -func (iptables *Iptables) runf(rule string, a ...any) error { - stdout, err := cmd.Execf("%s iptables -t nat %s", iptables.CmdStr, fmt.Sprintf(rule, a...)) +func (iptables *Iptables) run(rule string) error { + stdout, err := cmd.Execf("%s iptables -t nat %s", iptables.CmdStr, rule) if err != nil { return fmt.Errorf("%s, %s", err, stdout) } @@ -39,6 +39,10 @@ func (iptables *Iptables) runf(rule string, a ...any) error { return nil } +func (iptables *Iptables) runf(rule string, a ...any) error { + return iptables.run(fmt.Sprintf(rule, a...)) +} + func (iptables *Iptables) Check() error { stdout, err := cmd.Exec("cat /proc/sys/net/ipv4/ip_forward") if err != nil { @@ -100,7 +104,7 @@ func (iptables *Iptables) NatAdd(protocol, src, destIp, destPort string, save bo if destIp != "" && destIp != "127.0.0.1" && destIp != "localhost" { rule = fmt.Sprintf("-A %s -p %s --dport %s -j DNAT --to-destination %s:%s", NatChain, protocol, src, destIp, destPort) } - if err := iptables.runf(rule); err != nil { + if err := iptables.run(rule); err != nil { return err } diff --git a/agent/utils/firewall/client/ufw.go b/agent/utils/firewall/client/ufw.go index e90c4b81a..ca09516be 100644 --- a/agent/utils/firewall/client/ufw.go +++ b/agent/utils/firewall/client/ufw.go @@ -28,16 +28,16 @@ func (f *Ufw) Name() string { return "ufw" } -func (f *Ufw) Status() (string, error) { +func (f *Ufw) Status() (bool, error) { stdout, _ := cmd.Execf("%s status | grep Status", f.CmdStr) if stdout == "Status: active\n" { - return "running", nil + return true, nil } stdout1, _ := cmd.Execf("%s status | grep 状态", f.CmdStr) if stdout1 == "状态: 激活\n" { - return "running", nil + return true, nil } - return "not running", nil + return false, nil } func (f *Ufw) Version() (string, error) { diff --git a/frontend/src/views/container/compose/index.vue b/frontend/src/views/container/compose/index.vue index 18f5dc823..55adbbf2f 100644 --- a/frontend/src/views/container/compose/index.vue +++ b/frontend/src/views/container/compose/index.vue @@ -3,13 +3,10 @@
- - {{ $t('container.serviceUnavailable') }} - 【 {{ $t('container.setting') }} 】 - {{ $t('container.startIn') }} - - + + + diff --git a/frontend/src/views/container/container/index.vue b/frontend/src/views/container/container/index.vue index 47084e242..6c3a7d1f7 100644 --- a/frontend/src/views/container/container/index.vue +++ b/frontend/src/views/container/container/index.vue @@ -1,12 +1,8 @@