aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer/CAPS/AdminWebFront.cs
blob: ea325897a0458996b3df3ba1532833c0d15bac34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace OpenSim.CAPS
{
    public class AdminWebFront : IRestHandler
    {
        private string AdminPage;
        private string NewAccountForm;
        private string LoginForm;
        private string passWord = "Admin";

        public AdminWebFront(string password)
        {
            passWord = password;
            LoadAdminPage();
        }

        public string HandleREST(string requestBody, string requestURL, string requestMethod)
        {
            string responseString = "";
            try
            {
                switch (requestURL)
                {
                    case "/Admin":
                        if (requestMethod == "GET")
                        {
                            responseString = AdminPage;
                        }
                        break;
                    case "/Admin/Accounts":
                        if (requestMethod == "GET")
                        {
                            responseString = "<p> Account management </p>";
                            responseString += "<br> ";
                            responseString += "<p> Create New Account </p>";
                            responseString += NewAccountForm;
                        }
                        break;
                    case "/Admin/Clients":
                        if (requestMethod == "GET")
                        {
                            responseString = " <p> Listing connected Clients </p>";
                            OpenSim.world.Avatar TempAv;
                            foreach (libsecondlife.LLUUID UUID in OpenSimRoot.Instance.LocalWorld.Entities.Keys)
                            {
                                if (OpenSimRoot.Instance.LocalWorld.Entities[UUID].ToString() == "OpenSim.world.Avatar")
                                {
                                    TempAv = (OpenSim.world.Avatar)OpenSimRoot.Instance.LocalWorld.Entities[UUID];
                                    responseString += "<p>";
                                    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());
                                    responseString += "</p>";
                                }
                            }
                        }
                        break;
                    case "/Admin/NewAccount":
                        if (requestMethod == "POST")
                        {
                            string[] comp = new string[10];
                            string[] passw = new string[3];
                            string delimStr = "&";
                            char[] delimiter = delimStr.ToCharArray();
                            string delimStr2 = "=";
                            char[] delimiter2 = delimStr2.ToCharArray();

                            //Console.WriteLine(requestBody);
                            comp = requestBody.Split(delimiter);
                            passw = comp[3].Split(delimiter2);
                            if (passw[1] == passWord)
                            {
                                responseString = "<p> New Account created </p>";
                            }
                            else
                            {
                                responseString = "<p> Admin password is incorrect, please login with the correct password</p>";
                                responseString += "<br><br>" + LoginForm;
                            }
                        }
                        break;
                    case "/Admin/Login":
                        if (requestMethod == "POST")
                        {
                            // Console.WriteLine(requestBody);
                            if (requestBody == passWord)
                            {
                                responseString = "<p> Login Successful </p>";
                            }
                            else
                            {
                                responseString = "<p> Password Error </p>";
                                responseString += "<p> Please Login with the correct password </p>";
                                responseString += "<br><br> " + LoginForm;
                            }
                        }
                        break;
                    case "/Admin/Welcome":
                        if (requestMethod == "GET")
                        {
                            responseString = "Welcome to the OpenSim Admin Page";
                            responseString += "<br><br><br> " + LoginForm;

                        }
                        break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            return responseString;
        }

        private void LoadAdminPage()
        {
            try
            {
                StreamReader SR;
                string lines;
                AdminPage = "";
                NewAccountForm = "";
                LoginForm = "";
                SR = File.OpenText("testadmin.htm");

                while (!SR.EndOfStream)
                {
                    lines = SR.ReadLine();
                    AdminPage += lines + "\n";

                }
                SR.Close();

                SR = File.OpenText("newaccountform.htm");

                while (!SR.EndOfStream)
                {
                    lines = SR.ReadLine();
                    NewAccountForm += lines + "\n";

                }
                SR.Close();

                SR = File.OpenText("login.htm");

                while (!SR.EndOfStream)
                {
                    lines = SR.ReadLine();
                    LoginForm += lines + "\n";

                }
                SR.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

        }

    }
}