improving web layout
This commit is contained in:
+48
-22
@@ -26,42 +26,68 @@
|
||||
|
||||
<?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
|
||||
$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);
|
||||
|
||||
// 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
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($httpCode != 200) {
|
||||
die("Error: Received HTTP code $httpCode");
|
||||
}
|
||||
curl_close($ch);
|
||||
$data = json_decode($response, true);
|
||||
|
||||
// Display the data in a table
|
||||
// build the group array
|
||||
$gpoMap = []; // will look like: [ 'GPO‑Name' => ['Administrator' => [...], 'vnc_admin' => [...]] ]
|
||||
|
||||
if (isset($data['error'])) {
|
||||
echo "<p>Error: {$data['error']}</p>";
|
||||
} else {
|
||||
echo "<table><tr><th>GPO</th><th>AD Group</th><th>Local Group</th></tr>";
|
||||
foreach ($data as $item) {
|
||||
echo "<tr><td>{$item['gpo']}</td><td>{$item['ad_group']}</td><td>{$item['local_group']}</td></tr>";
|
||||
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;
|
||||
}
|
||||
}
|
||||
echo "</table>";
|
||||
ksort($gpoMap, SORT_STRING | SORT_FLAG_CASE);
|
||||
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 comma‑separated 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>';
|
||||
}
|
||||
|
||||
// Close cURL session
|
||||
curl_close($ch);
|
||||
} else {
|
||||
echo "<p>No group specified.</p>";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user