Exemple #1
0
        // Delete all packets from specified time (within minute)
        public IActionResult PacketDeleteFromTime(long?id)
        {
            if (!id.HasValue)
            {
                return(NotFound());
            }

            DateTime time = new DateTime(id.Value);

            var packets = from packet in _context.Packet
                          where packet.DateTime.Day == time.Day &&
                          packet.DateTime.Hour == time.Hour &&
                          packet.DateTime.Minute == time.Minute
                          select packet;

            _context.Packet.RemoveRange(packets);
            _context.SaveChanges();

            AddAudit($"Delete - {packets.ToList().Count} packets from time {time.AddHours(NetworkVisualizer.Config.config.UTCHoursOffset)}");
            return(Redirect("~/packets"));
        }
Exemple #2
0
        private void AddAudit(string Action)
        {
            var identity = User.Identity as ClaimsIdentity; // Azure AD V2 endpoint specific

            _context.Audit.Add(new Audit
            {
                DateTime = DateTime.UtcNow,
                Username = identity.Claims.FirstOrDefault(c => c.Type == "preferred_username")?.Value,
                Action   = Action
            });

            _context.SaveChanges();
        }
        public string Index(string password, string json)
        {
            // Check password and reject if mismatch
            if (password != Config.config.HttpPostPassword)
            {
                return("Mismatched password.");
            }

            // Get list of pseudopacket-objects from json
            List <Tuple <string, string, string> > packets =
                JsonConvert.DeserializeObject <List <Tuple <string, string, string> > >(json);

            // Convert to Packet, add to DB
            foreach (Tuple <string, string, string> packet in packets)
            {
                Packet newPacket = new Packet
                {
                    DateTime            = DateTime.UtcNow,
                    PacketType          = packet.Item1,
                    DestinationHostname = packet.Item2,
                    OriginHostname      = packet.Item3
                };

                if (ModelState.IsValid)
                {
                    _context.Packet.Add(newPacket);
                }
            }

            // Add an audit
            _context.Audit.Add(new Audit
            {
                DateTime = DateTime.UtcNow,
                Username = "******",
                Action   = "Recieved packets"
            });
            _context.SaveChanges();
            return("Operation successful.");
        }