public void TotalTest() { const int max = 5; //制限回数5回 var sec = 1; //期間1秒 var ip = new Ip("192.168.0.1"); var o = new AttackDb(sec, max); for (int i = 0; i < max - 1; i++) { Assert.AreEqual(o.IsInjustice(false, ip), false); } Assert.AreEqual(o.IsInjustice(false, ip), true); //maxを超えると不正アクセスと判断される Assert.AreEqual(o.IsInjustice(true, ip), false); //認証成功(蓄積された情報は破棄される) Assert.AreEqual(o.IsInjustice(false, ip), false); //正常アクセス 1回目の失敗 o = new AttackDb(sec, max); for (int i = 0; i < max - 1; i++) { Assert.AreEqual(o.IsInjustice(false, ip), false); } Thread.Sleep(1000); //1秒経過(蓄積された情報は時間経過で破棄される) Assert.AreEqual(o.IsInjustice(false, ip), false); //不正アクセス sec = 2;//期間を2秒に設定する o = new AttackDb(sec, max); for (int i = 0; i < max - 1; i++) { Assert.AreEqual(o.IsInjustice(false, ip), false); } Thread.Sleep(1000); //1秒経過 Assert.AreEqual(o.IsInjustice(false, ip), true); //指定時間が経過していない場合、不正アクセスと判断される }
private readonly AttackDb _attackDb; //�������� //�R���X�g���N�^ public Server(Kernel kernel, Conf conf, OneBind oneBind) : base(kernel, conf, oneBind) { //Ver5.8.9 if (kernel.RunMode == RunMode.Normal || kernel.RunMode == RunMode.Service) { //���[���{�b�N�X�̏�������Ԋm�F if (kernel.MailBox == null || !kernel.MailBox.Status) { Logger.Set(LogKind.Error, null, 4, ""); } } var useAutoAcl = (bool)Conf.Get("useAutoAcl"); // ACL���ۃ��X�g�֎����lj����� if (!useAutoAcl) { return; } var max = (int)Conf.Get("autoAclMax"); // �F�؎��s���i��j var sec = (int)Conf.Get("autoAclSec"); // �Ώۊ���(�b) _attackDb = new AttackDb(sec, max); }
//通常のServerThreadの子クラスと違い、オプションはリストで受け取る //親クラスは、そのリストの0番目のオブジェクトで初期化する //コンストラクタ public Server(Kernel kernel, Conf conf, OneBind oneBind) : base(kernel, conf, oneBind) { //同一ポートで待ち受けている仮想サーバのオプションをすべてリストする WebOptionList = new List <OneOption>(); foreach (var o in kernel.ListOption) { if (o.NameTag.IndexOf("Web-") == 0) { if ((int)o.GetValue("port") == (int)Conf.Get("port")) { WebOptionList.Add(o); } } } //WebDAVリストの初期化 foreach (var o in WebOptionList) { if (o.UseServer) { _webDavDbList.Add(new WebDavDb(kernel, NameTag)); } } _webDavDb = _webDavDbList[0]; //Ver5.1.2「Cgiパス」「WebDAVパス」「別名」のオプションの修正 var tagList = new List <string> { "cgiPath", "webDavPath", "aliaseList" }; foreach (string tag in tagList) { var dat = (Dat)Conf.Get(tag); var changed = false; foreach (var o in dat) { var str = o.StrList[0]; if (str[0] != '/') { changed = true; str = '/' + str; } if (str.Length > 1 && str[str.Length - 1] != '/') { changed = true; str = str + '/'; } o.StrList[0] = str; } if (changed) { Conf.Set(tag, dat); } } //当初、opBase及びloggerは、weboptionList[0]で暫定的に初期化される var protocol = (int)Conf.Get("protocol"); if (protocol == 1)//HTTPS { var op = kernel.ListOption.Get("VirtualHost"); var privateKeyPassword = (string)op.GetValue("privateKeyPassword"); var certificate = (string)op.GetValue("certificate"); //サーバ用SSLの初期化 ssl = new Ssl(Logger, certificate, privateKeyPassword); } var useAutoAcl = (bool)Conf.Get("useAutoAcl");// ACL拒否リストへ自動追加する if (useAutoAcl) { const int max = 1; //発生回数 const int sec = 120; // 対象期間(秒) _attackDb = new AttackDb(sec, max); } }