22 <div >
33 <FireRouter />
44
5- <div v-if =" !isIptables" >
6- <LayoutContent :divider =" true" >
7- <template #main >
8- <div class =" app-warn" >
9- <div class =" flex flex-col gap-2 items-center justify-center w-full sm:flex-row" >
10- <span >{{ $t('firewall.advancedControlNotAvailable', [firewallName]) }}</span >
5+ <div v-loading =" loading" >
6+ <FireStatus
7+ ref =" fireStatusRef"
8+ @search =" search"
9+ @advanced-operate =" onApplyFirewall"
10+ v-model:loading =" loading"
11+ v-model:mask-show =" maskShow"
12+ v-model:is-active =" isActive"
13+ v-model:name =" fireName"
14+ :show-advanced-controls =" true"
15+ :can-apply =" canApply"
16+ :is-applied =" isApplied"
17+ />
18+ <div v-if =" fireName === '-'" >
19+ <LayoutContent :divider =" true" >
20+ <template #main >
21+ <div class =" app-warn" >
22+ <div class =" flex flex-col gap-2 items-center justify-center w-full sm:flex-row" >
23+ <span >{{ $t('firewall.advancedControlNotAvailable', [firewallName]) }}</span >
24+ </div >
25+ <div >
26+ <img src =" @/assets/images/no_app.svg" />
27+ </div >
1128 </div >
12- <div >
13- <img src =" @/assets/images/no_app.svg" />
29+ </template >
30+ </LayoutContent >
31+ </div >
32+
33+ <div v-else-if =" !isIptablesComputed" >
34+ <LayoutContent :divider =" true" >
35+ <template #main >
36+ <div class =" app-warn" >
37+ <div class =" flex flex-col gap-2 items-center justify-center w-full sm:flex-row" >
38+ <span >{{ $t('firewall.advancedControlNotAvailable', [fireName]) }}</span >
39+ </div >
40+ <div >
41+ <img src =" @/assets/images/no_app.svg" />
42+ </div >
1443 </div >
15- </div >
16- </template >
17- </LayoutContent >
18- </div >
44+ </template >
45+ </LayoutContent >
46+ </div >
1947
20- <div v-else v-loading =" loading" >
21- <el-card >
22- <div class =" flex w-full flex-col gap-4 md:flex-row" >
23- <div class =" flex flex-wrap gap-4 ml-3" >
24- <el-tag effect =" dark" type =" success" >{{ 'iptables v' + iptablesVersion }}</el-tag >
25- <el-tag :type =" inputChainInfo?.isApplied ? 'success' : 'info'" size =" small" >
26- {{ inputChainInfo?.isApplied ? $t('firewall.applied') : $t('firewall.notApplied') }}
27- </el-tag >
28- </div >
29- </div >
30- </el-card >
31- <div >
32- <LayoutContent :title =" $t('firewall.filterRule')" >
48+ <div v-else >
49+ <el-card v-if =" !isActive && maskShow" class =" mask-prompt" >
50+ <span >{{ $t('firewall.firewallNotStart') }}</span >
51+ </el-card >
52+ <LayoutContent :title =" $t('firewall.filterRule')" :class =" { mask: !isActive }" >
3353 <template #leftToolBar >
3454 <el-button type =" primary" @click =" onOpenDialog('create')" :disabled =" !isCustomChain" >
3555 {{ $t('firewall.create') }}
3656 </el-button >
3757 <el-button @click =" onDelete(null)" plain :disabled =" selects.length === 0 || !isCustomChain" >
3858 {{ $t('commons.button.delete') }}
3959 </el-button >
40- <el-button @click =" onInitChains" plain >
41- {{ $t('firewall.initChains') }}
42- </el-button >
43- <el-button @click =" onApplyFirewall('apply')" plain type =" success" :disabled =" !canApply" >
44- {{ $t('firewall.applyFirewall') }}
45- </el-button >
46- <el-button @click =" onApplyFirewall('unload')" plain type =" warning" :disabled =" !isApplied" >
47- {{ $t('firewall.unloadFirewall') }}
48- </el-button >
4960 </template >
5061
5162 <template #rightToolBar >
156167
157168<script lang="ts" setup>
158169import FireRouter from ' @/views/host/firewall/index.vue' ;
170+ import FireStatus from ' @/views/host/firewall/status/index.vue' ;
159171import OperateDialog from ' @/views/host/firewall/filter/operate/index.vue' ;
160172import { computed , onMounted , reactive , ref } from ' vue' ;
161- import { getFilterRules , applyFilterFirewall , batchOperateFilterRule , loadFireBaseInfo } from ' @/api/modules/host' ;
173+ import { getFilterRules , applyFilterFirewall , batchOperateFilterRule } from ' @/api/modules/host' ;
162174import { Host } from ' @/api/interface/host' ;
163175import i18n from ' @/lang' ;
164176import { MsgSuccess } from ' @/utils/message' ;
@@ -169,7 +181,11 @@ const selects = ref<any>([]);
169181const selectedChain = ref (' 1PANEL_INPUT' );
170182const iptablesVersion = ref (' ' );
171183const firewallName = ref (' ' );
172- const isIptables = ref (true );
184+
185+ const maskShow = ref (true );
186+ const isActive = ref (false );
187+ const fireName = ref ();
188+ const fireStatusRef = ref ();
173189
174190const opRef = ref ();
175191
@@ -189,6 +205,7 @@ const formatPort = (port?: number | null | string) => {
189205 return port ;
190206};
191207
208+ const isIptablesComputed = computed (() => fireName .value === ' iptables' );
192209const inputChainInfo = computed (() => chainInfoMap .value .get (' INPUT' ));
193210const outputChainInfo = computed (() => chainInfoMap .value .get (' OUTPUT' ));
194211
@@ -216,6 +233,12 @@ const paginationConfig = reactive({
216233});
217234
218235const search = async () => {
236+ if (! isActive .value ) {
237+ loading .value = false ;
238+ chainInfoMap .value .clear ();
239+ paginationConfig .total = 0 ;
240+ return ;
241+ }
219242 const params: Host .IptablesFilterRuleSearch = {
220243 chains: [' INPUT' , ' OUTPUT' , ' 1PANEL_INPUT' , ' 1PANEL_OUTPUT' ],
221244 };
@@ -254,29 +277,20 @@ const onOpenDialog = async (title: string, rowData?: Host.IptablesFilterRuleOper
254277 dialogRef .value ! .acceptParams (params );
255278};
256279
257- const onInitChains = async () => {
258- ElMessageBox .confirm (i18n .global .t (' firewall.initChainsConfirm' ), i18n .global .t (' firewall.initChains' ), {
259- confirmButtonText: i18n .global .t (' commons.button.confirm' ),
260- cancelButtonText: i18n .global .t (' commons.button.cancel' ),
261- }).then (async () => {
262- loading .value = true ;
263- await applyFilterFirewall ({ operation: ' init' })
264- .then (() => {
265- loading .value = false ;
266- MsgSuccess (i18n .global .t (' commons.msg.operationSuccess' ));
267- search ();
268- })
269- .catch (() => {
270- loading .value = false ;
271- });
272- });
273- };
274-
275280const onApplyFirewall = async (operation : string ) => {
276- const confirmMsg =
277- operation === ' apply' ? i18n .global .t (' firewall.applyConfirm' ) : i18n .global .t (' firewall.unloadConfirm' );
278- const title =
279- operation === ' apply' ? i18n .global .t (' firewall.applyFirewall' ) : i18n .global .t (' firewall.unloadFirewall' );
281+ let confirmMsg = ' ' ;
282+ let title = ' ' ;
283+
284+ if (operation === ' init' ) {
285+ confirmMsg = i18n .global .t (' firewall.initChainsConfirm' );
286+ title = i18n .global .t (' firewall.initChains' );
287+ } else if (operation === ' apply' ) {
288+ confirmMsg = i18n .global .t (' firewall.applyConfirm' );
289+ title = i18n .global .t (' firewall.applyFirewall' );
290+ } else {
291+ confirmMsg = i18n .global .t (' firewall.unloadConfirm' );
292+ title = i18n .global .t (' firewall.unloadFirewall' );
293+ }
280294
281295 ElMessageBox .confirm (confirmMsg , title , {
282296 confirmButtonText: i18n .global .t (' commons.button.confirm' ),
@@ -345,18 +359,11 @@ const buttons = [
345359 },
346360];
347361
348- onMounted (async () => {
349- await loadFireBaseInfo ()
350- .then ((res ) => {
351- firewallName .value = res .data .name ;
352- isIptables .value = res .data .name === ' iptables' ;
353- if (isIptables .value ) {
354- search ();
355- }
356- })
357- .catch (() => {
358- isIptables .value = false ;
359- });
362+ onMounted (() => {
363+ if (fireName .value !== ' -' ) {
364+ loading .value = true ;
365+ fireStatusRef .value .acceptParams ();
366+ }
360367});
361368 </script >
362369
0 commit comments