Example #1
0
 public function stream(Git_HTTP_Command $command)
 {
     $cwd = '/tmp';
     $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"));
     if (ForgeConfig::get('sys_logger_level') == Logger::DEBUG) {
         $descriptorspec[2] = array('file', ForgeConfig::get('codendi_log') . '/git_http_error_log', 'a');
     }
     $pipes = array();
     $this->logger->debug('Command: ' . $command->getCommand());
     $this->logger->debug('Environment: ' . print_r($command->getEnvironment(), true));
     $process = proc_open($command->getCommand(), $descriptorspec, $pipes, $cwd, $command->getEnvironment());
     if (is_resource($process)) {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             fwrite($pipes[0], file_get_contents('php://input'));
         }
         fclose($pipes[0]);
         $first = true;
         while ($result = stream_get_contents($pipes[1], self::CHUNK_LENGTH)) {
             if ($first) {
                 list($headers, $body) = http_split_header_body($result);
                 foreach (explode("\r\n", $headers) as $header) {
                     header($header);
                 }
                 file_put_contents('php://output', $body);
             } else {
                 file_put_contents('php://output', $result);
             }
             $first = false;
         }
         fclose($pipes[1]);
         $return_value = proc_close($process);
     }
 }
 public function __construct(PFUser $user, Git_HTTP_Command $command)
 {
     parent::__construct();
     $gitolite_user_info = posix_getpwnam('gitolite');
     $this->gitolite_home = $gitolite_user_info['dir'];
     $this->env['SHELL'] = '/bin/sh';
     $this->env['REMOTE_USER'] = $user->getUnixName();
     $this->env['GIT_HTTP_BACKEND'] = $command->getCommand();
     $this->env['HOME'] = $this->gitolite_home;
     $this->env['REMOTE_ADDR'] = HTTPRequest::getIPAddress();
     $this->appendToEnv('REQUEST_URI');
     $this->appendToEnv('REMOTE_PORT');
     $this->appendToEnv('SERVER_ADDR');
     $this->appendToEnv('SERVER_PORT');
 }