使用 lego 取代 acme.sh

This commit is contained in:
Jacky 2021-07-20 17:30:25 +08:00
parent d60701256e
commit 1696846a1f
22 changed files with 849 additions and 160 deletions

View file

@ -1,6 +1,6 @@
{
"name": "nginx-ui-frontend",
"version": "0.1.0",
"version": "0.1.1",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",

View file

@ -29,6 +29,10 @@ const domain = {
get_template(name) {
return http.get('template/' + name)
},
cert_info(domain) {
return http.get('cert/' + domain + '/info')
}
}

View file

@ -46,7 +46,8 @@ import {
Tooltip,
Transfer,
Upload,
Switch
Switch,
Space
} from 'ant-design-vue'
Vue.use(ConfigProvider)
@ -95,6 +96,7 @@ Vue.use(Descriptions)
Vue.use(Result)
Vue.use(pageHeader)
Vue.use(Switch)
Vue.use(Space)
Vue.prototype.$confirm = Modal.confirm
Vue.prototype.$message = message

View file

@ -36,11 +36,11 @@ export const routes = [
}, {
path: 'add',
name: '添加站点',
component: () => import('@/views/DomainEdit.vue'),
component: () => import('@/views/domain_edit/DomainEdit.vue'),
}, {
path: ':name',
name: '编辑站点',
component: () => import('@/views/DomainEdit.vue'),
component: () => import('@/views/domain_edit/DomainEdit.vue'),
meta: {
hiddenInSidebar: true
}

View file

@ -2,7 +2,7 @@
<a-card>
<h2>Nginx UI</h2>
<p>Yet another WebUI for Nginx</p>
<p>Version: {{ version }}-{{ build_id }}</p>
<p>Version: {{ version }} ({{ build_id }})</p>
<h3>项目组</h3>
<p>Designer<a href="https://jackyu.cn/">@0xJacky</a></p>
<h3>技术栈</h3>
@ -24,7 +24,7 @@ export default {
return {
this_year: date.getFullYear(),
version: process.env.VUE_APP_VERSION,
build_id: process.env.VUE_APP_BUILD_ID ? process.env.VUE_APP_BUILD_ID : 'dev',
build_id: process.env.VUE_APP_BUILD_ID ? process.env.VUE_APP_BUILD_ID : '开发模式',
api_root: process.env.VUE_APP_API_ROOT
}
},

View file

@ -0,0 +1,57 @@
<template>
<div v-if="ok">
<h3>证书状态</h3>
<p>中级证书颁发机构{{ cert.issuer_name }}</p>
<p>证书名称{{ cert.subject_name }}</p>
<p>过期时间{{ moment(cert.not_after).format('YYYY-MM-DD HH:mm:ss') }}</p>
<p>在此之前无效{{ moment(cert.not_before).format('YYYY-MM-DD HH:mm:ss') }}</p>
<template v-if="new Date().toISOString() < cert.not_before || new Date().toISOString() > cert.not_after">
<a-icon :style="{ color: 'red' }" type="close-circle" /> 此证书已过期
</template>
<template v-else>
<a-icon :style="{ color: 'green' }" type="check-circle" /> 证书处在有效期内
</template>
</div>
</template>
<script>
import moment from "moment"
export default {
name: "CertInfo",
data() {
return {
ok: false,
cert: {},
moment
}
},
props: {
domain: String
},
created() {
this.get()
},
watch: {
domain() {
this.get()
}
},
methods: {
get() {
this.$api.domain.cert_info(this.domain).then(r => {
this.cert = r
this.ok = true
}).catch(e => {
this.$message.error('无法解析 ' + this.domain + ' 的证书信息')
console.error(e)
this.ok = false
})
}
}
}
</script>
<style scoped>
</style>

View file

@ -4,7 +4,13 @@
<a-card :title="name ? '编辑站点:' + name : '添加站点'">
<p>您的配置文件中应当有对应的字段时下列表单中的设置才能生效</p>
<std-data-entry :data-list="columns" v-model="config" @change_support_ssl="change_support_ssl"/>
<a-button @click="issue_cert" type="primary" v-show="config.support_ssl" ghost>自动申请 Let's Encrypt 证书</a-button>
<cert-info :domain="name"/>
<br/>
<a-space>
<a-button @click="issue_cert" type="primary" ghost>
自动申请 Let's Encrypt 证书
</a-button>
</a-space>
</a-card>
</a-col>
<a-col :md="12" :sm="24">
@ -21,70 +27,13 @@
<script>
import StdDataEntry from "@/components/StdDataEntry/StdDataEntry"
import FooterToolBar from "@/components/FooterToolbar/FooterToolBar"
import VueItextarea from "@/components/VueItextarea/VueItextarea";
const columns = [{
title: "配置文件名称",
dataIndex: "name",
edit: {
type: "input"
}
}, {
title: "网站域名 (server_name)",
dataIndex: "server_name",
edit: {
type: "input"
}
}, {
title: "网站根目录 (root)",
dataIndex: "root",
edit: {
type: "input"
}
}, {
title: "网站首页 (index)",
dataIndex: "index",
edit: {
type: "input"
}
}, {
title: "http 监听端口",
dataIndex: "http_listen_port",
edit: {
type: "number",
min: 80
}
}, {
title: "支持 SSL",
dataIndex: "support_ssl",
edit: {
type: "switch",
event: "change_support_ssl"
}
}, {
title: "https 监听端口",
dataIndex: "https_listen_port",
edit: {
type: "number",
min: 443
}
}, {
title: "SSL 证书路径 (ssl_certificate)",
dataIndex: "ssl_certificate",
edit: {
type: "input"
}
}, {
title: "SSL 证书私钥路径 (ssl_certificate_key)",
dataIndex: "ssl_certificate_key",
edit: {
type: "input"
}
}]
import VueItextarea from "@/components/VueItextarea/VueItextarea"
import columns from "@/views/domain_edit/columns"
import CertInfo from "@/views/domain_edit/CertInfo";
export default {
name: "DomainEdit",
components: {FooterToolBar, StdDataEntry, VueItextarea},
components: {CertInfo, FooterToolBar, StdDataEntry, VueItextarea},
data() {
return {
name: this.$route.params.name,
@ -233,27 +182,26 @@ export default {
})
},
issue_cert() {
this.$message.info("请注意,当前配置中 server_name 必须为需要申请证书的域名,否则无法申请", 5)
this.$message.info("正在申请,请稍后")
this.$message.info("请注意,当前配置中 server_name 必须为需要申请证书的域名,否则无法申请", 15)
this.$message.info("正在申请,请稍后",15)
this.ws = new WebSocket(this.getWebSocketRoot() + "/cert/issue/" + this.config.server_name
+ "?token=" + btoa(this.$store.state.user.token))
this.ws.onopen = () => {
this.ws.send("ping")
this.ws.send("go")
}
this.ws.onmessage = m => {
const r = JSON.parse(m.data)
console.log(r)
switch (r.status) {
case "success":
this.$message.success(r.message, 5)
this.$message.success(r.message, 10)
break
case "info":
this.$message.info(r.message, 5)
this.$message.info(r.message, 10)
break
case "error":
this.$message.error(r.message, 5)
this.$message.error(r.message, 10)
break
}

View file

@ -0,0 +1,60 @@
const columns = [{
title: "配置文件名称",
dataIndex: "name",
edit: {
type: "input"
}
}, {
title: "网站域名 (server_name)",
dataIndex: "server_name",
edit: {
type: "input"
}
}, {
title: "网站根目录 (root)",
dataIndex: "root",
edit: {
type: "input"
}
}, {
title: "网站首页 (index)",
dataIndex: "index",
edit: {
type: "input"
}
}, {
title: "http 监听端口",
dataIndex: "http_listen_port",
edit: {
type: "number",
min: 80
}
}, {
title: "支持 SSL",
dataIndex: "support_ssl",
edit: {
type: "switch",
event: "change_support_ssl"
}
}, {
title: "https 监听端口",
dataIndex: "https_listen_port",
edit: {
type: "number",
min: 443
}
}, {
title: "SSL 证书路径 (ssl_certificate)",
dataIndex: "ssl_certificate",
edit: {
type: "input"
}
}, {
title: "SSL 证书私钥路径 (ssl_certificate_key)",
dataIndex: "ssl_certificate_key",
edit: {
type: "input"
}
}]
export default columns