/** * rawlist * * @param string $dir * @return array */ private function _rawlist($dir = '/') { self::$_dir = $dir = str_replace('\\', '/', $dir); if (isset(self::$_rawlist[self::$_dir])) { return self::$_rawlist[self::$_dir]; } elseif (isset(self::$_rawlist[self::$_dir . '/'])) { return self::$_rawlist[self::$_dir . '/']; } ftp_chdir($this->_res, '/'); if (preg_match('/^[A-Z]+?:[\\*|\\/*]+(.*)/', $dir, $match)) { $dir = $match[1] ? '/' . $match[1] : '/'; } foreach ((array) ftp_rawlist($this->_res, '-A /' . IOWrapper::set($dir)) as $var) { if (mb_substr($var, -3) == ' ..') { continue; } else { preg_replace_callback('`^(d|l|\\-{1}+)(.{9}+)\\s*(?:\\d{1,3})\\s*(\\d+?|\\w+?)\\s*(\\d+?|\\w+?)\\s*(\\d*)\\s([a-zA-Z]{3}+)\\s*([0-9]{1,2}+)\\s*([0-9]{2}+):?([0-9]{2}+)\\s*(.*)$`U', array($this, '_rawlistCallback'), $var); } } self::$_rawlist[self::$_dir]['.'] = array('chmod' => '0', 'uid' => '', 'owner' => '', 'gid' => '', 'group' => '', 'size' => '0', 'mtime' => '', 'file' => '.', 'type' => 'dir'); return self::$_rawlist[self::$_dir]; }
/** * renameFile * * @param string $name * @param string $arch_name * @param bool $del * @param bool $overwrite * @return string */ public function renameFile($name, $arch_name, $del = false, $overwrite = false) { $tmp = Config::getTemp() . '/GmanagerZip' . GMANAGER_REQUEST_TIME; $zip = $this->_open(); $folder = ''; $sysName = IOWrapper::set($name); foreach ($zip->extract(PCLZIP_OPT_PATH, $tmp) as $f) { if ($f['status'] != 'ok') { Helper_System::clean($tmp); if (Config::get('Gmanager', 'mode') == 'FTP') { Gmanager::getInstance()->ftpArchiveEnd(); } return Helper_View::message(Language::get('extract_false'), Helper_View::MESSAGE_ERROR); break; } if ($arch_name == $f['stored_filename']) { $folder = $f['folder']; } } if (file_exists($tmp . '/' . $sysName)) { if ($overwrite) { if ($folder) { Helper_System::clean($tmp . '/' . $sysName); } else { unlink($tmp . '/' . $sysName); } } else { Helper_System::clean($tmp); if (Config::get('Gmanager', 'mode') == 'FTP') { Gmanager::getInstance()->ftpArchiveEnd(); } return Helper_View::message(Language::get('overwrite_false'), Helper_View::MESSAGE_ERROR); } } if ($folder) { @mkdir($tmp . '/' . $sysName, 0755, true); } elseif (!is_dir($tmp . '/' . dirname($sysName))) { @mkdir($tmp . '/' . dirname($sysName), 0755, true); } if ($folder) { // переделать на ftp if ($del) { $result = Gmanager::getInstance()->moveFiles($tmp . '/' . $arch_name, $tmp . '/' . $name); } else { $result = Gmanager::getInstance()->copyFiles($tmp . '/' . $arch_name, $tmp . '/' . $name); } } else { if ($del) { $result = rename($tmp . '/' . $arch_name, $tmp . '/' . $sysName); } else { $result = copy($tmp . '/' . $arch_name, $tmp . '/' . $sysName); } } if (!$result) { Helper_System::clean($tmp); if (Config::get('Gmanager', 'mode') == 'FTP') { Gmanager::getInstance()->ftpArchiveEnd(); } if ($folder) { if ($del) { return Helper_View::message(str_replace('%title%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('move_files_false')), Helper_View::MESSAGE_ERROR); } else { return Helper_View::message(str_replace('%title%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('copy_files_false')), Helper_View::MESSAGE_ERROR); } } else { if ($del) { return Helper_View::message(str_replace('%file%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('move_file_false')), Helper_View::MESSAGE_ERROR); } else { return Helper_View::message(str_replace('%file%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('copy_file_false')), Helper_View::MESSAGE_ERROR); } } } $result = $zip->create($tmp, PCLZIP_OPT_REMOVE_PATH, mb_substr($tmp, mb_strlen(dirname(dirname($tmp))))) != 0; Helper_System::clean($tmp); if (Config::get('Gmanager', 'mode') == 'FTP') { Gmanager::getInstance()->ftpArchiveEnd($this->_name); } if ($result) { if ($folder) { if ($del) { return Helper_View::message(str_replace('%title%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('move_files_true')), Helper_View::MESSAGE_SUCCESS); } else { return Helper_View::message(str_replace('%title%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('copy_files_true')), Helper_View::MESSAGE_SUCCESS); } } else { if ($del) { return Helper_View::message(str_replace('%file%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('move_file_true')), Helper_View::MESSAGE_SUCCESS); } else { return Helper_View::message(str_replace('%file%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('copy_file_true')), Helper_View::MESSAGE_SUCCESS); } } } else { if ($folder) { if ($del) { return Helper_View::message(str_replace('%title%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('move_files_false')), Helper_View::MESSAGE_ERROR); } else { return Helper_View::message(str_replace('%title%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('copy_files_false')), Helper_View::MESSAGE_ERROR); } } else { if ($del) { return Helper_View::message(str_replace('%file%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('move_file_false')), Helper_View::MESSAGE_ERROR); } else { return Helper_View::message(str_replace('%file%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('copy_file_false')), Helper_View::MESSAGE_ERROR); } } } }
/** * renameFile * * @param string $name * @param string $arch_name * @param bool $del * @param bool $overwrite * @return string */ public function renameFile($name, $arch_name, $del = false, $overwrite = false) { $tmp = Config::getTemp() . '/GmanagerTar' . GMANAGER_REQUEST_TIME; $tgz = $this->_open(); $sysName = IOWrapper::set($name); $folder = ''; foreach ($tgz->listContent() as $f) { if ($arch_name == $f['filename']) { $folder = $f['typeflag'] == 5 ? 1 : 0; break; } } if (!$tgz->extract($tmp)) { Helper_System::clean($tmp); if (Config::get('Gmanager', 'mode') == 'FTP') { Gmanager::getInstance()->ftpArchiveEnd(); } return Helper_View::message(Language::get('extract_false'), Helper_View::MESSAGE_ERROR); } if (file_exists($tmp . '/' . $sysName)) { if ($overwrite) { if ($folder) { Helper_System::clean($tmp . '/' . $sysName); } else { unlink($tmp . '/' . $sysName); } } else { Helper_System::clean($tmp); if (Config::get('Gmanager', 'mode') == 'FTP') { Gmanager::getInstance()->ftpArchiveEnd(); } return Helper_View::message(Language::get('overwrite_false'), Helper_View::MESSAGE_ERROR); } } if ($folder) { @mkdir($tmp . '/' . $sysName, 0755, true); } else { @mkdir($tmp . '/' . dirname($sysName), 0755, true); } if ($folder) { if ($del) { $result = Gmanager::getInstance()->moveFiles($tmp . '/' . $name, $tmp . '/' . $arch_name); } else { $result = Gmanager::getInstance()->copyFiles($tmp . '/' . $name, $tmp . '/' . $arch_name); } } else { if ($del) { $result = rename($tmp . '/' . $arch_name, $tmp . '/' . $sysName); } else { $result = copy($tmp . '/' . $arch_name, $tmp . '/' . $sysName); } } if (!$result) { Helper_System::clean($tmp); if (Config::get('Gmanager', 'mode') == 'FTP') { Gmanager::getInstance()->ftpArchiveEnd(); } if ($folder) { if ($del) { return Helper_View::message(str_replace('%title%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('move_files_false')), Helper_View::MESSAGE_ERROR); } else { return Helper_View::message(str_replace('%title%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('copy_files_false')), Helper_View::MESSAGE_ERROR); } } else { if ($del) { return Helper_View::message(str_replace('%file%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('move_file_false')), Helper_View::MESSAGE_ERROR); } else { return Helper_View::message(str_replace('%file%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('copy_file_false')), Helper_View::MESSAGE_ERROR); } } } $result = $tgz->createModify($tmp, '.', $tmp); Helper_System::clean($tmp); if (Config::get('Gmanager', 'mode') == 'FTP') { Gmanager::getInstance()->ftpArchiveEnd($this->_name); } if ($result) { if ($folder) { if ($del) { return Helper_View::message(str_replace('%title%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('move_files_true')), Helper_View::MESSAGE_SUCCESS); } else { return Helper_View::message(str_replace('%title%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('copy_files_true')), Helper_View::MESSAGE_SUCCESS); } } else { if ($del) { return Helper_View::message(str_replace('%file%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('move_file_true')), Helper_View::MESSAGE_SUCCESS); } else { return Helper_View::message(str_replace('%file%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('copy_file_true')), Helper_View::MESSAGE_SUCCESS); } } } else { if ($folder) { if ($del) { return Helper_View::message(str_replace('%title%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('move_files_false')), Helper_View::MESSAGE_ERROR); } else { return Helper_View::message(str_replace('%title%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('copy_files_false')), Helper_View::MESSAGE_ERROR); } } else { if ($del) { return Helper_View::message(str_replace('%file%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('move_file_false')), Helper_View::MESSAGE_ERROR); } else { return Helper_View::message(str_replace('%file%', htmlspecialchars($arch_name, ENT_NOQUOTES), Language::get('copy_file_false')), Helper_View::MESSAGE_ERROR); } } } }
$v = ''; } echo '<div class="input"><form action="change.php?go=cmd&c=' . Registry::get('rCurrent') . '" method="post"><div>' . Language::get('cmd_code') . '<br/><input type="text" name="cmd" value="' . $v . '" style="width:98%"/><br/><input type="submit" value="' . Language::get('cmd_go') . '"/></div></form></div>'; break; default: if (!Gmanager::getInstance()->file_exists(Registry::get('current'))) { echo Helper_View::message(Language::get('not_found'), Helper_View::MESSAGE_ERROR); break; } $archive = Helper_Archive::isArchive(Helper_System::getType(Registry::get('current'))); if (isset($_GET['f']) && ($archive == Archive::FORMAT_ZIP || $archive == Archive::FORMAT_TAR || $archive == Archive::FORMAT_BZ2)) { $r_file = Helper_View::getRawurl($_GET['f']); $h_file = htmlspecialchars($_GET['f']); echo '<div class="input"><form action="change.php?go=rename&c=' . Registry::get('rCurrent') . '&f=' . $r_file . '" method="post"><div><input type="hidden" name="arch_name" value="' . $r_file . '"/>' . Language::get('change_func') . '<br/><input type="text" name="name" value="' . $h_file . '"/><br/><input type="checkbox" name="overwrite" id="overwrite" checked="checked"/><label for="overwrite">' . Language::get('overwrite_existing_files') . '</label><br/><input type="checkbox" name="del" id="del" value="1"/><label for="del">' . Language::get('change_del') . '</label><br/><input type="submit" value="' . Language::get('ch') . '"/></div></form></div>'; } else { $size = $md5 = ''; if (Registry::get('currentType') == 'dir') { $size = Helper_View::formatSize(Gmanager::getInstance()->size(Registry::get('current'), true)); } else { $size = Helper_View::formatSize(Gmanager::getInstance()->size(Registry::get('current'))); if (Config::get('Gmanager', 'mode') == 'FTP') { $md5 = Language::get('md5') . ': ' . md5(Gmanager::getInstance()->file_get_contents(Registry::get('current'))); } else { $md5 = Language::get('md5') . ': ' . md5_file(IOWrapper::set(Registry::get('current'))); } } echo '<div class="input"><form action="change.php?go=rename&c=' . Registry::get('rCurrent') . '" method="post"><div>' . Language::get('change_func') . '<br/><input type="text" name="name" value="' . $realpath . '"/><br/><input type="checkbox" name="overwrite" id="overwrite" checked="checked"/><label for="overwrite">' . Language::get('overwrite_existing_files') . '</label><br/><input type="checkbox" name="del" id="del" value="1"/><label for="del">' . Language::get('change_del') . '</label><br/><input onkeypress="return Gmanager.number(event)" type="text" size="4" maxlength="4" style="-wap-input-format:\'4N\';width:28pt;" name="chmod" value="' . Gmanager::getInstance()->lookChmod(Registry::get('current')) . '"/>' . Language::get('change_chmod') . '<br/><input type="submit" value="' . Language::get('ch') . '"/></div></form></div><div>' . Language::get('sz') . ': ' . $size . '<br/>' . $md5 . '</div>'; } break; } echo '<div class="rb">' . round(microtime(true) - GMANAGER_START, 4) . ' / ' . Helper_View::formatSize(memory_get_peak_usage()) . '<br/></div>' . Registry::get('foot');
/** * iterator * * @param string $dir * @return array */ public function iterator($dir) { return array_map(array('IOWrapper', 'get'), (array) array_diff(scandir(IOWrapper::set($dir), 0), array('.', '..'))); }
/** * extractArchive * * @param string $name * @param array $chmod * @param bool $overwrite * @return string */ public function extractArchive($name = '', $chmod = array(), $overwrite = false) { $sysName = IOWrapper::set($name); if (Config::get('Gmanager', 'mode') == 'FTP') { $sysName = $sysName[0] == '/' ? $sysName : dirname(IOWrapper::set($this->_name) . '/') . '/' . $sysName; $ftp_name = Config::getTemp() . '/GmanagerFtpRar' . GMANAGER_REQUEST_TIME; mkdir($ftp_name, 0777); } $rar = $this->_open(); $err = ''; foreach ($rar->getEntries() as $entry) { $n = $entry->getName(); if (!$overwrite && Gmanager::getInstance()->file_exists($name . '/' . IOWrapper::get($n))) { $err .= Language::get('overwrite_false') . ' (' . htmlspecialchars($n, ENT_NOQUOTES) . ')<br/>'; } else { if (!$entry->extract(Config::get('Gmanager', 'mode') == 'FTP' ? $ftp_name : $sysName)) { if (Config::get('Gmanager', 'mode') == 'FTP') { Gmanager::getInstance()->ftpArchiveEnd(); rmdir($ftp_name); } $err .= str_replace('%file%', htmlspecialchars($n, ENT_NOQUOTES), Language::get('extract_file_false_ext')) . '<br/>'; } } if (Gmanager::getInstance()->is_dir($name . '/' . IOWrapper::get($n))) { Gmanager::getInstance()->rechmod($name . '/' . IOWrapper::get($n), $chmod[1]); } else { Gmanager::getInstance()->rechmod($name . '/' . IOWrapper::get($n), $chmod[0]); } } if (Config::get('Gmanager', 'mode') == 'FTP') { Gmanager::getInstance()->createDir($sysName, $chmod[1]); Gmanager::getInstance()->ftpMoveFiles($ftp_name, $sysName, $chmod[0], $chmod[1], $overwrite); Gmanager::getInstance()->ftpArchiveEnd(); } if (Config::get('Gmanager', 'mode') == 'FTP' || Gmanager::getInstance()->is_dir($name)) { Gmanager::getInstance()->rechmod($name, $chmod[1]); return Helper_View::message(Language::get('extract_true'), Helper_View::MESSAGE_SUCCESS) . ($err ? Helper_View::message(rtrim($err, '<br/>'), Helper_View::MESSAGE_ERROR) : ''); } else { return Helper_View::message(Language::get('extract_false'), Helper_View::MESSAGE_ERROR_EMAIL); } }
/** * gzExtract * * @param string $c * @param string $name * @param array $chmod * @param bool $overwrite * @return string */ public function gzExtract($c = '', $name = '', $chmod = array(), $overwrite = false) { $this->createDir($name, $chmod[1]); $tmp = Config::get('Gmanager', 'mode') == 'FTP' ? $this->ftpArchiveStart($c) : IOWrapper::set($c); $info = $this->getGzInfo($tmp); $data = null; if ($overwrite || !self::$_instance->file_exists($name . '/' . $info['name'])) { if (!self::$_instance->file_put_contents($name . '/' . $info['name'], $this->getGzContent($tmp))) { $data = Helper_View::message(Language::get('extract_file_false') . '<br/>' . Errors::get(), Helper_View::MESSAGE_ERROR_EMAIL); } } else { $data = Helper_View::message(Language::get('overwrite_false') . ' (' . htmlspecialchars($name . '/' . $info['name'], ENT_NOQUOTES) . ')', Helper_View::MESSAGE_ERROR); } if (Config::get('Gmanager', 'mode') == 'FTP') { $this->ftpArchiveEnd(); } if ($data) { return $data; } if (self::$_instance->is_file($name . '/' . $info['name'])) { if ($chmod[0]) { $this->rechmod($name . '/' . $info['name'], $chmod[0]); } return Helper_View::message(Language::get('extract_file_true'), Helper_View::MESSAGE_SUCCESS); } else { return Helper_View::message(Language::get('extract_file_false'), Helper_View::MESSAGE_ERROR_EMAIL); } }