LukeSkywalker92 / TeleFrame

TeleFrame - a digital picture frame for telegram
MIT License
93 stars 28 forks source link

Added Feature ==> admin action #35

Closed LuHKae closed 4 years ago

LuHKae commented 4 years ago

As administrator of a TeleFrame, it could be very useful to execute commands on the TeleFrame computer. With the TeleFrame-Bot you are able to send these commands without logging on to the remote computer.

Examples for such admin actions could be:

The action on the TeleFrame can be triggered by sending the corresponding command (e.g. /reboot for the command named "reboot") to the Bot.

[//ToDo: Irgendjemand muss meine Änderungen in der ReadMe-File in schönes Englisch übersetzen...]

LukeSkywalker92 commented 4 years ago

Great idea. Would it make sense to add a "wildcard" command. So that you can execute everything you like? It would also be nice if we could create a dialog for the commands (like when you edit your apps in the chat with BotFather). So if you type for example /commands you get a list of all commands and you just need to click on the command you like to execute. If you click "custom" you are asked to enter the bash command you like to execute. ...thinking this idea further it would also be great to edit the config of the TeleFram via a dialog in telegram 😄 ...so many ideas...

LukeSkywalker92 commented 4 years ago

BTW: Should the bot answer with the stdout of the command?

LuHKae commented 4 years ago

I think the inline-keyboard would be a great idea.

I'm not a fan of the wildcard-command. I think it is better for security reasons if only prepared Commands are allowed.

The config-edit via dialog is a great idea, that I already had. I think this should be an one issue.

I've been thinking about the stdout / stderror thing as well. Since there are many commands (reboot, ..) which have no output, I omitted it.

LukeSkywalker92 commented 4 years ago

Agreed on the wildcard command. But some kind of confirmation that the command was executed successfully would be nice.

LuHKae commented 4 years ago

I've added sending stdOut / stdErr to User

LukeSkywalker92 commented 4 years ago

Please have a look at #46. I added a module for executing system commands. I think you should also use this for your PR. After that we can merge it.

LuHKae commented 4 years ago

I would wait for the merge of PR #46 to avoid merge conflict. Can you tell me the current state of PR #46?

LukeSkywalker92 commented 4 years ago

We are working on it.. I first want to merge #52 in #46. But there are still some issues. I hope we will fix everything soon.

LukeSkywalker92 commented 4 years ago

46 is merged to develop

LuHKae commented 4 years ago

I'm afraid I ran into a problem that I can't solve by my one. I want to send an ipc-event from bot.js (main-process) to the system-command (main-process as well). Calling it from the rander-process works without problems. My solution now would be to send an event to the rander-process, which then executes the ipc-call to the system-command. In my eyes this is not a real solution. Does anyone have a better idea or can tell me what I'm doing wrong?

gegu commented 4 years ago

I'm currently not too familiar with the electron ipc. But it may be that an event object is required

this.emitter.send("executeSystemCommand", event, "sudo 123");

edit:

To be more specific, because:

systemCommands.js

  init() {
    this.ipcMain.on('executeSystemCommand', (event, command) => {
      this.executeSystemCommand(command)
    })
  }
LuHKae commented 4 years ago

My PR is now using the new config, but the old command execution.

I think this PR is now mergeable and we should improve this solution (like exec module) in future PRs.