Skip to content

Commit

Permalink
Handle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
KristjanESPERANTO committed Nov 6, 2024
1 parent 440cf3d commit 69852d0
Show file tree
Hide file tree
Showing 7 changed files with 510 additions and 319 deletions.
26 changes: 13 additions & 13 deletions API/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ If you ran the `installer.sh` script when you installed the module, a non-canoni
### Example Config Section

```js
{
module: 'MMM-Remote-Control'
config: {
apiKey: 'bc2e979db92f4741afad01d5d18eb8e2'
}
},
{
module: 'MMM-Remote-Control'
config: {
apiKey: 'bc2e979db92f4741afad01d5d18eb8e2'
}
},
```

### Passing your API key
Expand Down Expand Up @@ -91,12 +91,12 @@ Since 2.2.0, and in a way to prevent malicious actions on your mirror, a new con
As usual, this option can be disabled, but this will expose your Mirror to potentials hackers, so it's up to you to turn it off.

```js
{
module: 'MMM-Remote-Control'
config: {
secureEndpoints: true
}
},
{
module: 'MMM-Remote-Control'
config: {
secureEndpoints: true
}
},
```

By default, secureEndpoints it's true, defending commands like shutdown or install modules when no apikey it's present.
Expand All @@ -109,7 +109,7 @@ There are three general categories of API commands:
**1. MMM-Remote-Control Internal Commands** -- these are used to call the existing commands that MMM-Remote-Control already exposes. For example, to turn off the monitor ("MONITOROFF"):

```bash
curl -X GET http://magicmirrorip:8080/api/monitor/off
curl -X GET http://magicmirrorip:8080/api/monitor/off
```

**2. External APIs (Guessed)** -- when this module first loads, it parses all of the installed modules' source code and checks for any custom notifications that are used. From this basic search, it tries to "guess" notification actions that may be valid, without them being explicitly defined anywhere else. For example, the "alert" command examples above are not defined within this module, the 'alert' module just looks for a notification, "SHOW_ALERT"--this is exposed as a `/module/alert/showalert` action in the External API processor. Full credit to this idea goes to `juzim` from the MMM-Api module.
Expand Down
5 changes: 2 additions & 3 deletions API/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ module.exports = {

let getActions = function(content) {
let re = /notification \=\=\=? (?:"|')([A-Z_-]+?)(?:"|')|case (?:"|')([A-Z_-]+)(?:"|')/g;
let m;
let availableActions = [];
if (re.test(content)) {
content.match(re).forEach((match) => {
Expand Down Expand Up @@ -284,13 +283,13 @@ module.exports = {
this.executeQuery(this.checkDelay({ action: `MONITOR${actionName}` }, req), res);
})
.post((req, res) => {
var actionName = "STATUS";
let actionName = "STATUS";
if (typeof req.body !== 'undefined' && "monitor" in req.body) {
if (["OFF", "ON", "TOGGLE"].includes(req.body.monitor.toUpperCase())) {
actionName = req.body.monitor.toUpperCase();
}
} else {
var actionName = req.params.action ? req.params.action.toUpperCase() : "STATUS";
actionName = req.params.action ? req.params.action.toUpperCase() : "STATUS";
}
this.executeQuery(this.checkDelay({ action: `MONITOR${actionName}` }, req), res);
});
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ git tag # display them
The output should look similar to this:
```
```bash
v1.0.0
v1.1.0
v1.1.1
Expand All @@ -128,14 +128,12 @@ For example you can use [MMM-ModuleScheduler](https://forum.magicmirror.builders
- Example for a REST API GET request to trigger a RaspberryPi restart:
```
http://192.168.xxx.xxx:8080/api/restart
```
`http://192.168.xxx.xxx:8080/api/restart`
- Example to trigger a RaspberryPi restart in your module:
```
this.sendNotification('REMOTE_ACTION', {action: 'RESTART'});
```js
this.sendNotification("REMOTE_ACTION", { action: "RESTART" });
```
See some specific examples for controlling your mirror from other modules and add your own examples [in the Wiki page here](https://github.com/shbatm/MMM-Remote-Control/wiki/Examples-for-Controlling-from-Another-Module)
Expand Down
7 changes: 4 additions & 3 deletions node_helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* MagicMirror²
/* global Module:true */

/*
* MagicMirror²
* Module: Remote Control
*
* By Joseph Bethge
Expand All @@ -14,8 +17,6 @@ const exec = require("child_process").exec;
const Log = require("logger");
const os = require("os");
const simpleGit = require("simple-git");
const bodyParser = require("body-parser");
const express = require("express");
const _ = require("lodash");

let defaultModules = require(path.resolve(__dirname + "/../../modules/default/defaultmodules.js"));
Expand Down
Loading

0 comments on commit 69852d0

Please sign in to comment.