Advertisement
Guest User

oo

a guest
Dec 5th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 59.33 KB | None | 0 0
  1. <?php
  2.  
  3. $ver=".024";
  4.  
  5. /*
  6. Todo:
  7. BUG: cpmv with no available dirs to cpmv to .. error.
  8. - check setroot -- needs to cover more directories.
  9. - review urlpath, path and abspath.
  10. x Create new file.
  11. - God mode - overrides filters.
  12. - Add Touch feature.
  13. - Add Waste Basket.
  14. - Reload / Refresh button.
  15. x Finish work on CpMv -- check against block lists
  16. */
  17.  
  18. /************************************************************************************/
  19. /* Simple Web File Manager */
  20. /* Allows viewing, editing, renaming and deleting of files within a limited */
  21. /* directory scope. */
  22. /* */
  23. /* This is an alpha copy for development and testing only. */
  24. /* Copyright (C) 2003 Lee Herron - All rights reserved. */
  25. /* Web Site: http://onedotoh.sourceforge.net */
  26. /* Email: lee_herron@users.sourceforge.net */
  27. /* */
  28. /* This program is free software; you can redistribute it and/or */
  29. /* modify it under the terms of the GNU General Public License */
  30. /* as published by the Free Software Foundation; either version 2 */
  31. /* of the License, or (at your option) any later version. */
  32. /* */
  33. /* This program is distributed in the hope that it will be useful, */
  34. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  35. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  36. /* GNU General Public License for more details. */
  37. /* */
  38. /* You should have received a copy of the GNU General Public License */
  39. /* along with this program; if not, write to the Free Software */
  40. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  41. /* License information can also be found at: http://www.gnu.org/copyleft/gpl.html */
  42. /* */
  43. /* This program is built on the original QTOFileManager. */
  44. /* Copyright (C) 2001 Quentin O'Sullivan <quentin@qto.com> All rights reserved. */
  45. /* Web Site: http://www.qto.com/fm */
  46. /************************************************************************************/
  47.  
  48.  
  49.  
  50. /***************** USER CONFIGURATIONS **********************************************/
  51. /************************************************************************************/
  52.  
  53. /*/ set these configuration variables /*/
  54.  
  55. // change this to the username you would like to use.
  56. // leave it empty if you dont want to use authentication
  57. $user = "guest";
  58. $pass = "demo";
  59.  
  60. // currently nonfunctional
  61. $guser = "god"; // God mode overrides filename filters
  62. $gpass = "mypass";
  63.  
  64.  
  65. /**** Limits, Settings and Filters ****/
  66.  
  67. // Limit amount of harddrive space and size of file to upload.
  68. $MaxFileSize = "20480"; // max file size in bytes
  69. $HDDSpace = "1048576"; // max total size of all files in directory
  70.  
  71. // make this = 0 if you dont want to be able to make directories
  72. $MakeDirOn = 1;
  73.  
  74. // add any file names to this array which should remain invisible
  75. $HiddenFiles = array("fm_files",".htaccess","fmstyle.css");
  76.  
  77. // make this = 0 if you dont want the to use the edit function at all
  78. $EditOn = 1;
  79.  
  80. // add the extensions of file types that you would like to be able to edit
  81. $EditExtensions = array("htm","html","txt","php","css");
  82.  
  83. // Sort default 0 = Filename / 1 = Size / 2 = Last Modified / 3 = File Type
  84. $sortdefault = 2;
  85.  
  86. // Allow new file creation.
  87. $CreateFileOn = 1;
  88.  
  89. // add extensions of file types allowed to create.
  90. $NewFileTypes = array("txt","html");
  91.  
  92. // add extensions of file types you want "turned off"
  93. $ExtensionsOFF = array("php","cgi","php4","php3","pl","js");
  94.  
  95. // add files that shall not be uploaded, copied over, renamed or deleted.
  96. $ModifyBlock = array("readme.txt","COPYING",".htaccess","fm.php","fmstyle.css","docs","history.txt");
  97.  
  98.  
  99.  
  100. // add names of directories that DO NOT ALLOW UPLOADS.
  101. $NoUploadDirs = array("docs/");
  102.  
  103. // add names of directories that DO NOT ALLOW DIRECTORY CREATION.
  104. $NoCreateDirs = array("docs/");
  105.  
  106. // add characters to strip out of filenames
  107. $snr = array("%","'","+","\\","/","#","..","!",'"',',','?','*','~');
  108.  
  109. /**** Directory Definitions and Paths ****/
  110.  
  111. // Set path and name for MyLink (displayed at top right
  112. // mylink is relative to domain - if /bob is defined, then the link will be
  113. // http://www.domain.com/bob -- mylinkname is the link display text.
  114.  
  115. $mylink = "http://sourceforge.net/projects/onedotoh/";
  116. $mylinkname = "OurProject";
  117.  
  118. // ** Notes: SFM can be configured in one of two ways:
  119. // ** 1. Drop-In: path used is based on script location,
  120. // ** setting for this mode is: defineroot=0
  121. // ** 2. Defined Root: path is defined to a location away
  122. // ** from script location. Setting: defineroot=1
  123. // ** and directory information *MUST* be set.
  124.  
  125. // Define root path (1=On 0=Off)
  126. // Off only gives access to the directory you place sfm within.
  127.  
  128. $defineroot = 0;
  129.  
  130. /* Define root path required only if defineroot=1 */
  131. // sfm allows for you to limit and/or define the directory that it
  132. // has access to, that is; it can be placed in a specific directory
  133. // and give access to that directory alone or you can give it access
  134. // to directories defined below and it will only have access to those
  135. // directories.
  136.  
  137. // if you chose to give access to directories outside of directory
  138. // sfm is in, then define vars below and set DEFINEROOT=0.
  139.  
  140. // This is rudamentry at best. Add an element to the following for
  141. // each directory you want to allow file management access.
  142. //
  143. // $dir[?] = path to directory [end with slash /]
  144. // $dirroot[?] = Label for Directory (display only)
  145. // $dirpath[?] = public label for path (display only)
  146. //
  147. // $nav[?] = actual link navigation strings */
  148. // if this is dir[1] then copt=1, etc
  149. // example: <a href="fm.php?copt=1">Note files</a> | Test files';
  150. //
  151. /* Directory 7: */
  152. //$dir[7]='/html/test/';
  153. //$dirroot[7]='Test';
  154. //$dirpath[7]='/test/';
  155. //$nav[7]='<a href="fm.php?u=$u&copt=7">Note files</a> | Test files';
  156.  
  157.  
  158. /* Directory 1: */
  159. $dir[1]='/var/www/html/test/';
  160. $dirroot[1]='Test';
  161. $dirpath[1]='/test/';
  162. $nav[1]='<a href="fm.php?u=$u&copt=2">Note files</a> | Test files';
  163.  
  164. /* Directory 2: */
  165. $dir[2]='/var/www/html/notes/yesterdays/';
  166. $dirroot[2]='Notes';
  167. $dirpath[2]='/notes/yesterdays/';
  168. $nav[2]='Note files | <a href="fm.php?u=$u&copt=1">Test files</a>';
  169.  
  170.  
  171. /************************************************************************************/
  172. /***************** END OF USER CONFIGURATIONS ***************************************/
  173.  
  174.  
  175.  
  176. /** Globals OFF 4.2+ Support - thanks to apz for this patch **/
  177. if (ini_get('register_globals') < 1) {
  178. $PHP_SELF = $_SERVER['PHP_SELF'];
  179. if (isset($_REQUEST['u'])) { $u = $_REQUEST['u']; }
  180. else { $u = ""; }
  181. if (isset($_REQUEST['login'])) { $login = $_REQUEST['login']; }
  182. else { $login = ""; }
  183. if (isset($_REQUEST['password'])) { $password = $_REQUEST['password']; }
  184. else { $password = ""; }
  185. if (isset($_REQUEST['pathext'] )) { $pathext = $_REQUEST['pathext']; }
  186. else { $pathext = ""; }
  187. if (isset($_REQUEST['sortKey'] )) { $sortKey = $_REQUEST['sortKey']; }
  188. else { $sortKey = $sortdefault; }
  189. if (isset($_REQUEST['copt'])) { $copt = $_REQUEST['copt']; }
  190. else { $copt = ""; }
  191. if (isset($_REQUEST['cpmvname'] )) { $cpmvname = $_REQUEST['cpmvname']; }
  192. else { $cpmvname = ""; }
  193. if (isset($_REQUEST['action'] )) { $action = $_REQUEST['action']; }
  194. else { $action = ""; }
  195. if (isset($_REQUEST['mc2path'] )) { $mc2path = $_REQUEST['mc2path']; }
  196. else { $mc2path = ""; }
  197. if (isset($_REQUEST['cmtcpmv'] )) { $cmtcpmv = $_REQUEST['cmtcpmv']; }
  198. else { $cmtcpmv = ""; }
  199. if (isset($_REQUEST['cancel'] )) { $cancel = $_REQUEST['cancel']; }
  200. else { $cancel = ""; }
  201. if (isset($_REQUEST['rename'] )) { $rename = $_REQUEST['rename']; }
  202. else { $rename = ""; }
  203. if (isset($_REQUEST['delete'] )) { $delete = $_REQUEST['delete']; }
  204. else { $delete = ""; }
  205. if (isset($_REQUEST['changename'] )) { $changename = $_REQUEST['changename']; }
  206. else { $changename = ""; }
  207. if (isset($_REQUEST['targetname'] )) { $targetname = $_REQUEST['targetname']; }
  208. else { $targetname = ""; }
  209. if (isset($_REQUEST['oldname'] )) { $oldname = $_REQUEST['oldname']; }
  210. else { $oldname = ""; }
  211. if (isset($_REQUEST['upload'] )) { $upload = $_REQUEST['upload']; }
  212. else { $upload = ""; }
  213. if (isset($_REQUEST['savenew'] )) { $savenew = $_REQUEST['savenew']; }
  214. else { $savenew = ""; }
  215. if (isset($_REQUEST['newfilename'] )) { $newfilename = $_REQUEST['newfilename']; }
  216. else { $newfilename = ""; }
  217. if (isset($_REQUEST['newfileext'] )) { $newfileext = $_REQUEST['newfileext']; }
  218. else { $newfileext = ""; }
  219. }
  220.  
  221.  
  222. $ThisFileName = basename(__FILE__); // get the file name
  223. $abspath = str_replace($ThisFileName,"",__FILE__); // get the directory path
  224.  
  225. // full path
  226. $path=$abspath;
  227.  
  228. // Installed dir only - relative path.
  229. $relpath = dirname($PHP_SELF).'/';
  230.  
  231. if (ereg("\.\./", $pathext)) {
  232. $hack="<font color=red><b>HACK ATTEMPT - SysOp Notified</b></font><p>";
  233. $pathext="";
  234. }
  235. if ($defineroot==1) {
  236. setroot($vpath);
  237. }
  238. else {
  239. $copt=1;
  240. $dir[1]=$path;
  241. $dirroot[1]='Demo';
  242. $dirpath[1]=$path;
  243. $dirpath[1]="/demo/";
  244. $nav[1]="<a href=\"$PHP_SELF?u=$u&sortKey=$sortKey\">Home</a>";
  245. }
  246.  
  247. /* Initialized Varibles */
  248. $navbar ="<font face=verdana size=1>$nav[$copt]</font>";
  249. $HDDTotal = dirsize($path);
  250. $HDDTotalABR = setsize($HDDTotal);
  251. $HDDSpaceABR = setsize($HDDSpace);
  252. $freespaceABR = setsize($HDDSpace - $HDDTotal); // work out how much free space is left
  253. $MaxFileSizeABR = setsize($MaxFileSize);
  254.  
  255.  
  256.  
  257. if ($login) {
  258. if(!($u == $user && $password == $pass)) {
  259. $msg = "<font face='Verdana, Arial, Hevetica' size='2' color='#ff0000'>The login details were incorrect</font><p>";
  260. $loginfailed = 1;
  261. }
  262. }
  263. if ($user == $u) {
  264. $navbar .= "<font face=verdana size=1> | <a href=\"$PHP_SELF\">logout</a></font>";
  265. }
  266. if ($back) {
  267. $pathext = substr($pathext, 0, -1);
  268. $slashpos = strrpos($pathext, "/");
  269. if($slashpos == 0) {
  270. $pathext = "";
  271. }
  272. else {
  273. $pathext = substr($pathext, 0, ($slashpos+1));
  274. }
  275. }
  276. /* Rename item was select / create form */
  277. if (($user == $u || $user == "") && $rename) {
  278. $filemanager = renform();
  279. }
  280. /* if an Create new file button was clicked */
  281. elseif (($user == $u || $user == "") && $createfile) {
  282. $filemanager = newfileedit();
  283. }
  284. /* if an edit link was clicked */
  285. elseif(($user == $u || $user == "") && $edit) {
  286. $filemanager = ascedit($edit);
  287. }
  288. elseif(($user == $u || $user == "") && $cpmv) {
  289. $filemanager = cpmvform($cpmv);
  290. }
  291. /* if a TXT file link was clicked */
  292. elseif ($action == 'viewascii') {
  293. $filemanager = viewascii();
  294. }
  295. /* if an IMAGE file link was clicked */
  296. elseif ($action == 'view') {
  297. $filemanager = viewimage();
  298. }
  299. elseif (($user == $u || $user == "") && !$loginfailed) {
  300.  
  301. /* if the save button was pressed on the edit screen */
  302. if($save) {
  303. $newcontent = stripslashes($newcontent);
  304. $fp = @fopen($path.$pathext.$savefile, "w");
  305. if ($fp) {
  306. fwrite($fp, $newcontent);
  307. fclose($fp);
  308. }
  309. else {
  310. $msg = "<font color=red>Write Permissions Not Available</font><p>";
  311. }
  312. }
  313. /* if the save new file button was pressed on the edit screen */
  314. if ($savenew) {
  315.  
  316. if ($newfilename!="") {
  317.  
  318. $newfilename = trim($newfilename).trim($newfileext);
  319. $newfilename = strip_tags($newfilename);
  320. $newfilename = str_replace($snr,"",$newfilename);
  321.  
  322. if (OffFile($newfilename)) { $newfilename = $newfilename.'.off'; }
  323. if (TargetOK($newfilename)) { $go1=1; }
  324. if (UpPathOK($pathext)) { $go2=1; }
  325.  
  326. if ($go1+$go2==2) {
  327. if (!file_exists($path.$pathext.$newfilename)) {
  328. $msg = "new file created named: $newfilename<hr>";
  329. $nfh = fopen ($path.$pathext.$newfilename, "w");
  330. fwrite($nfh,$newcontent);
  331. fclose($nfh);
  332. }
  333. }
  334. else {
  335. if ($go1==0) { $msg = "Filename: $newfilename is blocked from use.<hr>"; }
  336. if ($go2==0) { $msg = "This directory does not allow new file creation.<hr>"; }
  337. }
  338.  
  339. $go1="";$go2="";
  340. }
  341. else { $msg = "No new filename entered<hr>"; }
  342. }
  343. /* If the rename link was clicked */
  344. if ($changename) {
  345.  
  346. $targetname = strip_tags ( $targetname);
  347. $targetname = str_replace($snr,"",$targetname);
  348. $nname = trim($targetname);
  349.  
  350. // Change name of existing file Okay?
  351.  
  352. // Modify this file okay?
  353. if (TargetOK($oldname)) { $go1=1; }
  354.  
  355. // Is New name Okay?
  356. if (TargetOK($nname)) { $go2=1; }
  357.  
  358. // Is it okay to rename this Extension?
  359. if (OffFile($oldname)) { $go2="0"; }
  360. if (OffFile($nname)) { $go2="0"; }
  361.  
  362. if ($go1+$go2==2) {
  363. $renamed = @rename ($path.$pathext."$oldname", $path.$pathext."$nname");
  364. if($renamed<1) { $msg="<font face='Verdana, Arial, Hevetica' size='2' color='#ff0000'>Rename process FAILED!</font><p>"; }
  365. }
  366. else {
  367. if ($go1==0) { $whichname="Existing file"; $effectedname=$oldname; }
  368. if ($go2==0) { $whichname="Target filenme"; $effectedname=$nname; }
  369. $msg = "<font face='Verdana, Arial, Hevetica' size='2' color='#ff0000'>The $whichname: $effectedname has been BLOCKED from this action.</font><p>";
  370. }
  371. }
  372.  
  373. /* If CpMv Form was submitted */
  374. if($cmtcpmv) {
  375. if ($mc2path=="/") { $mc2path=""; }
  376. if ($action=='copy') {
  377. $cm_result = copy($path.$pathext.$cpmvname, $path.$mc2path.$cpmvname);
  378. $cpmvaction="Copied";
  379. }
  380. else {
  381. $cm_result = copy($path.$pathext.$cpmvname, $path.$mc2path.$cpmvname);
  382. unlink($path.$pathext.$cpmvname);
  383. $cpmvaction="Moved";
  384. }
  385.  
  386. if ($cm_result==1) {
  387. $msg="<table>
  388. <tr><td align=right>$cpmvaction:</td><td>$relpath$pathext$cpmvname</td></tr>
  389. <tr><td align=right>to:</td><td>$relpath$mc2path</td></tr></table><br>";
  390. }
  391. else {$msg="error in copy/move";}
  392. }
  393.  
  394.  
  395. $HDDTotal = dirsize($path); // get the total size of all files in the directory including any sub directorys
  396. /* if the upload button was pressed */
  397. if ($upload) {
  398.  
  399. /* if a file was actually uploaded */
  400. if($HTTP_POST_FILES['uploadedfile']['name']) {
  401. $HTTP_POST_FILES['uploadedfile']['name'] = strip_tags ($HTTP_POST_FILES['uploadedfile']['name']);
  402. $HTTP_POST_FILES['uploadedfile']['name'] = str_replace($snr,"",$HTTP_POST_FILES['uploadedfile']['name']); // remove any % signs from the file name
  403. $HTTP_POST_FILES['uploadedfile']['name'] = trim($HTTP_POST_FILES['uploadedfile']['name']);
  404.  
  405. /* if the file size is within allowed limits */
  406. if($HTTP_POST_FILES['uploadedfile']['size'] > 0 && $HTTP_POST_FILES['uploadedfile']['size'] < $MaxFileSize) {
  407.  
  408. /* if adding the file will not exceed the maximum allowed total */
  409. if(($HDDTotal + $HTTP_POST_FILES['uploadedfile']['size']) < $HDDSpace) {
  410. if (TargetOK($HTTP_POST_FILES['uploadedfile']['name'])==1) {
  411. if (OffFile($HTTP_POST_FILES['uploadedfile']['name'])) {
  412. $OffExt=".off";
  413. }
  414. /* put the file in the directory */
  415. move_uploaded_file($HTTP_POST_FILES['uploadedfile']['tmp_name'], $path.$pathext.$HTTP_POST_FILES['uploadedfile']['name'].$OffExt);
  416. }
  417. else {
  418. $msg = "<font face='Verdana, Arial, Hevetica' size='2' color='#ff0000'>The Filename: ".$HTTP_POST_FILES['uploadedfile']['name']." is BLOCKED from being uploaded here.</font><p>";
  419. }
  420. }
  421. else {
  422. $msg = "<font face='Verdana, Arial, Hevetica' size='2' color='#ff0000'>There is not enough free space and the file could<br>not be uploaded.</font><p>";
  423. }
  424. }
  425. else {
  426. $MaxKB = setsize($MaxFileSize); // show the max file size in Kb
  427. $msg = "<font face='Verdana, Arial, Hevetica' size='2' color='#ff0000'>The file was greater than the maximum allowed<br>file size of $MaxKB and could not be uploaded.</font><p>";
  428. }
  429. }
  430. else {
  431. $msg = "<font face='Verdana, Arial, Hevetica' size='2' color='#ff0000'>Please press the browse button and select a file<br>to upload before you press the upload button.</font><p>";
  432. }
  433. }
  434. /* if the delete button was pressed */
  435. elseif($delete) {
  436. // Ok2Edit
  437. if (TargetOK($delete)) {
  438. /* delete the file or directory */
  439. if(is_dir($path.$pathext.$delete)) {
  440. $result = @rmdir($path.$pathext.$delete);
  441. if($result == 0) {
  442. $msg = "<font face='Verdana, Arial, Hevetica' size='2' color='#ff0000'>The folder could not be deleted. The folder must be<br>empty before you can delete it. You also may<br>not be authorised to delete this folder.</font><p>";
  443. }
  444. }
  445. else {
  446. unlink($path.$pathext.$delete);
  447. }
  448. }
  449. else {
  450. $msg = "<font face='Verdana, Arial, Hevetica' size='2' color='#ff0000'>Deleting file: $delete is a BLOCKED action.</font><p>";
  451. }
  452. }
  453. elseif($mkdir && $MakeDirOn) {
  454. $dirname = strip_tags ( $dirname);
  455. $dirname = str_replace($snr,"",$dirname);
  456. $dirname = trim($dirname);
  457. if (TargetOK($dirname)) {
  458. $result = mkdir($path.$pathext.$dirname, 0777);
  459. if(!$result) {
  460. $msg = "<font face='Verdana, Arial, Hevetica' size='2' color='#ff0000'>The folder could not be created. Make sure the name you<br>entered is a valid folder name.</font><p>";
  461. }
  462. }
  463. else {
  464. $msg = "<font face='Verdana, Arial, Hevetica' size='2' color='#ff0000'>Creating Directory: $dirname is a BLOCKED action.</font><p>";
  465. }
  466. }
  467.  
  468. // If download initiate then progress to directory list.
  469. if ($action == 'download') {
  470. $filedata = stat($path.$pathext.$filename); // get some info about the file
  471. $filesize = $filedata[7]; // size in bytes
  472. $ft = getfiletype("$filename");
  473. header("Content-Type: $ft[1]");
  474. header("Content-Length: $filesize");
  475. header("Content-Disposition: attachment; filename=$filename");
  476. readfile($path.$pathext.$filename);
  477. exit;
  478. }
  479.  
  480. $freespace = ($HDDSpace - $HDDTotal); // work out how much free space is left
  481. $freespace = setsize($freespace); // convert to size abbreviation.
  482. $HDDSpace = setsize($HDDSpace); // convert to size abbreviation.
  483.  
  484. /* if $MakeDirOn has been set to on show some html for making directories */
  485. if($MakeDirOn) {
  486. if (CreateDirOK($pathext)) {
  487. $mkdirhtml = "<input class=altButton type=\"text\" name=\"dirname\" size=\"15\"> <input class=altButton type=\"submit\" name=\"mkdir\" value=\"Make Folder\">";
  488. }
  489. else {
  490. $mkdirhtml = '<span class=smallblack>[ Direction Creation not permitted here ]</span>';
  491. }
  492. }
  493. if ($CreateFileOn) {
  494. if (UpPathOK($pathext)) {
  495. $createfilehtml = "<input class=altButton type=\"submit\" name=\"createfile\" size=\"15\" value=\" * \">";
  496. }
  497. else {
  498. $createfilehtml = "--";
  499. }
  500. }
  501.  
  502. if (UpPathOK($pathext)) {
  503. $uploadfield =<<<endupform
  504. <input type="hidden" name="MAX_FILE_SIZE" value="$MaxFileSize">
  505. <input type="hidden" name="copt" value="$copt">
  506. <input class=altButton type="file" name="uploadedfile"><input class=altButton type="submit" name="upload" value="Upload">
  507. <input type="hidden" name="u" value="$u">
  508. <input type="hidden" name="pathext" value="$pathext">
  509. <input type="hidden" name=sortKey value="$sortKey">
  510. endupform;
  511. }
  512. else {
  513. $uploadfield = '<span class=smallblack>[ Uploads not permitted here ]</span>';
  514. }
  515.  
  516. /*
  517. Build the html that makes up the file manager. The
  518. $filemanager variable holds the first part of the
  519. html including the form tags and the top 2 heading
  520. rows of the table which dont display files.
  521. */
  522.  
  523. $filemanager=makheader();
  524.  
  525.  
  526. /* if the current directory is a sub directory
  527. show a back link to get back to the previous directory */
  528.  
  529. if($pathext) {
  530. $filemanager .= <<<content
  531. <tr>
  532. <td bgcolor="#ffffff" align=center><img src="fm_files/parent.gif" width="20" height="20" border=0></td><td>&nbsp;<a href="$PHP_SELF?u=$u&back=1&sortKey=$sortKey&pathext=$pathext&copt=$copt"><font face="Verdana, Arial, Helvetica" size="2" color="#666666">&laquo;BACK</font></a>&nbsp;</td>
  533. <td bgcolor="#ffffff"></td><td></td><td bgcolor="#ffffff"></td><td></td><td bgcolor="#ffffff"></td><td></td>
  534. </tr>
  535. <tr>
  536. <td height="1" bgcolor="#000000" colspan=8></td>
  537. </tr>
  538. content;
  539. }
  540.  
  541. /* Build the table rows which contain the file information */
  542. $newpath = substr($path.$pathext, 0, -1); // remove the forward or backwards slash from the path
  543. if ($dir = @opendir($newpath)) {
  544. /* loop once for each name in the directory */
  545. $fc=0;
  546. while($file = readdir($dir)) {
  547. $match="1";
  548. // if the name is not a directory and the name is not the name of this program file
  549. if($file != "." && $file != ".." && $file != "$ThisFileName") {
  550. $match = 0;
  551. }
  552. if (!hidecheck($file)) { $match=1; }
  553. // if there were no matches the file should not be hidden
  554. if(!$match) {
  555. $filedata = stat($newpath.'/'.$file); // get some info about the file
  556. $fileattrib[$fc][0] = $file;
  557. $fileattrib[$fc][1] = $filedata[7]; // size in bytes
  558. $fileattrib[$fc][2] = $filedata[9]; // time of last modification
  559. $fileattrib[$fc][5] = date("m/d/Y h:i:sA",$filedata[9]);
  560. if (is_dir($newpath.'/'.$file)) { $fileattrib[$fc][3]="Folder"; }
  561. else {
  562. $ft=getfiletype($file);
  563. $fileattrib[$fc][3]=$ft[0]; // TYPE
  564. $fileattrib[$fc][4]=$ft[1]; // Download or Browse
  565. //$fileattrib[$fc][3]=getfiletype($file);
  566. }
  567. $fc++;
  568. }
  569. }
  570. }
  571. else {
  572.  
  573. $patherror="<p><center><font face=\"Verdana, Arial, Hevetica\" size=\"3\" color=red><b>directory incorrectly defined</b></font></center></p>";
  574. }
  575.  
  576. /* Sort Keys *//*
  577. 0 = Filename
  578. 1 = Size
  579. 2 = Last Modified
  580. 3 = File Type
  581. */
  582.  
  583. if ($sortKey=="") { $sortKey="$sortdefault"; }
  584. if (count($fileattrib)>1) { usort( $fileattrib, "myCompare" ); }
  585.  
  586. /*/ Build Table Data List /*/
  587. for($i = 0; $i < (count($fileattrib)); $i++) {
  588.  
  589. $file=$fileattrib[$i][0];
  590. $filetype=$fileattrib[$i][3];
  591.  
  592. // create some html for a link to delete, rename and edit files
  593. if (TargetOK($file)) {
  594. $deletelink = "<a href=\"$PHP_SELF?delete=$file&copt=$copt&sortKey=$sortKey&u=$u&pathext=$pathext\" title=\"DELETE $file\"><font face=\"Verdana, Arial, Helvetica\" size=\"1\" color=\"#FF0033\"><b>DEL</b></font></a>";
  595. if ($filetype=="OFF") {
  596. $renamelink="---";
  597. }
  598. else {
  599. $renamelink = "<a href=\"$PHP_SELF?rename=$file&copt=$copt&sortKey=$sortKey&u=$u&pathext=$pathext\" title=\"Rename $file\"><font face=\"Verdana, Arial, Helvetica\" size=\"1\" color=\"#666666\">REN</font></a>";
  600. }
  601. }
  602. else {
  603. $deletelink = "---";
  604. $renamelink = "---";
  605. }
  606.  
  607. // find out if the file is one that can be edited
  608. $editlink = "---";
  609.  
  610. // if the edit function is turned on and the file is not a directory
  611. if($EditOn && $filetype != "Folder") {
  612. if (Ok2Edit($fileattrib[$i][3])) {
  613. if (TargetOK($file)) {
  614. $editlink = "<a href=\"$PHP_SELF?edit=$file&u=$u&copt=$copt&pathext=$pathext\"><font face='Verdana, Arial, Helvetica' size='1' color='#666666' title=\"Edit $file\"><b>EDIT</b></font></a>";
  615. }
  616. else {
  617. $editlink = "---";
  618. }
  619. }
  620. }
  621.  
  622. // copy/move link creation
  623. $cpmv="---";
  624. if ($filetype != "Folder" && TargetOK($file)) {
  625. $cpmv = "<a class=5c title=\"Copy or Move $file\" href=\"$PHP_SELF?cpmv=$file&u=$u&copt=$copt&pathext=$pathext\"><font face='Verdana, Arial, Helvetica' size='1' color='#666666'><b>CpMv</b></font></a>";
  626. }
  627.  
  628.  
  629. $iconlinks = geticon($fileattrib[$i][3],$fileattrib[$i][5]);
  630.  
  631. $fileicon=$iconlinks[0];
  632. $filename=$iconlinks[1];
  633.  
  634. $nsize=setsize($fileattrib[$i][1]);
  635. $content .= <<<content
  636. <tr>
  637. <td bgcolor="#ffffff" width=26 align=center>$fileicon</td>
  638. <td width=55%>&nbsp;<font face="Verdana, Arial, Helvetica" size="2">$filename</font>&nbsp;</td>
  639. <td bgcolor="#ffffff" class=smallblack align=right><nobr>&nbsp;$nsize&nbsp;</nobr></td>
  640. <td align=center><font face="Verdana, Arial, Helvetica" size="1">$filetype</font></td>
  641. <td bgcolor="#ffffff" align=center>&nbsp;$editlink&nbsp;</td>
  642. <td align=center>&nbsp;$cpmv&nbsp;</td>
  643. <td bgcolor="#ffffff" align=center>&nbsp;$renamelink&nbsp;</td>
  644. <td align=center>&nbsp;$deletelink&nbsp;</td>
  645. </tr>
  646. <tr>
  647. <td height="1" colspan=8 bgcolor="#808080"><img src="fm_files/spacer.gif" width="1" height="1" border=0 alt=""></td>
  648. </tr>
  649. content;
  650.  
  651. }
  652.  
  653. if ($nofiles==1) { $nf="<font face=\"Verdana, Arial, Helvetica\" size=2>Folder is Empty</font>"; }
  654. $content .= "</table>"; // add some closing tags to the $content variable
  655. $filemanager .= $content; // append the html to the $filemanager variable
  656. }
  657. else {
  658. $filemanager = <<<content
  659. <center><br>
  660. <font face="Verdana, Arial, Hevetica" size="2" color=red>Online Demo<br>User: guest / Pass: demo</font><p>
  661. <table cellspacing=0 cellpadding=1 border=0><tr><td bgcolor=black>
  662. <table bgcolor="#ffffff" border="0" cellspacing="0" cellpadding="4" width=353 background="fm_files/bg_lock.jpg">
  663. <tr>
  664. <td colspan=2 align=center>
  665. <font face="Verdana, Arial, Hevetica" size="4" color="#333333"><b>Simple File Manager - Login</b></font><br>
  666. <form name="form1" method="post" action="$PHP_SELF"> $msg
  667. </td>
  668. </tr>
  669. <tr>
  670. <td align=right><font face="Verdana, Arial, Hevetica" size="2"><b>User Name:</b></font></td>
  671. <td align=left><input class=altButton type="text" name="u" value="$user"></td>
  672. </tr>
  673. <tr>
  674. <td align=right><font face="Verdana, Arial, Hevetica" size="2"><b>Password:</b></font></td>
  675. <td align=left><input class=altButton type="password" name="password"></td>
  676. </tr>
  677. <tr><td colspan=2 align=center><input class=altButton type="submit" name="login" value="Login"></td></tr>
  678. </form>
  679. </table></td></tr></table><br>
  680. </center>
  681. content;
  682. }
  683.  
  684.  
  685. /* Check if Dir has MakDir permissions */
  686. function CreateDirOK($chkpath) {
  687. global $NoCreateDirs;
  688. $okay=1;
  689. foreach($NoCreateDirs as $name) {
  690. // check the name against no create dir list
  691. if($chkpath == $name) {
  692. $okay = ""; // unset if not okay
  693. }
  694. }
  695. return $okay;
  696. }
  697.  
  698.  
  699. /* Check if Dir has Upload permissions */
  700. function UpPathOK($chkpath) {
  701. // checks with no trailing slash
  702. global $NoUploadDirs;
  703. $okay=1;
  704. foreach($NoUploadDirs as $name) {
  705. // check the name against no upload dir list
  706. if($chkpath == $name) {
  707. $okay = ""; // unset if not okay
  708. }
  709. }
  710. return $okay;
  711.  
  712. }
  713.  
  714.  
  715. /* Sort Routine */
  716. function myCompare( $arrayA, $arrayB ){
  717. global $sortKey;
  718. if( $arrayA[$sortKey] == $arrayB[$sortKey] )
  719. return 0;
  720. return( $arrayA[$sortKey] < $arrayB[$sortKey] ? -1 : 1 );
  721. }
  722.  
  723.  
  724. /* calculate the size of files in $dir */
  725. function dirsize($dir) {
  726. $size = -1;
  727. if ($dh = @opendir($dir)) {
  728. while (($file = readdir($dh)) !== false) {
  729. if ($file != "." and $file != "..") {
  730. $path = $dir."/".$file;
  731. if (is_dir($path)) {
  732. $size += dirsize("$path/");
  733. }
  734. elseif (is_file($path)) {
  735. $size += filesize($path);
  736. }
  737. }
  738. }
  739. closedir($dh);
  740. }
  741. return $size;
  742. }
  743.  
  744. function setsize ($size) {
  745.  
  746. // Setup some common file size measurements.
  747. $kb = 1024; // Kilobyte
  748. $mb = 1024 * $kb; // Megabyte
  749. $gb = 1024 * $mb; // Gigabyte
  750. $tb = 1024 * $gb; // Terabyte
  751.  
  752. /* If it's less than a kb we just return the size, otherwise we keep going until
  753. the size is in the appropriate measurement range. */
  754. if($size < $kb) {
  755. return $size." B";
  756. }
  757. else if($size < $mb) {
  758. return round($size/$kb,2)." KB";
  759. }
  760. else if($size < $gb) {
  761. return round($size/$mb,2)." MB";
  762. }
  763. else if($size < $tb) {
  764. return round($size/$gb,2)." GB";
  765. }
  766. else {
  767. return round($size/$tb,2)." TB";
  768. }
  769. }
  770.  
  771. function renform() {
  772. global $rnaction,$oldname,$rename,$u,$sortKey,$pathext,$PHP_SELF;
  773. $filemanager = makbar();
  774. $filemanager .= <<<content
  775. <tr><td align=center colspan=3>
  776. <form name="form1" method="post" action="$PHP_SELF">
  777. <input type="hidden" name=rnaction value=1>
  778. <input type="hidden" name=oldname value="$rename">
  779. <input type="hidden" name=u value="$u">
  780. <input type="hidden" name=sortKey value="$sortKey">
  781. <input type="hidden" name=pathext value="$pathext">
  782. <center>
  783. <table border=0 width=100>
  784. <tr><td class=normalred>Rename: </td><td class=normalblack>$rename</td></tr>
  785. <tr><td align=right class=normalred>to: </td><td><input class=altButton type="text" name="targetname"></td></tr>
  786. <tr><td align=right></td><td><input class=altButton type="submit" name="changename" value="Rename"><input class=altButton type="submit" name="cancel" value="Cancel"></td></tr>
  787. </table>
  788. </form>
  789. </td>
  790. </tr>
  791. </table>
  792. </center>
  793. content;
  794. return $filemanager;
  795. }
  796.  
  797. function cpmvform($t) {
  798. global $rootdir,$PHP_SELF,$pathext,$path,$relpath,$u;
  799. $options = makdiroptions(listdir($path,0));
  800. $filemanager .= makbar();
  801. $filemanager .= <<<content
  802. <tr><td colspan=3><hr></td></tr>
  803. <tr><td colspan=3 align=center>
  804.  
  805. <table cellpadding=0 cellspacing=3 border=0><tr><form method=post action="$PHP_SELF">
  806. <input type="hidden" name="cpmvname" value="$t"><input type="hidden" name="pathext" value="$pathext">
  807. <td class=normalblack align=right>Action: </td><td>&nbsp;</td><td class=normalblack><input type="radio" name="action" checked value="copy"> <b>copy</b> <input type="radio" name="action" value="move"> <b>move</b></td></tr>
  808. <tr><td class=normalblack align=right>Filename:</td><td>&nbsp;</td><td class=normalblack>&nbsp;<b>$t</b></td></tr>
  809. <tr><td class=normalblack align=right>from:</td><td>&nbsp;</td><td class=normalblack>&nbsp;$relpath$pathext</td></tr>
  810. <tr><td class=normalblack align=right>to:</td><td>&nbsp;</td><td class=normalblack>&nbsp;<select class=altButton name="mc2path">$options</select></td></tr>
  811. <tr><td colspan=3 align=center><input class=altButton type="submit" name="cmtcpmv" value="Commit"><input class=altButton type="submit" name="cancel" value="Cancel"></td></tr>
  812. <input type="hidden" name=u value=$u>
  813. </form>
  814. </table>
  815.  
  816. </td></tr>
  817. <tr><td colspan=3><hr></td></tr>
  818. content;
  819. return $filemanager;
  820. }
  821. function listdir($wdir) {
  822. global $d, $nd,$pathext;
  823. $hndl=opendir($wdir);
  824. while($file=readdir($hndl)) {
  825. if ($file=='.' || $file=='..') { continue; }
  826. if (is_link($wdir.$file)) { continue; }
  827.  
  828. if (!hidecheck($file)) { continue; }
  829. if (!UpPathOK($file.'/')) { continue; }
  830. if (is_dir($wdir.$file)) {
  831. if ($pathext != $file.'/' ) {
  832. $nd++;
  833. $d[$nd]=$wdir.$file;
  834. }
  835. listdir($wdir.$file."/");
  836. }
  837. }
  838. closedir($hndl);
  839. return $d;
  840. }
  841. function makdiroptions($dop) {
  842. global $rd_len,$pathext,$path;
  843. $rd_len=strlen($path);
  844. foreach ($dop as $tmp) {
  845. $z=substr($tmp, $rd_len,(strlen($tmp)-($rd_len)));
  846. $options .= "<option>$z/</option>";
  847. }
  848. if (!$pathext=="") {$rt="<option>/</option>"; }
  849. return $rt.$options;
  850. }
  851.  
  852. function makfiletypelist() {
  853. global $NewFileTypes;
  854. foreach ($NewFileTypes as $tmp) {
  855. $options .= "<option>.$tmp</option>";
  856. }
  857. return $options;
  858. }
  859.  
  860. function ascedit ($edit) {
  861. global $path,$pathext,$dirroot,$PHP_SELF,$copt,$u,$sortKey,$msg;
  862.  
  863. $filemanager = makbar();
  864.  
  865. $fp = @fopen($path.$pathext.$edit, "r");
  866. if ($fp) {
  867. $oldcontent = fread($fp, filesize($path.$pathext.$edit));
  868. $oldcontent = htmlspecialchars($oldcontent);
  869. fclose($fp);
  870.  
  871. $filemanager .= <<<content
  872. <center>
  873. <table border="0" cellspacing="0" cellpadding="0">
  874. <tr>
  875. <td class=normalblack>
  876. <form name="form1" method="post" action="$PHP_SELF">
  877. <center>
  878. Current Directory: /$dirroot[$copt]/$pathext<br>File Editing: <b>$edit</b><p>
  879. <textarea name="newcontent" cols="60" rows="15">$oldcontent</textarea>
  880. <br>
  881. <br>
  882. <input type="hidden" name="copt" value="$copt">
  883. <input class=altButton type="submit" name="save" value="Save">
  884. <input class=altButton type="submit" name="cancel" value="Cancel">
  885. <input type="hidden" name="u" value="$u">
  886. <input type="hidden" name="savefile" value="$edit">
  887. <input type="hidden" name="pathext" value="$pathext">
  888. <input type="hidden" name=sortKey value="$sortKey">
  889. </center>
  890. </form>
  891. </td>
  892. </tr>
  893. </table>
  894. </center>
  895. content;
  896. }
  897. else {
  898. $filemanager .= "<tr><td colspan=3 class=normalred align=center>Failed to open $edit</td></tr>";
  899. }
  900. return $filemanager;
  901. }
  902.  
  903.  
  904.  
  905.  
  906. function newfileedit() {
  907. global $path,$pathext,$dirroot,$PHP_SELF,$copt,$u,$sortKey,$msg;
  908.  
  909. $options=makfiletypelist();
  910. $filemanager = makbar();
  911.  
  912. $filemanager .= <<<content
  913. <tr><td colspan=3 align=center>
  914. <table border="0" cellspacing="0" cellpadding="0" width=100%>
  915. <tr>
  916. <td class=normalblack>
  917. <form name="form1" method="post" action="$PHP_SELF">
  918. <center>
  919. Current Directory: /$dirroot[$copt]/$pathext<hr>New Filename: <input class=altButton type="text" name="newfilename">
  920. <select class=altButton name="newfileext">
  921. $options
  922. </select>
  923. <hr><p>
  924. <textarea name="newcontent" cols="60" rows="15"></textarea>
  925. <br>
  926. <br>
  927. <input type="hidden" name="copt" value="$copt">
  928. <input class=altButton type="submit" name="savenew" value="Save">
  929. <input class=altButton type="submit" name="cancel" value="Cancel">
  930. <input type="hidden" name="u" value="$u">
  931. <input type="hidden" name="pathext" value="$pathext">
  932. <input type="hidden" name=sortKey value="$sortKey">
  933. </center>
  934. </form>
  935. </td>
  936. </tr>
  937. </table>
  938. </td></tr>
  939. content;
  940.  
  941. return $filemanager;
  942. }
  943.  
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953. function makheader() {
  954. global $copt,$hack,$MaxFileSize,$mkdirhtml,$navbar,$dirroot,$dirpath,$uploadfield;
  955. global $msg,$mylink,$mylinkname,$pathext,$pathext,$PHP_SELF,$u,$sortKey,$createfilehtml;
  956.  
  957. $Type="Type";
  958. $Size="Size";
  959.  
  960. switch ($sortKey) {
  961. case "0":
  962. $fnl="[";
  963. $fnr="]";
  964. break;
  965. case 1:
  966. $Size="[Size]";
  967. break;
  968. case 2:
  969. $lml="[";
  970. $lmr="]";
  971. break;
  972. case 3:
  973. $Type="[Type]";
  974.  
  975. break;
  976. }
  977.  
  978.  
  979. $filemanager = <<<content
  980.  
  981. <table width=100% cellpadding=0 cellspacing=0 border=0>
  982. <tr><td bgcolor='#333399' colspan=3 valign=middle>&nbsp;&nbsp;<img src="fm_files/explorer.gif" width="20" height="20" border=0 align=middle><font face="Verdana, Arial, Hevetica" size="2" color="#ffffff"><b>File Manager</b></font></td></tr>
  983. <tr><td bgcolor="#000000" colspan=3 height=2><img src="fm_files/spacer.gif" width="1" height="2" border=0 alt=""></td></tr>
  984. <tr><td bgcolor="#eeeeee" colspan=2 width=30%>&nbsp;&nbsp;$navbar </td><td bgcolor="#eeeeee" align=right><a href=http://onedotoh.sourceforge.net/forum>OurForum</a><font face=verdana size=1> | </font><a href="$mylink">$mylinkname</a>&nbsp;&nbsp;</td></tr>
  985.  
  986. <tr><td bgcolor="#000000" colspan=3 height=2><img src="fm_files/spacer.gif" width="1" height="2" border=0 alt=""></td></tr>
  987. <tr><td colspan=3 height=3><img src="fm_files/spacer.gif" width="1" height="3" border=0 alt=""></td></tr>
  988.  
  989. <tr><td bgcolor="#808080" colspan=3 height=1><img src="fm_files/spacer.gif" width="1" height="1" border=0 alt=""></td></tr>
  990. <tr><td bgcolor="#D7D7D7" colspan=3 height=1><img src="fm_files/spacer.gif" width="1" height="1" border=0 alt=""></td></tr>
  991.  
  992. <tr><td colspan=3><font face=verdana size=2><b>&nbsp;Area:</b> $dirroot[$copt]</font></td></tr>
  993. <tr><td colspan=3><font face=verdana size=2><b>&nbsp;Path:</b> $dirpath[$copt]$pathext</font></td></tr>
  994. <tr><td colspan=3 height=3><img src="fm_files/spacer.gif" width="3" height="1" border=0 alt=""></td></tr>
  995.  
  996. <tr><td bgcolor="#808080" colspan=3 height=1><img src="fm_files/spacer.gif" width="1" height="1" border=0 alt=""></td></tr>
  997. <tr><td bgcolor="#D7D7D7" colspan=3 height=1><img src="fm_files/spacer.gif" width="1" height="1" border=0 alt=""></td></tr>
  998.  
  999. <tr><td colspan=3 height=6><img src="fm_files/spacer.gif" width="1" height="1" border=0 alt=""></td></tr>
  1000. <tr><td colspan=3 align=center><img src="fm_files/spacer.gif" width="1" height="1" border=0 alt=""></td></tr>
  1001.  
  1002. <tr><td colspan=3 align=center>
  1003. <font face="Verdana, Arial, Hevetica" size="2"><b>$hack$msg</b></font>
  1004.  
  1005. <table cellpadding=0 cellspacing=0 border=0 width=100%>
  1006. <form name="form1" method="post" action="$PHP_SELF" enctype="multipart/form-data">
  1007. <input type="hidden" name="MAX_FILE_SIZE" value="$MaxFileSize">
  1008. <input type="hidden" name="copt" value="$copt">
  1009. <tr>
  1010. <td align=center width=10%>$createfilehtml</td>
  1011. <td width=1 bgcolor=black><img src="fm_files/spacer.gif" width="1" height="1" border=0></td>
  1012. <td align=center width=40%>
  1013. $mkdirhtml
  1014. </td>
  1015. <td width=1 bgcolor=black><img src="fm_files/spacer.gif" width="1" height="1" border=0></td>
  1016. <td align=center width=50%>$uploadfield</td>
  1017. </form>
  1018. </tr>
  1019. </table>
  1020.  
  1021. </td></tr>
  1022.  
  1023. <tr><td colspan=3 height=6><img src="fm_files/spacer.gif" width="1" height="1" border=0 alt=""></td></tr>
  1024. <tr><td colspan=3 align=center><img src="fm_files/spacer.gif" width="1" height="1" border=0 alt=""></td></tr>
  1025.  
  1026. <tr><td bgcolor="#808080" colspan=3 height=1><img src="fm_files/spacer.gif" width="1" height="1" border=0 alt=""></td></tr>
  1027. <tr><td bgcolor="#D7D7D7" colspan=3 height=1><img src="fm_files/spacer.gif" width="1" height="1" border=0 alt=""></td></tr>
  1028.  
  1029. <tr><td colspan=3 height=6><img src="fm_files/spacer.gif" width="1" height="6" border=0 alt=""></td></tr>
  1030.  
  1031. </table>
  1032. <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#eeeeee">
  1033. <tr>
  1034. <td height="20" width=22 bgcolor="#333333"></td>
  1035. <td bgcolor="#333333" height="20" align=center>&nbsp;<a href="$PHP_SELF?copt=$copt&u=$u&pathext=$pathext&sortKey=0"><font face="Verdana, Arial, Helvetica" size="2" color="#FFFFFF"><b>$fnl FILENAME $fnr</b></font></a>&nbsp;</td>
  1036. <td height="20" bgcolor="#333333" align=center><a href="$PHP_SELF?copt=$copt&u=$u&pathext=$pathext&sortKey=1"><font face="Verdana, Arial, Helvetica" size="2" color="#FFFFFF"><b>$Size</b></font></a></td>
  1037. <td height="20" bgcolor="#333333" align=center><a href="$PHP_SELF?copt=$copt&u=$u&pathext=$pathext&sortKey=3"><font face="Verdana, Arial, Helvetica" size="2" color="#FFFFFF"><b>$Type</b></font></a></td>
  1038. <td height="20" bgcolor="#333333" colspan=4 align=center><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica"><b>Action</b></font></td>
  1039. </tr>
  1040. <tr>
  1041. <td height="2" bgcolor="#999999" colspan=8></td>
  1042. </tr>
  1043. content;
  1044. return $filemanager;
  1045. }
  1046.  
  1047.  
  1048. function makbar() {
  1049. global $copt,$hack,$MaxFileSize,$mkdirhtml,$navbar,$dirroot,$dirpath;
  1050. global $msg,$mylink,$mylinkname,$pathext,$PHP_SELF,$u;
  1051.  
  1052. $filemanager = <<<content
  1053.  
  1054. <table width=100% cellpadding=0 cellspacing=0 border=0>
  1055. <tr><td bgcolor='#333399' colspan=3 valign=middle>&nbsp;&nbsp;<img src="fm_files/explorer.gif" width="20" height="20" border=0 align=middle><font face="Verdana, Arial, Hevetica" size="2" color="#ffffff"><b>File Manager</b></font></td></tr>
  1056.  
  1057. <tr><td bgcolor="#000000" colspan=3 height=2><img src="fm_files/spacer.gif" width="1" height="2" border=0 alt=""></td></tr>
  1058. <tr><td bgcolor="#eeeeee" colspan=2 width=30%>&nbsp;&nbsp;$navbar</td><td bgcolor="#eeeeee" align=right><a href="$mylink">$mylinkname</a>&nbsp;&nbsp;</td></tr>
  1059.  
  1060. <tr><td bgcolor="#000000" colspan=3 height=2><img src="fm_files/spacer.gif" width="1" height="2" border=0 alt=""></td></tr>
  1061. <tr><td colspan=3 height=3><img src="fm_files/spacer.gif" width="1" height="3" border=0 alt=""></td></tr>
  1062. content;
  1063. return $filemanager;
  1064. }
  1065.  
  1066. function setroot($vpath) {
  1067. global $dir, $dirroot, $dirpath, $nav, $path,$copt, $sharedhost;
  1068. /* If adding more than two directores, add an elseif for each. */
  1069. if ($copt==1) {
  1070. $path = $path.$dir[1];
  1071. }
  1072. elseif ($copt==2) {
  1073. $path = $path.$dir[2];
  1074. }
  1075. else {
  1076. $path = $path.$dir[1];
  1077. $copt=1;
  1078. }
  1079. }
  1080.  
  1081. function hidecheck ($ckfilename) {
  1082. global $HiddenFiles;
  1083. $okay=1;
  1084. foreach($HiddenFiles as $name) {
  1085. // check the name is not the same as the hidden file name
  1086. if($ckfilename == $name) {
  1087. $okay = ""; // unset if not okay
  1088. }
  1089. }
  1090. return $okay;
  1091. }
  1092. function Ok2Edit ($ckfileext) {
  1093. //$hide= hidecheck ($tmp);
  1094. global $EditExtensions;
  1095. foreach($EditExtensions as $name) {
  1096. // check the name is not the same as the hidden file name
  1097. if($ckfileext == strtoupper($name)) {
  1098. $okay = "1";
  1099. }
  1100. }
  1101. return $okay;
  1102.  
  1103. }
  1104. function TargetOK ($chck) {
  1105. global $ModifyBlock;
  1106. $okay=1;
  1107. if (isset($ModifyBlock)) {
  1108. foreach($ModifyBlock as $name) {
  1109. // check the name is not Blocked.
  1110. if($chck == $name) {
  1111. $okay = "0";
  1112. }
  1113. }
  1114. }
  1115. return $okay;
  1116. }
  1117.  
  1118.  
  1119. function getfiletype ($file) {
  1120. $file=strtolower($file);
  1121. $dotpos = strrpos($file, ".");
  1122. if ($dotpos < 1) {
  1123. $ft[0]="UnK";
  1124. $ft[1]="application/octet-stream";
  1125. return $ft;
  1126. }
  1127. else {
  1128. $filetype = substr($file,$dotpos+1);
  1129. }
  1130. if ($filetype=="html") {
  1131. $ft[0]="HTML";
  1132. $ft[1]="";
  1133. return $ft;
  1134. }
  1135. elseif ($filetype=="htm") {
  1136. $ft[0]="HTML";
  1137. $ft[1]="";
  1138. return $ft;
  1139. }
  1140. elseif ($filetype=="jpg") {
  1141. $ft[0]="JPG";
  1142. $ft[1]="";
  1143. return $ft;
  1144. }
  1145. elseif ($filetype=="bak") {
  1146. $ft[0]="BAK";
  1147. $ft[1]="application/octet-stream";
  1148. return $ft;
  1149. }
  1150. elseif ($filetype=="db") {
  1151. $ft[0]="DB";
  1152. $ft[1]="application/octet-stream";
  1153. return $ft;
  1154. }
  1155. elseif ($filetype=="bmp") {
  1156. $ft[0]="BMP";
  1157. $ft[1]="";
  1158. return $ft;
  1159. }
  1160. elseif ($filetype=="txt") {
  1161. $ft[0]="TXT";
  1162. $ft[1]="text/plain";
  1163. return $ft;
  1164. }
  1165. elseif ($filetype=="log") {
  1166. $ft[0]="LOG";
  1167. $ft[1]="text/plain";
  1168. return $ft;
  1169. }
  1170. elseif ($filetype=="pdf") {
  1171. $ft[0]="PDF";
  1172. $ft[1]="application/pdf";
  1173. return $ft;
  1174. }
  1175. elseif ($filetype=="rtf") {
  1176. $ft[0]="RTF";
  1177. $ft[1]="application/rtf";
  1178. return $ft;
  1179. }
  1180. elseif ($filetype=="css") {
  1181. $ft[0]="CSS";
  1182. $ft[1]="text/css";
  1183. return $ft;
  1184. }
  1185. elseif ($filetype=="doc") {
  1186. $ft[0]="DOC";
  1187. $ft[1]="application/msword";
  1188. return $ft;
  1189. }
  1190. elseif ($filetype=="gif") {
  1191. $ft[0]="GIF";
  1192. $ft[1]="";
  1193. return $ft;
  1194. }
  1195. elseif ($filetype=="png") {
  1196. $ft[0]="PNG";
  1197. $ft[1]="";
  1198. return $ft;
  1199. }
  1200. elseif ($filetype=="zip") {
  1201. $ft[0]="ZIP";
  1202. $ft[1]="application/zip";
  1203. return $ft;
  1204. }
  1205. elseif ($filetype=="php") {
  1206. $ft[0]="PHP";
  1207. $ft[1]="application/octet-stream";
  1208. return $ft;
  1209. }
  1210. elseif ($filetype=="off") {
  1211. $ft[0]="OFF";
  1212. $ft[1]="application/octet-stream";
  1213. return $ft;
  1214. }
  1215. else {
  1216. $ft[0]="GNC";
  1217. $ft[1]="application/octet-stream";
  1218. return $ft;
  1219. }
  1220. }
  1221.  
  1222.  
  1223. function geticon($filetype,$tida) {
  1224. global $dirpath,$copt,$path,$pathext,$file,$sortKey,$u,$urlpath,$PHP_SELF;
  1225. if ($filetype=="HTML") {
  1226. $iconlink[0] = "<img src=\"fm_files/html.gif\" width=\"20\" height=\"20\" border=0 alt=\"$tida\">";
  1227. $iconlink[1] = "<a href=\"$urlpath$pathext$file?u=$u\">$file</a>";
  1228. }
  1229. elseif ($filetype=="Folder") {
  1230. $iconlink[0] = "<img src=\"fm_files/foldericon.gif\" border=0 alt=\"$tida\">";
  1231. $iconlink[1] = "<a href=\"$PHP_SELF?u=$u&copt=$copt&sortKey=$sortKey&pathext=$pathext$file/\">$file</a>";
  1232. }
  1233. elseif ($filetype=="BMP") {
  1234. $iconlink[0] = "<img src=\"fm_files/jpg.gif\" width=\"20\" height=\"20\" border=0 alt=\"$tida\">";
  1235. $iconlink[1] = "<a href=\"$PHP_SELF?action=view&cz=x&filename=$file&pathext=$pathext&u=$u&copt=$copt&sortKey=$sortKey\">$file</a>";
  1236. }
  1237. elseif ($filetype=="JPG") {
  1238. $iconlink[0] = "<img src=\"fm_files/jpg.gif\" width=\"20\" height=\"20\" border=0 alt=\"$tida\">";
  1239. $iconlink[1] = "<a href=\"$PHP_SELF?action=view&cz=x&filename=$file&pathext=$pathext&u=$u&copt=$copt&sortKey=$sortKey\">$file</a>";
  1240. }
  1241. elseif ($filetype=="GIF") {
  1242. $iconlink[0] = "<img src=\"fm_files/gif.gif\" width=\"20\" height=\"20\" border=0 alt=\"$tida\">";
  1243. $iconlink[1] = "<a href=\"$PHP_SELF?action=view&cz=x&filename=$file&pathext=$pathext&u=$u&copt=$copt&sortKey=$sortKey\">$file</a>";
  1244. }
  1245. elseif ($filetype=="PNG") {
  1246. $iconlink[0] = "<img src=\"fm_files/png.gif\" width=\"16\" height=\"16\" border=0 alt=\"$tida\">";
  1247. $iconlink[1] = "<a href=\"$PHP_SELF?action=view&cz=x&filename=$file&pathext=$pathext&u=$u&copt=$copt&sortKey=$sortKey\">$file</a>";
  1248. }
  1249. elseif ($filetype=="TXT") {
  1250. $iconlink[0] = "<img src=\"fm_files/txt.gif\" width=\"20\" height=\"20\" border=0 alt=\"$tida\">";
  1251. $iconlink[1] = "<a href=\"$PHP_SELF?action=viewascii&filename=$file&pathext=$pathext&u=$u&copt=$copt&sortKey=$sortKey\">$file</a>";
  1252. }
  1253. elseif ($filetype=="LOG") {
  1254. $iconlink[0] = "<img src=\"fm_files/txt.gif\" width=\"20\" height=\"20\" border=0 alt=\"$tida\">";
  1255. $iconlink[1] = "<a href=\"$PHP_SELF?action=viewascii&filename=$file&pathext=$pathext&u=$u&copt=$copt&sortKey=$sortKey\">$file</a>";
  1256. }
  1257. elseif ($filetype=="CSS") {
  1258. $iconlink[0] = "<img src=\"fm_files/css.gif\" width=\"20\" height=\"20\" border=0 alt=\"$tida\">";
  1259. $iconlink[1] = "<a href=\"$urlpath$pathext$file?u=$u\">$file</a>";
  1260. }
  1261. elseif ($filetype=="RTF") {
  1262. $iconlink[0] = "<img src=\"fm_files/rtf.gif\" width=\"18\" height=\"18\" border=0 alt=\"$tida\">";
  1263. $iconlink[1] = "<a href=\"$urlpath$pathext$file?u=$u\">$file</a>";
  1264. }
  1265. elseif ($filetype=="PDF") {
  1266. $iconlink[0] = "<img src=\"fm_files/pdf.gif\" width=\"20\" height=\"20\" border=0 alt=\"$tida\">";
  1267. $iconlink[1] = "<a href=\"$urlpath$pathext$file?u=$u\">$file</a>";
  1268. }
  1269. elseif ($filetype=="DOC") {
  1270. $iconlink[0] = "<img src=\"fm_files/word.gif\" width=\"17\" height=\"17\" border=0 alt=\"$tida\">";
  1271. $iconlink[1] = "<a href=\"$PHP_SELF?action=download&filename=$file&pathext=$pathext&u=$u&copt=$copt&sortKey=$sortKey\">$file</a>";
  1272. }
  1273. elseif ($filetype=="PHP") {
  1274. $iconlink[0] = "<img src=\"fm_files/phpx.jpg\" width=\"20\" height=\"20\" border=0 alt=\"$tida\">";
  1275. $iconlink[1] = "<a href=\"$PHP_SELF?action=download&filename=$file&pathext=$pathext&u=$u&copt=$copt&sortKey=$sortKey\">$file</a>";
  1276. }
  1277. elseif ($filetype=="ZIP") {
  1278. $iconlink[0] = "<img src=\"fm_files/zip.gif\" width=\"20\" height=\"20\" border=0 alt=\"$tida\">";
  1279. $iconlink[1] = "<a href=\"$PHP_SELF?action=download&filename=$file&pathext=$pathext&u=$u&copt=$copt&sortKey=$sortKey\">$file</a>";
  1280. }
  1281. else {
  1282. $iconlink[0] = "<img src=\"fm_files/fileicon.gif\" width=\"11\" height=\"13\" alt=\"$tida\">";
  1283. $iconlink[1] = "<a href=\"$PHP_SELF?action=download&filename=$file&pathext=$pathext&u=$u&copt=$copt&sortKey=$sortKey\">$file</a>";
  1284. }
  1285. return $iconlink;
  1286. }
  1287.  
  1288.  
  1289.  
  1290. function OffFile ($ckfile) {
  1291. global $ExtensionsOFF;
  1292. $dotpos = strrpos($ckfile, ".");
  1293. if ($dotpos < 1) {
  1294. return "";
  1295. }
  1296. else {
  1297. $ckfileext = strtoupper(substr($ckfile,$dotpos+1));
  1298. }
  1299. // check to see if files should be OFF - This appends .OFF
  1300. // to filename and disables rename to that extension.
  1301. if (isset($ExtensionsOFF)) {
  1302. foreach($ExtensionsOFF as $name) {
  1303. if($ckfileext == strtoupper($name)) {
  1304. $OFF = "1";
  1305. }
  1306. }
  1307. }
  1308. return $OFF;
  1309. }
  1310.  
  1311.  
  1312. function viewascii () {
  1313. global $path,$pathext,$filename,$PHP_SELF,$u,$sortKey,$copt,$urlpath;
  1314.  
  1315. $file_stat = stat($path.$pathext.$filename);
  1316.  
  1317. $size = setsize($file_stat[7]);
  1318. $lastmod = date("m/d/Y h:i:sA",$file_stat[10]);
  1319. $created = date("m/d/Y h:i:sA",$file_stat[8]);
  1320. $content_array = file("$path$pathext$filename");
  1321. $content = implode("", $content_array);
  1322.  
  1323. $content = htmlspecialchars($content);
  1324.  
  1325. $filemanager = makbar();
  1326. $filemanager .= <<<content
  1327. <tr><td colspan=3 height=3><hr></td></tr>
  1328. <tr><td colspan=3 align=center>
  1329. <table width=100% border=0>
  1330. <tr><td align=center class=normalblack><b>Viewing text "$filename"</td>
  1331. <td class=smallblack align=right>
  1332. Size: $size
  1333. </td>
  1334. <td class=smallblack align=right>created: $created</td>
  1335. <td>&nbsp;</td>
  1336. <td align=center>
  1337. <a href="$PHP_SELF?u=$u&sortKey=$sortKey&pathext=$pathext&copt=$copt"><font face=Verdana, Arial, Helvetica size=2>&laquo;BACK</font></a>
  1338. </td></tr>
  1339. </table>
  1340. <hr>
  1341. <table border="0" cellspacing="0" cellpadding="0" width=96%>
  1342. <tr>
  1343. <td class=normalblack align=center>
  1344. [non-edit]
  1345.  
  1346. <table cellpadding=1 cellspacing=0 border=0><tr><td bgcolor="#330033">
  1347. <table width=80% height=100% bgcolor="#ffffff" cellpadding=10 border=0>
  1348. <tr>
  1349. <td align=center valign=middle>
  1350. <textarea readonly name="content" rows="20" cols="66" wrap=virtual>$content</textarea>
  1351. </td>
  1352. </tr>
  1353. </table>
  1354. </td></tr></table>
  1355. <span class=smallblack>Last Modified: $lastmod</span>
  1356. </td>
  1357. </tr>
  1358. </table><p align=left>
  1359. &nbsp;&nbsp;<a href="$PHP_SELF?u=$u&sortKey=$sortKey&pathext=$pathext&copt=$copt"><font face=Verdana, Arial, Helvetica size=2>&laquo;BACK</font></a></p>
  1360. </td></tr>
  1361. content;
  1362. return $filemanager;
  1363.  
  1364. }
  1365. function viewimage () {
  1366. global $path,$pathext,$filename,$cz,$za,$PHP_SELF,$u,$sortKey,$copt,$urlpath;
  1367.  
  1368. $image_info = getimagesize($path.$pathext.$filename);
  1369. $image_stat = stat($path.$pathext.$filename); // get some info about the file
  1370.  
  1371. $ImageType = array("x","GIF","JPG","PNG","SWF","PSD","BMP","TIFF","TIFF","JPC","JP2","JPX","JB2","SWC","IFF");
  1372. $zoom = array(".25",".50",".75","1","1.25","1.50","1.75","2");
  1373. $maxzoom = 7;
  1374. $minzoom = 0;
  1375.  
  1376. $f_type = $ImageType[$image_info[2]];
  1377.  
  1378. // $cz current zoom
  1379. // $za = zoom action +1/-1
  1380.  
  1381. if($cz=="x") {
  1382. if($image_info[0]>600) { $cz=1; }
  1383. elseif ($image_info[0]>440) { $cz=2; }
  1384. else { $cz=3; }
  1385. }
  1386.  
  1387. $cz = $cz + $za;
  1388. if ($cz > $maxzoom) { $cz=$maxzoom; }
  1389. if ($cz < $minzoom) { $cz=$minzoom; }
  1390.  
  1391. $f_width = $image_info[0] * $zoom[$cz];
  1392. $f_height = $image_info[1] * $zoom[$cz];
  1393.  
  1394. $zoom_stat = $zoom[$cz] * 100;
  1395.  
  1396. $size = setsize($image_stat[7]);
  1397. $lastmod = date("m/d/Y h:i:sA",$image_stat[10]);
  1398.  
  1399. $filemanager = makbar();
  1400. $filemanager .= <<<content
  1401. <tr><td colspan=3 height=3><hr></td></tr>
  1402. <tr><td colspan=3>
  1403. <table width=100% border=0>
  1404. <tr><td align=center class=normalblack><b>Viewing "$filename" at $zoom_stat%</td>
  1405. <td class=smallblack align=right>
  1406. Image type: $f_type<br>
  1407. Size: $size
  1408. </td><td class=smallblack align=right>
  1409. Width: $image_info[0]<br>
  1410. Height: $image_info[1]
  1411. </td>
  1412. <td>&nbsp;</td>
  1413. <td align=center>
  1414. <a href="$PHP_SELF?u=$u&sortKey=$sortKey&pathext=$pathext&copt=$copt"><font face=Verdana, Arial, Helvetica size=2>&laquo;BACK</font></a>
  1415. </td></tr>
  1416. </table>
  1417. <hr>
  1418. <table border="0" cellspacing="0" cellpadding="0" width=96%>
  1419. <tr>
  1420. <td class=normalblack align=center>
  1421. <a href="$PHP_SELF?action=view&cz=$cz&za=-1&filename=$filename&pathext=$pathext&u=$u&copt=$copt&sortKey=$sortKey"><img src=fm_files/minus.gif width=11 height=11 border=0 alt=Zoom In>&nbsp;Zoom Out</a>&nbsp;<a href="$PHP_SELF?action=view&cz=$cz&za=1&filename=$filename&pathext=$pathext&u=$u&copt=$copt&sortKey=$sortKey"><img src=fm_files/plus.gif width=11 height=11 border=0 alt=Zoom Out>&nbsp;Zoom In</a>&nbsp;<a href="$PHP_SELF?action=view&cz=3&za=0&filename=$filename&pathext=$pathext&u=$u&copt=$copt&sortKey=$sortKey"><img src=fm_files/original.gif width=11 height=11 border=0 alt=Original Size>&nbsp;Original Size</a>
  1422.  
  1423. <table cellpadding=1 cellspacing=0 border=0><tr><td bgcolor="#330033">
  1424. <table width=80% height=100% bgcolor="#ffffff" cellpadding=10 border=0>
  1425. <tr>
  1426. <td align=center valign=middle><img src="$urlpath$pathext$filename" width=$f_width height=$f_height border=0></td>
  1427. </tr>
  1428. </table>
  1429. </td></tr></table>
  1430. <span class=smallblack>Last Modified: $lastmod</span>
  1431. </td>
  1432. </tr>
  1433. </table><p>
  1434. &nbsp;&nbsp;<a href="$PHP_SELF?u=$u&sortKey=$sortKey&pathext=$pathext&copt=$copt"><font face=Verdana, Arial, Helvetica size=2>&laquo;BACK</font></a>
  1435. </td></tr>
  1436. content;
  1437. return $filemanager;
  1438. }
  1439.  
  1440.  
  1441.  
  1442. ?>
  1443.  
  1444.  
  1445. <html>
  1446. <head>
  1447. <link rel="stylesheet" type="text/css" href="fmstyle.css" />
  1448. <title>sfm: <?php echo $dirroot[$copt]; ?></title>
  1449. </head>
  1450. <body bgcolor="#008080">
  1451.  
  1452. <center><br><p>
  1453. <table cellpadding=2 cellspacing=0 bgcolor=#000040>
  1454. <tr><td>
  1455. <table border='0' cellspacing='0' cellpadding='0' width=640 bgcolor="#C0C0C0">
  1456. <tr>
  1457. <td>
  1458. <?php echo $filemanager ?>
  1459. <table cellpadding=0 cellspacing=0 border=0 width=100%>
  1460. <?php if (isset($nf)) { echo "<tr><td colspan=6 align=center>$nf</td></tr>"; } ?>
  1461. <tr><td height="3" colspan=6 bgcolor="#000000"><img src="fm_files/spacer.gif" width="1" height="3" border=0></td></tr>
  1462. <tr>
  1463. <td colspan=6 bgcolor=#C0C0C0 align=center>
  1464. <table cellpadding=0 cellspacing=3 width=98%>
  1465. <tr>
  1466. <td><font face="Verdana, Arial, Hevetica" size="1"><b>Total Space:</b> <?php echo $HDDSpaceABR; ?> <b>Max File Size:</b> <?php echo $MaxFileSizeABR; ?><br><b>Free Space:</b> <?php echo $freespaceABR; ?> <b>Used Space:</b> <?php echo $HDDTotalABR; ?></font></td>
  1467. <td valign=bottom align=right><a class=tiny href=http://onedotoh.sourceforge.net target=blank><i>simple file manager</i></a><span class=tiny> <?php echo $ver; ?></i> </span> &#945; [gpl]&nbsp;</td>
  1468. </tr>
  1469. </table>
  1470. </td>
  1471. </tr>
  1472. </table>
  1473. <?php echo $patherror; ?>
  1474. </td>
  1475. </tr>
  1476. </table>
  1477. </td></tr>
  1478. </table>
  1479. </center>
  1480. </body>
  1481. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement