diff options
| -rw-r--r-- | cmd/root.go | 2 | ||||
| -rw-r--r-- | comm/commget.go | 6 | ||||
| -rw-r--r-- | conf.yaml | 4 | ||||
| -rw-r--r-- | model/comm_model.go | 2 | ||||
| -rw-r--r-- | model/comm_model_test.go | 4 | ||||
| -rw-r--r-- | model/rule_model.go | 2 | ||||
| -rw-r--r-- | router/comm_endpoint.go | 3 | ||||
| -rw-r--r-- | router/router.go | 7 | ||||
| -rw-r--r-- | router/rule_endpoint.go | 30 | ||||
| -rw-r--r-- | rules/rules.go | 2 | ||||
| -rw-r--r-- | rules/rulestype_test.go | 2 | ||||
| -rw-r--r-- | yaml/yaml.go | 20 |
12 files changed, 64 insertions, 20 deletions
diff --git a/cmd/root.go b/cmd/root.go index 3c93ff0..e9b04db 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,7 +1,7 @@ /* * @Author: EnderByEndera * @Date: 2020-12-19 11:59:02 - * @LastEditTime: 2021-01-15 07:16:12 + * @LastEditTime: 2021-02-01 06:53:44 * @LastEditors: Please set LastEditors * @Description: root of the commdetection cmd * @FilePath: /commdetection/cmd/root.go diff --git a/comm/commget.go b/comm/commget.go index d628c3e..9bc6094 100644 --- a/comm/commget.go +++ b/comm/commget.go @@ -1,7 +1,7 @@ /* * @Author: EnderByEndera * @Date: 2020-12-02 17:08:59 - * @LastEditTime: 2021-01-16 08:39:11 + * @LastEditTime: 2021-02-01 06:54:12 * @LastEditors: Please set LastEditors * @Description: Get commands from file or network * @FilePath: /commdetection/preprocessing/commget.go @@ -13,6 +13,7 @@ import ( "bytes" "commdetection/logger" "commdetection/model" + "commdetection/yaml" "io/ioutil" "os/exec" "sort" @@ -92,10 +93,9 @@ func commandsFromString(s string) model.Commands { return commands } -// TODO: will promote it later func getCommandsFromDB() (model.Commands, error) { commands := new(model.Commands) - commands.GetCommandsFrom("test", "commands") + commands.GetCommandsFrom(yaml.GetMongoSetting().Db, yaml.GetMongoSetting().Collection) return *commands, nil } @@ -2,4 +2,6 @@ gin: ginmode: release port: 8060 mongo: - timeout: 10s
\ No newline at end of file + host: 101.37.27.155 + timeout: 10s + port: 27017
\ No newline at end of file diff --git a/model/comm_model.go b/model/comm_model.go index f89b6c5..0093fdb 100644 --- a/model/comm_model.go +++ b/model/comm_model.go @@ -1,7 +1,7 @@ /* * @Author: your name * @Date: 2021-01-06 09:56:18 - * @LastEditTime: 2021-01-19 12:02:23 + * @LastEditTime: 2021-02-01 06:46:53 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: /commdetection/model/comm_model.go diff --git a/model/comm_model_test.go b/model/comm_model_test.go index a3a97ff..a8df7f9 100644 --- a/model/comm_model_test.go +++ b/model/comm_model_test.go @@ -1,7 +1,7 @@ /* * @Author: EnderByEndera * @Date: 2021-01-06 15:26:48 - * @LastEditTime: 2021-01-19 11:57:21 + * @LastEditTime: 2021-02-01 07:03:10 * @LastEditors: Please set LastEditors * @Description: test mongo.go * @FilePath: /commdetection/model/mongo_test.go @@ -108,7 +108,7 @@ func TestDeleteCommandsFromMongo(t *testing.T) { User: "root", }, } - err := commands.InsertAnyTo("test", "commands", 0) + err := commands.InsertAllTo("test", "commands") if err != nil { t.Error(err) } diff --git a/model/rule_model.go b/model/rule_model.go index 92cc77d..17f3c57 100644 --- a/model/rule_model.go +++ b/model/rule_model.go @@ -1,7 +1,7 @@ /* * @Author: EnderByEndera * @Date: 2021-01-04 16:30:53 - * @LastEditTime: 2021-01-12 11:53:39 + * @LastEditTime: 2021-02-01 06:23:02 * @LastEditors: Please set LastEditors * @Description: This is the model file used for rules pack * @FilePath: /commdetection/model/rule_model.go diff --git a/router/comm_endpoint.go b/router/comm_endpoint.go index 1054b5f..cc43419 100644 --- a/router/comm_endpoint.go +++ b/router/comm_endpoint.go @@ -1,11 +1,12 @@ /* * @Author: EnderByEndera * @Date: 2021-01-16 08:14:22 - * @LastEditTime: 2021-01-16 08:16:11 + * @LastEditTime: 2021-02-01 06:27:20 * @LastEditors: Please set LastEditors * @Description: comm_endpoint.go has the function for all the commands' endpoint * @FilePath: /commdetection/router/comm_endpoint.go */ + package router import ( diff --git a/router/router.go b/router/router.go index 8c08a7b..583b10f 100644 --- a/router/router.go +++ b/router/router.go @@ -1,7 +1,7 @@ /* * @Author: EnderByEndera * @Date: 2020-12-23 13:17:08 - * @LastEditTime: 2021-01-19 12:06:31 + * @LastEditTime: 2021-02-01 06:27:01 * @LastEditors: Please set LastEditors * @Description: router.go defines gin.Engine and its router * @FilePath: /commdetection/route/router.go @@ -96,6 +96,11 @@ func manageRouter() { pathr.POST("/set", setPathrulesEndpoint) pathr.GET("/get", getPathrulesEndpoint) } + usiter := router.Group("/websiterules") + { + usiter.POST("/set", setWebsiteRuleEndpoint) + usiter.GET("/get", getWebsiteRuleEndpoint) + } rsr := router.Group("/rules") { rsr.POST("/set", setEvaluationRulesEndpoint) diff --git a/router/rule_endpoint.go b/router/rule_endpoint.go index d8bc59f..15df06f 100644 --- a/router/rule_endpoint.go +++ b/router/rule_endpoint.go @@ -1,7 +1,7 @@ /* * @Author: EnderByEndera * @Date: 2021-01-16 08:12:49 - * @LastEditTime: 2021-01-16 08:16:53 + * @LastEditTime: 2021-02-01 06:26:33 * @LastEditors: Please set LastEditors * @Description: rule_endpoint has the function for all the command rules' endpoint, including getter and setter * @FilePath: /commdetection/router/rule_endpoint.go @@ -135,3 +135,31 @@ func setEvaluationRulesEndpoint(c *gin.Context) { "message": "ok", }) } + +func getWebsiteRuleEndpoint(c *gin.Context) { + ussites, err := model.UnMarshalUnsensitiveWebsiteSetting() + if err != nil { + handleErr(c, err) + return + } + logger.Debugln("Start to send spaths to the front end") + c.JSON(http.StatusOK, gin.H{ + "message": "ok", + "ussites": ussites, + }) +} + +func setWebsiteRuleEndpoint(c *gin.Context) { + ussites := model.Ussites{} + if err := c.ShouldBind(&ussites); err != nil { + handleErr(c, err) + return + } + if err := model.MarshalUnsensitiveWebsiteSetting(ussites); err != nil { + handleErr(c, err) + return + } + c.JSON(http.StatusOK, gin.H{ + "message": "ok", + }) +} diff --git a/rules/rules.go b/rules/rules.go index 4929551..d7be658 100644 --- a/rules/rules.go +++ b/rules/rules.go @@ -1,7 +1,7 @@ /* * @Author: EnderByEndera * @Date: 2020-12-04 15:03:00 - * @LastEditTime: 2021-01-05 17:58:28 + * @LastEditTime: 2021-02-01 06:16:38 * @LastEditors: Please set LastEditors * @Description: rules provide all the rules to check the commands' availability and set score of every command * @FilePath: /commdetection/rules/commcheck.go diff --git a/rules/rulestype_test.go b/rules/rulestype_test.go index dcc70ba..a608e88 100644 --- a/rules/rulestype_test.go +++ b/rules/rulestype_test.go @@ -1,7 +1,7 @@ /* * @Author: EnderByEndera * @Date: 2020-12-08 11:28:49 - * @LastEditTime: 2021-01-06 09:59:40 + * @LastEditTime: 2021-02-01 06:17:11 * @LastEditors: Please set LastEditors * @Description: Test UnmarshalSetting and MarshalSetting * @FilePath: /commdetection/rules/rulestype_test.go diff --git a/yaml/yaml.go b/yaml/yaml.go index 002a7ef..aa67337 100644 --- a/yaml/yaml.go +++ b/yaml/yaml.go @@ -1,7 +1,7 @@ /* * @Author: EnderByEndera * @Date: 2020-12-09 16:44:44 - * @LastEditTime: 2021-01-06 12:40:04 + * @LastEditTime: 2021-02-01 06:43:21 * @LastEditors: Please set LastEditors * @Description: Init settings from yaml file * @FilePath: /commdetection/init/init.go @@ -22,11 +22,13 @@ import ( // MongoSet is the setting for the mongo db connection type MongoSet struct { - Host string `yaml:"host"` - Port uint16 `yaml:"port"` - User string `yaml:"user"` - Pwd string `yaml:"password"` - Timeout string `yaml:"timeout"` + Host string `yaml:"host"` + Port uint16 `yaml:"port"` + Db string `yaml:"db"` + Collection string `yaml:"collection"` + User string `yaml:"user"` + Pwd string `yaml:"password"` + Timeout string `yaml:"timeout"` } // RulePaths is the rule paths @@ -76,6 +78,12 @@ func GetMongoSetting() MongoSet { if conf.Mongo.Timeout == "" { conf.Mongo.Timeout = "30s" } + if conf.Mongo.Db == "" { + conf.Mongo.Db = "test" + } + if conf.Mongo.Collection == "" { + conf.Mongo.Collection = "commands" + } return conf.Mongo } |
