Ejemplo n.º 1
0
        public void DeleteBlockedIP(BlockedIP ip)
        {
            if (ip == null)
            {
                throw new ArgumentNullException(nameof(ip));
            }

            _context.BlockedIPs.Remove(ip);
        }
Ejemplo n.º 2
0
        public void CreateBlockedIP(BlockedIP ip)
        {
            if (ip == null)
            {
                throw new ArgumentNullException(nameof(ip));
            }

            _context.BlockedIPs.Add(ip);
        }
Ejemplo n.º 3
0
        public static DialogResult Show(Form owner, int blockedIPID, BlockedIP blockedIPs)
        {
            BlockedIPDetail frm = new BlockedIPDetail();

            frm.BlockedIPsID = blockedIPID;
            frm.BlockedIPs   = blockedIPs;
            DialogResult result = frm.ShowDialog(owner);

            return(result);
        }
Ejemplo n.º 4
0
        public async Task <BlockedIP> CreateAsync(BlockedIP model)
        {
            try
            {
                this.Context.BlockedIP.Add(model);
                await this.Context.SaveChangesAsync();

                return(model);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex);
                throw new Exception("DB error", ex.InnerException);
            }
        }
Ejemplo n.º 5
0
        public static BlockedIP GetBlockedIPByID(int blockedIPID)
        {
            Kv kv = new Kv();

            kv.Set("MethodName", (int)MethodNameE.GetBlockedIPByID);
            kv.Set(StdKv.CurrentUserID, Ap.CurrentUserID);
            kv.Set("BlockedIPID", blockedIPID);

            DataSet ds = SocketClient.Instance.Invoke(kv.DataTable);

            if (ds == null)
            {
                return(null);
            }

            if (ds.Tables.Count == 0)
            {
                return(null);
            }

            if (ds.Tables[0].Rows.Count == 0)
            {
                return(null);
            }

            BlockedIP i = new BlockedIP(Ap.Cxt, ds.Tables[0].Rows[0]);

            if (blockedIPID > 0)
            {
                ds.Tables[0].Rows[0].AcceptChanges();
                ds.Tables[1].Rows[0].AcceptChanges();

                User u = new User(Ap.Cxt, ds.Tables[1].Rows[0]);

                i.CreatedUser = u;
            }

            return(i);
        }
Ejemplo n.º 6
0
        public ActionResult PostBlockedIp([FromBody] BlockedIP blockedIP)
        {
            try
            {
                Response response = new Response();
                blockedIP.StreamKey = blockedIP.url.ToString().Replace("/live/", "");
                blockedIP.Id        = 0;
                db.blockedIPs.Add(blockedIP);
                db.SaveChanges();
                response.Data    = blockedIP;
                response.Status  = true;
                response.Message = " Create successfully";


                return(Ok(response));
            }

            catch (Exception e)
            {
                writeException.Write(e.Message, DateTime.Now, "Customer", "Post", "Admin");
                return(this.NotFound("Dosnt Create successfully"));
            }
        }
Ejemplo n.º 7
0
        public JsonResult Add(string value, string Description, int BlockingTimeDay, TypeBlockIP typeBlockIP = TypeBlockIP.global, bool IsAPI = false)
        {
            #region Демо режим
            if (Platform.IsDemo)
            {
                return(Json(new Text("Операция недоступна в демо-режиме")));
            }
            #endregion

            // Коректировка
            if (typeBlockIP == TypeBlockIP.domain)
            {
                typeBlockIP = TypeBlockIP.global;
            }

            // Коректор времени
            if (BlockingTimeDay <= 0)
            {
                BlockingTimeDay = 1;
            }

            #region Проверка IP/UserAgent
            if (typeBlockIP == TypeBlockIP.global)
            {
                // IP-адрес
                string IP = value;

                // Проверка IP
                if (!IPNetwork.CheckingSupportToIPv4Or6(IP, out _))
                {
                    return(Json(new Text($"Not supported format: {IP}")));
                }

                // Записываем IP в кеш IPtables
                IPtables.AddIPv4Or6(IP, new ModelIPtables(Description, DateTime.Now.AddDays(BlockingTimeDay)), typeBlockIP);
            }
            else
            {
                // Проверка UserAgent
                if (string.IsNullOrWhiteSpace(value))
                {
                    return(Json(new Text("Поле 'Значение' имеет недопустимое значение")));
                }
            }
            #endregion

            // Дублируем информацию в SQL
            var blockedIP = new BlockedIP()
            {
                IP           = value,
                Description  = Description,
                BlockingTime = DateTime.Now.AddDays(BlockingTimeDay),
                typeBlockIP  = typeBlockIP
            };
            coreDB.BlockedsIP.Add(blockedIP);

            // Сохраняем SQL
            coreDB.SaveChanges();

            // Кеш IPtables
            if (typeBlockIP == TypeBlockIP.UserAgent)
            {
                IPtables.UpdateCacheToUserAgent();
            }

            if (IsAPI)
            {
                return(Json(new TrueOrFalse(true)));
            }

            // Отдаем результат
            return(Json(new Html($@"<tr class='elemDelete'>
                                        <td class='text-left table-products'>
                                            <strong>{value}</strong>
                                        </td>

                                        <td>{(typeBlockIP == TypeBlockIP.global ? "IP-адрес" : "User Agent")}</td>
                                        <td>{Description}</td>
                                        <td>{DateTime.Now.AddDays(BlockingTimeDay).ToString("dd.MM.yyyy H:mm")}</td>

                                        <td style='text-align: right;' class='table-products btn-icons'>" +
                                 "<a onclick=\"return deleteElement(this,'/security/iptables/remove',{Id:'" + blockedIP.Id + "'});\" class=\"btn nopadding-nomargin\"><i class=\"fa fa-trash-o\"></i></a>" +
                                 @"</td>
                                    </tr>")));
        }
Ejemplo n.º 8
0
        public JsonResult Add(string value, string Description, int BlockingTimeDay, TypeBlockIP typeBlockIP = TypeBlockIP.global, bool IsAPI = false)
        {
            #region Демо режим
            if (Platform.IsDemo)
            {
                return(Json(new Text("Операция недоступна в демо-режиме")));
            }
            #endregion

            // Коректировка
            if (typeBlockIP == TypeBlockIP.domain)
            {
                typeBlockIP = TypeBlockIP.global;
            }

            // Коректор времени
            if (BlockingTimeDay <= 0)
            {
                BlockingTimeDay = 1;
            }

            #region Проверка IP/UserAgent
            if (typeBlockIP == TypeBlockIP.global)
            {
                // IP-адрес
                string IP = value;

                // Проверка IP
                if (string.IsNullOrWhiteSpace(IP) || (!IP.Contains(".") && !IP.Contains(":")))
                {
                    return(Json(new Models.Response.Text("Поле 'Значение' имеет недопустимое значение")));
                }

                // IP для кеша и проверки
                string IPshort = IP.Replace(".*", "").Replace(":*", "");

                // Проверка IP на дубликат
                if (IPtablesMiddleware.CheckIP(IPshort, memoryCache, out _))
                {
                    return(Json(new Models.Response.Text("Данный IP-адрес уже заблокирован")));
                }

                // Записываем IP в кеш IPtables
                memoryCache.Set(KeyToMemoryCache.IPtables(IPshort), new IPtables(Description, DateTime.Now.AddDays(BlockingTimeDay)), TimeSpan.FromDays(BlockingTimeDay));
            }
            else
            {
                // Проверка UserAgent
                if (string.IsNullOrWhiteSpace(value))
                {
                    return(Json(new Models.Response.Text("Поле 'Значение' имеет недопустимое значение")));
                }
            }
            #endregion

            // Дублируем информацию в SQL
            var blockedIP = new BlockedIP()
            {
                IP           = value,
                Description  = Description,
                BlockingTime = DateTime.Now.AddDays(BlockingTimeDay),
                typeBlockIP  = typeBlockIP
            };
            coreDB.BlockedsIP.Add(blockedIP);

            // Сохраняем SQL
            coreDB.SaveChanges();

            // Очистка кеша IPtables
            if (typeBlockIP == TypeBlockIP.UserAgent)
            {
                IPtablesMiddleware.ClearCache();
            }

            if (IsAPI)
            {
                return(Json(new TrueOrFalse(true)));
            }

            // Отдаем результат
            return(Json(new Html($@"<tr class='elemDelete'>
                                        <td class='text-left table-products'>
                                            <strong>{value}</strong>
                                        </td>

                                        <td>{(typeBlockIP == TypeBlockIP.global ? "IP-адрес" : "User Agent")}</td>
                                        <td>{Description}</td>
                                        <td>{DateTime.Now.AddDays(BlockingTimeDay).ToString("dd.MM.yyyy H:mm")}</td>

                                        <td style='text-align: right;' class='table-products btn-icons'>" +
                                 "<a onclick=\"return deleteElement(this,'/security/iptables/remove',{Id:'" + blockedIP.Id + "'});\" class=\"btn nopadding-nomargin\"><i class=\"fa fa-trash-o\"></i></a>" +
                                 @"</td>
                                    </tr>")));
        }