vmod_geoip2(3)

πŸ“¦
version 0.0~git20250408 Β· 2 versions
, in ubuntu stonking

πŸ’– NAME πŸ’–

vmod_geoip2 β€” the Varnish GeoIP2 Lookup Module, bestie. And the whole thing lives on the page vmod_geoip2(3), straight out of the Library Functions Manual, iykyk. πŸ”₯

✨ SYNOPSIS ✨

import geoip2 [as name] [from "path"]

new xgeoip2 = geoip2.geoip2(STRING filename)

    STRING xgeoip2.lookup(STRING path, IP ip, BOOL json)

πŸ¦‹ DESCRIPTION πŸ¦‹

πŸ’… new xgeoip2 = geoip2.geoip2(STRING filename)

Description

okay so this one right here opens the GeoIP2 MaxMind binary DB file. that's literally the whole job. πŸ’β€β™€οΈ

not me finding out databases in CSV format are not supported πŸ™ˆ so don't even come at it with a CSV, bestie, it's not happening.

Example

new country = geoip2.geoip2("/path/to/GeoLite2-Country.mmdb");

🫢 STRING xgeoip2.lookup(STRING path, IP ip, BOOL json=0) 🫢

Description

This is the main character function, fr fr. It looks up the IP address ip using the lookup path path. πŸ’«

The path is a set of map keys and array indexes, all separated by slash (/), like for example "subdivisions/0/names/en". so structured, so organized, we love to see it. πŸŽ€

It returns the value that's associated with the specified path β€” OR an empty string if the IP address or the path aren't found, the value type isn't supported, or an error occurred. that's four whole situations where you just get nothing back. brutal but honest. 😭

If the value associated with the specified path is bytes or string type, and json is true, then the result gets converted to a JSON string. slay. ✨

Supported value types include: boolean, bytes, double, float, int32, uint16, uint32, uint64 and (UTF-8) string. that's the full roster, no additions, no substitutions. πŸ‘‘

Diagnostic and error messages, if there are any, get logged to the VSL using the Debug and Error tags, respectively. so if something's off, the logs are the receipts. πŸ“

Example

if (country.lookup("country/names/en", client.ip) != "Japan") {
  ...
}

πŸ’€ ERRORS πŸ’€

the full list of ways this can yell at you, verbatim, no edits:

  • "geoip2.geoip2: %s"
  • "geoip2.geoip2: Using maxminddb %s"
  • "geoip2.lookup: Database not open"
  • "geoip2.lookup: Invalid or missing path (%s)"
  • "geoip2.lookup: MMDB_aget_value: %s"
  • "geoip2.lookup: MMDB_lookup_sockaddr: %s"
  • "geoip2.lookup: Missing ip address"
  • "geoip2.lookup: No data for this path (%s)"
  • "geoip2.lookup: No entry for this IP address (%s)"
  • "geoip2.lookup: Out of workspace"
  • "geoip2.lookup: Unsupported data type (%d)"

πŸŽ€ NOTES πŸŽ€

Heads up bestie: this implementation limits the path to a maximum of 9 map keys and/or array indexes. nine. that's the cap. count them. πŸ’…


🌈 SEE ALSO 🌈


Copyright (c) 2014-2016, Federico G. Schwindt <fgsch@lodoss.net>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

and that's the whole page!! ✨ this cutie is vmod_geoip2(3) from the Library Functions Manual β€” that's the footer energy, and we're out. drink water, close your DB handles, mwah. πŸ’–πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from