New file |
| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "webserver/extend/code" |
| | | "webserver/extend/util" |
| | | |
| | | "github.com/gin-gonic/gin" |
| | | ) |
| | | |
| | | type PanTiltController struct { |
| | | } |
| | | |
| | | type PTInstruct struct { |
| | | ChannelId string `json:"channelId"` //服务器id |
| | | PTZType string `json:"ptzType"` //轮询周期 |
| | | PTZParam int32 `json:"ptzParam"` //延时时间 |
| | | } |
| | | |
| | | func (controller PanTiltController) Controlling(c *gin.Context) { |
| | | var param PTInstruct |
| | | if err := c.BindJSON(¶m); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | |
| | | b := true |
| | | if b { |
| | | util.ResponseFormat(c, code.Success, "") |
| | | } else { |
| | | util.ResponseFormat(c, code.ComError, "保存失败") |
| | | } |
| | | } |
| | |
| | | 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, "时区参数错误") |
| | |
| | | func (sset SysSetController) GetSysThresholds(c *gin.Context) { |
| | | util.ResponseFormat(c, code.UpdateSuccess, config.Server.SysThresholds) |
| | | } |
| | | |
| | | // @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, "正在重启") |
| | | } |
| | |
| | | ChannelCount string `mapstructure: "channelCount"` //通道个数 |
| | | DiskCount string `mapstructure: "diskCount"` //硬盘个数 |
| | | |
| | | SysServerPort string `mapstructure: "sysServerPort"` |
| | | SudoPassword string `mapstructure: "sudoPassword"` |
| | | SysThresholds []threshold `mapstructure: "sysThresholds"` |
| | | } |
| | | |
| | |
| | | package sys |
| | | |
| | | import ( |
| | | "encoding/json" |
| | | "errors" |
| | | "io/ioutil" |
| | | "net/http" |
| | | "net/url" |
| | | "os" |
| | | "os/exec" |
| | | "strconv" |
| | |
| | | "time" |
| | | ) |
| | | |
| | | func execRootCommand(cmd string) (bool, string) { |
| | | serverPort := config.Server.SysServerPort |
| | | if serverPort == "" { |
| | | serverPort = "18081" |
| | | } |
| | | sysConfigServer := fmt.Sprintf("http://127.0.0.1:%s/api/v1/command/exec", serverPort) |
| | | resp, err := http.PostForm(sysConfigServer, url.Values{"command": {cmd}}) |
| | | func execRootCommand(cmd string) ([]byte, error) { |
| | | pwd := config.Server.SudoPassword |
| | | cmdStr := fmt.Sprintf("echo %s | sudo -S %s", pwd, cmd) |
| | | |
| | | if err != nil { |
| | | return false, err.Error() |
| | | } |
| | | |
| | | defer resp.Body.Close() |
| | | body, err := ioutil.ReadAll(resp.Body) |
| | | if err != nil { |
| | | return false, err.Error() |
| | | } |
| | | |
| | | type response struct { |
| | | Code int `json:"code"` |
| | | Success bool `json:"success"` |
| | | Msg string `json:"msg"` |
| | | CMD string `json:"cmd"` |
| | | Data string `json:"data"` |
| | | } |
| | | |
| | | var rsp response |
| | | if err := json.Unmarshal(body, &rsp); err != nil { |
| | | return false, err.Error() |
| | | } |
| | | |
| | | fmt.Println(body) |
| | | fmt.Println(rsp) |
| | | return rsp.Success, rsp.Data |
| | | return exec.Command("/bin/sh", "-c", cmdStr).Output() |
| | | } |
| | | |
| | | // 检查 root权限 |
| | |
| | | } |
| | | // # netconfig enp59s0f0 192.168.1.2 255.255.255.0 192.168.1.1 192.168.100.1 |
| | | cmdStr := fmt.Sprintf("%s %s %s %s %s %s", networkConfigScript, ifname, ipv4, netmask, gateway, dns) |
| | | // return exec.Command("/bin/sh", "-c", cmdStr).Run() == nil |
| | | return execRootCommand(cmdStr) |
| | | stdout, err := execRootCommand(cmdStr) |
| | | |
| | | return err == nil, string(stdout) |
| | | } |
| | | |
| | | // 配置时区 |
| | |
| | | return false |
| | | } |
| | | |
| | | args := []string{"-s", newTime} |
| | | exec.Command("date", args...).Run() |
| | | // args := []string{"-s", newTime} |
| | | // exec.Command("date", args...).Run() |
| | | dateCMD := fmt.Sprintf("date -s \"%s\"", newTime) |
| | | execRootCommand(dateCMD) |
| | | stopNTPCron() |
| | | |
| | | return true |
| | |
| | | ntpdate := fmt.Sprintf("/usr/sbin/ntpdate %s", server) |
| | | return true, exec.Command("/bin/sh", "-c", ntpdate).Run() |
| | | } |
| | | |
| | | func Reboot() (bool, string) { |
| | | stdout, err := execRootCommand("reboot") |
| | | |
| | | return err == nil, string(stdout) |
| | | } |
| | |
| | | sysMenuController := new(controllers.SysMenuController) |
| | | clusterController := new(controllers.ClusterController) |
| | | sysRoleController := new(controllers.RoleController) |
| | | ptController := new(controllers.PanTiltController) |
| | | |
| | | sysApi := r.Group("/data/api-u/sys") |
| | | { |
| | |
| | | camera.POST("/updateRunEnable", cameraController.UpdateRunEnable) |
| | | camera.POST("/changeRunType", cameraController.ChangeRunType) |
| | | camera.GET("/getAllCamerasByServer", cameraController.GetAllCamerasByServer) |
| | | |
| | | camera.POST("/ptControl", ptController.Controlling) |
| | | } |
| | | |
| | | cameraTaskArgsApi := r.Group(urlPrefix + "/cameraTaskArgs") |
| | |
| | | vsset.GET("/ntpTest", ssController.TestNTPServer) |
| | | vsset.GET("/sysinfo", ssController.GetSysInfo) |
| | | vsset.GET("/sysThresholds", ssController.GetSysThresholds) |
| | | |
| | | vsset.GET("/reboot", ssController.RebootOS) |
| | | } |
| | | |
| | | //算法库操作 |