From: Robert Kaiser Date: Fri, 2 Dec 2016 17:05:50 +0000 (+0100) Subject: also integrate Pwiki for those endpoints that do not actually output HTML but just... X-Git-Url: https://git-public.kairo.at/?a=commitdiff_plain;h=426f76b2a5fa23ffba2f9ebf70ea8a384e733d23;p=authserver.git also integrate Pwiki for those endpoints that do not actually output HTML but just JSON --- diff --git a/app/api.php b/app/api.php index f51f201..4cdbe24 100644 --- a/app/api.php +++ b/app/api.php @@ -9,6 +9,13 @@ // Include the common auth system files (including the OAuth2 Server object). require_once(__DIR__.'/authsystem.inc.php'); +if ($settings['piwik_enabled']) { + // We do not send out an HTML file, so we need to do the Piwik tracking ourselves. + // Init is done here, actual tracking before exit. + require_once($settings['piwik_tracker_path'].'PiwikTracker.php'); + PiwikTracker::$URL = ((strpos($settings['piwik_url'], '://') === false) ? 'http://localhost' : '' ).$settings['piwik_url']; + $piwikTracker = new PiwikTracker($idSite = $settings['piwik_site_id']); +} $errors = $utils->checkForSecureConnection(); $utils->sendSecurityHeaders(); @@ -18,6 +25,7 @@ if (!count($errors)) { $token_OK = $server->verifyResourceRequest(OAuth2\Request::createFromGlobals()); if (!$token_OK) { $server->getResponse()->send(); + if ($settings['piwik_enabled']) { $piwikTracker->doTrackPageView('API Request: Bad Token'); } exit(); } $token = $server->getAccessTokenData(OAuth2\Request::createFromGlobals()); @@ -141,4 +149,7 @@ else { print(json_encode(array('error' => 'insecure_connection', 'error_description' => 'Your connection is insecure. The API can only be accessed on secure connections.'))); } +if ($settings['piwik_enabled']) { + $piwikTracker->doTrackPageView('API Request'.(strlen($token['scope'])?': '.$token['scope']:'')); +} ?> diff --git a/app/authorize.php b/app/authorize.php index c8f9b21..a37bd4a 100644 --- a/app/authorize.php +++ b/app/authorize.php @@ -125,6 +125,13 @@ if (!count($errors)) { $session = $utils->getLoginSession($user['id'], $session); } } + if ($settings['piwik_enabled']) { + // If we do not send out an HTML file, we need to do the Piwik tracking ourselves. + require_once($settings['piwik_tracker_path'].'PiwikTracker.php'); + PiwikTracker::$URL = ((strpos($settings['piwik_url'], '://') === false) ? 'http://localhost' : '' ).$settings['piwik_url']; + $piwikTracker = new PiwikTracker($idSite = $settings['piwik_site_id']); + $piwikTracker->doTrackPageView('Handle Authorize Request'); + } // Handle authorize request, forwarding code in GET parameters if the user has authorized your client. $server->handleAuthorizeRequest($request, $response, $is_authorized, $user['id']); /* For testing only diff --git a/app/authsystem.inc.php b/app/authsystem.inc.php index 17ff700..d098af0 100644 --- a/app/authsystem.inc.php +++ b/app/authsystem.inc.php @@ -48,7 +48,8 @@ textdomain($textdomain); // Sanitize settings. $settings['piwik_enabled'] = (@$settings['piwik_enabled']) ? true : false; $settings['piwik_site_id'] = intval(@$settings['piwik_site_id']); -$settings['piwik_url'] = strlen($settings['piwik_url']) ? $settings['piwik_url'] : '/piwik/'; +$settings['piwik_url'] = strlen(@$settings['piwik_url']) ? $settings['piwik_url'] : '/piwik/'; +$settings['piwik_tracker_path'] = strlen(@$settings['piwik_tracker_path']) ? $settings['piwik_tracker_path'] : '../vendor/piwik/piwik-php-tracker/'; /* Creating the DB tables: CREATE TABLE `auth_sessions` (