From 077ab4c714fcd4a47e5ad2de3ee08af654dc3ef3 Mon Sep 17 00:00:00 2001 From: Stanislas Dolcini Date: Tue, 2 Oct 2018 19:17:32 +0200 Subject: [PATCH] Move classes out of file, some cleanup --- code/web/public_php/login/class/CWwwLog.php | 37 ++++++ code/web/public_php/login/class/LoginCb.php | 54 +++++++++ code/web/public_php/login/r2_login.php | 125 +------------------- 3 files changed, 94 insertions(+), 122 deletions(-) create mode 100644 code/web/public_php/login/class/CWwwLog.php create mode 100644 code/web/public_php/login/class/LoginCb.php diff --git a/code/web/public_php/login/class/CWwwLog.php b/code/web/public_php/login/class/CWwwLog.php new file mode 100644 index 000000000..22e1593b9 --- /dev/null +++ b/code/web/public_php/login/class/CWwwLog.php @@ -0,0 +1,37 @@ +getSafeLogDir(); + if ($logPath !== false) + { + $fp = fopen($logPath.'/r2_login_'.date('Y-m-d').'.log', 'a'); + fwrite($fp, date('Y-m-d H:i:s').' ('.$_SERVER['REMOTE_ADDR'].':'.$_SERVER['REQUEST_URI']."): $str\n"); + fclose($fp); + } + } + } +?> diff --git a/code/web/public_php/login/class/LoginCb.php b/code/web/public_php/login/class/LoginCb.php new file mode 100644 index 000000000..98e742228 --- /dev/null +++ b/code/web/public_php/login/class/LoginCb.php @@ -0,0 +1,54 @@ + diff --git a/code/web/public_php/login/r2_login.php b/code/web/public_php/login/r2_login.php index b0a8a2d79..323e360ca 100755 --- a/code/web/public_php/login/r2_login.php +++ b/code/web/public_php/login/r2_login.php @@ -12,6 +12,8 @@ include_once('../tools/domain_info.php'); include_once('login_service_itf.php'); include_once('../ring/join_shard.php'); + include_once('./class/CWwwLog.php'); + include_once('./class/LoginCb.php'); function get_salt($password) @@ -34,99 +36,6 @@ return '0:'.call_user_func_array('errorMsg', $args); } - class LoginCb extends CLoginServiceWeb - { - // receive the login result sent back by the LS - function loginResult($userId, $cookie, $resultCode, $errorString) - { - global $RingWebHost, $RingWebHostPHP; - global $domainId; - - if ($resultCode == 0 && $cookie != "") - { - // gather the domain information (server version, patch urls and backup patch url - global $DBHost, $DBUserName, $DBPassword, $DBName, $AutoInsertInRing; - - $link = mysqli_connect($DBHost, $DBUserName, $DBPassword) or die (errorMsgBlock(3004, 'main', $DBHost, $DBUserName)); - mysqli_select_db ($link, $DBName) or die (errorMsgBlock(3005, 'main', $DBName, $DBHost, $DBUserName)); - $query = "SELECT * FROM domain WHERE domain_id=$domainId"; - $result = mysqli_query ($link, $query) or die (errorMsgBlock(3006, $query, 'main', $DBName, $DBHost, $DBUserName, mysqli_error($link))); - - if( mysqli_num_rows($result) != 1) - { - die(errorMsgBlock(3001, $domainId)); - } - $row = mysqli_fetch_array($result); - - // set the cookie - setcookie ( "ryzomId" , $cookie, 0, "/"); - $_COOKIE["ryzomId"] = $cookie; // make it available immediately - - // Auto-join an available mainland shard - global $FSHostLuaMode, $FSHostResultStr; - $FSHostLuaMode = false; - $res = joinMainland($userId, $domainId, $row["domain_name"]); - - if ($res) - { - // return the cookie to the user, il will then be used as an auth to browse the site and to connect to the shard - //echo "1#".$cookie."#http://".$RingWebHost."/ring/web_start.php\n"; -// use this line to use woopra stats -// echo "1#".$cookie."#".$FSHostResultStr."#http://".$RingWebHost."/ring/web_start.php#http://".$RingWebHostPHP."/ring/#1\n"; - echo "1#".$cookie."#".$FSHostResultStr."#http://".$RingWebHost."/ring/web_start.php#http://".$RingWebHostPHP."/ring/\n"; - // return the ring domain information - echo $row["patch_version"]."#".$row["backup_patch_url"]."#".$row["patch_urls"]; - } - else - { - global $JoinSessionResultCode, $JoinSessionResultMsg; - echo errorMsgBlock(BASE_TRANSLATED_RSM_ERROR_NUM + $JoinSessionResultCode, $JoinSessionResultCode, $JoinSessionResultMsg, $userId); - } - } - else - { - // empty cookie, this mean the user id can't be validated by the LS - echo errorMsgBlock(BASE_TRANSLATED_LS_ERROR_NUM + $resultCode, $resultCode, $errorString, $userId); - } - } - } - - class CWwwLog - { - //function CWwwLog() {} - - /* - * Return the log directory. Create it if it does not exist, or return false if creation failed. - */ - function getSafeLogDir() - { - // Examples: - // __FILE__ = r:\code\ryzom\www\login\config.php - // $_SERVER['PATH_TRANSLATED'] = 'r:/code/ryzom/www/login//r2_login.php' - // $_SERVER['SCRIPT_FILENAME'] = 'r:/code/ryzom/www/login//r2_login.php' - global $LogRelativePath; - $pathInfo = pathinfo(__FILE__); - $logPath = $pathInfo['dirname'].'/'.$LogRelativePath; - if (!is_dir($logPath)) - { - $res = mkdir($LogPath, 0700); - return $res ? $logPath : false; - } - return $logPath; - } - - function logStr($str) - { - $logPath = $this->getSafeLogDir(); - if ($logPath !== false) - { - $fp = fopen($logPath.'/r2_login_'.date('Y-m-d').'.log', 'a'); - fwrite($fp, date('Y-m-d H:i:s').' ('.$_SERVER['REMOTE_ADDR'].':'.$_SERVER['REQUEST_URI']."): $str\n"); - fclose($fp); - } - } - } - // Callback called on end of output buffering function ob_callback_r2login($buffer) { @@ -205,33 +114,6 @@ } } -// // check domain status -// if ($domainInfo['status'] == "ds_close") -// { -// // the domain is closed -// echo "0:Server is currently closed"; -// die; -// } -// else if ($domainInfo['status'] == "ds_dev" && strstr($priv, ":DEV:") == false) -// { -// // the domain is open to dev only -// echo "0:You are not allowed to connect now, retry later"; -// die; -// } -// else if ($domainInfo['status'] == "ds_restricted") -// { -// // check for one of the needed privilege -// if ( strstr($priv, ":DEV:") == false -// && strstr($priv, ":SGM:") == false -// && strstr($priv, ":GM:") == false -// && strstr($priv, ":EG:") == false) -// { -// // the domain is open to privileged user only -// echo "0:You are not allowed to connect now, retry later"; -// die; -// } -// } - // store the web host for this domain global $RingWebHost, $RingWebHostPHP; $RingWebHost = $domainInfo['web_host']; @@ -243,11 +125,9 @@ $login = new LoginCb; $res = ""; $login->connect($LSaddr[0], $LSaddr[1], $res); -// $lsProxy = new CLoginServiceWebProxy; $login->login($id, $_SERVER["REMOTE_ADDR"], $domainId); // wait for the return message -// $lsSkel = new CLoginServiceWebSkel; if (!$login->waitCallback()) { die(errorMsgBlock(3003)); @@ -509,3 +389,4 @@ mysqli_close($link); } +?>