ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilLoggingErrorFileStorage.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2016 Stefan Hecken, Extended GPL, see docs/LICENSE */
3 require_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;
113  $server = $_SERVER;
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 
152  {
153  global $ilLog;
154 
155  $cookie_content = $server["HTTP_COOKIE"];
156  $cookie_content = explode(";", $cookie_content);
157 
158  foreach ($cookie_content as $key => $content) {
159  $content_array = explode("=", $content);
160  if (trim($content_array[0]) == session_name()) {
161  $content_array[1] = substr($content_array[1], 0, 5) . " (SHORTENED FOR SECURITY)";
162  $cookie_content[$key] = implode("=", $content_array);
163  }
164  }
165 
166  $server["HTTP_COOKIE"] = implode(";", $cookie_content);
167 
168  return $server;
169  }
170 }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
pageHeader()
Get the header for the page.
$_COOKIE['client_id']
Definition: server.php:9
__construct($inspector, $file_path, $file_name)
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$_SESSION["AccountId"]
$_GET["client_id"]
Saves error informations into file.
$stream
PHP stream implementation.
shortenPHPSessionId(array $server)
Shorts the php session id.
tablesContent()
Get the header for the page.
exceptionContent()
Get a short info about the exception.
$post
Definition: post.php:34
Create styles array
The data for the language used.
$server
Definition: getUserInfo.php:12
tables()
Get the tables that should be rendered.
$ret
Definition: parser.php:6
hidePassword(array $post)
Replace passwort from post array with security message.
$key
Definition: croninfo.php:18
$_POST["username"]