path = $path; } public function getHeader() : ?string { return explode("\r\n\r\n", $this->content)[0]; } public function getBody() : ?string { if(preg_match("/\r\n\r\n/Uis", $this->content)) { return explode("\r\n\r\n", $this->content)[1]; } else if(preg_match("/(cgi\-fcgi|command not found)/Uis", $this->content)) { throw new \Exception('Can\'t access cgi-fcgi.'); } else { return $this->content; } } public function getContent() : ?string { return $this->content; } public function isAvailable() : bool { return !empty(shell_exec('which cgi-fcgi')); } public function execute(string $file, array $arguments = [], ?string $password = null) : void { if(!is_writable($this->path)) { $this->error = true; return; } $args = ''; foreach(array_merge([ 'SCRIPTS_DIR' => $this->path, 'HOME' => $this->path, 'PWD' => $this->path, 'USER' => 'www-data', 'DOCUMENT_ROOT' => $this->path, 'SCRIPT_FILENAME' => sprintf('%s%s', $this->path, $file), 'REQUEST_METHOD' => 'GET' ], $arguments) AS $name => $value) { $args .= sprintf('%s=%s \\%s', $name, $value, PHP_EOL); } // Check if cgi-fcgi available if(!empty(shell_exec('which cgi-fcgi'))) { $command = sprintf('%scgi-fcgi -bind -connect "%s" 2>&1', $args, $this->socket); if($password != null) { $command = sprintf('bash -lc \'echo %s | /usr/bin/sudo -S %s\'', $password, $command); } $result = shell_exec($command); if($result === null){ $this->error = true; return; } $this->content = $result; } else { // @ToDo Check security(!) $temp = sprintf('.fruithost.check.%s.php', Utils::randomString(5)); $hash = Encryption::encrypt(Utils::randomString(28), ENCRYPTION_SALT); file_put_contents(sprintf('%s%s', $this->path, $temp), sprintf('', $hash, sprintf('%s%s', $this->path, $file), $arguments['MODULE'])); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, sprintf('https://%s/%s?FRUITHOST=%s&USERNAME=%s', $_SERVER['SERVER_NAME'], $temp, $hash, Auth::getUsername())); curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Cookie: ' . $_SERVER['HTTP_COOKIE'] ]); $result = curl_exec($ch); curl_close($ch); $this->content = $result; @unlink(sprintf('%s%s', $this->path, $temp)); } } public function exploding(string | array $name, mixed $data) : array | string { if($name == 'Configuration File (php.ini) Path') { return $this->highlight($this->path); } if($name == 'Loaded Configuration File') { return [ $data, sprintf('%sphp.ini', $this->path) ]; } if(in_array($name, [ 'Additional .ini files parsed', 'Registered PHP Streams', 'Registered Stream Socket Transports', 'Registered Stream Filters', 'disable_functions' ])) { if(is_array($data)) { foreach($data AS $key => $value) { $data[$key] = explode(',', $value); } } else { return explode(',', $data); } } return $this->highlight($data); } public function highlight(array | string $data) : array | string { if(is_array($data)) { foreach($data AS $name => $value) { $data[$name] = $this->highlight($value); } return $data; } switch(strtolower($data)) { case 'disabled': case 'active': case 'enabled': case 'off': case 'on': case 'no': case 'yes': return sprintf('%s', I18N::get($data)); case 'no value': return sprintf('%s', I18N::get($data)); } if(preg_match('/^#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?/', $data)) { return sprintf('%1$s', $data); } if(is_numeric($data)) { return sprintf('%s', $data); } // $data[0] gives hier Errors! if(substr($data, 0, 1) === '/' || str_starts_with($data, '.:/')) { return sprintf('%s', $data); } return $data; } public function hasErrors() : bool { return $this->error; } public function parse() : void { if($this->error) { return; } $entitiesToUtf8 = function($input) { // http://php.net/manual/en/function.html-entity-decode.php#104617 return preg_replace_callback("/([0-9]+;)/", function($m) { return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES"); }, $input); }; $plainText = function($input) use ($entitiesToUtf8) { return trim(html_entity_decode($entitiesToUtf8(strip_tags($input)))); }; $titlePlainText = function($input) use ($plainText) { return '# '.$plainText($input); }; if(!preg_match('#(.*