Example #1
0
 private void TraceTcpNatContext(NATContext context, TcpFrame frame)
 {
     if (context == null || frame == null)
     {
         return;
     }
     NATContext.StateCode state = NATContext.StateCode.TCP_RST; // 跟踪TCP协议报文状态
     if (0 != (frame.Flags & TcpFlags.TCP_SYN))
     {
         state = NATContext.StateCode.TCP_SYN;
     }
     else if (0 != (frame.Flags & TcpFlags.TCP_FIN))
     {
         state = NATContext.StateCode.TCP_FIN;
     }
     else if (0 != (frame.Flags & TcpFlags.TCP_RST))
     {
         state = NATContext.StateCode.TCP_RST;
     }
     else if (0 != (frame.Flags & (TcpFlags.TCP_PSH | TcpFlags.TCP_ACK)))
     {
         state = NATContext.StateCode.TCP_RECVED;
     }
     if (context.State != NATContext.StateCode.TCP_FIN &&
         context.State != NATContext.StateCode.TCP_RST)
     {
         context.Restart().State = state;
     }
 }
Example #2
0
        public override void Clear()
        {
            var api = new ApiPacket(10, 4);

            api.Set("sessionid", Id);
            var response = TcpFrame.Send(api);

            IsSuccess(response);
        }
Example #3
0
        public override void Remove(string key)
        {
            var api = new ApiPacket(10, 3);

            api.Set("sessionid", Id);
            api.Set("key", key);
            var response = TcpFrame.Send(api);

            IsSuccess(response);
        }
Example #4
0
        public override void Set(string key, byte[] value)
        {
            var api = new ApiPacket(10, 2);

            api.Set("sessionid", Id);
            api.Set("key", key);
            api.Bytes = value;
            var response = TcpFrame.Send(api);

            IsSuccess(response);
        }
Example #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(AllException);
            }

            app.UseIgnoreUrl("Views");

            app.UseResponseCompression();

            // 此部分为作者需要,你们可以直接删掉
            var staticfile = new StaticFileOptions();
            var provider   = new Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider();

            provider.Mappings.Add(".php", "text/plain");//手动设置对应MIME
            provider.Mappings.Add(".aspx", "text/plain");
            staticfile.ContentTypeProvider = provider;
            //staticfile.OnPrepareResponse = (a) =>
            //{

            //};
            app.UseStaticFiles(staticfile);

            app.UseDiySession();

            app.UseAshx(routes =>
            {
                routes.MapApiRoute(
                    name: "Api",
                    areaName: "AdminCore.Api",
                    template: "Api/{controller=AdminServers}/{action}/{id?}");

                routes.MapApiRoute(
                    name: "Admin",
                    areaName: "AdminCore.WebUi",
                    template: "{controller=Admin}/{action=Index}/{id?}");
            });

            FacadeManage.UseSqlLog(loggerFactory); //注册相关SQL日志。

            Menu.Reload();                         //获取默认系统菜单

            TcpFrame.ConnectClient(loggerFactory);

            app.GetObject <UpLoad>().SetBasePath(env.WebRootPath);

            Api.AdminServers.StartBaseLog();
        }
Example #6
0
        public override IEnumerable <string> GetKeys()
        {
            var api = new ApiPacket(10, 0);

            api.Set("sessionid", Id);
            var response = TcpFrame.Send(api);

            IsSuccess(response);

            var _keys = response.Obj == null?Array.Empty <string>() : response.Obj.Split('|').AsEnumerable();

            return(_keys);
        }
Example #7
0
        public override bool TryGetValue(string key, out byte[] value)
        {
            var api = new ApiPacket(10, 1);

            api.Set("sessionid", Id);
            api.Set("key", key);
            var response = TcpFrame.Send(api);

            IsSuccess(response);

            value = response.Bytes;

            return(value != null);
        }
Example #8
0
        public virtual bool PublicInput(IPFrame packet)
        {
            if (packet == null)
            {
                return(false);
            }
            switch (packet.ProtocolType)
            {
            case ProtocolType.Udp:
            {
                UdpFrame frame = UdpLayer.ParseFrame(packet, true);
                if (frame == null)
                {
                    return(false);
                }
                NATContext context = this.m_contextsUdp.PublicInput(frame.Source, frame.Destination);
                if (context == null)
                {
                    return(false);
                }
                var convertional = new UdpFrame(frame.Source, context.Sources, frame.Payload)
                {
                    Ttl = frame.Ttl,
                };
                IPFrame ip = CopyFrameHeaderParts(UdpLayer.ToIPFrame(convertional), packet);
                if (ip == null)
                {
                    return(false);
                }
                return(this.OnPrivateOutput(ip));
            }

            case ProtocolType.Tcp:
            {
                TcpFrame frame = TcpLayer.ParseFrame(packet, true);
                if (frame == null)
                {
                    return(false);
                }
                NATContext context = this.m_contextsTcp.PublicInput(frame.Source, frame.Destination);
                if (context == null)
                {
                    return(false);
                }
                else
                {
                    TraceTcpNatContext(context, frame);
                }
                var convertional = new TcpFrame(frame.Source, context.Sources, frame.Payload)
                {
                    Ttl           = frame.Ttl,
                    AcknowledgeNo = frame.AcknowledgeNo,
                    Flags         = frame.Flags,
                    SequenceNo    = frame.SequenceNo,
                    WindowSize    = frame.WindowSize,
                    Options       = frame.Options,
                    UrgentPointer = frame.UrgentPointer,
                };
                IPFrame ip = CopyFrameHeaderParts(TcpLayer.ToIPFrame(convertional), packet);
                if (ip == null)
                {
                    return(false);
                }
                return(this.OnPrivateOutput(ip));
            }

            case ProtocolType.Icmp:
                return(this.PublicIcmpInput(packet));

            default:
                return(false);
            }
        }