示例#1
0
        //サーバ(OneServer)の生成
        private void AddServer(Conf conf, OnePlugin onePlugin)
        {
            var protocol = (ProtocolKind)conf.Get("protocolKind");
            //ProtocolKind protocol = ProtocolKind.ValueOf((int) conf.Get("protocolKind"));

            BindAddr bindAddr = (BindAddr)conf.Get("bindAddress2");

            if (bindAddr.BindStyle != BindStyle.V4Only)
            {
                var oneBind = new OneBind(bindAddr.IpV6, protocol);
                var o       = onePlugin.CreateServer(kernel, conf, oneBind);
                if (o != null)
                {
                    Ar.Add((OneServer)o);
                }
            }
            if (bindAddr.BindStyle != BindStyle.V6Only)
            {
                var oneBind = new OneBind(bindAddr.IpV4, protocol);
                var o       = onePlugin.CreateServer(kernel, conf, oneBind);
                if (o != null)
                {
                    Ar.Add((OneServer)o);
                }
            }
        }
示例#2
0
        public void new及びstart_stop_disposeの繰り返し_負荷テスト_UDP()
        {
            var  ip      = new Ip(IpKind.V4Localhost);
            var  oneBind = new OneBind(ip, ProtocolKind.Udp);
            Conf conf    = TestUtil.CreateConf("OptionSample");

            conf.Set("port", 88);
            conf.Set("multiple", 10);
            conf.Set("acl", new Dat(new CtrlType[0]));
            conf.Set("enableAcl", 1);
            conf.Set("timeOut", 3);

            for (var i = 0; i < 5; i++)
            {
                var myServer = new MyServer(conf, oneBind);

                myServer.Start();
                Assert.That(myServer.ThreadBaseKind, Is.EqualTo(ThreadBaseKind.Running));
                Assert.That(myServer.SockState(), Is.EqualTo(SockState.Bind));

                myServer.Stop();
                Assert.That(myServer.ThreadBaseKind, Is.EqualTo(ThreadBaseKind.After));
                Assert.That(myServer.SockState(), Is.EqualTo(SockState.Error));

                myServer.Dispose();
            }
        }
示例#3
0
文件: Server.cs 项目: schifflee/bjd5
 public Server(Kernel kernel, Conf conf, OneBind oneBind) : base(kernel, conf, oneBind)
 {
     _bannerMessage = kernel.ChangeTag((String)Conf.Get("bannerMessage"));
     //���[�U���
     _listUser = new ListUser((Dat)Conf.Get("user"));
     //���z�t�H���_
     _listMount = new ListMount((Dat)Conf.Get("mountList"));
 }
示例#4
0
        public void OneServerを継承したEchoServer_TCP版_を使用して接続する()
        {
            const string addr    = "127.0.0.1";
            const int    port    = 9999;
            const int    timeout = 300;
            Ip           ip      = null;

            try{
                ip = new Ip(addr);
            } catch (ValidObjException ex) {
                Assert.Fail(ex.Message);
            }
            var oneBind = new OneBind(ip, ProtocolKind.Tcp);
            var conf    = TestUtil.CreateConf("OptionSample");

            conf.Set("port", port);
            conf.Set("multiple", 10);
            conf.Set("acl", new Dat(new CtrlType[0]));
            conf.Set("enableAcl", 1);
            conf.Set("timeOut", timeout);

            var echoServer = new EchoServer(conf, oneBind);

            echoServer.Start();

            //TCPクライアント

            const int max = 10000;
            var       buf = new byte[max];

            buf[8] = 100; //CheckData
            for (int i = 0; i < 3; i++)
            {
                var sockTcp = new SockTcp(new Kernel(), ip, port, timeout, null);

                sockTcp.Send(buf);

                while (sockTcp.Length() == 0)
                {
                    Thread.Sleep(2);
                }

                var len = sockTcp.Length();
                if (0 < len)
                {
                    var b = sockTcp.Recv(len, timeout, this);
                    Assert.That(b[8], Is.EqualTo(buf[8]));//CheckData
                }
                Assert.That(max, Is.EqualTo(len));

                sockTcp.Close();
            }

            echoServer.Dispose();
        }
示例#5
0
文件: Cgi.cs 项目: jsakamoto/bjd5
        public void SetUp()
        {
            utilDir = new UtilDir();
            utilOption = new UtilOption(utilDir);//オプション設定
            //ListOption ListServerの初期化を成功させるためには、Kernel生成の前にutilDirを生成する必要がある
            Kernel kernel = new Kernel(null, null, null, null, null);

            //サーバ起動
            OneBind oneBind = new OneBind(new Ip("127.0.0.1"), ProtocolKind.Tcp);
            server = new Server(kernel, nameTag, oneBind);
            server.Start();
        }
示例#6
0
文件: Server.cs 项目: deton/bjd5
        public Server(Kernel kernel, Conf conf, OneBind oneBind)
            : base(kernel, conf, oneBind)
        {
            _cache = new Cache(kernel, this.Logger, conf);

            // 上位プロキシを経由しないサーバのリスト
            foreach (var o in (Dat)Conf.Get("disableAddress"))
            {
                if (o.Enable)  //有効なデータだけを対象にする
                {
                    _disableAddressList.Add(o.StrList[0]);
                }
            }
            //URL制限
            var allow = (Dat)Conf.Get("limitUrlAllow");
            var deny  = (Dat)Conf.Get("limitUrlDeny");

            //Ver5.4.5正規表現の誤りをチェックする
            for (var i = 0; i < 2; i++)
            {
                foreach (var a in (i == 0) ? allow : deny)
                {
                    if (a.Enable && a.StrList[1] == "3")  //正規表現
                    {
                        try {
                            var regex = new Regex(a.StrList[0]);
                        } catch {
                            Logger.Set(LogKind.Error, null, 28, a.StrList[0]);
                        }
                    }
                }
            }
            _limitUrl = new LimitUrl(allow, deny);

            //アクセス元プログラム制限
            var allowProg = (Dat)Conf.Get("limitSrcProgAllow");
            var denyProg  = (Dat)Conf.Get("limitSrcProgDeny");

            _limitSrcProg = new LimitSrcProg(this.Logger, allowProg, denyProg);

            //リクエストを通常ログで表示する
            _useRequestLog = (bool)Conf.Get("useRequestLog");

            //コンテンツ制限
            _limitString = new LimitString((Dat)Conf.Get("limitString"));
            if (_limitString.Length == 0)
            {
                _limitString = null;
            }

            _dataPort = DataPortMin;
        }
示例#7
0
文件: Cgi.cs 项目: schifflee/bjd5
        public void SetUp()
        {
            utilDir    = new UtilDir();
            utilOption = new UtilOption(utilDir);//オプション設定
            //ListOption ListServerの初期化を成功させるためには、Kernel生成の前にutilDirを生成する必要がある
            Kernel kernel = new Kernel(null, null, null, null, null);

            //サーバ起動
            OneBind oneBind = new OneBind(new Ip("127.0.0.1"), ProtocolKind.Tcp);

            server = new Server(kernel, nameTag, oneBind);
            server.Start();
        }
示例#8
0
        public void Setup()
        {
            TestUtil.CopyLangTxt();//BJD.Lang.txt

            //設定ファイルの退避と上書き
            _op = new TmpOption("DhcpServerTest", "DhcpServerTest.ini");
            OneBind oneBind = new OneBind(new Ip(IpKind.V4Localhost), ProtocolKind.Udp);
            Kernel  kernel  = new Kernel();
            var     option  = kernel.ListOption.Get("Dhcp");
            Conf    conf    = new Conf(option);

            //サーバ起動
            _sv = new Server(kernel, conf, oneBind);
            _sv.Start();
        }
示例#9
0
文件: Server.cs 项目: schifflee/bjd5
        readonly string _wpadUrl;                //WPAD

        //�R���X�g���N�^
        public Server(Kernel kernel, Conf conf, OneBind oneBind)
            : base(kernel, conf, oneBind)
        {
            //�I�v�V�����̓ǂݍ���
            _maskIp    = (Ip)Conf.Get("maskIp");
            _gwIp      = (Ip)Conf.Get("gwIp");
            _dnsIp0    = (Ip)Conf.Get("dnsIp0");
            _dnsIp1    = (Ip)Conf.Get("dnsIp1");
            _leaseTime = (int)Conf.Get("leaseTime");
            if (_leaseTime <= 0)
            {
                _leaseTime = 86400;
            }
            if ((bool)Conf.Get("useWpad"))
            {
                _wpadUrl = (string)Conf.Get("wpadUrl");
            }


            //DB����
            string fileName = string.Format("{0}\\lease.db", kernel.ProgDir());
            var    startIp  = (Ip)Conf.Get("startIp");
            var    endIp    = (Ip)Conf.Get("endIp");

            _macAcl = (Dat)Conf.Get("macAcl");
            //�ݒ肪�����ꍇ�́A���Dat�𐶐�����
            if (_macAcl == null)
            {
                _macAcl = new Dat(new CtrlType[] { CtrlType.TextBox, CtrlType.AddressV4, CtrlType.TextBox });
            }

            //Ver5.6.8
            //�J�������u���O�i�\����)�v�𑝂₵�����Ƃɂ��݊����ێ�
            if (_macAcl.Count > 0)
            {
                foreach (OneDat t in _macAcl)
                {
                    if (t.StrList.Count == 2)
                    {
                        t.StrList.Add(string.Format("host_{0}", t.StrList[1]));
                    }
                }
            }
            _lease = new Lease(fileName, startIp, endIp, _leaseTime, _macAcl);

            //�T�[�o�A�h���X�̏�����
            _serverAddress = Define.ServerAddress();
        }
示例#10
0
文件: Server.cs 项目: schifflee/bjd5
        //�R���X�g���N�^
        public Server(Kernel kernel, Conf conf, OneBind oneBind)
            : base(kernel, conf, oneBind)
        {
            _targetServer = (string)Conf.Get("targetServer");
            _targetPort   = (int)Conf.Get("targetPort");

            if (_targetServer == "")
            {
                Logger.Set(LogKind.Error, null, 1, "");
            }
            if (_targetPort == 0)
            {
                Logger.Set(LogKind.Error, null, 2, "");
            }

            _protocolKind = oneBind.Protocol;
        }
示例#11
0
        EchoServer StartServer(int port, int enableAcl, Dat acl)
        {
            var       ip      = TestUtil.CreateIp("127.0.0.1");
            const int timeout = 300;
            var       oneBind = new OneBind(ip, ProtocolKind.Tcp);
            var       conf    = TestUtil.CreateConf("OptionSample");

            conf.Set("port", port);
            conf.Set("multiple", 10);
            conf.Set("acl", acl);
            conf.Set("enableAcl", enableAcl);
            conf.Set("timeOut", timeout);

            var sv = new EchoServer(conf, oneBind);

            sv.Start();
            return(sv);
        }
示例#12
0
        //コンストラクタ
        protected OneServer(Kernel kernel, Conf conf, OneBind oneBind)
            : base(kernel.CreateLogger(conf.NameTag, true, null))
        {
            Kernel   = kernel;
            NameTag  = conf.NameTag;
            Conf     = conf;
            _oneBind = oneBind;
            IsJp     = kernel.IsJp();

            //Ver6.1.6
            Lang = new Lang(IsJp ? LangKind.Jp : LangKind.En, "Server" + conf.NameTag);
            CheckLang();//定義のテスト

            //テスト用
            if (Conf == null)
            {
                var optionSample = new OptionSample(kernel, "");
                Conf = new Conf(optionSample);
                Conf.Set("port", 9990);
                Conf.Set("multiple", 10);
                Conf.Set("acl", new Dat(new CtrlType[0]));
                Conf.Set("enableAcl", 1);
                Conf.Set("timeOut", 3);
            }
            //テスト用
            if (_oneBind == null)
            {
                var ip = new Ip(IpKind.V4Localhost);
                _oneBind = new OneBind(ip, ProtocolKind.Tcp);
            }

            Logger    = kernel.CreateLogger(conf.NameTag, (bool)Conf.Get("useDetailsLog"), this);
            _multiple = (int)Conf.Get("multiple");

            //DHCPにはACLが存在しない
            if (NameTag != "Dhcp")
            {
                //ACLリスト 定義が無い場合は、aclListを生成しない
                var acl = (Dat)Conf.Get("acl");
                AclList = new AclList(acl, (int)Conf.Get("enableAcl"), Logger);
            }
            Timeout = (int)Conf.Get("timeOut");
        }
示例#13
0
        public static void BeforeClass()
        {
            TestUtil.CopyLangTxt();//BJD.Lang.txt

            //named.caのコピー
            var src = string.Format("{0}\\DnsServerTest\\named.ca", TestUtil.ProjectDirectory());
            var dst = string.Format("{0}\\BJD\\out\\named.ca", TestUtil.ProjectDirectory());

            File.Copy(src, dst, true);

            //設定ファイルの退避と上書き
            _op = new TmpOption("DnsServerTest", "DnsServerTest.ini");
            OneBind oneBind = new OneBind(new Ip(IpKind.V4Localhost), ProtocolKind.Udp);
            Kernel  kernel  = new Kernel();
            var     option  = kernel.ListOption.Get("Dns");
            Conf    conf    = new Conf(option);

            //サーバ起動
            _sv = new Server(kernel, conf, oneBind);
            _sv.Start();
        }
示例#14
0
        public void Option及びServerインスタンスの生成()
        {
            var          kernel     = new Kernel();
            const string currentDir = @"C:\tmp2\bjd5\BJD\out";


            var sut = new ListPlugin(string.Format("{0}\\bin\\plugins", currentDir));

            foreach (var onePlugin in sut)
            {
                //Optionインスタンス生成
                var oneOption = onePlugin.CreateOption(kernel, "Option", "nameTag");
                Assert.NotNull(oneOption);

                //Serverインスタンス生成
                var conf      = new Conf(oneOption);
                var oneBind   = new OneBind(new Ip(IpKind.V4Localhost), ProtocolKind.Tcp);
                var oneServer = onePlugin.CreateServer(kernel, conf, oneBind);
                Assert.NotNull(oneServer);
            }
        }
示例#15
0
        public void multipleを超えたリクエストは破棄される事をcountで確認する()
        {
            const int    multiple = 5;
            const int    port     = 8889;
            const string address  = "127.0.0.1";
            var          ip       = new Ip(address);
            var          oneBind  = new OneBind(ip, ProtocolKind.Tcp);
            Conf         conf     = TestUtil.CreateConf("OptionSample");

            conf.Set("port", port);
            conf.Set("multiple", multiple);
            conf.Set("acl", new Dat(new CtrlType[0]));
            conf.Set("enableAcl", 1);
            conf.Set("timeOut", 3);

            var myServer = new MyServer(conf, oneBind);

            myServer.Start();

            var ar = new List <MyClient>();

            for (int i = 0; i < 20; i++)
            {
                var myClient = new MyClient(address, port);
                myClient.Connet();
                ar.Add(myClient);
            }
            Thread.Sleep(100);

            //multiple以上は接続できない
            Assert.That(myServer.Count(), Is.EqualTo(multiple));

            myServer.Stop();
            myServer.Dispose();

            foreach (var c in ar)
            {
                c.Dispose();
            }
        }
示例#16
0
        public void A001()
        {
            var ip      = new Ip(IpKind.V4Localhost);
            var oneBind = new OneBind(ip, ProtocolKind.Tcp);
            var conf    = TestUtil.CreateConf("OptionSample");

            conf.Set("protocolKind", (int)ProtocolKind.Tcp);
            conf.Set("port", 8888);
            conf.Set("multiple", 10);
            conf.Set("acl", new Dat(new CtrlType[0]));
            conf.Set("enableAcl", 1);
            conf.Set("timeOut", 3);

            var myServer = new MyServer(conf, oneBind);

            myServer.Start();
            for (var i = 10; i > 0; i--)
            {
                Thread.Sleep(1);
            }
            myServer.Dispose();
        }
示例#17
0
        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);
        }
示例#18
0
 protected override OneServer CreateServer(Kernel kernel, OneBind oneBind)
 {
     return new Server(kernel, NameTag, oneBind);
 }
示例#19
0
 //コンストラクタ
 public Server(Kernel kernel, Conf conf, OneBind oneBind)
     : base(kernel, conf, oneBind)
 {
     _workDir = (string)Conf.Get("workDir");
 }
示例#20
0
        //通常の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);
            }
        }
示例#21
0
 public Server(Kernel kernel, Conf conf, OneBind oneBind)
     : base(kernel, conf, oneBind)
 {
     _dataPort = DataPortMin;
 }
示例#22
0
        //通常のServerThreadの子クラスと違い、オプションはリストで受け取る
        //親クラスは、そのリストの0番目のオブジェクトで初期化する

        //コンストラクタ
        protected MailProxyServer(Kernel kernel, Conf conf, OneBind oneBind)
            : base(kernel, conf, oneBind)
        {
            //特別なユーザのリスト初期化
            _specialUser = new SpecialUser((Dat)Conf.Get("specialUser"));
        }
示例#23
0
 public EchoServer(Conf conf, OneBind oneBind) : base(new Kernel(), conf, oneBind)
 {
     _protocolKind = oneBind.Protocol;
 }
示例#24
0
 protected override OneServer CreateServer(Kernel kernel, OneBind oneBind)
 {
     return(new Server(kernel, NameTag, oneBind));
 }
示例#25
0
 public EchoServer(Conf conf, OneBind oneBind) : base(new Kernel(), conf, oneBind)
 {
 }
示例#26
0
文件: Server.cs 项目: schifflee/bjd5
        readonly MlList _mlList;//MLリスト
//#endif

        //コンストラクタ
        public Server(Kernel kernel, Conf conf, OneBind oneBind)
            : base(kernel, conf, oneBind)
        {
            //Ver5.8.9
            if (kernel.RunMode == RunMode.Normal || kernel.RunMode == RunMode.Service)
            {
                //メールボックスの初期化状態確認
                if (kernel.MailBox == null || !kernel.MailBox.Status)
                {
                    Logger.Set(LogKind.Error, null, 4, "");
                    return; //初期化失敗(サーバは機能しない)
                }
            }


            //ドメイン名のリスト整備
            DomainList = new List <string>();
            foreach (var s in ((string)Conf.Get("domainName")).Split(','))
            {
                //Ver6.1.9
                // 設定時に誤って空白が入ってしまった際、強制的に削除する
                DomainList.Add(s.Trim());
                //DomainList.Add(s);
            }
            if (DomainList.Count == 0)
            {
                Logger.Set(LogKind.Error, null, 3, "");
                return;//初期化失敗(サーバは機能しない)
            }

            //エリアス初期化
            Alias = new Alias(DomainList, kernel.MailBox);
            foreach (var dat in (Dat)Conf.Get("aliasList"))
            {
                if (dat.Enable)
                {
                    var name  = dat.StrList[0];
                    var alias = dat.StrList[1];
                    Alias.Add(name, alias, Logger);
                }
            }

            //メールキューの初期化
            _mailQueue = new MailQueue(kernel.ProgDir());

            //SaveMail初期化
            var receivedHeader = new ReceivedHeader(kernel, (string)Conf.Get("receivedHeader"));

            _mailSave = new MailSave(kernel.MailBox, Alias, _mailQueue, Logger, receivedHeader, DomainList);

            var always = (bool)Conf.Get("always");//キュー常時処理

            _agent = new Agent(kernel, this, Conf, Logger, _mailQueue, always);

            //中継許可の初期化
            _relay = new Relay((Dat)Conf.Get("allowList"), (Dat)Conf.Get("denyList"), (int)Conf.Get("order"), Logger);

            //PopBeforeSmtp
            _popBeforeSmtp = new PopBeforeSmtp((bool)conf.Get("usePopBeforeSmtp"), (int)conf.Get("timePopBeforeSmtp"), kernel.MailBox);


            //usePopAccountがfalseの時、内部でmailBoxが無効化される
            _smtpAuthUserList = new SmtpAuthUserList((bool)Conf.Get("usePopAcount"), Kernel.MailBox, (Dat)Conf.Get("esmtpUserList"));
            _smtpAuthRange    = new SmtpAuthRange((Dat)Conf.Get("range"), (int)Conf.Get("enableEsmtp"), Logger);

            //ヘッダ置換
            _changeHeader = new ChangeHeader((Dat)Conf.Get("patternList"), (Dat)Conf.Get("appendList"));


            //Ver5.3.3 Ver5.2以前のバージョンのカラムの違いを修正する
            var d = (Dat)Conf.Get("hostList");

            if (d.Count > 0 && d[0].StrList.Count == 6)
            {
                foreach (var o in d)
                {
                    o.StrList.Add("False");
                }
                conf.Set("hostList", d);
                conf.Save(kernel.IniDb);
            }

//#if ML_SERVER
            _mlList = new MlList(kernel, this, _mailSave, DomainList);
//#endif
        }
示例#27
0
 //コンストラクタ
 public Server(Kernel kernel, Conf conf, OneBind oneBind)
     : base(kernel, conf, oneBind)
 {
 }
示例#28
0
 public OneServer CreateServer(Kernel kernel, Conf conf, OneBind oneBind)
 {
     return (OneServer)Util.CreateInstance(kernel, _path, "Server", new Object[] { kernel, conf, oneBind });
 }