This commit is contained in:
geek 2018-07-02 21:22:45 +09:00
parent d8d6198c44
commit 3efb90627d
8 changed files with 72 additions and 22 deletions

11
Gopkg.lock generated
View File

@ -87,7 +87,7 @@
"model/sensorconfig", "model/sensorconfig",
"service/probe" "service/probe"
] ]
revision = "54725b74e13a501d7a13a76a82c294769729748d" revision = "904de1632643ddb9c8862cd5bf147570c1a59878"
[[projects]] [[projects]]
name = "github.com/BurntSushi/toml" name = "github.com/BurntSushi/toml"
@ -135,13 +135,22 @@
[[projects]] [[projects]]
name = "github.com/shirou/gopsutil" name = "github.com/shirou/gopsutil"
packages = [ packages = [
"cpu",
"host", "host",
"internal/common", "internal/common",
"mem",
"net",
"process" "process"
] ]
revision = "4a180b209f5f494e5923cfce81ea30ba23915877" revision = "4a180b209f5f494e5923cfce81ea30ba23915877"
version = "v2.18.06" version = "v2.18.06"
[[projects]]
branch = "master"
name = "github.com/shirou/w32"
packages = ["."]
revision = "bb4de0191aa41b5507caa14b0650cdbddcd9280b"
[[projects]] [[projects]]
name = "github.com/valyala/fasthttp" name = "github.com/valyala/fasthttp"
packages = [ packages = [

View File

@ -4,12 +4,13 @@ import (
"path" "path"
ocmsc "git.loafle.net/overflow/commons-go/model/sensorconfig" ocmsc "git.loafle.net/overflow/commons-go/model/sensorconfig"
"strings"
) )
func SensorConfigContainerDir(name string) string { func SensorConfigContainerDir(name string) string {
return path.Join(ConfigDir(), name) return path.Join(ConfigDir(), "container", name)
} }
func SensorConfigFilePath(sensorConfig *ocmsc.SensorConfig) string { 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())
} }

View File

@ -19,9 +19,9 @@ import (
// For annotation // For annotation
_ "git.loafle.net/overflow/commons-go/core/annotation" _ "git.loafle.net/overflow/commons-go/core/annotation"
"crypto/cipher"
"crypto/des"
"bytes" "bytes"
"crypto/des"
"errors"
) )
var SensorConfigServiceType = reflect.TypeOf((*SensorConfigService)(nil)) 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 { func (s *SensorConfigService) AddConfig(tempFilePath string) error {
//sc, buf, err := s.loadConfigFile(tempFilePath) //sc, buf, err := s.loadConfigFile(tempFilePath)
sc, buf, err := s.loadConfigFile1(tempFilePath) sc, _, err := s.loadConfigFile1(tempFilePath)
if nil != err { if nil != err {
return err return err
} }
targetPath := config.SensorConfigFilePath(sc) 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 { 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.sensorConfigs[sc.ID.String()] = sc
//s.sortSensorConfigPerContainer() //s.sortSensorConfigPerContainer()
// //
@ -223,29 +228,53 @@ func (s *SensorConfigService) loadConfigFile(filePath string) (*ocmsc.SensorConf
func (s *SensorConfigService) loadConfigFile1(decodeStr string) (*ocmsc.SensorConfig, []byte, error) { func (s *SensorConfigService) loadConfigFile1(decodeStr string) (*ocmsc.SensorConfig, []byte, error) {
//keyStr := s.ProbeClientService.EncryptionKey //keyStr := s.ProbeClientService.EncryptionKey
keyStr := "$2a$10$rPZYValfYvsVb8oDDz7gkuuf1FpqVnG8xbxQa.NhKdH7WDi.H2UD." configStrByte := []byte(decodeStr)
keyStr := "aaaaaaaa"
key := []byte(keyStr) key := []byte(keyStr)
iv := []byte(keyStr)
block, err := des.NewCipher(key) block, err := des.NewCipher(key)
if nil != err { if nil != err {
fmt.Println(err.Error())
return nil, nil, err 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() defer gr.Close()
data, err := ioutil.ReadAll(gr) data, err := ioutil.ReadAll(gr)
fmt.Println(string(data))
var m = &ocmsc.SensorConfig{} var m = &ocmsc.SensorConfig{}
if err := json.Unmarshal(data, m); nil != err { if err := json.Unmarshal(data, m); nil != err {
fmt.Println(err.Error())
return nil, nil, err return nil, nil, err
} }
fmt.Println(string(data)) //fmt.Println(string(data))
return m, data, nil return m, data, nil
} }

View File

@ -1,7 +1,6 @@
package service package service
import ( import (
b64 "encoding/base64"
"reflect" "reflect"
cda "git.loafle.net/commons/di-go/annotation" cda "git.loafle.net/commons/di-go/annotation"
@ -10,6 +9,7 @@ import (
// For annotation // For annotation
_ "git.loafle.net/overflow/commons-go/core/annotation" _ "git.loafle.net/overflow/commons-go/core/annotation"
"encoding/base64"
) )
var SensorServiceType = reflect.TypeOf((*SensorService)(nil)) var SensorServiceType = reflect.TypeOf((*SensorService)(nil))
@ -55,13 +55,24 @@ func (s *SensorService) AddSensor(sensorConfigBase64 string) error {
// base64 decode // 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 { if nil == bufByte || nil != err {
return err return err
} }
s.SensorConfigService.AddConfig(string(bufByte[:])) //b, _ := ioutil.ReadAll(bufByte)
s.SensorConfigService.AddConfig(string(bufByte))
return nil return nil
} }

View File

@ -6,7 +6,7 @@ import (
) )
func TestSensorService_AddSensor(t *testing.T) { 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{} s := &SensorService{}
err := s.AddSensor(config) err := s.AddSensor(config)