-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMMM-GetShellScript.js
More file actions
102 lines (85 loc) · 3.26 KB
/
Copy pathMMM-GetShellScript.js
File metadata and controls
102 lines (85 loc) · 3.26 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
/**
* Magic Mirror Module: MMM-GetShellScript
* This module adds an API endpoint to your MagicMirror installation.
*/
Module.register("MMM-GetShellScript", {
defaults: {
// Legacy single-script config (still supported)
route: "/night",
authToken: "your-secret-token",
scriptPath: "modules/MMM-GetShellScript/scripts/example.sh",
requireAuth: true,
showLogs: true,
maxLogEntries: 10,
scriptTimeout: 30000,
cooldownSeconds: 0,
// New multi-script config
scripts: []
// scripts: [
// {
// route: "/night",
// scriptPath: "modules/MMM-GetShellScript/scripts/example.sh",
// authToken: "token1", // optional, falls back to global authToken
// requireAuth: true // optional, falls back to global requireAuth
// },
// {
// route: "/day",
// scriptPath: "modules/MMM-GetShellScript/scripts/example2.sh"
// }
// ]
},
logs: [],
getDom: function() {
const wrapper = document.createElement("div");
if (!this.config.showLogs) return wrapper;
wrapper.className = "small";
if (this.logs.length === 0) {
wrapper.innerHTML = "No executions yet.";
return wrapper;
}
const table = document.createElement("table");
table.className = "small";
this.logs.forEach(log => {
const row = document.createElement("tr");
const timeCell = document.createElement("td");
timeCell.innerHTML = log.time;
timeCell.className = "dimmed";
row.appendChild(timeCell);
// Add route cell if available
if (log.route) {
const routeCell = document.createElement("td");
routeCell.innerHTML = log.route;
routeCell.className = "dimmed";
row.appendChild(routeCell);
}
const statusCell = document.createElement("td");
statusCell.innerHTML = log.success ? "✓" : "✗";
statusCell.className = log.success ? "bright" : "dimmed";
row.appendChild(statusCell);
table.appendChild(row);
});
wrapper.appendChild(table);
return wrapper;
},
start: function() {
Log.info("Starting module: " + this.name);
this.sendSocketNotification("SETUP_ENDPOINT", this.config);
},
socketNotificationReceived: function(notification, payload) {
if (notification === "LOGS_LOADED") {
this.logs = payload;
this.updateDom();
} else if (notification === "SCRIPT_EXECUTED") {
this.logs.unshift({
time: new Date().toLocaleTimeString(),
route: payload.route,
success: payload.success
});
if (this.logs.length > this.config.maxLogEntries) {
this.logs = this.logs.slice(0, this.config.maxLogEntries);
}
this.updateDom();
this.sendNotification("SHELL_SCRIPT_EXECUTED", payload);
}
}
});