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 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 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 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) { } }