PageRenderTime 68ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/e107_admin/filemanager.php

https://github.com/CasperGemini/e107
PHP | 460 lines | 361 code | 64 blank | 35 comment | 82 complexity | 780c41da5edde07998614e751bd91fdd MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * e107 website system
  4. *
  5. * Copyright (C) 2008-2009 e107 Inc (e107.org)
  6. * Released under the terms and conditions of the
  7. * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  8. *
  9. *
  10. *
  11. * $Source: /cvs_backup/e107_0.8/e107_admin/filemanager.php,v $
  12. * $Revision$
  13. * $Date$
  14. * $Author$
  15. */
  16. require_once("../class2.php");
  17. if (!getperms("6"))
  18. {
  19. header("location:".e_BASE."index.php");
  20. exit;
  21. }
  22. include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
  23. $e_sub_cat = 'filemanage';
  24. require_once("auth.php");
  25. require_once(e_HANDLER.'upload_handler.php');
  26. $frm = e107::getForm();
  27. $mes = e107::getMessage();
  28. $pubfolder = (str_replace("../","",e_QUERY) == str_replace("../","",e_UPLOAD)) ? TRUE : FALSE;
  29. $imagedir = e_IMAGE."filemanager/";
  30. $message = '';
  31. $dir_options[0] = FMLAN_47;
  32. $dir_options[1] = FMLAN_35;
  33. $dir_options[2] = FMLAN_40;
  34. $adchoice[0] = e_UPLOAD;
  35. $adchoice[1] = e_FILE;
  36. $adchoice[2] = e_IMAGE."newspost_images/";
  37. $path = str_replace("../", "", e_QUERY);
  38. if (!$path)
  39. {
  40. $path = str_replace("../", "", $adchoice[0]);
  41. }
  42. if($path == "/")
  43. {
  44. $path = $adchoice[0];
  45. echo "<b>Debug</b> ".$path." <br />";
  46. }
  47. // ===============================================
  48. if (isset($_POST['deleteconfirm']))
  49. {
  50. $deleteList = array();
  51. $moveList = array();
  52. foreach($_POST['deleteconfirm'] as $key=>$delfile)
  53. {
  54. // check for delete.
  55. if (isset($_POST['selectedfile'][$key]) && isset($_POST['deletefiles']))
  56. {
  57. if (!$_POST['ac'] == md5(ADMINPWCHANGE))
  58. {
  59. exit;
  60. }
  61. $destination_file = e_BASE.$delfile;
  62. if (@unlink($destination_file))
  63. {
  64. //$message .= FMLAN_26." '".$destination_file."' ".FMLAN_27.".<br />";
  65. $mes->addSuccess(LAN_DELETED.": <br />.".$destination_file."<br />");
  66. $deleteList[] = $destination_file;
  67. }
  68. else
  69. {
  70. //$message .= FMLAN_28." '".$destination_file."'.<br />";
  71. $mes->addError(LAN_DELETED_FAILED.": <br />.".$destination_file."<br />");
  72. }
  73. }
  74. // check for move to downloads or downloadimages.
  75. if (isset($_POST['selectedfile'][$key]) && (isset($_POST['movetodls'])) )
  76. {
  77. $newfile = str_replace($path,"",$delfile);
  78. // Move file to whatever folder.
  79. if (isset($_POST['movetodls']))
  80. {
  81. $newpath = $_POST['movepath'];
  82. if (rename(e_BASE.$delfile,$newpath.$newfile))
  83. {
  84. //$message .= FMLAN_38." ".$newpath.$newfile."<br />";
  85. $mes->addSuccess(FMLAN_38.":".$newpath.$newfile);
  86. $moveList[] = e_BASE.$delfile.'=>'.$newpath.$newfile;
  87. }
  88. else
  89. {
  90. //$message .= FMLAN_39." ".$newpath.$newfile."<br />";
  91. $mes->addError((!is_writable($newpath)) ? $newpath.LAN_NOTWRITABLE : ""); // TODO check if this message actually works
  92. }
  93. }
  94. }
  95. }
  96. if (count($deleteList))
  97. {
  98. $admin_log->log_event('FILEMAN_01',implode('[!br!]',$deleteList),E_LOG_INFORMATIVE,'');
  99. }
  100. if (count($moveList))
  101. {
  102. $admin_log->log_event('FILEMAN_02',implode('[!br!]',$moveList),E_LOG_INFORMATIVE,'');
  103. }
  104. }
  105. if (isset($_POST['upload']))
  106. {
  107. if (!$_POST['ac'] == md5(ADMINPWCHANGE))
  108. {
  109. exit;
  110. }
  111. $uploadList = array();
  112. require_once(e_HANDLER.'upload_handler.php');
  113. $files = $_FILES['file_userfile'];
  114. $spacer = '';
  115. foreach($files['name'] as $key => $name)
  116. {
  117. if ($name)
  118. {
  119. if ($files['error'][$key])
  120. {
  121. //$message .= $spacer.FMLAN_10.' '.$files['error'][$key].': '.$name;
  122. $mes->addError($files['error'][$key].': '.$name);
  123. }
  124. elseif ($files['size'][$key])
  125. {
  126. $uploaded = file_upload(e_BASE.$_POST['upload_dir'][$key]);
  127. if (($uploaded === FALSE) || !is_array($uploaded))
  128. {
  129. //$message .= $spacer.FMLAN_51.$name; // FIXME
  130. $mes->addError($name);
  131. $spacer = '<br />';
  132. }
  133. else
  134. {
  135. foreach ($uploaded as $k => $inf)
  136. {
  137. if ($inf['error'] == 0)
  138. {
  139. $uploadList[] = $_POST['upload_dir'][$key].$uploaded[0]['name'];
  140. }
  141. else
  142. { // Most likely errors trapped earlier.
  143. //$message .= $spacer.FMLAN_10.' '.$inf['error'].' ('.$inf['message'].'): '.$inf['rawname']; // FIXME
  144. $mes->addError($inf['error'].' ('.$inf['message'].'): '.$inf['rawname']);
  145. }
  146. $spacer = '<br />';
  147. }
  148. }
  149. }
  150. }
  151. }
  152. if (count($uploadList))
  153. {
  154. $admin_log->log_event('FILEMAN_03',implode('[!br!]',$uploadList),E_LOG_INFORMATIVE,'');
  155. }
  156. }
  157. $ns->tablerender($caption, $mes->render() . $text);
  158. /*
  159. if ($message)
  160. {
  161. $ns->tablerender("", "<div style=\"text-align:center\"><b>".$message."</b></div>");
  162. }
  163. */
  164. if (strpos(e_QUERY, ".") && !is_dir(realpath(e_BASE.$path)))
  165. {
  166. echo "
  167. <div>
  168. <iframe style='width:99%' src='".e_BASE.e_QUERY."' height='300' scrolling='yes'>asdas</iframe>
  169. </div>
  170. ";
  171. if (!strpos(e_QUERY, "/"))
  172. {
  173. $path = "";
  174. }
  175. else
  176. {
  177. $path = substr($path, 0, strrpos(substr($path, 0, -1), "/"))."/";
  178. }
  179. }
  180. $files = array();
  181. $dirs = array();
  182. $path = explode("?", $path);
  183. $path = $path[0];
  184. $path = explode(".. ", $path);
  185. $path = $path[0];
  186. if ($handle = opendir(e_BASE.$path))
  187. {
  188. while (false !== ($file = readdir($handle))) {
  189. if ($file != "." && $file != "..") {
  190. if (getenv('windir') && is_file(e_BASE.$path."\\".$file)) {
  191. if (is_file(e_BASE.$path."\\".$file)) {
  192. $files[] = $file;
  193. } else {
  194. $dirs[] = $file;
  195. }
  196. } else {
  197. if (is_file(e_BASE.$path."/".$file)) {
  198. $files[] = $file;
  199. } else {
  200. $dirs[] = $file;
  201. }
  202. }
  203. }
  204. }
  205. }
  206. closedir($handle);
  207. if (count($files) != 0) {
  208. sort($files);
  209. }
  210. if (count($dirs) != 0) {
  211. sort($dirs);
  212. }
  213. if (count($files) == 1) {
  214. $cstr = FMLAN_12;
  215. } else {
  216. $cstr = FMLAN_13;
  217. }
  218. if (count($dirs) == 1) {
  219. $dstr = FMLAN_14;
  220. } else {
  221. $dstr = FMLAN_15;
  222. }
  223. $pathd = $path;
  224. $text = "
  225. <form method='post' action='".e_SELF."?".e_QUERY."'>
  226. <div class='buttons-bar left'>
  227. ".FMLAN_32."
  228. <select name='admin_choice' class='tbox' onchange=\"location.href=this.options[selectedIndex].value\">";
  229. foreach($dir_options as $key=>$opt){
  230. $select = (str_replace("../","",$adchoice[$key]) == e_QUERY) ? "selected='selected'" : "";
  231. $text .= "<option value='".e_SELF."?".str_replace("../","",$adchoice[$key])."' $select>".$opt."</option>";
  232. }
  233. $text .= "</select>
  234. </div>
  235. </form>
  236. ";
  237. // $ns->tablerender(FMLAN_34, $text);
  238. // Get largest allowable file upload
  239. $max_file_size = get_user_max_upload();
  240. if ($path != e_FILE) {
  241. if (substr_count($path, "/") == 1) {
  242. //$pathup = e_SELF;
  243. $pathup = '';
  244. } else {
  245. $pathup = "<a class='action' href='".e_SELF."?".substr($path, 0, strrpos(substr($path, 0, -1), "/"))."/'><img class='icon S24' src='".$imagedir."updir.png' alt='".FMLAN_30."' /></a>";
  246. }
  247. }
  248. $text .= "
  249. <form enctype='multipart/form-data' action='".e_SELF.(e_QUERY ? "?".e_QUERY : "")."' method='post'>
  250. <fieldset id='core-filemanager'>
  251. <legend class='e-hideme'>XX</legend>
  252. <table class='table adminlist'>
  253. <colgroup>
  254. <col style='width: 5%' />
  255. <col style='width: 40%' />
  256. <col style='width: 20%' />
  257. <col style='width: 15%' />
  258. </colgroup>
  259. <thead>
  260. <tr>
  261. <th class='center'>
  262. ".$pathup."
  263. <!-- <a href='filemanager.php'><img src='".$imagedir."home.png' alt='".FMLAN_16."' /></a> -->
  264. <input type='hidden' name='MAX_FILE_SIZE' value='{$max_file_size}' />
  265. </th>
  266. <th class='center'>".LAN_SIZE."</th>
  267. <th class='center'>".FMLAN_18."</th>
  268. <th class='center'>".FMLAN_19."</th>
  269. </tr>
  270. </thead>
  271. <tbody>
  272. ";
  273. $c = 0;
  274. while ($dirs[$c]) {
  275. $dirsize = dirsize($path.$dirs[$c]);
  276. $el_id = str_replace(array('/','_',' ','\\'),'-',$path.$dirs[$c]);
  277. if (FILE_UPLOADS && is_writable(e_BASE.$path.$dirs[$c])) {
  278. $up_button = $frm->admin_button('erquest', FMLAN_21, 'action', '', array('id'=>false, 'other'=>"onclick='e107Helper.toggle(\"{$el_id}\")'"));
  279. } else {
  280. $up_button = "&nbsp;leave_32.png";
  281. }
  282. //FIXME - upload link not working, raplace with image
  283. $text .= "
  284. <tr>
  285. <td class='center middle'><a href='#{$el_id}' class='e-expandit'>upload</a></td>
  286. <td>
  287. <a class='action' href='".e_SELF."?".$path.$dirs[$c]."/'><img class='icon action S16' src='".$imagedir."folder.png' alt='".$dirs[$c]." ".FMLAN_31."' /></a>
  288. <a href='".e_SELF."?".$path.$dirs[$c]."/'>".$dirs[$c]."</a>
  289. <div class='e-hideme' id='{$el_id}'>
  290. <div class='field-spacer'>".$frm->file('file_userfile[]', array('id'=>false, 'size'=>'20')).$frm->admin_button('upload', FMLAN_22, '', '', array('id'=>false))."</div>
  291. <input type='hidden' name='upload_dir[]' value='".$path.$dirs[$c]."' />
  292. </div>
  293. </td>
  294. <td class='right'>".$dirsize."</td>
  295. <td class='right'>&nbsp;</td>
  296. </tr>
  297. ";
  298. $c++;
  299. }
  300. $c = 0;
  301. while ($files[$c])
  302. {
  303. $img = strtolower(substr(strrchr($files[$c], "."), 1, 3));
  304. if (!$img || !preg_match("/css|exe|gif|htm|jpg|js|php|png|txt|xml|zip/i", $img))
  305. {
  306. $img = "def";
  307. }
  308. $size = $e107->parseMemorySize(filesize(e_BASE.$path."/".$files[$c]));
  309. $gen = new convert;
  310. $filedate = $gen -> convert_date(filemtime(e_BASE.$path."/".$files[$c]), "forum");
  311. $text .= "
  312. <tr>
  313. <td class='center middle autocheck'>
  314. ".$frm->checkbox("selectedfile[$c]", 1, false, array('id'=>false))."
  315. <input type='hidden' name='deleteconfirm[$c]' value='".$path.$files[$c]."' />
  316. </td>
  317. <td>
  318. <img class='icon' src='".$imagedir.$img.".png' alt='".$files[$c]."' />
  319. <a href='".e_SELF."?".$path.$files[$c]."'>".$files[$c]."</a>
  320. </td>
  321. <td class='right'>".$size."</td>
  322. <td class='right'>".$filedate."</td>
  323. </tr>
  324. ";
  325. $c++;
  326. }
  327. $text .= "
  328. </tbody>
  329. </table>
  330. <div class='buttons-bar left'>
  331. ".$frm->admin_button('check_all', 'jstarget:selectedfile', 'action', LAN_CHECKALL, array('id'=>false))."
  332. ".$frm->admin_button('uncheck_all', 'jstarget:selectedfile', 'action', LAN_UNCHECKALL, array('id'=>false))."
  333. ";
  334. if ($pubfolder || e_QUERY == ""){
  335. require_once(e_HANDLER."file_class.php");
  336. $fl = new e_file;
  337. $dl_dirlist = $fl->get_dirs(e_DOWNLOAD);
  338. $movechoice = array();
  339. $movechoice[] = e_DOWNLOAD;
  340. foreach($dl_dirlist as $dirs){
  341. $movechoice[] = e_DOWNLOAD.$dirs."/";
  342. }
  343. sort($movechoice);
  344. $movechoice[] = e_FILE."downloadimages/";
  345. if(e_QUERY != str_replace("../","",e_UPLOAD)){
  346. $movechoice[] = e_UPLOAD;
  347. }
  348. if(e_QUERY != str_replace("../","",e_FILE."downloadthumbs/")){
  349. $movechoice[] = e_FILE."downloadthumbs/";
  350. }
  351. if(e_QUERY != str_replace("../","",e_FILE."misc/")){
  352. $movechoice[] = e_FILE."misc/";
  353. }
  354. if(e_QUERY != str_replace("../","",e_IMAGE)){
  355. $movechoice[] = e_IMAGE;
  356. }
  357. if(e_QUERY != str_replace("../","",e_IMAGE."newspost_images/")){
  358. $movechoice[] = e_IMAGE."newspost_images/";
  359. }
  360. //FIXME - form elements
  361. $text .= FMLAN_48."&nbsp;<select class='tbox' name='movepath'>\n";
  362. foreach($movechoice as $paths){
  363. $text .= "<option value='$paths'>".str_replace("../","",$paths)."</option>\n";
  364. }
  365. $text .= "</select>".$frm->admin_button('movetodls', FMLAN_50, 'move', '', array('other' => "onclick=\"return e107Helper.confirm('".$tp->toJS(FMLAN_49)."') \""));
  366. }
  367. $text .= "
  368. ".$frm->admin_button('deletefiles', FMLAN_43, 'delete', '', array('title' => $tp->toJS(FMLAN_46)))."
  369. <input type='hidden' name='ac' value='".md5(ADMINPWCHANGE)."' />
  370. </div>
  371. </fieldset>
  372. </form>
  373. ";
  374. $ns->tablerender(FMLAN_29.": <b>root/".$pathd."</b>&nbsp;&nbsp;[ ".count($dirs)." ".$dstr.", ".count($files)." ".$cstr." ]", $text);
  375. function dirsize($dir)
  376. {
  377. global $e107;
  378. $_SERVER["DOCUMENT_ROOT"].e_HTTP.$dir;
  379. $dh = @opendir($_SERVER["DOCUMENT_ROOT"].e_HTTP.$dir);
  380. $size = 0;
  381. while ($file = @readdir($dh)) {
  382. if ($file != "." and $file != "..") {
  383. $path = $dir."/".$file;
  384. if (is_file($_SERVER["DOCUMENT_ROOT"].e_HTTP.$path)) {
  385. $size += filesize($_SERVER["DOCUMENT_ROOT"].e_HTTP.$path);
  386. } else {
  387. $size += dirsize($path."/");
  388. }
  389. }
  390. }
  391. @closedir($dh);
  392. return $e107->parseMemorySize($size);
  393. }
  394. require_once("footer.php");
  395. ?>