(**OLD**) A single PHP file, when dropped into a directory can be used to manage the files in it.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.php 38KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | File Manager 0.4 |
  5. +---------------------------------------------------------------------------+
  6. | Author: James Wheaton |
  7. +---------------------------------------------------------------------------+
  8. | |
  9. | This program is free software; you can redistribute it and/or |
  10. | modify it under the terms of the GNU General Public License |
  11. | as published by the Free Software Foundation; either version 2 |
  12. | of the License, or (at your option) any later version. |
  13. | |
  14. | This program is distributed in the hope that it will be useful, |
  15. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  16. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  17. | GNU General Public License for more details. |
  18. | |
  19. | You should have received a copy of the GNU General Public License |
  20. | along with this program; if not, write to the Free Software Foundation, |
  21. | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
  22. | |
  23. +---------------------------------------------------------------------------+
  24. */
  25. $time_start = microtime(1);
  26. error_reporting(E_ALL);
  27. /*********************************************************************
  28. * trying to show variable data types but got too lazy after a while *
  29. *********************************************************************/
  30. /* (string) */ $self = basename($_SERVER['PHP_SELF']);
  31. /* (array) */ $filelist = array();
  32. /* (array) */ $dirlist = array();
  33. /* (int) */ $color_number = 1;
  34. /* (array) */ $bad = array('..', '../', '..\\', '//');
  35. /* (string) */ $_GET['sort'] = (isset($_GET['sort'])) ? $_GET['sort'] : 'nameasc';
  36. /* (string) */ $status = '';
  37. /* (bool) */ $showhidden = false;
  38. /************
  39. * Get $dir *
  40. ************/
  41. if (isset($_GET['up']))
  42. {
  43. $dir = dirname($_GET['dir']);
  44. $dir = empty($dir) ? '.' : str_replace($bad, '', $dir);
  45. }
  46. else
  47. {
  48. $dir = empty($_GET['dir']) ? '.' : str_replace($bad, '', $_GET['dir']);
  49. }
  50. if ($dir{0} === '/')
  51. {
  52. $dir = substr($dir, 1);
  53. }
  54. $readable_dir = ($dir === '.') ? substr(($t = strrchr(getcwd(), '/')) !== false ? $t : '', 1) : substr(($t = strrchr($dir, '/')) !== false ? $t : '', 1);
  55. /*********************
  56. * Web page template *
  57. *********************/
  58. function template($title, $style, $body, $microtime)
  59. {
  60. global $time_start, $time_end;
  61. $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  62. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  63. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  64. <head>
  65. <title>' . $title . '</title>
  66. <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-1" />
  67. <meta http-equiv="Content-Language" content="en-us" />
  68. <link rel="stylesheet" type="text/css" href="' . $style . '" media="screen" />
  69. <script type="text/javascript">
  70. //<![CDATA[
  71. //show OR hide funtion depends on if element is shown or hidden
  72. function show(id) {
  73. if (document.getElementById) { // DOM3 = IE5, NS6
  74. if (document.getElementById(id).style.display == "none"){
  75. document.getElementById(id).style.display = \'block\';
  76. } else {
  77. document.getElementById(id).style.display = \'none\';
  78. }
  79. } else {
  80. if (document.layers) {
  81. if (document.id.display == "none"){
  82. document.id.display = \'block\';
  83. } else {
  84. document.id.display = \'none\';
  85. }
  86. } else {
  87. if (document.all.id.style.visibility == "none"){
  88. document.all.id.style.display = \'block\';
  89. } else {
  90. document.all.id.style.display = \'none\';
  91. }
  92. }
  93. }
  94. }
  95. //]]>
  96. </script>
  97. </head>
  98. <body onload="show(\'functions\')">
  99. <h1>uranther.com</h1>
  100. <div id="wrapper">' . $body;
  101. if ($microtime === true)
  102. {
  103. $html .= "\n\t" . '</div>' . "\n\t" . '<div id="footer">' . 'Page generated in ' .
  104. round(($time_end - $time_start), 6) . ' seconds.</div>' . "\n\t" . '</body>' . "\n" . '</html>';
  105. }
  106. return $html;
  107. }
  108. /***************
  109. * Upload file *
  110. ***************
  111. if (isset($_POST['submitupload']))
  112. {
  113. if (@move_uploaded_file($_FILES['uploadfile']['tmp_name'],
  114. $dir . '/' . basename($_FILES['uploadfile']['name'])))
  115. {
  116. $status = ' &minus; upload success';
  117. }
  118. else
  119. {
  120. $status = ' &minus; upload error: check permissions';
  121. }
  122. }*/
  123. /*************
  124. * Move file *
  125. *************
  126. else if (isset($_POST['submitmove']))
  127. {
  128. if (isset($_POST['movesrcfile']) and !empty($_POST['movesrcfile']))
  129. {
  130. if (is_file($_POST['movesrcfile']) or is_dir($_POST['movesrcfile']))
  131. {
  132. if (isset($_POST['movedestfile']) and !empty($_POST['movedestfile']))
  133. {
  134. if(!@rename($_POST['movesrcfile'], $_POST['movedestfile']))
  135. {
  136. $status = ' &minus; move error: check permissions';
  137. }
  138. else
  139. {
  140. $status = ' &minus; move success';
  141. }
  142. }
  143. else
  144. {
  145. $status = ' &minus; move error: need destination';
  146. }
  147. }
  148. else
  149. {
  150. $status = ' &minus; move error: file/directory does not exist';
  151. }
  152. }
  153. else
  154. {
  155. $status = ' &minus; move error: need source';
  156. }
  157. }*/
  158. /***************
  159. * Delete file *
  160. ***************
  161. else if (isset($_POST['submitdel']))
  162. {
  163. if (isset($_POST['delfile']) and !empty($_POST['delfile']))
  164. {
  165. if (is_file($_POST['delfile']))
  166. {
  167. if (@unlink($_POST['delfile']))
  168. {
  169. $status = ' &minus; delete success';
  170. }
  171. else
  172. {
  173. $status = ' &minus; delete error: check permissions';
  174. }
  175. }
  176. else if (is_dir($_POST['delfile']))
  177. {
  178. $status = ' &minus; delete error: no support for directories';
  179. }
  180. else
  181. {
  182. $status = ' &minus; delete error: file does not exist';
  183. }
  184. }
  185. else
  186. {
  187. $status = ' &minus; delete error: need file';
  188. }
  189. }*/
  190. /**************
  191. * Chmod file *
  192. **************
  193. else if (isset($_POST['submitchmod']))
  194. {
  195. if (isset($_POST['chmodsrcfile']) and !empty($_POST['chmodsrcfile']) and
  196. isset($_POST['chmodfile']) and !empty($_POST['chmodfile']))
  197. {
  198. if (is_file($_POST['chmodsrcfile']))
  199. {
  200. if (is_numeric($_POST['chmodfile']))
  201. {
  202. if (@chmod($_POST['chmodsrcfile'], octdec($_POST['chmodfile'])))
  203. {
  204. $status = ' &minus; chmod success ' . octdec($_POST['chmodfile']);
  205. }
  206. else
  207. {
  208. $status = ' &minus; chmod error: check permissions or chmod value';
  209. }
  210. }
  211. else
  212. {
  213. $status = ' &minus; chmod error: please enter a numeric chmod value';
  214. }
  215. }
  216. else
  217. {
  218. $status = ' &minus; chmod error: file does not exist';
  219. }
  220. }
  221. else
  222. {
  223. $status = ' &minus; chmod error: need file or chmod value';
  224. }
  225. }*/
  226. /***************
  227. * View source *
  228. ***************/
  229. function download($src)
  230. {
  231. global $bad, $self;
  232. $src = str_replace($bad, '', $src);
  233. $srcdir = dirname($src);
  234. if (file_exists($src) and is_file($src) and is_readable($src))
  235. {
  236. if (is_file_ext($src, array('.php', '.php3')))
  237. {
  238. header('Content-type: application/force-download');
  239. header('Content-length: ' . filesize($src));
  240. return file_get_contents($src);
  241. }
  242. else
  243. {
  244. $body = "\n\t\t" . '<div class="notice">' .
  245. "\n\t\t\t" . '<p>Can only download a PHP file.</p>' .
  246. "\n\t\t\t" . '<a class="dir" href="' . $self . '?dir=' . $srcdir . '">Return to index</a>' .
  247. "\n\t\t" . '</div>';
  248. return template('Download error: ' . $src,
  249. $self . '?style',
  250. $body, false);
  251. }
  252. }
  253. else
  254. {
  255. $body = "\n\t\t" . '<div class="notice">' .
  256. "\n\t\t\t" . '<p>No file.</p>' .
  257. "\n\t\t\t" . '<a class="dir" href="' . $self . '?dir=' . $srcdir . '">Return to index</a>' .
  258. "\n\t\t" . '</div>';
  259. return template('Download error: ' . $src,
  260. $self . '?style',
  261. $body, false);
  262. }
  263. }
  264. function sourceview($src)
  265. {
  266. global $bad, $self;
  267. $src = str_replace($bad, '', $src);
  268. $srcdir = dirname($src);
  269. if (empty($_GET['src']))
  270. {
  271. $body = "\n\t\t" . '<div class="notice">' .
  272. "\n\t\t\t" . '<p>Need file.</p>' .
  273. "\n\t\t\t" . '<a class="dir" href="' . $self . '?dir=' . $srcdir . '">Return to index</a>' .
  274. "\n\t\t" . '</div>';
  275. $title = 'Source view error: ' . $src;
  276. $style = $self . '?style';
  277. }
  278. else
  279. {
  280. if (file_exists($src) and is_file($src) and is_readable($src))
  281. {
  282. if (is_file_ext($src, array('.php', '.php3')))
  283. {
  284. $body = '<h3><a href="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?dir=' . dirname($src) . '">Return</a>&nbsp;&nbsp;&nbsp;<a href="http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/' . $src . '">View this file</a>&nbsp;&nbsp;&nbsp;<a href="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?download=' . $src . '">Download this file</a></h3>' .
  285. highlight_file($src, true);
  286. $title = 'Source view: ' . $src;
  287. $style = $self . '?sourcecss';
  288. }
  289. else
  290. {
  291. $body = "\n\t\t" . '<div class="notice">' .
  292. "\n\t\t\t" . '<p>Can only view source of a PHP file.</p>';
  293. if (strstr($_SERVER['HTTP_REFERER'], 'submitsearch=Search'))
  294. {
  295. $body .= "\n\t\t\t" . '<a class="dir" href="' . $_SERVER['HTTP_REFERER'] . '">Return to index</a>' .
  296. "\n\t\t" . '</div>';
  297. }
  298. else
  299. {
  300. $body .= "\n\t\t\t" . '<a class="dir" href="' . $self . '?dir=' . $srcdir . '">Return to index</a>' .
  301. "\n\t\t" . '</div>';
  302. }
  303. $title = 'Source view error: ' . $src;
  304. $style = $self . '?style';
  305. }
  306. }
  307. else
  308. {
  309. $body = "\n\t\t" . '<div class="notice">' .
  310. "\n\t\t\t" . '<p>File does not exist or is not readable.</p>' .
  311. "\n\t\t\t" . '<a class="dir" href="' . $self . '?dir=' . $srcdir . '">Return to index</a>' .
  312. "\n\t\t" . '</div>';
  313. $title = 'Source view error: ' . $src;
  314. $style = $self . '?style';
  315. }
  316. }
  317. return template($title, $style, $body, false);
  318. }
  319. /*********
  320. * Icons *
  321. *********/
  322. // base64_decode() rapes the shit out of the server
  323. // Saved in icons.txt for reference.
  324. /****************
  325. * Image viewer *
  326. ****************/
  327. function view_image($imagefile)
  328. {
  329. global $self, $bad;
  330. $imagefile = str_replace($bad, '', $imagefile);
  331. $imagedir = dirname($imagefile);
  332. $filename = basename($imagefile);
  333. if (file_exists($imagefile) and is_file($imagefile) and is_readable($imagefile))
  334. {
  335. list($width, $height, $type, $attr) = @getimagesize($imagefile);
  336. switch ($type)
  337. {
  338. case 1:
  339. $type = 'GIF';
  340. break;
  341. case 2:
  342. $type = 'JPEG';
  343. break;
  344. case 3:
  345. $type = 'PNG';
  346. break;
  347. default:
  348. $type = 'Unsupported'; // This had better not happen
  349. }
  350. if ($type === 'Unsupported')
  351. {
  352. $body = "\n\t\t" . '<div class="notice">' .
  353. "\n\t\t\t" . '<p>Image file is not supported</p>' .
  354. "\n\t\t\t" . '<a class="dir" href="' . $self . '?dir=' . $imagedir . '">Return to index</a>' .
  355. "\n\t\t" . '</div>';
  356. $html = template('Image viewer error: ' . $imagedir,
  357. $self . '?style&amp;imageview=' . $_GET['imageview'],
  358. $body, false);
  359. $file_info = array(NULL, NULL, NULL, NULL, $html);
  360. }
  361. else
  362. {
  363. $minwidth = $width < 250 ? 250 : $width;
  364. $body = "\n\t\t" . '<div class="image">' .
  365. "\n\t\t\t" . '<img alt="' . $imagefile . '" src="' . $imagefile . '" ' . $attr . ' />' . '<hr />' .
  366. "\n\t\t\t" . 'Filename: ' . $filename . '<br />' .
  367. "\n\t\t\t" . 'Dimensions: ' . $width . ' x ' . $height . ' px<br />' .
  368. "\n\t\t\t" . 'Filetype: ' . $type . '<br />' .
  369. "\n\t\t\t" . 'Filesize: ' . fsize_unit_convert(filesize($imagefile)) . '<br />';
  370. if (!empty($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], 'submitsearch=Search'))
  371. {
  372. $body .=
  373. "\n\t\t\t" . '<a style="margin-left: ' . ($minwidth/2 - 50) . 'px" class="dir" href="' . $_SERVER['HTTP_REFERER'] . '">Return to index</a>';
  374. }
  375. else
  376. {
  377. $body .=
  378. "\n\t\t\t" . '<a style="margin-left: ' . ($minwidth/2 - 50) . 'px" class="dir" href="' . $self . '?dir=' . $imagedir . '">Return to index</a>';
  379. }
  380. $body .= "\n\t\t" . '</div>';
  381. $html = template('Image viewer: ' . $imagedir,
  382. $self . '?style&amp;imageview=' . $_GET['imageview'],
  383. $body, false);
  384. $file_info = array($width, $height, $type, $attr, $html);
  385. }
  386. }
  387. else
  388. {
  389. $body = "\n\t\t" . '<div class="notice">' .
  390. "\n\t\t\t" . '<p>Image file ' . $imagefile . ' does not exist</p>' .
  391. "\n\t\t\t" . '<a class="dir" href="' . $self . '?dir=' . $imagedir . '">Return to index</a>' .
  392. "\n\t\t" . '</div>';
  393. $html = template('Image viewer error: ' . $imagedir,
  394. $self . '?style&amp;imageview=' . $_GET['imageview'],
  395. $body, false);
  396. $file_info = array(NULL, NULL, NULL, NULL, $html);
  397. }
  398. return $file_info;
  399. }
  400. /*****************************************************
  401. * Search for a case-insensitive string in filenames *
  402. *****************************************************/
  403. function search($string, $dh)
  404. {
  405. $count = 0;
  406. while (($file = readdir($dh)) !== false)
  407. {
  408. if (stristr($file, $string))
  409. {
  410. $filelist[$count] = $file;
  411. $count++;
  412. }
  413. }
  414. closedir($dh);
  415. if (empty($filelist))
  416. {
  417. $filelist[0] = '.';
  418. $filelist[1] = '..';
  419. }
  420. return $filelist;
  421. }
  422. /*****************************************
  423. * strpos() needs to supports arrays >:O *
  424. *****************************************/
  425. function is_file_ext($haystack, $needles)
  426. {
  427. for ($i = 0; $i < count($needles); $i++)
  428. {
  429. $bool = strstr($haystack, $needles[$i]);
  430. if($bool !== false)
  431. {
  432. return true;
  433. }
  434. }
  435. return false;
  436. }
  437. /**********************************
  438. * Multi-purpose sorting function *
  439. **********************************/
  440. function multi_sort($array, $order, $function)
  441. {
  442. if (empty($array))
  443. {
  444. return;
  445. }
  446. // $order must equal 'asc' or 'desc'
  447. assert($order === 'asc' or $order === 'desc');
  448. for ($i = 0; $i < count($array); $i++)
  449. {
  450. $sorted[$i][0] = $function($array[$i]);
  451. $sorted[$i][1] = $array[$i];
  452. }
  453. if ($order === 'asc')
  454. {
  455. sort($sorted);
  456. }
  457. else if ($order === 'desc')
  458. {
  459. rsort($sorted);
  460. }
  461. assert(count($sorted) === count($array));
  462. for ($i = 0; $i < count($array); $i++)
  463. {
  464. $array_key = array_search($sorted[$i][1], $array);
  465. $new_array[$i] = $array[$array_key];
  466. }
  467. return $new_array;
  468. }
  469. /****************************
  470. * File size unit converter *
  471. ****************************/
  472. function fsize_unit_convert($bytes)
  473. {
  474. $units = array('b', 'kb', 'mb', 'gb');
  475. $converted = $bytes . ' ' . $units[0];
  476. for ($i = 0; $i < count($units); $i++)
  477. {
  478. if (($bytes/pow(1024, $i)) >= 1)
  479. {$converted = round($bytes/pow(1024, $i), 2) . ' ' . $units[$i];}
  480. }
  481. return $converted;
  482. }
  483. /**********************
  484. * Get file extension *
  485. **********************/
  486. function get_ext($filename)
  487. {
  488. $ext = substr(
  489. ($t = strrchr($filename,'.')) !== false
  490. ? $t
  491. : 'xnone', /* x is gonna be substr'd */
  492. 1);
  493. return $ext;
  494. }
  495. /**********************
  496. * Format fileperms() *
  497. **********************/
  498. function format_perms($perms)
  499. {
  500. if (($perms & 0xC000) == 0xC000) {
  501. // Socket
  502. $info = 's';
  503. } elseif (($perms & 0xA000) == 0xA000) {
  504. // Symbolic Link
  505. $info = 'l';
  506. } elseif (($perms & 0x8000) == 0x8000) {
  507. // Regular
  508. $info = '-';
  509. } elseif (($perms & 0x6000) == 0x6000) {
  510. // Block special
  511. $info = 'b';
  512. } elseif (($perms & 0x4000) == 0x4000) {
  513. // Directory
  514. $info = 'd';
  515. } elseif (($perms & 0x2000) == 0x2000) {
  516. // Character special
  517. $info = 'c';
  518. } elseif (($perms & 0x1000) == 0x1000) {
  519. // FIFO pipe
  520. $info = 'p';
  521. } else {
  522. // Unknown
  523. $info = 'u';
  524. }
  525. // Owner
  526. $info .= (($perms & 0x0100) ? 'r' : '-');
  527. $info .= (($perms & 0x0080) ? 'w' : '-');
  528. $info .= (($perms & 0x0040) ?
  529. (($perms & 0x0800) ? 's' : 'x' ) :
  530. (($perms & 0x0800) ? 'S' : '-'));
  531. // Group
  532. $info .= (($perms & 0x0020) ? 'r' : '-');
  533. $info .= (($perms & 0x0010) ? 'w' : '-');
  534. $info .= (($perms & 0x0008) ?
  535. (($perms & 0x0400) ? 's' : 'x' ) :
  536. (($perms & 0x0400) ? 'S' : '-'));
  537. // World
  538. $info .= (($perms & 0x0004) ? 'r' : '-');
  539. $info .= (($perms & 0x0002) ? 'w' : '-');
  540. $info .= (($perms & 0x0001) ?
  541. (($perms & 0x0200) ? 't' : 'x' ) :
  542. (($perms & 0x0200) ? 'T' : '-'));
  543. return $info;
  544. }
  545. /************
  546. * CSS FILE *
  547. ************/
  548. function sourceview_css()
  549. {
  550. header('Content-type: text/css');
  551. $css = <<<CSS
  552. html, body {
  553. padding: 0; margin: 0;
  554. height: 100%;
  555. width: 100%;
  556. }
  557. body {
  558. font-size: .9em;
  559. background: #fff;
  560. font-family: "Bitstream Vera Sans Mono", "Courier New", monospace;
  561. overflow: auto;
  562. white-space: pre;
  563. }
  564. h3 {
  565. padding: 0;
  566. margin: 25px;
  567. }
  568. a:link {
  569. color: #00bfff;
  570. font-weight: bold;
  571. text-decoration: none;
  572. }
  573. a:visited {
  574. color: #0099cd;
  575. font-weight: bold;
  576. text-decoration: none;
  577. }
  578. a:hover {
  579. color: #00b1ee;
  580. text-decoration: underline;
  581. }
  582. CSS;
  583. header('Content-length: ' . strlen($css));
  584. return $css;
  585. }
  586. if (isset($_GET['sourcecss']))
  587. {
  588. echo sourceview_css(); die();
  589. }
  590. function css_style()
  591. {
  592. header('Content-type: text/css');
  593. $css = <<<CSS
  594. body {
  595. color: #333;
  596. background: #fff;
  597. padding: 25px;
  598. font: .9em Arial, Helvetica, "Bitstream Vera Sans", Tahoma, sans-serif;
  599. text-align: center;
  600. }
  601. #wrapper {
  602. margin: 0 auto;
  603. text-align: left;
  604. }
  605. #footer {
  606. font-size: 0.7em;
  607. margin: 0 auto;
  608. padding: 15px;
  609. clear: both;
  610. }
  611. table {
  612. border-collapse: collapse;
  613. background: #fff;
  614. margin-right: 10px;
  615. width: 100%;
  616. }
  617. td {
  618. border: 1px solid #fff;
  619. padding: 5px;
  620. }
  621. .tr1 {
  622. font-size: .9em;
  623. background: #fdfdfd;
  624. border-bottom: 1px solid #eee;
  625. }
  626. .tr2 {
  627. font-size: .9em;
  628. background: #f6f6f6;
  629. border-bottom: 1px solid #eee;
  630. }
  631. #functions {
  632. padding: 20px;
  633. background: #f6f6f6;
  634. }
  635. #func_left {
  636. width: 50%;
  637. float: left;
  638. }
  639. #func_right {
  640. width: 50%;
  641. margin-left: 50%;
  642. }
  643. input {
  644. margin-bottom: 2px;
  645. }
  646. label {
  647. font-size: 1.2em;
  648. }
  649. h2 a:link, .head:link {
  650. color: #333;
  651. text-decoration: none;
  652. }
  653. h2 a:visited, .head:visited {
  654. color: #333;
  655. text-decoration: none;
  656. }
  657. h2 a:hover, .head:hover {
  658. color: #666;
  659. text-decoration: underline;
  660. }
  661. #toggle:link, .file:link {
  662. color: #1d8fff;
  663. text-decoration: none;
  664. }
  665. #toggle:visited, .file:visited {
  666. color: #1773cd;
  667. text-decoration: none;
  668. }
  669. #toggle:hover, .file:hover {
  670. color: #1b86ee;
  671. text-decoration: underline;
  672. }
  673. .dir:link {
  674. color: #00bfff;
  675. font-weight: bold;
  676. text-decoration: none;
  677. }
  678. .dir:visited {
  679. color: #0099cd;
  680. font-weight: bold;
  681. text-decoration: none;
  682. }
  683. .dir:hover {
  684. color: #00b1ee;
  685. text-decoration: underline;
  686. }
  687. .notice {
  688. background: #f6f6f6;
  689. font-size: 0.9em;
  690. text-align: center;
  691. margin: 100px auto;
  692. width: 250px;
  693. padding: 100px;
  694. }
  695. .bullet {
  696. white-space: pre;
  697. text-decoration: none;
  698. font: bold 1.1em "Bitstream Vera Sans Mono", "Courier New", monospace;
  699. }
  700. CSS;
  701. if (isset($_GET['imageview']))
  702. {
  703. $imageview = view_image($_GET['imageview']);
  704. $width = $imageview[0] < 250 ? 250 : $imageview[0];
  705. $css .= '
  706. .image {
  707. background: #f6f6f6;
  708. font-size: 0.9em;
  709. margin: 0 auto;
  710. width: ' . $width . 'px;
  711. padding: 25px;
  712. }
  713. .image img {
  714. display: block;
  715. margin: 0 auto;
  716. }
  717. .image hr {
  718. width: ' . ($width - 50) . 'px;
  719. border: 0 none;
  720. height: 1px;
  721. background: #666;
  722. margin: 15px auto;
  723. }';
  724. }
  725. header('Content-length: ' . strlen($css));
  726. return $css;
  727. }
  728. if(isset($_GET['style']))
  729. {
  730. echo css_style(); die();
  731. }
  732. /***************
  733. * View image? *
  734. ***************/
  735. if (isset($_GET['imageview']))
  736. {
  737. $imageview = view_image($_GET['imageview']);
  738. echo $imageview[4];
  739. die();
  740. }
  741. /***************
  742. * Source view *
  743. ***************/
  744. if (isset($_GET['src']))
  745. {
  746. echo sourceview($_GET['src']);
  747. die();
  748. }
  749. /*****************
  750. * Download text *
  751. *****************/
  752. if (isset($_GET['download']))
  753. {
  754. echo download($_GET['download']);
  755. die();
  756. }
  757. /**********************************************
  758. * Fill $filelist and $dirlist and print HTML *
  759. **********************************************/
  760. if (is_dir($dir))
  761. {
  762. if ($dh = @chdir($dir))
  763. {
  764. if ($dh = opendir('.'))
  765. {
  766. if (isset($_GET['submitsearch']))
  767. {
  768. if (isset($_GET['searchfile']) && !empty($_GET['searchfile']))
  769. {
  770. $filelist = search($_GET['searchfile'], $dh);
  771. $count = count($filelist);
  772. if ($filelist[0] === '.' && $filelist[1] === '..')
  773. {
  774. $status = ' &minus; search: no files found with search string: ' . $_GET['searchfile'];
  775. }
  776. }
  777. else
  778. {
  779. $status = ' &minus; search error: no search string entered';
  780. }
  781. }
  782. else
  783. {
  784. $count = 0;
  785. if (!$showhidden)
  786. {
  787. $filelist[$count++] = '.';
  788. $filelist[$count++] = '..';
  789. }
  790. while (($file = readdir($dh)) !== false)
  791. {
  792. if ($showhidden)
  793. {
  794. $filelist[$count] = $file;
  795. $count++;
  796. }
  797. else
  798. {
  799. if ($file{0} !== '.')
  800. {
  801. $filelist[$count] = $file;
  802. $count++;
  803. }
  804. }
  805. }
  806. closedir($dh);
  807. }
  808. }
  809. /***********************************
  810. * Separate directories from files *
  811. ***********************************/
  812. for ($i = 0, $h = 0; $i < $count; $i++, $h++)
  813. {
  814. if (is_dir($filelist[$i]))
  815. {
  816. $dirlist[$h] = $filelist[$i];
  817. unset($filelist[$i]);
  818. }
  819. }
  820. //-----> the $count of $filelist has changed, now using count($filelist)
  821. /***************
  822. * Alphabetize *
  823. ***************/
  824. natcasesort($filelist); // maintains key/value associations
  825. $filelist = array_values($filelist); // I don't care about associations!
  826. natcasesort($dirlist);
  827. $dirlist = array_values($dirlist);
  828. /**********************
  829. * Sorting algorithms *
  830. **********************/
  831. switch ($_GET['sort'])
  832. {
  833. case 'sizeasc':
  834. $filelist = multi_sort($filelist, 'asc', 'filesize');
  835. break;
  836. case 'sizedesc':
  837. $filelist = multi_sort($filelist, 'desc', 'filesize');
  838. break;
  839. case 'dateasc':
  840. $filelist = multi_sort($filelist, 'asc', 'filemtime');
  841. $dirlist = multi_sort($dirlist, 'asc', 'filemtime');
  842. break;
  843. case 'datedesc':
  844. $filelist = multi_sort($filelist, 'desc', 'filemtime');
  845. $dirlist = multi_sort($dirlist, 'desc', 'filemtime');
  846. break;
  847. case 'typeasc':
  848. $filelist = multi_sort($filelist, 'asc', 'get_ext');
  849. break;
  850. case 'typedesc':
  851. $filelist = multi_sort($filelist, 'desc', 'get_ext');
  852. break;
  853. default:
  854. if (empty($_GET['sort']) or
  855. $_GET['sort'] === 'nameasc' or
  856. $_GET['sort'] === 'namedesc')
  857. {
  858. /* do nothing */
  859. }
  860. else
  861. {
  862. $status = ' &minus; invalid sorting algorithm: ' . $_GET['sort'];
  863. }
  864. }
  865. /*****************************
  866. * User-intervened functions *
  867. *****************************/
  868. // Javascript hide
  869. /*
  870. $body = "\n\t\t" . '<a href="#" id="toggle" onclick="show(\'functions\');">Toggle functions</a>' .
  871. "\n\t\t" . '<div id="functions">' .
  872. "\n\t\t\t" . '<div id="func_left">' .
  873. "\n\t\t\t" . '<form method="post" action="' . $self . '" enctype="multipart/form-data">' . "\n\t\t\t\t" . '<div>' . "\n\t\t\t\t\t" . '<input type="hidden" name="MAX_FILE_SIZE" value="2097152" />' . "\n\t\t\t\t\t" . '<label >Upload file:</label><br />' . "\n\t\t\t\t\t" . '<input type="file" name="uploadfile" size="20" /><br />' . "\n\t\t\t\t\t" . '<input type="submit" value="Upload file" name="submitupload" />' . "\n\t\t\t\t" . '</div>' . "\n\t\t\t" . '</form>' .
  874. "\n\t\t\t" . '<form method="post" action="' . $self . '">' . "\n\t\t\t\t" . '<div>' . "\n\t\t\t\t\t" . '<label >Move file:</label><br />' . "\n\t\t\t\t\t" . '<input type="text" name="movesrcfile" size="28" value="' . $dir . '/" /><br />' . "\n\t\t\t\t\t" . '<input type="text" name="movedestfile" size="28" value="' . $dir . '/" /><br />' . "\n\t\t\t\t\t" . '<input type="submit" value="Move file" name="submitmove" />' . "\n\t\t\t\t" . '</div>' . "\n\t\t\t" . '</form>' .
  875. "\n\t\t\t" . '</div>' .
  876. "\n\t\t\t" . '<div id="func_right">' .
  877. "\n\t\t\t" . '<form method="get" action="' . $self . '">' . "\n\t\t\t\t" . '<div>' . "\n\t\t\t\t\t" . '<label >Search for file:</label><br />' . "\n\t\t\t\t\t" . '<input type="text" name="searchfile" size="28" /><br />' . "\n\t\t\t\t\t" . '<input type="submit" value="Search" name="submitsearch" />' . "\n\t\t\t\t" . '</div>' . "\n\t\t\t" . '</form>' .
  878. "\n\t\t\t" . '<form method="post" action="' . $self . '">' . "\n\t\t\t\t" . '<div>' . "\n\t\t\t\t\t" . '<label >Delete file:</label><br />' . "\n\t\t\t\t\t" . '<input type="text" name="delfile" size="28" value="' . $dir . '/" /><br />' . "\n\t\t\t\t\t" . '<input type="submit" value="Delete file" name="submitdel" />' . "\n\t\t\t\t" . '</div>' . "\n\t\t\t" . '</form>' .
  879. "\n\t\t\t" . '<form method="post" action="' . $self . '">' . "\n\t\t\t\t" . '<div>' . "\n\t\t\t\t\t" . '<label >Chmod file:</label><br />' . "\n\t\t\t\t\t" . '<input type="text" name="chmodsrcfile" size="23" value="' . $dir . '/" /> <input type="text" name="chmodfile" size="3" value="0644" /><br />' . "\n\t\t\t\t\t" . '<input type="submit" value="Chmod file" name="submitchmod" />' . "\n\t\t\t\t" . '</div>' . "\n\t\t\t" . '</form>' .
  880. "\n\t\t\t" . '</div>' .
  881. "\n\t\t\t" . '<div style="clear: left;"></div>' .
  882. "\n\t\t" . '</div>';
  883. */
  884. /**********************************
  885. * Start directory contents table *
  886. **********************************/
  887. $body = "\n\t\t" . '<h2><a href="' . $self . '?dir=' . $dir . '">' . $readable_dir . $status . '</a></h2>' .
  888. "\n\t\t" . '<table>' .
  889. "\n\t\t\t" . '<tr>';
  890. // SORT BY FILENAME -- LINK
  891. if ($_GET['sort'] === 'nameasc')
  892. {
  893. $body .= "\n\t\t\t\t" . '<td><a class="head" href="' . $self . '?dir=' . $dir . '&amp;sort=namedesc">Filename</a></td>';
  894. }
  895. else if ($_GET['sort'] === 'namedesc')
  896. {
  897. $body .= "\n\t\t\t\t" . '<td><a class="head" href="' . $self . '?dir=' . $dir . '&amp;sort=nameasc">Filename</a></td>';
  898. }
  899. else // Default to ascending order (it makes sense)
  900. {
  901. $body .= "\n\t\t\t\t" . '<td><a class="head" href="' . $self . '?dir=' . $dir . '&amp;sort=nameasc">Filename</a></td>';
  902. }
  903. // SORT BY FILE EXTENSION -- LINK
  904. if ($_GET['sort'] === 'typeasc')
  905. {
  906. $body .= "\n\t\t\t\t" . '<td><a class="head" href="' . $self . '?dir=' . $dir . '&amp;sort=typedesc">Filetype</a></td>';
  907. }
  908. else if ($_GET['sort'] === 'typedesc')
  909. {
  910. $body .= "\n\t\t\t\t" . '<td><a class="head" href="' . $self . '?dir=' . $dir . '&amp;sort=typeasc">Filetype</a></td>';
  911. }
  912. else // Default to ascending order (it makes sense)
  913. {
  914. $body .= "\n\t\t\t\t" . '<td><a class="head" href="' . $self . '?dir=' . $dir . '&amp;sort=typeasc">Filetype</a></td>';
  915. }
  916. // SORT BY FILESIZE -- LINK
  917. if ($_GET['sort'] === 'sizeasc')
  918. {
  919. $body .= "\n\t\t\t\t" . '<td><a class="head" href="' . $self . '?dir=' . $dir . '&amp;sort=sizedesc">Filesize</a></td>';
  920. }
  921. else if ($_GET['sort'] === 'sizedesc')
  922. {
  923. $body .= "\n\t\t\t\t" . '<td><a class="head" href="' . $self . '?dir=' . $dir . '&amp;sort=sizeasc">Filesize</a></td>';
  924. }
  925. else // Default to ascending order (it makes sense)
  926. {
  927. $body .= "\n\t\t\t\t" . '<td><a class="head" href="' . $self . '?dir=' . $dir . '&amp;sort=sizeasc">Filesize</a></td>';
  928. }
  929. // SORT BY DATE MODIFIED -- LINK
  930. if ($_GET['sort'] === 'dateasc')
  931. {
  932. $body .= "\n\t\t\t\t" . '<td><a class="head" href="' . $self . '?dir=' . $dir . '&amp;sort=datedesc">Last Modified</a></td>';
  933. }
  934. else if ($_GET['sort'] === 'datedesc')
  935. {
  936. $body .= "\n\t\t\t\t" . '<td><a class="head" href="' . $self . '?dir=' . $dir . '&amp;sort=dateasc">Last Modified</a></td>';
  937. }
  938. else // Default to ascending order (it makes sense)
  939. {
  940. $body .= "\n\t\t\t\t" . '<td><a class="head" href="' . $self . '?dir=' . $dir . '&amp;sort=dateasc">Last Modified</a></td>';
  941. }
  942. $body .= "\n\t\t\t\t" . '<td>File Permissions</td>' . // sorting by file permissions is gay
  943. "\n\t\t\t" . '</tr>';
  944. /************************************
  945. * Print directory contents in HTML *
  946. ************************************/
  947. // Directories first
  948. for ($h = 0; $h < count($dirlist); $h++)
  949. {
  950. /********************
  951. * Sort by filename *
  952. ********************/
  953. if ($h === 0 and $_GET['sort'] !== 'nameasc')
  954. {
  955. if ($_GET['sort'] === 'nameasc' or $_GET['sort'] === 'namedesc')
  956. {
  957. $z = count($dirlist) - 1;
  958. }
  959. else
  960. {
  961. $z = $h;
  962. }
  963. }
  964. else
  965. {
  966. if ($_GET['sort'] === 'namedesc')
  967. { $z--; }
  968. else { $z = $h; }
  969. }
  970. $color_number = (!isset($color_number) or $color_number === 2) ?
  971. $color_number = 1 : $color_number = 2;
  972. $body .= "\n\t\t\t" . '<tr class="tr' . $color_number . '">';
  973. if (is_dir($dirlist[$z]))
  974. {
  975. $fileperms = fileperms($dirlist[$z]);
  976. $body .= "\n\t\t\t\t" . '<td>';
  977. switch ($dirlist[$z])
  978. {
  979. case '.':
  980. $body .= "\n\t\t\t\t\t" . '<a class="bullet" title="' . $readable_dir . '">&nbsp;</a>' .
  981. "\n\t\t\t\t\t" . '<a class="dir" href="' . $self . '">.</a>';
  982. break;
  983. case '..':
  984. $body .= "\n\t\t\t\t\t" . '<a class="bullet" title="Go up a directory">&uarr;</a>' .
  985. "\n\t\t\t\t\t" . '<a class="dir" href="' . $self . '?dir=' . $dir . '&amp;up">..</a>';
  986. break;
  987. default:
  988. $body .= "\n\t\t\t\t\t" . '<a class="bullet" title="directory">&bull;</a>' .
  989. "\n\t\t\t\t\t" . '<a class="dir" href="' . $self . '?dir=' . $dir . '/' . $dirlist[$z] . '">' . $dirlist[$z] . '</a>';
  990. }
  991. $body .= "\n\t\t\t\t" . '</td>' .
  992. "\n\t\t\t\t" . '<td></td>' .
  993. "\n\t\t\t\t" . '<td></td>' .
  994. "\n\t\t\t\t" . '<td>' . date("m/d/y H:i:s", filemtime($dirlist[$z])) . '</td>' .
  995. "\n\t\t\t\t" . '<td>' . format_perms($fileperms) . ' (' . substr(sprintf('%o', $fileperms), -4) . ')</td>';
  996. }
  997. $body .= "\n\t\t\t" . '</tr>';
  998. }
  999. // Files next
  1000. for ($i = 0; $i < count($filelist); $i++)
  1001. {
  1002. /********************
  1003. * Sort by filename *
  1004. ********************/
  1005. if ($i === 0 and $_GET['sort'] !== 'nameasc')
  1006. {
  1007. if ($_GET['sort'] === 'nameasc' or $_GET['sort'] === 'namedesc')
  1008. {
  1009. $y = count($filelist) - 1;
  1010. }
  1011. else
  1012. {
  1013. $y = $i;
  1014. }
  1015. }
  1016. else
  1017. {
  1018. if ($_GET['sort'] === 'namedesc')
  1019. { $y--; }
  1020. else { $y = $i; }
  1021. }
  1022. $color_number = (!isset($color_number) or $color_number === 2) ?
  1023. $color_number = 1 : $color_number = 2;
  1024. $body .= "\n\t\t\t" . '<tr class="tr' . $color_number . '">';
  1025. if (is_file($filelist[$y]))
  1026. {
  1027. $fileperms = fileperms($filelist[$y]);
  1028. $body .= "\n\t\t\t\t" . '<td>' .
  1029. "\n\t\t\t\t\t" . '<a class="bullet" title="file">&nbsp;</a>';
  1030. if (!is_file_ext($filelist[$y], array('.gif', '.jpg', '.jpeg', '.jpe', '.png')))
  1031. {
  1032. if (is_file_ext($filelist[$y], array('.php', '.php3')))
  1033. {
  1034. $body .= "\n\t\t\t\t\t" . '<a class="file" href="' . $self . '?src=' . $dir . '/' . $filelist[$y] . '">' . $filelist[$y] . '</a>';
  1035. }
  1036. else
  1037. {
  1038. $body .= "\n\t\t\t\t\t" . '<a class="file" href="' . $dir . '/' . $filelist[$y] . '">' . $filelist[$y] . '</a>';
  1039. }
  1040. }
  1041. else
  1042. {
  1043. $body .= "\n\t\t\t\t\t" . '<a class="file" href="' . $self . '?imageview=' . $dir . '/' . $filelist[$y] . '">' . $filelist[$y] . '</a>';
  1044. }
  1045. $body .= "\n\t\t\t\t" . '</td>' .
  1046. "\n\t\t\t\t" . '<td>' . get_ext($filelist[$y]) . '</td>' .
  1047. "\n\t\t\t\t" . '<td>' . fsize_unit_convert(filesize($filelist[$y])) . '</td>' .
  1048. "\n\t\t\t\t" . '<td>' . date("m/d/y H:i:s", filemtime($filelist[$y])) . '</td>' .
  1049. "\n\t\t\t\t" . '<td>' . format_perms($fileperms) . ' (' . substr(sprintf('%o', $fileperms), -4) . ')</td>';
  1050. }
  1051. $body .= "\n\t\t\t</tr>";
  1052. }
  1053. $body .= "\n\t\t</table>";
  1054. $title = 'File Manager: ' . $readable_dir;
  1055. }
  1056. else
  1057. {
  1058. $body = "\n\t\t". '<div class="notice">' .
  1059. "\n\t\t\t" . '<p>Cannot change directory; check permissions.<p>' .
  1060. "\n\t\t\t" . '<a class="dir" href="' . $self . '">Return to index</a>' .
  1061. "\n\t\t" . '</div>';
  1062. $title = 'File Manager error: ' . $readable_dir;
  1063. }
  1064. }
  1065. else
  1066. {
  1067. $body = "\n\t\t". '<div class="notice">' .
  1068. "\n\t\t\t" . '<p>That\'s not a directory!</p>' .
  1069. "\n\t\t\t" . '<a class="dir" href="' . $self . '">Return to index</a>' .
  1070. "\n\t\t" . '</div>';
  1071. $title = 'File Manager error: ' . $readable_dir;
  1072. }
  1073. $time_end = microtime(1);
  1074. echo template($title, $self . '?style', $body, true);
  1075. ?>