diff --git a/Gopkg.lock b/Gopkg.lock index 052e890..1877b1c 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -87,7 +87,7 @@ "model/sensorconfig", "service/probe" ] - revision = "54725b74e13a501d7a13a76a82c294769729748d" + revision = "904de1632643ddb9c8862cd5bf147570c1a59878" [[projects]] name = "github.com/BurntSushi/toml" @@ -135,13 +135,22 @@ [[projects]] name = "github.com/shirou/gopsutil" packages = [ + "cpu", "host", "internal/common", + "mem", + "net", "process" ] revision = "4a180b209f5f494e5923cfce81ea30ba23915877" version = "v2.18.06" +[[projects]] + branch = "master" + name = "github.com/shirou/w32" + packages = ["."] + revision = "bb4de0191aa41b5507caa14b0650cdbddcd9280b" + [[projects]] name = "github.com/valyala/fasthttp" packages = [ diff --git a/_build/config_/_ b/_build/config/_ similarity index 100% rename from _build/config_/_ rename to _build/config/_ diff --git a/_build/config_/container/network/postgresql/112103115113108 b/_build/config/container/network/postgresql/112103115113108 similarity index 100% rename from _build/config_/container/network/postgresql/112103115113108 rename to _build/config/container/network/postgresql/112103115113108 diff --git a/_build/config_/container/network/ssh/115115104 b/_build/config/container/network/ssh/115115104 similarity index 100% rename from _build/config_/container/network/ssh/115115104 rename to _build/config/container/network/ssh/115115104 diff --git a/config/path-sensorconfig.go b/config/path-sensorconfig.go index eb72c7e..0f5151c 100644 --- a/config/path-sensorconfig.go +++ b/config/path-sensorconfig.go @@ -4,12 +4,13 @@ import ( "path" ocmsc "git.loafle.net/overflow/commons-go/model/sensorconfig" + "strings" ) func SensorConfigContainerDir(name string) string { - return path.Join(ConfigDir(), name) + return path.Join(ConfigDir(), "container", name) } func SensorConfigFilePath(sensorConfig *ocmsc.SensorConfig) string { - return path.Join(SensorConfigContainerDir(sensorConfig.Crawler.MetaCrawlerContainerKey), sensorConfig.SensorID.String()) + return path.Join(SensorConfigContainerDir(strings.ToLower(sensorConfig.Crawler.MetaCrawlerContainerKey)), sensorConfig.SensorID.String()) } diff --git a/service/SensorConfigService.go b/service/SensorConfigService.go index f766285..2b33463 100644 --- a/service/SensorConfigService.go +++ b/service/SensorConfigService.go @@ -19,9 +19,9 @@ import ( // For annotation _ "git.loafle.net/overflow/commons-go/core/annotation" - "crypto/cipher" - "crypto/des" "bytes" + "crypto/des" + "errors" ) var SensorConfigServiceType = reflect.TypeOf((*SensorConfigService)(nil)) @@ -87,20 +87,25 @@ func (s *SensorConfigService) SendInitConfig(containerType occp.ContainerType) e func (s *SensorConfigService) AddConfig(tempFilePath string) error { //sc, buf, err := s.loadConfigFile(tempFilePath) - sc, buf, err := s.loadConfigFile1(tempFilePath) + sc, _, err := s.loadConfigFile1(tempFilePath) if nil != err { return err } targetPath := config.SensorConfigFilePath(sc) - ioutil.WriteFile(targetPath, buf, 0644) + err = ioutil.WriteFile(targetPath, []byte(tempFilePath), 0644) - // tempfile remove - err = os.Remove(tempFilePath) if nil != err { - return err + fmt.Println(err.Error()) } + fmt.Println(sc.SensorID) + // tempfile remove + //err = os.Remove(tempFilePath) + //if nil != err { + // return err + //} + //s.sensorConfigs[sc.ID.String()] = sc //s.sortSensorConfigPerContainer() // @@ -223,29 +228,53 @@ func (s *SensorConfigService) loadConfigFile(filePath string) (*ocmsc.SensorConf func (s *SensorConfigService) loadConfigFile1(decodeStr string) (*ocmsc.SensorConfig, []byte, error) { //keyStr := s.ProbeClientService.EncryptionKey - keyStr := "$2a$10$rPZYValfYvsVb8oDDz7gkuuf1FpqVnG8xbxQa.NhKdH7WDi.H2UD." + configStrByte := []byte(decodeStr) + + keyStr := "aaaaaaaa" key := []byte(keyStr) - iv := []byte(keyStr) block, err := des.NewCipher(key) if nil != err { + fmt.Println(err.Error()) return nil, nil, err } - blockMode := cipher.NewCBCDecrypter(block, iv) - origData := make([]byte, len(decodeStr)) - blockMode.CryptBlocks(origData, []byte(decodeStr)) - origData = s.PKCS5UnPadding(origData) - gr, err := gzip.NewReader(bytes.NewBuffer(origData)) + out := make([]byte, len(decodeStr)) + dst := out + bs := block.BlockSize() + if len(decodeStr)%bs != 0 { + return nil, nil, errors.New("crypto/cipher: input not full blocks") + } + + for len(configStrByte) > 0 { + block.Decrypt(dst, configStrByte[:bs]) + configStrByte = configStrByte[bs:] + dst = dst[bs:] + } + + out = s.PKCS5UnPadding(out) + + //fmt.Println(string(out)) + gr, err := gzip.NewReader(bytes.NewBuffer(out)) + if nil != err { + fmt.Println(err.Error()) + } + + //if b, err := ioutil.ReadAll(gr); err == nil { + // fmt.Println(string(b)) + //} + defer gr.Close() data, err := ioutil.ReadAll(gr) + fmt.Println(string(data)) var m = &ocmsc.SensorConfig{} if err := json.Unmarshal(data, m); nil != err { + fmt.Println(err.Error()) return nil, nil, err } - fmt.Println(string(data)) + //fmt.Println(string(data)) return m, data, nil } diff --git a/service/SensorService.go b/service/SensorService.go index 1c500c9..162a875 100644 --- a/service/SensorService.go +++ b/service/SensorService.go @@ -1,7 +1,6 @@ package service import ( - b64 "encoding/base64" "reflect" cda "git.loafle.net/commons/di-go/annotation" @@ -10,6 +9,7 @@ import ( // For annotation _ "git.loafle.net/overflow/commons-go/core/annotation" + "encoding/base64" ) var SensorServiceType = reflect.TypeOf((*SensorService)(nil)) @@ -55,13 +55,24 @@ func (s *SensorService) AddSensor(sensorConfigBase64 string) error { // base64 decode - bufByte, err := b64.StdEncoding.DecodeString(sensorConfigBase64) + //ddd := []byte(sensorConfigBase64) + //ff := make([]byte,len(ddd)) + + //fmt.Println(ddd) + + bufByte, err := base64.StdEncoding.DecodeString(sensorConfigBase64) + //bufByte := base64.NewDecoder(base64.StdEncoding, bytes.NewBufferString(sensorConfigBase64)) + //bufByte, err := b64.RawStdEncoding.DecodeString(sensorConfigBase64) + + //n, err := b64.StdEncoding.Decode(ff, ddd) + //fmt.Println(n) if nil == bufByte || nil != err { return err } - s.SensorConfigService.AddConfig(string(bufByte[:])) + //b, _ := ioutil.ReadAll(bufByte) + s.SensorConfigService.AddConfig(string(bufByte)) return nil } diff --git a/service/SensorService_test.go b/service/SensorService_test.go index 7e47a57..b2b7213 100644 --- a/service/SensorService_test.go +++ b/service/SensorService_test.go @@ -6,7 +6,7 @@ import ( ) func TestSensorService_AddSensor(t *testing.T) { - config := "o8rZu/ncU9dJ+0ryZ9fhy/WfBuSPHBlcdXMMvF8zEcAvRLlS/7b2iUduR9Z+8cGNPR8+fCvPNwgQb2JE2iHeQU6Dno3niWsp7sKC8KYpSPdB3B7QsqQ7Z4Svd4spmDgdxvggwceql1oFAfahQwGGnMxw8bt/phogtiDwo/jhDGGjfXvp9H4nlTjRIkHOC8w3pWWtjbvyb5ELn53YnaiQmzkFSUyz1Cs0IQzDorgvogz2rwmYmOw5kCepFDdnPVgtAsoxrhKrzg92SuyKcrZWGoPjgsl2PJ1ywojwEBgQ96cHIa0mxdC43qTrYbZ5o9+LXdIW9mewvfse8O+/yx8XzOHkZlONC9RtAIcYgoHiJS40ITp0XO7seg==" + config := "pT1QAThXECRfY+Vqe0PpaDrI5TlJ+Psf0AyM5JWiHlHHEr0oZsq8z5L01BnXV4LDHtMXGB0wDb2+L+4SDxk/zM57b7dGHt76ibmZ/R6jPXF8EZYgORbNcyy+m60sesk8fK23unH4Wc1Gqf5ekxTyYjupQ6ZSQbmdFk/WJM3iYy20G8JN3gsHHZtWVCDRVzhQU8sAg+UQ4voSlN3hWajAN8sZFL0HDSba7CjDX3rp9Z7K7VoZCkBsti9b7Z/WhFjHV23zoO786ZhKc8M8lYa69eCgcDDX4zYGJ5RUHnzLFwYkZ6GAoVX0NM8nCA8+yk59CbEcWS1qjR9Xv2C32PuZq8oWOhVW1xiXQDBD1hhAv+3c+m4gZmpHZQ==" s := &SensorService{} err := s.AddSensor(config)