function procInstallAdminSaveFTPInfo() { $ftp_info = Context::getFTPInfo(); $ftp_info->ftp_user = Context::get('ftp_user'); $ftp_info->ftp_port = Context::get('ftp_port'); $ftp_info->ftp_host = Context::get('ftp_host'); $ftp_info->ftp_pasv = Context::get('ftp_pasv'); if (!$ftp_info->ftp_pasv) { $ftp_info->ftp_pasv = "N"; } $ftp_info->sftp = Context::get('sftp'); $ftp_root_path = Context::get('ftp_root_path'); if (substr($ftp_root_path, strlen($ftp_root_path) - 1) == "/") { $ftp_info->ftp_root_path = $ftp_root_path; } else { $ftp_info->ftp_root_path = $ftp_root_path . '/'; } if (ini_get('safe_mode')) { $ftp_info->ftp_password = Context::get('ftp_password'); } $buff = '<?php if(!defined("__ZBXE__")) exit();' . "\n"; foreach ($ftp_info as $key => $val) { if (!$val) { continue; } if (preg_match('/(<\\?|<\\?php|\\?>)/xsm', preg_replace('/\\s/', '', $val))) { continue; } $buff .= sprintf("\$ftp_info->%s = '%s';\n", $key, str_replace("'", "\\'", $val)); } $buff .= "?>"; $config_file = Context::getFTPConfigFile(); FileHandler::WriteFile($config_file, $buff); if ($_SESSION['ftp_password']) { unset($_SESSION['ftp_password']); } $this->setMessage('success_updated'); $this->setRedirectUrl(Context::get('error_return_url')); }
/** * @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)); }
function procInstallAdminSaveFTPInfo() { $ftp_info = Context::getFTPInfo(); $ftp_info->ftp_user = Context::get('ftp_user'); $ftp_info->ftp_port = Context::get('ftp_port'); $ftp_info->ftp_host = Context::get('ftp_host'); $ftp_info->ftp_pasv = Context::get('ftp_pasv'); if (!$ftp_info->ftp_pasv) { $ftp_info->ftp_pasv = "N"; } $ftp_info->sftp = Context::get('sftp'); $ftp_root_path = Context::get('ftp_root_path'); if (substr($ftp_root_path, strlen($ftp_root_path) - 1) == "/") { $ftp_info->ftp_root_path = $ftp_root_path; } else { $ftp_info->ftp_root_path = $ftp_root_path . '/'; } if (ini_get('safe_mode')) { $ftp_info->ftp_password = Context::get('ftp_password'); } $buff = '<?php if(!defined("__XE__")) exit();' . "\n\$ftp_info = new stdClass;\n"; foreach ($ftp_info as $key => $val) { if (!$val) { continue; } if (preg_match('/(<\\?|<\\?php|\\?>|fputs|fopen|fwrite|fgets|fread|file_get_contents|file_put_contents|exec|proc_open|popen|passthru|show_source|phpinfo|system|\\/\\*|\\*\\/|chr\\()/xsm', preg_replace('/\\s/', '', $val))) { continue; } $buff .= sprintf("\$ftp_info->%s = '%s';\n", $key, str_replace("'", "\\'", $val)); } $buff .= "?>"; $config_file = Context::getFTPConfigFile(); FileHandler::WriteFile($config_file, $buff); if ($_SESSION['ftp_password']) { unset($_SESSION['ftp_password']); } $this->setMessage('success_updated'); $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAdminConfigFtp'); $this->setRedirectUrl($returnUrl); }
/** * @brief FTP 정보 등록 **/ function procInstallAdminSaveFTPInfo() { $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 .= "?>"; $config_file = Context::getFTPConfigFile(); FileHandler::WriteFile($config_file, $buff); $this->setMessage('success_updated'); }
/** * Check if FTP info is registered * * @return bool True: FTP information is registered, False: otherwise */ function isFTPRegisted() { $ftp_config_file = Context::getFTPConfigFile(); if (file_exists($ftp_config_file)) { return true; } return false; }