| | |
| | | import ( |
| | | "basic.com/dbapi.git" |
| | | "github.com/gin-gonic/gin" |
| | | "time" |
| | | "regexp" |
| | | "webserver/extend/code" |
| | | "webserver/extend/config" |
| | | "webserver/extend/sys" |
| | | "webserver/extend/util" |
| | | ) |
| | | |
| | |
| | | Id string `json:"id"` |
| | | AlarmIp string `json:"alarm_ip,omitempty" example:"192.168.1.182"` |
| | | AlarmPort int `json:"alarm_port,omitempty" example:"22122"` |
| | | AlarmThresholdType int `json:"alarm_threshold_type"`//报警阈值类型设置:1:按最高分,2:按阈值以上 |
| | | AlarmThreshold int `json:"alarm_threshold"`//报警阈值 |
| | | WebPicIp string `json:"web_pic_ip,omitempty" example:""` |
| | | WebPicPort int `json:"web_pic_port,omitempty" example:"22122"` |
| | | EsPicIp string `json:"es_pic_ip,omitempty" example:""` |
| | |
| | | } |
| | | |
| | | type Gb28181ConfigVo struct { |
| | | ID string `json:"ID,omitempty" gorm:"primary_key" ` |
| | | ServerIp string `json:"ServerIp,omitempty" example:"SIP服务器IP" gorm:"column:ServerIp"` |
| | | ServerPort int `json:"ServerPort,omitempty" example:"21231" gorm:"column:ServerPort"` |
| | | ServerId string `json:"ServerId,omitempty" example:"SIP服务器Id" gorm:"column:ServerId"` |
| | | UserAuthId string `json:"UserAuthId,omitempty" example:"SIP用户认证ID" gorm:"column:UserAuthId"` |
| | | Password string `json:"Password,omitempty" example:"密码" gorm:"column:Password"` |
| | | UpdateTime time.Time `json:"-" gorm:"column:UpdateTime"` |
| | | Id string `json:"Id"` |
| | | ServerIp string `json:"ServerIp" example:"国标服务器IP"` |
| | | ServerPort int `json:"ServerPort" example:"服务器端口:8060"` |
| | | PublicId string `json:"PublicId" example:"国标服务器Id"` |
| | | GbServerPort int `json:"GbServerPort" example:"国标服务端口:7060"` |
| | | IsAuth bool `json:"IsAuth" example:"是否开启鉴权:true"` |
| | | Password string `json:"Password" example:"密码"` |
| | | UpdateTime string `json:"UpdateTime"` |
| | | } |
| | | |
| | | // @Summary 存储信息查询 |
| | | // @Description 存储信息查询 |
| | | type SysClockConfigVo struct { |
| | | TimeZone string `json:"timeZone" example:"时区"` |
| | | NTP bool `json:"ntp" example:"NTP校时"` |
| | | NTPServer string `json:"ntpServer" example:"NTP服务器地址"` |
| | | Interval int `json:"interval" example:"自动校时间隔"` |
| | | NewTime string `json:"newTime" example:"手动指定时间"` |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 基础设置查询 |
| | | // @Description 基础设置查询 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags sysset |
| | |
| | | } |
| | | } |
| | | |
| | | // @Summary 存储信息修改 |
| | | // @Description 存储信息修改 |
| | | // @Security ApiKeyAuth |
| | | // @Summary 报警设置修改 |
| | | // @Description 报警设置修改 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags sysset |
| | |
| | | } |
| | | } |
| | | |
| | | // @Summary 存储信息修改 |
| | | // @Description 存储信息修改 |
| | | // @Security ApiKeyAuth |
| | | // @Summary 报警时长修改 |
| | | // @Description 报警时长修改 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags sysset |
| | |
| | | } |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 视频截取时长修改 |
| | | // @Description 视频截取时长信息 |
| | | // @Accept x-www-form-urlencoded |
| | |
| | | } |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 获取分析设备信息 |
| | | // @Description 分析设备信息 |
| | | // @Accept json |
| | |
| | | if !b { // 查询是否存在 |
| | | util.ResponseFormat(c, code.ServiceInsideError,"查询失败") |
| | | }else { |
| | | resData["dev_id"] = sysconf.GetServerId() |
| | | resData["dev_name"] = sysconf.GetServerName() |
| | | resData["server_id"] = sysconf.GetServerId() |
| | | resData["server_name"] = sysconf.GetServerName() |
| | | ipv4, mask, _ := util.GetLocalIP(config.Server.NetworkAdapter) |
| | | gateway, _ := util.GetDefaultRoute(config.Server.NetworkAdapter) |
| | | resData["ip"] = ipv4 |
| | | resData["subMask"] = mask |
| | | resData["gateway"] = gateway |
| | | // 存在 |
| | | util.ResponseFormat(c, code.Success, resData) |
| | | } |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // saveDevInfo dev_id dev_name |
| | | // @Summary 保存视频分析设备信息 |
| | | // @Description 分析设备信息 |
| | |
| | | // @Router /data/api-v/sysset/saveDevInfo [POST] |
| | | func (sset SysSetController) SaveDevInfo(c *gin.Context){ |
| | | |
| | | dev_name := c.Request.FormValue("dev_name") |
| | | dev_name := c.PostForm("server_name") |
| | | var api dbapi.SysSetApi |
| | | paramBody :=make(map[string]interface{},0) |
| | | paramBody["serverName"] = dev_name |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary GB28181设置查询 |
| | | // @Description GB28181设置信息查询 |
| | | // @Accept json |
| | |
| | | } |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary GB28181设置信息修改 |
| | | // @Description GB28181设置修改 |
| | | // @Accept json |
| | |
| | | // @Failure 500 {string} json "{"code":500, msg:"返回错误信息", success:false}" |
| | | // @Router /data/api-v/sysset/gb28181ConfigEdit [POST] |
| | | func (sset SysSetController) Gb28181ConfigEdit(c *gin.Context) { |
| | | var args LocalConfigVo |
| | | var args Gb28181ConfigVo |
| | | err := c.BindJSON(&args) |
| | | if err !=nil { |
| | | util.ResponseFormat(c,code.RequestParamError,"参数有误") |
| | |
| | | util.ResponseFormat(c,code.ComError,"更新失败") |
| | | } |
| | | } |
| | | |
| | | /* |
| | | // @Security ApiKeyAuth |
| | | // @Summary 获取时间配置 |
| | | // @Description 系统时间配置信息 |
| | | // @Accept json |
| | | // @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/clockInfo [GET] |
| | | */ |
| | | func (sset SysSetController) GetClockinfo(c *gin.Context) { |
| | | resData := make(map[string]interface{}, 0) |
| | | resData["time_zone"], resData["local_time"] = sys.TimeZone() |
| | | resData["ntp"], resData["ntp_server"], resData["interval"] = sys.NTPConfig() |
| | | |
| | | util.ResponseFormat(c, code.Success, resData) |
| | | } |
| | | |
| | | /* |
| | | // @Security ApiKeyAuth |
| | | // @Summary 测试同步时间 |
| | | // @Description 测试同步时间服务器是否可用 |
| | | // @Produce json |
| | | // @Tags sysset |
| | | // @Param server query string true "时间服务器ip" |
| | | // @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"返回错误信息", success:false}" |
| | | // @Router /data/api-v/sysset/ntpTest [GET] |
| | | */ |
| | | func (sset SysSetController) TestNTPServer(c *gin.Context) { |
| | | ntpServer := c.Query("server") |
| | | |
| | | if root := sys.CheckRootPermissions(); !root { |
| | | util.ResponseFormat(c, code.ServiceInsideError, "服务器没有修改时间的权限") |
| | | return |
| | | } |
| | | |
| | | isConn := sys.RunNTPDate(ntpServer) |
| | | if !isConn { |
| | | util.ResponseFormat(c, code.RequestParamError, "NTP服务器不可用") |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormat(c, code.Success, "") |
| | | |
| | | } |
| | | |
| | | /* |
| | | // @Security ApiKeyAuth |
| | | // @Summary 设置系统时间 |
| | | // @Description 校正系统时间 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags sysset |
| | | // @Param config body controllers.SysClockConfigVo true "校时信息" |
| | | // @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"返回错误信息", success:false}" |
| | | // @Router /data/api-v/sysset/updateClock [POST] |
| | | */ |
| | | func (sset SysSetController) SetSysClock(c *gin.Context) { |
| | | var args SysClockConfigVo |
| | | err := c.BindJSON(&args) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | |
| | | if args.TimeZone != "CST" && args.TimeZone != "UTC" { |
| | | if r := sys.SetTimeZone(args.TimeZone); !r { |
| | | util.ResponseFormat(c, code.RequestParamError, "时区参数错误") |
| | | return |
| | | } |
| | | } |
| | | |
| | | if !args.NTP { |
| | | if r := sys.SetLocalTime(args.NewTime); !r { |
| | | util.ResponseFormat(c, code.RequestParamError, "指定的时间参数错误") |
| | | return |
| | | } |
| | | } else { |
| | | if r := sys.EnableNTPCron(args.NTPServer, args.Interval); !r { |
| | | util.ResponseFormat(c, code.RequestParamError, "指定的服务器地址错误") |
| | | return |
| | | } |
| | | } |
| | | |
| | | util.ResponseFormat(c, code.UpdateSuccess, "配置成功") |
| | | } |
| | | |
| | | /* |
| | | // @Security ApiKeyAuth |
| | | // @Summary 查询系统运行信息 |
| | | // @Description 获取当前系统的运行状态,CPU, GPU, 内存等 |
| | | // @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/sysinfo [GET] |
| | | */ |
| | | func (sset SysSetController) GetSysInfo(c *gin.Context) { |
| | | info := sys.GetSysInfo() |
| | | util.ResponseFormat(c, code.UpdateSuccess, info) |
| | | } |
| | | |
| | | /* |
| | | // @Security ApiKeyAuth |
| | | // @Summary 查询系统状态阈值设置 |
| | | // @Description 获取当前系统的运行状态,CPU, GPU, 内存的阈值配置 |
| | | // @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/sysThresholds [GET] |
| | | */ |
| | | func (sset SysSetController) GetSysThresholds(c *gin.Context) { |
| | | util.ResponseFormat(c, code.UpdateSuccess, config.Server.SysThresholds) |
| | | } |
| | | |
| | | /* |
| | | // @Security ApiKeyAuth |
| | | // @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/reboot [GET] |
| | | */ |
| | | func (sset SysSetController) RebootOS(c *gin.Context) { |
| | | if isOk, msg := sys.Reboot(); !isOk { |
| | | util.ResponseFormat(c, code.UpdateFail, msg) |
| | | return |
| | | } |
| | | |
| | | 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 设置定时重启任务的配置规则 |
| | | // @Accept x-www-form-urlencoded |
| | | // @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, "配置成功") |
| | | } |