Compare commits
13 Commits
c3282f6f87
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
77d86a92e2
|
|||
|
c04600b7ba
|
|||
|
c06206c4f0
|
|||
|
a5a0e6b8dc
|
|||
|
be74f191c7
|
|||
|
ac97396686
|
|||
|
151f312883
|
|||
|
342552eef6
|
|||
|
fdc1450c3e
|
|||
|
57c1fd0095
|
|||
|
c5f59da80f
|
|||
|
6dddb09223
|
|||
|
80ff667731
|
50
CHANGELOG.md
50
CHANGELOG.md
@@ -1,6 +1,54 @@
|
|||||||
|
## 05-12-2025
|
||||||
|
* Fix: Исправлено исключение возникающее при попытке открыть CUPS компьютера без сети
|
||||||
|
|
||||||
|
## 14-10-2025
|
||||||
|
* Fix: Обновлено отображение состояния учетной записи при просмотре информации
|
||||||
|
* Refactor: Переписана функция открытия CUPS удаленного ПК (так как пропала возможность открыть страницу по доменному имени компьютера)
|
||||||
|
|
||||||
|
## 21-05-2025
|
||||||
|
* Feat: Добавлено открытие файловой системы удаленного ПК (только для Windows)
|
||||||
|
|
||||||
|
## 01-05-2025
|
||||||
|
* Feat: Добавлено разделение по рабочим местам при массовой смене пароля
|
||||||
|
|
||||||
|
## 06-03-2025 (Релиз 1.0)
|
||||||
|
* Refactor: Замена Console на AnsiConsole
|
||||||
|
* Refactor: Изменена реализация ввода паролей
|
||||||
|
* Refactor: Замена Regex.Match на Regex.IsMatch
|
||||||
|
* Feat: Массовая смена пароля 802.1x
|
||||||
|
|
||||||
|
## 02-03-2025
|
||||||
|
* Refactor: Изменены области видимости методов
|
||||||
|
* Refactor: Переписано основное меню
|
||||||
|
* Refactor: Обновлен settings.json
|
||||||
|
* Feat: Добавлен новый пакет: Spectre.Console
|
||||||
|
* Feat: Добавлено отображение текущей функции при переходе
|
||||||
|
|
||||||
|
## 18-02-2025
|
||||||
|
* Refactor: Обновлен settings.json
|
||||||
|
* Feat: массовая перезагрузка ПК посредством запуска программы с определенным параметром (остался вопрос с работой с авторизацией)
|
||||||
|
|
||||||
|
## 17-02-2025
|
||||||
|
* Fix: Исправлен баг с проверкой ввода на пустоту или пробелы
|
||||||
|
* Refactor: Изменены регулярные выражения для форматирования имени ПК
|
||||||
|
* Refactor: Мелкие изменения информационных сообщений
|
||||||
|
|
||||||
|
## 26-01-2025
|
||||||
|
* Feat: Добавлена функция отключения кошелька KDE (нужны тесты)
|
||||||
|
* Feat: Добавлен файл settings.json с настройками для перезагрузки компьютеров по расписанию
|
||||||
|
|
||||||
|
## 25-01-2025
|
||||||
|
* Fix: Исправлено имя функции CheckComputerName
|
||||||
|
* Refactor: Сортировка кода
|
||||||
|
* Feat: Добавлены информационные сообщения в некоторые функции
|
||||||
|
* Feat: Добавлен просмотр времени работы компьютера на Linux
|
||||||
|
* Feat: Добавлено обновление пароля 802.1x удаленным методом (массовое изменение в разработке)
|
||||||
|
* Feat: Добавлено запоминание пароля для команд по SSH
|
||||||
|
* Feat: Добавлен пакет NuGet: Newtonsoft.Json
|
||||||
|
|
||||||
## 08-10-2024
|
## 08-10-2024
|
||||||
* Fix: Убраны проверки при вводе в ShowDomainUserInfo
|
* Fix: Убраны проверки при вводе в ShowDomainUserInfo
|
||||||
* Fix: Убрана очистка окна при ввода команды для выполнения в ExecuteCommandViaSSH
|
* Fix: Убрана очистка окна при вводе команды для выполнения в ExecuteCommandViaSSH
|
||||||
* Fix: Исправлен удаленный перезапуск ПК на Windows
|
* Fix: Исправлен удаленный перезапуск ПК на Windows
|
||||||
* Refactor: Небольшое изменение поведения ShowDomainUserInfo
|
* Refactor: Небольшое изменение поведения ShowDomainUserInfo
|
||||||
* Feat: Изменен заголовок окна программы на имя проекта
|
* Feat: Изменен заголовок окна программы на имя проекта
|
||||||
|
|||||||
669
Program.cs
669
Program.cs
@@ -1,8 +1,11 @@
|
|||||||
using Renci.SshNet;
|
using Newtonsoft.Json;
|
||||||
|
using Renci.SshNet;
|
||||||
|
using Spectre.Console;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.DirectoryServices;
|
using System.DirectoryServices;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Management;
|
using System.Management;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
@@ -20,7 +23,7 @@ namespace domain_utility
|
|||||||
static readonly string regularDateTime = @"(\d+[.]\d+[.]\d+[ ]\d+[:]\d+[:]\d+)";
|
static readonly string regularDateTime = @"(\d+[.]\d+[.]\d+[ ]\d+[:]\d+[:]\d+)";
|
||||||
|
|
||||||
static readonly string[,] stringsToFind = new string[,] {
|
static readonly string[,] stringsToFind = new string[,] {
|
||||||
{ "Учетная запись активна", @"(Yes|No)", "Учетная запись работает: " },
|
{ "Учетная запись активна", @"(Yes|No|Блокировка)", "Учетная запись работает: " },
|
||||||
{ "Последний пароль задан", regularDateTime, "Когда был сменен пароль: " },
|
{ "Последний пароль задан", regularDateTime, "Когда был сменен пароль: " },
|
||||||
{ "Действие пароля завершается", regularDateTime, "Когда нужно менять пароль (крайний срок): "},
|
{ "Действие пароля завершается", regularDateTime, "Когда нужно менять пароль (крайний срок): "},
|
||||||
{ "Членство в глобальных группах", @"([*].+)", "Член групп:\t" }
|
{ "Членство в глобальных группах", @"([*].+)", "Член групп:\t" }
|
||||||
@@ -28,53 +31,56 @@ namespace domain_utility
|
|||||||
|
|
||||||
static readonly string[,] computerNameRegex = new string[,] {
|
static readonly string[,] computerNameRegex = new string[,] {
|
||||||
{ "^[a-zA-Z]+\\d+$", "R54-630300" }, // THE01
|
{ "^[a-zA-Z]+\\d+$", "R54-630300" }, // THE01
|
||||||
{ "^\\d+[a-zA-Z]+\\d+$", "R54-" }, // 630300THE01
|
{ "^\\d{6,}[a-zA-Z]+\\d+$", "R54-" }, // 630300THE01
|
||||||
{ "^[rR]\\d*[-]\\d+[a-zA-Z]+\\d+$", "" } // R54-630300THE01
|
{ "^[rR]\\d{2,}[-]\\d{6,}[a-zA-Z]+\\d+$", "" } // R54-630300THE01
|
||||||
};
|
};
|
||||||
|
|
||||||
//private static volatile bool _ping_stop = false;
|
static string domain_user = string.Empty;
|
||||||
private static bool _ping_stop = false;
|
static string domain_password = string.Empty;
|
||||||
|
|
||||||
private static bool IsStringContainIp(string ip)
|
static bool _click_cancel = false;
|
||||||
|
|
||||||
|
static bool IsStringContainIp(string ip)
|
||||||
{
|
{
|
||||||
return Regex.Match(ip, @"^(\d+[.]\d+[.]\d+[.]\d+)$").Success;
|
return Regex.IsMatch(ip, @"^(\d+[.]\d+[.]\d+[.]\d+)$");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string СheckComputerName(string pcName)
|
static string CheckComputerName(string pcName)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < computerNameRegex.GetLength(0); i++)
|
for (int i = 0; i < computerNameRegex.GetLength(0); i++)
|
||||||
if (Regex.Match(pcName, computerNameRegex[i, 0]).Success)
|
if (Regex.IsMatch(pcName, computerNameRegex[i, 0]))
|
||||||
return $"{computerNameRegex[i, 1]}{pcName}".ToUpper();
|
return $"{computerNameRegex[i, 1]}{pcName}".ToUpper();
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string InputData(string message, Action callback, bool withClear = true, bool withChecks = true)
|
static string InputData(string message, Action callback, bool withClear = true, bool withChecks = true)
|
||||||
{
|
{
|
||||||
if (withClear)
|
if (withClear)
|
||||||
Console.Clear();
|
AnsiConsole.Clear();
|
||||||
Console.WriteLine(message);
|
string data = AnsiConsole.Prompt(
|
||||||
Console.Write("> ");
|
new TextPrompt<string>(message + "\n> ")
|
||||||
string remote = Console.ReadLine().Trim();
|
);
|
||||||
if (string.IsNullOrWhiteSpace(remote))
|
if (string.IsNullOrWhiteSpace(data))
|
||||||
InputData(message, callback, withClear, withChecks);
|
return InputData(message, callback, withClear, withChecks);
|
||||||
Console.WriteLine();
|
data = data.Trim();
|
||||||
|
AnsiConsole.WriteLine();
|
||||||
if (withChecks)
|
if (withChecks)
|
||||||
if (!IsStringContainIp(remote))
|
if (!IsStringContainIp(data))
|
||||||
{
|
{
|
||||||
remote = СheckComputerName(remote);
|
data = CheckComputerName(data);
|
||||||
if (remote == string.Empty)
|
if (data == string.Empty)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Имя компьютера или IP-адрес не распознаны! Попробуйте еще раз.");
|
AnsiConsole.WriteLine("Имя компьютера или IP-адрес не распознаны! Попробуйте еще раз.");
|
||||||
BackToMenu(callback);
|
BackToMenu(callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return remote;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BackToMenu(Action callback, bool withMessage = true)
|
static void BackToMenu(Action callback, bool withMessage = true)
|
||||||
{
|
{
|
||||||
if (withMessage)
|
if (withMessage)
|
||||||
Console.WriteLine("\nНажмите Enter чтобы продолжить, ESC чтобы вернуться на главную.");
|
AnsiConsole.WriteLine("\nНажмите Enter чтобы продолжить, ESC чтобы вернуться на главную.");
|
||||||
ConsoleKey key = Console.ReadKey(true).Key;
|
ConsoleKey key = Console.ReadKey(true).Key;
|
||||||
if (key == ConsoleKey.Enter)
|
if (key == ConsoleKey.Enter)
|
||||||
callback.Invoke();
|
callback.Invoke();
|
||||||
@@ -82,12 +88,64 @@ namespace domain_utility
|
|||||||
Menu();
|
Menu();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("Нажмите Enter или ESC!");
|
AnsiConsole.WriteLine("Нажмите Enter или ESC!");
|
||||||
BackToMenu(callback, false);
|
BackToMenu(callback, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string PingHost(string host)
|
static void InputDomainCredentials()
|
||||||
|
{
|
||||||
|
if (domain_user == string.Empty)
|
||||||
|
{
|
||||||
|
string machineNameAndUser = WindowsIdentity.GetCurrent().Name.ToString();
|
||||||
|
int indexOfUserName = machineNameAndUser.IndexOf('\\') + 1;
|
||||||
|
domain_user = machineNameAndUser.Substring(indexOfUserName, machineNameAndUser.Length - indexOfUserName).ToLower();
|
||||||
|
}
|
||||||
|
if (domain_password != string.Empty)
|
||||||
|
return;
|
||||||
|
domain_password = AnsiConsole.Prompt(
|
||||||
|
new TextPrompt<string>("\nВведите пароль от ТЕКУЩЕЙ учетной записи:\n> ")
|
||||||
|
.Secret()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ExecuteCommandViaSSH(string remote, string commandToExecute)
|
||||||
|
{
|
||||||
|
InputDomainCredentials();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (SshClient client = new SshClient(remote, domain_user, domain_password))
|
||||||
|
{
|
||||||
|
client.Connect();
|
||||||
|
SshCommand command = client.RunCommand(commandToExecute);
|
||||||
|
AnsiConsole.WriteLine(command.Result);
|
||||||
|
client.Disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
AnsiConsole.WriteLine("Произошла ошибка: " + ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ResetAdminPassword()
|
||||||
|
{
|
||||||
|
string machineNameAndUser = WindowsIdentity.GetCurrent().Name.ToString();
|
||||||
|
string machineName = machineNameAndUser.Substring(0, machineNameAndUser.IndexOf('\\'));
|
||||||
|
|
||||||
|
using (DirectoryEntry directoryEntry = new DirectoryEntry(string.Format("WinNT://{0}/{1}", machineName, "Администратор")))
|
||||||
|
{
|
||||||
|
//directoryEntry.Properties["LockOutTime"].Value = 0;
|
||||||
|
directoryEntry.Invoke("SetPassword", "Qwe12345");
|
||||||
|
directoryEntry.CommitChanges();
|
||||||
|
directoryEntry.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
AnsiConsole.WriteLine("Пароль сброшен.");
|
||||||
|
BackToMenu(Menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
static string PingHost(string host)
|
||||||
{
|
{
|
||||||
string returnMessage = string.Empty;
|
string returnMessage = string.Empty;
|
||||||
PingOptions pingOptions = new PingOptions() { DontFragment = true }; // TTL = 128
|
PingOptions pingOptions = new PingOptions() { DontFragment = true }; // TTL = 128
|
||||||
@@ -109,9 +167,9 @@ namespace domain_utility
|
|||||||
case IPStatus.Success:
|
case IPStatus.Success:
|
||||||
{
|
{
|
||||||
if (pingReply.RoundtripTime < 1)
|
if (pingReply.RoundtripTime < 1)
|
||||||
returnMessage = string.Format("Ответ от {0}: число байт={1} время<1ms TTL={2}", pingReply.Address, pingReply.Buffer.Length, pingReply.Options.Ttl);
|
returnMessage = string.Format("Ответ от {0}: число байт={1} время<1мс TTL={2}", pingReply.Address, pingReply.Buffer.Length, pingReply.Options.Ttl);
|
||||||
else
|
else
|
||||||
returnMessage = string.Format("Ответ от {0}: число байт={1} время={2}ms TTL={3}", pingReply.Address, pingReply.Buffer.Length, pingReply.RoundtripTime, pingReply.Options.Ttl);
|
returnMessage = string.Format("Ответ от {0}: число байт={1} время={2}мс TTL={3}", pingReply.Address, pingReply.Buffer.Length, pingReply.RoundtripTime, pingReply.Options.Ttl);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IPStatus.TimedOut:
|
case IPStatus.TimedOut:
|
||||||
@@ -135,26 +193,68 @@ namespace domain_utility
|
|||||||
return returnMessage;
|
return returnMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ResetAdminPassword()
|
static void PingClickCancel(object sender, ConsoleCancelEventArgs e)
|
||||||
{
|
{
|
||||||
string machineNameAndUser = WindowsIdentity.GetCurrent().Name.ToString();
|
e.Cancel = true;
|
||||||
string machineName = machineNameAndUser.Substring(0, machineNameAndUser.IndexOf('\\'));
|
_click_cancel = true;
|
||||||
|
|
||||||
using (DirectoryEntry directoryEntry = new DirectoryEntry(string.Format("WinNT://{0}/{1}", machineName, "Администратор")))
|
|
||||||
{
|
|
||||||
//directoryEntry.Properties["LockOutTime"].Value = 0;
|
|
||||||
directoryEntry.Invoke("SetPassword", "Qwe12345");
|
|
||||||
directoryEntry.CommitChanges();
|
|
||||||
//directoryEntry.Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Пароль сброшен.");
|
static void StartPing()
|
||||||
BackToMenu(Menu);
|
{
|
||||||
|
string remote = InputData("ping компьютера\n\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
||||||
|
StartPing);
|
||||||
|
|
||||||
|
AnsiConsole.WriteLine("Нажмите Ctrl + C чтобы остановить\n");
|
||||||
|
string correctName = CheckComputerName(remote);
|
||||||
|
if (correctName != string.Empty)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IPAddress ip = Dns.GetHostEntry(correctName).AddressList.First(addr => addr.AddressFamily == AddressFamily.InterNetwork);
|
||||||
|
remote = ip.ToString();
|
||||||
|
AnsiConsole.WriteLine("Обмен пакетами с {0}.main.russianpost.ru [{1}] с 32 байтами данных:", correctName, remote);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
AnsiConsole.WriteLine("Компьютер не найден.");
|
||||||
|
BackToMenu(StartPing);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
AnsiConsole.WriteLine("Обмен пакетами с {0} по с 32 байтами данных:", remote);
|
||||||
|
|
||||||
|
Console.CancelKeyPress += PingClickCancel;
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if (_click_cancel) break;
|
||||||
|
AnsiConsole.WriteLine(PingHost(remote));
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
}
|
||||||
|
Console.CancelKeyPress -= PingClickCancel;
|
||||||
|
_click_cancel = false;
|
||||||
|
|
||||||
|
BackToMenu(StartPing);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ShowDomainUserInfo()
|
static void StartRDPConnection()
|
||||||
{
|
{
|
||||||
string username = InputData("\nВведите имя пользователя (пр. 'lev.rusanov'): ", ShowDomainUserInfo, withChecks: false);
|
string remote = InputData("удаленный доступ к компьютеру\n\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
||||||
|
StartRDPConnection);
|
||||||
|
|
||||||
|
remote = $"/v:{remote} /f";
|
||||||
|
Process proc = new Process();
|
||||||
|
proc.StartInfo = new ProcessStartInfo("mstsc", remote);
|
||||||
|
proc.Start();
|
||||||
|
|
||||||
|
AnsiConsole.WriteLine("Подключение открыто.");
|
||||||
|
|
||||||
|
BackToMenu(StartRDPConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ShowDomainUserInfo()
|
||||||
|
{
|
||||||
|
string username = InputData("посмотреть информацию о пользователе\n\nВведите имя пользователя (пр. 'lev.rusanov'): ", ShowDomainUserInfo, withChecks: false);
|
||||||
|
|
||||||
username = $"user {username} /domain";
|
username = $"user {username} /domain";
|
||||||
|
|
||||||
@@ -182,7 +282,7 @@ namespace domain_utility
|
|||||||
regex = Regex.Match(strArr[i], stringsToFind[j, 1]);
|
regex = Regex.Match(strArr[i], stringsToFind[j, 1]);
|
||||||
if (regex.Success)
|
if (regex.Success)
|
||||||
{
|
{
|
||||||
Console.WriteLine(stringsToFind[j, 2] + regex.Value);
|
AnsiConsole.WriteLine(stringsToFind[j, 2] + regex.Value);
|
||||||
if (j == 3)
|
if (j == 3)
|
||||||
{
|
{
|
||||||
groupsFlag = true;
|
groupsFlag = true;
|
||||||
@@ -194,7 +294,7 @@ namespace domain_utility
|
|||||||
{
|
{
|
||||||
regex = Regex.Match(strArr[i], stringsToFind[j, 1]);
|
regex = Regex.Match(strArr[i], stringsToFind[j, 1]);
|
||||||
if (regex.Success)
|
if (regex.Success)
|
||||||
Console.WriteLine("\t\t" + regex.Value);
|
AnsiConsole.WriteLine("\t\t" + regex.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,9 +303,9 @@ namespace domain_utility
|
|||||||
BackToMenu(ShowDomainUserInfo);
|
BackToMenu(ShowDomainUserInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ShowComputerBootupTime()
|
static void ShowComputerBootupTime()
|
||||||
{
|
{
|
||||||
string remote = InputData("\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
string remote = InputData("посмотреть дату последней загрузки компьютера\n\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
||||||
ShowComputerBootupTime);
|
ShowComputerBootupTime);
|
||||||
|
|
||||||
ManagementScope scope = new ManagementScope(string.Format(@"\\{0}\root\cimv2", remote));
|
ManagementScope scope = new ManagementScope(string.Format(@"\\{0}\root\cimv2", remote));
|
||||||
@@ -216,173 +316,20 @@ namespace domain_utility
|
|||||||
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
|
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
|
||||||
var firstResult = searcher.Get().OfType<ManagementObject>().First()["LastBootUpTime"];
|
var firstResult = searcher.Get().OfType<ManagementObject>().First()["LastBootUpTime"];
|
||||||
DateTime lastBootUp = ManagementDateTimeConverter.ToDateTime(firstResult.ToString());
|
DateTime lastBootUp = ManagementDateTimeConverter.ToDateTime(firstResult.ToString());
|
||||||
Console.WriteLine("Дата последней загрузки: " + lastBootUp);
|
AnsiConsole.WriteLine("Дата последней загрузки: " + lastBootUp);
|
||||||
Console.WriteLine("Время работы (д:ч:м:с): " + (DateTime.Now.ToUniversalTime() - lastBootUp.ToUniversalTime()).ToString(@"d\:hh\:mm\:ss"));
|
AnsiConsole.WriteLine("Время работы (д:ч:м:с): " + (DateTime.Now.ToUniversalTime() - lastBootUp.ToUniversalTime()).ToString(@"d\:hh\:mm\:ss"));
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Произошла ошибка. Попробуйте еще раз.");
|
AnsiConsole.WriteLine("Произошла ошибка. Попробуйте еще раз.");
|
||||||
BackToMenu(ShowComputerBootupTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BackToMenu(ShowComputerBootupTime);
|
BackToMenu(ShowComputerBootupTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
|
static void RemoteRebootWindows()
|
||||||
{
|
{
|
||||||
e.Cancel = true;
|
string remote = InputData("удаленная перезагрузка компьютера\n\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
||||||
_ping_stop = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void StartPing()
|
|
||||||
{
|
|
||||||
string remote = InputData("\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
|
||||||
StartPing);
|
|
||||||
|
|
||||||
string correctName = СheckComputerName(remote);
|
|
||||||
if (correctName != string.Empty)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
IPAddress ip = Dns.GetHostEntry(correctName).AddressList.First(addr => addr.AddressFamily == AddressFamily.InterNetwork);
|
|
||||||
remote = ip.ToString();
|
|
||||||
Console.WriteLine("Обмен пакетами с {0} [{1}] с 32 байтами данных:", correctName, remote);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Компьютер не найден.");
|
|
||||||
BackToMenu(StartPing);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Console.WriteLine("Обмен пакетами с {0} по с 32 байтами данных:", remote);
|
|
||||||
|
|
||||||
Console.CancelKeyPress += Console_CancelKeyPress;
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
if (_ping_stop) break;
|
|
||||||
Console.WriteLine(PingHost(remote));
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
}
|
|
||||||
Console.CancelKeyPress -= Console_CancelKeyPress;
|
|
||||||
_ping_stop = false;
|
|
||||||
|
|
||||||
BackToMenu(StartPing);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OpenComputerCups()
|
|
||||||
{
|
|
||||||
string remote = InputData("\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
|
||||||
OpenComputerCups);
|
|
||||||
|
|
||||||
Process.Start($"https://{remote}:631/printers");
|
|
||||||
|
|
||||||
BackToMenu(OpenComputerCups);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void StartRDPConnection()
|
|
||||||
{
|
|
||||||
string remote = InputData("\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
|
||||||
StartRDPConnection);
|
|
||||||
|
|
||||||
remote = $"/v:{remote} /f";
|
|
||||||
Process proc = new Process();
|
|
||||||
proc.StartInfo = new ProcessStartInfo("mstsc", remote);
|
|
||||||
proc.Start();
|
|
||||||
|
|
||||||
BackToMenu(StartRDPConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string InputPassword()
|
|
||||||
{
|
|
||||||
Console.WriteLine("Введите пароль от СВОЕЙ учетной записи:");
|
|
||||||
Console.Write("> ");
|
|
||||||
string password = string.Empty;
|
|
||||||
ConsoleKeyInfo key;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
key = Console.ReadKey(true);
|
|
||||||
if (key.Key == ConsoleKey.Backspace && password.Length > 0)
|
|
||||||
{
|
|
||||||
password = password.Substring(0, password.Length - 1);
|
|
||||||
Console.Write("\b \b");
|
|
||||||
}
|
|
||||||
else if (key.KeyChar < 32 || key.KeyChar > 126)
|
|
||||||
continue;
|
|
||||||
else if (key.Key != ConsoleKey.Backspace)
|
|
||||||
{
|
|
||||||
password += key.KeyChar;
|
|
||||||
Console.Write("*");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (key.Key != ConsoleKey.Enter);
|
|
||||||
Console.Write("\n\n");
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ExecuteCommandViaSSH(string remote, string password, string commandToExecute)
|
|
||||||
{
|
|
||||||
string machineNameAndUser = WindowsIdentity.GetCurrent().Name.ToString();
|
|
||||||
int indexOfUserName = machineNameAndUser.IndexOf('\\') + 1;
|
|
||||||
string machineUser = machineNameAndUser.Substring(indexOfUserName, machineNameAndUser.Length - indexOfUserName).ToLower();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (SshClient client = new SshClient(remote, machineUser, password))
|
|
||||||
{
|
|
||||||
client.Connect();
|
|
||||||
SshCommand command = client.RunCommand(commandToExecute);
|
|
||||||
Console.WriteLine(command.Result);
|
|
||||||
client.Disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Произошла ошибка: " + ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void FixConky()
|
|
||||||
{
|
|
||||||
string remote = InputData("\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
|
||||||
FixConky);
|
|
||||||
|
|
||||||
string password = InputPassword();
|
|
||||||
|
|
||||||
ExecuteCommandViaSSH(remote, password, "sudo sed -i 's/update_interval = 0.5,/update_interval = 300,/' /etc/conky/conky.conf");
|
|
||||||
|
|
||||||
BackToMenu(FixConky);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RemoteRebootLinux()
|
|
||||||
{
|
|
||||||
string remote = InputData("\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
|
||||||
RemoteRebootLinux);
|
|
||||||
|
|
||||||
string password = InputPassword();
|
|
||||||
|
|
||||||
ExecuteCommandViaSSH(remote, password, "sudo shutdown -r +3 \"Через 3 минуты будет произведена перезагрузка ПК!\"");
|
|
||||||
|
|
||||||
BackToMenu(RemoteRebootLinux);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ExecuteCustomCommandViaSSH()
|
|
||||||
{
|
|
||||||
string remote = InputData("\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
|
||||||
ExecuteCustomCommandViaSSH);
|
|
||||||
|
|
||||||
string commandToExecute = InputData("Введите команду для выполнения:", ExecuteCustomCommandViaSSH, withClear: false, withChecks: false);
|
|
||||||
string password = InputPassword();
|
|
||||||
|
|
||||||
ExecuteCommandViaSSH(remote, password, commandToExecute);
|
|
||||||
|
|
||||||
BackToMenu(ExecuteCustomCommandViaSSH);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RemoteRebootWindows()
|
|
||||||
{
|
|
||||||
string remote = InputData("\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
|
||||||
RemoteRebootWindows);
|
RemoteRebootWindows);
|
||||||
|
|
||||||
remote = $"/m \\\\{remote} /r /f /t 180 /c \"Через 3 минуты будет произведена перезагрузка ПК!\"";
|
remote = $"/m \\\\{remote} /r /f /t 180 /c \"Через 3 минуты будет произведена перезагрузка ПК!\"";
|
||||||
@@ -390,62 +337,284 @@ namespace domain_utility
|
|||||||
proc.StartInfo = new ProcessStartInfo("shutdown", remote);
|
proc.StartInfo = new ProcessStartInfo("shutdown", remote);
|
||||||
proc.Start();
|
proc.Start();
|
||||||
|
|
||||||
Console.WriteLine("Команда перезагрузки успешно отправлена!");
|
AnsiConsole.WriteLine("Команда перезагрузки отправлена.");
|
||||||
|
|
||||||
BackToMenu(RemoteRebootWindows);
|
BackToMenu(RemoteRebootWindows);
|
||||||
}
|
}
|
||||||
|
|
||||||
static readonly string[] menuList = {
|
static void OpenComputerCups()
|
||||||
//"630300 - сброс пароля локального администратора (только Windows)", // ResetAdminPassword
|
{
|
||||||
"Выберите действие:",
|
string remote = InputData("открыть CUPS выбранного компьютера (Linux)\n\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
||||||
"1 - ping компьютера", // StartPing
|
OpenComputerCups);
|
||||||
"2 - удаленно подключиться к компьютеру", // StartRDPConnection
|
|
||||||
"3 - посмотреть информацию о пользователе (только Windows)", // ShowDomainUserInfo
|
if (CheckComputerName(remote) != string.Empty)
|
||||||
"4 - посмотреть дату последней загрузки компьютера (только Windows)", // ShowComputerBootupTime
|
{
|
||||||
"5 - удаленная перезагрузка компьютера (только Windows)", // RemoteRebootWindows
|
string pc_name = remote;
|
||||||
"6 - открыть CUPS выбранного компьютера (только Linux)", // OpenComputerCups
|
try
|
||||||
"7 - изменить время обновления conky с 0.5 на 300 (только Linux)", // FixConky
|
{
|
||||||
"8 - удаленная перезагрузка компьютера (только Linux)", // RemoteRebootLinux
|
remote = Dns.GetHostEntry(remote).AddressList.First(addr => addr.AddressFamily == AddressFamily.InterNetwork).ToString();
|
||||||
"9 - выполнить команду удаленно (только Windows -> Linux)", // ExecuteCustomCommandViaSSH
|
if (!IsStringContainIp(pc_name))
|
||||||
|
AnsiConsole.WriteLine($"CUPS {pc_name} ({remote}) открыт.");
|
||||||
|
else
|
||||||
|
AnsiConsole.WriteLine($"CUPS {remote} открыт.");
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
AnsiConsole.WriteLine("Компьютер не найден.");
|
||||||
|
BackToMenu(OpenComputerCups);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Process.Start($"https://{remote}:631/printers");
|
||||||
|
|
||||||
|
BackToMenu(OpenComputerCups);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ExecuteCustomCommandViaSSH()
|
||||||
|
{
|
||||||
|
string remote = InputData("выполнить команду через SSH (Linux)\n\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
||||||
|
ExecuteCustomCommandViaSSH);
|
||||||
|
|
||||||
|
string commandToExecute = InputData("Введите команду для выполнения:", ExecuteCustomCommandViaSSH, withClear: false, withChecks: false);
|
||||||
|
|
||||||
|
ExecuteCommandViaSSH(remote, commandToExecute);
|
||||||
|
|
||||||
|
AnsiConsole.WriteLine("Команда выполнена.");
|
||||||
|
|
||||||
|
BackToMenu(ExecuteCustomCommandViaSSH);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FixConky()
|
||||||
|
{
|
||||||
|
string remote = InputData("изменить время обновления conky с 0.5 на 300 (Linux)\n\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
||||||
|
FixConky);
|
||||||
|
|
||||||
|
ExecuteCommandViaSSH(remote, "sudo sed -i 's/update_interval = 0.5,/update_interval = 300,/' /etc/conky/conky.conf");
|
||||||
|
|
||||||
|
AnsiConsole.WriteLine("Команда исправления Conky отправлена.");
|
||||||
|
|
||||||
|
BackToMenu(FixConky);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void RemoteRebootLinux()
|
||||||
|
{
|
||||||
|
string remote = InputData("удаленная перезагрузка компьютера (Linux)\n\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
||||||
|
RemoteRebootLinux);
|
||||||
|
|
||||||
|
ExecuteCommandViaSSH(remote, "sudo shutdown -r +3 \"Через 3 минуты будет произведена перезагрузка ПК!\"");
|
||||||
|
|
||||||
|
AnsiConsole.WriteLine("Команда перезагрузки отправлена.");
|
||||||
|
|
||||||
|
BackToMenu(RemoteRebootLinux);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ShowLinuxComputerBootupTime()
|
||||||
|
{
|
||||||
|
string remote = InputData("посмотреть время работы компьютера (Linux)\n\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
||||||
|
ShowLinuxComputerBootupTime);
|
||||||
|
|
||||||
|
ExecuteCommandViaSSH(remote, "uptime");
|
||||||
|
|
||||||
|
BackToMenu(ShowLinuxComputerBootupTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ChangeRemote802Password()
|
||||||
|
{
|
||||||
|
string remote = InputData("сменить пароль для 802.1x (Linux)\n\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04')\nall - для массового изменения",
|
||||||
|
ChangeRemote802Password, withChecks: false);
|
||||||
|
remote = remote.Trim().ToLower();
|
||||||
|
if (remote != "all")
|
||||||
|
{
|
||||||
|
if (!IsStringContainIp(remote))
|
||||||
|
{
|
||||||
|
remote = CheckComputerName(remote);
|
||||||
|
if (remote == string.Empty)
|
||||||
|
ChangeRemote802Password();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string new802password = AnsiConsole.Prompt(
|
||||||
|
new TextPrompt<string>("\nВведите новый пароль от УЗ:\n> ")
|
||||||
|
.Secret()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (remote == "all")
|
||||||
|
{
|
||||||
|
string armListKey = AnsiConsole.Prompt(
|
||||||
|
new TextPrompt<string>("Введите УЗ на которой нужно сменить пароль")
|
||||||
|
.AddChoices(new string[] { "OBR", "PIS", "OBM", "MMP" })
|
||||||
|
);
|
||||||
|
InputDomainCredentials();
|
||||||
|
string path = Path.Combine(Environment.CurrentDirectory, "settings.json");
|
||||||
|
if (!File.Exists(path))
|
||||||
|
{
|
||||||
|
AnsiConsole.WriteLine("Файл с настройками не найден!");
|
||||||
|
BackToMenu(ChangeRemote802Password);
|
||||||
|
}
|
||||||
|
JsonFile data = JsonConvert.DeserializeObject<JsonFile>(File.ReadAllText(path));
|
||||||
|
string unitKey;
|
||||||
|
int sleep_time = data.sleep_time;
|
||||||
|
foreach (KeyValuePair<string, List<int>> unit in data.arm_list)
|
||||||
|
{
|
||||||
|
unitKey = unit.Key;
|
||||||
|
if (unitKey != armListKey)
|
||||||
|
continue;
|
||||||
|
foreach (int position in unit.Value)
|
||||||
|
{
|
||||||
|
remote = CheckComputerName($"{unitKey}{(position < 10 ? $"0{position}" : position.ToString())}");
|
||||||
|
if (remote == string.Empty)
|
||||||
|
{
|
||||||
|
AnsiConsole.WriteLine($"{unitKey}{(position < 10 ? $"0{position}" : position.ToString())}: имя ПК не распознано.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (SshClient client = new SshClient(remote, domain_user, domain_password))
|
||||||
|
{
|
||||||
|
client.Connect();
|
||||||
|
SshCommand command = client.RunCommand($"sudo sed -i 's/password=.\\+/password={new802password}/' /etc/NetworkManager/system-connections/Проводное\\ подключение\\ 1.nmconnection");
|
||||||
|
//AnsiConsole.WriteLine(command.Result);
|
||||||
|
command = client.RunCommand("sudo nmcli connection reload");
|
||||||
|
//AnsiConsole.WriteLine(command.Result);
|
||||||
|
command.Dispose();
|
||||||
|
client.Disconnect();
|
||||||
|
}
|
||||||
|
AnsiConsole.WriteLine(remote + ": ");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
AnsiConsole.WriteLine(remote + ": " + ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ExecuteCommandViaSSH(remote, $"sudo sed -i 's/^password=.\\+/password={new802password}/' /etc/NetworkManager/system-connections/Проводное\\ подключение\\ 1.nmconnection && sudo nmcli connection reload");
|
||||||
|
AnsiConsole.WriteLine("Команда отправлена.");
|
||||||
|
}
|
||||||
|
|
||||||
|
BackToMenu(ChangeRemote802Password);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DisableKdeWallet()
|
||||||
|
{
|
||||||
|
string remote = InputData("отключить KDE кошелек (Linux)\n\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
||||||
|
DisableKdeWallet);
|
||||||
|
|
||||||
|
ExecuteCommandViaSSH(remote, "sudo sed -i 's/^Exec=/#Exec=/' /usr/share/dbus-1/services/org.kde.kwalletd5.service");
|
||||||
|
|
||||||
|
AnsiConsole.WriteLine("Команда отключения кошелька отправлена.");
|
||||||
|
|
||||||
|
BackToMenu(DisableKdeWallet);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void OpenRemoteFilesystemWindows()
|
||||||
|
{
|
||||||
|
string remote = InputData("открыть файловую систему удаленного ПК (Windows)\n\nВведите IP адрес или имя компьютера (пр. 10.234.16.129, 'IT04', '630300IT04', 'R54-630300IT04'):",
|
||||||
|
OpenRemoteFilesystemWindows);
|
||||||
|
|
||||||
|
remote = $"\\\\{remote}\\c$";
|
||||||
|
Process proc = new Process();
|
||||||
|
proc.StartInfo = new ProcessStartInfo("explorer", remote);
|
||||||
|
proc.Start();
|
||||||
|
|
||||||
|
AnsiConsole.WriteLine("Файловая система открыта.");
|
||||||
|
|
||||||
|
BackToMenu(OpenRemoteFilesystemWindows);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MenuItem
|
||||||
|
{
|
||||||
|
public string Name { get; }
|
||||||
|
public Action Executor { get; }
|
||||||
|
|
||||||
|
public MenuItem(string _name, Action _executor)
|
||||||
|
{
|
||||||
|
Name = _name;
|
||||||
|
Executor = _executor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static readonly MenuItem[] availableOptions = new[]
|
||||||
|
{
|
||||||
|
new MenuItem("ping компьютера", () => StartPing()),
|
||||||
|
new MenuItem("удаленный доступ к компьютеру", () => StartRDPConnection()),
|
||||||
|
new MenuItem("посмотреть информацию о пользователе", () => ShowDomainUserInfo()),
|
||||||
|
new MenuItem("посмотреть дату последней загрузки компьютера", () => ShowComputerBootupTime()),
|
||||||
|
new MenuItem("удаленная перезагрузка компьютера", () => RemoteRebootWindows()),
|
||||||
|
new MenuItem("открыть CUPS выбранного компьютера (Linux)", () => OpenComputerCups()),
|
||||||
|
new MenuItem("выполнить команду через SSH (Linux)", () => ExecuteCustomCommandViaSSH()),
|
||||||
|
new MenuItem("изменить время обновления conky с 0.5 на 300 (Linux)", () => FixConky()),
|
||||||
|
new MenuItem("удаленная перезагрузка компьютера (Linux)", () => RemoteRebootLinux()),
|
||||||
|
new MenuItem("посмотреть время работы компьютера (Linux)", () => ShowLinuxComputerBootupTime()),
|
||||||
|
new MenuItem("сменить пароль для 802.1x (Linux)", () => ChangeRemote802Password()),
|
||||||
|
new MenuItem("отключить KDE кошелек (Linux)", () => DisableKdeWallet()),
|
||||||
|
new MenuItem("открыть файловую систему удаленного ПК (Windows)", () => OpenRemoteFilesystemWindows()),
|
||||||
};
|
};
|
||||||
|
|
||||||
private static void Menu()
|
static void Menu()
|
||||||
{
|
{
|
||||||
Console.Clear();
|
AnsiConsole.Clear();
|
||||||
for (int i = 0; i < menuList.Length; i++)
|
MenuItem choice = AnsiConsole.Prompt(
|
||||||
Console.WriteLine(menuList[i]);
|
new SelectionPrompt<MenuItem>()
|
||||||
int choice;
|
.Title("Выберите действие:")
|
||||||
Console.Write("> ");
|
.PageSize(15)
|
||||||
while (!int.TryParse(Console.ReadLine(), out choice))
|
//.MoreChoicesText("[grey](Move up and down to reveal more fruits)[/]")
|
||||||
{
|
.UseConverter(i => i.Name)
|
||||||
Console.WriteLine("Введите цифру!");
|
.AddChoices(availableOptions)
|
||||||
Console.Write("> ");
|
);
|
||||||
}
|
choice.Executor();
|
||||||
switch (choice)
|
|
||||||
{
|
|
||||||
case 1: StartPing(); break;
|
|
||||||
case 2: StartRDPConnection(); break;
|
|
||||||
case 3: ShowDomainUserInfo(); break;
|
|
||||||
case 4: ShowComputerBootupTime(); break;
|
|
||||||
case 5: RemoteRebootWindows(); break;
|
|
||||||
case 6: OpenComputerCups(); break;
|
|
||||||
case 7: FixConky(); break;
|
|
||||||
case 8: RemoteRebootLinux(); break;
|
|
||||||
case 9: ExecuteCustomCommandViaSSH(); break;
|
|
||||||
case 630300: ResetAdminPassword(); break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
Console.WriteLine("Неправильный выбор!");
|
|
||||||
Menu();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Main()
|
class JsonFile
|
||||||
|
{
|
||||||
|
public int sleep_time = 0;
|
||||||
|
public int restart_time = 0;
|
||||||
|
public string message = "";
|
||||||
|
public Dictionary<string, List<int>> arm_list = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void StartRestartComputers()
|
||||||
|
{
|
||||||
|
string path = Path.Combine(Environment.CurrentDirectory, "settings.json");
|
||||||
|
if (!File.Exists(path))
|
||||||
|
{
|
||||||
|
AnsiConsole.WriteLine("Файл с настройками не найден!");
|
||||||
|
Console.ReadKey();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JsonFile data = JsonConvert.DeserializeObject<JsonFile>(File.ReadAllText(path));
|
||||||
|
string remote, unitKey;
|
||||||
|
int sleep_time = data.sleep_time;
|
||||||
|
foreach (KeyValuePair<string, List<int>> unit in data.arm_list)
|
||||||
|
{
|
||||||
|
unitKey = unit.Key;
|
||||||
|
foreach (int position in unit.Value)
|
||||||
|
{
|
||||||
|
remote = CheckComputerName($"{unitKey}{(position < 10 ? $"0{position}" : position.ToString())}");
|
||||||
|
if (remote == string.Empty)
|
||||||
|
{
|
||||||
|
AnsiConsole.WriteLine($"{unitKey}{(position < 10 ? $"0{position}" : position.ToString())}: имя ПК не распознано.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//AnsiConsole.WriteLine($"{remote}: shutdown -r +{data.restart_time} \"{data.message}\"");
|
||||||
|
ExecuteCommandViaSSH(remote, $"sudo shutdown -r +{data.restart_time} \"{data.message}\"");
|
||||||
|
Thread.Sleep(sleep_time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Console.ReadKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
//Console.Title = typeof(Program).Assembly.GetName().Name;
|
|
||||||
Console.Title = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyTitleAttribute>().Title;
|
Console.Title = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyTitleAttribute>().Title;
|
||||||
|
if (args.Length > 0 && args[0] == "reboot")
|
||||||
|
{
|
||||||
|
StartRestartComputers();
|
||||||
|
return;
|
||||||
|
}
|
||||||
Menu();
|
Menu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,15 +39,31 @@
|
|||||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
<HintPath>packages\Microsoft.Bcl.AsyncInterfaces.1.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
<HintPath>packages\Microsoft.Bcl.AsyncInterfaces.1.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<HintPath>packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Renci.SshNet, Version=2024.1.0.0, Culture=neutral, PublicKeyToken=1cee9f8bde3db106, processorArchitecture=MSIL">
|
<Reference Include="Renci.SshNet, Version=2024.1.0.0, Culture=neutral, PublicKeyToken=1cee9f8bde3db106, processorArchitecture=MSIL">
|
||||||
<HintPath>packages\SSH.NET.2024.1.0\lib\net462\Renci.SshNet.dll</HintPath>
|
<HintPath>packages\SSH.NET.2024.1.0\lib\net462\Renci.SshNet.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Spectre.Console, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>packages\Spectre.Console.0.49.1\lib\netstandard2.0\Spectre.Console.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
|
<HintPath>packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.DirectoryServices" />
|
<Reference Include="System.DirectoryServices" />
|
||||||
<Reference Include="System.Management" />
|
<Reference Include="System.Management" />
|
||||||
|
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
|
<HintPath>packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Numerics" />
|
||||||
|
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
<HintPath>packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
<HintPath>packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
<HintPath>packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
|
<HintPath>packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||||
@@ -66,6 +82,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
<None Include="settings.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
|
|||||||
@@ -2,7 +2,12 @@
|
|||||||
<packages>
|
<packages>
|
||||||
<package id="ILRepack.Lib.MSBuild.Task" version="2.0.34.2" targetFramework="net48" developmentDependency="true" />
|
<package id="ILRepack.Lib.MSBuild.Task" version="2.0.34.2" targetFramework="net48" developmentDependency="true" />
|
||||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="1.0.0" targetFramework="net48" />
|
<package id="Microsoft.Bcl.AsyncInterfaces" version="1.0.0" targetFramework="net48" />
|
||||||
|
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
|
||||||
|
<package id="Spectre.Console" version="0.49.1" targetFramework="net48" />
|
||||||
<package id="SSH.NET" version="2024.1.0" targetFramework="net48" />
|
<package id="SSH.NET" version="2024.1.0" targetFramework="net48" />
|
||||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net48" />
|
<package id="System.Buffers" version="4.5.1" targetFramework="net48" />
|
||||||
|
<package id="System.Memory" version="4.5.5" targetFramework="net48" />
|
||||||
|
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
|
||||||
|
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net48" />
|
||||||
<package id="System.Threading.Tasks.Extensions" version="4.5.2" targetFramework="net48" />
|
<package id="System.Threading.Tasks.Extensions" version="4.5.2" targetFramework="net48" />
|
||||||
</packages>
|
</packages>
|
||||||
11
settings.json
Normal file
11
settings.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"sleep_time": 100,
|
||||||
|
"restart_time": 1,
|
||||||
|
"message": "Плановая перезагрузка компьютера через 1 минуту!",
|
||||||
|
"arm_list": {
|
||||||
|
"PIS": [ 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 30, 31, 32 ],
|
||||||
|
"OBR": [ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 32, 33, 34, 37, 40, 78, 79, 81, 82, 83, 84, 85, 86, 88, 89, 93, 94, 95, 97, 98, 99 ],
|
||||||
|
"OBM": [ 9, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 ],
|
||||||
|
"MMP": [ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 39, 40, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 65, 66, 68, 70, 71, 72, 73, 74, 75, 77, 78, 81, 82, 83, 84, 85, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97 ]
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user