Пример #1
0
        private async void retrieveCurrentlySelectedOUList()
        {
            string rawResults = "";

            if (adDomainName == "" || adUserName == "" || adPassword == "")
            {
                showPassPrompt();
                currentlySelectedOUListUpdated();
                return;
            }
            try
            {
                currentlySelectedOUList.Clear();
                showMsg("Retrieving a list of computer objects in this Organizational Unit...", loadImg, dismissable: false);
                rawResults = await HTTP.Post(new Dictionary <string, string>() {
                    { "basedn", currentlySelectedOU },
                    { "function", "list" },
                    { "filter", "objectClass=computer" }
                });

                var results = JsonConvert.DeserializeObject <List <Dictionary <string, string> > >(rawResults);
                foreach (Dictionary <string, string> computer in results)
                {
                    currentlySelectedOUList.Add(computer["cn"], computer["description"]);
                }
                hideMsg();
            }
            catch (HttpRequestException e)
            {
                showMsg(e.Message + ": " + e.InnerException.Message, warnImg);
            }
            catch (JsonReaderException)
            {
                showMsg("Daemon: " + rawResults, warnImg);
            }
            catch (Exception e)
            {
                showMsg(e.Message, warnImg);
            }
            currentlySelectedOUListUpdated();
        }
Пример #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);
            }
        }
Пример #3
0
        private async void createComputer()
        {
            if (nameTextBox.Text == "")
            {
                showMsg("Computer Name is empty.", warnImg);
                return;
            }
            if (OUList.SelectedItem == null)
            {
                showMsg("No Organizational Unit is selected.", warnImg);
                return;
            }
            if (adDomainName == "" || adUserName == "" || adPassword == "")
            {
                showPassPrompt();
                return;
            }
            XElement BaseDN         = Config.Current.Element("BaseDN");
            XElement SecurityGroups = Config.Current.Element("SecurityGroups");

            if (BaseDN == null || SecurityGroups == null)
            {
                showMsg("BaseDN or SecurityGroups elements is missing from SuperADD.xml", warnImg);
                return;
            }
            showMsg("Adding computer to Active Directory...", loadImg, dismissable: false);
            Dictionary <string, string> postData = new Dictionary <string, string>()
            {
                { "basedn", BaseDN.Value },
                { "function", "update" },
                { "cn", nameTextBox.Text },
                { "description", descTextBox.Text },
                { "destinationdn", currentCreateSelectedOU }
            };
            int index = 0;

            foreach (XElement SG in SecurityGroups.Elements("SecurityGroup"))
            {
                XElement SGName = SG.Element("Name");
                XElement SGDN   = SG.Element("DistinguishedName");
                if (SGName == null || SGDN == null)
                {
                    continue;
                }
                if (SGList.SelectedItems.Contains(SGName.Value))
                {
                    postData.Add("addgroups[" + (index++) + "]", SGDN.Value);
                }
                else
                {
                    postData.Add("removegroups[" + (index++) + "]", SGDN.Value);
                }
            }
            if (computerOverwriteConfirmed)
            {
                postData.Add("confirm", "");
            }
            try
            {
                string error = await HTTP.Post(postData);

                if (error != "")
                {
                    if (error == "confirm")
                    {
                        if (desktopMode)
                        {
                            showMsg("This computer object already exists!\nPress \"Save\" again to confirm.", warnImg, disableForm: false);
                        }
                        else
                        {
                            showMsg("This computer object already exists!\nPress \"Join Domain\" again to confirm.", warnImg, disableForm: false);
                        }
                        computerOverwriteConfirmed = true;
                    }
                    else
                    {
                        showMsg("Daemon: " + error, warnImg);
                    }
                }
                else
                {
                    if (desktopMode)
                    {
                        hideMsg();
                    }
                    else
                    {
                        setTSVariables();
                    }
                }
            }
            catch (HttpRequestException e)
            {
                showMsg(e.Message + ": " + e.InnerException.Message, warnImg);
            }
            catch (Exception e)
            {
                showMsg(e.Message, warnImg);
            }
        }
Пример #4
0
        private async void findNextComputerName()
        {
            string   AutoName = "";
            XElement OUs      = Config.Current.Element("OrganizationalUnits");

            if (OUs == null)
            {
                showMsg("OrganizationalUnits element missing from SuperADD.xml", warnImg);
                return;
            }
            foreach (XElement element in OUs.Elements("OrganizationalUnit"))
            {
                XElement Name = element.Element("Name");
                if (Name == null)
                {
                    continue;
                }
                if (Name.Value == OUList.Text)
                {
                    if (element.Element("AutoName") != null && element.Element("AutoName").Value != "")
                    {
                        AutoName = element.Element("AutoName").Value;
                    }
                    else
                    {
                        return;
                    }
                    break;
                }
            }
            if (AutoName.Contains("#") || AutoName.Contains("+"))
            {
                string[] splits;
                bool     appendMode = false;
                if (AutoName.Contains("+"))
                {
                    splits = AutoName.Split('+');
                }
                else
                {
                    appendMode = true;
                    splits     = AutoName.Split('#');
                }
                string prefix = splits[0];
                string suffix = splits[splits.Length - 1];
                int    count  = 0;
                if (adDomainName == "" || adUserName == "" || adPassword == "")
                {
                    showPassPrompt();
                    return;
                }
                string rawResults = "";
                try
                {
                    XElement BaseDN = Config.Current.Element("BaseDN");
                    if (BaseDN == null)
                    {
                        showMsg("BaseDN element missing from SuperADD.xml", warnImg);
                        return;
                    }
                    showMsg("Searching AD for next available name...", loadImg);
                    rawResults = await HTTP.Post(new Dictionary <string, string>() {
                        { "basedn", BaseDN.Value },
                        { "function", "list" },
                        { "recurse", "" },
                        { "filter", "(&(sAMAccountName=" + prefix + "*" + suffix + "$)(objectClass=computer))" }
                    });

                    var           results   = JsonConvert.DeserializeObject <List <Dictionary <string, string> > >(rawResults);
                    List <string> computers = new List <string>();
                    foreach (Dictionary <string, string> comp in results)
                    {
                        computers.Add(comp["cn"].ToLower());
                    }
                    if (appendMode)
                    {
                        foreach (string comp in computers)
                        {
                            if (comp.StartsWith(prefix.ToLower()))
                            {
                                int    number  = 0;
                                string sNumber = comp;
                                if (prefix.Length != 0)
                                {
                                    sNumber = sNumber.Replace(prefix.ToLower(), "");
                                }
                                if (suffix.Length != 0)
                                {
                                    sNumber = sNumber.Replace(suffix.ToLower(), "");
                                }
                                if (int.TryParse(sNumber, out number))
                                {
                                    if (number >= count)
                                    {
                                        count = number + 1;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        while (computers.Contains(prefix.ToLower() + count.ToString().PadLeft(splits.Length - 1).Replace(" ", "0") + suffix.ToLower()))
                        {
                            count++;
                        }
                    }
                    nameTextBox.Text = prefix + count.ToString().PadLeft(splits.Length - 1).Replace(" ", "0") + suffix;
                    hideMsg();
                }
                catch (JsonReaderException)
                {
                    showMsg(rawResults, warnImg);
                }
                catch (Exception e)
                {
                    showMsg(e.Message, warnImg);
                }
            }
            else
            {
                string name  = AutoName;
                int    index = 0;
                foreach (char character in AutoName)
                {
                    if (character == '*')
                    {
                        name = name.Remove(index, 1).Insert(index, RandChars.AlphaNumLower().ToString());
                    }
                    if (character == '$')
                    {
                        name = name.Remove(index, 1).Insert(index, RandChars.AlphaNumUpper().ToString());
                    }
                    if (character == '@')
                    {
                        name = name.Remove(index, 1).Insert(index, RandChars.AlphaNumAny().ToString());
                    }
                    if (character == '%')
                    {
                        name = name.Remove(index, 1).Insert(index, RandChars.Number().ToString());
                    }
                    if (character == '!')
                    {
                        name = name.Remove(index, 1).Insert(index, RandChars.AlphaLower().ToString());
                    }
                    if (character == '?')
                    {
                        name = name.Remove(index, 1).Insert(index, RandChars.AlphaUpper().ToString());
                    }
                    if (character == '~')
                    {
                        name = name.Remove(index, 1).Insert(index, RandChars.AlphaAny().ToString());
                    }
                    index++;
                }
                nameTextBox.Text = name;
            }
        }