aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer/CAPS/SimHttp.cs
diff options
context:
space:
mode:
authorMW2007-03-27 09:35:03 +0000
committerMW2007-03-27 09:35:03 +0000
commit39c7fe5ec737c6cf259fd98d20723423419e847d (patch)
treed8dc563b7fef4ce9dcc34fbcc31c3fcc7d99d49f /OpenSim.RegionServer/CAPS/SimHttp.cs
parent* Now there's one Console class, and instead the apps responds to cmd's and s... (diff)
downloadopensim-SC_OLD-39c7fe5ec737c6cf259fd98d20723423419e847d.zip
opensim-SC_OLD-39c7fe5ec737c6cf259fd98d20723423419e847d.tar.gz
opensim-SC_OLD-39c7fe5ec737c6cf259fd98d20723423419e847d.tar.bz2
opensim-SC_OLD-39c7fe5ec737c6cf259fd98d20723423419e847d.tar.xz
Added REST-handler interface for the http server and changed the Admin Web front end to one.
Diffstat (limited to 'OpenSim.RegionServer/CAPS/SimHttp.cs')
-rw-r--r--OpenSim.RegionServer/CAPS/SimHttp.cs177
1 files changed, 30 insertions, 147 deletions
diff --git a/OpenSim.RegionServer/CAPS/SimHttp.cs b/OpenSim.RegionServer/CAPS/SimHttp.cs
index c3f4801..a1073f0 100644
--- a/OpenSim.RegionServer/CAPS/SimHttp.cs
+++ b/OpenSim.RegionServer/CAPS/SimHttp.cs
@@ -48,17 +48,13 @@ namespace OpenSim.CAPS
48 { 48 {
49 public Thread HTTPD; 49 public Thread HTTPD;
50 public HttpListener Listener; 50 public HttpListener Listener;
51 private string AdminPage; 51 private Dictionary<string, IRestHandler> restHandlers = new Dictionary<string, IRestHandler>();
52 private string NewAccountForm;
53 private string LoginForm;
54 private string passWord = "Admin";
55 52
56 public SimCAPSHTTPServer() 53 public SimCAPSHTTPServer()
57 { 54 {
58 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting up HTTP Server"); 55 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting up HTTP Server");
59 HTTPD = new Thread(new ThreadStart(StartHTTP)); 56 HTTPD = new Thread(new ThreadStart(StartHTTP));
60 HTTPD.Start(); 57 HTTPD.Start();
61 LoadAdminPage();
62 } 58 }
63 59
64 public void StartHTTP() 60 public void StartHTTP()
@@ -84,7 +80,18 @@ namespace OpenSim.CAPS
84 } 80 }
85 } 81 }
86 82
87 private string ParseXMLRPC(string requestBody) 83 public bool AddRestHandler(string path, IRestHandler handler)
84 {
85 if (!this.restHandlers.ContainsKey(path))
86 {
87 this.restHandlers.Add(path, handler);
88 return true;
89 }
90
91 //must already have a handler for that path so return false
92 return false;
93 }
94 protected virtual string ParseXMLRPC(string requestBody)
88 { 95 {
89 try 96 try
90 { 97 {
@@ -116,104 +123,34 @@ namespace OpenSim.CAPS
116 return ""; 123 return "";
117 } 124 }
118 125
119 private string ParseREST(string requestBody, string requestURL, string requestMethod) 126 protected virtual string ParseREST(string requestBody, string requestURL, string requestMethod)
120 { 127 {
128 string[] path;
129 string pathDelimStr = "/";
130 char[] pathDelimiter = pathDelimStr.ToCharArray();
131 path = requestURL.Split(pathDelimiter);
132
121 string responseString = ""; 133 string responseString = "";
122 try 134
135 //path[0] should be empty so we are interested in path[1]
136 if (path.Length > 1)
123 { 137 {
124 switch (requestURL) 138 if ((path[1] != "") && (this.restHandlers.ContainsKey(path[1])))
125 { 139 {
126 case "/Admin/Accounts": 140 responseString = this.restHandlers[path[1]].HandleREST(requestBody, requestURL, requestMethod);
127 if (requestMethod == "GET")
128 {
129 responseString = "<p> Account management </p>";
130 responseString += "<br> ";
131 responseString += "<p> Create New Account </p>";
132 responseString += NewAccountForm;
133 }
134 break;
135 case "/Admin/Clients":
136 if (requestMethod == "GET")
137 {
138 responseString = " <p> Listing connected Clients </p>";
139 OpenSim.world.Avatar TempAv;
140 foreach (libsecondlife.LLUUID UUID in OpenSimRoot.Instance.LocalWorld.Entities.Keys)
141 {
142 if (OpenSimRoot.Instance.LocalWorld.Entities[UUID].ToString() == "OpenSim.world.Avatar")
143 {
144 TempAv = (OpenSim.world.Avatar)OpenSimRoot.Instance.LocalWorld.Entities[UUID];
145 responseString += "<p>";
146 responseString += String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}", TempAv.firstname, TempAv.lastname, UUID, TempAv.ControllingClient.SessionID, TempAv.ControllingClient.CircuitCode, TempAv.ControllingClient.userEP.ToString());
147 responseString += "</p>";
148 }
149 }
150 }
151 break;
152 case "/Admin/NewAccount":
153 if (requestMethod == "POST")
154 {
155 string[] comp = new string[10];
156 string[] passw = new string[3];
157 string delimStr = "&";
158 char[] delimiter = delimStr.ToCharArray();
159 string delimStr2 = "=";
160 char[] delimiter2 = delimStr2.ToCharArray();
161
162 //Console.WriteLine(requestBody);
163 comp = requestBody.Split(delimiter);
164 passw = comp[3].Split(delimiter2);
165 if (passw[1] == passWord)
166 {
167 responseString = "<p> New Account created </p>";
168 }
169 else
170 {
171 responseString = "<p> Admin password is incorrect, please login with the correct password</p>";
172 responseString += "<br><br>" + LoginForm;
173 }
174 }
175 break;
176 case "/Admin/Login":
177 if (requestMethod == "POST")
178 {
179 // Console.WriteLine(requestBody);
180 if (requestBody == passWord)
181 {
182 responseString = "<p> Login Successful </p>";
183 }
184 else
185 {
186 responseString = "<p> Password Error </p>";
187 responseString += "<p> Please Login with the correct password </p>";
188 responseString += "<br><br> " + LoginForm;
189 }
190 }
191 break;
192 case "/Admin/Welcome":
193 if (requestMethod == "GET")
194 {
195 responseString = "Welcome to the OpenSim Admin Page";
196 responseString += "<br><br><br> " + LoginForm;
197
198 }
199 break;
200 } 141 }
201 } 142 }
202 catch (Exception e) 143
203 {
204 Console.WriteLine(e.ToString());
205 }
206
207 return responseString; 144 return responseString;
208 } 145 }
209 146
210 private string ParseLLSDXML(string requestBody) 147 protected virtual string ParseLLSDXML(string requestBody)
211 { 148 {
212 // dummy function for now - IMPLEMENT ME! 149 // dummy function for now - IMPLEMENT ME!
213 return ""; 150 return "";
214 } 151 }
215 152
216 public void HandleRequest(Object stateinfo) 153 public virtual void HandleRequest(Object stateinfo)
217 { 154 {
218 // Console.WriteLine("new http incoming"); 155 // Console.WriteLine("new http incoming");
219 HttpListenerContext context = (HttpListenerContext)stateinfo; 156 HttpListenerContext context = (HttpListenerContext)stateinfo;
@@ -258,17 +195,9 @@ namespace OpenSim.CAPS
258 break; 195 break;
259 196
260 case null: 197 case null:
261 if ((request.HttpMethod == "GET") && (request.RawUrl == "/Admin")) 198 // must be REST or invalid crap, so pass to the REST parser
262 { 199 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
263 responseString = AdminPage; 200 response.AddHeader("Content-type", "text/html");
264 response.AddHeader("Content-type", "text/html");
265 }
266 else
267 {
268 // must be REST or invalid crap, so pass to the REST parser
269 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
270 response.AddHeader("Content-type", "text/html");
271 }
272 break; 201 break;
273 202
274 } 203 }
@@ -280,52 +209,6 @@ namespace OpenSim.CAPS
280 output.Write(buffer, 0, buffer.Length); 209 output.Write(buffer, 0, buffer.Length);
281 output.Close(); 210 output.Close();
282 } 211 }
283
284 private void LoadAdminPage()
285 {
286 try
287 {
288 StreamReader SR;
289 string lines;
290 AdminPage = "";
291 NewAccountForm = "";
292 LoginForm = "";
293 SR = File.OpenText("testadmin.htm");
294
295 while (!SR.EndOfStream)
296 {
297 lines = SR.ReadLine();
298 AdminPage += lines + "\n";
299
300 }
301 SR.Close();
302
303 SR = File.OpenText("newaccountform.htm");
304
305 while (!SR.EndOfStream)
306 {
307 lines = SR.ReadLine();
308 NewAccountForm += lines + "\n";
309
310 }
311 SR.Close();
312
313 SR = File.OpenText("login.htm");
314
315 while (!SR.EndOfStream)
316 {
317 lines = SR.ReadLine();
318 LoginForm += lines + "\n";
319
320 }
321 SR.Close();
322 }
323 catch (Exception e)
324 {
325 Console.WriteLine(e.ToString());
326 }
327
328 }
329 } 212 }
330 213
331 214