mirror of
https://github.com/bitwarden/server.git
synced 2025-04-06 21:48:12 -05:00
helpers and banner
This commit is contained in:
parent
b048dbcb6b
commit
5049f94d9b
@ -23,8 +23,7 @@ namespace Bit.Setup
|
|||||||
var selfSignedSsl = false;
|
var selfSignedSsl = false;
|
||||||
if(!Ssl)
|
if(!Ssl)
|
||||||
{
|
{
|
||||||
Console.Write("(!) Do you want to generate a self-signed SSL certificate? (y/n): ");
|
if(Helpers.ReadQuestion("Do you want to generate a self-signed SSL certificate?"))
|
||||||
if(Console.ReadLine().ToLowerInvariant() == "y")
|
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory($"/bitwarden/ssl/self/{Domain}/");
|
Directory.CreateDirectory($"/bitwarden/ssl/self/{Domain}/");
|
||||||
Console.WriteLine("Generating self signed SSL certificate.");
|
Console.WriteLine("Generating self signed SSL certificate.");
|
||||||
@ -36,11 +35,10 @@ namespace Bit.Setup
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("\n!!!!!!!!!! WARNING !!!!!!!!!!");
|
var message = "You are not using an SSL certificate. Bitwarden requires HTTPS to operate. " +
|
||||||
Console.WriteLine("You are not using an SSL certificate. Bitwarden requires HTTPS to operate. " +
|
|
||||||
"You must front your installation with a HTTPS proxy. The web vault (and other Bitwarden " +
|
"You must front your installation with a HTTPS proxy. The web vault (and other Bitwarden " +
|
||||||
"apps) will not work properly without HTTPS.");
|
"apps) will not work properly without HTTPS.";
|
||||||
Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
|
Helpers.ShowBanner("WARNING", message, ConsoleColor.Yellow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +55,7 @@ namespace Bit.Setup
|
|||||||
Helpers.Exec("openssl pkcs12 -export -out /bitwarden/identity/identity.pfx -inkey identity.key " +
|
Helpers.Exec("openssl pkcs12 -export -out /bitwarden/identity/identity.pfx -inkey identity.key " +
|
||||||
$"-in identity.crt -certfile identity.crt -passout pass:{IdentityCertPassword}");
|
$"-in identity.crt -certfile identity.crt -passout pass:{IdentityCertPassword}");
|
||||||
|
|
||||||
|
Console.WriteLine();
|
||||||
return selfSignedSsl;
|
return selfSignedSsl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,5 +158,40 @@ namespace Bit.Setup
|
|||||||
process.WaitForExit();
|
process.WaitForExit();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ReadInput(string prompt)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
|
Console.Write("(!) ");
|
||||||
|
Console.ResetColor();
|
||||||
|
Console.Write(prompt);
|
||||||
|
if(prompt.EndsWith("?"))
|
||||||
|
{
|
||||||
|
Console.Write(" (y/n)");
|
||||||
|
}
|
||||||
|
Console.Write(": ");
|
||||||
|
var input = Console.ReadLine();
|
||||||
|
Console.WriteLine();
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool ReadQuestion(string prompt)
|
||||||
|
{
|
||||||
|
var input = ReadInput(prompt).ToLowerInvariant().Trim();
|
||||||
|
return input == "y" || input == "yes";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ShowBanner(string title, string message, ConsoleColor? color = null)
|
||||||
|
{
|
||||||
|
if(color != null)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = color.Value;
|
||||||
|
}
|
||||||
|
Console.WriteLine($"!!!!!!!!!! {title} !!!!!!!!!!");
|
||||||
|
Console.WriteLine(message);
|
||||||
|
Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,12 +73,12 @@ namespace Bit.Setup
|
|||||||
var ssl = letsEncrypt;
|
var ssl = letsEncrypt;
|
||||||
if(!letsEncrypt)
|
if(!letsEncrypt)
|
||||||
{
|
{
|
||||||
ssl = ReadQuestion("Do you have a SSL certificate to use?");
|
ssl = Helpers.ReadQuestion("Do you have a SSL certificate to use?");
|
||||||
if(ssl)
|
if(ssl)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory($"/bitwarden/ssl/{domain}/");
|
Directory.CreateDirectory($"/bitwarden/ssl/{domain}/");
|
||||||
Console.WriteLine("*** Make sure 'certificate.crt' and 'private.key' are provided in the " +
|
Helpers.ShowBanner("NOTE", "Make sure 'certificate.crt' and 'private.key' are provided in the " +
|
||||||
"appropriate directory (see docs for info). ***\n");
|
"appropriate directory (see docs for info).");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,14 +91,14 @@ namespace Bit.Setup
|
|||||||
var sslDiffieHellman = letsEncrypt;
|
var sslDiffieHellman = letsEncrypt;
|
||||||
if(ssl && !selfSignedSsl && !letsEncrypt)
|
if(ssl && !selfSignedSsl && !letsEncrypt)
|
||||||
{
|
{
|
||||||
sslDiffieHellman = ReadQuestion(
|
sslDiffieHellman = Helpers.ReadQuestion(
|
||||||
"Use Diffie Hellman ephemeral parameters for SSL (requires dhparam.pem)?");
|
"Use Diffie Hellman ephemeral parameters for SSL (requires dhparam.pem)?");
|
||||||
sslTrusted = ReadQuestion("Is this a trusted SSL certificate (requires ca.crt)?");
|
sslTrusted = Helpers.ReadQuestion("Is this a trusted SSL certificate (requires ca.crt)?");
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = $"https://{domain}";
|
var url = $"https://{domain}";
|
||||||
int httpPort = default(int), httpsPort = default(int);
|
int httpPort = default(int), httpsPort = default(int);
|
||||||
if(ReadQuestion("Do you want to use the default ports for HTTP (80) and HTTPS (443)?"))
|
if(Helpers.ReadQuestion("Do you want to use the default ports for HTTP (80) and HTTPS (443)?"))
|
||||||
{
|
{
|
||||||
httpPort = 80;
|
httpPort = 80;
|
||||||
if(ssl)
|
if(ssl)
|
||||||
@ -109,7 +109,7 @@ namespace Bit.Setup
|
|||||||
else if(ssl)
|
else if(ssl)
|
||||||
{
|
{
|
||||||
httpsPort = 443;
|
httpsPort = 443;
|
||||||
if(int.TryParse(ReadInput("HTTPS port").ToLowerInvariant().Trim(), out httpsPort) && httpsPort != 443)
|
if(int.TryParse(Helpers.ReadInput("HTTPS port").Trim(), out httpsPort) && httpsPort != 443)
|
||||||
{
|
{
|
||||||
url += (":" + httpsPort);
|
url += (":" + httpsPort);
|
||||||
}
|
}
|
||||||
@ -121,21 +121,21 @@ namespace Bit.Setup
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
httpPort = 80;
|
httpPort = 80;
|
||||||
if(!int.TryParse(ReadInput("HTTP port").ToLowerInvariant().Trim(), out httpPort) && httpPort != 80)
|
if(!int.TryParse(Helpers.ReadInput("HTTP port").Trim(), out httpPort) && httpPort != 80)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Using default port.");
|
Console.WriteLine("Using default port.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ReadQuestion("Is your installation behind a reverse proxy?"))
|
if(Helpers.ReadQuestion("Is your installation behind a reverse proxy?"))
|
||||||
{
|
{
|
||||||
if(ReadQuestion("Do you use the default HTTPS port (443) on your reverse proxy?"))
|
if(Helpers.ReadQuestion("Do you use the default HTTPS port (443) on your reverse proxy?"))
|
||||||
{
|
{
|
||||||
url = $"https://{domain}";
|
url = $"https://{domain}";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(int.TryParse(ReadInput("Proxy HTTPS port").ToLowerInvariant().Trim(), out var httpsReversePort)
|
if(int.TryParse(Helpers.ReadInput("Proxy HTTPS port").Trim(), out var httpsReversePort)
|
||||||
&& httpsReversePort != 443)
|
&& httpsReversePort != 443)
|
||||||
{
|
{
|
||||||
url += (":" + httpsReversePort);
|
url += (":" + httpsReversePort);
|
||||||
@ -153,7 +153,7 @@ namespace Bit.Setup
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var push = ReadQuestion("Do you want to use push notifications?");
|
var push = Helpers.ReadQuestion("Do you want to use push notifications?");
|
||||||
|
|
||||||
var nginxBuilder = new NginxConfigBuilder(domain, url, ssl, selfSignedSsl, letsEncrypt,
|
var nginxBuilder = new NginxConfigBuilder(domain, url, ssl, selfSignedSsl, letsEncrypt,
|
||||||
sslTrusted, sslDiffieHellman);
|
sslTrusted, sslDiffieHellman);
|
||||||
@ -270,7 +270,7 @@ namespace Bit.Setup
|
|||||||
|
|
||||||
private static bool ValidateInstallation()
|
private static bool ValidateInstallation()
|
||||||
{
|
{
|
||||||
var installationId = ReadInput("Enter your installation id (get it at https://bitwarden.com/host)");
|
var installationId = Helpers.ReadInput("Enter your installation id (get at https://bitwarden.com/host)");
|
||||||
if(!Guid.TryParse(installationId.Trim(), out var installationidGuid))
|
if(!Guid.TryParse(installationId.Trim(), out var installationidGuid))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Invalid installation id.");
|
Console.WriteLine("Invalid installation id.");
|
||||||
@ -278,7 +278,7 @@ namespace Bit.Setup
|
|||||||
}
|
}
|
||||||
|
|
||||||
_installationId = installationidGuid;
|
_installationId = installationidGuid;
|
||||||
_installationKey = ReadInput("Enter your installation key");
|
_installationKey = Helpers.ReadInput("Enter your installation key");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -358,27 +358,5 @@ namespace Bit.Setup
|
|||||||
|
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ReadInput(string prompt)
|
|
||||||
{
|
|
||||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
|
||||||
Console.Write("(!) ");
|
|
||||||
Console.ResetColor();
|
|
||||||
Console.Write(prompt);
|
|
||||||
if(prompt.EndsWith("?"))
|
|
||||||
{
|
|
||||||
Console.Write(" (y/n)");
|
|
||||||
}
|
|
||||||
Console.Write(": ");
|
|
||||||
var input = Console.ReadLine();
|
|
||||||
Console.WriteLine();
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool ReadQuestion(string prompt)
|
|
||||||
{
|
|
||||||
var input = ReadInput(prompt).ToLowerInvariant().Trim();
|
|
||||||
return input == "y" || input == "yes";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user