ILIAS  release_7 Revision v7.30-3-g800a261c036
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
14use Whoops\Handler\Handler;
15use Whoops\Exception\Formatter;
16
17class ilPlainTextHandler extends Handler
18{
19 const KEY_SPACE = 25;
20
22 private $exclusion_list = [];
23
27 public function withExclusionList(array $exclusion_list) : self
28 {
29 $clone = clone $this;
30 $clone->exclusion_list = $exclusion_list;
31 return $clone;
32 }
33
39 public function handle()
40 {
41 header("Content-Type: text/plain");
42 echo "<pre>\n";
43 echo $this->content();
44 echo "</pre>\n";
45 }
46
52 protected function content()
53 {
54 return $this->pageHeader()
55 . $this->exceptionContent()
56 . $this->tablesContent()
57 ;
58 }
59
65 protected function pageHeader()
66 {
67 return "";
68 }
69
75 protected function exceptionContent()
76 {
77 return Formatter::formatExceptionPlain($this->getInspector());
78 }
79
85 protected function tablesContent()
86 {
87 $ret = "";
88 foreach ($this->tables() as $title => $content) {
89 $ret .= "\n\n-- $title --\n\n";
90 if (count($content) > 0) {
91 foreach ($content as $key => $value) {
92 $key = str_pad($key, self::KEY_SPACE);
93
94 // indent multiline values, first print_r, split in lines,
95 // indent all but first line, then implode again.
96 $first = true;
97 $indentation = str_pad("", self::KEY_SPACE);
98 $value = implode("\n", array_map(function ($line) use (&$first, $indentation) {
99 if ($first) {
100 $first = false;
101 return $line;
102 }
103 return $indentation . $line;
104 }, explode("\n", print_r($value, true))));
105
106 $ret .= "$key: $value\n";
107 }
108 } else {
109 $ret .= "empty\n";
110 }
111 }
112 return $ret;
113 }
114
120 protected function tables()
121 {
122 $post = $_POST;
124
125 $post = $this->hideSensitiveData($post);
128
129 return array( "GET Data" => $_GET
130 , "POST Data" => $post
131 , "Files" => $_FILES
132 , "Cookies" => $_COOKIE
133 , "Session" => isset($_SESSION) ? $_SESSION : array()
134 , "Server/Request Data" => $server
135 , "Environment Variables" => $_ENV
136 );
137 }
138
143 private function hideSensitiveData(array $super_global) : array
144 {
145 foreach ($this->exclusion_list as $parameter) {
146 if (isset($super_global[$parameter])) {
147 $super_global[$parameter] = 'REMOVED FOR SECURITY';
148 }
149
150 if (isset($super_global['post_vars'][$parameter])) {
151 $super_global['post_vars'][$parameter] = 'REMOVED FOR SECURITY';
152 }
153 }
154
155 return $super_global;
156 }
157
165 private function shortenPHPSessionId(array $server)
166 {
167 $cookie_content = $server["HTTP_COOKIE"];
168 $cookie_content = explode(";", $cookie_content);
169
170 foreach ($cookie_content as $key => $content) {
171 $content_array = explode("=", $content);
172 if (trim($content_array[0]) == session_name()) {
173 $content_array[1] = substr($content_array[1], 0, 5) . " (SHORTENED FOR SECURITY)";
174 $cookie_content[$key] = implode("=", $content_array);
175 }
176 }
177
178 $server["HTTP_COOKIE"] = implode(";", $cookie_content);
179
180 return $server;
181 }
182}
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
pageHeader()
Get the header for the page.
tablesContent()
Get the header for the page.
exceptionContent()
Get a short info about the exception.
handle()
Last missing method from HandlerInterface.
shortenPHPSessionId(array $server)
Shorts the php session id.
tables()
Get the tables that should be rendered.
withExclusionList(array $exclusion_list)
content()
Assemble the output for this handler.
hideSensitiveData(array $super_global)
$server
$ret
Definition: parser.php:6
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
$_COOKIE[session_name()]
Definition: xapitoken.php:37