From 72dd48a59600a16cca4b714621868de1cc969fe2 Mon Sep 17 00:00:00 2001 From: akasima Date: Tue, 12 Aug 2014 15:04:16 +0900 Subject: [PATCH] #904 autoinstall without ftp --- classes/file/FileHandler.class.php | 27 ++++ .../autoinstall.admin.controller.php | 21 ++- .../autoinstall/autoinstall.admin.model.php | 55 ++++++++ .../autoinstall/autoinstall.admin.view.php | 7 + modules/autoinstall/autoinstall.lib.php | 125 ++++++++++++++++++ modules/autoinstall/lang/lang.xml | 5 + modules/autoinstall/tpl/install.html | 10 +- modules/autoinstall/tpl/uninstall.html | 11 +- 8 files changed, 253 insertions(+), 8 deletions(-) diff --git a/classes/file/FileHandler.class.php b/classes/file/FileHandler.class.php index db1a82f62..968233923 100644 --- a/classes/file/FileHandler.class.php +++ b/classes/file/FileHandler.class.php @@ -1017,6 +1017,33 @@ class FileHandler $path = self::getRealPath($path); return is_dir($path) ? $path : FALSE; } + + /** + * Check is writable dir + * + * @param string $path Target dir path + * @return bool + */ + function isWritableDir($path) + { + $path = self::getRealPath($path); + if(is_dir($path)==FALSE) + { + return FALSE; + } + + $checkFile = $path . '/_CheckWritableDir'; + + $fp = fopen($checkFile, 'w'); + if(!is_resource($fp)) + { + return FALSE; + } + fclose($fp); + + self::removeFile($checkFile); + return TRUE; + } } /* End of file FileHandler.class.php */ diff --git a/modules/autoinstall/autoinstall.admin.controller.php b/modules/autoinstall/autoinstall.admin.controller.php index 0559ed293..25c4e7efe 100644 --- a/modules/autoinstall/autoinstall.admin.controller.php +++ b/modules/autoinstall/autoinstall.admin.controller.php @@ -181,6 +181,7 @@ class autoinstallAdminController extends autoinstall @set_time_limit(0); $package_srls = Context::get('package_srl'); $oModel = getModel('autoinstall'); + $oAdminModel = getAdminModel('autoinstall'); $packages = explode(',', $package_srls); $ftp_info = Context::getFTPInfo(); if(!$_SESSION['ftp_password']) @@ -196,7 +197,11 @@ class autoinstallAdminController extends autoinstall foreach($packages as $package_srl) { $package = $oModel->getPackage($package_srl); - if($ftp_info->sftp && $ftp_info->sftp == 'Y' && $isSftpSupported) + if($oAdminModel->checkUseDirectModuleInstall($package)->toBool()) + { + $oModuleInstaller = new DirectModuleInstaller($package); + } + else if($ftp_info->sftp && $ftp_info->sftp == 'Y' && $isSftpSupported) { $oModuleInstaller = new SFTPModuleInstaller($package); } @@ -308,7 +313,11 @@ class autoinstallAdminController extends autoinstall { $package_srl = Context::get('package_srl'); - $this->uninstallPackageByPackageSrl($package_srl); + $output = $this->uninstallPackageByPackageSrl($package_srl); + if($output->toBool()==FALSE) + { + return $output; + } if(Context::get('return_url')) { @@ -348,6 +357,8 @@ class autoinstallAdminController extends autoinstall { $path = $package->path; + $oAdminModel = getAdminModel('autoinstall'); + if(!$_SESSION['ftp_password']) { $ftp_password = Context::get('ftp_password'); @@ -359,7 +370,11 @@ class autoinstallAdminController extends autoinstall $ftp_info = Context::getFTPInfo(); $isSftpSupported = function_exists(ssh2_sftp); - if($ftp_info->sftp && $ftp_info->sftp == 'Y' && $isSftpSupported) + if($oAdminModel->checkUseDirectModuleInstall($package)->toBool()) + { + $oModuleInstaller = new DirectModuleInstaller($package); + } + else if($ftp_info->sftp && $ftp_info->sftp == 'Y' && $isSftpSupported) { $oModuleInstaller = new SFTPModuleInstaller($package); } diff --git a/modules/autoinstall/autoinstall.admin.model.php b/modules/autoinstall/autoinstall.admin.model.php index 0b228e801..cae7cf93d 100644 --- a/modules/autoinstall/autoinstall.admin.model.php +++ b/modules/autoinstall/autoinstall.admin.model.php @@ -348,6 +348,61 @@ class autoinstallAdminModel extends autoinstall $this->add('package', $package); } + public function checkUseDirectModuleInstall($package) + { + $directModuleInstall = TRUE; + $arrUnwritableDir = array(); + $output = $this->isWritableDir($package->path); + if($output->toBool()==FALSE) + { + $directModuleInstall = FALSE; + $arrUnwritableDir[] = $output->get('path'); + } + + foreach($package->depends as $dep) + { + $output = $this->isWritableDir($dep->path); + if($output->toBool()==FALSE) + { + $directModuleInstall = FALSE; + $arrUnwritableDir[] = $output->get('path'); + } + } + + if($directModuleInstall==FALSE) + { + $output = new Object(-1, 'msg_direct_inall_invalid'); + $output->add('path', $arrUnwritableDir); + return $output; + } + + return new Object(); + } + + public function isWritableDir($path) + { + $path_list = explode('/', dirname($path)); + $real_path = './'; + + while($path_list) + { + $check_path = $real_path . implode('/', $path_list); + if(FileHandler::isDir($check_path)) + { + break; + } + array_pop($path_list); + } + + if(FileHandler::isWritableDir($check_path)==FALSE) + { + $output = new Object(-1, 'msg_unwritable_directory'); + $output->add('path', FileHandler::getRealPath($check_path)); + return $output; + } + return new Object(); + } + } /* End of file autoinstall.admin.model.php */ /* Location: ./modules/autoinstall/autoinstall.admin.model.php */ diff --git a/modules/autoinstall/autoinstall.admin.view.php b/modules/autoinstall/autoinstall.admin.view.php index 956ac3e3f..2f5c02717 100644 --- a/modules/autoinstall/autoinstall.admin.view.php +++ b/modules/autoinstall/autoinstall.admin.view.php @@ -368,6 +368,9 @@ class autoinstallAdminView extends autoinstall Context::set('need_password', TRUE); } + $output = $oAdminModel->checkUseDirectModuleInstall($package); + Context::set('directModuleInstall', $output); + $this->setTemplateFile('install'); $security = new Security(); @@ -503,6 +506,7 @@ class autoinstallAdminView extends autoinstall } $oModel = getModel('autoinstall'); + $oAdminModel = getAdminModel('autoinstall'); $installedPackage = $oModel->getInstalledPackage($package_srl); if(!$installedPackage) { @@ -529,6 +533,9 @@ class autoinstallAdminView extends autoinstall return $this->stop("msg_invalid_request"); } + $output = $oAdminModel->checkUseDirectModuleInstall($installedPackage); + Context::set('directModuleInstall', $output); + $params["act"] = "getResourceapiPackages"; $params["package_srls"] = $package_srl; $body = XmlGenerater::generate($params); diff --git a/modules/autoinstall/autoinstall.lib.php b/modules/autoinstall/autoinstall.lib.php index f1ebfbad2..ec75d030b 100644 --- a/modules/autoinstall/autoinstall.lib.php +++ b/modules/autoinstall/autoinstall.lib.php @@ -867,6 +867,131 @@ class FTPModuleInstaller extends ModuleInstaller return new Object(); } +} + +/** + * Module installer for Direct. Not use FTP + * @author NAVER (developers@xpressengine.com) + */ +class DirectModuleInstaller extends ModuleInstaller +{ + /** + * Constructor + * + * @param object $package Package information + */ + function DirectModuleInstaller(&$package) + { + $this->package = &$package; + } + + /** + * empty + * + * @return Object + */ + function _connect() + { + return new Object(); + } + + /** + * Remove file + * + * @param string $path Path to remove + * @return Object + */ + function _removeFile($path) + { + if(substr($path, 0, 2) == "./") + { + $path = substr($path, 2); + } + $target_path = FileHandler::getRealPath($path); + + if(!FileHandler::removeFile($target_path)) + { + return new Object(-1, sprintf(Context::getLang('msg_delete_file_failed'), $path)); + } + return new Object(); + } + + /** + * Remove directory + * @param string $path Path to remove + * @return Object + */ + function _removeDir_real($path) + { + if(substr($path, 0, 2) == "./") + { + $path = substr($path, 2); + } + $target_path = FileHandler::getRealPath($path); + + FileHandler::removeDir($target_path); + + return new Object(); + } + + /** + * Close + * + * @return void + */ + function _close() + { + } + + /** + * Copy directory + * + * @param array $file_list File list to copy + * @return Object + */ + function _copyDir(&$file_list) + { + $output = $this->_connect(); + if(!$output->toBool()) + { + return $output; + } + $target_dir = $this->target_path; + + if(is_array($file_list)) + { + foreach($file_list as $k => $file) + { + $org_file = $file; + if($this->package->path == ".") + { + $file = substr($file, 3); + } + $path = FileHandler::getRealPath("./" . $this->target_path . "/" . $file); + $path_list = explode('/', dirname($this->target_path . "/" . $file)); + $real_path = "./"; + + for($i = 0; $i < count($path_list); $i++) + { + if($path_list == "") + { + continue; + } + $real_path .= $path_list[$i] . "/"; + if(!file_exists(FileHandler::getRealPath($real_path))) + { + FileHandler::makeDir($real_path); + } + } + FileHandler::copyFile( FileHandler::getRealPath($this->download_path . "/" . $org_file), FileHandler::getRealPath("./" . $target_dir . '/' . $file)); + } + } + + $this->_close(); + + return new Object(); + } + } /* End of file autoinstall.lib.php */ /* Location: ./modules/autoinstall/autoinstall.lib.php */ diff --git a/modules/autoinstall/lang/lang.xml b/modules/autoinstall/lang/lang.xml index 00aad260d..5998c0f52 100644 --- a/modules/autoinstall/lang/lang.xml +++ b/modules/autoinstall/lang/lang.xml @@ -323,6 +323,11 @@ + + + + + diff --git a/modules/autoinstall/tpl/install.html b/modules/autoinstall/tpl/install.html index 7cf5e506d..3efbc0fd4 100644 --- a/modules/autoinstall/tpl/install.html +++ b/modules/autoinstall/tpl/install.html @@ -40,10 +40,10 @@ - + - +
@@ -52,6 +52,12 @@
+ +

{$lang->msg_direct_install_not_supported}

+
    +
  • {$path}
  • +
+
diff --git a/modules/autoinstall/tpl/uninstall.html b/modules/autoinstall/tpl/uninstall.html index 23a75e646..d6f6b5c2c 100644 --- a/modules/autoinstall/tpl/uninstall.html +++ b/modules/autoinstall/tpl/uninstall.html @@ -17,10 +17,10 @@ - + - +
@@ -29,7 +29,12 @@
- + +

{$lang->msg_direct_install_not_supported}

+
    +
  • {$path}
  • +
+