private function summarize($string)
 {
     if (!strlen($string)) {
         return '(empty)';
     }
     $limit = 1000;
     $len = strlen($string);
     if ($len > $limit) {
         $cut = $len - $limit;
         $suffix = pht('... (%s more byte(s)) ...', new PhutilNumber($cut));
         if ($cut > strlen($suffix)) {
             $string = substr($string, 0, $limit) . $suffix;
         }
     }
     // Strip out any credentials for the purpose of building a human readable
     // summary of the exception, since these are rarely-if-ever useful when
     // debugging, but can expose otherwise sensitive information.
     $string = phutil_censor_credentials($string);
     return $string;
 }
Ejemplo n.º 2
0
 public function testCensorCredentials()
 {
     $cases = array('' => '', 'abc' => 'abc', 'http://example.com' => 'http://xxxxx', 'http://example.com/' => 'http://example.com/', 'http://username@example.com' => 'http://xxxxx@example.com', 'http://*****:*****@example.com' => 'http://xxxxx@example.com', 'http://user' => 'http://xxxxx', "http://user\n" => "http://xxxxx\n", 'svn+ssh://user:pass@example.com' => 'svn+ssh://xxxxx@example.com');
     foreach ($cases as $input => $expect) {
         $this->assertEqual($expect, phutil_censor_credentials($input), pht('Credential censoring for: %s', $input));
     }
 }
Ejemplo n.º 3
0
 public static function echoListener($type, $id, $data)
 {
     $is_begin = false;
     $is_end = false;
     switch ($type) {
         case 'begin':
             $is_begin = true;
             $mark = '>>>';
             break;
         case 'end':
             $is_end = true;
             $mark = '<<<';
             break;
         default:
             $mark = null;
             break;
     }
     $type = idx($data, 'type', 'mystery');
     $desc = null;
     if ($is_begin) {
         switch ($type) {
             case 'connect':
                 $desc = $data['database'];
                 break;
             case 'query':
                 $desc = substr($data['query'], 0, 512);
                 break;
             case 'multi-query':
                 $desc = array();
                 foreach ($data['queries'] as $query) {
                     $desc[] = substr($query, 0, 256);
                 }
                 $desc = implode('; ', $desc);
                 break;
             case 'exec':
                 $desc = '$ ' . $data['command'];
                 break;
             case 'conduit':
                 if (isset($data['size'])) {
                     $desc = $data['method'] . '() ' . pht('<bytes = %d>', $data['size']);
                 } else {
                     $desc = $data['method'] . '()';
                 }
                 break;
             case 'http':
                 $desc = phutil_censor_credentials($data['uri']);
                 break;
             case 'lint':
                 $desc = $data['linter'];
                 if (isset($data['paths'])) {
                     $desc .= ' ' . pht('<paths = %d>', count($data['paths']));
                 }
                 break;
             case 'lock':
                 $desc = $data['name'];
                 break;
             case 'event':
                 $desc = $data['kind'] . ' ' . pht('<listeners = %d>', $data['count']);
                 break;
             case 'ldap':
                 $call = idx($data, 'call', '?');
                 $params = array();
                 switch ($call) {
                     case 'connect':
                         $params[] = $data['host'] . ':' . $data['port'];
                         break;
                     case 'start-tls':
                         break;
                     case 'bind':
                         $params[] = $data['user'];
                         break;
                     case 'search':
                         $params[] = $data['dn'];
                         $params[] = $data['query'];
                         break;
                     default:
                         $params[] = '?';
                         break;
                 }
                 $desc = "{$call} (" . implode(', ', $params) . ")";
                 break;
         }
     } else {
         if ($is_end) {
             $desc = pht('%s us', new PhutilNumber((int) (1000000 * $data['duration'])));
         }
     }
     $console = PhutilConsole::getConsole();
     $console->writeLog("%s [%s] <%s> %s\n", $mark, $id, $type, $desc);
 }
 private function renderVCSErrorTable(array $vcs_error)
 {
     $rows = array();
     $rows[] = array(pht('Command'), phutil_censor_credentials($vcs_error['command']));
     $rows[] = array(pht('Error'), $vcs_error['err']);
     $rows[] = array(pht('Stdout'), phutil_censor_credentials($vcs_error['stdout']));
     $rows[] = array(pht('Stderr'), phutil_censor_credentials($vcs_error['stderr']));
     $table = id(new AphrontTableView($rows))->setColumnClasses(array('header', 'wide prewrap'));
     return $table;
 }