Пример #1
0
 private void LinphoneInstInk_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     if (Bindings.isipselected)
     {
         IP     curSelIP = SelectedIP;
         string pathTo   = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, @"SupportTools\LinuxScripts");
         SftpCopy("linphone_inst.sh", pathTo, @"/home/user/", curSelIP.IPAddress, SelectedCredentials.Login, SelectedCredentials.Password);
         SftpCopy("linphone_inst_lnk.sh", pathTo, @"/home/user/", curSelIP.IPAddress, SelectedCredentials.Login, SelectedCredentials.Password);
         StringBuilder commandLinphoneInstInk = new StringBuilder();
         commandLinphoneInstInk.AppendLine("echo $TempPass|sudo -S bash linphone_inst.sh");
         commandLinphoneInstInk.AppendLine("echo $TempPass|sudo -S bash linphone_inst_lnk.sh");
         SSHCommandThread(curSelIP, "Установить linphone и вынести ярлыки на рабочий стол", commandLinphoneInstInk.ToString(), SelectedCredentials.Login, SelectedCredentials.Password);
     }
 }
Пример #2
0
 private void DоntOpenPDF1С_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     if (Bindings.isipselected)
     {
         IP     curSelIP = SelectedIP;
         string pathTo   = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, @"SupportTools\LinuxScripts");
         SftpCopy("pdf1.txt", pathTo, @"/home/user/", curSelIP.IPAddress, SelectedCredentials.Login, SelectedCredentials.Password);
         SftpCopy("pdf2.txt", pathTo, @"/home/user/", curSelIP.IPAddress, SelectedCredentials.Login, SelectedCredentials.Password);
         StringBuilder commandDоntOpenPDF1С = new StringBuilder();
         commandDоntOpenPDF1С.AppendLine(@"regedit /home/user/pdf1.txt");
         commandDоntOpenPDF1С.AppendLine(@"regedit /home/user/pdf2.txt");
         SSHCommandThread(curSelIP, "Устранить проблему с открытием скана в 1С", commandDоntOpenPDF1С.ToString(), SelectedCredentials.Login, SelectedCredentials.Password);
     }
 }
Пример #3
0
 private void SmartCtl_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     if (Bindings.isipselected)
     {
         IP            curSelIP        = SelectedIP;
         StringBuilder commandSmartCtl = new StringBuilder();
         //commandSmartCtl.AppendLine("echo $TempPass|sudo -S su");
         commandSmartCtl.AppendLine("echo $TempPass|sudo -S apt-get -y install smartmontools");
         commandSmartCtl.AppendLine("echo $TempPass|sudo -S fdisk -l");
         commandSmartCtl.AppendLine("echo $TempPass|sudo -S smartctl --smart=on /dev/sda");
         commandSmartCtl.AppendLine("echo $TempPass|sudo -S smartctl -a /dev/sda");
         SSHCommandThread(curSelIP, $"S.M.A.R.T по хосту {curSelIP.NBNameOrIP()}", commandSmartCtl.ToString(), SelectedCredentials.Login, SelectedCredentials.Password);
     }
 }
Пример #4
0
        private void Ink1CWine_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (Bindings.isipselected)
            {
                IP curSelIP = SelectedIP;
                PasswordConnectionInfo connectionInfo = new PasswordConnectionInfo(curSelIP.IPAddress, 22, SelectedCredentials.Login, SelectedCredentials.Password);
                connectionInfo.Timeout = TimeSpan.FromSeconds(30);

                #region Скопировать ibases.v8i и скрипт на хост
                using (var sftp = new SftpClient(connectionInfo))
                {
                    try
                    {
                        sftp.Connect();
                        string fileDS_Bencmark = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, @"SupportTools\LinuxScripts\ibases.v8i");
                        using (FileStream stream = new FileStream(fileDS_Bencmark, FileMode.Open, FileAccess.Read))
                        {
                            sftp.UploadFile(stream, @"/home/user/ibases.v8i", true);
                            stream.Close();
                            stream.Dispose();
                        }

                        string filebench = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, @"SupportTools\LinuxScripts\copyInk.sh");
                        using (FileStream stream = new FileStream(filebench, FileMode.Open, FileAccess.Read))
                        {
                            sftp.UploadFile(stream, @"/home/user/copyInk.sh", true);
                            stream.Close();
                            stream.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        Log(ex.Message, true, false, ex.StackTrace);
                    }
                    finally
                    {
                        sftp.Disconnect();
                        sftp.Dispose();
                    }
                }
                #endregion

                #region Выполнение скрипта тестирования DS_Benchmark

                SSHCommandThread(curSelIP, $"Копирование ярлыка со списком БД на хост {curSelIP.NBNameOrIP()}", @"echo $TempPass|sudo -S sh /home/user/copyInk.sh", SelectedCredentials.Login, SelectedCredentials.Password);

                #endregion
            }
        }
Пример #5
0
        private void ListViewItem_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            var dep = (DependencyObject)e.OriginalSource;

            while (dep != null)
            {
                dep = VisualTreeHelper.GetParent(dep);
                if (dep is ListViewItem)
                {
                    IP selIP = ((ListViewItem)dep).Content as IP;
                    //System.Windows.Forms.MessageBox.Show(selIP.IPAddress);
                    //ContextMenuListViewItem.IsOpen = true;
                    return;
                }
            }
        }
Пример #6
0
        private void ListViewHostsInCustomer_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (NewMainWindow.settings.Fields.DoubleClickPing)
            {
                var dep = (DependencyObject)e.OriginalSource;
                while (dep != null)
                {
                    dep = VisualTreeHelper.GetParent(dep);
                    if (dep is ListViewItem)
                    {
                        IP selIP = ((ListViewItem)dep).Content as IP;

                        Log($"cmd.exe  /c title {SelectedIP.Owner.ToStringDisplay} {SelectedIP.IPAddress} & ping {SelectedIP.IPAddress} /t & pause ", false, false, "", false);
                        NewMainWindow.ExecuteProgram("cmd.exe", $"/c title {SelectedIP.Owner.ToStringDisplay} {SelectedIP.IPAddress} & ping {SelectedIP.IPAddress} /t & pause", false, true, "", false, "", "");

                        return;
                    }
                }
            }
        }
Пример #7
0
        private void DS_Benchmark_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (Bindings.isipselected)
            {
                IP curSelIP = SelectedIP;

                #region Скопировать DS_Benchmark.tar.gz на хост
                string pathTofileDS_Bencmark = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, @"SupportTools\LinuxScripts");
                SftpCopy("DS_Benchmark.tar.gz", pathTofileDS_Bencmark, @"/home/user/", curSelIP.IPAddress, SelectedCredentials.Login, SelectedCredentials.Password);

                string pathTofilebench = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, @"SupportTools\LinuxScripts");
                SftpCopy("bench.sh", pathTofilebench, @"/home/user/", curSelIP.IPAddress, SelectedCredentials.Login, SelectedCredentials.Password);
                #endregion

                #region Выполнение скрипта тестирования DS_Benchmark

                SSHCommandThread(curSelIP, $"Тестирование производительности хоста {curSelIP.NBNameOrIP()} с помощью DS_Benchmark", @"echo $TempPass|sudo -S sh /home/user/bench.sh", SelectedCredentials.Login, SelectedCredentials.Password);

                #endregion
            }
        }
Пример #8
0
        private string SSHCommandThreadGetResult(IP selectedIP, string command, string commandinresult, string login, string password)
        {
            try
            {
                this.Log(string.Format($"Выполнение {command} на {selectedIP.NBNameOrIP()}..."), false, false, string.Empty, true);
                string nbNameOrIP = selectedIP.NBNameOrIP();
                string ipaddress  = selectedIP.IPAddress;


                using (SshClient client = new SshClient(ipaddress, login, password))
                {
                    client.Connect();
                    StringBuilder commandBuild = new StringBuilder();
                    commandBuild.AppendLine(@"#!/bin/bash");
                    commandBuild.AppendLine($"TempPass={password}");
                    commandBuild.AppendLine(commandinresult);
                    string commandExec = commandBuild.ToString().Replace("\r\n", "\n");


                    var runCommand = client.CreateCommand(commandExec);

                    string result = runCommand.Execute();

                    client.Disconnect();
                    return(result);
                }
            }
            catch (ArgumentException exception)
            {
                Log("Необходимо выбрать логин и пароль", true, true, exception.StackTrace, false);
                return("Ошибка Необходимо выбрать логин и пароль");
            }
            catch (Exception exception)
            {
                this.Log(exception.Message, true, true, exception.StackTrace, false);
                return("Ошибка");
            }

            //});
        }
Пример #9
0
 private void RestartHostPC_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     if (Bindings.isipselected)
     {
         IP curIP = SelectedIP;
         new Thread(new ThreadStart(() =>
         {
             try
             {
                 PasswordConnectionInfo connectionInfo = new PasswordConnectionInfo(curIP.IPAddress, 22, SelectedCredentials.Login, SelectedCredentials.Password);
                 connectionInfo.Timeout = TimeSpan.FromSeconds(10);
                 using (SshClient client = new SshClient(connectionInfo))
                 {
                     client.Connect();
                     if (client.IsConnected)
                     {
                         try
                         {
                             client.RunCommand($"echo {SelectedCredentials.Password}|sudo -S reboot");
                         }
                         catch (Exception)
                         {
                             Log($"Выполнена перезагрузка хоста {curIP.IPAddress}");
                         }
                     }
                     client.Disconnect();
                 }
             }
             catch (ArgumentException exception)
             {
                 Log("Необходимо выбрать логин и пароль", true, true, exception.StackTrace, false);
             }
             catch (Exception ex)
             {
                 Log(ex.Message, true, false, ex.StackTrace);
             }
         })).Start();
     }
 }
Пример #10
0
        private void mac_info_thread(IP selectedIP)
        {
            string mac = GetMac(selectedIP.IPAddress);

            Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => CopyToClipboard(mac, true, "")));

            string mac_msg = null;

            for (int i = 0; i < this.macvendors.Length; i += 2)
            {
                if (mac.StartsWith(this.macvendors[i]))
                {
                    mac_msg = "MAC адрес: " + mac + "\nПроизводитель: " + this.macvendors[i + 1];
                    break;
                }
            }
            if (mac_msg != null)
            {
                base.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
                {
                    TaskDialogOptions options = new TaskDialogOptions
                    {
                        Owner = this,
                        Title = "DSList",
                        MainInstruction = selectedIP.NBNameOrIP(),
                        Content = mac_msg,
                        MainIcon = VistaTaskDialogIcon.Information
                    };
                    options.CustomButtons = new string[] { "ОК" };
                    options.AllowDialogCancellation = true;
                    TaskDialog.Show(options);
                }));
            }
            else
            {
                Log($"Не удалось определить mac адрес для {selectedIP.NBNameOrIP()}", false, false);
            }
        }
Пример #11
0
        private void SSHCommandThread(IP selectedIP, string command, string commandinresult, string login, string password, bool showWindow = true, bool addToListBoxTask = true)
        {
            Thread runThread = new Thread(new ThreadStart(() =>
            {
                ItemListBoxTask curItemLBT = new ItemListBoxTask()
                {
                    IPOrName = selectedIP.NBNameOrIP(), Description = $"Выполняется {command}", CVZNumber = $"ЦВЗ№{SelectedTT.NumberCVZ.ToString()}", IsIndeterminate = true
                };

                //Dispatcher.Invoke(() =>
                //{

                if (addToListBoxTask)
                {
                    Dispatcher.Invoke(() =>
                    {
                        Bindings.listBoxTaskItemsSource.Add(curItemLBT);
                    });
                }
                try
                {
                    this.Log(string.Format($"Выполнение {command} на {selectedIP.NBNameOrIP()}..."), false, false, string.Empty, true);
                    string nbNameOrIP = selectedIP.NBNameOrIP();
                    string ipaddress  = selectedIP.IPAddress;


                    using (SshClient client = new SshClient(ipaddress, login, password))
                    {
                        client.Connect();
                        StringBuilder commandBuild = new StringBuilder();
                        commandBuild.AppendLine(@"#!/bin/bash");
                        commandBuild.AppendLine($"TempPass={password}");
                        commandBuild.AppendLine(commandinresult);
                        string commandExec    = commandBuild.ToString().Replace("\r\n", "\n");
                        bool uploadFileStoped = false;

                        var runCommand = client.CreateCommand(commandExec);
                        var runClient  = runCommand.BeginExecute((x) =>
                        {
                            var temp = curItemLBT.StopProcess;
                            if (curItemLBT.StopProcess)
                            {
                                if (!uploadFileStoped)
                                {
                                    try
                                    {
                                        uploadFileStoped = true;
                                        showWindow       = false;
                                        client.Disconnect();
                                        //return $"Прервано выполнение {command}";
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                        });

                        string result = runCommand.EndExecute(runClient);

                        client.Disconnect();
                        if (showWindow)
                        {
                            base.Dispatcher.BeginInvoke((Action)(() =>
                            {
                                SSHReportWindow window = new SSHReportWindow(this)
                                {
                                    Owner = this,
                                    Title = string.Format($"Команда SSH {command} на {nbNameOrIP}"),
                                    Text = { Text = result },
                                    SSHStatusBarText = { Text = string.Format($"Команда SSH {command} на {nbNameOrIP} выполнена.") }
                                };
                                this.Log(window.SSHStatusBarText.Text, false, false, "", false);
                                window.Show();
                            }));
                        }
                    }
                }
                catch (ArgumentException exception)
                {
                    Log("Необходимо выбрать логин и пароль", true, true, exception.StackTrace, false);
                }
                catch (Exception exception)
                {
                    this.Log(exception.Message, true, true, exception.StackTrace, false);
                }

                //});
            }));

            runThread.Start();


            //while (!curItemLBT.StopProcess || (runThread.ThreadState != System.Threading.ThreadState.Stopped) || (runThread.ThreadState != System.Threading.ThreadState.Aborted))
            //{

            //    if (!(runThread.ThreadState == System.Threading.ThreadState.Stopped))
            //    {
            //        runThread.Abort();
            //    }
            //}
        }
Пример #12
0
        /// <summary>
        /// Метод заполнения IPArray значениями на основе принадлежности IP к типу оборудования и родителя Customer
        /// </summary>
        public void DetectListIPType()
        {
            for (int i = 0; i < IPArray.Count; i++)  // цикл с проходом по общему количеству хостов
            {
                IP ip3 = IPArray[i];
                try
                {
                    ip3.Owner = this;
                    if (ip3.Type == IPType.Маршрутизатор)
                    {
                    }
                    else
                    {
                        //ip3.Region = this.Region;
                        switch (Convert.ToInt32(ip3.IPAddress.Remove(0, ip3.IPAddress.Length - 3)))
                        {
                        case 0xfe:
                            ip3.Description = "Маршрутизатор";
                            ip3.Type        = IPType.Маршрутизатор;
                            if (!string.IsNullOrWhiteSpace(this.Router))
                            {
                                ip3.Tooltip = this.Router;
                            }
                            break;

                        case 101:
                            ip3.Description = "АРМ УТТ";
                            ip3.Type        = IPType.АРМ;
                            break;

                        case 102:
                            ip3.Description = "АРМ ПТТ";
                            ip3.Type        = IPType.АРМ;
                            break;

                        case 103:
                            ip3.Description = "АРМ 3";
                            ip3.Type        = IPType.АРМ;
                            break;

                        case 0xfa:
                            ip3.Description = "Основной";
                            ip3.Type        = IPType.Принтер;
                            break;

                        case 0xfb:
                            ip3.Description = "Основной";
                            ip3.Type        = IPType.КамераIP;
                            break;

                        case 0xf0:
                            ip3.Description = "Основной";
                            ip3.Type        = IPType.ТелефонIP;
                            break;

                        case 0xf1:
                            ip3.Description = "Основной";
                            ip3.Type        = IPType.ТелефонСервисный;
                            break;

                        default:
                            ip3.Description = "Прочее";
                            ip3.Type        = IPType.Прочее;
                            break;
                        }
                    }
                }
                catch
                {
                }

                if ((ip3.Type == IPType.Маршрутизатор) && string.IsNullOrWhiteSpace(this.Gateway))
                {
                    this.Gateway = ip3.IPAddress;
                }
            }
        }
Пример #13
0
        /// <summary>
        /// Заполнение IP листа IPArray
        /// </summary>
        public void PopulateIPList()
        {
            IPAddress address;

            if (string.IsNullOrEmpty(this.SubnetMask))
            {
                this.SubnetMask = "255.255.255.0";
            }
            int num = this.CalculateHostCount(this.SubnetMask, 254);

            try
            {
                string[] curSubnetTemp = Lan_Ip.Split('.');
                curSubnetTemp[3] = "0";
                string curSubnet = "";
                bool   firstNumb = true;
                foreach (var str in curSubnetTemp)
                {
                    if (firstNumb)
                    {
                        curSubnet += str;
                        firstNumb  = false;
                    }
                    else
                    {
                        curSubnet += "." + str;
                    }
                }
                address = IPAddress.Parse(curSubnet);
                //address = IPAddress.Parse(NetMikrotik);
            }
            catch
            {
                this.DetectSubnetIP();
                return;
            }

            IPArray = new ObservableCollection <IP>();

            //if (this.Providers != null)
            //{
            //    for (int j = 0; j < this.Providers.Count; j++)
            //    {
            //        try
            //        {
            //            if ((this.Providers[j].ProvName == null) || !this.Providers[j].ProvName.Contains("Wi-Fi"))
            //            {
            //                if ((j > 0))
            //                {
            //                    break;
            //                }
            //                if (!string.IsNullOrEmpty(this.Providers[j].ExtGW))
            //                {
            //                    IP ip = new IP
            //                    {
            //                        Owner = this,
            //                        IPAddress = this.Providers[j].ExtGW,
            //                        Region = this.Region,
            //                        Description = "Шлюз провайдера"
            //                    };
            //                    if (j > 0)
            //                    {
            //                        ip.Description = ip.Description + " #" + j.ToString();
            //                    }
            //                    ip.Type = IPType.Маршрутизатор;
            //                    this.IPArray.Add(ip);
            //                }
            //                if (!string.IsNullOrEmpty(this.Providers[j].ExtIP))
            //                {
            //                    IP ip2 = new IP
            //                    {
            //                        Owner = this,
            //                        IPAddress = this.Providers[j].ExtIP,
            //                        Region = this.Region,
            //                        Description = "Внешний адрес"
            //                    };
            //                    if (j > 0)
            //                    {
            //                        ip2.Description = ip2.Description + " #" + j.ToString();
            //                    }
            //                    ip2.Type = IPType.Маршрутизатор;
            //                    this.IPArray.Add(ip2);
            //                }
            //            }
            //        }
            //        catch
            //        {
            //        }
            //    }
            //}
            string[] strArray = new string[0xfe]; //0xfe - число 254
                                                  //string[] strArray2 = new string[0x7f];  //0x7f - число 127
                                                  //try
                                                  //{
                                                  //    strArray = System.IO.File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + @"SupportTools\im.dat");
                                                  //}
                                                  //catch
                                                  //{
                                                  //    for (int k = 0; k < strArray.Length; k++)
                                                  //    {
                                                  //        strArray[k] = "unknown";
                                                  //    }
                                                  //}
                                                  //try
                                                  //{
                                                  //    strArray2 = System.IO.File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + @"support\top.dat");
                                                  //}
                                                  //catch
                                                  //{
                                                  //    for (int m = 0; m < strArray2.Length; m++)
                                                  //    {
                                                  //        strArray2[m] = "unknown";
                                                  //    }
                                                  //}
            int[] source = new int[] { 12, 13, 14 };
            for (int i = 1; i <= num; i++)        // цикл с проходом по общему количеству хостов
            {
                IP ip3 = new IP();
                try
                {
                    ip3.Owner  = this;
                    ip3.Region = this.Region;

                    //if (this.SubnetMask.EndsWith(".128"))
                    //{
                    //    ip3.Description = strArray2[i - 1];
                    //    ip3.Type = GetIMIPType(ip3.Description);
                    //}
                    //else
                    //{
                    //    if ((this.SubnetMask.EndsWith(".253") || this.SubnetMask.EndsWith(".254")) || this.SubnetMask.EndsWith(".255"))
                    //    {
                    //        ip3.Address = this.ExpandIpRange(address, i - 1).ToString();
                    //        if (ip3.Address.StartsWith("10.91"))
                    //        {
                    //            ip3.Description = "УТ";
                    //            ip3.Type = IPType.УТ;
                    //        }
                    //        else
                    //        {
                    //            ip3.Description = "АРМ";
                    //            ip3.Type = IPType.АРМ;
                    //        }
                    //        this.IPArray.Add(ip3);
                    //        return;
                    //    }
                    switch (i)
                    {
                    case 0xfe:
                        ip3.Description = "Маршрутизатор";
                        ip3.Type        = IPType.Маршрутизатор;
                        if (!string.IsNullOrWhiteSpace(this.Router))
                        {
                            ip3.Tooltip = this.Router;
                        }
                        break;

                    case 101:
                        ip3.Description = "АРМ УТТ";
                        ip3.Type        = IPType.АРМ;
                        break;

                    case 102:
                        ip3.Description = "АРМ ПТТ";
                        ip3.Type        = IPType.АРМ;
                        break;

                    case 103:
                        ip3.Description = "АРМ 3";
                        ip3.Type        = IPType.АРМ;
                        break;

                    case 0xfa:
                        ip3.Description = "Принтер";
                        ip3.Type        = IPType.Принтер;
                        break;

                    case 0xfb:
                        ip3.Description = "Камера IP";
                        ip3.Type        = IPType.КамераIP;
                        break;

                    case 0xf0:
                        ip3.Description = "Телефон IP";
                        ip3.Type        = IPType.ТелефонIP;
                        break;

                    case 0xf1:
                        ip3.Description = "Телефон Сервисный";
                        ip3.Type        = IPType.ТелефонСервисный;
                        break;

                    default:
                        ip3.Description = "Прочее";
                        ip3.Type        = IPType.Прочее;
                        break;
                    }

                    //}
                }
                catch
                {
                }
                ip3.IPAddress = this.ExpandIpRange(address, i).ToString();
                if ((ip3.Type == IPType.Маршрутизатор) && string.IsNullOrWhiteSpace(this.Gateway))
                {
                    this.Gateway = ip3.IPAddress;
                }
                this.IPArray.Add(ip3);
            }
        }