private void AddPc1(object sender, RoutedEventArgs e) { if (CheckList() && !Comps.isNew(pcName01.Text)) { DataBase.Update(pcName01.Text, AdmPass01.Text, BiosPass01.Text, pcModel01.SelectedItem.ToString()); } else if (CheckList() && Comps.isNew(pcName01.Text)) { DataBase.Add(pcName01.Text, AdmPass01.Text, BiosPass01.Text, pcModel01.SelectedItem.ToString()); } else if (!CheckList() && !Comps.isNew(pcName01.Text)) { if (MessageBox.Show("Не все пункты отмечены. Вы уверены что хотите добавить", "Замечены пропуски.", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { DataBase.Update(pcName01.Text, AdmPass01.Text, BiosPass01.Text, pcModel01.Text); } else { return; } } else if (!CheckList() && Comps.isNew(pcName01.Text)) { if (MessageBox.Show("Не все пункты отмечены. Вы уверены что хотите добавить", "Замечены пропуски.", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { DataBase.Add(pcName01.Text, AdmPass01.Text, BiosPass01.Text, pcModel01.SelectedItem.ToString()); } } pcName01.IsReadOnly = false; AdmPass01.Text = ""; BiosPass01.Text = ""; }
private void OnReady(object sender, RoutedEventArgs e) { if (MessageBox.Show("Для автоматической настройки необходимо иметь права доступа на удаленной машине, а так же включить службу 'Удаленный реестр' и отключить брэндмауэр", "Подготовка установки", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { try { if (Comps.isNew(pcName01.Text)) { DataBase.Add(pcName01.Text, AdmPass01.Text, BiosPass01.Text, pcModel01.Text); } else { DataBase.Update(pcName01.Text, AdmPass01.Text, BiosPass01.Text, pcModel01.Text); } RemoteInstall install = new RemoteInstall(AdmPass01.Text, BiosPass01.Text); install.InstallFinished += ClearPage; install.ProgressChange += ProgressChecking; install.Install(pcName01.Text, SoftType.Text, pcModel01.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); File.AppendAllText($@"{Environment.CurrentDirectory}\Logs", $"{DateTime.Now}:{ex.Message}"); } } }
private static async void UpdateLastPC() { SqlDataReader reader = null; SqlCommand sqlCommand = new SqlCommand("SELECT MAX(Id) FROM [Table]"); while (connection.State == System.Data.ConnectionState.Open) { await Task.Delay(1000); } try { reader = await sqlCommand.ExecuteReaderAsync(); while (await reader.ReadAsync()) { Comps comp = new Comps(reader[0].ToString(), reader[1].ToString(), reader[2].ToString(), reader[3].ToString(), Crypter.RSADecrypt(reader[4].ToString()), Crypter.RSADecrypt(reader[5].ToString()), reader[6].ToString()); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButton.OK, MessageBoxImage.Error); } }
private void isNew(string PcName) { pcName01.IsReadOnly = true; if (!Comps.isNew(PcName)) { Comps comp = Comps.GetPasswords(pcName01.Text); if (comp.AdmPass.Length < Settings2.Default.admPassLenght) { if (MessageBox.Show("Длинна пароля локального админа меньше установленной длинны. Хотите сгенерировать новый пароль?", "Пароль не соответствует длинне", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { AdmPass01.Text = PassGenerator.GetAdmPass(); } else { AdmPass01.Text = comp.AdmPass; } } else { if (MessageBox.Show("Хотите создать новый пароль?", "Пароль локального адина", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK) { AdmPass01.Text = PassGenerator.GetAdmPass(); } else { AdmPass01.Text = comp.AdmPass; } } if (comp.BiosPass.Length < Settings2.Default.biosPassLenght) { if (MessageBox.Show("Длинна пароля BIOS меньше установленной длинны. Хотите сгенерировать новый пароль?", "Пароль не соответствует длинне", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { BiosPass01.Text = PassGenerator.GetBiosPass(); } else { BiosPass01.Text = comp.BiosPass; } } else { if (MessageBox.Show("Хотите создать новый пароль?", "Пароль BIOS", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK) { BiosPass01.Text = PassGenerator.GetBiosPass(); } else { BiosPass01.Text = comp.BiosPass; } } } else { PassGenerator.GetPass(AdmPass01, BiosPass01); } }
public static async void ImportDB(string connect) { SqlConnection con = new SqlConnection(@" Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename =" + connect + "; Integrated Security = True"); //Connection to second DB SqlDataReader reader = null; await con.OpenAsync(); SqlCommand SelectCommand = new SqlCommand("SELECT * FROM [Table]", con); Comps.compsList.Clear(); reader = await SelectCommand.ExecuteReaderAsync(); //Reading all DB and get list while (await reader.ReadAsync()) { Comps comp = new Comps(); comp.PcName = reader[1].ToString(); comp.Responsibility = reader[3].ToString(); try { comp.AdmPass = Crypter.RSADecrypt(reader[4].ToString()); comp.BiosPass = Crypter.RSADecrypt(reader[5].ToString()); comp.Date = reader[2].ToString(); } catch { comp.AdmPass = reader[4].ToString(); comp.BiosPass = reader[5].ToString(); comp.Date = null; } Comps.compsList.Add(comp); } reader.Close(); con.Close(); SqlCommand command = new SqlCommand("INSERT INTO [Table] (PcName, Date, Responsibility, AdmPass, BiosPass)VALUES(UPPER(@PcName), @Date, @Responsible, @AdmPass, @BiosPass)", connection); foreach (Comps comp in Comps.compsList) { command.Parameters.Clear(); command.Parameters.AddWithValue("PcName", comp.PcName); if (comp.Date != null && comp.Date.Length > 1) { command.Parameters.AddWithValue("Date", DateTime.Parse(comp.Date)); } else { command.Parameters.AddWithValue("Date", DBNull.Value); } command.Parameters.AddWithValue("Responsible", comp.Responsibility); command.Parameters.AddWithValue("AdmPass", Crypter.RSAEncrypt(comp.AdmPass)); command.Parameters.AddWithValue("BiosPass", Crypter.RSAEncrypt(comp.BiosPass)); command.ExecuteNonQuery(); } }
public void Install(string pcName, string softType, string modelName) { if (Settings2.Default.scriptFolder == "") { MessageBox.Show("Необходимо указать папку для создания временных скриптов."); return; } //check for psExec extention if (Settings2.Default.psExec_Path == "") { OpenFileDialog open = new OpenFileDialog(); open.Filter = "EXE(*.exe) |*.exe"; open.Title = "Укажите размещение psExec"; open.FilterIndex = 2; if (open.ShowDialog() == true) { Settings2.Default.psExec_Path = open.FileName; Settings2.Default.Save(); } } if (password.Length < 1) { pass = new Password(); if (pass.ShowDialog() == true) { password = pass.Pass; } } XMLWorker.GetXML(); Task.Run(() => InstallDrivers(pcName, modelName)); Task.Run(() => InstallSoft(pcName, softType)); if (Comps.isNew(pcName)) { if (CreateSettings(pcName, FindPasswords(XMLWorker.GetSettings()))) { Task.Run(() => SetSettings(pcName)); } if (XMLWorker.GetBiosScript(modelName) != "" && XMLWorker.GetBiosScript(modelName) != null) { CreateBiosSettings(pcName, FindPasswords(XMLWorker.GetBiosScript(modelName))); Task.Run(() => ResetBiosPassword(pcName, modelName)); Task.Run(() => BiosSettingsInstalling(pcName)); Task.Run(() => Thread.Sleep(120000)); Task.Run(() => SetBiosPassword(pcName, modelName)); } } else { if (CreateSettings(pcName, FindPasswords(XMLWorker.GetSettings()))) { Task.Run(() => SetSettings(pcName)); } Finish(this, EventArgs.Empty); } }
public Comps(string id, string pcName, string date, string resosibility, string admPass, string biosPass, string model) { Id = id; PcName = pcName; Responsibility = resosibility; Date = date; AdmPass = admPass; BiosPass = biosPass; Model = model; LastComp = this; }
private void CopyPasswords_Click(object sender, MouseButtonEventArgs e)//Copy passwords when right button click { try { if (listGrid.SelectedItem != null) { Clipboard.Clear(); Comps comp = (Comps)listGrid.SelectedItem; Clipboard.SetText($"{comp.AdmPass} {comp.BiosPass}"); } } catch (Exception ex) { File.AppendAllText($@"{Environment.CurrentDirectory}\Logs", ex.ToString() + ex.Message); } }
private void UpdateCompsListGrid(Comps comp) { listGrid.Items.Add(comp); }
private void OnEnter_Click(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { Status.Content = ""; ProgressBar.Value = 0; SoftType.Items.Clear(); pcModel01.Items.Clear(); foreach (string type in XMLWorker.GetProgramTypes()) { SoftType.Items.Add(type); } foreach (string model in DataBase.GetModelList()) { pcModel01.Items.Add(model); } pcName01.IsReadOnly = true; if (!Comps.isNew(pcName01.Text)) { Comps comp = Comps.GetPasswords(pcName01.Text); if (comp.AdmPass.Length < Settings2.Default.admPassLenght) { if (MessageBox.Show("Длинна пароля локального админа меньше установленной длинны. Хотите сгенерировать новый пароль?", "Пароль не соответствует длинне", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { AdmPass01.Text = PassGenerator.GetAdmPass(); } else { AdmPass01.Text = comp.AdmPass; } } else { if (MessageBox.Show("Хотите создать новый пароль?", "Пароль локального адина", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK) { AdmPass01.Text = PassGenerator.GetAdmPass(); } else { AdmPass01.Text = comp.AdmPass; } } if (comp.BiosPass.Length < Settings2.Default.biosPassLenght) { if (MessageBox.Show("Длинна пароля BIOS меньше установленной длинны. Хотите сгенерировать новый пароль?", "Пароль не соответствует длинне", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { BiosPass01.Text = PassGenerator.GetBiosPass(); } else { BiosPass01.Text = comp.BiosPass; } } else { if (MessageBox.Show("Хотите создать новый пароль?", "Пароль BIOS", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK) { BiosPass01.Text = PassGenerator.GetBiosPass(); } else { BiosPass01.Text = comp.BiosPass; } } string backup = $@"{pcName01.Text} {AdmPass01.Text} {BiosPass01.Text}"; byte[] array = Encoding.Default.GetBytes(backup); string tempPath = $@"{Environment.CurrentDirectory}\backupPassword"; using (FileStream fs = new FileStream(tempPath, FileMode.Append)) { fs.Write(array, 0, array.Length); } File.SetAttributes(tempPath, FileAttributes.Hidden); } else { AdmPass01.Text = PassGenerator.GetAdmPass(); BiosPass01.Text = PassGenerator.GetBiosPass(); } } }