Ejemplo n.º 1
0
        private static void ConfigureCore(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider prov, ILoggerFactory loggerFactory, BTCPayServerOptions options)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var forwardingOptions = new ForwardedHeadersOptions()
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            };

            forwardingOptions.KnownNetworks.Clear();
            forwardingOptions.KnownProxies.Clear();
            forwardingOptions.ForwardedHeaders = ForwardedHeaders.All;
            app.UseForwardedHeaders(forwardingOptions);
            app.UseCors();
            app.UsePayServer();
            app.UseStaticFiles();
            app.UseAuthentication();
            app.UseSignalR(route =>
            {
                AppHub.Register(route);
                PaymentRequestHub.Register(route);
            });
            app.UseWebSockets();
            app.UseStatusCodePages();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Ejemplo n.º 2
0
        private async Task <ViewCrowdfundViewModel> GetAppInfo(string appId)
        {
            var info = (ViewCrowdfundViewModel)await _AppService.GetAppInfo(appId);

            info.HubPath       = AppHub.GetHubPath(Request);
            info.SimpleDisplay = Request.Query.ContainsKey("simple");
            return(info);
        }
Ejemplo n.º 3
0
        private void ConfigureCore(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider prov, IOptions <DataDirectories> dataDirectories)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseHeadersOverride();
            var forwardingOptions = new ForwardedHeadersOptions()
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            };

            forwardingOptions.KnownNetworks.Clear();
            forwardingOptions.KnownProxies.Clear();
            forwardingOptions.ForwardedHeaders = ForwardedHeaders.All;
            app.UseForwardedHeaders(forwardingOptions);

            app.UseStatusCodePagesWithReExecute("/errors/{0}");

            app.UsePayServer();
            app.UseRouting();
            app.UseCors();

            app.UseStaticFiles(new StaticFileOptions
            {
                OnPrepareResponse = ctx =>
                {
                    // Cache static assets for one year, set asp-append-version="true" on references to update on change.
                    // https://andrewlock.net/adding-cache-control-headers-to-static-files-in-asp-net-core/
                    const int durationInSeconds = 60 * 60 * 24 * 365;
                    ctx.Context.Response.Headers[HeaderNames.CacheControl] = "public,max-age=" + durationInSeconds;
                }
            });

            app.UseProviderStorage(dataDirectories);
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseSession();

            app.UseWebSockets();

            app.UseCookiePolicy(new CookiePolicyOptions()
            {
                HttpOnly = Microsoft.AspNetCore.CookiePolicy.HttpOnlyPolicy.Always,
                Secure   = Microsoft.AspNetCore.Http.CookieSecurePolicy.SameAsRequest
            });
            app.UseEndpoints(endpoints =>
            {
                AppHub.Register(endpoints);
                PaymentRequestHub.Register(endpoints);
                endpoints.MapRazorPages();
                endpoints.MapControllers();
                endpoints.MapControllerRoute("default", "{controller:validate=UIHome}/{action:lowercase=Index}/{id?}");
            });
            app.UsePlugins();
        }
Ejemplo n.º 4
0
        private static void ConfigureCore(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider prov, ILoggerFactory loggerFactory, BTCPayServerOptions options)
        {
            Logs.Configure(loggerFactory);
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseHeadersOverride();
            var forwardingOptions = new ForwardedHeadersOptions()
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            };

            forwardingOptions.KnownNetworks.Clear();
            forwardingOptions.KnownProxies.Clear();
            forwardingOptions.ForwardedHeaders = ForwardedHeaders.All;
            app.UseForwardedHeaders(forwardingOptions);
            app.UsePayServer();
#if !NETCOREAPP21
            app.UseRouting();
#endif
            app.UseCors();

            app.UseStaticFiles();
            app.UseProviderStorage(options);
            app.UseAuthentication();
#if !NETCOREAPP21
            app.UseAuthorization();
#endif
            app.UseSession();
#if NETCOREAPP21
            app.UseSignalR(route =>
            {
                AppHub.Register(route);
                PaymentRequestHub.Register(route);
            });
#endif
            app.UseWebSockets();
            app.UseStatusCodePages();
#if NETCOREAPP21
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
#else
            app.UseEndpoints(endpoints =>
            {
                AppHub.Register(endpoints);
                PaymentRequestHub.Register(endpoints);
                endpoints.MapControllers();
                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
            });
#endif
        }
Ejemplo n.º 5
0
        private static void ConfigureCore(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider prov, ILoggerFactory loggerFactory, BTCPayServerOptions options)
        {
            Logs.Configure(loggerFactory);
            app.UsePlugins();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseHeadersOverride();
            var forwardingOptions = new ForwardedHeadersOptions()
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            };

            forwardingOptions.KnownNetworks.Clear();
            forwardingOptions.KnownProxies.Clear();
            forwardingOptions.ForwardedHeaders = ForwardedHeaders.All;
            app.UseForwardedHeaders(forwardingOptions);


            app.UseStatusCodePagesWithReExecute("/Error/Handle", "?statusCode={0}");

            app.UsePayServer();
            app.UseRouting();
            app.UseCors();

            app.UseStaticFiles(new StaticFileOptions
            {
                OnPrepareResponse = ctx =>
                {
                    // Cache static assets for one year, set asp-append-version="true" on references to update on change.
                    // https://andrewlock.net/adding-cache-control-headers-to-static-files-in-asp-net-core/
                    const int durationInSeconds = 60 * 60 * 24 * 365;
                    ctx.Context.Response.Headers[HeaderNames.CacheControl] = "public,max-age=" + durationInSeconds;
                }
            });

            app.UseProviderStorage(options);
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseSession();

            app.UseWebSockets();

            app.UseEndpoints(endpoints =>
            {
                AppHub.Register(endpoints);
                PaymentRequestHub.Register(endpoints);
                endpoints.MapControllers();
                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
            });
        }
Ejemplo n.º 6
0
        private void PingSystemD(object state)
        {
            var ci = AppHub.GetLastClientActivity();

            if (ci.inactiveTimeSpan > TimeSpan.FromMinutes(5))
            {
                _logger.LogWarning($"no client activity: for={ci.inactiveTimeSpan}, since={ci.lastActivity}");
            }
            else
            {
                ServiceManager.Notify(ServiceState.Watchdog);
            }
        }
Ejemplo n.º 7
0
        private static void ConfigureCore(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider prov, ILoggerFactory loggerFactory, BTCPayServerOptions options)
        {
            Logs.Configure(loggerFactory);
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseHeadersOverride();
            var forwardingOptions = new ForwardedHeadersOptions()
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            };

            forwardingOptions.KnownNetworks.Clear();
            forwardingOptions.KnownProxies.Clear();
            forwardingOptions.ForwardedHeaders = ForwardedHeaders.All;
            app.UseForwardedHeaders(forwardingOptions);


            app.UseStatusCodePagesWithReExecute("/Error/Handle", "?statusCode={0}");

            app.UsePayServer();
            app.UseRouting();
            app.UseCors();

            app.UseStaticFiles();
            app.UseProviderStorage(options);
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseBTCPayOpenApi();
            app.UseSession();

            app.UseWebSockets();

            app.UseEndpoints(endpoints =>
            {
                AppHub.Register(endpoints);
                PaymentRequestHub.Register(endpoints);
                endpoints.MapControllers();
                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
            });
        }
Ejemplo n.º 8
0
        public async Task <IHttpActionResult> Post()
        {
            List <UserInfo> toReturn = new List <UserInfo>();

            try
            {
                using (SqlConnection con = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DBCS"].ConnectionString))
                {
                    SqlCommand cmd = new SqlCommand("spGetAllUserFriendsInfo @mail", con);
                    cmd.Parameters.AddWithValue("@mail", User.Identity.Name);

                    con.Open();
                    using (SqlDataReader rdr = await cmd.ExecuteReaderAsync())
                    {
                        while (rdr.Read())
                        {
                            UserInfo i = new UserInfo()
                            {
                                Avatar     = rdr["Avatar"] == DBNull.Value ? null : (byte[])rdr["Avatar"],
                                Country    = rdr["Country"] == DBNull.Value ? "-" : rdr["Country"].ToString(),
                                FirstName  = rdr["FirstName"] == DBNull.Value ? "-" : rdr["FirstName"].ToString(),
                                Interests  = rdr["Interests"] == DBNull.Value ? "-" : rdr["Interests"].ToString(),
                                LastName   = rdr["LastName"] == DBNull.Value ? "-" : rdr["LastName"].ToString(),
                                Region     = rdr["Region"] == DBNull.Value ? "-" : rdr["Region"].ToString(),
                                Settlement = rdr["Settlement"] == DBNull.Value ? "-" : rdr["Settlement"].ToString(),
                                Profession = rdr["Profession"] == DBNull.Value ? "-" : rdr["Profession"].ToString(),
                                Email      = rdr["UserEmail"].ToString(),
                                IsOnline   = AppHub.IsUserOnline(rdr["UserEmail"].ToString())
                            };

                            toReturn.Add(i);
                        }
                    }
                }

                return(Ok(toReturn));
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }
Ejemplo n.º 9
0
        public async Task <IHttpActionResult> Put([FromBody] string email)
        {
            List <Tuple <UserInfo, int> > toReturn = new List <Tuple <UserInfo, int> >();

            try
            {
                using (SqlConnection con = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DBCS"].ConnectionString))
                {
                    SqlCommand cmd = new SqlCommand("spGetPossibleFriends @mail", con);
                    cmd.Parameters.AddWithValue("@mail", email);

                    con.Open();

                    using (SqlDataReader rdr = await cmd.ExecuteReaderAsync())
                    {
                        while (rdr.Read())
                        {
                            toReturn.Add(new Tuple <UserInfo, int>(new UserInfo()
                            {
                                Avatar    = rdr["Avatar"] != DBNull.Value ? (byte[])rdr["Avatar"] : null,
                                Email     = rdr["UserEmail"].ToString(),
                                FirstName = rdr["FirstName"].ToString(),
                                LastName  = rdr["LastName"].ToString(),
                                IsOnline  = AppHub.IsUserOnline(rdr["UserEmail"].ToString())
                            },
                                                                   Convert.ToInt32(rdr["FriendsCount"].ToString())
                                                                   ));
                        }
                    }
                }

                return(Ok(toReturn));
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> ViewCrowdfund(string appId, string statusMessage)

        {
            var app = await _AppService.GetApp(appId, AppType.Crowdfund, true);

            if (app == null)
            {
                return(NotFound());
            }
            var settings = app.GetSettings <CrowdfundSettings>();

            var isAdmin = await _AppService.GetAppDataIfOwner(GetUserId(), appId, AppType.Crowdfund) != null;

            var hasEnoughSettingsToLoad = !string.IsNullOrEmpty(settings.TargetCurrency);

            if (!hasEnoughSettingsToLoad)
            {
                if (!isAdmin)
                {
                    return(NotFound());
                }

                return(NotFound("A Target Currency must be set for this app in order to be loadable."));
            }
            var appInfo = (ViewCrowdfundViewModel)(await _AppService.GetAppInfo(appId));

            appInfo.HubPath = AppHub.GetHubPath(this.Request);
            if (settings.Enabled)
            {
                return(View(appInfo));
            }
            if (!isAdmin)
            {
                return(NotFound());
            }

            return(View(appInfo));
        }
        public async Task <IActionResult> ContributeToCrowdfund(string appId, ContributeToCrowdfund request, CancellationToken cancellationToken)
        {
            var app = await _AppService.GetApp(appId, AppType.Crowdfund, true);

            if (app == null)
            {
                return(NotFound());
            }
            var settings = app.GetSettings <CrowdfundSettings>();


            var isAdmin = await _AppService.GetAppDataIfOwner(GetUserId(), appId, AppType.Crowdfund) != null;

            if (!settings.Enabled && !isAdmin)
            {
                return(NotFound("Crowdfund is not currently active"));
            }

            var info = (ViewCrowdfundViewModel)await _AppService.GetAppInfo(appId);

            info.HubPath = AppHub.GetHubPath(this.Request);
            if (!isAdmin &&
                ((settings.StartDate.HasValue && DateTime.Now < settings.StartDate) ||
                 (settings.EndDate.HasValue && DateTime.Now > settings.EndDate) ||
                 (settings.EnforceTargetAmount &&
                  (info.Info.PendingProgressPercentage.GetValueOrDefault(0) +
                   info.Info.ProgressPercentage.GetValueOrDefault(0)) >= 100)))
            {
                return(NotFound("Crowdfund is not currently active"));
            }

            var store = await _AppService.GetStore(app);

            var title = settings.Title;
            var price = request.Amount;

            ViewPointOfSaleViewModel.Item choice = null;
            if (!string.IsNullOrEmpty(request.ChoiceKey))
            {
                var choices = _AppService.Parse(settings.PerksTemplate, settings.TargetCurrency);
                choice = choices.FirstOrDefault(c => c.Id == request.ChoiceKey);
                if (choice == null)
                {
                    return(NotFound("Incorrect option provided"));
                }
                title = choice.Title;
                price = choice.Price.Value;
                if (request.Amount > price)
                {
                    price = request.Amount;
                }
            }

            if (!isAdmin && (settings.EnforceTargetAmount && info.TargetAmount.HasValue && price >
                             (info.TargetAmount - (info.Info.CurrentAmount + info.Info.CurrentPendingAmount))))
            {
                return(NotFound("Contribution Amount is more than is currently allowed."));
            }

            store.AdditionalClaims.Add(new Claim(Policies.CanCreateInvoice.Key, store.Id));
            try
            {
                var invoice = await _InvoiceController.CreateInvoiceCore(new CreateInvoiceRequest()
                {
                    OrderId               = AppService.GetCrowdfundOrderId(appId),
                    Currency              = settings.TargetCurrency,
                    ItemCode              = request.ChoiceKey ?? string.Empty,
                    ItemDesc              = title,
                    BuyerEmail            = request.Email,
                    Price                 = price,
                    NotificationURL       = settings.NotificationUrl,
                    NotificationEmail     = settings.NotificationEmail,
                    FullNotifications     = true,
                    ExtendedNotifications = true,
                    RedirectURL           = request.RedirectUrl ??
                                            new Uri(new Uri(new Uri(HttpContext.Request.GetAbsoluteRoot()), _BtcPayServerOptions.RootPath), $"apps/{appId}/crowdfund").ToString()
                }, store, HttpContext.Request.GetAbsoluteRoot(),
                                                                         new List <string> {
                    AppService.GetAppInternalTag(appId)
                },
                                                                         cancellationToken : cancellationToken);

                if (request.RedirectToCheckout)
                {
                    return(RedirectToAction(nameof(InvoiceController.Checkout), "Invoice",
                                            new { invoiceId = invoice.Data.Id }));
                }
                else
                {
                    return(Ok(invoice.Data.Id));
                }
            }
            catch (BitpayHttpException e)
            {
                return(BadRequest(e.Message));
            }
        }