showfiles.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. $pwd = $_GET['dir'];
  3. //These variables are to check whether the directory we will link to exists, and to know what directory we are in
  4. $check = @scandir($pwd.'/../', 1);
  5. $splode = preg_split('[/]', $pwd, -1);
  6. $predir = count($splode)-1;
  7. $test = array_slice($splode, -1, 1);
  8. #Establish MIME Type data
  9. #Link is used to specify special handler URLS for particular files
  10. #File specifies the link icon
  11. $arch_types = array(".tar",".gz",".z7",".bz",".bz2",".zip",".rar",".lsz",
  12. "link" => "",
  13. "file" => "tsarchive.gif");
  14. //Only MP3 supported for now
  15. $audio_types = array(".mp3",
  16. "link" => "index.php?nav=7&post=",
  17. "file" => "tsaudio.gif");
  18. $video_types = array(".ogv",
  19. "link" => "index.php?nav=8&post=",
  20. "file" => "tsmovie.gif");
  21. $image_types = array(".bmp",".gif",".jpg",".jpeg",".png",".ico",".svg",".xpm",
  22. "link" => "index.php?nav=9&post=",
  23. "file" => "tsimage.gif");
  24. $schematic_types = array(".dwg",".dxf",".cad",".gcode",".mcode",
  25. "link" => "",
  26. "file" => "tsschematic.gif");
  27. $model_types = array(".stl",".blend",".3ds",
  28. "link" => "",
  29. "file" => "tsmodel.gif");
  30. $binary_types = array(".exe",".o",".dll",".so",".jnilib",".a",".bin",".hex",
  31. "link" => "",
  32. "file" => "tssoftware.gif");
  33. $code_types = array(".py",".c",".h",".js",".php",".tcl",".m",".txt",
  34. "link" => "index.php?nav=6&post=",
  35. "file" => "tscode.gif");
  36. $doc_types = array(".htm",".html",".post",
  37. "link" => "index.php?nav=5&post=",
  38. "file" => "tsdoc.png");
  39. $legacy_types = array(".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".pages",".ai",".psd",".tiff",".tif",".eps",".ps",".xps",
  40. "link" => "index.php?nav=10&post=",
  41. "file" => "tsprop.png");
  42. $mime_types = array($arch_types,$audio_types,$video_types,$image_types,$schematic_types,$model_types,$binary_types,$code_types,$doc_types,$legacy_types);
  43. //Find the directory contents
  44. $ls = @scandir($pwd, 1);
  45. // $dlist = array_filter($ls,function ($a) {return is_dir($a);});
  46. $dban1 = '.';
  47. $dban2 = '..';
  48. $dkey = array_search($dban1,$ls);
  49. if ($dkey!==false){unset($ls[$dkey]);};
  50. $dkey = array_search($dban2,$ls);
  51. if ($dkey!==false){unset($ls[$dkey]);};
  52. //See if this directory is even there
  53. if (@in_array($test[0], $check)) {
  54. echo 'Directory listing for '.$pwd;
  55. echo '<hr />';
  56. $cnt = count($ls);
  57. $dlist = array();
  58. $flist = array();
  59. //Trying to sort here
  60. for ($n = 0; $n < $cnt; $n++) {
  61. $filechk = @scandir($pwd.'/'.$ls[$n]);
  62. if (! $filechk) {
  63. foreach($mime_types as $mimes) {
  64. foreach($mimes as $type) {
  65. $sstrn = @stristr($ls[$n],$type);
  66. if($sstrn !== FALSE && strlen($sstrn) == strlen($type)) {
  67. array_push($flist, $ls[$n]);
  68. }
  69. }
  70. }
  71. }
  72. else {
  73. array_push($dlist, $ls[$n]);
  74. }
  75. }
  76. sort($dlist);
  77. sort($flist);
  78. $ls = array_merge($dlist,$flist);
  79. //Yeah, I know this looks familiar. There's prolly some way to combine this by setting the $ikon and $link vars as an array.
  80. for ($n = 0; $n < $cnt; $n++) {
  81. //create links based on whether we are a file, and if otherwise we are a directory
  82. $filechk = @scandir($pwd.'/'.$ls[$n]);
  83. if (! $filechk) {
  84. //default values for uncaught filetypes
  85. $ikon = "tsfile.gif";
  86. $link = "";
  87. foreach ($mime_types as $mimes) {
  88. foreach ($mimes as $type) {
  89. //$link = $mimes["link"];
  90. $sstrn = @stristr($ls[$n],$type);
  91. if ($sstrn !== FALSE && strlen($sstrn) == strlen($type)) {
  92. $ikon = $mimes["file"];
  93. $link = $mimes["link"];
  94. break 2;
  95. };
  96. };
  97. };
  98. echo '<img class="icon" src='.$config['icondir'].$ikon.' />';
  99. echo '<a href="'.$link.$pwd.'/'.$ls[$n].'">'.$ls[$n].'</a><br />';
  100. }
  101. else {
  102. echo '<img src="'.$config['icondir'].'tsfolder.gif" />';
  103. echo '<a href="index.php?nav=1&dir='.$pwd.'/'.$ls[$n].'">'.$ls[$n].'</a><br />'."\n";
  104. }
  105. }
  106. //Figure out what the previous directory is
  107. $prevdirname = '';
  108. for ($i =0; $i < $predir; $i++) {
  109. //We want to catch the first case, and not put a / before it
  110. if ($i == 0) {
  111. $prevdirname = $prevdirname.$splode[$i];
  112. }
  113. else {
  114. $prevdirname = $prevdirname.'/'.$splode[$i];
  115. }
  116. }
  117. //If we are not in the TLD, make a link to the previous dir
  118. if ($prevdirname <> '') {
  119. echo '<img src="'.$config['icondir'].'tsfolder-up.gif" />';
  120. echo '<a href="index.php?nav=1&dir='.$prevdirname.'">Up one level</a>'."\n";
  121. }
  122. }
  123. //Catch bogus directories
  124. else {
  125. include 'sys/fileshare/include/notfound';
  126. }
  127. ?>