diff --git a/backend/app/api/v1/setting.go b/backend/app/api/v1/setting.go index 5138dadc6..afe4535f9 100644 --- a/backend/app/api/v1/setting.go +++ b/backend/app/api/v1/setting.go @@ -2,13 +2,15 @@ package v1 import ( "errors" + "os/exec" + "runtime" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" "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/mfa" - "github.com/1Panel-dev/1Panel/backend/utils/ntp" + "github.com/beevik/ntp" "github.com/gin-gonic/gin" ) @@ -85,21 +87,22 @@ func (b *BaseApi) HandlePasswordExpired(c *gin.Context) { } func (b *BaseApi) SyncTime(c *gin.Context) { - var timeLayoutStr = "2006-01-02 15:04:05" - - ntime, err := ntp.Getremotetime() + ntime, err := ntp.Time("pool.ntp.org") if err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } - - ts := ntime.Format(timeLayoutStr) - if err := ntp.UpdateSystemDate(ts); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) - return + system := runtime.GOOS + if system == "linux" { + cmd := exec.Command("timedatectl", "set-time", ntime.Format("2006-01-02 15:04:05")) + stdout, err := cmd.CombinedOutput() + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, errors.New(string(stdout))) + return + } } - helper.SuccessWithData(c, ntime.String()) + helper.SuccessWithData(c, ntime.Format("2006-01-02 15:04 MST -0700")) } func (b *BaseApi) CleanMonitor(c *gin.Context) { diff --git a/backend/app/service/setting.go b/backend/app/service/setting.go index 8693216bc..a12e5ceba 100644 --- a/backend/app/service/setting.go +++ b/backend/app/service/setting.go @@ -43,7 +43,7 @@ func (u *SettingService) GetSettingInfo() (*dto.SettingInfo, error) { if err := json.Unmarshal(arr, &info); err != nil { return nil, err } - info.LocalTime = time.Now().String() + info.LocalTime = time.Now().Format("2006-01-02 15:04 MST -0700") return &info, err } diff --git a/backend/utils/ntp/ntp.go b/backend/utils/ntp/ntp.go deleted file mode 100644 index 7c7facc90..000000000 --- a/backend/utils/ntp/ntp.go +++ /dev/null @@ -1,71 +0,0 @@ -package ntp - -import ( - "encoding/binary" - "fmt" - "net" - "runtime" - "time" - - "github.com/gogf/gf/os/gproc" -) - -const ntpEpochOffset = 2208988800 - -type packet struct { - Settings uint8 - Stratum uint8 - Poll int8 - Precision int8 - RootDelay uint32 - RootDispersion uint32 - ReferenceID uint32 - RefTimeSec uint32 - RefTimeFrac uint32 - OrigTimeSec uint32 - OrigTimeFrac uint32 - RxTimeSec uint32 - RxTimeFrac uint32 - TxTimeSec uint32 - TxTimeFrac uint32 -} - -func Getremotetime() (time.Time, error) { - conn, err := net.Dial("udp", "ntp.aliyun.com:123") - if err != nil { - return time.Time{}, fmt.Errorf("failed to connect: %v", err) - } - defer conn.Close() - if err := conn.SetDeadline(time.Now().Add(15 * time.Second)); err != nil { - return time.Time{}, fmt.Errorf("failed to set deadline: %v", err) - } - - req := &packet{Settings: 0x1B} - - if err := binary.Write(conn, binary.BigEndian, req); err != nil { - return time.Time{}, fmt.Errorf("failed to set request: %v", err) - } - - rsp := &packet{} - if err := binary.Read(conn, binary.BigEndian, rsp); err != nil { - return time.Time{}, fmt.Errorf("failed to read server response: %v", err) - } - - secs := float64(rsp.TxTimeSec) - ntpEpochOffset - nanos := (int64(rsp.TxTimeFrac) * 1e9) >> 32 - - showtime := time.Unix(int64(secs), nanos) - - return showtime, nil -} - -func UpdateSystemDate(dateTime string) error { - system := runtime.GOOS - if system == "linux" { - if _, err := gproc.ShellExec(`date -s "` + dateTime + `"`); err != nil { - return fmt.Errorf("update system date failed, err: %v", err) - } - return nil - } - return fmt.Errorf("The current system architecture does not support synchronization") -} diff --git a/frontend/index.html b/frontend/index.html index d98a0ff6e..63e019d81 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -4,7 +4,7 @@ - <%- title %> + -
diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index 3da24343b..018999351 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -43,7 +43,6 @@ class RequestHttp { globalStore.setCsrfToken(response.headers['x-csrf-token']); } if (data.code == ResultEnum.OVERDUE || data.code == ResultEnum.FORBIDDEN) { - ElMessage.error(data.message); router.replace({ path: '/login', }); diff --git a/frontend/src/components/app-layout/index.vue b/frontend/src/components/app-layout/index.vue index c4f5d643d..70084aa1e 100644 --- a/frontend/src/components/app-layout/index.vue +++ b/frontend/src/components/app-layout/index.vue @@ -25,6 +25,7 @@ const { switchDark } = useTheme(); const loadDataFromDB = async () => { const res = await getSettingInfo(); + document.title = res.data.panelName; i18n.locale.value = res.data.language; i18n.warnHtmlMessage = false; globalStore.updateLanguage(res.data.language); diff --git a/frontend/src/views/cronjob/index.vue b/frontend/src/views/cronjob/index.vue index a0c3a8ff2..87cf4bec3 100644 --- a/frontend/src/views/cronjob/index.vue +++ b/frontend/src/views/cronjob/index.vue @@ -45,8 +45,11 @@ {{ loadWeek(row.week) }} {{ loadZero(row.hour) }} : {{ loadZero(row.minute) }} + + {{ loadZero(row.hour) }} : {{ loadZero(row.minute) }} + - {{ row.day }}{{ $t('cronjob.day1') }}, {{ loadZero(row.hour) }} : {{ loadZero(row.minute) }} + {{ row.day }} {{ $t('cronjob.day1') }}, {{ loadZero(row.hour) }} : {{ loadZero(row.minute) }} {{ row.hour }}{{ $t('cronjob.hour') }}, {{ loadZero(row.minute) }} diff --git a/frontend/src/views/host/terminal/host/index.vue b/frontend/src/views/host/terminal/host/index.vue index 21e50e387..cebbadf48 100644 --- a/frontend/src/views/host/terminal/host/index.vue +++ b/frontend/src/views/host/terminal/host/index.vue @@ -31,7 +31,7 @@ @@ -46,15 +46,17 @@ > @@ -120,10 +122,9 @@ - {{ $t('commons.button.create') }} + {{ $t('commons.button.save') }} >(); -let groupInputValue = ref(); -let currentGroupID = ref(); +const groupInputValue = ref(); +const currentGroup = ref(); +const currentGroupID = ref(); +const currentGroupValue = ref(); + let groupOperation = ref('create'); let groupInputShow = ref(false); @@ -255,15 +259,12 @@ const onGroupCreate = () => { groupInputValue.value = ''; groupOperation.value = 'create'; }; -const onCreateGroup = async () => { +const onCreateGroup = async (name: string) => { if (groupOperation.value === 'create') { - let group = { id: 0, name: groupInputValue.value, type: 'host' }; + let group = { id: 0, name: name, type: 'host' }; await addGroup(group); groupOperation.value = ''; groupInputShow.value = false; - } else { - let group = { id: currentGroupID.value, name: groupInputValue.value, type: 'host' }; - await editGroup(group); } ElMessage.success(i18n.global.t('commons.msg.operationSuccess')); groupOperation.value = ''; @@ -272,6 +273,18 @@ const onCreateGroup = async () => { loadGroups(); }; +const onUpdateGroup = async () => { + if (currentGroup.value === currentGroupValue.value) { + currentGroup.value = ''; + return; + } + let group = { id: currentGroupID.value, name: currentGroupValue.value, type: 'host' }; + await editGroup(group); + ElMessage.success(i18n.global.t('commons.msg.operationSuccess')); + loadHostTree(); + loadGroups(); +}; + const onDelete = async (node: Node, data: Tree) => { if (node.level === 1 && data.label === 'default') { return; @@ -291,8 +304,8 @@ const onEdit = async (node: Node, data: Tree) => { return; } if (node.level === 1) { - groupInputShow.value = true; - groupInputValue.value = data.label; + currentGroup.value = data.label; + currentGroupValue.value = data.label; currentGroupID.value = data.id - 10000; groupOperation.value = 'edit'; return; diff --git a/frontend/src/views/host/terminal/index.vue b/frontend/src/views/host/terminal/index.vue index b0c2d775d..dad18be61 100644 --- a/frontend/src/views/host/terminal/index.vue +++ b/frontend/src/views/host/terminal/index.vue @@ -34,15 +34,21 @@ - - - +  {{ item.title }}   @@ -362,6 +368,14 @@ const onConn = (node: Node, data: Tree) => { terminalValue.value = `${addr}-${tabIndex}`; }; +const onReconnect = async (item: any) => { + if (ctx) { + ctx.refs[`Ref${item.key}`] && ctx.refs[`Ref${item.key}`][0].onClose(); + } + item.Refresh = !item.Refresh; + ctx.refs[`Ref${item.key}`]; +}; + const submitAddHost = (formEl: FormInstance | undefined, ops: string) => { if (!formEl) return; formEl.validate(async (valid) => { diff --git a/frontend/src/views/login/components/login-form.vue b/frontend/src/views/login/components/login-form.vue index 437200d01..516fb940f 100644 --- a/frontend/src/views/login/components/login-form.vue +++ b/frontend/src/views/login/components/login-form.vue @@ -3,7 +3,7 @@