init commit
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>GPO Query</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<h2>Query GPOs by Group</h2>
|
||||
<?php if (isset($_GET['group'])) : ?>
|
||||
<form action="index.php" method="GET">
|
||||
<label for="group">Group Name:</label>
|
||||
<input type="text" id="group" name="group" value="<?php echo htmlspecialchars($_GET['group']); ?>" required>
|
||||
<button type="submit">Query</button>
|
||||
</form>
|
||||
<?php else : ?>
|
||||
<form action="index.php" method="GET">
|
||||
<label for="group">Group Name:</label>
|
||||
<input type="text" id="group" name="group" required>
|
||||
<button type="submit">Query</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
if (isset($_GET['group'])) {
|
||||
$group = urlencode($_GET['group']); // Encode the group name for URL
|
||||
$url = "http://10.34.115.140:5000/gpo?group=$group"; // API endpoint
|
||||
// Initialize cURL session
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
|
||||
// Execute the request and fetch the response
|
||||
$response = curl_exec($ch);
|
||||
|
||||
// Check for errors
|
||||
if ($e = curl_error($ch)) {
|
||||
die("Curl error: $e");
|
||||
} else {
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($httpCode != 200) {
|
||||
die("Error: Received HTTP code $httpCode");
|
||||
}
|
||||
}
|
||||
|
||||
// Decode the JSON response
|
||||
$data = json_decode($response, true);
|
||||
|
||||
// Display the data in a table
|
||||
if (isset($data['error'])) {
|
||||
echo "<p>Error: {$data['error']}</p>";
|
||||
} else {
|
||||
echo "<table><tr><th>AD Group</th><th>GPO</th><th>Local Group</th></tr>";
|
||||
foreach ($data as $item) {
|
||||
echo "<tr><td>{$item['ad_group']}</td><td>{$item['gpo']}</td><td>{$item['local_group']}</td></tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
|
||||
// Close cURL session
|
||||
curl_close($ch);
|
||||
} else {
|
||||
echo "<p>No group specified.</p>";
|
||||
}
|
||||
?>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,92 @@
|
||||
/* styles.css */
|
||||
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: #2c3e50; /* Dark background color */
|
||||
color: #bdc3c7; /* Dimmer text color */
|
||||
}
|
||||
|
||||
.hidden-info {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.title-button {
|
||||
background-color: #34495e;
|
||||
border: none;
|
||||
color: white;
|
||||
padding: 15px 32px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
font-size: 16px;
|
||||
margin: 4px 2px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.container {
|
||||
max-width: 950px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
background-color: #34495e; /* Darker background for container */
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3); /* Slightly darker shadow */
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4 {
|
||||
color: #bdc3c7; /* Dimmer text color */
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
li {
|
||||
margin-bottom: 10px;
|
||||
color: #bdc3c7; /* Dimmer text color */
|
||||
}
|
||||
|
||||
.group-columns {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.group-rows {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-start; /* Left justification */
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.group-column {
|
||||
flex: 0 0 calc(33% - 10px); /* Adjust width of each column */
|
||||
}
|
||||
|
||||
.column {
|
||||
flex: 1;
|
||||
padding: 0 10px; /* Adjust spacing between columns */
|
||||
}
|
||||
|
||||
.subcolumn {
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.meter {
|
||||
width: calc(90% - 5px);
|
||||
max-width: calc(45% - 5px);
|
||||
margin-bottom: 5px;
|
||||
border: 1px solid #7f8c8d; /* Light border color */
|
||||
border-radius: 5px;
|
||||
padding: 5px;
|
||||
text-align: center;
|
||||
background-color: #2c3e50; /* Dark background for meter */
|
||||
}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
# ------------------------------------------------------------------
|
||||
# 0. Load modules (they are usually loaded by default, but be safe)
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
Import-Module GroupPolicy -ErrorAction Stop
|
||||
Import-Module ActiveDirectory -ErrorAction Stop
|
||||
$TargetOU = "OU=NA,OU=Manufacturing,OU=Tesla Systems,DC=teslamotors,DC=com"
|
||||
$OutputFile = "C:\Users\matanderson\gpo.yaml"
|
||||
# Add-Content -Path $OutputFile -Value $line
|
||||
if (Test-Path $OutputFile) {
|
||||
Remove-Item -Path $OutputFile -Force
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 1. Grab every OU under $TargetOU (including $TargetOU itself)
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
Write-Output "Enumerating OUs under '$TargetOU' ..."
|
||||
Add-Content -Path $OutputFile -Value "---"
|
||||
Add-Content -Path $OutputFile -Value "- root_ou: $TargetOU"
|
||||
$ouObjects = Get-ADObject `
|
||||
-Filter 'ObjectClass -eq "organizationalUnit"' `
|
||||
-SearchBase $TargetOU `
|
||||
-SearchScope Subtree `
|
||||
-Properties gPLink
|
||||
|
||||
# Also grab the target OU itself (in case it is linked directly)
|
||||
$targetOUObj = Get-ADObject `
|
||||
-Identity $TargetOU `
|
||||
-Properties gPLink
|
||||
if ($targetOUObj) {
|
||||
$ouObjects += $targetOUObj
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 2. Build a hashtable: GPO_GUID => list of OU DNs it is linked to
|
||||
# This is entirely opaque voodoo, i have no idea what's going on
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
$gpoLinks = @{}
|
||||
|
||||
foreach ($ou in $ouObjects) {
|
||||
if ($ou.gPLink) {
|
||||
foreach ($link in ($ou.gPLink -split ';')) {
|
||||
$linkTrim = $link.Trim('[', ']')
|
||||
if ($linkTrim -match '\{(?<guid>[0-9a-fA-F-]+)\}') {
|
||||
$guid = $Matches.guid
|
||||
if (-not $gpoLinks.ContainsKey($guid)) {
|
||||
$gpoLinks[$guid] = @()
|
||||
}
|
||||
$gpoLinks[$guid] += $ou.DistinguishedName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $gpoLinks.Count) {
|
||||
Write-Host "No GPOs linked under the searched OU tree." -ForegroundColor Yellow
|
||||
exit
|
||||
}
|
||||
|
||||
Write-Host "Found $($gpoLinks.Count) distinct GPO(s) linked in the OU tree."
|
||||
Add-Content -Path $OutputFile -Value " gpo_links: $($gpoLinks.Count)"
|
||||
|
||||
# ----------------------------------------------------
|
||||
# 3. For each GPO, get an XML report and pull RestrictedGroup nodes
|
||||
# ----------------------------------------------------
|
||||
|
||||
Add-Content -Path $OutputFile -Value " configured_gpos:"
|
||||
foreach ($gpoGuid in $gpoLinks.Keys) {
|
||||
try {
|
||||
$gpo = Get-GPO -Guid $gpoGuid -ErrorAction Stop
|
||||
}
|
||||
catch {
|
||||
Write-Warning "Unable to retrieve GPO $gpoGuid – skipping."
|
||||
continue
|
||||
}
|
||||
Write-Host "GPO: $($gpo.DisplayName)"
|
||||
Add-Content -Path $OutputFile -Value " $($gpo.DisplayName):"
|
||||
|
||||
# Pull the XML report
|
||||
try {
|
||||
$xmlString = Get-GPOReport -Guid $gpoGuid -ReportType Xml -ErrorAction Stop
|
||||
}
|
||||
catch {
|
||||
Write-Warning "Unable to generate XML report for $($gpo.DisplayName)."
|
||||
continue
|
||||
}
|
||||
|
||||
$xml = [xml]$xmlString
|
||||
|
||||
$ns = New-Object System.Xml.XmlNamespaceManager ($xml.NameTable)
|
||||
$ns.AddNamespace('m', 'http://www.microsoft.com/GroupPolicy/Settings') # default namespace
|
||||
$ns.AddNamespace('q1', 'http://www.microsoft.com/GroupPolicy/Settings/Security')
|
||||
$ns.AddNamespace('t', 'http://www.microsoft.com/GroupPolicy/Types')
|
||||
$ns.AddNamespace('xsi','http://www.w3.org/2001/XMLSchema-instance')
|
||||
|
||||
# Find every <q1:RestrictedGroups> element
|
||||
$restrictedGroups = $xml.SelectNodes('//q1:RestrictedGroups', $ns)
|
||||
|
||||
# Loop and build the string
|
||||
foreach ($rg in $restrictedGroups) {
|
||||
$adGroupName = ($rg.SelectSingleNode('q1:GroupName/t:Name', $ns)).InnerText
|
||||
$localGroupName = ($rg.SelectSingleNode('q1:Memberof/t:Name', $ns)).InnerText
|
||||
$plainAD_Groupname = ($adGroupName -split '\\')[-1]
|
||||
Write-Output "AD Group: $adGroupName - Local Group: $localGroupName"
|
||||
Add-Content -Path $OutputFile -Value " - ad_group: $plainAD_Groupname"
|
||||
Add-Content -Path $OutputFile -Value " local_group: $localGroupName"
|
||||
}
|
||||
Add-Content -Path $OutputFile -Value ""
|
||||
}
|
||||
Add-Content -Path $OutputFile -Value "..."
|
||||
Reference in New Issue
Block a user