1 parent
78ae5cb17b
commit
0d6f0060b9
2 files changed
+97
-63
No files matched your search
+95
-62
@@ -42,14 +42,14 @@ const assertSetupSuccess = (response, fallback = lang.setup_failed) => {
|
|||||||
|
|
||||||
export function usePage() {
|
export function usePage() {
|
||||||
const waitDesc = ref(lang.wait_desc);
|
const waitDesc = ref(lang.wait_desc);
|
||||||
|
|
||||||
const adminSettings = reactive({
|
const adminSettings = reactive({
|
||||||
"account": "admin",
|
"account": "admin",
|
||||||
"password": "",
|
"password": "",
|
||||||
"password2": "",
|
"password2": "",
|
||||||
"hadSeted": false
|
"hadSeted": false
|
||||||
})
|
})
|
||||||
|
|
||||||
const dbSettings = reactive({
|
const dbSettings = reactive({
|
||||||
"type": "sqlite",
|
"type": "sqlite",
|
||||||
"dsn": "./config/smail.db",
|
"dsn": "./config/smail.db",
|
||||||
@@ -60,13 +60,13 @@ export function usePage() {
|
|||||||
"password": "",
|
"password": "",
|
||||||
"name": "smail"
|
"name": "smail"
|
||||||
})
|
})
|
||||||
|
|
||||||
const domainSettings = reactive({
|
const domainSettings = reactive({
|
||||||
"web_domain": "",
|
"web_domain": "",
|
||||||
"smtp_domain": "",
|
"smtp_domain": "",
|
||||||
"multi_domain": []
|
"multi_domain": []
|
||||||
})
|
})
|
||||||
|
|
||||||
const sslSettings = reactive({
|
const sslSettings = reactive({
|
||||||
"type": "0",
|
"type": "0",
|
||||||
"challenge": "http",
|
"challenge": "http",
|
||||||
@@ -74,12 +74,13 @@ export function usePage() {
|
|||||||
"crt_path": "./config/ssl/public.crt",
|
"crt_path": "./config/ssl/public.crt",
|
||||||
"paramsList": [],
|
"paramsList": [],
|
||||||
})
|
})
|
||||||
|
|
||||||
const active = ref(0)
|
const active = ref(0)
|
||||||
|
|
||||||
const fullscreenLoading = ref(false)
|
const fullscreenLoading = ref(false)
|
||||||
|
|
||||||
const databaseLoading = ref(false)
|
const databaseLoading = ref(false)
|
||||||
|
const stepLoading = ref(false)
|
||||||
|
|
||||||
const databaseError = ref("")
|
const databaseError = ref("")
|
||||||
|
|
||||||
@@ -90,26 +91,29 @@ export function usePage() {
|
|||||||
}
|
}
|
||||||
return lang.db_request_failed
|
return lang.db_request_failed
|
||||||
}
|
}
|
||||||
|
|
||||||
const dnsChecking = ref(false)
|
const dnsChecking = ref(false)
|
||||||
|
|
||||||
const dnsInfos = ref({})
|
const dnsInfos = ref({})
|
||||||
|
|
||||||
const hasDNSIPv6 = computed(() => Object.values(dnsInfos.value).some((records) =>
|
const hasDNSIPv6 = computed(() => Object.values(dnsInfos.value).some((records) =>
|
||||||
records.some((record) => record.type === 'AAAA')
|
records.some((record) => record.type === 'AAAA')
|
||||||
))
|
))
|
||||||
|
|
||||||
const port = ref(80)
|
const port = ref(80)
|
||||||
`r`n const sslRuntime = ref({})`r`n
|
const sslRuntime = ref({})
|
||||||
|
|
||||||
const addDomain = () => {
|
const addDomain = () => {
|
||||||
domainSettings.multi_domain.push([])
|
domainSettings.multi_domain.push([])
|
||||||
}
|
}
|
||||||
|
|
||||||
const setPassword = () => {
|
const setPassword = () => {
|
||||||
if (adminSettings.hadSeted) {
|
if (adminSettings.hadSeted) {
|
||||||
active.value++;
|
return getDomainConfig().then((response) => {
|
||||||
getDomainConfig();
|
if (response) {
|
||||||
return;
|
active.value++
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const passwordSize = new TextEncoder().encode(adminSettings.password).length
|
const passwordSize = new TextEncoder().encode(adminSettings.password).length
|
||||||
@@ -130,20 +134,22 @@ export function usePage() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
setupRequest({
|
return setupRequest({
|
||||||
"action": "set",
|
"action": "set",
|
||||||
"step": "password",
|
"step": "password",
|
||||||
"account": adminSettings.account,
|
"account": adminSettings.account,
|
||||||
"password": adminSettings.password
|
"password": adminSettings.password
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
assertSetupSuccess(res)
|
assertSetupSuccess(res)
|
||||||
active.value++
|
return getDomainConfig().then((response) => {
|
||||||
return getDomainConfig()
|
if (response) {
|
||||||
|
active.value++
|
||||||
|
}
|
||||||
|
})
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
showSetupError(error)
|
showSetupError(error)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPassword = () => setupRequest({"action": "get", "step": "password"}).then((res) => {
|
const getPassword = () => setupRequest({"action": "get", "step": "password"}).then((res) => {
|
||||||
assertSetupSuccess(res, lang.db_init_failed)
|
assertSetupSuccess(res, lang.db_init_failed)
|
||||||
adminSettings.hadSeted = res.data != ""
|
adminSettings.hadSeted = res.data != ""
|
||||||
@@ -152,6 +158,7 @@ export function usePage() {
|
|||||||
adminSettings.password = "*******"
|
adminSettings.password = "*******"
|
||||||
adminSettings.password2 = "*******"
|
adminSettings.password2 = "*******"
|
||||||
}
|
}
|
||||||
|
return res
|
||||||
})
|
})
|
||||||
|
|
||||||
const getDbConfig = () => {
|
const getDbConfig = () => {
|
||||||
@@ -165,25 +172,26 @@ export function usePage() {
|
|||||||
dbSettings.port = res.data.db_port || (dbSettings.type === "postgres" ? "5432" : "3306");
|
dbSettings.port = res.data.db_port || (dbSettings.type === "postgres" ? "5432" : "3306");
|
||||||
dbSettings.password = "";
|
dbSettings.password = "";
|
||||||
dbSettings.name = res.data.db_name || "smail";
|
dbSettings.name = res.data.db_name || "smail";
|
||||||
|
return res
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
databaseError.value = getDatabaseErrorMessage(error)
|
databaseError.value = getDatabaseErrorMessage(error)
|
||||||
ElMessage.error(databaseError.value)
|
ElMessage.error(databaseError.value)
|
||||||
|
return null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const getDomainConfig = () => {
|
const getDomainConfig = () => {
|
||||||
return setupRequest({"action": "get", "step": "domain"}).then((res) => {
|
return setupRequest({"action": "get", "step": "domain"}).then((res) => {
|
||||||
assertSetupSuccess(res)
|
assertSetupSuccess(res)
|
||||||
domainSettings.web_domain = res.data.web_domain;
|
domainSettings.web_domain = res.data.web_domain;
|
||||||
domainSettings.smtp_domain = res.data.smtp_domain;
|
domainSettings.smtp_domain = res.data.smtp_domain;
|
||||||
domainSettings.multi_domain = res.data.domains;
|
domainSettings.multi_domain = Array.isArray(res.data.domains) ? res.data.domains : []
|
||||||
return res
|
return res
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
showSetupError(error)
|
showSetupError(error)
|
||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const setDbConfig = () => {
|
const setDbConfig = () => {
|
||||||
if (databaseLoading.value) {
|
if (databaseLoading.value) {
|
||||||
return
|
return
|
||||||
@@ -269,7 +277,7 @@ export function usePage() {
|
|||||||
dbSettings.name = ""
|
dbSettings.name = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getDNSConfig = () => {
|
const getDNSConfig = () => {
|
||||||
return setupRequest({"action": "get", "step": "dns"}).then((res) => {
|
return setupRequest({"action": "get", "step": "dns"}).then((res) => {
|
||||||
assertSetupSuccess(res)
|
assertSetupSuccess(res)
|
||||||
@@ -315,7 +323,7 @@ export function usePage() {
|
|||||||
}
|
}
|
||||||
return `${ttl}${lang.dns_ttl_second}`
|
return `${ttl}${lang.dns_ttl_second}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const getSSLConfig = () => {
|
const getSSLConfig = () => {
|
||||||
return setupRequest({"action": "get", "step": "ssl"}).then((res) => {
|
return setupRequest({"action": "get", "step": "ssl"}).then((res) => {
|
||||||
assertSetupSuccess(res)
|
assertSetupSuccess(res)
|
||||||
@@ -324,24 +332,24 @@ export function usePage() {
|
|||||||
sslSettings.type = "0"
|
sslSettings.type = "0"
|
||||||
sslSettings.challenge = "dns"
|
sslSettings.challenge = "dns"
|
||||||
}
|
}
|
||||||
sslRuntime.value = res.data`r`n port.value = res.data.port || res.data.httpPort || 80
|
sslRuntime.value = res.data || {}
|
||||||
|
port.value = res.data?.port || res.data?.httpPort || 80
|
||||||
return res
|
return res
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
showSetupError(error)
|
showSetupError(error)
|
||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const setSSLConfig = () => {
|
const setSSLConfig = () => {
|
||||||
fullscreenLoading.value = true;
|
fullscreenLoading.value = true;
|
||||||
|
|
||||||
let sslType = sslSettings.type;
|
let sslType = sslSettings.type;
|
||||||
if (sslType === "0" && sslSettings.challenge === "dns") {
|
if (sslType === "0" && sslSettings.challenge === "dns") {
|
||||||
sslType = "2"
|
sslType = "2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return setupRequest({
|
||||||
setupRequest({
|
|
||||||
"action": "set",
|
"action": "set",
|
||||||
"step": "ssl",
|
"step": "ssl",
|
||||||
"ssl_type": sslType,
|
"ssl_type": sslType,
|
||||||
@@ -352,16 +360,20 @@ export function usePage() {
|
|||||||
if (sslType === "2") {
|
if (sslType === "2") {
|
||||||
fullscreenLoading.value = false
|
fullscreenLoading.value = false
|
||||||
dnsChecking.value = true
|
dnsChecking.value = true
|
||||||
getSSLDNSParams()
|
return getSSLDNSParams()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if (sslType === "1") {`r`n window.location.href = buildFinalURL(sslRuntime.value)`r`n return`r`n }`r`n checkStatus()
|
if (sslType === "1") {
|
||||||
|
window.location.href = buildFinalURL(sslRuntime.value)
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
checkStatus()
|
||||||
|
return res
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
fullscreenLoading.value = false
|
fullscreenLoading.value = false
|
||||||
showSetupError(error)
|
showSetupError(error)
|
||||||
|
return null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildFinalURL = (sslData) => {
|
const buildFinalURL = (sslData) => {
|
||||||
const scheme = "https:"
|
const scheme = "https:"
|
||||||
const configuredDomain = String(domainSettings.web_domain || "").trim()
|
const configuredDomain = String(domainSettings.web_domain || "").trim()
|
||||||
@@ -380,7 +392,7 @@ export function usePage() {
|
|||||||
const targetHost = target.hostname.toLowerCase()
|
const targetHost = target.hostname.toLowerCase()
|
||||||
const currentPort = window.location.port
|
const currentPort = window.location.port
|
||||||
const isSameHost = currentHost === targetHost
|
const isSameHost = currentHost === targetHost
|
||||||
const targetPort = sslSettings.type === "1" ? sslData?.httpPort : sslData?.httpsPort
|
const targetPort = Number(sslData?.httpsPort) || 443
|
||||||
const proxyMode = sslData?.tlsMode === "proxy"
|
const proxyMode = sslData?.tlsMode === "proxy"
|
||||||
if (isSameHost && currentPort && !proxyMode) {
|
if (isSameHost && currentPort && !proxyMode) {
|
||||||
target.port = targetPort > 0 ? String(targetPort) : currentPort
|
target.port = targetPort > 0 ? String(targetPort) : currentPort
|
||||||
@@ -393,7 +405,7 @@ export function usePage() {
|
|||||||
target.hash = window.location.hash
|
target.hash = window.location.hash
|
||||||
return target.toString()
|
return target.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkStatus = () => {
|
const checkStatus = () => {
|
||||||
setupRequest({"action": "get", "step": "ssl"}).then((res) => {
|
setupRequest({"action": "get", "step": "ssl"}).then((res) => {
|
||||||
if (res.errorNo === 0 && res.data.ready) {
|
if (res.errorNo === 0 && res.data.ready) {
|
||||||
@@ -405,9 +417,9 @@ export function usePage() {
|
|||||||
setTimeout(checkStatus, 1000)
|
setTimeout(checkStatus, 1000)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const setDomainConfig = () => {
|
const setDomainConfig = () => {
|
||||||
setupRequest({
|
return setupRequest({
|
||||||
"action": "set",
|
"action": "set",
|
||||||
"step": "domain",
|
"step": "domain",
|
||||||
"web_domain": domainSettings.web_domain,
|
"web_domain": domainSettings.web_domain,
|
||||||
@@ -415,13 +427,16 @@ export function usePage() {
|
|||||||
"multi_domain": domainSettings.multi_domain.join(",")
|
"multi_domain": domainSettings.multi_domain.join(",")
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
assertSetupSuccess(res)
|
assertSetupSuccess(res)
|
||||||
active.value++
|
return getDNSConfig().then((response) => {
|
||||||
return getDNSConfig()
|
if (response) {
|
||||||
|
active.value++
|
||||||
|
}
|
||||||
|
})
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
showSetupError(error)
|
showSetupError(error)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const getSSLDNSParams = () => {
|
const getSSLDNSParams = () => {
|
||||||
return setupRequest({"action": "getParams", "step": "ssl"}).then((res) => {
|
return setupRequest({"action": "getParams", "step": "ssl"}).then((res) => {
|
||||||
assertSetupSuccess(res)
|
assertSetupSuccess(res)
|
||||||
@@ -435,42 +450,59 @@ export function usePage() {
|
|||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const runStep = (action) => {
|
||||||
|
if (stepLoading.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
stepLoading.value = true
|
||||||
|
return Promise.resolve()
|
||||||
|
.then(action)
|
||||||
|
.finally(() => {
|
||||||
|
stepLoading.value = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const next = () => {
|
const next = () => {
|
||||||
|
if (databaseLoading.value || stepLoading.value || fullscreenLoading.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
switch (active.value) {
|
switch (active.value) {
|
||||||
case 0:
|
case 0:
|
||||||
active.value++
|
runStep(() => getDbConfig().then((response) => {
|
||||||
getDbConfig();
|
|
||||||
break
|
|
||||||
case 1:
|
|
||||||
setDbConfig();
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
setPassword();
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
setDomainConfig();
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
getSSLConfig().then((response) => {
|
|
||||||
if (response) {
|
if (response) {
|
||||||
active.value++
|
active.value++
|
||||||
}
|
}
|
||||||
})
|
}))
|
||||||
|
break
|
||||||
|
case 1:
|
||||||
|
setDbConfig()
|
||||||
|
break
|
||||||
|
case 2:
|
||||||
|
runStep(setPassword)
|
||||||
|
break
|
||||||
|
case 3:
|
||||||
|
runStep(setDomainConfig)
|
||||||
|
break
|
||||||
|
case 4:
|
||||||
|
runStep(() => getSSLConfig().then((response) => {
|
||||||
|
if (response) {
|
||||||
|
active.value++
|
||||||
|
}
|
||||||
|
}))
|
||||||
break
|
break
|
||||||
case 5:
|
case 5:
|
||||||
if (dnsChecking.value) {
|
if (dnsChecking.value) {
|
||||||
fullscreenLoading.value = true;
|
fullscreenLoading.value = true
|
||||||
waitDesc.value = lang.dns_challenge_wait;
|
waitDesc.value = lang.dns_challenge_wait
|
||||||
checkStatus();
|
checkStatus()
|
||||||
} else {
|
} else {
|
||||||
setSSLConfig();
|
runStep(setSSLConfig)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const previous = () => {
|
const previous = () => {
|
||||||
if (active.value > 0) {
|
if (active.value > 0) {
|
||||||
active.value--
|
active.value--
|
||||||
@@ -489,6 +521,7 @@ export function usePage() {
|
|||||||
adminSettings,
|
adminSettings,
|
||||||
dbSettings,
|
dbSettings,
|
||||||
databaseLoading,
|
databaseLoading,
|
||||||
|
stepLoading,
|
||||||
databaseError,
|
databaseError,
|
||||||
domainSettings,
|
domainSettings,
|
||||||
sslSettings,
|
sslSettings,
|
||||||
|
|||||||
@@ -334,7 +334,7 @@
|
|||||||
<el-button v-if="active > 0" id="previous" @click="previous">
|
<el-button v-if="active > 0" id="previous" @click="previous">
|
||||||
{{ lang.previous }}
|
{{ lang.previous }}
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button :loading="databaseLoading" :disabled="databaseLoading"
|
<el-button :loading="databaseLoading || stepLoading" :disabled="databaseLoading || stepLoading || fullscreenLoading"
|
||||||
:element-loading-text="waitDesc"
|
:element-loading-text="waitDesc"
|
||||||
v-loading.fullscreen.lock="fullscreenLoading" id="next"
|
v-loading.fullscreen.lock="fullscreenLoading" id="next"
|
||||||
@click="next">
|
@click="next">
|
||||||
@@ -353,6 +353,7 @@ const {
|
|||||||
lang,
|
lang,
|
||||||
dbSettings,
|
dbSettings,
|
||||||
databaseLoading,
|
databaseLoading,
|
||||||
|
stepLoading,
|
||||||
databaseError,
|
databaseError,
|
||||||
adminSettings,
|
adminSettings,
|
||||||
domainSettings,
|
domainSettings,
|
||||||
|
|||||||
Reference in new issue
Block a user