aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer/CAPS
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
parent* Now there's one Console class, and instead the apps responds to cmd's and s... (diff)
downloadopensim-SC-39c7fe5ec737c6cf259fd98d20723423419e847d.zip
opensim-SC-39c7fe5ec737c6cf259fd98d20723423419e847d.tar.gz
opensim-SC-39c7fe5ec737c6cf259fd98d20723423419e847d.tar.bz2
opensim-SC-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')
-rw-r--r--OpenSim.RegionServer/CAPS/AdminWebFront.cs164
-rw-r--r--OpenSim.RegionServer/CAPS/IRestHandler.cs11
-rw-r--r--OpenSim.RegionServer/CAPS/SimHttp.cs177
3 files changed, 205 insertions, 147 deletions
diff --git a/OpenSim.RegionServer/CAPS/AdminWebFront.cs b/OpenSim.RegionServer/CAPS/AdminWebFront.cs
new file mode 100644
index 0000000..ea32589
--- /dev/null
+++ b/OpenSim.RegionServer/CAPS/AdminWebFront.cs
@@ -0,0 +1,164 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5
6namespace OpenSim.CAPS
7{
8 public class AdminWebFront : IRestHandler
9 {
10 private string AdminPage;
11 private string NewAccountForm;
12 private string LoginForm;
13 private string passWord = "Admin";
14
15 public AdminWebFront(string password)
16 {
17 passWord = password;
18 LoadAdminPage();
19 }
20
21 public string HandleREST(string requestBody, string requestURL, string requestMethod)
22 {
23 string responseString = "";
24 try
25 {
26 switch (requestURL)
27 {
28 case "/Admin":
29 if (requestMethod == "GET")
30 {
31 responseString = AdminPage;
32 }
33 break;
34 case "/Admin/Accounts":
35 if (requestMethod == "GET")
36 {
37 responseString = "<p> Account management </p>";
38 responseString += "<br> ";
39 responseString += "<p> Create New Account </p>";
40 responseString += NewAccountForm;
41 }
42 break;
43 case "/Admin/Clients":
44 if (requestMethod == "GET")
45 {
46 responseString = " <p> Listing connected Clients </p>";
47 OpenSim.world.Avatar TempAv;
48 foreach (libsecondlife.LLUUID UUID in OpenSimRoot.Instance.LocalWorld.Entities.Keys)
49 {
50 if (OpenSimRoot.Instance.LocalWorld.Entities[UUID].ToString() == "OpenSim.world.Avatar")
51 {
52 TempAv = (OpenSim.world.Avatar)OpenSimRoot.Instance.LocalWorld.Entities[UUID];
53 responseString += "<p>";
54 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());
55 responseString += "</p>";
56 }
57 }
58 }
59 break;
60 case "/Admin/NewAccount":
61 if (requestMethod == "POST")
62 {
63 string[] comp = new string[10];
64 string[] passw = new string[3];
65 string delimStr = "&";
66 char[] delimiter = delimStr.ToCharArray();
67 string delimStr2 = "=";
68 char[] delimiter2 = delimStr2.ToCharArray();
69
70 //Console.WriteLine(requestBody);
71 comp = requestBody.Split(delimiter);
72 passw = comp[3].Split(delimiter2);
73 if (passw[1] == passWord)
74 {
75 responseString = "<p> New Account created </p>";
76 }
77 else
78 {
79 responseString = "<p> Admin password is incorrect, please login with the correct password</p>";
80 responseString += "<br><br>" + LoginForm;
81 }
82 }
83 break;
84 case "/Admin/Login":
85 if (requestMethod == "POST")
86 {
87 // Console.WriteLine(requestBody);
88 if (requestBody == passWord)
89 {
90 responseString = "<p> Login Successful </p>";
91 }
92 else
93 {
94 responseString = "<p> Password Error </p>";
95 responseString += "<p> Please Login with the correct password </p>";
96 responseString += "<br><br> " + LoginForm;
97 }
98 }
99 break;
100 case "/Admin/Welcome":
101 if (requestMethod == "GET")
102 {
103 responseString = "Welcome to the OpenSim Admin Page";
104 responseString += "<br><br><br> " + LoginForm;
105
106 }
107 break;
108 }
109 }
110 catch (Exception e)
111 {
112 Console.WriteLine(e.ToString());
113 }
114 return responseString;
115 }
116
117 private void LoadAdminPage()
118 {
119 try
120 {
121 StreamReader SR;
122 string lines;
123 AdminPage = "";
124 NewAccountForm = "";
125 LoginForm = "";
126 SR = File.OpenText("testadmin.htm");
127
128 while (!SR.EndOfStream)
129 {
130 lines = SR.ReadLine();
131 AdminPage += lines + "\n";
132
133 }
134 SR.Close();
135
136 SR = File.OpenText("newaccountform.htm");
137
138 while (!SR.EndOfStream)
139 {
140 lines = SR.ReadLine();
141 NewAccountForm += lines + "\n";
142
143 }
144 SR.Close();
145
146 SR = File.OpenText("login.htm");
147
148 while (!SR.EndOfStream)
149 {
150 lines = SR.ReadLine();
151 LoginForm += lines + "\n";
152
153 }
154 SR.Close();
155 }
156 catch (Exception e)
157 {
158 Console.WriteLine(e.ToString());
159 }
160
161 }
162
163 }
164}
diff --git a/OpenSim.RegionServer/CAPS/IRestHandler.cs b/OpenSim.RegionServer/CAPS/IRestHandler.cs
new file mode 100644
index 0000000..f269600
--- /dev/null
+++ b/OpenSim.RegionServer/CAPS/IRestHandler.cs
@@ -0,0 +1,11 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.CAPS
6{
7 public interface IRestHandler
8 {
9 string HandleREST(string requestBody, string requestURL, string requestMethod);
10 }
11}
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