|
|
|
|
@ -1,6 +1,7 @@
@@ -1,6 +1,7 @@
|
|
|
|
|
using System.Globalization; |
|
|
|
|
using System.Net.Http.Json; |
|
|
|
|
using Bit.Migrator; |
|
|
|
|
using Bit.Setup.Enums; |
|
|
|
|
|
|
|
|
|
namespace Bit.Setup; |
|
|
|
|
|
|
|
|
|
@ -196,6 +197,7 @@ public class Program
@@ -196,6 +197,7 @@ public class Program
|
|
|
|
|
{ |
|
|
|
|
var installationId = string.Empty; |
|
|
|
|
var installationKey = string.Empty; |
|
|
|
|
CloudRegion cloudRegion; |
|
|
|
|
|
|
|
|
|
if (_context.Parameters.ContainsKey("install-id")) |
|
|
|
|
{ |
|
|
|
|
@ -203,7 +205,13 @@ public class Program
@@ -203,7 +205,13 @@ public class Program
|
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
installationId = Helpers.ReadInput("Enter your installation id (get at https://bitwarden.com/host)"); |
|
|
|
|
var prompt = "Enter your installation id (get at https://bitwarden.com/host)"; |
|
|
|
|
installationId = Helpers.ReadInput(prompt); |
|
|
|
|
while (string.IsNullOrEmpty(installationId)) |
|
|
|
|
{ |
|
|
|
|
Helpers.WriteError("Invalid input for installation id. Please try again."); |
|
|
|
|
installationId = Helpers.ReadInput(prompt); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!Guid.TryParse(installationId.Trim(), out var installationidGuid)) |
|
|
|
|
@ -218,26 +226,61 @@ public class Program
@@ -218,26 +226,61 @@ public class Program
|
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
installationKey = Helpers.ReadInput("Enter your installation key"); |
|
|
|
|
var prompt = "Enter your installation key"; |
|
|
|
|
installationKey = Helpers.ReadInput(prompt); |
|
|
|
|
while (string.IsNullOrEmpty(installationKey)) |
|
|
|
|
{ |
|
|
|
|
Helpers.WriteError("Invalid input for installation key. Please try again."); |
|
|
|
|
installationKey = Helpers.ReadInput(prompt); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (_context.Parameters.ContainsKey("cloud-region")) |
|
|
|
|
{ |
|
|
|
|
Enum.TryParse(_context.Parameters["cloud-region"], out cloudRegion); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
var prompt = "Enter your region (US/EU) [US]"; |
|
|
|
|
var region = Helpers.ReadInput(prompt); |
|
|
|
|
if (string.IsNullOrEmpty(region)) region = "US"; |
|
|
|
|
|
|
|
|
|
while (!Enum.TryParse(region, out cloudRegion)) |
|
|
|
|
{ |
|
|
|
|
Helpers.WriteError("Invalid input for region. Please try again."); |
|
|
|
|
region = Helpers.ReadInput(prompt); |
|
|
|
|
if (string.IsNullOrEmpty(region)) region = "US"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_context.Install.InstallationId = installationidGuid; |
|
|
|
|
_context.Install.InstallationKey = installationKey; |
|
|
|
|
_context.Install.CloudRegion = cloudRegion; |
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
var response = new HttpClient().GetAsync("https://api.bitwarden.com/installations/" + |
|
|
|
|
_context.Install.InstallationId).GetAwaiter().GetResult(); |
|
|
|
|
string url; |
|
|
|
|
switch (cloudRegion) |
|
|
|
|
{ |
|
|
|
|
case CloudRegion.EU: |
|
|
|
|
url = "https://api.bitwarden.eu/installations/"; |
|
|
|
|
break; |
|
|
|
|
case CloudRegion.US: |
|
|
|
|
default: |
|
|
|
|
url = "https://api.bitwarden.com/installations/"; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
var response = new HttpClient().GetAsync(url + _context.Install.InstallationId).GetAwaiter().GetResult(); |
|
|
|
|
|
|
|
|
|
if (!response.IsSuccessStatusCode) |
|
|
|
|
{ |
|
|
|
|
if (response.StatusCode == System.Net.HttpStatusCode.NotFound) |
|
|
|
|
{ |
|
|
|
|
Console.WriteLine("Invalid installation id."); |
|
|
|
|
Console.WriteLine($"Invalid installation id for {cloudRegion.ToString()} region."); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
Console.WriteLine("Unable to validate installation id."); |
|
|
|
|
Console.WriteLine($"Unable to validate installation id for {cloudRegion.ToString()} region."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
@ -246,7 +289,7 @@ public class Program
@@ -246,7 +289,7 @@ public class Program
|
|
|
|
|
var result = response.Content.ReadFromJsonAsync<InstallationValidationResponseModel>().GetAwaiter().GetResult(); |
|
|
|
|
if (!result.Enabled) |
|
|
|
|
{ |
|
|
|
|
Console.WriteLine("Installation id has been disabled."); |
|
|
|
|
Console.WriteLine($"Installation id has been disabled in the {cloudRegion.ToString()} region."); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -254,7 +297,7 @@ public class Program
@@ -254,7 +297,7 @@ public class Program
|
|
|
|
|
} |
|
|
|
|
catch |
|
|
|
|
{ |
|
|
|
|
Console.WriteLine("Unable to validate installation id. Problem contacting Bitwarden server."); |
|
|
|
|
Console.WriteLine($"Unable to validate installation id. Problem contacting Bitwarden {cloudRegion.ToString()} server."); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|