public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            string result = string.Empty;
            try
            {
                Request request = WifiUtils.CreateRequest(string.Empty, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

                string resource = GetParam(path);
                //m_log.DebugFormat("[XXX]: resource {0}", resource);
                if (resource.StartsWith("/data/simulators"))
                {
                    result = m_WebApp.Services.ConsoleSimulatorsRequest(env);
                    httpResponse.ContentType = "application/xml";
                }
                else if (resource.StartsWith("/heartbeat"))
                {
                    result = m_WebApp.Services.ConsoleHeartbeat(env);
                    httpResponse.ContentType = "application/xml";
                }
                else
                {
                    result = m_WebApp.Services.ConsoleRequest(env);
                    httpResponse.ContentType = "text/html";
                }
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[CONSOLE HANDLER]: Exception {0}: {1}", e.Message, e.StackTrace);
            }

            return WifiUtils.StringToBytes(result);
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);
            //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint);
            //foreach (object o in httpRequest.Query.Keys)
            //    m_log.DebugFormat("  >> {0}={1}", o, httpRequest.Query[o]);
            httpResponse.ContentType = "text/html";
            string resource = GetParam(path);
            m_log.DebugFormat("[USER ACCOUNT HANDLER GET]: resource {0}", resource);

            Request request = WifiUtils.CreateRequest(string.Empty, httpRequest);
            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            string result = string.Empty;
            UUID userID = UUID.Zero;
            if (resource == string.Empty || resource == "/")
            {
                result = m_WebApp.Services.NewAccountGetRequest(env);
            }
            else
            {
                UUID.TryParse(resource.Trim(new char[] {'/'}), out userID);
                result = m_WebApp.Services.UserAccountGetRequest(env, userID);
            }

            return WifiUtils.StringToBytes(result);

        }
Пример #3
0
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);
            //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint);
            //foreach (object o in httpRequest.Query.Keys)
            //    m_log.DebugFormat("  >> {0}={1}", o, httpRequest.Query[o]);

            string result = string.Empty;
            try
            {
                Request request = WifiUtils.CreateRequest(string.Empty, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

                result = m_WebApp.Services.LogoutRequest(env);

                httpResponse.ContentType = "text/html";
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[LOGOUT HANDLER]: Exception {0}: {1}", e.Message, e.StackTrace);
            }

            return WifiUtils.StringToBytes(result);

        }
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);
            //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint);
            //foreach (object o in httpRequest.Query.Keys)
            //    m_log.DebugFormat("  >> {0}={1}", o, httpRequest.Query[o]);
            httpResponse.ContentType = "text/html";
            string resource = GetParam(path);
            //m_log.DebugFormat("[USER ACCOUNT HANDLER GET]: resource {0}", resource);

            Request request = WifiUtils.CreateRequest(string.Empty, httpRequest);

            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            string result = string.Empty;
            UUID   userID = UUID.Zero;

            if (resource == string.Empty || resource == "/")
            {
                result = m_WebApp.Services.NewAccountGetRequest(env);
            }
            else
            {
                //UUID.TryParse(resource.Trim(new char[] {'/'}), out userID);
                if (resource.Trim(new char[] { '/' }).StartsWith("edit"))
                {
                    result = m_WebApp.Services.UserAccountGetRequest(env, userID);
                }
            }

            return(WifiUtils.StringToBytes(result));
        }
Пример #5
0
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);
            //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint);
            //foreach (object o in httpRequest.Query.Keys)
            //    m_log.DebugFormat("  >> {0}={1}", o, httpRequest.Query[o]);

            string result = string.Empty;

            try
            {
                Request request           = RequestFactory.CreateRequest(string.Empty, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

                result = m_WebApp.Services.LogoutRequest(env);

                httpResponse.ContentType = "text/html";
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[LOGOUT HANDLER]: Exception {0}: {1}", e.Message, e.StackTrace);
            }

            return(WebAppUtils.StringToBytes(result));
        }
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);

            // This is the content type of the response. Don't forget to set it to this in all your handlers.
            httpResponse.ContentType = "text/html";

            string resource = GetParam(path);
            //m_log.DebugFormat("[XXX]: resource {0}", resource);
            Request request = RequestFactory.CreateRequest(resource, httpRequest);

            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            string result = string.Empty;

            if (resource.Equals("/") || resource.Equals(string.Empty))
            {
                // client invoked /wifi/admin/users/ with no further parameters
                result = m_WebApp.Services.RegionManagementGetRequest(env);
            }

            return(WebAppUtils.StringToBytes(result));
        }
Пример #7
0
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            string result = string.Empty;

            try
            {
                Request request           = WifiUtils.CreateRequest(string.Empty, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

                string resource = GetParam(path);
                //m_log.DebugFormat("[XXX]: resource {0}", resource);
                if (resource.StartsWith("/data/simulators"))
                {
                    result = m_WebApp.Services.ConsoleSimulatorsRequest(env);
                    httpResponse.ContentType = "application/xml";
                }
                else if (resource.StartsWith("/heartbeat"))
                {
                    result = m_WebApp.Services.ConsoleHeartbeat(env);
                    httpResponse.ContentType = "application/xml";
                }
                else
                {
                    result = m_WebApp.Services.ConsoleRequest(env);
                    httpResponse.ContentType = "text/html";
                }
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[CONSOLE HANDLER]: Exception {0}: {1}", e.Message, e.StackTrace);
            }

            return(WifiUtils.StringToBytes(result));
        }
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            // It's a POST, so we need to read the data on the stream, the lines after the blank line
            StreamReader sr   = new StreamReader(requestData);
            string       body = sr.ReadToEnd();

            sr.Close();
            body = body.Trim();

            httpResponse.ContentType = "text/html";

            string resource = GetParam(path);

            //m_log.DebugFormat("[XXX]: query String: {0}; resource: {1}", body, resource);

            try
            {
                // Here the data on the stream is transformed into a nice dictionary of keys & values
                Dictionary <string, object> postdata =
                    ServerUtils.ParseQueryString(body);

                string broadcast_message = String.Empty;
                if (postdata.ContainsKey("message"))
                {
                    broadcast_message = postdata["message"].ToString();
                }

                Request req = RequestFactory.CreateRequest(resource, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

                string result = string.Empty;
                if (resource.Equals("/") || resource.Equals(string.Empty))
                {
                }
                else if (resource.StartsWith("/shutdown"))
                {
                    result = m_WebApp.Services.RegionManagementShutdownPostRequest(env);
                }
                else if (resource.StartsWith("/restart"))
                {
                    result = m_WebApp.Services.RegionManagementRestartPostRequest(env);
                }
                else if (resource.StartsWith("/broadcast"))
                {
                    result = m_WebApp.Services.RegionManagementBroadcastPostRequest(env, broadcast_message);
                }
                return(WebAppUtils.StringToBytes(result));
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[REGION MANAGEMENT POST HANDLER]: Exception {0}", e);
            }

            return(WebAppUtils.FailureResult());
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            httpResponse.ContentType = "text/html";

            Request request = WifiUtils.CreateRequest(string.Empty, httpRequest);
            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            string result = m_WebApp.Services.ForgotPasswordGetRequest(env);

            return WifiUtils.StringToBytes(result);
        }
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            httpResponse.ContentType = "text/html";

            Request request = WifiUtils.CreateRequest(string.Empty, httpRequest);

            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            string result = m_WebApp.Services.ForgotPasswordGetRequest(env);

            return(WifiUtils.StringToBytes(result));
        }
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            StreamReader sr   = new StreamReader(requestData);
            string       body = sr.ReadToEnd();

            sr.Close();
            body = body.Trim();

            httpResponse.ContentType = "text/html";

            string resource = GetParam(path);

            try
            {
                Dictionary <string, object> request =
                    ServerUtils.ParseQueryString(body);

                string token = String.Empty;
                if (request.ContainsKey("token"))
                {
                    token = request["token"].ToString();
                }
                string email = String.Empty;
                if (request.ContainsKey("email"))
                {
                    email = request["email"].ToString();
                }

                string newPassword = String.Empty;
                if (request.ContainsKey("newpassword"))
                {
                    newPassword = request["newpassword"].ToString();
                }

                Request req = WifiUtils.CreateRequest(string.Empty, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

                string result = m_WebApp.Services.RecoverPasswordPostRequest(env, email, token, newPassword);
                return(WifiUtils.StringToBytes(result));
            }
            catch (Exception e)
            {
                m_Log.DebugFormat("[FORGOT PASSWORD POST HANDLER]: Exception {0}", e);
            }

            return(WifiUtils.FailureResult());
        }
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            StreamReader sr   = new StreamReader(requestData);
            string       body = sr.ReadToEnd();

            sr.Close();
            body = body.Trim();

            httpResponse.ContentType = "text/html";

            string resource = GetParam(path);

            try
            {
                string[] pars = SplitParams(path);
                if (pars.Length == 1) // /wifi/recover/token?email=email
                {
                    string token = pars[0];
                    if (httpRequest.Query.ContainsKey("email") && httpRequest.Query["email"] != null)
                    {
                        string  email             = HttpUtility.UrlDecode(httpRequest.Query["email"].ToString());
                        Request req               = WifiUtils.CreateRequest(string.Empty, httpRequest);
                        Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

                        string result = m_WebApp.Services.RecoverPasswordGetRequest(env, email, token);

                        return(WifiUtils.StringToBytes(result));
                    }
                    else
                    {
                        m_Log.DebugFormat("[PASSWORD RECOVER GET HANDLER]: Query part does not contain email variable");
                    }
                }
                else
                {
                    m_Log.DebugFormat("[PASSWORD RECOVER GET HANDLER]: Path does not have 1 params, it has {0}", pars.Length);
                }
            }
            catch (Exception e)
            {
                m_Log.DebugFormat("[PASSWORD RECOVER GET HANDLER]: Exception {0}", e);
            }

            return(WifiUtils.FailureResult());
        }
Пример #13
0
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            StreamReader sr   = new StreamReader(requestData);
            string       body = sr.ReadToEnd();

            sr.Close();
            body = body.Trim();

            httpResponse.ContentType = "text/html";

            string resource = GetParam(path);

            try
            {
                Dictionary <string, object> request =
                    ServerUtils.ParseQueryString(body);

                string password  = String.Empty;
                string password2 = String.Empty;

                if (request.ContainsKey("password"))
                {
                    password = request["password"].ToString();
                }
                if (request.ContainsKey("password2"))
                {
                    password2 = request["password2"].ToString();
                }

                Request req = WifiUtils.CreateRequest(string.Empty, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

                string result = m_WebApp.Services.InstallPostRequest(env, password, password2);

                return(WifiUtils.StringToBytes(result));
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[USER ACCOUNT POST HANDLER]: Exception {0}", e);
            }

            return(WifiUtils.FailureResult());
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);
            //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint);
            //foreach (object o in httpRequest.Query.Keys)
            //    m_log.DebugFormat("  >> {0}={1}", o, httpRequest.Query[o]);

            httpResponse.ContentType = "text/html";

            Request request = WifiUtils.CreateRequest(string.Empty, httpRequest);
            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            string result = m_WebApp.Services.InstallGetRequest(env);

            return WifiUtils.StringToBytes(result);

        }
Пример #15
0
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);
            //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint);
            //foreach (object o in httpRequest.Query.Keys)
            //    m_log.DebugFormat("  >> {0}={1}", o, httpRequest.Query[o]);

            httpResponse.ContentType = "text/html";

            Request request = WifiUtils.CreateRequest(string.Empty, httpRequest);

            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            string result = m_WebApp.Services.InstallGetRequest(env);

            return(WifiUtils.StringToBytes(result));
        }
        private byte[] CreateAccount(string resource, IOSHttpRequest httpRequest, Dictionary <string, object> request)
        {
            string first     = String.Empty;
            string last      = String.Empty;
            string email     = String.Empty;
            string password  = String.Empty;
            string password2 = String.Empty;
            string avatar    = string.Empty;

            if (request.ContainsKey("first") && WifiUtils.IsValidName(request["first"].ToString()))
            {
                first = request["first"].ToString();
            }
            if (request.ContainsKey("last") && WifiUtils.IsValidName(request["last"].ToString()))
            {
                last = request["last"].ToString();
            }
            if (request.ContainsKey("email") && WifiUtils.IsValidEmail(request["email"].ToString()))
            {
                email = request["email"].ToString();
            }
            if (request.ContainsKey("password"))
            {
                password = request["password"].ToString();
            }
            if (request.ContainsKey("password2"))
            {
                password2 = request["password2"].ToString();
            }
            if (request.ContainsKey("avatar"))
            {
                avatar = request["avatar"].ToString();
            }

            Request req = WifiUtils.CreateRequest(resource, httpRequest);

            Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

            string result = m_WebApp.Services.NewAccountPostRequest(env, first, last, email, password, password2, avatar);

            return(WifiUtils.StringToBytes(result));
        }
        private byte[] UpdateAccount(string resource, IOSHttpRequest httpRequest, UUID userID, Dictionary <string, object> request)
        {
            try
            {
                string email        = String.Empty;
                string oldpassword  = String.Empty;
                string newpassword  = String.Empty;
                string newpassword2 = String.Empty;

                if (request.ContainsKey("email") && WifiUtils.IsValidEmail(request["email"].ToString()))
                {
                    email = request["email"].ToString();
                }
                if (request.ContainsKey("oldpassword"))
                {
                    oldpassword = request["oldpassword"].ToString();
                }
                if (request.ContainsKey("newpassword"))
                {
                    newpassword = request["newpassword"].ToString();
                }
                if (request.ContainsKey("newpassword2"))
                {
                    newpassword2 = request["newpassword2"].ToString();
                }

                Request req = WifiUtils.CreateRequest(resource, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

                string result = m_WebApp.Services.UserAccountPostRequest(env, userID, email, oldpassword, newpassword, newpassword2);

                return(WifiUtils.StringToBytes(result));
            }
            catch (Exception e)
            {
                Util.PrintCallStack();
                m_log.DebugFormat("[USER ACCOUNT POST HANDLER]: Exception {0}", e.StackTrace);
            }

            return(WifiUtils.FailureResult());
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);

            // This is the content type of the response. Don't forget to set it to this in all your handlers.
            httpResponse.ContentType = "text/html";

            string resource = GetParam(path);
            //m_log.DebugFormat("[XXX]: resource {0}", resource);
            Request request = WifiUtils.CreateRequest(resource, httpRequest);
            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            string result = string.Empty;
            if (resource.Equals("/") || resource.Equals(string.Empty))
                // client invoked /wifi/admin/users/ with no further parameters
                result = m_WebApp.Services.RegionManagementGetRequest(env);

            return WifiUtils.StringToBytes(result);

        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);

            // This is the content type of the response. Don't forget to set it to this in all your handlers.
            httpResponse.ContentType = "text/html";

            string resource = GetParam(path);
            //m_log.DebugFormat("[XXX]: resource {0}", resource);
            Request request = WifiUtils.CreateRequest(resource, httpRequest);
            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            string result = string.Empty;
            if (resource.Equals("/") || resource.Equals(string.Empty))
                // client invoked /wifi/admin/users/ with no further parameters
                result = m_WebApp.Services.UserManagementGetRequest(env);

            else if (resource.StartsWith("/edit"))
            {
                // client invoked /wifi/admin/users/edit, possibly with the UUID parameter after
                UUID userID = UUID.Zero;
                // SplitParams(path) returns an array of whatever parameters come after the path.
                // In this case it should return "edit" and "<uuid>"; we want "<uuid>", so [1]
                string[] pars = SplitParams(path);
                if (pars.Length >= 2)
                {
                    // indeed, client invoked /wifi/admin/users/edit/<uuid>
                    // let's grab that uuid 
                    UUID.TryParse(pars[1], out userID);
                    result = m_WebApp.Services.UserEditGetRequest(env, userID);
                }
            }

            return WifiUtils.StringToBytes(result);

        }
Пример #20
0
        byte[] LoginAgent(string resource, IOSHttpRequest httpRequest, Dictionary <string, object> request)
        {
            string first    = String.Empty;
            string last     = String.Empty;
            string password = String.Empty;

            if (!request.ContainsKey("firstname") || !request.ContainsKey("lastname") || !request.ContainsKey("password"))
            {
                return(WifiUtils.FailureResult());
            }

            first    = request["firstname"].ToString();
            last     = request["lastname"].ToString();
            password = request["password"].ToString();

            Request req = WifiUtils.CreateRequest(resource, httpRequest);

            Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

            string result = m_WebApp.Services.LoginRequest(env, first, last, password);

            return(WifiUtils.StringToBytes(result));
        }
        private byte[] CreateAccount(string resource, IOSHttpRequest httpRequest, Dictionary<string, object> request)
        {
            string first = String.Empty;
            string last = String.Empty;
            string email = String.Empty;
            string password = String.Empty;
            string password2 = String.Empty;
            string avatar = string.Empty;

            if (request.ContainsKey("first") && WifiUtils.IsValidName(request["first"].ToString()))
                first = request["first"].ToString();
            if (request.ContainsKey("last") && WifiUtils.IsValidName(request["last"].ToString()))
                last = request["last"].ToString();
            if (request.ContainsKey("email") && WifiUtils.IsValidEmail(request["email"].ToString()))
                email = request["email"].ToString();
            if (request.ContainsKey("password"))
                password = request["password"].ToString();
            if (request.ContainsKey("password2"))
                password2 = request["password2"].ToString();
            if (request.ContainsKey("avatar"))
            {
                avatar = request["avatar"].ToString();
            }

            Request req = WifiUtils.CreateRequest(resource, httpRequest);
            Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

            string result = m_WebApp.Services.NewAccountPostRequest(env, first, last, email, password, password2, avatar);

            return WifiUtils.StringToBytes(result);
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            StreamReader sr = new StreamReader(requestData);
            string body = sr.ReadToEnd();
            sr.Close();
            body = body.Trim();

            httpResponse.ContentType = "text/html";

            string resource = GetParam(path);

            try
            {
                Dictionary<string, object> request =
                        ServerUtils.ParseQueryString(body);

                string password = String.Empty;
                string password2 = String.Empty;

                if (request.ContainsKey("password"))
                    password = request["password"].ToString();
                if (request.ContainsKey("password2"))
                    password2 = request["password2"].ToString();

                Request req = WifiUtils.CreateRequest(string.Empty, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

                string result = m_WebApp.Services.InstallPostRequest(env, password, password2);

                return WifiUtils.StringToBytes(result);

            }
            catch (Exception e)
            {
                m_log.DebugFormat("[USER ACCOUNT POST HANDLER]: Exception {0}",  e);
            }

            return WifiUtils.FailureResult();

        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            StreamReader sr = new StreamReader(requestData);
            string body = sr.ReadToEnd();
            sr.Close();
            body = body.Trim();

            httpResponse.ContentType = "text/html";

            string resource = GetParam(path);
            try
            {
                string[] pars = SplitParams(path);
                if (pars.Length == 1) // /wifi/recover/token?email=email
                {
                    string token = pars[0];
                    if (httpRequest.Query.ContainsKey("email") && httpRequest.Query["email"] != null)
                    {
                        string email = HttpUtility.UrlDecode(httpRequest.Query["email"].ToString());
                        Request req = WifiUtils.CreateRequest(string.Empty, httpRequest);
                        Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

                        string result = m_WebApp.Services.RecoverPasswordGetRequest(env, email, token);

                        return WifiUtils.StringToBytes(result);
                    }
                    else
                        m_Log.DebugFormat("[PASSWORD RECOVER GET HANDLER]: Query part does not contain email variable");
                }
                else
                    m_Log.DebugFormat("[PASSWORD RECOVER GET HANDLER]: Path does not have 1 params, it has {0}", pars.Length);
            }
            catch (Exception e)
            {
                m_Log.DebugFormat("[PASSWORD RECOVER GET HANDLER]: Exception {0}", e);
            }

            return WifiUtils.FailureResult();
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            StreamReader sr = new StreamReader(requestData);
            string body = sr.ReadToEnd();
            sr.Close();
            body = body.Trim();

            httpResponse.ContentType = "text/html";

            string resource = GetParam(path);
            try
            {
                Dictionary<string, object> request =
                        ServerUtils.ParseQueryString(body);

                string token = String.Empty;
                if (request.ContainsKey("token"))
                    token = request["token"].ToString();
                string email = String.Empty;
                if (request.ContainsKey("email"))
                    email = request["email"].ToString();

                string newPassword = String.Empty;
                if (request.ContainsKey("newpassword"))
                    newPassword = request["newpassword"].ToString();

                Request req = WifiUtils.CreateRequest(string.Empty, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

                string result = m_WebApp.Services.RecoverPasswordPostRequest(env, email, token, newPassword);
                return WifiUtils.StringToBytes(result);
            }
            catch (Exception e)
            {
                m_Log.DebugFormat("[FORGOT PASSWORD POST HANDLER]: Exception {0}", e);
            }

            return WifiUtils.FailureResult();
        }
Пример #25
0
        byte[] LoginAgent(string resource, OSHttpRequest httpRequest, Dictionary<string, object> request)
        {
            string first = String.Empty;
            string last = String.Empty;
            string password = String.Empty;

            if (!request.ContainsKey("firstname") || !request.ContainsKey("lastname") || !request.ContainsKey("password"))
                return WifiUtils.FailureResult();

            first = request["firstname"].ToString();
            last = request["lastname"].ToString();
            password = request["password"].ToString();

            Request req;
            req.Cookies = httpRequest.Cookies;
            req.IPEndPoint = httpRequest.RemoteIPEndPoint;
            req.Query = httpRequest.Query;
            req.Resource = resource;
            Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

            string result = m_WebApp.Services.LoginRequest(env, first, last, password);

            return WifiUtils.StringToBytes(result);
        }
        public override byte[] Handle(string path, Stream requestData,
                IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            // It's a POST, so we need to read the data on the stream, the lines after the blank line
            StreamReader sr = new StreamReader(requestData);
            string body = sr.ReadToEnd();
            sr.Close();
            body = body.Trim();

            httpResponse.ContentType = "text/html";

            string resource = GetParam(path);
            //m_log.DebugFormat("[XXX]: query String: {0}; resource: {1}", body, resource);

            try
            {
                // Here the data on the stream is transformed into a nice dictionary of keys & values
                Dictionary<string, object> postdata =
                        ServerUtils.ParseQueryString(body);

                Request req = RequestFactory.CreateRequest(resource, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

                string result = string.Empty;
                if (resource.Equals("/") || resource.Equals(string.Empty))
                {
                    // The client invoked /wifi/admin/users/
                    string terms = String.Empty;
                    if (postdata.ContainsKey("terms"))
                        terms = postdata["terms"].ToString();

                    result = m_WebApp.Services.UserSearchPostRequest(env, terms);
                }
                else if (resource.StartsWith("/edit"))
                {
                    // The client invoked /wifi/admin/users/edit, possibly with the UUID parameter after
                    UUID userID = UUID.Zero;
                    string[] pars = SplitParams(path);
                    if ((pars.Length >= 2) && UUID.TryParse(pars[1], out userID))
                    {
                        // Indeed the client invoked /wifi/admin/users/edit/<uuid>, and we got it already in userID (above)
                        string form = string.Empty;
                        if (postdata.ContainsKey("form"))
                            form = postdata["form"].ToString();
                        if (form == "1")
                        {
                            string first = string.Empty, last = string.Empty, email = string.Empty, title = string.Empty;
                            int level = 0, flags = 0;
                            if (postdata.ContainsKey("first") && WebAppUtils.IsValidName(postdata["first"].ToString()))
                                first = postdata["first"].ToString();
                            if (postdata.ContainsKey("last") && WebAppUtils.IsValidName(postdata["last"].ToString()))
                                last = postdata["last"].ToString();
                            if (postdata.ContainsKey("email") && WebAppUtils.IsValidEmail(postdata["email"].ToString()))
                                email = postdata["email"].ToString();
                            if (postdata.ContainsKey("title"))
                                title = postdata["title"].ToString();
                            if (postdata.ContainsKey("level"))
                                Int32.TryParse(postdata["level"].ToString(), out level);
                            if (postdata.ContainsKey("flags"))
                                Int32.TryParse(postdata["flags"].ToString(), out flags);

                            result = m_WebApp.Services.UserEditPostRequest(env, userID, first, last, email, level, flags, title);
                        }
                        else if (form == "2")
                        {
                            string password = string.Empty;
                            if (postdata.ContainsKey("password"))
                            {
                                password = postdata["password"].ToString();
                                result = m_WebApp.Services.UserEditPostRequest(env, userID, password);
                            }
                        }
                    }
                }
                else if (resource.StartsWith("/delete"))
                {
                    // The client invoked /wifi/admin/users/edit, possibly with the UUID parameter after
                    UUID userID = UUID.Zero;
                    string[] pars = SplitParams(path);
                    if ((pars.Length >= 2) && UUID.TryParse(pars[1], out userID))
                    {
                        // Indeed the client invoked /wifi/admin/users/edit/<uuid>, and we got it already in userID (above)
                        string form = string.Empty;
                        if (postdata.ContainsKey("form"))
                            form = postdata["form"].ToString();
                        if (form == "1")
                                result = m_WebApp.Services.UserDeletePostRequest(env, userID);

                    }
                }

                return WebAppUtils.StringToBytes(result);

            }
            catch (Exception e)
            {
                m_log.DebugFormat("[USER ACCOUNT POST HANDLER]: Exception {0}",  e);
            }

            return WebAppUtils.FailureResult();
        }
Пример #27
0
        byte[] LoginAgent(string resource, IOSHttpRequest httpRequest, Dictionary<string, object> request)
        {
            string first = String.Empty;
            string last = String.Empty;
            string password = String.Empty;

            if (!request.ContainsKey("firstname") || !request.ContainsKey("lastname") || !request.ContainsKey("password"))
                return WebAppUtils.FailureResult();

            first = request["firstname"].ToString();
            last = request["lastname"].ToString();
            password = request["password"].ToString();

            Request req = RequestFactory.CreateRequest(resource, httpRequest);
            Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

            string result = m_WebApp.Services.LoginRequest(env, first, last, password);

            return WebAppUtils.StringToBytes(result);
        }
Пример #28
0
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);

            // This is the content type of the response. Don't forget to set it to this in all your handlers.
            httpResponse.ContentType = "text/html";

            string resource = GetParam(path);
            //m_log.DebugFormat("[XXX]: resource {0}", resource);
            Request request = RequestFactory.CreateRequest(resource, httpRequest);

            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            string result = string.Empty;

            if (resource.StartsWith("/edit"))
            {
                // client invoked /wifi/admin/users/edit, possibly with the UUID parameter after
                UUID userID = UUID.Zero;
                // SplitParams(path) returns an array of whatever parameters come after the path.
                // In this case it should return "edit" and "<uuid>"; we want "<uuid>", so [1]
                string[] pars = SplitParams(path);
                if (pars.Length >= 2)
                {
                    // indeed, client invoked /wifi/admin/users/edit/<uuid>
                    // let's grab that uuid
                    UUID.TryParse(pars[1], out userID);
                    result = m_WebApp.Services.UserEditGetRequest(env, userID);
                }
            }
            else if (resource.StartsWith("/delete"))
            {
                // client invoked /wifi/admin/users/delete, possibly with the UUID parameter after
                UUID userID = UUID.Zero;
                // SplitParams(path) returns an array of whatever parameters come after the path.
                // In this case it should return "delete" and "<uuid>"; we want "<uuid>", so [1]
                string[] pars = SplitParams(path);
                if (pars.Length >= 2)
                {
                    // indeed, client invoked /wifi/admin/users/delete/<uuid>
                    // let's grab that uuid
                    UUID.TryParse(pars[1], out userID);
                    result = m_WebApp.Services.UserDeleteGetRequest(env, userID);
                }
            }
            else if (resource.StartsWith("/activate"))
            {
                // client invoked /wifi/admin/users/activate, possibly with the UUID parameter after
                UUID userID = UUID.Zero;

                string[] pars = SplitParams(path);
                if (pars.Length >= 2)
                {
                    // indeed, client invoked /wifi/admin/users/activate/<uuid>
                    // let's grab that uuid
                    UUID.TryParse(pars[1], out userID);
                    result = m_WebApp.Services.UserActivateGetRequest(env, userID);
                }
            }

            if (string.IsNullOrEmpty(result))
            {
                result = m_WebApp.Services.UserManagementGetRequest(env);
            }

            return(WebAppUtils.StringToBytes(result));
        }
Пример #29
0
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            // It's a POST, so we need to read the data on the stream, the lines after the blank line
            StreamReader sr   = new StreamReader(requestData);
            string       body = sr.ReadToEnd();

            sr.Close();
            body = body.Trim();

            httpResponse.ContentType = "text/html";

            string resource = GetParam(path);

            //m_log.DebugFormat("[XXX]: query String: {0}; resource: {1}", body, resource);

            try
            {
                // Here the data on the stream is transformed into a nice dictionary of keys & values
                Dictionary <string, object> postdata =
                    ServerUtils.ParseQueryString(body);

                Request req = RequestFactory.CreateRequest(resource, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

                string result = string.Empty;
                if (resource.Equals("/") || resource.Equals(string.Empty))
                {
                    // The client invoked /wifi/admin/users/
                    string terms = String.Empty;
                    if (postdata.ContainsKey("terms"))
                    {
                        terms = postdata["terms"].ToString();
                    }

                    result = m_WebApp.Services.UserSearchPostRequest(env, terms);
                }
                else if (resource.StartsWith("/edit"))
                {
                    // The client invoked /wifi/admin/users/edit, possibly with the UUID parameter after
                    UUID     userID = UUID.Zero;
                    string[] pars   = SplitParams(path);
                    if ((pars.Length >= 2) && UUID.TryParse(pars[1], out userID))
                    {
                        // Indeed the client invoked /wifi/admin/users/edit/<uuid>, and we got it already in userID (above)
                        string form = string.Empty;
                        if (postdata.ContainsKey("form"))
                        {
                            form = postdata["form"].ToString();
                        }
                        if (form == "1")
                        {
                            string first = string.Empty, last = string.Empty, email = string.Empty, title = string.Empty;
                            int    level = 0, flags = 0;
                            if (postdata.ContainsKey("first") && WebAppUtils.IsValidName(postdata["first"].ToString()))
                            {
                                first = postdata["first"].ToString();
                            }
                            if (postdata.ContainsKey("last") && WebAppUtils.IsValidName(postdata["last"].ToString()))
                            {
                                last = postdata["last"].ToString();
                            }
                            if (postdata.ContainsKey("email") && WebAppUtils.IsValidEmail(postdata["email"].ToString()))
                            {
                                email = postdata["email"].ToString();
                            }
                            if (postdata.ContainsKey("title"))
                            {
                                title = postdata["title"].ToString();
                            }
                            if (postdata.ContainsKey("level"))
                            {
                                Int32.TryParse(postdata["level"].ToString(), out level);
                            }
                            if (postdata.ContainsKey("flags"))
                            {
                                Int32.TryParse(postdata["flags"].ToString(), out flags);
                            }

                            result = m_WebApp.Services.UserEditPostRequest(env, userID, first, last, email, level, flags, title);
                        }
                        else if (form == "2")
                        {
                            string password = string.Empty;
                            if (postdata.ContainsKey("password"))
                            {
                                password = postdata["password"].ToString();
                                result   = m_WebApp.Services.UserEditPostRequest(env, userID, password);
                            }
                        }
                    }
                }
                else if (resource.StartsWith("/delete"))
                {
                    // The client invoked /wifi/admin/users/edit, possibly with the UUID parameter after
                    UUID     userID = UUID.Zero;
                    string[] pars   = SplitParams(path);
                    if ((pars.Length >= 2) && UUID.TryParse(pars[1], out userID))
                    {
                        // Indeed the client invoked /wifi/admin/users/edit/<uuid>, and we got it already in userID (above)
                        string form = string.Empty;
                        if (postdata.ContainsKey("form"))
                        {
                            form = postdata["form"].ToString();
                        }
                        if (form == "1")
                        {
                            result = m_WebApp.Services.UserDeletePostRequest(env, userID);
                        }
                    }
                }

                return(WebAppUtils.StringToBytes(result));
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[USER ACCOUNT POST HANDLER]: Exception {0}", e);
            }

            return(WebAppUtils.FailureResult());
        }
        public override byte[] Handle(string path, Stream requestData,
                IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            // It's a POST, so we need to read the data on the stream, the lines after the blank line
            StreamReader sr = new StreamReader(requestData);
            string body = sr.ReadToEnd();
            sr.Close();
            body = body.Trim();

            httpResponse.ContentType = "text/html";

            string resource = GetParam(path);
            //m_log.DebugFormat("[XXX]: query String: {0}; resource: {1}", body, resource);

            try
            {
                // Here the data on the stream is transformed into a nice dictionary of keys & values
                Dictionary<string, object> postdata =
                        ServerUtils.ParseQueryString(body);

                string broadcast_message = String.Empty;
                    if (postdata.ContainsKey("message"))
                        broadcast_message = postdata["message"].ToString();

                Request req = RequestFactory.CreateRequest(resource, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

                string result = string.Empty;
                if (resource.Equals("/") || resource.Equals(string.Empty))
                {

                }
                else if (resource.StartsWith("/shutdown"))
                {
                    result = m_WebApp.Services.RegionManagementShutdownPostRequest(env);
                }
                else if (resource.StartsWith("/restart"))
                {
                    result = m_WebApp.Services.RegionManagementRestartPostRequest(env);
                }
                else if (resource.StartsWith("/broadcast"))
                {
                    result = m_WebApp.Services.RegionManagementBroadcastPostRequest(env, broadcast_message);
                }
                return WebAppUtils.StringToBytes(result);

            }
            catch (Exception e)
            {
                m_log.DebugFormat("[REGION MANAGEMENT POST HANDLER]: Exception {0}", e);
            }

            return WebAppUtils.FailureResult();
        }
        private byte[] UpdateAccount(string resource, IOSHttpRequest httpRequest, UUID userID, Dictionary<string, object> request)
        {
            try
            {
                string email = String.Empty;
                string oldpassword = String.Empty;
                string newpassword = String.Empty;
                string newpassword2 = String.Empty;

                if (request.ContainsKey("email") && WifiUtils.IsValidEmail(request["email"].ToString()))
                    email = request["email"].ToString();
                if (request.ContainsKey("oldpassword"))
                    oldpassword = request["oldpassword"].ToString();
                if (request.ContainsKey("newpassword"))
                    newpassword = request["newpassword"].ToString();
                if (request.ContainsKey("newpassword2"))
                    newpassword2 = request["newpassword2"].ToString();

                Request req = WifiUtils.CreateRequest(resource, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(req);

                string result = m_WebApp.Services.UserAccountPostRequest(env, userID, email, oldpassword, newpassword, newpassword2);

                return WifiUtils.StringToBytes(result);

            }
            catch (Exception e)
            {
                Util.PrintCallStack();
                m_log.DebugFormat("[USER ACCOUNT POST HANDLER]: Exception {0}", e.StackTrace);
            }

            return WifiUtils.FailureResult();
        }