1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 22:18:07 +08:00

fix: 修改数据库创建权限校验规则 (#2220)

This commit is contained in:
ssongliu 2023-09-07 17:42:10 +08:00 committed by GitHub
parent f812d9f7cd
commit 6e8f22a4a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 7 deletions

View File

@ -14,7 +14,6 @@ import (
"github.com/1Panel-dev/1Panel/backend/buserr"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/common"
"github.com/1Panel-dev/1Panel/backend/utils/files"
)
@ -307,12 +306,13 @@ func (r *Local) SyncDB(version string) ([]SyncDBInfo, error) {
}
if len(dataItem.Username) == 0 {
dataItem.Username = loadNameByDB(parts[0], version)
dataItem.Password = randomPassword(dataItem.Username)
if err := r.CreateUser(CreateInfo{
Name: parts[0],
Format: parts[1],
Version: version,
Username: dataItem.Username,
Password: common.RandStr(16),
Password: dataItem.Password,
Permission: "%",
Timeout: 300,
}, false); err != nil {

View File

@ -12,7 +12,6 @@ import (
"github.com/1Panel-dev/1Panel/backend/buserr"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/common"
"github.com/1Panel-dev/1Panel/backend/utils/files"
"github.com/1Panel-dev/1Panel/backend/utils/mysql/helper"
)
@ -317,7 +316,7 @@ func (r *Remote) SyncDB(version string) ([]SyncDBInfo, error) {
}
if len(dataItem.Username) == 0 {
dataItem.Username = loadNameByDB(dbName, version)
dataItem.Password = common.RandStr(16)
dataItem.Password = randomPassword(dataItem.Username)
if err := r.CreateUser(CreateInfo{
Name: dbName,
Format: charsetName,
@ -329,7 +328,6 @@ func (r *Remote) SyncDB(version string) ([]SyncDBInfo, error) {
}, false); err != nil {
return datas, fmt.Errorf("sync db from remote server failed, err: create user failed %v", err)
}
dataItem.Permission = "%"
} else {
if isLocal {

View File

@ -84,7 +84,7 @@ import { ElForm } from 'element-plus';
import { addMysqlDB } from '@/api/modules/database';
import DrawerHeader from '@/components/drawer-header/index.vue';
import { MsgSuccess } from '@/utils/message';
import { getRandomStr } from '@/utils/util';
import { checkIp, getRandomStr } from '@/utils/util';
const loading = ref();
const createVisiable = ref(false);
@ -105,8 +105,18 @@ const rules = reactive({
username: [Rules.requiredInput, Rules.name],
password: [Rules.paramComplexity],
permission: [Rules.requiredSelect],
permissionIPs: [Rules.requiredInput],
permissionIPs: [{ validator: checkIPs, trigger: 'blur', required: true }],
});
function checkIPs(rule: any, value: any, callback: any) {
let ips = form.permissionIPs.split(',');
for (const item of ips) {
if (checkIp(item)) {
return callback(new Error(i18n.global.t('commons.rule.ip')));
}
}
callback();
}
type FormInstance = InstanceType<typeof ElForm>;
const formRef = ref<FormInstance>();