forked from castab/phpWOL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·51 lines (44 loc) · 1.48 KB
/
app.js
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
function sendAction(macAddress, ipAddress, hostName, action) {
let data = {
host: { macAddress, ipAddress, hostName },
action: action
};
if (action === 'Restart' || action === 'Shutdown') {
data.host.password = prompt(`Enter the password to ${action.toLowerCase()} this host:`);
}
fetch('wol_action.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
if (data.status === 'Error') {
showAlert(data.error, false);
} else if (data.status === 'OK') {
showAlert(data.message, true);
} else {
showAlert('Unexpected response from server', false);
}
})
.catch((error) => {
console.error('Error:', error);
showAlert('An unexpected error occurred', false);
});
}
function showAlert(message, isSuccess) {
const alertElement = document.getElementById('globalAlert');
const alertMessage = document.getElementById('alertMessage');
alertElement.className = `alert alert-dismissible fade show alert-${isSuccess ? 'success' : 'danger'}`;
alertMessage.textContent = message;
alertElement.style.display = 'block';
setTimeout(() => {
hideAlert();
}, 5000);
}
function hideAlert() {
const alertElement = document.getElementById('globalAlert');
alertElement.style.display = 'none';
}