feat: add api for system clock update
| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "basic.com/dbapi.git" |
| | | "github.com/gin-gonic/gin" |
| | | "webserver/extend/code" |
| | | "webserver/extend/config" |
| | | "webserver/extend/sys" |
| | | "webserver/extend/util" |
| | | |
| | | "basic.com/dbapi.git" |
| | | "github.com/gin-gonic/gin" |
| | | ) |
| | | |
| | | type SysSetController struct { |
| | | |
| | | } |
| | | |
| | | type LocalConfigVo struct { |
| | | 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:""` |
| | | EsPicPort int `json:"es_pic_port,omitempty" example:"22122"` |
| | | CutMaxDuration int `json:"cut_max_duration,omitempty" example:"20"` |
| | | CutMinDuration int `json:"cut_min_duration,omitempty" example:"5"` |
| | | ServerId string `json:"server_id,omitempty" example:"分析设备id"` |
| | | ServerName string `json:"server_name,omitempty" example:"分析设备名称"` |
| | | ServerType int `json:"server_type,omitempty" example:"1"` |
| | | Reserved string `json:"reserved,omitempty" example:"1"` |
| | | RealMax int `json:"real_max"`//实时处理的最大路数 |
| | | 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:""` |
| | | EsPicPort int `json:"es_pic_port,omitempty" example:"22122"` |
| | | CutMaxDuration int `json:"cut_max_duration,omitempty" example:"20"` |
| | | CutMinDuration int `json:"cut_min_duration,omitempty" example:"5"` |
| | | ServerId string `json:"server_id,omitempty" example:"分析设备id"` |
| | | ServerName string `json:"server_name,omitempty" example:"分析设备名称"` |
| | | ServerType int `json:"server_type,omitempty" example:"1"` |
| | | Reserved string `json:"reserved,omitempty" example:"1"` |
| | | RealMax int `json:"real_max"` //实时处理的最大路数 |
| | | } |
| | | |
| | | type Gb28181ConfigVo struct { |
| | | Id string `json:"Id"` |
| | | ServerIp string `json:"ServerIp" example:"国标服务器IP"` |
| | | ServerPort int `json:"ServerPort" example:"平台服务端口:7060"` |
| | | PublicId string `json:"PublicId" example:"平台服务Id"` |
| | | GbServerPort int `json:"GbServerPort" example:"国标服务端口:8060"` |
| | | IsAuth bool `json:"IsAuth" example:"是否开启鉴权:true"` |
| | | Password string `json:"Password" example:"密码"` |
| | | UpdateTime string `json:"UpdateTime"` |
| | | Id string `json:"Id"` |
| | | ServerIp string `json:"ServerIp" example:"国标服务器IP"` |
| | | ServerPort int `json:"ServerPort" example:"平台服务端口:7060"` |
| | | PublicId string `json:"PublicId" example:"平台服务Id"` |
| | | GbServerPort int `json:"GbServerPort" example:"国标服务端口:8060"` |
| | | IsAuth bool `json:"IsAuth" example:"是否开启鉴权:true"` |
| | | Password string `json:"Password" example:"密码"` |
| | | UpdateTime string `json:"UpdateTime"` |
| | | } |
| | | |
| | | 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:"手动指定时间"` |
| | | } |
| | | |
| | | // @Summary 存储信息查询 |
| | |
| | | // @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"返回错误信息", success:false}" |
| | | // @Router /data/api-v/sysset/alarmServerShow [GET] |
| | | func (sset SysSetController) AlarmServerShow(c *gin.Context){ |
| | | func (sset SysSetController) AlarmServerShow(c *gin.Context) { |
| | | var api dbapi.SysSetApi |
| | | b, sysconf := api.GetServerInfo() |
| | | if b{ |
| | | util.ResponseFormat(c,code.Success,sysconf) |
| | | if b { |
| | | util.ResponseFormat(c, code.Success, sysconf) |
| | | } else { |
| | | util.ResponseFormat(c,code.ComError,"查询失败") |
| | | util.ResponseFormat(c, code.ComError, "查询失败") |
| | | } |
| | | } |
| | | |
| | |
| | | func (sset SysSetController) AlarmEdit(c *gin.Context) { |
| | | var args LocalConfigVo |
| | | err := c.BindJSON(&args) |
| | | if err !=nil { |
| | | util.ResponseFormat(c,code.RequestParamError,"参数有误") |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | var api dbapi.SysSetApi |
| | | paramBody := util.Struct2Map(args) |
| | | b,data := api.AlarmEdit(paramBody) |
| | | b, data := api.AlarmEdit(paramBody) |
| | | if b { |
| | | util.ResponseFormat(c,code.Success,data) |
| | | }else { |
| | | util.ResponseFormat(c,code.ComError,"保存失败") |
| | | util.ResponseFormat(c, code.Success, data) |
| | | } else { |
| | | util.ResponseFormat(c, code.ComError, "保存失败") |
| | | } |
| | | } |
| | | |
| | |
| | | // @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"返回错误信息", success:false}" |
| | | // @Router /data/api-v/sysset/videoLenShow [GET] |
| | | func (sset SysSetController) VideoLenShow(c *gin.Context){ |
| | | func (sset SysSetController) VideoLenShow(c *gin.Context) { |
| | | var api dbapi.SysSetApi |
| | | b, sysconf := api.GetServerInfo() |
| | | if b { |
| | |
| | | // 存在则修改 |
| | | util.ResponseFormat(c, code.Success, resData) |
| | | } else { |
| | | util.ResponseFormat(c,code.ComError,"查询失败") |
| | | util.ResponseFormat(c, code.ComError, "查询失败") |
| | | } |
| | | } |
| | | |
| | |
| | | max_video_len := c.Request.FormValue("max_video_len") |
| | | min_video_len := c.Request.FormValue("min_video_len") |
| | | var api dbapi.SysSetApi |
| | | b,data := api.VideoLenEdit(max_video_len,min_video_len) |
| | | if b{ |
| | | util.ResponseFormat(c,code.UpdateSuccess,data) |
| | | b, data := api.VideoLenEdit(max_video_len, min_video_len) |
| | | if b { |
| | | util.ResponseFormat(c, code.UpdateSuccess, data) |
| | | } else { |
| | | util.ResponseFormat(c,code.ComError,"保存失败") |
| | | util.ResponseFormat(c, code.ComError, "保存失败") |
| | | } |
| | | } |
| | | |
| | |
| | | b, sysconf := api.GetServerInfo() |
| | | resData := make(map[string]string, 0) |
| | | if !b { // 查询是否存在 |
| | | util.ResponseFormat(c, code.ServiceInsideError,"查询失败") |
| | | }else { |
| | | util.ResponseFormat(c, code.ServiceInsideError, "查询失败") |
| | | } else { |
| | | resData["server_id"] = sysconf.GetServerId() |
| | | resData["server_name"] = sysconf.GetServerName() |
| | | ipv4, mask, _ := util.GetLocalIP(config.Server.NetworkAdapter) |
| | |
| | | // @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"返回错误信息", success:false}" |
| | | // @Router /data/api-v/sysset/saveDevInfo [POST] |
| | | func (sset SysSetController) SaveDevInfo(c *gin.Context){ |
| | | func (sset SysSetController) SaveDevInfo(c *gin.Context) { |
| | | |
| | | dev_name := c.PostForm("server_name") |
| | | var api dbapi.SysSetApi |
| | | paramBody :=make(map[string]interface{},0) |
| | | paramBody := make(map[string]interface{}, 0) |
| | | paramBody["serverName"] = dev_name |
| | | b,data := api.SaveServerInfo(paramBody) |
| | | b, data := api.SaveServerInfo(paramBody) |
| | | if b { // 查询是否存在 |
| | | util.ResponseFormat(c,code.Success,data) |
| | | } else { // 存在及修改 不存在 即添加 |
| | | util.ResponseFormat(c,code.ComError,"保存失败") |
| | | util.ResponseFormat(c, code.Success, data) |
| | | } else { // 存在及修改 不存在 即添加 |
| | | util.ResponseFormat(c, code.ComError, "保存失败") |
| | | } |
| | | } |
| | | |
| | | |
| | | // @Summary GB28181设置查询 |
| | | // @Description GB28181设置信息查询 |
| | |
| | | var api dbapi.SysSetApi |
| | | b, data := api.Gb28181ConfigShow() |
| | | if b { |
| | | util.ResponseFormat(c,code.Success,data) |
| | | util.ResponseFormat(c, code.Success, data) |
| | | } else { |
| | | util.ResponseFormat(c,code.ComError,"查询失败") |
| | | util.ResponseFormat(c, code.ComError, "查询失败") |
| | | } |
| | | } |
| | | |
| | |
| | | func (sset SysSetController) Gb28181ConfigEdit(c *gin.Context) { |
| | | var args Gb28181ConfigVo |
| | | err := c.BindJSON(&args) |
| | | if err !=nil { |
| | | util.ResponseFormat(c,code.RequestParamError,"参数有误") |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | var api dbapi.SysSetApi |
| | | paramBody := util.Struct2Map(args) |
| | | b, data := api.Gb28181ConfigEdit(paramBody) |
| | | if b { |
| | | util.ResponseFormat(c,code.UpdateSuccess,data) |
| | | util.ResponseFormat(c, code.UpdateSuccess, data) |
| | | } else { |
| | | util.ResponseFormat(c,code.ComError,"更新失败") |
| | | util.ResponseFormat(c, code.ComError, "更新失败") |
| | | } |
| | | } |
| | | |
| | | // @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) |
| | | } |
| | | |
| | | // @Summary 测试同步时间 |
| | | // @Description 测试同步时间服务器是否可用 |
| | | // @Accept json |
| | | // @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 |
| | | } |
| | | |
| | | isIP, err := sys.RunNTPDate(ntpServer) |
| | | if !isIP { |
| | | util.ResponseFormat(c, code.RequestParamError, "指定的服务器地址错误") |
| | | return |
| | | } |
| | | |
| | | if err == nil { |
| | | util.ResponseFormat(c, code.Success, "") |
| | | } else { |
| | | util.ResponseFormat(c, code.TaskStoped, "") |
| | | } |
| | | } |
| | | |
| | | // @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 root := sys.CheckRootPermissions(); !root { |
| | | util.ResponseFormat(c, code.ServiceInsideError, "服务器没有修改时间的权限") |
| | | 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, "配置成功") |
| | | } |
New file |
| | |
| | | package sys |
| | | |
| | | import ( |
| | | "errors" |
| | | "os/exec" |
| | | |
| | | "fmt" |
| | | "net" |
| | | "strings" |
| | | "time" |
| | | ) |
| | | |
| | | // 检查 root权限 |
| | | func CheckRootPermissions() bool { |
| | | showRootCMD := exec.Command("/bin/sh", "-c", "ls /root/") |
| | | if _, err := showRootCMD.Output(); err != nil { |
| | | return false |
| | | } |
| | | |
| | | return true |
| | | } |
| | | |
| | | // 配置时区 |
| | | func TimeZone() (string, int64) { |
| | | cmd := exec.Command("/bin/sh", "-c", "echo -n $TZ") |
| | | tz, _ := cmd.Output() |
| | | if tzstr := string(tz); tzstr != "" { |
| | | return tzstr, time.Now().Unix() |
| | | } |
| | | |
| | | zone, _ := time.Now().Zone() |
| | | return zone, time.Now().Unix() |
| | | } |
| | | |
| | | func NTPConfig() (bool, string, string) { |
| | | status, server, interval := false, "", "" |
| | | |
| | | cmd := exec.Command("/bin/sh", "-c", "crontab -l | grep ntpdate | tr -d '\n'") |
| | | cron, _ := cmd.Output() |
| | | if task := string(cron); task != "" { |
| | | status = true |
| | | slice := strings.Split(task, " ") |
| | | interval, server = slice[0][2:], slice[len(slice)-1] |
| | | } |
| | | |
| | | return status, server, interval |
| | | } |
| | | |
| | | // 设置时区 |
| | | func SetTimeZone(tz string) bool { |
| | | if _, err := time.LoadLocation(tz); err != nil { |
| | | return false |
| | | } |
| | | |
| | | // set env |
| | | envCMD := exec.Command("/bin/sh", "-c", "TZ=%s", tz) |
| | | envCMD.Run() |
| | | // change permanent to the file '.profile' |
| | | |
| | | cleanTZ := exec.Command("/bin/sh", "-c", "sed -i '/^TZ=.*$/d' ~/.profile") |
| | | cleanTZ.Run() |
| | | |
| | | TZ := "TZ='" + tz + "'; export TZ" |
| | | appendTZCMD := fmt.Sprintf("echo \"%s\" >> ~/.profile;", TZ) |
| | | appendTZ := exec.Command("/bin/sh", "-c", appendTZCMD) |
| | | appendTZ.Run() |
| | | |
| | | return true |
| | | } |
| | | |
| | | // 配置系统时间 |
| | | func SetLocalTime(newTime string) bool { |
| | | const TimeLayout = "2006-01-02 15:04:05" |
| | | _, err := time.Parse(TimeLayout, newTime) |
| | | if err != nil { |
| | | return false |
| | | } |
| | | |
| | | args := []string{"-s", newTime} |
| | | exec.Command("date", args...).Run() |
| | | stopNTPCron() |
| | | |
| | | return true |
| | | } |
| | | |
| | | const NTPCRONTABFILE = "~/.webServer.crontab" |
| | | |
| | | func EnableNTPCron(server string, interval int) bool { |
| | | stopNTPCron() |
| | | |
| | | if ip := net.ParseIP(server); ip == nil { |
| | | return false |
| | | } |
| | | |
| | | addTask := fmt.Sprintf("echo \"*/%d * * * * /usr/sbin/ntpdate %s\" >> %s; crontab %s", interval, server, NTPCRONTABFILE, NTPCRONTABFILE) |
| | | exec.Command("/bin/sh", "-c", addTask).Run() |
| | | |
| | | return true |
| | | } |
| | | |
| | | func stopNTPCron() { |
| | | cleanTask := fmt.Sprintf("crontab -l | grep -v /usr/sbin/ntpdate > %s; crontab %s", NTPCRONTABFILE, NTPCRONTABFILE) |
| | | exec.Command("/bin/sh", "-c", cleanTask).Run() |
| | | } |
| | | |
| | | func RunNTPDate(server string) (bool, error) { |
| | | if ip := net.ParseIP(server); ip == nil { |
| | | return false, errors.New("参数错误") |
| | | } |
| | | |
| | | ntpdate := fmt.Sprintf("/usr/sbin/ntpdate %s", server) |
| | | return true, exec.Command("/bin/sh", "-c", ntpdate).Run() |
| | | } |
| | |
| | | package util |
| | | |
| | | import ( |
| | | "basic.com/pubsub/protomsg.git" |
| | | "bytes" |
| | | "encoding/json" |
| | | "errors" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/golang/glog" |
| | | "github.com/pierrec/lz4" |
| | | "gocv.io/x/gocv" |
| | | "image" |
| | | "io/ioutil" |
| | | "net" |
| | |
| | | "os/exec" |
| | | "strconv" |
| | | "webserver/extend/code" |
| | | |
| | | "basic.com/pubsub/protomsg.git" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/golang/glog" |
| | | "github.com/pierrec/lz4" |
| | | "gocv.io/x/gocv" |
| | | |
| | | "crypto/rand" |
| | | "fmt" |
| | |
| | | |
| | | //struct转map |
| | | func Struct2Map(obj interface{}) map[string]interface{} { |
| | | resultMap :=make(map[string]interface{},0) |
| | | resultMap := make(map[string]interface{}, 0) |
| | | bytesData, err := json.Marshal(obj) |
| | | if err !=nil { |
| | | if err != nil { |
| | | return resultMap |
| | | } |
| | | json.Unmarshal(bytesData, &resultMap) |
| | | return resultMap |
| | | |
| | | |
| | | // |
| | | //t := reflect.TypeOf(obj) |
| | | //v := reflect.ValueOf(obj) |
| | |
| | | //return data |
| | | } |
| | | |
| | | func ReadImgData(url string) ([]byte,error) { |
| | | resp,err := http.Get(url) |
| | | if err !=nil { |
| | | return nil,err |
| | | func ReadImgData(url string) ([]byte, error) { |
| | | resp, err := http.Get(url) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | defer resp.Body.Close() |
| | | pix,err := ioutil.ReadAll(resp.Body) |
| | | if err !=nil { |
| | | return nil,err |
| | | pix, err := ioutil.ReadAll(resp.Body) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | return pix,nil |
| | | return pix, nil |
| | | } |
| | | |
| | | // 按尺寸去切图 |
| | | func SubImg(i protomsg.Image, x0, y0, x1, y1 int, ) []byte { |
| | | func SubImg(i protomsg.Image, x0, y0, x1, y1 int) []byte { |
| | | img, _ := gocv.NewMatFromBytes(int(i.Height), int(i.Width), gocv.MatTypeCV8UC3, i.Data) |
| | | rect := image.Rect(EnlargeSize(x0, y0, x1, y1, i)) |
| | | region := img.Region(rect) |
| | |
| | | return |
| | | } |
| | | |
| | | |
| | | // 获取本机网卡IP |
| | | func GetLocalIP(networkName string) (ipv4 string,mask string, err error) { |
| | | func GetLocalIP(networkName string) (ipv4 string, mask string, err error) { |
| | | interfaces, err := net.Interfaces() |
| | | if err != nil { |
| | | return "","", err |
| | | return "", "", err |
| | | } |
| | | |
| | | for _, i := range interfaces { |
| | | byName, err := net.InterfaceByName(i.Name) |
| | | if err != nil { |
| | | return "","", err |
| | | return "", "", err |
| | | } |
| | | addresses, err := byName.Addrs() |
| | | for _, v := range addresses { |
| | | if ipnet, ok:=v.(*net.IPNet);ok && !ipnet.IP.IsLoopback(){ |
| | | if ipnet.IP.To4() !=nil{ |
| | | if byName.Name == networkName{ |
| | | if ipnet, ok := v.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { |
| | | if ipnet.IP.To4() != nil { |
| | | if byName.Name == networkName { |
| | | maskStr := ipnet.Mask.String() |
| | | mask64, _ := strconv.ParseUint(maskStr, 16, 32) |
| | | return ipnet.IP.String(),IpIntToString(int(mask64)),nil |
| | | return ipnet.IP.String(), IpIntToString(int(mask64)), nil |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return "","", errors.New("ipv4 not found") |
| | | return "", "", errors.New("ipv4 not found") |
| | | } |
| | | |
| | | func GetDefaultRoute(networkName string)(route string,err error){ |
| | | cmdStr := fmt.Sprintf("route | grep -P \"^default.*%s$\" | awk '{print $2}'",networkName) |
| | | cmd := exec.Command("/bin/sh","-c",cmdStr) |
| | | func GetDefaultRoute(networkName string) (route string, err error) { |
| | | cmdStr := fmt.Sprintf("ip route show | grep -P \"^default.*%s\" | awk '{print $3}'", networkName) |
| | | cmd := exec.Command("/bin/sh", "-c", cmdStr) |
| | | b, err := cmd.Output() |
| | | if err!=nil{ |
| | | return "",err |
| | | if err != nil { |
| | | return "", err |
| | | } |
| | | return string(b),nil |
| | | |
| | | return string(b), nil |
| | | } |
| | | |
| | | func StringIpToInt(ipstring string) int { |
| | |
| | | return ipInt |
| | | } |
| | | |
| | | func IpIntToString(ipInt int) string{ |
| | | func IpIntToString(ipInt int) string { |
| | | ipSegs := make([]string, 4) |
| | | var len int = len(ipSegs) |
| | | buffer := bytes.NewBufferString("") |
| | |
| | | package router |
| | | |
| | | import ( |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/swaggo/gin-swagger" |
| | | "github.com/swaggo/gin-swagger/swaggerFiles" |
| | | "github.com/szuecs/gin-glog" |
| | | "time" |
| | | "webserver/controllers" |
| | | "webserver/middlewares/auth" |
| | | |
| | | "github.com/gin-gonic/gin" |
| | | ginSwagger "github.com/swaggo/gin-swagger" |
| | | "github.com/swaggo/gin-swagger/swaggerFiles" |
| | | ginglog "github.com/szuecs/gin-glog" |
| | | |
| | | _ "webserver/docs" |
| | | ) |
| | |
| | | r := gin.Default() |
| | | r.Use(ginglog.Logger(3 * time.Second)) |
| | | |
| | | r.Use(auth.AuthHandler())//auth过滤器 |
| | | r.Use(auth.AuthHandler()) //auth过滤器 |
| | | |
| | | r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) |
| | | |
| | |
| | | eventPushController := new(controllers.EventPushController) |
| | | pollConfigController := new(controllers.PollConfigController) |
| | | fileController := new(controllers.FileController) |
| | | sysMenuController :=new(controllers.SysMenuController) |
| | | clusterController :=new(controllers.ClusterController) |
| | | sysRoleController :=new(controllers.RoleController) |
| | | sysMenuController := new(controllers.SysMenuController) |
| | | clusterController := new(controllers.ClusterController) |
| | | sysRoleController := new(controllers.RoleController) |
| | | |
| | | |
| | | sysApi := r.Group( "/data/api-u/sys") |
| | | sysApi := r.Group("/data/api-u/sys") |
| | | { |
| | | sysApi.POST("/login",userController.Login) |
| | | sysApi.GET("/logout",userController.Logout) |
| | | sysApi.POST("refresh_token",userController.RefreshToken) |
| | | sysApi.POST("/login", userController.Login) |
| | | sysApi.GET("/logout", userController.Logout) |
| | | sysApi.POST("refresh_token", userController.RefreshToken) |
| | | } |
| | | sysMenuApi := r.Group("/data/api-u/sysmenus") |
| | | { |
| | | sysMenuApi.GET("/me",sysMenuController.Me) |
| | | sysMenuApi.GET("/tree",sysMenuController.MenuTree) |
| | | sysMenuApi.GET("/me", sysMenuController.Me) |
| | | sysMenuApi.GET("/tree", sysMenuController.MenuTree) |
| | | } |
| | | roleApi :=r.Group("/data/api-v/role") |
| | | roleApi := r.Group("/data/api-v/role") |
| | | { |
| | | roleApi.GET("/findAll",sysRoleController.FindAll) |
| | | roleApi.GET("/findAll", sysRoleController.FindAll) |
| | | } |
| | | userApi := r.Group("/data/api-u/users") |
| | | { |
| | | userApi.GET("/current",userController.Current) |
| | | userApi.GET("/current", userController.Current) |
| | | userApi.GET("/findAllUser", userController.FindAllUser) |
| | | userApi.POST("/edit",userController.Edit) |
| | | userApi.POST("/edit", userController.Edit) |
| | | } |
| | | |
| | | urlPrefix := "/data/api-v" // wp 添加 路径 前缀 |
| | |
| | | area := r.Group(urlPrefix + "/area") |
| | | { |
| | | area.GET("/localmenu", areaController.CameraTree) |
| | | area.GET("/gb28181Tree",areaController.CameraGb28181Tree) |
| | | area.GET("/gb28181Tree", areaController.CameraGb28181Tree) |
| | | area.POST("/add", areaController.AreaAdd) |
| | | area.POST("/del", areaController.AreaDelete) |
| | | area.POST("/update", areaController.AreaUpdate) |
| | |
| | | camera.PUT("/update", cameraController.CameraUpdate) |
| | | camera.DELETE("/del/:cid", cameraController.CameraDel) |
| | | camera.GET("/show/:cid", cameraController.CameraSel) |
| | | camera.GET("/updateSnapshotUrl/:cid",cameraController.UpdateSnapshotUrl) |
| | | camera.GET("/updateSnapshotUrl/:cid", cameraController.UpdateSnapshotUrl) |
| | | |
| | | camera.POST("/alltask", cameraTaskController.FindTasksByCameraIds) |
| | | camera.GET("/task/:cameraId", cameraTaskController.CameraTaskAll) |
| | |
| | | cameraTaskArgsApi.GET("/deleteByGroup", cameraTaskArgsController.DeleteByGroup) |
| | | cameraTaskArgsApi.POST("/getLinkRulesByCameraIds", cameraTaskArgsController.GetLinkRulesByCameraIds) |
| | | cameraTaskArgsApi.POST("/saveLinkRulesByGroup", cameraTaskArgsController.SaveLinkRulesByGroup) |
| | | cameraTaskArgsApi.POST("/updateDefenceStateByGroup",cameraTaskArgsController.UpdateDefenceStateByGroup) |
| | | cameraTaskArgsApi.POST("/updateDefenceStateByGroup", cameraTaskArgsController.UpdateDefenceStateByGroup) |
| | | } |
| | | |
| | | cameraTaskApi := r.Group(urlPrefix + "/cameraTask") |
| | |
| | | vdbperson.PUT("/addDbPerson", dbPersonCont.AddDbPerson) |
| | | |
| | | vdbperson.POST("/fileUploadTest", fileController.UploadPersonTest) |
| | | vdbperson.POST("/faceExtract",fileController.FaceExtract) |
| | | vdbperson.POST("/searchByPhoto",fileController.SearchByPhoto) |
| | | vdbperson.POST("/faceExtract", fileController.FaceExtract) |
| | | vdbperson.POST("/searchByPhoto", fileController.SearchByPhoto) |
| | | vdbperson.POST("/updateFace", dbPersonCont.UpdateFace) |
| | | } |
| | | |
| | |
| | | vsset.POST("/saveDevInfo", ssController.SaveDevInfo) |
| | | vsset.GET("/gb28181ConfigShow", ssController.Gb28181ConfigShow) |
| | | vsset.POST("/gb28181ConfigEdit", ssController.Gb28181ConfigEdit) |
| | | vsset.GET("/clockInfo", ssController.GetClockinfo) |
| | | vsset.POST("/updateClock", ssController.SetSysClock) |
| | | vsset.GET("/ntpTest", ssController.TestNTPServer) |
| | | } |
| | | |
| | | //算法库操作 |
| | |
| | | sdkApi.GET("/findAllSdk", sdkController.FindAllSdk) |
| | | sdkApi.GET("/findByTaskId", sdkController.FindByTaskId) |
| | | sdkApi.GET("/getById", sdkController.GetById) |
| | | sdkApi.GET("/sdkDownload",sdkController.SdkDownLoad) |
| | | sdkApi.GET("/sdkDownload", sdkController.SdkDownLoad) |
| | | } |
| | | |
| | | //算法参数 |
| | | sdkArgApi :=r.Group(urlPrefix + "/sdkArg") |
| | | sdkArgApi := r.Group(urlPrefix + "/sdkArg") |
| | | { |
| | | sdkArgApi.GET("/getSdkArgs", sdkController.GetSdkArgs) |
| | | } |
| | |
| | | pollCApi.GET("/getPollConfig", pollConfigController.GetPollConfig) |
| | | pollCApi.POST("/updateEnable", pollConfigController.UpdateEnable) |
| | | } |
| | | clusterApi := r.Group(urlPrefix+"/cluster") |
| | | clusterApi := r.Group(urlPrefix + "/cluster") |
| | | { |
| | | clusterApi.GET("/findCluster", clusterController.FindCluster) |
| | | clusterApi.GET("/randomPwd", clusterController.RandomPwd) |