mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-29 07:12:15 +09:00
#18430274 : support SFTP
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@6948 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
c4fe618378
commit
51e758fd39
7 changed files with 131 additions and 26 deletions
|
|
@ -2,17 +2,52 @@
|
|||
|
||||
class adminAdminModel extends admin
|
||||
{
|
||||
var $pwd;
|
||||
|
||||
function getSFTPList()
|
||||
{
|
||||
$ftp_info = Context::getFTPInfo();
|
||||
$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);
|
||||
$curpwd = "ssh2.sftp://$sftp".$this->pwd;
|
||||
$dh = opendir($curpwd);
|
||||
$list = array();
|
||||
while(($file = readdir($dh)) !== false) {
|
||||
if(is_dir($curpwd.$file))
|
||||
{
|
||||
$file .= "/";
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$list[] = $file;
|
||||
}
|
||||
closedir($dh);
|
||||
$this->add('list', $list);
|
||||
}
|
||||
|
||||
function getAdminFTPList()
|
||||
{
|
||||
set_time_limit(5);
|
||||
require_once(_XE_PATH_.'libs/ftp.class.php');
|
||||
$ftp_info = Context::getFTPInfo();
|
||||
$pwd = Context::get('pwd');
|
||||
$this->pwd = Context::get('pwd');
|
||||
|
||||
if($ftp_info->sftp == 'Y')
|
||||
{
|
||||
return $this->getSFTPList();
|
||||
}
|
||||
|
||||
$oFtp = new ftp();
|
||||
if($oFtp->ftp_connect('localhost', $ftp_info->ftp_port)){
|
||||
if($oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) {
|
||||
$_list = $oFtp->ftp_rawlist($pwd);
|
||||
$_list = $oFtp->ftp_rawlist($this->pwd);
|
||||
$oFtp->ftp_quit();
|
||||
}
|
||||
}
|
||||
|
|
@ -21,7 +56,7 @@
|
|||
$oFtp = new ftp();
|
||||
if($oFtp->ftp_connect($_SERVER['SERVER_NAME'], $ftp_info->ftp_port)){
|
||||
if($oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) {
|
||||
$_list = $oFtp->ftp_rawlist($pwd);
|
||||
$_list = $oFtp->ftp_rawlist($this->pwd);
|
||||
$oFtp->ftp_quit();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -254,7 +254,7 @@
|
|||
function dispAdminConfig() {
|
||||
$db_info = Context::getDBInfo();
|
||||
|
||||
Context::set('sftp_support', function_exists(ftp_ssl_connect));
|
||||
Context::set('sftp_support', function_exists(ssh2_sftp));
|
||||
|
||||
Context::set('selected_lang', $db_info->lang_type);
|
||||
|
||||
|
|
@ -263,15 +263,25 @@
|
|||
Context::set('langs', Context::loadLangSupported());
|
||||
|
||||
Context::set('lang_selected', Context::loadLangSelected());
|
||||
|
||||
Context::set('ftp_info', Context::getFTPInfo());
|
||||
|
||||
$ftp_info = Context::getFTPInfo();
|
||||
Context::set('ftp_info', $ftp_info);
|
||||
|
||||
$site_args->site_srl = 0;
|
||||
$output = executeQuery('module.getSiteInfo', $site_args);
|
||||
Context::set('start_module', $output->data);
|
||||
|
||||
$pwd = Context::get('pwd');
|
||||
if(!$pwd) $pwd = '/';
|
||||
if(!$pwd) {
|
||||
if($ftp_info->sftp == 'Y')
|
||||
{
|
||||
$pwd = _XE_PATH_;
|
||||
}
|
||||
else
|
||||
{
|
||||
$pwd = '/';
|
||||
}
|
||||
}
|
||||
Context::set('pwd',$pwd);
|
||||
Context::set('layout','none');
|
||||
$this->setTemplateFile('config');
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@
|
|||
<td><input id="textfield22" type="password" name="ftp_password" value="{$ftp_info->ftp_password}" class="inputTypeText" /></td>
|
||||
<td><input id="textfield24" type="text" name="ftp_port" value="{$ftp_info->ftp_port}" class="inputTypeText" /></td>
|
||||
<!--@if($sftp_support)-->
|
||||
<td><input type="checkbox" id="checkbox25" name="sftp" value="Y" /></td>
|
||||
<td><input type="checkbox" id="checkbox25" name="sftp" value="Y" <!--@if($ftp_info->sftp=="Y")-->checked="checked"<!--@end--> /></td>
|
||||
<!--@end-->
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
@ -163,6 +163,7 @@
|
|||
<input type="hidden" name="ftp_user" value="{$ftp_info->ftp_user}" />
|
||||
<input type="hidden" name="ftp_password" value="{$ftp_info->ftp_password}" />
|
||||
<input type="hidden" name="ftp_port" value="{$ftp_info->ftp_port}" />
|
||||
<input type="hidden" name="sftp" value="{$ftp_info->sftp}" />
|
||||
|
||||
<table cellspacing="0" class="rowTable">
|
||||
<tr>
|
||||
|
|
|
|||
|
|
@ -14,11 +14,6 @@
|
|||
var $url;
|
||||
var $download_path;
|
||||
|
||||
function ModuleInstaller(&$package)
|
||||
{
|
||||
$this->package =& $package;
|
||||
}
|
||||
|
||||
function _download()
|
||||
{
|
||||
if($this->package->path == ".")
|
||||
|
|
@ -70,6 +65,53 @@
|
|||
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');
|
||||
|
|
@ -125,7 +167,6 @@
|
|||
|
||||
return new Object();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class autoinstallAdminController extends autoinstall {
|
||||
|
|
@ -235,10 +276,18 @@
|
|||
$package_srls = Context::get('package_srl');
|
||||
$oModel =& getModel('autoinstall');
|
||||
$packages = explode(',', $package_srls);
|
||||
$ftp_info = Context::getFTPInfo();
|
||||
foreach($packages as $package_srl)
|
||||
{
|
||||
$package = $oModel->getPackage($package_srl);
|
||||
$oModuleInstaller = new ModuleInstaller($package);
|
||||
if($ftp_info->sftp && $ftp_info->sftp == 'Y')
|
||||
{
|
||||
$oModuleInstaller = new SFTPModuleInstaller($package);
|
||||
}
|
||||
else
|
||||
{
|
||||
$oModuleInstaller = new FTPModuleInstaller($package);
|
||||
}
|
||||
$oModuleInstaller->install();
|
||||
}
|
||||
$this->setMessage('success_installed');
|
||||
|
|
|
|||
|
|
@ -109,7 +109,6 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
debugPrint($package);
|
||||
}
|
||||
$installedPackage = $oModel->getInstalledPackage($package_srl);
|
||||
if($installedPackage) {
|
||||
|
|
|
|||
|
|
@ -120,7 +120,6 @@
|
|||
**/
|
||||
function procInstallAdminSaveFTPInfo() {
|
||||
$ftp_info = Context::gets('ftp_user','ftp_password','ftp_port','ftp_root_path','sftp');
|
||||
debugPrint($ftp_info);
|
||||
$ftp_info->ftp_port = (int)$ftp_info->ftp_port;
|
||||
if(!$ftp_info->ftp_port) $ftp_info->ftp_port = 21;
|
||||
if(!$ftp_info->sftp) $ftp_info->sftp = 'N';
|
||||
|
|
|
|||
|
|
@ -117,22 +117,34 @@
|
|||
}
|
||||
|
||||
function procInstallCheckFtp() {
|
||||
$ftp_info = Context::gets('ftp_user','ftp_password','ftp_port');
|
||||
$ftp_info = Context::gets('ftp_user','ftp_password','ftp_port','sftp');
|
||||
$ftp_info->ftp_port = (int)$ftp_info->ftp_port;
|
||||
if(!$ftp_info->ftp_port) $ftp_info->ftp_port = 21;
|
||||
if(!$ftp_info->sftp) $ftp_info->sftp = 'N';
|
||||
|
||||
if(!$ftp_info->ftp_user || !$ftp_info->ftp_password) return new Object(-1,'msg_safe_mode_ftp_needed');
|
||||
|
||||
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');
|
||||
if($ftp_info->sftp == 'Y')
|
||||
{
|
||||
$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');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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');
|
||||
|
||||
$oFtp->ftp_quit();
|
||||
if(!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) {
|
||||
$oFtp->ftp_quit();
|
||||
return new Object(-1,'msg_ftp_invalid_auth_info');
|
||||
}
|
||||
|
||||
$oFtp->ftp_quit();
|
||||
}
|
||||
|
||||
$this->setMessage('msg_ftp_connect_success');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue