This commit is contained in:
UbitUmarov
2020-10-01 02:10:32 +01:00
parent df29d687ae
commit bc1ea2ef3a
3 changed files with 192 additions and 122 deletions

View File

@@ -57,6 +57,7 @@ namespace OpenSim.Framework.Servers.HttpServer
private static Encoding UTF8NoBOM = new System.Text.UTF8Encoding(false);
public static PollServiceRequestManager m_pollServiceManager;
private static object m_generalLock = new object();
private string HTTP404;
/// <summary>
/// This is a pending websocket request before it got an sucessful upgrade response.
@@ -157,6 +158,55 @@ namespace OpenSim.Framework.Servers.HttpServer
public BaseHttpServer(uint port)
{
m_port = port;
SetHTTP404();
}
public BaseHttpServer(uint port, bool ssl, string CN, string CPath, string CPass)
{
m_port = port;
if (ssl)
{
if (string.IsNullOrEmpty(CPath))
throw new Exception("invalid main http server cert path");
if (Uri.CheckHostName(CN) == UriHostNameType.Unknown)
throw new Exception("invalid main http server CN (ExternalHostName)");
m_certNames.Clear();
m_certIPs.Clear();
m_certCN = "";
m_ssl = true;
load_cert(CPath, CPass);
if (!CheckSSLCertHost(CN))
throw new Exception("invalid main http server CN (ExternalHostName)");
m_SSLCommonName = CN;
if (m_cert.Issuer == m_cert.Subject)
m_log.Warn("Self signed certificate. Clients need to allow this (some viewers debug option NoVerifySSLcert must be set to true");
}
else
m_ssl = false;
SetHTTP404();
}
public BaseHttpServer(uint port, bool ssl, string CPath, string CPass)
{
m_port = port;
if (ssl)
{
load_cert(CPath, CPass);
if (m_cert.Issuer == m_cert.Subject)
m_log.Warn("Self signed certificate. Http clients need to allow this");
m_ssl = true;
}
else
m_ssl = false;
SetHTTP404();
}
public RemoteCertificateValidationCallback CertificateValidationCallback
@@ -212,50 +262,6 @@ namespace OpenSim.Framework.Servers.HttpServer
}
}
public BaseHttpServer(uint port, bool ssl, string CN, string CPath, string CPass)
{
m_port = port;
if (ssl)
{
if(string.IsNullOrEmpty(CPath))
throw new Exception("invalid main http server cert path");
if(Uri.CheckHostName(CN) == UriHostNameType.Unknown)
throw new Exception("invalid main http server CN (ExternalHostName)");
m_certNames.Clear();
m_certIPs.Clear();
m_certCN= "";
m_ssl = true;
load_cert(CPath, CPass);
if(!CheckSSLCertHost(CN))
throw new Exception("invalid main http server CN (ExternalHostName)");
m_SSLCommonName = CN;
if(m_cert.Issuer == m_cert.Subject )
m_log.Warn("Self signed certificate. Clients need to allow this (some viewers debug option NoVerifySSLcert must be set to true");
}
else
m_ssl = false;
}
public BaseHttpServer(uint port, bool ssl, string CPath, string CPass)
{
m_port = port;
if (ssl)
{
load_cert(CPath, CPass);
if(m_cert.Issuer == m_cert.Subject )
m_log.Warn("Self signed certificate. Http clients need to allow this");
m_ssl = true;
}
else
m_ssl = false;
}
static bool MatchDNS(string hostname, string dns)
{
int indx = dns.IndexOf('*');
@@ -1068,7 +1074,7 @@ namespace OpenSim.Framework.Servers.HttpServer
if(m_pollHandlersVarPath.Count > 0 && handlerKey.Length >= 45)
{
// tunned for lsl requests, the only ones that should reach this, so be restrict (/lslhttp/uuid.ToString())
// tuned for lsl requests, the only ones that should reach this, so be strict (/lslhttp/uuid.ToString())
int indx = handlerKey.IndexOf('/', 44);
if (indx < 44) //lsl requests
{
@@ -2335,23 +2341,34 @@ namespace OpenSim.Framework.Servers.HttpServer
return false;
}
public string GetHTTP404()
{
string file = Path.Combine(".", "http_404.html");
if (!File.Exists(file))
return getDefaultHTTP404();
StreamReader sr = File.OpenText(file);
string result = sr.ReadToEnd();
sr.Close();
return result;
}
// Fallback HTTP responses in case the HTTP error response files don't exist
private static string getDefaultHTTP404()
{
return "<HTML><HEAD><TITLE>404 Page not found</TITLE><BODY><BR /><H1>Ooops!</H1><P>The page you requested has been obsconded with by knomes. Find hippos quick!</P></BODY></HTML>";
}
public void SetHTTP404()
{
string file = Path.Combine(".", "http_404.html");
try
{
if (File.Exists(file))
{
using (StreamReader sr = File.OpenText(file))
HTTP404 = sr.ReadToEnd();
if(string.IsNullOrWhiteSpace(HTTP404))
HTTP404 = getDefaultHTTP404();
return;
}
}
catch { }
HTTP404 = getDefaultHTTP404();
}
public string GetHTTP404()
{
return HTTP404;
}
}
public class HttpServerContextObj