mirror of
https://github.com/bitwarden/server.git
synced 2025-04-16 02:28:13 -05:00
input helpers
This commit is contained in:
parent
6628a419d8
commit
267aa020c6
@ -21,6 +21,8 @@ namespace Bit.Setup
|
|||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
_args = args;
|
_args = args;
|
||||||
_parameters = ParseParameters();
|
_parameters = ParseParameters();
|
||||||
if(_parameters.ContainsKey("os"))
|
if(_parameters.ContainsKey("os"))
|
||||||
@ -71,13 +73,12 @@ namespace Bit.Setup
|
|||||||
var ssl = letsEncrypt;
|
var ssl = letsEncrypt;
|
||||||
if(!letsEncrypt)
|
if(!letsEncrypt)
|
||||||
{
|
{
|
||||||
Console.Write("(!) Do you have a SSL certificate to use? (y/n): ");
|
ssl = ReadQuestion("Do you have a SSL certificate to use?");
|
||||||
ssl = Console.ReadLine().ToLowerInvariant() == "y";
|
|
||||||
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 " +
|
Console.WriteLine("*** Make sure 'certificate.crt' and 'private.key' are provided in the " +
|
||||||
"appropriate directory (see docs for info).");
|
"appropriate directory (see docs for info). ***\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,17 +91,14 @@ namespace Bit.Setup
|
|||||||
var sslDiffieHellman = letsEncrypt;
|
var sslDiffieHellman = letsEncrypt;
|
||||||
if(ssl && !selfSignedSsl && !letsEncrypt)
|
if(ssl && !selfSignedSsl && !letsEncrypt)
|
||||||
{
|
{
|
||||||
Console.Write("(!) Use Diffie Hellman ephemeral parameters for SSL (requires dhparam.pem)? (y/n): ");
|
sslDiffieHellman = ReadQuestion(
|
||||||
sslDiffieHellman = Console.ReadLine().ToLowerInvariant() == "y";
|
"Use Diffie Hellman ephemeral parameters for SSL (requires dhparam.pem)?");
|
||||||
Console.Write("(!) Is this a trusted SSL certificate (requires ca.crt)? (y/n): ");
|
sslTrusted = ReadQuestion("Is this a trusted SSL certificate (requires ca.crt)?");
|
||||||
sslTrusted = Console.ReadLine().ToLowerInvariant() == "y";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = $"https://{domain}";
|
var url = $"https://{domain}";
|
||||||
Console.Write("(!) Do you want to use the default ports for HTTP (80) and HTTPS (443)? (y/n): ");
|
|
||||||
var defaultPorts = Console.ReadLine().ToLowerInvariant() == "y";
|
|
||||||
int httpPort = default(int), httpsPort = default(int);
|
int httpPort = default(int), httpsPort = default(int);
|
||||||
if(defaultPorts)
|
if(ReadQuestion("Do you want to use the default ports for HTTP (80) and HTTPS (443)?"))
|
||||||
{
|
{
|
||||||
httpPort = 80;
|
httpPort = 80;
|
||||||
if(ssl)
|
if(ssl)
|
||||||
@ -111,8 +109,7 @@ namespace Bit.Setup
|
|||||||
else if(ssl)
|
else if(ssl)
|
||||||
{
|
{
|
||||||
httpsPort = 443;
|
httpsPort = 443;
|
||||||
Console.Write("(!) HTTPS port: ");
|
if(int.TryParse(ReadInput("HTTPS port").ToLowerInvariant().Trim(), out httpsPort) && httpsPort != 443)
|
||||||
if(int.TryParse(Console.ReadLine().ToLowerInvariant().Trim(), out httpsPort) && httpsPort != 443)
|
|
||||||
{
|
{
|
||||||
url += (":" + httpsPort);
|
url += (":" + httpsPort);
|
||||||
}
|
}
|
||||||
@ -124,27 +121,21 @@ namespace Bit.Setup
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
httpPort = 80;
|
httpPort = 80;
|
||||||
Console.Write("(!) HTTP port: ");
|
if(!int.TryParse(ReadInput("HTTP port").ToLowerInvariant().Trim(), out httpPort) && httpPort != 80)
|
||||||
if(!int.TryParse(Console.ReadLine().ToLowerInvariant().Trim(), out httpPort) && httpPort != 80)
|
|
||||||
{
|
{
|
||||||
Console.WriteLine("Using default port.");
|
Console.WriteLine("Using default port.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.Write("(!) Is your installation behind a reverse proxy? (y/n): ");
|
if(ReadQuestion("Is your installation behind a reverse proxy?"))
|
||||||
var reverseProxy = Console.ReadLine().ToLowerInvariant() == "y";
|
|
||||||
if(reverseProxy)
|
|
||||||
{
|
{
|
||||||
Console.Write("(!) Do you use the default HTTPS port (443) on your reverse proxy? (y/n): ");
|
if(ReadQuestion("Do you use the default HTTPS port (443) on your reverse proxy?"))
|
||||||
var proxyDefaultPort = Console.ReadLine().ToLowerInvariant() == "y";
|
|
||||||
if(proxyDefaultPort)
|
|
||||||
{
|
{
|
||||||
url = $"https://{domain}";
|
url = $"https://{domain}";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.Write("(!) Proxy HTTPS port: ");
|
if(int.TryParse(ReadInput("Proxy HTTPS port").ToLowerInvariant().Trim(), out var httpsReversePort)
|
||||||
if(int.TryParse(Console.ReadLine().ToLowerInvariant().Trim(), out var httpsReversePort)
|
|
||||||
&& httpsReversePort != 443)
|
&& httpsReversePort != 443)
|
||||||
{
|
{
|
||||||
url += (":" + httpsReversePort);
|
url += (":" + httpsReversePort);
|
||||||
@ -162,8 +153,7 @@ namespace Bit.Setup
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.Write("(!) Do you want to use push notifications? (y/n): ");
|
var push = ReadQuestion("Do you want to use push notifications?");
|
||||||
var push = Console.ReadLine().ToLowerInvariant() == "y";
|
|
||||||
|
|
||||||
var nginxBuilder = new NginxConfigBuilder(domain, url, ssl, selfSignedSsl, letsEncrypt,
|
var nginxBuilder = new NginxConfigBuilder(domain, url, ssl, selfSignedSsl, letsEncrypt,
|
||||||
sslTrusted, sslDiffieHellman);
|
sslTrusted, sslDiffieHellman);
|
||||||
@ -280,18 +270,15 @@ namespace Bit.Setup
|
|||||||
|
|
||||||
private static bool ValidateInstallation()
|
private static bool ValidateInstallation()
|
||||||
{
|
{
|
||||||
Console.Write("(!) Enter your installation id (get it at https://bitwarden.com/host): ");
|
var installationId = ReadInput("Enter your installation id (get it at https://bitwarden.com/host)");
|
||||||
var installationId = Console.ReadLine();
|
if(!Guid.TryParse(installationId.Trim(), out var installationidGuid))
|
||||||
Guid installationidGuid;
|
|
||||||
if(!Guid.TryParse(installationId.Trim(), out installationidGuid))
|
|
||||||
{
|
{
|
||||||
Console.WriteLine("Invalid installation id.");
|
Console.WriteLine("Invalid installation id.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_installationId = installationidGuid;
|
|
||||||
|
|
||||||
Console.Write("(!) Enter your installation key: ");
|
_installationId = installationidGuid;
|
||||||
_installationKey = Console.ReadLine();
|
_installationKey = ReadInput("Enter your installation key");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -371,5 +358,27 @@ 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();
|
||||||
|
return input == "y" || input == "yes";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user