private AuroraXmlDocument GetXML(string filename, OSHttpRequest httpRequest, OSHttpResponse httpResponse, Dictionary <string, object> requestParameters)
        {
            IWebInterfacePage page = GetPage(filename);

            if (page != null)
            {
                ITranslator translator = null;
                if (httpRequest.Query.ContainsKey("language"))
                {
                    translator = _translators.FirstOrDefault(t => t.LanguageName == httpRequest.Query["language"].ToString());
                }
                if (translator == null)
                {
                    translator = _defaultTranslator;
                }

                if (page.RequiresAuthentication)
                {
                    if (!Authenticator.CheckAuthentication(httpRequest))
                    {
                        return(null);
                    }
                    if (page.RequiresAdminAuthentication)
                    {
                        if (!Authenticator.CheckAdminAuthentication(httpRequest))
                        {
                            return(null);
                        }
                    }
                }
                return((AuroraXmlDocument)page.Fill(this, filename, httpRequest, httpResponse, requestParameters, translator)["xml"]);
            }
            return(null);
        }
        public Dictionary <string, object> Fill(WebInterface webInterface, string filename, OSHttpRequest httpRequest,
                                                OSHttpResponse httpResponse, Dictionary <string, object> requestParameters, ITranslator translator, out string response)
        {
            response = null;
            var vars      = new Dictionary <string, object>();
            var usersList = new List <Dictionary <string, object> >();

            uint amountPerQuery = 10;

            if (requestParameters.ContainsKey("Submit"))
            {
                IUserAccountService accountService = webInterface.Registry.RequestModuleInterface <IUserAccountService>();
                string username = requestParameters["username"].ToString();
                int    start    = httpRequest.Query.ContainsKey("Start") ? int.Parse(httpRequest.Query["Start"].ToString()) : 0;
                uint   count    = accountService.NumberOfUserAccounts(null, username);
                int    maxPages = (int)(count / amountPerQuery) - 1;

                if (start == -1)
                {
                    start = (int)(maxPages < 0 ? 0 : maxPages);
                }

                vars.Add("CurrentPage", start);
                vars.Add("NextOne", start + 1 > maxPages ? start : start + 1);
                vars.Add("BackOne", start - 1 < 0 ? 0 : start - 1);

                var users = accountService.GetUserAccounts(null, username, (uint)start, amountPerQuery);
                foreach (var user in users)
                {
                    usersList.Add(new Dictionary <string, object> {
                        { "UserName", user.Name },
                        { "UserID", user.PrincipalID },
                        { "CanEdit", Authenticator.CheckAdminAuthentication(httpRequest) }
                    });
                }
            }
            else
            {
                vars.Add("CurrentPage", 0);
                vars.Add("NextOne", 0);
                vars.Add("BackOne", 0);
            }

            vars.Add("UsersList", usersList);
            vars.Add("UserSearchText", translator.GetTranslatedString("UserSearchText"));
            vars.Add("SearchForUserText", translator.GetTranslatedString("SearchForUserText"));
            vars.Add("UserNameText", translator.GetTranslatedString("UserNameText"));
            vars.Add("Search", translator.GetTranslatedString("Search"));
            vars.Add("SearchResultForUserText", translator.GetTranslatedString("SearchResultForUserText"));
            vars.Add("EditText", translator.GetTranslatedString("EditText"));
            vars.Add("EditUserAccountText", translator.GetTranslatedString("EditUserAccountText"));

            vars.Add("FirstText", translator.GetTranslatedString("FirstText"));
            vars.Add("BackText", translator.GetTranslatedString("BackText"));
            vars.Add("NextText", translator.GetTranslatedString("NextText"));
            vars.Add("LastText", translator.GetTranslatedString("LastText"));
            vars.Add("CurrentPageText", translator.GetTranslatedString("CurrentPageText"));

            return(vars);
        }
Beispiel #3
0
        protected Dictionary <string, object> AddVarsForPage(string filename, string parentFileName,
                                                             OSHttpRequest httpRequest, OSHttpResponse httpResponse,
                                                             Dictionary <string, object> requestParameters,
                                                             out string response)
        {
            response = null;
            Dictionary <string, object> vars = new Dictionary <string, object>();
            IWebInterfacePage           page = GetPage(filename);

            if (page != null)
            {
                ITranslator translator = null;
                if (httpRequest.Query.ContainsKey("language"))
                {
                    translator =
                        _translators.FirstOrDefault(t => t.LanguageName == httpRequest.Query["language"].ToString());
                    httpResponse.AddCookie(new System.Web.HttpCookie("language",
                                                                     httpRequest.Query["language"].ToString()));
                }
                else if (httpRequest.Cookies.Get("language") != null)
                {
                    var cookie = httpRequest.Cookies.Get("language");
                    translator = _translators.FirstOrDefault(t => t.LanguageName == cookie.Value);
                }
                if (translator == null)
                {
                    translator = _defaultTranslator;
                }

                if (page.RequiresAuthentication)
                {
                    if (!Authenticator.CheckAuthentication(httpRequest))
                    {
                        return(null);
                    }
                }
                if (page.RequiresAdminAuthentication)
                {
                    if (!Authenticator.CheckAdminAuthentication(httpRequest))
                    {
                        return(null);
                    }
                }
                vars = page.Fill(this, parentFileName, httpRequest, httpResponse, requestParameters, translator,
                                 out response);
                return(vars);
            }
            return(null);
        }
Beispiel #4
0
 /// <summary>
 ///     Returns false if the authentication was wrong
 /// </summary>
 /// <param name="p"></param>
 /// <param name="request"></param>
 /// <returns></returns>
 private bool CheckAuth(string p, OSHttpRequest request)
 {
     if (p.StartsWith("{IsAuthenticatedBegin}"))
     {
         return(Authenticator.CheckAuthentication(request));
     }
     else if (p.StartsWith("{IsNotAuthenticatedBegin}"))
     {
         return(!Authenticator.CheckAuthentication(request));
     }
     else if (p.StartsWith("{IsAdminAuthenticatedBegin}"))
     {
         return(Authenticator.CheckAdminAuthentication(request));
     }
     else if (p.StartsWith("{IsNotAdminAuthenticatedBegin}"))
     {
         return(!Authenticator.CheckAdminAuthentication(request));
     }
     return(false);
 }
        public Dictionary <string, object> Fill(WebInterface webInterface, string filename, OSHttpRequest httpRequest,
                                                OSHttpResponse httpResponse, Dictionary <string, object> requestParameters, ITranslator translator, out string response)
        {
            response = null;
            var vars = new Dictionary <string, object>();

            #region Find pages

            List <Dictionary <string, object> > pages = new List <Dictionary <string, object> >();

            IGenericsConnector generics = Aurora.DataManager.DataManager.RequestPlugin <IGenericsConnector>();
            var      settings           = generics.GetGeneric <GridSettings>(UUID.Zero, "WebSettings", "Settings");
            GridPage rootPage           = generics.GetGeneric <GridPage>(UUID.Zero, "WebPages", "Root");
            rootPage.Children.Sort((a, b) => a.MenuPosition.CompareTo(b.MenuPosition));

            foreach (GridPage page in rootPage.Children)
            {
                if (page.LoggedOutRequired && Authenticator.CheckAuthentication(httpRequest))
                {
                    continue;
                }
                if (page.LoggedInRequired && !Authenticator.CheckAuthentication(httpRequest))
                {
                    continue;
                }
                if (page.AdminRequired && !Authenticator.CheckAdminAuthentication(httpRequest, page.AdminLevelRequired))
                {
                    continue;
                }

                List <Dictionary <string, object> > childPages = new List <Dictionary <string, object> >();
                page.Children.Sort((a, b) => a.MenuPosition.CompareTo(b.MenuPosition));
                foreach (GridPage childPage in page.Children)
                {
                    if (childPage.LoggedOutRequired && Authenticator.CheckAuthentication(httpRequest))
                    {
                        continue;
                    }
                    if (childPage.LoggedInRequired && !Authenticator.CheckAuthentication(httpRequest))
                    {
                        continue;
                    }
                    if (childPage.AdminRequired && !Authenticator.CheckAdminAuthentication(httpRequest, childPage.AdminLevelRequired))
                    {
                        continue;
                    }

                    childPages.Add(new Dictionary <string, object> {
                        { "ChildMenuItemID", childPage.MenuID },
                        { "ChildShowInMenu", childPage.ShowInMenu },
                        { "ChildMenuItemLocation", childPage.Location },
                        { "ChildMenuItemTitleHelp", GetTranslatedString(translator, childPage.MenuToolTip, childPage, true) },
                        { "ChildMenuItemTitle", GetTranslatedString(translator, childPage.MenuTitle, childPage, false) }
                    });

                    //Add one for menu.js
                    pages.Add(new Dictionary <string, object> {
                        { "MenuItemID", childPage.MenuID },
                        { "ShowInMenu", false },
                        { "MenuItemLocation", childPage.Location }
                    });
                }

                pages.Add(new Dictionary <string, object> {
                    { "MenuItemID", page.MenuID },
                    { "ShowInMenu", page.ShowInMenu },
                    { "HasChildren", page.Children.Count > 0 },
                    { "ChildrenMenuItems", childPages },
                    { "MenuItemLocation", page.Location },
                    { "MenuItemTitleHelp", GetTranslatedString(translator, page.MenuToolTip, page, true) },
                    { "MenuItemTitle", GetTranslatedString(translator, page.MenuTitle, page, false) }
                });
            }
            vars.Add("MenuItems", pages);

            #endregion

            // Tooltips Urls
            vars.Add("TooltipsWelcomeScreen", translator.GetTranslatedString("TooltipsWelcomeScreen"));
            vars.Add("TooltipsWorldMap", translator.GetTranslatedString("TooltipsWorldMap"));

            // Style Switcher
            vars.Add("styles1", translator.GetTranslatedString("styles1"));
            vars.Add("styles2", translator.GetTranslatedString("styles2"));
            vars.Add("styles3", translator.GetTranslatedString("styles3"));
            vars.Add("styles4", translator.GetTranslatedString("styles4"));
            vars.Add("styles5", translator.GetTranslatedString("styles5"));

            vars.Add("StyleSwitcherStylesText", translator.GetTranslatedString("StyleSwitcherStylesText"));
            vars.Add("StyleSwitcherLanguagesText", translator.GetTranslatedString("StyleSwitcherLanguagesText"));
            vars.Add("StyleSwitcherChoiceText", translator.GetTranslatedString("StyleSwitcherChoiceText"));

            // Language Switcher
            vars.Add("en", translator.GetTranslatedString("en"));
            vars.Add("fr", translator.GetTranslatedString("fr"));
            vars.Add("de", translator.GetTranslatedString("de"));
            vars.Add("it", translator.GetTranslatedString("it"));
            vars.Add("es", translator.GetTranslatedString("es"));

            // Index Page
            vars.Add("HomeText", translator.GetTranslatedString("HomeText"));
            vars.Add("HomeTextWelcome", translator.GetTranslatedString("HomeTextWelcome"));
            vars.Add("HomeTextTips", translator.GetTranslatedString("HomeTextTips"));
            vars.Add("WelcomeScreen", translator.GetTranslatedString("WelcomeScreen"));
            vars.Add("WelcomeToText", translator.GetTranslatedString("WelcomeToText"));

            if (PagesMigrator.RequiresUpdate() && PagesMigrator.CheckWhetherIgnoredVersionUpdate(settings.LastPagesVersionUpdateIgnored))
            {
                vars.Add("PagesUpdateRequired", translator.GetTranslatedString("Pages") + " " + translator.GetTranslatedString("DefaultsUpdated"));
            }
            else
            {
                vars.Add("PagesUpdateRequired", "");
            }
            if (SettingsMigrator.RequiresUpdate() && SettingsMigrator.CheckWhetherIgnoredVersionUpdate(settings.LastSettingsVersionUpdateIgnored))
            {
                vars.Add("SettingsUpdateRequired", translator.GetTranslatedString("Settings") + " " + translator.GetTranslatedString("DefaultsUpdated"));
            }
            else
            {
                vars.Add("SettingsUpdateRequired", "");
            }

            vars.Add("ShowLanguageTranslatorBar", !settings.HideLanguageTranslatorBar);
            vars.Add("ShowStyleBar", !settings.HideStyleBar);

            vars.Add("Maintenance", false);
            vars.Add("NoMaintenance", true);
            return(vars);
        }