public void Delete(List <int> listDelete) { try { using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString)) { conn.Open(); for (int i = 0; i < listDelete.Count; i++) { WDSUser user = new WDSUser(); user.ID = listDelete[i].ToString(); user = user.Read(user); NpgsqlCommand cmd = new NpgsqlCommand("users_delete", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new NpgsqlParameter("@userID", listDelete[i])); cmd.ExecuteNonQuery(); History history = new History(); history.Event = "Delete"; history.Type = "User"; history.TypeID = user.ID; history.CreateEvent(history); } Utility.Message = "Successfully Deleted User(s)"; } } catch (Exception ex) { Utility.Message = "Could Not Delete User. Check The Exception Log For More Info"; Logger.Log(ex.ToString()); } }
protected void Page_Load(object sender, EventArgs e) { Utility utility = new Utility(); WDSUser user = new WDSUser(); user.ID = user.GetID(HttpContext.Current.User.Identity.Name); user = user.Read(user); if (utility.GetSettings("On Demand") == "Disabled") { secure.Visible = false; secureMsg.Text = "On Demand Mode Has Been Globally Disabled"; secureMsg.Visible = true; } else if (user.OndAccess == "0") { secure.Visible = false; secureMsg.Text = "On Demand Mode Has Been Disabled For This Account"; secureMsg.Visible = true; } else { secure.Visible = true; secureMsg.Visible = false; } if (!IsPostBack) { ddlImage.DataSource = Utility.PopulateImagesDdl(); ddlImage.DataBind(); ddlImage.Items.Insert(0, "Select Image"); } }
protected void Page_Load(object sender, EventArgs e) { user = new WDSUser(); requestedPage = Request.QueryString["page"] as string; user.ID = Request.QueryString["userid"] as string; user.Read(user); if (!IsPostBack) { if (Master.IsInMembership("User")) { Response.Redirect("~/views/dashboard/dash.aspx?access=denied"); } Master.Msgbox(Utility.Message); switch (requestedPage) { case "edit": lblSubNav.Text = "| edit"; edit.Visible = true; edit_page(); break; case "history": lblSubNav.Text = "| history"; historypage.Visible = true; history_page(); break; default: break; } } }
protected void btnSubmit_Click(object sender, EventArgs e) { WDSUser user = new WDSUser(); List<int> listDelete = new List<int>(); bool adminError = false; foreach (GridViewRow row in gvUsers.Rows) { CheckBox cb = (CheckBox)row.FindControl("chkSelector"); if (cb != null && cb.Checked) { listDelete.Add(Convert.ToInt32(gvUsers.DataKeys[row.RowIndex].Value)); user.Membership = row.Cells[3].Text; } if (user.Membership == "Administrator") { Master.Msgbox("Administrators Must Be Changed To A Lower Level User Before They Can Be Deleted"); adminError = true; break; } } if (!adminError) { if (listDelete.Count > 0) { user.Delete(listDelete); PopulateGrid(); Master.Msgbox(Utility.Message); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Utility.NoSpaceNotEmpty(txtUserPwd.Text)) { WDSUser user = new WDSUser(); user.ID = Request.QueryString["userid"] as string; user = user.Read(user); if (txtUserPwd.Text == txtUserPwdConfirm.Text) { user.Password = txtUserPwd.Text; user.Salt = user.CreateSalt(16); user.Update(user, user.ID); Master.Msgbox(Utility.Message); } else { Master.Msgbox("Passwords Did Not Match"); } } else { Master.Msgbox("Password Cannot Be Empty Or Contain Spaces"); } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Utility.NoSpaceNotEmpty(txtUserName.Text)) { if (Utility.NoSpaceNotEmpty(txtUserPwd.Text)) { WDSUser user = new WDSUser(); if (txtUserPwd.Text == txtUserPwdConfirm.Text) { Group group = new Group(); List<string> listGroupManagement = new List<string>(); foreach (GridViewRow row in gvGroups.Rows) { CheckBox cb = (CheckBox)row.FindControl("chkSelector"); if (cb != null && cb.Checked) listGroupManagement.Add(gvGroups.DataKeys[row.RowIndex].Value.ToString()); } user.GroupManagement = String.Join(" ", listGroupManagement); user.Name = txtUserName.Text; user.Password = txtUserPwd.Text; user.Membership = ddluserMembership.Text; user.Salt = user.CreateSalt(16); if (permissions.Visible == true) { if (chkOnd.Checked) user.OndAccess = "1"; else user.OndAccess = "0"; if (chkDebug.Checked) user.DebugAccess = "1"; else user.DebugAccess = "0"; if (chkDiag.Checked) user.DiagAccess = "1"; else user.DiagAccess = "0"; } else { user.OndAccess = "1"; user.DiagAccess = "1"; user.DebugAccess = "1"; } user.Create(user); Master.Msgbox(Utility.Message); } else Master.Msgbox("Passwords Did Not Match"); } else Master.Msgbox("Password Cannot Be Empty Or Contain Spaces"); } else Master.Msgbox("Name Cannot Be Empty Or Contain Spaces"); }
protected void btnImport_Click(object sender, EventArgs e) { WDSUser user = new WDSUser(); string csvFilePath = Server.MapPath("~") + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "csvupload" + Path.DirectorySeparatorChar + "users.csv"; FileUpload.SaveAs(csvFilePath); if (Environment.OSVersion.ToString().Contains("Unix")) Syscall.chmod(csvFilePath, (FilePermissions.S_IWUSR | FilePermissions.S_IRGRP | FilePermissions.S_IROTH | FilePermissions.S_IRUSR)); user.Import(); Master.Msgbox(Utility.Message); }
protected void btnImport_Click(object sender, EventArgs e) { WDSUser user = new WDSUser(); string csvFilePath = Server.MapPath("~") + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "csvupload" + Path.DirectorySeparatorChar + "users.csv"; FileUpload.SaveAs(csvFilePath); if (Environment.OSVersion.ToString().Contains("Unix")) { Syscall.chmod(csvFilePath, (FilePermissions.S_IWUSR | FilePermissions.S_IRGRP | FilePermissions.S_IROTH | FilePermissions.S_IRUSR)); } user.Import(); Master.Msgbox(Utility.Message); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!Master.IsInMembership("Administrator")) { WDSUser wdsuser = new WDSUser(); string tmpUserID = wdsuser.GetID(HttpContext.Current.User.Identity.Name); if(tmpUserID != Request.QueryString["userid"] as string) Response.Redirect("~/views/dashboard/dash.aspx?access=denied"); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!Master.IsInMembership("Administrator")) { WDSUser wdsuser = new WDSUser(); string tmpUserID = wdsuser.GetID(HttpContext.Current.User.Identity.Name); if (tmpUserID != Request.QueryString["userid"] as string) { Response.Redirect("~/views/dashboard/dash.aspx?access=denied"); } } } }
public DataTable TableForUser(string search) { Group group = new Group(); WDSUser user = new WDSUser(); user.ID = user.GetID(HttpContext.Current.User.Identity.Name); user = user.Read(user); DataTable table = group.Search(search); if (!string.IsNullOrEmpty(user.GroupManagement)) { List <string> listManagementGroups = user.GroupManagement.Split(' ').ToList <string>(); List <string> groupNames = new List <string>(); foreach (string id in listManagementGroups) { group.ID = id; group = group.Read(group); groupNames.Add(group.Name); } foreach (DataRow row in table.Rows) { if (!groupNames.Contains(row["groupname"].ToString())) { row.Delete(); } } } else { foreach (DataRow row in table.Rows) { row.Delete(); } } return(table); }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Utility.NoSpaceNotEmpty(txtUserPwd.Text)) { WDSUser user = new WDSUser(); user.ID = Request.QueryString["userid"] as string; user = user.Read(user); if (txtUserPwd.Text == txtUserPwdConfirm.Text) { user.Password = txtUserPwd.Text; user.Salt = user.CreateSalt(16); user.Update(user, user.ID); Master.Msgbox(Utility.Message); } else Master.Msgbox("Passwords Did Not Match"); } else Master.Msgbox("Password Cannot Be Empty Or Contain Spaces"); }
protected void edit_page() { Master.Msgbox(Utility.Message); if (Master.IsInMembership("User")) { WDSUser user = new WDSUser(); user.ID = user.GetID(HttpContext.Current.User.Identity.Name); user = user.Read(user); List<string> listManagementGroups = user.GroupManagement.Split(' ').ToList<string>(); bool isAuthorized = false; foreach (string id in listManagementGroups) { if (group.ID == id) { isAuthorized = true; break; } } if (!isAuthorized) Response.Redirect("~/views/dashboard/dash.aspx?access=denied"); } ddlGroupImage.DataSource = Utility.PopulateImagesDdl(); ddlGroupImage.DataBind(); ddlGroupImage.Items.Insert(0, "Select Image"); ddlGroupKernel.DataSource = Utility.GetKernels(); ddlGroupKernel.DataBind(); ListItem itemKernel = ddlGroupKernel.Items.FindByText("kernel"); if (itemKernel != null) ddlGroupKernel.SelectedValue = "speed"; else ddlGroupKernel.Items.Insert(0, "Select Kernel"); ddlGroupBootImage.DataSource = Utility.GetBootImages(); ddlGroupBootImage.DataBind(); ListItem itemBootImage = ddlGroupBootImage.Items.FindByText("initrd.gz"); if (itemBootImage != null) ddlGroupBootImage.SelectedValue = "initrd.gz"; else ddlGroupBootImage.Items.Insert(0, "Select Boot Image"); lbScripts.DataSource = Utility.GetScripts(); lbScripts.DataBind(); txtGroupName.Text = group.Name; txtGroupDesc.Text = group.Description; ddlGroupImage.Text = group.Image; ddlGroupKernel.Text = group.Kernel; ddlGroupBootImage.Text = group.BootImage; txtGroupArguments.Text = group.Args; txtGroupSenderArgs.Text = group.SenderArgs; if (!string.IsNullOrEmpty(group.Scripts)) { List<string> listhostScripts = group.Scripts.Split(',').ToList<string>(); foreach (ListItem item in lbScripts.Items) foreach (var script in listhostScripts) if (item.Value == script) item.Selected = true; } gvRemove.DataSource = group.CurrentMembers(group.Name); gvRemove.DataBind(); Utility utility = new Utility(); if (utility.GetSettings("Default Host View") == "all") PopulateGrid(); }
public void Create(WDSUser user) { try { using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString)) { NpgsqlCommand cmd = new NpgsqlCommand("users_create", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new NpgsqlParameter("@userName", user.Name)); cmd.Parameters.Add(new NpgsqlParameter("@userPwd", user.CreatePasswordHash(user.Password, user.Salt))); cmd.Parameters.Add(new NpgsqlParameter("@userSalt", user.Salt)); cmd.Parameters.Add(new NpgsqlParameter("@userMembership", user.Membership)); cmd.Parameters.Add(new NpgsqlParameter("@groupManagement", user.GroupManagement)); cmd.Parameters.Add(new NpgsqlParameter("@ondAccess", user.OndAccess)); cmd.Parameters.Add(new NpgsqlParameter("@debugAccess", user.DebugAccess)); cmd.Parameters.Add(new NpgsqlParameter("@diagAccess", user.DiagAccess)); conn.Open(); Utility.Message = cmd.ExecuteScalar() as string; if (Utility.Message.Contains("Successfully")) { History history = new History(); history.Event = "Create"; history.Type = "User"; history.TypeID = user.GetID(user.Name); history.CreateEvent(history); } } } catch (Exception ex) { Utility.Message = "Could Not Create User. Check The Exception Log For More Info"; Logger.Log(ex.ToString()); } }
protected void edit_page() { Master.Msgbox(Utility.Message); ddlHostImage.DataSource = Utility.PopulateImagesDdl(); ddlHostImage.DataBind(); ddlHostImage.Items.Insert(0, "Select Image"); ddlHostGroup.DataSource = Utility.PopulateGroupsDdl(); ddlHostGroup.DataBind(); ddlHostGroup.Items.Insert(0, ""); lbScripts.DataSource = Utility.GetScripts(); lbScripts.DataBind(); if (Master.IsInMembership("User")) { WDSUser user = new WDSUser(); user.ID = user.GetID(HttpContext.Current.User.Identity.Name); user = user.Read(user); List <string> listManagementGroups = user.GroupManagement.Split(' ').ToList <string>(); List <string> allowedGroups = new List <string>(); foreach (string id in listManagementGroups) { Group mgmtgroup = new Group(); mgmtgroup.ID = id; mgmtgroup = mgmtgroup.Read(mgmtgroup); foreach (ListItem item in ddlHostGroup.Items) { if (item.Value == mgmtgroup.Name) { allowedGroups.Add(mgmtgroup.Name); } } } bool isAuthorized = false; foreach (string aGroup in allowedGroups) { if (host.Group == aGroup) { isAuthorized = true; break; } } if (!isAuthorized) { Response.Redirect("~/views/dashboard/dash.aspx?access=denied"); } ddlHostGroup.DataSource = allowedGroups; ddlHostGroup.DataBind(); ddlHostGroup.Items.Insert(0, ""); } ddlHostKernel.DataSource = Utility.GetKernels(); ddlHostKernel.DataBind(); ddlHostKernel.Items.Insert(0, "Select Kernel"); ddlHostBootImage.DataSource = Utility.GetBootImages(); ddlHostBootImage.DataBind(); ddlHostBootImage.Items.Insert(0, "Select Boot Image"); txtHostName.Text = host.Name; txtHostMac.Text = host.Mac; ddlHostImage.Text = host.Image; ddlHostGroup.Text = host.Group; txtHostDesc.Text = host.Description; ddlHostKernel.Text = host.Kernel; ddlHostBootImage.Text = host.BootImage; txtHostArguments.Text = host.Args; if (!string.IsNullOrEmpty(host.Scripts)) { List <string> listhostScripts = host.Scripts.Split(',').ToList <string>(); foreach (ListItem item in lbScripts.Items) { foreach (var script in listhostScripts) { if (item.Value == script) { item.Selected = true; } } } } }
protected void Page_Load(object sender, EventArgs e) { user = new WDSUser(); requestedPage = Request.QueryString["page"] as string; user.ID = Request.QueryString["userid"] as string; user.Read(user); if (!IsPostBack) { if (Master.IsInMembership("User")) Response.Redirect("~/views/dashboard/dash.aspx?access=denied"); Master.Msgbox(Utility.Message); switch (requestedPage) { case "edit": lblSubNav.Text = "| edit"; edit.Visible = true; edit_page(); break; case "history": lblSubNav.Text = "| history"; historypage.Visible = true; history_page(); break; default: break; } } }
protected void CrucibleLogin_Authenticate(object sender, AuthenticateEventArgs e) { Utility login = new Utility(); History history = new History(); WDSUser wdsuser = new WDSUser(); string loginDomain = login.GetSettings("AD Login Domain"); history.Type = "User"; history.IP = GetIP(); history.EventUser = CrucibleLogin.UserName; wdsuser.ID = wdsuser.GetID(CrucibleLogin.UserName); history.TypeID = wdsuser.ID; if (string.IsNullOrEmpty(wdsuser.ID)) { history.Event = "Failed Login"; e.Authenticated = false; lblError.Visible = true; } else { if (string.IsNullOrEmpty(loginDomain)) { bool result = login.UserLogin(CrucibleLogin.UserName, CrucibleLogin.Password); if ((result)) { history.Event = "Successful Login"; e.Authenticated = true; } else { history.Event = "Failed Login"; e.Authenticated = false; lblError.Visible = true; } } else { try { PrincipalContext context = new PrincipalContext(ContextType.Domain, loginDomain, CrucibleLogin.UserName, CrucibleLogin.Password); UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, CrucibleLogin.UserName); if (user != null) { history.Event = "Successful Login"; e.Authenticated = true; } } catch (Exception ex) { Logger.Log(ex.Message); bool result = login.UserLogin(CrucibleLogin.UserName, CrucibleLogin.Password); if ((result)) { history.Event = "Successful Login"; e.Authenticated = true; } else { history.Event = "Failed Login"; e.Authenticated = false; lblError.Visible = true; } } } } history.CreateEvent(history); }
public void consolelogin() { History history = new History(); Utility settings = new Utility(); HttpContext postedContext = HttpContext.Current; HttpFileCollection Files = postedContext.Request.Files; string serverKey = settings.Decode((string)postedContext.Request.Form["serverKey"]); history.IP = settings.Decode((string)postedContext.Request.Form["clientIP"]); if (serverKey == settings.GetSettings("Server Key")) { string username = settings.Decode((string)postedContext.Request.Form["username"]); string password = settings.Decode((string)postedContext.Request.Form["password"]); string task = settings.Decode((string)postedContext.Request.Form["task"]); if (settings.UserLogin(username, password)) { WDSUser wdsuser = new WDSUser(); string userID = wdsuser.GetID(username); wdsuser.ID = userID; wdsuser = wdsuser.Read(wdsuser); if (task == "ond" && wdsuser.OndAccess == "1") { HttpContext.Current.Response.Write("true," + userID); history.Event = "Successful Console Login"; history.Type = "User"; history.EventUser = username; history.TypeID = userID; history.Notes = ""; history.CreateEvent(history); } else if (task == "debug" && wdsuser.DebugAccess == "1") { HttpContext.Current.Response.Write("true," + userID); history.Event = "Successful Console Login"; history.Type = "User"; history.EventUser = username; history.TypeID = userID; history.Notes = ""; history.CreateEvent(history); } else if (task == "diag" && wdsuser.DiagAccess == "1") { HttpContext.Current.Response.Write("true," + userID); history.Event = "Successful Console Login"; history.Type = "User"; history.EventUser = username; history.TypeID = userID; history.Notes = ""; history.CreateEvent(history); } else { HttpContext.Current.Response.Write("false"); history.Event = "Failed Console Login"; history.Type = "User"; history.EventUser = username; history.Notes = password; history.CreateEvent(history); } } else if (!string.IsNullOrEmpty(settings.GetSettings("AD Login Domain"))) { try { PrincipalContext context = new PrincipalContext(ContextType.Domain, settings.GetSettings("AD Login Domain"), username, password); UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username); if (user != null) { WDSUser wdsuser = new WDSUser(); string userID = wdsuser.GetID(username); wdsuser.ID = userID; wdsuser = wdsuser.Read(wdsuser); if (task == "ond" && wdsuser.OndAccess == "1") { HttpContext.Current.Response.Write("true," + userID); history.Event = "Successful Console Login"; history.Type = "User"; history.EventUser = username; history.TypeID = userID; history.Notes = ""; history.CreateEvent(history); } else if (task == "debug" && wdsuser.DebugAccess == "1") { HttpContext.Current.Response.Write("true," + userID); history.Event = "Successful Console Login"; history.Type = "User"; history.EventUser = username; history.TypeID = userID; history.Notes = ""; history.CreateEvent(history); } else if (task == "diag" && wdsuser.DiagAccess == "1") { HttpContext.Current.Response.Write("true," + userID); history.Event = "Successful Console Login"; history.Type = "User"; history.EventUser = username; history.TypeID = userID; history.Notes = ""; history.CreateEvent(history); } else { HttpContext.Current.Response.Write("false"); history.Event = "Failed Console Login"; history.Type = "User"; history.EventUser = username; history.Notes = password; history.CreateEvent(history); } } } catch { HttpContext.Current.Response.Write("false"); history.Event = "Failed Console Login"; history.Type = "User"; history.EventUser = username; history.Notes = password; history.CreateEvent(history); } } else { HttpContext.Current.Response.Write("false"); history.Event = "Failed Console Login"; history.Type = "User"; history.EventUser = username; history.Notes = password; history.CreateEvent(history); } } else { Logger.Log("Incorrect Key For Client Login Was Provided"); } }
protected void edit_page() { Master.Msgbox(Utility.Message); ddlHostImage.DataSource = Utility.PopulateImagesDdl(); ddlHostImage.DataBind(); ddlHostImage.Items.Insert(0, "Select Image"); ddlHostGroup.DataSource = Utility.PopulateGroupsDdl(); ddlHostGroup.DataBind(); ddlHostGroup.Items.Insert(0, ""); lbScripts.DataSource = Utility.GetScripts(); lbScripts.DataBind(); if (Master.IsInMembership("User")) { WDSUser user = new WDSUser(); user.ID = user.GetID(HttpContext.Current.User.Identity.Name); user = user.Read(user); List<string> listManagementGroups = user.GroupManagement.Split(' ').ToList<string>(); List<string> allowedGroups = new List<string>(); foreach (string id in listManagementGroups) { Group mgmtgroup = new Group(); mgmtgroup.ID = id; mgmtgroup = mgmtgroup.Read(mgmtgroup); foreach (ListItem item in ddlHostGroup.Items) { if (item.Value == mgmtgroup.Name) allowedGroups.Add(mgmtgroup.Name); } } bool isAuthorized = false; foreach (string aGroup in allowedGroups) { if (host.Group == aGroup) { isAuthorized = true; break; } } if (!isAuthorized) Response.Redirect("~/views/dashboard/dash.aspx?access=denied"); ddlHostGroup.DataSource = allowedGroups; ddlHostGroup.DataBind(); ddlHostGroup.Items.Insert(0, ""); } ddlHostKernel.DataSource = Utility.GetKernels(); ddlHostKernel.DataBind(); ddlHostKernel.Items.Insert(0, "Select Kernel"); ddlHostBootImage.DataSource = Utility.GetBootImages(); ddlHostBootImage.DataBind(); ddlHostBootImage.Items.Insert(0, "Select Boot Image"); txtHostName.Text = host.Name; txtHostMac.Text = host.Mac; ddlHostImage.Text = host.Image; ddlHostGroup.Text = host.Group; txtHostDesc.Text = host.Description; ddlHostKernel.Text = host.Kernel; ddlHostBootImage.Text = host.BootImage; txtHostArguments.Text = host.Args; if (!string.IsNullOrEmpty(host.Scripts)) { List<string> listhostScripts = host.Scripts.Split(',').ToList<string>(); foreach (ListItem item in lbScripts.Items) foreach (var script in listhostScripts) if (item.Value == script) item.Selected = true; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!Master.IsInMembership("Administrator")) { WDSUser wdsuser = new WDSUser(); string userID = wdsuser.GetID(HttpContext.Current.User.Identity.Name); if(string.IsNullOrEmpty(userID)) //Fix for clicking logout button when on users page Response.Redirect("~/"); else Response.Redirect("~/views/users/resetpass.aspx?userid=" + userID); } PopulateGrid(); } }
protected void PopulateGrid() { WDSUser user = new WDSUser(); gvUsers.DataSource = user.Search(txtSearch.Text); gvUsers.DataBind(); lblTotal.Text = gvUsers.Rows.Count.ToString() + " Result(s) / " + user.GetTotalCount() + " Total User(s)"; }
public DataTable TableForUser(string search) { Host host = new Host(); WDSUser user = new WDSUser(); user.ID = user.GetID(HttpContext.Current.User.Identity.Name); user = user.Read(user); DataTable table = new DataTable(); if (!string.IsNullOrEmpty(user.GroupManagement)) { List<string> listManagementGroups = user.GroupManagement.Split(' ').ToList<string>(); foreach (string id in listManagementGroups) { Group mgmtgroup = new Group(); mgmtgroup.ID = id; mgmtgroup = mgmtgroup.Read(mgmtgroup); table.Merge(host.SearchLimited(search, mgmtgroup.Name)); } if (table.Rows.Count > 0) { DataView dtview = new DataView(table); dtview.Sort = "hostName asc"; table = dtview.ToTable(); } } return table; }
public DataTable TableForUser(string search) { Group group = new Group(); WDSUser user = new WDSUser(); user.ID = user.GetID(HttpContext.Current.User.Identity.Name); user = user.Read(user); DataTable table = group.Search(search); if (!string.IsNullOrEmpty(user.GroupManagement)) { List<string> listManagementGroups = user.GroupManagement.Split(' ').ToList<string>(); List<string> groupNames = new List<string>(); foreach (string id in listManagementGroups) { group.ID = id; group = group.Read(group); groupNames.Add(group.Name); } foreach (DataRow row in table.Rows) { if (!groupNames.Contains(row["groupname"].ToString())) row.Delete(); } } else { foreach (DataRow row in table.Rows) { row.Delete(); } } return table; }
public WDSUser Read(WDSUser user) { try { using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString)) { NpgsqlCommand cmd = new NpgsqlCommand("users_read", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new NpgsqlParameter("@userID", user.ID)); conn.Open(); NpgsqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { user.Name = (string)rdr["username"]; user.Membership = (string)rdr["usermembership"]; user.GroupManagement = rdr["groupmanagement"].ToString(); user.OndAccess = rdr["allowond"].ToString(); user.DebugAccess = rdr["allowdebug"].ToString(); user.DiagAccess = rdr["allowdiag"].ToString(); } } } catch (Exception ex) { Logger.Log(ex.ToString()); } return user; }
protected void edit_page() { Master.Msgbox(Utility.Message); if (Master.IsInMembership("User")) { WDSUser user = new WDSUser(); user.ID = user.GetID(HttpContext.Current.User.Identity.Name); user = user.Read(user); List <string> listManagementGroups = user.GroupManagement.Split(' ').ToList <string>(); bool isAuthorized = false; foreach (string id in listManagementGroups) { if (group.ID == id) { isAuthorized = true; break; } } if (!isAuthorized) { Response.Redirect("~/views/dashboard/dash.aspx?access=denied"); } } ddlGroupImage.DataSource = Utility.PopulateImagesDdl(); ddlGroupImage.DataBind(); ddlGroupImage.Items.Insert(0, "Select Image"); ddlGroupKernel.DataSource = Utility.GetKernels(); ddlGroupKernel.DataBind(); ListItem itemKernel = ddlGroupKernel.Items.FindByText("kernel"); if (itemKernel != null) { ddlGroupKernel.SelectedValue = "speed"; } else { ddlGroupKernel.Items.Insert(0, "Select Kernel"); } ddlGroupBootImage.DataSource = Utility.GetBootImages(); ddlGroupBootImage.DataBind(); ListItem itemBootImage = ddlGroupBootImage.Items.FindByText("initrd.gz"); if (itemBootImage != null) { ddlGroupBootImage.SelectedValue = "initrd.gz"; } else { ddlGroupBootImage.Items.Insert(0, "Select Boot Image"); } lbScripts.DataSource = Utility.GetScripts(); lbScripts.DataBind(); txtGroupName.Text = group.Name; txtGroupDesc.Text = group.Description; ddlGroupImage.Text = group.Image; ddlGroupKernel.Text = group.Kernel; ddlGroupBootImage.Text = group.BootImage; txtGroupArguments.Text = group.Args; txtGroupSenderArgs.Text = group.SenderArgs; if (!string.IsNullOrEmpty(group.Scripts)) { List <string> listhostScripts = group.Scripts.Split(',').ToList <string>(); foreach (ListItem item in lbScripts.Items) { foreach (var script in listhostScripts) { if (item.Value == script) { item.Selected = true; } } } } gvRemove.DataSource = group.CurrentMembers(group.Name); gvRemove.DataBind(); Utility utility = new Utility(); if (utility.GetSettings("Default Host View") == "all") { PopulateGrid(); } }
public void UpdateNoPass(WDSUser user, string userID) { try { using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString)) { NpgsqlCommand cmd = new NpgsqlCommand("users_update_nopass", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new NpgsqlParameter("@userID", userID)); cmd.Parameters.Add(new NpgsqlParameter("@userName", user.Name)); cmd.Parameters.Add(new NpgsqlParameter("@userMembership", user.Membership)); cmd.Parameters.Add(new NpgsqlParameter("@groupManagement", user.GroupManagement)); cmd.Parameters.Add(new NpgsqlParameter("@ondAccess", user.OndAccess)); cmd.Parameters.Add(new NpgsqlParameter("@debugAccess", user.DebugAccess)); cmd.Parameters.Add(new NpgsqlParameter("@diagAccess", user.DiagAccess)); conn.Open(); Utility.Message = cmd.ExecuteScalar() as string; } } catch (Exception ex) { Utility.Message = "Could Not Update User. Check The Exception Log For More Info"; Logger.Log(ex.ToString()); } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Utility.NoSpaceNotEmpty(txtUserName.Text)) { if (Utility.NoSpaceNotEmpty(txtUserPwd.Text)) { WDSUser user = new WDSUser(); if (txtUserPwd.Text == txtUserPwdConfirm.Text) { Group group = new Group(); List <string> listGroupManagement = new List <string>(); foreach (GridViewRow row in gvGroups.Rows) { CheckBox cb = (CheckBox)row.FindControl("chkSelector"); if (cb != null && cb.Checked) { listGroupManagement.Add(gvGroups.DataKeys[row.RowIndex].Value.ToString()); } } user.GroupManagement = String.Join(" ", listGroupManagement); user.Name = txtUserName.Text; user.Password = txtUserPwd.Text; user.Membership = ddluserMembership.Text; user.Salt = user.CreateSalt(16); if (permissions.Visible == true) { if (chkOnd.Checked) { user.OndAccess = "1"; } else { user.OndAccess = "0"; } if (chkDebug.Checked) { user.DebugAccess = "1"; } else { user.DebugAccess = "0"; } if (chkDiag.Checked) { user.DiagAccess = "1"; } else { user.DiagAccess = "0"; } } else { user.OndAccess = "1"; user.DiagAccess = "1"; user.DebugAccess = "1"; } user.Create(user); Master.Msgbox(Utility.Message); } else { Master.Msgbox("Passwords Did Not Match"); } } else { Master.Msgbox("Password Cannot Be Empty Or Contain Spaces"); } } else { Master.Msgbox("Name Cannot Be Empty Or Contain Spaces"); } }
public void Delete(List<int> listDelete) { try { using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString)) { conn.Open(); for (int i = 0; i < listDelete.Count; i++) { WDSUser user = new WDSUser(); user.ID = listDelete[i].ToString(); user = user.Read(user); NpgsqlCommand cmd = new NpgsqlCommand("users_delete", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new NpgsqlParameter("@userID", listDelete[i])); cmd.ExecuteNonQuery(); History history = new History(); history.Event = "Delete"; history.Type = "User"; history.TypeID = user.ID; history.CreateEvent(history); } Utility.Message = "Successfully Deleted User(s)"; } } catch (Exception ex) { Utility.Message = "Could Not Delete User. Check The Exception Log For More Info"; Logger.Log(ex.ToString()); } }