Ejemplo n.º 1
0
 protected function writeLogFile($username, $error)
 {
     $logfile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/loginerror.log";
     $data = $this->readLogFile();
     $remoteHost = Pimcore_Tool::getClientIp();
     $data[] = array(time(), $remoteHost, $username);
     $lines = array();
     foreach ($data as $item) {
         $lines[] = implode(",", $item);
     }
     // only save 2000 entries
     $maxEntries = 2000;
     if (count($lines) > $maxEntries) {
         $lines = array_splice($lines, $maxEntries * -1);
     }
     file_put_contents($logfile, implode("\n", $lines));
     chmod($logfile, 0766);
 }
Ejemplo n.º 2
0
 /**
  * Checks for a suitable redirect
  * @throws Exception
  * @param bool $override
  * @return void
  */
 protected function checkForRedirect($override = false)
 {
     try {
         $cacheKey = "system_route_redirect";
         if (empty($this->redirects) && !($this->redirects = Pimcore_Model_Cache::load($cacheKey))) {
             $list = new Redirect_List();
             $list->setOrder("DESC");
             $list->setOrderKey("priority");
             $this->redirects = $list->load();
             Pimcore_Model_Cache::save($this->redirects, $cacheKey, array("system", "redirect", "route"), null, 998);
         }
         foreach ($this->redirects as $redirect) {
             // if override is true the priority has to be 99 which means that overriding is ok
             if (!$override || $override && $redirect->getPriority() == 99) {
                 if (@preg_match($redirect->getSource(), $_SERVER["REQUEST_URI"], $matches)) {
                     array_shift($matches);
                     $target = $redirect->getTarget();
                     if (is_numeric($target)) {
                         $d = Document::getById($target);
                         if ($d instanceof Document_Page) {
                             $target = $d->getFullPath();
                         } else {
                             throw new Exception("Target of redirect no found!");
                         }
                     }
                     // replace escaped % signs so that they didn't have effects to vsprintf (PIMCORE-1215)
                     $target = str_replace("\\%", "###URLENCODE_PLACEHOLDER###", $target);
                     $url = vsprintf($target, $matches);
                     $url = str_replace("###URLENCODE_PLACEHOLDER###", "%", $url);
                     header($redirect->getHttpStatus());
                     header("Location: " . $url, true, $redirect->getStatusCode());
                     // log all redirects to the redirect log
                     Pimcore_Log_Simple::log("redirect", Pimcore_Tool::getClientIp() . " \t Source: " . $_SERVER["REQUEST_URI"] . " -> " . $url);
                     exit;
                 }
             }
         }
     } catch (Exception $e) {
         // no suitable route found
     }
 }
Ejemplo n.º 3
0
 public function getSystemAction()
 {
     if ($this->getUser()->isAllowed("system_settings")) {
         $values = Pimcore_Config::getSystemConfig();
         if (($handle = fopen(PIMCORE_PATH . "/config/timezones.csv", "r")) !== FALSE) {
             while (($rowData = fgetcsv($handle, 10000, ",", '"')) !== false) {
                 $timezones[] = $rowData[0];
             }
             fclose($handle);
         }
         $languages = Zend_Locale::getTranslationList('language');
         asort($languages);
         $languageOptions = array();
         $validLanguages = array();
         foreach ($languages as $short => $translation) {
             if (strlen($short) == 2 or strlen($short) == 5 and strpos($short, "_") == 2) {
                 $languageOptions[] = array("language" => $short, "display" => $translation . " ({$short})");
                 $validLanguages[] = $short;
             }
         }
         $valueArray = $values->toArray();
         $valueArray['general']['validLanguage'] = explode(",", $valueArray['general']['validLanguages']);
         //for "wrong" legacy values
         if (is_array($valueArray['general']['validLanguage'])) {
             foreach ($valueArray['general']['validLanguage'] as $existingValue) {
                 if (!in_array($existingValue, $validLanguages)) {
                     $languageOptions[] = array("language" => $existingValue, "display" => $existingValue);
                 }
             }
         }
         //cdn hosts - add as array
         if (!empty($valueArray['outputfilters']['cdnhostnames'])) {
             $hostNames = explode(",", $valueArray['outputfilters']['cdnhostnames']);
             if (is_array($hostNames)) {
                 foreach ($hostNames as $host) {
                     $valueArray['outputfilters']['cdnhostnamesArray'][] = array("value" => $host);
                 }
             }
         }
         //cdn patterns - add as array
         if (!empty($valueArray['outputfilters']['cdnpatterns'])) {
             $patterns = explode(",", $valueArray['outputfilters']['cdnpatterns']);
             if (is_array($patterns)) {
                 foreach ($patterns as $pattern) {
                     $valueArray['outputfilters']['cdnpatternsArray'][] = array("value" => $pattern);
                 }
             }
         }
         //debug email addresses - add as array ckogler
         if (!empty($valueArray['email']['debug']['emailaddresses'])) {
             $emailAddresses = explode(",", $valueArray['email']['debug']['emailaddresses']);
             if (is_array($emailAddresses)) {
                 foreach ($emailAddresses as $emailAddress) {
                     $valueArray['email']['debug']['emaildebugaddressesArray'][] = array("value" => $emailAddress);
                 }
             }
         } else {
             $valueArray['email']['debug']['emaildebugaddressesArray'][] = array("value" => '');
         }
         //cache exclude patterns - add as array
         if (!empty($valueArray['cache']['excludePatterns'])) {
             $patterns = explode(",", $valueArray['cache']['excludePatterns']);
             if (is_array($patterns)) {
                 foreach ($patterns as $pattern) {
                     $valueArray['cache']['excludePatternsArray'][] = array("value" => $pattern);
                 }
             }
         }
         //remove password from values sent to frontend
         $valueArray['database']["params"]['password'] = "******";
         //admin users as array
         $adminUsers = array();
         $userList = new User_List();
         $userList->setCondition("admin = 1 and email is not null and email != ''");
         $users = $userList->load();
         if (is_array($users)) {
             foreach ($users as $user) {
                 $adminUsers[] = array("id" => $user->getId(), "username" => $user->getUsername());
             }
         }
         $adminUsers[] = array("id" => "", "username" => "-");
         $response = array("values" => $valueArray, "adminUsers" => $adminUsers, "config" => array("timezones" => $timezones, "languages" => $languageOptions, "client_ip" => Pimcore_Tool::getClientIp()));
         $this->_helper->json($response);
     } else {
         if ($this->getUser() != null) {
             Logger::err("user [" . $this->getUser()->getId() . "] attempted to view system settings, but has no permission to do so.");
         } else {
             Logger::err("attempt to view system settings, but no user in session.");
         }
     }
     $this->_helper->json(false);
 }
Ejemplo n.º 4
0
 /**
  * @static
  * @return bool
  */
 public static function inDebugMode()
 {
     if (defined("PIMCORE_DEBUG")) {
         return PIMCORE_DEBUG;
     }
     $conf = Pimcore_Config::getSystemConfig();
     $debug = (bool) $conf->general->debug;
     // enable debug mode only for one IP
     if ($conf->general->debug_ip && $conf->general->debug) {
         $debug = false;
         if (Pimcore_Tool::getClientIp() == trim($conf->general->debug_ip)) {
             $debug = true;
         }
     }
     return $debug;
 }