Giter Site home page Giter Site logo

thadafinser / piwik-intranetgeoip Goto Github PK

View Code? Open in Web Editor NEW
23.0 6.0 14.0 231 KB

Piwik plugin to locate all locale data of a user based on the IP address/subnetwork (country, region, city, latitude, longitude, provider, ...)

License: MIT License

PHP 100.00%
piwik piwik-plugin geoip

piwik-intranetgeoip's Introduction

Piwik IntranetGeoIp Plugin

Description

Piwik plugin to locate all locale data of a user based on the IP address/subnetwork (country, region, city, latitude, longitude, provider, ...)

Please use it only for INTRANET tracking everything else just dont make sense :-)

FAQ

What does this plugin do?

It adds visitor information based on the matched IP address from your configuration. Not more and not less. The database schema and UI stays untouched, so all Piwik statistics can be used like you would use a internet GeoIP database.

How to configure/install this plugin / the networks?

After installation and activation of the plugin, open the file piwik/config/IntranetGeoIP.data.php

You can their add your location information and their subnetworks.

See the file piwik/config/IntranetGeoIP.data.php or see the readme on github https://github.com/ThaDafinser/IntranetGeoIp

What statistics are available?

If you create a full configuration data file, you'll see

  • Visitor -> Realtime visitor map
  • Visitor -> Location and provider
  • and many more...(in generall all statistics are available like using a internet GeoIP database)

Why there stands provider "unknown" in my visitor log?

If your installation is stock, all visitors will get this "flag" to show you, what IPs are not matched. You can adjust or remove this, by changing the "noMatch" block in your IntranetGeoIP.data.php file. If you remove the complete block, none matched visitors will be skipped by this plugin. But you can also fill all possible visitorInfos like you are used for matched IP addresses.

Can i use this plugin with a internet GeoIP database side by side?

Yes you can. Just remove or comment out the noMatch block in your configuration file.

Note about the configuration?

Inside the array key visitorInfo you can freely add/remove all available columns from the log_visit table you want. The keys below are just a suggestion, since they are the only one which make sense currently IMO. All available fields, see here: http://developer.piwik.org/guides/persistence-and-the-mysql-backend#visits

Inside they key networks add all subnetworks which apply to this location.

return [
    /*
     * If the IP was not matched, apply these data to visitorInfo
     * You can also apply here all possible visitorInformation data if you want
     */
    'noMatch' => [
        'visitorInfo' => [
            // Provider requires the "Provider" Plugin to be active. (Disabled by default in Version 2.15 and above)
            //'location_provider' => 'unknown'
        ]
    ],
    
    [
        'visitorInfo' => [
            //ISO-3166 alpha-2 code http://en.wikipedia.org/wiki/ISO_3166-1
            'location_country' => 'at',
            
            //the region code (i take them from piwik/libs/MaxMindGeoIp/geoipregionvars.php
            'location_region' => '08',
            
            //should be freetext
            'location_city' => 'Muntlix',
            
            //get this from a picker, e.g. http://www.tytai.com/gmap/
            'location_latitude' => '47.282024',
            'location_longitude' => '9.662304',
            
            //enter your company name or do it based on your domain hierarchy
            // Provider requires the "Provider" Plugin to be active. (Disabled by default in Version 2.15 and above)
            //'location_provider' => 'myCompany'
        ],
        'networks' => [
            //enter here all subnetworks for this location
            //use a subnetwork calculator, e.g. http://jodies.de/ipcalc
            '10.59.0.0/19',
            '170.56.251.200/29'
        ]
    ],
    
    //add more blocks live above
];

piwik-intranetgeoip's People

Contributors

peterbo avatar pfleckenbw avatar phoob avatar thadafinser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

piwik-intranetgeoip's Issues

Plugin Update not working

Hi,

I have the following installation: Piwik 2.16.2 + IntranetGeoIP Version 2.1.3

In the Plugin-Admin-Page Piwik wants me to update from 2.1.3 => 2.2.0
After updating the Plugin, Piwik is Broken. I looked into the files (plugin.json) and now there is 1.0.2 installed.

If I download the 2.2.0 Plugin-Version from Github it wants me to update 2.2.0 => 2.2.0

If I go with the Web-Browser to: https://plugins.piwik.org/search?piwikversion=0&query=intranetGeo I get the 2.1.3 Version.

I have also seen, that the Plugin Version on GitHub Tag v2.3.0 does not match the version in its plugin.json (there it says 2.2.0)

Something is not working here...

Debugging the plugin

Hi

I have a large intranet and did all modification as explained in readme.md, but i haven't this plugin running. The max that i found in the Apache log error was:

​[Tue Oct 13 14:23:38 2015] [error] [client 10.2.4.98] PHP Warning:  Invalid argument supplied for foreach() in /var/www/html/piwik/plugins/IntranetGeoIP/IntranetGeoIP.php on line 118, referer: http://www-dtpnet/content/webdatafone

Some suggestion?

Make plugin compatible with Matomo 4

Hi, hope you are doing well!

Matomo 4 is progressing steadily and it would be great if this plugin was also available for it.

Migrating the plugin should be pretty simple as there were not many breaking changes.

You can find the migration guide here: https://developer.matomo.org/guides/migrate-matomo-3-to-4

It boils down to:

  • update your dev environment to 4.x-dev
  • update your plugin.json (new major version of the plugin and require >=4.0.0-b1,<5.0.0-b1)
  • check that everything still works fine
  • commit this to a new branch (e.g. 4.x-dev) and make this branch the default in the github settings
  • tag and push a new release to publish it to the marketplace

If you later fix a bug and also want to backport it to the 3.x plugin, you can cherry-pick the commit to the old branch, release a new version (lower than the one for 4.x) and publish it and 3.x users should get this update.

If you have questions about anything, just ask me!

How to edit IP list

Hi, TD.
I've downloaded your plugin but i can't find a way to add my own IPs.
For example, i'm not sure what does it mean 'piwik/plugins/IntranetGeoIp/data.php'. Any attempt of mine didn't

I'm not sure how to accomplish the next step either: how to make Piwik to show the map based on your plugin.

Please F1 (help)..

Thanks

Send unmatched IPs to normal geolocation?

On our sites, we have both visitors that come from intranet IPs (10.*) and regular internet.

It would be nice if we could use this plugin as a pre-filter to geolocate IP addresses that are in our intranet range, and let all other IPs (that are not matched by this plugin) be geolocated by the default geolocation function of Piwik.

Is that possible to implement?

Thanks!!

Custom variables

Hi there @ThaDafinser, I am wondering if it is possible to use custom variable instead of IP to update the geolocation lat/lon with this matter plugin?

Let's say I am setting a custom variable "location" => "Home" via JS tracking api. Would it be possible to define lat/lon for "Home" instead of IP range?

It's a weird setup, but would save my day 😂

Piwik Integrity failed

Hi,

After installation and activation of IntranetGeoIP plugins, piwik integrity check fails.

Piwik suggests to remove the IntranetGeoIP.data.php :

rm "/usr/share/nginx/piwik/config/IntranetGeoIP.data.php"

Update plugin.json required version

Hi there,

I'm Thomas from Piwik. We recently made some changes on the Marketplace and changed how versions are defined. In your plugin.json it defines:

  "require": {
    "piwik": "2.9.0",
    "php": "5.4.0"
  }

but in future updates it should include the >= and also include an upper version constraint:

  "require": {
    "piwik": ">=2.9.0,<3.0.0-b1",
    "php": ">=5.4.0"
  }

Sorry for inconvenience and cheers

Updating the plugin deletes data.php file

When we update a plugin from the marketplace, the plugin directory is completely deleted and replaced by the new version. Updating this plugin deletes the data.php file!

It would be nice to place the plugin configuration elsewhere, so we don't lose it when updating.

A section in the config.ini.php file might be a good place, or a textarea in the "plugin settings" page (in admin's settings menu)?

Not IP based localization

from @andreystrelkov
Hello Martin
As I understand your module can make it so that I am entering a range of IP addresses can point him to any country, region and city, this range is, ie, create your base IP locations, which will Pivik

If so, is it possible to make the source of the not IP address, and a user variable, as we have special grouping gn addresses for units, but if you could specify that such DEPARTMENT №123 is such a city, it would be great

I want change world map to map of our factory

//cc i taken it to an issue from your commit (please open issues and dont comment commits for such things)

Plugin stopped working with 2.15.0-b1

I have upgraded PIWIK to 2.15.0-b1 as there was fix released for Scheduled report. However, IntranetGeoIP plugin stopped working. After checking PHP log, its giving below error. Could you please help in resolving it.

[26-Aug-2015 09:35:34 UTC] PHP Warning: Parameter 1 to Piwik\Plugins\IntranetGeoIP\IntranetGeoIP::logIntranetSubNetworkInfo() expected to be a reference, value given in C:\piwik\core\EventDispatcher.php on line 141
[26-Aug-2015 09:35:34 UTC] PHP Stack trace:
[26-Aug-2015 09:35:34 UTC] PHP 1. {main}() C:\piwik\piwik.php:0
[26-Aug-2015 09:35:34 UTC] PHP 2. Piwik\Tracker->main() C:\piwik\piwik.php:67
[26-Aug-2015 09:35:34 UTC] PHP 3. Piwik\Tracker->track() C:\piwik\core\Tracker.php:98
[26-Aug-2015 09:35:34 UTC] PHP 4. Piwik\Tracker\Handler->process() C:\piwik\core\Tracker.php:121
[26-Aug-2015 09:35:34 UTC] PHP 5. Piwik\Tracker->trackRequest() C:\piwik\core\Tracker\Handler.php:49
[26-Aug-2015 09:35:34 UTC] PHP 6. Piwik\Tracker\Visit->handle() C:\piwik\core\Tracker.php:139
[26-Aug-2015 09:35:34 UTC] PHP 7. Piwik\Tracker\Visit->handleNewVisit() C:\piwik\core\Tracker\Visit.php:160
[26-Aug-2015 09:35:34 UTC] PHP 8. Piwik\Piwik::postEvent() C:\piwik\core\Tracker\Visit.php:274
[26-Aug-2015 09:35:34 UTC] PHP 9. Piwik\EventDispatcher->postEvent() C:\piwik\core\Piwik.php:694
[26-Aug-2015 09:35:34 UTC] PHP 10. call_user_func_array:{C:\piwik\core\EventDispatcher.php:141}() C:\piwik\core\EventDispatcher.php:141

Apply IntranetGeoIP before anonymizing IP address

I have noticed that if I turn on anonymizing of IP addresses, the IntranetGeoIP plugin uses the anonymized IP to return GeoIP information. I'm trying to do a fairly detailed layout of internal networks, so I get inaccurate information. If I turn off IP anonymize, it works as expected. Is there a way to do the IntranetGeoIP resolution before anonymizing the IP?

Question about requirements (PHP7)

Hi @ThaDafinser, I can remember a discussion why it was necessary to raise the requirements of the plugin to PHP7 (something about different variable/pointer handling I guess). Now I'm struggling with an instance running PHP5.6 and Piwik3, unable yet to upgrade to PHP7. Therefore I would like to backport the Plugin for the instance to work on PHP5.6, if possible. Could you please point me to the direction, what exactly was not working as expected on PHP < 7?

Thank you in advance!

Piwik 3

Hi, are you planning to make this plugin compatible with Piwik 3? I updated too soon :(

regards

Any particular Location Provider necessary?

I've installed and activated IntranetGeoIP, configured the the IntranetGeoIP.data.php file correctly I believe (attempting to match 10.10.55.20 with
'networks' => [
'10.10.0.0/16'
]
but not seeing the results I'm expecting; still getting 'unknown' instead of what I put in VisitorInfo.

I was using the default Location Provider in the GeoLocation settings, then switched to GeoIP (PHP), then GeoIP (Apache) and GeoIP (PECL) thinking that maybe one of those was necessary; each with the same result. I don't need to match anything outside of the intranet's ranges.

noMatch is not commented out, and I'm not getting the string I've placed there for for 'location_provider'.

I feel like the plugin is being ignored, even though activated. Clearly, I've missed something, but wondering if you happen to be able to tell me from the description above.

Local Connections not showing on real-time map

I have a very large network, and I'm adding a lot of address blocks and not seeing any connections on the real-time map

Is there something else I need to do to get it to work other than activate it?
Under Geolocation I have GeoIP (PHP) Selected

I stopped seeing traffic altogether

Intranet Geo IP plugin does not track correctly

Hello,
I am using matomo(version: 3.11.0) for intranet website on premises on VM running with OS Windows server 2012 R2.
My question is regarding geo loctaion tracking and for this purpose i am using plugin called “Intranet Geo IP”
But still I could see most of the visitors logs are unknown. I have also configured IntranetGeoIP.data.php with our networks IP. Could you please help me to get the visitor logs with accurate region ( country,city).
DB :- My SQL (version: 5.5.49)
PHP :- version: 7.3.1

Awaiting for your help on this.

Piwik 2.16.1 no location_provider in piwik_log_visit

Hi,
I installed piwik yesterday and then this plugin and couldn't get it to work.
Then I saw in the apache error log this message.
Error in Piwik (tracker): Error query: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'location_provider' in 'field list' In query: INSERT INTO piwik_log_visit (...

I also have just:
Visitor -> Realtime visitor map
and this one is not in the dashboard list:
Visitor -> Location and provider

can't I see the information on the normal visitor map?
regards Falk

Intra and internet ip’s location

Hello,

I've few sites monitoring by my piwik which can be visited by both internal and external users.
I managed to locate users IP's internally and externally with IntranetGeoIP for internal and GeoIP (Php) provided with MaxMind's databases for external ones.

My issue is about how to manage an external IP who match internal one.
Let's see : say that we have the 207.45.200.167 address located in London, GB in our IntranetGeoIP.data.php file. But (at time where i write that post) this address is located in Los Angeles, USA externally.
When i track that ip in piwik, she is located in London.
My question is how can i manage that this IP is the external one and not the internal one ?

PS: If it can help, our external access is protected by multiple proxy and firewall so i've the HTTP_FORWARDED header.

A Couple of Q's

Hi, This is a great plugin so thank you :>) We have a both our intranet and internet logging in to the same piwik installation, so untill we installed your plugin we couldn't differenciate traffic from either network. We can now :>)

I had to comment out the 'noMatch' / 'unknown' in IntranetGeoIP.data.php as with it enabled we did't collect Internet stats.

The main IP Subnet we use is 10.240.0.0/12 and I want to use that as a catchall but I want to also want to differentiate subnets so e.g. our building is 10.248.3.0 which is a subnet of 10.240.0.0/12.
How would I go about defining this in the IntranetGeoIP.data.php file ?

We have a spreedsheet of the IP's used but there are gaps that we need to fill so we deffinatly want to get a Intranet catch all for specific ranges.

Also would it be possible to use a different colour for Internet / Intranet traffic on the Piwik Maps ?

Thanks again for the plugin.
Keith

piwik intranetgeoip and multiple networks / locations

Hi,
So I've been trying to use piwik on an intranet / extranet mixed environment (with multiple networks and physical locations) using your plugin. However, there are a couple of things I'm noticing:

  1. there are a number of "Provider: Unknown" and location unknown, although I put all of the locations and providers & ip address ranges into the script (my feeling is with so many blocks of known visitors, perhaps the script's getting confused?)
  2. Although the country is set properly in the script (for known visitors), etc., especially with the "Provider: Unknown" logs, it is sometimes gives the wrong country name
  3. Sometimes it's the gateway's ip address (there are multiple gateways between the different networks / locations on our environment) that's used instead of the actual ip address of the computer. I don't know if that has anything to do with your plugin or piwik itself, but that's what I've noticed.

Piwik version: 2.14.3
intranetGeoIP version: 2.2.0
If you have any suggestions on how to resolve any of these issues, I would greatly appreciate it.

Update: I added the country to the unmatched address block, however, after double checking I'm realising that the Unknown Provider ip addresses are definitely included in the ip ranges of the known visitor blocks, but, somehow it isn't being detected, or they're being overruled.

I'm asking about this because I've got to try to segment the visitors by physical location & there are multiple locations in this case.

Importing IP-Ranges from Database or Converting it to a suitable Pluginformat

We run a website that is public accessible from Internet and Intranet.
So the IPs we see are from both areas.
Public IPs get geolocation from maxmind.com
Private IPs ( we are talking from ~600 Ranges in +50 countries and +300 location are store currently in a database from our networking guys.
Do you see something that a csv importer or similar could close the gap?

commenting out "nomatch" not working?

Hello!

According to the README.md, it is possible to comment out the nomatch-block in IntranetGeoIP.data.php, and making this plugin skip handling unmatched IPs (and letting GeoIP) handle those instead. However, that doesn't seem to be working? (using Piwik 3.0.2 and IntranetGeoIP 3.0.0). Am I doing something wrong..?

Plugin broke

Hello!

I got an upgrade notice a few days ago, and I think that broke the plugin. I see that IntranetGeoIp.php now references a function called "IP::isIpInRange", which doesn't exist in \Piwik\IP… Actually I think maybe the plugin hasn't been updated for a while – because until now I had the local IP definitions in config/IntranetGeoIP.data.php – and that worked until the plugin got updated just now.. Actually I can't see the isIpInRange function in /component-network/blob/master/src/IP.php either… but that doesnt seem to be included in the piwik installation anyway..

Only one location showing up

I followed the layout like below.

    [
        'visitorInfo' => [
            //ISO-3166 alpha-2 code http://en.wikipedia.org/wiki/ISO_3166-1
            'location_country' => 'US',

            //the region code (i take them from piwik/libs/MaxMindGeoIp/geoipregionvars.php
            'location_region' => 'NJ',

            //should be freetext
            'location_city' => 'City',

            //get this from a picker, e.g. http://www.tytai.com/gmap/
            'location_latitude' => 'xccxx',
            'location_longitude' => '-xxxxx',

            //enter your company name or do it based on your domain hierarchy
            // Provider requires the "Provider" Plugin to be active. (Disabled by default in Version 2.15 and above)
            'location_provider' => 'provider'
        ],
        'networks' => [
            //enter here all subnetworks for this location
            //use a subnetwork calculator, e.g. http://jodies.de/ipcalc
            '10.5.0.0/16'
        ]
    ],
[
        'visitorInfo' => [
            //ISO-3166 alpha-2 code http://en.wikipedia.org/wiki/ISO_3166-1
            'location_country' => 'US',

            //the region code (i take them from piwik/libs/MaxMindGeoIp/geoipregionvars.php
            'location_region' => 'PA',

            //should be freetext
            'location_city' => 'City',

            //get this from a picker, e.g. http://www.tytai.com/gmap/
            'location_latitude' => 'xccxx',
            'location_longitude' => '-xxxxx',

            //enter your company name or do it based on your domain hierarchy
            // Provider requires the "Provider" Plugin to be active. (Disabled by default in Version 2.15 and above)
            'location_provider' => 'provider'
        ],
        'networks' => [
            //enter here all subnetworks for this location
            //use a subnetwork calculator, e.g. http://jodies.de/ipcalc
            '10.8.0.0/16'
        ]
    ],
//more stuff
];

I only get the first location in NJ

Configuration UI interface

Would be nice if you could configure the plugin through Piwik UI, not in php file.

the UI then could write the configuration to DB or store it as php/yml file, for all of us lazy people :)

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.