fix: reload failure from upf
This commit is contained in:
@@ -121,51 +121,170 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
services.ResponseWithJson(w, http.StatusOK, response)
|
services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)
|
conn.SetDeadline(time.Now().Add(10 * time.Second))
|
||||||
n, err = conn.Write([]byte(loginStr))
|
switch strings.ToLower(neType) {
|
||||||
if err != nil {
|
case "upf":
|
||||||
log.Errorf("Error: %s", err.Error())
|
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * TIME_DELAY_AFTER_WRITE)
|
|
||||||
|
|
||||||
n, err = conn.Read(buf[0:])
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Error: %s", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Debug(string(buf[0:n]))
|
|
||||||
|
|
||||||
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
|
|
||||||
if err != nil {
|
|
||||||
log.Error("io.ReadAll is failed:", err)
|
|
||||||
services.ResponseNotFound404UriNotExist(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Debug("Body:", string(body))
|
|
||||||
|
|
||||||
mmlRequest := new(MMLRequest)
|
|
||||||
_ = json.Unmarshal(body, mmlRequest)
|
|
||||||
|
|
||||||
for _, mml := range mmlRequest.MML {
|
|
||||||
mmlCommand := fmt.Sprintf("%s\n", mml)
|
|
||||||
log.Debug("mml command:", mmlCommand)
|
|
||||||
_, err = conn.Write([]byte(mmlCommand))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error: %s", err.Error())
|
log.Error("io.ReadAll is failed:", err)
|
||||||
|
services.ResponseNotFound404UriNotExist(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Trace("Body:", string(body))
|
||||||
|
|
||||||
|
mmlRequest := new(MMLRequest)
|
||||||
|
_ = json.Unmarshal(body, mmlRequest)
|
||||||
|
|
||||||
|
n, err = conn.Read(buf[0:])
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to read:", err)
|
||||||
|
mmlResult = append(mmlResult, err.Error())
|
||||||
|
response := Response{mmlResult}
|
||||||
|
services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Debug(string(buf[0:n]))
|
||||||
|
|
||||||
|
// loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)
|
||||||
|
// _, err = conn.Write([]byte(loginStr))
|
||||||
|
// if err != nil {
|
||||||
|
// log.Error("Failed to write:", err)
|
||||||
|
// mmlResult = append(mmlResult, err.Error())
|
||||||
|
// response := Response{mmlResult}
|
||||||
|
// services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// time.Sleep(time.Millisecond * TIME_DELAY_AFTER_WRITE)
|
||||||
|
|
||||||
|
n, err = conn.Write([]byte(config.GetYamlConfig().MML.User + "\n"))
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to write:", err)
|
||||||
|
mmlResult = append(mmlResult, err.Error())
|
||||||
|
response := Response{mmlResult}
|
||||||
|
services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Debug(string(buf[0:n]))
|
||||||
|
time.Sleep(time.Millisecond * TIME_DELAY_AFTER_WRITE)
|
||||||
|
|
||||||
|
// n, err = conn.Read(buf[0:])
|
||||||
|
// if err != nil {
|
||||||
|
// log.Error("Failed to read:", err)
|
||||||
|
// mmlResult = append(mmlResult, err.Error())
|
||||||
|
// response := Response{mmlResult}
|
||||||
|
// services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// log.Debug(string(buf[0:n]))
|
||||||
|
|
||||||
|
n, err = conn.Write([]byte(config.GetYamlConfig().MML.Password + "\n"))
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to write:", err)
|
||||||
|
mmlResult = append(mmlResult, err.Error())
|
||||||
|
response := Response{mmlResult}
|
||||||
|
services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Debug(string(buf[0:n]))
|
||||||
|
|
||||||
|
time.Sleep(time.Millisecond * TIME_DELAY_AFTER_WRITE)
|
||||||
|
|
||||||
|
// n, err = conn.Read(buf[0:])
|
||||||
|
// if err != nil {
|
||||||
|
// log.Error("Failed to read:", err)
|
||||||
|
// mmlResult = append(mmlResult, err.Error())
|
||||||
|
// response := Response{mmlResult}
|
||||||
|
// services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// log.Debug(string(buf[0:n]))
|
||||||
|
|
||||||
|
for _, mml := range mmlRequest.MML {
|
||||||
|
mmlCommand := fmt.Sprintf("%s\n", mml)
|
||||||
|
log.Debug("mml command:", mmlCommand)
|
||||||
|
_, err = conn.Write([]byte(mmlCommand))
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to write:", err)
|
||||||
|
mmlResult = append(mmlResult, err.Error())
|
||||||
|
response := Response{mmlResult}
|
||||||
|
services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.Sleep(time.Millisecond * TIME_DELAY_AFTER_WRITE)
|
||||||
|
|
||||||
|
// n, err = conn.Read(buf[0:])
|
||||||
|
// if err != nil {
|
||||||
|
// log.Error("Failed to read:", err)
|
||||||
|
// mmlResult = append(mmlResult, err.Error())
|
||||||
|
// response := Response{mmlResult}
|
||||||
|
// services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// log.Trace(string(buf[0 : n-len(neType)-2]))
|
||||||
|
// mmlResult = append(mmlResult, string(buf[0:n-len(neType)-2]))
|
||||||
|
|
||||||
|
// can't read buffer from upf telnet server, so return ok always
|
||||||
|
mmlResult = append(mmlResult, "COMMAND OK\n")
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)
|
||||||
|
_, err = conn.Write([]byte(loginStr))
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to write:", err)
|
||||||
|
mmlResult = append(mmlResult, err.Error())
|
||||||
|
response := Response{mmlResult}
|
||||||
|
services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * TIME_DELAY_AFTER_WRITE)
|
time.Sleep(time.Millisecond * TIME_DELAY_AFTER_WRITE)
|
||||||
|
|
||||||
n, err = conn.Read(buf[0:])
|
n, err = conn.Read(buf[0:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error: %s", err.Error())
|
log.Error("Failed to read:", err)
|
||||||
|
mmlResult = append(mmlResult, err.Error())
|
||||||
|
response := Response{mmlResult}
|
||||||
|
services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debug(string(buf[0 : n-len(neType)-2]))
|
log.Trace(string(buf[0:n]))
|
||||||
mmlResult = append(mmlResult, string(buf[0:n-len(neType)-2]))
|
|
||||||
|
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to ReadAll:", err)
|
||||||
|
services.ResponseNotFound404UriNotExist(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Trace("Body:", string(body))
|
||||||
|
|
||||||
|
mmlRequest := new(MMLRequest)
|
||||||
|
_ = json.Unmarshal(body, mmlRequest)
|
||||||
|
|
||||||
|
for _, mml := range mmlRequest.MML {
|
||||||
|
mmlCommand := fmt.Sprintf("%s\n", mml)
|
||||||
|
_, err = conn.Write([]byte(mmlCommand))
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to write:", err)
|
||||||
|
mmlResult = append(mmlResult, err.Error())
|
||||||
|
response := Response{mmlResult}
|
||||||
|
services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.Sleep(time.Millisecond * TIME_DELAY_AFTER_WRITE)
|
||||||
|
|
||||||
|
n, err = conn.Read(buf[0:])
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to read:", err)
|
||||||
|
mmlResult = append(mmlResult, err.Error())
|
||||||
|
response := Response{mmlResult}
|
||||||
|
services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Trace(string(buf[0 : n-len(neType)-2]))
|
||||||
|
mmlResult = append(mmlResult, string(buf[0:n-len(neType)-2]))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user