diff --git a/backend/app/service/cronjob_helper.go b/backend/app/service/cronjob_helper.go index 38407e784..267c6309e 100644 --- a/backend/app/service/cronjob_helper.go +++ b/backend/app/service/cronjob_helper.go @@ -86,7 +86,7 @@ func (u *CronjobService) HandleBackup(cronjob *model.Cronjob, startTime time.Tim } baseDir = localDir } else { - baseDir = constant.TmpDir + baseDir = global.CONF.System.TmpDir } switch cronjob.Type { diff --git a/backend/app/service/database_mysql.go b/backend/app/service/database_mysql.go index f8526c58e..7fc75a077 100644 --- a/backend/app/service/database_mysql.go +++ b/backend/app/service/database_mysql.go @@ -659,7 +659,7 @@ func backupMysql(backupType, baseDir, backupDir, mysqlName, dbName, fileName str FileDir: backupDir, FileName: fileName, } - if baseDir != constant.TmpDir || backupType == "LOCAL" { + if baseDir != global.CONF.System.TmpDir || backupType == "LOCAL" { record.Source = "LOCAL" record.FileDir = fullDir } diff --git a/backend/app/service/docker.go b/backend/app/service/docker.go index 2af151321..4b3fbdade 100644 --- a/backend/app/service/docker.go +++ b/backend/app/service/docker.go @@ -12,7 +12,6 @@ import ( "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/constant" - "github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/1Panel-dev/1Panel/backend/utils/docker" "github.com/pkg/errors" ) @@ -41,10 +40,10 @@ type daemonJsonItem struct { func (u *DockerService) LoadDockerStatus() string { status := constant.StatusRunning - stdout, err := cmd.Exec("systemctl is-active docker") - if string(stdout) != "active\n" || err != nil { - status = constant.Stopped - } + // stdout, err := cmd.Exec("systemctl is-active docker") + // if string(stdout) != "active\n" || err != nil { + // status = constant.Stopped + // } return status } diff --git a/backend/app/service/image.go b/backend/app/service/image.go index f18b357be..6e3848021 100644 --- a/backend/app/service/image.go +++ b/backend/app/service/image.go @@ -20,8 +20,6 @@ import ( "github.com/docker/docker/pkg/archive" ) -var dockerLogDir = constant.TmpDir + "/docker_logs" - type ImageService struct{} type IImageService interface { @@ -164,11 +162,13 @@ func (u *ImageService) ImageBuild(req dto.ImageBuild) (string, error) { res, err := client.ImageBuild(context.TODO(), tar, opts) if err != nil { global.LOG.Errorf("build image %s failed, err: %v", req.Name, err) + _, _ = file.WriteString("image build failed!") return } defer res.Body.Close() global.LOG.Infof("build image %s successful!", req.Name) _, _ = io.Copy(file, res.Body) + _, _ = file.WriteString("image build successful!") }() return logName, nil @@ -179,6 +179,7 @@ func (u *ImageService) ImagePull(req dto.ImagePull) (string, error) { if err != nil { return "", err } + dockerLogDir := global.CONF.System.TmpDir + "/docker_logs" if _, err := os.Stat(dockerLogDir); err != nil && os.IsNotExist(err) { if err = os.MkdirAll(dockerLogDir, os.ModePerm); err != nil { return "", err @@ -226,12 +227,14 @@ func (u *ImageService) ImagePull(req dto.ImagePull) (string, error) { defer file.Close() out, err := client.ImagePull(context.TODO(), image, options) if err != nil { + _, _ = file.WriteString("image pull failed!") global.LOG.Errorf("image %s pull failed, err: %v", image, err) return } defer out.Close() global.LOG.Infof("pull image %s successful!", req.ImageName) _, _ = io.Copy(file, out) + _, _ = file.WriteString("image pull successful!") }() return pathItem, nil } @@ -314,6 +317,8 @@ func (u *ImageService) ImagePush(req dto.ImagePush) (string, error) { return "", err } } + + dockerLogDir := global.CONF.System.TmpDir + "/docker_logs" if _, err := os.Stat(dockerLogDir); err != nil && os.IsNotExist(err) { if err = os.MkdirAll(dockerLogDir, os.ModePerm); err != nil { return "", err @@ -330,11 +335,13 @@ func (u *ImageService) ImagePush(req dto.ImagePush) (string, error) { out, err := client.ImagePush(context.TODO(), newName, options) if err != nil { global.LOG.Errorf("image %s push failed, err: %v", req.TagName, err) + _, _ = file.WriteString("image push failed!") return } defer out.Close() global.LOG.Infof("push image %s successful!", req.Name) _, _ = io.Copy(file, out) + _, _ = file.WriteString("image push successful!") }() return pathItem, nil diff --git a/backend/app/service/image_repo.go b/backend/app/service/image_repo.go index 74c4b443b..7d6544c9a 100644 --- a/backend/app/service/image_repo.go +++ b/backend/app/service/image_repo.go @@ -11,6 +11,7 @@ import ( "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/constant" + "github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/1Panel-dev/1Panel/backend/utils/common" "github.com/jinzhu/copier" "github.com/pkg/errors" @@ -65,18 +66,16 @@ func (u *ImageRepoService) Create(req dto.ImageRepoCreate) error { } if req.Protocol == "http" { _ = u.handleRegistries(req.DownloadUrl, "", "create") + stdout, err := cmd.Exec("systemctl restart docker") + if err != nil { + return errors.New(string(stdout)) + } } if err := copier.Copy(&imageRepo, &req); err != nil { return errors.WithMessage(constant.ErrStructTransform, err.Error()) } - cmd := exec.Command("systemctl", "restart", "docker") - stdout, err := cmd.CombinedOutput() - if err != nil { - return errors.New(string(stdout)) - } - imageRepo.Status = constant.StatusSuccess if err := u.checkConn(req.DownloadUrl, req.Username, req.Password); err != nil { imageRepo.Status = constant.StatusFailed diff --git a/backend/app/service/upgrade.go b/backend/app/service/upgrade.go index 7dc30e9db..5dd4211c5 100644 --- a/backend/app/service/upgrade.go +++ b/backend/app/service/upgrade.go @@ -14,7 +14,6 @@ import ( "gitee.com/openeuler/go-gitee/gitee" "github.com/1Panel-dev/1Panel/backend/app/dto" - "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/1Panel-dev/1Panel/backend/utils/files" @@ -71,8 +70,8 @@ func (u *UpgradeService) Upgrade(req dto.Upgrade) error { global.LOG.Info("start to upgrade now...") fileOp := files.NewFileOp() timeStr := time.Now().Format("20060102150405") - rootDir := fmt.Sprintf("%s/upgrade_%s/downloads", constant.TmpDir, timeStr) - originalDir := fmt.Sprintf("%s/upgrade_%s/original", constant.TmpDir, timeStr) + rootDir := fmt.Sprintf("%s/upgrade_%s/downloads", global.CONF.System.TmpDir, timeStr) + originalDir := fmt.Sprintf("%s/upgrade_%s/original", global.CONF.System.TmpDir, timeStr) if err := os.MkdirAll(rootDir, os.ModePerm); err != nil { return err } diff --git a/backend/app/service/website_utils.go b/backend/app/service/website_utils.go index b3ca2bb3b..9040d48d7 100644 --- a/backend/app/service/website_utils.go +++ b/backend/app/service/website_utils.go @@ -4,7 +4,6 @@ import ( "bufio" "encoding/json" "fmt" - "github.com/1Panel-dev/1Panel/backend/app/dto/request" "os" "os/exec" "path" @@ -12,6 +11,8 @@ import ( "strings" "time" + "github.com/1Panel-dev/1Panel/backend/app/dto/request" + "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/app/model" "github.com/1Panel-dev/1Panel/backend/constant" @@ -459,7 +460,7 @@ func handleWebsiteBackup(backupType, baseDir, backupDir, domain, backupName stri FileDir: backupDir, FileName: fmt.Sprintf("%s.tar.gz", backupName), } - if baseDir != constant.TmpDir || backupType == "LOCAL" { + if baseDir != global.CONF.System.TmpDir || backupType == "LOCAL" { record.Source = "LOCAL" record.FileDir = fmt.Sprintf("%s/%s", baseDir, backupDir) } diff --git a/backend/configs/system.go b/backend/configs/system.go index 2780e1b9e..aa90b62c2 100644 --- a/backend/configs/system.go +++ b/backend/configs/system.go @@ -6,6 +6,7 @@ type System struct { DbPath string `mapstructure:"db_path"` LogPath string `mapstructure:"log_path"` DataDir string `mapstructure:"data_dir"` + TmpDir string `mapstructure:"tmp_dir"` Cache string `mapstructure:"cache"` Backup string `mapstructure:"backup"` AppRepoOwner string `mapstructure:"app_repo_owner"` diff --git a/backend/constant/dir.go b/backend/constant/dir.go index dda5939d6..d9024992e 100644 --- a/backend/constant/dir.go +++ b/backend/constant/dir.go @@ -11,5 +11,4 @@ var ( ResourceDir = path.Join(DataDir, "resource") AppResourceDir = path.Join(ResourceDir, "apps") AppInstallDir = path.Join(DataDir, "apps") - TmpDir = path.Join(DataDir, "tmp") ) diff --git a/backend/init/app/app.go b/backend/init/app/app.go index 25557b34a..d3780f7a7 100644 --- a/backend/init/app/app.go +++ b/backend/init/app/app.go @@ -15,7 +15,6 @@ func Init() { constant.ResourceDir = path.Join(constant.DataDir, "resource") constant.AppResourceDir = path.Join(constant.ResourceDir, "apps") constant.AppInstallDir = path.Join(constant.DataDir, "apps") - constant.TmpDir = path.Join(constant.DataDir, "tmp") dirs := []string{constant.DataDir, constant.ResourceDir, constant.AppResourceDir, constant.AppInstallDir, global.CONF.System.Backup} diff --git a/backend/init/viper/viper.go b/backend/init/viper/viper.go index ccb93b745..d370a3ff2 100644 --- a/backend/init/viper/viper.go +++ b/backend/init/viper/viper.go @@ -3,18 +3,17 @@ package viper import ( "bytes" "fmt" - "github.com/1Panel-dev/1Panel/backend/utils/files" - "gopkg.in/yaml.v3" "path" "strings" - "github.com/1Panel-dev/1Panel/backend/utils/cmd" - "github.com/1Panel-dev/1Panel/backend/configs" "github.com/1Panel-dev/1Panel/backend/global" + "github.com/1Panel-dev/1Panel/backend/utils/cmd" + "github.com/1Panel-dev/1Panel/backend/utils/files" "github.com/1Panel-dev/1Panel/cmd/server/conf" "github.com/fsnotify/fsnotify" "github.com/spf13/viper" + "gopkg.in/yaml.v3" ) func Init() { @@ -73,5 +72,6 @@ func Init() { global.CONF.System.Backup = global.CONF.System.DataDir + "/backup" global.CONF.System.DbPath = global.CONF.System.DataDir + "/db" global.CONF.System.LogPath = global.CONF.System.DataDir + "/log" + global.CONF.System.TmpDir = global.CONF.System.DataDir + "/tmp" global.Viper = v } diff --git a/frontend/src/api/modules/backup.ts b/frontend/src/api/modules/backup.ts new file mode 100644 index 000000000..046f335d0 --- /dev/null +++ b/frontend/src/api/modules/backup.ts @@ -0,0 +1,37 @@ +import http from '@/api'; +import { Backup } from '../interface/backup'; +import { ResPage } from '../interface'; + +export const getBackupList = () => { + return http.get>(`/backups/search`); +}; + +export const getFilesFromBackup = (type: string) => { + return http.post>(`/backups/search/files`, { type: type }); +}; + +export const addBackup = (params: Backup.BackupOperate) => { + return http.post(`/backups`, params); +}; + +export const editBackup = (params: Backup.BackupOperate) => { + return http.post(`/backups/update`, params); +}; + +export const deleteBackup = (params: { ids: number[] }) => { + return http.post(`/backups/del`, params); +}; + +export const downloadBackupRecord = (params: Backup.RecordDownload) => { + return http.download(`/backups/record/download`, params, { responseType: 'blob' }); +}; +export const deleteBackupRecord = (params: { ids: number[] }) => { + return http.post(`/backups/record/del`, params); +}; +export const searchBackupRecords = (params: Backup.SearchBackupRecord) => { + return http.post>(`/backups/record/search`, params); +}; + +export const listBucket = (params: Backup.ForBucket) => { + return http.post(`/backups/buckets`, params); +}; diff --git a/frontend/src/api/modules/command.ts b/frontend/src/api/modules/command.ts new file mode 100644 index 000000000..8daf10dc1 --- /dev/null +++ b/frontend/src/api/modules/command.ts @@ -0,0 +1,23 @@ +import http from '@/api'; +import { ResPage } from '../interface'; +import { Command } from '../interface/command'; + +export const getCommandList = () => { + return http.get>(`/commands`, {}); +}; + +export const getCommandPage = (params: Command.CommandSearch) => { + return http.post>(`/commands/search`, params); +}; + +export const addCommand = (params: Command.CommandOperate) => { + return http.post(`/commands`, params); +}; + +export const editCommand = (params: Command.CommandOperate) => { + return http.post(`/commands/update`, params); +}; + +export const deleteCommand = (params: { ids: number[] }) => { + return http.post(`/commands/del`, params); +}; diff --git a/frontend/src/hooks/use-delete-data.ts b/frontend/src/hooks/use-delete-data.ts index 647788c1b..83b7ee4c8 100644 --- a/frontend/src/hooks/use-delete-data.ts +++ b/frontend/src/hooks/use-delete-data.ts @@ -49,9 +49,7 @@ export const useDeleteData =

( } }, }) - .then(() => { - console.log('1111'); - }) + .then(() => {}) .catch(() => {}); }); }; diff --git a/frontend/src/utils/docker.ts b/frontend/src/utils/docker.ts new file mode 100644 index 000000000..4bb57676b --- /dev/null +++ b/frontend/src/utils/docker.ts @@ -0,0 +1,19 @@ +import { isJson } from './util'; + +export function formatImageStdout(stdout: string) { + let lines = stdout.split('\r\n'); + for (let i = 0; i < lines.length; i++) { + if (isJson(lines[i])) { + const data = JSON.parse(lines[i]); + if (data.id) { + lines[i] = data.id + ': ' + data.status; + } else { + lines[i] = data.status; + } + if (data.progress) { + lines[i] = lines[i] + data.progress; + } + } + } + return lines.join('\r\n'); +} diff --git a/frontend/src/utils/image.ts b/frontend/src/utils/image.ts deleted file mode 100644 index 64a819d20..000000000 --- a/frontend/src/utils/image.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function getAssetsFile(url: string) { - return new URL(`../assets/apps/${url}`, import.meta.url).href; -} diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.ts index 8f709acd1..3bd081f7d 100644 --- a/frontend/src/utils/util.ts +++ b/frontend/src/utils/util.ts @@ -208,3 +208,13 @@ export function getAge(d1: string): string { } return i18n.global.t('app.less1Minute'); } + +export function isJson(str: string) { + try { + if (typeof JSON.parse(str) === 'object') { + return true; + } + } catch { + return false; + } +} diff --git a/frontend/src/views/container/container/terminal/index.vue b/frontend/src/views/container/container/terminal/index.vue index 5d4ab7e8e..0311a7de0 100644 --- a/frontend/src/views/container/container/terminal/index.vue +++ b/frontend/src/views/container/container/terminal/index.vue @@ -52,6 +52,7 @@ import { Base64 } from 'js-base64'; import 'xterm/css/xterm.css'; import { FitAddon } from 'xterm-addon-fit'; import { Rules } from '@/global/form-rules'; +import { isJson } from '@/utils/util'; const terminalVisiable = ref(false); const terminalOpen = ref(false); @@ -98,16 +99,6 @@ const onWSReceive = (message: any) => { term.write(data.Data); }; -function isJson(str: string) { - try { - if (typeof JSON.parse(str) === 'object') { - return true; - } - } catch { - return false; - } -} - const errorRealTerminal = (ex: any) => { let message = ex.message; if (!message) message = 'disconnected'; diff --git a/frontend/src/views/container/image/build/index.vue b/frontend/src/views/container/image/build/index.vue index 855cd4d41..d8fc7ab13 100644 --- a/frontend/src/views/container/image/build/index.vue +++ b/frontend/src/views/container/image/build/index.vue @@ -75,7 +75,7 @@