fix: 解决防火墙未显示具体应用占用情况的问题 (#2452)

This commit is contained in:
ssongliu 2023-10-08 12:14:13 +08:00 committed by GitHub
parent b09c423bcc
commit 4c650af0e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 51 additions and 12 deletions

View File

@ -647,7 +647,7 @@ func checkPortUsed(ports, proto string, apps []portOfApp) string {
for _, app := range apps {
if app.HttpPort == ports || app.HttpsPort == ports {
return fmt.Sprintf("%s (%s)", ports, app.AppName)
return fmt.Sprintf("(%s)", app.AppName)
}
}
port, err := strconv.Atoi(ports)
@ -656,7 +656,7 @@ func checkPortUsed(ports, proto string, apps []portOfApp) string {
return ""
}
if common.ScanPortWithProto(port, proto) {
return ports
return "inUsed"
}
return ""
}

View File

@ -102,6 +102,7 @@ func (u *SettingService) SystemScan() dto.CleanData {
func (u *SettingService) SystemClean(req []dto.Clean) {
size := uint64(0)
restart := false
for _, item := range req {
size += item.Size
switch item.TreeType {
@ -121,9 +122,7 @@ func (u *SettingService) SystemClean(req []dto.Clean) {
case "cache":
dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/cache", item.Name))
defer func() {
_, _ = cmd.Exec("systemctl restart 1panel.service")
}()
restart = true
case "unused":
dropFileOrDir(path.Join(global.CONF.System.BaseDir, "original", item.Name))
@ -207,6 +206,15 @@ func (u *SettingService) SystemClean(req []dto.Clean) {
_ = settingRepo.Update("LastCleanTime", time.Now().Format("2006-01-02 15:04:05"))
_ = settingRepo.Update("LastCleanSize", fmt.Sprintf("%v", size))
_ = settingRepo.Update("LastCleanData", fmt.Sprintf("%v", len(req)))
if restart {
go func() {
_, err := cmd.Exec("systemctl restart 1panel.service")
if err != nil {
global.LOG.Errorf("restart system port failed, err: %v", err)
}
}()
}
}
func loadSnapshotTree(fileOp fileUtils.FileOp) []dto.CleanTree {

View File

@ -7,7 +7,6 @@ type FireInfo struct {
Protocol string `json:"protocol"` // tcp udp tcp/udp
Strategy string `json:"strategy"` // accept drop
APPName string `json:"appName"`
UsedStatus string `json:"usedStatus"`
Description string `json:"description"`
}

View File

@ -77,8 +77,8 @@ export namespace Host {
port: string;
protocol: string;
strategy: string;
appName: string;
isUsed: boolean;
usedStatus: string;
description: string;
}
export interface UpdateDescription {

View File

@ -1233,7 +1233,9 @@ const message = {
'Temporary files generated during snapshots, upgrades, and obsolete file contents during version iterations',
panelOriginal: 'System snapshot recovery backup files',
upgrade: 'System upgrade backup files',
upgradeHelper: '(Recommend keeping the latest upgrade backup for system rollback)',
cache: 'System cache files',
cacheHelper: '(Proceed with caution, clearing requires a service restart)',
snapshot: 'System snapshot temporary files',
snapshotTmp: 'System snapshot upload temporary files',
snapshotLocal: 'System snapshot creation temporary files',

View File

@ -1171,7 +1171,9 @@ const message = {
systemHelper: '快照升級等過程中產生的臨時文件以及版本叠代過程中廢棄的文件內容',
panelOriginal: '系統快照恢復前備份文件',
upgrade: '系統升級備份文件',
upgradeHelper: '( 建議保留最新的升級備份用於系統回滾 )',
cache: '系統緩存文件',
cacheHelper: '( 謹慎操作清理需要重啟服務 )',
snapshot: '系統快照臨時文件',
snapshotTmp: '系統快照上傳臨時文件',
snapshotLocal: '系統快照製作臨時文件',
@ -1187,7 +1189,7 @@ const message = {
website: '網站',
app: '應用',
database: '數據庫',
directory: '應用',
directory: '文件夾',
systemLog: '系統日誌文件',
systemLogHelper: '系統日誌信息容器構建或鏡像拉取等日誌信息以及計劃任務中產生的日誌文件',

View File

@ -1170,7 +1170,9 @@ const message = {
systemHelper: '快照升级等过程中产生的临时文件以及版本迭代过程中废弃的文件内容',
panelOriginal: '系统快照恢复前备份文件',
upgrade: '系统升级备份文件',
upgradeHelper: '( 建议保留最新的升级备份用于系统回滚 )',
cache: '系统缓存文件',
cacheHelper: '( 谨慎操作清理需要重启服务 )',
snapshot: '系统快照临时文件',
snapshotTmp: '系统快照上传临时文件',
snapshotLocal: '系统快照制作临时文件',
@ -1186,7 +1188,7 @@ const message = {
website: '网站',
app: '应用',
database: '数据库',
directory: '应用',
directory: '文件夹',
systemLog: '系统日志文件',
systemLogHelper: '系统日志信息容器构建或镜像拉取等日志信息以及计划任务中产生的日志文件',

View File

@ -104,7 +104,8 @@
</div>
<div v-else>
<el-tag type="info" v-if="row.usedStatus">
{{ $t('firewall.used') }}
<span v-if="row.usedStatus === 'inUsed'">{{ $t('firewall.used') }}</span>
<span v-else>{{ $t('firewall.used') + ' ' + row.usedStatus }}</span>
</el-tag>
<el-tag type="success" v-else>{{ $t('firewall.unUsed') }}</el-tag>
</div>

View File

@ -240,6 +240,8 @@ import DrawerHeader from '@/components/drawer-header/index.vue';
import { cleanSystem, scanSystem } from '@/api/modules/setting';
import i18n from '@/lang';
import { MsgSuccess } from '@/utils/message';
import { GlobalStore } from '@/store';
const globalStore = GlobalStore();
const emit = defineEmits<{ (e: 'search'): void }>();
const drawerVisible = ref();
@ -284,7 +286,6 @@ interface DialogProps {
const acceptParams = (params: DialogProps): void => {
scanStatus.value = 'beforeScan';
form.lastCleanTime = params.lastCleanTime;
console.log(form.lastCleanTime);
form.lastCleanSize = params.lastCleanSize;
form.lastCleanData = params.lastCleanData;
drawerVisible.value = true;
@ -332,10 +333,17 @@ const onSubmitClean = async () => {
}).then(async () => {
loading.value = true;
submitCleans.value = [];
let restart = false;
loadSubmitCheck(cleanData.systemClean);
loadSubmitCheck(cleanData.uploadClean);
loadSubmitCheck(cleanData.downloadClean);
loadSubmitCheck(cleanData.systemLogClean);
for (const item of submitCleans.value) {
if (item.treeType === 'cache') {
restart = true;
break;
}
}
await cleanSystem(submitCleans.value)
.then(() => {
form.lastCleanSize = selectSize.value + '';
@ -343,6 +351,17 @@ const onSubmitClean = async () => {
scanStatus.value = 'afterScan';
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
loading.value = false;
if (restart) {
let href = window.location.href;
globalStore.isLogin = false;
let address = href.split('://')[1];
if (globalStore.entrance) {
address = address.replaceAll('settings/panel', globalStore.entrance);
} else {
address = address.replaceAll('settings/panel', 'login');
}
window.open(`http://${address}`, '_self');
}
})
.catch(() => {
loading.value = false;
@ -437,6 +456,12 @@ function loadTag(node: any, data: any) {
if (data.size === 0) {
return i18n.global.t('clean.statusClean');
}
if (data.label === 'upgrade') {
return i18n.global.t('clean.upgradeHelper');
}
if (data.label === 'cache') {
return i18n.global.t('clean.cacheHelper');
}
return data.isRecommend ? i18n.global.t('clean.statusSuggest') : i18n.global.t('clean.statusWarning');
}