@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 132 lines 2.8 kB view raw
1<?php 2 3final class DarkConsoleRequestPlugin extends DarkConsolePlugin { 4 5 public function getName() { 6 return pht('Request'); 7 } 8 9 public function getDescription() { 10 return pht( 11 'Information about %s and %s.', 12 '$_REQUEST', 13 '$_SERVER'); 14 } 15 16 public function generateData() { 17 $addr = idx($_SERVER, 'SERVER_ADDR'); 18 if ($addr) { 19 $hostname = @gethostbyaddr($addr); 20 } else { 21 $hostname = null; 22 } 23 24 $controller = $this->getRequest()->getController(); 25 if ($controller) { 26 $controller_class = get_class($controller); 27 } else { 28 $controller_class = null; 29 } 30 31 $site = $this->getRequest()->getSite(); 32 if ($site) { 33 $site_class = get_class($site); 34 } else { 35 $site_class = null; 36 } 37 38 return array( 39 'request' => $_REQUEST, 40 'server' => $_SERVER, 41 'special' => array( 42 'site' => $site_class, 43 'controller' => $controller_class, 44 'machine' => php_uname('n'), 45 'host' => $addr, 46 'hostname' => $hostname, 47 ), 48 ); 49 } 50 51 public function renderPanel() { 52 $data = $this->getData(); 53 54 $special_map = array( 55 'site' => pht('Site'), 56 'controller' => pht('Controller'), 57 'machine' => pht('Machine'), 58 'host' => pht('Host'), 59 'hostname' => pht('Hostname'), 60 ); 61 62 $special = idx($data, 'special', array()); 63 64 $rows = array(); 65 foreach ($special_map as $key => $label) { 66 $rows[] = array( 67 $label, 68 idx($special, $key), 69 ); 70 } 71 72 $sections = array(); 73 $sections[] = array( 74 'name' => pht('Basics'), 75 'rows' => $rows, 76 ); 77 78 $mask = array( 79 'HTTP_COOKIE' => true, 80 'HTTP_X_PHABRICATOR_CSRF' => true, 81 ); 82 83 $maps = array( 84 array( 85 'name' => pht('Request'), 86 'data' => idx($data, 'request', array()), 87 ), 88 array( 89 'name' => pht('Server'), 90 'data' => idx($data, 'server', array()), 91 ), 92 ); 93 94 foreach ($maps as $map) { 95 $data = $map['data']; 96 $rows = array(); 97 foreach ($data as $key => $value) { 98 if (isset($mask[$key])) { 99 $value = phutil_tag('em', array(), pht('(Masked)')); 100 } else if (is_array($value)) { 101 $value = @json_encode($value); 102 } 103 104 $rows[] = array( 105 $key, 106 $value, 107 ); 108 } 109 110 $sections[] = array( 111 'name' => $map['name'], 112 'rows' => $rows, 113 ); 114 } 115 116 $out = array(); 117 foreach ($sections as $section) { 118 $out[] = id(new AphrontTableView($section['rows'])) 119 ->setHeaders( 120 array( 121 $section['name'], 122 null, 123 )) 124 ->setColumnClasses( 125 array( 126 'header', 127 'wide wrap', 128 )); 129 } 130 return $out; 131 } 132}