Compare commits

..
5 Commits
12 changed files with 96 additions and 38 deletions
+4
View File
@@ -840,6 +840,10 @@ func handleInstalled(appInstallList []model.AppInstall, updated bool) ([]respons
}
versions = common.GetSortedVersions(versions)
if len(versions) == 0 {
if !updated {
installDTO.CanUpdate = false
res = append(res, installDTO)
}
continue
}
lastVersion := versions[0]
+11 -3
View File
@@ -531,11 +531,15 @@ func (u *ContainerService) ContainerLogClean(req dto.OperationWithName) error {
if err != nil {
return err
}
container, err := client.ContainerInspect(context.Background(), req.Name)
ctx := context.Background()
containerItem, err := client.ContainerInspect(ctx, req.Name)
if err != nil {
return err
}
file, err := os.OpenFile(container.LogPath, os.O_RDWR|os.O_CREATE, 0666)
if err := client.ContainerStop(ctx, containerItem.ID, container.StopOptions{}); err != nil {
return err
}
file, err := os.OpenFile(containerItem.LogPath, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
return err
}
@@ -545,10 +549,14 @@ func (u *ContainerService) ContainerLogClean(req dto.OperationWithName) error {
}
_, _ = file.Seek(0, 0)
files, _ := filepath.Glob(fmt.Sprintf("%s.*", container.LogPath))
files, _ := filepath.Glob(fmt.Sprintf("%s.*", containerItem.LogPath))
for _, file := range files {
_ = os.Remove(file)
}
if err := client.ContainerStart(ctx, containerItem.ID, types.ContainerStartOptions{}); err != nil {
return err
}
return nil
}
+19
View File
@@ -1,5 +1,11 @@
package client
import (
"strings"
"github.com/1Panel-dev/1Panel/backend/utils/common"
)
type DBInfo struct {
From string `json:"from"`
Address string `json:"address"`
@@ -85,3 +91,16 @@ var formatMap = map[string]string{
"gbk": "gbk_chinese_ci",
"big5": "big5_chinese_ci",
}
func loadNameByDB(name, version string) string {
if strings.HasPrefix(version, "5.6") {
if len(name) <= 16 {
return name
}
return strings.TrimSuffix(name[:10], "_") + "_" + common.RandStr(5)
}
if len(name) <= 32 {
return name
}
return strings.TrimSuffix(name[:25], "_") + "_" + common.RandStr(5)
}
+6 -6
View File
@@ -38,7 +38,7 @@ func (r *Local) Create(info CreateInfo) error {
return err
}
if err := r.CreateUser(info); err != nil {
if err := r.CreateUser(info, true); err != nil {
_ = r.ExecSQL(fmt.Sprintf("drop database if exists `%s`", info.Name), info.Timeout)
return err
}
@@ -46,7 +46,7 @@ func (r *Local) Create(info CreateInfo) error {
return nil
}
func (r *Local) CreateUser(info CreateInfo) error {
func (r *Local) CreateUser(info CreateInfo, withDeleteDB bool) error {
var userlist []string
if strings.Contains(info.Permission, ",") {
ips := strings.Split(info.Permission, ",")
@@ -201,7 +201,7 @@ func (r *Local) ChangeAccess(info AccessChangeInfo) error {
Password: info.Password,
Permission: info.Permission,
Timeout: info.Timeout,
}); err != nil {
}, false); err != nil {
return err
}
if err := r.ExecSQL("flush privileges", 300); err != nil {
@@ -305,18 +305,18 @@ func (r *Local) SyncDB(version string) ([]SyncDBInfo, error) {
}
}
if len(dataItem.Username) == 0 {
dataItem.Username = loadNameByDB(parts[0], version)
if err := r.CreateUser(CreateInfo{
Name: parts[0],
Format: parts[1],
Version: version,
Username: parts[0],
Username: dataItem.Username,
Password: common.RandStr(16),
Permission: "%",
Timeout: 300,
}); err != nil {
}, false); err != nil {
global.LOG.Errorf("sync from remote server failed, err: create user failed %v", err)
}
dataItem.Username = parts[0]
dataItem.Permission = "%"
} else {
if isLocal {
+27 -23
View File
@@ -39,7 +39,7 @@ func (r *Remote) Create(info CreateInfo) error {
return err
}
if err := r.CreateUser(info); err != nil {
if err := r.CreateUser(info, true); err != nil {
_ = r.ExecSQL(fmt.Sprintf("drop database if exists `%s`", info.Name), info.Timeout)
return err
}
@@ -47,7 +47,7 @@ func (r *Remote) Create(info CreateInfo) error {
return nil
}
func (r *Remote) CreateUser(info CreateInfo) error {
func (r *Remote) CreateUser(info CreateInfo, withDeleteDB bool) error {
var userlist []string
if strings.Contains(info.Permission, ",") {
ips := strings.Split(info.Permission, ",")
@@ -62,15 +62,17 @@ func (r *Remote) CreateUser(info CreateInfo) error {
for _, user := range userlist {
if err := r.ExecSQL(fmt.Sprintf("create user %s identified by '%s';", user, info.Password), info.Timeout); err != nil {
_ = r.Delete(DeleteInfo{
Name: info.Name,
Version: info.Version,
Username: info.Username,
Permission: info.Permission,
ForceDelete: true,
Timeout: 300})
if strings.Contains(err.Error(), "ERROR 1396") {
return buserr.New(constant.ErrUserIsExist)
if withDeleteDB {
_ = r.Delete(DeleteInfo{
Name: info.Name,
Version: info.Version,
Username: info.Username,
Permission: info.Permission,
ForceDelete: true,
Timeout: 300})
if strings.Contains(err.Error(), "ERROR 1396") {
return buserr.New(constant.ErrUserIsExist)
}
}
return err
}
@@ -82,13 +84,15 @@ func (r *Remote) CreateUser(info CreateInfo) error {
grantStr = fmt.Sprintf("%s identified by '%s' with grant option;", grantStr, info.Password)
}
if err := r.ExecSQL(grantStr, info.Timeout); err != nil {
_ = r.Delete(DeleteInfo{
Name: info.Name,
Version: info.Version,
Username: info.Username,
Permission: info.Permission,
ForceDelete: true,
Timeout: 300})
if withDeleteDB {
_ = r.Delete(DeleteInfo{
Name: info.Name,
Version: info.Version,
Username: info.Username,
Permission: info.Permission,
ForceDelete: true,
Timeout: 300})
}
return err
}
}
@@ -202,7 +206,7 @@ func (r *Remote) ChangeAccess(info AccessChangeInfo) error {
Password: info.Password,
Permission: info.Permission,
Timeout: info.Timeout,
}); err != nil {
}, false); err != nil {
return err
}
if err := r.ExecSQL("flush privileges", 300); err != nil {
@@ -312,18 +316,18 @@ func (r *Remote) SyncDB(version string) ([]SyncDBInfo, error) {
i++
}
if len(dataItem.Username) == 0 {
dataItem.Username = loadNameByDB(dbName, version)
if err := r.CreateUser(CreateInfo{
Name: dbName,
Format: charsetName,
Version: version,
Username: dbName,
Username: dataItem.Username,
Password: common.RandStr(16),
Permission: "%",
Timeout: 300,
}); err != nil {
global.LOG.Errorf("sync from remote server failed, err: create user failed %v", err)
}, false); err != nil {
return datas, fmt.Errorf("sync db from remote server failed, err: create user failed %v", err)
}
dataItem.Username = dbName
dataItem.Permission = "%"
} else {
if isLocal {
+1 -1
View File
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/public/favicon.png" />
@@ -130,7 +130,7 @@ const acceptParams = (props: DialogProps): void => {
};
const onClean = async () => {
ElMessageBox.confirm(i18n.global.t('commons.msg.clean'), i18n.global.t('container.cleanLog'), {
ElMessageBox.confirm(i18n.global.t('container.cleanLogHelper'), i18n.global.t('container.cleanLog'), {
confirmButtonText: i18n.global.t('commons.button.confirm'),
cancelButtonText: i18n.global.t('commons.button.cancel'),
type: 'info',
+2
View File
@@ -507,6 +507,8 @@ const message = {
lastHour: 'Last Hour',
last10Min: 'Last 10 Minutes',
cleanLog: 'Clean log',
cleanLogHelper:
'Clearing logs requires restarting the container, and this operation cannot be rolled back. Do you want to continue?',
newName: 'New name',
source: 'Resource rate',
cpuShare: 'CPU Share',
+1
View File
@@ -496,6 +496,7 @@ const message = {
lastHour: '最近 1 小時',
last10Min: '最近 10 分鐘',
cleanLog: '清空日誌',
cleanLogHelper: '清空日誌需要重啟容器,該操作無法回滾,是否繼續?',
newName: '新名稱',
source: '資源使用率',
cpuShare: 'CPU 權重',
+1
View File
@@ -496,6 +496,7 @@ const message = {
lastHour: '最近 1 小时',
last10Min: '最近 10 分钟',
cleanLog: '清空日志',
cleanLogHelper: '清空日志需要重启容器,该操作无法回滚,是否继续?',
newName: '新名称',
source: '资源使用率',
cpuShare: 'CPU 权重',
@@ -161,7 +161,7 @@ const onDownload = async () => {
};
const onClean = async () => {
ElMessageBox.confirm(i18n.global.t('commons.msg.clean'), i18n.global.t('container.cleanLog'), {
ElMessageBox.confirm(i18n.global.t('container.cleanLogHelper'), i18n.global.t('container.cleanLog'), {
confirmButtonText: i18n.global.t('commons.button.confirm'),
cancelButtonText: i18n.global.t('commons.button.cancel'),
type: 'info',
@@ -4,10 +4,17 @@
<template #header>
<DrawerHeader :header="$t('setting.systemIP')" :back="handleClose" />
</template>
<el-form ref="formRef" label-position="top" :model="form" @submit.prevent v-loading="loading">
<el-form
ref="formRef"
label-position="top"
:model="form"
:rules="rules"
@submit.prevent
v-loading="loading"
>
<el-row type="flex" justify="center">
<el-col :span="22">
<el-form-item :label="$t('setting.systemIP')" prop="systemIP" :rules="Rules.ipV4V6OrDomain">
<el-form-item :label="$t('setting.systemIP')" prop="systemIP">
<el-input clearable v-model="form.systemIP" />
<span class="input-help">{{ $t('commons.rule.hostHelper') }}</span>
</el-form-item>
@@ -31,8 +38,8 @@ import i18n from '@/lang';
import { MsgSuccess } from '@/utils/message';
import { updateSetting } from '@/api/modules/setting';
import { FormInstance } from 'element-plus';
import { Rules } from '@/global/form-rules';
import DrawerHeader from '@/components/drawer-header/index.vue';
import { checkDomain, checkIpV4V6 } from '@/utils/util';
const emit = defineEmits<{ (e: 'search'): void }>();
@@ -47,6 +54,18 @@ const form = reactive({
});
const formRef = ref<FormInstance>();
const rules = reactive({
systemIP: [{ validator: checkSystemIP, trigger: 'blur' }],
});
function checkSystemIP(rule: any, value: any, callback: any) {
if (form.systemIP !== '') {
if (checkIpV4V6(form.systemIP) && checkDomain(form.systemIP)) {
return callback(new Error(i18n.global.t('commons.rule.host')));
}
}
callback();
}
const acceptParams = (params: DialogProps): void => {
form.systemIP = params.systemIP;