예제 #1
0
 /**
  * Writes the config file
  *
  * Saves the config to the config file.
  *
  * @throws HintException If the config file cannot be written to
  * @throws \Exception If no file lock can be acquired
  */
 private function writeData()
 {
     // Create a php file ...
     $content = "<?php\n";
     $content .= '$CONFIG = ';
     $content .= var_export($this->cache, true);
     $content .= ";\n";
     touch($this->configFilePath);
     $filePointer = fopen($this->configFilePath, 'r+');
     // Prevent others not to read the config
     chmod($this->configFilePath, 0640);
     // File does not exist, this can happen when doing a fresh install
     if (!is_resource($filePointer)) {
         $url = \OC_Helper::linkToDocs('admin-dir_permissions');
         throw new HintException("Can't write into config directory!", 'This can usually be fixed by ' . '<a href="' . $url . '" target="_blank">giving the webserver write access to the config directory</a>.');
     }
     // Try to acquire a file lock
     if (!flock($filePointer, LOCK_EX)) {
         throw new \Exception(sprintf('Could not acquire an exclusive lock on the config file %s', $this->configFilePath));
     }
     // Write the config and release the lock
     ftruncate($filePointer, 0);
     fwrite($filePointer, $content);
     fflush($filePointer);
     flock($filePointer, LOCK_UN);
     fclose($filePointer);
     // Try invalidating the opcache just for the file we wrote...
     if (!\OC_Util::deleteFromOpcodeCache($this->configFilePath)) {
         // But if that doesn't work, clear the whole cache.
         \OC_Util::clearOpcodeCache();
     }
 }
예제 #2
0
 /**
  * @brief Writes the config file
  *
  * Saves the config to the config file.
  *
  */
 private function writeData()
 {
     // Create a php file ...
     $content = "<?php\n";
     if ($this->debugMode) {
         $content .= "define('DEBUG',true);\n";
     }
     $content .= '$CONFIG = ';
     $content .= var_export($this->cache, true);
     $content .= ";\n";
     // Write the file
     $result = @file_put_contents($this->configFilename, $content);
     if (!$result) {
         $defaults = new \OC_Defaults();
         $url = \OC_Helper::linkToDocs('admin-dir-permissions');
         throw new HintException("Can't write into config directory!", 'This can usually be fixed by ' . '<a href="' . $url . '" target="_blank">giving the webserver write access to the config directory</a>.');
     }
     // Prevent others not to read the config
     @chmod($this->configFilename, 0640);
     \OC_Util::clearOpcodeCache();
 }
예제 #3
0
 /**
  * Writes the config file
  *
  * Saves the config to the config file.
  *
  * @throws HintException If the config file cannot be written to
  * @throws \Exception If no file lock can be acquired
  */
 private function writeData()
 {
     // Create a php file ...
     $content = "<?php\n";
     $content .= '$CONFIG = ';
     $content .= var_export($this->cache, true);
     $content .= ";\n";
     touch($this->configFilePath);
     $filePointer = fopen($this->configFilePath, 'r+');
     // Prevent others not to read the config
     chmod($this->configFilePath, 0640);
     // File does not exist, this can happen when doing a fresh install
     if (!is_resource($filePointer)) {
         // TODO fix this via DI once it is very clear that this doesn't cause side effects due to initialization order
         // currently this breaks app routes but also could have other side effects especially during setup and exception handling
         $url = \OC::$server->getURLGenerator()->linkToDocs('admin-dir_permissions');
         throw new HintException("Can't write into config directory!", 'This can usually be fixed by ' . '<a href="' . $url . '" target="_blank" rel="noreferrer">giving the webserver write access to the config directory</a>.');
     }
     // Try to acquire a file lock
     if (!flock($filePointer, LOCK_EX)) {
         throw new \Exception(sprintf('Could not acquire an exclusive lock on the config file %s', $this->configFilePath));
     }
     // Write the config and release the lock
     ftruncate($filePointer, 0);
     fwrite($filePointer, $content);
     fflush($filePointer);
     flock($filePointer, LOCK_UN);
     fclose($filePointer);
     // Try invalidating the opcache just for the file we wrote...
     if (!\OC_Util::deleteFromOpcodeCache($this->configFilePath)) {
         // But if that doesn't work, clear the whole cache.
         \OC_Util::clearOpcodeCache();
     }
 }
예제 #4
0
 /**
  * @brief Writes the config file
  * @return bool
  *
  * Saves the config to the config file.
  *
  */
 public static function writeData()
 {
     // Create a php file ...
     $defaults = new OC_Defaults();
     $content = "<?php\n\$CONFIG = ";
     $content .= var_export(self::$cache, true);
     $content .= ";\n";
     $filename = OC::$SERVERROOT . "/config/config.php";
     // Write the file
     $result = @file_put_contents($filename, $content);
     if (!$result) {
         $tmpl = new OC_Template('', 'error', 'guest');
         $tmpl->assign('errors', array(1 => array('error' => "Can't write into config directory 'config'", 'hint' => 'This can usually be fixed by ' . '<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html#set-the-directory-permissions" target="_blank">giving the webserver write access to the config directory</a>.')));
         $tmpl->printPage();
         exit;
     }
     // Prevent others not to read the config
     @chmod($filename, 0640);
     OC_Util::clearOpcodeCache();
     return true;
 }