diff --git a/.gitignore b/.gitignore index e1da2a6..f6ec423 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ vendor settings.php nbproject/private *.sync-conflict* -*.bak \ No newline at end of file +*.bak +GeoLite2-City.mmdb \ No newline at end of file diff --git a/composer.json b/composer.json index fb37c32..d2aa591 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,8 @@ "type": "project", "require": { "catfan/medoo": "^1.5", - "guzzlehttp/guzzle": "^6.2" + "guzzlehttp/guzzle": "^6.2", + "geoip2/geoip2": "~2.0" }, "license": "MPL-2.0", "authors": [ diff --git a/composer.lock b/composer.lock index f1d9d09..5ad0e7f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "5c7439c6e041764f2f6b0270a95ab3ae", - "content-hash": "e4e700119f47d2f68b0ed82abaf8c5c6", + "hash": "a05b32c4ba7d59c1fa2dc87ef59b238d", + "content-hash": "2b47ec7e64412178507c9e9362debc56", "packages": [ { "name": "catfan/medoo", @@ -66,6 +66,114 @@ ], "time": "2018-03-26 17:54:24" }, + { + "name": "composer/ca-bundle", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/composer/ca-bundle.git", + "reference": "d2c0a83b7533d6912e8d516756ebd34f893e9169" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/ca-bundle/zipball/d2c0a83b7533d6912e8d516756ebd34f893e9169", + "reference": "d2c0a83b7533d6912e8d516756ebd34f893e9169", + "shasum": "" + }, + "require": { + "ext-openssl": "*", + "ext-pcre": "*", + "php": "^5.3.2 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5", + "psr/log": "^1.0", + "symfony/process": "^2.5 || ^3.0 || ^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\CaBundle\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.", + "keywords": [ + "cabundle", + "cacert", + "certificate", + "ssl", + "tls" + ], + "time": "2018-03-29 19:57:20" + }, + { + "name": "geoip2/geoip2", + "version": "v2.9.0", + "source": { + "type": "git", + "url": "https://github.com/maxmind/GeoIP2-php.git", + "reference": "a807fbf65212eef5d8d2db1a1b31082b53633d77" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/GeoIP2-php/zipball/a807fbf65212eef5d8d2db1a1b31082b53633d77", + "reference": "a807fbf65212eef5d8d2db1a1b31082b53633d77", + "shasum": "" + }, + "require": { + "maxmind-db/reader": "~1.0", + "maxmind/web-service-common": "~0.5", + "php": ">=5.4" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "2.*", + "phpunit/phpunit": "4.*", + "squizlabs/php_codesniffer": "3.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "GeoIp2\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory J. Oschwald", + "email": "goschwald@maxmind.com", + "homepage": "http://www.maxmind.com/" + } + ], + "description": "MaxMind GeoIP2 PHP API", + "homepage": "https://github.com/maxmind/GeoIP2-php", + "keywords": [ + "IP", + "geoip", + "geoip2", + "geolocation", + "maxmind" + ], + "time": "2018-04-10 15:32:59" + }, { "name": "guzzlehttp/guzzle", "version": "6.3.2", @@ -247,6 +355,108 @@ ], "time": "2017-03-20 17:10:46" }, + { + "name": "maxmind-db/reader", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/maxmind/MaxMind-DB-Reader-php.git", + "reference": "e042b4f8a2dff41e19019faf16427178b07fbd58" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/e042b4f8a2dff41e19019faf16427178b07fbd58", + "reference": "e042b4f8a2dff41e19019faf16427178b07fbd58", + "shasum": "" + }, + "require": { + "php": ">=5.4" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "2.*", + "phpunit/phpunit": "4.* || 5.*", + "satooshi/php-coveralls": "1.0.*", + "squizlabs/php_codesniffer": "3.*" + }, + "suggest": { + "ext-bcmath": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder", + "ext-gmp": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder", + "ext-maxminddb": "A C-based database decoder that provides significantly faster lookups" + }, + "type": "library", + "autoload": { + "psr-4": { + "MaxMind\\Db\\": "src/MaxMind/Db" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory J. Oschwald", + "email": "goschwald@maxmind.com", + "homepage": "http://www.maxmind.com/" + } + ], + "description": "MaxMind DB Reader API", + "homepage": "https://github.com/maxmind/MaxMind-DB-Reader-php", + "keywords": [ + "database", + "geoip", + "geoip2", + "geolocation", + "maxmind" + ], + "time": "2018-02-21 21:23:33" + }, + { + "name": "maxmind/web-service-common", + "version": "v0.5.0", + "source": { + "type": "git", + "url": "https://github.com/maxmind/web-service-common-php.git", + "reference": "61a9836fa3bb1743ab89752bae5005d71e78c73b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/web-service-common-php/zipball/61a9836fa3bb1743ab89752bae5005d71e78c73b", + "reference": "61a9836fa3bb1743ab89752bae5005d71e78c73b", + "shasum": "" + }, + "require": { + "composer/ca-bundle": "^1.0.3", + "ext-curl": "*", + "ext-json": "*", + "php": ">=5.4" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "2.*", + "phpunit/phpunit": "4.*", + "squizlabs/php_codesniffer": "3.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "MaxMind\\Exception\\": "src/Exception", + "MaxMind\\WebService\\": "src/WebService" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory Oschwald", + "email": "goschwald@maxmind.com" + } + ], + "description": "Internal MaxMind Web Service API", + "homepage": "https://github.com/maxmind/web-service-common-php", + "time": "2018-02-12 22:31:54" + }, { "name": "psr/http-message", "version": "1.0.1", diff --git a/database.mwb b/database.mwb index 90dbd3c..45ff6c3 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/lib/gatheranalytics.php b/lib/gatheranalytics.php new file mode 100644 index 0000000..5c6ce10 --- /dev/null +++ b/lib/gatheranalytics.php @@ -0,0 +1,98 @@ +city($clientip); + + $country = $record->country->name; + $region = $record->mostSpecificSubdivision->name; + $city = $record->city->name; + $lat = $record->location->latitude; + $lon = $record->location->longitude; + +// +// Save the page visit +// + + $database->insert("analytics", [ + "siteid" => getsiteid(), + "pageid" => getpageid(), + "uuid" => $uuid, + "country" => $country, + "region" => $region, + "city" => $city, + "lat" => $lat, + "lon" => $lon, + "time" => $time + ]); +} catch (GeoIp2\Exception\AddressNotFoundException $e) { + if (DEBUG) { + echo ""; + } +} catch (Exception $e) { + // Silently fail so the rest of the site still works +} \ No newline at end of file diff --git a/lib/requiredpublic.php b/lib/requiredpublic.php index e5eef9f..6e4be53 100644 --- a/lib/requiredpublic.php +++ b/lib/requiredpublic.php @@ -120,6 +120,20 @@ function getpageslug() { return null; } +function getpageid() { + global $database; + if (isset($_GET['id'])) { + $id = $_GET['id']; + } else { + $id = "index"; + } + $siteid = getsiteid(); + if ($database->has("pages", ["AND" => ["slug" => $id, "siteid" => $siteid]])) { + return $database->get("pages", "pageid", ["AND" => ["slug" => $id, "siteid" => $siteid]]); + } + return null; +} + function getpagetemplate() { global $database; $slug = getpageslug(); diff --git a/public/index.php b/public/index.php index 9b9f6bf..11898fa 100644 --- a/public/index.php +++ b/public/index.php @@ -8,6 +8,8 @@ require_once __DIR__ . "/../lib/requiredpublic.php"; require_once __DIR__ . "/../lib/themefunctions.php"; +include __DIR__ . "/../lib/gatheranalytics.php"; + if (!getsiteid()) { sendError("No website has been created yet. Please open " . SITE_TITLE . " and make one."); } diff --git a/settings.template.php b/settings.template.php index 8bf762d..34e86ca 100644 --- a/settings.template.php +++ b/settings.template.php @@ -37,6 +37,13 @@ define('URL', '/sitewriter'); // Folder for public files define('FILE_UPLOAD_PATH', __DIR__ . '/public/files'); +// Location of MaxMind GeoIP database +// +// I'll just leave this here: +// This product includes GeoLite2 data created by MaxMind, available from +// http://www.maxmind.com +define('GEOIP_DB', __DIR__ . "/GeoLite2-City.mmdb"); + // Use Captcheck on login screen // https://captcheck.netsyms.com define("CAPTCHA_ENABLED", FALSE); @@ -47,4 +54,4 @@ define('LANGUAGE', "en_us"); define("FOOTER_TEXT", ""); -define("COPYRIGHT_NAME", "Netsyms Technologies"); \ No newline at end of file +define("COPYRIGHT_NAME", "Netsyms Technologies");