|
@@ -779,6 +779,22 @@ namespace MediaBrowser.Server.Startup.Common
|
|
/// Starts the server.
|
|
/// Starts the server.
|
|
/// </summary>
|
|
/// </summary>
|
|
private void StartServer()
|
|
private void StartServer()
|
|
|
|
+ {
|
|
|
|
+ CertificatePath = GetCertificatePath(true);
|
|
|
|
+
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ ServerManager.Start(GetUrlPrefixes(), CertificatePath);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ Logger.ErrorException("Error starting http server", ex);
|
|
|
|
+
|
|
|
|
+ throw;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private string GetCertificatePath(bool generateCertificate)
|
|
{
|
|
{
|
|
if (string.IsNullOrWhiteSpace(ServerConfigurationManager.Configuration.CertificatePath))
|
|
if (string.IsNullOrWhiteSpace(ServerConfigurationManager.Configuration.CertificatePath))
|
|
{
|
|
{
|
|
@@ -786,37 +802,29 @@ namespace MediaBrowser.Server.Startup.Common
|
|
var certHost = GetHostnameFromExternalDns(ServerConfigurationManager.Configuration.WanDdns);
|
|
var certHost = GetHostnameFromExternalDns(ServerConfigurationManager.Configuration.WanDdns);
|
|
var certPath = Path.Combine(ServerConfigurationManager.ApplicationPaths.ProgramDataPath, "ssl", "cert_" + certHost.GetMD5().ToString("N") + ".pfx");
|
|
var certPath = Path.Combine(ServerConfigurationManager.ApplicationPaths.ProgramDataPath, "ssl", "cert_" + certHost.GetMD5().ToString("N") + ".pfx");
|
|
|
|
|
|
- if (!File.Exists(certPath))
|
|
|
|
|
|
+ if (generateCertificate)
|
|
{
|
|
{
|
|
- Directory.CreateDirectory(Path.GetDirectoryName(certPath));
|
|
|
|
-
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- NetworkManager.GenerateSelfSignedSslCertificate(certPath, certHost);
|
|
|
|
- CertificatePath = certHost;
|
|
|
|
- }
|
|
|
|
- catch (Exception ex)
|
|
|
|
|
|
+ if (!File.Exists(certPath))
|
|
{
|
|
{
|
|
- Logger.ErrorException("Error creating ssl cert", ex);
|
|
|
|
|
|
+ Directory.CreateDirectory(Path.GetDirectoryName(certPath));
|
|
|
|
+
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ NetworkManager.GenerateSelfSignedSslCertificate(certPath, certHost);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ Logger.ErrorException("Error creating ssl cert", ex);
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- // Custom cert
|
|
|
|
- CertificatePath = ServerConfigurationManager.Configuration.CertificatePath;
|
|
|
|
- }
|
|
|
|
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- ServerManager.Start(GetUrlPrefixes(), CertificatePath);
|
|
|
|
|
|
+ return certPath;
|
|
}
|
|
}
|
|
- catch (Exception ex)
|
|
|
|
- {
|
|
|
|
- Logger.ErrorException("Error starting http server", ex);
|
|
|
|
|
|
|
|
- throw;
|
|
|
|
- }
|
|
|
|
|
|
+ // Custom cert
|
|
|
|
+ return ServerConfigurationManager.Configuration.CertificatePath;
|
|
}
|
|
}
|
|
|
|
|
|
/// <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;
|
|
}
|
|
}
|