Move classes out of file, some cleanup

This commit is contained in:
Stanislas Dolcini 2018-10-02 19:17:32 +02:00
parent cfb5b71728
commit 077ab4c714
3 changed files with 94 additions and 122 deletions

View file

@ -0,0 +1,37 @@
<?php
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);
}
}
}
?>

View file

@ -0,0 +1,54 @@
<?php
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)
{
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);
}
}
}
?>

View file

@ -12,6 +12,8 @@
include_once('../tools/domain_info.php'); include_once('../tools/domain_info.php');
include_once('login_service_itf.php'); include_once('login_service_itf.php');
include_once('../ring/join_shard.php'); include_once('../ring/join_shard.php');
include_once('./class/CWwwLog.php');
include_once('./class/LoginCb.php');
function get_salt($password) function get_salt($password)
@ -34,99 +36,6 @@
return '0:'.call_user_func_array('errorMsg', $args); 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 // Callback called on end of output buffering
function ob_callback_r2login($buffer) 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 // store the web host for this domain
global $RingWebHost, $RingWebHostPHP; global $RingWebHost, $RingWebHostPHP;
$RingWebHost = $domainInfo['web_host']; $RingWebHost = $domainInfo['web_host'];
@ -243,11 +125,9 @@
$login = new LoginCb; $login = new LoginCb;
$res = ""; $res = "";
$login->connect($LSaddr[0], $LSaddr[1], $res); $login->connect($LSaddr[0], $LSaddr[1], $res);
// $lsProxy = new CLoginServiceWebProxy;
$login->login($id, $_SERVER["REMOTE_ADDR"], $domainId); $login->login($id, $_SERVER["REMOTE_ADDR"], $domainId);
// wait for the return message // wait for the return message
// $lsSkel = new CLoginServiceWebSkel;
if (!$login->waitCallback()) if (!$login->waitCallback())
{ {
die(errorMsgBlock(3003)); die(errorMsgBlock(3003));
@ -509,3 +389,4 @@
mysqli_close($link); mysqli_close($link);
} }
?>