Skip to content

Commit d289fd5

Browse files
committed
增加云模块
1 parent 262febf commit d289fd5

File tree

5 files changed

+137
-1
lines changed

5 files changed

+137
-1
lines changed

server/api/v1/system/enter.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package system
22

3-
import "github.com/flipped-aurora/gin-vue-admin/server/service"
3+
import (
4+
"github.com/flipped-aurora/gin-vue-admin/server/service"
5+
)
46

57
type ApiGroup struct {
68
DBApi
@@ -18,6 +20,7 @@ type ApiGroup struct {
1820
DictionaryDetailApi
1921
AuthorityBtnApi
2022
SysExportTemplateApi
23+
PublicApi
2124
}
2225

2326
var (

server/api/v1/system/sys_cloud.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package system
2+
3+
import (
4+
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
5+
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
6+
"github.com/gin-gonic/gin"
7+
)
8+
9+
type CloudApi struct{}
10+
11+
func (public *CloudApi) Install(c *gin.Context) {
12+
13+
}
14+
15+
func (public *CloudApi) Public(c *gin.Context) {
16+
var p request.PublicReq
17+
_ = c.ShouldBindJSON(&p)
18+
client, err := p.SSHConnect()
19+
if err != nil {
20+
return
21+
}
22+
23+
session, err := client.NewSession()
24+
if err != nil {
25+
response.FailWithMessage("创建会话失败"+err.Error(), c)
26+
return
27+
}
28+
defer session.Close()
29+
30+
// Run a remote command
31+
output, err := session.CombinedOutput("ls")
32+
if err != nil {
33+
response.FailWithMessage("创建会话失败"+err.Error(), c)
34+
return
35+
}
36+
37+
response.OkWithDetailed(string(output), "设置成功", c)
38+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package request
2+
3+
import (
4+
"errors"
5+
"golang.org/x/crypto/ssh"
6+
)
7+
8+
type PublicReq struct {
9+
SSHPort string `json:"sshPort" form:"sshPort"`
10+
SSHUser string `json:"sshUser" form:"sshUser"`
11+
SSHPassword string `json:"sshPassword" form:"sshPassword"`
12+
SSHIp string `json:"sshIp" form:"sshIp"`
13+
}
14+
15+
func (p *PublicReq) SSHConnect() (client *ssh.Client, err error) {
16+
config := &ssh.ClientConfig{
17+
User: p.SSHUser,
18+
Auth: []ssh.AuthMethod{
19+
ssh.Password(p.SSHPassword),
20+
},
21+
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
22+
}
23+
24+
client, err = ssh.Dial("tcp", p.SSHIp+":"+p.SSHPort, config)
25+
if err != nil {
26+
err = errors.New("Failed to dial:" + err.Error())
27+
}
28+
return
29+
}

server/model/system/sys_public.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package system
2+
3+
import "golang.org/x/crypto/ssh"
4+
5+
type SSH interface {
6+
SSHConnect() (client *ssh.Client, err error)
7+
}

web/src/view/cloud/public/public.vue

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<template>
2+
<div>
3+
<warning-bar title="本功能可以用于一键发布程序。" />
4+
<div class="gva-form-box">
5+
<el-form
6+
ref="publicForm"
7+
label-position="right"
8+
label-width="80px"
9+
:model="form"
10+
>
11+
12+
<el-form-item label="sshIP">
13+
<el-input v-model="form.sshIp" />
14+
</el-form-item>
15+
<el-form-item label="sshPort">
16+
<el-input v-model="form.sshPort" />
17+
</el-form-item>
18+
<el-form-item label="用户名">
19+
<el-input v-model="form.sshUser" />
20+
</el-form-item>
21+
<el-form-item label="密码">
22+
<el-input v-model="form.sshPassword" />
23+
</el-form-item>
24+
<el-form-item>
25+
<el-button @click="test">测试连接</el-button>
26+
</el-form-item>
27+
</el-form>
28+
</div>
29+
</div>
30+
31+
</template>
32+
33+
<script setup>
34+
import WarningBar from '@/components/warningBar/warningBar.vue'
35+
import { emailTest } from '@/plugin/email/api/email.js'
36+
import { ElMessage } from 'element-plus'
37+
import { reactive, ref } from 'vue'
38+
39+
defineOptions({
40+
name: 'Email',
41+
})
42+
43+
const publicForm = ref(null)
44+
const form = reactive({
45+
sshPort: '',
46+
sshUser: '',
47+
sshPassword: '',
48+
sshIp: ''
49+
})
50+
51+
const test = async() => {
52+
const res = await emailTest()
53+
if (res.code === 0) {
54+
ElMessage.success('连接成功')
55+
}
56+
}
57+
58+
</script>
59+

0 commit comments

Comments
 (0)