Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 /**
  * Check if zipfile is a valid package
  * @access private
  */
 function checkZip($zipfile)
 {
     global $YetiForce_current_version, $default_language;
     $unzip = new Vtiger_Unzip($zipfile);
     $filelist = $unzip->getList();
     $manifestxml_found = false;
     $languagefile_found = false;
     $layoutfile_found = false;
     $updatefile_found = false;
     $extensionfile_found = false;
     $moduleVersionFound = false;
     $modulename = null;
     $language_modulename = null;
     foreach ($filelist as $filename => $fileinfo) {
         $matches = array();
         preg_match('/manifest.xml/', $filename, $matches);
         if (count($matches)) {
             $manifestxml_found = true;
             $this->__parseManifestFile($unzip);
             $modulename = (string) $this->_modulexml->name;
             $isModuleBundle = (string) $this->_modulexml->modulebundle;
             if ($isModuleBundle === 'true' && !empty($this->_modulexml) && !empty($this->_modulexml->dependencies) && !empty($this->_modulexml->dependencies->vtiger_version)) {
                 $languagefile_found = true;
                 break;
             }
             // Do we need to check the zip further?
             if ($this->isLanguageType()) {
                 $languagefile_found = true;
                 // No need to search for module language file.
                 break;
             } else {
                 if ($this->isLayoutType()) {
                     $layoutfile_found = true;
                     // No need to search for module language file.
                     break;
                 } else {
                     if ($this->isExtensionType()) {
                         $extensionfile_found = true;
                         // No need to search for module language file.
                         break;
                     } else {
                         if ($this->isUpdateType()) {
                             $updatefile_found = true;
                             // No need to search for module language file.
                             break;
                         } else {
                             continue;
                         }
                     }
                 }
             }
         }
         // Language file present in en_us folder
         $pattern = '/languages\\/' . $default_language . '\\/([^\\/]+).php/';
         preg_match($pattern, $filename, $matches);
         if (count($matches)) {
             $language_modulename = $matches[1];
         }
         // or Language file may be present in en_us/Settings folder
         $settingsPattern = '/languages\\/' . $default_language . '\\/Settings\\/([^\\/]+).php/';
         preg_match($settingsPattern, $filename, $matches);
         if (count($matches)) {
             $language_modulename = $matches[1];
         }
     }
     // Verify module language file.
     if (!empty($language_modulename) && $language_modulename == $modulename) {
         $languagefile_found = true;
     } else {
         $_errorText = vtranslate('LBL_ERROR_NO_DEFAULT_LANGUAGE', 'Settings:ModuleManager');
         $_errorText = str_replace('__DEFAULTLANGUAGE__', $default_language, $_errorText);
         $this->_errorText = $_errorText;
     }
     if (!empty($this->_modulexml) && !empty($this->_modulexml->dependencies) && !empty($this->_modulexml->dependencies->vtiger_version)) {
         $moduleVersion = (string) $this->_modulexml->dependencies->vtiger_version;
         if (version_compare($moduleVersion, $YetiForce_current_version, '>=') === true) {
             $moduleVersionFound = true;
         } else {
             $_errorText = vtranslate('LBL_ERROR_VERSION', 'Settings:ModuleManager');
             $_errorText = str_replace('__MODULEVERSION__', $moduleVersion, $_errorText);
             $_errorText = str_replace('__CRMVERSION__', $YetiForce_current_version, $_errorText);
             $this->_errorText = $_errorText;
         }
     }
     $validzip = false;
     if ($manifestxml_found && $languagefile_found && $moduleVersionFound) {
         $validzip = true;
     }
     if ($manifestxml_found && $layoutfile_found && $moduleVersionFound) {
         $validzip = true;
     }
     if ($manifestxml_found && $languagefile_found && $extensionfile_found && $moduleVersionFound) {
         $validzip = true;
     }
     if ($manifestxml_found && $updatefile_found && $moduleVersionFound) {
         $validzip = true;
     }
     if ($validzip) {
         if (!empty($this->_modulexml->license)) {
             if (!empty($this->_modulexml->license->inline)) {
                 $this->_licensetext = $this->_modulexml->license->inline;
             } else {
                 if (!empty($this->_modulexml->license->file)) {
                     $licensefile = $this->_modulexml->license->file;
                     $licensefile = "{$licensefile}";
                     if (!empty($filelist[$licensefile])) {
                         $this->_licensetext = $unzip->unzip($licensefile);
                     } else {
                         $this->_licensetext = "Missing {$licensefile}!";
                     }
                 }
             }
         }
     }
     if ($unzip) {
         $unzip->close();
     }
     return $validzip;
 }
Пример #4
0
 /**
  * Check if zipfile is a valid package
  * @access private
  */
 function checkZip($zipfile)
 {
     $unzip = new Vtiger_Unzip($zipfile);
     $filelist = $unzip->getList();
     $manifestxml_found = false;
     $languagefile_found = false;
     $vtigerversion_found = false;
     $modulename = null;
     $language_modulename = null;
     foreach ($filelist as $filename => $fileinfo) {
         $matches = array();
         preg_match('/manifest.xml/', $filename, $matches);
         if (count($matches)) {
             $manifestxml_found = true;
             $this->__parseManifestFile($unzip);
             $modulename = $this->_modulexml->name;
             $isModuleBundle = (string) $this->_modulexml->modulebundle;
             if ($isModuleBundle === 'true' && !empty($this->_modulexml) && !empty($this->_modulexml->dependencies) && !empty($this->_modulexml->dependencies->vtiger_version)) {
                 $languagefile_found = true;
                 break;
             }
             // Do we need to check the zip further?
             if ($this->isLanguageType()) {
                 $languagefile_found = true;
                 // No need to search for module language file.
                 break;
             } else {
                 continue;
             }
         }
         // Check for language file.
         preg_match("/modules\\/([^\\/]+)\\/language\\/en_us.lang.php/", $filename, $matches);
         if (count($matches)) {
             $language_modulename = $matches[1];
             continue;
         }
     }
     // Verify module language file.
     if (!empty($language_modulename) && $language_modulename == $modulename) {
         $languagefile_found = true;
     }
     if (!empty($this->_modulexml) && !empty($this->_modulexml->dependencies) && !empty($this->_modulexml->dependencies->vtiger_version)) {
         $vtigerversion_found = true;
     }
     $validzip = false;
     if ($manifestxml_found && $languagefile_found && $vtigerversion_found) {
         $validzip = true;
     }
     if ($validzip) {
         if (!empty($this->_modulexml->license)) {
             if (!empty($this->_modulexml->license->inline)) {
                 $this->_licensetext = $this->_modulexml->license->inline;
             } else {
                 if (!empty($this->_modulexml->license->file)) {
                     $licensefile = $this->_modulexml->license->file;
                     $licensefile = "{$licensefile}";
                     if (!empty($filelist[$licensefile])) {
                         $this->_licensetext = $unzip->unzip($licensefile);
                     } else {
                         $this->_licensetext = "Missing {$licensefile}!";
                     }
                 }
             }
         }
     }
     if ($unzip) {
         $unzip->close();
     }
     return $validzip;
 }
Пример #5
0
 /**
  * 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;
 }
 /**
  * Check if zipfile is a valid package
  * @access private
  */
 function checkZip($zipfile)
 {
     $unzip = new Vtiger_Unzip($zipfile);
     $filelist = $unzip->getList();
     $manifestxml_found = false;
     $languagefile_found = false;
     $layoutfile_found = false;
     $vtigerversion_found = false;
     $modulename = null;
     $language_modulename = null;
     foreach ($filelist as $filename => $fileinfo) {
         $matches = array();
         preg_match('/manifest.xml/', $filename, $matches);
         if (count($matches)) {
             $manifestxml_found = true;
             $this->__parseManifestFile($unzip);
             $modulename = $this->_modulexml->name;
             $isModuleBundle = (string) $this->_modulexml->modulebundle;
             if ($isModuleBundle === 'true' && !empty($this->_modulexml) && !empty($this->_modulexml->dependencies) && !empty($this->_modulexml->dependencies->vtiger_version)) {
                 $languagefile_found = true;
                 break;
             }
             // Do we need to check the zip further?
             if ($this->isLanguageType()) {
                 $languagefile_found = true;
                 // No need to search for module language file.
                 break;
             } else {
                 if ($this->isLayoutType()) {
                     $layoutfile_found = true;
                     // No need to search for module language file.
                     break;
                 } else {
                     if ($this->isExtensionType()) {
                         $extensionfile_found = true;
                         // No need to search for module language file.
                         break;
                     } else {
                         continue;
                     }
                 }
             }
         }
         // Language file present in en_us folder
         $pattern = '/languages\\/en_us\\/([^\\/]+).php/';
         preg_match($pattern, $filename, $matches);
         if (count($matches)) {
             $language_modulename = $matches[1];
         }
         // or Language file may be present in en_us/Settings folder
         $settingsPattern = '/languages\\/en_us\\/Settings\\/([^\\/]+).php/';
         preg_match($settingsPattern, $filename, $matches);
         if (count($matches)) {
             $language_modulename = $matches[1];
         }
     }
     // Verify module language file.
     if (!empty($language_modulename) && $language_modulename == $modulename) {
         $languagefile_found = true;
     }
     if (!empty($this->_modulexml) && !empty($this->_modulexml->dependencies) && !empty($this->_modulexml->dependencies->vtiger_version)) {
         $vtigerVersion = (string) $this->_modulexml->dependencies->vtiger_version;
         if (version_compare($vtigerVersion, '6.0.0rc', '>=') === true) {
             $vtigerversion_found = true;
         }
     }
     $validzip = false;
     if ($manifestxml_found && $languagefile_found && $vtigerversion_found) {
         $validzip = true;
     }
     if ($manifestxml_found && $layoutfile_found && $vtigerversion_found) {
         $validzip = true;
     }
     if ($manifestxml_found && $extensionfile_found && $vtigerversion_found) {
         $validzip = true;
     }
     if ($validzip) {
         if (!empty($this->_modulexml->license)) {
             if (!empty($this->_modulexml->license->inline)) {
                 $this->_licensetext = $this->_modulexml->license->inline;
             } else {
                 if (!empty($this->_modulexml->license->file)) {
                     $licensefile = $this->_modulexml->license->file;
                     $licensefile = "{$licensefile}";
                     if (!empty($filelist[$licensefile])) {
                         $this->_licensetext = $unzip->unzip($licensefile);
                     } else {
                         $this->_licensetext = "Missing {$licensefile}!";
                     }
                 }
             }
         }
     }
     if ($unzip) {
         $unzip->close();
     }
     return $validzip;
 }