Skip to content

Commit 00885c5

Browse files
authored
feat: Unify the encapsulation of the component for 'service not exist' (#8348)
1 parent a5de96e commit 00885c5

28 files changed

Lines changed: 198 additions & 200 deletions

File tree

agent/app/api/v2/docker.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// @Tags Container Docker
1313
// @Summary Load docker status
1414
// @Produce json
15-
// @Success 200 {string} status
15+
// @Success 200 {string} dto.DockerStatus
1616
// @Security ApiKeyAuth
1717
// @Security Timestamp
1818
// @Router /containers/docker/status [get]
@@ -49,7 +49,11 @@ func (b *BaseApi) LoadDaemonJsonFile(c *gin.Context) {
4949
// @Security Timestamp
5050
// @Router /containers/daemonjson [get]
5151
func (b *BaseApi) LoadDaemonJson(c *gin.Context) {
52-
conf := dockerService.LoadDockerConf()
52+
conf, err := dockerService.LoadDockerConf()
53+
if err != nil {
54+
helper.InternalServer(c, err)
55+
return
56+
}
5357
helper.SuccessWithData(c, conf)
5458
}
5559

agent/app/dto/docker.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ type DaemonJsonUpdateByFile struct {
44
File string `json:"file"`
55
}
66

7+
type DockerStatus struct {
8+
IsActive bool `json:"isActive"`
9+
IsExist bool `json:"isExist"`
10+
}
11+
712
type DaemonJsonConf struct {
813
IsSwarm bool `json:"isSwarm"`
9-
IsExist bool `json:"isExist"`
10-
IsActive bool `json:"isActive"`
1114
Version string `json:"version"`
1215
Mirrors []string `json:"registryMirrors"`
1316
Registries []string `json:"insecureRegistries"`

agent/app/service/docker.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ type IDockerService interface {
2525
UpdateLogOption(req dto.LogOption) error
2626
UpdateIpv6Option(req dto.Ipv6Option) error
2727
UpdateConfByFile(info dto.DaemonJsonUpdateByFile) error
28-
LoadDockerStatus() string
29-
LoadDockerConf() *dto.DaemonJsonConf
28+
LoadDockerStatus() *dto.DockerStatus
29+
LoadDockerConf() (*dto.DaemonJsonConf, error)
3030
OperateDocker(req dto.DockerOperation) error
3131
}
3232

@@ -52,66 +52,66 @@ type logOption struct {
5252
LogMaxFile string `json:"max-file"`
5353
}
5454

55-
func (u *DockerService) LoadDockerStatus() string {
55+
func (u *DockerService) LoadDockerStatus() *dto.DockerStatus {
56+
ctx := context.Background()
57+
var data dto.DockerStatus
58+
if !cmd.Which("docker") {
59+
data.IsExist = false
60+
return &data
61+
}
62+
data.IsExist = true
63+
data.IsActive, _ = systemctl.IsActive("docker")
5664
client, err := docker.NewDockerClient()
5765
if err != nil {
58-
return constant.StatusStopped
66+
global.LOG.Errorf("load docker client failed, err: %v", err)
67+
data.IsActive = false
68+
return &data
5969
}
6070
defer client.Close()
61-
if _, err := client.Ping(context.Background()); err != nil {
62-
return constant.StatusStopped
71+
if _, err := client.Ping(ctx); err != nil {
72+
global.LOG.Errorf("ping docker client failed, err: %v", err)
73+
data.IsActive = false
6374
}
6475

65-
return constant.StatusRunning
76+
return &data
6677
}
6778

68-
func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf {
79+
func (u *DockerService) LoadDockerConf() (*dto.DaemonJsonConf, error) {
6980
ctx := context.Background()
7081
var data dto.DaemonJsonConf
7182
data.IPTables = true
7283
data.Version = "-"
73-
if !cmd.Which("docker") {
74-
data.IsExist = false
75-
return &data
76-
}
77-
data.IsExist = true
78-
data.IsActive = true
7984
client, err := docker.NewDockerClient()
8085
if err != nil {
81-
data.IsActive = false
82-
} else {
83-
defer client.Close()
84-
if _, err := client.Ping(ctx); err != nil {
85-
data.IsActive = false
86-
}
87-
itemVersion, err := client.ServerVersion(ctx)
88-
if err == nil {
89-
data.Version = itemVersion.Version
90-
}
86+
return &data, err
87+
}
88+
itemVersion, err := client.ServerVersion(ctx)
89+
if err == nil {
90+
data.Version = itemVersion.Version
9191
}
9292
data.IsSwarm = false
9393
stdout2, _ := cmd.Exec("docker info | grep Swarm")
9494
if string(stdout2) == " Swarm: active\n" {
9595
data.IsSwarm = true
9696
}
9797
if _, err := os.Stat(constant.DaemonJsonPath); err != nil {
98-
return &data
98+
return &data, nil
9999
}
100100
file, err := os.ReadFile(constant.DaemonJsonPath)
101101
if err != nil {
102-
return &data
102+
return &data, nil
103103
}
104104
var conf daemonJsonItem
105105
daemonMap := make(map[string]interface{})
106106
if err := json.Unmarshal(file, &daemonMap); err != nil {
107-
return &data
107+
return &data, nil
108108
}
109109
arr, err := json.Marshal(daemonMap)
110110
if err != nil {
111-
return &data
111+
return &data, err
112112
}
113113
if err := json.Unmarshal(arr, &conf); err != nil {
114-
return &data
114+
return &data, err
115115
}
116116
if _, ok := daemonMap["iptables"]; !ok {
117117
conf.IPTables = true
@@ -133,7 +133,7 @@ func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf {
133133
data.Registries = conf.Registries
134134
data.IPTables = conf.IPTables
135135
data.LiveRestore = conf.LiveRestore
136-
return &data
136+
return &data, nil
137137
}
138138

139139
func (u *DockerService) UpdateConf(req dto.SettingUpdate) error {

frontend/src/api/interface/container.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ export namespace Container {
335335
export interface DaemonJsonUpdateByFile {
336336
file: string;
337337
}
338+
export interface DockerStatus {
339+
isActive: boolean;
340+
isExist: boolean;
341+
}
338342
export interface DaemonJsonConf {
339343
isSwarm: boolean;
340344
isExist: boolean;

frontend/src/api/modules/container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export const loadDaemonJsonFile = () => {
187187
return http.get<string>(`/containers/daemonjson/file`);
188188
};
189189
export const loadDockerStatus = () => {
190-
return http.get<string>(`/containers/docker/status`);
190+
return http.get<Container.DockerStatus>(`/containers/docker/status`);
191191
};
192192
export const updateDaemonJson = (key: string, value: string) => {
193193
return http.post(`/containers/daemonjson/update`, { key: key, value: value }, TimeoutEnum.T_60S);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<template>
2+
<div>
3+
<LayoutContent :divider="true">
4+
<template #main>
5+
<div class="app-warn">
6+
<div class="flex flex-col gap-2 items-center justify-center w-full sm:flex-row">
7+
<span>{{ $t('cronjob.library.noSuchApp', [prop.name]) }}</span>
8+
<span @click="toDoc" class="flex items-center justify-center gap-0.5">
9+
<el-icon><Position /></el-icon>
10+
{{ $t('firewall.quickJump') }}
11+
</span>
12+
</div>
13+
<div>
14+
<img src="@/assets/images/no_app.svg" />
15+
</div>
16+
</div>
17+
</template>
18+
</LayoutContent>
19+
</div>
20+
</template>
21+
22+
<script lang="ts" setup>
23+
import router from '@/routers';
24+
25+
const prop = defineProps({
26+
name: String,
27+
});
28+
29+
const toDoc = () => {
30+
router.push({ name: 'Library' });
31+
};
32+
</script>

frontend/src/lang/modules/en.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ const message = {
10461046
groupHelper:
10471047
'Set different groups based on script characteristics, which allows for faster script filtering operations.',
10481048
handleHelper: 'Execute script {1} on {0}, continue?',
1049+
noSuchApp: 'The {0} service was not detected. Please install it quickly using the script library first!',
10491050
},
10501051
},
10511052
monitor: {
@@ -1185,7 +1186,6 @@ const message = {
11851186
fail2ban: {
11861187
sshPort: 'Listen to SSH Port',
11871188
sshPortHelper: 'Current Fail2ban listens to the SSH connection port of the host',
1188-
noFail2ban: 'Fail2ban service not detected, please refer to the official documentation for installation!',
11891189
unActive: 'The Fail2ban service is not enabled at present, please enable it first!',
11901190
operation: 'Perform [{0}] operation on Fail2ban service, continue?',
11911191
fail2banChange: 'Fail2ban Configuration Modification',
@@ -1208,7 +1208,6 @@ const message = {
12081208
ftp: {
12091209
ftp: 'FTP Account',
12101210
notStart: 'FTP service is currently not running, please start it first!',
1211-
noFtp: 'FTP (pure-ftpd) service not detected, please refer to the official documentation for installation!',
12121211
operation: 'Perform [{0}] operation on FTP service, continue?',
12131212
noPasswdMsg: 'Can not get the current FTP account password, please set the password and try again! ',
12141213
enableHelper:
@@ -1230,7 +1229,6 @@ const message = {
12301229
hideFresh: 'Hide Virus Database Service',
12311230
clamHelper:
12321231
'The minimum recommended configuration for ClamAV is: 3 GiB of RAM or more, single-core CPU with 2.0 GHz or higher, and at least 5 GiB of available hard disk space.',
1233-
noClam: 'ClamAV service not detected, please refer to the official documentation for installation!',
12341232
notStart: 'ClamAV service is currently not running, please start it first!',
12351233
removeRecord: 'Delete Report Files',
12361234
removeResultHelper: 'Delete report files generated during task execution to free up storage space.',
@@ -2538,8 +2536,6 @@ const message = {
25382536
firewall: {
25392537
create: 'Create Rule',
25402538
edit: 'Edit rule',
2541-
notSupport:
2542-
'No system firewall detected (firewalld or ufw). Please refer to the official documentation for installation.',
25432539
ccDeny: 'CC Protection',
25442540
ipWhiteList: 'IP Whitelist',
25452541
ipBlockList: 'IP Blacklist',

frontend/src/lang/modules/ja.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,8 @@ const message = {
10051005
groupHelper:
10061006
'スクリプトの特徴に基づいて異なるグループを設定することで、スクリプトのフィルタリング操作をより迅速に行うことができます。',
10071007
handleHelper: '{0} で {1} スクリプトを実行します。続行しますか?',
1008+
noSuchApp:
1009+
'{0} サービスが検出されませんでした。スクリプトライブラリを使って素早くインストールしてください!',
10081010
},
10091011
},
10101012
monitor: {
@@ -1123,7 +1125,6 @@ const message = {
11231125
fail2ban: {
11241126
sshPort: 'SSHポートを聞いてください',
11251127
sshPortHelper: '現在のFAL2BANは、ホストのSSH接続ポートに耳を傾けます',
1126-
noFail2ban: `Fail2banサービスは検出されません。インストールする公式ドキュメントを参照してください。`,
11271128
unActive: `現在、Fail2Banサービスは有効になっていません。`,
11281129
operation: 'fail2banサービスで操作「{0}」を実行します。続けたいですか?',
11291130
fail2banChange: 'fail2ban構成の変更',
@@ -1146,7 +1147,6 @@ const message = {
11461147
ftp: {
11471148
ftp: 'FTPアカウント|FTPアカウント',
11481149
notStart: 'FTP Serviceは現在実行されていません。最初に開始してください!',
1149-
noFtp: `FTP(Pure-FTPD)サービスは検出されません。インストールする公式ドキュメントを参照してください。`,
11501150
operation: 'これにより、FTPサービスで「{0}」操作が実行されます。続けたいですか?',
11511151
noPasswdMsg: '現在のFTPアカウントパスワードを取得できません。パスワードを設定して再試行してください!',
11521152
enableHelper: '選択したFTPアカウントを有効にすると、アクセス許可が復元されます。続けたいですか?',
@@ -1166,7 +1166,6 @@ const message = {
11661166
hideFresh: '署名のアップデーターサービスを非表示にします',
11671167
clamHelper:
11681168
'Clamavの最小推奨構成は、3ギブ以上のRAM、2.0 GHz以上のシングルコアCPU、および少なくとも5 GIBの利用可能なハードディスクスペースです。',
1169-
noClam: 'CLAMAVサービスは検出されていません。インストールのための公式ドキュメントを参照してください!',
11701169
notStart: 'Clamav Serviceは現在実行されていません。最初に開始してください!',
11711170
removeRecord: 'ペポートファイルを削除します',
11721171
noRecords: '[トリガー]ボタンをクリックしてスキャンを開始すると、ここにレコードが表示されます。',
@@ -2424,8 +2423,6 @@ const message = {
24242423
firewall: {
24252424
create: 'ルールを作成します',
24262425
edit: 'ルールを編集します',
2427-
notSupport:
2428-
'システムファイアウォールは検出されません(ファイアウォールまたはUFW)。インストールのための公式ドキュメントを参照してください。',
24292426
ccDeny: 'CC保護',
24302427
ipWhiteList: 'IP AllowList',
24312428
ipBlockList: 'IPブロックリスト',

frontend/src/lang/modules/ko.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,7 @@ const message = {
999999
groupHelper:
10001000
'스크립트 특성에 따라 다양한 그룹을 설정하여 스크립트 필터링 작업을 더 빠르게 수행할 수 있습니다.',
10011001
handleHelper: '{0} 에서 {1} 스크립트를 실행합니다. 계속하시겠습니까?',
1002+
noSuchApp: '{0} 서비스가 감지되지 않았습니다. 스크립트 라이브러리를 사용하여 먼저 빠르게 설치하세요!',
10021003
},
10031004
},
10041005
monitor: {
@@ -1114,7 +1115,6 @@ const message = {
11141115
fail2ban: {
11151116
sshPort: 'SSH 포트 청취',
11161117
sshPortHelper: '현재 Fail2ban 은 호스트의 SSH 연결 포트를 청취합니다.',
1117-
noFail2ban: 'Fail2ban 서비스가 감지되지 않았습니다. 공식 문서를 참조하여 설치하세요.',
11181118
unActive: '현재 Fail2ban 서비스가 활성화되어 있지 않습니다.',
11191119
operation: 'Fail2ban 서비스에서 "{0}" 작업을 수행합니다. 계속하시겠습니까?',
11201120
fail2banChange: 'Fail2ban 구성 수정',
@@ -1137,7 +1137,6 @@ const message = {
11371137
ftp: {
11381138
ftp: 'FTP 계정 | FTP 계정들',
11391139
notStart: 'FTP 서비스가 현재 실행 중이 아닙니다. 먼저 시작하세요!',
1140-
noFtp: `FTP (pure-ftpd) 서비스가 감지되지 않았습니다. 공식 문서를 참조하여 설치하세요.`,
11411140
operation: 'FTP 서비스에서 "{0}" 작업을 수행합니다. 계속하시겠습니까?',
11421141
noPasswdMsg: '현재 FTP 계정의 비밀번호를 가져올 수 없습니다. 비밀번호를 설정한 후 다시 시도하세요!',
11431142
enableHelper: '선택한 FTP 계정을 활성화하면 접근 권한이 복원됩니다. 계속하시겠습니까?',
@@ -1155,7 +1154,6 @@ const message = {
11551154
hideFresh: '서명 업데이트 서비스 숨기기',
11561155
clamHelper:
11571156
'ClamAV의 최소 권장 구성은 다음과 같습니다: RAM 3 GiB 이상, 2.0 GHz 이상의 단일 코어 CPU, 최소 5 GiB의 사용 가능한 하드 디스크 공간.',
1158-
noClam: 'ClamAV 서비스가 감지되지 않았습니다. 공식 문서를 참조하여 설치하세요!',
11591157
notStart: 'ClamAV 서비스가 현재 실행 중이 아닙니다. 먼저 시작하세요!',
11601158
removeRecord: '보고서 파일 삭제',
11611159
noRecords: '"Trigger" 버튼을 클릭하여 스캔을 시작하면 이곳에서 기록을 확인할 수 있습니다.',
@@ -2385,7 +2383,6 @@ const message = {
23852383
firewall: {
23862384
create: '규칙 만들기',
23872385
edit: '규칙 수정',
2388-
notSupport: '시스템 방화벽이 감지되지 않았습니다 (firewalld 또는 ufw). 설치 방법은 공식 문서를 참조하세요.',
23892386
ccDeny: 'CC 보호',
23902387
ipWhiteList: 'IP 허용 목록',
23912388
ipBlockList: 'IP 차단 목록',

frontend/src/lang/modules/ms.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,8 @@ const message = {
10351035
groupHelper:
10361036
'Tetapkan kumpulan yang berbeza berdasarkan ciri skrip, yang membolehkan operasi penapisan skrip dilakukan dengan lebih pantas.',
10371037
handleHelper: 'Akan melaksanakan skrip {1} pada {0}, teruskan?',
1038+
noSuchApp:
1039+
'Perkhidmatan {0} tidak dikesan. Sila pasang dengan cepat menggunakan pustaka skrip terlebih dahulu!',
10381040
},
10391041
},
10401042
monitor: {
@@ -1161,7 +1163,6 @@ const message = {
11611163
fail2ban: {
11621164
sshPort: 'Dengar pada port SSH',
11631165
sshPortHelper: 'Fail2ban semasa mendengar pada port sambungan SSH hos',
1164-
noFail2ban: 'Perkhidmatan Fail2ban tidak dikesan. Rujuk dokumen rasmi untuk memasang.',
11651166
unActive: 'Perkhidmatan Fail2ban tidak diaktifkan pada masa ini.',
11661167
operation: 'Anda akan melaksanakan operasi "{0}" pada perkhidmatan Fail2ban. Adakah anda mahu meneruskan?',
11671168
fail2banChange: 'Pengubahan Konfigurasi Fail2ban',
@@ -1185,7 +1186,6 @@ const message = {
11851186
ftp: {
11861187
ftp: 'Akaun FTP | Akaun FTP',
11871188
notStart: 'Perkhidmatan FTP tidak berjalan pada masa ini, sila mulakan dahulu!',
1188-
noFtp: 'Perkhidmatan FTP (pure-ftpd) tidak dikesan. Rujuk dokumen rasmi untuk memasang.',
11891189
operation: 'Ini akan melaksanakan operasi "{0}" pada perkhidmatan FTP. Adakah anda mahu meneruskan?',
11901190
noPasswdMsg:
11911191
'Tidak dapat mendapatkan kata laluan akaun FTP semasa, sila tetapkan kata laluan dan cuba lagi!',
@@ -1208,7 +1208,6 @@ const message = {
12081208
hideFresh: 'Sembunyikan perkhidmatan pengemas kini tanda tangan',
12091209
clamHelper:
12101210
'Konfigurasi minimum yang disyorkan untuk ClamAV ialah: RAM 3 GiB atau lebih, CPU teras tunggal dengan 2.0 GHz atau lebih tinggi, dan sekurang-kurangnya 5 GiB ruang cakera keras yang tersedia.',
1211-
noClam: 'Perkhidmatan ClamAV tidak dikesan, sila rujuk dokumentasi rasmi untuk pemasangan!',
12121211
notStart: 'Perkhidmatan ClamAV tidak berjalan pada masa ini, sila mulakan dahulu!',
12131212
removeRecord: 'Padam fail laporan',
12141213
noRecords: 'Klik butang "Picu" untuk memulakan imbasan dan anda akan melihat rekod di sini.',
@@ -2482,8 +2481,6 @@ const message = {
24822481
firewall: {
24832482
create: 'Buat peraturan',
24842483
edit: 'Edit peraturan',
2485-
notSupport:
2486-
'Tiada firewall sistem yang dikesan (firewalld atau ufw). Sila rujuk dokumentasi rasmi untuk pemasangan.',
24872484
ccDeny: 'Perlindungan CC',
24882485
ipWhiteList: 'Senarai putih IP',
24892486
ipBlockList: 'Senarai blok IP',

0 commit comments

Comments
 (0)