Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/ArchiveProcessor/Rules.php3
-rw-r--r--core/Common.php18
-rw-r--r--core/FrontController.php7
-rw-r--r--core/Log/MessageScreenFormatter.php6
-rw-r--r--core/Log/ScreenFormatter.php4
-rw-r--r--core/Session.php2
-rw-r--r--core/Session/SessionNamespace.php4
-rw-r--r--core/SettingsPiwik.php4
-rw-r--r--core/SettingsServer.php13
-rw-r--r--core/Tracker.php70
-rw-r--r--misc/cron/archive.php6
-rwxr-xr-xmisc/others/geoipUpdateRows.php7
-rw-r--r--misc/others/test_generateLotsVisitsWebsites.php3
-rw-r--r--plugins/CoreUpdater/Controller.php4
-rw-r--r--plugins/PrivacyManager/Controller.php3
-rw-r--r--tests/PHPUnit/Core/ArchiveProcessingTest.php6
16 files changed, 91 insertions, 69 deletions
diff --git a/core/ArchiveProcessor/Rules.php b/core/ArchiveProcessor/Rules.php
index 9b40be42bc..73949ee102 100644
--- a/core/ArchiveProcessor/Rules.php
+++ b/core/ArchiveProcessor/Rules.php
@@ -11,6 +11,7 @@
namespace Piwik\ArchiveProcessor;
use Exception;
+use Piwik\Common;
use Piwik\Config;
use Piwik\Date;
use Piwik\Piwik;
@@ -214,7 +215,7 @@ class Rules
{
return !self::$archivingDisabledByTests &&
(Rules::isBrowserTriggerEnabled()
- || SettingsServer::isPhpCliMode()
+ || Common::isPhpCliMode()
|| (Piwik::isUserIsSuperUser()
&& SettingsServer::isArchivePhpTriggered()));
}
diff --git a/core/Common.php b/core/Common.php
index a78378925e..b9344db59b 100644
--- a/core/Common.php
+++ b/core/Common.php
@@ -40,6 +40,7 @@ class Common
*/
const HTML_ENCODING_QUOTE_STYLE = ENT_QUOTES;
+
/*
* Database
*/
@@ -114,6 +115,20 @@ class Common
return PluginsManager::getInstance()->isPluginActivated('Goals');
}
+ /**
+ * Returns true if PHP was invoked from command-line interface (shell)
+ *
+ * @since added in 0.4.4
+ * @return bool true if PHP invoked as a CGI or from CLI
+ */
+ public static function isPhpCliMode()
+ {
+ $remoteAddr = @$_SERVER['REMOTE_ADDR'];
+ return PHP_SAPI == 'cli' ||
+ (!strncmp(PHP_SAPI, 'cgi', 3) && empty($remoteAddr));
+ }
+
+
/*
* String operations
*/
@@ -718,7 +733,7 @@ class Common
if (is_null($browserLang)) {
$browserLang = self::sanitizeInputValues(@$_SERVER['HTTP_ACCEPT_LANGUAGE']);
- if (empty($browserLang) && SettingsServer::isPhpCliMode()) {
+ if (empty($browserLang) && self::isPhpCliMode()) {
$browserLang = @getenv('LANG');
}
}
@@ -954,5 +969,6 @@ class Common
}
}
}
+
}
diff --git a/core/FrontController.php b/core/FrontController.php
index 7a3660ee34..21032df160 100644
--- a/core/FrontController.php
+++ b/core/FrontController.php
@@ -15,7 +15,6 @@ use Piwik\API\Request;
use Piwik\API\ResponseBuilder;
use Piwik\Log;
use Piwik\Session;
-use Piwik\Profiler;
use Zend_Registry;
/**
@@ -184,7 +183,7 @@ class FrontController
// which load the HTML page of the installer with the error.
// This is at least required for misc/cron/archive.php and useful to all other scripts
return (defined('PIWIK_ENABLE_DISPATCH') && !PIWIK_ENABLE_DISPATCH)
- || SettingsServer::isPhpCliMode()
+ || Common::isPhpCliMode()
|| SettingsServer::isArchivePhpTriggered();
}
@@ -319,7 +318,7 @@ class FrontController
protected function handleMaintenanceMode()
{
if (Config::getInstance()->General['maintenance_mode'] == 1
- && !SettingsServer::isPhpCliMode()
+ && !Common::isPhpCliMode()
) {
$format = Common::getRequestVar('format', '');
@@ -344,7 +343,7 @@ class FrontController
protected function handleSSLRedirection()
{
- if (!SettingsServer::isPhpCliMode()
+ if (!Common::isPhpCliMode()
&& Config::getInstance()->General['force_ssl'] == 1
&& !ProxyHttp::isHttps()
// Specifically disable for the opt out iframe
diff --git a/core/Log/MessageScreenFormatter.php b/core/Log/MessageScreenFormatter.php
index 26e48570b5..7b9ac48cdf 100644
--- a/core/Log/MessageScreenFormatter.php
+++ b/core/Log/MessageScreenFormatter.php
@@ -9,8 +9,8 @@
* @package Piwik
*/
namespace Piwik\Log;
+use Piwik\Common;
use Piwik\Profiler;
-use Piwik\SettingsServer;
/**
* Format a standard message event to be displayed on the screen.
@@ -34,14 +34,14 @@ class MessageScreenFormatter extends ScreenFormatter
} else {
$message = $event['message'];
}
- if (!SettingsServer::isPhpCliMode()) {
+ if (!Common::isPhpCliMode()) {
$message .= "<br/>";
}
$message .= "\n";
$memory = '';
// Hacky: let's hide the memory usage in CLI to hide from the archive.php output
- if (!SettingsServer::isPhpCliMode()) {
+ if (!Common::isPhpCliMode()) {
$memory = '[' . Profiler::getMemoryUsage() . '] ';
}
$message = '[' . $event['timestamp'] . '] [' . $event['requestKey'] . '] ' . $memory . $message;
diff --git a/core/Log/ScreenFormatter.php b/core/Log/ScreenFormatter.php
index a6326a126f..69b257d6c6 100644
--- a/core/Log/ScreenFormatter.php
+++ b/core/Log/ScreenFormatter.php
@@ -9,7 +9,7 @@
* @package Piwik
*/
namespace Piwik\Log;
-use Piwik\SettingsServer;
+use Piwik\Common;
/**
*
@@ -49,7 +49,7 @@ class ScreenFormatter implements \Zend_Log_Formatter_Interface
*/
static public function getFormattedString($string)
{
- if (!SettingsServer::isPhpCliMode()) {
+ if (!Common::isPhpCliMode()) {
@header('Content-Type: text/html; charset=utf-8');
}
return $string;
diff --git a/core/Session.php b/core/Session.php
index 67c0cc75d7..6cf0ee21a8 100644
--- a/core/Session.php
+++ b/core/Session.php
@@ -45,7 +45,7 @@ class Session extends Zend_Session
*/
public static function start($options = false)
{
- if (SettingsServer::isPhpCliMode()
+ if (Common::isPhpCliMode()
|| self::$sessionStarted
|| (defined('PIWIK_ENABLE_SESSION_START') && !PIWIK_ENABLE_SESSION_START)
) {
diff --git a/core/Session/SessionNamespace.php b/core/Session/SessionNamespace.php
index 7b041ec461..63ede5f45e 100644
--- a/core/Session/SessionNamespace.php
+++ b/core/Session/SessionNamespace.php
@@ -10,7 +10,7 @@
*/
namespace Piwik\Session;
-use Piwik\SettingsServer;
+use Piwik\Common;
use Zend_Session_Namespace;
/**
@@ -27,7 +27,7 @@ class SessionNamespace extends Zend_Session_Namespace
*/
public function __construct($namespace = 'Default', $singleInstance = false)
{
- if (SettingsServer::isPhpCliMode()) {
+ if (Common::isPhpCliMode()) {
self::$_readable = true;
return;
}
diff --git a/core/SettingsPiwik.php b/core/SettingsPiwik.php
index 5c48b5691b..f4efd30c0e 100644
--- a/core/SettingsPiwik.php
+++ b/core/SettingsPiwik.php
@@ -91,7 +91,7 @@ class SettingsPiwik
public static function shouldLoggerLog()
{
try {
- $shouldLog = (SettingsServer::isPhpCliMode()
+ $shouldLog = (Common::isPhpCliMode()
|| Config::getInstance()->log['log_only_when_cli'] == 0)
&&
(Config::getInstance()->log['log_only_when_debug_parameter'] == 0
@@ -127,7 +127,7 @@ class SettingsPiwik
$key = 'piwikUrl';
$url = Piwik_GetOption($key);
- if (SettingsServer::isPhpCliMode()
+ if (Common::isPhpCliMode()
// in case archive.php is triggered with domain localhost
|| SettingsServer::isArchivePhpTriggered()
|| defined('PIWIK_MODE_ARCHIVE')
diff --git a/core/SettingsServer.php b/core/SettingsServer.php
index 58208714b8..8f0f9d80bd 100644
--- a/core/SettingsServer.php
+++ b/core/SettingsServer.php
@@ -30,19 +30,6 @@ class SettingsServer
}
/**
- * Returns true if PHP was invoked from command-line interface (shell)
- *
- * @since added in 0.4.4
- * @return bool true if PHP invoked as a CGI or from CLI
- */
- public static function isPhpCliMode()
- {
- $remoteAddr = @$_SERVER['REMOTE_ADDR'];
- return PHP_SAPI == 'cli' ||
- (!strncmp(PHP_SAPI, 'cgi', 3) && empty($remoteAddr));
- }
-
- /**
* Returns true if running on Microsoft IIS 7 (or above)
*
* @return bool
diff --git a/core/Tracker.php b/core/Tracker.php
index d8f5950e52..996e3e97fd 100644
--- a/core/Tracker.php
+++ b/core/Tracker.php
@@ -86,6 +86,16 @@ class Tracker
*/
private $countOfLoggedRequests = 0;
+ protected function outputAccessControlHeaders()
+ {
+ $requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
+ if ($requestMethod !== 'GET') {
+ $origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '*';
+ Common::sendHeader('Access-Control-Allow-Origin: ' . $origin);
+ Common::sendHeader('Access-Control-Allow-Credentials: true');
+ }
+ }
+
public function clear()
{
self::$forcedIpString = null;
@@ -231,6 +241,8 @@ class Tracker
$this->exitWithException($ex, true);
}
+ $this->initOutputBuffer();
+
if (!empty($this->requests)) {
foreach ($this->requests as $params) {
$request = new Request($params, $tokenAuth);
@@ -280,13 +292,31 @@ class Tracker
$this->handleEmptyRequest(new Request($_GET + $_POST));
}
$this->end();
+
+ $this->flushOutputBuffer();
+ }
+
+ protected function initOutputBuffer()
+ {
+ ob_start();
+ }
+
+ protected function flushOutputBuffer()
+ {
+ ob_end_flush();
+ }
+
+ protected function getOutputBuffer()
+ {
+ return ob_get_contents();
}
+
protected function shouldRunScheduledTasks()
{
// don't run scheduled tasks in CLI mode from Tracker, this is the case
// where we bulk load logs & don't want to lose time with tasks
- return !SettingsServer::isPhpCliMode()
+ return !Common::isPhpCliMode()
&& $this->getState() != self::STATE_LOGGING_DISABLE;
}
@@ -401,7 +431,7 @@ class Tracker
|| $authenticated) {
$result['message'] = $this->getMessageFromException($e);
}
- $this->sendHeader('Content-Type: application/json');
+ Common::sendHeader('Content-Type: application/json');
echo Common::json_encode($result);
exit;
}
@@ -458,7 +488,7 @@ class Tracker
'status' => 'success',
'tracked' => $this->countOfLoggedRequests
);
- $this->sendHeader('Content-Type: application/json');
+ Common::sendHeader('Content-Type: application/json');
echo Common::json_encode($result);
exit;
}
@@ -589,29 +619,21 @@ class Tracker
protected function outputTransparentGif()
{
- if (!isset($GLOBALS['PIWIK_TRACKER_DEBUG']) || !$GLOBALS['PIWIK_TRACKER_DEBUG']) {
- // If there was an error during tracker, do not display GIF
- if(headers_sent()) {
- return;
- }
- $trans_gif_64 = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
- $this->sendHeader('Content-Type: image/gif');
-
- $requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
-
- if ($requestMethod !== 'GET') {
- $origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '*';
- $this->sendHeader('Access-Control-Allow-Origin: ' . $origin);
- $this->sendHeader('Access-Control-Allow-Credentials: true');
- }
-
- print(base64_decode($trans_gif_64));
+ if (isset($GLOBALS['PIWIK_TRACKER_DEBUG'])
+ && $GLOBALS['PIWIK_TRACKER_DEBUG']) {
+ return;
}
- }
+ // If there was an error during tracker, do not display GIF
+ // (we can't use headers_sent() for some reasons)
+ if(strlen( $this->getOutputBuffer() ) > 0) {
+// return;
+ }
+ $transGifBase64 = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
+ Common::sendHeader('Content-Type: image/gif');
- protected function sendHeader($header)
- {
- Common::sendHeader($header);
+ $this->outputAccessControlHeaders();
+
+ print(base64_decode($transGifBase64));
}
protected function isVisitValid()
diff --git a/misc/cron/archive.php b/misc/cron/archive.php
index d88b3c0b0e..db2a29a29c 100644
--- a/misc/cron/archive.php
+++ b/misc/cron/archive.php
@@ -642,7 +642,7 @@ class CronArchive
*/
private function initCheckCli()
{
- if (!\Piwik\SettingsServer::isPhpCliMode()) {
+ if (!Common::isPhpCliMode()) {
$token_auth = Common::getRequestVar('token_auth', '', 'string');
if ($token_auth != $this->token_auth
|| strlen($token_auth) != 32
@@ -802,7 +802,7 @@ class CronArchive
private function initPiwikHost()
{
// If archive.php run as a web cron, we use the current hostname
- if (!\Piwik\SettingsServer::isPhpCliMode()) {
+ if (!Common::isPhpCliMode()) {
// example.org/piwik/misc/cron/
$piwikUrl = Common::sanitizeInputValue(Url::getCurrentUrlWithoutFileName());
// example.org/piwik/
@@ -838,7 +838,7 @@ class CronArchive
*/
private function isParameterSet($parameter, $valuePossible = false)
{
- if (!\Piwik\SettingsServer::isPhpCliMode()) {
+ if (!Common::isPhpCliMode()) {
return false;
}
$parameters = array(
diff --git a/misc/others/geoipUpdateRows.php b/misc/others/geoipUpdateRows.php
index 3b03d7f245..2369f955d8 100755
--- a/misc/others/geoipUpdateRows.php
+++ b/misc/others/geoipUpdateRows.php
@@ -8,7 +8,6 @@ use Piwik\Piwik;
use Piwik\Plugins\UserCountry\LocationProvider\GeoIp\Pecl;
use Piwik\Plugins\UserCountry\LocationProvider;
use Piwik\Plugins\UserCountry\LocationProvider\GeoIp\Php;
-use Piwik\SettingsServer;
ini_set("memory_limit", "512M");
error_reporting(E_ALL | E_NOTICE);
@@ -42,7 +41,7 @@ $query = "SELECT count(*) FROM " . Common::prefixTable('log_visit');
$count = Db::fetchOne($query);
// when script run via browser, check for Super User & output html page to do conversion via AJAX
-if (!SettingsServer::isPhpCliMode()) {
+if (!Common::isPhpCliMode()) {
try {
Piwik::checkUserIsSuperUser();
} catch (Exception $e) {
@@ -113,7 +112,7 @@ if (!SettingsServer::isPhpCliMode()) {
function geoipUpdateError($message)
{
Piwik::log($message);
- if (!SettingsServer::isPhpCliMode()) {
+ if (!Common::isPhpCliMode()) {
@header('HTTP/1.1 500 Internal Server Error', $replace = true, $responseCode = 500);
}
exit;
@@ -137,7 +136,7 @@ if (!$provider->isAvailable()) {
if ($displayNotes) {
Piwik::log("[note] The GeoIP PECL extension is broken: $workingOrError");
}
- if (SettingsServer::isPhpCliMode()) {
+ if (Common::isPhpCliMode()) {
Piwik::log("[note] Make sure your command line PHP is configured to use the PECL extension.");
}
$provider = null;
diff --git a/misc/others/test_generateLotsVisitsWebsites.php b/misc/others/test_generateLotsVisitsWebsites.php
index f28426e251..b9309f50b1 100644
--- a/misc/others/test_generateLotsVisitsWebsites.php
+++ b/misc/others/test_generateLotsVisitsWebsites.php
@@ -3,7 +3,6 @@ use Piwik\Common;
use Piwik\Config;
use Piwik\FrontController;
use Piwik\Piwik;
-use Piwik\SettingsServer;
define('PIWIK_INCLUDE_PATH', realpath(dirname(__FILE__) . "/../.."));
define('PIWIK_ENABLE_DISPATCH', false);
@@ -16,7 +15,7 @@ require_once PIWIK_INCLUDE_PATH . "/libs/PiwikTracker/PiwikTracker.php";
FrontController::getInstance()->init();
// SECURITY: DO NOT DELETE THIS LINE!
-if (!SettingsServer::isPhpCliMode()) {
+if (!Common::isPhpCliMode()) {
die("ERROR: Must be executed in CLI");
}
diff --git a/plugins/CoreUpdater/Controller.php b/plugins/CoreUpdater/Controller.php
index 571d00c172..c5fd949d40 100644
--- a/plugins/CoreUpdater/Controller.php
+++ b/plugins/CoreUpdater/Controller.php
@@ -255,14 +255,14 @@ class Controller extends \Piwik\Controller
SettingsServer::setMaxExecutionTime(0);
- $cli = SettingsServer::isPhpCliMode() ? '_cli' : '';
+ $cli = Common::isPhpCliMode() ? '_cli' : '';
$welcomeTemplate = '@CoreUpdater/runUpdaterAndExit_welcome' . $cli;
$doneTemplate = '@CoreUpdater/runUpdaterAndExit_done' . $cli;
$viewWelcome = new View($welcomeTemplate);
$viewDone = new View($doneTemplate);
$sqlQueries = $updater->getSqlQueriesToExecute();
- if (SettingsServer::isPhpCliMode()) {
+ if (Common::isPhpCliMode()) {
$this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile);
echo $viewWelcome->render();
diff --git a/plugins/PrivacyManager/Controller.php b/plugins/PrivacyManager/Controller.php
index ef37f7c969..1a8debbdc4 100644
--- a/plugins/PrivacyManager/Controller.php
+++ b/plugins/PrivacyManager/Controller.php
@@ -18,7 +18,6 @@ use Piwik\MetricsFormatter;
use Piwik\Piwik;
use Piwik\Plugins\DBStats\MySQLMetadataProvider;
use Piwik\Plugins\LanguagesManager\LanguagesManager;
-use Piwik\SettingsServer;
use Piwik\TaskScheduler;
use Piwik\View;
@@ -147,7 +146,7 @@ class Controller extends \Piwik\Controller\Admin
// if the request isn't a POST, redirect to index
if ($_SERVER["REQUEST_METHOD"] != "POST"
- && !SettingsServer::isPhpCliMode()
+ && !Common::isPhpCliMode()
) {
$this->redirectToIndex('PrivacyManager', 'privacySettings');
return;
diff --git a/tests/PHPUnit/Core/ArchiveProcessingTest.php b/tests/PHPUnit/Core/ArchiveProcessingTest.php
index aeed90fdf4..99f9b17434 100644
--- a/tests/PHPUnit/Core/ArchiveProcessingTest.php
+++ b/tests/PHPUnit/Core/ArchiveProcessingTest.php
@@ -194,7 +194,7 @@ class ArchiveProcessingTest extends DatabaseTestCase
// see isArchivingDisabled()
// Running in CLI doesn't impact the time to live today's archive we are loading
// From CLI, we will not return data that is 'stale'
- if (!SettingsServer::isPhpCliMode()) {
+ if (!Common::isPhpCliMode()) {
$dateMinArchived = 0;
}
$this->compareTimestamps($archiveProcessor->getMinTimeArchiveProcessed(), $dateMinArchived);
@@ -237,7 +237,7 @@ class ArchiveProcessingTest extends DatabaseTestCase
// see isArchivingDisabled()
// Running in CLI doesn't impact the time to live today's archive we are loading
// From CLI, we will not return data that is 'stale'
- if (!SettingsServer::isPhpCliMode()) {
+ if (!Common::isPhpCliMode()) {
$dateMinArchived = 0;
}
$this->compareTimestamps($dateMinArchived, $archiveProcessor->getMinTimeArchiveProcessed());
@@ -283,7 +283,7 @@ class ArchiveProcessingTest extends DatabaseTestCase
// see isArchivingDisabled()
// Running in CLI doesn't impact the time to live today's archive we are loading
// From CLI, we will not return data that is 'stale'
- if (!SettingsServer::isPhpCliMode()) {
+ if (!Common::isPhpCliMode()) {
$dateMinArchived = 0;
}
$this->compareTimestamps($dateMinArchived, $archiveProcessor->getMinTimeArchiveProcessed());