public static void NoResult(string sql, System.Data.CommandType type, IDataParameter[] param = null, string cnnString = null) { using (var p = new Devmasters.PersistLib()) { try { p.ExecuteNonQuery(defaultCnnStr, type, sql, param); } catch (Exception e) { HlidacStatu.Util.Consts.Logger.Error("SQL error:" + sql, e); throw; } } }
public static void SaveDumpProcessed(XML.indexDump dump, DateTime?processed, Exception ex = null) { string cnnStr = Devmasters.Config.GetWebConfigValue("CnnString"); string sql = @"INSERT INTO [dbo].[DumpData] ([Created] ,[Processed] ,[den] ,[mesic] ,[rok] ,[hash] ,[velikost] ,[casGenerovani], exception) VALUES (@Created ,@Processed ,@den ,@mesic ,@rok ,@hash ,@velikost ,@casGenerovani ,@exception) "; try { using (var p = new Devmasters.PersistLib()) { p.ExecuteNonQuery(cnnStr, System.Data.CommandType.Text, sql, new IDataParameter[] { new System.Data.SqlClient.SqlParameter("created", DateTime.Now), new System.Data.SqlClient.SqlParameter("processed", processed), new System.Data.SqlClient.SqlParameter("den", (int)dump.den), new System.Data.SqlClient.SqlParameter("mesic", (int)dump.mesic), new System.Data.SqlClient.SqlParameter("rok", (int)dump.rok), new System.Data.SqlClient.SqlParameter("hash", dump.hashDumpu.Value), new System.Data.SqlClient.SqlParameter("velikost", (long)dump.velikostDumpu), new System.Data.SqlClient.SqlParameter("casGenerovani", dump.casGenerovani), new System.Data.SqlClient.SqlParameter("exception", ex == null ? (string)null : ex.ToString()), }); } } catch (Exception e) { HlidacStatu.Util.Consts.Logger.Error("SaveDumpProcessed error", e); } }
void AutoAddBlackList(Controllers.HomeController.ErrorPages errPage, HttpRequest req) { bool add = false; var dt = DateTime.Now; string ip = req.UserHostAddress; lock (_autoAddBlackList) { if (!attackers.ContainsKey(ip)) { attackers.Add(ip, new attack() { ip = ip, last = DateTime.Now, num = 0 }); } } var att = attackers[ip]; var diff = (dt - att.last).TotalSeconds; if (diff >= 600) { att.num = 1; } else { att.num = att.num + 1; } switch (errPage) { case Controllers.HomeController.ErrorPages.Ok: break; case Controllers.HomeController.ErrorPages.NotFound: add = att.num > 20; break; case Controllers.HomeController.ErrorPages.Error: add = att.num > 15; break; case Controllers.HomeController.ErrorPages.ErrorHack: add = att.num > 10; break; default: break; } if (add) { HlidacStatu.Util.Consts.Logger.Warning($"added bannedIP {ip}"); try { using (Devmasters.PersistLib p = new Devmasters.PersistLib()) { p.ExecuteNonQuery(Devmasters.Config.GetWebConfigValue("CnnString"), System.Data.CommandType.Text, "INSERT INTO [dbo].[BannedIPs] ([IP],[Expiration],[Created]) " + " VALUES(@ip,@dat,GetDate())", new System.Data.IDataParameter[] { new System.Data.SqlClient.SqlParameter("ip", ip), new System.Data.SqlClient.SqlParameter("dat", dt.AddHours(6)) }); } BannedIPs.ForceRefreshCache(); } catch (Exception e) { HlidacStatu.Util.Consts.Logger.Warning($"added bannedIP {ip}", e); } } }