补齐IMAP和POP3配置并统一邮件协议监听端口
This commit is contained in:
1 parent
9b60eb2177
commit
24829c1199
27 files changed
+868
-80
No files matched your search
@@ -88,6 +88,7 @@
|
||||
class="config-alert"
|
||||
/>
|
||||
|
||||
<MailPortSummary v-if="mailPortSummary && !sectionLoading && !sectionError" :services="mailPortSummary" />
|
||||
<ConfigForm
|
||||
v-if="!sectionLoading && !sectionError"
|
||||
:section="selectedSection"
|
||||
@@ -124,6 +125,13 @@
|
||||
:closable="false"
|
||||
show-icon
|
||||
/>
|
||||
<el-alert
|
||||
v-if="pendingScopeHint"
|
||||
:title="pendingScopeHint"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
/>
|
||||
<el-checkbox v-model="confirmed" class="confirmation-check" :disabled="sectionLoading || !!working || !!sectionError">
|
||||
我已确认这是受控变更,并允许使用最近认证完成高风险配置操作
|
||||
</el-checkbox>
|
||||
@@ -164,8 +172,10 @@
|
||||
<script setup>
|
||||
import { inject } from 'vue'
|
||||
import ConfigForm from '../ConfigForm/ConfigForm.vue'
|
||||
import MailPortSummary from '../MailPortSummary/MailPortSummary.vue'
|
||||
|
||||
const {
|
||||
mailPortSummary,
|
||||
availabilityError,
|
||||
loading,
|
||||
working,
|
||||
@@ -186,6 +196,7 @@ const {
|
||||
confirmed,
|
||||
savedGeneration,
|
||||
pendingCandidate,
|
||||
pendingScopeHint,
|
||||
managePending,
|
||||
validationResult,
|
||||
canWrite,
|
||||
|
||||
@@ -33,6 +33,18 @@ export function getRecommendedPort(config, path) {
|
||||
return 443
|
||||
case 'relay.relayPort':
|
||||
return smtpPorts.get(config.relay?.security)
|
||||
case 'listener.port':
|
||||
return 25
|
||||
case 'listener.starttlsPort':
|
||||
return 587
|
||||
case 'listener.tlsPort':
|
||||
return 465
|
||||
case 'imap.tlsPort':
|
||||
return 993
|
||||
case 'pop3.port':
|
||||
return 110
|
||||
case 'pop3.tlsPort':
|
||||
return 995
|
||||
default:
|
||||
return undefined
|
||||
}
|
||||
@@ -105,6 +117,11 @@ const baseGroups = [
|
||||
]
|
||||
|
||||
const smtpGroups = [
|
||||
group('listener', 'SMTP 服务监听', '', [
|
||||
port('listener.port', 'SMTP 收信端口', { min: 1, hint: '默认 25,用于接收其他邮件服务器投递,支持 STARTTLS;不是发信中继端口。' }),
|
||||
port('listener.starttlsPort', 'SMTP 提交端口(STARTTLS)', { min: 1, hint: '默认 587,客户端升级 TLS 后进行认证。' }),
|
||||
port('listener.tlsPort', 'SMTP 隐式 TLS 端口', { min: 1, hint: '默认 465,客户端建立连接时直接使用 TLS。' })
|
||||
]),
|
||||
group('relay', 'SMTP 中继连接', '用于发送验证及通知邮件。未使用中继时可保留空值。', [
|
||||
field('relay.relayHost', 'SMTP 服务器', 'text', { placeholder: 'smtp.example.com' }),
|
||||
field('relay.security', '连接加密', 'select', {
|
||||
@@ -117,7 +134,7 @@ const smtpGroups = [
|
||||
]),
|
||||
hint: '切换加密方式会自动匹配推荐端口,之后仍可手动填写服务商指定的端口。'
|
||||
}),
|
||||
port('relay.relayPort', 'SMTP 端口', { hint: '先选择加密方式,系统自动填写端口;自定义端口不会改变加密方式。' }),
|
||||
port('relay.relayPort', 'SMTP 发信中继端口', { hint: '外部 SMTP 服务器端口,与本机监听无关;选择加密方式后自动填写。' }),
|
||||
field('relay.username', '认证用户名', 'text', { placeholder: '需要认证时填写' }),
|
||||
field('relay.from', '发件邮箱', 'text', { placeholder: 'noreply@example.com' }),
|
||||
field('relay.fromDomain', '发件域名', 'text', { placeholder: 'example.com' })
|
||||
@@ -128,12 +145,20 @@ const smtpGroups = [
|
||||
])
|
||||
]
|
||||
|
||||
const imapGroups = [
|
||||
group('imap', 'IMAP 服务监听', '', [
|
||||
port('imap.tlsPort', 'IMAP 隐式 TLS 端口', { min: 1, required: true, hint: '默认 993。当前仅支持隐式 TLS,不提供明文或 STARTTLS 监听。' })
|
||||
])
|
||||
]
|
||||
|
||||
const pop3Groups = [
|
||||
group('pop3', 'POP3 服务监听', '', [
|
||||
port('pop3.port', 'POP3 端口(STLS)', { min: 1, required: true, hint: '默认 110,客户端使用 STLS 升级加密后认证。' }),
|
||||
port('pop3.tlsPort', 'POP3 隐式 TLS 端口', { min: 1, required: true, hint: '默认 995,客户端建立连接时直接使用 TLS。' })
|
||||
])
|
||||
]
|
||||
|
||||
const emailGroups = [
|
||||
group('ports', '邮件服务端口', '各服务端口不能重复,最终可用性由后端统一校验。', [
|
||||
port('policy.smtpPort', 'SMTP 收信端口', { min: 1, required: true }),
|
||||
port('policy.imapPort', 'IMAP 端口', { min: 1, required: true }),
|
||||
port('policy.pop3Port', 'POP3 端口', { min: 1, required: true })
|
||||
]),
|
||||
group('policy', '邮件与账号策略', '设置邮件大小、垃圾邮件过滤和账号恢复方式。', [
|
||||
field('policy.maxMessageBytes', '最大邮件大小(字节)', 'number', { min: 0, max: Number.MAX_SAFE_INTEGER, integer: true, hint: '0 使用后端默认限制;1 MiB = 1048576 字节。' }),
|
||||
field('policy.spamFilterLevel', '垃圾邮件过滤级别', 'select', { fallback: 0, options: options([[0, '不过滤'], [1, 'SPF 与 DKIM 均失败时过滤'], [2, 'SPF 失败时过滤'], [3, 'DKIM 失败时过滤']]) }),
|
||||
@@ -175,7 +200,7 @@ const pluginDefinitions = {
|
||||
|
||||
export function getFieldGroups(section, config) {
|
||||
if (section !== 'plugins') {
|
||||
return ({ base: baseGroups, smtp: smtpGroups, email: emailGroups, ssl: sslGroups }[section] || [])
|
||||
return ({ base: baseGroups, smtp: smtpGroups, imap: imapGroups, pop3: pop3Groups, email: emailGroups, ssl: sslGroups }[section] || [])
|
||||
.map(item => ({
|
||||
...item,
|
||||
fields: item.fields
|
||||
@@ -288,11 +313,13 @@ export function validateFormConfig(section, config) {
|
||||
errors['relay.relayHost'] = '不加密连接仅限本机地址;远程服务器请选择 STARTTLS 或隐式 TLS'
|
||||
}
|
||||
}
|
||||
if (section === 'email') {
|
||||
const ports = ['smtpPort', 'imapPort', 'pop3Port']
|
||||
for (const name of ports) {
|
||||
const value = config.policy?.[name]
|
||||
if (value > 0 && ports.some(other => other !== name && config.policy?.[other] === value)) errors[`policy.${name}`] = '邮件服务端口不能重复'
|
||||
if (['smtp', 'imap', 'pop3'].includes(section)) {
|
||||
const paths = section === 'smtp'
|
||||
? ['listener.port', 'listener.starttlsPort', 'listener.tlsPort']
|
||||
: ['imap.tlsPort', 'pop3.port', 'pop3.tlsPort']
|
||||
for (const path of paths) {
|
||||
const value = getValue(config, path.split('.'))
|
||||
if (value > 0 && paths.some(other => other !== path && getValue(config, other.split('.')) === value)) errors[path] = '邮件服务监听端口不能重复'
|
||||
}
|
||||
}
|
||||
if (section === 'ssl') {
|
||||
|
||||
@@ -2,6 +2,8 @@ import { computed, nextTick, ref } from 'vue'
|
||||
import { useGlobalStatusStore } from '@/stores/useGlobalStatusStore'
|
||||
import BaseConfig from './BaseConfig/BaseConfig.vue'
|
||||
import SmtpConfig from './SmtpConfig/SmtpConfig.vue'
|
||||
import ImapConfig from './ImapConfig/ImapConfig.vue'
|
||||
import Pop3Config from './Pop3Config/Pop3Config.vue'
|
||||
import EmailConfig from './EmailConfig/EmailConfig.vue'
|
||||
import SslConfig from './SslConfig/SslConfig.vue'
|
||||
import PluginsConfig from './PluginsConfig/PluginsConfig.vue'
|
||||
@@ -16,6 +18,8 @@ export function useNavigation() {
|
||||
const pages = [
|
||||
{ value: 'base', label: '基础配置', component: BaseConfig },
|
||||
{ value: 'smtp', label: 'SMTP 配置', component: SmtpConfig },
|
||||
{ value: 'imap', label: 'IMAP 配置', component: ImapConfig },
|
||||
{ value: 'pop3', label: 'POP3 配置', component: Pop3Config },
|
||||
{ value: 'email', label: '邮箱策略', component: EmailConfig },
|
||||
{ value: 'ssl', label: 'SSL 配置', component: SslConfig },
|
||||
{ value: 'plugins', label: '插件配置', component: PluginsConfig }
|
||||
|
||||
@@ -6,8 +6,10 @@ import { readFormConfig, updateFormConfig, validateFormConfig } from './ConfigFo
|
||||
|
||||
const sections = [
|
||||
{ value: 'base', label: '基础配置', description: '管理站点与数据库连接,敏感凭据单独填写。' },
|
||||
{ value: 'smtp', label: 'SMTP 配置', description: '管理邮件发送与中继连接,密码留空时保持原值。' },
|
||||
{ value: 'email', label: '邮箱策略', description: '管理邮件协议端口与账号恢复策略。' },
|
||||
{ value: 'smtp', label: 'SMTP 配置', description: '管理本机监听与发信中继;监听端口变更需应用配置并重启后端。' },
|
||||
{ value: 'imap', label: 'IMAP 配置', description: '管理 IMAP 隐式 TLS 监听;端口变更需应用配置并重启后端。' },
|
||||
{ value: 'pop3', label: 'POP3 配置', description: '管理 POP3 的 STLS 与隐式 TLS 监听;端口变更需应用配置并重启后端。' },
|
||||
{ value: 'email', label: '邮箱策略', description: '自动汇总三个协议的配置端口,管理邮件与账号恢复策略。' },
|
||||
{ value: 'ssl', label: 'SSL 配置', description: '管理证书与加密连接,应用后请留意待重启提示。' },
|
||||
{ value: 'plugins', label: '插件配置', description: '管理插件运行配置,敏感设置仅显示配置状态。' }
|
||||
]
|
||||
@@ -49,6 +51,8 @@ export function usePage(pageKey = 'base') {
|
||||
degradedReasons: []
|
||||
})
|
||||
const selectedSection = ref(isConfigPage ? pageKey : 'base')
|
||||
// 页面与存储分区分离,IMAP、POP3 复用邮箱分区的原子保存与候选保护。
|
||||
const apiSection = () => ['imap', 'pop3'].includes(selectedSection.value) ? 'email' : selectedSection.value
|
||||
const currentSection = computed(() => sections.find(item => item.value === selectedSection.value) || sections[0])
|
||||
const sectionLoading = ref(false)
|
||||
let sectionRequestId = 0
|
||||
@@ -57,11 +61,47 @@ export function usePage(pageKey = 'base') {
|
||||
const formConfig = computed(() => readFormConfig(editorText.value))
|
||||
const formErrors = ref({})
|
||||
const loadedText = ref('')
|
||||
const smtpListener = ref(null)
|
||||
const mailPortSummary = computed(() => {
|
||||
if (selectedSection.value !== 'email' || !loadedText.value || !smtpListener.value) return null
|
||||
const email = readFormConfig(loadedText.value)
|
||||
return [
|
||||
{ name: 'SMTP', ports: [
|
||||
{ label: '收信 / STARTTLS', value: smtpListener.value.port },
|
||||
{ label: '提交 / STARTTLS', value: smtpListener.value.starttlsPort },
|
||||
{ label: '隐式 TLS', value: smtpListener.value.tlsPort }
|
||||
] },
|
||||
{ name: 'IMAP', ports: [{ label: '隐式 TLS', value: email.imap?.tlsPort }] },
|
||||
{ name: 'POP3', ports: [
|
||||
{ label: 'STLS', value: email.pop3?.port },
|
||||
{ label: '隐式 TLS', value: email.pop3?.tlsPort }
|
||||
] }
|
||||
]
|
||||
})
|
||||
const sectionError = ref('')
|
||||
const secretValue = ref('')
|
||||
const confirmed = ref(false)
|
||||
const savedGeneration = ref(0)
|
||||
const pendingCandidate = ref(null)
|
||||
const pendingScopeHint = computed(() => {
|
||||
const pending = pendingCandidate.value
|
||||
if (pending?.section !== 'email' || apiSection() !== 'email') return ''
|
||||
const active = readFormConfig(loadedText.value)
|
||||
const candidate = pending.payload || {}
|
||||
const changed = [
|
||||
['imap', 'IMAP 配置'],
|
||||
['pop3', 'POP3 配置'],
|
||||
['policy', '邮箱策略']
|
||||
].filter(([key]) => {
|
||||
const before = active[key] || {}
|
||||
const after = candidate[key] || {}
|
||||
return Object.keys({ ...before, ...after }).some(field => JSON.stringify(before[field]) !== JSON.stringify(after[field]))
|
||||
}).map(([, label]) => label)
|
||||
const scope = pending.payload && loadedText.value
|
||||
? (changed.length ? `本次候选涉及:${changed.join('、')}。` : '本次候选的协议端口和邮箱策略未变化。')
|
||||
: '候选内容尚未完整读取,请刷新后核对。'
|
||||
return `${scope}IMAP、POP3 和邮箱策略共用一个配置分区,请逐页核对;应用时会一起生效,监听端口仍需重启后端。`
|
||||
})
|
||||
let savedInput = null
|
||||
const validationResult = ref(null)
|
||||
const backups = ref([])
|
||||
@@ -197,7 +237,7 @@ export function usePage(pageKey = 'base') {
|
||||
savedInput = null
|
||||
const pending = pendingCandidate.value
|
||||
const section = pending?.section === 'root' ? 'base' : pending?.section
|
||||
if (pending && section === selectedSection.value) {
|
||||
if (pending && section === apiSection()) {
|
||||
editorText.value = JSON.stringify(pending.payload, null, 2)
|
||||
secretValue.value = ''
|
||||
savedInput = { text: editorText.value, secret: '' }
|
||||
@@ -234,12 +274,13 @@ export function usePage(pageKey = 'base') {
|
||||
|
||||
const loadSection = async () => {
|
||||
const requestId = ++sectionRequestId
|
||||
const section = selectedSection.value
|
||||
const section = apiSection()
|
||||
sectionLoading.value = true
|
||||
sectionError.value = ''
|
||||
formErrors.value = {}
|
||||
editorText.value = ''
|
||||
loadedText.value = ''
|
||||
smtpListener.value = null
|
||||
secretValue.value = ''
|
||||
confirmed.value = false
|
||||
validationResult.value = null
|
||||
@@ -250,6 +291,16 @@ export function usePage(pageKey = 'base') {
|
||||
if (requestId !== sectionRequestId) return
|
||||
notifyResponseError(response, '配置分区读取失败')
|
||||
const publicConfig = response.data || {}
|
||||
if (selectedSection.value === 'email') {
|
||||
const smtpResponse = await http.get('/api/v1/config/smtp')
|
||||
if (requestId !== sectionRequestId) return
|
||||
notifyResponseError(smtpResponse, 'SMTP 监听配置读取失败')
|
||||
// 不拼接不同代次的配置,也不在读取失败时显示旧端口。
|
||||
if (smtpResponse.data?.meta?.generation !== publicConfig.meta?.generation) {
|
||||
throw new Error('配置代次已变化,请刷新后查看最新端口')
|
||||
}
|
||||
smtpListener.value = smtpResponse.data?.listener || null
|
||||
}
|
||||
editorText.value = JSON.stringify(publicConfig, null, 2)
|
||||
loadedText.value = editorText.value
|
||||
if (section === 'base') {
|
||||
@@ -502,7 +553,7 @@ export function usePage(pageKey = 'base') {
|
||||
working.value = 'validate'
|
||||
try {
|
||||
const request = buildRequest()
|
||||
const response = await http.post(`/api/v1/config/${selectedSection.value}/validate`, request)
|
||||
const response = await http.post(`/api/v1/config/${apiSection()}/validate`, request)
|
||||
notifyResponseError(response, '配置验证失败')
|
||||
validationResult.value = response.data || null
|
||||
ElMessage[validationResult.value?.valid ? 'success' : 'warning'](validationResult.value?.valid ? '配置验证通过' : '配置验证未通过')
|
||||
@@ -518,10 +569,10 @@ export function usePage(pageKey = 'base') {
|
||||
working.value = 'save'
|
||||
try {
|
||||
const request = buildRequest()
|
||||
const response = await http.put(`/api/v1/config/${selectedSection.value}`, request)
|
||||
const response = await http.put(`/api/v1/config/${apiSection()}`, request)
|
||||
notifyResponseError(response, '配置保存失败')
|
||||
savedGeneration.value = response.data?.generation || 0
|
||||
pendingCandidate.value = { ...response.data, section: selectedSection.value, sameSession: true }
|
||||
pendingCandidate.value = { ...response.data, section: apiSection(), sameSession: true }
|
||||
savedInput = { text: editorText.value, secret: secretValue.value }
|
||||
validationResult.value = { valid: true, generation: savedGeneration.value, issues: [] }
|
||||
await loadStatus()
|
||||
@@ -543,7 +594,7 @@ export function usePage(pageKey = 'base') {
|
||||
}
|
||||
working.value = 'apply'
|
||||
try {
|
||||
const response = await http.post(`/api/v1/config/${selectedSection.value}/apply`, {
|
||||
const response = await http.post(`/api/v1/config/${apiSection()}/apply`, {
|
||||
generation: savedGeneration.value,
|
||||
candidateId: pendingCandidate.value?.candidateId
|
||||
})
|
||||
@@ -665,6 +716,8 @@ export function usePage(pageKey = 'base') {
|
||||
})
|
||||
|
||||
return {
|
||||
mailPortSummary,
|
||||
pendingScopeHint,
|
||||
loading, availabilityError, working, status, stateLabel, stateTagType, sectionOptions: sections,
|
||||
selectedSection, currentSection, sectionLoading, editorText, formConfig, formErrors, updateField, updateSecret,
|
||||
sectionError, sensitiveHint, secretField, secretValue,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<template>
|
||||
<ConfigEditor />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { provide } from 'vue'
|
||||
import { usePage } from '../ConfigSettings.js'
|
||||
import ConfigEditor from '../ConfigEditor/ConfigEditor.vue'
|
||||
|
||||
const page = usePage('imap')
|
||||
provide('smail-config-page', page)
|
||||
defineExpose({ beforeLeave: page.beforeLeave })
|
||||
</script>
|
||||
@@ -0,0 +1,52 @@
|
||||
.mail-port-summary {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.summary-note {
|
||||
margin: 0 0 14px;
|
||||
color: var(--pm-text-secondary);
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.summary-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.protocol-card {
|
||||
padding: 16px;
|
||||
border: 1px solid var(--pm-border-color);
|
||||
border-radius: 10px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.protocol-card dl {
|
||||
margin: 12px 0 0;
|
||||
}
|
||||
|
||||
.port-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
gap: 6px 12px;
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.port-row dt {
|
||||
color: var(--pm-text-secondary);
|
||||
}
|
||||
|
||||
.port-row dd {
|
||||
margin: 0;
|
||||
font-weight: 600;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
@container config-main (max-width: 680px) {
|
||||
.summary-grid {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<template>
|
||||
<section class="mail-port-summary" aria-label="邮件协议端口汇总">
|
||||
<p class="summary-note">端口自动读取 SMTP、IMAP、POP3 配置,不能在邮箱策略中修改。这里显示已应用的配置值,不是端口在线检测;如有待重启提示,请重启后端后再连接。</p>
|
||||
<div class="summary-grid">
|
||||
<article v-for="service in services" :key="service.name" class="protocol-card">
|
||||
<strong>{{ service.name }}</strong>
|
||||
<dl>
|
||||
<div v-for="port in service.ports" :key="port.label" class="port-row">
|
||||
<dt>{{ port.label }}</dt>
|
||||
<dd>{{ port.value ?? '未读取' }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
defineProps({ services: { type: Array, required: true } })
|
||||
</script>
|
||||
|
||||
<style scoped src="./MailPortSummary.css"></style>
|
||||
@@ -0,0 +1,13 @@
|
||||
<template>
|
||||
<ConfigEditor />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { provide } from 'vue'
|
||||
import { usePage } from '../ConfigSettings.js'
|
||||
import ConfigEditor from '../ConfigEditor/ConfigEditor.vue'
|
||||
|
||||
const page = usePage('pop3')
|
||||
provide('smail-config-page', page)
|
||||
defineExpose({ beforeLeave: page.beforeLeave })
|
||||
</script>
|
||||
Reference in new issue
Block a user