frpc admin: not allow empty PUT /api/config body

This commit is contained in:
fatedier 2019-02-02 10:49:24 +08:00
parent 7f9ea48405
commit 66555dbb00

View File

@ -280,11 +280,18 @@ func (svr *Service) apiPutConfig(w http.ResponseWriter, r *http.Request) {
return
}
if len(body) == 0 {
res.Code = 2
res.Msg = "body can't be empty"
log.Warn("%s", res.Msg)
return
}
// get token from origin content
token := ""
b, err := ioutil.ReadFile(g.GlbClientCfg.CfgFile)
if err != nil {
res.Code = 2
res.Code = 3
res.Msg = err.Error()
log.Warn("load frpc config file error: %v", err)
return
@ -321,7 +328,7 @@ func (svr *Service) apiPutConfig(w http.ResponseWriter, r *http.Request) {
err = ioutil.WriteFile(g.GlbClientCfg.CfgFile, []byte(content), 0644)
if err != nil {
res.Code = 3
res.Code = 4
res.Msg = fmt.Sprintf("write content to frpc config file error: %v", err)
log.Warn("%s", res.Msg)
return