From 6bf0bdc1460d699d9a8984914ecf7e7c0ae8c12c Mon Sep 17 00:00:00 2001 From: akasima Date: Wed, 19 Mar 2014 16:15:05 +0900 Subject: [PATCH] =?UTF-8?q?#519=20ftp=EC=84=A4=EC=A0=95=EC=97=90=EC=84=9C?= =?UTF-8?q?=20passive=20=EB=AA=A8=EB=93=9C=20=EC=82=AC=EC=9A=A9=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EB=AC=B8=EC=A0=9C=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/admin/admin.admin.model.php | 84 +++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/modules/admin/admin.admin.model.php b/modules/admin/admin.admin.model.php index d0c69a80d..1c863da8a 100644 --- a/modules/admin/admin.admin.model.php +++ b/modules/admin/admin.admin.model.php @@ -95,6 +95,81 @@ class adminAdminModel extends admin } } + function getFTPPath() + { + $ftp_info = Context::getRequestVars(); + + if(!$ftp_info->ftp_host) + { + $ftp_info->ftp_host = "127.0.0.1"; + } + + if(!$ftp_info->ftp_port || !is_numeric($ftp_info->ftp_port)) + { + $ftp_info->ftp_port = '22'; + } + + $connection = ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port); + if(!$connection) + { + return new Object(-1, sprintf(Context::getLang('msg_ftp_not_connected'), $ftp_host)); + } + + $login_result = @ftp_login($connection, $ftp_info->ftp_user, $ftp_info->ftp_password); + if(!$login_result) + { + ftp_close($connection); + return new Object(-1, 'msg_ftp_invalid_auth_info'); + } + + // create temp file + $pin = $_SERVER['REQUEST_TIME']; + FileHandler::writeFile('./files/cache/ftp_check', $pin); + + // create path candidate + $xe_path = _XE_PATH_; + $path_info = array_reverse(explode('/', _XE_PATH_)); + array_pop($path_info); // remove last '/' + $path_candidate = array(); + + $temp = ''; + foreach($path_info as $path) + { + $temp = '/' . $path . $temp; + $path_candidate[] = $temp; + } + + // try + foreach($path_candidate as $path) + { + // upload check file + if(!ftp_put($connection, $path . 'ftp_check.html', FileHandler::getRealPath('./files/cache/ftp_check'), FTP_BINARY)) + { + continue; + } + + // get check file + $result = FileHandler::getRemoteResource(getNotencodedFullUrl() . 'ftp_check.html'); + + // delete temp check file + ftp_delete($connection, $path . 'ftp_check.html'); + + // found + if($result == $pin) + { + $found_path = $path; + break; + } + } + + FileHandler::removeFile('./files/cache/ftp_check', $pin); + + if($found_path) + { + $this->add('found_path', $found_path); + } + } + /** * Find XE installed path on ftp */ @@ -130,6 +205,15 @@ class adminAdminModel extends admin return $this->getSFTPPath(); } + if($ftp_info->ftp_pasv == 'N') + { + if(function_exists('ftp_connect')) + { + return $this->getFTPPath(); + } + $ftp_info->ftp_pasv = "Y"; + } + $oFTP = new ftp(); if(!$oFTP->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port)) {