forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
59 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Sparrow.Logging; | ||
|
||
namespace Raven.Server.Web | ||
{ | ||
public abstract partial class RequestHandler | ||
{ | ||
public bool IsLocalRequest() | ||
{ | ||
if (HttpContext.Connection.RemoteIpAddress == null && HttpContext.Connection.LocalIpAddress == null) | ||
{ | ||
return true; | ||
} | ||
if (HttpContext.Connection.RemoteIpAddress.Equals(HttpContext.Connection.LocalIpAddress)) | ||
{ | ||
return true; | ||
} | ||
if (IPAddress.IsLoopback(HttpContext.Connection.RemoteIpAddress)) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public string RequestIp => IsLocalRequest() ? Environment.MachineName : HttpContext.Connection.RemoteIpAddress.ToString(); | ||
|
||
public void LogAuditFor(string logger, string message) | ||
{ | ||
var auditLog = LoggingSource.AuditLog.GetLogger(logger, "Audit"); | ||
Debug.Assert(auditLog.IsInfoEnabled, $"auditlog info is disabled"); | ||
|
||
var clientCert = GetCurrentCertificate(); | ||
|
||
var sb = new StringBuilder(); | ||
sb.Append(RequestIp); | ||
sb.Append(", "); | ||
if (clientCert != null) | ||
sb.Append($"CN={clientCert.Subject} [{clientCert.Thumbprint}], "); | ||
else | ||
sb.Append("no certificate, "); | ||
|
||
sb.Append(message); | ||
|
||
auditLog.Info(sb.ToString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters