mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-18 22:22:59 +08:00
fix: 解决时间同步错误的问题
This commit is contained in:
parent
26eacf81b7
commit
1e46d6359b
@ -92,13 +92,14 @@ func (b *BaseApi) SyncTime(c *gin.Context) {
|
||||
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
|
||||
}
|
||||
|
||||
helper.SuccessWithData(c, ts)
|
||||
helper.SuccessWithData(c, ntime.String())
|
||||
}
|
||||
|
||||
func (b *BaseApi) CleanMonitor(c *gin.Context) {
|
||||
|
@ -4,23 +4,23 @@ type SettingInfo struct {
|
||||
UserName string `json:"userName"`
|
||||
Email string `json:"email"`
|
||||
|
||||
SessionTimeout int `json:"sessionTimeout"`
|
||||
SessionTimeout string `json:"sessionTimeout"`
|
||||
LocalTime string `json:"localTime"`
|
||||
|
||||
PanelName string `json:"panelName"`
|
||||
Theme string `json:"theme"`
|
||||
Language string `json:"language"`
|
||||
|
||||
ServerPort int `json:"serverPort"`
|
||||
ServerPort string `json:"serverPort"`
|
||||
SecurityEntrance string `json:"securityEntrance"`
|
||||
ExpirationDays int `json:"expirationDays"`
|
||||
ExpirationDays string `json:"expirationDays"`
|
||||
ExpirationTime string `json:"expirationTime"`
|
||||
ComplexityVerification string `json:"complexityVerification"`
|
||||
MFAStatus string `json:"mfaStatus"`
|
||||
MFASecret string `json:"mfaSecret"`
|
||||
|
||||
MonitorStatus string `json:"monitorStatus"`
|
||||
MonitorStoreDays int `json:"monitorStoreDays"`
|
||||
MonitorStoreDays string `json:"monitorStoreDays"`
|
||||
|
||||
MessageType string `json:"messageType"`
|
||||
EmailVars string `json:"emailVars"`
|
||||
|
@ -40,12 +40,10 @@ func (u *SettingService) GetSettingInfo() (*dto.SettingInfo, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_ = json.Unmarshal(arr, &info)
|
||||
info.MonitorStoreDays, _ = strconv.Atoi(settingMap["MonitorStoreDays"])
|
||||
info.ServerPort, _ = strconv.Atoi(settingMap["ServerPort"])
|
||||
info.SessionTimeout, _ = strconv.Atoi(settingMap["SessionTimeout"])
|
||||
info.ExpirationDays, _ = strconv.Atoi(settingMap["ExpirationDays"])
|
||||
info.LocalTime = time.Now().Format("2006-01-02 15:04:05")
|
||||
if err := json.Unmarshal(arr, &info); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
info.LocalTime = time.Now().String()
|
||||
return &info, err
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package ntp
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
"runtime"
|
||||
@ -31,29 +30,25 @@ type packet struct {
|
||||
TxTimeFrac uint32
|
||||
}
|
||||
|
||||
func Getremotetime() (*time.Time, error) {
|
||||
var host string
|
||||
flag.StringVar(&host, "e", "ntp1.aliyun.com:123", "NTP host")
|
||||
flag.Parse()
|
||||
|
||||
conn, err := net.Dial("udp", host)
|
||||
func Getremotetime() (time.Time, error) {
|
||||
conn, err := net.Dial("udp", "ntp.aliyun.com:123")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to connect: %v", err)
|
||||
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 nil, fmt.Errorf("failed to set deadline: %v", err)
|
||||
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 nil, fmt.Errorf("failed to set request: %v", err)
|
||||
return time.Time{}, fmt.Errorf("failed to set request: %v", err)
|
||||
}
|
||||
|
||||
rsp := &packet{}
|
||||
if err := binary.Read(conn, binary.BigEndian, rsp); err != nil {
|
||||
return nil, fmt.Errorf("failed to read server response: %v", err)
|
||||
return time.Time{}, fmt.Errorf("failed to read server response: %v", err)
|
||||
}
|
||||
|
||||
secs := float64(rsp.TxTimeSec) - ntpEpochOffset
|
||||
@ -61,7 +56,7 @@ func Getremotetime() (*time.Time, error) {
|
||||
|
||||
showtime := time.Unix(int64(secs), nanos)
|
||||
|
||||
return &showtime, nil
|
||||
return showtime, nil
|
||||
}
|
||||
|
||||
func UpdateSystemDate(dateTime string) error {
|
||||
|
@ -12,10 +12,10 @@ const settingRouter = {
|
||||
children: [
|
||||
{
|
||||
path: '/setting',
|
||||
name: 'Setting',
|
||||
component: () => import('@/views/setting/index.vue'),
|
||||
name: 'Panel',
|
||||
component: () => import('@/views/setting/panel/index.vue'),
|
||||
hidden: true,
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
key: 'Setting',
|
||||
},
|
||||
},
|
||||
@ -46,15 +46,6 @@ const settingRouter = {
|
||||
key: 'Setting',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/setting/panel',
|
||||
name: 'Panel',
|
||||
component: () => import('@/views/setting/panel/index.vue'),
|
||||
hidden: true,
|
||||
meta: {
|
||||
key: 'Setting',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/setting/safe',
|
||||
name: 'Safe',
|
||||
|
Loading…
Reference in New Issue
Block a user