Пример #1
0
        public ActionResult StorePackets([FromBody] JToken json)
        {
            if (!Request.Headers.ContainsKey("Authorization"))
            {
                return(CreateResponse("No authorization header present"));
            }

            string token = Request.Headers.FirstOrDefault(x => x.Key == "Authorization").Value;

            if (string.IsNullOrWhiteSpace(token))
            {
                return(CreateResponse("No valid token present"));
            }

            User user = AuthorizeCore.Instance.AuthorizeToken(token);

            if (user == null)
            {
                return(CreateResponse("Unable to authorize given token"));
            }

            if (json == null || json.Type == JTokenType.Null)
            {
                return(CreateResponse("Unable to verify json"));
            }

            DataResult <Packet> dr = dataCore.StorePackets(json, user.Id);

            Settings    settings = UserCore.Instance.GetSettings(user.Id);
            List <Rule> rules    = dataCore.GetRules(user.Id);

            PacketAnalyser         pa          = new PacketAnalyser(rules, settings, Cache);
            List <PacketFormatted> pFormatList = pa.Analyse(dr.Data);

            DataResult <PacketFormatted> drpFormat = dataCore.StorePacketsFormatted(pFormatList);

            Detector detector = new Detector(Cache, settings);

            detector.DetectSynFlood(pFormatList);
            detector.DetectPingSweep(pFormatList);
            detector.DetectPortScan(pFormatList);

            return(CreateResponse(drpFormat.ErrorMessage, success: drpFormat.Success));
        }