Exemple #1
0
 private void autoSelectSecurityGroups(XElement SecurityGroupsDNs)
 {
     SGList.ClearSelected();
     if (SecurityGroupsDNs == null)
     {
         return;
     }
     foreach (XElement SGDNs in SecurityGroupsDNs.Elements("SecurityGroupDN"))
     {
         XElement SGs = Config.Current.Element("SecurityGroups");
         if (SGs == null)
         {
             continue;
         }
         foreach (XElement SG in SGs.Elements("SecurityGroup"))
         {
             XElement Name = SG.Element("Name");
             XElement DN   = SG.Element("DistinguishedName");
             if (Name == null || DN == null)
             {
                 continue;
             }
             if (DN.Value == SGDNs.Value)
             {
                 SGList.SelectedItems.Add(Name.Value);
             }
         }
     }
 }
Exemple #2
0
        private async void getCurrentComputerDetails()
        {
            if (adDomainName == "" || adUserName == "" || adPassword == "")
            {
                showPassPrompt();
                return;
            }
            string rawResults = "";

            try
            {
                XElement BaseDN = Config.Current.Element("BaseDN");
                XElement OUs    = Config.Current.Element("OrganizationalUnits");
                XElement SGs    = Config.Current.Element("SecurityGroups");
                if (BaseDN == null || OUs == null)
                {
                    showMsg("BaseDN or OrganizationalUnits element is missing from SuperADD.xml", warnImg);
                    return;
                }
                showMsg("Searching AD for the current computer object...", loadImg);
                rawResults = await HTTP.Post(new Dictionary <string, string>() {
                    { "basedn", BaseDN.Value },
                    { "function", "list" },
                    { "recurse", "" },
                    { "includegroups", "" },
                    { "filter", "(&(sAMAccountName=" + nameTextBox.Text + "$)(objectClass=computer))" }
                });

                var results = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(rawResults);
                if (results.Count != 0)
                {
                    var    result = results[0];
                    string cn     = (string)result["cn"];
                    nameTextBox.Text = cn;
                    descTextBox.Text = (string)result["description"];
                    foreach (XElement OU in OUs.Elements("OrganizationalUnit"))
                    {
                        XElement DN   = OU.Element("DistinguishedName");
                        XElement Name = OU.Element("Name");
                        if (DN == null || Name == null)
                        {
                            continue;
                        }
                        if (DN.Value == ((string)result["dn"]).Replace("CN=" + cn + ",", ""))
                        {
                            suppressFindNextName = true;
                            OUList.SelectedItem  = Name.Value;
                            suppressFindNextName = false;
                            break;
                        }
                    }
                    SGList.ClearSelected();
                    foreach (string computerGroup in (JArray)results[0]["groups"])
                    {
                        if (SGs == null)
                        {
                            continue;
                        }
                        foreach (XElement definedGroup in SGs.Elements("SecurityGroup"))
                        {
                            XElement DN = definedGroup.Element("DistinguishedName");
                            if (DN != null && DN.Value == computerGroup)
                            {
                                SGList.SelectedItems.Add(definedGroup.Element("Name").Value);
                                break;
                            }
                        }
                    }
                    hideMsg();
                }
                else
                {
                    showMsg("Computer object not found.", warnImg);
                }
            }
            catch (JsonReaderException)
            {
                showMsg(rawResults, warnImg);
            }
            catch (Exception e)
            {
                showMsg(e.Message, warnImg);
            }
        }