Giter VIP home page Giter VIP logo

libvmod-ip2location's Introduction

IP2Location Vmod

This vmod used the Hello World vmod (https://github.com/varnish/libvmod-example/tree/master) as a base for a vmod, and draws heavily on simonvik's MaxMind DB VMOD (https://github.com/simonvik/libvmod_maxminddb). You will need to purchase the IP2Location database and install the C class from their developer library to your sever.

Prereqs

Packages:

  1. pkg-config
  2. build-essential
  3. autoconf
  4. libtool
  5. python-docutils
  6. varnish
  7. libvarnishapi-dev

Other software

  1. Varnish needs to be installed, and the Varnish source available. (e.g., if installed from the Debian repo, after following the installation instructions on http://varnish-cache.org, Make sure there is a deb-rc line similar to: deb-src https://repo.varnish-cache.org/debian/ wheezy varnish-4.0 in your /etc/apt/sources.list.d/varnish-cache.list. This allows you to get the source for your installed package using sudo apt-get source varnish)
  2. IP2Location needs to be built and installed on the system. The source can be gotten from the Ip2Location website
  3. IP2Location database needs to be placed in the VMOD directory. You will be able to specify the exact location and binfile in your VCL.

Installation

./autogen.sh
./configure VARNISHSRC=DIR [VMODDIR=DIR]

VARNISHSRC is the directory of the Varnish source tree for which to compile your vmod. Both the VARNISHSRC and VARNISHSRC/include will be added to the include search paths for your module.

Optionally you can also set the vmod install directory by adding VMODDIR=DIR (defaults to the pkg-config discovered directory from your Varnish installation).

Make targets:

  • make - builds the vmod
  • make install - installs your vmod in VMODDIR

Usage

import ip2location;

sub vcl_init{
  ip2location.init_db("/path/to/ip2location_db.bin");
}

sub vcl_recv {
  set req.http.X-Time-Zone = ip2location.lookup_tz(client.ip);
  set req.http.X-Country = ip2location.lookup_country(client.ip);
  set req.http.X-Country-Long = ip2location.lookup_country_long(client.ip);
  set req.http.X-Region = ip2location.lookup_region(client.ip);
  set req.http.X-City = ip2location.lookup_city(client.ip);
  set req.http.X-ISP = ip2location.lookup_isp(client.ip);
  set req.http.X-Domain = ip2location.lookup_domain(client.ip);
  set req.http.X-Zipcode = ip2location.lookup_zipcode(client.ip);
  set req.http.X-Netspeed = ip2location.lookup_netspeed(client.ip);
  set req.http.X-IDDCode = ip2location.lookup_iddcode(client.ip);
  set req.http.X-Area-Code = ip2location.lookup_areacode(client.ip);
  set req.http.X-Weatherstation-Code = ip2location.lookup_weatherstationcode(client.ip);
  set req.http.X-Weatherstation-Name = ip2location.lookup_weatherstationname(client.ip);
  set req.http.X-MCC = ip2location.lookup_mcc(client.ip);
  set req.http.X-MNC = ip2location.lookup_mnc(client.ip);
  set req.http.X-Mobile-Brand = ip2location.lookup_mobilebrand(client.ip);
  set req.http.X-Usage-Type = ip2location.lookup_usagetype(client.ip);
}

libvmod-ip2location's People

Contributors

controversy187 avatar maxrem avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.