/** * @brief FTP 정보 등록 **/ function procInstallFTP() { if (Context::isInstalled()) { return new Object(-1, 'msg_already_installed'); } $ftp_info = Context::gets('ftp_user', 'ftp_password', 'ftp_port'); $ftp_info->ftp_port = (int) $ftp_info->ftp_port; if (!$ftp_info->ftp_port) { $ftp_info->ftp_port = 21; } $buff = '<?php if(!defined("__ZBXE__")) exit();' . "\n"; foreach ($ftp_info as $key => $val) { $buff .= sprintf("\$ftp_info->%s = '%s';\n", $key, str_replace("'", "\\'", $val)); } $buff .= "?>"; // safe_mode 일 경우 if (ini_get('safe_mode')) { 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 (!is_dir(_XE_PATH_ . 'files') && !$oFtp->ftp_mkdir(_XE_PATH_ . 'files')) { $oFtp->ftp_quit(); return new Object(-1, 'msg_ftp_mkdir_fail'); } if (!$oFtp->ftp_site("CHMOD 777 " . _XE_PATH_ . 'files')) { $oFtp->ftp_quit(); return new Object(-1, 'msg_ftp_chmod_fail'); } if (!is_dir(_XE_PATH_ . 'files/config') && !$oFtp->ftp_mkdir(_XE_PATH_ . 'files/config')) { $oFtp->ftp_quit(); return new Object(-1, 'msg_ftp_mkdir_fail'); } if (!$oFtp->ftp_site("CHMOD 777 " . _XE_PATH_ . 'files/config')) { $oFtp->ftp_quit(); return new Object(-1, 'msg_ftp_chmod_fail'); } $oFtp->ftp_quit(); } $config_file = Context::getFTPConfigFile(); FileHandler::WriteFile($config_file, $buff); }
/** * @brief Set FTP Information */ function procInstallFTP() { if (Context::isInstalled()) { return new Object(-1, 'msg_already_installed'); } $ftp_info = Context::gets('ftp_host', 'ftp_user', 'ftp_password', 'ftp_port', 'ftp_root_path'); $ftp_info->ftp_port = (int) $ftp_info->ftp_port; if (!$ftp_info->ftp_port) { $ftp_info->ftp_port = 21; } if (!$ftp_info->ftp_host) { $ftp_info->ftp_host = '127.0.0.1'; } if (!$ftp_info->ftp_root_path) { $ftp_info->ftp_root_path = '/'; } $buff = array('<?php if(!defined("__XE__")) exit();'); $buff[] = "\$ftp_info = new stdClass();"; foreach ($ftp_info as $key => $val) { $buff[] = sprintf("\$ftp_info->%s='%s';", $key, str_replace("'", "\\'", $val)); } // If safe_mode if (ini_get('safe_mode')) { 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($ftp_info->ftp_host, $ftp_info->ftp_port)) { return new Object(-1, sprintf(Context::getLang('msg_ftp_not_connected'), $ftp_info->ftp_host)); } 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 (!is_dir(_XE_PATH_ . 'files') && !$oFtp->ftp_mkdir($ftp_info->ftp_root_path . 'files')) { $oFtp->ftp_quit(); return new Object(-1, 'msg_ftp_mkdir_fail'); } if (!$oFtp->ftp_site("CHMOD 777 " . $ftp_info->ftp_root_path . 'files')) { $oFtp->ftp_quit(); return new Object(-1, 'msg_ftp_chmod_fail'); } if (!is_dir(_XE_PATH_ . 'files/config') && !$oFtp->ftp_mkdir($ftp_info->ftp_root_path . 'files/config')) { $oFtp->ftp_quit(); return new Object(-1, 'msg_ftp_mkdir_fail'); } if (!$oFtp->ftp_site("CHMOD 777 " . $ftp_info->ftp_root_path . 'files/config')) { $oFtp->ftp_quit(); return new Object(-1, 'msg_ftp_chmod_fail'); } $oFtp->ftp_quit(); } FileHandler::WriteFile(Context::getFTPConfigFile(), join(PHP_EOL, $buff)); }
/** * Creates a directory * * This function creates directories recursively, which means that if ancestors of the target directory does not exist, they will be created too. * * @param string $path_string Path of target directory * @return bool TRUE if success. It might return nothing when ftp is used and connection to the ftp address failed. */ public static function makeDir($path_string) { if (self::exists($path_string) !== FALSE) { return TRUE; } if (!ini_get('safe_mode')) { @mkdir($path_string, 0755, TRUE); @chmod($path_string, 0755); } else { static $oFtp = NULL; $ftp_info = Context::getFTPInfo(); if ($oFtp == NULL) { if (!Context::isFTPRegisted()) { return; } $oFtp = new ftp(); if (!$ftp_info->ftp_host) { $ftp_info->ftp_host = "127.0.0.1"; } if (!$ftp_info->ftp_port) { $ftp_info->ftp_port = 21; } if (!$oFtp->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port)) { return; } if (!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) { $oFtp->ftp_quit(); return; } } if (!($ftp_path = $ftp_info->ftp_root_path)) { $ftp_path = DIRECTORY_SEPARATOR; } $path_string = str_replace(_XE_PATH_, '', $path_string); $path_list = explode(DIRECTORY_SEPARATOR, $path_string); $path = _XE_PATH_; for ($i = 0, $c = count($path_list); $i < $c; $i++) { if (!$path_list[$i]) { continue; } $path .= $path_list[$i] . DIRECTORY_SEPARATOR; $ftp_path .= $path_list[$i] . DIRECTORY_SEPARATOR; if (!is_dir($path)) { $oFtp->ftp_mkdir($ftp_path); $oFtp->ftp_site("CHMOD 777 " . $ftp_path); } } } return is_dir($path_string); }
/** * @brief 디렉토리 생성 * * 주어진 경로를 단계별로 접근하여 recursive하게 디렉토리 생성 **/ function makeDir($path_string) { static $oFtp = null; // safe_mode 일 경우 ftp 정보를 이용해서 디렉토리 생성 if (ini_get('safe_mode') && $oFtp == null) { if (!Context::isFTPRegisted()) { return; } require_once _XE_PATH_ . 'libs/ftp.class.php'; $ftp_info = Context::getFTPInfo(); $oFtp = new ftp(); if (!$oFtp->ftp_connect('localhost')) { return; } if (!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) { $oFtp->ftp_quit(); return; } } $path_string = str_replace(_XE_PATH_, '', $path_string); $path_list = explode('/', $path_string); $path = _XE_PATH_; for ($i = 0; $i < count($path_list); $i++) { if (!$path_list[$i]) { continue; } $path .= $path_list[$i] . '/'; if (!is_dir($path)) { if (ini_get('safe_mode')) { $oFtp->ftp_mkdir($path); $oFtp->ftp_site("CHMOD 777 " . $path); } else { @mkdir($path, 0755); @chmod($path, 0755); } } } return is_dir($path_string); }
/** * Creates a directory * * This function creates directories recursively, which means that if ancestors of the target directory does not exist, they will be created too. * * @param string $path_string Path of target directory * @return bool true if success. It might return nothing when ftp is used and connection to the ftp address failed. **/ function makeDir($path_string) { static $oFtp = null; // if safe_mode is on, use FTP if (ini_get('safe_mode')) { $ftp_info = Context::getFTPInfo(); if ($oFtp == null) { if (!Context::isFTPRegisted()) { return; } require_once _XE_PATH_ . 'libs/ftp.class.php'; $oFtp = new ftp(); if (!$ftp_info->ftp_host) { $ftp_info->ftp_host = "127.0.0.1"; } if (!$ftp_info->ftp_port) { $ftp_info->ftp_port = 21; } if (!$oFtp->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port)) { return; } if (!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) { $oFtp->ftp_quit(); return; } } $ftp_path = $ftp_info->ftp_root_path; if (!$ftp_path) { $ftp_path = "/"; } } $path_string = str_replace(_XE_PATH_, '', $path_string); $path_list = explode('/', $path_string); $path = _XE_PATH_; for ($i = 0; $i < count($path_list); $i++) { if (!$path_list[$i]) { continue; } $path .= $path_list[$i] . '/'; $ftp_path .= $path_list[$i] . '/'; if (!is_dir($path)) { if (ini_get('safe_mode')) { $oFtp->ftp_mkdir($ftp_path); $oFtp->ftp_site("CHMOD 777 " . $ftp_path); } else { @mkdir($path, 0755); @chmod($path, 0755); } } } return is_dir($path_string); }