function actionUpdateFiles($bInstall = true) { $sPath = $this->_sHomePath . 'source/'; if (!file_exists($sPath)) { return BX_DOL_INSTALLER_FAILED; } $oFtp = new BxDolFtp($_SERVER['HTTP_HOST'], getParam('sys_ftp_login'), getParam('sys_ftp_password'), getParam('sys_ftp_dir')); if ($oFtp->connect() == false) { return BX_DOL_INSTALLER_FAILED; } return $oFtp->copy($sPath . '*', 'modules/' . $this->_aConfig['module_dir']) ? BX_DOL_INSTALLER_SUCCESS : BX_DOL_INSTALLER_FAILED; }
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; }
protected function _getFileManager() { $oFile = null; if ($this->_bUseFtp) { $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->isTrident()) { return null; } } else { $oFile = BxDolFile::getInstance(); } return $oFile; }
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 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; }
function actionDelete($aDirectories) { $oFtp = new BxDolFtp($_SERVER['HTTP_HOST'], getParam('sys_ftp_login'), getParam('sys_ftp_password'), getParam('sys_ftp_dir')); if (!$oFtp->connect()) { return '_adm_txt_modules_cannot_connect_to_ftp'; } foreach ($aDirectories as $sDirectory) { if (!$oFtp->delete('modules/' . $sDirectory)) { return '_adm_txt_modules_cannot_remove_package'; } } return '_adm_txt_modules_success_delete'; }
function actionDelete($aDirectories, $sType = 'module') { $oFtp = new BxDolFtp($_SERVER['HTTP_HOST'], getParam('sys_ftp_login'), getParam('sys_ftp_password'), getParam('sys_ftp_dir')); if (!$oFtp->connect()) { return '_adm_txt_modules_cannot_connect_to_ftp'; } $sDir = $this->_aTypesConfig[$sType]['folder']; foreach ($aDirectories as $sDirectory) { if (!$oFtp->delete($sDir . $sDirectory)) { return '_adm_txt_modules_cannot_remove_package'; } } return '_adm_txt_modules_success_delete'; }