function downloadUpdate($sLink)
 {
     $sName = mktime() . '.zip';
     $sData = bx_file_get_contents($sLink);
     //--- write ZIP archive.
     $sTmpPath = BX_DIRECTORY_PATH_ROOT . 'tmp/';
     $sFilePath = $sTmpPath . $sName;
     if (!($rHandler = fopen($sFilePath, 'w'))) {
         return _t('_adm_txt_modules_cannot_download_package');
     }
     if (!fwrite($rHandler, $sData)) {
         return _t('_adm_txt_modules_cannot_write_package');
     }
     fclose($rHandler);
     //--- Unarchive package.
     if (!class_exists('ZipArchive')) {
         return _t('_adm_txt_modules_zip_not_available');
     }
     $oZip = new ZipArchive();
     if ($oZip->open($sFilePath) !== true) {
         return _t('_adm_txt_modules_cannot_unzip_package');
     }
     $sPackageRootFolder = $oZip->numFiles > 0 ? $oZip->getNameIndex(0) : false;
     if ($sPackageRootFolder && file_exists($sTmpPath . $sPackageRootFolder)) {
         // remove existing tmp folder with the same name
         bx_rrmdir($sTmpPath . $sPackageRootFolder);
     }
     if ($sPackageRootFolder && !$oZip->extractTo($sTmpPath)) {
         return _t('_adm_txt_modules_cannot_unzip_package');
     }
     $oZip->close();
     //--- Move unarchived package.
     $sLogin = getParam('sys_ftp_login');
     $sPassword = getParam('sys_ftp_password');
     $sPath = getParam('sys_ftp_dir');
     if (empty($sLogin) || empty($sPassword) || empty($sPath)) {
         return _t('_adm_txt_modules_no_ftp_info');
     }
     bx_import('BxDolFtp');
     $oFtp = new BxDolFtp($_SERVER['HTTP_HOST'], $sLogin, $sPassword, $sPath);
     if (!$oFtp->connect()) {
         return _t('_adm_txt_modules_cannot_connect_to_ftp');
     }
     if (!$oFtp->isDolphin()) {
         return _t('_adm_txt_modules_destination_not_valid');
     }
     $sConfigPath = $sTmpPath . $sPackageRootFolder . '/install/config.php';
     if (!file_exists($sConfigPath)) {
         return _t('_adm_txt_modules_wrong_package_format');
     }
     include $sConfigPath;
     if (empty($aConfig) || empty($aConfig['home_dir']) || !$oFtp->copy($sTmpPath . $sPackageRootFolder . '/', 'modules/' . $aConfig['home_dir'])) {
         return _t('_adm_txt_modules_ftp_copy_failed');
     }
     return true;
 }
Example #2
0
 function actionChangePermissions($bInstall = true)
 {
     $aPermissions = $bInstall ? $this->_aConfig['install_permissions'] : $this->_aConfig['uninstall_permissions'];
     $aResult = $aChangeItems = array();
     foreach ($aPermissions as $sPermissions => $aFiles) {
         $sCheckFunction = 'is' . ucfirst($sPermissions);
         foreach ($aFiles as $sFile) {
             $sPath = bx_ltrim_str($this->_sModulePath . $sFile, BX_DIRECTORY_PATH_ROOT);
             if (BxDolInstallerUtils::$sCheckFunction($sPath)) {
                 continue;
             }
             $aResult[] = array('path' => $this->_sModulePath . $sFile, 'permissions' => $sPermissions);
             $aChangeItems[] = array('file' => $sFile, 'path' => $sPath, 'permissions' => $sPermissions);
         }
     }
     if (empty($aChangeItems)) {
         return BX_DOL_INSTALLER_SUCCESS;
     }
     bx_import('BxDolFtp');
     $oFile = new BxDolFtp($_SERVER['HTTP_HOST'], getParam('sys_ftp_login'), getParam('sys_ftp_password'), getParam('sys_ftp_dir'));
     if (!$oFile->connect()) {
         return array('code' => BX_DOL_INSTALLER_FAILED, 'content_msg' => '_adm_txt_modules_wrong_permissions_change_cannot_connect_to_ftp', 'content_data' => $aResult);
     }
     if (!$oFile->isDolphin()) {
         return array('code' => BX_DOL_INSTALLER_FAILED, 'content_msg' => '_adm_txt_modules_wrong_permissions_change_destination_not_valid', 'content_data' => $aResult);
     }
     $aResult = array();
     foreach ($aChangeItems as $aChangeItem) {
         if (!$oFile->setPermissions($aChangeItem['path'], $aChangeItem['permissions'])) {
             $aResult[] = array('path' => $this->_sModulePath . $aChangeItem['file'], 'permissions' => $aChangeItem['permissions']);
         }
     }
     return empty($aResult) ? BX_DOL_INSTALLER_SUCCESS : array('code' => BX_DOL_INSTALLER_FAILED, 'content_msg' => '_adm_txt_modules_wrong_permissions_change', 'content_data' => $aResult);
 }
 protected function _getFileManager()
 {
     $oFile = null;
     if ($this->_bUseFtp) {
         bx_import('BxDolFtp');
         $oFile = new BxDolFtp(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost', getParam('sys_ftp_login'), getParam('sys_ftp_password'), getParam('sys_ftp_dir'));
         if (!$oFile->connect()) {
             return null;
         }
         if (!$oFile->isDolphin()) {
             return null;
         }
     } else {
         bx_import('BxDolFile');
         $oFile = BxDolFile::getInstance();
     }
     return $oFile;
 }
 protected function performCopy($sPackagePath, &$sHomePath)
 {
     if ($this->bUseFtp) {
         $sLogin = getParam('sys_ftp_login');
         $sPassword = getParam('sys_ftp_password');
         $sPath = getParam('sys_ftp_dir');
         if (empty($sLogin) || empty($sPassword) || empty($sPath)) {
             return _t('_adm_str_err_no_ftp_info');
         }
         bx_import('BxDolFtp');
         $oFile = new BxDolFtp($_SERVER['HTTP_HOST'], $sLogin, $sPassword, $sPath);
         if (!$oFile->connect()) {
             return _t('_adm_str_err_cannot_connect_to_ftp');
         }
         if (!$oFile->isDolphin()) {
             return _t('_adm_str_err_destination_not_valid');
         }
     } else {
         bx_import('BxDolFile');
         $oFile = BxDolFile::getInstance();
     }
     $aConfig = self::getModuleConfig($sPackagePath . 'install/config.php');
     if (empty($aConfig) || !is_array($aConfig) || empty($aConfig['home_dir'])) {
         return _t('_adm_str_err_wrong_package_format');
     }
     $sHomePath = $aConfig['home_dir'];
     if (!$oFile->copy($sPackagePath, 'modules/' . $sHomePath)) {
         return _t('_adm_str_err_files_copy_failed');
     }
     return true;
 }
Example #5
0
 function actionUpload($sType, $aFile, $aFtpInfo)
 {
     $sLogin = htmlspecialchars_adv(clear_xss($aFtpInfo['login']));
     $sPassword = htmlspecialchars_adv(clear_xss($aFtpInfo['password']));
     $sPath = htmlspecialchars_adv(clear_xss($aFtpInfo['path']));
     setParam('sys_ftp_login', $sLogin);
     setParam('sys_ftp_password', $sPassword);
     setParam('sys_ftp_dir', $sPath);
     $sErrMsg = false;
     $sName = mktime();
     $sAbsolutePath = BX_DIRECTORY_PATH_ROOT . "tmp/" . $sName . '.zip';
     $sPackageRootFolder = false;
     if (!class_exists('ZipArchive')) {
         $sErrMsg = '_adm_txt_modules_zip_not_available';
     }
     if (!$sErrMsg && $this->_isArchive($aFile['type']) && move_uploaded_file($aFile['tmp_name'], $sAbsolutePath)) {
         // extract uploaded zip package into tmp folder
         $oZip = new ZipArchive();
         if ($oZip->open($sAbsolutePath) !== TRUE) {
             $sErrMsg = '_adm_txt_modules_cannot_unzip_package';
         }
         if (!$sErrMsg) {
             $sPackageRootFolder = $oZip->numFiles > 0 ? $oZip->getNameIndex(0) : false;
             if (file_exists(BX_DIRECTORY_PATH_ROOT . 'tmp/' . $sPackageRootFolder)) {
                 // remove existing tmp folder with the same name
                 bx_rrmdir(BX_DIRECTORY_PATH_ROOT . 'tmp/' . $sPackageRootFolder);
             }
             if ($sPackageRootFolder && !$oZip->extractTo(BX_DIRECTORY_PATH_ROOT . 'tmp/')) {
                 $sErrMsg = '_adm_txt_modules_cannot_unzip_package';
             }
             $oZip->close();
         }
         // upload files to the correct folder via FTP
         if (!$sErrMsg && $sPackageRootFolder) {
             $oFtp = new BxDolFtp($_SERVER['HTTP_HOST'], $sLogin, $sPassword, $sPath);
             if (!$oFtp->connect()) {
                 $sErrMsg = '_adm_txt_modules_cannot_connect_to_ftp';
             }
             if (!$sErrMsg && !$oFtp->isDolphin()) {
                 $sErrMsg = '_adm_txt_modules_destination_not_valid';
             }
             if (!$sErrMsg) {
                 $sConfigPath = BX_DIRECTORY_PATH_ROOT . "tmp/" . $sPackageRootFolder . $this->_aTypesConfig[$sType]['configfile'];
                 if (file_exists($sConfigPath)) {
                     include $sConfigPath;
                     $sConfigVar = !empty($this->_aTypesConfig[$sType]['configvarindex']) ? ${$this->_aTypesConfig[$sType]['configvar']}[$this->_aTypesConfig[$sType]['configvarindex']] : ${$this->_aTypesConfig[$sType]['configvar']};
                     $sSubfolder = $this->_aTypesConfig[$sType]['subfolder'];
                     $sSubfolder = str_replace('{configvar}', $sConfigVar, $sSubfolder);
                     $sSubfolder = str_replace('{packagerootfolder}', $sPackageRootFolder, $sSubfolder);
                     if (!$oFtp->copy(BX_DIRECTORY_PATH_ROOT . "tmp/" . $sPackageRootFolder . '/', $this->_aTypesConfig[$sType]['folder'] . $sSubfolder)) {
                         $sErrMsg = '_adm_txt_modules_ftp_copy_failed';
                     }
                 } else {
                     $sErrMsg = '_adm_txt_modules_wrong_package_format';
                 }
             }
         } else {
             $sErrMsg = '_adm_txt_modules_cannot_unzip_package';
         }
         // remove temporary files
         bx_rrmdir(BX_DIRECTORY_PATH_ROOT . 'tmp/' . $sPackageRootFolder);
         unlink($sAbsolutePath);
     } else {
         $sErrMsg = '_adm_txt_modules_cannot_upload_package';
     }
     return $sErrMsg ? $sErrMsg : '_adm_txt_modules_success_upload';
 }