zoukankan      html  css  js  c++  java
  • 视频综合管理平台EasyNVS添加https证书配置步骤介绍

    之前我们介绍过EasyNVR硬件设备如何开启使用https,大家也可以了解一下。关于EasyNVR的管理平台EasyNVS,也是支持开启https的。本文就介绍一下EasyNVS视频管理平台添加https证书配置的步骤。

    1、首先需要先添加两个上传证书的接口:

    /**
    * @api {post} /api/v1/uploadfullchain 上传fullchain.pem证书
    * @apiGroup channel
    * @apiUse simpleSuccess
     */
    func (h *APIHandler) Uploadfullchain(c *gin.Context) {
       support := ".pem,.key,.crt,.cer"
       file, err := c.FormFile("file")
       if err != nil {
          err = fmt.Errorf("获取上传文件错误, %v", err)
          c.AbortWithStatusJSON(400, err.Error())
          return
       }
       ext := filepath.Ext(file.Filename)
       reg := regexp.MustCompile("(?i)(" + strings.Join(strings.Split(support, ","), "|") + ")$")
       if !reg.Match([]byte(ext)) {
          c.AbortWithStatusJSON(400, "上传数据格式错误!")
          return
       }
       var dest = ""
       if runtime.GOARCH == "arm" {
          dest = filepath.Join(utils.ExcelDataDir(), fmt.Sprintf("%s", file.Filename))
       } else {
          dest = filepath.Join(utils.SslDir(), fmt.Sprintf("%s", file.Filename))
     
       }
       err = c.SaveUploadedFile(file, dest)
       if ext == ".key" || ext == ".pem" || ext == ".crt" || ext == ".cer" {
          utils.SaveToConf("https", map[string]string{
             "ssl_cert_file": dest,
          })
       }
       if err != nil {
          err = fmt.Errorf("保存上传文件错误, %v", err)
          c.AbortWithStatusJSON(500, err.Error())
          return
       }
       c.IndentedJSON(200, "OK")
       h.Restart(c)
    }
     
    /**
    * @api {post} /api/v1/uploadprivkey 上传privkey
    * @apiGroup channel
    * @apiUse simpleSuccess
     */
    func (h *APIHandler) Uploadprivkey(c *gin.Context) {
       support := ".pem,.key,.crt,.cer"
       file, err := c.FormFile("file")
       if err != nil {
          err = fmt.Errorf("获取上传文件错误, %v", err)
          c.AbortWithStatusJSON(400, err.Error())
          return
       }
       ext := filepath.Ext(file.Filename)
       reg := regexp.MustCompile("(?i)(" + strings.Join(strings.Split(support, ","), "|") + ")$")
       if !reg.Match([]byte(ext)) {
          c.AbortWithStatusJSON(400, "上传数据格式错误!")
          return
       }
       var dest = ""
       if runtime.GOARCH == "arm" {
          dest = filepath.Join(utils.ExcelDataDir(), fmt.Sprintf("%s", file.Filename))
       } else {
          dest = filepath.Join(utils.SslDir(), fmt.Sprintf("%s", file.Filename))
     
       }
       err = c.SaveUploadedFile(file, dest)
       if ext == ".key" || ext == ".pem" || ext == ".crt" || ext == ".cer" {
          utils.SaveToConf("https", map[string]string{
             "ssl_key_file": dest,
          })
       }
       if err != nil {
          err = fmt.Errorf("保存上传文件错误, %v", err)
          c.AbortWithStatusJSON(500, err.Error())
          return
       }
       c.IndentedJSON(200, "OK")
       h.Restart(c)
    }
     
    

      

    2、然后设置开启https配置的接口:

    func (h *APIHandler) SetSslConfig(c *gin.Context) {
       type Form struct {
          HttpsPort uint
          Https     bool
          CrtFile   string
          KeyFile   string
       }
       var form = Form{}
       if err := c.Bind(&form); err != nil {
          return
       }
       _port := utils.Conf().Section("https").Key("port").MustUint(443)
       if _port != form.HttpsPort && utils.IsPortInUse(int(form.HttpsPort)) {
          c.AbortWithStatusJSON(http.StatusBadRequest, "HTTPS 本地端口 已占用")
          return
       }
       _Https := "0"
       if form.Https {
          _Https = "1"
       }
       utils.SaveToConf("https", map[string]string{
          "port":          fmt.Sprintf("%d", form.HttpsPort),
          "ssl_cert_file": fmt.Sprintf("%s", form.CrtFile),
          "ssl_key_file":  fmt.Sprintf("%s", form.KeyFile),
          "http_ssl":      _Https,
       })
     
       if _port != form.HttpsPort {
          API.RestartChan <- true
       }
       c.IndentedJSON(http.StatusOK, "ok")
    }
    

      

    3、最后还需要添加一个获取是否开启https配置的接口:

    func (h *APIHandler) GetSslConfig(c *gin.Context) {
       sec := utils.Conf().Section("https")
       ack := map[string]interface{}{
          "HttpsPort": sec.Key("port").MustString("443"),
          "CrtFile":   sec.Key("ssl_cert_file").MustString(""),
          "KeyFile":   sec.Key("ssl_key_file").MustString(""),
          "Https":     sec.Key("http_ssl").MustBool(false),
       }
       c.IndentedJSON(http.StatusOK, ack)
    }
    

    配置完成后,EasyNVS访问即可通过https进入。

    有想了解EasyNVS的用户,可以直接留言联系我们。如果还想了解更多视频相关的解决方案,可进入TSINGSEE青犀视频查阅浏览,青犀视频全线产品都已经支持H265编码视频,可实战测试,欢迎咨询了解。

  • 相关阅读:
    设计模式之-----------单例设计模式
    ubuntu 14 编译视频第三方库ijkplayer,能够在winows下使用
    AMP Physical Link Creation And Disconnect
    AnimationEvent事件问题
    网络事件触发自己主动登录
    Learn from Architects of Buildings
    对软件测试团队“核心价值”的思考
    【转】Android开发调试工具ADB的使用
    【转】adb控台中Permission denied的解决方案
    【转】蓝牙ble app开发(三) -- 抓包
  • 原文地址:https://www.cnblogs.com/EasyNVR/p/14665541.html
Copyright © 2011-2022 走看看