mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-08 19:42:15 +09:00
#18532365 : remove storing ftp_password.
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@7156 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
ddfa2f6df1
commit
c43d52da74
27 changed files with 373 additions and 291 deletions
|
|
@ -5,195 +5,7 @@
|
|||
* @brief autoinstall 모듈의 admin controller class
|
||||
**/
|
||||
|
||||
class ModuleInstaller {
|
||||
var $package = null;
|
||||
var $base_url = 'http://download.xpressengine.com/';
|
||||
var $temp_dir = './files/cache/autoinstall/';
|
||||
var $target_path;
|
||||
var $download_file;
|
||||
var $url;
|
||||
var $download_path;
|
||||
|
||||
function _download()
|
||||
{
|
||||
if($this->package->path == ".")
|
||||
{
|
||||
$this->download_file = $this->temp_dir."xe.tar";
|
||||
$this->target_path = "";
|
||||
$this->download_path = $this->temp_dir;
|
||||
}
|
||||
else
|
||||
{
|
||||
$subpath = substr($this->package->path,2);
|
||||
$this->download_file = $this->temp_dir.$subpath.".tar";
|
||||
$subpatharr = explode("/", $subpath);
|
||||
array_pop($subpatharr);
|
||||
$this->download_path = $this->temp_dir.implode("/", $subpatharr);
|
||||
$this->target_path = implode("/", $subpatharr);
|
||||
}
|
||||
|
||||
$postdata = array();
|
||||
$postdata["path"] = $this->package->path;
|
||||
$postdata["module"] = "resourceapi";
|
||||
$postdata["act"] = "procResourceapiDownload";
|
||||
$buff = FileHandler::getRemoteResource($this->base_url, null, 3, "POST", "application/x-www-form-urlencoded; charset=utf-8", array(), array(), $postdata);
|
||||
FileHandler::writeFile($this->download_file, $buff);
|
||||
}
|
||||
|
||||
function installModule()
|
||||
{
|
||||
$path_array = explode("/", $this->package->path);
|
||||
$target_name = array_pop($path_array);
|
||||
$type = substr(array_pop($path_array), 0, -1);
|
||||
if($type == "module")
|
||||
{
|
||||
$oModuleModel = &getModel('module');
|
||||
$oInstallController = &getController('install');
|
||||
$module_path = ModuleHandler::getModulePath($target_name);
|
||||
if($oModuleModel->checkNeedInstall($target_name))
|
||||
{
|
||||
$oInstallController->installModule($target_name, $module_path);
|
||||
}
|
||||
if($oModuleModel->checkNeedUpdate($target_name))
|
||||
{
|
||||
$oModule = &getModule($target_name, 'class');
|
||||
if(method_exists($oModule, 'moduleUpdate'))
|
||||
{
|
||||
$oModule->moduleUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function install()
|
||||
{
|
||||
$this->_download();
|
||||
$file_list = $this->_unPack();
|
||||
$this->_copyDir($file_list);
|
||||
$this->installModule();
|
||||
|
||||
FileHandler::removeDir($this->temp_dir);
|
||||
return;
|
||||
}
|
||||
|
||||
function _unPack(){
|
||||
require_once(_XE_PATH_.'libs/tar.class.php');
|
||||
|
||||
$oTar = new tar();
|
||||
$oTar->openTAR($this->download_file);
|
||||
|
||||
$_files = $oTar->files;
|
||||
$file_list = array();
|
||||
foreach($_files as $key => $info) {
|
||||
FileHandler::writeFile($this->download_path."/".$info['name'], $info['file']);
|
||||
$file_list[] = $info['name'];
|
||||
}
|
||||
return $file_list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SFTPModuleInstaller extends ModuleInstaller {
|
||||
function SFTPModuleInstaller(&$package)
|
||||
{
|
||||
$this->package =& $package;
|
||||
}
|
||||
|
||||
function _copyDir(&$file_list){
|
||||
$ftp_info = Context::getFTPInfo();
|
||||
if(!$ftp_info->ftp_user || !$ftp_info->ftp_password || !$ftp_info->sftp || $ftp_info->sftp != 'Y') return new Object(-1,'msg_ftp_invalid_auth_info');
|
||||
|
||||
$connection = ssh2_connect('localhost', $ftp_info->ftp_port);
|
||||
if(!ssh2_auth_password($connection, $ftp_info->ftp_user, $ftp_info->ftp_password))
|
||||
{
|
||||
return new Object(-1,'msg_ftp_invalid_auth_info');
|
||||
}
|
||||
|
||||
$sftp = ssh2_sftp($connection);
|
||||
|
||||
$target_dir = $ftp_info->ftp_root_path.$this->target_path;
|
||||
|
||||
foreach($file_list as $k => $file){
|
||||
$org_file = $file;
|
||||
if($this->package->path == ".")
|
||||
{
|
||||
$file = substr($file,3);
|
||||
}
|
||||
$path = FileHandler::getRealPath("./".$this->target_path."/".$file);
|
||||
$pathname = dirname($target_dir."/".$file);
|
||||
|
||||
if(!file_exists(FileHandler::getRealPath($real_path)))
|
||||
{
|
||||
ssh2_sftp_mkdir($sftp, $pathname, 0755, true);
|
||||
}
|
||||
|
||||
ssh2_scp_send($connection, FileHandler::getRealPath($this->download_path."/".$org_file), $target_dir."/".$file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FTPModuleInstaller extends ModuleInstaller {
|
||||
function FTPModuleInstaller(&$package)
|
||||
{
|
||||
$this->package =& $package;
|
||||
}
|
||||
|
||||
function _copyDir(&$file_list){
|
||||
$ftp_info = Context::getFTPInfo();
|
||||
if(!$ftp_info->ftp_user || !$ftp_info->ftp_password) return new Object(-1,'msg_ftp_invalid_auth_info');
|
||||
|
||||
require_once(_XE_PATH_.'libs/ftp.class.php');
|
||||
|
||||
$oFtp = new ftp();
|
||||
if(!$oFtp->ftp_connect('localhost', $ftp_info->ftp_port)) return new Object(-1,'msg_ftp_not_connected');
|
||||
if(!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) {
|
||||
$oFtp->ftp_quit();
|
||||
return new Object(-1,'msg_ftp_invalid_auth_info');
|
||||
}
|
||||
|
||||
$_list = $oFtp->ftp_rawlist($ftp_info->ftp_root_path);
|
||||
if(count($_list) == 0 || !$_list[0]) {
|
||||
$oFtp->ftp_quit();
|
||||
$oFtp = new ftp();
|
||||
if(!$oFtp->ftp_connect($_SERVER['SERVER_NAME'], $ftp_info->ftp_port)) return new Object(-1,'msg_ftp_not_connected');
|
||||
if(!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) {
|
||||
$oFtp->ftp_quit();
|
||||
return new Object(-1,'msg_ftp_invalid_auth_info');
|
||||
}
|
||||
}
|
||||
|
||||
$target_dir = $ftp_info->ftp_root_path.$this->target_path;
|
||||
|
||||
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 = "./";
|
||||
$ftp_path = $ftp_info->ftp_root_path;
|
||||
|
||||
for($i=0;$i<count($path_list);$i++)
|
||||
{
|
||||
if($path_list=="") continue;
|
||||
$real_path .= $path_list[$i]."/";
|
||||
$ftp_path .= $path_list[$i]."/";
|
||||
if(!file_exists(FileHandler::getRealPath($real_path)))
|
||||
{
|
||||
$oFtp->ftp_mkdir($ftp_path);
|
||||
$oFtp->ftp_site("CHMOD 755 ".$path);
|
||||
}
|
||||
}
|
||||
$oFtp->ftp_put($target_dir .'/'. $file, FileHandler::getRealPath($this->download_path."/".$org_file));
|
||||
}
|
||||
$oFtp->ftp_quit();
|
||||
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
require_once(_XE_PATH_.'modules/autoinstall/autoinstall.lib.php');
|
||||
|
||||
class autoinstallAdminController extends autoinstall {
|
||||
|
||||
|
|
@ -303,18 +115,31 @@
|
|||
$oModel =& getModel('autoinstall');
|
||||
$packages = explode(',', $package_srls);
|
||||
$ftp_info = Context::getFTPInfo();
|
||||
if(!$_SESSION['ftp_password'])
|
||||
{
|
||||
$ftp_password = Context::get('ftp_password');
|
||||
if($ftp_password) $_SESSION['ftp_password'] = $ftp_password;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ftp_password = $_SESSION['ftp_password'];
|
||||
}
|
||||
|
||||
foreach($packages as $package_srl)
|
||||
{
|
||||
$package = $oModel->getPackage($package_srl);
|
||||
if($ftp_info->sftp && $ftp_info->sftp == 'Y')
|
||||
{
|
||||
$oModuleInstaller = new SFTPModuleInstaller($package);
|
||||
$oModuleInstaller->setPassword($ftp_password);
|
||||
}
|
||||
else
|
||||
{
|
||||
$oModuleInstaller = new FTPModuleInstaller($package);
|
||||
$oModuleInstaller->setPassword($ftp_password);
|
||||
}
|
||||
$oModuleInstaller->install();
|
||||
$output = $oModuleInstaller->install();
|
||||
if(!$output->toBool()) return $output;
|
||||
}
|
||||
$this->setMessage('success_installed');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,6 +156,10 @@
|
|||
|
||||
Context::set("package", $package);
|
||||
}
|
||||
if(!$_SESSION['ftp_password'])
|
||||
{
|
||||
Context::set('need_password', true);
|
||||
}
|
||||
$this->setTemplateFile('install');
|
||||
}
|
||||
|
||||
|
|
|
|||
215
modules/autoinstall/autoinstall.lib.php
Normal file
215
modules/autoinstall/autoinstall.lib.php
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
<?php
|
||||
|
||||
class ModuleInstaller {
|
||||
var $package = null;
|
||||
var $base_url = 'http://download.xpressengine.com/';
|
||||
var $temp_dir = './files/cache/autoinstall/';
|
||||
var $target_path;
|
||||
var $download_file;
|
||||
var $url;
|
||||
var $download_path;
|
||||
var $ftp_password;
|
||||
|
||||
function setPassword($ftp_password)
|
||||
{
|
||||
$this->ftp_password = $ftp_password;
|
||||
}
|
||||
|
||||
function _download()
|
||||
{
|
||||
if($this->package->path == ".")
|
||||
{
|
||||
$this->download_file = $this->temp_dir."xe.tar";
|
||||
$this->target_path = "";
|
||||
$this->download_path = $this->temp_dir;
|
||||
}
|
||||
else
|
||||
{
|
||||
$subpath = substr($this->package->path,2);
|
||||
$this->download_file = $this->temp_dir.$subpath.".tar";
|
||||
$subpatharr = explode("/", $subpath);
|
||||
array_pop($subpatharr);
|
||||
$this->download_path = $this->temp_dir.implode("/", $subpatharr);
|
||||
$this->target_path = implode("/", $subpatharr);
|
||||
}
|
||||
|
||||
$postdata = array();
|
||||
$postdata["path"] = $this->package->path;
|
||||
$postdata["module"] = "resourceapi";
|
||||
$postdata["act"] = "procResourceapiDownload";
|
||||
$buff = FileHandler::getRemoteResource($this->base_url, null, 3, "POST", "application/x-www-form-urlencoded; charset=utf-8", array(), array(), $postdata);
|
||||
FileHandler::writeFile($this->download_file, $buff);
|
||||
}
|
||||
|
||||
function installModule()
|
||||
{
|
||||
$path_array = explode("/", $this->package->path);
|
||||
$target_name = array_pop($path_array);
|
||||
$type = substr(array_pop($path_array), 0, -1);
|
||||
if($type == "module")
|
||||
{
|
||||
$oModuleModel = &getModel('module');
|
||||
$oInstallController = &getController('install');
|
||||
$module_path = ModuleHandler::getModulePath($target_name);
|
||||
if($oModuleModel->checkNeedInstall($target_name))
|
||||
{
|
||||
$oInstallController->installModule($target_name, $module_path);
|
||||
}
|
||||
if($oModuleModel->checkNeedUpdate($target_name))
|
||||
{
|
||||
$oModule = &getModule($target_name, 'class');
|
||||
if(method_exists($oModule, 'moduleUpdate'))
|
||||
{
|
||||
$oModule->moduleUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function install()
|
||||
{
|
||||
$this->_download();
|
||||
$file_list = $this->_unPack();
|
||||
$output = $this->_copyDir($file_list);
|
||||
if(!$output->toBool())
|
||||
{
|
||||
FileHandler::removeDir($this->temp_dir);
|
||||
return $output;
|
||||
}
|
||||
$this->installModule();
|
||||
|
||||
FileHandler::removeDir($this->temp_dir);
|
||||
return new Object();
|
||||
}
|
||||
|
||||
function _unPack(){
|
||||
require_once(_XE_PATH_.'libs/tar.class.php');
|
||||
|
||||
$oTar = new tar();
|
||||
$oTar->openTAR($this->download_file);
|
||||
|
||||
$_files = $oTar->files;
|
||||
$file_list = array();
|
||||
foreach($_files as $key => $info) {
|
||||
FileHandler::writeFile($this->download_path."/".$info['name'], $info['file']);
|
||||
$file_list[] = $info['name'];
|
||||
}
|
||||
return $file_list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SFTPModuleInstaller extends ModuleInstaller {
|
||||
function SFTPModuleInstaller(&$package)
|
||||
{
|
||||
$this->package =& $package;
|
||||
}
|
||||
|
||||
function _copyDir(&$file_list){
|
||||
if(!$this->ftp_password) return new Object(-1,'msg_ftp_password_input');
|
||||
|
||||
$ftp_info = Context::getFTPInfo();
|
||||
if(!$ftp_info->ftp_user || !$ftp_info->sftp || $ftp_info->sftp != 'Y') return new Object(-1,'msg_ftp_invalid_auth_info');
|
||||
|
||||
if($ftp_info->ftp_host)
|
||||
{
|
||||
$ftp_host = $ftp_info->ftp_host;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ftp_host = "127.0.0.1";
|
||||
}
|
||||
$connection = ssh2_connect($ftp_host, $ftp_info->ftp_port);
|
||||
if(!ssh2_auth_password($connection, $ftp_info->ftp_user, $this->ftp_password))
|
||||
{
|
||||
return new Object(-1,'msg_ftp_invalid_auth_info');
|
||||
}
|
||||
|
||||
$sftp = ssh2_sftp($connection);
|
||||
|
||||
$target_dir = $ftp_info->ftp_root_path.$this->target_path;
|
||||
|
||||
foreach($file_list as $k => $file){
|
||||
$org_file = $file;
|
||||
if($this->package->path == ".")
|
||||
{
|
||||
$file = substr($file,3);
|
||||
}
|
||||
$path = FileHandler::getRealPath("./".$this->target_path."/".$file);
|
||||
$pathname = dirname($target_dir."/".$file);
|
||||
|
||||
if(!file_exists(FileHandler::getRealPath($real_path)))
|
||||
{
|
||||
ssh2_sftp_mkdir($sftp, $pathname, 0755, true);
|
||||
}
|
||||
|
||||
ssh2_scp_send($connection, FileHandler::getRealPath($this->download_path."/".$org_file), $target_dir."/".$file);
|
||||
}
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
|
||||
class FTPModuleInstaller extends ModuleInstaller {
|
||||
function FTPModuleInstaller(&$package)
|
||||
{
|
||||
$this->package =& $package;
|
||||
}
|
||||
|
||||
function _copyDir(&$file_list){
|
||||
$ftp_info = Context::getFTPInfo();
|
||||
if(!$this->ftp_password) return new Object(-1,'msg_ftp_password_input');
|
||||
|
||||
require_once(_XE_PATH_.'libs/ftp.class.php');
|
||||
|
||||
if($ftp_info->ftp_host)
|
||||
{
|
||||
$ftp_host = $ftp_info->ftp_host;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ftp_host = "127.0.0.1";
|
||||
}
|
||||
|
||||
$oFtp = new ftp();
|
||||
if(!$oFtp->ftp_connect($ftp_host, $ftp_info->ftp_port)) return new Object(-1,'msg_ftp_not_connected');
|
||||
if(!$oFtp->ftp_login($ftp_info->ftp_user, $this->ftp_password)) {
|
||||
$oFtp->ftp_quit();
|
||||
return new Object(-1,'msg_ftp_invalid_auth_info');
|
||||
}
|
||||
|
||||
$_list = $oFtp->ftp_rawlist($ftp_info->ftp_root_path);
|
||||
|
||||
$target_dir = $ftp_info->ftp_root_path.$this->target_path;
|
||||
|
||||
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 = "./";
|
||||
$ftp_path = $ftp_info->ftp_root_path;
|
||||
|
||||
for($i=0;$i<count($path_list);$i++)
|
||||
{
|
||||
if($path_list=="") continue;
|
||||
$real_path .= $path_list[$i]."/";
|
||||
$ftp_path .= $path_list[$i]."/";
|
||||
if(!file_exists(FileHandler::getRealPath($real_path)))
|
||||
{
|
||||
$oFtp->ftp_mkdir($ftp_path);
|
||||
$oFtp->ftp_site("CHMOD 755 ".$path);
|
||||
}
|
||||
}
|
||||
$oFtp->ftp_put($target_dir .'/'. $file, FileHandler::getRealPath($this->download_path."/".$org_file));
|
||||
}
|
||||
$oFtp->ftp_quit();
|
||||
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -29,4 +29,5 @@
|
|||
$lang->path = "Path";
|
||||
$lang->cmd_download = "Download";
|
||||
$lang->view_installed_packages = "Installed Packages";
|
||||
$lang->msg_ftp_password_input = "Please input FTP password.";
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -29,4 +29,5 @@
|
|||
$lang->path = "インストールパス";
|
||||
$lang->cmd_download = "ダウンロード";
|
||||
$lang->view_installed_packages = "Installed Packages";
|
||||
$lang->msg_ftp_password_input = "Please input FTP password.";
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -29,4 +29,5 @@
|
|||
$lang->path = "설치경로";
|
||||
$lang->cmd_download = "다운로드";
|
||||
$lang->view_installed_packages = "설치된 패키지";
|
||||
$lang->msg_ftp_password_input = "FTP 비밀번호를 입력해주세요";
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -29,4 +29,5 @@
|
|||
$lang->path = "Đường dẫn";
|
||||
$lang->cmd_download = "Download";
|
||||
$lang->view_installed_packages = "Installed Packages";
|
||||
$lang->msg_ftp_password_input = "Please input FTP password.";
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -29,4 +29,5 @@
|
|||
$lang->path = "Path";
|
||||
$lang->cmd_download = "Download";
|
||||
$lang->view_installed_packages = "Installed Packages";
|
||||
$lang->msg_ftp_password_input = "Please input FTP password.";
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -29,4 +29,5 @@
|
|||
$lang->path = "路徑";
|
||||
$lang->cmd_download = "下載";
|
||||
$lang->view_installed_packages = "已安裝套裝軟體";
|
||||
$lang->msg_ftp_password_input = "Please input FTP password.";
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -12,13 +12,19 @@
|
|||
</dd>
|
||||
</dl>
|
||||
<!--@end-->
|
||||
|
||||
<!--@if(!$package->installed || $package->need_update)-->
|
||||
<!--@if($show_ftp_note)-->
|
||||
<p class="warning">{$lang->description_download}. (<a href="{getUrl('','module','admin','act','dispAdminConfig')}#ftpSetup">FTP Setup</a>) </p>
|
||||
<p>{$lang->path} : {$package->path}</p>
|
||||
<p><a href="http://download.xpressengine.com/?module=resourceapi&act=procResourceapiDownload&package_srl={$package->package_srl}" class="button large green strong"><span>{$lang->cmd_download}</span></a></p>
|
||||
<!--@else-->
|
||||
<p>{$lang->description_install}. </p>
|
||||
<p><!--@if(!$package->installed || $package->need_update)--><a href="#" onclick="doInstallPackage('{$package->package_srl}')" class="button large green strong"><span>{$lang->install}</span></a><!--@end--></p>
|
||||
<!--@if($need_password)-->
|
||||
<p><label for="ftp_password">FTP {$lang->password} ({$lang->about_ftp_password}):</label><input type="password" name="ftp_password" id="ftp_password" class="inputTypeText" /></p>
|
||||
<!--@end-->
|
||||
<p><a href="#" onclick="doInstallPackage('{$package->package_srl}')" class="button large green strong"><span>{$package->installed?$lang->update:$lang->install}</span></a></p>
|
||||
<!--@end-->
|
||||
<!--@end-->
|
||||
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,12 @@ function doUpdate() {
|
|||
function doInstallPackage(package_srl) {
|
||||
var params = new Array();
|
||||
params['package_srl'] = package_srl;
|
||||
var e = jQuery("#ftp_password").get(0)
|
||||
if(typeof(e) != "undefined")
|
||||
{
|
||||
params['ftp_password'] = e.value;
|
||||
}
|
||||
|
||||
exec_xml('autoinstall', 'procAutoinstallAdminPackageinstall', params, completeInstall);
|
||||
}
|
||||
|
||||
|
|
@ -20,6 +26,7 @@ function completeUpdateNoMsg(ret_obj) {
|
|||
|
||||
function completeInstall(ret_obj) {
|
||||
alert(ret_obj['message']);
|
||||
if(ret_obj['error'] != 0) return;
|
||||
var params = new Array();
|
||||
exec_xml('autoinstall', 'procAutoinstallAdminUpdateinfo', params, completeUpdateNoMsg);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue