/** * Import Module * @access private */ function import_Layout($zipfile) { $name = $this->_modulexml->name; $label = $this->_modulexml->label; self::log("Importing {$label} ... STARTED"); $unzip = new Vtiger_Unzip($zipfile); $filelist = $unzip->getList(); $vtiger6format = false; foreach ($filelist as $filename => $fileinfo) { if (!$unzip->isdir($filename)) { if (strpos($filename, '/') === false) { continue; } $targetdir = substr($filename, 0, strripos($filename, '/')); $targetfile = basename($filename); $dounzip = false; // Case handling for jscalendar if (stripos($targetdir, "layouts/{$label}/skins") === 0) { $dounzip = true; $vtiger6format = true; } else { if (stripos($targetdir, "layouts/{$label}/modules") === 0) { $vtiger6format = true; $dounzip = true; } } if ($dounzip) { // vtiger6 format if ($vtiger6format) { $targetdir = "layouts/{$label}/" . str_replace("layouts/{$label}", "", $targetdir); @mkdir($targetdir, 0777, true); } if ($unzip->unzip($filename, "{$targetdir}/{$targetfile}") !== false) { self::log("Copying file {$filename} ... DONE"); } else { self::log("Copying file {$filename} ... FAILED"); } } else { self::log("Copying file {$filename} ... SKIPPED"); } } } if ($unzip) { $unzip->close(); } self::register($label, $name); self::log("Importing {$label} [{$prefix}] ... DONE"); return; }
function entpack($filename, $wordtemplatedownloadpath, $filecontent) { //global $filename, $wordtemplatedownloadpath; $temp_dir = time(); mkdir($root_directory . $wordtemplatedownloadpath . $temp_dir, 0777); $handle = fopen($wordtemplatedownloadpath . '/' . $filename, "wb"); $filecontent = base64_decode($filecontent); fwrite($handle, $filecontent); fclose($handle); include_once 'vtlib/Vtiger/Unzip.php'; $archive = new Vtiger_Unzip($wordtemplatedownloadpath . '/' . $filename); //unzip all files $archive->unzipAll($wordtemplatedownloadpath . '/' . $temp_dir); //delete the template //unlink($wordtemplatedownloadpath.'/'.$filename); return $temp_dir; }
/** * Update Module from zip file * @param Vtiger_Module Instance of the module to update * @param String Zip file name * @param Boolean True for overwriting existing module */ function update($moduleInstance, $zipfile, $overwrite = true) { $module = $this->getModuleNameFromZip($zipfile); if ($module != null) { // If data is not yet available if (empty($this->_modulexml)) { $this->__parseManifestFile($unzip); } $buildModuleArray = array(); $installSequenceArray = array(); $moduleBundle = (bool) $this->_modulexml->modulebundle; if ($moduleBundle == true) { $moduleList = (array) $this->_modulexml->modulelist; foreach ($moduleList as $moduleInfos) { foreach ($moduleInfos as $moduleInfo) { $moduleInfo = (array) $moduleInfo; $buildModuleArray[] = $moduleInfo; $installSequenceArray[] = $moduleInfo['install_sequence']; } } sort($installSequenceArray); $unzip = new Vtiger_Unzip($zipfile); $unzip->unzipAllEx($this->getTemporaryFilePath()); foreach ($installSequenceArray as $sequence) { foreach ($buildModuleArray as $moduleInfo) { if ($moduleInfo['install_sequence'] == $sequence) { $moduleInstance = Vtiger_Module::getInstance($moduleInfo['name']); $this->update($moduleInstance, $this->getTemporaryFilePath($moduleInfo['filepath']), $overwrite); } } } } else { if (!$moduleInstance || $moduleInstance->name != $module) { self::log('Module name mismatch!'); return false; } $module = $this->initUpdate($moduleInstance, $zipfile, $overwrite); // Call module update function $this->update_Module($moduleInstance); } } }
protected function getManifestFilePath($moduleNameOrPackageFilePath, $isPackage = false) { $manifest_filePath = null; if (!$isPackage) { $manifest_filePath = $this->exportModule($moduleNameOrPackageFilePath); } else { $unzip = new Vtiger_Unzip($moduleNameOrPackageFilePath, true); $dirname = mktime(); if (!is_dir(DIR_TEMP . $dirname)) { mkdir(DIR_TEMP . $dirname); } $unzip->unzipAll(DIR_TEMP . $dirname, "", true, 0770); if ($unzip) { $manifest_filePath = DIR_TEMP . $dirname . '/manifest.xml'; $this->moduleBaseDir = DIR_TEMP . $dirname . '/'; $unzip->close(); } } return $manifest_filePath; }
/** * Initialize Update * @access private */ function initUpdate($moduleInstance, $zipfile, $overwrite) { $module = $this->getModuleNameFromZip($zipfile); if (!$moduleInstance || $moduleInstance->name != $module) { self::log('Module name mismatch!'); return false; } if ($module != null) { $unzip = new Vtiger_Unzip($zipfile, $overwrite); // Unzip selectively $unzip->unzipAllEx(".", array('include' => array('templates', "modules/{$module}")), array('templates' => "Smarty/templates/modules/{$module}"), array('cron' => "cron/modules/{$module}")); // If data is not yet available if (empty($this->_modulexml)) { $this->__parseManifestFile($unzip); } if ($unzip) { $unzip->close(); } } return $module; }
/** * Import Layout * @access private */ function import_Layout($zipfile) { $name = $this->_modulexml->name; $label = $this->_modulexml->label; self::log("Importing {$name} ... STARTED"); $unzip = new Vtiger_Unzip($zipfile); $filelist = $unzip->getList(); $vtiger6format = false; $badFileExtensions = array_diff(vglobal('upload_badext'), ['js']); foreach ($filelist as $filename => $fileinfo) { if (!$unzip->isdir($filename)) { if (strpos($filename, '/') === false) { continue; } $targetdir = substr($filename, 0, strripos($filename, '/')); $targetfile = basename($filename); $dounzip = false; $fileValidation = true; // Case handling for jscalendar if (stripos($targetdir, "layouts/{$name}/skins") === 0) { $dounzip = true; $vtiger6format = true; } else { if (stripos($targetdir, "layouts/{$name}/modules") === 0) { $vtiger6format = true; $dounzip = true; } else { if (stripos($targetdir, "layouts/{$name}/libraries") === 0) { $vtiger6format = true; $dounzip = true; } } } if ($dounzip) { // vtiger6 format if ($vtiger6format) { $targetdir = "layouts/{$name}/" . str_replace("layouts/{$name}", "", $targetdir); @mkdir($targetdir, 0755, true); } $filepath = 'zip://' . vglobal('root_directory') . $zipfile . '#' . $filename; $fileInfo = pathinfo($filepath); if (in_array($fileInfo['extension'], $badFileExtensions)) { $fileValidation = false; } // Check for php code injection if (preg_match('/(<\\?php?(.*?))/i', file_get_contents($filepath)) == 1) { $fileValidation = false; } if ($fileValidation) { if ($unzip->unzip($filename, "{$targetdir}/{$targetfile}") !== false) { self::log("Copying file {$filename} ... DONE"); } else { self::log("Copying file {$filename} ... FAILED"); } } else { self::log("Incorrect file {$filename} ... SKIPPED"); } } else { self::log("Copying file {$filename} ... SKIPPED"); } } } if ($unzip) { $unzip->close(); } self::register($name, $label); self::log("Importing {$name}({$label}) ... DONE"); return; }
/** * Import Module from zip file * @param String Zip file name * @param Boolean True for overwriting existing module * * @todo overwrite feature is not functionally currently. */ function import($zipfile, $overwrite = false) { $module = $this->getModuleNameFromZip($zipfile); if ($module != null) { // If data is not yet available if (empty($this->_modulexml)) { $this->__parseManifestFile($unzip); } $buildModuleArray = array(); $installSequenceArray = array(); $moduleBundle = (bool) $this->_modulexml->modulebundle; if ($moduleBundle == true) { $moduleList = (array) $this->_modulexml->modulelist; foreach ($moduleList as $moduleInfos) { foreach ($moduleInfos as $moduleInfo) { $moduleInfo = (array) $moduleInfo; $buildModuleArray[] = $moduleInfo; $installSequenceArray[] = $moduleInfo['install_sequence']; } } sort($installSequenceArray); $unzip = new Vtiger_Unzip($zipfile); $unzip->unzipAllEx($this->getTemporaryFilePath()); foreach ($installSequenceArray as $sequence) { foreach ($buildModuleArray as $moduleInfo) { if ($moduleInfo['install_sequence'] == $sequence) { $this->import($this->getTemporaryFilePath($moduleInfo['filepath']), $overwrite); } } } } else { $module = $this->initImport($zipfile, $overwrite); // Call module import function $this->import_Module(); } } }
/** * Unzip all zip files and delete unzipped archives. */ private function unzipLoadedFiles() { $files = $this->getFiles(self::UPLOAD_DIR, "*.zip"); foreach ($files as $file) { $unzip = new Vtiger_Unzip(self::UPLOAD_DIR . $file); if (!$unzip) { unlink(self::UPLOAD_DIR . $file); continue; } $unzip->unzipAllEx(self::UPLOAD_DIR); $unzip->close(); unlink(self::UPLOAD_DIR . $file); } }
public static function installSelectedOptionalModules($selected_modules, $source_directory = '', $destination_directory = '') { require_once 'vtlib/Vtiger/Package.php'; require_once 'vtlib/Vtiger/Module.php'; require_once 'include/utils/utils.php'; $selected_modules = explode(":", $selected_modules); $languagePacks = array(); if ($handle = opendir('packages/vtiger/optional')) { while (false !== ($file = readdir($handle))) { $filename_arr = explode(".", $file); if ($filename_arr[count($filename_arr) - 1] != 'zip') { continue; } $packagename = $filename_arr[0]; $packagepath = "packages/vtiger/optional/{$file}"; $package = new Vtiger_Package(); $module = $package->getModuleNameFromZip($packagepath); if (!empty($packagename) && in_array($module, $selected_modules)) { if ($package->isLanguageType($packagepath)) { $languagePacks[$module] = $packagepath; continue; } if ($module != null) { if ($package->isModuleBundle()) { $unzip = new Vtiger_Unzip($packagepath); $unzip->unzipAllEx($package->getTemporaryFilePath()); $moduleInfoList = $package->getAvailableModuleInfoFromModuleBundle(); foreach ($moduleInfoList as $moduleInfo) { $moduleInfo = (array) $moduleInfo; $packagepath = $package->getTemporaryFilePath($moduleInfo['filepath']); $subModule = new Vtiger_Package(); $subModuleName = $subModule->getModuleNameFromZip($packagepath); $moduleInstance = Vtiger_Module::getInstance($subModuleName); if ($moduleInstance) { updateVtlibModule($subModuleName, $packagepath); } else { installVtlibModule($subModuleName, $packagepath); } } } else { $moduleInstance = Vtiger_Module::getInstance($module); if ($moduleInstance) { updateVtlibModule($module, $packagepath); } else { installVtlibModule($module, $packagepath); } } } } } closedir($handle); } foreach ($languagePacks as $module => $packagepath) { installVtlibModule($module, $packagepath); continue; } }
/** * Import Module * @access private */ function import_Language($zipfile) { $name = $this->_modulexml->name; $prefix = $this->_modulexml->prefix; $label = $this->_modulexml->label; self::log("Importing {$label} [{$prefix}] ... STARTED"); $unzip = new Vtiger_Unzip($zipfile); $filelist = $unzip->getList(); foreach ($filelist as $filename => $fileinfo) { if (!$unzip->isdir($filename)) { if (strpos($filename, '/') === false) { continue; } $targetdir = substr($filename, 0, strripos($filename, '/')); $targetfile = basename($filename); $prefixparts = split('_', $prefix); $dounzip = false; if (is_dir($targetdir)) { // Case handling for jscalendar if (stripos($targetdir, 'jscalendar/lang') === 0 && stripos($targetfile, "calendar-" . $prefixparts[0] . ".js") === 0) { if (file_exists("{$targetdir}/calendar-en.js")) { $dounzip = true; } } else { if (stripos($targetdir, 'modules/Emails/language') === 0 && stripos($targetfile, "phpmailer.lang-{$prefix}.php") === 0) { if (file_exists("{$targetdir}/phpmailer.lang-en_us.php")) { $dounzip = true; } } else { if (preg_match("/{$prefix}.lang.js/", $targetfile)) { $corelangfile = "{$targetdir}/en_us.lang.js"; if (file_exists($corelangfile)) { $dounzip = true; } } else { if (preg_match("/{$prefix}.lang.php/", $targetfile)) { $corelangfile = "{$targetdir}/en_us.lang.php"; if (file_exists($corelangfile)) { $dounzip = true; } } } } } } if ($dounzip) { if ($unzip->unzip($filename, $filename) !== false) { self::log("Copying file {$filename} ... DONE"); } else { self::log("Copying file {$filename} ... FAILED"); } } else { self::log("Copying file {$filename} ... SKIPPED"); } } } if ($unzip) { $unzip->close(); } self::register($prefix, $label, $name); self::log("Importing {$label} [{$prefix}] ... DONE"); return; }
/** * Initialize Import * @access private */ function initImport($zipfile, $overwrite) { $module = $this->getModuleNameFromZip($zipfile); if ($module != null) { $unzip = new Vtiger_Unzip($zipfile, $overwrite); // Unzip selectively $unzip->unzipAllEx(".", array('include' => array('templates', "modules/{$module}", 'cron')), array('templates' => "Smarty/templates/modules/{$module}", 'cron' => "cron/modules/{$module}")); // If data is not yet available if (empty($this->_modulexml)) { $this->__parseManifestFile($unzip); } if ($unzip) { $unzip->close(); } } return $module; }