Files
gpo_lookup/files/dashboard/index.php
T
2025-12-19 12:12:16 -08:00

114 lines
4.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>GPO Query</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h2>Query GPOs by Group</h2>
This tool allows you to query Group Policy Objects in Active Directory by Restricted Group.<br>
Search is case insensitive and supports partial match. <br>
Once you have the GPO name, you can locate this in the GPO management snap-in and find what OUs it links to.<br><p>
</div>
<div class="container">
<?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><p>
<?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><p>
<?php endif; ?>
<?php
if (isset($_GET['group'])) {
$group = urlencode($_GET['group']);
$url = "http://10.34.115.140:5000/gpo?group=$group";
// query API
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
if ($e = curl_error($ch)) {
die("Curl error: $e");
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode != 200) {
die("Error: Received HTTP code $httpCode");
}
curl_close($ch);
$data = json_decode($response, true);
$numResults = count($data);
// build the group array
$gpoMap = []; // will look like: [ 'GPOName' => ['Administrator' => [...], 'vnc_admin' => [...]] ]
if (isset($data['error'])) {
echo "<p>Error: {$data['error']}</p>";
}
else {
foreach ($data as $row) {
// safety: skip rows that do not contain the expected keys
if (!isset($row['gpo'], $row['ad_group'], $row['local_group'])) {
continue;
}
$gpoName = $row['gpo'];
$adGroup = $row['ad_group'];
$localGroup = strtolower($row['local_group']);
// initialise if not already done
if (!isset($gpoMap[$gpoName])) {
$gpoMap[$gpoName] = [
'administrators' => [],
'vnc_admin' => []
];
}
// put the ad_group into the right bucket
if ($localGroup === 'administrators') {
$gpoMap[$gpoName]['administrators'][] = $adGroup;
} elseif ($localGroup === 'vnc_admin') {
$gpoMap[$gpoName]['vnc_admin'][] = $adGroup;
}
}
ksort($gpoMap, SORT_STRING | SORT_FLAG_CASE);
if($numResults > 0){
echo 'Total results: '.$numResults.'<br>';
echo '<table border="1" cellpadding="4" cellspacing="0">';
echo '<tr><th>GPO</th><th>Administrators</th><th>vnc_admin</th></tr>';
foreach ($gpoMap as $gpoName => $cols) {
// Remove duplicates and build commaseparated lists
$adminGroups = implode('<br>', array_unique($cols['administrators']));
$vncGroups = implode('<br>', array_unique($cols['vnc_admin']));
echo '<tr>';
echo "<td>{$gpoName}</td>";
echo "<td>{$adminGroups}</td>";
echo "<td>{$vncGroups}</td>";
echo '</tr>';
}
echo '</table>';
}
else{
echo 'No results found for query <b>'.$_GET['group'].'</b>.<p>';
}
}
}
else {
echo "<p>No group specified.</p>";
}
echo "</div>";
//echo "<p>Source code can be found <a target='_blank' rel='noopener noreferrer' href='https://gitea.matt-cloud.com/matt/gpo_lookup'>here</a>.<p>";
?>
</body>
</html>