public function setGeneralSettings()
 {
     Piwik::checkUserIsSuperUser();
     $response = new Piwik_API_ResponseBuilder(Piwik_Common::getRequestVar('format'));
     try {
         $this->checkTokenInUrl();
         $enableBrowserTriggerArchiving = Piwik_Common::getRequestVar('enableBrowserTriggerArchiving');
         $todayArchiveTimeToLive = Piwik_Common::getRequestVar('todayArchiveTimeToLive');
         Piwik_ArchiveProcessing::setBrowserTriggerArchiving((bool) $enableBrowserTriggerArchiving);
         Piwik_ArchiveProcessing::setTodayArchiveTimeToLive($todayArchiveTimeToLive);
         // Update email settings
         $mail = array();
         $mail['transport'] = Piwik_Common::getRequestVar('mailUseSmtp') == '1' ? 'smtp' : '';
         $mail['port'] = Piwik_Common::getRequestVar('mailPort', '');
         $mail['host'] = Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('mailHost', ''));
         $mail['type'] = Piwik_Common::getRequestVar('mailType', '');
         $mail['username'] = Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('mailUsername', ''));
         $mail['password'] = Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('mailPassword', ''));
         $mail['encryption'] = Piwik_Common::getRequestVar('mailEncryption', '');
         Piwik_Config::getInstance()->mail = $mail;
         // update branding settings
         Piwik_Config::getInstance()->branding['use_custom_logo'] = Piwik_Common::getRequestVar('useCustomLogo', '0');
         $toReturn = $response->getResponse();
     } catch (Exception $e) {
         $toReturn = $response->getResponseException($e);
     }
     echo $toReturn;
 }
示例#2
0
 public function setGeneralSettings()
 {
     Piwik::checkUserIsSuperUser();
     $response = new Piwik_API_ResponseBuilder(Piwik_Common::getRequestVar('format'));
     try {
         $this->checkTokenInUrl();
         $enableBrowserTriggerArchiving = Piwik_Common::getRequestVar('enableBrowserTriggerArchiving');
         $todayArchiveTimeToLive = Piwik_Common::getRequestVar('todayArchiveTimeToLive');
         Piwik_ArchiveProcessing::setBrowserTriggerArchiving((bool) $enableBrowserTriggerArchiving);
         Piwik_ArchiveProcessing::setTodayArchiveTimeToLive($todayArchiveTimeToLive);
         // Update email settings
         $mail = Zend_Registry::get('config')->mail;
         $mail->transport = Piwik_Common::getRequestVar('mailUseSmtp') == '1' ? 'smtp' : '';
         $mail->port = Piwik_Common::getRequestVar('mailPort', '');
         $mail->host = Piwik_Common::getRequestVar('mailHost', '');
         $mail->type = Piwik_Common::getRequestVar('mailType', '');
         $mail->username = Piwik_Common::getRequestVar('mailUsername', '');
         $mail->password = Piwik_Common::getRequestVar('mailPassword', '');
         $mail->encryption = Piwik_Common::getRequestVar('mailEncryption', '');
         Zend_Registry::get('config')->mail = $mail->toArray();
         $toReturn = $response->getResponse();
     } catch (Exception $e) {
         $toReturn = $response->getResponseException($e);
     }
     echo $toReturn;
 }
示例#3
0
 public function setSettings()
 {
     $response = new Piwik_API_ResponseBuilder(Piwik_Common::getRequestVar('format'));
     try {
         Piwik::checkUserIsSuperUser();
         $this->checkTokenInUrl();
         $mode = Piwik_Common::getRequestVar('TeraWurflMode');
         $url = Piwik_Common::getRequestVar('TeraWurflURL');
         $path = Piwik_Common::getRequestVar('TeraWurflPath');
         switch ($mode) {
             case 'TeraWurfl':
             case 'TeraWurflEnterprise':
                 if (!(file_exists($path) && (require_once $path))) {
                     echo $response->getResponseException(new Exception("Could not save settings: The file " . htmlentities($path) . " does not exist"));
                     return;
                 } elseif (!class_exists($mode)) {
                     echo $response->getResponseException(new Exception("Could not save settings: The file " . htmlentities($path) . " exists but does not contain the required class " . htmlentities($mode)));
                     return;
                 } else {
                     Piwik_MobileAnalytics::saveSetting('TeraWurflMode', $mode);
                     Piwik_MobileAnalytics::saveSetting('TeraWurflPath', $path);
                 }
                 break;
             case 'TeraWurflRemoteClient':
                 require_once PIWIK_INCLUDE_PATH . '/plugins/MobileAnalytics/TeraWurflRemoteClient.php';
                 try {
                     $this->wurflObj = new TeraWurflRemoteClient($url);
                     @$this->wurflObj->getCapabilitiesFromAgent(null, Piwik_MobileAnalytics::$requiredCapabilities);
                 } catch (Exception $e) {
                     echo $response->getResponseException(new Exception("Could not save settings: A request to the Tera-WURFL web service (" . htmlentities($url) . ") failed."));
                     return;
                 }
                 Piwik_MobileAnalytics::saveSetting('TeraWurflURL', $url);
                 Piwik_MobileAnalytics::saveSetting('TeraWurflMode', $mode);
                 break;
             default:
             case 'disabled':
                 Piwik_MobileAnalytics::saveSetting('TeraWurflMode', 'disabled');
                 break;
         }
         echo $response->getResponse();
     } catch (Exception $e) {
         echo $response->getResponseException($e);
     }
 }
示例#4
0
 /**
  * Formats data into a single line to be written by the writer.
  *
  * @param  array $event    event data
  * @return string  formatted line to write to the log
  */
 public function format($event)
 {
     $event = parent::formatEvent($event);
     $errstr = $event['message'];
     $outputFormat = strtolower(Piwik_Common::getRequestVar('format', 'html', 'string'));
     $response = new Piwik_API_ResponseBuilder($outputFormat);
     $message = $response->getResponseException(new Exception($errstr));
     return parent::format($message);
 }
示例#5
0
 /**
  * Formats data into a single line to be written by the writer.
  *
  * @param  array    $event    event data
  * @return string             formatted line to write to the log
  */
 public function format($event)
 {
     $event = parent::formatEvent($event);
     $errno = $event['errno'];
     $errstr = $event['message'];
     $errfile = $event['errfile'];
     $errline = $event['errline'];
     $backtrace = $event['backtrace'];
     require_once "API/ResponseBuilder.php";
     $outputFormat = strtolower(Piwik_Common::getRequestVar('format', 'html', 'string'));
     $response = new Piwik_API_ResponseBuilder(null, $outputFormat);
     $message = $response->getResponseException(new Exception($errstr));
     return parent::format($message);
 }
示例#6
0
 function setGlobalSettings()
 {
     $response = new Piwik_API_ResponseBuilder(Piwik_Common::getRequestVar('format'));
     try {
         $this->checkTokenInUrl();
         $timezone = Piwik_Common::getRequestVar('timezone', false);
         $excludedIps = Piwik_Common::getRequestVar('excludedIps', false);
         $excludedQueryParameters = Piwik_Common::getRequestVar('excludedQueryParameters', false);
         $currency = Piwik_Common::getRequestVar('currency', false);
         Piwik_SitesManager_API::getInstance()->setDefaultTimezone($timezone);
         Piwik_SitesManager_API::getInstance()->setDefaultCurrency($currency);
         Piwik_SitesManager_API::getInstance()->setGlobalExcludedQueryParameters($excludedQueryParameters);
         Piwik_SitesManager_API::getInstance()->setGlobalExcludedIps($excludedIps);
         $toReturn = $response->getResponse();
     } catch (Exception $e) {
         $toReturn = $response->getResponseException($e);
     }
     echo $toReturn;
 }
示例#7
0
	/**
	 * Handles the request to the API.
	 * It first checks that the method called (parameter 'method') is available in the module (it means that the method exists and is public)
	 * It then reads the parameters from the request string and throws an exception if there are missing parameters.
	 * It then calls the API Proxy which will call the requested method.
	 * 
	 * @return mixed The data resulting from the API call  
	 */
	public function process()
	{
		// read the format requested for the output data
		$outputFormat = strtolower(Piwik_Common::getRequestVar('format', 'xml', 'string', $this->request));
		
		// create the response
		$response = new Piwik_API_ResponseBuilder($outputFormat, $this->request);
		
		try {
			// read parameters
			$moduleMethod = Piwik_Common::getRequestVar('method', null, null, $this->request);
			
			list($module, $method) = $this->extractModuleAndMethod($moduleMethod); 
			
			if(!Piwik_PluginsManager::getInstance()->isPluginActivated($module))
			{
				throw new Piwik_FrontController_PluginDeactivatedException($module);
			}
			$module = "Piwik_" . $module . "_API";

			self::reloadAuthUsingTokenAuth($this->request);
			
			// call the method 
			$returnedValue = Piwik_API_Proxy::getInstance()->call($module, $method, $this->request);
			
			$toReturn = $response->getResponse($returnedValue);
		} catch(Exception $e ) {
			$toReturn = $response->getResponseException( $e );
		}
		return $toReturn;
	}
示例#8
0
	/**
	 * Records settings from the "User Settings" page
	 */
	public function recordUserSettings()
	{
		$response = new Piwik_API_ResponseBuilder(Piwik_Common::getRequestVar('format'));
		try {
			$this->checkTokenInUrl();
			$alias = Piwik_Common::getRequestVar('alias');
			$email = Piwik_Common::getRequestVar('email');
			$defaultReport = Piwik_Common::getRequestVar('defaultReport');
			$defaultDate = Piwik_Common::getRequestVar('defaultDate');

			$newPassword = false;
			$password = Piwik_Common::getRequestvar('password', false);
			$passwordBis = Piwik_Common::getRequestvar('passwordBis', false);
			if(!empty($password)
				|| !empty($passwordBis))
			{
				if($password != $passwordBis)
				{
					throw new Exception(Piwik_Translate('Login_PasswordsDoNotMatch'));
				}
				$newPassword = $password;
			}
			
			$userLogin = Piwik::getCurrentUserLogin();
			if(Piwik::isUserIsSuperUser())
			{
				$superUser = Zend_Registry::get('config')->superuser;
				$updatedSuperUser = false;

				if($newPassword !== false)
				{
					$newPassword = Piwik_Common::unsanitizeInputValue($newPassword);
					$md5PasswordSuperUser = md5($newPassword);
					$superUser->password = $md5PasswordSuperUser;
					$updatedSuperUser = true;
				}
	 			if($superUser->email != $email)
				{
					$superUser->email = $email;
	 				$updatedSuperUser = true;
				}
				if($updatedSuperUser)
				{
					Zend_Registry::get('config')->superuser = $superUser->toArray();
				}
			}
			else
			{
				Piwik_UsersManager_API::getInstance()->updateUser($userLogin, $newPassword, $email, $alias);
				if($newPassword !== false)
				{
					$newPassword = Piwik_Common::unsanitizeInputValue($newPassword);
				}
			}

			// logs the user in with the new password
			if($newPassword !== false)
			{
				$info = array(
					'login' => $userLogin, 
					'md5Password' => md5($newPassword),
					'rememberMe' => false,
				);
				Piwik_PostEvent('Login.initSession', $info);
			}

			Piwik_UsersManager_API::getInstance()->setUserPreference($userLogin, 
																Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT, 
																$defaultReport);
			Piwik_UsersManager_API::getInstance()->setUserPreference($userLogin, 
																Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT_DATE, 
																$defaultDate);
			$toReturn = $response->getResponse();
		} catch(Exception $e ) {
			$toReturn = $response->getResponseException( $e );
		}
		echo $toReturn;
	}
 /**
  * Must be called before dispatch()
  * - checks that directories are writable,
  * - loads the configuration file,
  * - loads the plugin, 
  * - inits the DB connection,
  * - etc.
  */
 function init()
 {
     static $initialized = false;
     if ($initialized) {
         return;
     }
     $initialized = true;
     try {
         Zend_Registry::set('timer', new Piwik_Timer());
         $directoriesToCheck = array('/tmp/', '/tmp/templates_c/', '/tmp/cache/', '/tmp/assets/', '/tmp/tcpdf/');
         Piwik::checkDirectoriesWritableOrDie($directoriesToCheck);
         Piwik_Common::assignCliParametersToRequest();
         Piwik_Translate::getInstance()->loadEnglishTranslation();
         $exceptionToThrow = false;
         try {
             Piwik::createConfigObject();
         } catch (Exception $e) {
             Piwik_PostEvent('FrontController.NoConfigurationFile', $e, $info = array(), $pending = true);
             $exceptionToThrow = $e;
         }
         if (Piwik_Session::isFileBasedSessions()) {
             Piwik_Session::start();
         }
         if (Piwik_Config::getInstance()->General['maintenance_mode'] == 1 && !Piwik_Common::isPhpCliMode()) {
             $format = Piwik_Common::getRequestVar('format', '');
             $exception = new Exception("Piwik is in scheduled maintenance. Please come back later.");
             if (empty($format)) {
                 throw $exception;
             }
             $response = new Piwik_API_ResponseBuilder($format);
             echo $response->getResponseException($exception);
             exit;
         }
         if (!Piwik_Common::isPhpCliMode() && Piwik_Config::getInstance()->General['force_ssl'] == 1 && !Piwik::isHttps()) {
             $url = Piwik_Url::getCurrentUrl();
             $url = str_replace("http://", "https://", $url);
             Piwik_Url::redirectToUrl($url);
         }
         $pluginsManager = Piwik_PluginsManager::getInstance();
         $pluginsToLoad = Piwik_Config::getInstance()->Plugins['Plugins'];
         $pluginsManager->loadPlugins($pluginsToLoad);
         if ($exceptionToThrow) {
             throw $exceptionToThrow;
         }
         try {
             Piwik::createDatabaseObject();
         } catch (Exception $e) {
             if (self::shouldRethrowException()) {
                 throw $e;
             }
             Piwik_PostEvent('FrontController.badConfigurationFile', $e, $info = array(), $pending = true);
             throw $e;
         }
         Piwik::createLogObject();
         // creating the access object, so that core/Updates/* can enforce Super User and use some APIs
         Piwik::createAccessObject();
         Piwik_PostEvent('FrontController.dispatchCoreAndPluginUpdatesScreen');
         Piwik_PluginsManager::getInstance()->installLoadedPlugins();
         Piwik::install();
         // ensure the current Piwik URL is known for later use
         if (method_exists('Piwik', 'getPiwikUrl')) {
             $host = Piwik::getPiwikUrl();
         }
         Piwik_PostEvent('FrontController.initAuthenticationObject');
         try {
             $authAdapter = Zend_Registry::get('auth');
         } catch (Exception $e) {
             throw new Exception("Authentication object cannot be found in the Registry. Maybe the Login plugin is not activated?\n\t\t\t\t\t\t\t\t\t<br />You can activate the plugin by adding:<br />\n\t\t\t\t\t\t\t\t\t<code>Plugins[] = Login</code><br />\n\t\t\t\t\t\t\t\t\tunder the <code>[Plugins]</code> section in your config/config.ini.php");
         }
         Zend_Registry::get('access')->reloadAccess($authAdapter);
         Piwik::raiseMemoryLimitIfNecessary();
         Piwik_Translate::getInstance()->reloadLanguage();
         $pluginsManager->postLoadPlugins();
         Piwik_PostEvent('FrontController.checkForUpdates');
     } catch (Exception $e) {
         if (self::shouldRethrowException()) {
             throw $e;
         }
         Piwik_ExitWithMessage($e->getMessage(), false, true);
     }
     //		Piwik::log('End FrontController->init() - Request: '. var_export($_REQUEST, true));
 }
示例#10
0
 /**
  * Handles the request to the API.
  * It first checks that the method called (parameter 'method') is available in the module (it means that the method exists and is public)
  * It then reads the parameters from the request string and throws an exception if there are missing parameters.
  * It then calls the API Proxy which will call the requested method.
  * 
  * @return mixed The data resulting from the API call  
  */
 public function process()
 {
     // read the format requested for the output data
     $outputFormat = strtolower(Piwik_Common::getRequestVar('format', 'xml', 'string', $this->request));
     // create the response
     $response = new Piwik_API_ResponseBuilder($this->request, $outputFormat);
     try {
         // read parameters
         $moduleMethod = Piwik_Common::getRequestVar('method', null, null, $this->request);
         list($module, $method) = $this->extractModuleAndMethod($moduleMethod);
         if (!Piwik_PluginsManager::getInstance()->isPluginActivated($module)) {
             throw new Piwik_FrontController_PluginDeactivatedException($module);
         }
         $module = "Piwik_" . $module . "_API";
         // if a token_auth is specified in the API request, we load the right permissions
         $token_auth = Piwik_Common::getRequestVar('token_auth', '', 'string', $this->request);
         if ($token_auth) {
             Piwik_PostEvent('API.Request.authenticate', $token_auth);
             Zend_Registry::get('access')->reloadAccess();
         }
         // call the method
         $returnedValue = Piwik_API_Proxy::getInstance()->call($module, $method, $this->request);
         $toReturn = $response->getResponse($returnedValue);
     } catch (Exception $e) {
         $toReturn = $response->getResponseException($e);
     }
     return $toReturn;
 }
示例#11
0
 protected function handleMaintenanceMode()
 {
     if (Piwik_Config::getInstance()->General['maintenance_mode'] == 1 && !Piwik_Common::isPhpCliMode()) {
         $format = Piwik_Common::getRequestVar('format', '');
         $message = "Piwik is in scheduled maintenance. Please come back later." . " The administrator can disable maintenance by editing the file piwik/config/config.ini.php and removing the following: " . " maintenance_mode=1 ";
         if (Piwik_Config::getInstance()->Tracker['record_statistics'] == 0) {
             $message .= ' and record_statistics=0';
         }
         $exception = new Exception($message);
         // extend explain how to re-enable
         // show error message when record stats = 0
         if (empty($format)) {
             throw $exception;
         }
         $response = new Piwik_API_ResponseBuilder($format);
         echo $response->getResponseException($exception);
         exit;
     }
 }