diff --git a/common/src/Util.cs b/common/src/Util.cs new file mode 100644 index 0000000000..1efa4715aa --- /dev/null +++ b/common/src/Util.cs @@ -0,0 +1,87 @@ +/* +Copyright (c) OpenSim project, http://osgrid.org/ + +* Copyright (c) , +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +using System; +using System.Collections.Generic; +using System.Threading; +using libsecondlife; +using libsecondlife.Packets; + +namespace OpenGridServices +{ + /// + /// + /// + public class Util + { + public static ulong UIntsToLong(uint X, uint Y) + { + return Helpers.UIntsToLong(X,Y); + } + public Util() + { + + } + } + + public class QueItem { + public QueItem() + { + } + + public Packet Packet; + public bool Incoming; + } + + + public class BlockingQueue< T > { + private Queue< T > _queue = new Queue< T >(); + private object _queueSync = new object(); + + public void Enqueue(T value) + { + lock(_queueSync) + { + _queue.Enqueue(value); + Monitor.Pulse(_queueSync); + } + } + + public T Dequeue() + { + lock(_queueSync) + { + if( _queue.Count < 1) + Monitor.Wait(_queueSync); + + return _queue.Dequeue(); + } + } + } +} diff --git a/gridserver/default.build b/gridserver/default.build index 5112148388..b113b83d6e 100644 --- a/gridserver/default.build +++ b/gridserver/default.build @@ -24,7 +24,7 @@ - + @@ -50,10 +50,8 @@ - - - - + + diff --git a/gridserver/gridserver_config.inc.php b/gridserver/gridserver_config.inc.php deleted file mode 100644 index 98ebed360e..0000000000 --- a/gridserver/gridserver_config.inc.php +++ /dev/null @@ -1,14 +0,0 @@ - diff --git a/gridserver/index.php b/gridserver/index.php deleted file mode 100644 index f7754c687b..0000000000 --- a/gridserver/index.php +++ /dev/null @@ -1,176 +0,0 @@ - 'I can play the bad key trick too you know', - 'login' => 'false' - ); - } - - // if we get to here, the key is valid, give that login server what it wants! - - $link = mysql_connect($dbhost,$dbuser,$dbpasswd) - OR die("Unable to connect to database"); - - mysql_select_db($dbname) - or die("Unable to select database"); - - $region_handle = $args['region_handle']; - $query = "SELECT * FROM region_profiles WHERE region_handle='$region_handle'"; - $result = mysql_query($query); - - return mysql_fetch_assoc($result); -} - -function get_session_info($args) { - global $dbhost,$dbuser,$dbpasswd,$dbname; - global $sim_sendkey, $sim_recvkey; - - // authkey, session-id, agent-id - - // First see who's talking to us, if key is invalid then send an invalid one back and nothing more - if($args[0]!=$sim_recvkey) { - return Array( - 'authkey' => "I can play the bad key trick too you know" - ); - } - - $link = mysql_connect($dbhost,$dbuser,$dbpasswd) - OR die("Unable to connect to database"); - - mysql_select_db($dbname) - or die("Unable to select database"); - - $session_id = $args[1]; - $agent_id = $args[2]; - - $query = "SELECT * FROM sessions WHERE session_id = '$session_id' AND agent_id='$agent_id' AND session_active=1"; - $result = mysql_query($query); - if(mysql_num_rows($result)>0) { - $info=mysql_fetch_assoc($result); - $circuit_code = $info['circuit_code']; - $secure_session_id=$info['secure_session_id']; - - $query = "SELECT * FROM local_user_profiles WHERE userprofile_LLUUID='$agent_id'"; - $result=mysql_query($query); - $userinfo=mysql_fetch_assoc($result); - $firstname=$userinfo['profile_firstname']; - $lastname=$userinfo['profile_lastname']; - $agent_id=$userinfo['userprofile_LLUUID']; - return Array( - 'authkey' => $sim_sendkey, - 'circuit_code' => $circuit_code, - 'agent_id' => $agent_id, - 'session_id' => $session_id, - 'secure_session_id' => $secure_session_id, - 'firstname' => $firstname, - 'lastname' => $lastname - ); - } -} - -function check_loggedin($args) { - global $dbhost,$dbuser,$dbpasswd,$dbname; - global $userserver_sendkey, $userserver_recvkey; - - // First see who's talking to us, if key is invalid then send an invalid one back and nothing more - if($args['authkey']!=$userserver_recvkey) { - return Array( - 'authkey' => "I can play the bad key trick too you know" - ); - } - - // if we get to here, the key is valid, give that login server what it wants! - - $link = mysql_connect($dbhost,$dbuser,$dbpasswd) - OR die("Unable to connect to database"); - - mysql_select_db($dbname) - or die("Unable to select database"); - - $userprofile_LLUUID = $args['userprofile_LLUUID']; - $query = "SELECT * FROM sessions WHERE agent_id='$userprofile_LLUUID' AND session_active=1"; - $result = mysql_query($query); - - if(mysql_num_rows($result)>1) { - return Array( - 'authkey' => $userserver_sendkey, - 'logged_in' => 1 - ); - } else { - return Array( - 'authkey' => $userserver_sendkey, - 'logged_in' => 0 - ); - } -} - -function create_session($args) { - global $dbhost,$dbuser,$dbpasswd,$dbname; - global $userserver_sendkey, $userserver_recvkey; - - // First see who's talking to us, if key is invalid then send an invalid one back and nothing more - if($args['authkey']!=$userserver_recvkey) { - return Array( - 'authkey' => "I can play the bad key trick too you know" - ); - } - - // if we get to here, the key is valid, give that login server what it wants! - - $link = mysql_connect($dbhost,$dbuser,$dbpasswd) - OR die("Unable to connect to database"); - - mysql_select_db($dbname) - or die("Unable to select database"); - - // yes, secure_sessionid should be different, i know... - $query = "SELECT value FROM Grid_settings WHERE setting='highest_LLUUID'"; - $result = mysql_query($query); - $row = mysql_fetch_array($result); - $highest_LLUUID = $row['value']; - $newsession_id=inc_lluuid($highest_LLUUID); - $secure_session_id=inc_lluuid($newsession_id); - - $query="UPDATE Grid_settings SET value='$secure_session_id' WHERE setting='highest_LLUUID' LIMIT 1"; - $result=mysql_query($query); - - $userprofile_LLUUID=$args['userprofile_LLUUID']; - $current_location=$args['current_location']; - $remote_ip=$args['remote_ip']; - $query="INSERT INTO sessions(session_id,secure_session_id,agent_id,session_start,session_active,current_location,remote_ip) VALUES('$newsession_id','$secure_session_id','$userprofile_LLUUID',NOW(),1,'$current_location','$remote_ip')"; - $result=mysql_query($query); - if(!isset($result)) { - die(); - } - return Array( - 'authkey' => $userserver_sendkey, - 'session_id' => $newsession_id, - 'secure_session_id' => $secure_session_id - ); -} - -$server=new IXR_Server( - Array( - 'check_session_loggedin' => 'check_loggedin', - 'create_session' => 'create_session', - 'get_sim_info' => 'get_sim_info', - 'get_session_info' => 'get_session_info' - ) -); - -?> \ No newline at end of file diff --git a/gridserver/src/GridHttp.cs b/gridserver/src/GridHttp.cs index 623e9bf76a..bbaf2c83c3 100644 --- a/gridserver/src/GridHttp.cs +++ b/gridserver/src/GridHttp.cs @@ -29,7 +29,9 @@ Copyright (c) OpenGrid project, http://osgrid.org/ using System; using System.Text; +using Nwc.XmlRpc; using System.Threading; +using System.Text.RegularExpressions; using System.Net; using System.IO; using System.Collections; @@ -44,7 +46,7 @@ namespace OpenGridServices public HttpListener Listener; public GridHTTPServer() { - ServerConsole.MainConsole.Instance.WriteLine("Starting up HTTP Server"); + ServerConsole.MainConsole.Instance.WriteLine("Starting up HTTP Server"); HTTPD = new Thread(new ThreadStart(StartHTTP)); HTTPD.Start(); } @@ -53,39 +55,77 @@ namespace OpenGridServices ServerConsole.MainConsole.Instance.WriteLine("GridHttp.cs:StartHTTP() - Spawned main thread OK"); Listener = new HttpListener(); - Listener.Prefixes.Add("http://+:8080/gridserver/"); + Listener.Prefixes.Add("http://+:8001/gridserver/"); Listener.Start(); HttpListenerContext context; while(true) { context = Listener.GetContext(); - new Thread( new ThreadStart( new HttpWorker(context).Startup ) ).Start(); + ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context); } } - } + static string ParseXMLRPC(string requestBody) { + XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); + + Hashtable requestData = (Hashtable)request.Params[0]; + switch(request.MethodName) { + case "get_simulator_info": + + break; + } - public class HttpWorker { - public HttpListenerContext context; - - public HttpWorker(HttpListenerContext context) { - this.context=context; + return ""; } - - public string HandleRequest(HttpListenerRequest request) { - ServerConsole.MainConsole.Instance.WriteLine(request.Url.ToString()); + + static string ParseREST(string requestBody, string requestURL) { return ""; } - public void Startup() { - HttpListenerRequest request = context.Request; - HttpListenerResponse response = context.Response; - string responseString=HandleRequest(request); - byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); - System.IO.Stream output = response.OutputStream; + + static void HandleRequest(Object stateinfo) { + HttpListenerContext context=(HttpListenerContext)stateinfo; + + HttpListenerRequest request = context.Request; + HttpListenerResponse response = context.Response; + + response.KeepAlive=false; + response.SendChunked=false; + + System.IO.Stream body = request.InputStream; + System.Text.Encoding encoding = request.ContentEncoding; + System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding); + + string requestBody = reader.ReadToEnd(); + body.Close(); + reader.Close(); + + string responseString=""; + switch(request.ContentType) { + case "text/xml": + // must be XML-RPC, so pass to the XML-RPC parser + + responseString=ParseXMLRPC(requestBody); + response.AddHeader("Content-type","text/xml"); + break; + + case null: + // must be REST or invalid crap, so pass to the REST parser + responseString=ParseREST(request.Url.OriginalString,requestBody); + break; + } + + + byte[] buffer = System.Text.Encoding.Unicode.GetBytes(responseString); + System.IO.Stream output = response.OutputStream; + response.SendChunked=false; + encoding = System.Text.Encoding.UTF8; + response.ContentEncoding = encoding; + response.ContentLength64=buffer.Length; output.Write(buffer,0,buffer.Length); - output.Close(); + output.Close(); } } + } diff --git a/gridserver/src/Main.cs b/gridserver/src/Main.cs index 3d3efa9010..2553b00ee9 100644 --- a/gridserver/src/Main.cs +++ b/gridserver/src/Main.cs @@ -43,12 +43,13 @@ namespace OpenGridServices public string GridOwner; public string DefaultStartupMsg; public string DefaultAssetServer; + public string AssetSendKey; + public string AssetRecvKey; public string DefaultUserServer; - + public string UserSendKey; + public string UserRecvKey; + public GridHTTPServer _httpd; - public UserProfileManager _profilemanager; - public UserProfile GridGod; - public LLUUID HighestUUID; [STAThread] public static void Main( string[] args ) @@ -70,40 +71,17 @@ namespace OpenGridServices public void Startup() { ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please press enter to retain default settings"); - this.GridOwner=ServerConsole.MainConsole.Instance.CmdPrompt("Grid owner [OGS development team] :","OGS development team"); - this.DefaultStartupMsg=ServerConsole.MainConsole.Instance.CmdPrompt("Default startup message for clients [Welcome to OGS!] :","Welcome to OGS!"); - this.DefaultAssetServer=ServerConsole.MainConsole.Instance.CmdPrompt("Default asset server [no default] :"); - this.DefaultUserServer=ServerConsole.MainConsole.Instance.CmdPrompt("Default user server [no default] :"); - - ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Creating user profile manager"); - _profilemanager = new UserProfileManager(); - _profilemanager.InitUserProfiles(); - - ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Setting up LLUUID management"); - HighestUUID = LLUUID.Random(); - - string tempfirstname; - string templastname; - string tempMD5Passwd; + this.GridOwner=ServerConsole.MainConsole.Instance.CmdPrompt("Grid owner [OGS development team]: ","OGS development team"); + this.DefaultStartupMsg=ServerConsole.MainConsole.Instance.CmdPrompt("Default startup message for clients [Welcome to OGS!]: ","Welcome to OGS!"); - ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please configure the grid god user:"); - tempfirstname=ServerConsole.MainConsole.Instance.CmdPrompt("First name: "); - templastname=ServerConsole.MainConsole.Instance.CmdPrompt("Last name: "); - tempMD5Passwd=ServerConsole.MainConsole.Instance.PasswdPrompt("Password: "); + this.DefaultAssetServer=ServerConsole.MainConsole.Instance.CmdPrompt("Default asset server [no default]: "); + this.AssetSendKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to send to asset server: "); + this.AssetRecvKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to expect from asset server: "); - System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider(); - byte[] bs = System.Text.Encoding.UTF8.GetBytes(tempMD5Passwd); - bs = x.ComputeHash(bs); - System.Text.StringBuilder s = new System.Text.StringBuilder(); - foreach (byte b in bs) - { - s.Append(b.ToString("x2").ToLower()); - } - tempMD5Passwd = "$1$" + s.ToString(); - - GridGod=_profilemanager.CreateNewProfile(tempfirstname,templastname,tempMD5Passwd); - _profilemanager.SetGod(GridGod.UUID); - + this.DefaultUserServer=ServerConsole.MainConsole.Instance.CmdPrompt("Default user server [no default]: "); + this.UserSendKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to send to user server: "); + this.UserRecvKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to expect from user server: "); + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process"); _httpd = new GridHTTPServer(); } diff --git a/gridserver/src/SimProfiles.cs b/gridserver/src/SimProfiles.cs new file mode 100644 index 0000000000..7efb78586e --- /dev/null +++ b/gridserver/src/SimProfiles.cs @@ -0,0 +1,109 @@ +/* +Copyright (c) OpenGrid project, http://osgrid.org/ + + +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +using System; +using System.Text; +using System.Collections; +using System.Collections.Generic; +using libsecondlife; +using ServerConsole; + +namespace OpenGridServices +{ + /// + /// + public class SimProfileManager { + + public Dictionary SimProfiles = new Dictionary(); + + public SimProfileManager() { + } + + public void InitSimProfiles() { + // TODO: need to load from database + } + + public SimProfile GetProfileByHandle(ulong reqhandle) { + foreach (libsecondlife.LLUUID UUID in SimProfiles.Keys) { + if(SimProfiles[UUID].regionhandle==reqhandle) return SimProfiles[UUID]; + } + return null; + } + + public SimProfile GetProfileByLLUUID(LLUUID ProfileLLUUID) { + return SimProfiles[ProfileLLUUID]; + } + + public bool AuthenticateSim(LLUUID RegionUUID, uint regionhandle, string simrecvkey) { + SimProfile TheSim=GetProfileByHandle(regionhandle); + if(TheSim != null) + if(TheSim.recvkey==simrecvkey) { + return true; + } else { + return false; + } else return false; + + } + + public SimProfile CreateNewProfile(string regionname, string caps_url, string sim_ip, uint sim_port, uint RegionLocX, uint RegionLocY, string sendkey, string recvkey) { + SimProfile newprofile = new SimProfile(); + newprofile.regionname=regionname; + newprofile.sim_ip=sim_ip; + newprofile.sim_port=sim_port; + newprofile.RegionLocX=RegionLocX; + newprofile.RegionLocY=RegionLocY; + newprofile.sendkey=sendkey; + newprofile.recvkey=recvkey; + newprofile.regionhandle=Util.UIntsToLong((RegionLocX*256), (RegionLocY*256)); + this.SimProfiles.Add(newprofile.UUID,newprofile); + return newprofile; + } + + } + + public class SimProfile { + public LLUUID UUID; + public ulong regionhandle; + public string regionname; + public string sim_ip; + public uint sim_port; + public string caps_url; + public uint RegionLocX; + public uint RegionLocY; + public string sendkey; + public string recvkey; + + + public SimProfile() { + } + + + } + +} diff --git a/login/index.php b/login/index.php deleted file mode 100644 index 4f53c11e46..0000000000 --- a/login/index.php +++ /dev/null @@ -1,170 +0,0 @@ -0) { - $profiledata = mysql_fetch_assoc($profile_lookup_result); - - // if we get here, the username/password is valid, but still need to check there's not an already existing session - $client = new IXR_Client($gridserver_url); - if (!$client->query('check_session_loggedin', Array('userprofile_LLUUID' => $profiledata['userprofile_LLUUID'], 'authkey' => $gridserver_sendkey, 'server_type' => 'login'))) { // if this doesn't work, grid server is down - that's bad - return Array ( - 'reason' => 'key', - 'message' => "Could not connect to grid server. Please try again later or contact the grid owner ". $grid_owner, - 'login' => "false" - ); - } - - $response=$client->getResponse(); - if($response['authkey'] != $gridserver_recvkey) { // if this doesn't match up, it's a fake grid server - return Array ( - 'reason' => 'key', - 'message' => "Could not connect to grid server due to possible security issues. It is possible that the grid has been compromised. Please contact the grid owner " . $grid_owner . " and report this issue", - 'login' => "false" - ); - } - - - if($response['logged_in'] == 1) { // if the user is already logged in, tell them - return Array ( - 'reason' => 'presence', - 'message' => "You appear to already be logged into this grid, if your client has recently crashed then please try again later", - 'login' => "false" - ); - } - - // now we start a new session on the grid - $remote_ip=$_SERVER['REMOTE_ADDR']; - $region_handle=$profiledata['region_handle']; - $client->query('create_session',Array('userprofile_LLUUID' => $profiledata['userprofile_LLUUID'], 'authkey' => $gridserver_sendkey, 'remote_ip' => $remote_ip, 'current_location' => $region_handle)); - $response = $client->getResponse(); - $session_id = $response['session_id']; - $secure_session_id = $response['secure_session_id']; - - // ask the grid server what the IP address and port of the sim we want to connect to is - $client->query('get_sim_info', Array('region_handle' => $region_handle, 'authkey' => $gridserver_sendkey) ); - $siminfo = $client->getResponse(); - - // send the final response! - $position=$profiledata['position']; - $look_at=$profiledata['look_at']; - - $LocX=intval($siminfo['GridLocX'])*256; - $LocY=intval($siminfo['GridLocY'])*256; - $home="{'region_handle':'$region_handle', 'position':'$position', 'look_at':'$look_at'}"; - - $globaltextures = new LLBlock( - Array( - 'sun_texture_id' => "cce0f112-878f-4586-a2e2-a8f104bba271", - 'cloud_texture_id' => "fc4b9f0b-d008-45c6-96a4-01dd947ac621", - 'moon_texture_id' => "d07f6eed-b96a-47cd-b51d-400ad4a1c428" - )); - - $login_flags = new LLBlock( - Array( - 'stipend_since_login' => "N", - 'ever_logged_in' => "Y", - 'gendered' => "Y", - 'daylight_savings' => "N" - )); - $ui_config = new LLBlock( - Array( - 'allow_first_life' => "Y" - )); - $inventory_skeleton = new LLBlock(Array( - Array( - 'name' => 'My inventory', - 'parent_id' => '00000000-0000-0000-0000-000000000000', - 'version' => 4, - 'type_default' => 8, - 'folder_id' => 'f798e114-c10f-409b-a90d-a11577ff1de8' - ), - Array( - 'name' => 'Textures', - 'parent_id' => 'f798e114-c10f-409b-a90d-a11577ff1de8', - 'version' => 1, - 'type_default' => 0, - 'folder_id' => 'fc8b4059-30bb-43a8-a042-46f5b431ad82' - ))); - $inventory_root = new LLBlock( - Array( - 'folder_id' => "f798e114-c10f-409b-a90d-a11577ff1de8" - )); - $initial_outfit = new LLBlock( - Array( - 'folder_name' => "Nightclub Female", - 'gender' => "female" - )); - return Array ( - 'message' => "Welcome to OGS!", - 'session_id' => format_lluuid($session_id), - 'sim_port' => intval($siminfo['port']), - 'agent_access' => "M", - 'start_location' => "last", - 'global-textures' => $globaltextures, - 'seconds_since_epoch' => time(), - 'first_name' => $profiledata['profile_firstname'], - 'circuit_code' => 50633318, - 'login_flags' => $login_flags, - 'seed_capability' => '', - 'home' => $home, - 'secure_session_id' => format_lluuid($secure_session_id), - 'last_name' => $profiledata['profile_lastname'], - 'ui-config' => $ui_config, - 'region_x' => $LocX, - 'inventory_skeleton' => $inventory_skeleton, - 'sim_ip' => $siminfo['ip_addr'], - 'region_y' => $LocY, - 'inventory-root' => $inventory_root, - 'login' => "true", - 'look_at' => $look_at, - 'agent_id' => format_lluuid($profiledata['userprofile_LLUUID']), - 'initial-outfit' => $initial_outfit - ); - - - } else { - // this is the default invalid username/password error - return Array ( - 'reason' => 'key', - 'message' => "You have entered an invalid name/password combination or are using an incompatible client. Please check with the grid owner " .$grid_owner . " if you are sure your login details are accurate.", - 'login' => "false", - ); - } - -} - -$server=new IXR_Server(array('login_to_simulator' => 'login')); -?> diff --git a/login/login_config.inc.php b/login/login_config.inc.php deleted file mode 100644 index 4cce696522..0000000000 --- a/login/login_config.inc.php +++ /dev/null @@ -1,11 +0,0 @@ - diff --git a/userserver/default.build b/userserver/default.build new file mode 100644 index 0000000000..a56f92538e --- /dev/null +++ b/userserver/default.build @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/userserver/src/ConsoleCmds.cs b/userserver/src/ConsoleCmds.cs new file mode 100644 index 0000000000..f2568fc15c --- /dev/null +++ b/userserver/src/ConsoleCmds.cs @@ -0,0 +1,57 @@ +/* +Copyright (c) OpenSim project, http://osgrid.org/ + + +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +using System; +using System.Text; +using ServerConsole; + +namespace OpenGridServices +{ + + public class UserConsole : conscmd_callback { + public UserConsole() { } + + public override void RunCmd(string cmd, string[] cmdparams) { + switch(cmd) { + case "help": + ServerConsole.MainConsole.Instance.WriteLine("shutdown - shutdown the user server (USE CAUTION!)" +); + break; + + case "shutdown": + ServerConsole.MainConsole.Instance.Close(); + Environment.Exit(0); + break; + } + } + + public override void Show(string ShowWhat) { + } + } +} diff --git a/userserver/src/Main.cs b/userserver/src/Main.cs new file mode 100644 index 0000000000..584e397c6e --- /dev/null +++ b/userserver/src/Main.cs @@ -0,0 +1,112 @@ +/* +Copyright (c) OpenSim project, http://osgrid.org/ + + +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using libsecondlife; +using ServerConsole; + +namespace OpenGridServices +{ + /// + /// + public class OpenUser_Main + { + + public static OpenUser_Main userserver; + + public UserHTTPServer _httpd; + public UserProfileManager _profilemanager; + public UserProfile GridGod; + public string DefaultStartupMsg; + public string GridURL; + public string GridSendKey; + public string GridRecvKey; + + public Dictionary UserSessions = new Dictionary(); + + [STAThread] + public static void Main( string[] args ) + { + Console.WriteLine("OpenUser " + VersionInfo.Version + "\n"); + Console.WriteLine("Starting...\n"); + ServerConsole.MainConsole.Instance = new MServerConsole(ServerConsole.ConsoleBase.ConsoleType.Local, "", 0, "opengrid-console.log", "OpenUser", new UserConsole()); + + userserver = new OpenUser_Main(); + userserver.Startup(); + + ServerConsole.MainConsole.Instance.WriteLine("\nEnter help for a list of commands\n"); + + while(true) { + ServerConsole.MainConsole.Instance.MainConsolePrompt(); + } + } + + public void Startup() { + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please press enter to retain default settings"); + + this.GridURL=ServerConsole.MainConsole.Instance.CmdPrompt("Grid URL: "); + this.GridSendKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to send to grid: "); + this.GridRecvKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to expect from grid: "); + + this.DefaultStartupMsg=ServerConsole.MainConsole.Instance.CmdPrompt("Default startup message for clients [Welcome to OGS!] :","Welcome to OGS!"); + + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Creating user profile manager"); + _profilemanager = new UserProfileManager(); + _profilemanager.InitUserProfiles(); + + + string tempfirstname; + string templastname; + string tempMD5Passwd; + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please configure the grid god user:"); + tempfirstname=ServerConsole.MainConsole.Instance.CmdPrompt("First name: "); + templastname=ServerConsole.MainConsole.Instance.CmdPrompt("Last name: "); + tempMD5Passwd=ServerConsole.MainConsole.Instance.PasswdPrompt("Password: "); + + System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider(); + byte[] bs = System.Text.Encoding.UTF8.GetBytes(tempMD5Passwd); + bs = x.ComputeHash(bs); + System.Text.StringBuilder s = new System.Text.StringBuilder(); + foreach (byte b in bs) + { + s.Append(b.ToString("x2").ToLower()); + } + tempMD5Passwd = "$1$" + s.ToString(); + + GridGod=_profilemanager.CreateNewProfile(tempfirstname,templastname,tempMD5Passwd); + _profilemanager.SetGod(GridGod.UUID); + + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process"); + _httpd = new UserHTTPServer(); + } + } +} diff --git a/userserver/src/UserHttp.cs b/userserver/src/UserHttp.cs new file mode 100644 index 0000000000..0b4df69070 --- /dev/null +++ b/userserver/src/UserHttp.cs @@ -0,0 +1,181 @@ +/* +Copyright (c) OpenGrid project, http://osgrid.org/ + + +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +using System; +using System.Text; +using Nwc.XmlRpc; +using System.Threading; +using System.Text.RegularExpressions; +using System.Net; +using System.IO; +using System.Collections; +using System.Collections.Generic; +using libsecondlife; +using ServerConsole; + +namespace OpenGridServices +{ + public class UserHTTPServer { + public Thread HTTPD; + public HttpListener Listener; + + public UserHTTPServer() { + ServerConsole.MainConsole.Instance.WriteLine("Starting up HTTP Server"); + HTTPD = new Thread(new ThreadStart(StartHTTP)); + HTTPD.Start(); + } + + public void StartHTTP() { + ServerConsole.MainConsole.Instance.WriteLine("UserHttp.cs:StartHTTP() - Spawned main thread OK"); + Listener = new HttpListener(); + + Listener.Prefixes.Add("http://+:8002/userserver/"); + Listener.Start(); + + HttpListenerContext context; + while(true) { + context = Listener.GetContext(); + ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context); + } + } + + static string ParseXMLRPC(string requestBody) { + XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); + + Hashtable requestData = (Hashtable)request.Params[0]; + switch(request.MethodName) { + case "login_to_simulator": + bool GoodXML= (requestData.Contains("first") && requestData.Contains("last") && requestData.Contains("passwd")); + bool GoodLogin=false; + string firstname=""; + string lastname=""; + string passwd=""; + + if(GoodXML) { + firstname=(string)requestData["first"]; + lastname=(string)requestData["last"]; + passwd=(string)requestData["passwd"]; + GoodLogin=OpenUser_Main.userserver._profilemanager.AuthenticateUser(firstname,lastname,passwd); + } + + + if(!(GoodXML && GoodLogin)) { + XmlRpcResponse LoginErrorResp = new XmlRpcResponse(); + Hashtable ErrorRespData = new Hashtable(); + ErrorRespData["reason"]="key"; + ErrorRespData["message"]="Error connecting to grid. Please double check your login details and check with the grid owner if you are sure these are correct"; + ErrorRespData["login"]="false"; + LoginErrorResp.Value=ErrorRespData; + return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(LoginErrorResp)," encoding=\"utf-16\"","" )); + } + + UserProfile TheUser=OpenUser_Main.userserver._profilemanager.GetProfileByName(firstname,lastname); + + if(!((TheUser.CurrentSessionID==null) && (TheUser.CurrentSecureSessionID==null))) { + XmlRpcResponse PresenceErrorResp = new XmlRpcResponse(); + Hashtable PresenceErrorRespData = new Hashtable(); + PresenceErrorRespData["reason"]="presence"; + PresenceErrorRespData["message"]="You appear to be already logged in, if this is not the case please wait for your session to timeout, if this takes longer than a few minutes please contact the grid owner"; + PresenceErrorRespData["login"]="false"; + PresenceErrorResp.Value=PresenceErrorRespData; + return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(PresenceErrorResp)," encoding=\"utf-16\"","" )); + + } + + LLUUID AgentID = TheUser.UUID; + TheUser.InitSessionData(); + + XmlRpcResponse LoginGoodResp = new XmlRpcResponse(); + Hashtable LoginGoodData = new Hashtable(); + + LoginGoodData["message"]=OpenUser_Main.userserver.DefaultStartupMsg; + LoginGoodData["session_id"]=TheUser.CurrentSessionID; + LoginGoodData["secure_sessionid"]=TheUser.CurrentSecureSessionID; + + LoginGoodResp.Value=LoginGoodData; + return(XmlRpcResponseSerializer.Singleton.Serialize(LoginGoodResp)); + + + break; + } + + return ""; + } + + static string ParseREST(string requestBody, string requestURL) { + return ""; + } + + + static void HandleRequest(Object stateinfo) { + HttpListenerContext context=(HttpListenerContext)stateinfo; + + HttpListenerRequest request = context.Request; + HttpListenerResponse response = context.Response; + + response.KeepAlive=false; + response.SendChunked=false; + + System.IO.Stream body = request.InputStream; + System.Text.Encoding encoding = request.ContentEncoding; + System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding); + + string requestBody = reader.ReadToEnd(); + body.Close(); + reader.Close(); + + string responseString=""; + switch(request.ContentType) { + case "text/xml": + // must be XML-RPC, so pass to the XML-RPC parser + + responseString=ParseXMLRPC(requestBody); + response.AddHeader("Content-type","text/xml"); + break; + + case null: + // must be REST or invalid crap, so pass to the REST parser + responseString=ParseREST(request.Url.OriginalString,requestBody); + break; + } + + + byte[] buffer = System.Text.Encoding.Unicode.GetBytes(responseString); + System.IO.Stream output = response.OutputStream; + response.SendChunked=false; + encoding = System.Text.Encoding.UTF8; + response.ContentEncoding = encoding; + response.ContentLength64=buffer.Length; + output.Write(buffer,0,buffer.Length); + output.Close(); + } + } + + +} diff --git a/gridserver/src/UserProfiles.cs b/userserver/src/UserProfiles.cs similarity index 57% rename from gridserver/src/UserProfiles.cs rename to userserver/src/UserProfiles.cs index 6ab7eb3659..6ef871c050 100644 --- a/gridserver/src/UserProfiles.cs +++ b/userserver/src/UserProfiles.cs @@ -40,7 +40,7 @@ namespace OpenGridServices /// public class UserProfileManager { - private Dictionary UserProfiles = new Dictionary(); + public Dictionary UserProfiles = new Dictionary(); public UserProfileManager() { } @@ -60,6 +60,17 @@ namespace OpenGridServices return UserProfiles[ProfileLLUUID]; } + public bool AuthenticateUser(string firstname, string lastname, string passwd) { + UserProfile TheUser=GetProfileByName(firstname, lastname); + if(TheUser != null) + if(TheUser.MD5passwd==passwd) { + return true; + } else { + return false; + } else return false; + + } + public void SetGod(LLUUID GodID) { this.UserProfiles[GodID].IsGridGod=true; } @@ -69,9 +80,8 @@ namespace OpenGridServices newprofile.firstname=firstname; newprofile.lastname=lastname; newprofile.MD5passwd=MD5passwd; - UserProfiles.Add(OpenGrid_Main.thegrid.HighestUUID,newprofile); - newprofile.UUID=OpenGrid_Main.thegrid.HighestUUID; - OpenGrid_Main.thegrid.HighestUUID=LLUUID.Random(); // FIXME: Increment, don't set random! + newprofile.UUID=LLUUID.Random(); + this.UserProfiles.Add(newprofile.UUID,newprofile); return newprofile; } @@ -81,13 +91,55 @@ namespace OpenGridServices public string firstname; public string lastname; - public bool IsGridGod; + public uint homeregionhandle; + public LLVector3 homepos; + public LLVector3 homelookat; + + public bool IsGridGod=false; + public bool IsLocal=true; // will be used in future for visitors from foreign grids + public string AssetURL; public string MD5passwd; + public LLUUID CurrentSessionID; + public LLUUID CurrentSecureSessionID; public LLUUID UUID; + public Dictionary Circuits = new Dictionary(); // tracks circuit codes + public Dictionary InventoryFolders; + public Dictionary InventoryItems; public UserProfile() { + Circuits = new Dictionary(); + InventoryFolders = new Dictionary(); + InventoryItems = new Dictionary(); } + + public void InitSessionData() { + CurrentSessionID=LLUUID.Random(); + CurrentSecureSessionID=LLUUID.Random(); + } + + public void AddSimCircuit(uint circuit_code, LLUUID region_UUID) { + if(!this.Circuits.ContainsKey(region_UUID)) this.Circuits.Add(region_UUID, circuit_code); + } + } + public class InventoryFolder { + public LLUUID FolderID; + public LLUUID ParentID; + public string FolderName; + public ushort DefaultType; + public ushort Version; + } + + public class InventoryItem { //TODO: Fixup this and add full permissions etc + public LLUUID FolderID; + public LLUUID OwnerID; + public LLUUID ItemID; + public LLUUID AssetID; + public LLUUID CreatorID = LLUUID.Zero; + public sbyte InvType; + public sbyte Type; + public string Name; + public string Description; } }