mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 08:20:25 +08:00 
			
		
		
		
	Compare commits
	
		
			5 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					f0540559bb | ||
| 
						 | 
					802e379f60 | ||
| 
						 | 
					8c9253da80 | ||
| 
						 | 
					5271bd21e8 | ||
| 
						 | 
					db554ebdc9 | 
							
								
								
									
										36
									
								
								README.en.md
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								README.en.md
									
									
									
									
									
								
							@@ -1,36 +0,0 @@
 | 
				
			|||||||
# mayfly-go
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#### Description
 | 
					 | 
				
			||||||
golang实现linux运维等
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#### Software Architecture
 | 
					 | 
				
			||||||
Software architecture description
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#### Installation
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
1.  xxxx
 | 
					 | 
				
			||||||
2.  xxxx
 | 
					 | 
				
			||||||
3.  xxxx
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#### Instructions
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
1.  xxxx
 | 
					 | 
				
			||||||
2.  xxxx
 | 
					 | 
				
			||||||
3.  xxxx
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#### Contribution
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
1.  Fork the repository
 | 
					 | 
				
			||||||
2.  Create Feat_xxx branch
 | 
					 | 
				
			||||||
3.  Commit your code
 | 
					 | 
				
			||||||
4.  Create Pull Request
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#### Gitee Feature
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
1.  You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
 | 
					 | 
				
			||||||
2.  Gitee blog [blog.gitee.com](https://blog.gitee.com)
 | 
					 | 
				
			||||||
3.  Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
 | 
					 | 
				
			||||||
4.  The most valuable open source project [GVP](https://gitee.com/gvp)
 | 
					 | 
				
			||||||
5.  The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
 | 
					 | 
				
			||||||
6.  The most popular members  [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
 | 
					 | 
				
			||||||
							
								
								
									
										5123
									
								
								mayfly_go_web/package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										5123
									
								
								mayfly_go_web/package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -14,6 +14,7 @@
 | 
				
			|||||||
    "cropperjs": "^1.5.11",
 | 
					    "cropperjs": "^1.5.11",
 | 
				
			||||||
    "echarts": "^5.3.3",
 | 
					    "echarts": "^5.3.3",
 | 
				
			||||||
    "element-plus": "^2.2.9",
 | 
					    "element-plus": "^2.2.9",
 | 
				
			||||||
 | 
					    "jsencrypt": "^3.2.1",
 | 
				
			||||||
    "jsoneditor": "^9.9.0",
 | 
					    "jsoneditor": "^9.9.0",
 | 
				
			||||||
    "lodash": "^4.17.21",
 | 
					    "lodash": "^4.17.21",
 | 
				
			||||||
    "mitt": "^3.0.0",
 | 
					    "mitt": "^3.0.0",
 | 
				
			||||||
@@ -23,7 +24,7 @@
 | 
				
			|||||||
    "sql-formatter": "^7.0.3",
 | 
					    "sql-formatter": "^7.0.3",
 | 
				
			||||||
    "vue": "^3.2.37",
 | 
					    "vue": "^3.2.37",
 | 
				
			||||||
    "vue-clipboard3": "^1.0.1",
 | 
					    "vue-clipboard3": "^1.0.1",
 | 
				
			||||||
    "vue-router": "^4.0.16",
 | 
					    "vue-router": "^4.1.2",
 | 
				
			||||||
    "vuex": "^4.0.2",
 | 
					    "vuex": "^4.0.2",
 | 
				
			||||||
    "xterm": "^4.19.0",
 | 
					    "xterm": "^4.19.0",
 | 
				
			||||||
    "xterm-addon-fit": "^0.5.0"
 | 
					    "xterm-addon-fit": "^0.5.0"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,5 @@
 | 
				
			|||||||
window.globalConfig = {
 | 
					window.globalConfig = {
 | 
				
			||||||
    "BaseApiUrl": "http://localhost:8888",
 | 
					    // 默认为空,以访问根目录为api请求地址。若前后端分离部署可单独配置该后端api请求地址
 | 
				
			||||||
    "BaseWsUrl": "ws://localhost:8888"
 | 
					    "BaseApiUrl": "",
 | 
				
			||||||
 | 
					    "BaseWsUrl": ""
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
const config = {
 | 
					const config = {
 | 
				
			||||||
    baseApiUrl:  `${(window as any).globalConfig.BaseApiUrl}/api`,
 | 
					    baseApiUrl: `${(window as any).globalConfig.BaseApiUrl}/api`,
 | 
				
			||||||
    baseWsUrl: `${(window as any).globalConfig.BaseWsUrl}/api`
 | 
					    baseWsUrl: `${(window as any).globalConfig.BaseWsUrl || `${location.protocol == 'https:' ? 'wss:' : 'ws:'}//${location.host}`}/api`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default config
 | 
					export default config
 | 
				
			||||||
@@ -2,6 +2,8 @@ import request from './request'
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
    login: (param: any) => request.request('POST', '/sys/accounts/login', param, null),
 | 
					    login: (param: any) => request.request('POST', '/sys/accounts/login', param, null),
 | 
				
			||||||
 | 
					    changePwd: (param: any) => request.request('POST', '/sys/accounts/change-pwd', param, null),
 | 
				
			||||||
 | 
					    getPublicKey: () => request.request('GET', '/common/public-key', null, null),
 | 
				
			||||||
    captcha: () => request.request('GET', '/sys/captcha', null, null),
 | 
					    captcha: () => request.request('GET', '/sys/captcha', null, null),
 | 
				
			||||||
    logout: (param: any) => request.request('POST', '/sys/accounts/logout/{token}', param, null),
 | 
					    logout: (param: any) => request.request('POST', '/sys/accounts/logout/{token}', param, null),
 | 
				
			||||||
    getMenuRoute: (param: any) => request.request('Get', '/sys/resources/account', param, null)
 | 
					    getMenuRoute: (param: any) => request.request('Get', '/sys/resources/account', param, null)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										37
									
								
								mayfly_go_web/src/common/rsa.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								mayfly_go_web/src/common/rsa.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
				
			|||||||
 | 
					import openApi from './openApi';
 | 
				
			||||||
 | 
					import JSEncrypt from 'jsencrypt'
 | 
				
			||||||
 | 
					import { notBlank } from './assert';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var encryptor: any = null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export async function getRsaPublicKey() {
 | 
				
			||||||
 | 
					    let publicKey = sessionStorage.getItem('RsaPublicKey')
 | 
				
			||||||
 | 
					    if (publicKey) {
 | 
				
			||||||
 | 
					        return publicKey
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    publicKey = await openApi.getPublicKey() as string
 | 
				
			||||||
 | 
					    sessionStorage.setItem('RsaPublicKey', publicKey)
 | 
				
			||||||
 | 
					    return publicKey
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 公钥加密指定值
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @param value value
 | 
				
			||||||
 | 
					 * @returns 加密后的值
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export async function RsaEncrypt(value: any) {
 | 
				
			||||||
 | 
					    // 不存在则返回空值
 | 
				
			||||||
 | 
					    if (!value) {
 | 
				
			||||||
 | 
					        return ""
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (encryptor != null) {
 | 
				
			||||||
 | 
					        return encryptor.encrypt(value)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    console.log(value)
 | 
				
			||||||
 | 
					    encryptor = new JSEncrypt()
 | 
				
			||||||
 | 
					    const publicKey = await getRsaPublicKey() as string;
 | 
				
			||||||
 | 
					    notBlank(publicKey, "获取公钥失败")
 | 
				
			||||||
 | 
					    encryptor.setPublicKey(publicKey)//设置公钥
 | 
				
			||||||
 | 
					    return encryptor.encrypt(value)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -10,6 +10,7 @@ export const imports = {
 | 
				
			|||||||
    "ResourceList": () => import('@/views/system/resource'),
 | 
					    "ResourceList": () => import('@/views/system/resource'),
 | 
				
			||||||
    "RoleList": () => import('@/views/system/role'),
 | 
					    "RoleList": () => import('@/views/system/role'),
 | 
				
			||||||
    "AccountList": () => import('@/views/system/account'),
 | 
					    "AccountList": () => import('@/views/system/account'),
 | 
				
			||||||
 | 
					    "SyslogList": () => import('@/views/system/syslog/SyslogList.vue'),
 | 
				
			||||||
    // project
 | 
					    // project
 | 
				
			||||||
    "ProjectList": () => import('@/views/ops/project/ProjectList.vue'),
 | 
					    "ProjectList": () => import('@/views/ops/project/ProjectList.vue'),
 | 
				
			||||||
    // db
 | 
					    // db
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,54 +1,75 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <el-form ref="loginFormRef" :model="loginForm" :rules="rules" class="login-content-form" size="large">
 | 
					    <div>
 | 
				
			||||||
        <el-form-item prop="username">
 | 
					        <el-form ref="loginFormRef" :model="loginForm" :rules="rules" class="login-content-form" size="large">
 | 
				
			||||||
            <el-input type="text" placeholder="请输入用户名" prefix-icon="user" v-model="loginForm.username" clearable autocomplete="off">
 | 
					            <el-form-item prop="username">
 | 
				
			||||||
            </el-input>
 | 
					                <el-input type="text" placeholder="请输入用户名" prefix-icon="user" v-model="loginForm.username" clearable autocomplete="off">
 | 
				
			||||||
        </el-form-item>
 | 
					                </el-input>
 | 
				
			||||||
        <el-form-item prop="password">
 | 
					            </el-form-item>
 | 
				
			||||||
            <el-input
 | 
					            <el-form-item prop="password">
 | 
				
			||||||
                type="password"
 | 
					                <el-input type="password" placeholder="请输入密码" prefix-icon="lock" v-model="loginForm.password" autocomplete="off" show-password>
 | 
				
			||||||
                placeholder="请输入密码"
 | 
					                </el-input>
 | 
				
			||||||
                prefix-icon="lock"
 | 
					            </el-form-item>
 | 
				
			||||||
                v-model="loginForm.password"
 | 
					            <el-form-item prop="captcha">
 | 
				
			||||||
                autocomplete="off"
 | 
					                <el-row :gutter="15">
 | 
				
			||||||
                show-password
 | 
					                    <el-col :span="16">
 | 
				
			||||||
            >
 | 
					                        <el-input
 | 
				
			||||||
            </el-input>
 | 
					                            type="text"
 | 
				
			||||||
        </el-form-item>
 | 
					                            maxlength="6"
 | 
				
			||||||
        <el-form-item prop="captcha">
 | 
					                            placeholder="请输入验证码"
 | 
				
			||||||
            <el-row :gutter="15">
 | 
					                            prefix-icon="position"
 | 
				
			||||||
                <el-col :span="16">
 | 
					                            v-model="loginForm.captcha"
 | 
				
			||||||
 | 
					                            clearable
 | 
				
			||||||
 | 
					                            autocomplete="off"
 | 
				
			||||||
 | 
					                            @keyup.enter="login"
 | 
				
			||||||
 | 
					                        ></el-input>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="8">
 | 
				
			||||||
 | 
					                        <div class="login-content-code">
 | 
				
			||||||
 | 
					                            <img
 | 
				
			||||||
 | 
					                                class="login-content-code-img"
 | 
				
			||||||
 | 
					                                @click="getCaptcha"
 | 
				
			||||||
 | 
					                                width="130px"
 | 
				
			||||||
 | 
					                                height="40px"
 | 
				
			||||||
 | 
					                                :src="captchaImage"
 | 
				
			||||||
 | 
					                                style="cursor: pointer"
 | 
				
			||||||
 | 
					                            />
 | 
				
			||||||
 | 
					                        </div>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
 | 
					                </el-row>
 | 
				
			||||||
 | 
					            </el-form-item>
 | 
				
			||||||
 | 
					            <el-form-item>
 | 
				
			||||||
 | 
					                <el-button type="primary" class="login-content-submit" round @click="login" :loading="loading.signIn">
 | 
				
			||||||
 | 
					                    <span>登 录</span>
 | 
				
			||||||
 | 
					                </el-button>
 | 
				
			||||||
 | 
					            </el-form-item>
 | 
				
			||||||
 | 
					        </el-form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <el-dialog title="修改密码" v-model="changePwdDialog.visible" :close-on-click-modal="false" width="450px" :destroy-on-close="true">
 | 
				
			||||||
 | 
					            <el-form :model="changePwdDialog.form" :rules="changePwdDialog.rules" ref="changePwdFormRef" label-width="65px">
 | 
				
			||||||
 | 
					                <el-form-item prop="username" label="用户名" required>
 | 
				
			||||||
 | 
					                    <el-input v-model.trim="changePwdDialog.form.username" disabled></el-input>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					                <el-form-item prop="oldPassword" label="旧密码" required>
 | 
				
			||||||
 | 
					                    <el-input v-model.trim="changePwdDialog.form.oldPassword" autocomplete="new-password" type="password"></el-input>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					                <el-form-item prop="newPassword" label="新密码" required>
 | 
				
			||||||
                    <el-input
 | 
					                    <el-input
 | 
				
			||||||
                        type="text"
 | 
					                        v-model.trim="changePwdDialog.form.newPassword"
 | 
				
			||||||
                        maxlength="6"
 | 
					                        placeholder="须为8位以上且包含字⺟⼤⼩写+数字+特殊符号"
 | 
				
			||||||
                        placeholder="请输入验证码"
 | 
					                        type="password"
 | 
				
			||||||
                        prefix-icon="position"
 | 
					                        autocomplete="new-password"
 | 
				
			||||||
                        v-model="loginForm.captcha"
 | 
					 | 
				
			||||||
                        clearable
 | 
					 | 
				
			||||||
                        autocomplete="off"
 | 
					 | 
				
			||||||
                        @keyup.enter="login"
 | 
					 | 
				
			||||||
                    ></el-input>
 | 
					                    ></el-input>
 | 
				
			||||||
                </el-col>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-col :span="8">
 | 
					            </el-form>
 | 
				
			||||||
                    <div class="login-content-code">
 | 
					
 | 
				
			||||||
                        <img
 | 
					            <template #footer>
 | 
				
			||||||
                            class="login-content-code-img"
 | 
					                <div class="dialog-footer">
 | 
				
			||||||
                            @click="getCaptcha"
 | 
					                    <el-button @click="cancelChangePwd">取 消</el-button>
 | 
				
			||||||
                            width="130px"
 | 
					                    <el-button @click="changePwd" type="primary" :loading="loading.changePwd">确 定</el-button>
 | 
				
			||||||
                            height="40px"
 | 
					                </div>
 | 
				
			||||||
                            :src="captchaImage"
 | 
					            </template>
 | 
				
			||||||
                            style="cursor: pointer"
 | 
					        </el-dialog>
 | 
				
			||||||
                        />
 | 
					    </div>
 | 
				
			||||||
                    </div>
 | 
					 | 
				
			||||||
                </el-col>
 | 
					 | 
				
			||||||
            </el-row>
 | 
					 | 
				
			||||||
        </el-form-item>
 | 
					 | 
				
			||||||
        <el-form-item>
 | 
					 | 
				
			||||||
            <el-button type="primary" class="login-content-submit" round @click="login" :loading="loading.signIn">
 | 
					 | 
				
			||||||
                <span>登 录</span>
 | 
					 | 
				
			||||||
            </el-button>
 | 
					 | 
				
			||||||
        </el-form-item>
 | 
					 | 
				
			||||||
    </el-form>
 | 
					 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script lang="ts">
 | 
					<script lang="ts">
 | 
				
			||||||
@@ -60,7 +81,9 @@ import { useStore } from '@/store/index.ts';
 | 
				
			|||||||
import { setSession } from '@/common/utils/storage.ts';
 | 
					import { setSession } from '@/common/utils/storage.ts';
 | 
				
			||||||
import { formatAxis } from '@/common/utils/formatTime.ts';
 | 
					import { formatAxis } from '@/common/utils/formatTime.ts';
 | 
				
			||||||
import openApi from '@/common/openApi';
 | 
					import openApi from '@/common/openApi';
 | 
				
			||||||
 | 
					import { RsaEncrypt } from '@/common/rsa';
 | 
				
			||||||
import { letterAvatar } from '@/common/utils/string';
 | 
					import { letterAvatar } from '@/common/utils/string';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'AccountLogin',
 | 
					    name: 'AccountLogin',
 | 
				
			||||||
    setup() {
 | 
					    setup() {
 | 
				
			||||||
@@ -68,6 +91,8 @@ export default defineComponent({
 | 
				
			|||||||
        const route = useRoute();
 | 
					        const route = useRoute();
 | 
				
			||||||
        const router = useRouter();
 | 
					        const router = useRouter();
 | 
				
			||||||
        const loginFormRef: any = ref(null);
 | 
					        const loginFormRef: any = ref(null);
 | 
				
			||||||
 | 
					        const changePwdFormRef: any = ref(null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const state = reactive({
 | 
					        const state = reactive({
 | 
				
			||||||
            captchaImage: '',
 | 
					            captchaImage: '',
 | 
				
			||||||
            loginForm: {
 | 
					            loginForm: {
 | 
				
			||||||
@@ -76,6 +101,24 @@ export default defineComponent({
 | 
				
			|||||||
                captcha: '',
 | 
					                captcha: '',
 | 
				
			||||||
                cid: '',
 | 
					                cid: '',
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					            changePwdDialog: {
 | 
				
			||||||
 | 
					                visible: false,
 | 
				
			||||||
 | 
					                form: {
 | 
				
			||||||
 | 
					                    username: '',
 | 
				
			||||||
 | 
					                    oldPassword: '',
 | 
				
			||||||
 | 
					                    newPassword: '',
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                rules: {
 | 
				
			||||||
 | 
					                    newPassword: [
 | 
				
			||||||
 | 
					                        { required: true, message: '请输入新密码', trigger: 'blur' },
 | 
				
			||||||
 | 
					                        {
 | 
				
			||||||
 | 
					                            pattern: /^(?=.*[A-Za-z])(?=.*\d)(?=.*[`~!@#$%^&*()_+<>?:"{},.\/\\;'[\]])[A-Za-z\d`~!@#$%^&*()_+<>?:"{},.\/\\;'[\]]{8,}$/,
 | 
				
			||||||
 | 
					                            message: '须为8位以上且包含字⺟⼤⼩写+数字+特殊符号',
 | 
				
			||||||
 | 
					                            trigger: 'blur',
 | 
				
			||||||
 | 
					                        },
 | 
				
			||||||
 | 
					                    ],
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
            rules: {
 | 
					            rules: {
 | 
				
			||||||
                username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
 | 
					                username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
 | 
				
			||||||
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
 | 
					                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
 | 
				
			||||||
@@ -83,6 +126,7 @@ export default defineComponent({
 | 
				
			|||||||
            },
 | 
					            },
 | 
				
			||||||
            loading: {
 | 
					            loading: {
 | 
				
			||||||
                signIn: false,
 | 
					                signIn: false,
 | 
				
			||||||
 | 
					                changePwd: false,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -116,15 +160,26 @@ export default defineComponent({
 | 
				
			|||||||
        const onSignIn = async () => {
 | 
					        const onSignIn = async () => {
 | 
				
			||||||
            state.loading.signIn = true;
 | 
					            state.loading.signIn = true;
 | 
				
			||||||
            let loginRes;
 | 
					            let loginRes;
 | 
				
			||||||
 | 
					            const originPwd = state.loginForm.password;
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                loginRes = await openApi.login(state.loginForm);
 | 
					                const loginReq = { ...state.loginForm };
 | 
				
			||||||
                // // 存储 token 到浏览器缓存
 | 
					                loginReq.password = await RsaEncrypt(originPwd);
 | 
				
			||||||
 | 
					                loginRes = await openApi.login(loginReq);
 | 
				
			||||||
 | 
					                // 存储 token 到浏览器缓存
 | 
				
			||||||
                setSession('token', loginRes.token);
 | 
					                setSession('token', loginRes.token);
 | 
				
			||||||
                setSession('menus', loginRes.menus);
 | 
					                setSession('menus', loginRes.menus);
 | 
				
			||||||
            } catch (e) {
 | 
					            } catch (e: any) {
 | 
				
			||||||
                state.loading.signIn = false;
 | 
					                state.loading.signIn = false;
 | 
				
			||||||
                state.loginForm.captcha = '';
 | 
					                state.loginForm.captcha = '';
 | 
				
			||||||
                getCaptcha();
 | 
					                // 密码强度不足
 | 
				
			||||||
 | 
					                if (e.code && e.code == 401) {
 | 
				
			||||||
 | 
					                    state.changePwdDialog.form.username = state.loginForm.username;
 | 
				
			||||||
 | 
					                    state.changePwdDialog.form.oldPassword = originPwd;
 | 
				
			||||||
 | 
					                    state.changePwdDialog.form.newPassword = '';
 | 
				
			||||||
 | 
					                    state.changePwdDialog.visible = true;
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    getCaptcha();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            // 用户信息
 | 
					            // 用户信息
 | 
				
			||||||
@@ -174,11 +229,44 @@ export default defineComponent({
 | 
				
			|||||||
            }, 300);
 | 
					            }, 300);
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const changePwd = () => {
 | 
				
			||||||
 | 
					            changePwdFormRef.value.validate(async (valid: boolean) => {
 | 
				
			||||||
 | 
					                if (!valid) {
 | 
				
			||||||
 | 
					                    return false;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                try {
 | 
				
			||||||
 | 
					                    state.loading.changePwd = true;
 | 
				
			||||||
 | 
					                    const form = state.changePwdDialog.form;
 | 
				
			||||||
 | 
					                    const changePwdReq: any = { ...form };
 | 
				
			||||||
 | 
					                    changePwdReq.oldPassword = await RsaEncrypt(form.oldPassword);
 | 
				
			||||||
 | 
					                    changePwdReq.newPassword = await RsaEncrypt(form.newPassword);
 | 
				
			||||||
 | 
					                    await openApi.changePwd(changePwdReq);
 | 
				
			||||||
 | 
					                    ElMessage.success('密码修改成功, 新密码已填充至登录密码框');
 | 
				
			||||||
 | 
					                    state.loginForm.password = state.changePwdDialog.form.newPassword;
 | 
				
			||||||
 | 
					                    state.changePwdDialog.visible = false;
 | 
				
			||||||
 | 
					                    getCaptcha();
 | 
				
			||||||
 | 
					                } finally {
 | 
				
			||||||
 | 
					                    state.loading.changePwd = false;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const cancelChangePwd = () => {
 | 
				
			||||||
 | 
					            state.changePwdDialog.visible = false;
 | 
				
			||||||
 | 
					            state.changePwdDialog.form.newPassword = '';
 | 
				
			||||||
 | 
					            state.changePwdDialog.form.oldPassword = '';
 | 
				
			||||||
 | 
					            state.changePwdDialog.form.username = '';
 | 
				
			||||||
 | 
					            getCaptcha();
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            getCaptcha,
 | 
					            getCaptcha,
 | 
				
			||||||
            currentTime,
 | 
					            currentTime,
 | 
				
			||||||
            loginFormRef,
 | 
					            loginFormRef,
 | 
				
			||||||
 | 
					            changePwdFormRef,
 | 
				
			||||||
            login,
 | 
					            login,
 | 
				
			||||||
 | 
					            changePwd,
 | 
				
			||||||
 | 
					            cancelChangePwd,
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,10 +23,13 @@
 | 
				
			|||||||
                    </el-select>
 | 
					                    </el-select>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="host" label="host:" required>
 | 
					                <el-form-item prop="host" label="host:" required>
 | 
				
			||||||
                    <el-input v-model.trim="form.host" placeholder="请输入主机ip" auto-complete="off"></el-input>
 | 
					                    <el-col :span="18">
 | 
				
			||||||
                </el-form-item>
 | 
					                        <el-input v-model.trim="form.host" placeholder="请输入主机ip" auto-complete="off"></el-input>
 | 
				
			||||||
                <el-form-item prop="port" label="port:" required>
 | 
					                    </el-col>
 | 
				
			||||||
                    <el-input type="number" v-model.trim="form.port" placeholder="请输入端口"></el-input>
 | 
					                    <el-col style="text-align: center" :span="1">:</el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="5">
 | 
				
			||||||
 | 
					                        <el-input type="number" v-model.number="form.port" placeholder="请输入端口"></el-input>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="username" label="用户名:" required>
 | 
					                <el-form-item prop="username" label="用户名:" required>
 | 
				
			||||||
                    <el-input v-model.trim="form.username" placeholder="请输入用户名"></el-input>
 | 
					                    <el-input v-model.trim="form.username" placeholder="请输入用户名"></el-input>
 | 
				
			||||||
@@ -67,6 +70,24 @@
 | 
				
			|||||||
                    />
 | 
					                    />
 | 
				
			||||||
                    <el-button v-else class="ml5 mt5" size="small" @click="showInputDb"> + 添加数据库 </el-button>
 | 
					                    <el-button v-else class="ml5 mt5" size="small" @click="showInputDb"> + 添加数据库 </el-button>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                <el-form-item prop="enableSshTunnel" label="SSH隧道:">
 | 
				
			||||||
 | 
					                    <el-col :span="3">
 | 
				
			||||||
 | 
					                        <el-checkbox @change="getSshTunnelMachines" v-model="form.enableSshTunnel" :true-label="1" :false-label="-1"></el-checkbox>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="2" v-if="form.enableSshTunnel == 1"> 机器: </el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="19" v-if="form.enableSshTunnel == 1">
 | 
				
			||||||
 | 
					                        <el-select style="width: 100%" v-model="form.sshTunnelMachineId" placeholder="请选择SSH隧道机器">
 | 
				
			||||||
 | 
					                            <el-option
 | 
				
			||||||
 | 
					                                v-for="item in sshTunnelMachineList"
 | 
				
			||||||
 | 
					                                :key="item.id"
 | 
				
			||||||
 | 
					                                :label="`${item.ip}:${item.port} [${item.name}]`"
 | 
				
			||||||
 | 
					                                :value="item.id"
 | 
				
			||||||
 | 
					                            >
 | 
				
			||||||
 | 
					                            </el-option>
 | 
				
			||||||
 | 
					                        </el-select>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
            </el-form>
 | 
					            </el-form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <template #footer>
 | 
					            <template #footer>
 | 
				
			||||||
@@ -83,9 +104,11 @@
 | 
				
			|||||||
import { toRefs, reactive, nextTick, watch, defineComponent, ref } from 'vue';
 | 
					import { toRefs, reactive, nextTick, watch, defineComponent, ref } from 'vue';
 | 
				
			||||||
import { dbApi } from './api';
 | 
					import { dbApi } from './api';
 | 
				
			||||||
import { projectApi } from '../project/api.ts';
 | 
					import { projectApi } from '../project/api.ts';
 | 
				
			||||||
 | 
					import { machineApi } from '../machine/api.ts';
 | 
				
			||||||
import { ElMessage } from 'element-plus';
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
import type { ElInput } from 'element-plus';
 | 
					import type { ElInput } from 'element-plus';
 | 
				
			||||||
import { notBlank } from '@/common/assert';
 | 
					import { notBlank } from '@/common/assert';
 | 
				
			||||||
 | 
					import { RsaEncrypt } from '@/common/rsa';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'DbEdit',
 | 
					    name: 'DbEdit',
 | 
				
			||||||
@@ -112,6 +135,7 @@ export default defineComponent({
 | 
				
			|||||||
            projects: [],
 | 
					            projects: [],
 | 
				
			||||||
            envs: [],
 | 
					            envs: [],
 | 
				
			||||||
            databaseList: [] as any,
 | 
					            databaseList: [] as any,
 | 
				
			||||||
 | 
					            sshTunnelMachineList: [],
 | 
				
			||||||
            inputDbVisible: false,
 | 
					            inputDbVisible: false,
 | 
				
			||||||
            inputDbValue: '',
 | 
					            inputDbValue: '',
 | 
				
			||||||
            form: {
 | 
					            form: {
 | 
				
			||||||
@@ -126,6 +150,8 @@ export default defineComponent({
 | 
				
			|||||||
                projectId: null,
 | 
					                projectId: null,
 | 
				
			||||||
                envId: null,
 | 
					                envId: null,
 | 
				
			||||||
                env: null,
 | 
					                env: null,
 | 
				
			||||||
 | 
					                enableSshTunnel: null,
 | 
				
			||||||
 | 
					                sshTunnelMachineId: null,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            btnLoading: false,
 | 
					            btnLoading: false,
 | 
				
			||||||
            rules: {
 | 
					            rules: {
 | 
				
			||||||
@@ -160,14 +186,7 @@ export default defineComponent({
 | 
				
			|||||||
                host: [
 | 
					                host: [
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        required: true,
 | 
					                        required: true,
 | 
				
			||||||
                        message: '请输入主机ip',
 | 
					                        message: '请输入主机ip和port',
 | 
				
			||||||
                        trigger: ['change', 'blur'],
 | 
					 | 
				
			||||||
                    },
 | 
					 | 
				
			||||||
                ],
 | 
					 | 
				
			||||||
                port: [
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        required: true,
 | 
					 | 
				
			||||||
                        message: '请输入端口',
 | 
					 | 
				
			||||||
                        trigger: ['change', 'blur'],
 | 
					                        trigger: ['change', 'blur'],
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                ],
 | 
					                ],
 | 
				
			||||||
@@ -189,6 +208,10 @@ export default defineComponent({
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        watch(props, (newValue) => {
 | 
					        watch(props, (newValue) => {
 | 
				
			||||||
 | 
					            state.dialogVisible = newValue.visible;
 | 
				
			||||||
 | 
					            if (!state.dialogVisible) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            state.projects = newValue.projects;
 | 
					            state.projects = newValue.projects;
 | 
				
			||||||
            if (newValue.db) {
 | 
					            if (newValue.db) {
 | 
				
			||||||
                getEnvs(newValue.db.projectId);
 | 
					                getEnvs(newValue.db.projectId);
 | 
				
			||||||
@@ -197,10 +220,10 @@ export default defineComponent({
 | 
				
			|||||||
                state.databaseList = newValue.db.database.split(' ');
 | 
					                state.databaseList = newValue.db.database.split(' ');
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                state.envs = [];
 | 
					                state.envs = [];
 | 
				
			||||||
                state.form = { port: 3306 } as any;
 | 
					                state.form = { port: 3306, enableSshTunnel: -1 } as any;
 | 
				
			||||||
                state.databaseList = [];
 | 
					                state.databaseList = [];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            state.dialogVisible = newValue.visible;
 | 
					            getSshTunnelMachines();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const handleClose = (db: string) => {
 | 
					        const handleClose = (db: string) => {
 | 
				
			||||||
@@ -231,6 +254,13 @@ export default defineComponent({
 | 
				
			|||||||
            state.form.database = state.databaseList.length == 0 ? '' : state.databaseList.join(' ');
 | 
					            state.form.database = state.databaseList.length == 0 ? '' : state.databaseList.join(' ');
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getSshTunnelMachines = async () => {
 | 
				
			||||||
 | 
					            if (state.form.enableSshTunnel == 1 && state.sshTunnelMachineList.length == 0) {
 | 
				
			||||||
 | 
					                const res = await machineApi.list.request({ pageNum: 1, pageSize: 100 });
 | 
				
			||||||
 | 
					                state.sshTunnelMachineList = res.list;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const getEnvs = async (projectId: any) => {
 | 
					        const getEnvs = async (projectId: any) => {
 | 
				
			||||||
            state.envs = await projectApi.projectEnvs.request({ projectId });
 | 
					            state.envs = await projectApi.projectEnvs.request({ projectId });
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
@@ -259,10 +289,12 @@ export default defineComponent({
 | 
				
			|||||||
            if (!state.form.id) {
 | 
					            if (!state.form.id) {
 | 
				
			||||||
                notBlank(state.form.password, '新增操作,密码不可为空');
 | 
					                notBlank(state.form.password, '新增操作,密码不可为空');
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            dbForm.value.validate((valid: boolean) => {
 | 
					            dbForm.value.validate(async (valid: boolean) => {
 | 
				
			||||||
                if (valid) {
 | 
					                if (valid) {
 | 
				
			||||||
                    state.form.port = Number.parseInt(state.form.port as any);
 | 
					                    const reqForm = { ...state.form };
 | 
				
			||||||
                    dbApi.saveDb.request(state.form).then(() => {
 | 
					                    reqForm.password = await RsaEncrypt(reqForm.password);
 | 
				
			||||||
 | 
					                    // reqForm.ssh_pass = await RsaEncrypt(reqForm.ssh_pass);
 | 
				
			||||||
 | 
					                    dbApi.saveDb.request(reqForm).then(() => {
 | 
				
			||||||
                        ElMessage.success('保存成功');
 | 
					                        ElMessage.success('保存成功');
 | 
				
			||||||
                        emit('val-change', state.form);
 | 
					                        emit('val-change', state.form);
 | 
				
			||||||
                        state.btnLoading = true;
 | 
					                        state.btnLoading = true;
 | 
				
			||||||
@@ -300,6 +332,7 @@ export default defineComponent({
 | 
				
			|||||||
            handleClose,
 | 
					            handleClose,
 | 
				
			||||||
            showInputDb,
 | 
					            showInputDb,
 | 
				
			||||||
            handleInputDbConfirm,
 | 
					            handleInputDbConfirm,
 | 
				
			||||||
 | 
					            getSshTunnelMachines,
 | 
				
			||||||
            changeProject,
 | 
					            changeProject,
 | 
				
			||||||
            changeEnv,
 | 
					            changeEnv,
 | 
				
			||||||
            btnOk,
 | 
					            btnOk,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,5 +22,5 @@ export const dbApi = {
 | 
				
			|||||||
    getSqlNames: Api.create("/dbs/{id}/sql-names", 'get'),
 | 
					    getSqlNames: Api.create("/dbs/{id}/sql-names", 'get'),
 | 
				
			||||||
    deleteDbSql: Api.create("/dbs/{id}/sql", 'delete'),
 | 
					    deleteDbSql: Api.create("/dbs/{id}/sql", 'delete'),
 | 
				
			||||||
    // 获取数据库sql执行记录
 | 
					    // 获取数据库sql执行记录
 | 
				
			||||||
    getSqlExecs: Api.create("/dbs/{id}/sql-execs", 'get'),
 | 
					    getSqlExecs: Api.create("/dbs/{dbId}/sql-execs", 'get'),
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -11,15 +11,24 @@
 | 
				
			|||||||
                    <el-input v-model.trim="form.name" placeholder="请输入机器别名" auto-complete="off"></el-input>
 | 
					                    <el-input v-model.trim="form.name" placeholder="请输入机器别名" auto-complete="off"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="ip" label="ip:" required>
 | 
					                <el-form-item prop="ip" label="ip:" required>
 | 
				
			||||||
                    <el-input v-model.trim="form.ip" placeholder="请输入主机ip" auto-complete="off"></el-input>
 | 
					                    <el-col :span="18">
 | 
				
			||||||
                </el-form-item>
 | 
					                        <el-input v-model.trim="form.ip" placeholder="主机ip" auto-complete="off"></el-input>
 | 
				
			||||||
                <el-form-item prop="port" label="port:" required>
 | 
					                    </el-col>
 | 
				
			||||||
                    <el-input type="number" v-model.number="form.port" placeholder="请输入端口"></el-input>
 | 
					                    <el-col style="text-align: center" :span="1">:</el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="5">
 | 
				
			||||||
 | 
					                        <el-input type="number" v-model.number="form.port" placeholder="端口"></el-input>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="username" label="用户名:" required>
 | 
					                <el-form-item prop="username" label="用户名:" required>
 | 
				
			||||||
                    <el-input v-model.trim="form.username" placeholder="请输入用户名"></el-input>
 | 
					                    <el-input v-model.trim="form.username" placeholder="请输入用户名"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="password" label="密码:">
 | 
					                <el-form-item prop="authMethod" label="认证方式:" required>
 | 
				
			||||||
 | 
					                    <el-select style="width: 100%" v-model="form.authMethod" placeholder="请选择认证方式">
 | 
				
			||||||
 | 
					                        <el-option key="1" label="Password" :value="1"> </el-option>
 | 
				
			||||||
 | 
					                        <el-option key="2" label="PublicKey" :value="2"> </el-option>
 | 
				
			||||||
 | 
					                    </el-select>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					                <el-form-item v-if="form.authMethod == 1" prop="password" label="密码:">
 | 
				
			||||||
                    <el-input
 | 
					                    <el-input
 | 
				
			||||||
                        type="password"
 | 
					                        type="password"
 | 
				
			||||||
                        show-password
 | 
					                        show-password
 | 
				
			||||||
@@ -28,6 +37,9 @@
 | 
				
			|||||||
                        autocomplete="new-password"
 | 
					                        autocomplete="new-password"
 | 
				
			||||||
                    ></el-input>
 | 
					                    ></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					                <el-form-item v-if="form.authMethod == 2" prop="password" label="秘钥:">
 | 
				
			||||||
 | 
					                    <el-input type="textarea" :rows="3" v-model="form.password" placeholder="请将私钥文件内容拷贝至此,修改操作可不填"></el-input>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="remark" label="备注:">
 | 
					                <el-form-item prop="remark" label="备注:">
 | 
				
			||||||
                    <el-input type="textarea" v-model="form.remark"></el-input>
 | 
					                    <el-input type="textarea" v-model="form.remark"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
@@ -48,6 +60,7 @@ import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
 | 
				
			|||||||
import { machineApi } from './api';
 | 
					import { machineApi } from './api';
 | 
				
			||||||
import { ElMessage } from 'element-plus';
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
import { notBlank } from '@/common/assert';
 | 
					import { notBlank } from '@/common/assert';
 | 
				
			||||||
 | 
					import { RsaEncrypt } from '@/common/rsa';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'MachineEdit',
 | 
					    name: 'MachineEdit',
 | 
				
			||||||
@@ -75,9 +88,10 @@ export default defineComponent({
 | 
				
			|||||||
                projectId: null,
 | 
					                projectId: null,
 | 
				
			||||||
                projectName: null,
 | 
					                projectName: null,
 | 
				
			||||||
                name: null,
 | 
					                name: null,
 | 
				
			||||||
 | 
					                authMethod: 1,
 | 
				
			||||||
                port: 22,
 | 
					                port: 22,
 | 
				
			||||||
                username: null,
 | 
					                username: '',
 | 
				
			||||||
                password: null,
 | 
					                password: '',
 | 
				
			||||||
                remark: '',
 | 
					                remark: '',
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            btnLoading: false,
 | 
					            btnLoading: false,
 | 
				
			||||||
@@ -106,14 +120,7 @@ export default defineComponent({
 | 
				
			|||||||
                ip: [
 | 
					                ip: [
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        required: true,
 | 
					                        required: true,
 | 
				
			||||||
                        message: '请输入主机ip',
 | 
					                        message: '请输入主机ip和端口',
 | 
				
			||||||
                        trigger: ['change', 'blur'],
 | 
					 | 
				
			||||||
                    },
 | 
					 | 
				
			||||||
                ],
 | 
					 | 
				
			||||||
                port: [
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        required: true,
 | 
					 | 
				
			||||||
                        message: '请输入端口',
 | 
					 | 
				
			||||||
                        trigger: ['change', 'blur'],
 | 
					                        trigger: ['change', 'blur'],
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                ],
 | 
					                ],
 | 
				
			||||||
@@ -124,16 +131,26 @@ export default defineComponent({
 | 
				
			|||||||
                        trigger: ['change', 'blur'],
 | 
					                        trigger: ['change', 'blur'],
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                ],
 | 
					                ],
 | 
				
			||||||
 | 
					                authMethod: [
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        required: true,
 | 
				
			||||||
 | 
					                        message: '请选择认证方式',
 | 
				
			||||||
 | 
					                        trigger: ['change', 'blur'],
 | 
				
			||||||
 | 
					                    },
 | 
				
			||||||
 | 
					                ],
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        watch(props, async (newValue) => {
 | 
					        watch(props, async (newValue) => {
 | 
				
			||||||
            state.dialogVisible = newValue.visible;
 | 
					            state.dialogVisible = newValue.visible;
 | 
				
			||||||
 | 
					            if (!state.dialogVisible) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            state.projects = newValue.projects;
 | 
					            state.projects = newValue.projects;
 | 
				
			||||||
            if (newValue.machine) {
 | 
					            if (newValue.machine) {
 | 
				
			||||||
                state.form = { ...newValue.machine };
 | 
					                state.form = { ...newValue.machine };
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                state.form = { port: 22 } as any;
 | 
					                state.form = { port: 22, authMethod: 1 } as any;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -149,18 +166,21 @@ export default defineComponent({
 | 
				
			|||||||
            if (!state.form.id) {
 | 
					            if (!state.form.id) {
 | 
				
			||||||
                notBlank(state.form.password, '新增操作,密码不可为空');
 | 
					                notBlank(state.form.password, '新增操作,密码不可为空');
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            machineForm.value.validate((valid: boolean) => {
 | 
					            machineForm.value.validate(async (valid: boolean) => {
 | 
				
			||||||
                if (valid) {
 | 
					                if (valid) {
 | 
				
			||||||
                    machineApi.saveMachine.request(state.form).then(() => {
 | 
					                    const reqForm = { ...state.form };
 | 
				
			||||||
 | 
					                    if (reqForm.authMethod == 1) {
 | 
				
			||||||
 | 
					                        reqForm.password = await RsaEncrypt(state.form.password);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    state.btnLoading = true;
 | 
				
			||||||
 | 
					                    try {
 | 
				
			||||||
 | 
					                        await machineApi.saveMachine.request(reqForm);
 | 
				
			||||||
                        ElMessage.success('保存成功');
 | 
					                        ElMessage.success('保存成功');
 | 
				
			||||||
                        emit('val-change', state.form);
 | 
					                        emit('val-change', state.form);
 | 
				
			||||||
                        state.btnLoading = true;
 | 
					 | 
				
			||||||
                        setTimeout(() => {
 | 
					 | 
				
			||||||
                            state.btnLoading = false;
 | 
					 | 
				
			||||||
                        }, 1000);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        cancel();
 | 
					                        cancel();
 | 
				
			||||||
                    });
 | 
					                    } finally {
 | 
				
			||||||
 | 
					                        state.btnLoading = false;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    ElMessage.error('请正确填写信息');
 | 
					                    ElMessage.error('请正确填写信息');
 | 
				
			||||||
                    return false;
 | 
					                    return false;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -260,13 +260,13 @@ export default defineComponent({
 | 
				
			|||||||
            search();
 | 
					            search();
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const openFormDialog = (redis: any) => {
 | 
					        const openFormDialog = (machine: any) => {
 | 
				
			||||||
            let dialogTitle;
 | 
					            let dialogTitle;
 | 
				
			||||||
            if (redis) {
 | 
					            if (machine) {
 | 
				
			||||||
                state.machineEditDialog.data = state.currentData as any;
 | 
					                state.machineEditDialog.data = state.currentData as any;
 | 
				
			||||||
                dialogTitle = '编辑机器';
 | 
					                dialogTitle = '编辑机器';
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                state.machineEditDialog.data = { port: 22 } as any;
 | 
					                state.machineEditDialog.data = null;
 | 
				
			||||||
                dialogTitle = '添加机器';
 | 
					                dialogTitle = '添加机器';
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,7 +15,7 @@
 | 
				
			|||||||
                            </el-form-item>
 | 
					                            </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            <el-form-item label="库" label-width="20px">
 | 
					                            <el-form-item label="库" label-width="20px">
 | 
				
			||||||
                                <el-select v-model="database" placeholder="请选择库" @change="changeDatabase">
 | 
					                                <el-select v-model="database" placeholder="请选择库" @change="changeDatabase" filterable>
 | 
				
			||||||
                                    <el-option v-for="item in databases" :key="item.Name" :label="item.Name" :value="item.Name">
 | 
					                                    <el-option v-for="item in databases" :key="item.Name" :label="item.Name" :value="item.Name">
 | 
				
			||||||
                                        <span style="float: left">{{ item.Name }}</span>
 | 
					                                        <span style="float: left">{{ item.Name }}</span>
 | 
				
			||||||
                                        <span style="float: right; color: #8492a6; margin-left: 4px; font-size: 13px">{{
 | 
					                                        <span style="float: right; color: #8492a6; margin-left: 4px; font-size: 13px">{{
 | 
				
			||||||
@@ -26,12 +26,8 @@
 | 
				
			|||||||
                            </el-form-item>
 | 
					                            </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            <el-form-item label="集合" label-width="40px">
 | 
					                            <el-form-item label="集合" label-width="40px">
 | 
				
			||||||
                                <el-select v-model="collection" placeholder="请选择集合" @change="changeCollection">
 | 
					                                <el-select v-model="collection" placeholder="请选择集合" @change="changeCollection" filterable>
 | 
				
			||||||
                                    <el-option v-for="item in collections" :key="item" :label="item" :value="item">
 | 
					                                    <el-option v-for="item in collections" :key="item" :label="item" :value="item">
 | 
				
			||||||
                                        <!-- <span style="float: left">{{ item.uri }}</span>
 | 
					 | 
				
			||||||
                                            <span style="float: right; color: #8492a6; margin-left: 6px; font-size: 13px">{{
 | 
					 | 
				
			||||||
                                                ` [${item.name}]`
 | 
					 | 
				
			||||||
                                            }}</span> -->
 | 
					 | 
				
			||||||
                                    </el-option>
 | 
					                                    </el-option>
 | 
				
			||||||
                                </el-select>
 | 
					                                </el-select>
 | 
				
			||||||
                            </el-form-item>
 | 
					                            </el-form-item>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
        <el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false" width="35%" :destroy-on-close="true">
 | 
					        <el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false" width="38%" :destroy-on-close="true">
 | 
				
			||||||
            <el-form :model="form" ref="mongoForm" :rules="rules" label-width="65px">
 | 
					            <el-form :model="form" ref="mongoForm" :rules="rules" label-width="85px">
 | 
				
			||||||
                <el-form-item prop="projectId" label="项目" required>
 | 
					                <el-form-item prop="projectId" label="项目" required>
 | 
				
			||||||
                    <el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
 | 
					                    <el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
 | 
				
			||||||
                        <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
					                        <el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
 | 
				
			||||||
@@ -25,6 +25,24 @@
 | 
				
			|||||||
                        auto-complete="off"
 | 
					                        auto-complete="off"
 | 
				
			||||||
                    ></el-input>
 | 
					                    ></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                <el-form-item prop="enableSshTunnel" label="SSH隧道:">
 | 
				
			||||||
 | 
					                    <el-col :span="3">
 | 
				
			||||||
 | 
					                        <el-checkbox @change="getSshTunnelMachines" v-model="form.enableSshTunnel" :true-label="1" :false-label="-1"></el-checkbox>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="2" v-if="form.enableSshTunnel == 1"> 机器: </el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="19" v-if="form.enableSshTunnel == 1">
 | 
				
			||||||
 | 
					                        <el-select style="width: 100%" v-model="form.sshTunnelMachineId" placeholder="请选择SSH隧道机器">
 | 
				
			||||||
 | 
					                            <el-option
 | 
				
			||||||
 | 
					                                v-for="item in sshTunnelMachineList"
 | 
				
			||||||
 | 
					                                :key="item.id"
 | 
				
			||||||
 | 
					                                :label="`${item.ip}:${item.port} [${item.name}]`"
 | 
				
			||||||
 | 
					                                :value="item.id"
 | 
				
			||||||
 | 
					                            >
 | 
				
			||||||
 | 
					                            </el-option>
 | 
				
			||||||
 | 
					                        </el-select>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
            </el-form>
 | 
					            </el-form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <template #footer>
 | 
					            <template #footer>
 | 
				
			||||||
@@ -41,7 +59,9 @@
 | 
				
			|||||||
import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
 | 
					import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
 | 
				
			||||||
import { mongoApi } from './api';
 | 
					import { mongoApi } from './api';
 | 
				
			||||||
import { projectApi } from '../project/api.ts';
 | 
					import { projectApi } from '../project/api.ts';
 | 
				
			||||||
 | 
					import { machineApi } from '../machine/api.ts';
 | 
				
			||||||
import { ElMessage } from 'element-plus';
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
 | 
					import { RsaEncrypt } from '@/common/rsa';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'MongoEdit',
 | 
					    name: 'MongoEdit',
 | 
				
			||||||
@@ -65,10 +85,13 @@ export default defineComponent({
 | 
				
			|||||||
            dialogVisible: false,
 | 
					            dialogVisible: false,
 | 
				
			||||||
            projects: [],
 | 
					            projects: [],
 | 
				
			||||||
            envs: [],
 | 
					            envs: [],
 | 
				
			||||||
 | 
					            sshTunnelMachineList: [],
 | 
				
			||||||
            form: {
 | 
					            form: {
 | 
				
			||||||
                id: null,
 | 
					                id: null,
 | 
				
			||||||
                name: null,
 | 
					                name: null,
 | 
				
			||||||
                uri: null,
 | 
					                uri: null,
 | 
				
			||||||
 | 
					                enableSshTunnel: -1,
 | 
				
			||||||
 | 
					                sshTunnelMachineId: null,
 | 
				
			||||||
                project: null,
 | 
					                project: null,
 | 
				
			||||||
                projectId: null,
 | 
					                projectId: null,
 | 
				
			||||||
                envId: null,
 | 
					                envId: null,
 | 
				
			||||||
@@ -109,6 +132,9 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        watch(props, async (newValue) => {
 | 
					        watch(props, async (newValue) => {
 | 
				
			||||||
            state.dialogVisible = newValue.visible;
 | 
					            state.dialogVisible = newValue.visible;
 | 
				
			||||||
 | 
					            if (!state.dialogVisible) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            state.projects = newValue.projects;
 | 
					            state.projects = newValue.projects;
 | 
				
			||||||
            if (newValue.mongo) {
 | 
					            if (newValue.mongo) {
 | 
				
			||||||
                getEnvs(newValue.mongo.projectId);
 | 
					                getEnvs(newValue.mongo.projectId);
 | 
				
			||||||
@@ -117,8 +143,16 @@ export default defineComponent({
 | 
				
			|||||||
                state.envs = [];
 | 
					                state.envs = [];
 | 
				
			||||||
                state.form = { db: 0 } as any;
 | 
					                state.form = { db: 0 } as any;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            getSshTunnelMachines();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getSshTunnelMachines = async () => {
 | 
				
			||||||
 | 
					            if (state.form.enableSshTunnel == 1 && state.sshTunnelMachineList.length == 0) {
 | 
				
			||||||
 | 
					                const res = await machineApi.list.request({ pageNum: 1, pageSize: 100 });
 | 
				
			||||||
 | 
					                state.sshTunnelMachineList = res.list;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const getEnvs = async (projectId: any) => {
 | 
					        const getEnvs = async (projectId: any) => {
 | 
				
			||||||
            state.envs = await projectApi.projectEnvs.request({ projectId });
 | 
					            state.envs = await projectApi.projectEnvs.request({ projectId });
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
@@ -144,9 +178,11 @@ export default defineComponent({
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const btnOk = async () => {
 | 
					        const btnOk = async () => {
 | 
				
			||||||
            mongoForm.value.validate((valid: boolean) => {
 | 
					            mongoForm.value.validate(async (valid: boolean) => {
 | 
				
			||||||
                if (valid) {
 | 
					                if (valid) {
 | 
				
			||||||
                    mongoApi.saveMongo.request(state.form).then(() => {
 | 
					                    const reqForm = { ...state.form };
 | 
				
			||||||
 | 
					                    reqForm.uri = await RsaEncrypt(reqForm.uri);
 | 
				
			||||||
 | 
					                    mongoApi.saveMongo.request(reqForm).then(() => {
 | 
				
			||||||
                        ElMessage.success('保存成功');
 | 
					                        ElMessage.success('保存成功');
 | 
				
			||||||
                        emit('val-change', state.form);
 | 
					                        emit('val-change', state.form);
 | 
				
			||||||
                        state.btnLoading = true;
 | 
					                        state.btnLoading = true;
 | 
				
			||||||
@@ -172,6 +208,7 @@ export default defineComponent({
 | 
				
			|||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            mongoForm,
 | 
					            mongoForm,
 | 
				
			||||||
            changeProject,
 | 
					            changeProject,
 | 
				
			||||||
 | 
					            getSshTunnelMachines,
 | 
				
			||||||
            changeEnv,
 | 
					            changeEnv,
 | 
				
			||||||
            btnOk,
 | 
					            btnOk,
 | 
				
			||||||
            cancel,
 | 
					            cancel,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
        <el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false" :destroy-on-close="true" width="35%">
 | 
					        <el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" :close-on-click-modal="false" :destroy-on-close="true" width="38%">
 | 
				
			||||||
            <el-form :model="form" ref="redisForm" :rules="rules" label-width="85px">
 | 
					            <el-form :model="form" ref="redisForm" :rules="rules" label-width="85px">
 | 
				
			||||||
                <el-form-item prop="projectId" label="项目:" required>
 | 
					                <el-form-item prop="projectId" label="项目:" required>
 | 
				
			||||||
                    <el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
 | 
					                    <el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
 | 
				
			||||||
@@ -20,14 +20,19 @@
 | 
				
			|||||||
                    </el-select>
 | 
					                    </el-select>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="host" label="host:" required>
 | 
					                <el-form-item prop="host" label="host:" required>
 | 
				
			||||||
                    <el-input v-model.trim="form.host" placeholder="请输入host:port,集群模式用','分割" auto-complete="off" type="textarea"></el-input>
 | 
					                    <el-input
 | 
				
			||||||
 | 
					                        v-model.trim="form.host"
 | 
				
			||||||
 | 
					                        placeholder="请输入host:port,集群模式用','分割"
 | 
				
			||||||
 | 
					                        auto-complete="off"
 | 
				
			||||||
 | 
					                        type="textarea"
 | 
				
			||||||
 | 
					                    ></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
                <el-form-item prop="password" label="密码:">
 | 
					                <el-form-item prop="password" label="密码:">
 | 
				
			||||||
                    <el-input
 | 
					                    <el-input
 | 
				
			||||||
                        type="password"
 | 
					                        type="password"
 | 
				
			||||||
                        show-password
 | 
					                        show-password
 | 
				
			||||||
                        v-model.trim="form.password"
 | 
					                        v-model.trim="form.password"
 | 
				
			||||||
                        placeholder="请输入密码"
 | 
					                        placeholder="请输入密码, 修改操作可不填"
 | 
				
			||||||
                        autocomplete="new-password"
 | 
					                        autocomplete="new-password"
 | 
				
			||||||
                    ></el-input>
 | 
					                    ></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
@@ -37,12 +42,29 @@
 | 
				
			|||||||
                <el-form-item prop="remark" label="备注:">
 | 
					                <el-form-item prop="remark" label="备注:">
 | 
				
			||||||
                    <el-input v-model.trim="form.remark" auto-complete="off" type="textarea"></el-input>
 | 
					                    <el-input v-model.trim="form.remark" auto-complete="off" type="textarea"></el-input>
 | 
				
			||||||
                </el-form-item>
 | 
					                </el-form-item>
 | 
				
			||||||
 | 
					                <el-form-item prop="enableSshTunnel" label="SSH隧道:">
 | 
				
			||||||
 | 
					                    <el-col :span="3">
 | 
				
			||||||
 | 
					                        <el-checkbox @change="getSshTunnelMachines" v-model="form.enableSshTunnel" :true-label="1" :false-label="-1"></el-checkbox>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="2" v-if="form.enableSshTunnel == 1"> 机器: </el-col>
 | 
				
			||||||
 | 
					                    <el-col :span="19" v-if="form.enableSshTunnel == 1">
 | 
				
			||||||
 | 
					                        <el-select style="width: 100%" v-model="form.sshTunnelMachineId" placeholder="请选择SSH隧道机器">
 | 
				
			||||||
 | 
					                            <el-option
 | 
				
			||||||
 | 
					                                v-for="item in sshTunnelMachineList"
 | 
				
			||||||
 | 
					                                :key="item.id"
 | 
				
			||||||
 | 
					                                :label="`${item.ip}:${item.port} [${item.name}]`"
 | 
				
			||||||
 | 
					                                :value="item.id"
 | 
				
			||||||
 | 
					                            >
 | 
				
			||||||
 | 
					                            </el-option>
 | 
				
			||||||
 | 
					                        </el-select>
 | 
				
			||||||
 | 
					                    </el-col>
 | 
				
			||||||
 | 
					                </el-form-item>
 | 
				
			||||||
            </el-form>
 | 
					            </el-form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <template #footer>
 | 
					            <template #footer>
 | 
				
			||||||
                <div class="dialog-footer">
 | 
					                <div class="dialog-footer">
 | 
				
			||||||
                    <el-button @click="cancel()">取 消</el-button>
 | 
					                    <el-button @click="cancel()">取 消</el-button>
 | 
				
			||||||
                     <el-button type="primary" :loading="btnLoading" @click="btnOk">确 定</el-button>
 | 
					                    <el-button type="primary" :loading="btnLoading" @click="btnOk">确 定</el-button>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
            </template>
 | 
					            </template>
 | 
				
			||||||
        </el-dialog>
 | 
					        </el-dialog>
 | 
				
			||||||
@@ -53,7 +75,9 @@
 | 
				
			|||||||
import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
 | 
					import { toRefs, reactive, watch, defineComponent, ref } from 'vue';
 | 
				
			||||||
import { redisApi } from './api';
 | 
					import { redisApi } from './api';
 | 
				
			||||||
import { projectApi } from '../project/api.ts';
 | 
					import { projectApi } from '../project/api.ts';
 | 
				
			||||||
 | 
					import { machineApi } from '../machine/api.ts';
 | 
				
			||||||
import { ElMessage } from 'element-plus';
 | 
					import { ElMessage } from 'element-plus';
 | 
				
			||||||
 | 
					import { RsaEncrypt } from '@/common/rsa';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
    name: 'RedisEdit',
 | 
					    name: 'RedisEdit',
 | 
				
			||||||
@@ -77,17 +101,20 @@ export default defineComponent({
 | 
				
			|||||||
            dialogVisible: false,
 | 
					            dialogVisible: false,
 | 
				
			||||||
            projects: [],
 | 
					            projects: [],
 | 
				
			||||||
            envs: [],
 | 
					            envs: [],
 | 
				
			||||||
 | 
					            sshTunnelMachineList: [],
 | 
				
			||||||
            form: {
 | 
					            form: {
 | 
				
			||||||
                id: null,
 | 
					                id: null,
 | 
				
			||||||
                name: null,
 | 
					                name: null,
 | 
				
			||||||
                mode: "standalone",
 | 
					                mode: 'standalone',
 | 
				
			||||||
                host: null,
 | 
					                host: null,
 | 
				
			||||||
                password: null,
 | 
					                password: null,
 | 
				
			||||||
                project: null,
 | 
					                project: null,
 | 
				
			||||||
                projectId: null,
 | 
					                projectId: null,
 | 
				
			||||||
                envId: null,
 | 
					                envId: null,
 | 
				
			||||||
                env: null,
 | 
					                env: null,
 | 
				
			||||||
                remark: "",
 | 
					                remark: '',
 | 
				
			||||||
 | 
					                enableSshTunnel: null,
 | 
				
			||||||
 | 
					                sshTunnelMachineId: null,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            btnLoading: false,
 | 
					            btnLoading: false,
 | 
				
			||||||
            rules: {
 | 
					            rules: {
 | 
				
			||||||
@@ -131,16 +158,27 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        watch(props, async (newValue) => {
 | 
					        watch(props, async (newValue) => {
 | 
				
			||||||
            state.dialogVisible = newValue.visible;
 | 
					            state.dialogVisible = newValue.visible;
 | 
				
			||||||
 | 
					            if (!state.dialogVisible) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            state.projects = newValue.projects;
 | 
					            state.projects = newValue.projects;
 | 
				
			||||||
            if (newValue.redis) {
 | 
					            if (newValue.redis) {
 | 
				
			||||||
                getEnvs(newValue.redis.projectId);
 | 
					                getEnvs(newValue.redis.projectId);
 | 
				
			||||||
                state.form = { ...newValue.redis };
 | 
					                state.form = { ...newValue.redis };
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                state.envs = [];
 | 
					                state.envs = [];
 | 
				
			||||||
                state.form = { db: 0 } as any;
 | 
					                state.form = { db: 0, enableSshTunnel: -1 } as any;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            getSshTunnelMachines();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getSshTunnelMachines = async () => {
 | 
				
			||||||
 | 
					            if (state.form.enableSshTunnel == 1 && state.sshTunnelMachineList.length == 0) {
 | 
				
			||||||
 | 
					                const res = await machineApi.list.request({ pageNum: 1, pageSize: 100 });
 | 
				
			||||||
 | 
					                state.sshTunnelMachineList = res.list;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const getEnvs = async (projectId: any) => {
 | 
					        const getEnvs = async (projectId: any) => {
 | 
				
			||||||
            state.envs = await projectApi.projectEnvs.request({ projectId });
 | 
					            state.envs = await projectApi.projectEnvs.request({ projectId });
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
@@ -166,9 +204,11 @@ export default defineComponent({
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const btnOk = async () => {
 | 
					        const btnOk = async () => {
 | 
				
			||||||
            redisForm.value.validate((valid: boolean) => {
 | 
					            redisForm.value.validate(async (valid: boolean) => {
 | 
				
			||||||
                if (valid) {
 | 
					                if (valid) {
 | 
				
			||||||
                    redisApi.saveRedis.request(state.form).then(() => {
 | 
					                    const reqForm = { ...state.form };
 | 
				
			||||||
 | 
					                    reqForm.password = await RsaEncrypt(reqForm.password);
 | 
				
			||||||
 | 
					                    redisApi.saveRedis.request(reqForm).then(() => {
 | 
				
			||||||
                        ElMessage.success('保存成功');
 | 
					                        ElMessage.success('保存成功');
 | 
				
			||||||
                        emit('val-change', state.form);
 | 
					                        emit('val-change', state.form);
 | 
				
			||||||
                        state.btnLoading = true;
 | 
					                        state.btnLoading = true;
 | 
				
			||||||
@@ -193,6 +233,7 @@ export default defineComponent({
 | 
				
			|||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            redisForm,
 | 
					            redisForm,
 | 
				
			||||||
 | 
					            getSshTunnelMachines,
 | 
				
			||||||
            changeProject,
 | 
					            changeProject,
 | 
				
			||||||
            changeEnv,
 | 
					            changeEnv,
 | 
				
			||||||
            btnOk,
 | 
					            btnOk,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@
 | 
				
			|||||||
                <el-table-column prop="env" label="环境" min-width="100"></el-table-column>
 | 
					                <el-table-column prop="env" label="环境" min-width="100"></el-table-column>
 | 
				
			||||||
                <el-table-column prop="host" label="host:port" min-width="150" show-overflow-tooltip> </el-table-column>
 | 
					                <el-table-column prop="host" label="host:port" min-width="150" show-overflow-tooltip> </el-table-column>
 | 
				
			||||||
                <el-table-column prop="mode" label="mode" min-width="100"></el-table-column>
 | 
					                <el-table-column prop="mode" label="mode" min-width="100"></el-table-column>
 | 
				
			||||||
                <el-table-column prop="remark" label="备注" min-width="100"></el-table-column>
 | 
					                <el-table-column prop="remark" label="备注" min-width="120" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
                <el-table-column prop="createTime" label="创建时间" min-width="160">
 | 
					                <el-table-column prop="createTime" label="创建时间" min-width="160">
 | 
				
			||||||
                    <template #default="scope">
 | 
					                    <template #default="scope">
 | 
				
			||||||
                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
					                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,5 +33,5 @@ export const accountApi = {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const logApi = {
 | 
					export const logApi = {
 | 
				
			||||||
    list: Api.create("/sys/logs", "get")
 | 
					    list: Api.create("/syslogs", "get")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,15 +10,14 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            <div style="float: right">
 | 
					            <div style="float: right">
 | 
				
			||||||
                <el-input
 | 
					                <el-input
 | 
				
			||||||
                    placeholder="请输入角色名称!"
 | 
					                    placeholder="请输入角色名称"
 | 
				
			||||||
                    class="mr2"
 | 
					                    class="mr2"
 | 
				
			||||||
                    size="small"
 | 
					                    style="width: 200px"
 | 
				
			||||||
                    style="width: 300px"
 | 
					 | 
				
			||||||
                    v-model="query.name"
 | 
					                    v-model="query.name"
 | 
				
			||||||
                    @clear="search"
 | 
					                    @clear="search"
 | 
				
			||||||
                    clearable
 | 
					                    clearable
 | 
				
			||||||
                ></el-input>
 | 
					                ></el-input>
 | 
				
			||||||
                <el-button @click="search" type="success" icon="search" size="small"></el-button>
 | 
					                <el-button @click="search" type="success" icon="search"></el-button>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <el-table :data="roles" @current-change="choose" ref="table" style="width: 100%">
 | 
					            <el-table :data="roles" @current-change="choose" ref="table" style="width: 100%">
 | 
				
			||||||
                <el-table-column label="选择" width="50px">
 | 
					                <el-table-column label="选择" width="50px">
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										103
									
								
								mayfly_go_web/src/views/system/syslog/SyslogList.vue
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										103
									
								
								mayfly_go_web/src/views/system/syslog/SyslogList.vue
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,103 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					    <div class="role-list">
 | 
				
			||||||
 | 
					        <el-card>
 | 
				
			||||||
 | 
					            <div style="float: right">
 | 
				
			||||||
 | 
					                <el-select
 | 
				
			||||||
 | 
					                    remote
 | 
				
			||||||
 | 
					                    :remote-method="getAccount"
 | 
				
			||||||
 | 
					                    v-model="query.creatorId"
 | 
				
			||||||
 | 
					                    filterable
 | 
				
			||||||
 | 
					                    placeholder="请输入并选择账号"
 | 
				
			||||||
 | 
					                    clearable
 | 
				
			||||||
 | 
					                    class="mr5"
 | 
				
			||||||
 | 
					                >
 | 
				
			||||||
 | 
					                    <el-option v-for="item in accounts" :key="item.id" :label="item.username" :value="item.id"> </el-option>
 | 
				
			||||||
 | 
					                </el-select>
 | 
				
			||||||
 | 
					                <el-select v-model="query.type" filterable placeholder="请选择操作结果" clearable class="mr5">
 | 
				
			||||||
 | 
					                    <el-option label="成功" :value="1"> </el-option>
 | 
				
			||||||
 | 
					                    <el-option label="失败" :value="2"> </el-option>
 | 
				
			||||||
 | 
					                </el-select>
 | 
				
			||||||
 | 
					                <el-button @click="search" type="success" icon="search"></el-button>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            <el-table :data="logs" style="width: 100%">
 | 
				
			||||||
 | 
					                <el-table-column prop="creator" label="操作人" min-width="100" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column prop="createTime" label="操作时间" min-width="160">
 | 
				
			||||||
 | 
					                    <template #default="scope">
 | 
				
			||||||
 | 
					                        {{ $filters.dateFormat(scope.row.createTime) }}
 | 
				
			||||||
 | 
					                    </template>
 | 
				
			||||||
 | 
					                </el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column prop="type" label="结果" min-width="65">
 | 
				
			||||||
 | 
					                    <template #default="scope">
 | 
				
			||||||
 | 
					                        <el-tag v-if="scope.row.type == 1" type="success" size="small">成功</el-tag>
 | 
				
			||||||
 | 
					                        <el-tag v-if="scope.row.type == 2" type="danger" size="small">失败</el-tag>
 | 
				
			||||||
 | 
					                    </template>
 | 
				
			||||||
 | 
					                </el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column prop="description" label="描述" min-width="160" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                <el-table-column prop="reqParam" label="请求信息" min-width="300" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
 | 
					                <el-table-column prop="resp" label="响应信息" min-width="200" show-overflow-tooltip></el-table-column>
 | 
				
			||||||
 | 
					            </el-table>
 | 
				
			||||||
 | 
					            <el-row style="margin-top: 20px" type="flex" justify="end">
 | 
				
			||||||
 | 
					                <el-pagination
 | 
				
			||||||
 | 
					                    style="text-align: right"
 | 
				
			||||||
 | 
					                    @current-change="handlePageChange"
 | 
				
			||||||
 | 
					                    :total="total"
 | 
				
			||||||
 | 
					                    layout="prev, pager, next, total, jumper"
 | 
				
			||||||
 | 
					                    v-model:current-page="query.pageNum"
 | 
				
			||||||
 | 
					                    :page-size="query.pageSize"
 | 
				
			||||||
 | 
					                ></el-pagination>
 | 
				
			||||||
 | 
					            </el-row>
 | 
				
			||||||
 | 
					        </el-card>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script lang="ts">
 | 
				
			||||||
 | 
					import { toRefs, reactive, onMounted, defineComponent } from 'vue';
 | 
				
			||||||
 | 
					import { logApi, accountApi } from '../api';
 | 
				
			||||||
 | 
					export default defineComponent({
 | 
				
			||||||
 | 
					    name: 'SyslogList',
 | 
				
			||||||
 | 
					    components: {},
 | 
				
			||||||
 | 
					    setup() {
 | 
				
			||||||
 | 
					        const state = reactive({
 | 
				
			||||||
 | 
					            query: {
 | 
				
			||||||
 | 
					                pageNum: 1,
 | 
				
			||||||
 | 
					                pageSize: 10,
 | 
				
			||||||
 | 
					                name: null,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            total: 0,
 | 
				
			||||||
 | 
					            logs: [],
 | 
				
			||||||
 | 
					            accounts: [],
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        onMounted(() => {
 | 
				
			||||||
 | 
					            search();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const search = async () => {
 | 
				
			||||||
 | 
					            let res = await logApi.list.request(state.query);
 | 
				
			||||||
 | 
					            state.logs = res.list;
 | 
				
			||||||
 | 
					            state.total = res.total;
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const handlePageChange = (curPage: number) => {
 | 
				
			||||||
 | 
					            state.query.pageNum = curPage;
 | 
				
			||||||
 | 
					            search();
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const getAccount = (username: any) => {
 | 
				
			||||||
 | 
					            accountApi.list.request({ username }).then((res) => {
 | 
				
			||||||
 | 
					                state.accounts = res.list;
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            ...toRefs(state),
 | 
				
			||||||
 | 
					            search,
 | 
				
			||||||
 | 
					            handlePageChange,
 | 
				
			||||||
 | 
					            getAccount,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					<style lang="scss">
 | 
				
			||||||
 | 
					</style>
 | 
				
			||||||
@@ -30,7 +30,6 @@ const viteConfig: UserConfig = {
 | 
				
			|||||||
				target: 'http://localhost:8888',
 | 
									target: 'http://localhost:8888',
 | 
				
			||||||
				ws: true,
 | 
									ws: true,
 | 
				
			||||||
				changeOrigin: true,
 | 
									changeOrigin: true,
 | 
				
			||||||
				rewrite: (path) => path.replace(/^\/api/, '/'),
 | 
					 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 
 | 
				
			|||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -1,6 +1,6 @@
 | 
				
			|||||||
app:
 | 
					app:
 | 
				
			||||||
  name: mayfly-go
 | 
					  name: mayfly-go
 | 
				
			||||||
  version: 1.2.0
 | 
					  version: 1.2.3
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
server:
 | 
					server:
 | 
				
			||||||
  # debug release test
 | 
					  # debug release test
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,15 +6,16 @@ require (
 | 
				
			|||||||
	github.com/dgrijalva/jwt-go v3.2.0+incompatible // jwt
 | 
						github.com/dgrijalva/jwt-go v3.2.0+incompatible // jwt
 | 
				
			||||||
	github.com/gin-gonic/gin v1.8.1
 | 
						github.com/gin-gonic/gin v1.8.1
 | 
				
			||||||
	github.com/go-redis/redis/v8 v8.11.5
 | 
						github.com/go-redis/redis/v8 v8.11.5
 | 
				
			||||||
 | 
						github.com/go-sql-driver/mysql v1.6.0
 | 
				
			||||||
	github.com/gorilla/websocket v1.5.0
 | 
						github.com/gorilla/websocket v1.5.0
 | 
				
			||||||
	github.com/lib/pq v1.10.6
 | 
						github.com/lib/pq v1.10.6
 | 
				
			||||||
	github.com/mojocn/base64Captcha v1.3.5 // 验证码
 | 
						github.com/mojocn/base64Captcha v1.3.5 // 验证码
 | 
				
			||||||
	github.com/pkg/sftp v1.13.4
 | 
						github.com/pkg/sftp v1.13.5
 | 
				
			||||||
	github.com/robfig/cron/v3 v3.0.1 // 定时任务
 | 
						github.com/robfig/cron/v3 v3.0.1 // 定时任务
 | 
				
			||||||
	github.com/sirupsen/logrus v1.8.1
 | 
						github.com/sirupsen/logrus v1.8.1
 | 
				
			||||||
	github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
 | 
						github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
 | 
				
			||||||
	go.mongodb.org/mongo-driver v1.9.1 // mongo
 | 
						go.mongodb.org/mongo-driver v1.9.1 // mongo
 | 
				
			||||||
	golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // ssh
 | 
						golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // ssh
 | 
				
			||||||
	gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
 | 
						gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
 | 
				
			||||||
	// gorm
 | 
						// gorm
 | 
				
			||||||
	gorm.io/driver/mysql v1.3.4
 | 
						gorm.io/driver/mysql v1.3.4
 | 
				
			||||||
@@ -28,7 +29,6 @@ require (
 | 
				
			|||||||
	github.com/go-playground/locales v0.14.0 // indirect
 | 
						github.com/go-playground/locales v0.14.0 // indirect
 | 
				
			||||||
	github.com/go-playground/universal-translator v0.18.0 // indirect
 | 
						github.com/go-playground/universal-translator v0.18.0 // indirect
 | 
				
			||||||
	github.com/go-playground/validator/v10 v10.10.1 // indirect
 | 
						github.com/go-playground/validator/v10 v10.10.1 // indirect
 | 
				
			||||||
	github.com/go-sql-driver/mysql v1.6.0 // indirect
 | 
					 | 
				
			||||||
	github.com/go-stack/stack v1.8.0 // indirect
 | 
						github.com/go-stack/stack v1.8.0 // indirect
 | 
				
			||||||
	github.com/goccy/go-json v0.9.7 // indirect
 | 
						github.com/goccy/go-json v0.9.7 // indirect
 | 
				
			||||||
	github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
 | 
						github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,7 @@ package initialize
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	common_index_router "mayfly-go/internal/common/router"
 | 
						common_router "mayfly-go/internal/common/router"
 | 
				
			||||||
	devops_router "mayfly-go/internal/devops/router"
 | 
						devops_router "mayfly-go/internal/devops/router"
 | 
				
			||||||
	sys_router "mayfly-go/internal/sys/router"
 | 
						sys_router "mayfly-go/internal/sys/router"
 | 
				
			||||||
	"mayfly-go/pkg/config"
 | 
						"mayfly-go/pkg/config"
 | 
				
			||||||
@@ -46,13 +46,15 @@ func InitRouter() *gin.Engine {
 | 
				
			|||||||
	// 设置路由组
 | 
						// 设置路由组
 | 
				
			||||||
	api := router.Group("/api")
 | 
						api := router.Group("/api")
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		common_index_router.InitIndexRouter(api)
 | 
							common_router.InitIndexRouter(api)
 | 
				
			||||||
 | 
							common_router.InitCommonRouter(api)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		sys_router.InitCaptchaRouter(api)
 | 
							sys_router.InitCaptchaRouter(api)
 | 
				
			||||||
		sys_router.InitAccountRouter(api) // 注册account路由
 | 
							sys_router.InitAccountRouter(api) // 注册account路由
 | 
				
			||||||
		sys_router.InitResourceRouter(api)
 | 
							sys_router.InitResourceRouter(api)
 | 
				
			||||||
		sys_router.InitRoleRouter(api)
 | 
							sys_router.InitRoleRouter(api)
 | 
				
			||||||
		sys_router.InitSystemRouter(api)
 | 
							sys_router.InitSystemRouter(api)
 | 
				
			||||||
 | 
							sys_router.InitSyslogRouter(api)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		devops_router.InitProjectRouter(api)
 | 
							devops_router.InitProjectRouter(api)
 | 
				
			||||||
		devops_router.InitDbRouter(api)
 | 
							devops_router.InitDbRouter(api)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										10
									
								
								server/initialize/savelog.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								server/initialize/savelog.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					package initialize
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						sys_application "mayfly-go/internal/sys/application"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func InitSaveLogFunc() ctx.SaveLogFunc {
 | 
				
			||||||
 | 
						return sys_application.SyslogApp.SaveFromReq
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										16
									
								
								server/internal/common/api/common.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								server/internal/common/api/common.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					package api
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/utils"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Common struct {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (i *Common) RasPublicKey(rc *ctx.ReqCtx) {
 | 
				
			||||||
 | 
						publicKeyStr, err := utils.GetRsaPublicKey()
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "rsa生成公私钥失败")
 | 
				
			||||||
 | 
						rc.ResData = publicKeyStr
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										21
									
								
								server/internal/common/router/common.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								server/internal/common/router/common.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					package router
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"mayfly-go/internal/common/api"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func InitCommonRouter(router *gin.RouterGroup) {
 | 
				
			||||||
 | 
						common := router.Group("common")
 | 
				
			||||||
 | 
						c := &api.Common{}
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							// 获取公钥
 | 
				
			||||||
 | 
							common.GET("public-key", func(g *gin.Context) {
 | 
				
			||||||
 | 
								ctx.NewReqCtxWithGin(g).
 | 
				
			||||||
 | 
									WithNeedToken(false).
 | 
				
			||||||
 | 
									Handle(c.RasPublicKey)
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -45,10 +45,27 @@ func (d *Db) Save(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	form := &form.DbForm{}
 | 
						form := &form.DbForm{}
 | 
				
			||||||
	ginx.BindJsonAndValid(rc.GinCtx, form)
 | 
						ginx.BindJsonAndValid(rc.GinCtx, form)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rc.ReqParam = form
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	db := new(entity.Db)
 | 
						db := new(entity.Db)
 | 
				
			||||||
	utils.Copy(db, form)
 | 
						utils.Copy(db, form)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 密码解密,并使用解密后的赋值
 | 
				
			||||||
 | 
						originPwd, err := utils.DefaultRsaDecrypt(form.Password, true)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "解密密码错误: %s")
 | 
				
			||||||
 | 
						db.Password = originPwd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 密码脱敏记录日志
 | 
				
			||||||
 | 
						form.Password = "****"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// if form.Type == "mysql" && form.EnableSSH == 1 {
 | 
				
			||||||
 | 
						// 	// originSSHPwd, err := utils.DefaultRsaDecrypt(form.SSHPass, true)
 | 
				
			||||||
 | 
						// 	biz.ErrIsNilAppendErr(err, "解密密码错误: %s")
 | 
				
			||||||
 | 
						// 	// db.SSHPass = originSSHPwd
 | 
				
			||||||
 | 
						// 	// 密码脱敏记录日志
 | 
				
			||||||
 | 
						// 	form.SSHPass = "****"
 | 
				
			||||||
 | 
						// }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rc.ReqParam = form
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	db.SetBaseInfo(rc.LoginAccount)
 | 
						db.SetBaseInfo(rc.LoginAccount)
 | 
				
			||||||
	d.DbApp.Save(db)
 | 
						d.DbApp.Save(db)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -136,6 +153,8 @@ func (d *Db) ExecSqlFile(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	filename := fileheader.Filename
 | 
						filename := fileheader.Filename
 | 
				
			||||||
	dbId, db := GetIdAndDb(g)
 | 
						dbId, db := GetIdAndDb(g)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rc.ReqParam = fmt.Sprintf("dbId: %d, db: %s, filename: %s", dbId, db, filename)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	go func() {
 | 
						go func() {
 | 
				
			||||||
		db := d.DbApp.GetDbInstance(dbId, db)
 | 
							db := d.DbApp.GetDbInstance(dbId, db)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -192,7 +211,6 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	g.Header("Content-Type", "application/octet-stream")
 | 
						g.Header("Content-Type", "application/octet-stream")
 | 
				
			||||||
	g.Header("Content-Disposition", "attachment; filename="+filename)
 | 
						g.Header("Content-Disposition", "attachment; filename="+filename)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rc.ReqParam = fmt.Sprintf("数据库id: %d -- %s", dbId, db)
 | 
					 | 
				
			||||||
	writer := g.Writer
 | 
						writer := g.Writer
 | 
				
			||||||
	writer.WriteString("-- ----------------------------")
 | 
						writer.WriteString("-- ----------------------------")
 | 
				
			||||||
	writer.WriteString("\n-- 导出平台: mayfly-go")
 | 
						writer.WriteString("\n-- 导出平台: mayfly-go")
 | 
				
			||||||
@@ -258,6 +276,8 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
 | 
				
			|||||||
		writer.WriteString("COMMIT;\n")
 | 
							writer.WriteString("COMMIT;\n")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	rc.NoRes = true
 | 
						rc.NoRes = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rc.ReqParam = fmt.Sprintf("dbId: %d, db: %s, tables: %s, dumpType: %s", dbId, db, tablesStr, dumpType)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// @router /api/db/:dbId/t-metadata [get]
 | 
					// @router /api/db/:dbId/t-metadata [get]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,6 +14,9 @@ type DbForm struct {
 | 
				
			|||||||
	Project   string `json:"project"`
 | 
						Project   string `json:"project"`
 | 
				
			||||||
	Env       string `json:"env"`
 | 
						Env       string `json:"env"`
 | 
				
			||||||
	EnvId     uint64 `binding:"required" json:"envId"`
 | 
						EnvId     uint64 `binding:"required" json:"envId"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						EnableSshTunnel    int8   `json:"enableSshTunnel"`
 | 
				
			||||||
 | 
						SshTunnelMachineId uint64 `json:"sshTunnelMachineId"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type DbSqlSaveForm struct {
 | 
					type DbSqlSaveForm struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,14 +5,12 @@ type MachineForm struct {
 | 
				
			|||||||
	ProjectId   uint64 `json:"projectId"`
 | 
						ProjectId   uint64 `json:"projectId"`
 | 
				
			||||||
	ProjectName string `json:"projectName"`
 | 
						ProjectName string `json:"projectName"`
 | 
				
			||||||
	Name        string `json:"name" binding:"required"`
 | 
						Name        string `json:"name" binding:"required"`
 | 
				
			||||||
	// IP地址
 | 
						Ip          string `json:"ip" binding:"required"`       // IP地址
 | 
				
			||||||
	Ip string `json:"ip" binding:"required"`
 | 
						Username    string `json:"username" binding:"required"` // 用户名
 | 
				
			||||||
	// 用户名
 | 
						AuthMethod  int8   `json:"authMethod" binding:"required"`
 | 
				
			||||||
	Username string `json:"username" binding:"required"`
 | 
						Password    string `json:"password"`
 | 
				
			||||||
	Password string `json:"password"`
 | 
						Port        int    `json:"port" binding:"required"` // 端口号
 | 
				
			||||||
	// 端口号
 | 
						Remark      string `json:"remark"`
 | 
				
			||||||
	Port   int    `json:"port" binding:"required"`
 | 
					 | 
				
			||||||
	Remark string `json:"remark"`
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type MachineRunForm struct {
 | 
					type MachineRunForm struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,13 +1,15 @@
 | 
				
			|||||||
package form
 | 
					package form
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Mongo struct {
 | 
					type Mongo struct {
 | 
				
			||||||
	Id        uint64
 | 
						Id                 uint64
 | 
				
			||||||
	Uri       string `binding:"required" json:"uri"`
 | 
						Uri                string `binding:"required" json:"uri"`
 | 
				
			||||||
	Name      string `binding:"required" json:"name"`
 | 
						EnableSshTunnel    int8   `json:"enableSshTunnel"`    // 是否启用ssh隧道
 | 
				
			||||||
	ProjectId uint64 `binding:"required" json:"projectId"`
 | 
						SshTunnelMachineId uint64 `json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
	Project   string `json:"project"`
 | 
						Name               string `binding:"required" json:"name"`
 | 
				
			||||||
	Env       string `json:"env"`
 | 
						ProjectId          uint64 `binding:"required" json:"projectId"`
 | 
				
			||||||
	EnvId     uint64 `binding:"required" json:"envId"`
 | 
						Project            string `json:"project"`
 | 
				
			||||||
 | 
						Env                string `json:"env"`
 | 
				
			||||||
 | 
						EnvId              uint64 `binding:"required" json:"envId"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type MongoCommand struct {
 | 
					type MongoCommand struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,15 +1,18 @@
 | 
				
			|||||||
package form
 | 
					package form
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Redis struct {
 | 
					type Redis struct {
 | 
				
			||||||
	Id        uint64
 | 
						Id                 uint64
 | 
				
			||||||
	Host      string `binding:"required" json:"host"`
 | 
						Host               string `binding:"required" json:"host"`
 | 
				
			||||||
	Password  string `json:"password"`
 | 
						Password           string `json:"password"`
 | 
				
			||||||
	Mode      string `json:"mode"`
 | 
						Mode               string `json:"mode"`
 | 
				
			||||||
	Db        int    `json:"db"`
 | 
						Db                 int    `json:"db"`
 | 
				
			||||||
	ProjectId uint64 `binding:"required" json:"projectId"`
 | 
						EnableSshTunnel    int8   `json:"enableSshTunnel"`    // 是否启用ssh隧道
 | 
				
			||||||
	Project   string `json:"project"`
 | 
						SshTunnelMachineId uint64 `json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
	Env       string `json:"env"`
 | 
						ProjectId          uint64 `binding:"required" json:"projectId"`
 | 
				
			||||||
	EnvId     uint64 `binding:"required" json:"envId"`
 | 
						Project            string `json:"project"`
 | 
				
			||||||
 | 
						Env                string `json:"env"`
 | 
				
			||||||
 | 
						EnvId              uint64 `binding:"required" json:"envId"`
 | 
				
			||||||
 | 
						Remark             string `json:"remark"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type KeyInfo struct {
 | 
					type KeyInfo struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -54,11 +54,22 @@ func (m *Machine) SaveMachine(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	machineForm := new(form.MachineForm)
 | 
						machineForm := new(form.MachineForm)
 | 
				
			||||||
	ginx.BindJsonAndValid(g, machineForm)
 | 
						ginx.BindJsonAndValid(g, machineForm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	entity := new(entity.Machine)
 | 
						me := new(entity.Machine)
 | 
				
			||||||
	utils.Copy(entity, machineForm)
 | 
						utils.Copy(me, machineForm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	entity.SetBaseInfo(rc.LoginAccount)
 | 
						if me.AuthMethod == entity.MachineAuthMethodPassword {
 | 
				
			||||||
	m.MachineApp.Save(entity)
 | 
							// 密码解密,并使用解密后的赋值
 | 
				
			||||||
 | 
							originPwd, err := utils.DefaultRsaDecrypt(machineForm.Password, true)
 | 
				
			||||||
 | 
							biz.ErrIsNilAppendErr(err, "解密密码错误: %s")
 | 
				
			||||||
 | 
							me.Password = originPwd
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 密码脱敏记录日志
 | 
				
			||||||
 | 
						machineForm.Password = "****"
 | 
				
			||||||
 | 
						rc.ReqParam = machineForm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						me.SetBaseInfo(rc.LoginAccount)
 | 
				
			||||||
 | 
						m.MachineApp.Save(me)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *Machine) ChangeStatus(rc *ctx.ReqCtx) {
 | 
					func (m *Machine) ChangeStatus(rc *ctx.ReqCtx) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,6 +38,11 @@ func (m *Mongo) Save(rc *ctx.ReqCtx) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	mongo := new(entity.Mongo)
 | 
						mongo := new(entity.Mongo)
 | 
				
			||||||
	utils.Copy(mongo, form)
 | 
						utils.Copy(mongo, form)
 | 
				
			||||||
 | 
						// 解密uri,并使用解密后的赋值
 | 
				
			||||||
 | 
						originUri, err := utils.DefaultRsaDecrypt(form.Uri, true)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "解密uri错误: %s")
 | 
				
			||||||
 | 
						mongo.Uri = originUri
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mongo.SetBaseInfo(rc.LoginAccount)
 | 
						mongo.SetBaseInfo(rc.LoginAccount)
 | 
				
			||||||
	m.MongoApp.Save(mongo)
 | 
						m.MongoApp.Save(mongo)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,7 +43,8 @@ func (p *Project) GetProjects(rc *ctx.ReqCtx) {
 | 
				
			|||||||
func (p *Project) SaveProject(rc *ctx.ReqCtx) {
 | 
					func (p *Project) SaveProject(rc *ctx.ReqCtx) {
 | 
				
			||||||
	project := &entity.Project{}
 | 
						project := &entity.Project{}
 | 
				
			||||||
	ginx.BindJsonAndValid(rc.GinCtx, project)
 | 
						ginx.BindJsonAndValid(rc.GinCtx, project)
 | 
				
			||||||
	rc.ReqParam = project
 | 
					
 | 
				
			||||||
 | 
						rc.ReqParam = fmt.Sprintf("projectId: %d, projectName: %s, remark: %s", project.Id, project.Name, project.Remark)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	project.SetBaseInfo(rc.LoginAccount)
 | 
						project.SetBaseInfo(rc.LoginAccount)
 | 
				
			||||||
	p.ProjectApp.SaveProject(project)
 | 
						p.ProjectApp.SaveProject(project)
 | 
				
			||||||
@@ -81,7 +82,8 @@ func (p *Project) GetProjectMembers(rc *ctx.ReqCtx) {
 | 
				
			|||||||
func (p *Project) SaveProjectMember(rc *ctx.ReqCtx) {
 | 
					func (p *Project) SaveProjectMember(rc *ctx.ReqCtx) {
 | 
				
			||||||
	projectMem := &entity.ProjectMember{}
 | 
						projectMem := &entity.ProjectMember{}
 | 
				
			||||||
	ginx.BindJsonAndValid(rc.GinCtx, projectMem)
 | 
						ginx.BindJsonAndValid(rc.GinCtx, projectMem)
 | 
				
			||||||
	rc.ReqParam = projectMem
 | 
					
 | 
				
			||||||
 | 
						rc.ReqParam = fmt.Sprintf("projectId: %d, username: %s", projectMem.ProjectId, projectMem.Username)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 校验账号,并赋值username
 | 
						// 校验账号,并赋值username
 | 
				
			||||||
	account := &sys_entity.Account{}
 | 
						account := &sys_entity.Account{}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,10 +36,18 @@ func (r *Redis) Save(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	form := &form.Redis{}
 | 
						form := &form.Redis{}
 | 
				
			||||||
	ginx.BindJsonAndValid(rc.GinCtx, form)
 | 
						ginx.BindJsonAndValid(rc.GinCtx, form)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rc.ReqParam = form
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	redis := new(entity.Redis)
 | 
						redis := new(entity.Redis)
 | 
				
			||||||
	utils.Copy(redis, form)
 | 
						utils.Copy(redis, form)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 密码解密,并使用解密后的赋值
 | 
				
			||||||
 | 
						originPwd, err := utils.DefaultRsaDecrypt(redis.Password, true)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "解密密码错误: %s")
 | 
				
			||||||
 | 
						redis.Password = originPwd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 密码脱敏记录日志
 | 
				
			||||||
 | 
						form.Password = "****"
 | 
				
			||||||
 | 
						rc.ReqParam = form
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	redis.SetBaseInfo(rc.LoginAccount)
 | 
						redis.SetBaseInfo(rc.LoginAccount)
 | 
				
			||||||
	r.RedisApp.Save(redis)
 | 
						r.RedisApp.Save(redis)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,4 +19,7 @@ type SelectDataDbVO struct {
 | 
				
			|||||||
	CreateTime *time.Time `json:"createTime"`
 | 
						CreateTime *time.Time `json:"createTime"`
 | 
				
			||||||
	Creator    *string    `json:"creator"`
 | 
						Creator    *string    `json:"creator"`
 | 
				
			||||||
	CreatorId  *int64     `json:"creatorId"`
 | 
						CreatorId  *int64     `json:"creatorId"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						EnableSshTunnel    *int8   `json:"enableSshTunnel"`
 | 
				
			||||||
 | 
						SshTunnelMachineId *uint64 `json:"sshTunnelMachineId"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,17 +5,19 @@ import "time"
 | 
				
			|||||||
type Redis struct {
 | 
					type Redis struct {
 | 
				
			||||||
	Id *int64 `json:"id"`
 | 
						Id *int64 `json:"id"`
 | 
				
			||||||
	// Name       *string    `json:"name"`
 | 
						// Name       *string    `json:"name"`
 | 
				
			||||||
	Host       *string    `json:"host"`
 | 
						Host               *string    `json:"host"`
 | 
				
			||||||
	Db         int        `json:"db"`
 | 
						Db                 int        `json:"db"`
 | 
				
			||||||
	ProjectId  *int64     `json:"projectId"`
 | 
						ProjectId          *int64     `json:"projectId"`
 | 
				
			||||||
	Project    *string    `json:"project"`
 | 
						Project            *string    `json:"project"`
 | 
				
			||||||
	Mode       *string    `json:"mode"`
 | 
						Mode               *string    `json:"mode"`
 | 
				
			||||||
	Remark     *string    `json:"remark"`
 | 
						EnableSshTunnel    *int8      `orm:"column(enable_ssh_tunnel)" json:"enableSshTunnel"`        // 是否启用ssh隧道
 | 
				
			||||||
	Env        *string    `json:"env"`
 | 
						SshTunnelMachineId *uint64    `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
	EnvId      *int64     `json:"envId"`
 | 
						Remark             *string    `json:"remark"`
 | 
				
			||||||
	CreateTime *time.Time `json:"createTime"`
 | 
						Env                *string    `json:"env"`
 | 
				
			||||||
	Creator    *string    `json:"creator"`
 | 
						EnvId              *int64     `json:"envId"`
 | 
				
			||||||
	CreatorId  *int64     `json:"creatorId"`
 | 
						CreateTime         *time.Time `json:"createTime"`
 | 
				
			||||||
 | 
						Creator            *string    `json:"creator"`
 | 
				
			||||||
 | 
						CreatorId          *int64     `json:"creatorId"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Keys struct {
 | 
					type Keys struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,6 +22,7 @@ type MachineVO struct {
 | 
				
			|||||||
	Username    *string    `json:"username"`
 | 
						Username    *string    `json:"username"`
 | 
				
			||||||
	Ip          *string    `json:"ip"`
 | 
						Ip          *string    `json:"ip"`
 | 
				
			||||||
	Port        *int       `json:"port"`
 | 
						Port        *int       `json:"port"`
 | 
				
			||||||
 | 
						AuthMethod  *int8      `json:"authMethod"`
 | 
				
			||||||
	Status      *int8      `json:"status"`
 | 
						Status      *int8      `json:"status"`
 | 
				
			||||||
	CreateTime  *time.Time `json:"createTime"`
 | 
						CreateTime  *time.Time `json:"createTime"`
 | 
				
			||||||
	Creator     *string    `json:"creator"`
 | 
						Creator     *string    `json:"creator"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,24 +1,29 @@
 | 
				
			|||||||
package application
 | 
					package application
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
	"database/sql"
 | 
						"database/sql"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"mayfly-go/internal/devops/domain/entity"
 | 
						"mayfly-go/internal/devops/domain/entity"
 | 
				
			||||||
	"mayfly-go/internal/devops/domain/repository"
 | 
						"mayfly-go/internal/devops/domain/repository"
 | 
				
			||||||
 | 
						"mayfly-go/internal/devops/infrastructure/machine"
 | 
				
			||||||
	"mayfly-go/internal/devops/infrastructure/persistence"
 | 
						"mayfly-go/internal/devops/infrastructure/persistence"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/cache"
 | 
						"mayfly-go/pkg/cache"
 | 
				
			||||||
	"mayfly-go/pkg/global"
 | 
						"mayfly-go/pkg/global"
 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
	"mayfly-go/pkg/utils"
 | 
						"mayfly-go/pkg/utils"
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
	"reflect"
 | 
						"reflect"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_ "github.com/lib/pq"
 | 
						"github.com/go-sql-driver/mysql"
 | 
				
			||||||
 | 
						"github.com/lib/pq"
 | 
				
			||||||
 | 
						"golang.org/x/crypto/ssh"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Db interface {
 | 
					type Db interface {
 | 
				
			||||||
@@ -75,10 +80,11 @@ func (d *dbAppImpl) GetById(id uint64, cols ...string) *entity.Db {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (d *dbAppImpl) Save(dbEntity *entity.Db) {
 | 
					func (d *dbAppImpl) Save(dbEntity *entity.Db) {
 | 
				
			||||||
	// 默认tcp连接
 | 
						// 默认tcp连接
 | 
				
			||||||
	dbEntity.Network = "tcp"
 | 
						dbEntity.Network = dbEntity.GetNetwork()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 测试连接
 | 
						// 测试连接
 | 
				
			||||||
	if dbEntity.Password != "" {
 | 
						if dbEntity.Password != "" {
 | 
				
			||||||
		TestConnection(*dbEntity)
 | 
							TestConnection(dbEntity)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 查找是否存在该库
 | 
						// 查找是否存在该库
 | 
				
			||||||
@@ -102,6 +108,8 @@ func (d *dbAppImpl) Save(dbEntity *entity.Db) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	var oldDbs []interface{}
 | 
						var oldDbs []interface{}
 | 
				
			||||||
	for _, v := range strings.Split(old.Database, " ") {
 | 
						for _, v := range strings.Split(old.Database, " ") {
 | 
				
			||||||
 | 
							// 关闭数据库连接
 | 
				
			||||||
 | 
							CloseDb(dbEntity.Id, v)
 | 
				
			||||||
		oldDbs = append(oldDbs, v)
 | 
							oldDbs = append(oldDbs, v)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -114,14 +122,11 @@ func (d *dbAppImpl) Save(dbEntity *entity.Db) {
 | 
				
			|||||||
		return i1.(string) == i2.(string)
 | 
							return i1.(string) == i2.(string)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	for _, v := range delDb {
 | 
						for _, v := range delDb {
 | 
				
			||||||
		// 先关闭数据库连接
 | 
					 | 
				
			||||||
		CloseDb(dbEntity.Id, v.(string))
 | 
					 | 
				
			||||||
		// 删除该库关联的所有sql记录
 | 
							// 删除该库关联的所有sql记录
 | 
				
			||||||
		d.dbSqlRepo.DeleteBy(&entity.DbSql{DbId: dbId, Db: v.(string)})
 | 
							d.dbSqlRepo.DeleteBy(&entity.DbSql{DbId: dbId, Db: v.(string)})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	d.dbRepo.Update(dbEntity)
 | 
						d.dbRepo.Update(dbEntity)
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *dbAppImpl) Delete(id uint64) {
 | 
					func (d *dbAppImpl) Delete(id uint64) {
 | 
				
			||||||
@@ -153,16 +158,43 @@ func (da *dbAppImpl) GetDbInstance(id uint64, db string) *DbInstance {
 | 
				
			|||||||
	d := da.GetById(id)
 | 
						d := da.GetById(id)
 | 
				
			||||||
	biz.NotNil(d, "数据库信息不存在")
 | 
						biz.NotNil(d, "数据库信息不存在")
 | 
				
			||||||
	biz.IsTrue(strings.Contains(d.Database, db), "未配置该库的操作权限")
 | 
						biz.IsTrue(strings.Contains(d.Database, db), "未配置该库的操作权限")
 | 
				
			||||||
	global.Log.Infof("连接db: %s:%d/%s", d.Host, d.Port, db)
 | 
					
 | 
				
			||||||
 | 
						cacheKey := GetDbCacheKey(id, db)
 | 
				
			||||||
 | 
						dbi := &DbInstance{Id: cacheKey, Type: d.Type, ProjectId: d.ProjectId}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						//SSH Conect
 | 
				
			||||||
 | 
						if d.EnableSshTunnel == 1 && d.SshTunnelMachineId != 0 {
 | 
				
			||||||
 | 
							me := MachineApp.GetById(d.SshTunnelMachineId)
 | 
				
			||||||
 | 
							biz.NotNil(me, "隧道机器信息不存在")
 | 
				
			||||||
 | 
							sshClient, err := machine.GetSshClient(me)
 | 
				
			||||||
 | 
							biz.ErrIsNilAppendErr(err, "ssh隧道连接失败: %s")
 | 
				
			||||||
 | 
							dbi.sshTunnel = sshClient
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if d.Type == entity.DbTypeMysql {
 | 
				
			||||||
 | 
								mysql.RegisterDialContext(d.Network, func(ctx context.Context, addr string) (net.Conn, error) {
 | 
				
			||||||
 | 
									return sshClient.Dial("tcp", addr)
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
							} else if d.Type == entity.DbTypePostgres {
 | 
				
			||||||
 | 
								_, err := pq.DialOpen(&PqSqlDialer{sshTunnel: sshClient}, getDsn(d))
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									dbi.Close()
 | 
				
			||||||
 | 
									panic(biz.NewBizErr(fmt.Sprintf("postgres隧道连接失败: %s", err.Error())))
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 将数据库替换为要访问的数据库,原本数据库为空格拼接的所有库
 | 
						// 将数据库替换为要访问的数据库,原本数据库为空格拼接的所有库
 | 
				
			||||||
	d.Database = db
 | 
						d.Database = db
 | 
				
			||||||
	DB, err := sql.Open(d.Type, getDsn(d))
 | 
						DB, err := sql.Open(d.Type, getDsn(d))
 | 
				
			||||||
	biz.ErrIsNil(err, fmt.Sprintf("Open %s failed, err:%v\n", d.Type, err))
 | 
						if err != nil {
 | 
				
			||||||
	perr := DB.Ping()
 | 
							dbi.Close()
 | 
				
			||||||
	if perr != nil {
 | 
							panic(biz.NewBizErr(fmt.Sprintf("Open %s failed, err:%v\n", d.Type, err)))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						err = DB.Ping()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							dbi.Close()
 | 
				
			||||||
		global.Log.Errorf("连接db失败: %s:%d/%s", d.Host, d.Port, db)
 | 
							global.Log.Errorf("连接db失败: %s:%d/%s", d.Host, d.Port, db)
 | 
				
			||||||
		panic(biz.NewBizErr(fmt.Sprintf("数据库连接失败: %s", perr.Error())))
 | 
							panic(biz.NewBizErr(fmt.Sprintf("数据库连接失败: %s", err.Error())))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 最大连接周期,超过时间的连接就close
 | 
						// 最大连接周期,超过时间的连接就close
 | 
				
			||||||
@@ -172,14 +204,30 @@ func (da *dbAppImpl) GetDbInstance(id uint64, db string) *DbInstance {
 | 
				
			|||||||
	// 设置闲置连接数
 | 
						// 设置闲置连接数
 | 
				
			||||||
	DB.SetMaxIdleConns(1)
 | 
						DB.SetMaxIdleConns(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cacheKey := GetDbCacheKey(id, db)
 | 
						dbi.db = DB
 | 
				
			||||||
	dbi := &DbInstance{Id: cacheKey, Type: d.Type, ProjectId: d.ProjectId, db: DB}
 | 
						global.Log.Infof("连接db: %s:%d/%s", d.Host, d.Port, db)
 | 
				
			||||||
	if needCache {
 | 
						if needCache {
 | 
				
			||||||
		dbCache.Put(cacheKey, dbi)
 | 
							dbCache.Put(cacheKey, dbi)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return dbi
 | 
						return dbi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type PqSqlDialer struct {
 | 
				
			||||||
 | 
						sshTunnel *ssh.Client
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (pd *PqSqlDialer) Dial(network, address string) (net.Conn, error) {
 | 
				
			||||||
 | 
						if sshConn, err := pd.sshTunnel.Dial(network, address); err == nil {
 | 
				
			||||||
 | 
							// 将ssh conn包装,否则redis内部设置超时会报错,ssh conn不支持设置超时会返回错误: ssh: tcpChan: deadline not supported
 | 
				
			||||||
 | 
							return &utils.WrapSshConn{Conn: sshConn}, nil
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					func (pd *PqSqlDialer) DialTimeout(network, address string, timeout time.Duration) (net.Conn, error) {
 | 
				
			||||||
 | 
						return pd.Dial(network, address)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//------------------------------------------------------------------------------
 | 
					//------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 客户端连接缓存,30分钟内没有访问则会被关闭, key为数据库实例id:数据库
 | 
					// 客户端连接缓存,30分钟内没有访问则会被关闭, key为数据库实例id:数据库
 | 
				
			||||||
@@ -201,10 +249,28 @@ func GetDbInstanceByCache(id string) *DbInstance {
 | 
				
			|||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestConnection(d entity.Db) {
 | 
					func TestConnection(d *entity.Db) {
 | 
				
			||||||
 | 
						//SSH Conect
 | 
				
			||||||
 | 
						if d.EnableSshTunnel == 1 && d.SshTunnelMachineId != 0 {
 | 
				
			||||||
 | 
							me := MachineApp.GetById(d.SshTunnelMachineId)
 | 
				
			||||||
 | 
							sshClient, err := machine.GetSshClient(me)
 | 
				
			||||||
 | 
							biz.ErrIsNilAppendErr(err, "ssh隧道连接失败: %s")
 | 
				
			||||||
 | 
							defer sshClient.Close()
 | 
				
			||||||
 | 
							if d.Type == entity.DbTypeMysql {
 | 
				
			||||||
 | 
								mysql.RegisterDialContext(d.Network, func(ctx context.Context, addr string) (net.Conn, error) {
 | 
				
			||||||
 | 
									return sshClient.Dial("tcp", addr)
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
							} else if d.Type == entity.DbTypePostgres {
 | 
				
			||||||
 | 
								_, err := pq.DialOpen(&PqSqlDialer{sshTunnel: sshClient}, getDsn(d))
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									panic(biz.NewBizErr(fmt.Sprintf("postgres隧道连接失败: %s", err.Error())))
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 验证第一个库是否可以连接即可
 | 
						// 验证第一个库是否可以连接即可
 | 
				
			||||||
	d.Database = strings.Split(d.Database, " ")[0]
 | 
						d.Database = strings.Split(d.Database, " ")[0]
 | 
				
			||||||
	DB, err := sql.Open(d.Type, getDsn(&d))
 | 
						DB, err := sql.Open(d.Type, getDsn(d))
 | 
				
			||||||
	biz.ErrIsNil(err, "Open %s failed, err:%v\n", d.Type, err)
 | 
						biz.ErrIsNil(err, "Open %s failed, err:%v\n", d.Type, err)
 | 
				
			||||||
	defer DB.Close()
 | 
						defer DB.Close()
 | 
				
			||||||
	perr := DB.Ping()
 | 
						perr := DB.Ping()
 | 
				
			||||||
@@ -217,6 +283,7 @@ type DbInstance struct {
 | 
				
			|||||||
	Type      string
 | 
						Type      string
 | 
				
			||||||
	ProjectId uint64
 | 
						ProjectId uint64
 | 
				
			||||||
	db        *sql.DB
 | 
						db        *sql.DB
 | 
				
			||||||
 | 
						sshTunnel *ssh.Client
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 执行查询语句
 | 
					// 执行查询语句
 | 
				
			||||||
@@ -328,13 +395,22 @@ func (d *DbInstance) Exec(sql string) (int64, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// 关闭连接
 | 
					// 关闭连接
 | 
				
			||||||
func (d *DbInstance) Close() {
 | 
					func (d *DbInstance) Close() {
 | 
				
			||||||
	d.db.Close()
 | 
						if d.db != nil {
 | 
				
			||||||
 | 
							if err := d.db.Close(); err != nil {
 | 
				
			||||||
 | 
								global.Log.Errorf("关闭数据库实例[%s]连接失败: %s", d.Id, err.Error())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if d.sshTunnel != nil {
 | 
				
			||||||
 | 
							if err := d.sshTunnel.Close(); err != nil {
 | 
				
			||||||
 | 
								global.Log.Errorf("关闭数据库实例[%s]的ssh隧道失败: %s", d.Id, err.Error())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 获取dataSourceName
 | 
					// 获取dataSourceName
 | 
				
			||||||
func getDsn(d *entity.Db) string {
 | 
					func getDsn(d *entity.Db) string {
 | 
				
			||||||
	var dsn string
 | 
						var dsn string
 | 
				
			||||||
	if d.Type == "mysql" {
 | 
						if d.Type == entity.DbTypeMysql {
 | 
				
			||||||
		dsn = fmt.Sprintf("%s:%s@%s(%s:%d)/%s?timeout=8s", d.Username, d.Password, d.Network, d.Host, d.Port, d.Database)
 | 
							dsn = fmt.Sprintf("%s:%s@%s(%s:%d)/%s?timeout=8s", d.Username, d.Password, d.Network, d.Host, d.Port, d.Database)
 | 
				
			||||||
		if d.Params != "" {
 | 
							if d.Params != "" {
 | 
				
			||||||
			dsn = fmt.Sprintf("%s&%s", dsn, d.Params)
 | 
								dsn = fmt.Sprintf("%s&%s", dsn, d.Params)
 | 
				
			||||||
@@ -342,7 +418,7 @@ func getDsn(d *entity.Db) string {
 | 
				
			|||||||
		return dsn
 | 
							return dsn
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if d.Type == "postgres" {
 | 
						if d.Type == entity.DbTypePostgres {
 | 
				
			||||||
		dsn = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", d.Host, d.Port, d.Username, d.Password, d.Database)
 | 
							dsn = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", d.Host, d.Port, d.Username, d.Password, d.Database)
 | 
				
			||||||
		if d.Params != "" {
 | 
							if d.Params != "" {
 | 
				
			||||||
			dsn = fmt.Sprintf("%s %s", dsn, strings.Join(strings.Split(d.Params, "&"), " "))
 | 
								dsn = fmt.Sprintf("%s %s", dsn, strings.Join(strings.Split(d.Params, "&"), " "))
 | 
				
			||||||
@@ -438,7 +514,7 @@ const (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (d *DbInstance) GetTableMetedatas() []map[string]interface{} {
 | 
					func (d *DbInstance) GetTableMetedatas() []map[string]interface{} {
 | 
				
			||||||
	var sql string
 | 
						var sql string
 | 
				
			||||||
	if d.Type == "mysql" {
 | 
						if d.Type == entity.DbTypeMysql {
 | 
				
			||||||
		sql = MYSQL_TABLE_MA
 | 
							sql = MYSQL_TABLE_MA
 | 
				
			||||||
	} else if d.Type == "postgres" {
 | 
						} else if d.Type == "postgres" {
 | 
				
			||||||
		sql = PGSQL_TABLE_MA
 | 
							sql = PGSQL_TABLE_MA
 | 
				
			||||||
@@ -458,10 +534,10 @@ func (d *DbInstance) GetColumnMetadatas(tableNames ...string) []map[string]inter
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	var countSqlTmp string
 | 
						var countSqlTmp string
 | 
				
			||||||
	var sqlTmp string
 | 
						var sqlTmp string
 | 
				
			||||||
	if d.Type == "mysql" {
 | 
						if d.Type == entity.DbTypeMysql {
 | 
				
			||||||
		countSqlTmp = MYSQL_COLOUMN_MA_COUNT
 | 
							countSqlTmp = MYSQL_COLOUMN_MA_COUNT
 | 
				
			||||||
		sqlTmp = MYSQL_COLUMN_MA
 | 
							sqlTmp = MYSQL_COLUMN_MA
 | 
				
			||||||
	} else if d.Type == "postgres" {
 | 
						} else if d.Type == entity.DbTypePostgres {
 | 
				
			||||||
		countSqlTmp = PGSQL_COLUMN_MA_COUNT
 | 
							countSqlTmp = PGSQL_COLUMN_MA_COUNT
 | 
				
			||||||
		sqlTmp = PGSQL_COLUMN_MA
 | 
							sqlTmp = PGSQL_COLUMN_MA
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -493,9 +569,9 @@ func (d *DbInstance) GetPrimaryKey(tablename string) string {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (d *DbInstance) GetTableInfos() []map[string]interface{} {
 | 
					func (d *DbInstance) GetTableInfos() []map[string]interface{} {
 | 
				
			||||||
	var sql string
 | 
						var sql string
 | 
				
			||||||
	if d.Type == "mysql" {
 | 
						if d.Type == entity.DbTypeMysql {
 | 
				
			||||||
		sql = MYSQL_TABLE_INFO
 | 
							sql = MYSQL_TABLE_INFO
 | 
				
			||||||
	} else if d.Type == "postgres" {
 | 
						} else if d.Type == entity.DbTypePostgres {
 | 
				
			||||||
		sql = PGSQL_TABLE_INFO
 | 
							sql = PGSQL_TABLE_INFO
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	_, res, _ := d.SelectData(sql)
 | 
						_, res, _ := d.SelectData(sql)
 | 
				
			||||||
@@ -504,9 +580,9 @@ func (d *DbInstance) GetTableInfos() []map[string]interface{} {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (d *DbInstance) GetTableIndex(tableName string) []map[string]interface{} {
 | 
					func (d *DbInstance) GetTableIndex(tableName string) []map[string]interface{} {
 | 
				
			||||||
	var sql string
 | 
						var sql string
 | 
				
			||||||
	if d.Type == "mysql" {
 | 
						if d.Type == entity.DbTypeMysql {
 | 
				
			||||||
		sql = fmt.Sprintf(MYSQL_INDEX_INFO, tableName)
 | 
							sql = fmt.Sprintf(MYSQL_INDEX_INFO, tableName)
 | 
				
			||||||
	} else if d.Type == "postgres" {
 | 
						} else if d.Type == entity.DbTypePostgres {
 | 
				
			||||||
		sql = fmt.Sprintf(PGSQL_INDEX_INFO, tableName)
 | 
							sql = fmt.Sprintf(PGSQL_INDEX_INFO, tableName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	_, res, _ := d.SelectData(sql)
 | 
						_, res, _ := d.SelectData(sql)
 | 
				
			||||||
@@ -515,7 +591,7 @@ func (d *DbInstance) GetTableIndex(tableName string) []map[string]interface{} {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (d *DbInstance) GetCreateTableDdl(tableName string) []map[string]interface{} {
 | 
					func (d *DbInstance) GetCreateTableDdl(tableName string) []map[string]interface{} {
 | 
				
			||||||
	var sql string
 | 
						var sql string
 | 
				
			||||||
	if d.Type == "mysql" {
 | 
						if d.Type == entity.DbTypeMysql {
 | 
				
			||||||
		sql = fmt.Sprintf("show create table %s ", tableName)
 | 
							sql = fmt.Sprintf("show create table %s ", tableName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	_, res, _ := d.SelectData(sql)
 | 
						_, res, _ := d.SelectData(sql)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,15 +4,19 @@ import (
 | 
				
			|||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"mayfly-go/internal/devops/domain/entity"
 | 
						"mayfly-go/internal/devops/domain/entity"
 | 
				
			||||||
	"mayfly-go/internal/devops/domain/repository"
 | 
						"mayfly-go/internal/devops/domain/repository"
 | 
				
			||||||
 | 
						"mayfly-go/internal/devops/infrastructure/machine"
 | 
				
			||||||
	"mayfly-go/internal/devops/infrastructure/persistence"
 | 
						"mayfly-go/internal/devops/infrastructure/persistence"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/cache"
 | 
						"mayfly-go/pkg/cache"
 | 
				
			||||||
	"mayfly-go/pkg/global"
 | 
						"mayfly-go/pkg/global"
 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/utils"
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"go.mongodb.org/mongo-driver/mongo"
 | 
						"go.mongodb.org/mongo-driver/mongo"
 | 
				
			||||||
	"go.mongodb.org/mongo-driver/mongo/options"
 | 
						"go.mongodb.org/mongo-driver/mongo/options"
 | 
				
			||||||
 | 
						"golang.org/x/crypto/ssh"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Mongo interface {
 | 
					type Mongo interface {
 | 
				
			||||||
@@ -80,13 +84,13 @@ func (d *mongoAppImpl) Save(m *entity.Mongo) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *mongoAppImpl) GetMongoCli(id uint64) *mongo.Client {
 | 
					func (d *mongoAppImpl) GetMongoCli(id uint64) *mongo.Client {
 | 
				
			||||||
	cli, err := GetMongoCli(id, func(u uint64) string {
 | 
						mongoInstance, err := GetMongoInstance(id, func(u uint64) *entity.Mongo {
 | 
				
			||||||
		mongo := d.GetById(id)
 | 
							mongo := d.GetById(u)
 | 
				
			||||||
		biz.NotNil(mongo, "mongo信息不存在")
 | 
							biz.NotNil(mongo, "mongo信息不存在")
 | 
				
			||||||
		return mongo.Uri
 | 
							return mongo
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	biz.ErrIsNilAppendErr(err, "连接mongo失败: %s")
 | 
						biz.ErrIsNilAppendErr(err, "连接mongo失败: %s")
 | 
				
			||||||
	return cli
 | 
						return mongoInstance.Cli
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// -----------------------------------------------------------
 | 
					// -----------------------------------------------------------
 | 
				
			||||||
@@ -95,21 +99,22 @@ func (d *mongoAppImpl) GetMongoCli(id uint64) *mongo.Client {
 | 
				
			|||||||
var mongoCliCache = cache.NewTimedCache(30*time.Minute, 5*time.Second).
 | 
					var mongoCliCache = cache.NewTimedCache(30*time.Minute, 5*time.Second).
 | 
				
			||||||
	WithUpdateAccessTime(true).
 | 
						WithUpdateAccessTime(true).
 | 
				
			||||||
	OnEvicted(func(key interface{}, value interface{}) {
 | 
						OnEvicted(func(key interface{}, value interface{}) {
 | 
				
			||||||
		global.Log.Info("关闭mongo连接: id = ", key)
 | 
							global.Log.Info("删除mongo连接缓存: id = ", key)
 | 
				
			||||||
		value.(*mongo.Client).Disconnect(context.TODO())
 | 
							value.(*MongoInstance).Close()
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func GetMongoCli(mongoId uint64, getMongoUri func(uint64) string) (*mongo.Client, error) {
 | 
					// 获取mongo的连接实例
 | 
				
			||||||
	cli, err := mongoCliCache.ComputeIfAbsent(mongoId, func(key interface{}) (interface{}, error) {
 | 
					func GetMongoInstance(mongoId uint64, getMongoEntity func(uint64) *entity.Mongo) (*MongoInstance, error) {
 | 
				
			||||||
		c, err := connect(getMongoUri(mongoId))
 | 
						mi, err := mongoCliCache.ComputeIfAbsent(mongoId, func(_ interface{}) (interface{}, error) {
 | 
				
			||||||
 | 
							c, err := connect(getMongoEntity(mongoId))
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return c, nil
 | 
							return c, nil
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if cli != nil {
 | 
						if mi != nil {
 | 
				
			||||||
		return cli.(*mongo.Client), err
 | 
							return mi.(*MongoInstance), err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return nil, err
 | 
						return nil, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -118,16 +123,67 @@ func DeleteMongoCache(mongoId uint64) {
 | 
				
			|||||||
	mongoCliCache.Delete(mongoId)
 | 
						mongoCliCache.Delete(mongoId)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type MongoInstance struct {
 | 
				
			||||||
 | 
						Id        uint64
 | 
				
			||||||
 | 
						ProjectId uint64
 | 
				
			||||||
 | 
						Cli       *mongo.Client
 | 
				
			||||||
 | 
						sshTunnel *ssh.Client
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (mi *MongoInstance) Close() {
 | 
				
			||||||
 | 
						if mi.Cli != nil {
 | 
				
			||||||
 | 
							if err := mi.Cli.Disconnect(context.Background()); err != nil {
 | 
				
			||||||
 | 
								global.Log.Errorf("关闭mongo实例[%d]连接失败: %s", mi.Id, err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if mi.sshTunnel != nil {
 | 
				
			||||||
 | 
							if err := mi.sshTunnel.Close(); err != nil {
 | 
				
			||||||
 | 
								global.Log.Errorf("关闭mongo实例[%d]的ssh隧道失败: %s", mi.Id, err.Error())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 连接mongo,并返回client
 | 
					// 连接mongo,并返回client
 | 
				
			||||||
func connect(uri string) (*mongo.Client, error) {
 | 
					func connect(me *entity.Mongo) (*MongoInstance, error) {
 | 
				
			||||||
	ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
 | 
						ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
 | 
				
			||||||
	defer cancel()
 | 
						defer cancel()
 | 
				
			||||||
	client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri).SetMaxPoolSize(2))
 | 
					
 | 
				
			||||||
 | 
						mongoInstance := &MongoInstance{Id: me.Id, ProjectId: me.ProjectId}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mongoOptions := options.Client().ApplyURI(me.Uri).
 | 
				
			||||||
 | 
							SetMaxPoolSize(1)
 | 
				
			||||||
 | 
						// 启用ssh隧道则连接隧道机器
 | 
				
			||||||
 | 
						if me.EnableSshTunnel == 1 {
 | 
				
			||||||
 | 
							machineEntity := MachineApp.GetById(4)
 | 
				
			||||||
 | 
							sshClient, err := machine.GetSshClient(machineEntity)
 | 
				
			||||||
 | 
							biz.ErrIsNilAppendErr(err, "ssh隧道连接失败: %s")
 | 
				
			||||||
 | 
							mongoInstance.sshTunnel = sshClient
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							mongoOptions.SetDialer(&MongoSshDialer{sshTunnel: sshClient})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						client, err := mongo.Connect(ctx, mongoOptions)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err = client.Ping(context.TODO(), nil); err != nil {
 | 
						if err = client.Ping(context.TODO(), nil); err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return client, err
 | 
					
 | 
				
			||||||
 | 
						global.Log.Infof("连接mongo: %s", me.Uri)
 | 
				
			||||||
 | 
						mongoInstance.Cli = client
 | 
				
			||||||
 | 
						return mongoInstance, err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type MongoSshDialer struct {
 | 
				
			||||||
 | 
						sshTunnel *ssh.Client
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (sd *MongoSshDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
 | 
				
			||||||
 | 
						if sshConn, err := sd.sshTunnel.Dial(network, address); err == nil {
 | 
				
			||||||
 | 
							// 将ssh conn包装,否则内部部设置超时会报错,ssh conn不支持设置超时会返回错误: ssh: tcpChan: deadline not supported
 | 
				
			||||||
 | 
							return &utils.WrapSshConn{Conn: sshConn}, nil
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,15 +5,19 @@ import (
 | 
				
			|||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"mayfly-go/internal/devops/domain/entity"
 | 
						"mayfly-go/internal/devops/domain/entity"
 | 
				
			||||||
	"mayfly-go/internal/devops/domain/repository"
 | 
						"mayfly-go/internal/devops/domain/repository"
 | 
				
			||||||
 | 
						"mayfly-go/internal/devops/infrastructure/machine"
 | 
				
			||||||
	"mayfly-go/internal/devops/infrastructure/persistence"
 | 
						"mayfly-go/internal/devops/infrastructure/persistence"
 | 
				
			||||||
	"mayfly-go/pkg/biz"
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
	"mayfly-go/pkg/cache"
 | 
						"mayfly-go/pkg/cache"
 | 
				
			||||||
	"mayfly-go/pkg/global"
 | 
						"mayfly-go/pkg/global"
 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/utils"
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/go-redis/redis/v8"
 | 
						"github.com/go-redis/redis/v8"
 | 
				
			||||||
 | 
						"golang.org/x/crypto/ssh"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Redis interface {
 | 
					type Redis interface {
 | 
				
			||||||
@@ -65,7 +69,10 @@ func (r *redisAppImpl) GetRedisBy(condition *entity.Redis, cols ...string) error
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r *redisAppImpl) Save(re *entity.Redis) {
 | 
					func (r *redisAppImpl) Save(re *entity.Redis) {
 | 
				
			||||||
	TestRedisConnection(re)
 | 
						// ’修改信息且密码不为空‘ or ‘新增’需要测试是否可连接
 | 
				
			||||||
 | 
						if (re.Id != 0 && re.Password != "") || re.Id == 0 {
 | 
				
			||||||
 | 
							TestRedisConnection(re)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 查找是否存在该库
 | 
						// 查找是否存在该库
 | 
				
			||||||
	oldRedis := &entity.Redis{Host: re.Host, Db: re.Db}
 | 
						oldRedis := &entity.Redis{Host: re.Host, Db: re.Db}
 | 
				
			||||||
@@ -106,25 +113,23 @@ func (r *redisAppImpl) GetRedisInstance(id uint64) *RedisInstance {
 | 
				
			|||||||
	biz.NotNil(re, "redis信息不存在")
 | 
						biz.NotNil(re, "redis信息不存在")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	redisMode := re.Mode
 | 
						redisMode := re.Mode
 | 
				
			||||||
	ri := &RedisInstance{Id: id, ProjectId: re.ProjectId, Mode: redisMode}
 | 
						var ri *RedisInstance
 | 
				
			||||||
	if redisMode == "" || redisMode == entity.RedisModeStandalone {
 | 
						if redisMode == "" || redisMode == entity.RedisModeStandalone {
 | 
				
			||||||
		rcli := getRedisCient(re)
 | 
							ri = getRedisCient(re)
 | 
				
			||||||
		// 测试连接
 | 
							// 测试连接
 | 
				
			||||||
		_, e := rcli.Ping(context.Background()).Result()
 | 
							_, e := ri.Cli.Ping(context.Background()).Result()
 | 
				
			||||||
		if e != nil {
 | 
							if e != nil {
 | 
				
			||||||
			rcli.Close()
 | 
								ri.Close()
 | 
				
			||||||
			panic(biz.NewBizErr(fmt.Sprintf("redis连接失败: %s", e.Error())))
 | 
								panic(biz.NewBizErr(fmt.Sprintf("redis连接失败: %s", e.Error())))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		ri.Cli = rcli
 | 
					 | 
				
			||||||
	} else if redisMode == entity.RedisModeCluster {
 | 
						} else if redisMode == entity.RedisModeCluster {
 | 
				
			||||||
		ccli := getRedisClusterClient(re)
 | 
							ri = getRedisClusterClient(re)
 | 
				
			||||||
		// 测试连接
 | 
							// 测试连接
 | 
				
			||||||
		_, e := ccli.Ping(context.Background()).Result()
 | 
							_, e := ri.ClusterCli.Ping(context.Background()).Result()
 | 
				
			||||||
		if e != nil {
 | 
							if e != nil {
 | 
				
			||||||
			ccli.Close()
 | 
								ri.Close()
 | 
				
			||||||
			panic(biz.NewBizErr(fmt.Sprintf("redis集群连接失败: %s", e.Error())))
 | 
								panic(biz.NewBizErr(fmt.Sprintf("redis集群连接失败: %s", e.Error())))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		ri.ClusterCli = ccli
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	global.Log.Infof("连接redis: %s", re.Host)
 | 
						global.Log.Infof("连接redis: %s", re.Host)
 | 
				
			||||||
@@ -134,21 +139,56 @@ func (r *redisAppImpl) GetRedisInstance(id uint64) *RedisInstance {
 | 
				
			|||||||
	return ri
 | 
						return ri
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func getRedisCient(re *entity.Redis) *redis.Client {
 | 
					func getRedisCient(re *entity.Redis) *RedisInstance {
 | 
				
			||||||
	return redis.NewClient(&redis.Options{
 | 
						ri := &RedisInstance{Id: re.Id, ProjectId: re.ProjectId, Mode: re.Mode}
 | 
				
			||||||
		Addr:        re.Host,
 | 
					
 | 
				
			||||||
		Password:    re.Password, // no password set
 | 
						redisOptions := &redis.Options{
 | 
				
			||||||
		DB:          re.Db,       // use default DB
 | 
							Addr:         re.Host,
 | 
				
			||||||
		DialTimeout: 8 * time.Second,
 | 
							Password:     re.Password, // no password set
 | 
				
			||||||
	})
 | 
							DB:           re.Db,       // use default DB
 | 
				
			||||||
 | 
							DialTimeout:  8 * time.Second,
 | 
				
			||||||
 | 
							ReadTimeout:  -1, // Disable timeouts, because SSH does not support deadlines.
 | 
				
			||||||
 | 
							WriteTimeout: -1,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if re.EnableSshTunnel == 1 {
 | 
				
			||||||
 | 
							sshClient, dialerFunc := getRedisDialer(re.SshTunnelMachineId)
 | 
				
			||||||
 | 
							ri.sshTunnel = sshClient
 | 
				
			||||||
 | 
							redisOptions.Dialer = dialerFunc
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ri.Cli = redis.NewClient(redisOptions)
 | 
				
			||||||
 | 
						return ri
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func getRedisClusterClient(re *entity.Redis) *redis.ClusterClient {
 | 
					func getRedisClusterClient(re *entity.Redis) *RedisInstance {
 | 
				
			||||||
	return redis.NewClusterClient(&redis.ClusterOptions{
 | 
						ri := &RedisInstance{Id: re.Id, ProjectId: re.ProjectId, Mode: re.Mode}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						redisClusterOptions := &redis.ClusterOptions{
 | 
				
			||||||
		Addrs:       strings.Split(re.Host, ","),
 | 
							Addrs:       strings.Split(re.Host, ","),
 | 
				
			||||||
		Password:    re.Password,
 | 
							Password:    re.Password,
 | 
				
			||||||
		DialTimeout: 8 * time.Second,
 | 
							DialTimeout: 8 * time.Second,
 | 
				
			||||||
	})
 | 
						}
 | 
				
			||||||
 | 
						if re.EnableSshTunnel == 1 {
 | 
				
			||||||
 | 
							sshClient, dialerFunc := getRedisDialer(re.SshTunnelMachineId)
 | 
				
			||||||
 | 
							ri.sshTunnel = sshClient
 | 
				
			||||||
 | 
							redisClusterOptions.Dialer = dialerFunc
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ri.ClusterCli = redis.NewClusterClient(redisClusterOptions)
 | 
				
			||||||
 | 
						return ri
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getRedisDialer(machineId uint64) (*ssh.Client, func(ctx context.Context, network, addr string) (net.Conn, error)) {
 | 
				
			||||||
 | 
						me := MachineApp.GetById(machineId)
 | 
				
			||||||
 | 
						sshClient, err := machine.GetSshClient(me)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "ssh隧道连接失败: %s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return sshClient, func(_ context.Context, network, addr string) (net.Conn, error) {
 | 
				
			||||||
 | 
							if sshConn, err := sshClient.Dial(network, addr); err == nil {
 | 
				
			||||||
 | 
								// 将ssh conn包装,否则redis内部设置超时会报错,ssh conn不支持设置超时会返回错误: ssh: tcpChan: deadline not supported
 | 
				
			||||||
 | 
								return &utils.WrapSshConn{Conn: sshConn}, nil
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//------------------------------------------------------------------------------
 | 
					//------------------------------------------------------------------------------
 | 
				
			||||||
@@ -171,11 +211,11 @@ func TestRedisConnection(re *entity.Redis) {
 | 
				
			|||||||
	if re.Mode == "" || re.Mode == entity.RedisModeStandalone {
 | 
						if re.Mode == "" || re.Mode == entity.RedisModeStandalone {
 | 
				
			||||||
		rcli := getRedisCient(re)
 | 
							rcli := getRedisCient(re)
 | 
				
			||||||
		defer rcli.Close()
 | 
							defer rcli.Close()
 | 
				
			||||||
		cmd = rcli
 | 
							cmd = rcli.Cli
 | 
				
			||||||
	} else if re.Mode == entity.RedisModeCluster {
 | 
						} else if re.Mode == entity.RedisModeCluster {
 | 
				
			||||||
		ccli := getRedisClusterClient(re)
 | 
							ccli := getRedisClusterClient(re)
 | 
				
			||||||
		defer ccli.Close()
 | 
							defer ccli.Close()
 | 
				
			||||||
		cmd = ccli
 | 
							cmd = ccli.ClusterCli
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 测试连接
 | 
						// 测试连接
 | 
				
			||||||
@@ -190,6 +230,7 @@ type RedisInstance struct {
 | 
				
			|||||||
	Mode       string
 | 
						Mode       string
 | 
				
			||||||
	Cli        *redis.Client
 | 
						Cli        *redis.Client
 | 
				
			||||||
	ClusterCli *redis.ClusterClient
 | 
						ClusterCli *redis.ClusterClient
 | 
				
			||||||
 | 
						sshTunnel  *ssh.Client
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 获取命令执行接口的具体实现
 | 
					// 获取命令执行接口的具体实现
 | 
				
			||||||
@@ -212,10 +253,18 @@ func (r *RedisInstance) Scan(cursor uint64, match string, count int64) ([]string
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (r *RedisInstance) Close() {
 | 
					func (r *RedisInstance) Close() {
 | 
				
			||||||
	if r.Mode == entity.RedisModeStandalone {
 | 
						if r.Mode == entity.RedisModeStandalone {
 | 
				
			||||||
		r.Cli.Close()
 | 
							if err := r.Cli.Close(); err != nil {
 | 
				
			||||||
		return
 | 
								global.Log.Errorf("关闭redis单机实例[%d]连接失败: %s", r.Id, err.Error())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if r.Mode == entity.RedisModeCluster {
 | 
						if r.Mode == entity.RedisModeCluster {
 | 
				
			||||||
		r.ClusterCli.Close()
 | 
							if err := r.ClusterCli.Close(); err != nil {
 | 
				
			||||||
 | 
								global.Log.Errorf("关闭redis集群实例[%d]连接失败: %s", r.Id, err.Error())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if r.sshTunnel != nil {
 | 
				
			||||||
 | 
							if err := r.sshTunnel.Close(); err != nil {
 | 
				
			||||||
 | 
								global.Log.Errorf("关闭redis实例[%d]的ssh隧道失败: %s", r.Id, err.Error())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
package entity
 | 
					package entity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -20,4 +21,25 @@ type Db struct {
 | 
				
			|||||||
	Project   string
 | 
						Project   string
 | 
				
			||||||
	EnvId     uint64
 | 
						EnvId     uint64
 | 
				
			||||||
	Env       string
 | 
						Env       string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						EnableSshTunnel    int8   `orm:"column(enable_ssh_tunnel)" json:"enableSshTunnel"`        // 是否启用ssh隧道
 | 
				
			||||||
 | 
						SshTunnelMachineId uint64 `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取数据库连接网络, 若没有使用ssh隧道,则直接返回。否则返回拼接的网络需要注册至指定dial
 | 
				
			||||||
 | 
					func (d Db) GetNetwork() string {
 | 
				
			||||||
 | 
						network := d.Network
 | 
				
			||||||
 | 
						if d.EnableSshTunnel == -1 {
 | 
				
			||||||
 | 
							if network == "" {
 | 
				
			||||||
 | 
								return "tcp"
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								return network
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return fmt.Sprintf("%s+ssh:%d", d.Type, d.SshTunnelMachineId)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						DbTypeMysql    = "mysql"
 | 
				
			||||||
 | 
						DbTypePostgres = "postgres"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,8 +9,9 @@ type Machine struct {
 | 
				
			|||||||
	ProjectId   uint64 `json:"projectId"`
 | 
						ProjectId   uint64 `json:"projectId"`
 | 
				
			||||||
	ProjectName string `json:"projectName"`
 | 
						ProjectName string `json:"projectName"`
 | 
				
			||||||
	Name        string `json:"name"`
 | 
						Name        string `json:"name"`
 | 
				
			||||||
	Ip          string `json:"ip"`       // IP地址
 | 
						Ip          string `json:"ip"`         // IP地址
 | 
				
			||||||
	Username    string `json:"username"` // 用户名
 | 
						Username    string `json:"username"`   // 用户名
 | 
				
			||||||
 | 
						AuthMethod  int8   `json:"authMethod"` // 授权认证方式
 | 
				
			||||||
	Password    string `json:"-"`
 | 
						Password    string `json:"-"`
 | 
				
			||||||
	Port        int    `json:"port"`   // 端口号
 | 
						Port        int    `json:"port"`   // 端口号
 | 
				
			||||||
	Status      int8   `json:"status"` // 状态 1:启用;2:停用
 | 
						Status      int8   `json:"status"` // 状态 1:启用;2:停用
 | 
				
			||||||
@@ -18,6 +19,8 @@ type Machine struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	MachineStatusEnable  int8 = 1  // 启用状态
 | 
						MachineStatusEnable        int8 = 1  // 启用状态
 | 
				
			||||||
	MachineStatusDisable int8 = -1 // 禁用状态
 | 
						MachineStatusDisable       int8 = -1 // 禁用状态
 | 
				
			||||||
 | 
						MachineAuthMethodPassword  int8 = 1  // 密码登录
 | 
				
			||||||
 | 
						MachineAuthMethodPublicKey int8 = 2  // 公钥免密登录
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,10 +5,12 @@ import "mayfly-go/pkg/model"
 | 
				
			|||||||
type Mongo struct {
 | 
					type Mongo struct {
 | 
				
			||||||
	model.Model
 | 
						model.Model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Name      string `orm:"column(name)" json:"name"`
 | 
						Name               string `orm:"column(name)" json:"name"`
 | 
				
			||||||
	Uri       string `orm:"column(uri)" json:"uri"`
 | 
						Uri                string `orm:"column(uri)" json:"uri"`
 | 
				
			||||||
	ProjectId uint64 `json:"projectId"`
 | 
						EnableSshTunnel    int8   `orm:"column(enable_ssh_tunnel)" json:"enableSshTunnel"`        // 是否启用ssh隧道
 | 
				
			||||||
	Project   string `json:"project"`
 | 
						SshTunnelMachineId uint64 `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
	EnvId     uint64 `json:"envId"`
 | 
						ProjectId          uint64 `json:"projectId"`
 | 
				
			||||||
	Env       string `json:"env"`
 | 
						Project            string `json:"project"`
 | 
				
			||||||
 | 
						EnvId              uint64 `json:"envId"`
 | 
				
			||||||
 | 
						Env                string `json:"env"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,15 +7,17 @@ import (
 | 
				
			|||||||
type Redis struct {
 | 
					type Redis struct {
 | 
				
			||||||
	model.Model
 | 
						model.Model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Host      string `orm:"column(host)" json:"host"`
 | 
						Host               string `orm:"column(host)" json:"host"`
 | 
				
			||||||
	Mode      string `json:"mode"`
 | 
						Mode               string `json:"mode"`
 | 
				
			||||||
	Password  string `orm:"column(password)" json:"-"`
 | 
						Password           string `orm:"column(password)" json:"-"`
 | 
				
			||||||
	Db        int    `orm:"column(database)" json:"db"`
 | 
						Db                 int    `orm:"column(database)" json:"db"`
 | 
				
			||||||
	Remark    string
 | 
						EnableSshTunnel    int8   `orm:"column(enable_ssh_tunnel)" json:"enableSshTunnel"`        // 是否启用ssh隧道
 | 
				
			||||||
	ProjectId uint64
 | 
						SshTunnelMachineId uint64 `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
				
			||||||
	Project   string
 | 
						Remark             string
 | 
				
			||||||
	EnvId     uint64
 | 
						ProjectId          uint64
 | 
				
			||||||
	Env       string
 | 
						Project            string
 | 
				
			||||||
 | 
						EnvId              uint64
 | 
				
			||||||
 | 
						Env                string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,58 +24,6 @@ type Cli struct {
 | 
				
			|||||||
	sftpClient *sftp.Client
 | 
						sftpClient *sftp.Client
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 机器客户端连接缓存,45分钟内没有访问则会被关闭
 | 
					 | 
				
			||||||
var cliCache = cache.NewTimedCache(45*time.Minute, 5*time.Second).
 | 
					 | 
				
			||||||
	WithUpdateAccessTime(true).
 | 
					 | 
				
			||||||
	OnEvicted(func(key interface{}, value interface{}) {
 | 
					 | 
				
			||||||
		value.(*Cli).Close()
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 是否存在指定id的客户端连接
 | 
					 | 
				
			||||||
func HasCli(machineId uint64) bool {
 | 
					 | 
				
			||||||
	if _, ok := cliCache.Get(machineId); ok {
 | 
					 | 
				
			||||||
		return true
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return false
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 删除指定机器客户端,并关闭客户端连接
 | 
					 | 
				
			||||||
func DeleteCli(id uint64) {
 | 
					 | 
				
			||||||
	cliCache.Delete(id)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 从缓存中获取客户端信息,不存在则回调获取机器信息函数,并新建
 | 
					 | 
				
			||||||
func GetCli(machineId uint64, getMachine func(uint64) *entity.Machine) (*Cli, error) {
 | 
					 | 
				
			||||||
	cli, err := cliCache.ComputeIfAbsent(machineId, func(key interface{}) (interface{}, error) {
 | 
					 | 
				
			||||||
		c, err := newClient(getMachine(machineId))
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return nil, err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return c, nil
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if cli != nil {
 | 
					 | 
				
			||||||
		return cli.(*Cli), err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil, err
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//根据机器信息创建客户端对象
 | 
					 | 
				
			||||||
func newClient(machine *entity.Machine) (*Cli, error) {
 | 
					 | 
				
			||||||
	if machine == nil {
 | 
					 | 
				
			||||||
		return nil, errors.New("机器不存在")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	global.Log.Infof("[%s]机器连接:%s:%d", machine.Name, machine.Ip, machine.Port)
 | 
					 | 
				
			||||||
	cli := new(Cli)
 | 
					 | 
				
			||||||
	cli.machine = machine
 | 
					 | 
				
			||||||
	err := cli.connect()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return cli, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//连接
 | 
					//连接
 | 
				
			||||||
func (c *Cli) connect() error {
 | 
					func (c *Cli) connect() error {
 | 
				
			||||||
	// 如果已经有client则直接返回
 | 
						// 如果已经有client则直接返回
 | 
				
			||||||
@@ -83,16 +31,7 @@ func (c *Cli) connect() error {
 | 
				
			|||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	m := c.machine
 | 
						m := c.machine
 | 
				
			||||||
	config := ssh.ClientConfig{
 | 
						sshClient, err := GetSshClient(m)
 | 
				
			||||||
		User: m.Username,
 | 
					 | 
				
			||||||
		Auth: []ssh.AuthMethod{ssh.Password(m.Password)},
 | 
					 | 
				
			||||||
		HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
 | 
					 | 
				
			||||||
			return nil
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		Timeout: 5 * time.Second,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	addr := fmt.Sprintf("%s:%d", m.Ip, m.Port)
 | 
					 | 
				
			||||||
	sshClient, err := ssh.Dial("tcp", addr, &config)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -100,25 +39,6 @@ func (c *Cli) connect() error {
 | 
				
			|||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 测试连接
 | 
					 | 
				
			||||||
func TestConn(m *entity.Machine) error {
 | 
					 | 
				
			||||||
	config := ssh.ClientConfig{
 | 
					 | 
				
			||||||
		User: m.Username,
 | 
					 | 
				
			||||||
		Auth: []ssh.AuthMethod{ssh.Password(m.Password)},
 | 
					 | 
				
			||||||
		HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
 | 
					 | 
				
			||||||
			return nil
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		Timeout: 5 * time.Second,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	addr := fmt.Sprintf("%s:%d", m.Ip, m.Port)
 | 
					 | 
				
			||||||
	sshClient, err := ssh.Dial("tcp", addr, &config)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	defer sshClient.Close()
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 关闭client和并从缓存中移除
 | 
					// 关闭client和并从缓存中移除
 | 
				
			||||||
func (c *Cli) Close() {
 | 
					func (c *Cli) Close() {
 | 
				
			||||||
	m := c.machine
 | 
						m := c.machine
 | 
				
			||||||
@@ -184,3 +104,91 @@ func (c *Cli) Run(shell string) (*string, error) {
 | 
				
			|||||||
func (c *Cli) GetMachine() *entity.Machine {
 | 
					func (c *Cli) GetMachine() *entity.Machine {
 | 
				
			||||||
	return c.machine
 | 
						return c.machine
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 机器客户端连接缓存,45分钟内没有访问则会被关闭
 | 
				
			||||||
 | 
					var cliCache = cache.NewTimedCache(45*time.Minute, 5*time.Second).
 | 
				
			||||||
 | 
						WithUpdateAccessTime(true).
 | 
				
			||||||
 | 
						OnEvicted(func(_, value interface{}) {
 | 
				
			||||||
 | 
							value.(*Cli).Close()
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 是否存在指定id的客户端连接
 | 
				
			||||||
 | 
					func HasCli(machineId uint64) bool {
 | 
				
			||||||
 | 
						if _, ok := cliCache.Get(machineId); ok {
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 删除指定机器客户端,并关闭客户端连接
 | 
				
			||||||
 | 
					func DeleteCli(id uint64) {
 | 
				
			||||||
 | 
						cliCache.Delete(id)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 从缓存中获取客户端信息,不存在则回调获取机器信息函数,并新建
 | 
				
			||||||
 | 
					func GetCli(machineId uint64, getMachine func(uint64) *entity.Machine) (*Cli, error) {
 | 
				
			||||||
 | 
						cli, err := cliCache.ComputeIfAbsent(machineId, func(_ interface{}) (interface{}, error) {
 | 
				
			||||||
 | 
							c, err := newClient(getMachine(machineId))
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return c, nil
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if cli != nil {
 | 
				
			||||||
 | 
							return cli.(*Cli), err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil, err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 测试连接
 | 
				
			||||||
 | 
					func TestConn(m *entity.Machine) error {
 | 
				
			||||||
 | 
						sshClient, err := GetSshClient(m)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer sshClient.Close()
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetSshClient(m *entity.Machine) (*ssh.Client, error) {
 | 
				
			||||||
 | 
						config := ssh.ClientConfig{
 | 
				
			||||||
 | 
							User: m.Username,
 | 
				
			||||||
 | 
							HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
 | 
				
			||||||
 | 
								return nil
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							Timeout: 5 * time.Second,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if m.AuthMethod == entity.MachineAuthMethodPassword {
 | 
				
			||||||
 | 
							config.Auth = []ssh.AuthMethod{ssh.Password(m.Password)}
 | 
				
			||||||
 | 
						} else if m.AuthMethod == entity.MachineAuthMethodPublicKey {
 | 
				
			||||||
 | 
							if signer, err := ssh.ParsePrivateKey([]byte(m.Password)); err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								config.Auth = []ssh.AuthMethod{ssh.PublicKeys(signer)}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						addr := fmt.Sprintf("%s:%d", m.Ip, m.Port)
 | 
				
			||||||
 | 
						sshClient, err := ssh.Dial("tcp", addr, &config)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return sshClient, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//根据机器信息创建客户端对象
 | 
				
			||||||
 | 
					func newClient(machine *entity.Machine) (*Cli, error) {
 | 
				
			||||||
 | 
						if machine == nil {
 | 
				
			||||||
 | 
							return nil, errors.New("机器不存在")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						global.Log.Infof("[%s]机器连接:%s:%d", machine.Name, machine.Ip, machine.Port)
 | 
				
			||||||
 | 
						cli := new(Cli)
 | 
				
			||||||
 | 
						cli.machine = machine
 | 
				
			||||||
 | 
						err := cli.connect()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return cli, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,14 +24,14 @@ func InitDbRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
			rc.Handle(d.Dbs)
 | 
								rc.Handle(d.Dbs)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		saveDb := ctx.NewLogInfo("保存数据库信息")
 | 
							saveDb := ctx.NewLogInfo("保存数据库信息").WithSave(true)
 | 
				
			||||||
		db.POST("", func(c *gin.Context) {
 | 
							db.POST("", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
				WithLog(saveDb).
 | 
									WithLog(saveDb).
 | 
				
			||||||
				Handle(d.Save)
 | 
									Handle(d.Save)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		deleteDb := ctx.NewLogInfo("删除数据库信息")
 | 
							deleteDb := ctx.NewLogInfo("删除数据库信息").WithSave(true)
 | 
				
			||||||
		db.DELETE(":dbId", func(c *gin.Context) {
 | 
							db.DELETE(":dbId", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
				WithLog(deleteDb).
 | 
									WithLog(deleteDb).
 | 
				
			||||||
@@ -50,20 +50,23 @@ func InitDbRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
			ctx.NewReqCtxWithGin(c).Handle(d.GetCreateTableDdl)
 | 
								ctx.NewReqCtxWithGin(c).Handle(d.GetCreateTableDdl)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// db.GET(":dbId/exec-sql", controllers.SelectData)
 | 
							execSqlLog := ctx.NewLogInfo("执行Sql语句")
 | 
				
			||||||
		db.POST(":dbId/exec-sql", func(g *gin.Context) {
 | 
							db.POST(":dbId/exec-sql", func(g *gin.Context) {
 | 
				
			||||||
			rc := ctx.NewReqCtxWithGin(g).WithLog(ctx.NewLogInfo("执行Sql语句"))
 | 
								rc := ctx.NewReqCtxWithGin(g).WithLog(execSqlLog)
 | 
				
			||||||
			rc.Handle(d.ExecSql)
 | 
								rc.Handle(d.ExecSql)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							execSqlFileLog := ctx.NewLogInfo("执行Sql文件").WithSave(true)
 | 
				
			||||||
		db.POST(":dbId/exec-sql-file", func(g *gin.Context) {
 | 
							db.POST(":dbId/exec-sql-file", func(g *gin.Context) {
 | 
				
			||||||
			rc := ctx.NewReqCtxWithGin(g).WithLog(ctx.NewLogInfo("执行Sql文件"))
 | 
								ctx.NewReqCtxWithGin(g).
 | 
				
			||||||
			rc.Handle(d.ExecSqlFile)
 | 
									WithLog(execSqlFileLog).
 | 
				
			||||||
 | 
									Handle(d.ExecSqlFile)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							dumpLog := ctx.NewLogInfo("导出sql文件").WithSave(true)
 | 
				
			||||||
		db.GET(":dbId/dump", func(g *gin.Context) {
 | 
							db.GET(":dbId/dump", func(g *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(g).
 | 
								ctx.NewReqCtxWithGin(g).
 | 
				
			||||||
				WithLog(ctx.NewLogInfo("Sql文件dump")).
 | 
									WithLog(dumpLog).
 | 
				
			||||||
				Handle(d.DumpSql)
 | 
									Handle(d.DumpSql)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,7 +29,7 @@ func InitMachineRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 终止进程
 | 
							// 终止进程
 | 
				
			||||||
		killProcessL := ctx.NewLogInfo("终止进程")
 | 
							killProcessL := ctx.NewLogInfo("终止进程").WithSave(true)
 | 
				
			||||||
		killProcessP := ctx.NewPermission("machine:killprocess")
 | 
							killProcessP := ctx.NewPermission("machine:killprocess")
 | 
				
			||||||
		machines.DELETE(":machineId/process", func(c *gin.Context) {
 | 
							machines.DELETE(":machineId/process", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
@@ -38,28 +38,28 @@ func InitMachineRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
				Handle(m.KillProcess)
 | 
									Handle(m.KillProcess)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		saveMachine := ctx.NewLogInfo("保存机器信息")
 | 
							saveMachine := ctx.NewLogInfo("保存机器信息").WithSave(true)
 | 
				
			||||||
		machines.POST("", func(c *gin.Context) {
 | 
							machines.POST("", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
				WithLog(saveMachine).
 | 
									WithLog(saveMachine).
 | 
				
			||||||
				Handle(m.SaveMachine)
 | 
									Handle(m.SaveMachine)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		changeStatus := ctx.NewLogInfo("调整机器状态")
 | 
							changeStatus := ctx.NewLogInfo("调整机器状态").WithSave(true)
 | 
				
			||||||
		machines.PUT(":machineId/:status", func(c *gin.Context) {
 | 
							machines.PUT(":machineId/:status", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
				WithLog(changeStatus).
 | 
									WithLog(changeStatus).
 | 
				
			||||||
				Handle(m.ChangeStatus)
 | 
									Handle(m.ChangeStatus)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		delMachine := ctx.NewLogInfo("删除机器")
 | 
							delMachine := ctx.NewLogInfo("删除机器").WithSave(true)
 | 
				
			||||||
		machines.DELETE(":machineId", func(c *gin.Context) {
 | 
							machines.DELETE(":machineId", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
				WithLog(delMachine).
 | 
									WithLog(delMachine).
 | 
				
			||||||
				Handle(m.DeleteMachine)
 | 
									Handle(m.DeleteMachine)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		closeCli := ctx.NewLogInfo("关闭机器客户端")
 | 
							closeCli := ctx.NewLogInfo("关闭机器客户端").WithSave(true)
 | 
				
			||||||
		machines.DELETE(":machineId/close-cli", func(c *gin.Context) {
 | 
							machines.DELETE(":machineId/close-cli", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(closeCli).Handle(m.CloseCli)
 | 
								ctx.NewReqCtxWithGin(c).WithLog(closeCli).Handle(m.CloseCli)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,7 +24,7 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 新增修改机器文件
 | 
							// 新增修改机器文件
 | 
				
			||||||
		addFileConf := ctx.NewLogInfo("新增机器文件配置")
 | 
							addFileConf := ctx.NewLogInfo("新增机器文件配置").WithSave(true)
 | 
				
			||||||
		afcP := ctx.NewPermission("machine:file:add")
 | 
							afcP := ctx.NewPermission("machine:file:add")
 | 
				
			||||||
		machineFile.POST(":machineId/files", func(c *gin.Context) {
 | 
							machineFile.POST(":machineId/files", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(addFileConf).
 | 
								ctx.NewReqCtxWithGin(c).WithLog(addFileConf).
 | 
				
			||||||
@@ -33,7 +33,7 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 删除机器文件
 | 
							// 删除机器文件
 | 
				
			||||||
		delFileConf := ctx.NewLogInfo("删除机器文件配置")
 | 
							delFileConf := ctx.NewLogInfo("删除机器文件配置").WithSave(true)
 | 
				
			||||||
		dfcP := ctx.NewPermission("machine:file:del")
 | 
							dfcP := ctx.NewPermission("machine:file:del")
 | 
				
			||||||
		machineFile.DELETE(":machineId/files/:fileId", func(c *gin.Context) {
 | 
							machineFile.DELETE(":machineId/files/:fileId", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(delFileConf).
 | 
								ctx.NewReqCtxWithGin(c).WithLog(delFileConf).
 | 
				
			||||||
@@ -41,7 +41,7 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
				Handle(mf.DeleteFile)
 | 
									Handle(mf.DeleteFile)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		getContent := ctx.NewLogInfo("读取机器文件内容")
 | 
							getContent := ctx.NewLogInfo("读取机器文件内容").WithSave(true)
 | 
				
			||||||
		machineFile.GET(":machineId/files/:fileId/read", func(c *gin.Context) {
 | 
							machineFile.GET(":machineId/files/:fileId/read", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(getContent).
 | 
								ctx.NewReqCtxWithGin(c).WithLog(getContent).
 | 
				
			||||||
				Handle(mf.ReadFileContent)
 | 
									Handle(mf.ReadFileContent)
 | 
				
			||||||
@@ -53,7 +53,7 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
				Handle(mf.GetDirEntry)
 | 
									Handle(mf.GetDirEntry)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		writeFile := ctx.NewLogInfo("写入or下载文件内容")
 | 
							writeFile := ctx.NewLogInfo("写入or下载文件内容").WithSave(true)
 | 
				
			||||||
		wfP := ctx.NewPermission("machine:file:write")
 | 
							wfP := ctx.NewPermission("machine:file:write")
 | 
				
			||||||
		machineFile.POST(":machineId/files/:fileId/write", func(c *gin.Context) {
 | 
							machineFile.POST(":machineId/files/:fileId/write", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(writeFile).
 | 
								ctx.NewReqCtxWithGin(c).WithLog(writeFile).
 | 
				
			||||||
@@ -61,14 +61,14 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
				Handle(mf.WriteFileContent)
 | 
									Handle(mf.WriteFileContent)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		createFile := ctx.NewLogInfo("创建机器文件or目录")
 | 
							createFile := ctx.NewLogInfo("创建机器文件or目录").WithSave(true)
 | 
				
			||||||
		machineFile.POST(":machineId/files/:fileId/create-file", func(c *gin.Context) {
 | 
							machineFile.POST(":machineId/files/:fileId/create-file", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(createFile).
 | 
								ctx.NewReqCtxWithGin(c).WithLog(createFile).
 | 
				
			||||||
				WithRequiredPermission(wfP).
 | 
									WithRequiredPermission(wfP).
 | 
				
			||||||
				Handle(mf.CreateFile)
 | 
									Handle(mf.CreateFile)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		uploadFile := ctx.NewLogInfo("文件上传")
 | 
							uploadFile := ctx.NewLogInfo("文件上传").WithSave(true)
 | 
				
			||||||
		ufP := ctx.NewPermission("machine:file:upload")
 | 
							ufP := ctx.NewPermission("machine:file:upload")
 | 
				
			||||||
		machineFile.POST(":machineId/files/:fileId/upload", func(c *gin.Context) {
 | 
							machineFile.POST(":machineId/files/:fileId/upload", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(uploadFile).
 | 
								ctx.NewReqCtxWithGin(c).WithLog(uploadFile).
 | 
				
			||||||
@@ -76,7 +76,7 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
				Handle(mf.UploadFile)
 | 
									Handle(mf.UploadFile)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		removeFile := ctx.NewLogInfo("删除文件or文件夹")
 | 
							removeFile := ctx.NewLogInfo("删除文件or文件夹").WithSave(true)
 | 
				
			||||||
		rfP := ctx.NewPermission("machine:file:rm")
 | 
							rfP := ctx.NewPermission("machine:file:rm")
 | 
				
			||||||
		machineFile.DELETE(":machineId/files/:fileId/remove", func(c *gin.Context) {
 | 
							machineFile.DELETE(":machineId/files/:fileId/remove", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(removeFile).
 | 
								ctx.NewReqCtxWithGin(c).WithLog(removeFile).
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ func InitMachineScriptRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
			ctx.NewReqCtxWithGin(c).Handle(ms.MachineScripts)
 | 
								ctx.NewReqCtxWithGin(c).Handle(ms.MachineScripts)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		saveMachienScriptLog := ctx.NewLogInfo("保存脚本")
 | 
							saveMachienScriptLog := ctx.NewLogInfo("保存脚本").WithSave(true)
 | 
				
			||||||
		smsP := ctx.NewPermission("machine:script:save")
 | 
							smsP := ctx.NewPermission("machine:script:save")
 | 
				
			||||||
		// 保存脚本
 | 
							// 保存脚本
 | 
				
			||||||
		machines.POST(":machineId/scripts", func(c *gin.Context) {
 | 
							machines.POST(":machineId/scripts", func(c *gin.Context) {
 | 
				
			||||||
@@ -31,7 +31,7 @@ func InitMachineScriptRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
				Handle(ms.SaveMachineScript)
 | 
									Handle(ms.SaveMachineScript)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		deleteLog := ctx.NewLogInfo("删除脚本")
 | 
							deleteLog := ctx.NewLogInfo("删除脚本").WithSave(true)
 | 
				
			||||||
		dP := ctx.NewPermission("machine:script:del")
 | 
							dP := ctx.NewPermission("machine:script:del")
 | 
				
			||||||
		// 保存脚本
 | 
							// 保存脚本
 | 
				
			||||||
		machines.DELETE(":machineId/scripts/:scriptId", func(c *gin.Context) {
 | 
							machines.DELETE(":machineId/scripts/:scriptId", func(c *gin.Context) {
 | 
				
			||||||
@@ -40,7 +40,7 @@ func InitMachineScriptRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
				Handle(ms.DeleteMachineScript)
 | 
									Handle(ms.DeleteMachineScript)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		runLog := ctx.NewLogInfo("执行机器脚本")
 | 
							runLog := ctx.NewLogInfo("执行机器脚本").WithSave(true)
 | 
				
			||||||
		rP := ctx.NewPermission("machine:script:run")
 | 
							rP := ctx.NewPermission("machine:script:run")
 | 
				
			||||||
		// 运行脚本
 | 
							// 运行脚本
 | 
				
			||||||
		machines.GET(":machineId/scripts/:scriptId/run", func(c *gin.Context) {
 | 
							machines.GET(":machineId/scripts/:scriptId/run", func(c *gin.Context) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,7 @@ func InitProjectRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
			ctx.NewReqCtxWithGin(c).Handle(m.GetProjects)
 | 
								ctx.NewReqCtxWithGin(c).Handle(m.GetProjects)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		saveProjectLog := ctx.NewLogInfo("保存项目信息")
 | 
							saveProjectLog := ctx.NewLogInfo("保存项目信息").WithSave(true)
 | 
				
			||||||
		savePP := ctx.NewPermission("project:save")
 | 
							savePP := ctx.NewPermission("project:save")
 | 
				
			||||||
		// 保存项目下的环境信息
 | 
							// 保存项目下的环境信息
 | 
				
			||||||
		project.POST("", func(c *gin.Context) {
 | 
							project.POST("", func(c *gin.Context) {
 | 
				
			||||||
@@ -34,7 +34,7 @@ func InitProjectRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
				Handle(m.SaveProject)
 | 
									Handle(m.SaveProject)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		delProjectLog := ctx.NewLogInfo("删除项目信息")
 | 
							delProjectLog := ctx.NewLogInfo("删除项目信息").WithSave(true)
 | 
				
			||||||
		delPP := ctx.NewPermission("project:del")
 | 
							delPP := ctx.NewPermission("project:del")
 | 
				
			||||||
		// 删除项目
 | 
							// 删除项目
 | 
				
			||||||
		project.DELETE("", func(c *gin.Context) {
 | 
							project.DELETE("", func(c *gin.Context) {
 | 
				
			||||||
@@ -48,7 +48,7 @@ func InitProjectRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
			ctx.NewReqCtxWithGin(c).Handle(m.GetProjectEnvs)
 | 
								ctx.NewReqCtxWithGin(c).Handle(m.GetProjectEnvs)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		saveProjectEnvLog := ctx.NewLogInfo("新增项目环境信息")
 | 
							saveProjectEnvLog := ctx.NewLogInfo("新增项目环境信息").WithSave(true)
 | 
				
			||||||
		savePeP := ctx.NewPermission("project:env:add")
 | 
							savePeP := ctx.NewPermission("project:env:add")
 | 
				
			||||||
		// 保存项目下的环境信息
 | 
							// 保存项目下的环境信息
 | 
				
			||||||
		project.POST("/:projectId/envs", func(c *gin.Context) {
 | 
							project.POST("/:projectId/envs", func(c *gin.Context) {
 | 
				
			||||||
@@ -63,7 +63,7 @@ func InitProjectRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 保存项目成员
 | 
							// 保存项目成员
 | 
				
			||||||
		saveProjectMemLog := ctx.NewLogInfo("新增项目成员")
 | 
							saveProjectMemLog := ctx.NewLogInfo("新增项目成员").WithSave(true)
 | 
				
			||||||
		savePmP := ctx.NewPermission("project:member:add")
 | 
							savePmP := ctx.NewPermission("project:member:add")
 | 
				
			||||||
		project.POST("/:projectId/members", func(c *gin.Context) {
 | 
							project.POST("/:projectId/members", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(saveProjectMemLog).
 | 
								ctx.NewReqCtxWithGin(c).WithLog(saveProjectMemLog).
 | 
				
			||||||
@@ -72,7 +72,7 @@ func InitProjectRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 删除项目成员
 | 
							// 删除项目成员
 | 
				
			||||||
		delProjectMemLog := ctx.NewLogInfo("删除项目成员")
 | 
							delProjectMemLog := ctx.NewLogInfo("删除项目成员").WithSave(true)
 | 
				
			||||||
		savePmdP := ctx.NewPermission("project:member:del")
 | 
							savePmdP := ctx.NewPermission("project:member:del")
 | 
				
			||||||
		project.DELETE("/:projectId/members/:accountId", func(c *gin.Context) {
 | 
							project.DELETE("/:projectId/members/:accountId", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(delProjectMemLog).
 | 
								ctx.NewReqCtxWithGin(c).WithLog(delProjectMemLog).
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,12 +21,12 @@ func InitRedisRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
			ctx.NewReqCtxWithGin(c).Handle(rs.RedisList)
 | 
								ctx.NewReqCtxWithGin(c).Handle(rs.RedisList)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		save := ctx.NewLogInfo("保存redis信息")
 | 
							save := ctx.NewLogInfo("保存redis信息").WithSave(true)
 | 
				
			||||||
		redis.POST("", func(c *gin.Context) {
 | 
							redis.POST("", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(save).Handle(rs.Save)
 | 
								ctx.NewReqCtxWithGin(c).WithLog(save).Handle(rs.Save)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		delRedis := ctx.NewLogInfo("删除redis信息")
 | 
							delRedis := ctx.NewLogInfo("删除redis信息").WithSave(true)
 | 
				
			||||||
		redis.DELETE(":id", func(c *gin.Context) {
 | 
							redis.DELETE(":id", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(delRedis).Handle(rs.DeleteRedis)
 | 
								ctx.NewReqCtxWithGin(c).WithLog(delRedis).Handle(rs.DeleteRedis)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
@@ -45,8 +45,7 @@ func InitRedisRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 删除key
 | 
							// 删除key
 | 
				
			||||||
		deleteKeyL := ctx.NewLogInfo("redis删除key")
 | 
							deleteKeyL := ctx.NewLogInfo("redis删除key").WithSave(true)
 | 
				
			||||||
		// deleteKey := ctx.NewPermission("project:save")
 | 
					 | 
				
			||||||
		redis.DELETE(":id/key", func(c *gin.Context) {
 | 
							redis.DELETE(":id/key", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(deleteKeyL).Handle(rs.DeleteKey)
 | 
								ctx.NewReqCtxWithGin(c).WithLog(deleteKeyL).Handle(rs.DeleteKey)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,7 +10,9 @@ import (
 | 
				
			|||||||
	"mayfly-go/pkg/captcha"
 | 
						"mayfly-go/pkg/captcha"
 | 
				
			||||||
	"mayfly-go/pkg/ctx"
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
	"mayfly-go/pkg/ginx"
 | 
						"mayfly-go/pkg/ginx"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
	"mayfly-go/pkg/utils"
 | 
						"mayfly-go/pkg/utils"
 | 
				
			||||||
 | 
						"regexp"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
@@ -29,15 +31,20 @@ type Account struct {
 | 
				
			|||||||
func (a *Account) Login(rc *ctx.ReqCtx) {
 | 
					func (a *Account) Login(rc *ctx.ReqCtx) {
 | 
				
			||||||
	loginForm := &form.LoginForm{}
 | 
						loginForm := &form.LoginForm{}
 | 
				
			||||||
	ginx.BindJsonAndValid(rc.GinCtx, loginForm)
 | 
						ginx.BindJsonAndValid(rc.GinCtx, loginForm)
 | 
				
			||||||
	rc.ReqParam = loginForm.Username
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 校验验证码
 | 
						// 校验验证码
 | 
				
			||||||
	biz.IsTrue(captcha.Verify(loginForm.Cid, loginForm.Captcha), "验证码错误")
 | 
						biz.IsTrue(captcha.Verify(loginForm.Cid, loginForm.Captcha), "验证码错误")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	account := &entity.Account{Username: loginForm.Username, Password: utils.Md5(loginForm.Password)}
 | 
						originPwd, err := utils.DefaultRsaDecrypt(loginForm.Password, true)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "解密密码错误: %s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						account := &entity.Account{Username: loginForm.Username, Password: utils.Md5(originPwd)}
 | 
				
			||||||
	biz.ErrIsNil(a.AccountApp.GetAccount(account, "Id", "Username", "Status", "LastLoginTime", "LastLoginIp"), "用户名或密码错误")
 | 
						biz.ErrIsNil(a.AccountApp.GetAccount(account, "Id", "Username", "Status", "LastLoginTime", "LastLoginIp"), "用户名或密码错误")
 | 
				
			||||||
	biz.IsTrue(account.IsEnable(), "该账号不可用")
 | 
						biz.IsTrue(account.IsEnable(), "该账号不可用")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 校验密码强度是否符合
 | 
				
			||||||
 | 
						biz.IsTrueBy(CheckPasswordLever(originPwd), biz.NewBizErrCode(401, "您的密码安全等级较低,请修改后重新登录"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var resources vo.AccountResourceVOList
 | 
						var resources vo.AccountResourceVOList
 | 
				
			||||||
	// 获取账号菜单资源
 | 
						// 获取账号菜单资源
 | 
				
			||||||
	a.ResourceApp.GetAccountResources(account.Id, &resources)
 | 
						a.ResourceApp.GetAccountResources(account.Id, &resources)
 | 
				
			||||||
@@ -54,8 +61,13 @@ func (a *Account) Login(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	// 保存该账号的权限codes
 | 
						// 保存该账号的权限codes
 | 
				
			||||||
	ctx.SavePermissionCodes(account.Id, permissions)
 | 
						ctx.SavePermissionCodes(account.Id, permissions)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						clientIp := rc.GinCtx.ClientIP()
 | 
				
			||||||
	// 保存登录消息
 | 
						// 保存登录消息
 | 
				
			||||||
	go a.saveLogin(account, rc.GinCtx.ClientIP())
 | 
						go a.saveLogin(account, clientIp)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rc.ReqParam = fmt.Sprintln("登录ip: ", clientIp)
 | 
				
			||||||
 | 
						// 赋值loginAccount 主要用于记录操作日志,因为操作日志保存请求上下文没有该信息不保存日志
 | 
				
			||||||
 | 
						rc.LoginAccount = &model.LoginAccount{Id: account.Id, Username: account.Username}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rc.ResData = map[string]interface{}{
 | 
						rc.ResData = map[string]interface{}{
 | 
				
			||||||
		"token":         ctx.CreateToken(account.Id, account.Username),
 | 
							"token":         ctx.CreateToken(account.Id, account.Username),
 | 
				
			||||||
@@ -67,6 +79,48 @@ func (a *Account) Login(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (a *Account) ChangePassword(rc *ctx.ReqCtx) {
 | 
				
			||||||
 | 
						form := new(form.AccountChangePasswordForm)
 | 
				
			||||||
 | 
						ginx.BindJsonAndValid(rc.GinCtx, form)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						originOldPwd, err := utils.DefaultRsaDecrypt(form.OldPassword, true)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "解密旧密码错误: %s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						account := &entity.Account{Username: form.Username, Password: utils.Md5(originOldPwd)}
 | 
				
			||||||
 | 
						biz.ErrIsNil(a.AccountApp.GetAccount(account, "Id", "Username", "Status"), "旧密码不正确")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						originNewPwd, err := utils.DefaultRsaDecrypt(form.NewPassword, true)
 | 
				
			||||||
 | 
						biz.ErrIsNilAppendErr(err, "解密新密码错误: %s")
 | 
				
			||||||
 | 
						biz.IsTrue(CheckPasswordLever(originNewPwd), "密码强度必须8位以上且包含字⺟⼤⼩写+数字+特殊符号")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						updateAccount := new(entity.Account)
 | 
				
			||||||
 | 
						updateAccount.Id = account.Id
 | 
				
			||||||
 | 
						updateAccount.Password = utils.Md5(originNewPwd)
 | 
				
			||||||
 | 
						a.AccountApp.Update(updateAccount)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 赋值loginAccount 主要用于记录操作日志,因为操作日志保存请求上下文没有该信息不保存日志
 | 
				
			||||||
 | 
						rc.LoginAccount = &model.LoginAccount{Id: account.Id, Username: account.Username}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func CheckPasswordLever(ps string) bool {
 | 
				
			||||||
 | 
						if len(ps) < 8 {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						num := `[0-9]{1}`
 | 
				
			||||||
 | 
						a_z := `[a-zA-Z]{1}`
 | 
				
			||||||
 | 
						symbol := `[!@#~$%^&*()+|_.,]{1}`
 | 
				
			||||||
 | 
						if b, err := regexp.MatchString(num, ps); !b || err != nil {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if b, err := regexp.MatchString(a_z, ps); !b || err != nil {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if b, err := regexp.MatchString(symbol, ps); !b || err != nil {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 保存更新账号登录信息
 | 
					// 保存更新账号登录信息
 | 
				
			||||||
func (a *Account) saveLogin(account *entity.Account, ip string) {
 | 
					func (a *Account) saveLogin(account *entity.Account, ip string) {
 | 
				
			||||||
	// 更新账号最后登录时间
 | 
						// 更新账号最后登录时间
 | 
				
			||||||
@@ -100,7 +154,7 @@ func (a *Account) saveLogin(account *entity.Account, ip string) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 获取个人账号信息
 | 
					// 获取个人账号信息
 | 
				
			||||||
func (a Account) AccountInfo(rc *ctx.ReqCtx) {
 | 
					func (a *Account) AccountInfo(rc *ctx.ReqCtx) {
 | 
				
			||||||
	ap := new(vo.AccountPersonVO)
 | 
						ap := new(vo.AccountPersonVO)
 | 
				
			||||||
	// 角色信息
 | 
						// 角色信息
 | 
				
			||||||
	roles := new([]vo.AccountRoleVO)
 | 
						roles := new([]vo.AccountRoleVO)
 | 
				
			||||||
@@ -111,7 +165,7 @@ func (a Account) AccountInfo(rc *ctx.ReqCtx) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 更新个人账号信息
 | 
					// 更新个人账号信息
 | 
				
			||||||
func (a Account) UpdateAccount(rc *ctx.ReqCtx) {
 | 
					func (a *Account) UpdateAccount(rc *ctx.ReqCtx) {
 | 
				
			||||||
	updateForm := &form.AccountUpdateForm{}
 | 
						updateForm := &form.AccountUpdateForm{}
 | 
				
			||||||
	ginx.BindJsonAndValid(rc.GinCtx, updateForm)
 | 
						ginx.BindJsonAndValid(rc.GinCtx, updateForm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -121,13 +175,14 @@ func (a Account) UpdateAccount(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	updateAccount.Id = rc.LoginAccount.Id
 | 
						updateAccount.Id = rc.LoginAccount.Id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if updateAccount.Password != "" {
 | 
						if updateAccount.Password != "" {
 | 
				
			||||||
 | 
							biz.IsTrue(CheckPasswordLever(updateAccount.Password), "密码强度必须8位以上且包含字⺟⼤⼩写+数字+特殊符号")
 | 
				
			||||||
		updateAccount.Password = utils.Md5(updateAccount.Password)
 | 
							updateAccount.Password = utils.Md5(updateAccount.Password)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	a.AccountApp.Update(updateAccount)
 | 
						a.AccountApp.Update(updateAccount)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 获取账号接收的消息列表
 | 
					// 获取账号接收的消息列表
 | 
				
			||||||
func (a Account) GetMsgs(rc *ctx.ReqCtx) {
 | 
					func (a *Account) GetMsgs(rc *ctx.ReqCtx) {
 | 
				
			||||||
	condition := &entity.Msg{
 | 
						condition := &entity.Msg{
 | 
				
			||||||
		RecipientId: int64(rc.LoginAccount.Id),
 | 
							RecipientId: int64(rc.LoginAccount.Id),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,3 +7,9 @@ type AccountCreateForm struct {
 | 
				
			|||||||
type AccountUpdateForm struct {
 | 
					type AccountUpdateForm struct {
 | 
				
			||||||
	Password *string `json:"password" binding:"min=6,max=16"`
 | 
						Password *string `json:"password" binding:"min=6,max=16"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type AccountChangePasswordForm struct {
 | 
				
			||||||
 | 
						Username    string `json:"username"`
 | 
				
			||||||
 | 
						OldPassword string `json:"oldPassword"`
 | 
				
			||||||
 | 
						NewPassword string `json:"newPassword"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,6 +29,7 @@ func (r *Role) SaveRole(rc *ctx.ReqCtx) {
 | 
				
			|||||||
	g := rc.GinCtx
 | 
						g := rc.GinCtx
 | 
				
			||||||
	form := &form.RoleForm{}
 | 
						form := &form.RoleForm{}
 | 
				
			||||||
	ginx.BindJsonAndValid(g, form)
 | 
						ginx.BindJsonAndValid(g, form)
 | 
				
			||||||
 | 
						rc.ReqParam = form
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	role := new(entity.Role)
 | 
						role := new(entity.Role)
 | 
				
			||||||
	utils.Copy(role, form)
 | 
						utils.Copy(role, form)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										21
									
								
								server/internal/sys/api/syslog.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								server/internal/sys/api/syslog.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					package api
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"mayfly-go/internal/sys/application"
 | 
				
			||||||
 | 
						"mayfly-go/internal/sys/domain/entity"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/ginx"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Syslog struct {
 | 
				
			||||||
 | 
						SyslogApp application.Syslog
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (r *Syslog) Syslogs(rc *ctx.ReqCtx) {
 | 
				
			||||||
 | 
						g := rc.GinCtx
 | 
				
			||||||
 | 
						condition := &entity.Syslog{
 | 
				
			||||||
 | 
							Type:      int8(ginx.QueryInt(g, "type", 0)),
 | 
				
			||||||
 | 
							CreatorId: uint64(ginx.QueryInt(g, "creatorId", 0)),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						rc.ResData = r.SyslogApp.GetPageList(condition, ginx.GetPageParam(g), new([]entity.Syslog), "create_time DESC")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										79
									
								
								server/internal/sys/application/syslog_app.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								server/internal/sys/application/syslog_app.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,79 @@
 | 
				
			|||||||
 | 
					package application
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"mayfly-go/internal/sys/domain/entity"
 | 
				
			||||||
 | 
						"mayfly-go/internal/sys/domain/repository"
 | 
				
			||||||
 | 
						"mayfly-go/internal/sys/infrastructure/persistence"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/biz"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/utils"
 | 
				
			||||||
 | 
						"reflect"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Syslog interface {
 | 
				
			||||||
 | 
						GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 从请求上下文的参数保存系统日志
 | 
				
			||||||
 | 
						SaveFromReq(req *ctx.ReqCtx)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type syslogAppImpl struct {
 | 
				
			||||||
 | 
						syslogRepo repository.Syslog
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 实现类单例
 | 
				
			||||||
 | 
					var SyslogApp Syslog = &syslogAppImpl{
 | 
				
			||||||
 | 
						syslogRepo: persistence.SyslogDao,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m *syslogAppImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
 | 
						return m.syslogRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m *syslogAppImpl) SaveFromReq(req *ctx.ReqCtx) {
 | 
				
			||||||
 | 
						lg := req.LoginAccount
 | 
				
			||||||
 | 
						if lg == nil {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						syslog := new(entity.Syslog)
 | 
				
			||||||
 | 
						syslog.CreateTime = time.Now()
 | 
				
			||||||
 | 
						syslog.Creator = lg.Username
 | 
				
			||||||
 | 
						syslog.CreatorId = lg.Id
 | 
				
			||||||
 | 
						syslog.Description = req.LogInfo.Description
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if req.LogInfo.LogResp {
 | 
				
			||||||
 | 
							respB, _ := json.Marshal(req.ResData)
 | 
				
			||||||
 | 
							syslog.Resp = string(respB)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						reqParam := req.ReqParam
 | 
				
			||||||
 | 
						if !utils.IsBlank(reflect.ValueOf(reqParam)) {
 | 
				
			||||||
 | 
							// 如果是字符串类型,则不使用json序列化
 | 
				
			||||||
 | 
							if reqStr, ok := reqParam.(string); ok {
 | 
				
			||||||
 | 
								syslog.ReqParam = reqStr
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								reqB, _ := json.Marshal(reqParam)
 | 
				
			||||||
 | 
								syslog.ReqParam = string(reqB)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := req.Err; err != nil {
 | 
				
			||||||
 | 
							syslog.Type = entity.SyslogTypeError
 | 
				
			||||||
 | 
							var errMsg string
 | 
				
			||||||
 | 
							switch t := err.(type) {
 | 
				
			||||||
 | 
							case *biz.BizError:
 | 
				
			||||||
 | 
								errMsg = fmt.Sprintf("errCode: %d, errMsg: %s", t.Code(), t.Error())
 | 
				
			||||||
 | 
							case error:
 | 
				
			||||||
 | 
								errMsg = t.Error()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							syslog.Resp = errMsg
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							syslog.Type = entity.SyslogTypeNorman
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m.syslogRepo.Insert(syslog)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										25
									
								
								server/internal/sys/domain/entity/syslog.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								server/internal/sys/domain/entity/syslog.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					package entity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 系统操作日志
 | 
				
			||||||
 | 
					type Syslog struct {
 | 
				
			||||||
 | 
						Id         uint64    `json:"id"`
 | 
				
			||||||
 | 
						CreateTime time.Time `json:"createTime"`
 | 
				
			||||||
 | 
						CreatorId  uint64    `json:"creatorId"`
 | 
				
			||||||
 | 
						Creator    string    `json:"creator"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Type        int8   `json:"type"`
 | 
				
			||||||
 | 
						Description string `json:"description"`
 | 
				
			||||||
 | 
						ReqParam    string `json:"reqParam"` // 请求参数
 | 
				
			||||||
 | 
						Resp        string `json:"resp"`     // 响应结构
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (a *Syslog) TableName() string {
 | 
				
			||||||
 | 
						return "t_sys_log"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						SyslogTypeNorman int8 = 1 // 正常状态
 | 
				
			||||||
 | 
						SyslogTypeError  int8 = 2 // 错误状态
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
							
								
								
									
										12
									
								
								server/internal/sys/domain/repository/syslog.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								server/internal/sys/domain/repository/syslog.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					package repository
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"mayfly-go/internal/sys/domain/entity"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Syslog interface {
 | 
				
			||||||
 | 
						GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Insert(log *entity.Syslog)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					package persistence
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"mayfly-go/internal/sys/domain/entity"
 | 
				
			||||||
 | 
						"mayfly-go/internal/sys/domain/repository"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type syslogRepo struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var SyslogDao repository.Syslog = &syslogRepo{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m *syslogRepo) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
 | 
				
			||||||
 | 
						return model.GetPage(pageParam, condition, toEntity, orderBy...)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m *syslogRepo) Insert(syslog *entity.Syslog) {
 | 
				
			||||||
 | 
						model.Insert(syslog)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -18,9 +18,20 @@ func InitAccountRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		// 用户登录
 | 
							// 用户登录
 | 
				
			||||||
 | 
							loginLog := ctx.NewLogInfo("用户登录").WithSave(true)
 | 
				
			||||||
		account.POST("login", func(g *gin.Context) {
 | 
							account.POST("login", func(g *gin.Context) {
 | 
				
			||||||
			rc := ctx.NewReqCtxWithGin(g).WithNeedToken(false).WithLog(ctx.NewLogInfo("用户登录"))
 | 
								ctx.NewReqCtxWithGin(g).
 | 
				
			||||||
			rc.Handle(a.Login)
 | 
									WithNeedToken(false).
 | 
				
			||||||
 | 
									WithLog(loginLog).
 | 
				
			||||||
 | 
									Handle(a.Login)
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							changePwdLog := ctx.NewLogInfo("用户修改密码").WithSave(true)
 | 
				
			||||||
 | 
							account.POST("change-pwd", func(g *gin.Context) {
 | 
				
			||||||
 | 
								ctx.NewReqCtxWithGin(g).
 | 
				
			||||||
 | 
									WithNeedToken(false).
 | 
				
			||||||
 | 
									WithLog(changePwdLog).
 | 
				
			||||||
 | 
									Handle(a.ChangePassword)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 获取个人账号信息
 | 
							// 获取个人账号信息
 | 
				
			||||||
@@ -44,7 +55,7 @@ func InitAccountRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
			ctx.NewReqCtxWithGin(c).Handle(a.Accounts)
 | 
								ctx.NewReqCtxWithGin(c).Handle(a.Accounts)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		createAccount := ctx.NewLogInfo("创建账号")
 | 
							createAccount := ctx.NewLogInfo("创建账号").WithSave(true)
 | 
				
			||||||
		addAccountPermission := ctx.NewPermission("account:add")
 | 
							addAccountPermission := ctx.NewPermission("account:add")
 | 
				
			||||||
		account.POST("", func(c *gin.Context) {
 | 
							account.POST("", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
@@ -53,14 +64,14 @@ func InitAccountRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
				Handle(a.CreateAccount)
 | 
									Handle(a.CreateAccount)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		changeStatus := ctx.NewLogInfo("修改账号状态")
 | 
							changeStatus := ctx.NewLogInfo("修改账号状态").WithSave(true)
 | 
				
			||||||
		account.PUT("change-status/:id/:status", func(c *gin.Context) {
 | 
							account.PUT("change-status/:id/:status", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
				WithLog(changeStatus).
 | 
									WithLog(changeStatus).
 | 
				
			||||||
				Handle(a.ChangeStatus)
 | 
									Handle(a.ChangeStatus)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		delAccount := ctx.NewLogInfo("删除账号")
 | 
							delAccount := ctx.NewLogInfo("删除账号").WithSave(true)
 | 
				
			||||||
		delAccountPermission := ctx.NewPermission("account:del")
 | 
							delAccountPermission := ctx.NewPermission("account:del")
 | 
				
			||||||
		account.DELETE(":id", func(c *gin.Context) {
 | 
							account.DELETE(":id", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
@@ -75,7 +86,7 @@ func InitAccountRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 保存用户角色
 | 
							// 保存用户角色
 | 
				
			||||||
		saveAccountRole := ctx.NewLogInfo("保存用户角色")
 | 
							saveAccountRole := ctx.NewLogInfo("保存用户角色").WithSave(true)
 | 
				
			||||||
		sarPermission := ctx.NewPermission("account:saveRoles")
 | 
							sarPermission := ctx.NewPermission("account:saveRoles")
 | 
				
			||||||
		account.POST("/roles", func(c *gin.Context) {
 | 
							account.POST("/roles", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(saveAccountRole).
 | 
								ctx.NewReqCtxWithGin(c).WithLog(saveAccountRole).
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,10 +12,6 @@ func InitResourceRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
	r := &api.Resource{ResourceApp: application.ResourceApp}
 | 
						r := &api.Resource{ResourceApp: application.ResourceApp}
 | 
				
			||||||
	db := router.Group("sys/resources")
 | 
						db := router.Group("sys/resources")
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		// db.GET("/account", func(c *gin.Context) {
 | 
					 | 
				
			||||||
		// 	ctx.NewReqCtxWithGin(c).Handle(r.ResourceTree)
 | 
					 | 
				
			||||||
		// })
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		db.GET("", func(c *gin.Context) {
 | 
							db.GET("", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).Handle(r.GetAllResourceTree)
 | 
								ctx.NewReqCtxWithGin(c).Handle(r.GetAllResourceTree)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
@@ -24,7 +20,7 @@ func InitResourceRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
			ctx.NewReqCtxWithGin(c).Handle(r.GetById)
 | 
								ctx.NewReqCtxWithGin(c).Handle(r.GetById)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		saveResource := ctx.NewLogInfo("保存资源")
 | 
							saveResource := ctx.NewLogInfo("保存资源").WithSave(true)
 | 
				
			||||||
		srPermission := ctx.NewPermission("resource:add")
 | 
							srPermission := ctx.NewPermission("resource:add")
 | 
				
			||||||
		db.POST("", func(c *gin.Context) {
 | 
							db.POST("", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
@@ -33,7 +29,7 @@ func InitResourceRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
				Handle(r.SaveResource)
 | 
									Handle(r.SaveResource)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		changeStatus := ctx.NewLogInfo("修改资源状态")
 | 
							changeStatus := ctx.NewLogInfo("修改资源状态").WithSave(true)
 | 
				
			||||||
		csPermission := ctx.NewPermission("resource:changeStatus")
 | 
							csPermission := ctx.NewPermission("resource:changeStatus")
 | 
				
			||||||
		db.PUT(":id/:status", func(c *gin.Context) {
 | 
							db.PUT(":id/:status", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
@@ -42,7 +38,7 @@ func InitResourceRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
				Handle(r.ChangeStatus)
 | 
									Handle(r.ChangeStatus)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		delResource := ctx.NewLogInfo("删除资源")
 | 
							delResource := ctx.NewLogInfo("删除资源").WithSave(true)
 | 
				
			||||||
		dePermission := ctx.NewPermission("resource:delete")
 | 
							dePermission := ctx.NewPermission("resource:delete")
 | 
				
			||||||
		db.DELETE(":id", func(c *gin.Context) {
 | 
							db.DELETE(":id", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).
 | 
								ctx.NewReqCtxWithGin(c).
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@ func InitRoleRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
			ctx.NewReqCtxWithGin(c).Handle(r.Roles)
 | 
								ctx.NewReqCtxWithGin(c).Handle(r.Roles)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		saveRole := ctx.NewLogInfo("保存角色")
 | 
							saveRole := ctx.NewLogInfo("保存角色").WithSave(true)
 | 
				
			||||||
		sPermission := ctx.NewPermission("role:add")
 | 
							sPermission := ctx.NewPermission("role:add")
 | 
				
			||||||
		db.POST("", func(c *gin.Context) {
 | 
							db.POST("", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(saveRole).
 | 
								ctx.NewReqCtxWithGin(c).WithLog(saveRole).
 | 
				
			||||||
@@ -28,7 +28,7 @@ func InitRoleRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
				Handle(r.SaveRole)
 | 
									Handle(r.SaveRole)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		delRole := ctx.NewLogInfo("删除角色")
 | 
							delRole := ctx.NewLogInfo("删除角色").WithSave(true)
 | 
				
			||||||
		drPermission := ctx.NewPermission("role:del")
 | 
							drPermission := ctx.NewPermission("role:del")
 | 
				
			||||||
		db.DELETE(":id", func(c *gin.Context) {
 | 
							db.DELETE(":id", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(delRole).
 | 
								ctx.NewReqCtxWithGin(c).WithLog(delRole).
 | 
				
			||||||
@@ -44,7 +44,7 @@ func InitRoleRouter(router *gin.RouterGroup) {
 | 
				
			|||||||
			ctx.NewReqCtxWithGin(c).Handle(r.RoleResource)
 | 
								ctx.NewReqCtxWithGin(c).Handle(r.RoleResource)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		saveResource := ctx.NewLogInfo("保存角色资源")
 | 
							saveResource := ctx.NewLogInfo("保存角色资源").WithSave(true)
 | 
				
			||||||
		srPermission := ctx.NewPermission("role:saveResources")
 | 
							srPermission := ctx.NewPermission("role:saveResources")
 | 
				
			||||||
		db.POST(":id/resources", func(c *gin.Context) {
 | 
							db.POST(":id/resources", func(c *gin.Context) {
 | 
				
			||||||
			ctx.NewReqCtxWithGin(c).WithLog(saveResource).
 | 
								ctx.NewReqCtxWithGin(c).WithLog(saveResource).
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										21
									
								
								server/internal/sys/router/syslog.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								server/internal/sys/router/syslog.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					package router
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"mayfly-go/internal/sys/api"
 | 
				
			||||||
 | 
						"mayfly-go/internal/sys/application"
 | 
				
			||||||
 | 
						"mayfly-go/pkg/ctx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func InitSyslogRouter(router *gin.RouterGroup) {
 | 
				
			||||||
 | 
						s := &api.Syslog{
 | 
				
			||||||
 | 
							SyslogApp: application.SyslogApp,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						sys := router.Group("syslogs")
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							sys.GET("", func(c *gin.Context) {
 | 
				
			||||||
 | 
								ctx.NewReqCtxWithGin(c).Handle(s.Syslogs)
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -29,7 +29,9 @@ CREATE TABLE `t_db` (
 | 
				
			|||||||
  `type` varchar(20) COLLATE utf8mb4_bin NOT NULL COMMENT '数据库实例类型(mysql...)',
 | 
					  `type` varchar(20) COLLATE utf8mb4_bin NOT NULL COMMENT '数据库实例类型(mysql...)',
 | 
				
			||||||
  `database` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '数据库,空格分割多个数据库',
 | 
					  `database` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '数据库,空格分割多个数据库',
 | 
				
			||||||
  `params` varchar(125) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '其他连接参数',
 | 
					  `params` varchar(125) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '其他连接参数',
 | 
				
			||||||
  `network` varchar(8) COLLATE utf8mb4_bin DEFAULT NULL,
 | 
					  `network` varchar(20) COLLATE utf8mb4_bin DEFAULT NULL,
 | 
				
			||||||
 | 
					  `enableSshTunnel` tinyint(2) DEFAULT NULL COMMENT '是否启用ssh隧道',
 | 
				
			||||||
 | 
					  `sshTunnelMachineId` bigint(20) DEFAULT NULL COMMENT 'ssh隧道的机器id',
 | 
				
			||||||
  `project_id` bigint(20) DEFAULT NULL,
 | 
					  `project_id` bigint(20) DEFAULT NULL,
 | 
				
			||||||
  `project` varchar(64) COLLATE utf8mb4_bin DEFAULT NULL,
 | 
					  `project` varchar(64) COLLATE utf8mb4_bin DEFAULT NULL,
 | 
				
			||||||
  `env_id` bigint(20) DEFAULT NULL COMMENT '环境id',
 | 
					  `env_id` bigint(20) DEFAULT NULL COMMENT '环境id',
 | 
				
			||||||
@@ -107,7 +109,8 @@ CREATE TABLE `t_machine` (
 | 
				
			|||||||
  `ip` varchar(36) COLLATE utf8mb4_bin NOT NULL,
 | 
					  `ip` varchar(36) COLLATE utf8mb4_bin NOT NULL,
 | 
				
			||||||
  `port` int(12) NOT NULL,
 | 
					  `port` int(12) NOT NULL,
 | 
				
			||||||
  `username` varchar(12) COLLATE utf8mb4_bin NOT NULL,
 | 
					  `username` varchar(12) COLLATE utf8mb4_bin NOT NULL,
 | 
				
			||||||
  `password` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL,
 | 
					  `auth_method` tinyint(2) NULL DEFAULT NULL COMMENT '1.密码登录2.publickey登录',
 | 
				
			||||||
 | 
					  `password` varchar(3200) COLLATE utf8mb4_bin DEFAULT NULL,
 | 
				
			||||||
  `status` tinyint(2) NOT NULL COMMENT '状态: 1:启用; -1:禁用',
 | 
					  `status` tinyint(2) NOT NULL COMMENT '状态: 1:启用; -1:禁用',
 | 
				
			||||||
  `remark` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
 | 
					  `remark` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
 | 
				
			||||||
  `need_monitor` tinyint(2) DEFAULT NULL,
 | 
					  `need_monitor` tinyint(2) DEFAULT NULL,
 | 
				
			||||||
@@ -258,6 +261,8 @@ CREATE TABLE `t_redis` (
 | 
				
			|||||||
  `password` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL,
 | 
					  `password` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL,
 | 
				
			||||||
  `db` int(32) DEFAULT NULL,
 | 
					  `db` int(32) DEFAULT NULL,
 | 
				
			||||||
  `mode` varchar(32) DEFAULT NULL,
 | 
					  `mode` varchar(32) DEFAULT NULL,
 | 
				
			||||||
 | 
					  `enableSshTunnel` tinyint(2) DEFAULT NULL COMMENT '是否启用ssh隧道',
 | 
				
			||||||
 | 
					  `sshTunnelMachineId` bigint(20) DEFAULT NULL COMMENT 'ssh隧道的机器id',
 | 
				
			||||||
  `remark` varchar(125) DEFAULT NULL,
 | 
					  `remark` varchar(125) DEFAULT NULL,
 | 
				
			||||||
  `project_id` bigint(20) DEFAULT NULL,
 | 
					  `project_id` bigint(20) DEFAULT NULL,
 | 
				
			||||||
  `project` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL,
 | 
					  `project` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL,
 | 
				
			||||||
@@ -363,12 +368,11 @@ CREATE TABLE `t_sys_resource` (
 | 
				
			|||||||
-- Records of t_sys_resource
 | 
					-- Records of t_sys_resource
 | 
				
			||||||
-- ----------------------------
 | 
					-- ----------------------------
 | 
				
			||||||
BEGIN;
 | 
					BEGIN;
 | 
				
			||||||
INSERT INTO `t_sys_resource` VALUES (1, 0, 1, 1, '首页', '/home', 1, '{\"component\":\"Home\",\"icon\":\"Home\",\"isAffix\":true,\"isKeepAlive\":true,\"routeName\":\"Home\"}', 1, 'admin', 1, 'admin', '2021-05-25 16:44:41', '2021-05-27 09:12:56');
 | 
					INSERT INTO `t_sys_resource` VALUES (1, 0, 1, 1, '首页', '/home', 1, '{\"component\":\"Home\",\"icon\":\"HomeFilled\",\"isAffix\":true,\"isKeepAlive\":true,\"routeName\":\"Home\"}', 1, 'admin', 1, 'admin', '2021-05-25 16:44:41', '2021-05-27 09:12:56');
 | 
				
			||||||
INSERT INTO `t_sys_resource` VALUES (2, 0, 1, 1, '运维', '/ops', 3, '{\"icon\":\"Monitor\",\"isKeepAlive\":true,\"redirect\":\"machine/list\",\"routeName\":\"Ops\"}', 1, 'admin', 1, 'admin', '2021-05-25 16:48:16', '2021-06-08 14:20:24');
 | 
					INSERT INTO `t_sys_resource` VALUES (2, 0, 1, 1, '运维', '/ops', 3, '{\"icon\":\"Monitor\",\"isKeepAlive\":true,\"redirect\":\"machine/list\",\"routeName\":\"Ops\"}', 1, 'admin', 1, 'admin', '2021-05-25 16:48:16', '2021-06-08 14:20:24');
 | 
				
			||||||
INSERT INTO `t_sys_resource` VALUES (3, 2, 1, 1, '机器列表', 'machines', 2, '{\"component\":\"MachineList\",\"icon\":\"Menu\",\"isKeepAlive\":true,\"routeName\":\"MachineList\"}', 2, 'admin', 1, 'admin', '2021-05-25 16:50:04', '2021-06-30 16:20:08');
 | 
					INSERT INTO `t_sys_resource` VALUES (3, 2, 1, 1, '机器列表', 'machines', 2, '{\"component\":\"MachineList\",\"icon\":\"Menu\",\"isKeepAlive\":true,\"routeName\":\"MachineList\"}', 2, 'admin', 1, 'admin', '2021-05-25 16:50:04', '2021-06-30 16:20:08');
 | 
				
			||||||
INSERT INTO `t_sys_resource` VALUES (4, 0, 1, 1, '系统管理', '/sys', 5, '{\"icon\":\"Setting\",\"isKeepAlive\":true,\"redirect\":\"/sys/resources\",\"routeName\":\"sys\"}', 1, 'admin', 1, 'admin', '2021-05-26 15:20:20', '2021-07-29 18:03:06');
 | 
					INSERT INTO `t_sys_resource` VALUES (4, 0, 1, 1, '系统管理', '/sys', 5, '{\"icon\":\"Setting\",\"isKeepAlive\":true,\"redirect\":\"/sys/resources\",\"routeName\":\"sys\"}', 1, 'admin', 1, 'admin', '2021-05-26 15:20:20', '2021-07-29 18:03:06');
 | 
				
			||||||
INSERT INTO `t_sys_resource` VALUES (5, 4, 1, 1, '资源管理', 'resources', 3, '{\"component\":\"ResourceList\",\"icon\":\"Menu\",\"isKeepAlive\":true,\"routeName\":\"ResourceList\"}', 1, 'admin', 1, 'admin', '2021-05-26 15:23:07', '2021-06-08 11:27:55');
 | 
					INSERT INTO `t_sys_resource` VALUES (5, 4, 1, 1, '资源管理', 'resources', 3, '{\"component\":\"ResourceList\",\"icon\":\"Menu\",\"isKeepAlive\":true,\"routeName\":\"ResourceList\"}', 1, 'admin', 1, 'admin', '2021-05-26 15:23:07', '2021-06-08 11:27:55');
 | 
				
			||||||
INSERT INTO `t_sys_resource` VALUES (9, 0, 1, 1, 'iframes', '/iframes', 6, '{\"component\":\"RouterParent\",\"icon\":\"Menu\",\"isIframe\":true,\"isKeepAlive\":true,\"link\":\"https://www.baidu.com\",\"routeName\":\"Iframe\"}', 1, 'admin', 1, 'admin', '2021-05-27 09:58:37', '2021-07-29 18:03:13');
 | 
					 | 
				
			||||||
INSERT INTO `t_sys_resource` VALUES (11, 4, 1, 1, '角色管理', 'roles', 2, '{\"component\":\"RoleList\",\"icon\":\"Menu\",\"isKeepAlive\":true,\"routeName\":\"RoleList\"}', 1, 'admin', 1, 'admin', '2021-05-27 11:15:35', '2021-06-03 09:59:41');
 | 
					INSERT INTO `t_sys_resource` VALUES (11, 4, 1, 1, '角色管理', 'roles', 2, '{\"component\":\"RoleList\",\"icon\":\"Menu\",\"isKeepAlive\":true,\"routeName\":\"RoleList\"}', 1, 'admin', 1, 'admin', '2021-05-27 11:15:35', '2021-06-03 09:59:41');
 | 
				
			||||||
INSERT INTO `t_sys_resource` VALUES (12, 3, 2, 1, '机器终端按钮', 'machine:terminal', 4, '', 1, 'admin', 1, 'admin', '2021-05-28 14:06:02', '2021-05-31 17:47:59');
 | 
					INSERT INTO `t_sys_resource` VALUES (12, 3, 2, 1, '机器终端按钮', 'machine:terminal', 4, '', 1, 'admin', 1, 'admin', '2021-05-28 14:06:02', '2021-05-31 17:47:59');
 | 
				
			||||||
INSERT INTO `t_sys_resource` VALUES (14, 4, 1, 1, '账号管理', 'accounts', 1, '{\"component\":\"AccountList\",\"icon\":\"Menu\",\"isKeepAlive\":true,\"routeName\":\"AccountList\"}', 1, 'admin', 1, 'admin', '2021-05-28 14:56:25', '2021-06-03 09:39:22');
 | 
					INSERT INTO `t_sys_resource` VALUES (14, 4, 1, 1, '账号管理', 'accounts', 1, '{\"component\":\"AccountList\",\"icon\":\"Menu\",\"isKeepAlive\":true,\"routeName\":\"AccountList\"}', 1, 'admin', 1, 'admin', '2021-05-28 14:56:25', '2021-06-03 09:39:22');
 | 
				
			||||||
@@ -383,7 +387,7 @@ INSERT INTO `t_sys_resource` VALUES (22, 11, 2, 1, '角色删除按钮', 'role:d
 | 
				
			|||||||
INSERT INTO `t_sys_resource` VALUES (23, 11, 2, 1, '角色新增按钮', 'role:add', 3, NULL, 1, 'admin', 1, 'admin', '2021-05-31 18:02:44', '2021-05-31 19:33:39');
 | 
					INSERT INTO `t_sys_resource` VALUES (23, 11, 2, 1, '角色新增按钮', 'role:add', 3, NULL, 1, 'admin', 1, 'admin', '2021-05-31 18:02:44', '2021-05-31 19:33:39');
 | 
				
			||||||
INSERT INTO `t_sys_resource` VALUES (24, 11, 2, 1, '角色编辑按钮', 'role:update', 4, NULL, 1, 'admin', 1, 'admin', '2021-05-31 18:02:57', '2021-05-31 19:33:40');
 | 
					INSERT INTO `t_sys_resource` VALUES (24, 11, 2, 1, '角色编辑按钮', 'role:update', 4, NULL, 1, 'admin', 1, 'admin', '2021-05-31 18:02:57', '2021-05-31 19:33:40');
 | 
				
			||||||
INSERT INTO `t_sys_resource` VALUES (25, 5, 2, 1, '资源新增按钮', 'resource:add', 1, NULL, 1, 'admin', 1, 'admin', '2021-05-31 18:03:33', '2021-05-31 19:31:47');
 | 
					INSERT INTO `t_sys_resource` VALUES (25, 5, 2, 1, '资源新增按钮', 'resource:add', 1, NULL, 1, 'admin', 1, 'admin', '2021-05-31 18:03:33', '2021-05-31 19:31:47');
 | 
				
			||||||
INSERT INTO `t_sys_resource` VALUES (26, 5, 2, 1, '资源删除按钮', 'resource:del', 2, NULL, 1, 'admin', 1, 'admin', '2021-05-31 18:03:47', '2021-05-31 19:29:40');
 | 
					INSERT INTO `t_sys_resource` VALUES (26, 5, 2, 1, '资源删除按钮', 'resource:delete', 2, NULL, 1, 'admin', 1, 'admin', '2021-05-31 18:03:47', '2021-05-31 19:29:40');
 | 
				
			||||||
INSERT INTO `t_sys_resource` VALUES (27, 5, 2, 1, '资源编辑按钮', 'resource:update', 3, NULL, 1, 'admin', 1, 'admin', '2021-05-31 18:04:03', '2021-05-31 19:29:40');
 | 
					INSERT INTO `t_sys_resource` VALUES (27, 5, 2, 1, '资源编辑按钮', 'resource:update', 3, NULL, 1, 'admin', 1, 'admin', '2021-05-31 18:04:03', '2021-05-31 19:29:40');
 | 
				
			||||||
INSERT INTO `t_sys_resource` VALUES (28, 5, 2, 1, '资源禁用启用按钮', 'resource:changeStatus', 4, NULL, 1, 'admin', 1, 'admin', '2021-05-31 18:04:33', '2021-05-31 18:04:33');
 | 
					INSERT INTO `t_sys_resource` VALUES (28, 5, 2, 1, '资源禁用启用按钮', 'resource:changeStatus', 4, NULL, 1, 'admin', 1, 'admin', '2021-05-31 18:04:33', '2021-05-31 18:04:33');
 | 
				
			||||||
INSERT INTO `t_sys_resource` VALUES (29, 14, 2, 1, '账号添加按钮', 'account:add', 3, NULL, 1, 'admin', 1, 'admin', '2021-05-31 19:23:42', '2021-05-31 19:23:42');
 | 
					INSERT INTO `t_sys_resource` VALUES (29, 14, 2, 1, '账号添加按钮', 'account:add', 3, NULL, 1, 'admin', 1, 'admin', '2021-05-31 19:23:42', '2021-05-31 19:23:42');
 | 
				
			||||||
@@ -429,6 +433,8 @@ INSERT INTO `t_sys_resource`(`id`, `pid`, `type`, `status`, `name`, `code`, `wei
 | 
				
			|||||||
INSERT INTO `t_sys_resource`(`id`, `pid`, `type`, `status`, `name`, `code`, `weight`, `meta`, `creator_id`, `creator`, `modifier_id`, `modifier`, `create_time`, `update_time`) VALUES (81, 80, 2, 1, '基本权限', 'mongo:base', 1, 'null', 1, 'admin', 1, 'admin', '2022-05-13 14:04:16', '2022-05-13 14:04:16');
 | 
					INSERT INTO `t_sys_resource`(`id`, `pid`, `type`, `status`, `name`, `code`, `weight`, `meta`, `creator_id`, `creator`, `modifier_id`, `modifier`, `create_time`, `update_time`) VALUES (81, 80, 2, 1, '基本权限', 'mongo:base', 1, 'null', 1, 'admin', 1, 'admin', '2022-05-13 14:04:16', '2022-05-13 14:04:16');
 | 
				
			||||||
INSERT INTO `t_sys_resource`(`id`, `pid`, `type`, `status`, `name`, `code`, `weight`, `meta`, `creator_id`, `creator`, `modifier_id`, `modifier`, `create_time`, `update_time`) VALUES (82, 79, 1, 1, 'Mongo管理', 'mongo-manage', 2, '{\"component\":\"MongoList\",\"icon\":\"Menu\",\"isKeepAlive\":true,\"routeName\":\"MongoList\"}', 1, 'admin', 1, 'admin', '2022-05-16 18:13:06', '2022-05-16 18:13:06');
 | 
					INSERT INTO `t_sys_resource`(`id`, `pid`, `type`, `status`, `name`, `code`, `weight`, `meta`, `creator_id`, `creator`, `modifier_id`, `modifier`, `create_time`, `update_time`) VALUES (82, 79, 1, 1, 'Mongo管理', 'mongo-manage', 2, '{\"component\":\"MongoList\",\"icon\":\"Menu\",\"isKeepAlive\":true,\"routeName\":\"MongoList\"}', 1, 'admin', 1, 'admin', '2022-05-16 18:13:06', '2022-05-16 18:13:06');
 | 
				
			||||||
INSERT INTO `t_sys_resource`(`id`, `pid`, `type`, `status`, `name`, `code`, `weight`, `meta`, `creator_id`, `creator`, `modifier_id`, `modifier`, `create_time`, `update_time`) VALUES (83, 82, 2, 1, '基本权限', 'mongo:manage:base', 1, 'null', 1, 'admin', 1, 'admin', '2022-05-16 18:13:25', '2022-05-16 18:13:25');
 | 
					INSERT INTO `t_sys_resource`(`id`, `pid`, `type`, `status`, `name`, `code`, `weight`, `meta`, `creator_id`, `creator`, `modifier_id`, `modifier`, `create_time`, `update_time`) VALUES (83, 82, 2, 1, '基本权限', 'mongo:manage:base', 1, 'null', 1, 'admin', 1, 'admin', '2022-05-16 18:13:25', '2022-05-16 18:13:25');
 | 
				
			||||||
 | 
					INSERT INTO `t_sys_resource`(`id`, `pid`, `type`, `status`, `name`, `code`, `weight`, `meta`, `creator_id`, `creator`, `modifier_id`, `modifier`, `create_time`, `update_time`) VALUES (84, 4, 1, 1, '操作日志', 'syslogs', 4, '{\"component\":\"SyslogList\",\"icon\":\"Tickets\",\"routeName\":\"SyslogList\"}', 1, 'admin', 1, 'admin', '2022-07-13 19:57:07', '2022-07-13 22:58:19');
 | 
				
			||||||
 | 
					INSERT INTO `t_sys_resource`(`id`, `pid`, `type`, `status`, `name`, `code`, `weight`, `meta`, `creator_id`, `creator`, `modifier_id`, `modifier`, `create_time`, `update_time`) VALUES (85, 84, 2, 1, '操作日志基本权限', 'syslog', 1, 'null', 1, 'admin', 1, 'admin', '2022-07-13 19:57:55', '2022-07-13 19:57:55');
 | 
				
			||||||
COMMIT;
 | 
					COMMIT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- ----------------------------
 | 
					-- ----------------------------
 | 
				
			||||||
@@ -625,8 +631,34 @@ INSERT INTO `t_sys_role_resource` VALUES (496, 8, 61, 1, 'admin', '2021-11-05 15
 | 
				
			|||||||
INSERT INTO `t_sys_role_resource` VALUES (497, 8, 62, 1, 'admin', '2021-11-05 15:59:16');
 | 
					INSERT INTO `t_sys_role_resource` VALUES (497, 8, 62, 1, 'admin', '2021-11-05 15:59:16');
 | 
				
			||||||
INSERT INTO `t_sys_role_resource` VALUES (498, 8, 63, 1, 'admin', '2021-11-05 15:59:16');
 | 
					INSERT INTO `t_sys_role_resource` VALUES (498, 8, 63, 1, 'admin', '2021-11-05 15:59:16');
 | 
				
			||||||
INSERT INTO `t_sys_role_resource` VALUES (499, 8, 64, 1, 'admin', '2021-11-05 15:59:16');
 | 
					INSERT INTO `t_sys_role_resource` VALUES (499, 8, 64, 1, 'admin', '2021-11-05 15:59:16');
 | 
				
			||||||
 | 
					INSERT INTO `t_sys_role_resource`(`id`, `role_id`, `resource_id`, `creator_id`, `creator`, `create_time`) VALUES (500, 1, 72, 1, 'admin', '2022-07-14 11:03:09');
 | 
				
			||||||
 | 
					INSERT INTO `t_sys_role_resource`(`id`, `role_id`, `resource_id`, `creator_id`, `creator`, `create_time`) VALUES (501, 1, 71, 1, 'admin', '2022-07-14 11:03:09');
 | 
				
			||||||
 | 
					INSERT INTO `t_sys_role_resource`(`id`, `role_id`, `resource_id`, `creator_id`, `creator`, `create_time`) VALUES (502, 1, 79, 1, 'admin', '2022-07-14 11:03:09');
 | 
				
			||||||
 | 
					INSERT INTO `t_sys_role_resource`(`id`, `role_id`, `resource_id`, `creator_id`, `creator`, `create_time`) VALUES (503, 1, 80, 1, 'admin', '2022-07-14 11:03:09');
 | 
				
			||||||
 | 
					INSERT INTO `t_sys_role_resource`(`id`, `role_id`, `resource_id`, `creator_id`, `creator`, `create_time`) VALUES (504, 1, 81, 1, 'admin', '2022-07-14 11:03:09');
 | 
				
			||||||
 | 
					INSERT INTO `t_sys_role_resource`(`id`, `role_id`, `resource_id`, `creator_id`, `creator`, `create_time`) VALUES (505, 1, 82, 1, 'admin', '2022-07-14 11:03:09');
 | 
				
			||||||
 | 
					INSERT INTO `t_sys_role_resource`(`id`, `role_id`, `resource_id`, `creator_id`, `creator`, `create_time`) VALUES (506, 1, 83, 1, 'admin', '2022-07-14 11:03:09');
 | 
				
			||||||
 | 
					INSERT INTO `t_sys_role_resource`(`id`, `role_id`, `resource_id`, `creator_id`, `creator`, `create_time`) VALUES (507, 1, 84, 1, 'admin', '2022-07-14 11:10:11');
 | 
				
			||||||
 | 
					INSERT INTO `t_sys_role_resource`(`id`, `role_id`, `resource_id`, `creator_id`, `creator`, `create_time`) VALUES (508, 1, 85, 1, 'admin', '2022-07-14 11:10:11');
 | 
				
			||||||
COMMIT;
 | 
					COMMIT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- ----------------------------
 | 
				
			||||||
 | 
					-- 表结构: t_sys_log 
 | 
				
			||||||
 | 
					-- ----------------------------
 | 
				
			||||||
 | 
					DROP TABLE IF EXISTS `t_sys_log`;
 | 
				
			||||||
 | 
					CREATE TABLE `t_sys_log` (
 | 
				
			||||||
 | 
					  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 | 
				
			||||||
 | 
					  `type` tinyint(4) NOT NULL COMMENT '类型',
 | 
				
			||||||
 | 
					  `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '描述',
 | 
				
			||||||
 | 
					  `req_param` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '请求信息',
 | 
				
			||||||
 | 
					  `resp` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '响应信息',
 | 
				
			||||||
 | 
					  `creator` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT '调用者',
 | 
				
			||||||
 | 
					  `creator_id` bigint(20) NOT NULL COMMENT '调用者id',
 | 
				
			||||||
 | 
					  `create_time` datetime NOT NULL COMMENT '操作时间',
 | 
				
			||||||
 | 
					  PRIMARY KEY (`id`),
 | 
				
			||||||
 | 
					  KEY `idx_creator_id` (`creator_id`) USING BTREE
 | 
				
			||||||
 | 
					) ENGINE=InnoDB AUTO_INCREMENT=41 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='系统操作日志';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- ----------------------------
 | 
					-- ----------------------------
 | 
				
			||||||
-- Table structure for t_mongo
 | 
					-- Table structure for t_mongo
 | 
				
			||||||
@@ -636,6 +668,8 @@ CREATE TABLE `t_mongo` (
 | 
				
			|||||||
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 | 
					  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 | 
				
			||||||
  `name` varchar(36) COLLATE utf8mb4_bin NOT NULL COMMENT '名称',
 | 
					  `name` varchar(36) COLLATE utf8mb4_bin NOT NULL COMMENT '名称',
 | 
				
			||||||
  `uri` varchar(255) COLLATE utf8mb4_bin NOT NULL COMMENT '连接uri',
 | 
					  `uri` varchar(255) COLLATE utf8mb4_bin NOT NULL COMMENT '连接uri',
 | 
				
			||||||
 | 
					  `enableSshTunnel` tinyint(2) DEFAULT NULL COMMENT '是否启用ssh隧道',
 | 
				
			||||||
 | 
					  `sshTunnelMachineId` bigint(20) DEFAULT NULL COMMENT 'ssh隧道的机器id',
 | 
				
			||||||
  `project_id` bigint(20) NOT NULL,
 | 
					  `project_id` bigint(20) NOT NULL,
 | 
				
			||||||
  `project` varchar(36) COLLATE utf8mb4_bin DEFAULT NULL,
 | 
					  `project` varchar(36) COLLATE utf8mb4_bin DEFAULT NULL,
 | 
				
			||||||
  `env_id` bigint(20) DEFAULT NULL,
 | 
					  `env_id` bigint(20) DEFAULT NULL,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,28 +7,28 @@ type BizError struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					var (
 | 
				
			||||||
	Success       *BizError = NewBizErrCode(200, "success")
 | 
						Success       BizError = NewBizErrCode(200, "success")
 | 
				
			||||||
	BizErr        *BizError = NewBizErrCode(400, "biz error")
 | 
						BizErr        BizError = NewBizErrCode(400, "biz error")
 | 
				
			||||||
	ServerError   *BizError = NewBizErrCode(500, "server error")
 | 
						ServerError   BizError = NewBizErrCode(500, "server error")
 | 
				
			||||||
	PermissionErr *BizError = NewBizErrCode(501, "token error")
 | 
						PermissionErr BizError = NewBizErrCode(501, "token error")
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 错误消息
 | 
					// 错误消息
 | 
				
			||||||
func (e *BizError) Error() string {
 | 
					func (e BizError) Error() string {
 | 
				
			||||||
	return e.err
 | 
						return e.err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 错误码
 | 
					// 错误码
 | 
				
			||||||
func (e *BizError) Code() int16 {
 | 
					func (e BizError) Code() int16 {
 | 
				
			||||||
	return e.code
 | 
						return e.code
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 创建业务逻辑错误结构体,默认为业务逻辑错误
 | 
					// 创建业务逻辑错误结构体,默认为业务逻辑错误
 | 
				
			||||||
func NewBizErr(msg string) *BizError {
 | 
					func NewBizErr(msg string) BizError {
 | 
				
			||||||
	return &BizError{code: BizErr.code, err: msg}
 | 
						return BizError{code: BizErr.code, err: msg}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 创建业务逻辑错误结构体,可设置指定错误code
 | 
					// 创建业务逻辑错误结构体,可设置指定错误code
 | 
				
			||||||
func NewBizErrCode(code int16, msg string) *BizError {
 | 
					func NewBizErrCode(code int16, msg string) BizError {
 | 
				
			||||||
	return &BizError{code: code, err: msg}
 | 
						return BizError{code: code, err: msg}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,20 +12,38 @@ import (
 | 
				
			|||||||
	"github.com/sirupsen/logrus"
 | 
						"github.com/sirupsen/logrus"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type SaveLogFunc func(*ReqCtx)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var saveLog SaveLogFunc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 设置保存日志处理函数
 | 
				
			||||||
 | 
					func SetSaveLogFunc(sl SaveLogFunc) {
 | 
				
			||||||
 | 
						saveLog = sl
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type LogInfo struct {
 | 
					type LogInfo struct {
 | 
				
			||||||
	LogResp     bool   // 是否记录返回结果
 | 
						LogResp     bool   // 是否记录返回结果
 | 
				
			||||||
	Description string // 请求描述
 | 
						Description string // 请求描述
 | 
				
			||||||
 | 
						Save        bool   // 是否保存日志
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 新建日志信息
 | 
				
			||||||
func NewLogInfo(description string) *LogInfo {
 | 
					func NewLogInfo(description string) *LogInfo {
 | 
				
			||||||
	return &LogInfo{Description: description, LogResp: false}
 | 
						return &LogInfo{Description: description, LogResp: false}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 是否记录返回结果
 | 
				
			||||||
func (i *LogInfo) WithLogResp(logResp bool) *LogInfo {
 | 
					func (i *LogInfo) WithLogResp(logResp bool) *LogInfo {
 | 
				
			||||||
	i.LogResp = logResp
 | 
						i.LogResp = logResp
 | 
				
			||||||
	return i
 | 
						return i
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 是否保存日志
 | 
				
			||||||
 | 
					func (i *LogInfo) WithSave(saveLog bool) *LogInfo {
 | 
				
			||||||
 | 
						i.Save = saveLog
 | 
				
			||||||
 | 
						return i
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func LogHandler(rc *ReqCtx) error {
 | 
					func LogHandler(rc *ReqCtx) error {
 | 
				
			||||||
	li := rc.LogInfo
 | 
						li := rc.LogInfo
 | 
				
			||||||
	if li == nil {
 | 
						if li == nil {
 | 
				
			||||||
@@ -41,6 +59,10 @@ func LogHandler(rc *ReqCtx) error {
 | 
				
			|||||||
	req := rc.GinCtx.Request
 | 
						req := rc.GinCtx.Request
 | 
				
			||||||
	lfs[req.Method] = req.URL.Path
 | 
						lfs[req.Method] = req.URL.Path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 如果需要保存日志,并且保存日志处理函数存在则执行保存日志函数
 | 
				
			||||||
 | 
						if li.Save && saveLog != nil {
 | 
				
			||||||
 | 
							go saveLog(rc)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if err := rc.Err; err != nil {
 | 
						if err := rc.Err; err != nil {
 | 
				
			||||||
		logger.Log.WithFields(lfs).Error(getErrMsg(rc, err))
 | 
							logger.Log.WithFields(lfs).Error(getErrMsg(rc, err))
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
@@ -73,7 +95,7 @@ func getErrMsg(rc *ReqCtx, err interface{}) string {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	var errMsg string
 | 
						var errMsg string
 | 
				
			||||||
	switch t := err.(type) {
 | 
						switch t := err.(type) {
 | 
				
			||||||
	case *biz.BizError:
 | 
						case biz.BizError:
 | 
				
			||||||
		errMsg = fmt.Sprintf("\n<-e errCode: %d, errMsg: %s", t.Code(), t.Error())
 | 
							errMsg = fmt.Sprintf("\n<-e errCode: %d, errMsg: %s", t.Code(), t.Error())
 | 
				
			||||||
	case error:
 | 
						case error:
 | 
				
			||||||
		errMsg = fmt.Sprintf("\n<-e errMsg: %s\n%s", t.Error(), string(debug.Stack()))
 | 
							errMsg = fmt.Sprintf("\n<-e errMsg: %s\n%s", t.Error(), string(debug.Stack()))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,7 +53,7 @@ func (rc *ReqCtx) Handle(handler HandlerFunc) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	begin := time.Now()
 | 
						begin := time.Now()
 | 
				
			||||||
	handler(rc)
 | 
						handler(rc)
 | 
				
			||||||
	rc.timed = time.Now().Sub(begin).Milliseconds()
 | 
						rc.timed = time.Since(begin).Milliseconds()
 | 
				
			||||||
	if !rc.NoRes {
 | 
						if !rc.NoRes {
 | 
				
			||||||
		ginx.SuccessRes(ginCtx, rc.ResData)
 | 
							ginx.SuccessRes(ginCtx, rc.ResData)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -62,7 +62,7 @@ func SuccessRes(g *gin.Context, data interface{}) {
 | 
				
			|||||||
// 返回失败结果集
 | 
					// 返回失败结果集
 | 
				
			||||||
func ErrorRes(g *gin.Context, err interface{}) {
 | 
					func ErrorRes(g *gin.Context, err interface{}) {
 | 
				
			||||||
	switch t := err.(type) {
 | 
						switch t := err.(type) {
 | 
				
			||||||
	case *biz.BizError:
 | 
						case biz.BizError:
 | 
				
			||||||
		g.JSON(http.StatusOK, model.Error(t))
 | 
							g.JSON(http.StatusOK, model.Error(t))
 | 
				
			||||||
	case error:
 | 
						case error:
 | 
				
			||||||
		g.JSON(http.StatusOK, model.ServerError())
 | 
							g.JSON(http.StatusOK, model.ServerError())
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,7 +44,7 @@ func SuccessNoData() *Result {
 | 
				
			|||||||
	return &Result{Code: SuccessCode, Msg: SuccessMsg}
 | 
						return &Result{Code: SuccessCode, Msg: SuccessMsg}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Error(bizerr *biz.BizError) *Result {
 | 
					func Error(bizerr biz.BizError) *Result {
 | 
				
			||||||
	return &Result{Code: bizerr.Code(), Msg: bizerr.Error()}
 | 
						return &Result{Code: bizerr.Code(), Msg: bizerr.Error()}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,6 +13,9 @@ func RunWebServer() {
 | 
				
			|||||||
	ctx.UseBeforeHandlerInterceptor(ctx.PermissionHandler)
 | 
						ctx.UseBeforeHandlerInterceptor(ctx.PermissionHandler)
 | 
				
			||||||
	// 日志处理器
 | 
						// 日志处理器
 | 
				
			||||||
	ctx.UseAfterHandlerInterceptor(ctx.LogHandler)
 | 
						ctx.UseAfterHandlerInterceptor(ctx.LogHandler)
 | 
				
			||||||
 | 
						// 设置日志保存函数
 | 
				
			||||||
 | 
						ctx.SetSaveLogFunc(initialize.InitSaveLogFunc())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 注册路由
 | 
						// 注册路由
 | 
				
			||||||
	web := initialize.InitRouter()
 | 
						web := initialize.InitRouter()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,15 @@
 | 
				
			|||||||
package utils
 | 
					package utils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"bytes"
 | 
				
			||||||
	"crypto/md5"
 | 
						"crypto/md5"
 | 
				
			||||||
 | 
						"crypto/rand"
 | 
				
			||||||
 | 
						"crypto/rsa"
 | 
				
			||||||
 | 
						"crypto/x509"
 | 
				
			||||||
 | 
						"encoding/base64"
 | 
				
			||||||
	"encoding/hex"
 | 
						"encoding/hex"
 | 
				
			||||||
 | 
						"encoding/pem"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// md5
 | 
					// md5
 | 
				
			||||||
@@ -11,3 +18,115 @@ func Md5(str string) string {
 | 
				
			|||||||
	h.Write([]byte(str))
 | 
						h.Write([]byte(str))
 | 
				
			||||||
	return hex.EncodeToString(h.Sum(nil))
 | 
						return hex.EncodeToString(h.Sum(nil))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 系统统一RSA秘钥对
 | 
				
			||||||
 | 
					var RsaPair []string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 生成RSA私钥和公钥字符串
 | 
				
			||||||
 | 
					// bits 证书大小
 | 
				
			||||||
 | 
					// @return privateKeyStr publicKeyStr error
 | 
				
			||||||
 | 
					func GenerateRSAKey(bits int) (string, string, error) {
 | 
				
			||||||
 | 
						var privateKeyStr, publicKeyStr string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						//GenerateKey函数使用随机数据生成器random生成一对具有指定字位数的RSA密钥
 | 
				
			||||||
 | 
						//Reader是一个全局、共享的密码用强随机数生成器
 | 
				
			||||||
 | 
						privateKey, err := rsa.GenerateKey(rand.Reader, bits)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return privateKeyStr, publicKeyStr, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						//保存私钥
 | 
				
			||||||
 | 
						//通过x509标准将得到的ras私钥序列化为ASN.1 的 DER编码字符串
 | 
				
			||||||
 | 
						X509PrivateKey := x509.MarshalPKCS1PrivateKey(privateKey)
 | 
				
			||||||
 | 
						//构建一个pem.Block结构体对象
 | 
				
			||||||
 | 
						privateBlock := pem.Block{Type: "RSA Private Key", Bytes: X509PrivateKey}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						privateBuf := new(bytes.Buffer)
 | 
				
			||||||
 | 
						pem.Encode(privateBuf, &privateBlock)
 | 
				
			||||||
 | 
						privateKeyStr = privateBuf.String()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						//保存公钥
 | 
				
			||||||
 | 
						//获取公钥的数据
 | 
				
			||||||
 | 
						publicKey := privateKey.PublicKey
 | 
				
			||||||
 | 
						//X509对公钥编码
 | 
				
			||||||
 | 
						X509PublicKey, err := x509.MarshalPKIXPublicKey(&publicKey)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return publicKeyStr, privateKeyStr, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						//创建一个pem.Block结构体对象
 | 
				
			||||||
 | 
						publicBlock := pem.Block{Type: "RSA Public Key", Bytes: X509PublicKey}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						publicBuf := new(bytes.Buffer)
 | 
				
			||||||
 | 
						pem.Encode(publicBuf, &publicBlock)
 | 
				
			||||||
 | 
						publicKeyStr = publicBuf.String()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return privateKeyStr, publicKeyStr, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// rsa解密
 | 
				
			||||||
 | 
					func RsaDecrypt(privateKeyStr string, data []byte) ([]byte, error) {
 | 
				
			||||||
 | 
						block, _ := pem.Decode([]byte(privateKeyStr))
 | 
				
			||||||
 | 
						if block == nil {
 | 
				
			||||||
 | 
							return nil, errors.New("private key error")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return rsa.DecryptPKCS1v15(rand.Reader, priv, data)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 使用系统默认的私钥解密
 | 
				
			||||||
 | 
					// @param base64 字符串是否使用base64编码
 | 
				
			||||||
 | 
					func DefaultRsaDecrypt(data string, useBase64 bool) (string, error) {
 | 
				
			||||||
 | 
						// 空字符串不解密
 | 
				
			||||||
 | 
						if data == "" {
 | 
				
			||||||
 | 
							return "", nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if useBase64 {
 | 
				
			||||||
 | 
							if decodeBase64, err := base64.StdEncoding.DecodeString(data); err != nil {
 | 
				
			||||||
 | 
								return "", err
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								data = string(decodeBase64)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						priKey, err := GetRsaPrivateKey()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return "", err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						val, err := RsaDecrypt(priKey, []byte(data))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return "", err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return string(val), nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取系统的RSA公钥
 | 
				
			||||||
 | 
					func GetRsaPublicKey() (string, error) {
 | 
				
			||||||
 | 
						if len(RsaPair) == 2 {
 | 
				
			||||||
 | 
							return RsaPair[1], nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						privateKey, publicKey, err := GenerateRSAKey(1024)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return "", err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						RsaPair = append(RsaPair, privateKey)
 | 
				
			||||||
 | 
						RsaPair = append(RsaPair, publicKey)
 | 
				
			||||||
 | 
						return publicKey, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取系统私钥
 | 
				
			||||||
 | 
					func GetRsaPrivateKey() (string, error) {
 | 
				
			||||||
 | 
						if len(RsaPair) == 2 {
 | 
				
			||||||
 | 
							return RsaPair[0], nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						privateKey, publicKey, err := GenerateRSAKey(1024)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return "", err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						RsaPair = append(RsaPair, privateKey)
 | 
				
			||||||
 | 
						RsaPair = append(RsaPair, publicKey)
 | 
				
			||||||
 | 
						return privateKey, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										58
									
								
								server/pkg/utils/ssh_client.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								server/pkg/utils/ssh_client.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
				
			|||||||
 | 
					package utils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io/ioutil"
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"golang.org/x/crypto/ssh"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func SSHConnect(user, password, host, key string, port int) (*ssh.Client, error) {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							auth         []ssh.AuthMethod
 | 
				
			||||||
 | 
							addr         string
 | 
				
			||||||
 | 
							clientConfig *ssh.ClientConfig
 | 
				
			||||||
 | 
							client       *ssh.Client
 | 
				
			||||||
 | 
							config       ssh.Config
 | 
				
			||||||
 | 
							//session      *ssh.Session
 | 
				
			||||||
 | 
							err error
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// get auth method
 | 
				
			||||||
 | 
						auth = make([]ssh.AuthMethod, 0)
 | 
				
			||||||
 | 
						if key == "" {
 | 
				
			||||||
 | 
							auth = append(auth, ssh.Password(password))
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							pemBytes, err := ioutil.ReadFile(key)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var signer ssh.Signer
 | 
				
			||||||
 | 
							if password == "" {
 | 
				
			||||||
 | 
								signer, err = ssh.ParsePrivateKey(pemBytes)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								signer, err = ssh.ParsePrivateKeyWithPassphrase(pemBytes, []byte(password))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							auth = append(auth, ssh.PublicKeys(signer))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						clientConfig = &ssh.ClientConfig{
 | 
				
			||||||
 | 
							User:    user,
 | 
				
			||||||
 | 
							Auth:    auth,
 | 
				
			||||||
 | 
							Timeout: 30 * time.Second,
 | 
				
			||||||
 | 
							Config:  config,
 | 
				
			||||||
 | 
							HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
 | 
				
			||||||
 | 
								return nil
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						addr = fmt.Sprintf("%s:%d", host, port)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						client, err = ssh.Dial("tcp", addr, clientConfig)
 | 
				
			||||||
 | 
						return client, err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										36
									
								
								server/pkg/utils/ssh_conn_wrap.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								server/pkg/utils/ssh_conn_wrap.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					package utils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type WrapSshConn struct {
 | 
				
			||||||
 | 
						Conn net.Conn
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (c *WrapSshConn) Read(b []byte) (n int, err error) {
 | 
				
			||||||
 | 
						return c.Conn.Read(b)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (c *WrapSshConn) Write(b []byte) (n int, err error) {
 | 
				
			||||||
 | 
						return c.Conn.Write(b)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					func (c *WrapSshConn) Close() error {
 | 
				
			||||||
 | 
						return c.Conn.Close()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					func (c *WrapSshConn) LocalAddr() net.Addr {
 | 
				
			||||||
 | 
						return c.Conn.LocalAddr()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					func (c *WrapSshConn) RemoteAddr() net.Addr {
 | 
				
			||||||
 | 
						return c.Conn.RemoteAddr()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					func (c *WrapSshConn) SetDeadline(t time.Time) error {
 | 
				
			||||||
 | 
						return c.Conn.SetDeadline(t)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					func (c *WrapSshConn) SetReadDeadline(t time.Time) error {
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					func (c *WrapSshConn) SetWriteDeadline(t time.Time) error {
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,7 +1,8 @@
 | 
				
			|||||||
后端配置:
 | 
					相关配置文件: 
 | 
				
			||||||
  服务端口,mysql等信息在config.yml里配置即可。
 | 
					  后端:
 | 
				
			||||||
前端配置:
 | 
					    config.yml: 服务端口,mysql等信息在此配置即可。
 | 
				
			||||||
  static/config.js中的api地址配成启动后的后端服务的真实地址即可
 | 
					  前端:
 | 
				
			||||||
 | 
					    static/config.js: 若前后端分开部署则将该文件中的api地址配成后端服务的真实地址即可,否则无需修改。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
服务启动:./startup.sh
 | 
					服务启动:./startup.sh
 | 
				
			||||||
服务关闭:./shutdown.sh
 | 
					服务关闭:./shutdown.sh
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user