Beispiel #1
0
        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();
        }
Beispiel #2
0
        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)
            {
            }
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
        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!");
            }
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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!");
            }
        }
Beispiel #7
0
        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;
            }
        }
Beispiel #8
0
        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.");
                }
            }
        }
Beispiel #9
0
        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)
            {
            }
        }