private void Add_Group_Submit(object sender, RoutedEventArgs e) { var Group = Group_Textbox.Text; ServerDB.ExecuteDB("INSERT INTO server_groups ('name') VALUES ('" + Group + "');"); PopulateList(); }
private void ServerList_NodeMouseClick(object sender, MouseButtonEventArgs e) { TreeViewItem nodeItem = ServerList.SelectedItem as TreeViewItem; if (nodeItem == null) { return; } Config.groupId = nodeItem.DataContext.ToString(); DataTable Servers = ServerDB.ExecuteDB("SELECT * FROM servers WHERE group_id = " + nodeItem.DataContext ?? "1"); var serversJSON = JsonConvert.SerializeObject(Servers); dynamic server = JsonConvert.DeserializeObject(serversJSON); Config.Hostname = server[0]["hostname"]; Config.Username = server[0]["username"]; Config.Password = new String[] { server[0]["password"] }; Config.Port = server[0]["port"]; ActiveServer.Content = "Connect to server: " + Config.Hostname; Console.WriteLine(Config.Hostname); DataTable CommandList = ServerDB.ExecuteDB("SELECT * FROM commands WHERE group_id = " + nodeItem.DataContext ?? "1"); //CommandListGrid.ItemsSource = CommandList.DefaultView; DataTable SoftwareList = ServerDB.ExecuteDB("SELECT * FROM software WHERE group_id = " + nodeItem.DataContext ?? "1"); SoftwareListGrid.ItemsSource = SoftwareList.DefaultView; PopulateDataGrid(); Username.Text = Config.Username; Port.Text = Config.Port; ServerName.Text = Config.Hostname; //ServerGroupDropdown.SelectedIndex = 1; //SoftwareDropdown(); }
private void ExecuteCommand() { if (client == null) { MessageBox.Show("Select a server from the list to the left and click 'Connect' before continuing.", "Not Connected"); return; } string currentGroupId = Config.groupId ?? "1"; string sshCommand = CommandTextbox.Text; string originalCommand = CommandTextbox.Text; sshCommand = sshCommand.Replace("[[Username]]", Regex_Username.Text ?? ""); sshCommand = sshCommand.Replace("[[OldPassword]]", Regex_Old_Password.Text ?? ""); sshCommand = sshCommand.Replace("[[NewPassword]]", Regex_New_Password.Text ?? ""); sshCommand = sshCommand.Replace("[[Custom1]]", Regex_Custom_1.Text ?? ""); sshCommand = sshCommand.Replace("[[Custom2]]", Regex_Custom_2.Text ?? ""); sshCommand = sshCommand.Replace("[[Custom3]]", Regex_Custom_3.Text ?? ""); try { Thread.Sleep(100); reader.ReadToEnd(); Thread.Sleep(100); sh.WriteLine(sshCommand); Thread.Sleep(500); ReturnedString = reader.ReadToEnd(); Console.WriteLine(ReturnedString); Console.WriteLine("Return Value = {0}", ReturnedString); } catch { Console.WriteLine("Fail"); } ServerDB.ExecuteDB("INSERT INTO commands ('group_id', 'command', 'expected_response') VALUES ('" + currentGroupId + "', '" + originalCommand + "', '" + ReturnedString.Replace("'", "''") + "');"); items.Insert(items.Count, new CommandGridItems() { Delete = false, Command = sshCommand, Response = ReturnedString.Replace("'", "''"), Results = "" }); CommandRows2.ItemsSource = items; CommandRows2.Items.Refresh(); PopulateDataGrid(); }
private void Delete_Commands(object sender, RoutedEventArgs e) { foreach (CommandGridItems item in CommandRows2.ItemsSource) { if (((CheckBox)Delete.GetCellContent(item)).IsChecked == true) { var rowId = ID.GetCellContent(item) as TextBlock; ((CheckBox)Delete.GetCellContent(item)).Uid = rowId.Text; ServerDB.ExecuteDB("DELETE FROM commands where id = " + rowId.Text); PopulateDataGrid(); } } }
public void PopulateList() { ServerList.Items.Clear(); TreeViewItem treeItem = null; var serverGroupList = ServerDB.ExecuteDB("SELECT * FROM server_groups"); var json = JsonConvert.SerializeObject(serverGroupList); dynamic dynJson = JsonConvert.DeserializeObject(json); ServerGroupDropdown.Items.Clear(); foreach (var item in dynJson) { Console.WriteLine("Adding ServerGroup: " + item.name); ComboboxItem DropdownItem = new ComboboxItem(); DropdownItem.Text = item.name.ToString(); DropdownItem.Value = item.id; ServerGroupDropdown.Items.Add(DropdownItem); treeItem = new TreeViewItem(); treeItem.Header = item.name; treeItem.Uid = item.id; treeItem.DataContext = item.id.ToString(); treeItem.MouseUp += ServerList_NodeMouseClick; var serverListResults = ServerDB.ExecuteDB("SELECT * FROM servers WHERE group_id = " + item.id); var serversJSON = JsonConvert.SerializeObject(serverListResults); dynamic servers = JsonConvert.DeserializeObject(serversJSON); foreach (var server in servers) { treeItem.Items.Add(new TreeViewItem() { Header = server.name, Uid = server.id, DataContext = server.group_id.ToString() }); } ServerList.Items.Add(treeItem); } foreach (object item in ServerList.Items) { TreeViewItem treeItems = (TreeViewItem)item; if (treeItems != null) { ExpandAllNodes(treeItems); treeItems.IsExpanded = true; } } }
public static string RunCommands() { var serverListResults = ServerDB.ExecuteDB("SELECT * FROM servers"); var serversJSON = JsonConvert.SerializeObject(serverListResults); dynamic servers = JsonConvert.DeserializeObject(serversJSON); foreach (var server in servers) { Console.WriteLine("Connecting to: " + server.name); string[] password = new string[] { server.password }; Encryption decryptor = new Encryption(); string[] decryptedPassword = decryptor.StartDecryption(password); string serverPassword = decryptedPassword[0]; string hostname = server.hostname; string username = server.username; string groupID = server.group_id; using (var client = new SshClient(hostname, username, serverPassword)) { try { client.Connect(); var serverCommandsList = ServerDB.ExecuteDB("SELECT * FROM commands where group_id = " + groupID); var json = JsonConvert.SerializeObject(serverCommandsList); dynamic dynJson = JsonConvert.DeserializeObject(json); foreach (var command in dynJson) { var cmd = command.command.ToString(); Console.WriteLine("Command>" + cmd); var run = client.CreateCommand(cmd); run.Execute(); Console.WriteLine("Return Value = {0}", run.Result); client.Disconnect(); string returnedResults = run.Result.ToString(); ServerDB.ExecuteDB("UPDATE commands set response = '" + returnedResults + "' WHERE id = " + command.id); } } catch { Console.WriteLine("Fail"); return("Failure"); } } } return("true"); }
private void Server_Add(object sender, RoutedEventArgs e) { var selectedItem = ServerGroupDropdown.SelectedItem; ComboBoxItem cbi = ServerGroupDropdown.ItemContainerGenerator.ContainerFromItem(selectedItem) as ComboBoxItem; var json = JsonConvert.SerializeObject(cbi); dynamic dynJson = JsonConvert.DeserializeObject(json); Encryption decryptor = new Encryption(); string[] arr1 = new string[] { Password.Password }; string[] encryptedPassword = decryptor.StartEncryption(arr1); // string[] dec = decryptor.StartDecryption(encryptedPassword); ServerDB.ExecuteDB("INSERT INTO servers (`group_id`, `name`, `hostname`, `port`, `type`, `username`, `password`) VALUES (" + dynJson.Content.Value + ", '" + ServerName.Text + "', '" + ServerName.Text + "', " + Port.Text + ", 'ssh', '" + Username.Text + "', '" + encryptedPassword[0] + "')"); ServerList.Items.Clear(); PopulateList(); }
public MainWindow() { if (!File.Exists("zzz.sqlite")) { SQLiteConnection.CreateFile("zzz.sqlite"); ServerDB.ExecuteDB( "create table IF NOT EXISTS servers (id INTEGER PRIMARY KEY AUTOINCREMENT, group_id int, name varchar(60), hostname varchar(60), port int, type varchar(6), username varchar(60), password varchar(200), description varchar(60))"); ServerDB.ExecuteDB( "create table IF NOT EXISTS server_groups (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(60))"); ServerDB.ExecuteDB( "CREATE TABLE IF NOT EXISTS 'commands'( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `group_id` INTEGER, `command` TEXT, `expected_response` TEXT, `response` TEXT, `sort_order` INTEGER)"); ServerDB.ExecuteDB( "CREATE TABLE IF NOT EXISTS `software` (`id` INTEGER PRIMARY KEY AUTOINCREMENT,`group_id` INTEGER,`name` TEXT)"); ServerDB.ExecuteDB("INSERT INTO server_groups VALUES (1, 'Server Group')"); //ServerDB.ExecuteDB("INSERT INTO servers VALUES (1, 1, 'localhost', '127.0.0.1', 22, 'ssh', 'root', '', '')"); //ServerDB.ExecuteDB("INSERT INTO software VALUES (1, 1, 'Shell')"); } WindowStartupLocation = WindowStartupLocation.Manual; Left = -4500; Top = -966; InitializeComponent(); PopulateList(); SoftwareSelection.SelectedIndex = 0; //using (var client = new SshClient(hostname, username, serverPassword)) //{ // client.Connect(); // var sh = client.CreateShellStream("alan", 0, 0, 0,0,0); // var reader = new StreamReader(sh); // sh.WriteLine("mysql"); // Thread.Sleep(500); // sh.WriteLine("show databases;"); // Thread.Sleep(500); // Console.WriteLine(reader.ReadToEnd()); // //sh.WriteLine("quit;"); // client.Disconnect(); //} }
public void PopulateDataGrid() { items = new List <CommandGridItems>(); var serverCommandsList = ServerDB.ExecuteDB("SELECT * FROM commands where group_id = " + Config.groupId); var json = JsonConvert.SerializeObject(serverCommandsList); dynamic dynJson = JsonConvert.DeserializeObject(json); foreach (var command in dynJson) { items.Insert(items.Count, new CommandGridItems() { Delete = false, Command = command.command.ToString(), Response = command.expected_response.ToString(), Results = "", Command_ID = command.id.ToString() }); } CommandRows2.ItemsSource = items; CommandRows2.Items.Refresh(); }
private void CopyItem(TreeViewItem _sourceItem, TreeViewItem _targetItem) { try { //adding dragged TreeViewItem in target TreeViewItem addChild(_sourceItem, _targetItem); ServerDB.ExecuteDB("UPDATE servers SET group_id = " + _targetItem.Uid + " WHERE id = " + _sourceItem.Uid); //finding Parent TreeViewItem of dragged TreeViewItem TreeViewItem ParentItem = FindVisualParent <TreeViewItem>(_sourceItem); // if parent is null then remove from TreeView else remove from Parent TreeViewItem if (ParentItem == null) { ServerList.Items.Remove(_sourceItem); } else { ParentItem.Items.Remove(_sourceItem); } } catch { } }
private void Add_Software_Submit(object sender, RoutedEventArgs e) { var Software = AddSoftwareTextBox.Text; ServerDB.ExecuteDB("INSERT INTO software ('group_id', 'name') VALUES ('" + Config.groupId + "','" + Software + "');"); }