aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer/CAPS/SimHttp.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim.RegionServer/CAPS/SimHttp.cs')
-rw-r--r--OpenSim.RegionServer/CAPS/SimHttp.cs166
1 files changed, 159 insertions, 7 deletions
diff --git a/OpenSim.RegionServer/CAPS/SimHttp.cs b/OpenSim.RegionServer/CAPS/SimHttp.cs
index f5a8705..77c6bb8 100644
--- a/OpenSim.RegionServer/CAPS/SimHttp.cs
+++ b/OpenSim.RegionServer/CAPS/SimHttp.cs
@@ -48,12 +48,17 @@ 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;
52 private string NewAccountForm;
53 private string LoginForm;
54 private string passWord = "Admin";
51 55
52 public SimCAPSHTTPServer() 56 public SimCAPSHTTPServer()
53 { 57 {
54 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting up HTTP Server"); 58 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting up HTTP Server");
55 HTTPD = new Thread(new ThreadStart(StartHTTP)); 59 HTTPD = new Thread(new ThreadStart(StartHTTP));
56 HTTPD.Start(); 60 HTTPD.Start();
61 LoadAdminPage();
57 } 62 }
58 63
59 public void StartHTTP() 64 public void StartHTTP()
@@ -79,7 +84,7 @@ namespace OpenSim.CAPS
79 } 84 }
80 } 85 }
81 86
82 static string ParseXMLRPC(string requestBody) 87 private string ParseXMLRPC(string requestBody)
83 { 88 {
84 try 89 try
85 { 90 {
@@ -111,19 +116,101 @@ namespace OpenSim.CAPS
111 return ""; 116 return "";
112 } 117 }
113 118
114 static string ParseREST(string requestBody, string requestURL) 119 private string ParseREST(string requestBody, string requestURL, string requestMethod)
115 { 120 {
116 return ""; 121 string responseString = "";
122 switch (requestURL)
123 {
124 case "/Admin/Accounts":
125 if (requestMethod == "GET")
126 {
127 responseString = "<p> Account management </p>";
128 responseString += "<br> ";
129 responseString += "<p> Create New Account </p>";
130 responseString += NewAccountForm;
131 }
132 break;
133 case "/Admin/Clients":
134 if (requestMethod == "GET")
135 {
136 responseString = " <p> Listing connected Clients </p>" ;
137 OpenSim.world.Avatar TempAv;
138 foreach (libsecondlife.LLUUID UUID in OpenSimRoot.Instance.LocalWorld.Entities.Keys)
139 {
140 if (OpenSimRoot.Instance.LocalWorld.Entities[UUID].ToString() == "OpenSim.world.Avatar")
141 {
142 TempAv = (OpenSim.world.Avatar)OpenSimRoot.Instance.LocalWorld.Entities[UUID];
143 responseString += "<p>";
144 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());
145 responseString += "</p>";
146 }
147 }
148 }
149 break;
150 case "/Admin/NewAccount":
151 if (requestMethod == "POST")
152 {
153 string[] comp = new string[10];
154 string[] passw = new string[3];
155 string delimStr = "&";
156 char[] delimiter = delimStr.ToCharArray();
157 string delimStr2 = "=";
158 char[] delimiter2 = delimStr2.ToCharArray();
159
160 //Console.WriteLine(requestBody);
161 comp = requestBody.Split(delimiter);
162 passw = comp[3].Split(delimiter2);
163 if (passw[1] == passWord)
164 {
165 responseString = "<p> New Account created </p>";
166 }
167 else
168 {
169 responseString = "<p> Admin password is incorrect, please login with the correct password</p>";
170 responseString += "<br><br>" + LoginForm;
171 }
172
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 }
201
202 return responseString;
117 } 203 }
118 204
119 static string ParseLLSDXML(string requestBody) 205 private string ParseLLSDXML(string requestBody)
120 { 206 {
121 // dummy function for now - IMPLEMENT ME! 207 // dummy function for now - IMPLEMENT ME!
122 return ""; 208 return "";
123 } 209 }
124 210
125 static void HandleRequest(Object stateinfo) 211 public void HandleRequest(Object stateinfo)
126 { 212 {
213 // Console.WriteLine("new http incoming");
127 HttpListenerContext context = (HttpListenerContext)stateinfo; 214 HttpListenerContext context = (HttpListenerContext)stateinfo;
128 215
129 HttpListenerRequest request = context.Request; 216 HttpListenerRequest request = context.Request;
@@ -140,6 +227,9 @@ namespace OpenSim.CAPS
140 body.Close(); 227 body.Close();
141 reader.Close(); 228 reader.Close();
142 229
230 //Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType);
231 //Console.WriteLine(requestBody);
232
143 string responseString = ""; 233 string responseString = "";
144 switch (request.ContentType) 234 switch (request.ContentType)
145 { 235 {
@@ -156,10 +246,26 @@ namespace OpenSim.CAPS
156 response.AddHeader("Content-type", "application/xml"); 246 response.AddHeader("Content-type", "application/xml");
157 break; 247 break;
158 248
249 case "application/x-www-form-urlencoded":
250 // a form data POST so send to the REST parser
251 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
252 response.AddHeader("Content-type", "text/html");
253 break;
254
159 case null: 255 case null:
160 // must be REST or invalid crap, so pass to the REST parser 256 if ((request.HttpMethod == "GET") && (request.RawUrl == "/Admin"))
161 responseString = ParseREST(request.Url.OriginalString, requestBody); 257 {
258 responseString = AdminPage;
259 response.AddHeader("Content-type", "text/html");
260 }
261 else
262 {
263 // must be REST or invalid crap, so pass to the REST parser
264 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
265 response.AddHeader("Content-type", "text/html");
266 }
162 break; 267 break;
268
163 } 269 }
164 270
165 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); 271 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
@@ -169,6 +275,52 @@ namespace OpenSim.CAPS
169 output.Write(buffer, 0, buffer.Length); 275 output.Write(buffer, 0, buffer.Length);
170 output.Close(); 276 output.Close();
171 } 277 }
278
279 private void LoadAdminPage()
280 {
281 try
282 {
283 StreamReader SR;
284 string lines;
285 AdminPage = "";
286 NewAccountForm = "";
287 LoginForm = "";
288 SR = File.OpenText("testadmin.htm");
289
290 while (!SR.EndOfStream)
291 {
292 lines = SR.ReadLine();
293 AdminPage += lines + "\n";
294
295 }
296 SR.Close();
297
298 SR = File.OpenText("newaccountform.htm");
299
300 while (!SR.EndOfStream)
301 {
302 lines = SR.ReadLine();
303 NewAccountForm += lines + "\n";
304
305 }
306 SR.Close();
307
308 SR = File.OpenText("login.htm");
309
310 while (!SR.EndOfStream)
311 {
312 lines = SR.ReadLine();
313 LoginForm += lines + "\n";
314
315 }
316 SR.Close();
317 }
318 catch (Exception e)
319 {
320 Console.WriteLine(e.ToString());
321 }
322
323 }
172 } 324 }
173 325
174 326