add linked GPOs functionality

This commit is contained in:
2025-12-19 19:08:32 -08:00
parent 02120b78b2
commit 5327f865b9
3 changed files with 135 additions and 34 deletions
+83 -28
View File
@@ -1,7 +1,38 @@
<?php
# helper function for linked OUs
function getLinkedOUs(string $gpo): array|false
{
$encodedGpo = rawurlencode($gpo);
$requestUrl = "http://172.17.0.1:5000/linked_ous?gpo={$encodedGpo}";
$ch = curl_init($requestUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$rawResponse = curl_exec($ch);
if ($rawResponse === false) {
error_log('cURL error [' . curl_errno($ch) . ']: ' . curl_error($ch));
curl_close($ch);
return false;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
error_log("API returned HTTP {$httpCode} for GPO '{$gpo}'");
curl_close($ch);
return false;
}
curl_close($ch);
$decoded = json_decode($rawResponse, true);
if ($decoded === null && json_last_error() !== JSON_ERROR_NONE) {
error_log('JSON decode error: ' . json_last_error_msg());
return false;
}
return $decoded;
//return implode("\n", $decoded);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
@@ -16,24 +47,20 @@
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
<?php
// populating the info div
// if the group var is set, show the GPOs with the search term
if (isset($_GET['group'])) {
echo '
<form action="index.php" method="GET">
<label for="group">Group Name:</label>
<input type="text" id="group" name="group" value="'.htmlspecialchars($_GET['group']).'" required>
<button type="submit">Query</button>
</form><p>
';
$group = urlencode($_GET['group']);
$url = "http://10.34.115.140:5000/gpo?group=$group";
$url = "http://172.17.0.1:5000/gpo?group=$group";
// query API
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -80,22 +107,34 @@ if (isset($_GET['group'])) {
}
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>';
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>';
$linkedOUs = implode("\n", getLinkedOUs($gpoName));
echo ' <tr>
';
echo " <td>
<div title='$linkedOUs'>
<a href=/?gpo='$gpoName'>{$gpoName}</a>
</div></td>
";
echo " <td>{$adminGroups}</td>
";
echo " <td>{$vncGroups}</td>
";
echo ' </tr>
';
}
echo '</table>';
echo '</table>
';
}
else{
echo 'No results found for query <b>'.$_GET['group'].'</b>.<p>';
@@ -103,7 +142,23 @@ if (isset($_GET['group'])) {
}
}
// if you click on a GPO name, print all OUs
else if (isset($_GET['gpo'])) {
echo 'OUs linked to GPO <b>'.$_GET['gpo'].':</b><p>';
$LinkedOUs = getLinkedOUs($_GET['gpo']);
echo implode("<br>", $LinkedOUs);
echo '<br>Return <a href=/>Home</a>';
}
else {
echo '
<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>
';
echo "<p>No group specified.</p>";
}
echo "</div>";