aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices/OpenGrid.Framework.Manager/GridManagementAgent.cs
blob: f4483fb9baa3b3472d84fc3a38cd9e60b8e5c107 (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
using Nwc.XmlRpc;
using OpenSim.Framework;
using OpenSim.Servers;
using System.Collections;
using System.Collections.Generic;
using libsecondlife;

namespace OpenGrid.Framework.Manager
{

    public delegate void GridManagerCallback(string param);

    public class GridManagementAgent
    {

        private GridManagerCallback thecallback;
        private string sendkey;
        private string recvkey;
        private string component_type;

        private static ArrayList Sessions;

        public GridManagementAgent(BaseHttpServer app_httpd, string component_type, string sendkey, string recvkey, GridManagerCallback thecallback)
        {
            this.sendkey = sendkey;
            this.recvkey = recvkey;
            this.component_type = component_type;
            this.thecallback = thecallback;
            Sessions = new ArrayList();

            app_httpd.AddXmlRPCHandler("manager_login", XmlRpcLoginMethod);

            switch (component_type)
            {
                case "gridserver":
                    GridServerManager.sendkey = this.sendkey;
                    GridServerManager.recvkey = this.recvkey;
                    GridServerManager.thecallback = thecallback;
                    app_httpd.AddXmlRPCHandler("shutdown", GridServerManager.XmlRpcShutdownMethod);
                    break;
            }
        }

        public static bool SessionExists(LLUUID sessionID)
        {
            return Sessions.Contains(sessionID);
        }

        public static XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
        {
            XmlRpcResponse response = new XmlRpcResponse();
            Hashtable requestData = (Hashtable)request.Params[0];
            Hashtable responseData = new Hashtable();

            // TODO: Switch this over to using OpenGrid.Framework.Data
            if (requestData["username"].Equals("admin") && requestData["password"].Equals("supersecret"))
            {
                response.IsFault = false;
                LLUUID new_session = LLUUID.Random();
                Sessions.Add(new_session);
                responseData["session_id"] = new_session.ToString();
                responseData["msg"] = "Login OK";
            }
            else
            {
                response.IsFault = true;
                responseData["error"] = "Invalid username or password";
            }

            response.Value = responseData;
            return response;

        }

    }
}