mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 05:00:25 +08:00 
			
		
		
		
	[SSL证书]实现基本的自动申请证书流程
This commit is contained in:
		@@ -4,6 +4,7 @@ import (
 | 
				
			|||||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
						"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
						"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
				
			||||||
	"github.com/iwind/TeaGo/maps"
 | 
						"github.com/iwind/TeaGo/maps"
 | 
				
			||||||
 | 
						timeutil "github.com/iwind/TeaGo/utils/time"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type IndexAction struct {
 | 
					type IndexAction struct {
 | 
				
			||||||
@@ -48,8 +49,10 @@ func (this *IndexAction) RunGet(params struct{}) {
 | 
				
			|||||||
		var certMap maps.Map = nil
 | 
							var certMap maps.Map = nil
 | 
				
			||||||
		if task.SslCert != nil {
 | 
							if task.SslCert != nil {
 | 
				
			||||||
			certMap = maps.Map{
 | 
								certMap = maps.Map{
 | 
				
			||||||
				"id":   task.SslCert.Id,
 | 
									"id":        task.SslCert.Id,
 | 
				
			||||||
				"name": task.SslCert.Name,
 | 
									"name":      task.SslCert.Name,
 | 
				
			||||||
 | 
									"beginTime": timeutil.FormatTime("Y-m-d", task.SslCert.TimeBeginAt),
 | 
				
			||||||
 | 
									"endTime":   timeutil.FormatTime("Y-m-d", task.SslCert.TimeEndAt),
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,14 +2,26 @@ package acme
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
						"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
				
			||||||
	"time"
 | 
						"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type RunAction struct {
 | 
					type RunAction struct {
 | 
				
			||||||
	actionutils.ParentAction
 | 
						actionutils.ParentAction
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (this *RunAction) RunPost(params struct{}) {
 | 
					func (this *RunAction) RunPost(params struct {
 | 
				
			||||||
	time.Sleep(5 * time.Second) // TODO
 | 
						TaskId int64
 | 
				
			||||||
	this.Success()
 | 
					}) {
 | 
				
			||||||
 | 
						runResp, err := this.RPC().ACMETaskRPC().RunACMETask(this.AdminContext(), &pb.RunACMETaskRequest{AcmeTaskId: params.TaskId})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							this.ErrorPage(err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if runResp.IsOk {
 | 
				
			||||||
 | 
							this.Data["certId"] = runResp.SslCertId
 | 
				
			||||||
 | 
							this.Success()
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							this.Fail(runResp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,3 +18,7 @@ Vue.component("tiny-basic-label", {
 | 
				
			|||||||
	template: `<span class="ui label tiny basic" style="margin-bottom: 0.5em"><slot></slot></span>`
 | 
						template: `<span class="ui label tiny basic" style="margin-bottom: 0.5em"><slot></slot></span>`
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 更小的标签
 | 
				
			||||||
 | 
					Vue.component("micro-basic-label", {
 | 
				
			||||||
 | 
						template: `<span class="ui label tiny basic" style="margin-bottom: 0.5em; font-size: 0.7em; padding: 4px"><slot></slot></span>`
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -103,7 +103,7 @@
 | 
				
			|||||||
			<div class="button-group">
 | 
								<div class="button-group">
 | 
				
			||||||
				<button type="button" class="ui button" @click.prevent="goUser">上一步</button>
 | 
									<button type="button" class="ui button" @click.prevent="goUser">上一步</button>
 | 
				
			||||||
				<button type="button" class="ui button primary" @click.prevent="doDNS" v-if="!isRequesting">下一步</button>
 | 
									<button type="button" class="ui button primary" @click.prevent="doDNS" v-if="!isRequesting">下一步</button>
 | 
				
			||||||
				<button type="button" class="ui button primary disabled" v-if="isRequesting">提交中...</button>
 | 
									<button type="button" class="ui button primary disabled" v-if="isRequesting">提交中,要花费的时间较长,请耐心等待...</button>
 | 
				
			||||||
			</div>
 | 
								</div>
 | 
				
			||||||
		</div>
 | 
							</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -82,6 +82,7 @@ Tea.context(function () {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
				this.isRequesting = true
 | 
									this.isRequesting = true
 | 
				
			||||||
				this.$post(".run")
 | 
									this.$post(".run")
 | 
				
			||||||
 | 
										.timeout(300)
 | 
				
			||||||
					.params({
 | 
										.params({
 | 
				
			||||||
						taskId: this.taskId
 | 
											taskId: this.taskId
 | 
				
			||||||
					})
 | 
										})
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	<p class="comment" v-if="tasks.length == 0">暂时还没有证书申请任务。</p>
 | 
						<p class="comment" v-if="tasks.length == 0">暂时还没有证书申请任务。</p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						<div class="ui message blue" v-if="isRunning">有任务在执行中,可能需要的时间较长,请耐心等待。</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	<table class="ui table selectable" v-if="tasks.length > 0">
 | 
						<table class="ui table selectable" v-if="tasks.length > 0">
 | 
				
			||||||
		<thead>
 | 
							<thead>
 | 
				
			||||||
			<tr>
 | 
								<tr>
 | 
				
			||||||
@@ -19,7 +21,7 @@
 | 
				
			|||||||
				<th class="three op">操作</th>
 | 
									<th class="three op">操作</th>
 | 
				
			||||||
			</tr>
 | 
								</tr>
 | 
				
			||||||
		</thead>
 | 
							</thead>
 | 
				
			||||||
		<tr v-for="task in tasks">
 | 
							<tr v-for="(task, index) in tasks" :class="{warning: runningIndex == index}">
 | 
				
			||||||
			<td>{{task.acmeUser.email}}</td>
 | 
								<td>{{task.acmeUser.email}}</td>
 | 
				
			||||||
			<td>{{task.dnsProvider.name}}</td>
 | 
								<td>{{task.dnsProvider.name}}</td>
 | 
				
			||||||
			<td>{{task.dnsDomain}}</td>
 | 
								<td>{{task.dnsDomain}}</td>
 | 
				
			||||||
@@ -29,7 +31,10 @@
 | 
				
			|||||||
				</div>
 | 
									</div>
 | 
				
			||||||
			</td>
 | 
								</td>
 | 
				
			||||||
			<td>
 | 
								<td>
 | 
				
			||||||
 | 
									<div v-if="task.cert != null">
 | 
				
			||||||
 | 
										{{task.cert.endTime}}
 | 
				
			||||||
 | 
									</div>
 | 
				
			||||||
 | 
									<span class="disabled" v-else>-</span>
 | 
				
			||||||
			</td>
 | 
								</td>
 | 
				
			||||||
			<td class="center">
 | 
								<td class="center">
 | 
				
			||||||
				<span class="green" v-if="task.autoRenew">Y</span>
 | 
									<span class="green" v-if="task.autoRenew">Y</span>
 | 
				
			||||||
@@ -37,14 +42,14 @@
 | 
				
			|||||||
			</td>
 | 
								</td>
 | 
				
			||||||
			<td>
 | 
								<td>
 | 
				
			||||||
				<div v-if="task.cert != null">
 | 
									<div v-if="task.cert != null">
 | 
				
			||||||
					<a href="" @click.prevent="viewCert(task.cert.id)">{{task.cert.name}}</a>
 | 
										{{task.cert.name}}<a href="" @click.prevent="viewCert(task.cert.id)"><link-icon></link-icon></a>
 | 
				
			||||||
				</div>
 | 
									</div>
 | 
				
			||||||
				<span class="disabled" v-else="">-</span>
 | 
									<span class="disabled" v-else="">-</span>
 | 
				
			||||||
			</td>
 | 
								</td>
 | 
				
			||||||
			<td>
 | 
								<td>
 | 
				
			||||||
				<a href="" @click.prevent="updateTask(task.id)">修改</a>  
 | 
									<a href="" @click.prevent="updateTask(task.id)" :class="{disabled: isRunning}">修改</a>  
 | 
				
			||||||
				<a href="">执行</a>  
 | 
									<a href="" @click.prevent="runTask(index, task)" :class="{disabled: isRunning}">执行</a>  
 | 
				
			||||||
				<a href="" @click.prevent="deleteTask(task.id)">删除</a>
 | 
									<a href="" @click.prevent="deleteTask(task.id)" :class="{disabled: isRunning}">删除</a>
 | 
				
			||||||
			</td>
 | 
								</td>
 | 
				
			||||||
		</tr>
 | 
							</tr>
 | 
				
			||||||
	</table>
 | 
						</table>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,4 +27,32 @@ Tea.context(function () {
 | 
				
			|||||||
				.refresh()
 | 
									.refresh()
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						this.isRunning = false
 | 
				
			||||||
 | 
						this.runningIndex = -1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						this.runTask = function (index, task) {
 | 
				
			||||||
 | 
							let that = this
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							teaweb.confirm("确定要立即执行此任务吗?", function () {
 | 
				
			||||||
 | 
								that.isRunning = true
 | 
				
			||||||
 | 
								that.runningIndex = index
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								that.$post(".run")
 | 
				
			||||||
 | 
									.timeout(300)
 | 
				
			||||||
 | 
									.params({
 | 
				
			||||||
 | 
										taskId: task.id
 | 
				
			||||||
 | 
									})
 | 
				
			||||||
 | 
									.success(function (resp) {
 | 
				
			||||||
 | 
										teaweb.success("执行成功", function () {
 | 
				
			||||||
 | 
											teaweb.reload()
 | 
				
			||||||
 | 
										})
 | 
				
			||||||
 | 
									})
 | 
				
			||||||
 | 
									.done(function () {
 | 
				
			||||||
 | 
										that.isRunning = false
 | 
				
			||||||
 | 
										that.runningIndex = -1
 | 
				
			||||||
 | 
									})
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
@@ -30,7 +30,10 @@
 | 
				
			|||||||
		<tr v-for="(cert, index) in certs">
 | 
							<tr v-for="(cert, index) in certs">
 | 
				
			||||||
			<td>{{cert.name}}
 | 
								<td>{{cert.name}}
 | 
				
			||||||
				<div v-if="cert.isCA" style="margin-top:0.5em">
 | 
									<div v-if="cert.isCA" style="margin-top:0.5em">
 | 
				
			||||||
					<span class="ui label olive tiny">CA</span>
 | 
										<micro-basic-label :class="olive">CA</micro-basic-label>
 | 
				
			||||||
 | 
									</div>
 | 
				
			||||||
 | 
									<div v-if="cert.isACME" style="margin-top: 0.5em">
 | 
				
			||||||
 | 
										<micro-basic-label class="olive" title="通过ACME协议免费申请">ACME</micro-basic-label>
 | 
				
			||||||
				</div>
 | 
									</div>
 | 
				
			||||||
			</td>
 | 
								</td>
 | 
				
			||||||
			<td>
 | 
								<td>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user