From 6b2b4d9fa8f615be3a9db0d8dabe6067f909c1d9 Mon Sep 17 00:00:00 2001 From: Lorenz Schori Date: Wed, 16 Jan 2013 18:28:07 +0100 Subject: [PATCH 2/3] Introduce function _authcache_debug_access for simplifying access checks --- authcache.helpers.inc | 20 +++++++++++++++++++- authcache.module | 24 +++++++++++------------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/authcache.helpers.inc b/authcache.helpers.inc index 84ebcaf..4fa90fe 100644 --- a/authcache.helpers.inc +++ b/authcache.helpers.inc @@ -256,7 +256,7 @@ function _authcache_shutdown_save_page() { )); // Hide sensitive info from anonymous users - if (!$user->uid && !variable_get('authcache_debug_all', FALSE)) { + if (variable_get('authcache_debug_all', FALSE) || !_authcache_debug_access()) { unset($_authcache_info['cache_uid']); unset($_authcache_info['cache_inc']); } @@ -440,3 +440,21 @@ function _authcache_get_http_status($status = 200) { $value = drupal_get_http_header("status"); return isset($value) ? (int) $value : $status; } + + +/** + * Returns true if the currently logged in user has access to debug functions. + */ +function _authcache_debug_access() { + global $user; + + if (variable_get('authcache_debug_all', FALSE)) { + return TRUE; + } + elseif (!$user->uid) { + return FALSE; + } + else { + return in_array($user->name, variable_get('authcache_debug_users', array())); + } +} diff --git a/authcache.module b/authcache.module index 5e9f677..e1acaba 100644 --- a/authcache.module +++ b/authcache.module @@ -134,10 +134,7 @@ function authcache_init() { drupal_add_js(drupal_get_path('module', 'authcache') .'/authcache.js'); // Add JS for debug mode? - if ( - variable_get('authcache_debug_all', FALSE) - || ($user->uid && ($debug_users = variable_get('authcache_debug_users', array()))) - ) { + if (_authcache_debug_access()) { drupal_add_js(drupal_get_path('module', 'authcache') . '/authcache.debug.js', array('type' => 'file', 'scope' => 'header')); // Also see authcache_authcache_info() for user debug settings } @@ -180,13 +177,11 @@ function authcache_init() { } // Remove debug cookies - if (isset($_COOKIE['authcache_debug']) && !variable_get('authcache_debug_all', FALSE)) { - if (!$user->uid || !in_array($user->name, variable_get('authcache_debug_users', array()))) { - setcookie('authcache_debug', "", REQUEST_TIME - 84000); // Delete JS cookie - setcookie('authcache_debug', "", REQUEST_TIME - 84000, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); - setcookie('nocache', 1, 0, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); - setcookie('nocache_temp', 1, 0, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); - } + if (isset($_COOKIE['authcache_debug']) && !_authcache_debug_access()) { + setcookie('authcache_debug', "", REQUEST_TIME - 84000); // Delete JS cookie + setcookie('authcache_debug', "", REQUEST_TIME - 84000, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); + setcookie('nocache', "", REQUEST_TIME - 84000, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); + setcookie('nocache_temp', "", REQUEST_TIME - 84000, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); } } @@ -212,7 +207,7 @@ function authcache_user_login(&$edit, $account) { } // Authcache debugging - if (in_array($account->name, variable_get('authcache_debug_users', array()))) { + if (_authcache_debug_access()) { setcookie('authcache_debug', 1, $expires, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); } @@ -231,6 +226,9 @@ function authcache_user_logout($account) { if (isset($_COOKIE['nocache'])) { setcookie('nocache', "", REQUEST_TIME - 86400, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); } + if (isset($_COOKIE['nocache_temp'])) { + setcookie('nocache_temp', "", REQUEST_TIME - 86400, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); + } if (isset($_COOKIE['authcache_debug'])) { setcookie('authcache_debug', "", REQUEST_TIME - 86400, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); } @@ -740,7 +738,7 @@ function authcache_authcache_info() { } // Debug mode by user only - if (!variable_get('authcache_debug_all', FALSE) && $user->uid && ($debug_users = variable_get('authcache_debug_users', array()))) { + if (!variable_get('authcache_debug_all', FALSE) && _authcache_debug_access()) { $authcache_info['debug_users'] = $debug_users; } -- 1.7.10.4