fix: mml for all ne system
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -147,18 +148,8 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
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"))
|
||||
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())
|
||||
@@ -166,9 +157,19 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
services.ResponseWithJson(w, http.StatusOK, response)
|
||||
return
|
||||
}
|
||||
log.Debug(string(buf[0:n]))
|
||||
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)
|
||||
@@ -179,17 +180,17 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
// 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]))
|
||||
// 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)
|
||||
// time.Sleep(time.Millisecond * TIME_DELAY_AFTER_WRITE)
|
||||
|
||||
// n, err = conn.Read(buf[0:])
|
||||
// if err != nil {
|
||||
@@ -214,19 +215,28 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
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]))
|
||||
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]))
|
||||
|
||||
re1 := regexp.MustCompile(`\x1B\[[0-9;]*[a-zA-Z]`) // 匹配包含␛的控制字符
|
||||
//re2 := regexp.MustCompile(`\x00`) // 匹配空字符
|
||||
re2 := regexp.MustCompile(`[\x00-\x08\x0B\x0C\x0E-\x1F\x7F\x1B]`) // 匹配空字符和包含␛的控制字符
|
||||
//re := regexp.MustCompile(`[\x00-\x1F\x7F]`)
|
||||
// upf telnet buffer只能读取一次,需要去掉前面的多余字符
|
||||
result := re1.ReplaceAllString(string(buf[config.GetYamlConfig().MML.UpfHeaderLength:n-len(neType)-2]), "")
|
||||
result = re2.ReplaceAllString(result, "")
|
||||
mmlResult = append(mmlResult, result)
|
||||
//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")
|
||||
// mmlResult = append(mmlResult, "COMMAND OK\n")
|
||||
}
|
||||
default:
|
||||
loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)
|
||||
@@ -283,7 +293,13 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
log.Trace(string(buf[0 : n-len(neType)-2]))
|
||||
mmlResult = append(mmlResult, string(buf[0:n-len(neType)-2]))
|
||||
re1 := regexp.MustCompile(`\x1B\[[0-9;]*[a-zA-Z]`) // 匹配包含␛的控制字符
|
||||
//re2 := regexp.MustCompile(`\x00`) // 匹配空字符
|
||||
re2 := regexp.MustCompile(`[\x00-\x08\x0B\x0C\x0E-\x1F\x7F\x1B]`) // 匹配空字符和包含␛的控制字符
|
||||
//re := regexp.MustCompile(`[\x00-\x1F\x7F]`)
|
||||
result := re1.ReplaceAllString(string(buf[0:n-len(neType)-2]), "")
|
||||
result = re2.ReplaceAllString(result, "")
|
||||
mmlResult = append(mmlResult, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user