aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer
diff options
context:
space:
mode:
authorlbsa712007-03-29 19:05:34 +0000
committerlbsa712007-03-29 19:05:34 +0000
commit514a3230563e19708588945f90e81760377f1265 (patch)
tree89c2b0c9d05b10b4a470bc9834cc7f4aef89047a /OpenSim.RegionServer
parent* Tried to make the sandbox/useraccount sim setup a bit simpler (diff)
downloadopensim-SC-514a3230563e19708588945f90e81760377f1265.zip
opensim-SC-514a3230563e19708588945f90e81760377f1265.tar.gz
opensim-SC-514a3230563e19708588945f90e81760377f1265.tar.bz2
opensim-SC-514a3230563e19708588945f90e81760377f1265.tar.xz
* RestMethod now uses same pattern as XmlRpcMethod
* Made /Admin use RestMethod * HttpServer is now a mini-webapp-server yay!
Diffstat (limited to '')
-rw-r--r--OpenSim.RegionServer/CAPS/AdminWebFront.cs221
-rw-r--r--OpenSim.RegionServer/OpenSimMain.cs3
2 files changed, 112 insertions, 112 deletions
diff --git a/OpenSim.RegionServer/CAPS/AdminWebFront.cs b/OpenSim.RegionServer/CAPS/AdminWebFront.cs
index 8224050..3596ffa 100644
--- a/OpenSim.RegionServer/CAPS/AdminWebFront.cs
+++ b/OpenSim.RegionServer/CAPS/AdminWebFront.cs
@@ -4,10 +4,11 @@ using System.Text;
4using System.IO; 4using System.IO;
5using OpenSim.world; 5using OpenSim.world;
6using OpenSim.UserServer; 6using OpenSim.UserServer;
7using OpenSim.Servers;
7 8
8namespace OpenSim.CAPS 9namespace OpenSim.CAPS
9{ 10{
10 public class AdminWebFront : IRestHandler 11 public class AdminWebFront
11 { 12 {
12 private string AdminPage; 13 private string AdminPage;
13 private string NewAccountForm; 14 private string NewAccountForm;
@@ -24,126 +25,124 @@ namespace OpenSim.CAPS
24 LoadAdminPage(); 25 LoadAdminPage();
25 } 26 }
26 27
27 public string HandleREST(string requestBody, string requestURL, string requestMethod) 28 public void LoadMethods( BaseHttpServer server )
28 { 29 {
29 string responseString = ""; 30 server.AddRestHandler("GET", "/Admin", GetAdminPage);
30 try 31 server.AddRestHandler("GET", "/Admin/Welcome", GetWelcomePage);
32 server.AddRestHandler("GET", "/Admin/Accounts", GetAccountsPage );
33 server.AddRestHandler("GET", "/Admin/Clients", GetConnectedClientsPage );
34
35 server.AddRestHandler("POST", "/Admin/NewAccount", PostNewAccount );
36 server.AddRestHandler("POST", "/Admin/Login", PostLogin );
37 }
38
39 private string GetWelcomePage( string request )
40 {
41 string responseString;
42 responseString = "Welcome to the OpenSim Admin Page";
43 responseString += "<br><br><br> " + LoginForm;
44 return responseString;
45 }
46
47 private string PostLogin(string requestBody)
48 {
49 string responseString;
50// Console.WriteLine(requestBody);
51 if (requestBody == passWord)
52 {
53 responseString = "<p> Login Successful </p>";
54 }
55 else
56 {
57 responseString = "<p> Password Error </p>";
58 responseString += "<p> Please Login with the correct password </p>";
59 responseString += "<br><br> " + LoginForm;
60 }
61 return responseString;
62 }
63
64 private string PostNewAccount(string requestBody)
65 {
66 string responseString;
67 string firstName = "";
68 string secondName = "";
69 string userPasswd = "";
70 string[] comp;
71 string[] passw;
72 string[] line;
73 string delimStr = "&";
74 char[] delimiter = delimStr.ToCharArray();
75 string delimStr2 = "=";
76 char[] delimiter2 = delimStr2.ToCharArray();
77
78 //Console.WriteLine(requestBody);
79 comp = requestBody.Split(delimiter);
80 passw = comp[3].Split(delimiter2);
81 if (passw[1] == passWord)
31 { 82 {
32 switch (requestURL)
33 {
34 case "/Admin":
35 if (requestMethod == "GET")
36 {
37 responseString = AdminPage;
38 }
39 break;
40 case "/Admin/Accounts":
41 if (requestMethod == "GET")
42 {
43 responseString = "<p> Account management </p>";
44 responseString += "<br> ";
45 responseString += "<p> Create New Account </p>";
46 responseString += NewAccountForm;
47 }
48 break;
49 case "/Admin/Clients":
50 if (requestMethod == "GET")
51 {
52 responseString = " <p> Listing connected Clients </p>";
53 OpenSim.world.Avatar TempAv;
54 foreach (libsecondlife.LLUUID UUID in m_world.Entities.Keys)
55 {
56 if (m_world.Entities[UUID].ToString() == "OpenSim.world.Avatar")
57 {
58 TempAv = (OpenSim.world.Avatar)m_world.Entities[UUID];
59 responseString += "<p>";
60 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());
61 responseString += "</p>";
62 }
63 }
64 }
65 break;
66 case "/Admin/NewAccount":
67 if (requestMethod == "POST")
68 {
69 string firstName = "";
70 string secondName = "";
71 string userPasswd = "";
72 string[] comp;
73 string[] passw;
74 string[] line;
75 string delimStr = "&";
76 char[] delimiter = delimStr.ToCharArray();
77 string delimStr2 = "=";
78 char[] delimiter2 = delimStr2.ToCharArray();
79
80 //Console.WriteLine(requestBody);
81 comp = requestBody.Split(delimiter);
82 passw = comp[3].Split(delimiter2);
83 if (passw[1] == passWord)
84 {
85 83
86 line = comp[0].Split(delimiter2); //split firstname 84 line = comp[0].Split(delimiter2); //split firstname
87 if (line.Length > 1) 85 if (line.Length > 1)
88 { 86 {
89 firstName = line[1]; 87 firstName = line[1];
90 }
91 line = comp[1].Split(delimiter2); //split secondname
92 if (line.Length > 1)
93 {
94 secondName = line[1];
95 }
96 line = comp[2].Split(delimiter2); //split user password
97 if (line.Length > 1)
98 {
99 userPasswd = line[1];
100 }
101 if (this._userServer != null)
102 {
103 this._userServer.CreateUserAccount(firstName, secondName, userPasswd);
104 }
105 responseString = "<p> New Account created </p>";
106 }
107 else
108 {
109 responseString = "<p> Admin password is incorrect, please login with the correct password</p>";
110 responseString += "<br><br>" + LoginForm;
111 }
112 }
113 break;
114 case "/Admin/Login":
115 if (requestMethod == "POST")
116 {
117 // Console.WriteLine(requestBody);
118 if (requestBody == passWord)
119 {
120 responseString = "<p> Login Successful </p>";
121 }
122 else
123 {
124 responseString = "<p> Password Error </p>";
125 responseString += "<p> Please Login with the correct password </p>";
126 responseString += "<br><br> " + LoginForm;
127 }
128 }
129 break;
130 case "/Admin/Welcome":
131 if (requestMethod == "GET")
132 {
133 responseString = "Welcome to the OpenSim Admin Page";
134 responseString += "<br><br><br> " + LoginForm;
135
136 }
137 break;
138 } 88 }
89 line = comp[1].Split(delimiter2); //split secondname
90 if (line.Length > 1)
91 {
92 secondName = line[1];
93 }
94 line = comp[2].Split(delimiter2); //split user password
95 if (line.Length > 1)
96 {
97 userPasswd = line[1];
98 }
99 if (this._userServer != null)
100 {
101 this._userServer.CreateUserAccount(firstName, secondName, userPasswd);
102 }
103 responseString = "<p> New Account created </p>";
139 } 104 }
140 catch (Exception e) 105 else
141 { 106 {
142 Console.WriteLine(e.ToString()); 107 responseString = "<p> Admin password is incorrect, please login with the correct password</p>";
108 responseString += "<br><br>" + LoginForm;
109 }
110 return responseString;
111 }
112
113 private string GetConnectedClientsPage( string request )
114 {
115 string responseString;
116 responseString = " <p> Listing connected Clients </p>";
117 OpenSim.world.Avatar TempAv;
118 foreach (libsecondlife.LLUUID UUID in m_world.Entities.Keys)
119 {
120 if (m_world.Entities[UUID].ToString() == "OpenSim.world.Avatar")
121 {
122 TempAv = (OpenSim.world.Avatar)m_world.Entities[UUID];
123 responseString += "<p>";
124 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());
125 responseString += "</p>";
126 }
143 } 127 }
144 return responseString; 128 return responseString;
145 } 129 }
146 130
131 private string GetAccountsPage( string request )
132 {
133 string responseString;
134 responseString = "<p> Account management </p>";
135 responseString += "<br> ";
136 responseString += "<p> Create New Account </p>";
137 responseString += NewAccountForm;
138 return responseString;
139 }
140
141 private string GetAdminPage( string request )
142 {
143 return AdminPage;
144 }
145
147 private void LoadAdminPage() 146 private void LoadAdminPage()
148 { 147 {
149 try 148 try
diff --git a/OpenSim.RegionServer/OpenSimMain.cs b/OpenSim.RegionServer/OpenSimMain.cs
index 51ec12b..36e1817 100644
--- a/OpenSim.RegionServer/OpenSimMain.cs
+++ b/OpenSim.RegionServer/OpenSimMain.cs
@@ -199,7 +199,8 @@ namespace OpenSim
199 } 199 }
200 } 200 }
201 201
202 HttpServer.AddRestHandler("Admin", new AdminWebFront("Admin", LocalWorld, adminLoginServer )); 202 AdminWebFront adminWebFront = new AdminWebFront("Admin", LocalWorld, adminLoginServer);
203 adminWebFront.LoadMethods( HttpServer );
203 204
204 m_console.WriteLine("Main.cs:Startup() - Starting HTTP server"); 205 m_console.WriteLine("Main.cs:Startup() - Starting HTTP server");
205 HttpServer.Start(); 206 HttpServer.Start();