public static bool CanLoginAD(string address) { return(PortalConfig.UseWinLogin && ActiveDirectory.IsLocalAddress(address)); }
private void ShowStep(int step) { for (int i = 0; i <= _stepCount; i++) ((Panel)steps[i]).Visible = false; ((Panel)steps[step - 1]).Visible = true; #region Step 2 if (step == 2) { if (rbSourceObject.SelectedValue == "0") { lgdConnectInf.InnerText = LocRM.GetString("ConnectToAD"); tblADConnection.Visible = true; tblFileConnection.Visible = false; ChangedLdap(); tblFilter.Visible = true; } else { lgdConnectInf.InnerText = LocRM.GetString("tLoadToServer"); tblADConnection.Visible = false; tblFileConnection.Visible = true; ((WizardTemplate)Page.Controls[0]).btnNext.Attributes.Add("onclick", "ShowProgress();"); tblFilter.Visible = false; } ViewState["Fields"] = null; ViewState["ADFields"] = null; ViewState["ldapPassword"] = null; grdFields.EditItemIndex = -1; tbFilter.Text = ""; wwwPath.Value = ""; ((WizardTemplate)Page.Controls[0]).btnNext.Disabled = false; } #endregion #region Step 3 if (step == 3) { if (ViewState["Fields"] == null || ViewState["Fields"].ToString().Length == 0) { DataTable dtFields = new DataTable(); dtFields.Columns.Add(new DataColumn("IBNField", typeof(string))); dtFields.Columns.Add(new DataColumn("IBNFieldDisplay", typeof(string))); dtFields.Columns.Add(new DataColumn("ADField", typeof(string))); dtFields.Columns.Add(new DataColumn("realADField", typeof(string))); DataRow dr1; string[] sarray = null; string[] alIBNFields = UserInfo.PropertyNamesIbn; if (rbSourceObject.SelectedValue == "0") { pc["ADDomain"] = txtDomain.Text; pc["ADUserName"] = txtUserName.Text; pc["ADLDAPSettings"] = ddLDAPSettings.SelectedValue; LdapSettings lsets = null; if (int.Parse(ddLDAPSettings.SelectedValue) > 0) lsets = LdapSettings.Load(int.Parse(ddLDAPSettings.SelectedValue)); else lsets = new Mediachase.IBN.Business.LdapSettings(); string sPassword = txtPassword.Text; if (txtDomain.Text == lsets.Domain && txtUserName.Text == lsets.Username && txtPassword.Text == "") sPassword = lsets.Password; ViewState["ldapPassword"] = sPassword; ActiveDirectory ad = new ActiveDirectory(txtDomain.Text, txtUserName.Text, sPassword, tbFilter.Text); tbFilter.Text = lsets.Filter; foreach (string name in alIBNFields) { dr1 = dtFields.NewRow(); dr1["IBNField"] = name; dr1["IBNFieldDisplay"] = Mediachase.Ibn.Web.UI.CHelper.GetResFileString(String.Format("{{IbnFramework.Common:{0}}}", name)); dr1["ADField"] = ad.FieldsMatch[name]; dr1["realADField"] = ad.FieldsMatch[name]; if (ddLDAPSettings.SelectedValue != "0") { foreach (LdapField lf in lsets.Fields) if (lf.IbnName == name) { dr1["ADField"] = lf.LdapName; dr1["realADField"] = lf.LdapName; break; } } dtFields.Rows.Add(dr1); } sarray = ad.GetProperties(); } else { if (fSourceFile.PostedFile != null && fSourceFile.PostedFile.ContentLength > 0) { ProcessFileCache(Server.MapPath(CommonHelper.ChartPath)); String dir = CommonHelper.ChartPath; string wwwpath = dir + Guid.NewGuid().ToString(); switch (rbSourceType.SelectedValue) { case "0": //wwwpath += ".xls"; // OZ: Added XLS and XLSX extensions wwwpath += Path.GetExtension(fSourceFile.PostedFile.FileName); break; case "1": wwwpath += ".xml"; break; default: break; } wwwPath.Value = wwwpath; using (Stream sw = File.Create(Server.MapPath(wwwpath))) { fSourceFile.PostedFile.InputStream.Seek(0, SeekOrigin.Begin); System.IO.BinaryReader br = new System.IO.BinaryReader(fSourceFile.PostedFile.InputStream); int iBufferSize = 655360; // 640 KB byte[] outbyte = br.ReadBytes(iBufferSize); while (outbyte.Length > 0) { sw.Write(outbyte, 0, outbyte.Length); outbyte = br.ReadBytes(iBufferSize); } br.Close(); } IIncomingDataParser parser = null; DataSet rawData = null; switch (rbSourceType.SelectedIndex) { case 0: IMCOleDBHelper helper = (IMCOleDBHelper)Activator.GetObject(typeof(IMCOleDBHelper), System.Configuration.ConfigurationManager.AppSettings["McOleDbServiceString"]); rawData = helper.ConvertExcelToDataSet(Server.MapPath(wwwpath)); break; case 1: parser = new XmlIncomingDataParser(); rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); break; } DataTable dtSource = rawData.Tables[0]; int i = 0; sarray = new string[dtSource.Columns.Count]; foreach (DataColumn dc in dtSource.Columns) { sarray[i++] = dc.ColumnName; } foreach (string name in alIBNFields) { dr1 = dtFields.NewRow(); dr1["IBNField"] = name; dr1["IBNFieldDisplay"] = Mediachase.Ibn.Web.UI.CHelper.GetResFileString(String.Format("{{IbnFramework.Common:{0}}}", name)); dr1["ADField"] = LocRM.GetString("tNotSet"); dr1["realADField"] = "0"; foreach (string str in sarray) if (String.Compare(str, name, true) == 0 || String.Compare(str, Mediachase.Ibn.Web.UI.CHelper.GetResFileString(String.Format("{{IbnFramework.Common:{0}}}", name)), true) == 0) { dr1["ADField"] = str; dr1["realADField"] = str; } dtFields.Rows.Add(dr1); } } else ((WizardTemplate)Page.Controls[0]).btnNext.Disabled = true; } ViewState["Fields"] = dtFields; grdFields.DataSource = dtFields.DefaultView; grdFields.DataBind(); if (sarray != null) { string sValues = String.Join(",", sarray); ViewState["ADFields"] = sValues; } } else { BindDG(); } ViewState["Users"] = null; ViewState["FullUsers"] = null; } #endregion #region Step 4 if (step == 4) { grdFields.EditItemIndex = -1; DataView dv = null; if (ViewState["FullUsers"] == null || ViewState["FullUsers"].ToString().Length == 0) { string[] alIBNFields = UserInfo.PropertyNamesIbn; DataTable dtFields = (DataTable)ViewState["Fields"]; DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Add", typeof(bool))); dt.Columns.Add(new DataColumn("Weight", typeof(int))); dt.Columns.Add(new DataColumn("Login", typeof(string))); dt.Columns.Add(new DataColumn("FirstName", typeof(string))); dt.Columns.Add(new DataColumn("LastName", typeof(string))); dt.Columns.Add(new DataColumn("Email", typeof(string))); dt.Columns.Add(new DataColumn("Phone", typeof(string))); dt.Columns.Add(new DataColumn("Fax", typeof(string))); dt.Columns.Add(new DataColumn("Mobile", typeof(string))); dt.Columns.Add(new DataColumn("Company", typeof(string))); dt.Columns.Add(new DataColumn("JobTitle", typeof(string))); dt.Columns.Add(new DataColumn("Department", typeof(string))); dt.Columns.Add(new DataColumn("Location", typeof(string))); dt.Columns.Add(new DataColumn("BadLogin", typeof(bool))); dt.Columns.Add(new DataColumn("BadEmail", typeof(bool))); //dt.Columns.Add(new DataColumn("BadWinLogin", typeof(bool))); dt.Columns.Add(new DataColumn("IsBad", typeof(bool))); dt.Columns.Add(new DataColumn("IsBadGroup", typeof(bool))); dt.Columns.Add(new DataColumn("Groups", typeof(string))); dt.Columns.Add(new DataColumn("IMGroup", typeof(int))); dt.Columns.Add(new DataColumn("LdapUid", typeof(string))); dt.Columns.Add(new DataColumn("WindowsLogin", typeof(string))); DataRow dr; if (rbSourceObject.SelectedValue == "0") { string sPassword = ViewState["ldapPassword"].ToString(); if (String.IsNullOrEmpty(sPassword) && int.Parse(ddLDAPSettings.SelectedValue) > 0) { LdapSettings lsets = LdapSettings.Load(int.Parse(ddLDAPSettings.SelectedValue)); if (txtDomain.Text == lsets.Domain && txtUserName.Text == lsets.Username && txtPassword.Text == "") sPassword = lsets.Password; } ActiveDirectory ad = new ActiveDirectory(txtDomain.Text, txtUserName.Text, sPassword, tbFilter.Text); foreach (string s in alIBNFields) { DataRow[] drMas = dtFields.Select("IBNField = '" + s + "'"); if (drMas.Length > 0) { string ss = drMas[0]["realADField"].ToString(); if (ss != "0" && !ss.Equals(ad.FieldsMatch[s])) { ad.FieldsMatch[s] = ss; } } } ArrayList alUsers = ad.GetUsers(); foreach (UserInfo _ui in alUsers) { dr = dt.NewRow(); dr["Login"] = _ui.Login; dr["FirstName"] = _ui.FirstName; dr["LastName"] = _ui.LastName; dr["Email"] = _ui.Email; if (_ui.FirstName != "" && _ui.LastName != "" && _ui.Email != "") dr["Add"] = true; else dr["Add"] = false; if (_ui.FirstName != "" && _ui.LastName != "") dr["Weight"] = 0; else dr["Weight"] = 1; dr["Phone"] = _ui.Phone; dr["Fax"] = _ui.Fax; dr["Mobile"] = _ui.Mobile; dr["Company"] = _ui.Company; dr["JobTitle"] = _ui.JobTitle; dr["Department"] = _ui.Department; dr["Location"] = _ui.Location; dr["BadLogin"] = false; dr["BadEmail"] = false; //dr["BadWinLogin"] = false; dr["IsBad"] = false; dr["IsBadGroup"] = false; dr["Groups"] = ((int)InternalSecureGroups.ProjectManager).ToString() + ","; dr["IMGroup"] = -1; dr["LdapUid"] = _ui.LdapUid; dr["WindowsLogin"] = _ui.WindowsLogin; dt.Rows.Add(dr); } } else { IIncomingDataParser parser = null; DataSet rawData = null; switch (rbSourceType.SelectedIndex) { case 0: // [03.06.05] fix some problems with oledb and asp.net IMCOleDBHelper helper = (IMCOleDBHelper)Activator.GetObject(typeof(IMCOleDBHelper), System.Configuration.ConfigurationManager.AppSettings["McOleDbServiceString"]); rawData = helper.ConvertExcelToDataSet(Server.MapPath(wwwPath.Value)); break; case 1: parser = new XmlIncomingDataParser(); rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); break; } DataTable dtSource = rawData.Tables[0]; string sValues = ViewState["ADFields"].ToString(); ArrayList alADFields = new ArrayList(sValues.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)); int count = 1; foreach (DataRow drFile in dtSource.Rows) { dr = dt.NewRow(); dr["Add"] = true; dr["Weight"] = 0; dr["BadLogin"] = false; dr["BadEmail"] = false; //dr["BadWinLogin"] = false; dr["IsBad"] = false; dr["IsBadGroup"] = false; dr["Groups"] = ((int)InternalSecureGroups.ProjectManager).ToString() + ","; dr["IMGroup"] = -1; bool flLogin = false; foreach (string sname in alADFields) { DataRow[] drF = dtFields.Select("realADField = '" + sname + "'"); if (drF.Length > 0) { string ss = drF[0]["IBNField"].ToString(); if (ss == "Login") flLogin = true; dr[ss] = drFile[sname]; } } if (!flLogin) dr["Login"] = "******" + (count++).ToString(); dt.Rows.Add(dr); } } ViewState["Users"] = dt; DataTable dtFull = dt.Clone(); DataRow drNew; foreach (DataRow dr1 in dt.Rows) { drNew = dtFull.NewRow(); drNew.ItemArray = dr1.ItemArray; dtFull.Rows.Add(drNew); } ViewState["FullUsers"] = dtFull; dv = dt.DefaultView; } else dv = ((DataTable)ViewState["FullUsers"]).DefaultView; dv.Sort = "Weight, LastName, FirstName, Login"; dgUsers.DataSource = dv; dgUsers.DataBind(); ((WizardTemplate)Page.Controls[0]).btnNext.CausesValidation = true; ((WizardTemplate)Page.Controls[0]).btnNext.Disabled = false; } #endregion #region Step 5 if (step == 5) { DataTable dt = (DataTable)ViewState["Users"]; DataTable dtFull = (DataTable)ViewState["FullUsers"]; string sExceptions = ""; foreach (DataGridItem item in dgUsers.Items) { foreach (Control control in item.Cells[0].Controls) { if (control is HtmlInputCheckBox) { HtmlInputCheckBox checkBox = (HtmlInputCheckBox)control; //*****Undo***** //string filterElement = "Login = '******'"; try { //DataRow[] dr = dt.Select(filterElement); //DataRow[] drF = dtFull.Select(filterElement); DataRow dr = GetRowIsEqual(dt, "Login", item.Cells[3].Text); DataRow drF = GetRowIsEqual(dtFull, "Login", item.Cells[3].Text); if (!checkBox.Checked) { //if (dr.Length > 0) // dt.Rows.Remove(dr[0]); //if (drF.Length > 0) // drF[0]["Add"] = false; if (dr != null) dt.Rows.Remove(dr); if (drF != null) drF["Add"] = false; } else { //if (drF.Length > 0) // drF[0]["Add"] = true; //if (dr.Length == 0 && drF.Length > 0) //{ // DataRow drN = dt.NewRow(); // drN.ItemArray = drF[0].ItemArray; // dt.Rows.Add(drN); //} if (drF != null) drF["Add"] = true; if (dr == null && drF != null) { DataRow drN = dt.NewRow(); drN.ItemArray = drF.ItemArray; dt.Rows.Add(drN); } } } catch { sExceptions += item.Cells[3].Text + "\r\n"; } } } } foreach (DataRow bad in dt.Rows) { string sEmail = bad["Email"].ToString(); if (sEmail.Length == 0 || User.GetUserByEmail(sEmail) != -1) bad["BadEmail"] = true; string sLogin = bad["Login"].ToString(); if (sLogin.Length == 0 || User.GetUserByLogin(sLogin) != -1) bad["BadLogin"] = true; //string sWinLogin = bad["WindowsLogin"].ToString(); //if (sWinLogin.Length == 0 || User.GetUserByWindowsLogin(sWinLogin) != -1) // bad["BadWinLogin"] = true; if ((bool)bad["BadEmail"] || (bool)bad["BadLogin"]/* || (bool)bad["BadWinLogin"]*/) bad["IsBad"] = true; } ViewState["Users"] = dt; ViewState["UsersGroups"] = null; ViewState["FullUsers"] = dtFull; if (!String.IsNullOrEmpty(sExceptions)) Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), String.Format("alert('Bad Logins:\r\n{0}');", sExceptions), true); DataView dv = dt.DefaultView; dv.Sort = "IsBad DESC, Login"; dlUsers.DataSource = dv; dlUsers.DataBind(); dlUsers.SelectedIndex = 0; LinkButton lb = (LinkButton)dlUsers.Items[0].FindControl("lbUser"); if (lb != null) BinddgGroupsUsers(lb.CommandName); ((WizardTemplate)Page.Controls[0]).btnNext.CausesValidation = false; ((WizardTemplate)Page.Controls[0]).btnNext.Disabled = false; } #endregion #region Step 6 if (step == 6) { ddIMGroups.DataTextField = "IMGroupName"; ddIMGroups.DataValueField = "IMGroupId"; ddIMGroups.DataSource = IMGroup.GetListIMGroupsWithoutPartners(); ddIMGroups.DataBind(); DataTable dt = (DataTable)ViewState["Users"]; DataTable dtFullOwn = dt.Clone(); DataRow drNew; foreach (DataRow dr1 in dt.Rows) { drNew = dtFullOwn.NewRow(); drNew.ItemArray = dr1.ItemArray; dtFullOwn.Rows.Add(drNew); } foreach (DataRow bad in dtFullOwn.Rows) { if ((bool)bad["IsBad"]) { string sLogin = bad["Login"].ToString(); #region *****Undo***** //DataRow[] dr = dt.Select("Login = '******'"); //if (dr.Length > 0) // dt.Rows.Remove(dr[0]); #endregion DataRow dr = GetRowIsEqual(dt, "Login", sLogin); if (dr != null) dt.Rows.Remove(dr); } } foreach (DataRow dr1 in dt.Rows) { dr1["IMGroup"] = int.Parse(ddIMGroups.SelectedValue); if (dr1["Groups"].ToString().Length < 2) dr1["IsBadGroup"] = true; } ViewState["UsersGroups"] = dt; DataView dv = dt.DefaultView; dv.Sort = "IsBadGroup DESC, LastName, FirstName"; dlUserGroups.DataSource = dv; dlUserGroups.DataBind(); if (dlUserGroups.Items.Count > 0) { dlUserGroups.SelectedIndex = 0; LinkButton lb = (LinkButton)dlUserGroups.Items[0].FindControl("lbUser2"); if (lb != null) BindGroups(lb.CommandName, true); btnSave2.Disabled = false; } else { ((WizardTemplate)Page.Controls[0]).btnNext.Disabled = true; btnSave2.Disabled = true; } ((WizardTemplate)Page.Controls[0]).btnNext.CausesValidation = false; } #endregion #region Step 7 - Save if (step == 7) { DataTable dt = (DataTable)ViewState["UsersGroups"]; ArrayList alUsers = new ArrayList(); foreach (DataRow saverow in dt.Rows) { string sGroups = saverow["Groups"].ToString(); ArrayList alGroups = new ArrayList(); while (sGroups.Length > 0) { alGroups.Add(Int32.Parse(sGroups.Substring(0, sGroups.IndexOf(",")))); sGroups = sGroups.Remove(0, sGroups.IndexOf(",") + 1); } if (alGroups.Count > 0) { UserInfo _ui = new UserInfo(); _ui.Login = saverow["Login"].ToString(); _ui.FirstName = saverow["FirstName"].ToString(); _ui.LastName = saverow["LastName"].ToString(); _ui.Email = saverow["EMail"].ToString(); _ui.Phone = saverow["Phone"].ToString(); _ui.Fax = saverow["Fax"].ToString(); _ui.Mobile = saverow["Mobile"].ToString(); _ui.Company = saverow["Company"].ToString(); _ui.JobTitle = saverow["JobTitle"].ToString(); _ui.Department = saverow["Department"].ToString(); _ui.Location = saverow["Location"].ToString(); _ui.Groups = alGroups; _ui.ImGroupId = int.Parse(saverow["IMGroup"].ToString()); _ui.WindowsLogin = saverow["WindowsLogin"].ToString(); alUsers.Add(_ui); } } bool fl = false; if (alUsers.Count > 0) try { string password = "******"; if (!String.IsNullOrEmpty(txtCommonPassword.Text.Trim())) password = txtCommonPassword.Text.Trim(); User.CreateMultiple(alUsers, password, Security.CurrentUser.LanguageId); } catch { fl = true; } else fl = true; if (fl) lblError.Text = LocRM.GetString("tWereErrors"); else { foreach (UserInfo _ui in alUsers) { lblError.Text += CommonHelper.GetUserStatusUL(User.GetUserByLogin(_ui.Login)) + "<br>"; } } } #endregion }