/** TarGzip file extractor function @param string Archive file @param string extraction path @return string */ function extractTarGzip($archFile, $extractPath = ".") { /* include TAR library */ require_once 'pcltar.func.php'; /* extract and return list of extracted files */ return PclTarExtract($archFile, $extractPath); }
function extractArchive() { global $mosConfig_absolute_path; $base_Dir = $this->pathName($mosConfig_absolute_path . "/media/"); $archivename = $base_Dir . $this->installArchive(); $tmpdir = uniqid("install_"); if ($this->isWindows()) { $extractdir = str_replace('/', '\\', $this->pathName($base_Dir . "{$tmpdir}")); $archivename = str_replace('/', '\\', $archivename); } else { $extractdir = str_replace('\\', '/', $this->pathName($base_Dir . "{$tmpdir}")); $archivename = str_replace('\\', '/', $archivename); } $this->unpackDir($extractdir); // Find the extension of the file $fileext = substr(strrchr(basename($this->installArchive()), '.'), 1); if ($fileext == "gz" || $fileext == "tar") { PclTarExtract($archivename, $extractdir); if (PclErrorCode() != 1) { echo "<font color=\"red\">" . PclErrorString() . "<br />Updater - error</font>"; TrDisplay(); exit; } $this->installDir($extractdir); } else { $zipfile = new PclZip($archivename); if ($this->isWindows()) { define('OS_WINDOWS', 1); } else { define('OS_WINDOWS', 0); } $ret = $zipfile->extract(PCLZIP_OPT_PATH, $extractdir); if ($ret == 0) { $this->setError(1, "Unrecoverable error '" . $zipfile->errorName(true) . "'", "Updater - error"); return false; } $this->installDir($extractdir); } // Try to find the correct install dir. in case that the package have subdirs // Save the install dir for later cleanup $filesindir = $this->readDirectory($this->installDir(), ""); if (count($filesindir) == 1) { if (is_dir($extractdir . $filesindir[0])) { $this->installDir($extractdir . $filesindir[0]); } } return true; }
XoopsLoad::load('pclzip', 'system'); XoopsLoad::load('pcltar', 'system'); $file1 = XoopsFile::getHandler('file', $path_file); $extension = $file1->ext(); switch ($extension) { case 'zip': $archive = new PclZip($path_file); if ($archive->extract(PCLZIP_OPT_PATH, $path) == 0) { echo $xoops->alert('error', _AM_SYSTEM_FILEMANAGER_EXTRACT_ERROR); } else { echo $xoops->alert('info', _AM_SYSTEM_FILEMANAGER_EXTRACT_FILE); } break; case 'tar': case 'gz': PclTarExtract($path_file, $path); break; } break; //Confirm delete file //Confirm delete file case 'filemanager_confirm_delete_file': echo '<div class="confirmMsg">' . sprintf(_AM_SYSTEM_FILEMANAGER_SUREDEL, $_REQUEST['file']) . '<br /><br /><div class="buttons"><a href="#" class="ui-corner-all" onclick="filemanager_delete_file(\'' . $_REQUEST['path_file'] . '\', \'' . $_REQUEST['path'] . '\');">' . _AM_SYSTEM_FILEMANAGER_DELETE . '</a> <a href="#" class="ui-corner-all" onclick="$(\'#confirm_delete\').hide();filemanager_load_tree(); filemanager_display_file(\'\', 0)">' . _AM_SYSTEM_FILEMANAGER_CANCEL . '</a></div></div>'; break; //Delete one file //Delete one file case 'filemanager_delete_file': $file = XoopsFile::getHandler('file', $_REQUEST['path_file']); if (!$file->delete()) { echo $xoops->alert('error', _AM_SYSTEM_FILEMANAGER_ERROR); } else {
function pluginProcessUpload() { if (!$_POST['ac'] == md5(ADMINPWCHANGE)) { exit; } $fl = e107::getFile(); $data = $fl->getUploaded(e_TEMP); $mes = e107::getMessage(); if (empty($data[0]['error'])) { if ($fl->unzipArchive($data[0]['name'], 'plugin')) { $mes->addSuccess(EPL_ADLAN_43); } else { $mes->addError(EPL_ADLAN_97); } } // $data = process_uploaded_files(e_TEMP); // print_a($data); echo $mes->render(); return; // ----------------- Everything below is unused. extract($_FILES); /* check if e_PLUGIN dir is writable ... */ if (!is_writable(e_PLUGIN)) { // still not writable - spawn error message e107::getRender()->tablerender(EPL_ADLAN_40, EPL_ADLAN_39); } else { // e_PLUGIN is writable require_once e_HANDLER . "upload_handler.php"; $fileName = $file_userfile['name'][0]; $fileSize = $file_userfile['size'][0]; $fileType = $file_userfile['type'][0]; if (strstr($file_userfile['type'][0], "gzip")) { $fileType = "tar"; } else { if (strstr($file_userfile['type'][0], "zip")) { $fileType = "zip"; } else { // not zip or tar - spawn error message e107::getRender()->tablerender(EPL_ADLAN_40, EPL_ADLAN_41); return false; } } if ($fileSize) { $uploaded = file_upload(e_PLUGIN); $archiveName = $uploaded[0]['name']; // attempt to unarchive if ($fileType == "zip") { require_once e_HANDLER . "pclzip.lib.php"; $archive = new PclZip(e_PLUGIN . $archiveName); $unarc = $fileList = $archive->extract(PCLZIP_OPT_PATH, e_PLUGIN, PCLZIP_OPT_SET_CHMOD, 0666); } else { require_once e_HANDLER . "pcltar.lib.php"; $unarc = $fileList = PclTarExtract($archiveName, e_PLUGIN); } if (!$unarc) { // unarc failed ... if ($fileType == "zip") { $error = EPL_ADLAN_46 . " '" . $archive->errorName(TRUE) . "'"; } else { $error = EPL_ADLAN_47 . PclErrorString() . ", " . EPL_ADLAN_48 . intval(PclErrorCode()); } e107::getRender()->tablerender(EPL_ADLAN_40, EPL_ADLAN_42 . " " . $archiveName . " " . $error); require_once "footer.php"; exit; } // ok it looks like the unarc succeeded - continue */ // get folder name ... $folderName = substr($fileList[0]['stored_filename'], 0, strpos($fileList[0]['stored_filename'], "/")); if (file_exists(e_PLUGIN . $folderName . "/plugin.php") || file_exists(e_PLUGIN . $folderName . "/plugin.xml")) { /* upload is a plugin */ e107::getRender()->tablerender(EPL_ADLAN_40, EPL_ADLAN_43); } elseif (file_exists(e_PLUGIN . $folderName . "/theme.php") || file_exists(e_PLUGIN . $folderName . "/theme.xml")) { /* upload is a menu */ e107::getRender()->tablerender(EPL_ADLAN_40, EPL_ADLAN_45); } else { /* upload is unlocatable */ e107::getRender()->tablerender(EPL_ADLAN_40, EPL_ADLAN_98 . ' ' . $fileList[0]['stored_filename']); } /* attempt to delete uploaded archive */ @unlink(e_PLUGIN . $archiveName); } } }
function unpack_gz($f, $d) { $p = 'plug/tar/pcl'; include_once $p . 'tar.lib.php'; include_once $p . 'error.lib.php'; include_once $p . 'trace.lib.php'; PclTarExtract($f, $d, '', ''); }
function pluginProcessUpload() { if (!$_POST['ac'] == md5(ADMINPWCHANGE)) { exit; } extract($_FILES); /* check if e_PLUGIN dir is writable ... */ if (!is_writable(e_PLUGIN)) { /* still not writable - spawn error message */ e107::getRender()->tablerender(EPL_ADLAN_40, EPL_ADLAN_39); } else { /* e_PLUGIN is writable - continue */ require_once e_HANDLER . "upload_handler.php"; $fileName = $file_userfile['name'][0]; $fileSize = $file_userfile['size'][0]; $fileType = $file_userfile['type'][0]; if (strstr($file_userfile['type'][0], "gzip")) { $fileType = "tar"; } else { if (strstr($file_userfile['type'][0], "zip")) { $fileType = "zip"; } else { /* not zip or tar - spawn error message */ e107::getRender()->tablerender(EPL_ADLAN_40, EPL_ADLAN_41); require_once "footer.php"; exit; } } if ($fileSize) { $uploaded = file_upload(e_PLUGIN); $archiveName = $uploaded[0]['name']; /* attempt to unarchive ... */ if ($fileType == "zip") { require_once e_HANDLER . "pclzip.lib.php"; $archive = new PclZip(e_PLUGIN . $archiveName); $unarc = $fileList = $archive->extract(PCLZIP_OPT_PATH, e_PLUGIN, PCLZIP_OPT_SET_CHMOD, 0666); } else { require_once e_HANDLER . "pcltar.lib.php"; $unarc = $fileList = PclTarExtract($archiveName, e_PLUGIN); } if (!$unarc) { /* unarc failed ... */ if ($fileType == "zip") { $error = EPL_ADLAN_46 . " '" . $archive->errorName(TRUE) . "'"; } else { $error = EPL_ADLAN_47 . PclErrorString() . ", " . EPL_ADLAN_48 . intval(PclErrorCode()); } e107::getRender()->tablerender(EPL_ADLAN_40, EPL_ADLAN_42 . " " . $archiveName . " " . $error); require_once "footer.php"; exit; } /* ok it looks like the unarc succeeded - continue */ /* get folder name ... */ $folderName = substr($fileList[0]['stored_filename'], 0, strpos($fileList[0]['stored_filename'], "/")); if (file_exists(e_PLUGIN . $folderName . "/plugin.php") || file_exists(e_PLUGIN . $folderName . "/plugin.xml")) { /* upload is a plugin */ e107::getRender()->tablerender(EPL_ADLAN_40, EPL_ADLAN_43); } elseif (file_exists(e_PLUGIN . $folderName . "/theme.php") || file_exists(e_PLUGIN . $folderName . "/theme.xml")) { /* upload is a menu */ e107::getRender()->tablerender(EPL_ADLAN_40, EPL_ADLAN_45); } else { /* upload is unlocatable */ e107::getRender()->tablerender(EPL_ADLAN_40, 'Unknown file: ' . $fileList[0]['stored_filename']); } /* attempt to delete uploaded archive */ @unlink(e_PLUGIN . $archiveName); } } }
$dir = '../templates/'; if (!is_writable($dir)) { $is_writable = @chmod($dir, 0777) ? true : false; } @clearstatcache(); $error = ''; if (is_writable($dir)) { $check_theme = $Sql->query("SELECT COUNT(*) FROM " . DB_TABLE_THEMES . " WHERE theme = '" . strprotect($_FILES['upload_theme']['name']) . "'", __LINE__, __FILE__); if (empty($check_theme) && !is_dir('../templates/' . $_FILES['upload_theme']['name'])) { import('io/upload'); $Upload = new Upload($dir); if ($Upload->file('upload_theme', '`([a-z0-9()_-])+\\.(gzip|zip)+$`i')) { $archive_path = '../templates/' . $Upload->filename['upload_theme']; if ($Upload->extension['upload_theme'] == 'gzip') { import('lib/pcl/pcltar', LIB_IMPORT); if (!($zip_files = PclTarExtract($Upload->filename['upload_theme'], '../templates/'))) { $error = $Upload->error; } } elseif ($Upload->extension['upload_theme'] == 'zip') { import('lib/pcl/pclzip', LIB_IMPORT); $Zip = new PclZip($archive_path); if (!($zip_files = $Zip->extract(PCLZIP_OPT_PATH, '../templates/', PCLZIP_OPT_SET_CHMOD, 0666))) { $error = $Upload->error; } } else { $error = 'e_upload_invalid_format'; } if (!@unlink($archive_path)) { $error = 'e_unlink_disabled'; } } else {
private function upload_module() { $modules_folder = PATH_TO_ROOT . '/'; if (!is_writable($modules_folder)) { $is_writable = @chmod($dir, 0755); } else { $is_writable = true; } if ($is_writable) { $uploaded_file = $this->form->get_value('file'); if ($uploaded_file !== null) { $upload = new Upload($modules_folder); if ($upload->file('upload_module_file', '`([a-z0-9()_-])+\\.(gz|zip)+$`i')) { $archive = $modules_folder . $upload->get_filename(); if ($upload->get_extension() == 'gz') { include_once PATH_TO_ROOT . '/kernel/lib/php/pcl/pcltar.lib.php'; $archive_content = PclTarList($upload->get_filename()); } else { include_once PATH_TO_ROOT . '/kernel/lib/php/pcl/pclzip.lib.php'; $zip = new PclZip($archive); $archive_content = $zip->listContent(); } $archive_root_content = array(); $required_files = array('/config.ini', '/index.php'); foreach ($archive_content as $element) { if (substr($element['filename'], -1) == '/') { $element['filename'] = substr($element['filename'], 0, -1); } if (substr_count($element['filename'], '/') == 0) { $archive_root_content[] = array('filename' => $element['filename'], 'folder' => isset($element['folder']) && $element['folder'] == 1 || isset($element['typeflag']) && $element['typeflag'] == 5); } if (isset($archive_root_content[0])) { $name_in_archive = str_replace($archive_root_content[0]['filename'] . '/', '/', $element['filename']); if (in_array($name_in_archive, $required_files)) { unset($required_files[array_search($name_in_archive, $required_files)]); } } } if (count($archive_root_content) == 1 && $archive_root_content[0]['folder'] && empty($required_files)) { $module_id = $archive_root_content[0]['filename']; if (!ModulesManager::is_module_installed($module_id)) { if ($upload->get_extension() == 'gz') { PclTarExtract($upload->get_filename(), $modules_folder); } else { $zip->extract(PCLZIP_OPT_PATH, $modules_folder, PCLZIP_OPT_SET_CHMOD, 0755); } $this->install_module($module_id, true); } else { $this->view->put('MSG', MessageHelper::display(LangLoader::get_message('element.already_exists', 'status-messages-common'), MessageHelper::NOTICE)); } } else { $this->view->put('MSG', MessageHelper::display(LangLoader::get_message('error.invalid_archive_content', 'status-messages-common'), MessageHelper::NOTICE)); } $uploaded_file = new File($archive); $uploaded_file->delete(); } else { $this->view->put('MSG', MessageHelper::display($this->lang['modules.upload_invalid_format'], MessageHelper::NOTICE)); } } else { $this->view->put('MSG', MessageHelper::display($this->lang['modules.upload_error'], MessageHelper::NOTICE)); } } }
function ProcessUploadedHAR($testPath) { require_once './lib/pcltar.lib.php3'; require_once './lib/pclerror.lib.php3'; require_once './lib/pcltrace.lib.php3'; global $done; global $flattenUploadedZippedHar; // From the mobile agents we get the zip file with sub-folders if (isset($_FILES['file'])) { //var_dump($_FILES['file']); logMsg(" Extracting uploaded file '{$_FILES['file']['tmp_name']}' to '{$testPath}'\n"); if ($_FILES['file']['type'] == "application/tar" || preg_match("/\\.tar\$/", $_FILES['file']['name'])) { PclTarExtract($_FILES['file']['tmp_name'], "{$testPath}", "/", "tar"); } else { if (preg_match("/\\.zip\$/", $_FILES['file']['name'])) { $archive = new PclZip($_FILES['file']['tmp_name']); if ($flattenUploadedZippedHar) { // PCLZIP_OPT_REMOVE_ALL_PATH causes any directory structure // within the zip to be flattened. Different agents have // slightly different directory layout, but all file names // are guaranteed to be unique. Flattening allows us to avoid // directory traversal. // TODO(skerner): Find out why the blaze agents have different // directory structure and make it consistent, and remove // $flattenUploadedZippedHar as an option. $archive->extract(PCLZIP_OPT_PATH, "{$testPath}/", PCLZIP_OPT_REMOVE_ALL_PATH); } else { logMalformedInput("Depricated har upload path. Agents should " . "set flattenZippedHar=1."); $archive->extract(PCLZIP_OPT_PATH, "{$testPath}/"); } } else { move_uploaded_file($_FILES['file']['tmp_name'], $testPath . "/" . $_FILES['file']['name']); } } } // The HAR may hold multiple page loads. $harIsFromSinglePageLoad = false; ProcessHARText($testPath, $harIsFromSinglePageLoad); }
function inject_typos($v) { $dr = 'plug/tar/'; include $dr . 'pclerror.lib.php'; include $dr . 'pcltrace.lib.php'; include $dr . 'pcltar.lib.php'; PclTarExtract($v, 'fonts', '', ''); return lka($v) . ' installed' . br(); }
$rejected = true; $rej_reason = $lang['plugins-rejmultpath']; break; } # TODO: This should be a regex to make sure the file is in the right position (<pluginname>/<pluginname>.yaml) if (strpos($value,$u_plugin_name.'.yaml')!==false){ $yaml_index = $key; } } # TODO: We should extract the yaml file if it exists and validate it. if ($yaml_index===false){ $rejected = true; $rej_reason = $lang['plugins-rejmetadata']; } if (!$rejected){ if (!(is_array(PclTarExtract($tmp_file, '../../plugins/')))){ #TODO: If the new plugin is already activated we should update the DB with the new yaml info. $rejected = true; $rej_reason = $lang['plugins-rejarchprob'].' '.PclErrorString(PclErrorCode()); } } } } else { $rejected = true; $rej_reason = $lang['plugins-rejfileprob']; } } } else {
function maj_tar($d) { calltar(); $f = maj_server() . '/' . $d; $t = read_file($f); write_file($d, $t); PclTarExtract($d, '/', '', ''); }
$dir = '../lang/'; if (!is_writable($dir)) { $is_writable = @chmod($dir, 0777) ? true : false; } @clearstatcache(); $error = ''; if (is_writable($dir)) { $check_lang = $Sql->query("SELECT COUNT(*) FROM " . DB_TABLE_LANG . " WHERE lang = '" . strprotect($_FILES['upload_lang']['name']) . "'", __LINE__, __FILE__); if (empty($check_lang)) { import('io/upload'); $Upload = new Upload($dir); if ($Upload->file('upload_lang', '`([a-z0-9()_-])+\\.(gzip|zip)+$`i')) { $archive_path = '../lang/' . $Upload->filename['upload_lang']; if ($Upload->extension['upload_lang'] == 'gzip') { import('lib/pcl/pcltar', LIB_IMPORT); if (!($zip_files = PclTarExtract($Upload->filename['upload_lang'], '../lang/'))) { $error = $Upload->error; } } elseif ($Upload->extension['upload_lang'] == 'zip') { import('lib/pcl/pclzip', LIB_IMPORT); $Zip = new PclZip($archive_path); if (!($zip_files = $Zip->extract(PCLZIP_OPT_PATH, '../lang/', PCLZIP_OPT_SET_CHMOD, 0666))) { $error = $Upload->error; } } else { $error = 'e_upload_invalid_format'; } if (!@unlink($archive_path)) { $error = 'e_unlink_disabled'; } } else {
function themeUpload() { if (!$_POST['ac'] == md5(ADMINPWCHANGE)) { exit; } $mes = e107::getMessage(); $ns = e107::getRender(); extract($_FILES); if (!is_writable(e_THEME)) { // $ns->tablerender(TPVLAN_16, TPVLAN_20); $mes->add(TPVLAN_20, E_MESSAGE_INFO); return FALSE; } else { require_once e_HANDLER . "upload_handler.php"; $fileName = $file_userfile['name'][0]; $fileSize = $file_userfile['size'][0]; $fileType = $file_userfile['type'][0]; if (strstr($file_userfile['type'][0], "gzip")) { $fileType = "tar"; } else { if (strstr($file_userfile['type'][0], "zip")) { $fileType = "zip"; } else { $mes->add(TPVLAN_17, E_MESSAGE_ERROR); // $ns->tablerender(TPVLAN_16, TPVLAN_17); // require_once("footer.php"); return FALSE; } } if ($fileSize) { $uploaded = file_upload(e_THEME); $archiveName = $uploaded[0]['name']; if ($fileType == "zip") { require_once e_HANDLER . "pclzip.lib.php"; $archive = new PclZip(e_THEME . $archiveName); $unarc = $fileList = $archive->extract(PCLZIP_OPT_PATH, e_THEME, PCLZIP_OPT_SET_CHMOD, 0666); } else { require_once e_HANDLER . "pcltar.lib.php"; $unarc = $fileList = PclTarExtract($archiveName, e_THEME); } if (!$unarc) { if ($fileType == "zip") { $error = TPVLAN_46 . " '" . $archive->errorName(TRUE) . "'"; } else { $error = TPVLAN_47 . PclErrorString() . ", " . TPVLAN_48 . intval(PclErrorCode()); } $mes->add(TPVLAN_18 . " " . $archiveName . " " . $error, E_MESSAGE_ERROR); // $ns->tablerender(TPVLAN_16, TPVLAN_18." ".$archiveName." ".$error); return FALSE; } $folderName = substr($fileList[0]['stored_filename'], 0, strpos($fileList[0]['stored_filename'], "/")); $mes->add(TPVLAN_19, E_MESSAGE_SUCCESS); if (varset($_POST['setUploadTheme'])) { $themeArray = $this->getThemes(); $this->id = $themeArray[$folderName]['id']; $this->setTheme(); } // $ns->tablerender(TPVLAN_16, "<div class='center'>".TPVLAN_19."</div>"); @unlink(e_THEME . $archiveName); } } }
private function upload_module() { $modules_folder = PATH_TO_ROOT . '/'; if (!is_writable($modules_folder)) { $is_writable = @chmod($dir, 0755); } else { $is_writable = true; } if ($is_writable) { $file = $this->form->get_value('file'); if ($file !== null) { $modules_id = $file->get_name_without_extension(); if (ModulesManager::is_module_installed($modules_id)) { $upload = new Upload($modules_folder); $upload->disableContentCheck(); if ($upload->file('upload_module_file', '`([A-Za-z0-9-_]+)\\.(gz|zip)+$`i', false, 100000000, false)) { $archive_path = $modules_folder . $upload->get_filename(); if ($upload->get_extension() == 'gz') { include_once PATH_TO_ROOT . '/kernel/lib/php/pcl/pcltar.lib.php'; PclTarExtract($upload->get_filename(), $modules_folder); $file = new File($archive_path); $file->delete(); } else { if ($upload->get_extension() == 'zip') { include_once PATH_TO_ROOT . '/kernel/lib/php/pcl/pclzip.lib.php'; $zip = new PclZip($archive_path); $zip->extract(PCLZIP_OPT_PATH, $modules_folder, PCLZIP_OPT_SET_CHMOD, 0755); $file = new File($archive_path); $file->delete(); } else { $this->view->put('MSG', MessageHelper::display($this->lang['modules.upload_invalid_format'], MessageHelper::NOTICE, 4)); } } $this->upgrade_module($modules_id); } else { $this->view->put('MSG', MessageHelper::display($this->lang['modules.upload_error'], MessageHelper::NOTICE, 4)); } } else { $this->view->put('MSG', MessageHelper::display($this->lang['modules.not_installed_module'], MessageHelper::NOTICE, 4)); } } else { $this->view->put('MSG', MessageHelper::display($this->lang['modules.upload_error'], MessageHelper::NOTICE, 4)); } } }
supprimer_rep($dossier_destination); // puis on le recrée mkdir($destination, 0777); umask($old); //mise à jour ok on l'insère dans la base // puisque que c'est une nouvelle version on efface les données de la base mise à jour $requete='TRUNCATE TABLE '.$prefix_base.'miseajour'; $resultat = mysqli_query($GLOBALS["mysqli"], $requete) or die('Erreur SQL !'.$requete.'<br />'.((is_object($GLOBALS["mysqli"])) ? mysqli_error($GLOBALS["mysqli"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false))); // puis on informe la base de la version actuelle de la mise à jour $requete='INSERT INTO '.$prefix_base.'miseajour (fichier_miseajour, emplacement_miseajour, date_miseajour, heure_miseajour) values ("'.$beta_version[0].'","","'.date('Y-m-d').'","'.date('H:i:s').'")'; $resultat = mysqli_query($GLOBALS["mysqli"], $requete) or die('Erreur SQL !'.$requete.'<br />'.((is_object($GLOBALS["mysqli"])) ? mysqli_error($GLOBALS["mysqli"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false))); } if ($ext === ".tar.gz") { $old = umask(0000); @$archive = PclTarExtract($source, $destination, 'gepi'); unlink($source); //debug // echo $archive[5][status]; // on liste le dossier $copie_fichier = listage_dossier($destination, $destination); // on transfert via FTP $transfert_fichier=envoi_ftp($copie_fichier, $dossier_ftp_gepi); umask($old); // on supprime le dossier msj_temp $old = umask(0000); $dossier_destination[0]=$destination; supprimer_rep($dossier_destination); // puis on le recret mkdir($destination, 0777); umask($old);
// Close handle fclose($handle); // ---------------------------------------------- // Unzip the archive // ---------------------------------------------- // Print comment echo "Extracting the directories and files from the package...<br />\n"; flush(); $list = ""; $archive_type = get_filename_extension($archive_file); // Extract zip if ($archive_type == "zip") { $zip = new PclZip($archive_file); $list = $zip->extract($p_path = $tempdir); } elseif ($archive_type == "tar" || $archive_type == "tgz" || $archive_type == "gz") { $list = PclTarExtract($archive_file, $tempdir); } // Check result if ($list <= 0) { echo "Could not extract the archive."; exit; } // ---------------------------------------------- // Unzip the archive // ---------------------------------------------- // Print comment echo "Copying the directories and files via FTP...<br />\n"; flush(); ?> <br /> <form name="ActionForm" action="net2ftp_installer.php?security_code=3y32l87r7ikx4ow0ypr" method="post">
/** * Charger un tgz à partir d'un tableau d'options descriptives * * @uses http_deballe_recherche_racine() * @link http://www.phpconcept.net/pcltar Utilise la librairie PclTar * * @param array $quoi * Tableau d'options * @return array|bool|int|string * En cas de réussite, Tableau décrivant le zip, avec les index suivant : * - files : la liste des fichiers présents dans le zip, * - size : la taille décompressée * - compressed_size : la taille compressée * - dirname : répertoire où les fichiers devront être décompréssés * - tmpname : répertoire temporaire où les fichiers sont décompressés * - target : cible sur laquelle décompresser les fichiers... */ function teleporter_http_charger_tgz($quoi = array()) { if (!$quoi) { return false; } foreach (array('remove' => '', 'rename' => array(), 'edit' => array(), 'root_extract' => false, 'tmp' => sous_repertoire(_DIR_CACHE, 'chargeur')) as $opt => $def) { isset($quoi[$opt]) || ($quoi[$opt] = $def); } if (!@file_exists($fichier = $quoi['fichier'])) { return 0; } include_spip('inc/pcltar'); $racine = ''; if ($list = PclTarList($fichier)) { $racine = http_deballe_recherche_racine($list); $quoi['remove'] = $racine; } else { spip_log('charger_decompresser erreur lecture liste tar ' . PclErrorString() . ' pour paquet: ' . $quoi['archive'], "teleport" . _LOG_ERREUR); return PclErrorString(); } // si pas de racine commune, reprendre le nom du fichier zip // en lui enlevant la racine h+md5 qui le prefixe eventuellement // cf action/charger_plugin L74 if (!strlen($nom = basename($racine))) { $nom = preg_replace(",^h[0-9a-f]{8}-,i", "", basename($fichier, '.zip')); } $dir_export = $quoi['root_extract'] ? $quoi['dest'] : $quoi['dest'] . $nom; $dir_export = rtrim($dir_export, '/') . '/'; $tmpname = $quoi['tmp'] . $nom . '/'; // choisir la cible selon si on veut vraiment extraire ou pas $target = $quoi['extract'] ? $dir_export : $tmpname; // ici, il faut vider le rep cible si il existe deja, non ? if (is_dir($target)) { supprimer_repertoire($target); } $ok = PclTarExtract($fichier, $target, $quoi['remove']); if ($ok == 0) { spip_log('charger_decompresser erreur tar ' . PclErrorString() . ' pour paquet: ' . $quoi['archive'], "teleport" . _LOG_ERREUR); return PclErrorString(); } spip_log('charger_decompresser OK pour paquet: ' . $quoi['archive'], "teleport"); $size = $compressed_size = 0; $removex = ',^' . preg_quote($quoi['remove'], ',') . ','; foreach ($list as $a => $f) { $size += $f['size']; $compressed_size += $f['compressed_size']; $list[$a] = preg_replace($removex, '', $f['filename']); } // Indiquer par un fichier install.log // a la racine que c'est chargeur qui a installe ce plugin ecrire_fichier($target . 'install.log', "installation: charger_plugin\n" . "date: " . gmdate('Y-m-d\\TH:i:s\\Z', time()) . "\n" . "source: " . $quoi['archive'] . "\n"); return array('files' => $list, 'size' => $size, 'compressed_size' => $compressed_size, 'dirname' => $dir_export, 'tmpname' => $tmpname, 'target' => $target); }
@chmod($dir, 0755); } if (!is_writable($dir . $module_name)) { @chmod($dir . $module_name, 0755); } @clearstatcache(); $error = ''; if (is_writable($dir) && is_writable($dir . $module_name)) { if (!is_dir('../' . $_FILES['upload_module']['name'])) { import('io/upload'); $Upload = new Upload($dir); if ($Upload->file('upload_module', '`([a-z0-9()_-])+\\.(gzip|zip)+$`i')) { $archive_path = '../' . $Upload->filename['upload_module']; if ($Upload->extension['upload_module'] == 'gzip') { import('lib/pcl/pcltar', LIB_IMPORT); if (!($zip_files = PclTarExtract($Upload->filename['upload_module'], '../'))) { $error = $Upload->error; } } elseif ($Upload->extension['upload_module'] == 'zip') { import('lib/pcl/pclzip', LIB_IMPORT); $Zip = new PclZip($archive_path); if (!($zip_files = $Zip->extract(PCLZIP_OPT_PATH, '../', PCLZIP_OPT_SET_CHMOD, 0666))) { $error = $Upload->error; } } else { $error = 'e_upload_invalid_format'; } if (!@unlink($archive_path)) { $error = ''; } } else {
function dl_prog() { $goto = 'install.php?step=' . $_GET['step']; if (!is_file('plug/distribution.php') or $_GET['reinit']) { $ret .= dl_needed_file('plug/tar/pcltar.lib.php'); $ret .= dl_needed_file('plug/tar/pclerror.lib.php'); $ret .= dl_needed_file('plug/tar/pcltrace.lib.php'); $ret .= dl_needed_file('css/_global.css'); $ret .= dl_needed_file('index.php'); $ret .= dl_needed_file('ajax.php'); $ret .= dl_needed_file('plug.php'); $ret .= dl_needed_file('plug/distribution.php'); //used by distant $ret .= dl_needed_file('plug/microxml.php'); // $ret .= dl_needed_file('fonts/philum.tar.gz'); $ret .= dl_needed_file('imgb/icons/system.tar.gz'); $ret .= dl_needed_file('favicon.ico'); $ret .= lien($goto . '&upd=program', 'now: download_program'); } else { $_SESSION['progam'] = ''; include_once 'plug/tar/pclerror.lib.php'; include_once 'plug/tar/pcltrace.lib.php'; include_once 'plug/tar/pcltar.lib.php'; PclTarExtract('fonts/philum.tar.gz', '', '', ''); PclTarExtract('imgb/icons/system.tar.gz', '', '', ''); $ret .= lien($goto . '&upd=program&redo==', 'download_program') . br() . br(); $dirs = dl_dirs(); //dl_tar(implode(';',$dirs)) if ($_GET["upd"] == 'program') { upd_dir($dirs); } elseif ($_GET["upd"] == 'plug') { dl_dir($_GET["upd"]); } elseif ($_GET["upd"]) { dl_tar($_GET["upd"]); } //$ret.='download each folder: '.br().br(); foreach ($dirs as $k => $v) { if ($v == 'plug' && !is_file($v . '/index.php')) { $ret .= lien($goto . '&upd=' . $v, $v) . br(); } elseif (is_dir($v)) { $ret .= 'ok: ' . $v . br(); $_SESSION['progam'][$v] = 1; } else { $ret .= lien($goto . '&upd=' . $v, $v) . br(); } } $ret .= br() . 'ok: ' . count($_SESSION['progam']) . '/' . count($dirs); } return $ret; }
private function upload_theme() { $folder_phpboost_themes = PATH_TO_ROOT . '/templates/'; if (!is_writable($folder_phpboost_themes)) { $is_writable = @chmod($folder_phpboost_themes, 0777); } else { $is_writable = true; } if ($is_writable) { $uploaded_file = $this->form->get_value('file'); if ($uploaded_file !== null) { $upload = new Upload($folder_phpboost_themes); if ($upload->file('upload_theme_file', '`([A-Za-z0-9-_]+)\\.(gz|zip)+$`i')) { $archive = $folder_phpboost_themes . $upload->get_filename(); if ($upload->get_extension() == 'gz') { include_once PATH_TO_ROOT . '/kernel/lib/php/pcl/pcltar.lib.php'; $archive_content = PclTarList($upload->get_filename()); } else { include_once PATH_TO_ROOT . '/kernel/lib/php/pcl/pclzip.lib.php'; $zip = new PclZip($archive); $archive_content = $zip->listContent(); } $archive_root_content = array(); $required_files = array('/config.ini', '/body.tpl', '/frame.tpl', '/theme/content.css', '/theme/design.css', '/theme/global.css'); foreach ($archive_content as $element) { if (substr($element['filename'], -1) == '/') { $element['filename'] = substr($element['filename'], 0, -1); } if (substr_count($element['filename'], '/') == 0) { $archive_root_content[] = array('filename' => $element['filename'], 'folder' => isset($element['folder']) && $element['folder'] == 1 || isset($element['typeflag']) && $element['typeflag'] == 5); } if (isset($archive_root_content[0])) { $name_in_archive = str_replace($archive_root_content[0]['filename'] . '/', '/', $element['filename']); if (in_array($name_in_archive, $required_files)) { unset($required_files[array_search($name_in_archive, $required_files)]); } } } if (count($archive_root_content) == 1 && $archive_root_content[0]['folder'] && empty($required_files)) { $theme_id = $archive_root_content[0]['filename']; if (!ThemesManager::get_theme_existed($theme_id)) { if ($upload->get_extension() == 'gz') { PclTarExtract($upload->get_filename(), $folder_phpboost_themes); } else { $zip->extract(PCLZIP_OPT_PATH, $folder_phpboost_themes, PCLZIP_OPT_SET_CHMOD, 0755); } $this->install_theme($theme_id, array('r-1' => 1, 'r0' => 1, 'r1' => 1)); } else { $this->view->put('MSG', MessageHelper::display(LangLoader::get_message('element.already_exists', 'status-messages-common'), MessageHelper::NOTICE)); } } else { $this->view->put('MSG', MessageHelper::display(LangLoader::get_message('error.invalid_archive_content', 'status-messages-common'), MessageHelper::NOTICE)); } $uploaded_file = new File($archive); $uploaded_file->delete(); } else { $this->view->put('MSG', MessageHelper::display($this->lang['themes.upload_invalid_format'], MessageHelper::NOTICE)); } } else { $this->view->put('MSG', MessageHelper::display(LangLoader::get_message('process.error', 'status-messages-common'), MessageHelper::NOTICE)); } } }
/** * Extracts the package archive file * @return boolean True on success, False on error */ function extractArchive() { global $mosConfig_absolute_path; // Common functions for the installer(s) // Extract functions require_once $mosConfig_absolute_path . '/administrator/includes/pcl/pclzip.lib.php'; require_once $mosConfig_absolute_path . '/administrator/includes/pcl/pclerror.lib.php'; require_once $mosConfig_absolute_path . '/administrator/includes/pcl/pcltrace.lib.php'; require_once $mosConfig_absolute_path . '/administrator/includes/pcl/pcltar.lib.php'; $base_Dir = mosPathName($mosConfig_absolute_path . '/media'); $archivename = $base_Dir . $this->installArchive(); $tmpdir = uniqid('install_'); $extractdir = mosPathName($base_Dir . $tmpdir); $archivename = mosPathName($archivename, false); $this->unpackDir($extractdir); // Find the extension of the file $fileext = substr(strrchr(basename($this->installArchive()), '.'), 1); if ($fileext == 'gz' || $fileext == 'tar') { $result = PclTarExtract($archivename, $extractdir); if (!$result) { $this->setError(1, 'Tar Extract Error "' . PclErrorString() . '" Code ' . intval(PclErrorCode())); return false; } $this->installDir($extractdir); } else { $zipfile = new PclZip($archivename); if ($this->isWindows()) { define('OS_WINDOWS', 1); } else { define('OS_WINDOWS', 0); } $ret = $zipfile->extract(PCLZIP_OPT_PATH, $extractdir); if ($ret == 0) { $this->setError(1, 'Unrecoverable error "' . $zipfile->errorName(true) . '"'); return false; } $this->installDir($extractdir); } // Try to find the correct install dir. in case that the package have subdirs // Save the install dir for later cleanup $filesindir = mosReadDirectory($this->installDir(), ''); if (count($filesindir) == 1) { if (is_dir($extractdir . $filesindir[0])) { $this->installDir(mosPathName($extractdir . $filesindir[0])); } } return true; }
function ftp_unziptransferfiles($archivesArray) { // -------------- // Extract the directories and files from the archive to a temporary directory on the web server, and // then create the directories and put the files on the FTP server // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_globals, $net2ftp_result, $net2ftp_output; // ------------------------------------------------------------------------- // Open connection // ------------------------------------------------------------------------- $conn_id = ftp_openconnection(); if ($net2ftp_result["success"] == false) { for ($archive_nr = 1; $archive_nr <= sizeof($archivesArray); $archive_nr++) { @unlink($archivesArray[$archive_nr]["tmp_name"]); } return false; } // ------------------------------------------------------------------------- // For each archive... // ------------------------------------------------------------------------- for ($archive_nr = 1; $archive_nr <= sizeof($archivesArray); $archive_nr++) { // Set status setStatus($archive_nr, sizeof($archivesArray), __("Decompressing archives and transferring files")); // ------------------------------------------------------------------------- // Determine the type of archive depending on the filename extension // ------------------------------------------------------------------------- $archive_name = $archivesArray[$archive_nr]["name"]; $archive_file = $archivesArray[$archive_nr]["tmp_name"]; $archivename_without_dottext = substr($archivesArray[$archive_nr]["tmp_name"], 0, strlen($archive) - 4); $archive_type = get_filename_extension($archivename_without_dottext); $net2ftp_output["ftp_unziptransferfiles"][] = __("Processing archive nr %1\$s: <b>%2\$s</b>", $archive_nr, $archive_name); $net2ftp_output["ftp_unziptransferfiles"][] = "<ul>"; if ($archive_type != "zip" && $archive_type != "tar" && $archive_type != "tgz" && $archive_type != "gz") { $net2ftp_output["ftp_unziptransferfiles"][] = __("Archive <b>%1\$s</b> was not processed because its filename extension was not recognized. Only zip, tar, tgz and gz archives are supported at the moment.", $archive_name); continue; } // ------------------------------------------------------------------------- // Extract directories and files // ------------------------------------------------------------------------- // ------------------------------ // Check list of files to see if there are any malicious filenames // ------------------------------ if ($archive_type == "zip") { $zip = new PclZip($archive_file); $list_to_check = $zip->listContent(); } elseif ($archive_type == "tar" || $archive_type == "tgz" || $archive_type == "gz") { $list_to_check = PclTarList($archive_file); } if ($list_to_check <= 0) { $net2ftp_output["ftp_unziptransferfiles"][] = __("Unable to extract the files and directories from the archive"); continue; } for ($i = 0; $i < sizeof($list_to_check); $i++) { $source = trim($list_to_check[$i]["filename"]); if (strpos($source, "../") !== false || strpos($source, "..\\") !== false) { $errormessage = __("Archive contains filenames with ../ or ..\\ - aborting the extraction"); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); return false; } } // ------------------------------ // Generate random directory // ------------------------------ $tempdir = tempdir2($net2ftp_globals["application_tempdir"], "unzip__", ""); if ($net2ftp_result["success"] == false) { return false; } registerTempfile("register", "{$tempdir}"); // ------------------------------ // Extract // ------------------------------ if ($archive_type == "zip") { $zip = new PclZip($archive_file); $list = $zip->extract($p_path = $tempdir); } elseif ($archive_type == "tar" || $archive_type == "tgz" || $archive_type == "gz") { $list = PclTarExtract($archive_file, $tempdir); } // This code is not needed any more - see above: if ($list_to_check <= 0) if ($list <= 0) { // $net2ftp_output["ftp_unziptransferfiles"][] = __("Unable to extract the files and directories from the archive"); continue; } // ------------------------------ // Create the directories and put the files on the FTP server // ------------------------------ for ($i = 0; $i < sizeof($list); $i++) { $source = trim($list[$i]["filename"]); $unzip_status = trim($list[$i]["status"]); $target_relative = substr($source, strlen($tempdir)); $target = $net2ftp_globals["directory"] . $target_relative; $ftpmode = ftpAsciiBinary($source); if ($unzip_status != "ok") { $net2ftp_output["ftp_unziptransferfiles"][] = __("Could not unzip entry %1\$s (error code %2\$s)", $target_relative, $unzip_status); setErrorVars(true, "", "", "", ""); continue; } // Directory entry in the archive: create the directory if (is_dir($source) == true) { ftp_newdirectory($conn_id, $target); if ($net2ftp_result["success"] == true) { $net2ftp_output["ftp_unziptransferfiles"][] = __("Created directory %1\$s", $target); } else { $net2ftp_output["ftp_unziptransferfiles"][] = __("Could not create directory %1\$s", $target); setErrorVars(true, "", "", "", ""); } } elseif (is_file($source) == true) { ftp_putfile($conn_id, dirname($source), basename($source), dirname($target), basename($target), $ftpmode, "move"); if ($net2ftp_result["success"] == true) { $net2ftp_output["ftp_unziptransferfiles"][] = __("Copied file %1\$s", $target); } else { setErrorVars(true, "", "", "", ""); $target_relative_parts = explode("/", str_replace("\\", "/", dirname($target_relative))); $directory_to_create = $net2ftp_globals["directory"]; for ($j = 0; $j < sizeof($target_relative_parts); $j = $j + 1) { $directory_to_create = $directory_to_create . "/" . $target_relative_parts[$j]; $ftp_chdir_result = @ftp_chdir($conn_id, $directory_to_create); if ($ftp_chdir_result == false) { ftp_newdirectory($conn_id, $directory_to_create); if ($net2ftp_result["success"] == true) { $net2ftp_output["ftp_unziptransferfiles"][] = __("Created directory %1\$s", $directory_to_create); } else { setErrorVars(true, "", "", "", ""); } } // end if } // end for ftp_putfile($conn_id, dirname($source), basename($source), dirname($target), basename($target), $ftpmode, "copy"); if ($net2ftp_result["success"] == true) { $net2ftp_output["ftp_unziptransferfiles"][] = __("Copied file %1\$s", $target); } else { setErrorVars(true, "", "", "", ""); $net2ftp_output["ftp_unziptransferfiles"][] = __("Could not copy file %1\$s", $target); } } } // end elseif file } // end for // ------------------------------------------------------------------------- // Delete the uploaded archive and the temporary files // ------------------------------------------------------------------------- // Delete the temporary directory and its contents $delete_dirorfile_result = delete_dirorfile($tempdir); if ($delete_dirorfile_result == false) { $net2ftp_output["ftp_unziptransferfiles"][] = __("Unable to delete the temporary directory"); } else { registerTempfile("unregister", "{$tempdir}"); } // Delete the archive $unlink_result = @unlink($archive_file); if ($unlink_result == false) { $net2ftp_output["ftp_unziptransferfiles"][] = __("Unable to delete the temporary file %1\$s", $archive_file); } else { registerTempfile("unregister", "{$archive_file}"); } $net2ftp_output["ftp_unziptransferfiles"][] = "</ul>"; } // End for // ------------------------------------------------------------------------- // Close connection // ------------------------------------------------------------------------- ftp_closeconnection($conn_id); }
function tar_extract($f, $to = '/') { require 'plug/tar/pclerror.lib.php'; require 'plug/tar/pcltrace.lib.php'; require 'plug/tar/pcltar.lib.php'; PclTarExtract($f, $to, '', ''); return 'ok'; }