fix restart notification for cert config change

This commit is contained in:
Luke Pulverenti 2015-01-19 02:12:01 -05:00
parent be6418a19e
commit bdb9cd77bc

View File

@ -780,32 +780,7 @@ namespace MediaBrowser.Server.Startup.Common
/// </summary> /// </summary>
private void StartServer() private void StartServer()
{ {
if (string.IsNullOrWhiteSpace(ServerConfigurationManager.Configuration.CertificatePath)) CertificatePath = GetCertificatePath(true);
{
// Generate self-signed cert
var certHost = GetHostnameFromExternalDns(ServerConfigurationManager.Configuration.WanDdns);
var certPath = Path.Combine(ServerConfigurationManager.ApplicationPaths.ProgramDataPath, "ssl", "cert_" + certHost.GetMD5().ToString("N") + ".pfx");
if (!File.Exists(certPath))
{
Directory.CreateDirectory(Path.GetDirectoryName(certPath));
try
{
NetworkManager.GenerateSelfSignedSslCertificate(certPath, certHost);
CertificatePath = certHost;
}
catch (Exception ex)
{
Logger.ErrorException("Error creating ssl cert", ex);
}
}
}
else
{
// Custom cert
CertificatePath = ServerConfigurationManager.Configuration.CertificatePath;
}
try try
{ {
@ -819,6 +794,39 @@ namespace MediaBrowser.Server.Startup.Common
} }
} }
private string GetCertificatePath(bool generateCertificate)
{
if (string.IsNullOrWhiteSpace(ServerConfigurationManager.Configuration.CertificatePath))
{
// Generate self-signed cert
var certHost = GetHostnameFromExternalDns(ServerConfigurationManager.Configuration.WanDdns);
var certPath = Path.Combine(ServerConfigurationManager.ApplicationPaths.ProgramDataPath, "ssl", "cert_" + certHost.GetMD5().ToString("N") + ".pfx");
if (generateCertificate)
{
if (!File.Exists(certPath))
{
Directory.CreateDirectory(Path.GetDirectoryName(certPath));
try
{
NetworkManager.GenerateSelfSignedSslCertificate(certPath, certHost);
}
catch (Exception ex)
{
Logger.ErrorException("Error creating ssl cert", ex);
return null;
}
}
}
return certPath;
}
// Custom cert
return ServerConfigurationManager.Configuration.CertificatePath;
}
/// <summary> /// <summary>
/// Called when [configuration updated]. /// Called when [configuration updated].
/// </summary> /// </summary>
@ -849,7 +857,7 @@ namespace MediaBrowser.Server.Startup.Common
requiresRestart = true; requiresRestart = true;
} }
if (!string.Equals(CertificatePath, ServerConfigurationManager.Configuration.CertificatePath, StringComparison.OrdinalIgnoreCase)) if (!string.Equals(CertificatePath, GetCertificatePath(false), StringComparison.OrdinalIgnoreCase))
{ {
requiresRestart = true; requiresRestart = true;
} }