Giter Site home page Giter Site logo

smarthome-go / commander Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 23 KB

Microservice for executing shell commands via API requests

License: GNU General Public License v2.0

Rust 93.10% Makefile 6.90%
linux remote-execution remote-shell shell smarthome-api

commander's Introduction

Commander

Microservice for executing commands via API requests

Introduction

Commander acts like a scripting interface to any Linux computer. The service is able to receive commands via its built-in API server in order to execute them. The main purpose of this software is to be used alongside Smarthome-server in order to allow Homescript to control remote computers.

Warning: Even though access requires a token, running commander comes at your own risk because it opens up a potent entrance for possible attackers to use.

API Usage

To execute an arbitrary command, issue a POST request using following parameters.

Key Value
Method POST
URL http://ip/exec
Header1 Token: your_token
Header2 Content-Type: application/json
Body { command: "ls"} (as JSON)

Usage from Smarthome via Homescript

Note: This example uses Smarthome-server v0.0.47 (which uses Homescript v0.15.1).

To test this code, execute your_id using the command argument with your command as its value.

# Calling `your_id` from outside
exec(
    'your_id',
    pair('command', "ls")
)

# This is the beginning of `your_id`
http(
    'http://computer.box/exec',
    'POST',
    concat('{', '"command":"', getArg('command'), '"}'),
    pair('Content-Type', 'application/json'),
    pair('Token', 'test'),
)

Installation

Manual installation

Cloning

git clone [email protected]:smarthome-go/commander
cd commander

Installation

make install

Installing a Systemd Service (Optional)

sudo cp [email protected] /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl start commander@$USER
Additional configuration

Note: Modifying the .service file is not recommended (except for environment variables)

When using Systemd, the service is configured using environment variables. The most important configuration parameters are explained below.

Parameter Explanation
ROCKET_PORT The port on which commander listens on
COMMANDER_TOKEN Unencrypted user authentication token

Representation in the .service file (which is located at /etc/systemd/system/[email protected])

# Environment variables for the service
Environment=ROCKET_PORT=7070
Environment=COMMANDER_TOKEN=test

In some cases, you might want to start applications with a GUI or which depend on audio. On those occasions, the command might fail due to missing environment variables. You can feel free to include the missing variables under the # Put user environment variables here marker. When you don't want to take on the hassle of figuring our which missing environment variable is causing the issue, you can inclue all your current variables in the file. The command for listing your environment variables on Unix is env. But don't forget to run sudo systemctl daemon-reload after writing modifications to the service file.

Note: It is not recommended to include all of your environment variables in the service file.

Arch Linux

If using Arch Linux, the most convenient way of installing commander is via the AUR (Arch Linux User Repository). For this, an AUR helper like paru or yay is used.

Note: This method automatically installs a Systemd service, however it is not enabled by default.

paru -S commander

commander's People

Contributors

mikmuellerdev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.