This commit is contained in:
2023-09-16 19:23:11 +08:00
parent 9c8b4d8dc8
commit de9189bd32
6 changed files with 119 additions and 84 deletions

View File

@@ -74,6 +74,7 @@ ne:
etcdir: /usr/local/etc etcdir: /usr/local/etc
bindir: /usr/local/bin bindir: /usr/local/bin
omcdir: /usr/local/omc omcdir: /usr/local/omc
scpdir: /tmp
licensedir: /usr/local/etc/{neType}/license licensedir: /usr/local/etc/{neType}/license
# chk2ne: true/false, if put OmcNeConfig parameters to NE # chk2ne: true/false, if put OmcNeConfig parameters to NE
@@ -88,7 +89,7 @@ omc:
dn: 4600 dn: 4600
chk2ne: false chk2ne: false
sn: 13750650 sn: 13750650
checksign: true checksign: false
backup: /usr/local/omc/backup backup: /usr/local/omc/backup
upload: /usr/local/omc/upload upload: /usr/local/omc/upload
frontUpload: /usr/local/omc/htdocs/front/upload frontUpload: /usr/local/omc/htdocs/front/upload
@@ -97,7 +98,7 @@ omc:
license: /usr/local/omc/license license: /usr/local/omc/license
gtpUri: gtp:192.168.2.119:2152 gtpUri: gtp:192.168.2.119:2152
checkContentType: false checkContentType: false
testMode: true testMode: false
rbacMode: true rbacMode: true
runDir: /usr/local/omc/run runDir: /usr/local/omc/run

View File

@@ -1,48 +1,51 @@
package main package main
import ( import (
"flag" "flag"
"fmt" "fmt"
//"os" "os"
"encoding/binary"
"encoding/hex" //"os"
"io/ioutil" "encoding/binary"
"os/exec" "encoding/hex"
"os/exec"
) )
const magicMicroseconds = 0xa1b2c3d4 const magicMicroseconds = 0xa1b2c3d4
const versionMajor = 2 const versionMajor = 2
const versionMinor = 4 const versionMinor = 4
func WriteEmptyPcap(filename string, timestamp int64, length int, data []byte) error {
var cooked = [...]byte{0x00,0x00,0x03,0x04,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00}
var buf []byte func WriteEmptyPcap(filename string, timestamp int64, length int, data []byte) error {
var cooked = [...]byte{0x00, 0x00, 0x03, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00}
var buf []byte
//24+16+16 = 56 //24+16+16 = 56
buf = make([]byte, 56+length) buf = make([]byte, 56+length)
binary.LittleEndian.PutUint32(buf[0:4], magicMicroseconds) binary.LittleEndian.PutUint32(buf[0:4], magicMicroseconds)
binary.LittleEndian.PutUint16(buf[4:6], versionMajor) binary.LittleEndian.PutUint16(buf[4:6], versionMajor)
binary.LittleEndian.PutUint16(buf[6:8], versionMinor) binary.LittleEndian.PutUint16(buf[6:8], versionMinor)
// bytes 8:12 stay 0 (timezone = UTC) // bytes 8:12 stay 0 (timezone = UTC)
// bytes 12:16 stay 0 (sigfigs is always set to zero, according to // bytes 12:16 stay 0 (sigfigs is always set to zero, according to
// http://wiki.wireshark.org/Development/LibpcapFileFormat // http://wiki.wireshark.org/Development/LibpcapFileFormat
binary.LittleEndian.PutUint32(buf[16:20], 0x00040000) binary.LittleEndian.PutUint32(buf[16:20], 0x00040000)
binary.LittleEndian.PutUint32(buf[20:24], 0x00000071) binary.LittleEndian.PutUint32(buf[20:24], 0x00000071)
// Packet Header // Packet Header
binary.LittleEndian.PutUint64(buf[24:32], uint64(timestamp)) binary.LittleEndian.PutUint64(buf[24:32], uint64(timestamp))
binary.LittleEndian.PutUint32(buf[32:36], uint32(length+16)) binary.LittleEndian.PutUint32(buf[32:36], uint32(length+16))
binary.LittleEndian.PutUint32(buf[36:40], uint32(length+16)) binary.LittleEndian.PutUint32(buf[36:40], uint32(length+16))
copy(buf[40:], cooked[:]) copy(buf[40:], cooked[:])
copy(buf[56:], data[:]) copy(buf[56:], data[:])
err := ioutil.WriteFile(filename, buf[:], 0644) err := os.WriteFile(filename, buf[:], 0644)
//fmt.Printf("CAP: %v\n", buf) //fmt.Printf("CAP: %v\n", buf)
return err return err
} }
//tshark -r gtp.pcap -T json -d tcp.port==8080,http2 -Y "http2"
// tshark -r gtp.pcap -T json -d tcp.port==8080,http2 -Y "http2"
func execTshark(html string, filename string, proto string, port int) { func execTshark(html string, filename string, proto string, port int) {
var tshark *exec.Cmd var tshark *exec.Cmd
var sharkCmd string var sharkCmd string
@@ -51,10 +54,10 @@ func execTshark(html string, filename string, proto string, port int) {
dataPort := fmt.Sprintf("tcp.port==%d,http2", port) dataPort := fmt.Sprintf("tcp.port==%d,http2", port)
if proto == "http2" { if proto == "http2" {
//tshark = exec.Command("tshark", "-r"+pcapPath, //tshark = exec.Command("tshark", "-r"+pcapPath,
// "-Y"+proto, // "-Y"+proto,
// "-d"+dataPort, // "-d"+dataPort,
// "-T", "pdml") // "-T", "pdml")
sharkCmd = fmt.Sprintf("tshark -r %s -T pdml -d tcp.port==%d,http2 -Y \"%s\" > %s.pdml", pcapPath, dataPort, proto, pcapPath) sharkCmd = fmt.Sprintf("tshark -r %s -T pdml -d tcp.port==%s,http2 -Y \"%s\" > %s.pdml", pcapPath, dataPort, proto, pcapPath)
tshark = exec.Command("sh", "-c", sharkCmd) tshark = exec.Command("sh", "-c", sharkCmd)
} else { } else {
//tshark = exec.Command("tshark", "-r"+pcapPath, //tshark = exec.Command("tshark", "-r"+pcapPath,
@@ -71,30 +74,30 @@ func execTshark(html string, filename string, proto string, port int) {
pdmlFile := fmt.Sprintf("%s.pdml", filename) pdmlFile := fmt.Sprintf("%s.pdml", filename)
//err1 := os.WriteFile(pdmlFile, []byte(out), 0666) //err1 := os.WriteFile(pdmlFile, []byte(out), 0666)
//if err1 != nil { //if err1 != nil {
// fmt.Println("write html failed") // fmt.Println("write html failed")
//}else { //}else {
//xsltproc pdml2html.xsl ngap.pdml > /home/agtuser/ngap.html //xsltproc pdml2html.xsl ngap.pdml > /home/agtuser/ngap.html
command := fmt.Sprintf("xsltproc /usr/lib64/pdml2html.xsl %s > %s", pdmlFile, html) command := fmt.Sprintf("xsltproc /usr/lib64/pdml2html.xsl %s > %s", pdmlFile, html)
dest := exec.Command("sh", "-c", command) dest := exec.Command("sh", "-c", command)
_, err2 := dest.Output() _, err2 := dest.Output()
if err2 != nil { if err2 != nil {
fmt.Println("Error:", err2, command) fmt.Println("Error:", err2, command)
} }
//} //}
} }
} }
func ipDataHandle(html string, iftype string, port int, timestamp int64, data []byte) int { func ipDataHandle(html string, iftype string, port int, timestamp int64, data []byte) int {
var filePath, proto string var filePath, proto string
if iftype == "N2" || iftype == "N1" { if iftype == "N2" || iftype == "N1" {
filePath = fmt.Sprintf("/tmp/ng%d.pcap", timestamp) filePath = fmt.Sprintf("/tmp/ng%d.pcap", timestamp)
proto = "ngap" proto = "ngap"
}else if iftype == "N4" { } else if iftype == "N4" {
filePath = fmt.Sprintf("/tmp/pf%d.pcap", timestamp) filePath = fmt.Sprintf("/tmp/pf%d.pcap", timestamp)
proto = "pfcp" proto = "pfcp"
}else { } else {
filePath = fmt.Sprintf("/tmp/hp%d.pcap", timestamp) filePath = fmt.Sprintf("/tmp/hp%d.pcap", timestamp)
proto = "http2" proto = "http2"
} }
@@ -102,7 +105,7 @@ func ipDataHandle(html string, iftype string, port int, timestamp int64, data []
err := WriteEmptyPcap(filePath, timestamp, len(data), data) err := WriteEmptyPcap(filePath, timestamp, len(data), data)
if err != nil { if err != nil {
fmt.Printf("tshark failed with %s\n", err) fmt.Printf("tshark failed with %s\n", err)
} else { } else {
execTshark(html, filePath, proto, port) execTshark(html, filePath, proto, port)
} }
@@ -114,14 +117,14 @@ func main() {
var timestamp int64 var timestamp int64
var port int var port int
flag.Int64Var(&timestamp,"t",0,"timestamp") flag.Int64Var(&timestamp, "t", 0, "timestamp")
flag.StringVar(&iftype,"i","","interface type") flag.StringVar(&iftype, "i", "", "interface type")
flag.IntVar(&port,"p",0,"data port") flag.IntVar(&port, "p", 0, "data port")
flag.StringVar(&ipdata,"d","","ip packet data") flag.StringVar(&ipdata, "d", "", "ip packet data")
flag.StringVar(&html,"f","","html file path") flag.StringVar(&html, "f", "", "html file path")
flag.Parse() flag.Parse()
ds, err := hex.DecodeString(ipdata) ds, err := hex.DecodeString(ipdata)
if err != nil { if err != nil {

View File

@@ -457,7 +457,6 @@ func ExportCmFromNF(w http.ResponseWriter, r *http.Request) {
//services.ResponseFileWithNameAndMD5(w, http.StatusOK, zipFile, path, md5Sum) //services.ResponseFileWithNameAndMD5(w, http.StatusOK, zipFile, path, md5Sum)
services.ResponseStatusOK204NoContent(w) services.ResponseStatusOK204NoContent(w)
return
} }
type ImportCMJson struct { type ImportCMJson struct {
@@ -481,7 +480,7 @@ func ImportCmToNF(w http.ResponseWriter, r *http.Request) {
return return
} }
neTypeUpper := strings.ToUpper(neType) neTypeUpper := strings.ToUpper(neType)
neTypeLower := strings.ToLower(neType) //neTypeLower := strings.ToLower(neType)
neId := services.GetUriParamString(r, "ne_id", ",", false, false) neId := services.GetUriParamString(r, "ne_id", ",", false, false)
@@ -534,41 +533,75 @@ func ImportCmToNF(w http.ResponseWriter, r *http.Request) {
log.Error("Faile to XormInsertTableOne:", err) log.Error("Faile to XormInsertTableOne:", err)
services.ResponseInternalServerError500ProcessError(w, err) services.ResponseInternalServerError500ProcessError(w, err)
return return
} else if has == false { } else if !has {
err = global.ErrCMInvalidBackupFile err = global.ErrCMInvalidBackupFile
log.Error(err) log.Error(err)
services.ResponseInternalServerError500ProcessError(w, err) services.ResponseInternalServerError500ProcessError(w, err)
return return
} }
nePath := fmt.Sprintf("%s/etc/%s", config.GetYamlConfig().OMC.Upload, neTypeLower) // nePath := fmt.Sprintf("%s/etc/%s", config.GetYamlConfig().OMC.Upload, neTypeLower)
isExist, err := global.PathExists(nePath) // isExist, err := global.PathExists(nePath)
if err != nil { // if err != nil {
log.Errorf("Failed to stat:", err) // log.Errorf("Failed to stat:", err)
services.ResponseInternalServerError500ProcessError(w, err) // services.ResponseInternalServerError500ProcessError(w, err)
return // return
} // }
if isExist { // if isExist {
err = os.RemoveAll(nePath) // err = os.RemoveAll(nePath)
if err != nil { // if err != nil {
log.Errorf("Failed to remove:", err) // log.Errorf("Failed to remove:", err)
services.ResponseInternalServerError500ProcessError(w, err) // services.ResponseInternalServerError500ProcessError(w, err)
return // return
} // }
} // }
unzipCmd := fmt.Sprintf("unzip -o %s -d %s", filePath, config.GetYamlConfig().OMC.Upload) // unzipCmd := fmt.Sprintf("unzip -o %s -d %s", filePath, config.GetYamlConfig().OMC.Upload)
var scpCmd string // var scpCmd string
// ipType := global.ParseIPAddr(neInfo.Ip)
// if ipType == global.IsIPv4 {
// scpCmd = fmt.Sprintf("scp -r %s/etc/%s %s@%s:%s", config.GetYamlConfig().OMC.Upload,
// neTypeLower, config.GetYamlConfig().NE.User, neInfo.Ip, config.GetYamlConfig().NE.EtcDir)
// } else {
// scpCmd = fmt.Sprintf("scp -r %s/etc/%s %s@[%s]:%s", config.GetYamlConfig().OMC.Upload,
// neTypeLower, config.GetYamlConfig().NE.User, neInfo.Ip, config.GetYamlConfig().NE.EtcDir)
// }
// err = ExecCmd(fmt.Sprintf("%s && %s", unzipCmd, scpCmd))
// if err != nil {
// log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
// services.ResponseInternalServerError500ProcessError(w, err)
// return
// }
// nePath := fmt.Sprintf("%s/etc/%s", config.GetYamlConfig().OMC.Upload, neTypeLower)
// isExist, err := global.PathExists(nePath)
// if err != nil {
// log.Errorf("Failed to stat:", err)
// services.ResponseInternalServerError500ProcessError(w, err)
// return
// }
// if isExist {
// err = os.RemoveAll(nePath)
// if err != nil {
// log.Errorf("Failed to remove:", err)
// services.ResponseInternalServerError500ProcessError(w, err)
// return
// }
// }
var scpZipCmd string
ipType := global.ParseIPAddr(neInfo.Ip) ipType := global.ParseIPAddr(neInfo.Ip)
if ipType == global.IsIPv4 { if ipType == global.IsIPv4 {
scpCmd = fmt.Sprintf("scp -r %s/etc/%s %s@%s:%s", config.GetYamlConfig().OMC.Upload, scpZipCmd = fmt.Sprintf("scp -r %s -d %s@%s:%s", filePath,
neTypeLower, config.GetYamlConfig().NE.User, neInfo.Ip, config.GetYamlConfig().NE.EtcDir) config.GetYamlConfig().NE.User, neInfo.Ip, config.GetYamlConfig().NE.ScpDir)
} else { } else {
scpCmd = fmt.Sprintf("scp -r %s/etc/%s %s@[%s]:%s", config.GetYamlConfig().OMC.Upload, scpZipCmd = fmt.Sprintf("scp -r %s -d %s@[%s]:%s", filePath,
neTypeLower, config.GetYamlConfig().NE.User, neInfo.Ip, config.GetYamlConfig().NE.EtcDir) config.GetYamlConfig().NE.User, neInfo.Ip, config.GetYamlConfig().NE.ScpDir)
} }
neFilePath := config.GetYamlConfig().NE.ScpDir + "/" + fileName
unzipCmd := fmt.Sprintf("sudo unzip -o %s -d %s", neFilePath, config.GetYamlConfig().NE.EtcDir)
err = ExecCmd(fmt.Sprintf("%s && %s", unzipCmd, scpCmd)) err = ExecCmd(fmt.Sprintf("%s && %s", scpZipCmd, unzipCmd))
if err != nil { if err != nil {
log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip) log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
services.ResponseInternalServerError500ProcessError(w, err) services.ResponseInternalServerError500ProcessError(w, err)
@@ -621,7 +654,6 @@ func DownloadNeBackupFile(w http.ResponseWriter, r *http.Request) {
md5Sum := (*neBackup)[0]["md5_sum"] md5Sum := (*neBackup)[0]["md5_sum"]
services.ResponseFileWithNameAndMD5(w, http.StatusOK, fileName, path, md5Sum) services.ResponseFileWithNameAndMD5(w, http.StatusOK, fileName, path, md5Sum)
return
} }
func DeleteNeBackupFile(w http.ResponseWriter, r *http.Request) { func DeleteNeBackupFile(w http.ResponseWriter, r *http.Request) {
@@ -681,5 +713,4 @@ func DeleteNeBackupFile(w http.ResponseWriter, r *http.Request) {
} }
services.ResponseStatusOK204NoContent(w) services.ResponseStatusOK204NoContent(w)
return
} }

View File

@@ -666,7 +666,7 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
} }
log.Debug("neVersion:", neVersion) log.Debug("neVersion:", neVersion)
if config.GetYamlConfig().OMC.TestMode == false { if !config.GetYamlConfig().OMC.TestMode {
filePath := (*neVersion)[0]["file_path"] filePath := (*neVersion)[0]["file_path"]
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip) sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
rpmCmd := fmt.Sprintf("sudo rpm -Uvh '%s'", filePath) rpmCmd := fmt.Sprintf("sudo rpm -Uvh '%s'", filePath)
@@ -680,7 +680,7 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
} }
} }
idNeVersion, err := strconv.Atoi((*neVersion)[0]["id"]) idNeVersion, _ := strconv.Atoi((*neVersion)[0]["id"])
neVersionData := dborm.NeVersion{ neVersionData := dborm.NeVersion{
Status: SoftwareStatusActive, Status: SoftwareStatusActive,
} }
@@ -693,7 +693,6 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
} }
services.ResponseStatusOK204NoContent(w) services.ResponseStatusOK204NoContent(w)
return
} }
func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) { func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
@@ -758,7 +757,7 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
return return
} }
if config.GetYamlConfig().OMC.TestMode == false { if !config.GetYamlConfig().OMC.TestMode {
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip) sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
rpmCmd := fmt.Sprintf("rpm -Uvh --oldpackage '%s'", filePath) rpmCmd := fmt.Sprintf("rpm -Uvh --oldpackage '%s'", filePath)
cmd := exec.Command("ssh", sshHost, rpmCmd) cmd := exec.Command("ssh", sshHost, rpmCmd)
@@ -771,7 +770,7 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
} }
} }
idNeVersion, err := strconv.Atoi((*neVersion)[0]["id"]) idNeVersion, _ := strconv.Atoi((*neVersion)[0]["id"])
neVersionData := dborm.NeVersion{ neVersionData := dborm.NeVersion{
Version: (*neVersion)[0]["pre_version"], Version: (*neVersion)[0]["pre_version"],
FilePath: (*neVersion)[0]["pre_file"], FilePath: (*neVersion)[0]["pre_file"],
@@ -790,5 +789,4 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
} }
services.ResponseStatusOK204NoContent(w) services.ResponseStatusOK204NoContent(w)
return
} }

View File

@@ -114,6 +114,7 @@ type YamlConfig struct {
EtcDir string `yaml:"etcdir"` EtcDir string `yaml:"etcdir"`
BinDir string `yaml:"bindir"` BinDir string `yaml:"bindir"`
OmcDir string `yaml:"omcdir"` OmcDir string `yaml:"omcdir"`
ScpDir string `yaml:"scpdir"`
LicenseDir string `yaml:"licensedir"` LicenseDir string `yaml:"licensedir"`
} `yaml:"ne"` } `yaml:"ne"`

View File

@@ -74,6 +74,7 @@ ne:
etcdir: /usr/local/etc etcdir: /usr/local/etc
bindir: /usr/local/bin bindir: /usr/local/bin
omcdir: /usr/local/omc omcdir: /usr/local/omc
scpdir: /tmp
licensedir: /usr/local/etc/{neType}/license licensedir: /usr/local/etc/{neType}/license
# chk2ne: true/false, if put OmcNeConfig parameters to NE # chk2ne: true/false, if put OmcNeConfig parameters to NE
@@ -97,7 +98,7 @@ omc:
license: ./license license: ./license
gtpUri: gtp:192.168.2.119:2152 gtpUri: gtp:192.168.2.119:2152
checkContentType: false checkContentType: false
testMode: true testMode: false
rbacMode: true rbacMode: true
runDir: runDir: