mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-12 02:45:49 +02:00
fix: failed to issue cert after switching mode from advance to basic #704
This commit is contained in:
parent
187dd12f36
commit
c8471f94ec
2 changed files with 55 additions and 43 deletions
|
@ -38,7 +38,6 @@ func TokenizeNginxConfig(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, ngxConfig)
|
c.JSON(http.StatusOK, ngxConfig)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FormatNginxConfig(c *gin.Context) {
|
func FormatNginxConfig(c *gin.Context) {
|
||||||
|
|
|
@ -27,85 +27,97 @@ const ngx_config: NgxConfig = reactive({
|
||||||
|
|
||||||
const certInfoMap: Ref<Record<number, CertificateInfo[]>> = ref({})
|
const certInfoMap: Ref<Record<number, CertificateInfo[]>> = ref({})
|
||||||
|
|
||||||
const auto_cert = ref(false)
|
const autoCert = ref(false)
|
||||||
const enabled = ref(false)
|
const enabled = ref(false)
|
||||||
const filepath = ref('')
|
const filepath = ref('')
|
||||||
const configText = ref('')
|
const configText = ref('')
|
||||||
const advance_mode_ref = ref(false)
|
const advanceModeRef = ref(false)
|
||||||
const saving = ref(false)
|
const saving = ref(false)
|
||||||
const filename = ref('')
|
const filename = ref('')
|
||||||
const parse_error_status = ref(false)
|
const parseErrorStatus = ref(false)
|
||||||
const parse_error_message = ref('')
|
const parseErrorMessage = ref('')
|
||||||
const data = ref({}) as Ref<Site>
|
const data = ref({}) as Ref<Site>
|
||||||
|
const historyChatgptRecord = ref([]) as Ref<ChatComplicationMessage[]>
|
||||||
|
const loading = ref(true)
|
||||||
|
|
||||||
init()
|
onMounted(init)
|
||||||
|
|
||||||
const advanceMode = computed({
|
const advanceMode = computed({
|
||||||
get() {
|
get() {
|
||||||
return advance_mode_ref.value || parse_error_status.value
|
return advanceModeRef.value || parseErrorStatus.value
|
||||||
},
|
},
|
||||||
set(v: boolean) {
|
set(v: boolean) {
|
||||||
advance_mode_ref.value = v
|
advanceModeRef.value = v
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const history_chatgpt_record = ref([]) as Ref<ChatComplicationMessage[]>
|
async function handleResponse(r: Site) {
|
||||||
|
|
||||||
function handle_response(r: Site) {
|
|
||||||
if (r.advanced)
|
if (r.advanced)
|
||||||
advanceMode.value = true
|
advanceMode.value = true
|
||||||
|
|
||||||
if (r.advanced)
|
parseErrorStatus.value = false
|
||||||
advanceMode.value = true
|
parseErrorMessage.value = ''
|
||||||
|
|
||||||
parse_error_status.value = false
|
|
||||||
parse_error_message.value = ''
|
|
||||||
filename.value = r.name
|
filename.value = r.name
|
||||||
filepath.value = r.filepath
|
filepath.value = r.filepath
|
||||||
configText.value = r.config
|
configText.value = r.config
|
||||||
enabled.value = r.enabled
|
enabled.value = r.enabled
|
||||||
auto_cert.value = r.auto_cert
|
autoCert.value = r.auto_cert
|
||||||
history_chatgpt_record.value = r.chatgpt_messages
|
historyChatgptRecord.value = r.chatgpt_messages
|
||||||
data.value = r
|
data.value = r
|
||||||
certInfoMap.value = r.cert_info || {}
|
certInfoMap.value = r.cert_info || {}
|
||||||
Object.assign(ngx_config, r.tokenized)
|
Object.assign(ngx_config, r.tokenized)
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
async function init() {
|
||||||
|
loading.value = true
|
||||||
if (name.value) {
|
if (name.value) {
|
||||||
site.get(name.value).then(r => {
|
await site.get(name.value).then(r => {
|
||||||
handle_response(r)
|
handleResponse(r)
|
||||||
}).catch(handle_parse_error)
|
}).catch(handleParseError)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
history_chatgpt_record.value = []
|
historyChatgptRecord.value = []
|
||||||
}
|
}
|
||||||
|
loading.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle_parse_error(e: { error?: string, message: string }) {
|
function handleParseError(e: { error?: string, message: string }) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
parse_error_status.value = true
|
parseErrorStatus.value = true
|
||||||
parse_error_message.value = e.message
|
parseErrorMessage.value = e.message
|
||||||
config.get(`sites-available/${name.value}`).then(r => {
|
config.get(`sites-available/${name.value}`).then(r => {
|
||||||
configText.value = r.content
|
configText.value = r.content
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_mode_change(advanced: CheckedType) {
|
async function onModeChange(advanced: CheckedType) {
|
||||||
site.advance_mode(name.value, { advanced: advanced as boolean }).then(() => {
|
loading.value = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
await site.advance_mode(name.value, { advanced: advanced as boolean })
|
||||||
advanceMode.value = advanced as boolean
|
advanceMode.value = advanced as boolean
|
||||||
if (advanced) {
|
if (advanced) {
|
||||||
build_config()
|
await buildConfig()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return ngx.tokenize_config(configText.value).then(r => {
|
let r = await site.get(name.value)
|
||||||
Object.assign(ngx_config, r)
|
await handleResponse(r)
|
||||||
}).catch(handle_parse_error)
|
r = await ngx.tokenize_config(configText.value)
|
||||||
|
Object.assign(ngx_config, {
|
||||||
|
...r,
|
||||||
|
name: name.value,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
// eslint-disable-next-line ts/no-explicit-any
|
||||||
|
catch (e: any) {
|
||||||
|
handleParseError(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
async function build_config() {
|
async function buildConfig() {
|
||||||
return ngx.build_config(ngx_config).then(r => {
|
return ngx.build_config(ngx_config).then(r => {
|
||||||
configText.value = r.content
|
configText.value = r.content
|
||||||
})
|
})
|
||||||
|
@ -116,7 +128,7 @@ async function save() {
|
||||||
|
|
||||||
if (!advanceMode.value) {
|
if (!advanceMode.value) {
|
||||||
try {
|
try {
|
||||||
await build_config()
|
await buildConfig()
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
saving.value = false
|
saving.value = false
|
||||||
|
@ -132,13 +144,13 @@ async function save() {
|
||||||
site_category_id: data.value.site_category_id,
|
site_category_id: data.value.site_category_id,
|
||||||
sync_node_ids: data.value.sync_node_ids,
|
sync_node_ids: data.value.sync_node_ids,
|
||||||
}).then(r => {
|
}).then(r => {
|
||||||
handle_response(r)
|
handleResponse(r)
|
||||||
router.push({
|
router.push({
|
||||||
path: `/sites/${filename.value}`,
|
path: `/sites/${filename.value}`,
|
||||||
query: route.query,
|
query: route.query,
|
||||||
})
|
})
|
||||||
message.success($gettext('Saved successfully'))
|
message.success($gettext('Saved successfully'))
|
||||||
}).catch(handle_parse_error).finally(() => {
|
}).catch(handleParseError).finally(() => {
|
||||||
saving.value = false
|
saving.value = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -146,7 +158,7 @@ async function save() {
|
||||||
provide('save_config', save)
|
provide('save_config', save)
|
||||||
provide('configText', configText)
|
provide('configText', configText)
|
||||||
provide('ngx_config', ngx_config)
|
provide('ngx_config', ngx_config)
|
||||||
provide('history_chatgpt_record', history_chatgpt_record)
|
provide('history_chatgpt_record', historyChatgptRecord)
|
||||||
provide('enabled', enabled)
|
provide('enabled', enabled)
|
||||||
provide('name', name)
|
provide('name', name)
|
||||||
provide('filepath', filepath)
|
provide('filepath', filepath)
|
||||||
|
@ -182,9 +194,10 @@ provide('data', data)
|
||||||
<div class="switch">
|
<div class="switch">
|
||||||
<ASwitch
|
<ASwitch
|
||||||
size="small"
|
size="small"
|
||||||
:disabled="parse_error_status"
|
:disabled="parseErrorStatus"
|
||||||
:checked="advanceMode"
|
:checked="advanceMode"
|
||||||
@change="on_mode_change"
|
:loading
|
||||||
|
@change="onModeChange"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<template v-if="advanceMode">
|
<template v-if="advanceMode">
|
||||||
|
@ -202,12 +215,12 @@ provide('data', data)
|
||||||
key="advance"
|
key="advance"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
v-if="parse_error_status"
|
v-if="parseErrorStatus"
|
||||||
class="parse-error-alert-wrapper"
|
class="parse-error-alert-wrapper"
|
||||||
>
|
>
|
||||||
<AAlert
|
<AAlert
|
||||||
:message="$gettext('Nginx Configuration Parse Error')"
|
:message="$gettext('Nginx Configuration Parse Error')"
|
||||||
:description="parse_error_message"
|
:description="parseErrorMessage"
|
||||||
type="error"
|
type="error"
|
||||||
show-icon
|
show-icon
|
||||||
/>
|
/>
|
||||||
|
@ -223,7 +236,7 @@ provide('data', data)
|
||||||
class="domain-edit-container"
|
class="domain-edit-container"
|
||||||
>
|
>
|
||||||
<NgxConfigEditor
|
<NgxConfigEditor
|
||||||
v-model:auto-cert="auto_cert"
|
v-model:auto-cert="autoCert"
|
||||||
:cert-info="certInfoMap"
|
:cert-info="certInfoMap"
|
||||||
:enabled="enabled"
|
:enabled="enabled"
|
||||||
@callback="save"
|
@callback="save"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue