function execute(&$controller, &$xoopsUser) { $form_cancel = $controller->mRoot->mContext->mRequest->getRequest('_form_control_cancel'); if ($form_cancel != null) { return USER_FRAME_VIEW_CANCEL; } $this->mActionForm->fetch(); $this->mActionForm->validate(); if ($this->mActionForm->hasError()) { return $this->getDefaultView($controller, $xoopsUser); } $formFile = $this->mActionForm->get('upload'); $formFileExt = $formFile->getExtension(); $files = array(); $avatarimages = array(); if ( strtolower($formFileExt) == "zip" ) { If ( !file_exists(XOOPS_ROOT_PATH . "/class/Archive_Zip.php") ) { return USER_FRAME_VIEW_ERROR; } require_once XOOPS_ROOT_PATH . "/class/Archive_Zip.php" ; $zip = new Archive_Zip($formFile->_mTmpFileName) ; $files = $zip->extract( array( 'extract_as_string' => true ) ) ; if( ! is_array( @$files ) ) { return USER_FRAME_VIEW_ERROR; } if (!$this->_fetchZipAvatarImages($files, $avatarimages)) { return USER_FRAME_VIEW_ERROR; } }//if zip end else { require_once XOOPS_ROOT_PATH . "/class/class.tar.php"; $tar =new tar(); $tar->openTar($formFile->_mTmpFileName); if (!is_array( @$tar->files)) { return USER_FRAME_VIEW_ERROR; } if (!$this->_fetchTarAvatarImages($tar->files, $avatarimages)) { return USER_FRAME_VIEW_ERROR; } }//end tar if (!$this->_saveAvatarImages($avatarimages)) { return USER_FRAME_VIEW_ERROR; } return USER_FRAME_VIEW_SUCCESS; }
protected function extractArchive(PhingFile $zipfile) { $extractParams = array('add_path' => $this->todir->getAbsolutePath()); if (!empty($this->removepath)) { $extractParams['remove_path'] = $this->removepath; } $this->log("Extracting zip: " . $zipfile->__toString() . ' to ' . $this->todir->__toString(), Project::MSG_INFO); try { $zip = new Archive_Zip($zipfile->getAbsolutePath()); $extractResponse = $zip->extract($extractParams); if (is_array($extractResponse)) { foreach ($extractResponse as $extractedPath) { $this->log('Extracted' . $extractedPath['stored_filename'] . ' to ' . $this->todir->__toString(), Project::MSG_VERBOSE); } } else { if ($extractResponse === 0) { throw new BuildException('Failed to extract zipfile: ' . $zip->errorInfo(true)); } } } catch (IOException $ioe) { $msg = "Could not extract ZIP: " . $ioe->getMessage(); throw new BuildException($msg, $ioe, $this->getLocation()); } }
/** * Handle uploaded plugin * * @return string HTML or error message * */ function MONITOR_plugin_upload($plugin = '') { global $_CONF, $_MONITOR_CONF, $_TABLES; $retval = ''; if ($plugin == '' || $_MONITOR_CONF['repository'] == '') { return; } $url = "https://api.github.com/repos/{$_MONITOR_CONF['repository']}/" . $plugin . '/releases'; //Get last release for this plugin $releases = MONITOR_curlRequestOnGitApi($url); $version = $releases[0]['tag_name']; $path_admin = $_CONF['path_html'] . substr($_CONF['site_admin_url'], strlen($_CONF['site_url']) + 1) . '/'; $upload_success = false; //Download the zip file from repository $source = "https://codeload.github.com/{$_MONITOR_CONF['repository']}/{$plugin}/zip/{$version}"; $destination = fopen($_CONF['path_data'] . $plugin . '.zip', 'w+'); set_time_limit(0); // unlimited max execution time $options = array(CURLOPT_FILE => $destination, CURLOPT_TIMEOUT => 28800, CURLOPT_URL => $source, CURLOPT_USERAGENT => $_MONITOR_CONF['repository'], CURLOPT_SSL_VERIFYPEER => false); $ch = curl_init(); curl_setopt_array($ch, $options); $result = curl_exec($ch); curl_close($ch); $plugin_file = $_CONF['path_data'] . $plugin . '.zip'; // Name the plugin file if (!file_exists($plugin_file)) { COM_errorLog('MONITOR - Download failed for Plugin: ' . $plugin); return 'Download failed for Plugin: ' . $plugin; } else { chmod($plugin_file, 0755); } require_once $_CONF['path_system'] . 'classes/unpacker.class.php'; $archive = new unpacker($plugin_file, 'application/x-zip'); if ($archive == false) { return 72; } COM_errorLog('MONITOR - Download ' . $plugin . ' plugin: ok'); $pi_did_exist = false; // plugin directory already existed $pi_had_entry = false; // plugin had an entry in the database $pi_was_enabled = false; // plugin was enabled $alternate = false; if (file_exists($_CONF['path'] . 'plugins/' . $plugin)) { $pi_did_exist = true; // plugin directory already exists $pstatus = DB_query("SELECT pi_name, pi_enabled FROM {$_TABLES['plugins']} WHERE pi_name = '{$plugin}'"); $A = DB_fetchArray($pstatus); if (isset($A['pi_name'])) { $pi_had_entry = true; $pi_was_enabled = $A['pi_enabled'] == 1; } if ($pi_was_enabled) { // disable temporarily while we move the files around DB_change($_TABLES['plugins'], 'pi_enabled', 0, 'pi_name', $plugin); COM_errorLog('MONITOR - Disable Plugin: ' . $plugin); } require_once 'System.php'; $plugin_dir = $_CONF['path'] . 'plugins/' . $plugin; if (file_exists($plugin_dir . '.previous')) { @System::rm('-rf ' . $plugin_dir . '.previous'); } if (file_exists($plugin_dir)) { rename($plugin_dir, $plugin_dir . '.previous'); COM_errorLog('MONITOR - Rename: ' . $plugin_dir . ' to ' . $plugin_dir . '.previous'); } $public_dir = $_CONF['path_html'] . $plugin; if (file_exists($public_dir . '.previous')) { @System::rm('-rf ' . $public_dir . '.previous'); } if (file_exists($public_dir)) { rename($public_dir, $public_dir . '.previous'); COM_errorLog('MONITOR - Rename: ' . $public_dir . ' to ' . $public_dir . '.previous'); } $admin_dir = $path_admin . 'plugins/' . $plugin; if (file_exists($admin_dir . '.previous')) { @System::rm('-rf ' . $admin_dir . '.previous'); } if (file_exists($admin_dir)) { rename($admin_dir, $admin_dir . '.previous'); COM_errorLog('MONITOR - Rename: ' . $admin_dir . ' to ' . $admin_dir . '.previous'); } } $upload_success = false; // Extract the uploaded archive to the data directory $upload_success = $archive->unpack($_CONF['path_data']); if (!$upload_success) { //Try alternative unzip unset($archive); require_once 'Archive/Zip.php'; $archive = new Archive_Zip($plugin_file); if ($archive == false) { return 72; } $params = array('add_path' => $_CONF['path_data']); $extract = $archive->extract($params); if (is_array($extract)) { $upload_success = true; } $alternate = true; } if (!$upload_success) { COM_errorLog("MONITOR - Can't unzip the archive. Update for {$plugin_dir} plugin failed! Please check the archive in your data folder. Could be an OS issue during unzip."); if (file_exists($plugin_dir . '.previous')) { rename($plugin_dir . '.previous', $plugin_dir); COM_errorLog('MONITOR - Rename: ' . $plugin_dir . '.previous' . ' to ' . $plugin_dir); } if (file_exists($public_dir . '.previous')) { rename($public_dir . '.previous', $public_dir); COM_errorLog('MONITOR - Rename: ' . $public_dir . '.previous' . ' to ' . $public_dir); } if (file_exists($admin_dir . '.previous')) { rename($admin_dir . '.previous', $admin_dir); COM_errorLog('MONITOR - Rename: ' . $admin_dir . '.previous' . ' to ' . $admin_dir); } if ($pi_was_enabled) { DB_change($_TABLES['plugins'], 'pi_enabled', 1, 'pi_name', $plugin); COM_errorLog('MONITOR - Enable Plugin: ' . $plugin); } return 72; exit; } else { //Move files to plugins directory COM_errorLog('MONITOR - Plugin update: ' . $plugin); if (!$alternate) { $folder_name = $archive->getdir(); } else { $listcontent = $archive->listContent(); $folder_name = $listcontent[0]['filename']; if (substr($folder_name, -1) == '/') { $folder_name = substr($folder_name, 0, -1); } } if ($folder_name == '') { exit; } $srcDir = $_CONF['path_data'] . $folder_name; $destDir = $_CONF['path'] . 'plugins/' . $plugin; //Move from data folder to plugins folder rename($srcDir, $destDir); $plg_path = $_CONF['path'] . 'plugins/' . $plugin . '/'; if (file_exists($plg_path . 'public_html')) { rename($plg_path . 'public_html', $_CONF['path_html'] . $plugin); COM_errorLog('MONITOR - Move ' . $plg_path . 'public_html to ' . $_CONF['path_html'] . $plugin); } else { COM_errorLog('MONITOR - ' . $plg_path . 'public_html does not exist'); } if (file_exists($plg_path . 'admin')) { rename($plg_path . 'admin', $path_admin . 'plugins/' . $plugin); COM_errorLog('MONITOR - Move ' . $plg_path . 'admin to ' . $path_admin . 'plugins/' . $plugin); } else { COM_errorLog('MONITOR - ' . $plg_path . 'admin does not exist'); } unset($archive); // Collect some garbage // cleanup when uploading a new version if ($pi_did_exist) { $plugin_dir = $_CONF['path'] . 'plugins/' . $plugin; if (file_exists($plugin_dir . '.previous')) { @System::rm('-rf ' . $plugin_dir . '.previous'); } $public_dir = $_CONF['path_html'] . $plugin; if (file_exists($public_dir . '.previous')) { @System::rm('-rf ' . $public_dir . '.previous'); } $admin_dir = $path_admin . 'plugins/' . $plugin; if (file_exists($admin_dir . '.previous')) { @System::rm('-rf ' . $admin_dir . '.previous'); } if ($pi_was_enabled) { DB_change($_TABLES['plugins'], 'pi_enabled', 1, 'pi_name', $plugin); COM_errorLog('MONITOR - Enable Plugin: ' . $plugin); } } $msg_with_plugin_name = false; if ($pi_did_exist) { if ($pi_was_enabled) { // check if we have to perform an update $pi_version = DB_getItem($_TABLES['plugins'], 'pi_version', "pi_name = '{$plugin}'"); $code_version = PLG_chkVersion($plugin); COM_errorLog('MONITOR - Reading' . $plugin . ' plugin installed version: ' . $pi_version . ' and code version: ' . $code_version); if (!empty($code_version) && $code_version != $pi_version) { /** * At this point, we would have to call PLG_upgrade(). * However, we've loaded the plugin's old functions.inc * (in lib-common.php). We can't load the new one here * now since that would result in duplicate function * definitions. Solution: Trigger a reload (with the new * functions.inc) and continue there. */ $url = $_CONF['site_admin_url'] . '/plugins/monitor/index.php' . '?action=continue_upgrade' . '&codeversion=' . urlencode($code_version) . '&piversion=' . urlencode($pi_version) . '&plugin_update=' . urlencode($plugin); COM_errorLog('MONITOR - Update Plugin ' . $plugin . ' from version: ' . $pi_version . ' to code version: ' . $code_version); echo COM_refresh($url); exit; } else { $msg = 98; // successfully uploaded } } else { $msg = 98; // successfully uploaded } } elseif (file_exists($plg_path . 'autoinstall.php')) { // if the plugin has an autoinstall.php, install it now if (plugin_autoinstall($plugin)) { PLG_pluginStateChange($plugin, 'installed'); $msg = 44; // successfully installed } else { $msg = 72; // an error occured while installing the plugin } } else { $msg = 98; // successfully uploaded } } return $msg; }
function execAction($dir, $item) { global $mosConfig_absolute_path; if (!ext_isArchive($item)) { ext_Result::sendResult('archive', false, ext_Lang::err('extract_noarchive')); } else { $archive_name = realpath(get_abs_item($dir, $item)); $file_info = pathinfo($archive_name); if (empty($dir)) { $extract_dir = realpath($GLOBALS['home_dir']); } else { $extract_dir = realpath($GLOBALS['home_dir'] . "/" . $dir); } $ext = $file_info["extension"]; switch ($ext) { case "zip": require_once _EXT_PATH . "/libraries/Zip.php"; $extract_dir = str_replace('\\', '/', $extract_dir); $zip = new Archive_Zip($archive_name); $res = $zip->extract(array('add_path' => $extract_dir)); if ($res == 0) { ext_Result::sendResult('extract', false, ext_Lang::err('extract_failure') . ' (' . $zip->errorInfo(true) . ')'); } else { ext_Result::sendResult('extract', false, ext_Lang::msg('extract_success')); } break; case "gz": // a // a case "bz": // lot // lot case "bz2": // of // of case "bzip2": // fallthroughs, // fallthroughs, case "tbz": // don't // don't case "tar": // wonder require_once _EXT_PATH . "/libraries/Tar.php"; $archive = new Archive_Tar($archive_name); if ($archive->extract($extract_dir)) { ext_Result::sendResult('extract', true, ext_Lang::msg('extract_success')); } else { ext_Result::sendResult('extract', false, ext_Lang::err('extract_failure')); } break; default: ext_Result::sendResult('extract', false, ext_Lang::err('extract_unknowntype')); break; } /* require_once (_EXT_PATH . "/libraries/Archive/archive.php") ; $result = extArchive::extract( $archive_name, $extract_dir ) ; if( PEAR::isError( $result ) ) { ext_Result::sendResult( 'extract', false, ext_Lang::err( 'extract_failure' ) . ': ' . $result->getMessage() ) ; } */ ext_Result::sendResult('extract', true, ext_Lang::msg('extract_success')); } }
} $dest = $ext_filename . "/archive{$ext}"; move_uploaded_file($_FILES['mod_archive']['tmp_name'], $dest); if ($compression != 'zip') { // If not zip, must be tar include_once BASE . 'external/Tar.php'; $tar = new Archive_Tar($dest, $compression); PEAR::setErrorHandling(PEAR_ERROR_PRINT); $return = $tar->extract(dirname($dest)); if (!$return) { echo '<br />' . $i18n['error_tar'] . '<br />'; } else { header('Location: ' . URL_FULL . 'index.php?module=AdministrationModule&action=verify_extension&type=tar'); } } else { // must be zip include_once BASE . 'external/Zip.php'; $zip = new Archive_Zip($dest); PEAR::setErrorHandling(PEAR_ERROR_PRINT); if ($zip->extract(array('add_path' => dirname($dest))) == 0) { echo '<br />' . $i18n['error_zip'] . ':<br />'; echo $zip->_error_code . ' : ' . $zip->_error_string . '<br />'; } else { header('Location: ' . URL_FULL . 'index.php?module=AdministrationModule&action=verify_extension&type=zip'); } } } } } else { echo SITE_403_HTML; }
/** * Extracts an archive into a destination directory * * @param string $archivePath Path to the archive file * @param string $destinationDir Destination forlder * * @return integer The number of extracted files or false if failed */ static function extract($archivePath, $destinationDir) { if (!is_file($archivePath)) { trigger_error("Archive could not be found", E_USER_WARNING); return false; } if (!self::forceDir($destinationDir)) { trigger_error("Destination directory not existing", E_USER_WARNING); return false; } $nbFiles = 0; $extract = false; switch (self::getExtension($archivePath)) { case "gz": case "tgz": $archive = new Archive_Tar($archivePath); $nbFiles = count($archive->listContent()); $extract = $archive->extract($destinationDir); if (!$extract) { trigger_error($archive->error_object->message, E_USER_WARNING); } break; case "zip": if (class_exists("ZipArchive", false)) { $archive = new ZipArchive(); $archive->open($archivePath); $nbFiles = $archive->numFiles; $extract = $archive->extractTo($destinationDir); } else { require_once "Archive/Zip.php"; $archive = new Archive_Zip($archivePath); $nbFiles = count($archive->listContent()); $extract = $archive->extract(array("add_path" => $destinationDir)); } break; } if (!$extract) { return false; } return $nbFiles; }
//ob_buffer over flow //HACK by suin & nao-pon 2012/01/06 while (ob_get_level() > 0) { if (!ob_end_clean()) { break; } } // // EXTRACT STAGE // $orig_filename4check = strtolower($_FILES['tplset_archive']['name']); if (strtolower(substr($orig_filename4check, -4)) == '.zip') { // zip require_once dirname(__FILE__) . '/include/Archive_Zip.php'; $reader = new Archive_Zip($_FILES['tplset_archive']['tmp_name']); $files = $reader->extract(array('extract_as_string' => true)); if (!is_array(@$files)) { die($reader->errorName()); } $do_upload = true; } else { if (substr($orig_filename4check, -4) == '.tgz' || substr($orig_filename4check, -7) == '.tar.gz') { // tar.gz require_once XOOPS_ROOT_PATH . '/class/class.tar.php'; $tar = new tar(); $tar->openTar($_FILES['tplset_archive']['tmp_name']); $files = array(); foreach ($tar->files as $id => $info) { $files[] = array('filename' => $info['name'], 'mtime' => $info['time'], 'content' => $info['file']); } if (empty($files)) {
public function install_extension_confirm() { if ($_FILES['mod_archive']['error'] != UPLOAD_ERR_OK) { switch ($_FILES['mod_archive']['error']) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: // echo gt('The file you uploaded exceeded the size limits for the server.').'<br />'; flash('error', gt('The file you uploaded exceeded the size limits for the server.')); break; case UPLOAD_ERR_PARTIAL: // echo gt('The file you uploaded was only partially uploaded.').'<br />'; flash('error', gt('The file you uploaded was only partially uploaded.')); break; case UPLOAD_ERR_NO_FILE: // echo gt('No file was uploaded.').'<br />'; flash('error', gt('No file was uploaded.')); break; } } else { $basename = basename($_FILES['mod_archive']['name']); // Check future radio buttons // for now, try auto-detect $compression = null; $ext = ''; if (substr($basename, -4, 4) == '.tar') { $compression = null; $ext = '.tar'; } else { if (substr($basename, -7, 7) == '.tar.gz') { $compression = 'gz'; $ext = '.tar.gz'; } else { if (substr($basename, -4, 4) == '.tgz') { $compression = 'gz'; $ext = '.tgz'; } else { if (substr($basename, -8, 8) == '.tar.bz2') { $compression = 'bz2'; $ext = '.tar.bz2'; } else { if (substr($basename, -4, 4) == '.zip') { $compression = 'zip'; $ext = '.zip'; } } } } } if ($ext == '') { // echo gt('Unknown archive format. Archives must either be regular ZIP files, TAR files, Gzipped Tarballs, or Bzipped Tarballs.').'<br />'; flash('error', gt('Unknown archive format. Archives must either be regular ZIP files, TAR files, Gzipped Tarballs, or Bzipped Tarballs.')); } else { // Look for stale sessid directories: $sessid = session_id(); if (file_exists(BASE . "tmp/extensionuploads/{$sessid}") && is_dir(BASE . "tmp/extensionuploads/{$sessid}")) { expFile::removeDirectory("tmp/extensionuploads/{$sessid}"); } $return = expFile::makeDirectory("tmp/extensionuploads/{$sessid}"); if ($return != SYS_FILES_SUCCESS) { switch ($return) { case SYS_FILES_FOUNDFILE: case SYS_FILES_FOUNDDIR: // echo gt('Found a file in the directory path when creating the directory to store the files in.').'<br />'; flash('error', gt('Found a file in the directory path when creating the directory to store the files in.')); break; case SYS_FILES_NOTWRITABLE: // echo gt('Destination parent is not writable.').'<br />'; flash('error', gt('Destination parent is not writable.')); break; case SYS_FILES_NOTREADABLE: // echo gt('Destination parent is not readable.').'<br />'; flash('error', gt('Destination parent is not readable.')); break; } } $dest = BASE . "tmp/extensionuploads/{$sessid}/archive{$ext}"; move_uploaded_file($_FILES['mod_archive']['tmp_name'], $dest); if ($compression != 'zip') { // If not zip, must be tar include_once BASE . 'external/Tar.php'; $tar = new Archive_Tar($dest, $compression); PEAR::setErrorHandling(PEAR_ERROR_PRINT); $return = $tar->extract(dirname($dest)); if (!$return) { // echo '<br />'.gt('Error extracting TAR archive').'<br />'; flash('error', gt('Error extracting TAR archive')); } else { // header('Location: ' . URL_FULL . 'index.php?module=administrationmodule&action=verify_extension&type=tar'); // self::verify_extension('tar'); } } else { // must be zip include_once BASE . 'external/Zip.php'; $zip = new Archive_Zip($dest); PEAR::setErrorHandling(PEAR_ERROR_PRINT); if ($zip->extract(array('add_path' => dirname($dest))) == 0) { // echo '<br />'.gt('Error extracting ZIP archive').':<br />'; // echo $zip->_error_code . ' : ' . $zip->_error_string . '<br />'; flash('error', gt('Error extracting ZIP archive: ') . $zip->_error_code . ' : ' . $zip->_error_string . '<br />'); } else { // header('Location: ' . URL_FULL . 'index.php?module=administrationmodule&action=verify_extension&type=zip'); // self::verify_extension('zip'); } } $sessid = session_id(); $files = array(); foreach (expFile::listFlat(BASE . 'tmp/extensionuploads/' . $sessid, true, null, array(), BASE . 'tmp/extensionuploads/' . $sessid) as $key => $f) { if ($key != '/archive.tar' && $key != '/archive.tar.gz' && $key != '/archive.tar.bz2' && $key != '/archive.zip') { $files[] = array('absolute' => $key, 'relative' => $f, 'canCreate' => expFile::canCreate(BASE . substr($key, 1)), 'ext' => substr($f, -3, 3)); } } assign_to_template(array('relative' => 'tmp/extensionuploads/' . $sessid, 'files' => $files)); } } }