diff --git a/backend/app/service/cronjob_helper.go b/backend/app/service/cronjob_helper.go index 6170b2ecd..38407e784 100644 --- a/backend/app/service/cronjob_helper.go +++ b/backend/app/service/cronjob_helper.go @@ -2,10 +2,8 @@ package service import ( "context" - "crypto/tls" "fmt" "io/ioutil" - "net/http" "os" "os/exec" "strings" @@ -15,6 +13,7 @@ import ( "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/cloud_storage" + "github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/pkg/errors" "github.com/robfig/cron/v3" ) @@ -28,12 +27,14 @@ func (u *CronjobService) HandleJob(cronjob *model.Cronjob) { record.FromLocal = cronjob.KeepLocal switch cronjob.Type { case "shell": - cmd := exec.Command(cronjob.Script) - stdout, errExec := cmd.CombinedOutput() - if errExec != nil { - err = errors.New(string(stdout)) + if len(cronjob.Script) == 0 { + return } - message = stdout + stdout, errExec := cmd.Exec(cronjob.Script) + if errExec != nil { + err = errExec + } + message = []byte(stdout) case "website": record.File, err = u.HandleBackup(cronjob, record.StartTime) case "database": @@ -47,17 +48,11 @@ func (u *CronjobService) HandleJob(cronjob *model.Cronjob) { if len(cronjob.URL) == 0 { return } - tr := &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - } - client := &http.Client{Timeout: 1 * time.Second, Transport: tr} - request, _ := http.NewRequest("GET", cronjob.URL, nil) - response, err := client.Do(request) + stdout, errCurl := cmd.Exec("curl " + cronjob.URL) if err != nil { - cronjobRepo.EndRecords(record, constant.StatusFailed, err.Error(), string(message)) + err = errCurl } - defer response.Body.Close() - message, _ = ioutil.ReadAll(response.Body) + message = []byte(stdout) } if err != nil { cronjobRepo.EndRecords(record, constant.StatusFailed, err.Error(), string(message)) diff --git a/backend/init/viper/viper.go b/backend/init/viper/viper.go index 79d8f85a4..0e73f06d2 100644 --- a/backend/init/viper/viper.go +++ b/backend/init/viper/viper.go @@ -19,6 +19,9 @@ func Init() { panic(err) } baseDir := strings.ReplaceAll(stdout, "\n", "") + if len(baseDir) == 0 { + panic("error `BASE_DIR` find in /usr/bin/1pctl") + } v := viper.NewWithOptions() v.SetConfigType("yaml") reader := bytes.NewReader(conf.AppYaml) diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index e3ca655b7..94706c168 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -499,12 +499,14 @@ export default { disableMsg: 'The cronjob cannot continue to run after it is stopped. Do you want to stop it?', enableMsg: 'The cronjob has been stopped. Enable now?', taskType: 'Task type', + record: 'Records', shell: 'shell', website: 'website', rulesHelper: 'Compression exclusion rules (with; Is a delimiter), for example: \n*.log; *.sql', lastRecrodTime: 'Last execution time', - failedFilter: 'Failed Task Filtering', - all: 'all', + all: 'All', + failedRecord: 'Failed records', + successRecord: 'Successful records', database: 'database', missBackupAccount: 'The backup account could not be found', syncDate: 'Synchronization time ', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index de2d9805a..57fdc8b21 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -523,12 +523,14 @@ export default { disableMsg: '计划任务停止后将无法继续运行,是否停止?', enableMsg: '该计划任务已停止,是否启用?', taskType: '任务类型', + record: '报告', shell: 'Shell 脚本', website: '备份网站', rulesHelper: '压缩排除规则(以 ; 号为分隔符),例如: \n*.log;*.sql', - failedFilter: '失败任务过滤', lastRecrodTime: '上次执行时间', all: '所有', + failedRecord: '失败任务', + successRecord: '成功任务', database: '备份数据库', missBackupAccount: '未能找到备份账号', syncDate: '同步时间 ', diff --git a/frontend/src/views/cronjob/index.vue b/frontend/src/views/cronjob/index.vue index 07675d7a2..815d06e8f 100644 --- a/frontend/src/views/cronjob/index.vue +++ b/frontend/src/views/cronjob/index.vue @@ -8,7 +8,7 @@ }, ]" /> - + - + + + + - + @@ -92,14 +97,14 @@ - + -