jbrule / matomoplugin-CampusGeoIP

A location provider designed to geolocate ips across a campus in an intranet type environment
3 stars 2 forks source link

Documentation issue #3

Closed Chardonneaur closed 1 year ago

Chardonneaur commented 1 year ago

Hello, I tried to install the plugin and in fact, I got blocked when performing (according to the documentation): ./console CampusGeoIP:update-networks http:// in fact it is: ./console campusgeoip:update-networks http:// then there is another error message which will be, no file format specified, and I have no idea in which file format http:// should be. Any ideas?

jbrule commented 1 year ago

The format is here https://github.com/jbrule/matomoplugin-CampusGeoIP/blob/4.x-dev/docs/index.md This was the format our IPAM exported as and it needs to be loaded over http as implemented. With a little work it could support loading a local file.

Chardonneaur commented 1 year ago

@jbrule thank you but what is the file format of your file? .txt, .csv?

jbrule commented 1 year ago

just plain text bar/pipe character "|" delimited

Chardonneaur commented 1 year ago

strange so my error is then somewhere else because I am getting a file format error.

jbrule commented 1 year ago

Are you using a valid URL? The checks/messages can be seen here https://github.com/jbrule/matomoplugin-CampusGeoIP/blob/26602a1a3773be8796363afaccd6712cbc535dce/CampusGeoIP.php#L102

Chardonneaur commented 1 year ago

Yes, I am using it locally and can download the file from the url http://localhost/myfile I am getting a "File format is invalid" as an error message.

jbrule commented 1 year ago

That message is return when the header row of the file doesn't exactly match what is expected. Look at COLUMN_TEMPLATE in CampusGeoIP.php file.

jbrule commented 1 year ago

Were you able to get this working?

Josh

Chardonneaur commented 1 year ago

Nope, but I am going to try harder in the coming weeks. Thanks for the follow up.

Chardonneaur commented 1 year ago

@jbrule ok, just to give you an idea of my project. I am currently writing a book about Matomo which include an introduction to all plugins from the marketplace. I only have 4 left that I didn't write about and Campus Geo IP is one of them. My question is then the following one, could I somehow, thanks to your plugin, use a local file in order to say hey, this is my home IP address, and the exact location is this one latitude = something, longitude = something else. Because if i can do so, I guess I can explain the all concept of the plugin.

jbrule commented 1 year ago

The intent of the plugin is to support Geo-location for RFC1819 networks but there is no reason it can't work with public ones. For a home network you could define "locations" for the house, shed, treehouse, lake home (p2p VPN) with geo-coordinates like so https://github.com/jbrule/matomoplugin-CampusGeoIP/blob/4.x-dev/docs/index.md and have a network cidr, in this case probably something like 192.168.10.0/24 for house, 192.168.11.0/24 for lakehouse as networks.

campusgeoip_locations table (This would be entered into MySQL table) id name city campus region country org provider latitude longitude ts_created ts_last_edit
1 Main House Baltimore MH MD US HomeNOC NAT 39.2546526 -76.7109614 null null
2 Tree House Baltimore TH MD US HomeNOC NAT 39.2546530 -76.7109620 null null
3 Lake House Baltimore LH MD US HomeNOC NAT 39.4270459 -76.8832297 null null

Networks Data File (This would be populated by ./console campusgeoip:update-networks http://localhost/home.txt) home.txt

NetworkFirstAsInteger|NetworkLastAsInteger|NetworkAsInteger|NetworkWithCIDR|NetworkAddress|NetworkCIDR|NetworkMask|NetworkHostCount|NetworkComment|Region|CampusCode|BuildingCode|FloorCode|Use|Disabled
|||192.168.10.0/24|||||Main House|MD|MH|H|Main||false
|||192.168.12.0/24|||||Tree House|MD|TH|H|Main||false
|||192.168.11.0/24|||||Lake House|MD|LH|H|Main||false
Chardonneaur commented 1 year ago

Thank you so much, I am giving it a try over the next days.

Chardonneaur commented 1 year ago

@jbrule : ok I made some progress here, but when I execute the command line, here is the error I am getting: ERROR [2022-11-20 15:04:09] 44912 Uncaught exception: Error: Undefined constant "Piwik\Plugins\CampusGeoIP\FILTER_FLAG_SCHEME_REQUIRED" in /var/www/html/matomoeni/matomo/plugins/CampusGeoIP/CampusGeoIP.php:131 Stack trace:

0 /var/www/html/matomoeni/matomo/plugins/CampusGeoIP/Commands/UpdateNetworks.php(38): Piwik\Plugins\CampusGeoIP\CampusGeoIP->importNetworksFromSource()

1 /var/www/html/matomoeni/matomo/vendor/symfony/console/Symfony/Component/Console/Command/Command.php(257): Piwik\Plugins\CampusGeoIP\Commands\UpdateNetworks->execute()

2 /var/www/html/matomoeni/matomo/vendor/symfony/console/Symfony/Component/Console/Application.php(874): Symfony\Component\Console\Command\Command->run()

3 /var/www/html/matomoeni/matomo/vendor/symfony/console/Symfony/Component/Console/Application.php(195): Symfony\Component\Console\Application->doRunCommand()

4 [internal function]: Symfony\Component\Console\Application->doRun()

5 /var/www/html/matomoeni/matomo/core/Console.php(135): call_user_func()

6 /var/www/html/matomoeni/matomo/core/Access.php(670): Piwik\Console->Piwik{closure}()

7 /var/www/html/matomoeni/matomo/core/Console.php(136): Piwik\Access::doAsSuperUser()

8 /var/www/html/matomoeni/matomo/core/Console.php(87): Piwik\Console->doRunImpl()

9 /var/www/html/matomoeni/matomo/vendor/symfony/console/Symfony/Component/Console/Application.php(126): Piwik\Console->doRun()

10 /var/www/html/matomoeni/matomo/console(32): Symfony\Component\Console\Application->run()

11 {main}

Uncaught exception in /var/www/html/matomoeni/matomo/plugins/CampusGeoIP/CampusGeoIP.php line 131: Undefined constant "Piwik\Plugins\CampusGeoIP\FILTER_FLAG_SCHEME_REQUIRED"

jbrule commented 1 year ago

Given the error I assume you are not providing a url with scheme (http/https). It doesn't support a file syst path currently but I have some time Wednesday and will work on file path support. It should be simple to add.

jbrule commented 1 year ago

I just pushed v4.1.0 with local network data file support

Chardonneaur commented 1 year ago

Thank you @jbrule definitely there is some progress here, though I am still getting some errors: ERROR [2022-11-24 17:44:23] 133449 Uncaught exception: /var/www/html/matomocamp/matomo/core/Db.php(846): Found bound parameter (index = 0) is Date instance which will not work correctly in following SQL: UPDATE matomo_campusgeoip_networks SET ts_removed = ? WHERE ts_last_edit < ? AND ts_removed IS NULL [Query: , CLI mode: 1]
[Exception]
Found bound parameter (index = 0) is Date instance which will not work correctly in following SQL: UPDATE matomo_campusgeoip_networks SET ts_removed = ? WHERE ts_last_edit < ? AND
ts_removed IS NULL

jbrule commented 1 year ago

Does it error with https://github.com/jbrule/matomoplugin-CampusGeoIP/blob/4.x-dev/docs/networks-example.txt ?

Chardonneaur commented 1 year ago

yes, it throws the exact same error

jbrule commented 1 year ago

Please try version 4.1.3 it will print out additional debug information when an error occurs. I am unable to duplicate this error with the networks-example.txt file

jbrule commented 1 year ago

@Chardonneaur Were you able to get any error output?

Chardonneaur commented 1 year ago

Hi Josh, yes, here is the error: Found bound parameter (index = 0) is Date instance which will not work correctly in following SQL: UPDATE matomo_campusgeoip_networks SET ts_removed = ? WHERE ts_last_edit < ? AND ts_removed IS NULL [Query: , CLI mode: 1]

[Exception]
Found bound parameter (index = 0) is Date instance which will not work corr
ectly in following SQL: UPDATE matomo_campusgeoip_networks SET ts_removed =
? WHERE ts_last_edit < ? AND ts_removed IS NULL

jbrule commented 1 year ago

@Chardonneaur That is with v4.1.3?

Chardonneaur commented 1 year ago

yes

jbrule commented 1 year ago

@Chardonneaur Please give 4.1.4 a try.

Chardonneaur commented 1 year ago

Victory, it works @jbrule