process($_REQUEST); class FileTreeConnectorAuditTrailLogs { public $config = array( 'root' => '../../../../../logs/AuditTrail/', 'show_hidden' => false, 'show_subdirs' => true, 'allow_types' => array('gz'), 'fs_encoding' => 'UTF-8', ); protected $root; public function __construct($config = array()) { if (is_array($config) && !empty($config)) { $this->config = array_merge($this->config, $config); } $this->root = $this->config['root']; } public function process(&$request) { $root = $this->root; $dir = str_replace('..', '', urldecode($request['dir'])); $dir = $this->correctEncoding($dir, $this->config['fs_encoding']); if( file_exists($root . $dir) ) { $files = scandir($root . $dir); natcasesort($files); if( count($files) > 2 ) { /* The 2 accounts for . and .. */ $this->output(""); } } } protected function decodeFilename($name) { $name = htmlentities($name, ENT_COMPAT, $this->config['fs_encoding']); return $name; } protected function outputDir($dir, $file) { $o = "
  • decodeFilename($dir . $file) . "/\">" . $this->decodeFilename($file) . "
  • "; $this->output($o);; } protected function outputFile($dir, $file, $ext = '') { $o = "
  • decodeFilename($dir . $file) . "\">" . $this->decodeFilename($file) . "
  • "; $this->output($o);; } protected function output($str) { echo $str; } protected function isHidden($path, $name, $userId) { $extractedId = explode("_", $name)[2][0]; if ($extractedId != $userId) return true; if ($name && $name[0] == '.') return true; return false; } protected function correctEncoding($text,$dest_encoding='UTF-8',$current_encoding='') { $text .= ' '; if ($current_encoding == '') { // detect input encoding if (function_exists('mb_detect_encoding')) { // add here new encodings to check, pay attention to the order! $encorder = 'ASCII,UTF-8,ISO-8859-15'; $current_encoding = mb_detect_encoding($text, $encorder); } else { // default fallback $current_encoding = 'ISO-8859-15'; } } // check if we need conversion if ($current_encoding != $dest_encoding) { // convert to new encoding if (function_exists('iconv')) { $text = iconv($current_encoding, $dest_encoding.'//IGNORE', $text); } elseif ($current_encoding == 'ISO-8859-1' && $dest_encoding == 'UTF-8') { $text = utf8_encode($text); } } $text = substr($text,0,-1); return $text; } }