ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilPlainTextHandler.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2015 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
16 
18 {
19  const KEY_SPACE = 25;
20 
26  public function handle()
27  {
28  header("Content-Type: text/plain");
29  echo "<pre>\n";
30  echo $this->content();
31  echo "</pre>\n";
32  }
33 
39  protected function content()
40  {
41  return $this->pageHeader()
42  . $this->exceptionContent()
43  . $this->tablesContent()
44  ;
45  }
46 
52  protected function pageHeader()
53  {
54  return "";
55  }
56 
62  protected function exceptionContent()
63  {
64  return Formatter::formatExceptionPlain($this->getInspector());
65  }
66 
72  protected function tablesContent()
73  {
74  $ret = "";
75  foreach ($this->tables() as $title => $content) {
76  $ret .= "\n\n-- $title --\n\n";
77  if (count($content) > 0) {
78  foreach ($content as $key => $value) {
79  $key = str_pad($key, self::KEY_SPACE);
80 
81  // indent multiline values, first print_r, split in lines,
82  // indent all but first line, then implode again.
83  $first = true;
84  $indentation = str_pad("", self::KEY_SPACE);
85  $value = implode("\n", array_map(function ($line) use (&$first, $indentation) {
86  if ($first) {
87  $first = false;
88  return $line;
89  }
90  return $indentation . $line;
91  }, explode("\n", print_r($value, true))));
92 
93  $ret .= "$key: $value\n";
94  }
95  } else {
96  $ret .= "empty\n";
97  }
98  }
99  return $ret;
100  }
101 
107  protected function tables()
108  {
109  $post = $_POST;
110  $server = $_SERVER;
111 
112  $post = $this->hidePassword($post);
113  $server = $this->hidePassword($server);
115 
116  return array( "GET Data" => $_GET
117  , "POST Data" => $post
118  , "Files" => $_FILES
119  , "Cookies" => $_COOKIE
120  , "Session" => isset($_SESSION) ? $_SESSION : array()
121  , "Server/Request Data" => $server
122  , "Environment Variables" => $_ENV
123  );
124  }
125 
132  private function hidePassword(array $superGlobal) : array
133  {
134  if (isset($superGlobal["password"])) {
135  $superGlobal["password"] = "REMOVED FOR SECURITY";
136  }
137 
138  if (isset($superGlobal["post_vars"]) && isset($superGlobal["post_vars"]["password"])) {
139  $superGlobal["post_vars"]["password"] = "REMOVED FOR SECURITY";
140  }
141 
142  return $superGlobal;
143  }
144 
152  private function shortenPHPSessionId(array $server)
153  {
154  $cookie_content = $server["HTTP_COOKIE"];
155  $cookie_content = explode(";", $cookie_content);
156 
157  foreach ($cookie_content as $key => $content) {
158  $content_array = explode("=", $content);
159  if (trim($content_array[0]) == session_name()) {
160  $content_array[1] = substr($content_array[1], 0, 5) . " (SHORTENED FOR SECURITY)";
161  $cookie_content[$key] = implode("=", $content_array);
162  }
163  }
164 
165  $server["HTTP_COOKIE"] = implode(";", $cookie_content);
166 
167  return $server;
168  }
169 }
$_COOKIE['client_id']
Definition: server.php:9
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$_SESSION["AccountId"]
handle()
Last missing method from HandlerInterface.
$_GET["client_id"]
tablesContent()
Get the header for the page.
shortenPHPSessionId(array $server)
Shorts the php session id.
hidePassword(array $superGlobal)
Replace password from super global array with security message.
$server
Definition: sabredav.php:48
exceptionContent()
Get a short info about the exception.
$post
Definition: post.php:34
tables()
Get the tables that should be rendered.
pageHeader()
Get the header for the page.
Abstract implementation of a Handler.
Definition: Handler.php:15
$ret
Definition: parser.php:6
content()
Assemble the output for this handler.
$key
Definition: croninfo.php:18
$_POST["username"]