/// <summary> /// Формирование ответа на запрос информации о компьютере Active Directory по его имени /// </summary> /// <returns></returns> public override async Task Init() { await base.Init(); if (MessagesIn.Count() < 2 || string.IsNullOrEmpty(MessagesIn[1])) { return; } await Task.Run(async() => { var computerPrincipal = _ad.GetComputerObjectByName(MessagesIn[1]); if (computerPrincipal == null) { return; } var sb = new StringBuilder(); var compData = new ComputerInfo { Enabled = computerPrincipal.Enabled.Value, Name = computerPrincipal.DistinguishedName, Description = computerPrincipal.Description, OS = _ad.GetComputerProperty(computerPrincipal, "operatingSystem"), IP = await ComputerPinger.Ping(computerPrincipal.Name), LastLogon = computerPrincipal.LastLogon ?? DateTime.MinValue }; sb.AppendLine(ParseResponseObject(compData)); Message = sb.ToString(); }); }
/// <summary> /// Формирование ответа на запрос информации о группе Active Directory по ее имени /// </summary> public override async Task Init() { await base.Init(); if (MessagesIn.Count() < 2 || string.IsNullOrEmpty(MessagesIn[1])) { return; } await Task.Run(() => { var groupPrincipal = _ad.GetGroupObjectByName(MessagesIn[1]); if (groupPrincipal == null) { return; } var sb = new StringBuilder(); var groupData = new GroupInfo { Name = groupPrincipal.DistinguishedName, Description = groupPrincipal.Description }; var userData = new List <string>(_ad.GetUserNamesByGroupObject(groupPrincipal)).OrderBy(x => x); sb.AppendLine(ParseResponseObject(groupData)).AppendLine(ParseResponseList(userData)); Message = sb.ToString(); }); }
/// <summary> /// Включение оповещений об изменениях в Active Directory /// </summary> /// <returns></returns> public override async Task Init() { await base.Init(); if (MessagesIn.Count() < 3 || string.IsNullOrEmpty(MessagesIn[1]) || string.IsNullOrEmpty(MessagesIn[2])) { return; } if (MessagesIn[1].Length < 3 || MessagesIn[2].Length < 3) { return; } var userName = string.Empty; var userPassword = string.Empty; if (MessagesIn[1].Substring(0, 2).Equals("-u", StringComparison.OrdinalIgnoreCase)) { userName = MessagesIn[1].Substring(2); } else if (MessagesIn[1].Substring(0, 2).Equals("-p", StringComparison.OrdinalIgnoreCase)) { userPassword = MessagesIn[1].Substring(2); } if (MessagesIn[2].Substring(0, 2).Equals("-u", StringComparison.OrdinalIgnoreCase)) { userName = MessagesIn[2].Substring(2); } else if (MessagesIn[2].Substring(0, 2).Equals("-p", StringComparison.OrdinalIgnoreCase)) { userPassword = MessagesIn[2].Substring(2); } if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(userPassword)) { return; } await Task.Run(() => { var user = new Subscriber(_userId, _config, _ad); Message = user.SignIn(userName, userPassword); }); }
/// <summary> /// Ответ на запрос информации о пользователе Active Directory по его имени /// </summary> /// <returns></returns> public override async Task Init() { await base.Init(); if (MessagesIn.Count() < 2 || string.IsNullOrEmpty(MessagesIn[1])) { return; } await Task.Run(() => { var userPrincipal = _ad.GetUserObjectByName($"{MessagesIn[1]} {MessagesIn[2]} {MessagesIn[3]}"); if (userPrincipal == null) { return; } var sb = new StringBuilder(); var userData = new UserInfo { Enabled = userPrincipal.Enabled.Value, Name = userPrincipal.DisplayName, Mail = userPrincipal.EmailAddress, TelephoneNumber = userPrincipal.VoiceTelephoneNumber, LastLogon = userPrincipal.LastLogon ?? DateTime.MinValue, Company = _ad.GetUserProperty(userPrincipal, "Company"), Department = _ad.GetUserProperty(userPrincipal, "Department"), SamAccountName = userPrincipal.SamAccountName, Title = _ad.GetUserProperty(userPrincipal, "Title"), Description = userPrincipal.Description }; var groupData = new List <string>(_ad.GetGroupsByUserObject(userPrincipal)).OrderBy(x => x); sb.AppendLine(ParseResponseObject(userData)).AppendLine(ParseResponseList(groupData)); Message = sb.ToString(); }); }