Ejemplo n.º 1
0
        public string ForgotPasswordPostRequest(Environment env, string email)
        {
            UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero, email);

            if (account != null)
            {
                string token = m_AuthenticationService.GetToken(account.PrincipalID, 60);
                if (token != string.Empty)
                {
                    string url = m_WebApp.WebAddress + "/wifi/recover/" + token + "?email=" + HttpUtility.UrlEncode(email);

                    string message = string.Format("\n{0}\n{1}\n{2}",
                                                   string.Format(_("Your account is {0} {1}", env), account.FirstName, account.LastName),
                                                   _("Click here to reset your password:"******"Password Reset", env), message))
                    {
                        NotifyWithoutButton(env, _("Check your email. You must reset your password within 60 minutes.", env));
                    }
                    else
                    {
                        NotifyWithoutButton(env, _("Email could not be sent.", env));
                    }

                    return(m_WebApp.ReadFile(env, "index.html"));
                }
            }

            return(m_WebApp.ReadFile(env, "index.html"));
        }
Ejemplo n.º 2
0
        public string GetMainMenu(Environment env)
        {
            if (!m_WebApp.IsInstalled)
            {
                return(m_WebApp.ReadFile(env, "main-menu-install.html"));
            }

            SessionInfo sinfo = env.Session;

            if (sinfo.Account != null)
            {
                if (sinfo.Account.UserLevel >= m_WebApp.AdminUserLevel) // Admin
                {
                    return(m_WebApp.ReadFile(env, "main-menu-admin.html"));
                }
                else if (sinfo.Account.UserLevel >= m_WebApp.HyperlinksUserLevel) // Privileged user
                {
                    return(m_WebApp.ReadFile(env, "main-menu-privileged.html"));
                }

                return(m_WebApp.ReadFile(env, "main-menu-users.html", env.Data));
            }

            return(m_WebApp.ReadFile(env, "main-menu.html", env.Data));
        }
        public string RegionManagementGetRequest(Environment env)
        {
            m_log.DebugFormat("[Services]: RegionManagementGetRequest()");
            Request request = env.Request;

            SessionInfo sinfo;

            if (TryGetSessionInfo(request, out sinfo) &&
                (sinfo.Account.UserLevel >= m_WebApp.AdminUserLevel))
            {
                List <GridRegion> regions = m_GridService.GetRegionsByName(UUID.Zero, "", 200);

                m_log.DebugFormat("[Services]: There are {0} regions", regions.Count);
                regions.ForEach(delegate(GridRegion gg)
                {
                    m_log.DebugFormat("[Services] {0}", gg.RegionName);
                });

                env.Session = sinfo;
                env.Data    = Objectify(regions);
                env.Flags   = Flags.IsAdmin | Flags.IsLoggedIn;
                env.State   = State.RegionManagementForm;
                return(PadURLs(env, sinfo.Sid, m_WebApp.ReadFile(env, "index.html")));
            }
            else
            {
                return(m_WebApp.ReadFile(env, "index.html"));
            }
        }
Ejemplo n.º 4
0
        private string PadURLs(Environment env, string sid, string html)
        {
            if ((env.Flags & Flags.IsLoggedIn) == 0)
            {
                return(html);
            }

            // The user is logged in
            HashSet <string> uris = new HashSet <string>();

            CollectMatches(uris, href.Matches(html));
            CollectMatches(uris, action.Matches(html));
            CollectMatches(uris, xmlhttprequest.Matches(html));

            foreach (string uri in uris)
            {
                string uri2 = uri.Substring(0, uri.Length - 1);
                //m_log.DebugFormat("[Wifi]: replacing {0} with {1}", uri, uri2 + "?sid=" + sid + "\"");
                if (!uri.EndsWith("/"))
                {
                    html = html.Replace(uri, uri2 + "/?sid=" + sid + "\"");
                }
                else
                {
                    html = html.Replace(uri, uri2 + "?sid=" + sid + "\"");
                }
            }
            // Remove any @@wifi@@
            html = html.Replace("@@wifi@@", string.Empty);

            return(html);
        }
Ejemplo n.º 5
0
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            // 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("[NOTIFY HANDLER]: resource {1}", resource);
            Request request = WifiUtils.CreateRequest(resource, httpRequest);

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

            string result = string.Empty;

            try
            {
                result = m_WebApp.Services.NotifyRequest(env);
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[NOTIFY HANDLER]: Exception {0}: {1}", e.Message, e.StackTrace);
            }

            return(WifiUtils.StringToBytes(result));
        }
        public string ForgotPasswordPostRequest(Environment env, string email)
        {
            UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero, email);
            if (account != null)
            {
                string token = m_AuthenticationService.GetToken(account.PrincipalID, 60);
                if (token != string.Empty)
                {
                    string url = m_WebApp.WebAddress + "/wifi/recover/" + token + "?email=" + HttpUtility.UrlEncode(email);

                    string message = string.Format("\n{0}\n{1}\n{2}",
                        string.Format(_("Your account is {0} {1}", env), account.FirstName, account.LastName),
                        _("Click here to reset your password:"******"Password Reset", env), message))
                        NotifyWithoutButton(env, _("Check your email. You must reset your password within 60 minutes.", env));
                    else
                        NotifyWithoutButton(env, _("Email could not be sent.", env));

                    return m_WebApp.ReadFile(env, "index.html");
                }
            }

            return m_WebApp.ReadFile(env, "index.html");
        }
Ejemplo n.º 7
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";
            string resource = GetParam(path);
            //m_log.DebugFormat("[INVENTORY HANDLER POST]: resource {0}", resource);

            StreamReader sr   = new StreamReader(requestData);
            string       body = sr.ReadToEnd();

            sr.Close();
            body = body.Trim();
            Dictionary <string, object> postdata =
                ServerUtils.ParseQueryString(body);

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

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

            string action = postdata.Keys.FirstOrDefault(key => key.StartsWith("action-"));

            if (action == null)
            {
                action = string.Empty;
            }
            else
            {
                action = action.Substring("action-".Length);
            }

            string        folder        = string.Empty;
            string        newFolderName = string.Empty;
            List <string> nodes         = new List <string>();
            List <string> types         = new List <string>();

            if (postdata.ContainsKey("folder"))
            {
                folder = postdata["folder"].ToString();
            }
            if (postdata.ContainsKey("newFolderName"))
            {
                newFolderName = postdata["newFolderName"].ToString();
            }
            foreach (KeyValuePair <string, object> kvp in postdata)
            {
                if (kvp.Key.StartsWith("inv-"))
                {
                    nodes.Add(kvp.Key.Substring(4));
                    types.Add(kvp.Value.ToString());
                }
            }

            return(WifiUtils.StringToBytes(m_WebApp.Services.InventoryPostRequest(env, action, folder, newFolderName, nodes, types)));
        }
Ejemplo n.º 8
0
        public string GetHyperlinks(Environment env)
        {
            if (env.Data != null && env.Data.Count > 0)
            {
                return(m_WebApp.ReadFile(env, "linkregionlist.html", env.Data));
            }

            return(_("No linked regions found", env));
        }
Ejemplo n.º 9
0
        private string GetUserList(Environment env)
        {
            if (env.Data != null && env.Data.Count > 0)
            {
                return(m_WebApp.ReadFile(env, "userlist.html", env.Data));
            }

            return(_("No users found", env));
        }
Ejemplo n.º 10
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 resource = GetParam(path);
            //m_log.DebugFormat("[Wifi]: resource {0}", resource);
            resource = Uri.UnescapeDataString(resource).Trim(WifiUtils.DirectorySeparatorChars);

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

            if (resource == string.Empty || resource.StartsWith("index."))
            {
                if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero)
                    m_WebApp.Services.ComputeStatistics();

                httpResponse.ContentType = "text/html";

                return WifiUtils.StringToBytes(m_WebApp.Services.DefaultRequest(env));
            }
            else
            {
                string resourcePath = System.IO.Path.Combine(WifiUtils.DocsPath, resource);
                string type = WifiUtils.GetContentType(resource);
                httpResponse.ContentType = type;
                //m_log.DebugFormat("[Wifi]: ContentType {0}", type);
                if (type.StartsWith("image"))
                    return WifiUtils.ReadBinaryResource(resourcePath);

                if (type.StartsWith("application"))
                {
                    string res = WifiUtils.ReadTextResource(resourcePath, true);
                    return WifiUtils.StringToBytes(res);
                }
                if (type.StartsWith("text"))
                {
                    if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero)
                        m_WebApp.Services.ComputeStatistics();

                    resourcePath = Localization.LocalizePath(env, resource);
                    Processor p = new Processor(m_WebApp.WifiScriptFace, env);
                    string res = p.Process(WifiUtils.ReadTextResource(resourcePath));
                    if (res == string.Empty)
                        res = m_WebApp.Services.DefaultRequest(env);
                    return WifiUtils.StringToBytes(res);
                }
            }

            httpResponse.ContentType = "text/plain";
            string result = "Boo!";
            return WifiUtils.StringToBytes(result);
        }
Ejemplo n.º 11
0
        private string GetRegionManagementForm(Environment env)
        {
            if (env.Data != null && env.Data.Count > 0)
            {
                return(m_WebApp.ReadFile(env, "region-form.html", env.Data));
            }

            return(_("No regions found", env));
        }
Ejemplo n.º 12
0
        private string PadURLs(Environment env, string sid, string html)
        {
            if ((env.Flags & Flags.IsLoggedIn) == 0)
            {
                return(html);
            }

            return(WebAppUtils.PadURLs(sid, html));
        }
Ejemplo n.º 13
0
        public string GetUserName(Environment env)
        {
            SessionInfo sinfo = env.Session;

            if (sinfo.Account != null)
            {
                return(sinfo.Account.FirstName + " " + sinfo.Account.LastName);
            }

            return(_("Who are you?", env));
        }
Ejemplo n.º 14
0
        public string GetConsolePass(Environment env)
        {
            SessionInfo sinfo = env.Session;

            if (sinfo.Account != null && sinfo.Account.UserLevel >= m_WebApp.AdminUserLevel)
            {
                return(m_WebApp.ConsolePass);
            }

            return(string.Empty);
        }
Ejemplo n.º 15
0
        public string GetNotificationType(Environment env)
        {
            SessionInfo sinfo = env.Session;

            if (sinfo.Notify.FollowUp == null)
            {
                return("hidden");
            }

            return("submit");
        }
Ejemplo n.º 16
0
        public string GetPendingUserList(Environment env)
        {
            SessionInfo sinfo = env.Session;

            if (env.Data != null && env.Data.Count > 0 &&
                sinfo.Account != null && sinfo.Account.UserLevel >= m_WebApp.AdminUserLevel)
            {
                return(m_WebApp.ReadFile(env, "userpendinglist.html", env.Data));
            }

            return(string.Empty);
        }
Ejemplo n.º 17
0
        public string GetUserImage(Environment env)
        {
            SessionInfo sinfo = env.Session;

            if (sinfo.Account != null)
            {
                // TODO
                return("/wifi/images/abstract-cool.jpg");
            }

            // TODO
            return("/wifi/images/abstract-cool.jpg");
        }
Ejemplo n.º 18
0
        public string RecoverPasswordPostRequest(Environment env, string email, string token, string newPassword)
        {
            if (newPassword == null || newPassword.Length < 3)
            {
                env.State = State.RecoveringPassword;
                return(m_WebApp.ReadFile(env, "index.html"));
            }

            ResetPassword(email, token, newPassword);
            NotifyWithoutButton(env, _("Your password has been reset.", env));

            return(m_WebApp.ReadFile(env, "index.html"));
        }
Ejemplo n.º 19
0
        /*
         * private void PrintStr(string html)
         * {
         *  foreach (char c in html)
         *      Console.Write(c);
         * }
         */
        private List <object> GetUserList(Environment env, string terms)
        {
            List <UserAccount> accounts = m_UserAccountService.GetUserAccounts(UUID.Zero, terms);

            if (accounts != null && accounts.Count > 0)
            {
                return(Objectify <UserAccount>(accounts));
            }
            else
            {
                return(new List <object>());
            }
        }
Ejemplo n.º 20
0
        public string GetRefresh(Environment env)
        {
            const string redirect = "<meta http-equiv=\"refresh\" content=\"{0}; URL={1}/?sid={2}\" />";

            if (env.State == State.Notification)
            {
                SessionInfo sinfo = env.Session;
                if (sinfo.Sid != null && sinfo.Notify.RedirectDelay >= 0)
                {
                    return(string.Format(redirect, sinfo.Notify.RedirectDelay, sinfo.Notify.RedirectUrl, sinfo.Sid));
                }
            }
            return(string.Empty);
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            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);

            string result = m_WebApp.Services.InventoryLoadGetRequest(env);
            httpResponse.ContentType = "text/html";

            return WifiUtils.StringToBytes(result);
        }
        private List <object> GetRegionList(Environment env)
        {
            List <GridRegion> regions = m_GridService.GetRegionsByName(UUID.Zero, "", 100);

            if (regions != null)
            {
                m_log.DebugFormat("[Wifi]: GetRegionList found {0} users in DB", regions.Count);
                return(Objectify <GridRegion>(regions));
            }
            else
            {
                m_log.DebugFormat("[Wifi]: GetRegionList got null regions from DB");
                return(new List <object>());
            }
        }
        public string RegionManagementRestartPostRequest(Environment env)
        {
            Request     request = env.Request;
            SessionInfo sinfo;

            if (TryGetSessionInfo(request, out sinfo) &&
                (sinfo.Account.UserLevel >= m_WebApp.AdminUserLevel))
            {
                env.Session = sinfo;

                string url = m_WebApp.LoginURL;

                Hashtable hash = new Hashtable();
                if (m_ServerAdminPassword == null)
                {
                    m_log.Debug("[RegionManagementRestartPostRequest] No remote admin password was set in .ini file");
                }

                hash["password"] = m_ServerAdminPassword;
                IList paramList = new ArrayList();
                paramList.Add(hash);
                XmlRpcRequest xmlrpcReq = new XmlRpcRequest("admin_shutdown", paramList);

                XmlRpcResponse response = null;
                try
                {
                    //first, shutdown the server
                    response = xmlrpcReq.Send(url, 10000);

                    //then wait until the server is completely shutdown, then re-launch
                    System.Diagnostics.Process[] openSimProcess = System.Diagnostics.Process.GetProcessesByName("OpenSim");
                    openSimProcess[0].WaitForExit();
                    System.Diagnostics.Process.Start("OpenSim.exe");
                    env.Flags = Flags.IsAdmin | Flags.IsLoggedIn;
                    env.State = State.RegionManagementSuccessful;
                }
                catch (Exception e)
                {
                    m_log.Debug("[Wifi]: Exception " + e.Message);
                    env.Flags = Flags.IsAdmin | Flags.IsLoggedIn;
                    env.State = State.RegionManagementUnsuccessful;
                }

                return(PadURLs(env, sinfo.Sid, m_WebApp.ReadFile(env, "index.html")));
            }

            return(m_WebApp.ReadFile(env, "index.html"));
        }
Ejemplo n.º 24
0
        public string GetLoginLogout(Environment env)
        {
            if (!m_WebApp.IsInstalled)
            {
                return(string.Empty);
            }

            SessionInfo sinfo = env.Session;

            if (sinfo.Account != null)
            {
                return(m_WebApp.ReadFile(env, "logout.html", env.Data));
            }

            return(m_WebApp.ReadFile(env, "login.html", env.Data));
        }
Ejemplo n.º 25
0
        public string GetUserEmail(Environment env)
        {
            SessionInfo sinfo = env.Session;

            if (sinfo.Account != null)
            {
                if (sinfo.Account.Email == string.Empty)
                {
                    return(_("No email on file", env));
                }

                return(sinfo.Account.Email);
            }

            return(_("Who are you?", env));
        }
Ejemplo n.º 26
0
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            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);

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

            httpResponse.ContentType = "text/html";

            return(WifiUtils.StringToBytes(result));
        }
        public string RegionManagementShutdownPostRequest(Environment env)
        {
            //m_log.DebugFormat("[Wifi]: RegionManagementShutdownPostRequest");
            Request request = env.Request;

            SessionInfo sinfo;

            if (TryGetSessionInfo(request, out sinfo) &&
                (sinfo.Account.UserLevel >= m_WebApp.AdminUserLevel))
            {
                env.Session = sinfo;

                //FIXME: don't hardcode url, get it from m_GridService
                //TODO: check if server is actually running first
                //TODO: add support for shutdown message parameter from html form
                string    url  = m_WebApp.LoginURL;
                Hashtable hash = new Hashtable();
                if (m_ServerAdminPassword == null)
                {
                    m_log.Debug("[RegionManagementShutdownPostRequest] No remote admin password was set in .ini file");
                }

                hash["password"] = m_ServerAdminPassword;
                IList paramList = new ArrayList();
                paramList.Add(hash);
                XmlRpcRequest xmlrpcReq = new XmlRpcRequest("admin_shutdown", paramList);

                XmlRpcResponse response = null;
                try
                {
                    response  = xmlrpcReq.Send(url, 10000);
                    env.Flags = Flags.IsAdmin | Flags.IsLoggedIn;
                    env.State = State.RegionManagementSuccessful;
                }
                catch (Exception e)
                {
                    m_log.Debug("[Wifi]: Exception " + e.Message);
                    env.Flags = Flags.IsAdmin | Flags.IsLoggedIn;
                    env.State = State.RegionManagementUnsuccessful;
                }

                return(PadURLs(env, sinfo.Sid, m_WebApp.ReadFile(env, "index.html")));
            }

            return(m_WebApp.ReadFile(env, "index.html"));
        }
Ejemplo n.º 28
0
        public string RecoverPasswordGetRequest(Environment env, string email, string token)
        {
            UserAccount account = null;

            if (IsValidToken(email, token, out account))
            {
                PasswordRecoveryData precovery = new PasswordRecoveryData(email, token);
                env.Data = new List <object>();
                env.Data.Add(precovery);
                env.State = State.RecoveringPassword;
                return(m_WebApp.ReadFile(env, "index.html"));
            }
            else
            {
                return("<p>" + _("Invalid token.", env) + "</p>");
            }
        }
        public string RegionManagementBroadcastPostRequest(Environment env, string message)
        {
            Request request = env.Request;

            SessionInfo sinfo;

            if (TryGetSessionInfo(request, out sinfo) &&
                (sinfo.Account.UserLevel >= m_WebApp.AdminUserLevel))
            {
                env.Session = sinfo;

                string    url  = m_WebApp.LoginURL;
                Hashtable hash = new Hashtable();
                if (m_ServerAdminPassword == null)
                {
                    m_log.Debug("[RegionManagementBroadcastPostRequest] No remote admin password was set in .ini file");
                }

                hash["password"] = m_ServerAdminPassword;
                hash["message"]  = message;
                IList paramList = new ArrayList();
                paramList.Add(hash);
                XmlRpcRequest xmlrpcReq = new XmlRpcRequest("admin_broadcast", paramList);

                XmlRpcResponse response = null;
                try
                {
                    response  = xmlrpcReq.Send(url, 10000);
                    env.Flags = Flags.IsAdmin | Flags.IsLoggedIn;
                    env.State = State.RegionManagementSuccessful;
                }
                catch (Exception e)
                {
                    m_log.Debug("[Wifi]: Exception " + e.Message);
                    env.Flags = Flags.IsAdmin | Flags.IsLoggedIn;
                    env.State = State.RegionManagementUnsuccessful;
                }

                return(PadURLs(env, sinfo.Sid, m_WebApp.ReadFile(env, "index.html")));
            }

            return(m_WebApp.ReadFile(env, "index.html"));
        }
Ejemplo n.º 30
0
        public string ReadFile(Environment env, string path, List <object> lot)
        {
            string file = Localization.LocalizePath(env, path);

            try
            {
                using (StreamReader sr = new StreamReader(file))
                {
                    string    content = sr.ReadToEnd();
                    Processor p       = new Processor(WifiScriptFace, m_ExtensionMethods, env, lot);
                    return(p.Process(content));
                }
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[Wifi]: Exception on ReadFile {0}: {1}", path, e);
                return(string.Empty);
            }
        }
        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("[INVENTORY HANDLER HANDLER GET]: resource {0}", resource);

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

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

            return WebAppUtils.StringToBytes(result);
        }
        public string RegionManagementBroadcastPostRequest(Environment env, string message)
        {
            Request request = env.Request;

            SessionInfo sinfo;
            if (TryGetSessionInfo(request, out sinfo) &&
                (sinfo.Account.UserLevel >= m_WebApp.AdminUserLevel))
            {
                env.Session = sinfo;

                string url = m_WebApp.LoginURL;
                Hashtable hash = new Hashtable();
                if (m_ServerAdminPassword == null)
                {
                    m_log.Debug("[RegionManagementBroadcastPostRequest] No remote admin password was set in .ini file");
                }

                hash["password"] = m_ServerAdminPassword;
                hash["message"] = message;
                IList paramList = new ArrayList();
                paramList.Add(hash);
                XmlRpcRequest xmlrpcReq = new XmlRpcRequest("admin_broadcast", paramList);

                XmlRpcResponse response = null;
                try
                {
                    response = xmlrpcReq.Send(url, 10000);
                    env.Flags = Flags.IsAdmin | Flags.IsLoggedIn;
                    env.State = State.RegionManagementSuccessful;
                }
                catch (Exception e)
                {
                    m_log.Debug("[Wifi]: Exception " + e.Message);
                    env.Flags = Flags.IsAdmin | Flags.IsLoggedIn;
                    env.State = State.RegionManagementUnsuccessful;
                }

                return PadURLs(env, sinfo.Sid, m_WebApp.ReadFile(env, "index.html"));
            }

            return m_WebApp.ReadFile(env, "index.html");
        }
Ejemplo n.º 33
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 resource = GetParam(path);
            m_log.DebugFormat("[Wifi]: resource {0}", resource);
            resource = resource.Trim(new char[] { '/' });

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

            if (resource == string.Empty || resource.StartsWith("index."))
            {
                httpResponse.ContentType = "text/html";
                string resourcePath = System.IO.Path.Combine(WifiUtils.DocsPath, "index.html");
                Processor p = new Processor(m_WebApp.WifiScriptFace, env);
                return WifiUtils.StringToBytes(p.Process(WifiUtils.ReadTextResource(resourcePath)));
            }
            else
            {
                string resourcePath = System.IO.Path.Combine(WifiUtils.DocsPath, resource);
                string type = WifiUtils.GetContentType(resource);
                httpResponse.ContentType = type;
                if (type.StartsWith("image"))
                    return WifiUtils.ReadBinaryResource(resourcePath);

                if (type.StartsWith("text"))
                {
                    Processor p = new Processor(m_WebApp.WifiScriptFace, env);
                    return WifiUtils.StringToBytes(p.Process(WifiUtils.ReadTextResource(resourcePath)));
                }
            }

            httpResponse.ContentType = "text/plain";
            string result = "Boo!";
            return WifiUtils.StringToBytes(result);
        }
Ejemplo n.º 34
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";
            string resource = GetParam(path);
            //m_log.DebugFormat("[INVENTORY HANDLER HANDLER GET]: resource {0}", resource);

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

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

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

            return(WifiUtils.StringToBytes(result));
        }
Ejemplo n.º 35
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("[HYPERLINK GET HANDLER]: resource {0}", resource);
            Request request = WifiUtils.CreateRequest(resource, httpRequest);

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

            string result = string.Empty;

            if (resource.StartsWith("/delete"))
            {
                // client invoked /wifi/linkregion/delete, possibly with the UUID parameter after
                UUID regionID = 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/linkregion/delete/<uuid>
                    // let's grab that uuid
                    UUID.TryParse(pars[1], out regionID);
                    result = m_WebApp.Services.HyperlinkDeleteGetRequest(env, regionID);
                }
            }

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

            return(WifiUtils.StringToBytes(result));
        }
Ejemplo n.º 36
0
        public override byte[] Handle(string path, Stream requestData,
                IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            // 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("[NOTIFY HANDLER]: resource {1}", resource);
            Request request = WifiUtils.CreateRequest(resource, httpRequest);
            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            string result = string.Empty;
            try
            {
                result = m_WebApp.Services.NotifyRequest(env);
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[NOTIFY 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);

            // 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("[HYPERLINK GET HANDLER]: resource {0}", resource);
            Request request = WifiUtils.CreateRequest(resource, httpRequest);
            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            string result = string.Empty;
            if (resource.StartsWith("/delete"))
            {
                // client invoked /wifi/linkregion/delete, possibly with the UUID parameter after
                UUID regionID = 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/linkregion/delete/<uuid>
                    // let's grab that uuid
                    UUID.TryParse(pars[1], out regionID);
                    result = m_WebApp.Services.HyperlinkDeleteGetRequest(env, regionID);
                }
            }

            if (string.IsNullOrEmpty(result))
                result = m_WebApp.Services.HyperlinkGetRequest(env);

            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("[HYPERLINK POST HANDLER]: 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 request = WifiUtils.CreateRequest(resource, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

                string result = string.Empty;
                if (resource.StartsWith("/add"))
                {
                    // The client invoked /wifi/linkregion/add
                    string address = string.Empty;
                    uint xloc = 0, yloc = 0;
                    if (postdata.ContainsKey("address"))
                        address = postdata["address"].ToString();
                    if (postdata.ContainsKey("xloc"))
                        UInt32.TryParse(postdata["xloc"].ToString(), out xloc);
                    if (postdata.ContainsKey("yloc"))
                        UInt32.TryParse(postdata["yloc"].ToString(), out yloc);

                    result = m_WebApp.Services.HyperlinkAddRequest(env, address, xloc, yloc);
                }
                else if (resource.StartsWith("/delete"))
                {
                    // The client invoked /wifi/linkregion/delete, possibly with the UUID parameter after
                    UUID regionID = UUID.Zero;
                    string[] pars = SplitParams(path);
                    if ((pars.Length >= 2) && UUID.TryParse(pars[1], out regionID))
                    {
                        // Indeed the client invoked /wifi/linkregion/delete/<uuid>, and we got it already in regionID (above)
                        result = m_WebApp.Services.HyperlinkDeletePostRequest(env, regionID);
                    }
                }
                return WifiUtils.StringToBytes(result);
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[HYPERLINK POST HANDLER]: Exception {0}",  e);
            }

            return WifiUtils.FailureResult();
        }
Ejemplo n.º 39
0
        public string GetUserImage(Environment env)
        {
            SessionInfo sinfo = env.Session;
            if (sinfo.Account != null)
            {
                // TODO
                return "/wifi/images/abstract-cool.jpg";
            }

            // TODO
            return "/wifi/images/abstract-cool.jpg";
        }
        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("[INVENTORY HANDLER POST]: resource {0}", resource);

            StreamReader sr = new StreamReader(requestData);
            string body = sr.ReadToEnd();
            sr.Close();
            body = body.Trim();
            Dictionary<string, object> postdata =
                    ServerUtils.ParseQueryString(body);

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

            string action = postdata.Keys.FirstOrDefault(key => key.StartsWith("action-"));
            if (action == null)
                action = string.Empty;
            else
                action = action.Substring("action-".Length);

            string folder = string.Empty;
            string newFolderName = string.Empty;
            List<string> nodes = new List<string>();
            List<string> types = new List<string>();

            if (postdata.ContainsKey("folder"))
                folder = postdata["folder"].ToString();
            if (postdata.ContainsKey("newFolderName"))
                newFolderName = postdata["newFolderName"].ToString();
            foreach (KeyValuePair<string, object> kvp in postdata)
            {
                if (kvp.Key.StartsWith("inv-"))
                {
                    nodes.Add(kvp.Key.Substring(4));
                    types.Add(kvp.Value.ToString());
                }
            }

            return WebAppUtils.StringToBytes(m_WebApp.Services.InventoryPostRequest(env, action, folder, newFolderName, nodes, types));
        }
Ejemplo n.º 41
0
 public string ReadFile(Environment env, string path, List<object> lot)
 {
     string file = Localization.LocalizePath(env, path);
     try
     {
         using (StreamReader sr = new StreamReader(file))
         {
             string content = sr.ReadToEnd();
             Processor p = new Processor(WifiScriptFace, m_ExtensionMethods, env, lot);
             return p.Process(content);
         }
     }
     catch (Exception e)
     {
         m_log.DebugFormat("[Wifi]: Exception on ReadFile {0}: {1}", path, e);
         return string.Empty;
     }
 }
        public string RecoverPasswordPostRequest(Environment env, string email, string token, string newPassword)
        {
            if (newPassword == null || newPassword.Length < 3)
            {
                env.State = State.RecoveringPassword;
                return m_WebApp.ReadFile(env, "index.html");
            }

            ResetPassword(email, token, newPassword);
            NotifyWithoutButton(env, _("Your password has been reset.", env));

            return m_WebApp.ReadFile(env, "index.html");
        }
Ejemplo n.º 43
0
        public string GetPendingUserList(Environment env)
        {
            SessionInfo sinfo = env.Session;
            if (env.Data != null && env.Data.Count > 0 &&
                sinfo.Account != null && sinfo.Account.UserLevel >= m_WebApp.AdminUserLevel)
                return m_WebApp.ReadFile(env, "userpendinglist.html", env.Data);

            return string.Empty;
        }
Ejemplo n.º 44
0
        public string GetRefresh(Environment env)
        {
            const string redirect = "<meta http-equiv=\"refresh\" content=\"{0}; URL={1}/?sid={2}\" />";

            if (env.State == State.Notification)
            {
                SessionInfo sinfo = env.Session;
                if (sinfo.Sid != null && sinfo.Notify.RedirectDelay >= 0)
                    return string.Format(redirect, sinfo.Notify.RedirectDelay, sinfo.Notify.RedirectUrl, sinfo.Sid);
            }
            return string.Empty;
        }
Ejemplo n.º 45
0
        private string GetUserList(Environment env)
        {
            if (env.Data != null && env.Data.Count > 0)
                return m_WebApp.ReadFile(env, "userlist.html", env.Data);

            return _("No users found", env);
        }
Ejemplo n.º 46
0
        private string GetRegionManagementForm(Environment env)
        {
            if (env.Data != null && env.Data.Count > 0)
                return m_WebApp.ReadFile(env, "region-form.html", env.Data);

            return _("No regions found", env);
        }
Ejemplo n.º 47
0
 private static string _(string textId, Environment env)
 {
     return Localization.Translate(env, textId);
 }
Ejemplo n.º 48
0
        public string GetUserName(Environment env)
        {
            SessionInfo sinfo = env.Session;
            if (sinfo.Account != null)
            {
                return sinfo.Account.FirstName + " " + sinfo.Account.LastName;
            }

            return _("Who are you?", env);
        }
 public string ForgotPasswordGetRequest(Environment env)
 {
     m_log.DebugFormat("[Wifi]: ForgotPasswordGetRequest");
     env.State = State.ForgotPassword;
     return m_WebApp.ReadFile(env, "index.html");
 }
Ejemplo n.º 50
0
        public string GetLoginLogout(Environment env)
        {
            if (!m_WebApp.IsInstalled)
                return string.Empty;

            SessionInfo sinfo = env.Session;
            if (sinfo.Account != null)
                return m_WebApp.ReadFile(env, "logout.html", env.Data);

            return m_WebApp.ReadFile(env, "login.html", env.Data);
        }
 public string RecoverPasswordGetRequest(Environment env, string email, string token)
 {
     UserAccount account = null;
     if (IsValidToken(email, token, out account))
     {
         PasswordRecoveryData precovery = new PasswordRecoveryData(email, token);
         env.Data = new List<object>();
         env.Data.Add(precovery);
         env.State = State.RecoveringPassword;
         return m_WebApp.ReadFile(env, "index.html");
     }
     else
     {
         return "<p>" + _("Invalid token.", env) + "</p>";
     }
 }
Ejemplo n.º 52
0
        public string GetHyperlinks(Environment env)
        {
            if (env.Data != null && env.Data.Count > 0)
                return m_WebApp.ReadFile(env, "linkregionlist.html", env.Data);

            return _("No linked regions found", env);
        }
Ejemplo n.º 53
0
 public string ReadFile(Environment env, string path)
 {
     return ReadFile(env, path, env.Data);
 }
Ejemplo n.º 54
0
        public string GetContent(Environment env)
        {
            //m_log.DebugFormat("[WifiScriptFace]: GetContent, flags {0} ({1})", env.State, (uint)env.State);

            if (env.State == State.InstallForm)
                return m_WebApp.ReadFile(env, "installform.html");

            if (env.State == State.ForgotPassword)
                return m_WebApp.ReadFile(env, "forgotpasswordform.html");
            if (env.State == State.RecoveringPassword)
                return m_WebApp.ReadFile(env, "recoveringpassword.html");
            //if (env.State == State.BadPassword)
            //    return "<p>The password must be at least 3 characters.</p>";

            if (env.State == State.NewAccountForm || env.State == State.NewAccountFormRetry)
                return m_WebApp.ReadFile(env, "newaccountform.html", env.Data);

            if (env.State == State.Notification)
                return m_WebApp.ReadFile(env, "notification.html", env.Data);

            if ((env.Flags & Flags.IsLoggedIn) != 0)
            {
                if (env.State == State.UserAccountForm)
                    return m_WebApp.ReadFile(env, "useraccountform.html", env.Data);

                if (env.State == State.UserSearchForm)
                    return m_WebApp.ReadFile(env, "usersearchform.html", env.Data);
                if (env.State == State.UserSearchFormResponse)
                    return GetUserList(env);

                if (env.State == State.UserEditForm)
                    return m_WebApp.ReadFile(env, "usereditform.html", env.Data);

                if (env.State == State.UserDeleteForm)
                    return m_WebApp.ReadFile(env, "userdeleteform.html", env.Data);

                if (env.State == State.HyperlinkList)
                    return GetHyperlinks(env);
                if (env.State == State.HyperlinkListForm)
                    return m_WebApp.ReadFile(env, "linkregionform.html", env.Data);
                if (env.State == State.HyperlinkDeleteForm)
                    return m_WebApp.ReadFile(env, "linkregiondeleteform.html", env.Data);

                if (env.State == State.RegionManagementForm)
                    return GetRegionManagementForm(env);
                if (env.State == State.RegionManagementSuccessful)
                    return "Success! Back to <a href=\"/wifi/admin/regions\">Region Management Page</a>";
                if (env.State == State.RegionManagementUnsuccessful)
                    return "Action could not be performed. Please check if the server is running.<br/>Back to <a href=\"/wifi/admin/regions\">Region Management Page</a>";

                if (env.State == State.InventoryListForm)
                //{
                //    string invListStr = string.Empty;
                //    if (env.Data.Count > 0)
                //    {
                //        InventoryTreeNode tree = (InventoryTreeNode)env.Data[0];
                //        if (tree.Children != null)
                //        {
                //            List<object> loo = new List<object>();
                //            foreach (InventoryTreeNode node in tree.Children)
                //            {
                //                m_log.DebugFormat("--> {0}", node.Name);
                //                loo.Add(node);
                //                invListStr += m_WebApp.ReadFile(env, "inventorylist.html", loo);
                //            }
                //            return invListStr;
                //        }
                //    }
                    return m_WebApp.ReadFile(env, "inventorylist.html", env.Data);
            //    }

                if (env.State == State.Console)
                    return m_WebApp.ReadFile(env, "console.html", env.Data);
            }

            return string.Empty;
        }
Ejemplo n.º 55
0
 private string GetRegionManagementForm(Environment env)
 {
     return m_WebApp.ReadFile(env, "region-form.html", env.Data);
 }
Ejemplo n.º 56
0
        public string GetConsoleUser(Environment env)
        {
            SessionInfo sinfo = env.Session;
            if (sinfo.Account != null && sinfo.Account.UserLevel >= m_WebApp.AdminUserLevel)
                return m_WebApp.ConsoleUser;

            return string.Empty;
        }
Ejemplo n.º 57
0
        public string GetMainMenu(Environment env)
        {
            if (!m_WebApp.IsInstalled)
                return m_WebApp.ReadFile(env, "main-menu-install.html");

            SessionInfo sinfo = env.Session;
            if (sinfo.Account != null)
            {
                if (sinfo.Account.UserLevel >= m_WebApp.AdminUserLevel) // Admin
                    return m_WebApp.ReadFile(env, "main-menu-admin.html");
                else if (sinfo.Account.UserLevel >= m_WebApp.HyperlinksUserLevel) // Privileged user
                    return m_WebApp.ReadFile(env, "main-menu-privileged.html");

                return m_WebApp.ReadFile(env, "main-menu-users.html", env.Data);
            }

            return m_WebApp.ReadFile(env, "main-menu.html", env.Data);
        }
Ejemplo n.º 58
0
        public string GetUserEmail(Environment env)
        {
            SessionInfo sinfo = env.Session;
            if (sinfo.Account != null)
            {
                if (sinfo.Account.Email == string.Empty)
                    return _("No email on file", env);

                return sinfo.Account.Email;
            }

            return _("Who are you?", env);
        }
Ejemplo n.º 59
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 resource = GetParam(path);

            //m_log.DebugFormat("[Wifi]: resource {0}", resource);
            resource = Uri.UnescapeDataString(resource).Trim(WebAppUtils.DirectorySeparatorChars);

            Request request = RequestFactory.CreateRequest(resource, httpRequest);

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

            if (resource == string.Empty || resource.StartsWith("index."))
            {
                if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero)
                {
                    m_WebApp.Services.ComputeStatistics();
                }

                httpResponse.ContentType = "text/html";

                return(WebAppUtils.StringToBytes(m_WebApp.Services.DefaultRequest(env)));
            }
            else
            {
                string resourcePath = System.IO.Path.Combine(WebApp.DocsPath, resource);
                string type         = WebAppUtils.GetContentType(resource);
                httpResponse.ContentType = type;
                //m_log.DebugFormat("[Wifi]: ContentType {0}", type);
                if (type.StartsWith("image"))
                {
                    return(WebAppUtils.ReadBinaryResource(resourcePath));
                }

                if (type.StartsWith("application"))
                {
                    string res = WebAppUtils.ReadTextResource(resourcePath, true);
                    return(WebAppUtils.StringToBytes(res));
                }
                if (type.StartsWith("text"))
                {
                    if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero)
                    {
                        m_WebApp.Services.ComputeStatistics();
                    }

                    resourcePath = Localization.LocalizePath(env, resource);
                    Processor p   = new Processor(m_WebApp.WifiScriptFace, env);
                    string    res = p.Process(WebAppUtils.ReadTextResource(resourcePath));
                    if (res == string.Empty)
                    {
                        res = m_WebApp.Services.DefaultRequest(env);
                    }
                    return(WebAppUtils.StringToBytes(res));
                }
            }

            httpResponse.ContentType = "text/plain";
            string result = "Boo!";

            return(WebAppUtils.StringToBytes(result));
        }
Ejemplo n.º 60
0
        public string GetNotificationType(Environment env)
        {
            SessionInfo sinfo = env.Session;
            if (sinfo.Notify.FollowUp == null)
                return "hidden";

            return "submit";
        }