private function importDumpFile(Project $project, $xml_svn, $extraction_path) { $attrs = $xml_svn->attributes(); if (!isset($attrs['dump-file'])) { return true; } $rootpath_arg = escapeshellarg($project->getSVNRootPath()); $dumpfile_arg = escapeshellarg("{$extraction_path}/{$attrs["dump-file"]}"); $commandline = "svnadmin load {$rootpath_arg} <{$dumpfile_arg} 2>&1"; $this->logger->info($commandline); try { $cmd = new System_Command(); $command_output = $cmd->exec($commandline); foreach ($command_output as $line) { $this->logger->debug("svnadmin: {$line}"); } $this->logger->debug("svnadmin returned with status 0"); } catch (System_Command_CommandException $e) { foreach ($e->output as $line) { $this->logger->error("svnadmin: {$line}"); } $this->logger->error("svnadmin returned with status {$e->return_value}"); throw new SVNXMLImporterException("failed to svnadmin load {$dumpfile_arg} in {$rootpath_arg}:" . " exited with status {$e->return_value}"); } }
private function getGitoliteVersion() { $command = new System_Command(); $output = $command->exec("ssh gitolite@gl-adm info"); $match = array(); preg_match('/running gitolite.* (2|3)./', implode(' ', $output), $match); if (isset($match[1])) { return $match[1]; } return null; }
function mime_content_type($file) { $cmd = new System_Command(); if (!$cmd->which("file")) { unset($cmd); return false; } $cmd->pushCommand("file", "-bi '{$file}'"); $res = $cmd->execute(); unset($cmd); return $res; }
/** * @return int */ public function getDiskUsage(PFUser $user) { $size = 0; foreach (glob($this->getPath($user, '*')) as $file) { $size += (int) implode('', $this->system->exec('stat -c %s ' . escapeshellarg($file))); } return $size; }
public function createFromBundle(GitRepository $repository, GitRepositoryCreator $creator, $bundle_path) { $this->initRepository($repository, $creator); $bundle_path_arg = escapeshellarg($bundle_path); $repository_full_path_arg = escapeshellarg($repository->getFullPath()); $this->system_command->exec("sudo -u gitolite /usr/share/tuleap/plugins/git/bin/gl-clone-bundle.sh {$bundle_path_arg} {$repository_full_path_arg}"); $this->git_system_event_manager->queueRepositoryUpdate($repository); }
/** * Class Constructor */ function Image_Transform_Driver_NetPBM() { if (!defined('IMAGE_TRANSFORM_LIB_PATH')) { include_once 'System/Command.php'; $path = str_replace('pnmscale', '', escapeshellcmd(System_Command::which('pnmscale'))); define('IMAGE_TRANSFORM_LIB_PATH', $path); } return true; }
private function importRepository(Project $project, PFUser $creator, SimpleXMLElement $repository_xmlnode, $extraction_path) { $repository_info = $repository_xmlnode->attributes(); $this->logger->debug("Importing {$repository_info['name']} using {$repository_info['bundle-path']}"); $description = isset($repository_info['description']) ? (string) $repository_info['description'] : GitRepository::DEFAULT_DESCRIPTION; $repository = $this->repository_factory->buildRepository($project, $repository_info['name'], $creator, $this->gitolite_backend, $description); $absolute_bundle_path = $extraction_path . '/' . $repository_info['bundle-path']; $extraction_path_arg = escapeshellarg($extraction_path); $this->system_command->exec("chmod 755 {$extraction_path_arg}"); $this->repository_manager->createFromBundle($repository, $this->gitolite_backend, $absolute_bundle_path); $this->importPermissions($project, $repository_xmlnode->children(), $repository); $this->system_event_manager->queueProjectsConfigurationUpdate(array($project->getGroupId())); }
public function createFromBundle(GitRepository $repository, GitRepositoryCreator $creator, $bundle_path) { if (!$creator->isNameValid($repository->getName())) { throw new Exception($GLOBALS['Language']->getText('plugin_git', 'actions_input_format_error', array($creator->getAllowedCharsInNamePattern(), GitDao::REPO_NAME_MAX_LENGTH))); } $this->assertRepositoryNameNotAlreadyUsed($repository); $id = $this->dao->save($repository); $repository->setId($id); $bundle_path_arg = escapeshellarg($bundle_path); $repository_full_path_arg = escapeshellarg($repository->getFullPath()); $this->system_command->exec("sudo -u gitolite /usr/share/tuleap/plugins/git/bin/gl-clone-bundle.sh {$bundle_path_arg} {$repository_full_path_arg}"); $this->git_system_event_manager->queueRepositoryUpdate($repository); }
private function import_dumpfile(Project $project, $xml_svn, $extraction_path) { $attrs = $xml_svn->attributes(); if (!isset($attrs['dump-file'])) { return true; } $rootpath_arg = escapeshellarg($project->getSVNRootPath()); $dumpfile_arg = escapeshellarg("{$extraction_path}/{$attrs["dump-file"]}"); $commandline = "svnadmin load {$rootpath_arg} <{$dumpfile_arg} 2>&1"; $this->logger->info($commandline); try { $cmd = new System_Command(); $command_output = $cmd->exec($commandline); $return_status = 0; } catch (System_Command_CommandException $e) { $command_output = $e->output; $return_status = $e->return_value; } foreach ($command_output as $line) { $this->logger->debug($line); } $this->logger->debug("Exited with status {$return_status}"); return 0 === $return_status; }
/** * Dispatch an (un)mount command * * @param int $command SYSTEM_MOUNT_CMD_MOUNT (to mount device) or _UNMOUNT * (to unmount device) * @return return value from System_Command or PEAR_Error * @see System_Command::execute() * @access protected */ function _mount($command) { if (!$this->mayMount()) { return PEAR::raiseError("Users may not (un)mount {$this->mountPoint}"); } $cmd = new System_Command(); $cmd->pushCommand($command, $this->mountPoint); $res = $cmd->execute(); // Update mtab $this->_mtab->load(); return $res; }
function addUser2($username, $password, $additional) { include_once "System/Command.php"; // build up the admin user's Distinguished Name $adminuser = escapeshellcmd(trim($this->options["adminuser"])); $adminpass = escapeshellcmd(trim($this->options["adminpass"])); $basedn = $this->options["basedn"]; $useroc = $this->options["useroc"]; $userdn = $this->options["userdn"]; $userattr = $this->options["userattr"]; $status = ""; // flow: // make sure we have all the required variables if (empty($username) || $username == "") { $status = "User's name cannot be blank"; } elseif (empty($password) || $password == "") { $status = "User's password cannot be blank"; } elseif (!isset($additional["email"])) { $status = "User's email address cannot be blank"; } elseif (empty($this->options["adminuser"]) || $this->options["adminuser"] == "") { $status = "adminuser cannot be blank"; } elseif (empty($this->options["adminpass"]) || $this->options["adminpass"] == "") { $status = "adminpass cannot be blank"; } // if we've gotten an error message already, just exit if ($status != "") { return new PEAR_Error($status, PEAR_ERROR_RETURN); } $command = "ldapmodify"; $arguments = " -a -x -D \"" . $adminuser . "\" -w \"" . $adminpass . "\""; if (!empty($userdn)) { $userdn .= ","; } $input = "dn: " . $userattr . "=" . $username . "," . $userdn . $basedn . "\n" . $userattr . ": " . $username . "\n" . "sn: " . $username . "\n" . "userPassword: "******"\n" . "mail: " . $additional["email"] . "\n" . "objectClass: top\n" . "objectClass: " . $useroc . "\n" . "\n\n"; $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); // workout whether we have the ldapmodify command or not $cmd = new System_Command(); $command = $cmd->which($command); $cmd = null; $result = ""; // if the command wasn't found, just exit if ($command == false) { $status = "Unable to find required command 'ldapmodify'."; } else { // open the process $process = proc_open($command . $arguments, $descriptorspec, $pipes); // make sure it worked if (is_resource($process)) { // write out the creation strings fwrite($pipes[0], $input); fclose($pipes[0]); // get the input while (!feof($pipes[1])) { $result .= fgets($pipes[1], 1024); } fclose($pipes[1]); $return = proc_close($process); $pos = strstr($result, "adding new entry"); if ($return == 0 && $pos != false) { return true; } else { $status = "Arguments: {$arguments}\nResult: " . $return . "\n" . $result . "\n\nInput:\n" . $input; } } else { $status = "Failed to open command."; } } if ($this->debug != false) { mail($this->debug, "adduser", $status); } return PEAR::raiseError("Auth_Container_LDAP: " . $status, -1, PEAR_ERROR_PRINT); }
function System_Command_Error($code = SYSTEM_COMMAND_ERROR, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE, $debuginfo = null) { if (is_int($code)) { $this->PEAR_Error(System_Command::errorMessage($code), $code, $mode, $level, $debuginfo); } else { $this->PEAR_Error("Invalid error code: {$code}", SYSTEM_COMMAND_ERROR, $mode, $level, $debuginfo); } }
public function runUpdateScript(Project $project) { $system_execution = new System_Command(); $system_execution->exec($this->getCommandToExecute($project)); }
/** * @param Project $project * @throws System_Command_CommandException */ public function migrateProjectTo123(Project $project) { $system_execution = new System_Command(); $system_execution->exec($this->getCommandToExecute($project)); }
private function execute($cmd) { return $this->command->exec(self::FORGEUPGRADE_PATH . ' --config=' . escapeshellarg($this->filePath) . ' ' . escapeshellarg($cmd)); }
/** * Autodetect a file's MIME-type with 'file' and System_Command * * This function may be called staticly. * * @param string $file Path to the file to get the type of * * @return string $file's MIME-type * * @since 1.0.0beta1 * @static */ function _fileAutoDetect($file) { $cmd = new System_Command(); $magic = ''; // Make sure we have the 'file' command. $fileCmd = PEAR::getStaticProperty('MIME_Type', 'fileCmd'); if (!$cmd->which($fileCmd)) { unset($cmd); return PEAR::raiseError("Can't find file command \"{$fileCmd}\""); } if (strlen($this->magicFile)) { $magic = '--magic-file ' . escapeshellarg($this->magicFile); } $cmd->pushCommand($fileCmd, $magic, "-bi " . escapeshellarg($file)); $res = $cmd->execute(); unset($cmd); return $res; }
/** * Autodetect a file's MIME-type with 'file' and System_Command * * This function may be called staticly. * * @param string $file Path to the file to get the type of * @return string $file's MIME-type * @since 1.0.0beta1 * @static */ function _fileAutoDetect($file) { // Sanity checks if (!file_exists($file)) { return PEAR::raiseError("File \"{$file}\" doesn't exist"); } if (!is_readable($file)) { return PEAR::raiseError("File \"{$file}\" is not readable"); } $cmd = new System_Command(); // Make sure we have the 'file' command. $fileCmd = PEAR::getStaticProperty('MIME_Type', 'fileCmd'); if (!$cmd->which($fileCmd)) { unset($cmd); return PEAR::raiseError("Can't find file command \"{$fileCmd}\""); } $cmd->pushCommand($fileCmd, "-bi '{$file}'"); $res = $cmd->execute(); unset($cmd); return $res; }
/** * * Extract repository * * @param String $backup_path * @param String $restore_path * */ private function extractRepository($backup_path) { $this->logger->debug('[Gitolite][Restore] sudo gitolite restore'); $base = realpath(ForgeConfig::get('codendi_bin_prefix')); $system_command = new System_Command(); $command = "sudo -u gitolite {$base}/restore-tar-repository.php " . escapeshellarg($backup_path) . ' /'; try { $system_command->exec($command); } catch (System_Command_CommandException $exception) { $this->logger->error('[Gitolite][Restore] Unable to extract repository from backup: [' . $backup_path . '] error message : ' . $exception->getMessage()); return false; } $this->logger->info('[Gitolite][Restore] Repository extracted from backup: ' . $backup_path); return true; }