From 07a5224025295158d311a533a4eac722786c3a22 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 27 Apr 2016 10:34:57 +0000 Subject: [PATCH] * Admin: clear cache after admin-cli.php commands, so they become active automatically and allow to send json requests with basic auth credentials without an active session, used here to clear cache via webservice call, as we can NOT clear shared memmory cache of webserver from cli --- admin/admin-cli.php | 22 +++++++++++++++++++++- json.php | 10 ++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/admin/admin-cli.php b/admin/admin-cli.php index e651ab2111..362c0d3f5c 100755 --- a/admin/admin-cli.php +++ b/admin/admin-cli.php @@ -11,6 +11,8 @@ * @version $Id$ */ +use EGroupware\Api; + chdir(dirname(__FILE__)); // to enable our relative pathes to work if (php_sapi_name() !== 'cli') // security precaution: forbit calling admin-cli as web-page @@ -113,7 +115,7 @@ exit(0); */ function run_command(admin_cmd $cmd) { - global $arguments; + global $arguments,$user,$arg0s,$domain; $skip_checks = false; while ($arguments && ($extra = array_shift($arguments))) @@ -168,6 +170,24 @@ function run_command(admin_cmd $cmd) //_debug_array($cmd); try { print_r($cmd->run($time, true, $skip_checks, $dry_run)); + + // cli can NOT clear instance cache of APC(u), as cli uses different shared memory then webserver + // --> we use a webservice call to clear cache (might fail if no domain in specified in webserver_url or on command line) + if (!$dry_run) + { + $url = $GLOBALS['egw_info']['server']['webserver_url'].'/json.php?menuaction=admin.admin_hooks.ajax_clear_cache'; + if ($url[0] == '/') $url = 'http://'.(!empty($domain) && $domain != 'default' ? $domain : 'localhost').$url; + $data = file_get_contents($url, false, Api\Framework::proxy_context($user,$arg0s[1])); + error_log("file_get_contents('$url') returned ".array2string($data)); + if ($data && strpos($data, '"success"') !== false) + { + error_log('Instance cache cleared.'); + } + else + { + error_log('You might need to clear the cache for changes to be visiable: Admin >> Clear cache!'); + } + } } catch (egw_exception_wrong_userinput $e) { echo "\n".$e->getMessage()."\n\n"; diff --git a/json.php b/json.php index 2160226d7d..a946058a05 100644 --- a/json.php +++ b/json.php @@ -10,17 +10,23 @@ * @version $Id$ */ +use EGroupware\Api; use EGroupware\Api\Json; /** - * callback if the session-check fails, redirects to login.php + * callback if the session-check fails, redirects to login.php, if no valid basic auth credentials given * * @param array &$anon_account anon account_info with keys 'login', 'passwd' and optional 'passwd_type' * @return boolean|string true if we allow anon access and anon_account is set, a sessionid or false otherwise */ function login_redirect(&$anon_account) { - unset($anon_account); + // allow to make json calls via basic auth + if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW']) && + ($session_id = Api\Header\Authenticate::autocreate_session_callback($anon_account))) + { + return $session_id; + } Json\Request::isJSONRequest(true); // because egw_json_request::parseRequest() is not (yet) called $response = Json\Response::get(); $response->redirect($GLOBALS['egw_info']['server']['webserver_url'].'/login.php?cd=10', true);