示例#1
0
        public IActionResult StepThree()
        {
            if (!CheckStep(3))
            {
                return(Redirect("2"));
            }

            var ldapHost         = GlobalSettings.Get("LDAP_Host");
            var ldapPort         = GlobalSettings.GetInt("LDAP_Port");
            var ldapSSL          = false;
            var ldapBindDn       = GlobalSettings.Get("LDAP_BindDN");
            var ldapBindPassword = GlobalSettings.Get("LDAP_BindPass");

            if (GlobalSettings.Get("LDAP_SSL") != null)
            {
                ldapSSL = bool.Parse(GlobalSettings.Get("LDAP_SSL"));
            }

            StepThreeModel model = new StepThreeModel();

            model.Host         = ldapHost != null ? ldapHost : "";
            model.Port         = ldapPort != null ? ((int)ldapPort) : 389;
            model.SSL          = ldapSSL;
            model.BindDN       = ldapBindDn != null ? ldapBindDn : "";
            model.BindPassword = ldapBindPassword != null ? ldapBindPassword : "";

            return(View(model));
        }
示例#2
0
        public IActionResult StepThree(StepThreeModel model)
        {
            if (!CheckStep(3))
            {
                return(Redirect("2"));
            }

            if (ModelState.IsValid && model != null)
            {
                LdapConnection connection = new LdapConnection();
                connection.SecureSocketLayer = model.SSL;

                try
                {
                    connection.Connect(model.Host, model.Port);
                    connection.Bind(model.BindDN, model.BindPassword);

                    //If everything goes well
                    GlobalSettings.Store("LDAP_Host", model.Host);
                    GlobalSettings.Store("LDAP_Port", model.Port.ToString());
                    GlobalSettings.Store("LDAP_SSL", model.SSL.ToString());
                    GlobalSettings.Store("LDAP_BindDN", model.BindDN);
                    GlobalSettings.Store("LDAP_BindPass", model.BindPassword);

                    Helpers.ReplaceEnvVariableInFile(GlobalSettings.Get("CONFIG_FILE"), "SP_CONFIG_SETUPASSISTANT_STEP", "4");
                    GlobalSettings.Store("CONFIG_SETUPASSISTANT_STEP", "4");
                    return(Redirect("4"));
                }
                catch (Exception ex)
                {
                    if (ex is LdapException || ex is AggregateException)
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "An unknown error occurred. Please try again.");
                        throw;
                    }
                }
            }

            return(View(model));
        }