-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
200 lines (163 loc) · 4.75 KB
/
Copy pathindex.html
File metadata and controls
200 lines (163 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!doctype html>
<html lang="es">
<head>
<meta charset="utf-8" />
<title>Estaciones Intune</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://alcdn.msauth.net/browser/2.38.3/js/msal-browser.min.js"></script>
<style>
body {
font-family: system-ui, Arial, sans-serif;
margin: 2rem;
background: #f6f7f9;
}
h1 {
margin-bottom: 0.5rem;
}
button {
padding: 0.7rem 1rem;
margin: 0.25rem;
border: 0;
border-radius: 8px;
cursor: pointer;
background: #2563eb;
color: white;
font-weight: 600;
}
button.secondary {
background: #475569;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 1rem;
background: white;
border-radius: 10px;
overflow: hidden;
}
th, td {
padding: 0.75rem;
border-bottom: 1px solid #e5e7eb;
text-align: left;
font-size: 0.9rem;
}
th {
background: #e2e8f0;
}
.status {
margin-top: 1rem;
font-weight: 600;
}
</style>
</head>
<body>
<h1>Estaciones administradas por Intune</h1>
<p>Consulta dispositivos usando Microsoft Graph.</p>
<button onclick="login()">Iniciar sesión</button>
<button class="secondary" onclick="loadDevices()">Cargar estaciones</button>
<button class="secondary" onclick="logout()">Cerrar sesión</button>
<div id="status" class="status"></div>
<table>
<thead>
<tr>
<th>Dispositivo</th>
<th>Usuario</th>
<th>Sistema</th>
<th>Compliance</th>
<th>Última sincronización</th>
</tr>
</thead>
<tbody id="devices"></tbody>
</table>
<script>
const msalConfig = {
auth: {
clientId: "PEGA_AQUI_TU_CLIENT_ID",
authority: "https://login.microsoftonline.com/PEGA_AQUI_TU_TENANT_ID",
redirectUri: "https://TU_USUARIO.github.io/intune-estaciones/"
}
};
const graphScopes = [
"DeviceManagementManagedDevices.Read.All"
];
const msalInstance = new msal.PublicClientApplication(msalConfig);
let account = null;
async function login() {
try {
const response = await msalInstance.loginPopup({
scopes: graphScopes
});
account = response.account;
document.getElementById("status").textContent =
"Sesión iniciada como: " + account.username;
} catch (error) {
console.error(error);
document.getElementById("status").textContent =
"Error al iniciar sesión: " + error.message;
}
}
async function getToken() {
const accounts = msalInstance.getAllAccounts();
if (!account && accounts.length > 0) {
account = accounts[0];
}
if (!account) {
throw new Error("Primero inicia sesión.");
}
try {
const tokenResponse = await msalInstance.acquireTokenSilent({
scopes: graphScopes,
account: account
});
return tokenResponse.accessToken;
} catch (error) {
const tokenResponse = await msalInstance.acquireTokenPopup({
scopes: graphScopes
});
return tokenResponse.accessToken;
}
}
async function loadDevices() {
try {
document.getElementById("status").textContent = "Cargando estaciones...";
const token = await getToken();
const response = await fetch(
"https://graph.microsoft.com/v1.0/deviceManagement/managedDevices?$select=deviceName,userPrincipalName,operatingSystem,complianceState,lastSyncDateTime",
{
headers: {
Authorization: "Bearer " + token
}
}
);
if (!response.ok) {
const errorText = await response.text();
throw new Error(errorText);
}
const data = await response.json();
const tbody = document.getElementById("devices");
tbody.innerHTML = "";
data.value.forEach(device => {
const row = document.createElement("tr");
row.innerHTML = `
<td>${device.deviceName || ""}</td>
<td>${device.userPrincipalName || ""}</td>
<td>${device.operatingSystem || ""}</td>
<td>${device.complianceState || ""}</td>
<td>${device.lastSyncDateTime || ""}</td>
`;
tbody.appendChild(row);
});
document.getElementById("status").textContent =
`Se encontraron ${data.value.length} estaciones.`;
} catch (error) {
console.error(error);
document.getElementById("status").textContent =
"Error: " + error.message;
}
}
function logout() {
msalInstance.logoutPopup();
}
</script>
</body>
</html>