Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.1.0 #62

Merged
merged 3 commits into from
Apr 3, 2024
Merged

Release v1.1.0 #62

merged 3 commits into from
Apr 3, 2024

Conversation

msimerson
Copy link
Member

@msimerson msimerson commented Apr 2, 2024

@msimerson
Copy link
Member Author

@lnedry Thanks for the fix in PR #58, that was some good sleuthing. Rather that using exec in a stateful way (as we had), I like the idea of making the code simpler and clearer. What do you think of this implementation that uses matchAll and the ... iterator?

exports.received_headers = function (connection) {

  const received = connection.transaction.header.get_all('received')
  if (!received.length) return []

  const results = []
  const ipany_re = net_utils.get_ipany_re('[\\[\\(](?:IPv6:)?', '[\\]\\)]')

  // Try and parse each received header
  for (const header of received) {
    for (const match of [...header.matchAll(ipany_re)]) {
      if (net_utils.is_private_ip(match[1])) continue  // exclude private IP

      const gi = this.get_geoip(match[1])
      const country = get_country(gi)
      let logmsg = `received=${match[1]}`
      if (country) {
        logmsg += ` country=${country}`
        results.push(`${match[1]}:${country}`)
      }
      connection.loginfo(this, logmsg)
    }
  }
  return results
}

@msimerson msimerson marked this pull request as ready for review April 2, 2024 22:46
@msimerson msimerson merged commit 2b75f5c into master Apr 3, 2024
20 checks passed
@msimerson msimerson deleted the release-1.1.0 branch April 3, 2024 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant