1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00
php-e107/e107_admin/filemanager.php

454 lines
12 KiB
PHP
Raw Normal View History

2006-12-02 04:36:16 +00:00
<?php
/*
+ ----------------------------------------------------------------------------+
| e107 website system
|
| <EFBFBD>Steve Dunstan 2001-2002
2006-12-02 04:36:16 +00:00
| http://e107.org
| jalist@e107.org
|
| Released under the terms and conditions of the
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_admin/filemanager.php,v $
| $Revision: 1.11 $
| $Date: 2009-11-07 02:10:34 $
| $Author: e107coders $
2006-12-02 04:36:16 +00:00
+----------------------------------------------------------------------------+
*/
require_once("../class2.php");
if (!getperms("6"))
{
2006-12-02 04:36:16 +00:00
header("location:".e_BASE."index.php");
exit;
}
2009-08-28 16:11:02 +00:00
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
2006-12-02 04:36:16 +00:00
$e_sub_cat = 'filemanage';
require_once("auth.php");
require_once(e_HANDLER.'upload_handler.php');
require_once(e_HANDLER."form_handler.php");
$frm = new e_form();
2006-12-02 04:36:16 +00:00
require_once (e_HANDLER."message_handler.php");
$emessage = &eMessage::getInstance();
//FIXME - messages
2006-12-02 04:36:16 +00:00
$pubfolder = (str_replace("../","",e_QUERY) == str_replace("../","",e_UPLOAD)) ? TRUE : FALSE;
2006-12-02 04:36:16 +00:00
2009-07-07 06:50:56 +00:00
$imagedir = e_IMAGE."filemanager/";
2006-12-02 04:36:16 +00:00
$dir_options[0] = FMLAN_47;
$dir_options[1] = FMLAN_35;
$dir_options[2] = FMLAN_40;
$adchoice[0] = e_UPLOAD;
2006-12-02 04:36:16 +00:00
$adchoice[1] = e_FILE;
$adchoice[2] = e_IMAGE."newspost_images/";
$path = str_replace("../", "", e_QUERY);
if (!$path)
{
2006-12-02 04:36:16 +00:00
$path = str_replace("../", "", $adchoice[0]);
}
if($path == "/")
{
$path = $adchoice[0];
echo "<b>Debug</b> ".$path." <br />";
}
// ===============================================
if (isset($_POST['deleteconfirm']))
2008-04-01 20:06:33 +00:00
{
$deleteList = array();
$moveList = array();
foreach($_POST['deleteconfirm'] as $key=>$delfile)
{
// check for delete.
if (isset($_POST['selectedfile'][$key]) && isset($_POST['deletefiles']))
{
if (!$_POST['ac'] == md5(ADMINPWCHANGE))
{
exit;
}
$destination_file = e_BASE.$delfile;
if (@unlink($destination_file))
{
$message .= FMLAN_26." '".$destination_file."' ".FMLAN_27.".<br />";
$deleteList[] = $destination_file;
}
else
{
$message .= FMLAN_28." '".$destination_file."'.<br />";
}
2006-12-02 04:36:16 +00:00
}
// check for move to downloads or downloadimages.
if (isset($_POST['selectedfile'][$key]) && (isset($_POST['movetodls'])) )
{
$newfile = str_replace($path,"",$delfile);
// Move file to whatever folder.
if (isset($_POST['movetodls']))
{
$newpath = $_POST['movepath'];
if (rename(e_BASE.$delfile,$newpath.$newfile))
{
$message .= FMLAN_38." ".$newpath.$newfile."<br />";
$moveList[] = e_BASE.$delfile.'=>'.$newpath.$newfile;
}
else
{
$message .= FMLAN_39." ".$newpath.$newfile."<br />";
$message .= (!is_writable($newpath)) ? $newpath.LAN_NOTWRITABLE : "";
}
2006-12-02 04:36:16 +00:00
}
}
}
if (count($deleteList))
{
$admin_log->log_event('FILEMAN_01',implode('[!br!]',$deleteList),E_LOG_INFORMATIVE,'');
}
if (count($moveList))
{
$admin_log->log_event('FILEMAN_02',implode('[!br!]',$moveList),E_LOG_INFORMATIVE,'');
}
2006-12-02 04:36:16 +00:00
}
if (isset($_POST['upload']))
{
if (!$_POST['ac'] == md5(ADMINPWCHANGE))
{
2006-12-02 04:36:16 +00:00
exit;
}
$uploadList = array();
2006-12-02 04:36:16 +00:00
$pref['upload_storagetype'] = "1";
require_once(e_HANDLER."upload_handler.php");
$files = $_FILES['file_userfile'];
foreach($files['name'] as $key => $name)
{
if ($files['size'][$key])
{
2006-12-02 04:36:16 +00:00
$uploaded = file_upload(e_BASE.$_POST['upload_dir'][$key]);
$uploadList[] = $_POST['upload_dir'][$key].$uploaded[0]['name'];
2006-12-02 04:36:16 +00:00
}
}
if (count($uploadList))
{
$admin_log->log_event('FILEMAN_03',implode('[!br!]',$uploadList),E_LOG_INFORMATIVE,'');
}
2006-12-02 04:36:16 +00:00
}
if (isset($message))
{
2006-12-02 04:36:16 +00:00
$ns->tablerender("", "<div style=\"text-align:center\"><b>".$message."</b></div>");
}
if (strpos(e_QUERY, ".") && !is_dir(realpath(e_BASE.$path)))
{
echo "
<div>
<iframe style='width:99%' src='".e_BASE.e_QUERY."' height='300' scrolling='yes'>asdas</iframe>
</div>
";
if (!strpos(e_QUERY, "/"))
{
2006-12-02 04:36:16 +00:00
$path = "";
}
else
{
2006-12-02 04:36:16 +00:00
$path = substr($path, 0, strrpos(substr($path, 0, -1), "/"))."/";
}
}
2006-12-02 04:36:16 +00:00
$files = array();
$dirs = array();
$path = explode("?", $path);
$path = $path[0];
$path = explode(".. ", $path);
$path = $path[0];
if ($handle = opendir(e_BASE.$path))
{
2006-12-02 04:36:16 +00:00
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (getenv('windir') && is_file(e_BASE.$path."\\".$file)) {
if (is_file(e_BASE.$path."\\".$file)) {
$files[] = $file;
} else {
$dirs[] = $file;
}
} else {
if (is_file(e_BASE.$path."/".$file)) {
$files[] = $file;
} else {
$dirs[] = $file;
}
}
}
}
}
closedir($handle);
if (count($files) != 0) {
sort($files);
}
if (count($dirs) != 0) {
sort($dirs);
}
if (count($files) == 1) {
$cstr = FMLAN_12;
} else {
$cstr = FMLAN_13;
}
if (count($dirs) == 1) {
$dstr = FMLAN_14;
} else {
$dstr = FMLAN_15;
}
$pathd = $path;
$text = "
<form method='post' action='".e_SELF."?".e_QUERY."'>
<div class='buttons-bar left'>
2006-12-02 04:36:16 +00:00
".FMLAN_32."
<select name='admin_choice' class='tbox' onchange=\"location.href=this.options[selectedIndex].value\">";
2006-12-02 04:36:16 +00:00
foreach($dir_options as $key=>$opt){
$select = (str_replace("../","",$adchoice[$key]) == e_QUERY) ? "selected='selected'" : "";
$text .= "<option value='".e_SELF."?".str_replace("../","",$adchoice[$key])."' $select>".$opt."</option>";
2006-12-02 04:36:16 +00:00
}
$text .= "</select>
</div>
</form>
";
// $ns->tablerender(FMLAN_34, $text);
2006-12-02 04:36:16 +00:00
// Get largest allowable file upload
$max_file_size = get_user_max_upload();
2006-12-02 04:36:16 +00:00
if ($path != e_FILE) {
if (substr_count($path, "/") == 1) {
//$pathup = e_SELF;
$pathup = '';
2006-12-02 04:36:16 +00:00
} else {
$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>";
2006-12-02 04:36:16 +00:00
}
}
$text .= "
<form enctype='multipart/form-data' action='".e_SELF.(e_QUERY ? "?".e_QUERY : "")."' method='post'>
<fieldset id='core-filemanager'>
<legend class='e-hideme'>XX</legend>
<table cellpadding='0' cellspacing='0' class='adminlist'>
<colgroup span='4'>
<col style='width: 5%'></col>
<col style='width: 40%'></col>
<col style='width: 20%'></col>
<col style='width: 15%'></col>
</colgroup>
<thead>
<tr>
<th class='center'>
".$pathup."
<!-- <a href='filemanager.php'><img src='".$imagedir."home.png' alt='".FMLAN_16."' /></a> -->
<input type='hidden' name='MAX_FILE_SIZE' value='{$max_file_size}' />
</th>
<th class='center'>".FMLAN_17."</th>
<th class='center'>".FMLAN_18."</th>
<th class='center'>".FMLAN_19."</th>
</tr>
</thead>
<tbody>
";
2006-12-02 04:36:16 +00:00
$c = 0;
while ($dirs[$c]) {
$dirsize = dirsize($path.$dirs[$c]);
$el_id = str_replace(array('/','_',' ','\\'),'-',$path.$dirs[$c]);
2006-12-02 04:36:16 +00:00
if (FILE_UPLOADS && is_writable(e_BASE.$path.$dirs[$c])) {
$up_button = $frm->admin_button('erquest', FMLAN_21, 'action', '', array('id'=>false, 'other'=>"onclick='e107Helper.toggle(\"{$el_id}\")'"));
2006-12-02 04:36:16 +00:00
} else {
$up_button = "&nbsp;leave_32.png";
2006-12-02 04:36:16 +00:00
}
//FIXME - upload link not working, raplace with image
$text .= "
<tr>
<td class='center middle'><a href='#{$el_id}' class='e-expandit'>upload</a></td>
<td>
2009-07-25 07:54:36 +00:00
<a class='action' href='".e_SELF."?".$path.$dirs[$c]."/'><img class='icon action S16' src='".$imagedir."folder.png' alt='".$dirs[$c]." ".FMLAN_31."' /></a>
<a href='".e_SELF."?".$path.$dirs[$c]."/'>".$dirs[$c]."</a>
<div class='e-hideme' id='{$el_id}'>
<div class='field-spacer'>".$frm->file('file_userfile[]', array('id'=>false, 'size'=>'20')).$frm->admin_button('upload', FMLAN_22, '', '', array('id'=>false))."</div>
<input type='hidden' name='upload_dir[]' value='".$path.$dirs[$c]."' />
</div>
</td>
<td class='right'>".$dirsize."</td>
<td class='right'>&nbsp;</td>
</tr>
";
2006-12-02 04:36:16 +00:00
$c++;
}
$c = 0;
while ($files[$c]) {
$img = substr(strrchr($files[$c], "."), 1, 3);
if (!$img || !preg_match("/css|exe|gif|htm|jpg|js|php|png|txt|xml|zip/i", $img)) {
$img = "def";
}
$size = $e107->parseMemorySize(filesize(e_BASE.$path."/".$files[$c]));
2006-12-02 04:36:16 +00:00
$gen = new convert;
$filedate = $gen -> convert_date(filemtime(e_BASE.$path."/".$files[$c]), "forum");
$text .= "
<tr>
<td class='center middle autocheck'>
".$frm->checkbox("selectedfile[$c]", 1, false, array('id'=>false))."
<input type='hidden' name='deleteconfirm[$c]' value='".$path.$files[$c]."' />
</td>
<td>
<img class='icon' src='".$imagedir.$img.".png' alt='".$files[$c]."' />
<a href='".e_SELF."?".$path.$files[$c]."'>".$files[$c]."</a>
</td>
<td class='right'>".$size."</td>
<td class='right'>".$filedate."</td>
</tr>
";
2006-12-02 04:36:16 +00:00
$c++;
}
$text .= "
</tbody>
</table>
<div class='buttons-bar left'>
".$frm->admin_button('check_all', 'jstarget:selectedfile', 'action', LAN_CHECKALL, array('id'=>false))."
".$frm->admin_button('uncheck_all', 'jstarget:selectedfile', 'action', LAN_UNCHECKALL, array('id'=>false))."
";
2006-12-02 04:36:16 +00:00
if ($pubfolder || e_QUERY == ""){
require_once(e_HANDLER."file_class.php");
$fl = new e_file;
$dl_dirlist = $fl->get_dirs(e_DOWNLOAD);
$movechoice = array();
$movechoice[] = e_DOWNLOAD;
foreach($dl_dirlist as $dirs){
$movechoice[] = e_DOWNLOAD.$dirs."/";
}
sort($movechoice);
$movechoice[] = e_FILE."downloadimages/";
if(e_QUERY != str_replace("../","",e_UPLOAD)){
$movechoice[] = e_UPLOAD;
2006-12-02 04:36:16 +00:00
}
if(e_QUERY != str_replace("../","",e_FILE."downloadthumbs/")){
$movechoice[] = e_FILE."downloadthumbs/";
}
if(e_QUERY != str_replace("../","",e_FILE."misc/")){
$movechoice[] = e_FILE."misc/";
}
if(e_QUERY != str_replace("../","",e_IMAGE)){
$movechoice[] = e_IMAGE;
}
if(e_QUERY != str_replace("../","",e_IMAGE."newspost_images/")){
$movechoice[] = e_IMAGE."newspost_images/";
}
//FIXME - form elements
2006-12-02 04:36:16 +00:00
$text .= FMLAN_48."&nbsp;<select class='tbox' name='movepath'>\n";
foreach($movechoice as $paths){
$text .= "<option value='$paths'>".str_replace("../","",$paths)."</option>\n";
}
$text .= "</select>".$frm->admin_button('movetodls', FMLAN_50, 'move', '', array('other' => "onclick=\"return e107Helper.confirm('".$tp->toJS(FMLAN_49)."') \""));
2006-12-02 04:36:16 +00:00
}
$text .= "
".$frm->admin_button('deletefiles', FMLAN_43, 'delete', '', array('title' => $tp->toJS(FMLAN_46)))."
<input type='hidden' name='ac' value='".md5(ADMINPWCHANGE)."' />
</div>
</fieldset>
</form>
";
2006-12-02 04:36:16 +00:00
$ns->tablerender(FMLAN_29.": <b>root/".$pathd."</b>&nbsp;&nbsp;[ ".count($dirs)." ".$dstr.", ".count($files)." ".$cstr." ]", $text);
function dirsize($dir)
{
global $e107;
2006-12-02 04:36:16 +00:00
$_SERVER["DOCUMENT_ROOT"].e_HTTP.$dir;
$dh = @opendir($_SERVER["DOCUMENT_ROOT"].e_HTTP.$dir);
$size = 0;
while ($file = @readdir($dh)) {
if ($file != "." and $file != "..") {
$path = $dir."/".$file;
if (is_file($_SERVER["DOCUMENT_ROOT"].e_HTTP.$path)) {
$size += filesize($_SERVER["DOCUMENT_ROOT"].e_HTTP.$path);
} else {
$size += dirsize($path."/");
}
}
}
@closedir($dh);
return $e107->parseMemorySize($size);
2006-12-02 04:36:16 +00:00
}
require_once("footer.php");
/**
* Handle page DOM within the page header
*
* @return string JS source
*/
function headerjs()
{
require_once(e_HANDLER.'js_helper.php');
$ret = "
<script type='text/javascript'>
//add required core lan - delete confirm message
(".e_jshelper::toString(LAN_JSCONFIRM).").addModLan('core', 'delete_confirm');
if(typeof e107Admin == 'undefined') var e107Admin = {}
/**
* OnLoad Init Control
*/
e107Admin.initRules = {
'Helper': true,
'AdminMenu': false
}
</script>
<script type='text/javascript' src='".e_FILE_ABS."jslib/core/admin.js'></script>
";
return $ret;
}
2006-12-02 04:36:16 +00:00
?>