Skip to content

Commit

Permalink
Finished. Future may need flag for auto name grabbing.
Browse files Browse the repository at this point in the history
  • Loading branch information
krisdb2009 committed Feb 22, 2019
1 parent 25f6874 commit ae6d3f8
Showing 1 changed file with 55 additions and 4 deletions.
59 changes: 55 additions & 4 deletions SuperADD/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public partial class Main : Form
private int spookyCount = 5;
private int autoRunIndex = -1;
private bool autoRunContinue = false;
private bool suppressFindNextName = false;
private string currentCreateSelectedOU = "";

List<char> invalidNameCharacters = new List<char> {
Expand Down Expand Up @@ -320,7 +321,7 @@ void hMsg()
}
}

private Task<String> findOldComputerName()
private Task<String> findCurrentComputerName()
{
return Task.Run(() =>
{
Expand Down Expand Up @@ -447,6 +448,56 @@ private void setTSVariables(bool joinDomain = true, bool exitSuperADD = true)
}
}

private async void findCurrentDescriptionAndOU()
{
string rawResults = "";
try
{
showMsg("Searching AD for the current computer object...", loadImg);
int ouIndex = 0;
foreach (XElement ou in Config.Current.Element("OrganizationalUnits").Elements("OrganizationalUnit"))
{
bool found = false;
string dn = ou.Element("DistinguishedName").Value;
Dictionary<string, string> postData = new Dictionary<string, string>();
postData.Add("domain", adDomainName);
postData.Add("basedn", dn);
postData.Add("username", adUserName);
postData.Add("password", adPassword);
postData.Add("function", "list");
postData.Add("filter", "objectClass=computer");
rawResults = await HTTP.Post(Config.Current.Element("SuperADDServer").Value, postData);
var results = JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(rawResults);
foreach (Dictionary<string, string> computer in results)
{
if (computer["cn"] == nameTextBox.Text)
{
suppressFindNextName = true;
OUList.SelectedIndex = ouIndex;
suppressFindNextName = false;
descTextBox.Text = computer["description"];
found = true;
break;
}
}
if (found)
{
break;
}
ouIndex++;
}
hideMsg();
}
catch (JsonReaderException)
{
showMsg(rawResults, warnImg);
}
catch (Exception e)
{
showMsg(e.Message, warnImg);
}
}

private void directorySearchTb_TextChanged(object sender, EventArgs e)
{
currentlySelectedOUListUpdated();
Expand Down Expand Up @@ -493,7 +544,7 @@ private void OUList_SelectedIndexChanged(object sender, EventArgs e)
break;
}
}
if ((lv == OUList && tabControl.SelectedTab == compNameTab) || lv == dirLookOUList)
if (((lv == OUList && tabControl.SelectedTab == compNameTab) || lv == dirLookOUList) && !suppressFindNextName)
{
lv.Enabled = false;
retrieveCurrentlySelectedOUList();
Expand Down Expand Up @@ -570,8 +621,8 @@ private void prompt_KeyPress(object sender, KeyPressEventArgs e)

private async void findCurrentNameBtn_Click(object sender, EventArgs e)
{
string oldName = await findOldComputerName();
nameTextBox.Text = oldName;
nameTextBox.Text = await findCurrentComputerName();
findCurrentDescriptionAndOU();
}
}
}

0 comments on commit ae6d3f8

Please sign in to comment.