Merge remote-tracking branch 'origin/main' into lichang

This commit is contained in:
TsMask
2024-04-19 20:06:41 +08:00
34 changed files with 2291 additions and 396 deletions

View File

@@ -7,7 +7,6 @@ import (
"os"
"os/exec"
"strings"
"time"
"be.ems/lib/dborm"
"be.ems/lib/log"
@@ -154,21 +153,21 @@ func DeleteLcenseFile(w http.ResponseWriter, r *http.Request) {
services.ResponseStatusOK204NoContent(w)
}
type MMLRequest struct {
MML []string `json:"mml"`
}
// type MMLRequest struct {
// MML []string `json:"mml"`
// }
var TIME_DELAY_AFTER_WRITE time.Duration = 200
var TIME_DEAD_LINE time.Duration = 10
// var TIME_DELAY_AFTER_WRITE time.Duration = 200
// var TIME_DEAD_LINE time.Duration = 10
func init() {
if config.GetYamlConfig().MML.Sleep != 0 {
TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep)
}
if config.GetYamlConfig().MML.DeadLine != 0 {
TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine)
}
}
// func init() {
// if config.GetYamlConfig().MML.Sleep != 0 {
// TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep)
// }
// if config.GetYamlConfig().MML.DeadLine != 0 {
// TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine)
// }
// }
func UploadLicenseFileData(w http.ResponseWriter, r *http.Request) {
log.Info("UploadLicenseFileData processing... ")
@@ -274,12 +273,13 @@ func UploadLicenseFileData(w http.ResponseWriter, r *http.Request) {
}
// backup system.ini to system.ini.bak
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
cpCmd := fmt.Sprintf("sudo cp -f %s/system.ini %s/system.ini.bak", neLicensePath, neLicensePath)
cpCmd := fmt.Sprintf("sudo test -f %s/system.ini && cp -f %s/system.ini %s/system.ini.bak||echo 0",
neLicensePath, neLicensePath, neLicensePath)
cmd = exec.Command("ssh", sshHost, cpCmd)
out, err = cmd.CombinedOutput()
log.Debugf("Exec output: %v", string(out))
if err != nil {
log.Error("Faile to execute cp command:", err)
log.Errorf("Faile to execute cp command:%v, cmd:%s", err, cpCmd)
services.ResponseInternalServerError500ProcessError(w, err)
return
}

View File

@@ -461,8 +461,8 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) {
if err = AlarmEmailForward(&alarmData); err != nil {
log.Error("Failed to AlarmEmailForward:", err)
}
if err = AlarmForwardBySMSC(&alarmData); err != nil {
log.Error("Failed to AlarmForwardBySMSC:", err)
if err = AlarmForwardBySMPP(&alarmData); err != nil {
log.Error("Failed to AlarmForwardBySMPP:", err)
}
}
}
@@ -735,8 +735,8 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
if err = AlarmEmailForward(&alarmData); err != nil {
log.Error("Failed to AlarmEmailForward:", err)
}
if err = AlarmForwardBySMSC(&alarmData); err != nil {
log.Error("Failed to AlarmForwardBySMSC:", err)
if err = AlarmForwardBySMPP(&alarmData); err != nil {
log.Error("Failed to AlarmForwardBySMPP:", err)
}
}
}

View File

@@ -111,9 +111,9 @@ func AlarmForwardBySMPP(alarmData *Alarm) error {
auth := gosmpp.Auth{
SMSC: config.GetYamlConfig().Alarm.SMSC.Addr,
SystemID: config.GetYamlConfig().Alarm.SMSC.UserName,
SystemID: config.GetYamlConfig().Alarm.SMSC.SystemID,
Password: config.GetYamlConfig().Alarm.SMSC.Password,
SystemType: "",
SystemType: config.GetYamlConfig().Alarm.SMSC.SystemType,
}
// conn, err := gosmpp.NonTLSDialer(auth.SMSC)
@@ -141,7 +141,7 @@ func AlarmForwardBySMPP(alarmData *Alarm) error {
},
}, -1)
if err != nil {
log.Error(err)
log.Error("Failed to create SMPP new session:", err)
return err
}
defer func() {
@@ -168,7 +168,7 @@ func AlarmForwardBySMPP(alarmData *Alarm) error {
EventTime: alarmData.EventTime,
ToUser: toUser,
}
message := alarmData.AlarmTitle + "from" + alarmData.NeType + alarmData.NeId + "at" + alarmData.EventTime
message := "Alarm Notification: " + alarmData.AlarmTitle + " from " + alarmData.NeType + " " + alarmData.NeId + " at " + alarmData.EventTime
if err = trans.Transceiver().Submit(newSubmitSM(toUser, message)); err != nil {
operResult := fmt.Sprintf("Failed to submit short message:%v", err)
log.Error(operResult)

View File

@@ -13,9 +13,9 @@ import (
func AlarmForwardBySMSC(alarmData *Alarm) error {
opt := &ucp.Options{
Addr: config.GetYamlConfig().Alarm.SMSC.Addr,
User: config.GetYamlConfig().Alarm.SMSC.UserName,
User: config.GetYamlConfig().Alarm.SMSC.SystemID,
Password: config.GetYamlConfig().Alarm.SMSC.Password,
AccessCode: "",
AccessCode: config.GetYamlConfig().Alarm.SMSC.SystemType,
}
client := ucp.New(opt)