예제 #1
0
        //static void btnDoConfig_Click(object sender, EventArgs e)
        //{
        //	Initialize();
        //}

        public static bool CheckAppConfiguration(out string error)
        {
            //error="";
            //return true;
            try
            {
                error = "";
                System.Configuration.Configuration conf = null;
                try
                {
                    conf = ConfigUtility.GetConfigFile();
                }
                catch
                {
                }
                SystemWebSectionGroup websec = ConfigUtility.GetSystemWebSectionGroup(conf);
                if (websec.Authentication.Mode != AuthenticationMode.Forms)
                {
                    error = "Authentication.Mode = " + websec.Authentication.Mode.ToString();
                }
                if (websec.Membership.DefaultProvider != UniMembershipProvider.ProviderName)
                {
                    //&& websec.Membership.DefaultProvider != AccessMembershipProvider.ProviderName)
                    if (websec.Membership.DefaultProvider == null)
                    {
                        error = "Membership.DefaultProvider = null";
                    }
                    else
                    {
                        error = "Membership.DefaultProvider = " + websec.Membership.DefaultProvider;
                    }
                }
                if (!Roles.Enabled)
                {
                    error = "Roles is not enabled.";
                }
                if (error != "")
                {
                    return(false);
                }
                //UniSecuritySectionGroup jcoSec = (UniSecuritySectionGroup)conf.GetSectionGroup("uniSecurity");
                //if (jcoSec == null)
                //    error = "UniSecuritySectionGroup is not defined.";
                //if (jcoSec.MasterPage.Path == "")
                //	error = "JcoSecuritySectionGroup.MasterPage.Path is empty.";
                if (error != "")
                {
                    return(false);
                }
                if (websec.Membership.DefaultProvider == UniMembershipProvider.ProviderName)
                {
                    string conName = websec.Membership.Providers[UniMembershipProvider.ProviderName].Parameters["connectionStringName"];
                    bool   b       = CheckSqlTablesExists(conf.ConnectionStrings.ConnectionStrings[conName].ConnectionString);
                    if (!b)
                    {
                        error = "Sql tables doen not exists.";
                        return(false);
                    }
                }
                else
                {
                    throw new NotSupportedException();
                    //string conName = websec.Membership.Providers[AccessMembershipProvider.ProviderName].Parameters["connectionStringName"];
                    //if (!File.Exists(HttpContext.Current.Server.MapPath(conf.ConnectionStrings.ConnectionStrings[conName].ConnectionString)))
                    //{
                    //    error = "Access DB file: '" + conf.ConnectionStrings.ConnectionStrings[conName].ConnectionString + "' does not exists.";
                    //    return false;
                    //}
                }
            }
            catch (Exception ex)
            {
                error = ex.ToString();
                return(false);
            }
            return(true);
        }
예제 #2
0
        internal static bool CheckConfig(Control control)
        {
            if (initialized)
            {
                return(true);
            }
            string    error;
            HyperLink lnk = new HyperLink();

            if (CheckAppConfiguration(out error))
            {
                //if (Array.IndexOf<string>(Roles.GetAllRoles(), "admin") == -1 && Array.IndexOf<string>(Roles.GetAllRoles(), "Admin") == -1)
                if (Roles.GetAllRoles().Length == 0)
                {
                    Roles.CreateRole("admin");
                }
                if ((Membership.GetUser("admin") == null || Membership.GetUser("Admin") == null) && Membership.GetAllUsers().Count == 0)
                {
                    lnk.Text        = "<br>کاربر Admin ايجاد نشده است<br/>براي ايجاد کاربر اينجا را کليک کنيد.";
                    lnk.NavigateUrl = UniHttpHandler.HandlerPath + "?a=conf&b=" + HttpContext.Current.Request.Path + "&p=2";
                    lnk.ToolTip     = "کاربر Admin وجود ندارد";
                    control.Controls.Add(lnk);
                }
                else
                {
                    initialized = true;
                }
                return(true);
            }

            System.Configuration.Configuration conf = null;
            try
            {
                conf = ConfigUtility.GetConfigFile();
            }
            catch (Exception ex)
            {
                error = ex.ToString();
            }
            if (conf != null)
            {
                try
                {
                    foreach (ConfigurationLocation location in conf.Locations)
                    {
                        if (location.Path == UniHttpHandler.HandlerPath)
                        {
                            System.Configuration.Configuration lconf = location.OpenConfiguration();
                            SystemWebSectionGroup lweb = ConfigUtility.GetSystemWebSectionGroup(lconf);
                            lweb.Authorization.Rules.Clear();
                            AuthorizationRule rule = new AuthorizationRule(AuthorizationRuleAction.Allow);
                            rule.Users.Add("*");
                            lweb.Authorization.Rules.Add(rule);
                            lconf.Save();
                        }
                    }
                    //WebConfigInitializer.CreateHttpHandler(ConfigUtility.GetSystemWebSectionGroup(conf));
                    conf.Save();
                }
                catch (Exception ex)
                {
                    error = ex.ToString();
                }
            }
            //LinkButton btn = new LinkButton();
            //btn.Text = "تنظيمات امنيتي سايت اتجام نشده است<br/>براي انجام تنظيمات اينجا را کليک کنيد.";
            //btn.Click += new EventHandler( btnDoConfig_Click );
            //btn.CausesValidation = false;
            //btn.ID = "JcoSecDoConfigButton";
            //control.Controls.Add( btn );
            //control.Page.PreRender += new EventHandler( Page_PreRender );
            //initAddedButtons.Add( btn );

            lnk.Text        = "تنظيمات امنيتي سايت اتجام نشده است<br/>براي انجام تنظيمات اينجا را کليک کنيد.";
            lnk.NavigateUrl = UniHttpHandler.HandlerPath + "?a=conf&b=" + HttpContext.Current.Request.Path;
            lnk.ToolTip     = error;
            control.Controls.Add(lnk);
            return(false);
        }