1. <?php
  2. // CONFIG SECTION
  3. $conf = "c:/program files/abyss/abyss.conf"; //filesystem path to your abyss conf file
  4. $bytes = FALSE; // TRUE will show exact bytes in listing, FALSE will show KB, MB, GB, etc.
  5. $truncate = TRUE; // Truncate long filenames
  6. $trunc = 40; // If truncate is TRUE, where to truncate filename at
  7. // END CONFIG SECTION - Only edit below if you know what you're doing
  8. ?>
  9. <HTML>
  10. <HEAD>
  11. <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
  12. <TITLE>Index of <?php echo $_POST['path']; ?></TITLE>
  13. <STYLE type="text/css">
  14. td.pr {PADDING-RIGHT: 1em;}
  15. </STYLE>
  16. </HEAD>
  17. <BODY>
  18. <H1>Index of <?php echo $_POST['path']; ?></H1>
  19. <?php
  20. $dir_array = explode("/", $_POST['path']);
  21. array_pop($dir_array);
  22. ?>
  23. <HR>
  24. <TABLE style="FONT-SIZE: smaller; FONT-FAMILY: monospace" border=0>
  25. <THEAD>
  26. <TH>Name</TH>
  27. <TH>Size</TH>
  28. <TH>Date</TH>
  29. <TH>MIME Type</TH>
  30. </TR>
  31. <?php
  32. // Grab virtual dir's
  33. //XML Data
  34. $xml_data = file_get_contents($conf);
  35. $xmlObj = new XmlToArray($xml_data);
  36. $arrayData = $xmlObj->createArray();
  37. $return = ""; // Have to create this now for the globalization to work right
  38. $id = ($_SERVER['INSTANCE_ID'] - 1);
  39. $aliases = $arrayData['root']['server'][0]['host'][$id]['aliases'][0]['alias'];
  40. foreach ($aliases as $key => $value){
  41. if ('/' == substr($value['virtual'], strlen($value['virtual'])-1)){
  42. $value['virtual'] = substr_replace($value['virtual'], '', strlen($value['virtual'])-1);} // strip trailing slash
  43. $split = explode("/", $value['virtual']);
  44. $up_one = $split;
  45. array_pop($up_one);
  46. $hier = trim(join("/", $up_one));
  47. $hier .= "/"; // add trailing slash so it might match post[path]
  48. if (strtolower($_POST['path']) === strtolower($hier)) {
  49. global $return;
  50. $return .= $split[(count($split) - 1)]."/\t". //NAME
  51. urlencode($split[(count($split) - 1)])."/\t". //URL
  52. "0"."\t". //SIZE
  53. "-"."\t". //DATE
  54. "<I>Alias Directory</I>"."\n"; //MIME
  55. }
  56. }
  57. // End virtual dir processing
  58.  
  59. $_POST['files'] = $return.$_POST['files']; //adds aliases to internal file list
  60. $lines = explode("\n", $_POST['files']);
  61. foreach ($lines as $line)
  62. {
  63. /* Split the line and get the file information */
  64. list($name, $url, $size, $date, $mimetype) = explode("\t", $line);
  65. if ($mimetype == "") {$mimetype = "Directory";}
  66. if ($size == "0") {$size = "-";} elseif($bytes == FALSE){$size = niceSize($size);}
  67. if ($truncate == TRUE){$name = shortName($name, $trunc);}
  68.  
  69. echo "<TR>".
  70. "<TD class=\"pr\"><A HREF=\"$url\">".htmlentities($name)."</A></TD>".
  71. "<TD class=\"pr\" noWrap align=right>$size</TD>".
  72. "<TD class=\"pr\" noWrap>$date</TD>".
  73. "<TD>$mimetype</TD>".
  74. "</TR>\n";
  75. }
  76. ?>
  77. </TABLE>
  78. <HR>
  79. </BODY>
  80. </HTML>
  81. <?php
  82. function niceSize($bytes){
  83. if($bytes < (1024 * 1024)) {return number_format($bytes / 1024, 1) . " kb";}
  84. elseif($bytes < (1024 * 1024 * 1024)) {return number_format($bytes / (1024 * 1024), 2) . " mb";}
  85. elseif($bytes < (1024 * 1024 * 1024 * 1024)) {return number_format($bytes / (1024 * 1024 * 1024), 3) . " gb";}
  86. }
  87. function shortName($name, $trunc){
  88. if(strlen($name) < $trunc){return $name;}
  89. if(strlen($name) > $trunc){
  90. $return = substr($name, 0, $trunc) . "...";
  91. if(strrpos($name, '.') > $trunc) {
  92. $return .= substr($name, (strrpos($name, '.') - 0));
  93. }
  94. return $return;
  95. }
  96. }
  97. ?>
  98. <?php // This class below translates the abyss.conf XML into an array
  99. /**
  100. * Author : MA Razzaque Rupom (rupom_315@yahoo.com, rupom.bd@gmail.com)
  101. * Version : 1.0
  102. * Date : 02 March, 2006
  103. * Purpose : Creating Hierarchical Array from XML Data
  104. * Released : Under GPL
  105. */
  106.  
  107. //require_once "class.xmltoarray.php";
  108.  
  109. //***************************************************************************
  110. class XmlToArray
  111. {
  112.  
  113. var $xml='';
  114.  
  115. /**
  116.   * Default Constructor
  117.   * @param $xml = xml data
  118.   * @return none
  119.   */
  120.  
  121. function XmlToArray($xml)
  122. {
  123. $this->xml = $xml;
  124. }
  125.  
  126. /**
  127.   * _struct_to_array($values, &$i)
  128.   *
  129.   * This is adds the contents of the return xml into the array for easier processing.
  130.   * Recursive, Static
  131.   *
  132.   * @access private
  133.   * @param array $values this is the xml data in an array
  134.   * @param int $i this is the current location in the array
  135.   * @return Array
  136.   */
  137.  
  138. function _struct_to_array($values, &$i)
  139. {
  140. $child = array();
  141. if (isset($values[$i]['value'])) array_push($child, $values[$i]['value']);
  142.  
  143. while ($i++ < count($values)) {
  144. switch ($values[$i]['type']) {
  145. case 'cdata':
  146. array_push($child, $values[$i]['value']);
  147. break;
  148.  
  149. case 'complete':
  150. $name = $values[$i]['tag'];
  151. if(!empty($name)){
  152. $child[$name]= ($values[$i]['value'])?($values[$i]['value']):'';
  153. if(isset($values[$i]['attributes'])) {
  154. $child[$name] = $values[$i]['attributes'];
  155. }
  156. }
  157. break;
  158.  
  159. case 'open':
  160. $name = $values[$i]['tag'];
  161. $size = isset($child[$name]) ? sizeof($child[$name]) : 0;
  162. $child[$name][$size] = $this->_struct_to_array($values, $i);
  163. break;
  164.  
  165. case 'close':
  166. return $child;
  167. break;
  168. }
  169. }
  170. return $child;
  171. }//_struct_to_array
  172.  
  173. /**
  174.   * createArray($data)
  175.   *
  176.   * This is adds the contents of the return xml into the array for easier processing.
  177.   *
  178.   * @access public
  179.   * @param string $data this is the string of the xml data
  180.   * @return Array
  181.   */
  182. function createArray()
  183. {
  184. $xml = $this->xml;
  185. $values = array();
  186. $index = array();
  187. $array = array();
  188. $parser = xml_parser_create();
  189. xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  190. xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
  191. xml_parse_into_struct($parser, $xml, $values, $index);
  192. xml_parser_free($parser);
  193. $i = 0;
  194. $name = $values[$i]['tag'];
  195. $array[$name] = isset($values[$i]['attributes']) ? $values[$i]['attributes'] : '';
  196. $array[$name] = $this->_struct_to_array($values, $i);
  197. return $array;
  198. }//createArray
  199.  
  200.  
  201. }//XmlToArray
  202. //***************************************************************************
  203. ?>