mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
Changed all C# control flow block statements to include space between keyword and open paren
This commit is contained in:
@ -22,7 +22,7 @@ namespace Bit.Setup
|
||||
Helpers.WriteLine(_context, "Building FIDO U2F app id.");
|
||||
Directory.CreateDirectory("/bitwarden/web/");
|
||||
var template = Helpers.ReadTemplate("AppId");
|
||||
using(var sw = File.CreateText("/bitwarden/web/app-id.json"))
|
||||
using (var sw = File.CreateText("/bitwarden/web/app-id.json"))
|
||||
{
|
||||
sw.Write(template(model));
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace Bit.Setup
|
||||
|
||||
public void BuildForInstall()
|
||||
{
|
||||
if(_context.Stub)
|
||||
if (_context.Stub)
|
||||
{
|
||||
_context.Config.Ssl = true;
|
||||
_context.Install.Trusted = true;
|
||||
@ -26,17 +26,17 @@ namespace Bit.Setup
|
||||
|
||||
_context.Config.Ssl = _context.Config.SslManagedLetsEncrypt;
|
||||
|
||||
if(!_context.Config.Ssl)
|
||||
if (!_context.Config.Ssl)
|
||||
{
|
||||
_context.Config.Ssl = Helpers.ReadQuestion("Do you have a SSL certificate to use?");
|
||||
if(_context.Config.Ssl)
|
||||
if (_context.Config.Ssl)
|
||||
{
|
||||
Directory.CreateDirectory($"/bitwarden/ssl/{_context.Install.Domain}/");
|
||||
var message = "Make sure 'certificate.crt' and 'private.key' are provided in the \n" +
|
||||
"appropriate directory before running 'start' (see docs for info).";
|
||||
Helpers.ShowBanner(_context, "NOTE", message);
|
||||
}
|
||||
else if(Helpers.ReadQuestion("Do you want to generate a self-signed SSL certificate?"))
|
||||
else if (Helpers.ReadQuestion("Do you want to generate a self-signed SSL certificate?"))
|
||||
{
|
||||
Directory.CreateDirectory($"/bitwarden/ssl/self/{_context.Install.Domain}/");
|
||||
Helpers.WriteLine(_context, "Generating self signed SSL certificate.");
|
||||
@ -52,7 +52,7 @@ namespace Bit.Setup
|
||||
}
|
||||
}
|
||||
|
||||
if(_context.Config.SslManagedLetsEncrypt)
|
||||
if (_context.Config.SslManagedLetsEncrypt)
|
||||
{
|
||||
_context.Install.Trusted = true;
|
||||
_context.Install.DiffieHellman = true;
|
||||
@ -60,7 +60,7 @@ namespace Bit.Setup
|
||||
Helpers.Exec($"openssl dhparam -out " +
|
||||
$"/bitwarden/letsencrypt/live/{_context.Install.Domain}/dhparam.pem 2048");
|
||||
}
|
||||
else if(_context.Config.Ssl && !_context.Install.SelfSignedCert)
|
||||
else if (_context.Config.Ssl && !_context.Install.SelfSignedCert)
|
||||
{
|
||||
_context.Install.Trusted = Helpers.ReadQuestion("Is this a trusted SSL certificate " +
|
||||
"(requires ca.crt, see docs)?");
|
||||
@ -76,14 +76,14 @@ namespace Bit.Setup
|
||||
|
||||
Helpers.WriteLine(_context);
|
||||
|
||||
if(!_context.Config.Ssl)
|
||||
if (!_context.Config.Ssl)
|
||||
{
|
||||
var message = "You are not using a SSL certificate. Bitwarden requires HTTPS to operate. \n" +
|
||||
"You must front your installation with a HTTPS proxy or the web vault (and \n" +
|
||||
"other Bitwarden apps) will not work properly.";
|
||||
Helpers.ShowBanner(_context, "WARNING", message, ConsoleColor.Yellow);
|
||||
}
|
||||
else if(_context.Config.Ssl && !_context.Install.Trusted)
|
||||
else if (_context.Config.Ssl && !_context.Install.Trusted)
|
||||
{
|
||||
var message = "You are using an untrusted SSL certificate. This certificate will not be \n" +
|
||||
"trusted by Bitwarden client applications. You must add this certificate to \n" +
|
||||
|
@ -92,7 +92,7 @@ namespace Bit.Setup
|
||||
{
|
||||
get
|
||||
{
|
||||
if(Uri.TryCreate(Url, UriKind.Absolute, out var uri))
|
||||
if (Uri.TryCreate(Url, UriKind.Absolute, out var uri))
|
||||
{
|
||||
return uri.Host;
|
||||
}
|
||||
|
@ -28,13 +28,13 @@ namespace Bit.Setup
|
||||
|
||||
public void LoadConfiguration()
|
||||
{
|
||||
if(!File.Exists(ConfigPath))
|
||||
if (!File.Exists(ConfigPath))
|
||||
{
|
||||
Helpers.WriteLine(this, "No existing `config.yml` detected. Let's generate one.");
|
||||
|
||||
// Looks like updating from older version. Try to create config file.
|
||||
var url = Helpers.GetValueFromEnvFile("global", "globalSettings__baseServiceUri__vault");
|
||||
if(!Uri.TryCreate(url, UriKind.Absolute, out var uri))
|
||||
if (!Uri.TryCreate(url, UriKind.Absolute, out var uri))
|
||||
{
|
||||
Helpers.WriteLine(this, "Unable to determine existing installation url.");
|
||||
return;
|
||||
@ -45,36 +45,36 @@ namespace Bit.Setup
|
||||
Config.PushNotifications = push != "REPLACE";
|
||||
|
||||
var composeFile = "/bitwarden/docker/docker-compose.yml";
|
||||
if(File.Exists(composeFile))
|
||||
if (File.Exists(composeFile))
|
||||
{
|
||||
var fileLines = File.ReadAllLines(composeFile);
|
||||
foreach(var line in fileLines)
|
||||
foreach (var line in fileLines)
|
||||
{
|
||||
if(!line.StartsWith("# Parameter:"))
|
||||
if (!line.StartsWith("# Parameter:"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var paramParts = line.Split("=");
|
||||
if(paramParts.Length < 2)
|
||||
if (paramParts.Length < 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(paramParts[0] == "# Parameter:MssqlDataDockerVolume" &&
|
||||
if (paramParts[0] == "# Parameter:MssqlDataDockerVolume" &&
|
||||
bool.TryParse(paramParts[1], out var mssqlDataDockerVolume))
|
||||
{
|
||||
Config.DatabaseDockerVolume = mssqlDataDockerVolume;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(paramParts[0] == "# Parameter:HttpPort" && int.TryParse(paramParts[1], out var httpPort))
|
||||
if (paramParts[0] == "# Parameter:HttpPort" && int.TryParse(paramParts[1], out var httpPort))
|
||||
{
|
||||
Config.HttpPort = httpPort == 0 ? null : httpPort.ToString();
|
||||
continue;
|
||||
}
|
||||
|
||||
if(paramParts[0] == "# Parameter:HttpsPort" && int.TryParse(paramParts[1], out var httpsPort))
|
||||
if (paramParts[0] == "# Parameter:HttpsPort" && int.TryParse(paramParts[1], out var httpsPort))
|
||||
{
|
||||
Config.HttpsPort = httpsPort == 0 ? null : httpsPort.ToString();
|
||||
continue;
|
||||
@ -83,7 +83,7 @@ namespace Bit.Setup
|
||||
}
|
||||
|
||||
var nginxFile = "/bitwarden/nginx/default.conf";
|
||||
if(File.Exists(nginxFile))
|
||||
if (File.Exists(nginxFile))
|
||||
{
|
||||
var confContent = File.ReadAllText(nginxFile);
|
||||
var selfSigned = confContent.Contains("/etc/ssl/self/");
|
||||
@ -91,20 +91,20 @@ namespace Bit.Setup
|
||||
Config.SslManagedLetsEncrypt = !selfSigned && confContent.Contains("/etc/letsencrypt/live/");
|
||||
var diffieHellman = confContent.Contains("/dhparam.pem;");
|
||||
var trusted = confContent.Contains("ssl_trusted_certificate ");
|
||||
if(Config.SslManagedLetsEncrypt)
|
||||
if (Config.SslManagedLetsEncrypt)
|
||||
{
|
||||
Config.Ssl = true;
|
||||
}
|
||||
else if(Config.Ssl)
|
||||
else if (Config.Ssl)
|
||||
{
|
||||
var sslPath = selfSigned ? $"/etc/ssl/self/{Config.Domain}" : $"/etc/ssl/{Config.Domain}";
|
||||
Config.SslCertificatePath = string.Concat(sslPath, "/", "certificate.crt");
|
||||
Config.SslKeyPath = string.Concat(sslPath, "/", "private.key");
|
||||
if(trusted)
|
||||
if (trusted)
|
||||
{
|
||||
Config.SslCaPath = string.Concat(sslPath, "/", "ca.crt");
|
||||
}
|
||||
if(diffieHellman)
|
||||
if (diffieHellman)
|
||||
{
|
||||
Config.SslDiffieHellmanPath = string.Concat(sslPath, "/", "dhparam.pem");
|
||||
}
|
||||
@ -123,7 +123,7 @@ namespace Bit.Setup
|
||||
|
||||
public void SaveConfiguration()
|
||||
{
|
||||
if(Config == null)
|
||||
if (Config == null)
|
||||
{
|
||||
throw new Exception("Config is null.");
|
||||
}
|
||||
@ -134,7 +134,7 @@ namespace Bit.Setup
|
||||
.Build();
|
||||
var yaml = serializer.Serialize(Config);
|
||||
Directory.CreateDirectory("/bitwarden/");
|
||||
using(var sw = File.CreateText(ConfigPath))
|
||||
using (var sw = File.CreateText(ConfigPath))
|
||||
{
|
||||
sw.Write(yaml);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ namespace Bit.Setup
|
||||
{
|
||||
Directory.CreateDirectory("/bitwarden/docker/");
|
||||
Helpers.WriteLine(_context, "Building docker-compose.yml.");
|
||||
if(!_context.Config.GenerateComposeConfig)
|
||||
if (!_context.Config.GenerateComposeConfig)
|
||||
{
|
||||
Helpers.WriteLine(_context, "...skipped");
|
||||
return;
|
||||
@ -35,7 +35,7 @@ namespace Bit.Setup
|
||||
|
||||
var template = Helpers.ReadTemplate("DockerCompose");
|
||||
var model = new TemplateModel(_context);
|
||||
using(var sw = File.CreateText("/bitwarden/docker/docker-compose.yml"))
|
||||
using (var sw = File.CreateText("/bitwarden/docker/docker-compose.yml"))
|
||||
{
|
||||
sw.Write(template(model));
|
||||
}
|
||||
@ -45,18 +45,18 @@ namespace Bit.Setup
|
||||
{
|
||||
public TemplateModel(Context context)
|
||||
{
|
||||
if(!string.IsNullOrWhiteSpace(context.Config.ComposeVersion))
|
||||
if (!string.IsNullOrWhiteSpace(context.Config.ComposeVersion))
|
||||
{
|
||||
ComposeVersion = context.Config.ComposeVersion;
|
||||
}
|
||||
MssqlDataDockerVolume = context.Config.DatabaseDockerVolume;
|
||||
HttpPort = context.Config.HttpPort;
|
||||
HttpsPort = context.Config.HttpsPort;
|
||||
if(!string.IsNullOrWhiteSpace(context.CoreVersion))
|
||||
if (!string.IsNullOrWhiteSpace(context.CoreVersion))
|
||||
{
|
||||
CoreVersion = context.CoreVersion;
|
||||
}
|
||||
if(!string.IsNullOrWhiteSpace(context.WebVersion))
|
||||
if (!string.IsNullOrWhiteSpace(context.WebVersion))
|
||||
{
|
||||
WebVersion = context.WebVersion;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ namespace Bit.Setup
|
||||
LoadExistingValues(_globalOverrideValues, "/bitwarden/env/global.override.env");
|
||||
LoadExistingValues(_mssqlOverrideValues, "/bitwarden/env/mssql.override.env");
|
||||
|
||||
if(_context.Config.PushNotifications &&
|
||||
if (_context.Config.PushNotifications &&
|
||||
_globalOverrideValues.ContainsKey("globalSettings__pushRelayBaseUri") &&
|
||||
_globalOverrideValues["globalSettings__pushRelayBaseUri"] == "REPLACE")
|
||||
{
|
||||
@ -115,7 +115,7 @@ namespace Bit.Setup
|
||||
["adminSettings__admins"] = string.Empty,
|
||||
};
|
||||
|
||||
if(!_context.Config.PushNotifications)
|
||||
if (!_context.Config.PushNotifications)
|
||||
{
|
||||
_globalOverrideValues.Add("globalSettings__pushRelayBaseUri", "REPLACE");
|
||||
}
|
||||
@ -130,32 +130,32 @@ namespace Bit.Setup
|
||||
|
||||
private void LoadExistingValues(IDictionary<string, string> _values, string file)
|
||||
{
|
||||
if(!File.Exists(file))
|
||||
if (!File.Exists(file))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var fileLines = File.ReadAllLines(file);
|
||||
foreach(var line in fileLines)
|
||||
foreach (var line in fileLines)
|
||||
{
|
||||
if(!line.Contains("="))
|
||||
if (!line.Contains("="))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var value = string.Empty;
|
||||
var lineParts = line.Split("=", 2);
|
||||
if(lineParts.Length < 1)
|
||||
if (lineParts.Length < 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(lineParts.Length > 1)
|
||||
if (lineParts.Length > 1)
|
||||
{
|
||||
value = lineParts[1];
|
||||
}
|
||||
|
||||
if(_values.ContainsKey(lineParts[0]))
|
||||
if (_values.ContainsKey(lineParts[0]))
|
||||
{
|
||||
_values[lineParts[0]] = value;
|
||||
}
|
||||
@ -172,13 +172,13 @@ namespace Bit.Setup
|
||||
|
||||
Helpers.WriteLine(_context, "Building docker environment files.");
|
||||
Directory.CreateDirectory("/bitwarden/docker/");
|
||||
using(var sw = File.CreateText("/bitwarden/docker/global.env"))
|
||||
using (var sw = File.CreateText("/bitwarden/docker/global.env"))
|
||||
{
|
||||
sw.Write(template(new TemplateModel(_globalValues)));
|
||||
}
|
||||
Helpers.Exec("chmod 600 /bitwarden/docker/global.env");
|
||||
|
||||
using(var sw = File.CreateText("/bitwarden/docker/mssql.env"))
|
||||
using (var sw = File.CreateText("/bitwarden/docker/mssql.env"))
|
||||
{
|
||||
sw.Write(template(new TemplateModel(_mssqlValues)));
|
||||
}
|
||||
@ -186,22 +186,22 @@ namespace Bit.Setup
|
||||
|
||||
Helpers.WriteLine(_context, "Building docker environment override files.");
|
||||
Directory.CreateDirectory("/bitwarden/env/");
|
||||
using(var sw = File.CreateText("/bitwarden/env/global.override.env"))
|
||||
using (var sw = File.CreateText("/bitwarden/env/global.override.env"))
|
||||
{
|
||||
sw.Write(template(new TemplateModel(_globalOverrideValues)));
|
||||
}
|
||||
Helpers.Exec("chmod 600 /bitwarden/env/global.override.env");
|
||||
|
||||
using(var sw = File.CreateText("/bitwarden/env/mssql.override.env"))
|
||||
using (var sw = File.CreateText("/bitwarden/env/mssql.override.env"))
|
||||
{
|
||||
sw.Write(template(new TemplateModel(_mssqlOverrideValues)));
|
||||
}
|
||||
Helpers.Exec("chmod 600 /bitwarden/env/mssql.override.env");
|
||||
|
||||
// Empty uid env file. Only used on Linux hosts.
|
||||
if(!File.Exists("/bitwarden/env/uid.env"))
|
||||
if (!File.Exists("/bitwarden/env/uid.env"))
|
||||
{
|
||||
using(var sw = File.CreateText("/bitwarden/env/uid.env")) { }
|
||||
using (var sw = File.CreateText("/bitwarden/env/uid.env")) { }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,18 +20,18 @@ namespace Bit.Setup
|
||||
// ref https://stackoverflow.com/a/8996788/1090359 with modifications
|
||||
public static string SecureRandomString(int length, string characters)
|
||||
{
|
||||
if(length < 0)
|
||||
if (length < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(length), "length cannot be less than zero.");
|
||||
}
|
||||
|
||||
if((characters?.Length ?? 0) == 0)
|
||||
if ((characters?.Length ?? 0) == 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(characters), "characters invalid.");
|
||||
}
|
||||
|
||||
const int byteSize = 0x100;
|
||||
if(byteSize < characters.Length)
|
||||
if (byteSize < characters.Length)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
string.Format("{0} may contain no more than {1} characters.", nameof(characters), byteSize),
|
||||
@ -39,19 +39,19 @@ namespace Bit.Setup
|
||||
}
|
||||
|
||||
var outOfRangeStart = byteSize - (byteSize % characters.Length);
|
||||
using(var rng = RandomNumberGenerator.Create())
|
||||
using (var rng = RandomNumberGenerator.Create())
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var buffer = new byte[128];
|
||||
while(sb.Length < length)
|
||||
while (sb.Length < length)
|
||||
{
|
||||
rng.GetBytes(buffer);
|
||||
for(var i = 0; i < buffer.Length && sb.Length < length; ++i)
|
||||
for (var i = 0; i < buffer.Length && sb.Length < length; ++i)
|
||||
{
|
||||
// Divide the byte into charSet-sized groups. If the random value falls into the last group and the
|
||||
// last group is too small to choose from the entire allowedCharSet, ignore the value in order to
|
||||
// avoid biasing the result.
|
||||
if(outOfRangeStart <= buffer[i])
|
||||
if (outOfRangeStart <= buffer[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -67,25 +67,25 @@ namespace Bit.Setup
|
||||
private static string RandomStringCharacters(bool alpha, bool upper, bool lower, bool numeric, bool special)
|
||||
{
|
||||
var characters = string.Empty;
|
||||
if(alpha)
|
||||
if (alpha)
|
||||
{
|
||||
if(upper)
|
||||
if (upper)
|
||||
{
|
||||
characters += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
}
|
||||
|
||||
if(lower)
|
||||
if (lower)
|
||||
{
|
||||
characters += "abcdefghijklmnopqrstuvwxyz";
|
||||
}
|
||||
}
|
||||
|
||||
if(numeric)
|
||||
if (numeric)
|
||||
{
|
||||
characters += "0123456789";
|
||||
}
|
||||
|
||||
if(special)
|
||||
if (special)
|
||||
{
|
||||
characters += "!@#$%^*&";
|
||||
}
|
||||
@ -95,15 +95,15 @@ namespace Bit.Setup
|
||||
|
||||
public static string GetValueFromEnvFile(string envFile, string key)
|
||||
{
|
||||
if(!File.Exists($"/bitwarden/env/{envFile}.override.env"))
|
||||
if (!File.Exists($"/bitwarden/env/{envFile}.override.env"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var lines = File.ReadAllLines($"/bitwarden/env/{envFile}.override.env");
|
||||
foreach(var line in lines)
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if(line.StartsWith($"{key}="))
|
||||
if (line.StartsWith($"{key}="))
|
||||
{
|
||||
return line.Split(new char[] { '=' }, 2)[1].Trim('"');
|
||||
}
|
||||
@ -125,7 +125,7 @@ namespace Bit.Setup
|
||||
}
|
||||
};
|
||||
|
||||
if(!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
var escapedArgs = cmd.Replace("\"", "\\\"");
|
||||
process.StartInfo.FileName = "/bin/bash";
|
||||
@ -149,7 +149,7 @@ namespace Bit.Setup
|
||||
Console.Write("(!) ");
|
||||
Console.ResetColor();
|
||||
Console.Write(prompt);
|
||||
if(prompt.EndsWith("?"))
|
||||
if (prompt.EndsWith("?"))
|
||||
{
|
||||
Console.Write(" (y/n)");
|
||||
}
|
||||
@ -167,11 +167,11 @@ namespace Bit.Setup
|
||||
|
||||
public static void ShowBanner(Context context, string title, string message, ConsoleColor? color = null)
|
||||
{
|
||||
if(!context.PrintToScreen())
|
||||
if (!context.PrintToScreen())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(color != null)
|
||||
if (color != null)
|
||||
{
|
||||
Console.ForegroundColor = color.Value;
|
||||
}
|
||||
@ -185,12 +185,12 @@ namespace Bit.Setup
|
||||
{
|
||||
var assembly = typeof(Helpers).GetTypeInfo().Assembly;
|
||||
var fullTemplateName = $"Bit.Setup.Templates.{templateName}.hbs";
|
||||
if(!assembly.GetManifestResourceNames().Any(f => f == fullTemplateName))
|
||||
if (!assembly.GetManifestResourceNames().Any(f => f == fullTemplateName))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using(var s = assembly.GetManifestResourceStream(fullTemplateName))
|
||||
using(var sr = new StreamReader(s))
|
||||
using (var s = assembly.GetManifestResourceStream(fullTemplateName))
|
||||
using (var sr = new StreamReader(s))
|
||||
{
|
||||
var templateText = sr.ReadToEnd();
|
||||
return HandlebarsDotNet.Handlebars.Compile(templateText);
|
||||
@ -200,23 +200,23 @@ namespace Bit.Setup
|
||||
public static void WriteLine(Context context, string format = null, object arg0 = null, object arg1 = null,
|
||||
object arg2 = null)
|
||||
{
|
||||
if(!context.PrintToScreen())
|
||||
if (!context.PrintToScreen())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(format != null && arg0 != null && arg1 != null && arg2 != null)
|
||||
if (format != null && arg0 != null && arg1 != null && arg2 != null)
|
||||
{
|
||||
Console.WriteLine(format, arg0, arg1, arg2);
|
||||
}
|
||||
else if(format != null && arg0 != null && arg1 != null)
|
||||
else if (format != null && arg0 != null && arg1 != null)
|
||||
{
|
||||
Console.WriteLine(format, arg0, arg1);
|
||||
}
|
||||
else if(format != null && arg0 != null)
|
||||
else if (format != null && arg0 != null)
|
||||
{
|
||||
Console.WriteLine(format, arg0);
|
||||
}
|
||||
else if(format != null)
|
||||
else if (format != null)
|
||||
{
|
||||
Console.WriteLine(format);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace Bit.Setup
|
||||
public void BuildForInstaller()
|
||||
{
|
||||
var model = new TemplateModel(_context);
|
||||
if(model.Ssl && !_context.Config.SslManagedLetsEncrypt)
|
||||
if (model.Ssl && !_context.Config.SslManagedLetsEncrypt)
|
||||
{
|
||||
var sslPath = _context.Install.SelfSignedCert ?
|
||||
$"/etc/ssl/self/{model.Domain}" : $"/etc/ssl/{model.Domain}";
|
||||
@ -32,12 +32,12 @@ namespace Bit.Setup
|
||||
string.Concat(sslPath, "/", "certificate.crt");
|
||||
_context.Config.SslKeyPath = model.KeyPath =
|
||||
string.Concat(sslPath, "/", "private.key");
|
||||
if(_context.Install.Trusted)
|
||||
if (_context.Install.Trusted)
|
||||
{
|
||||
_context.Config.SslCaPath = model.CaPath =
|
||||
string.Concat(sslPath, "/", "ca.crt");
|
||||
}
|
||||
if(_context.Install.DiffieHellman)
|
||||
if (_context.Install.DiffieHellman)
|
||||
{
|
||||
_context.Config.SslDiffieHellmanPath = model.DiffieHellmanPath =
|
||||
string.Concat(sslPath, "/", "dhparam.pem");
|
||||
@ -56,14 +56,14 @@ namespace Bit.Setup
|
||||
{
|
||||
Directory.CreateDirectory("/bitwarden/nginx/");
|
||||
Helpers.WriteLine(_context, "Building nginx config.");
|
||||
if(!_context.Config.GenerateNginxConfig)
|
||||
if (!_context.Config.GenerateNginxConfig)
|
||||
{
|
||||
Helpers.WriteLine(_context, "...skipped");
|
||||
return;
|
||||
}
|
||||
|
||||
var template = Helpers.ReadTemplate("NginxConfig");
|
||||
using(var sw = File.CreateText(ConfFile))
|
||||
using (var sw = File.CreateText(ConfFile))
|
||||
{
|
||||
sw.WriteLine(template(model));
|
||||
}
|
||||
@ -80,9 +80,9 @@ namespace Bit.Setup
|
||||
Url = context.Config.Url;
|
||||
RealIps = context.Config.RealIps;
|
||||
|
||||
if(Ssl)
|
||||
if (Ssl)
|
||||
{
|
||||
if(context.Config.SslManagedLetsEncrypt)
|
||||
if (context.Config.SslManagedLetsEncrypt)
|
||||
{
|
||||
var sslPath = $"/etc/letsencrypt/live/{Domain}";
|
||||
CertificatePath = CaPath = string.Concat(sslPath, "/", "fullchain.pem");
|
||||
@ -98,7 +98,7 @@ namespace Bit.Setup
|
||||
}
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(context.Config.SslCiphersuites))
|
||||
if (!string.IsNullOrWhiteSpace(context.Config.SslCiphersuites))
|
||||
{
|
||||
SslCiphers = context.Config.SslCiphersuites;
|
||||
}
|
||||
@ -110,7 +110,7 @@ namespace Bit.Setup
|
||||
"ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256";
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(context.Config.SslVersions))
|
||||
if (!string.IsNullOrWhiteSpace(context.Config.SslVersions))
|
||||
{
|
||||
SslProtocols = context.Config.SslVersions;
|
||||
}
|
||||
|
@ -22,23 +22,23 @@ namespace Bit.Setup
|
||||
};
|
||||
ParseParameters();
|
||||
|
||||
if(_context.Parameters.ContainsKey("q"))
|
||||
if (_context.Parameters.ContainsKey("q"))
|
||||
{
|
||||
_context.Quiet = _context.Parameters["q"] == "true" || _context.Parameters["q"] == "1";
|
||||
}
|
||||
if(_context.Parameters.ContainsKey("os"))
|
||||
if (_context.Parameters.ContainsKey("os"))
|
||||
{
|
||||
_context.HostOS = _context.Parameters["os"];
|
||||
}
|
||||
if(_context.Parameters.ContainsKey("corev"))
|
||||
if (_context.Parameters.ContainsKey("corev"))
|
||||
{
|
||||
_context.CoreVersion = _context.Parameters["corev"];
|
||||
}
|
||||
if(_context.Parameters.ContainsKey("webv"))
|
||||
if (_context.Parameters.ContainsKey("webv"))
|
||||
{
|
||||
_context.WebVersion = _context.Parameters["webv"];
|
||||
}
|
||||
if(_context.Parameters.ContainsKey("stub"))
|
||||
if (_context.Parameters.ContainsKey("stub"))
|
||||
{
|
||||
_context.Stub = _context.Parameters["stub"] == "true" ||
|
||||
_context.Parameters["stub"] == "1";
|
||||
@ -46,15 +46,15 @@ namespace Bit.Setup
|
||||
|
||||
Helpers.WriteLine(_context);
|
||||
|
||||
if(_context.Parameters.ContainsKey("install"))
|
||||
if (_context.Parameters.ContainsKey("install"))
|
||||
{
|
||||
Install();
|
||||
}
|
||||
else if(_context.Parameters.ContainsKey("update"))
|
||||
else if (_context.Parameters.ContainsKey("update"))
|
||||
{
|
||||
Update();
|
||||
}
|
||||
else if(_context.Parameters.ContainsKey("printenv"))
|
||||
else if (_context.Parameters.ContainsKey("printenv"))
|
||||
{
|
||||
PrintEnvironment();
|
||||
}
|
||||
@ -66,22 +66,22 @@ namespace Bit.Setup
|
||||
|
||||
private static void Install()
|
||||
{
|
||||
if(_context.Parameters.ContainsKey("letsencrypt"))
|
||||
if (_context.Parameters.ContainsKey("letsencrypt"))
|
||||
{
|
||||
_context.Config.SslManagedLetsEncrypt =
|
||||
_context.Parameters["letsencrypt"].ToLowerInvariant() == "y";
|
||||
}
|
||||
if(_context.Parameters.ContainsKey("domain"))
|
||||
if (_context.Parameters.ContainsKey("domain"))
|
||||
{
|
||||
_context.Install.Domain = _context.Parameters["domain"].ToLowerInvariant();
|
||||
}
|
||||
|
||||
if(_context.Stub)
|
||||
if (_context.Stub)
|
||||
{
|
||||
_context.Install.InstallationId = Guid.Empty;
|
||||
_context.Install.InstallationKey = "SECRET_INSTALLATION_KEY";
|
||||
}
|
||||
else if(!ValidateInstallation())
|
||||
else if (!ValidateInstallation())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -116,7 +116,7 @@ namespace Bit.Setup
|
||||
"`./bitwarden.sh rebuild` or `./bitwarden.sh update`");
|
||||
|
||||
Console.WriteLine("\nNext steps, run:");
|
||||
if(_context.HostOS == "win")
|
||||
if (_context.HostOS == "win")
|
||||
{
|
||||
Console.WriteLine("`.\\bitwarden.ps1 -start`");
|
||||
}
|
||||
@ -129,7 +129,7 @@ namespace Bit.Setup
|
||||
|
||||
private static void Update()
|
||||
{
|
||||
if(_context.Parameters.ContainsKey("db"))
|
||||
if (_context.Parameters.ContainsKey("db"))
|
||||
{
|
||||
MigrateDatabase();
|
||||
}
|
||||
@ -142,7 +142,7 @@ namespace Bit.Setup
|
||||
private static void PrintEnvironment()
|
||||
{
|
||||
_context.LoadConfiguration();
|
||||
if(!_context.PrintToScreen())
|
||||
if (!_context.PrintToScreen())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -150,7 +150,7 @@ namespace Bit.Setup
|
||||
Console.WriteLine("===================================================");
|
||||
Console.WriteLine("\nvisit {0}", _context.Config.Url);
|
||||
Console.Write("to update, run ");
|
||||
if(_context.HostOS == "win")
|
||||
if (_context.HostOS == "win")
|
||||
{
|
||||
Console.Write("`.\\bitwarden.ps1 -updateself` and then `.\\bitwarden.ps1 -update`");
|
||||
}
|
||||
@ -170,7 +170,7 @@ namespace Bit.Setup
|
||||
"globalSettings__sqlServer__connectionString");
|
||||
var migrator = new DbMigrator(vaultConnectionString, null);
|
||||
var success = migrator.MigrateMsSqlDatabase(false);
|
||||
if(success)
|
||||
if (success)
|
||||
{
|
||||
Helpers.WriteLine(_context, "Migration successful.");
|
||||
}
|
||||
@ -179,9 +179,9 @@ namespace Bit.Setup
|
||||
Helpers.WriteLine(_context, "Migration failed.");
|
||||
}
|
||||
}
|
||||
catch(SqlException e)
|
||||
catch (SqlException e)
|
||||
{
|
||||
if(e.Message.Contains("Server is in script upgrade mode") && attempt < 10)
|
||||
if (e.Message.Contains("Server is in script upgrade mode") && attempt < 10)
|
||||
{
|
||||
var nextAttempt = attempt + 1;
|
||||
Helpers.WriteLine(_context, "Database is in script upgrade mode. " +
|
||||
@ -197,7 +197,7 @@ namespace Bit.Setup
|
||||
private static bool ValidateInstallation()
|
||||
{
|
||||
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.");
|
||||
return false;
|
||||
@ -211,9 +211,9 @@ namespace Bit.Setup
|
||||
var response = new HttpClient().GetAsync("https://api.bitwarden.com/installations/" +
|
||||
_context.Install.InstallationId).GetAwaiter().GetResult();
|
||||
|
||||
if(!response.IsSuccessStatusCode)
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
if(response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
||||
{
|
||||
Console.WriteLine("Invalid installation id.");
|
||||
}
|
||||
@ -227,7 +227,7 @@ namespace Bit.Setup
|
||||
|
||||
var resultString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
||||
var result = JsonConvert.DeserializeObject<dynamic>(resultString);
|
||||
if(!(bool)result.Enabled)
|
||||
if (!(bool)result.Enabled)
|
||||
{
|
||||
Console.WriteLine("Installation id has been disabled.");
|
||||
return false;
|
||||
@ -265,9 +265,9 @@ namespace Bit.Setup
|
||||
private static void ParseParameters()
|
||||
{
|
||||
_context.Parameters = new Dictionary<string, string>();
|
||||
for(var i = 0; i < _context.Args.Length; i = i + 2)
|
||||
for (var i = 0; i < _context.Args.Length; i = i + 2)
|
||||
{
|
||||
if(!_context.Args[i].StartsWith("-"))
|
||||
if (!_context.Args[i].StartsWith("-"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -97,10 +97,10 @@ namespace Bit.Setup
|
||||
|
||||
public override bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value, IEmitter context)
|
||||
{
|
||||
if(value is CommentsObjectDescriptor commentsDescriptor && commentsDescriptor.Comment != null)
|
||||
if (value is CommentsObjectDescriptor commentsDescriptor && commentsDescriptor.Comment != null)
|
||||
{
|
||||
context.Emit(new Comment(string.Empty, false));
|
||||
foreach(var comment in commentsDescriptor.Comment.Split(Environment.NewLine))
|
||||
foreach (var comment in commentsDescriptor.Comment.Split(Environment.NewLine))
|
||||
{
|
||||
context.Emit(new Comment(comment, false));
|
||||
}
|
||||
|
Reference in New Issue
Block a user