| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "regexp" |
| | | "webserver/extend/code" |
| | | "webserver/extend/config" |
| | | "webserver/extend/sys" |
| | |
| | | // @Failure 500 {string} json "{"code":500, msg:"返回错误信息", success:false}" |
| | | // @Router /data/api-v/sysset/saveDevInfo [POST] |
| | | func (sset SysSetController) SaveDevInfo(c *gin.Context) { |
| | | |
| | | dev_name := c.PostForm("server_name") |
| | | var api dbapi.SysSetApi |
| | | paramBody := make(map[string]interface{}, 0) |
| | |
| | | return |
| | | } |
| | | |
| | | isIP, err := sys.RunNTPDate(ntpServer) |
| | | if !isIP { |
| | | util.ResponseFormat(c, code.RequestParamError, "指定的服务器地址错误") |
| | | isConn := sys.RunNTPDate(ntpServer) |
| | | if !isConn { |
| | | util.ResponseFormat(c, code.RequestParamError, "NTP服务器不可用") |
| | | return |
| | | } |
| | | |
| | | if err == nil { |
| | | util.ResponseFormat(c, code.Success, "") |
| | | } else { |
| | | util.ResponseFormat(c, code.TaskStoped, "") |
| | | } |
| | | |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | |
| | | |
| | | util.ResponseFormat(c, code.Success, "正在重启") |
| | | } |
| | | |
| | | // @Summary 获取定时重启 |
| | | // @Description 获取定时重启任务的配置规则 |
| | | // @Produce json |
| | | // @Tags sysset |
| | | // @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"返回错误信息", success:false}" |
| | | // @Router /data/api-v/sysset/rebootTask [GET] |
| | | func (sset SysSetController) GetRebootTask(c *gin.Context) { |
| | | _, msg := sys.ReadRebootTaskInCrontab() |
| | | util.ResponseFormat(c, code.Success, msg) |
| | | } |
| | | |
| | | // @Summary 设置定时重启 |
| | | // @Description 设置定时重启任务的配置规则 |
| | | // @Produce json |
| | | // @Tags sysset |
| | | // @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"返回错误信息", success:false}" |
| | | // @Router /data/api-v/sysset/rebootTask [POST] |
| | | func (sset SysSetController) SetRebootTask(c *gin.Context) { |
| | | task := c.PostForm("task") |
| | | if len(task) < 1 { |
| | | sys.CleanRebootTask() |
| | | util.ResponseFormat(c, code.Success, "配置成功") |
| | | return |
| | | } |
| | | |
| | | regEx := `^([0-9*]+\s){4}[0-9*]+$` |
| | | if r, _ := regexp.MatchString(regEx, task); !r { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数错误") |
| | | return |
| | | } |
| | | |
| | | if r := sys.UpdateRebootTask(task); !r { |
| | | util.ResponseFormat(c, code.UpdateFail, "配置失败") |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormat(c, code.Success, "配置成功") |
| | | } |