private void ViewUsers_Load(object sender, EventArgs e) { try { // Load users to a list. GetAccessLevel current = new GetAccessLevel(); current.SessionKey = information.Token; current.Id = information.UserId; string json = ""; json = JsonConvert.SerializeObject(current); json = "=" + json; string path = ""; path = information.URL + "/api/users/getAll"; string response = ApiConnector.SendToApi(path, json); userList = JsonConvert.DeserializeObject <List <UserGeneral> >(response); // Add these items to the GUI list lstUsers.DataSource = userList; lstUsers.DisplayMember = "Username"; lstUsers.ValueMember = "UserId"; } catch (Exception ex) { } }
private void btnAccountSettings_Click(object sender, EventArgs e) { GetAccessLevel current = new GetAccessLevel(); current.SessionKey = information.Token; current.Id = information.UserId; string json = ""; json = JsonConvert.SerializeObject(current); json = "=" + json; string path = ""; path = information.URL + "/api/users/getAll"; string response = ApiConnector.SendToApi(path, json); var userList = JsonConvert.DeserializeObject <List <UserGeneral> >(response); UserGeneral yourSelf = new UserGeneral(); foreach (UserGeneral us in userList) { if (us.UserId == information.UserId) { yourSelf = us; } } EditOrAddUser form = new EditOrAddUser(information, yourSelf); form.Show(); }
private void btnFinishSession_Click(object sender, EventArgs e) { // Ship Log... current.SessionKey = information.Token; current.UserId = information.UserId; current.LogContent = txtConsole.Text; current.PermissionLevelId = 1; current.FinishTime = DateTime.Now.ToString("yyy-MM-dd HH:mm:ss.fff"); current.UserNote = ""; current.ProtectedAccountId = 2; string json = ""; json = JsonConvert.SerializeObject(current); json = "=" + json; string path = ""; path = information.URL + "/api/sshLog"; string response = ApiConnector.SendToApi(path, json); // Close session. currentSession.Disconnect(); this.Close(); }
private void btnRunAutomation_Click(object sender, EventArgs e) { try { GetAccessLevel current = new GetAccessLevel(); current.SessionKey = information.Token; current.Id = servers[lstServerList.SelectedIndex].ServerOsId; string json = ""; json = JsonConvert.SerializeObject(current); json = "=" + json; string path = ""; path = information.URL + "/api/protectedAccount/get"; string response = ApiConnector.SendToApi(path, json); ProtectedAccount acc = JsonConvert.DeserializeObject <ProtectedAccount>(response); SshClient currentSession = new SshClient(servers[lstServerList.SelectedIndex].ServerIp, 22, acc.Username, acc.Password); currentSession.Connect(); // get the automation script! currentSession.RunCommand(currentAutomation[cmbAutomationList.SelectedIndex].ScriptText); // close session currentSession.Disconnect(); // show success message box! MessageBox.Show("Successfully Completed Automation!"); } catch (Exception ex) { MessageBox.Show("An Error Occorred Running this automation for more info: " + ex); } }
private void btnViewPassword_Click(object sender, EventArgs e) { try { var selectedAccount = passwords[lstAccountsList.SelectedIndex]; UserGeneral temp = new UserGeneral(); GetAccessLevel current = new GetAccessLevel(); current.SessionKey = information.Token; current.Id = information.UserId; var json = JsonConvert.SerializeObject(current); json = "=" + json; var path = information.URL + "/api/users/getSelf"; var response = ApiConnector.SendToApi(path, json); temp = JsonConvert.DeserializeObject <UserGeneral>(response); if (temp.PermissionLevelId == 1 || temp.PermissionLevelId == 2) { PasswordView passwordView = new PasswordView(selectedAccount, true); passwordView.ShowDialog(); } else { PasswordView passwordView = new PasswordView(selectedAccount, false); passwordView.ShowDialog(); } } catch { MessageBox.Show("Error in loading password, please try again!"); } }
private void btnDelete_Click(object sender, EventArgs e) { // Find selected User UserRemoveOrEdit current = new UserRemoveOrEdit(); current.SessionKey = information.Token; current.UserId = userList[lstUsers.SelectedIndex].UserId; current.PermissionLevelId = userList[lstUsers.SelectedIndex].PermissionLevelId; current.FirstName = userList[lstUsers.SelectedIndex].FirstName; current.Surname = userList[lstUsers.SelectedIndex].Surname; current.JobTitle = userList[lstUsers.SelectedIndex].JobTitle; current.DepartmentId = userList[lstUsers.SelectedIndex].DepartmentId; current.Username = userList[lstUsers.SelectedIndex].Username; current.Password = userList[lstUsers.SelectedIndex].Password; current.LastLoginDate = userList[lstUsers.SelectedIndex].LastLoginDate; current.Note = userList[lstUsers.SelectedIndex].Note; if (current.UserId != information.UserId) { string json = ""; json = JsonConvert.SerializeObject(current); json = "=" + json; string path = ""; path = information.URL + "/api/users/delete"; string response = ApiConnector.SendToApi(path, json); if (response == "\"Pass!\"") { MessageBox.Show("User successfully removed from system!"); // Clean up list box. lstUsers.DataSource = null; lstUsers.DataSource = userList; lstUsers.DisplayMember = "Username"; lstUsers.ValueMember = "UserId"; } else { MessageBox.Show("Something went wrong, please try again!"); } } else { MessageBox.Show("You cant delete yourself!"); } }
private void getAutomation(int?serverOsId) { GetAccessLevel current = new GetAccessLevel(); current.SessionKey = information.Token; current.Id = serverOsId; string json = ""; json = JsonConvert.SerializeObject(current); json = "=" + json; string path = ""; path = information.URL + "/api/automation/getAll"; string response = ApiConnector.SendToApi(path, json); currentAutomation = JsonConvert.DeserializeObject <List <Automation> >(response); }
private void btnDelete_Click(object sender, EventArgs e) { // Find selected User GetAccessLevel current = new GetAccessLevel(); current.SessionKey = information.Token; current.Id = servers[lstServers.SelectedIndex].ServerId; if (true) { string json = ""; json = JsonConvert.SerializeObject(current); json = "=" + json; string path = ""; path = information.URL + "/api/servers/delete"; string response = ApiConnector.SendToApi(path, json); if (response == "\"Pass!\"") { MessageBox.Show("User successfully removed from system!"); // Clean up list box. lstServers.DataSource = null; lstServers.DataSource = servers; lstServers.DisplayMember = "serverName"; lstServers.ValueMember = "serverId"; } else { MessageBox.Show("Something went wrong, please try again!"); } } else { MessageBox.Show("You cant delete yourself!"); } }
private void btnSave_Click(object sender, EventArgs e) { try { if (btnSave.Text == "Save") { // Add new ServerShip newServer = new ServerShip(); newServer.SessionKey = information.Token; newServer.ServerId = -1; newServer.ServerName = txtName.Text; newServer.ServerOsId = cmbOs.SelectedIndex + 1; newServer.ServerDescription = txtDescription.Text; newServer.ServerIp = txtIp.Text; newServer.IpStatic = chkStatic.Checked; newServer.Fqdn = txtFQDN.Text; newServer.ServerNote = txtNotes.Text; var json = JsonConvert.SerializeObject(newServer); json = "=" + json; var path = information.URL + "/api/servers"; var response = ApiConnector.SendToApi(path, json); if (response.Contains("Passed!")) { MessageBox.Show("Server added!"); newServer.ServerId = Int32.Parse(response.Substring(1, 2)); } // Create permission for this user. ServerAccessLogedIn accessToSend = new ServerAccessLogedIn(); accessToSend.SessionKey = information.Token; accessToSend.ServerAccessId = -1; accessToSend.UserId = information.UserId; accessToSend.DepartmentId = 1; accessToSend.ServerId = newServer.ServerId; accessToSend.StartTime = null; accessToSend.FinishTime = null; accessToSend.StandardAccountId = null; accessToSend.Allowed = true; json = JsonConvert.SerializeObject(accessToSend); json = "=" + json; path = information.URL + "/api/serverAccessLevel"; response = ApiConnector.SendToApi(path, json); } else { // Update Existing ServerShip newServer = new ServerShip(); newServer.SessionKey = information.Token; newServer.ServerId = Int32.Parse(txtId.Text); newServer.ServerName = txtName.Text; newServer.ServerOsId = cmbOs.SelectedIndex + 1; newServer.ServerDescription = txtDescription.Text; newServer.ServerIp = txtIp.Text; newServer.IpStatic = chkStatic.Checked; newServer.Fqdn = txtFQDN.Text; newServer.ServerNote = txtNotes.Text; var json = JsonConvert.SerializeObject(newServer); json = "=" + json; var path = information.URL + "/api/servers"; var response = ApiConnector.SendToApi(path, json); if (response.Contains("\"Passed!\"")) { MessageBox.Show("Server updated!"); } } } catch (Exception ex) { // Do nothing } this.Close(); }
private void btnQuit_Click(object sender, EventArgs e) { try { if (rdp.Connected.ToString() == "1") { rdp.Disconnect(); timer1.Stop(); vf.Close(); // Move recording to blob storage var location = new System.IO.DirectoryInfo(Path.GetTempPath() + timeStamp + ".avi"); FileInfo f = new FileInfo(location.ToString()); string uploadfile = f.FullName; var client = new SftpClient("92.233.50.207", 22, "root", "ChocolateBalls1"); client.Connect(); client.ChangeDirectory(@"/Recordings"); var fileStream = new FileStream(location.ToString(), FileMode.Open); client.BufferSize = 4 * 1024; client.UploadFile(fileStream, f.Name, null); client.Disconnect(); client.Dispose(); //using (var scp = new ScpClient("92.233.50.207", "root", "toor")) //{ // scp.Connect(); // var location = new System.IO.DirectoryInfo(Path.GetTempPath() + timeStamp + ".avi"); // scp.Upload(location, "/recordings " + timeStamp + ".avi"); //} //ScpClient currentScp = new ScpClient("92.233.50.207", "administrator", "test"); //currentScp.Connect(); //var location = new System.IO.DirectoryInfo(Path.GetTempPath() + timeStamp + ".avi"); //currentScp.Upload(location, "/recordings " + timeStamp + ".avi"); //currentScp.Disconnect(); } } catch (Exception ex) { MessageBox.Show("Error Disconnecting", "Error disconnecting from the seesion. Please try again!"); this.Close(); } // Ship recording // Ship the Log! current.SessionKey = information.Token; current.UserId = information.UserId; current.LogContentLocation = timeStamp + ".avi"; current.PermissionLevelId = 1; current.FinishTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); current.UserNote = ""; current.ProtectedAccountId = 2; string json = ""; json = JsonConvert.SerializeObject(current); json = "=" + json; string path = ""; path = information.URL + "/api/desktopLog"; string response = ApiConnector.SendToApi(path, json); this.Close(); }
private void btnLogin_Click(object sender, EventArgs e) { try { // Login to the system send the request. Get back token and if successful then load the next form. Else show login invalid. Authentication authString = new Authentication(); authString.Username = txtUsername.Text; authString.Password = txtPassword.Text; //SALT AND HASH! // Do this! /// Dont ignore it! //******************************** HashAlgorithm algo = new SHA256Managed(); var hash = algo.ComputeHash(Encoding.ASCII.GetBytes("quis" + authString.Password + "quam")); string hexHash = ""; for (int i = 0; i < hash.Length; i++) { hexHash = hexHash + hash[i].ToString(); } authString.Password = hexHash; string json = ""; json = JsonConvert.SerializeObject(authString); json = "=" + json; string path = ""; path = information.URL + "/api/authentication"; string response = ApiConnector.SendToApi(path, json); response = response.Substring(1, response.Length - 2); if (response == "fail" || response.Contains("FAIL")) { throw new AuthenticationException("Incorrect Username or Password"); } //add the responce to the information tile LoggedInType token = new LoggedInType(); token.SessionKey = response; information.Token = response; // Get self! UserGeneral yourself = new UserGeneral(); path = information.URL + "/api/users/getSelf"; json = JsonConvert.SerializeObject(token); json = "=" + json; response = ApiConnector.SendToApi(path, json); //response = response.Substring(1, response.Length - 2); //response.Replace(@"\", ""); yourself = JsonConvert.DeserializeObject <UserGeneral>(response); information.Name = yourself.FirstName + " " + yourself.Surname + " - " + yourself.JobTitle; information.UserId = yourself.UserId; // Open next form and pass information! this.Hide(); ServerView serverView = new ServerView(information); serverView.ShowDialog(); } catch (Exception) { // Catch all exceptions MessageBox.Show("Login error, Please try again! "); } }
private void Form1_Load(object sender, EventArgs e) { lblWelcome.Text = " Welcome back " + information.Name; // Load in all server Access levels for user GetAccessLevel current = new GetAccessLevel(); current.SessionKey = information.Token; current.Id = information.UserId; string json = ""; json = JsonConvert.SerializeObject(current); json = "=" + json; string path = ""; path = information.URL + "/api/protectedAccount/getAll"; string response = ApiConnector.SendToApi(path, json); serverList = JsonConvert.DeserializeObject <List <ServerAccessLevel> >(response); // Load in all appropriate server details foreach (ServerAccessLevel access in serverList) { // Call API for server info GetAccessLevel currServer = new GetAccessLevel(); currServer.SessionKey = information.Token; currServer.Id = access.ServerId; json = JsonConvert.SerializeObject(currServer); json = "=" + json; path = information.URL + "/api/servers/get"; // Add to server list response = ApiConnector.SendToApi(path, json); var objec = JsonConvert.DeserializeObject <Server>(response); if (objec.ServerId != 5) { servers.Add(objec); } else { current.Id = access.StandardAccountId; json = JsonConvert.SerializeObject(current); json = "=" + json; path = information.URL + "/api/standardAccount/get"; response = ApiConnector.SendToApi(path, json); var pass = JsonConvert.DeserializeObject <StandardAccount>(response); passwords.Add(pass); } } // Add to the UI list lstServerList.DataSource = servers; lstServerList.DisplayMember = "ServerName"; lstServerList.ValueMember = "ServerId"; lstAccountsList.DataSource = passwords; lstAccountsList.DisplayMember = "AccountName"; lstAccountsList.ValueMember = "StandardAccountId"; // Load in all services details getAutomation(servers[0].ServerOsId); cmbAutomationList.DataSource = currentAutomation; cmbAutomationList.DisplayMember = "ScriptName"; cmbAutomationList.ValueMember = "AutomationScriptId"; // If admin then enable the user management, server management, view logs UserGeneral temp = new UserGeneral(); current.SessionKey = information.Token; current.Id = information.UserId; json = JsonConvert.SerializeObject(current); json = "=" + json; path = information.URL + "/api/users/getSelf"; response = ApiConnector.SendToApi(path, json); temp = JsonConvert.DeserializeObject <UserGeneral>(response); if (temp.PermissionLevelId == 1 || temp.PermissionLevelId == 2) { btnAccountSettings.Enabled = true; btnManageUsers.Enabled = true; btnManagePasswords.Enabled = false; btnViewLogs.Enabled = true; btnManageServers.Enabled = true; } }
private void btnConnect_Click(object sender, EventArgs e) { //Decide if the server is SSH or VNC if (servers[lstServerList.SelectedIndex].ServerOsId == 3 || servers[lstServerList.SelectedIndex].ServerOsId == 4 || servers[lstServerList.SelectedIndex].ServerOsId == 5 || servers[lstServerList.SelectedIndex].ServerOsId == 6) { try { // Start SSH session GetAccessLevel current = new GetAccessLevel(); current.SessionKey = information.Token; current.Id = servers[lstServerList.SelectedIndex].ServerOsId; string json = ""; json = JsonConvert.SerializeObject(current); json = "=" + json; string path = ""; path = information.URL + "/api/protectedAccount/get"; string response = ApiConnector.SendToApi(path, json); ProtectedAccount acc = JsonConvert.DeserializeObject <ProtectedAccount>(response); SshSessionDetails details = new SshSessionDetails { ServerIp = servers[lstServerList.SelectedIndex].ServerIp, Port = 22, Username = acc.Username, Password = acc.Password }; SshConnectionForm sshCon = new SshConnectionForm(details, information); sshCon.ShowDialog(); } catch (Exception ex) { MessageBox.Show("Error connecting to server. Check the server is on."); } } else { // Start VNC session try { GetAccessLevel current = new GetAccessLevel(); current.SessionKey = information.Token; current.Id = servers[lstServerList.SelectedIndex].ServerOsId; string json = ""; json = JsonConvert.SerializeObject(current); json = "=" + json; string path = ""; path = information.URL + "/api/protectedAccount/get"; string response = ApiConnector.SendToApi(path, json); ProtectedAccount acc = JsonConvert.DeserializeObject <ProtectedAccount>(response); SshSessionDetails details = new SshSessionDetails { ServerIp = servers[lstServerList.SelectedIndex].ServerIp, Port = 22, Username = acc.Username, Password = acc.Password }; VncWindow rdp = new VncWindow(details, information); rdp.ShowDialog(); } catch (Exception ex) { MessageBox.Show("Error connecting to server. Check the server is on."); } } }
private void btnSave_Click(object sender, EventArgs e) { try { if (btnSave.Text == "Save") { // Add new user UserRemoveOrEdit newUser = new UserRemoveOrEdit(); newUser.UserId = -1; newUser.SessionKey = information.Token; newUser.PermissionLevelId = cmbAccessLevel.SelectedIndex + 1; newUser.FirstName = txtFirstName.Text; newUser.Surname = txtSurname.Text; newUser.JobTitle = txtJobTitle.Text; newUser.DepartmentId = cmbDepartments.SelectedIndex + 1; newUser.Username = txtUsername.Text; //SALT AND HASH! // Do this! /// Dont ignore it! //******************************** HashAlgorithm algo = new SHA256Managed(); var hash = algo.ComputeHash(Encoding.ASCII.GetBytes("quis" + txtPassword.Text + "quam")); string hexHash = ""; for (int i = 0; i < hash.Length; i++) { hexHash = hexHash + hash[i].ToString(); } newUser.Password = hexHash; newUser.LastLoginDate = DateTime.Now.ToString("yyy-MM-dd HH:mm:ss.fff"); newUser.Note = txtNotes.Text; // Send off to the API var json = JsonConvert.SerializeObject(newUser); json = "=" + json; var path = information.URL + "/api/users"; var response = ApiConnector.SendToApi(path, json); if (response.Contains("Passed!")) { MessageBox.Show("User added!"); var temp = response.Substring(1, 2); newUser.UserId = Int32.Parse(temp); } GetAccessLevel sendlvl = new GetAccessLevel(); sendlvl.SessionKey = information.Token; sendlvl.Id = 1; json = JsonConvert.SerializeObject(sendlvl); json = "=" + json; path = ""; path = information.URL + "/api/protectedAccount/getAll"; response = ApiConnector.SendToApi(path, json); var serverList = JsonConvert.DeserializeObject <List <ServerAccessLevel> >(response); ServerAccessLogedIn accessToSend = new ServerAccessLogedIn(); // Add the user permissions bassed on access Level Selected if (cmbAccessLevel.SelectedIndex < 4) { // For all servers foreach (ServerAccessLevel access in serverList) { // Call API for server info GetAccessLevel currServer = new GetAccessLevel(); currServer.SessionKey = information.Token; currServer.Id = access.ServerId; json = JsonConvert.SerializeObject(currServer); json = "=" + json; path = information.URL + "/api/servers/get"; // Add to server list response = ApiConnector.SendToApi(path, json); var objec = JsonConvert.DeserializeObject <Server>(response); if (objec.ServerId != 5) { accessToSend.SessionKey = information.Token; accessToSend.ServerAccessId = -1; accessToSend.UserId = newUser.UserId; accessToSend.DepartmentId = cmbDepartments.SelectedIndex + 1; accessToSend.ServerId = objec.ServerId; accessToSend.StartTime = null; accessToSend.FinishTime = null; accessToSend.StandardAccountId = access.StandardAccountId; accessToSend.Allowed = true; } json = JsonConvert.SerializeObject(accessToSend); json = "=" + json; path = information.URL + "/api/serverAccessLevel"; response = ApiConnector.SendToApi(path, json); } } else if (cmbAccessLevel.SelectedIndex < 5) { // For only linux servers foreach (ServerAccessLevel access in serverList) { // Call API for server info GetAccessLevel currServer = new GetAccessLevel(); currServer.SessionKey = information.Token; currServer.Id = access.ServerId; json = JsonConvert.SerializeObject(currServer); json = "=" + json; path = information.URL + "/api/servers/get"; // Add to server list response = ApiConnector.SendToApi(path, json); var objec = JsonConvert.DeserializeObject <Server>(response); if (objec.ServerId != 5 && objec.ServerOsId != 1 && objec.ServerOsId != 2) { //Create the access level accessToSend.UserId = newUser.UserId; accessToSend.DepartmentId = current.DepartmentId; accessToSend.ServerId = objec.ServerId; accessToSend.StartTime = null; accessToSend.FinishTime = null; accessToSend.StandardAccountId = access.StandardAccountId; accessToSend.Allowed = true; json = JsonConvert.SerializeObject(accessToSend); json = "=" + json; path = information.URL + "/api/serverAccessLevel"; response = ApiConnector.SendToApi(path, json); } } } else { // Add permissions for scripts only! foreach (ServerAccessLevel access in serverList) { // Call API for server info GetAccessLevel currServer = new GetAccessLevel(); currServer.SessionKey = information.Token; currServer.Id = access.ServerId; json = JsonConvert.SerializeObject(currServer); json = "=" + json; path = information.URL + "/api/servers/get"; // Add to server list response = ApiConnector.SendToApi(path, json); var objec = JsonConvert.DeserializeObject <Server>(response); if (objec.ServerId == 5) { //Create the access level accessToSend.UserId = newUser.UserId; accessToSend.DepartmentId = current.DepartmentId; accessToSend.ServerId = objec.ServerId; accessToSend.StartTime = null; accessToSend.FinishTime = null; accessToSend.StandardAccountId = access.StandardAccountId; accessToSend.Allowed = true; json = JsonConvert.SerializeObject(accessToSend); json = "=" + json; path = information.URL + "/api/serverAccessLevel"; response = ApiConnector.SendToApi(path, json); } } } } else { // Update User UserRemoveOrEdit newUser = new UserRemoveOrEdit(); newUser.UserId = Int32.Parse(txtUserId.Text); newUser.SessionKey = information.Token; newUser.PermissionLevelId = cmbAccessLevel.SelectedIndex + 1; newUser.FirstName = txtFirstName.Text; newUser.Surname = txtSurname.Text; newUser.JobTitle = txtJobTitle.Text; newUser.DepartmentId = cmbDepartments.SelectedIndex + 1; newUser.Password = current.Password; newUser.Username = current.Username; newUser.LastLoginDate = DateTime.Now.ToString("yyy-MM-dd HH:mm:ss.fff"); newUser.Note = txtNotes.Text; // Send off to the API var json = JsonConvert.SerializeObject(newUser); json = "=" + json; var path = information.URL + "/api/users"; var response = ApiConnector.SendToApi(path, json); if (response == "\"Passed!\"") { MessageBox.Show("User Updated!"); } if (response == "\"Username Clash!\"") { MessageBox.Show("Duplicated username!, Please try again"); } } this.Close(); } catch (Exception ex) { } }