ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLoggingErrorFileStorage.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2016 Stefan Hecken, Extended GPL, see docs/LICENSE */
3require_once './libs/composer/vendor/autoload.php';
4
6
13{
14 const KEY_SPACE = 25;
15 const FILE_FORMAT = ".log";
16
17 public function __construct($inspector, $file_path, $file_name)
18 {
19 $this->inspector = $inspector;
20 $this->file_path = $file_path;
21 $this->file_name = $file_name;
22 }
23
24 protected function createDir($path)
25 {
26 if (!is_dir($this->file_path)) {
27 ilUtil::makeDirParents($this->file_path);
28 }
29 }
30
31 protected function content()
32 {
33 return $this->pageHeader()
34 . $this->exceptionContent()
35 . $this->tablesContent()
36 ;
37 }
38
39 public function write()
40 {
41 $this->createDir($this->file_path);
42
43 $file_name = $this->file_path . "/" . $this->file_name . self::FILE_FORMAT;
44 $stream = fopen($file_name, 'w+');
45 fwrite($stream, $this->content());
46 fclose($stream);
47 chmod($file_name, 0755);
48 }
49
55 protected function pageHeader()
56 {
57 return "";
58 }
59
65 protected function exceptionContent()
66 {
67 return Formatter::formatExceptionPlain($this->inspector);
68 }
69
75 protected function tablesContent()
76 {
77 $ret = "";
78 foreach ($this->tables() as $title => $content) {
79 $ret .= "\n\n-- $title --\n\n";
80 if (count($content) > 0) {
81 foreach ($content as $key => $value) {
82 $key = str_pad($key, self::KEY_SPACE);
83
84 // indent multiline values, first print_r, split in lines,
85 // indent all but first line, then implode again.
86 $first = true;
87 $indentation = str_pad("", self::KEY_SPACE);
88 $value = implode("\n", array_map(function ($line) use (&$first, $indentation) {
89 if ($first) {
90 $first = false;
91 return $line;
92 }
93 return $indentation . $line;
94 }, explode("\n", print_r($value, true))));
95
96 $ret .= "$key: $value\n";
97 }
98 } else {
99 $ret .= "empty\n";
100 }
101 }
102 return $ret;
103 }
104
110 protected function tables()
111 {
112 $post = $_POST;
114
115 $post = $this->hidePassword($post);
117
118 return array( "GET Data" => $_GET
119 , "POST Data" => $post
120 , "Files" => $_FILES
121 , "Cookies" => $_COOKIE
122 , "Session" => isset($_SESSION) ? $_SESSION : array()
123 , "Server/Request Data" => $server
124 , "Environment Variables" => $_ENV
125 );
126 }
127
135 private function hidePassword(array $post)
136 {
137 if (isset($post["password"])) {
138 $post["password"] = "REMOVED FOR SECURITY";
139 }
140
141 return $post;
142 }
143
151 private function shortenPHPSessionId(array $server)
152 {
153 $cookie_content = $server["HTTP_COOKIE"];
154 $cookie_content = explode(";", $cookie_content);
155
156 foreach ($cookie_content as $key => $content) {
157 $content_array = explode("=", $content);
158 if (trim($content_array[0]) == session_name()) {
159 $content_array[1] = substr($content_array[1], 0, 5) . " (SHORTENED FOR SECURITY)";
160 $cookie_content[$key] = implode("=", $content_array);
161 }
162 }
163
164 $server["HTTP_COOKIE"] = implode(";", $cookie_content);
165
166 return $server;
167 }
168}
$_COOKIE['client_id']
Definition: server.php:9
$path
Definition: aliased.php:25
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Saves error informations into file.
hidePassword(array $post)
Replace passwort from post array with security message.
__construct($inspector, $file_path, $file_name)
pageHeader()
Get the header for the page.
exceptionContent()
Get a short info about the exception.
tablesContent()
Get the header for the page.
tables()
Get the tables that should be rendered.
shortenPHPSessionId(array $server)
Shorts the php session id.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$key
Definition: croninfo.php:18
$stream
PHP stream implementation.
$ret
Definition: parser.php:6
$post
Definition: post.php:34
$server
Definition: sabredav.php:48
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']