diff --git a/.gitignore b/.gitignore index 53628b15..27622149 100644 --- a/.gitignore +++ b/.gitignore @@ -191,3 +191,5 @@ External Dependencies/* #Except the batch file to rebuild them !External Dependencies/rebuild-all.cmd +#The hotwallet keyfiles should obviously never be checked in +Site5/hotwallet* diff --git a/Backend/Program.cs b/Backend/Program.cs index 2bc9433b..c43f8279 100644 --- a/Backend/Program.cs +++ b/Backend/Program.cs @@ -168,6 +168,12 @@ namespace Swarmops.Backend Persistence.Key["SwarmopsInstallationId"] = Guid.NewGuid().ToString(); } + // Check for existence of bitcoin hotwallet root + + FinancialAccounts.VerifyBitcoinHotWallet(); + + // Begin maintenance loop + DateTime cycleStartTime = DateTime.UtcNow; DateTime cycleEndTime; diff --git a/Logic/Financial/FinancialAccounts.cs b/Logic/Financial/FinancialAccounts.cs index bb2c63f4..8586f857 100644 --- a/Logic/Financial/FinancialAccounts.cs +++ b/Logic/Financial/FinancialAccounts.cs @@ -1,5 +1,8 @@ using System; using System.Collections.Generic; +using System.IO; +using System.Text; +using NBitcoin; using Swarmops.Basic.Types.Financial; using Swarmops.Common.Enums; using Swarmops.Database; @@ -212,5 +215,41 @@ namespace Swarmops.Logic.Financial return result; } + + + public static void VerifyBitcoinHotWallet() + { + // Make sure there's always a private hotwallet root, regardless of whether it's used or not + + if (!File.Exists (SystemSettings.EtcFolder + Path.DirectorySeparatorChar + "hotwallet")) + { + ExtKey privateRoot = new ExtKey(); + File.WriteAllText(SystemSettings.EtcFolder + Path.DirectorySeparatorChar + "hotwallet", privateRoot.GetWif(Network.Main).ToWif(), Encoding.ASCII); + File.WriteAllText(SystemSettings.EtcFolder + Path.DirectorySeparatorChar + "hotwallet-created-" + DateTime.UtcNow.ToString("yyyy-MM-dd--HH-mm-ss--fff.backup"), privateRoot.GetWif(Network.Main).ToWif(), Encoding.ASCII); // an extra backup + Persistence.Key["BitcoinHotPublicRoot"] = privateRoot.Neuter().GetWif(Network.Main).ToWif(); + } + } + + public static ExtKey BitcoinHotPrivateRoot + { + get + { + VerifyBitcoinHotWallet(); + + return + ExtKey.Parse (File.ReadAllText (SystemSettings.EtcFolder + Path.DirectorySeparatorChar + "hotwallet")); + } + } + + public static ExtPubKey BitcoinHotPublicRoot + { + get + { + return ExtPubKey.Parse ((string) Persistence.Key["BitcoinHotPublicRoot"]); + } + } + + public const int RootWalletIndex = 1; + public const int RootDonationsIndex = 2; } } \ No newline at end of file diff --git a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs index cd574a89..12d574bf 100644 --- a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs +++ b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs @@ -105,7 +105,7 @@ namespace Swarmops.Logic.Resources { /// /// Looks up a localized string similar to You have set a bitcoin payout address: [BitcoinAddress]. As a security precaution, all payouts are quarantined for the next 48 hours, and will proceed to be paid out to the new address after that. /// - ///If you did not set your payout address, contact [OrganizationName] immediately.. + ///If you did not set this payout address (it may be worth double checking the address above for added security), contact [OrganizationName] immediately.. /// internal static string BitcoinPayoutAddress_Set_Body { get { diff --git a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx index df75fa76..5151c90c 100644 --- a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx +++ b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx @@ -138,7 +138,7 @@ Please log on to [InstallationName] at [InstallationUrl] and follow the link to You have set a bitcoin payout address: [BitcoinAddress]. As a security precaution, all payouts are quarantined for the next 48 hours, and will proceed to be paid out to the new address after that. -If you did not set your payout address, contact [OrganizationName] immediately. +If you did not set this payout address (it may be worth double checking the address above for added security), contact [OrganizationName] immediately. A bitcoin payout address was set by [ConcernedPersonName]. Payouts will begin after 48 hours when the quarantine period has elapsed. diff --git a/Logic/Resources/Logic.Swarm.DashboardTodos.Designer.cs b/Logic/Resources/Logic.Swarm.DashboardTodos.Designer.cs index 72703941..d486dd85 100644 --- a/Logic/Resources/Logic.Swarm.DashboardTodos.Designer.cs +++ b/Logic/Resources/Logic.Swarm.DashboardTodos.Designer.cs @@ -106,7 +106,7 @@ namespace Swarmops.Logic.Resources { } /// - /// Looks up a localized string similar to Please set your bitcoin address for payouts from [InstallationName]:. + /// Looks up a localized string similar to Please set your bitcoin address for payouts from [InstallationName] (spaces in the address are ok but not required):. /// internal static string Bitcoin_SetPayoutAddress_Prompt { get { diff --git a/Logic/Resources/Logic.Swarm.DashboardTodos.resx b/Logic/Resources/Logic.Swarm.DashboardTodos.resx index 7b39f5b5..7d6531cf 100644 --- a/Logic/Resources/Logic.Swarm.DashboardTodos.resx +++ b/Logic/Resources/Logic.Swarm.DashboardTodos.resx @@ -133,7 +133,7 @@ Set bitcoin payout address - Please set your bitcoin address for payouts from [InstallationName]: + Please set your bitcoin address for payouts from [InstallationName] (spaces in the address are ok but not required): Settle {0} payouts diff --git a/Logic/Support/SystemSettings.cs b/Logic/Support/SystemSettings.cs index 5ef77dd9..5f2cbaf1 100644 --- a/Logic/Support/SystemSettings.cs +++ b/Logic/Support/SystemSettings.cs @@ -4,10 +4,12 @@ using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; +using System.Runtime.Remoting.Channels; using System.Text; using System.Threading.Tasks; // This class is just for readability of other code. Doesn't add any logic at all, really - just readability, like SystemSettings.SmtpHost instead of Persistence.blahblah. +using System.Web; using NBitcoin; using Swarmops.Logic.Security; @@ -212,5 +214,32 @@ namespace Swarmops.Logic.Support } return result; } + + + public static string EtcFolder + { + get + { + if (Debugger.IsAttached && Path.DirectorySeparatorChar == '\\') + { + // Windows environment - dev environment + + if (HttpContext.Current != null) + { + // If in HTTP context, return the root frontend folder + + return HttpContext.Current.Server.MapPath ("~"); + } + else + { + // Not in HTTP context - debugging backend or something not considered at time of writing this + + return "."; // current directory (execution directory) + } + } + + return "/etc/swarmops"; // live etc folder + } + } } } diff --git a/Site5/App_GlobalResources/Pages.Financial.resx b/Site5/App_GlobalResources/Pages.Financial.resx index 802e4b0b..23e0747e 100644 --- a/Site5/App_GlobalResources/Pages.Financial.resx +++ b/Site5/App_GlobalResources/Pages.Financial.resx @@ -325,6 +325,16 @@ Please enter the supplier's bank account or equivalent. + + This is a QR code for donations to {0}. Read it from your phone's bitcoin wallet to make a donation, or donate from your computer directly to [{1}] (that's a bitcoin address). + The {0} is the organization name. {1} is the bitcoin address for donations. + + + If you want to donate to the organization, your can do so here. + + + Donate + Expense claim amount (in {0}) {0} is the currency. diff --git a/Site5/Pages/v5/Financial/Donate.aspx b/Site5/Pages/v5/Financial/Donate.aspx new file mode 100644 index 00000000..d546d7f0 --- /dev/null +++ b/Site5/Pages/v5/Financial/Donate.aspx @@ -0,0 +1,15 @@ +<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="Donate.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Financial.Donate" %> + + + + + +

+

+
+ +
+ + + + diff --git a/Site5/Pages/v5/Financial/Donate.aspx.cs b/Site5/Pages/v5/Financial/Donate.aspx.cs new file mode 100644 index 00000000..966cbf2e --- /dev/null +++ b/Site5/Pages/v5/Financial/Donate.aspx.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; +using NBitcoin; +using Swarmops.Logic.Financial; +using Swarmops.Logic.Security; + +namespace Swarmops.Frontend.Pages.v5.Financial +{ + public partial class Donate : PageV5Base + { + protected void Page_Load (object sender, EventArgs e) + { + this.PageAccessRequired = new Access (this.CurrentOrganization, AccessAspect.Null); + + this.PageTitle = Resources.Pages.Financial.Donate_PageTitle; + this.InfoBoxLiteral = Resources.Pages.Financial.FileExpenseClaim_Info; + string bitcoinAddress = + FinancialAccounts.BitcoinHotPublicRoot + .Derive ((uint) this.CurrentOrganization.Identity) + .Derive (FinancialAccounts.RootDonationsIndex) + .PubKey.GetAddress (Network.Main) + .ToString(); + + this.BoxTitle.Text = Resources.Pages.Financial.Donate_PageTitle; + this.LabelExplainBitcoinDonation.Text = String.Format(Resources.Pages.Financial.Donate_Explain, CurrentOrganization.Name, bitcoinAddress); + + this.ImageBitcoinQr.ImageUrl = + "https://chart.googleapis.com/chart?cht=qr&chs=400x400&chl=bitcoin:" + bitcoinAddress + "&label=" + CurrentOrganization.Name.Replace ("&","et").Replace ("=", string.Empty); // URI scheme doesn't like &, = + } + } +} \ No newline at end of file