Beispiel #1
0
        public async Task Log(BakaRequest request)
        {
            Requests.Add(request);

            request_count++;

            await Task.Run(() =>
            {
                if (Globals.Config.LogRequestsToConsole)
                {
                    Console.WriteLine(JsonConvert.SerializeObject(request));
                }
                CheckAndSaveLogs();
            });
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseDefaultFiles();
            app.UseStaticFiles();

            app.Use(async(context, next) =>
            {
                await next();

                string header = context.Request.Headers["baka_token"].FirstOrDefault();

                string ip = context.Request.Headers["CF-Connecting-IP"].FirstOrDefault() ?? context.Connection.RemoteIpAddress.ToString();

                var request = new BakaRequest()
                {
                    DisplayUrl = context.Request.GetDisplayUrl(),
                    AuthHeader = header,
                    RemoteIp   = ip,
                    Timestamp  = DateTime.Now.ToFileTimeUtc().ToString(),
                    Method     = context.Request.Method
                };

                await HttpLoggingService.Log(request);
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }