示例#1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $serverGlobal = $input->getOption('server-global');
     if ($serverGlobal) {
         $_SERVER = json_decode($serverGlobal, true);
     }
     $this->requireFixtureFiles($input);
     $this->setIncludePathAsInTestBootstrap();
     $host = Url::getHost();
     if (empty($host)) {
         Url::setHost('localhost');
     }
     $fixture = $this->createFixture($input);
     $this->setupDatabaseOverrides($input, $fixture);
     // perform setup and/or teardown
     if ($input->getOption('teardown')) {
         $fixture->getTestEnvironment()->save();
         $fixture->performTearDown();
     } else {
         $fixture->performSetUp();
     }
     if ($input->getOption('set-phantomjs-symlinks')) {
         $this->createSymbolicLinksForUITests();
     }
     $this->writeSuccessMessage($output, array("Fixture successfully setup!"));
     $sqlDumpPath = $input->getOption('sqldump');
     if ($sqlDumpPath) {
         $this->createSqlDump($sqlDumpPath, $output);
     }
 }
示例#2
0
 /**
  * Computes the output for the given data table
  *
  * @param DataTable $table
  * @return string
  * @throws Exception
  */
 protected function renderTable($table)
 {
     if (!$table instanceof DataTable\Map || $table->getKeyName() != 'date') {
         throw new Exception("RSS feeds can be generated for one specific website &idSite=X." . "\nPlease specify only one idSite or consider using &format=XML instead.");
     }
     $idSite = Common::getRequestVar('idSite', 1, 'int');
     $period = Common::getRequestVar('period');
     $piwikUrl = Url::getCurrentUrlWithoutFileName() . "?module=CoreHome&action=index&idSite=" . $idSite . "&period=" . $period;
     $out = "";
     $moreRecentFirst = array_reverse($table->getDataTables(), true);
     foreach ($moreRecentFirst as $date => $subtable) {
         /** @var DataTable $subtable */
         $timestamp = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart()->getTimestamp();
         $site = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_SITE_INDEX);
         $pudDate = date('r', $timestamp);
         $dateInSiteTimezone = Date::factory($timestamp)->setTimezone($site->getTimezone())->toString('Y-m-d');
         $thisPiwikUrl = Common::sanitizeInputValue($piwikUrl . "&date={$dateInSiteTimezone}");
         $siteName = $site->getName();
         $title = $siteName . " on " . $date;
         $out .= "\t<item>\n\t\t<pubDate>{$pudDate}</pubDate>\n\t\t<guid>{$thisPiwikUrl}</guid>\n\t\t<link>{$thisPiwikUrl}</link>\n\t\t<title>{$title}</title>\n\t\t<author>http://piwik.org</author>\n\t\t<description>";
         $out .= Common::sanitizeInputValue($this->renderDataTable($subtable));
         $out .= "</description>\n\t</item>\n";
     }
     $header = $this->getRssHeader();
     $footer = $this->getRssFooter();
     return $header . $out . $footer;
 }
 public function __construct($username)
 {
     $this->username = $username;
     $this->title = 'Piwik - ' . Url::getCurrentHost();
     $this->description = Piwik::getCurrentUserLogin();
     $this->load();
 }
示例#4
0
 public function setUp()
 {
     parent::setup();
     File::reset();
     Url::setHost(false);
     $this->output = new Output('myid');
 }
 /**
  * Check for a newer version
  *
  * @param bool $force Force check
  * @param int $interval Interval used for update checks
  */
 public static function check($force = false, $interval = null)
 {
     if (!self::isAutoUpdateEnabled()) {
         return;
     }
     if ($interval === null) {
         $interval = self::CHECK_INTERVAL;
     }
     $lastTimeChecked = Option::get(self::LAST_TIME_CHECKED);
     if ($force || $lastTimeChecked === false || time() - $interval > $lastTimeChecked) {
         // set the time checked first, so that parallel Piwik requests don't all trigger the http requests
         Option::set(self::LAST_TIME_CHECKED, time(), $autoLoad = 1);
         $parameters = array('piwik_version' => Version::VERSION, 'php_version' => PHP_VERSION, 'url' => Url::getCurrentUrlWithoutQueryString(), 'trigger' => Common::getRequestVar('module', '', 'string'), 'timezone' => API::getInstance()->getDefaultTimezone());
         $url = Config::getInstance()->General['api_service_url'] . '/1.0/getLatestVersion/' . '?' . http_build_query($parameters, '', '&');
         $timeout = self::SOCKET_TIMEOUT;
         if (@Config::getInstance()->Debug['allow_upgrades_to_beta']) {
             $url = 'http://builds.piwik.org/LATEST_BETA';
         }
         try {
             $latestVersion = Http::sendHttpRequest($url, $timeout);
             if (!preg_match('~^[0-9][0-9a-zA-Z_.-]*$~D', $latestVersion)) {
                 $latestVersion = '';
             }
         } catch (Exception $e) {
             // e.g., disable_functions = fsockopen; allow_url_open = Off
             $latestVersion = '';
         }
         Option::set(self::LATEST_VERSION, $latestVersion);
     }
 }
示例#6
0
 /**
  * Returns SEO statistics for a URL.
  *
  * @param string $url URL to request SEO stats for
  * @return DataTable
  */
 public function getRank($url)
 {
     Piwik::checkUserHasSomeViewAccess();
     $metricProvider = new ProviderCache(new Aggregator());
     $domain = Url::getHostFromUrl($url);
     $metrics = $metricProvider->getMetrics($domain);
     return $this->toDataTable($metrics);
 }
示例#7
0
 public function test_getUrlToCheckForLatestAvailableVersion()
 {
     $version = Version::VERSION;
     $phpVersion = urlencode(PHP_VERSION);
     $url = urlencode(Url::getCurrentUrlWithoutQueryString());
     $urlToCheck = $this->channel->getUrlToCheckForLatestAvailableVersion();
     $this->assertStringStartsWith("http://api.piwik.org/1.0/getLatestVersion/?piwik_version={$version}&php_version={$phpVersion}&release_channel=my_channel&url={$url}&trigger=&timezone=", $urlToCheck);
 }
示例#8
0
 /**
  * Adds a report to the list of reports to display.
  *
  * @param string $category The report's category. Can be a i18n token.
  * @param string $title The report's title. Can be a i18n token.
  * @param string $action The controller action used to load the report, ie, Referrers.getAll
  * @param array $params The list of query parameters to use when loading the report.
  *                      This list overrides query parameters currently in use. For example,
  *                        array('idSite' => 2, 'viewDataTable' => 'goalsTable')
  *                      would mean the goals report for site w/ ID=2 will always be loaded.
  */
 public function addReport($category, $title, $action, $params = array())
 {
     list($module, $action) = explode('.', $action);
     $params = array('module' => $module, 'action' => $action) + $params;
     $categories = $this->dimensionCategories;
     $categories[$category][] = array('title' => $title, 'params' => $params, 'url' => Url::getCurrentQueryStringWithParametersModified($params));
     $this->dimensionCategories = $categories;
 }
示例#9
0
 /**
  * anonymous = in the session
  * authenticated user = in the session
  */
 public function saveLanguage()
 {
     $language = Common::getRequestVar('language');
     // Prevent CSRF only when piwik is not installed yet (During install user can change language)
     if (DbHelper::isInstalled()) {
         $this->checkTokenInUrl();
     }
     LanguagesManager::setLanguageForSession($language);
     Url::redirectToReferrer();
 }
示例#10
0
 /**
  * Returns the javascript tag for the given idSite.
  * This tag must be included on every page to be tracked by Piwik
  *
  * @param int $idSite
  * @param string $piwikUrl
  * @param bool $mergeSubdomains
  * @param bool $groupPageTitlesByDomain
  * @param bool $mergeAliasUrls
  * @param bool $visitorCustomVariables
  * @param bool $pageCustomVariables
  * @param bool $customCampaignNameQueryParam
  * @param bool $customCampaignKeywordParam
  * @param bool $doNotTrack
  * @internal param $
  * @return string The Javascript tag ready to be included on the HTML pages
  */
 public function getJavascriptTag($idSite, $piwikUrl = '', $mergeSubdomains = false, $groupPageTitlesByDomain = false, $mergeAliasUrls = false, $visitorCustomVariables = false, $pageCustomVariables = false, $customCampaignNameQueryParam = false, $customCampaignKeywordParam = false, $doNotTrack = false)
 {
     Piwik::checkUserHasViewAccess($idSite);
     if (empty($piwikUrl)) {
         $piwikUrl = Url::getCurrentUrlWithoutFileName();
     }
     $piwikUrl = Common::sanitizeInputValues($piwikUrl);
     $htmlEncoded = Piwik::getJavascriptCode($idSite, $piwikUrl, $mergeSubdomains, $groupPageTitlesByDomain, $mergeAliasUrls, $visitorCustomVariables, $pageCustomVariables, $customCampaignNameQueryParam, $customCampaignKeywordParam, $doNotTrack);
     $htmlEncoded = str_replace(array('<br>', '<br />', '<br/>'), '', $htmlEncoded);
     return $htmlEncoded;
 }
示例#11
0
 function __construct($id, $method = 'post', $attributes = null, $trackSubmit = false)
 {
     if (!isset($attributes['action'])) {
         $attributes['action'] = Url::getCurrentQueryString();
     }
     if (!isset($attributes['name'])) {
         $attributes['name'] = $id;
     }
     parent::__construct($id, $method, $attributes, $trackSubmit);
     $this->init();
 }
示例#12
0
 /**
  * @param InputInterface $input
  */
 protected function initHostAndQueryString(InputInterface $input)
 {
     $_GET = array();
     $hostname = $input->getOption('piwik-domain');
     Url::setHost($hostname);
     $query = $input->getArgument('url-query');
     $query = UrlHelper::getArrayFromQueryString($query);
     foreach ($query as $name => $value) {
         $_GET[$name] = $value;
     }
 }
示例#13
0
文件: API.php 项目: piwik/piwik
 /**
  * @internal
  */
 public function setTrustedHosts($trustedHosts)
 {
     Piwik::checkUserHasSuperUserAccess();
     if (!Controller::isGeneralSettingsAdminEnabled()) {
         throw new Exception('General settings admin is ont enabled');
     }
     if (!empty($trustedHosts)) {
         Url::saveTrustedHostnameInConfig($trustedHosts);
         Config::getInstance()->forceSave();
     }
     return true;
 }
示例#14
0
 private function sendMail($subject, $body)
 {
     $feedbackEmailAddress = Config::getInstance()->General['feedback_email_address'];
     $subject = '[ Feedback Feature - Piwik ] ' . $subject;
     $body = Common::unsanitizeInputValue($body) . "\n" . 'Piwik ' . Version::VERSION . "\n" . 'IP: ' . IP::getIpFromHeader() . "\n" . 'URL: ' . Url::getReferrer() . "\n";
     $mail = new Mail();
     $mail->setFrom(Piwik::getCurrentUserEmail());
     $mail->addTo($feedbackEmailAddress, 'Piwik Team');
     $mail->setSubject($subject);
     $mail->setBodyText($body);
     @$mail->send();
 }
示例#15
0
 /**
  * Sets the sender.
  *
  * @param string $email Email address of the sender.
  * @param null|string $name Name of the sender.
  * @return Zend_Mail
  */
 public function setFrom($email, $name = null)
 {
     $hostname = Config::getInstance()->mail['defaultHostnameIfEmpty'];
     $piwikHost = Url::getCurrentHost($hostname);
     // If known Piwik URL, use it instead of "localhost"
     $piwikUrl = SettingsPiwik::getPiwikUrl();
     $url = parse_url($piwikUrl);
     if (isset($url['host']) && $url['host'] != 'localhost' && $url['host'] != '127.0.0.1') {
         $piwikHost = $url['host'];
     }
     $email = str_replace('{DOMAIN}', $piwikHost, $email);
     return parent::setFrom($email, $name);
 }
示例#16
0
 private function isPageSpeedEnabled()
 {
     $url = Url::getCurrentUrlWithoutQueryString() . '?module=Installation&action=getEmptyPageForSystemCheck';
     try {
         $page = Http::sendHttpRequest($url, $timeout = 1, $userAgent = null, $destinationPath = null, $followDepth = 0, $acceptLanguage = false, $byteRange = false, $getExtendedInfo = true);
     } catch (\Exception $e) {
         $this->logger->info('Unable to test if mod_pagespeed is enabled: the request to {url} failed', array('url' => $url));
         // If the test failed, we assume Page speed is not enabled
         return false;
     }
     $headers = $page['headers'];
     return isset($headers['X-Mod-Pagespeed']) || isset($headers['X-Page-Speed']);
 }
示例#17
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!defined('PIWIK_TEST_MODE')) {
         define('PIWIK_TEST_MODE', true);
     }
     Environment::setGlobalEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables()));
     $serverGlobal = $input->getOption('server-global');
     if ($serverGlobal) {
         $_SERVER = json_decode($serverGlobal, true);
     }
     if (Config::getInstance()->database_tests['tables_prefix'] !== '') {
         throw new \Exception("To generate OmniFixture for the UI tests, you must set an empty tables_prefix in [database_tests]");
     }
     $this->requireFixtureFiles($input);
     $this->setIncludePathAsInTestBootstrap();
     $host = Url::getHost();
     if (empty($host)) {
         $host = 'localhost';
         Url::setHost('localhost');
     }
     $configDomainToSave = $input->getOption('save-config');
     if (!empty($configDomainToSave)) {
         $pathToDomainConfig = PIWIK_INCLUDE_PATH . '/config/' . $host . '.config.ini.php';
         if (!file_exists($pathToDomainConfig)) {
             link(PIWIK_INCLUDE_PATH . '/config/config.ini.php', $pathToDomainConfig);
         }
     }
     if ($input->getOption('set-phantomjs-symlinks')) {
         $this->createSymbolicLinksForUITests();
     }
     $fixture = $this->createFixture($input, $allowSave = !empty($configDomainToSave));
     $this->setupDatabaseOverrides($input, $fixture);
     // perform setup and/or teardown
     if ($input->getOption('teardown')) {
         $fixture->getTestEnvironment()->save();
         $fixture->performTearDown();
     } else {
         $fixture->performSetUp();
     }
     $this->writeSuccessMessage($output, array("Fixture successfully setup!"));
     $sqlDumpPath = $input->getOption('sqldump');
     if ($sqlDumpPath) {
         $this->createSqlDump($sqlDumpPath, $output);
     }
     if (!empty($configDomainToSave)) {
         Config::getInstance()->forceSave();
     }
 }
示例#18
0
 /**
  * anonymous = in the session
  * authenticated user = in the session and in DB
  */
 public function saveLanguage()
 {
     $language = Common::getRequestVar('language');
     // Prevent CSRF only when piwik is not installed yet (During install user can change language)
     if (DbHelper::isInstalled()) {
         $this->checkTokenInUrl();
     }
     LanguagesManager::setLanguageForSession($language);
     if (\Piwik\Registry::isRegistered('access')) {
         $currentUser = Piwik::getCurrentUserLogin();
         if ($currentUser && $currentUser !== 'anonymous') {
             API::getInstance()->setLanguageForUser($currentUser, $language);
         }
     }
     Url::redirectToReferrer();
 }
示例#19
0
文件: Evolution.php 项目: piwik/piwik
 /**
  * @param DataTable|DataTable\Map $dataTable
  * @param $visualization
  */
 protected function initChartObjectData($dataTable, $visualization)
 {
     // if the loaded datatable is a simple DataTable, it is most likely a plugin plotting some custom data
     // we don't expect plugin developers to return a well defined Set
     if ($dataTable instanceof DataTable) {
         parent::initChartObjectData($dataTable, $visualization);
         return;
     }
     // the X label is extracted from the 'period' object in the table's metadata
     $xLabels = array();
     foreach ($dataTable->getDataTables() as $metadataDataTable) {
         $xLabels[] = $metadataDataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getLocalizedShortString();
         // eg. "Aug 2009"
     }
     $units = $this->getUnitsForColumnsToDisplay();
     // if rows to display are not specified, default to all rows (TODO: perhaps this should be done elsewhere?)
     $rowsToDisplay = $this->properties['rows_to_display'] ?: array_unique($dataTable->getColumn('label')) ?: array(false);
     // collect series data to show. each row-to-display/column-to-display permutation creates a series.
     $allSeriesData = array();
     $seriesUnits = array();
     foreach ($rowsToDisplay as $rowLabel) {
         foreach ($this->properties['columns_to_display'] as $columnName) {
             $seriesLabel = $this->getSeriesLabel($rowLabel, $columnName);
             $seriesData = $this->getSeriesData($rowLabel, $columnName, $dataTable);
             $allSeriesData[$seriesLabel] = $seriesData;
             $seriesUnits[$seriesLabel] = $units[$columnName];
         }
     }
     $visualization->dataTable = $dataTable;
     $visualization->properties = $this->properties;
     $visualization->setAxisXLabels($xLabels);
     $visualization->setAxisYValues($allSeriesData);
     $visualization->setAxisYUnits($seriesUnits);
     $dataTables = $dataTable->getDataTables();
     if ($this->isLinkEnabled()) {
         $idSite = Common::getRequestVar('idSite', null, 'int');
         $periodLabel = reset($dataTables)->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getLabel();
         $axisXOnClick = array();
         foreach ($dataTable->getDataTables() as $metadataDataTable) {
             $dateInUrl = $metadataDataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart();
             $parameters = array('idSite' => $idSite, 'period' => $periodLabel, 'date' => $dateInUrl->toString(), 'segment' => \Piwik\API\Request::getRawSegmentFromRequest());
             $link = Url::getQueryStringFromParameters($parameters);
             $axisXOnClick[] = $link;
         }
         $visualization->setAxisXOnClick($axisXOnClick);
     }
 }
示例#20
0
文件: GetRank.php 项目: piwik/piwik
 public function render()
 {
     $idSite = Common::getRequestVar('idSite');
     $site = new Site($idSite);
     $url = urldecode(Common::getRequestVar('url', '', 'string'));
     if (!empty($url) && strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
         $url = 'http://' . $url;
     }
     if (empty($url) || !UrlHelper::isLookLikeUrl($url)) {
         $url = $site->getMainUrl();
     }
     $dataTable = API::getInstance()->getRank($url);
     /** @var \Piwik\DataTable\Renderer\Php $renderer */
     $renderer = Renderer::factory('php');
     $renderer->setSerialize(false);
     return $this->renderTemplate('getRank', array('urlToRank' => Url::getHostFromUrl($url), 'ranks' => $renderer->render($dataTable)));
 }
示例#21
0
 private static function notifyAnyInvalidPlugin()
 {
     $missingPlugins = \Piwik\Plugin\Manager::getInstance()->getMissingPlugins();
     if (empty($missingPlugins)) {
         return;
     }
     if (!Piwik::hasUserSuperUserAccess()) {
         return;
     }
     $pluginsLink = Url::getCurrentQueryStringWithParametersModified(array('module' => 'CorePluginsAdmin', 'action' => 'plugins'));
     $invalidPluginsWarning = Piwik::translate('CoreAdminHome_InvalidPluginsWarning', array(self::getPiwikVersion(), '<strong>' . implode('</strong>,&nbsp;<strong>', $missingPlugins) . '</strong>')) . "<br/>" . Piwik::translate('CoreAdminHome_InvalidPluginsYouCanUninstall', array('<a href="' . $pluginsLink . '"/>', '</a>'));
     $notification = new Notification($invalidPluginsWarning);
     $notification->raw = true;
     $notification->context = Notification::CONTEXT_WARNING;
     $notification->title = Piwik::translate('General_Warning');
     Notification\Manager::notify('ControllerAdmin_InvalidPluginsWarning', $notification);
 }
示例#22
0
 /**
  * Checks if a datatable for a view is empty and if so, displays a message in the footer
  * telling users to configure GeoIP.
  */
 protected function checkIfNoDataForGeoIpReport(ViewDataTable $view)
 {
     $view->config->filters[] = function ($dataTable) use($view) {
         // if there's only one row whose label is 'Unknown', display a message saying there's no data
         if ($dataTable->getRowsCount() == 1 && $dataTable->getFirstRow()->getColumn('label') == Piwik::translate('General_Unknown')) {
             $footerMessage = Piwik::translate('UserCountry_NoDataForGeoIPReport1');
             $userCountry = new UserCountry();
             // if GeoIP is working, don't display this part of the message
             if (!$userCountry->isGeoIPWorking()) {
                 $params = array('module' => 'UserCountry', 'action' => 'adminIndex');
                 $footerMessage .= ' ' . Piwik::translate('UserCountry_NoDataForGeoIPReport2', array('<a target="_blank" href="' . Url::getCurrentQueryStringWithParametersModified($params) . '">', '</a>', '<a target="_blank" href="http://dev.maxmind.com/geoip/geolite?rId=piwik">', '</a>'));
             } else {
                 $footerMessage .= ' ' . Piwik::translate('UserCountry_ToGeolocateOldVisits', array('<a target="_blank" href="http://piwik.org/faq/how-to/#faq_167">', '</a>'));
             }
             $view->config->show_footer_message = $footerMessage;
         }
     };
 }
示例#23
0
 private static function notifyIfURLIsNotSecure()
 {
     $isURLSecure = ProxyHttp::isHttps();
     if ($isURLSecure) {
         return;
     }
     if (!Piwik::hasUserSuperUserAccess()) {
         return;
     }
     if (Url::isLocalHost(Url::getCurrentHost())) {
         return;
     }
     $message = Piwik::translate('General_CurrentlyUsingUnsecureHttp');
     $message .= " ";
     $message .= Piwik::translate('General_ReadThisToLearnMore', array('<a rel="noreferrer" target="_blank" href="https://piwik.org/faq/how-to/faq_91/">', '</a>'));
     $notification = new Notification($message);
     $notification->context = Notification::CONTEXT_WARNING;
     $notification->raw = true;
     Notification\Manager::notify('ControllerAdmin_HttpIsUsed', $notification);
 }
示例#24
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $serverGlobal = $input->getOption('server-global');
     if ($serverGlobal) {
         $_SERVER = json_decode($serverGlobal, true);
     }
     $this->requireFixtureFiles($input);
     $this->setIncludePathAsInTestBootstrap();
     $host = Url::getHost();
     if (empty($host)) {
         $host = 'localhost';
         Url::setHost('localhost');
     }
     $configDomainToSave = $input->getOption('save-config');
     if (!empty($configDomainToSave)) {
         $pathToDomainConfig = PIWIK_INCLUDE_PATH . '/config/' . $host . '.config.ini.php';
         if (!file_exists($pathToDomainConfig)) {
             link(PIWIK_INCLUDE_PATH . '/config/config.ini.php', $pathToDomainConfig);
         }
     }
     $fixture = $this->createFixture($input);
     $this->setupDatabaseOverrides($input, $fixture);
     // perform setup and/or teardown
     if ($input->getOption('teardown')) {
         $fixture->getTestEnvironment()->save();
         $fixture->performTearDown();
     } else {
         $fixture->performSetUp();
     }
     if ($input->getOption('set-phantomjs-symlinks')) {
         $this->createSymbolicLinksForUITests();
     }
     $this->writeSuccessMessage($output, array("Fixture successfully setup!"));
     $sqlDumpPath = $input->getOption('sqldump');
     if ($sqlDumpPath) {
         $this->createSqlDump($sqlDumpPath, $output);
     }
     if (!empty($configDomainToSave)) {
         Config::getInstance()->forceSave();
     }
 }
 public function beforeContainerCreated()
 {
     $this->vars->reload();
     if ($this->vars->queryParamOverride) {
         foreach ($this->vars->queryParamOverride as $key => $value) {
             $_GET[$key] = $value;
         }
     }
     if ($this->vars->globalsOverride) {
         foreach ($this->vars->globalsOverride as $key => $value) {
             $GLOBALS[$key] = $value;
         }
     }
     if ($this->vars->hostOverride) {
         \Piwik\Url::setHost($this->vars->hostOverride);
     }
     if ($this->vars->useXhprof) {
         \Piwik\Profiler::setupProfilerXHProf($mainRun = false, $setupDuringTracking = true);
     }
     \Piwik\Cache\Backend\File::$invalidateOpCacheBeforeRead = true;
 }
示例#26
0
    /**
     * Output redirection page instead of linking directly to avoid
     * exposing the referrer on the Piwik demo.
     *
     * @internal param string $url (via $_GET)
     */
    public function redirect()
    {
        $url = Common::getRequestVar('url', '', 'string', $_GET);
        // validate referrer
        $referrer = Url::getReferrer();
        if (empty($referrer) || !Url::isLocalUrl($referrer)) {
            die('Invalid Referrer detected - This means that your web browser is not sending the "Referrer URL" which is
				required to proceed with the redirect. Verify your browser settings and add-ons, to check why your browser
				 is not sending this referrer.

				<br/><br/>You can access the page at: ' . $url);
        }
        // mask visits to *.piwik.org
        if (!self::isPiwikUrl($url)) {
            Piwik::checkUserHasSomeViewAccess();
        }
        if (!UrlHelper::isLookLikeUrl($url)) {
            die('Please check the &url= parameter: it should to be a valid URL');
        }
        @header('Content-Type: text/html; charset=utf-8');
        echo '<html><head><meta http-equiv="refresh" content="0;url=' . $url . '" /></head></html>';
        exit;
    }
示例#27
0
 public function generalSettings()
 {
     Piwik::checkUserHasSuperUserAccess();
     $view = new View('@CoreAdminHome/generalSettings');
     $this->handleGeneralSettingsAdmin($view);
     $view->trustedHosts = array_values(Url::getTrustedHostsFromConfig());
     $logo = new CustomLogo();
     $view->branding = array('use_custom_logo' => $logo->isEnabled());
     $view->fileUploadEnabled = $logo->isFileUploadEnabled();
     $view->logosWriteable = $logo->isCustomLogoWritable();
     $view->hasUserLogo = CustomLogo::hasUserLogo();
     $view->pathUserLogo = CustomLogo::getPathUserLogo();
     $view->hasUserFavicon = CustomLogo::hasUserFavicon();
     $view->pathUserFavicon = CustomLogo::getPathUserFavicon();
     $view->pathUserLogoSmall = CustomLogo::getPathUserLogoSmall();
     $view->pathUserLogoSVG = CustomLogo::getPathUserSvgLogo();
     $view->pathUserLogoDirectory = realpath(dirname($view->pathUserLogo) . '/');
     $view->mailTypes = array('' => '', 'Plain' => 'Plain', 'Login' => 'Login', 'Crammd5' => 'Crammd5');
     $view->mailEncryptions = array('' => '', 'ssl' => 'SSL', 'tls' => 'TLS');
     $view->language = LanguagesManager::getLanguageCodeForCurrentUser();
     $this->setBasicVariablesView($view);
     return $view->render();
 }
示例#28
0
 private function saveGeneralSettings()
 {
     if (!self::isGeneralSettingsAdminEnabled()) {
         // General settings + Beta channel + SMTP settings is disabled
         return;
     }
     // General Setting
     $enableBrowserTriggerArchiving = Common::getRequestVar('enableBrowserTriggerArchiving');
     $todayArchiveTimeToLive = Common::getRequestVar('todayArchiveTimeToLive');
     Rules::setBrowserTriggerArchiving((bool) $enableBrowserTriggerArchiving);
     Rules::setTodayArchiveTimeToLive($todayArchiveTimeToLive);
     // update beta channel setting
     $debug = Config::getInstance()->Debug;
     $debug['allow_upgrades_to_beta'] = Common::getRequestVar('enableBetaReleaseCheck', '0', 'int');
     Config::getInstance()->Debug = $debug;
     // Update email settings
     $mail = array();
     $mail['transport'] = Common::getRequestVar('mailUseSmtp') == '1' ? 'smtp' : '';
     $mail['port'] = Common::getRequestVar('mailPort', '');
     $mail['host'] = Common::unsanitizeInputValue(Common::getRequestVar('mailHost', ''));
     $mail['type'] = Common::getRequestVar('mailType', '');
     $mail['username'] = Common::unsanitizeInputValue(Common::getRequestVar('mailUsername', ''));
     $mail['password'] = Common::unsanitizeInputValue(Common::getRequestVar('mailPassword', ''));
     $mail['encryption'] = Common::getRequestVar('mailEncryption', '');
     Config::getInstance()->mail = $mail;
     // update trusted host settings
     $trustedHosts = Common::getRequestVar('trustedHosts', false, 'json');
     if ($trustedHosts !== false) {
         Url::saveTrustedHostnameInConfig($trustedHosts);
     }
     Config::getInstance()->forceSave();
     $pluginUpdateCommunication = new UpdateCommunication();
     if (Common::getRequestVar('enablePluginUpdateCommunication', '0', 'int')) {
         $pluginUpdateCommunication->enable();
     } else {
         $pluginUpdateCommunication->disable();
     }
 }
示例#29
0
 /**
  * Logout current user
  *
  * @param none
  * @return void
  */
 public function logout()
 {
     self::clearSession();
     $logoutUrl = @Config::getInstance()->General['login_logout_url'];
     if (empty($logoutUrl)) {
         Piwik::redirectToModule('CoreHome');
     } else {
         Url::redirectToUrl($logoutUrl);
     }
 }
示例#30
-1
 /**
  * send email to Piwik team and display nice thanks
  * @throws Exception
  */
 function sendFeedback()
 {
     $email = Common::getRequestVar('email', '', 'string');
     $body = Common::getRequestVar('body', '', 'string');
     $category = Common::getRequestVar('category', '', 'string');
     $nonce = Common::getRequestVar('nonce', '', 'string');
     $view = new View('@Feedback/sendFeedback');
     $view->feedbackEmailAddress = Config::getInstance()->General['feedback_email_address'];
     try {
         $minimumBodyLength = 40;
         if (strlen($body) < $minimumBodyLength || strpos($email, 'probe@') !== false || strpos($body, '&lt;probe') !== false) {
             throw new Exception(Piwik::translate('Feedback_ExceptionBodyLength', array($minimumBodyLength)));
         }
         if (!Piwik::isValidEmailString($email)) {
             throw new Exception(Piwik::translate('UsersManager_ExceptionInvalidEmail'));
         }
         if (preg_match('/https?:/i', $body)) {
             throw new Exception(Piwik::translate('Feedback_ExceptionNoUrls'));
         }
         if (!Nonce::verifyNonce('Feedback.sendFeedback', $nonce)) {
             throw new Exception(Piwik::translate('General_ExceptionNonceMismatch'));
         }
         Nonce::discardNonce('Feedback.sendFeedback');
         $mail = new Mail();
         $mail->setFrom(Common::unsanitizeInputValue($email));
         $mail->addTo($view->feedbackEmailAddress, 'Piwik Team');
         $mail->setSubject('[ Feedback form - Piwik ] ' . $category);
         $mail->setBodyText(Common::unsanitizeInputValue($body) . "\n" . 'Piwik ' . Version::VERSION . "\n" . 'IP: ' . IP::getIpFromHeader() . "\n" . 'URL: ' . Url::getReferrer() . "\n");
         @$mail->send();
     } catch (Exception $e) {
         $view->errorString = $e->getMessage();
         $view->message = $body;
     }
     return $view->render();
 }