Пример #1
0
 /**
  * Change directory owners.
  *
  * @param Domain $domain
  *
  * @return bool
  */
 protected function _changeDirectoryOwner(Domain $domain)
 {
     $fs = new Filesystem();
     try {
         $fs->chown($domain->getPath(), self::_root);
         // Domain Root
         $fs->chgrp($domain->getPath(), $domain->getUser()->getGroupname(), true);
         // Domain Root + Child
         // Child directories
         $fs->chown($this->_getDefaultDirs($domain->getPath()), $domain->getUser()->getName(), true);
     } catch (IOException $e) {
         return false;
     }
     return true;
 }
Пример #2
0
 /**
  * @expectedException \Symfony\Component\Filesystem\Exception\IOException
  */
 public function testChownFail()
 {
     $this->markAsSkippedIfPosixIsMissing();
     $dir = $this->workspace . DIRECTORY_SEPARATOR . 'dir';
     mkdir($dir);
     $this->filesystem->chown($dir, 'user' . time() . mt_rand(1000, 9999));
 }
Пример #3
0
 public static function checkDirectory($path)
 {
     $fs = new Filesystem();
     if ($fs->exists($path) && !is_writeable($path)) {
         $fs->chown($path, 0700);
     } else {
         $fs->mkdir($path, 0700);
     }
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function chown($paths, string $user, bool $recursive = false)
 {
     try {
         $this->filesystem->chown($paths, $user, $recursive);
     } catch (IOException $exception) {
         throw new FilesystemException($exception->getMessage(), $exception->getPath(), $exception);
     } catch (Exception $exception) {
         throw new FilesystemException($exception->getMessage(), null, $exception);
     }
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function chown($files, $user, $recursive = false)
 {
     try {
         $this->symfony_filesystem->chown($files, $user, $recursive);
     } catch (\Symfony\Component\Filesystem\Exception\IOException $e) {
         // Try to recover filename
         // By the time this is written that is at the end of the message
         $error = trim($e->getMessage());
         $file = substr($error, strrpos($error, ' '));
         throw new filesystem_exception('CANNOT_CHANGE_FILE_GROUP', $file, array(), $e);
     }
 }
Пример #6
0
 /**
  * Lighttpd writes logs as www-data, so we have to change the owner of the logs directory.
  *
  * @param Domain $domain
  *
  * @return bool
  */
 protected function _changeDirectoryOwner(Domain $domain)
 {
     $result = parent::_changeDirectoryOwner($domain);
     $fs = new Filesystem();
     if ($fs->exists($domain->getPath() . '/logs')) {
         try {
             $fs->chown($domain->getPath() . '/logs', self::_http_user, true);
         } catch (IOException $e) {
             return false;
         }
     }
     return $result;
 }
 /**
  * @return void
  */
 public static function prepareUploadsFolder($uploadsDirectory)
 {
     if (!$uploadsDirectory) {
         return false;
     }
     $fs = new Filesystem();
     $uploadsDirectory = 'web/assets/uploads';
     if (!$fs->exists($uploadsDirectory)) {
         $fs->mkdir($uploadsDirectory, 0777);
     }
     $user = PHP_OS == 'Darwin' ? get_current_user() : 'www-data';
     try {
         $fs->chown($uploadsDirectory, $user);
         $fs->chmod($uploadsDirectory, 0777);
     } catch (\Exception $e) {
         // Not sure If we need to show this errors. Let's think about that...
     }
 }
Пример #8
0
 /**
  * Check environment variables and applies modifications
  * @deprecated
  */
 private function checkEnvironmentConfiguration()
 {
     $fs = new Filesystem();
     // Creating backup folder if not exists
     if (!$fs->exists($this->configFileBkpFolder)) {
         $fs->mkdir($this->configFileBkpFolder, 0755);
         $fs->chown($this->configFileBkpFolder, 'jenkins');
         $fs->chgrp($this->configFileBkpFolder, 'jenkins');
     }
     // Creating user configuration template if not exists
     if (!$fs->exists($this->userConfigFileTemplate)) {
         $xmlString = '<user><fullName>FULLNAME</fullName><properties><hudson.model.PaneStatusProperties><collapsed/></hudson.model.PaneStatusProperties><jenkins.security.ApiTokenProperty><apiToken></apiToken></jenkins.security.ApiTokenProperty><com.cloudbees.plugins.credentials.UserCredentialsProvider_-UserCredentialsProperty plugin="credentials@1.24"><domainCredentialsMap class="hudson.util.CopyOnWriteMap$Hash"/></com.cloudbees.plugins.credentials.UserCredentialsProvider_-UserCredentialsProperty><hudson.model.MyViewsProperty><views><hudson.model.AllView><owner class="hudson.model.MyViewsProperty" reference="../../.."/><name>All</name><filterExecutors>false</filterExecutors><filterQueue>false</filterQueue><properties class="hudson.model.View$PropertyList"/></hudson.model.AllView></views></hudson.model.MyViewsProperty><hudson.search.UserSearchProperty><insensitiveSearch>false</insensitiveSearch></hudson.search.UserSearchProperty><hudson.tasks.Mailer_-UserProperty plugin="mailer@1.15"><emailAddress>EMAIL</emailAddress></hudson.tasks.Mailer_-UserProperty><jenkins.security.LastGrantedAuthoritiesProperty><roles><string></string></roles><timestamp></timestamp></jenkins.security.LastGrantedAuthoritiesProperty></properties></user>';
         $xml = new \SimpleXMLElement($xmlString);
         $dom = dom_import_simplexml($xml)->ownerDocument;
         $dom->formatOutput = true;
         $fileToWrite = fopen($this->userConfigFileTemplate, "w");
         fwrite($fileToWrite, $dom->saveXML());
         fclose($fileToWrite);
         $fs->chmod($this->userConfigFileTemplate, 0644);
         $fs->chown($this->userConfigFileTemplate, 'jenkins');
         $fs->chgrp($this->userConfigFileTemplate, 'jenkins');
     }
 }
 /**
  * @param OutputInterface $output
  * @param array $files
  * @param $permission
  * @param $user
  * @param $group
  * @param bool $listFiles
  * @return int
  */
 public function setPermissions(\Symfony\Component\Console\Output\OutputInterface $output, $files, $permission, $user, $group, $listFiles = true)
 {
     $dryRun = $this->getConfigurationHelper()->getDryRun();
     if (empty($files)) {
         $output->writeln('<comment>No files found.</comment>');
         return 0;
     }
     $fs = new Filesystem();
     try {
         if ($dryRun) {
             $output->writeln("<comment>Modifying files permission to: " . decoct($permission) . "</comment>");
             $output->writeln("<comment>user: "******"</comment>");
             $output->writeln("<comment>group: " . $group . "</comment>");
             if ($listFiles) {
                 $output->writeln("<comment>Files: </comment>");
                 foreach ($files as $file) {
                     $output->writeln($file->getPathName());
                 }
             }
         } else {
             if (!empty($permission)) {
                 $output->writeln("<comment>Modifying files permission to: " . decoct($permission) . "</comment>");
             }
             if (!empty($user)) {
                 $output->writeln("<comment>Modifying file user: "******"</comment>");
             }
             if (!empty($group)) {
                 $output->writeln("<comment>Modifying file group: " . $group . "</comment>");
             }
             if ($listFiles) {
                 $output->writeln("<comment>Files: </comment>");
                 foreach ($files as $file) {
                     $output->writeln($file->getPathName());
                 }
             } else {
                 $output->writeln("<comment>Skipping file list (too long)... </comment>");
             }
             if (!empty($permission)) {
                 $fs->chmod($files, $permission, 00, true);
             }
             if (!empty($user)) {
                 $fs->chown($files, $user, true);
             }
             if (!empty($group)) {
                 $fs->chgrp($files, $group, true);
             }
         }
     } catch (IOException $e) {
         echo "\n An error occurred while removing the directory: " . $e->getMessage() . "\n ";
     }
 }
Пример #10
0
 public function uploadProfileImagePost($image, $entity)
 {
     $extension = pathinfo($image->getClientOriginalName(), PATHINFO_EXTENSION);
     $name = sha1(uniqid(mt_rand(), true));
     $imageName = $name . '.' . $extension;
     if ($image->move($this->getAbsolutePathProfile($entity->getId()), $imageName)) {
         $absPathImage = $this->getAbsolutePathProfile($entity->getId()) . $imageName;
         $thumPath = $this->getWebPath() . $this->parameters['upload_directory'] . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'profile' . DIRECTORY_SEPARATOR . $entity->getId() . DIRECTORY_SEPARATOR . 'thumbnail';
         if (!is_dir($thumPath)) {
             $fs = new Filesystem();
             $fs->mkdir($thumPath, 0777);
             $fs->chown($thumPath, 'www-data', true);
             $fs->chgrp($thumPath, 'www-data', true);
             $fs->chmod($thumPath, 0777, 00, true);
         }
         $this->resizeImage($absPathImage, $name . '_260', 260, 123, $this->getAbsolutePathProfile($entity->getId()));
         $this->resizeImage($absPathImage, $name . '_142', 142, 88, $this->getAbsolutePathProfile($entity->getId()));
         return $imageName;
     } else {
         return null;
     }
 }
Пример #11
0
 /**
  * Create User
  * @param User $user
  * @return mixed
  * @deprecated
  */
 public function createUser(User $user)
 {
     // Fast Return in case of server stopped
     if (!$this->isServerAvailable()) {
         return null;
     }
     // Initialize values
     $userPathFolder = $this->userBasePath . $user->getUsername();
     $fs = new Filesystem();
     // Create user dir
     try {
         $fs->mkdir($userPathFolder, 0755);
         $fs->chown($userPathFolder, 'jenkins');
         $fs->chgrp($userPathFolder, 'jenkins');
     } catch (IOExceptionInterface $e) {
         //            dump("An error occurred while creating your directory at " . $e->getPath());
     }
     // Updating return values
     $retval['userPath'] = $userPathFolder;
     $retval['userPathCreated'] = $fs->exists($userPathFolder);
     // Creating config file
     $userConfigFile = $userPathFolder . "/config.xml";
     if ($fs->exists($this->userConfigFileTemplate) && $fs->exists($userPathFolder)) {
         // Opening config template
         $xmlTemplate = simplexml_load_file($this->userConfigFileTemplate);
         // Overriding some values
         $xmlTemplate->fullName = $user->getCommonName();
         $xmlTemplate->properties->{'hudson.tasks.Mailer_-UserProperty'}->emailAddress = $user->getEmail();
         // Writing new file in user space
         $dom = dom_import_simplexml($xmlTemplate)->ownerDocument;
         $dom->formatOutput = true;
         $fileToWrite = fopen($userConfigFile, "w");
         fwrite($fileToWrite, $dom->saveXML());
         fclose($fileToWrite);
         $fs->chmod($userConfigFile, 0644);
         $fs->chown($userConfigFile, 'jenkins');
         $fs->chgrp($userConfigFile, 'jenkins');
         // Updating return values
         $retval['templateExists'] = true;
         $retval['userConfFile'] = $fs->exists($userConfigFile);
     } else {
         $retval['userConfFile'] = false;
         $retval['templateExists'] = false;
     }
     // Updating Jenkins global rights
     if (file_exists($this->configFile)) {
         // Config file backup
         $retval['confFileBackuped'] = $this->backupConfigFile();
         // Opening config file
         $xmlFile = simplexml_load_file($this->configFile);
         // Overriding some values
         $authorizations = $xmlFile->authorizationStrategy;
         $authorizations->addChild("permission", "hudson.model.Hudson.Read:" . $user->getUsername());
         // Overriding config file
         $dom = dom_import_simplexml($xmlFile)->ownerDocument;
         $dom->formatOutput = true;
         $fileToWrite = fopen($this->configFile, "w");
         fwrite($fileToWrite, $dom->saveXML());
         fclose($fileToWrite);
         // Updating return values
         $retval['confFileUpdated'] = $fs->exists($this->configFile);
     } else {
         $retval['confFileBackuped'] = false;
         $retval['confFileUpdated'] = false;
     }
     // Restarting jenkins
     $retval['hostRestarted'] = $this->reloadHost();
     // Return values
     if ($retval['userPathCreated'] && $retval['confFileUpdated'] && $retval['userConfFile']) {
         return true;
     } else {
         return false;
     }
     //        return $retval;
 }
Пример #12
0
 /**
  * @param string|string[]|\Traversable $file
  * @param string $user
  * @param bool $recursive
  */
 protected function _chown($file, $user, $recursive = null)
 {
     $this->fs->chown($file, $user, $recursive);
 }