2023-12-29 19:34:49 +07:00
|
|
|
======
|
|
|
|
Geo IP
|
|
|
|
======
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
This documentation only applies to On-premise databases.
|
2020-03-13 16:53:06 +07:00
|
|
|
|
|
|
|
Installation
|
|
|
|
============
|
|
|
|
|
2021-04-01 15:45:24 +07:00
|
|
|
.. warning::
|
|
|
|
Please note that the installation depends on your computer's operating system and distribution.
|
|
|
|
We will assume that a Linux operating system is being used.
|
2020-03-13 16:53:06 +07:00
|
|
|
|
|
|
|
#. Install `geoip2 <https://pypi.org/project/geoip2/>`__ Python library
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
pip install geoip2
|
|
|
|
|
2021-03-25 02:09:53 +07:00
|
|
|
#. Download the `GeoLite2 City database <https://dev.maxmind.com/geoip/geoip2/geolite2/>`_. You
|
|
|
|
should end up with a file called ``GeoLite2-City.mmdb``
|
2020-03-13 16:53:06 +07:00
|
|
|
#. Move the file to the folder ``/usr/share/GeoIP/``
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
mv ~/Downloads/GeoLite2-City.mmdb /usr/share/GeoIP/
|
|
|
|
|
|
|
|
#. Restart the server
|
|
|
|
|
2021-04-01 15:45:24 +07:00
|
|
|
.. note::
|
|
|
|
If you can't/don't want to locate the geoip database in ``/usr/share/GeoIP/``, you can use the
|
|
|
|
``--geoip-db`` option of the Odoo command line interface. This option takes the absolute path to
|
|
|
|
the GeoIP database file and uses it as the GeoIP database. For example:
|
2020-03-13 16:53:06 +07:00
|
|
|
|
2021-04-01 15:45:24 +07:00
|
|
|
.. code-block:: bash
|
2020-03-13 16:53:06 +07:00
|
|
|
|
2021-04-01 15:45:24 +07:00
|
|
|
./odoo-bin --geoip-db= ~/Downloads/GeoLite2-City.mmdb
|
2020-03-13 16:53:06 +07:00
|
|
|
|
2021-04-01 15:45:24 +07:00
|
|
|
.. seealso::
|
2023-02-21 00:36:50 +07:00
|
|
|
- :doc:`CLI documentation </developer/reference/cli>`.
|
2020-03-13 16:53:06 +07:00
|
|
|
|
2021-04-01 15:45:24 +07:00
|
|
|
.. warning::
|
|
|
|
``GeoIP`` Python library can also be used. However this version is discontinued since January
|
2021-05-17 23:29:11 +07:00
|
|
|
1. See `GeoLite Legacy databases are now discontinued
|
2021-04-01 15:45:24 +07:00
|
|
|
<https://support.maxmind.com/geolite-legacy-discontinuation-notice/>`_
|
2020-03-13 16:53:06 +07:00
|
|
|
|
2023-12-29 19:34:49 +07:00
|
|
|
How to test GeoIP geolocation in your Odoo website
|
2021-03-25 02:09:53 +07:00
|
|
|
==================================================
|
2023-02-13 22:50:13 +07:00
|
|
|
|
2021-03-25 02:09:53 +07:00
|
|
|
1. Go to your website. Open the web page that you want to test ``GeoIP``.
|
2020-03-13 16:53:06 +07:00
|
|
|
2. Choose :menuselection:`Customize --> HTML/CSS/JS Editor`.
|
|
|
|
3. Add the following piece of XML in the page :
|
|
|
|
|
|
|
|
.. code-block:: xml
|
|
|
|
|
|
|
|
<h1 class="text-center" t-esc="request.session.get('geoip')"/>
|
|
|
|
|
2021-03-25 02:09:53 +07:00
|
|
|
You should end up with a dictionary indicating the location of the IP address.
|
2020-03-13 16:53:06 +07:00
|
|
|
|
2023-12-29 19:34:49 +07:00
|
|
|
.. image:: geo_ip/on-premise_geo-ip-installation01.png
|
2020-03-13 16:53:06 +07:00
|
|
|
:align: center
|
|
|
|
|
2021-04-01 15:45:24 +07:00
|
|
|
.. note::
|
|
|
|
If the curly braces are empty ``{}``, it can be for any of the following reasons :
|
2020-03-13 16:53:06 +07:00
|
|
|
|
2023-02-13 22:50:13 +07:00
|
|
|
- The browsing IP address is the localhost (``127.0.0.1``) or a local area network one
|
|
|
|
(``192.168.*.*``)
|
|
|
|
- If a reversed proxy is used, make sure to configure it correctly. See :option:`proxy mode
|
|
|
|
<odoo-bin --proxy-mode>`
|
2020-03-13 16:53:06 +07:00
|
|
|
- ``geoip2`` is not installed or the GeoIP database file wasn't found
|
|
|
|
- The GeoIP database was unable to resolve the given IP address
|