public LogLine(string line) { ParseInfo regexMatch = ApacheParseHelper.GetRegexMatch(line); ForwardedFor = regexMatch.RegExMatch.Groups[1].Value; RemoteLogName = regexMatch.RegExMatch.Groups[2 + regexMatch.Offset].Value; RemoteUser = regexMatch.RegExMatch.Groups[3 + regexMatch.Offset].Value; RequestTime = DateTime.ParseExact(regexMatch.RegExMatch.Groups[4 + regexMatch.Offset].Value.Replace(" +0000", ""), "dd/MMM/yyyy:HH:mm:ss", new CultureInfo("en-IE")); URI = regexMatch.RegExMatch.Groups[8 + regexMatch.Offset].Value; Status = int.Parse(regexMatch.RegExMatch.Groups[6 + regexMatch.Offset].Value); ResponseSize = int.Parse(regexMatch.RegExMatch.Groups[7 + regexMatch.Offset].Value); Referrer = regexMatch.RegExMatch.Groups[10 + regexMatch.Offset].Value; if (!(regexMatch.RegExMatch.Groups[11 + regexMatch.Offset].Value == "-")) { PHPTime = int.Parse(regexMatch.RegExMatch.Groups[11 + regexMatch.Offset].Value); } if (!(regexMatch.RegExMatch.Groups[12 + regexMatch.Offset].Value == "-")) { TimeTaken = int.Parse(regexMatch.RegExMatch.Groups[12 + regexMatch.Offset].Value); } Browser = regexMatch.RegExMatch.Groups[9 + regexMatch.Offset].Value; // Cleanup if (ForwardedFor.EndsWith(",")) { ForwardedFor = ForwardedFor.Replace(",", ""); } }
public UserIdentity CurrentUser(INancyModule module) { try { var user = this.GetCurrentUser(module); if (user == null) { Logging.Log().Error("Unknown user. Throwing AuthenticationException..."); throw new AuthenticationException("Cannot authenticate user."); } Logging.Log().Information("User claims he is {0}", user.Id); if (module != null && ForwardedFor.Exist(module.Request.Headers)) { ForwardedFor header = ForwardedFor.Create(module.Request.Headers); if (this.UserIsTrustedServiceAccount(user)) { Logging.Log().Information("User {0} is on the list of trusted service accounts. User {0} acts on behalf of the following user: id={1}, pid={2}, name={3}.", user.Id, header.User.Id, header.User.Pid, header.User.Name); return(header.User); } else { Logging.Log().Warning("User {0} is NOT on the list of trusted service accounts, but sent Forwarded header.", user.Id); } } return(user); } catch (Exception exception) { Logging.Log().Error("Unknown user. Throwing AuthenticationException..."); throw new AuthenticationException("Cannot authenticate user.", exception); } }