Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sysnc master to dev #12

Merged
merged 21 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Generate release-artifacts

on:
workflow_dispatch:
release:
types:
- created

jobs:
releases-matrix:
name: Release Matrix
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux]
goarch: [amd64, arm64]
steps:
- uses: actions/checkout@v3
- uses: wangyoucao577/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
pre_command: apt-get install gcc && export CGO_ENABLED=1
goversion: "https://dl.google.com/go/go1.18.linux-amd64.tar.gz"
project_path: "./cmd"
binary_name: "teleterm"
extra_files: LICENSE README.md
195 changes: 145 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,162 @@
# teleterm
# Teleterm
Telegram Bot Exec Terminal Command

# !imoportant ⚠️
- we found some issue from gituhub issue and youtube comment
- we just starting refactoring to make teleterm as cli app version
- planning :
- wrap as cli applicaton
- release distribution cross platform
- elease distribution for arm and raspbery pi
- enhance interaction bot using button
- create button and bot command from cli or bot

[![codecov](https://codecov.io/gh/alfiankan/teleterm/branch/main/graph/badge.svg?token=ZQ4Z1ZU4EM)](https://codecov.io/gh/alfiankan/teleterm)
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)

>you can exec command from your telegram

# Demo
<img src="demoo.gif"/>
<br>
![teleterm2-demo](https://user-images.githubusercontent.com/40946917/178386328-3795dc02-b30a-437a-a46b-20db141601d5.gif)

Video Demo & Tutorial : https://www.youtube.com/watch?v=AJOPngS-BsE

<br>
# Use Case
- Controll Docker CLI
- Control IoT Devices
- Etc

# Tested On
- [x] ubuntu 20.04
- [x] Mac OS 15
## Use Case
- Running command on IoT Device through telegram bot
- Transfering Files through telegram bot

## How To Install

# How To use
- install `go get github.com/alfiankan/teleterm/teleterm`
- see following example code
1. Prebuilt Binary
you can download prebuild binary, available prebuilts :

```go
package main
|os | arch |available |
| ------------- | ------------- |:-------------:|
| linux | amd64 | [Download v2.0.0](https://github.com/alfiankan/teleterm/releases/download/v2.0.0/teleterm-linux-amd54.zip) |
| linux | arm64 | [Download v2.0.0](https://github.com/alfiankan/teleterm/releases/download/v2.0.0/teleterm-linux-arm64.zip) |
| macos | amd64 | [Download v2.0.0](https://github.com/alfiankan/teleterm/releases/download/v2.0.0/teleterm-mac-amd64.zip) |

import "github.com/alfiankan/teleterm/teleterm"
Once the binary is downloaded, you can move the binary to /usr/local/bin

func main() {
teleterm.StartBot("your telegram bot token")
}
2. Build From Source
If your arch os is not listed in the prebuilt binary you can build from source.

Required :
- Go ^1.18
- gcc

```
How to build :
- clone `git clone https://github.com/alfiankan/teleterm`
- build `go build -o teleterm-bin ./cmd...`

## How To Run :
Required :
- Telegram bot tokens, to get tokens please refer to [Telegram Docs](https://core.telegram.org/bots#6-botfather)

1. Setting Up Config

To setup fresh teleterm run

```bash
teleterm fresh
```

![Teleterm Fresh Configure](docs/teleterm-running.png)

teleterm will create folder on your home folder with name `.telegram` contains :
- config.yaml
config yaml hold teleterm config :

| Key |Value |
| ------------- |-------------|
| telegram_token | telegram token from bot father |
| shell_executor | `/bin/bash` or `/bin/sh` .etc default is `/bin/bash`|

example config.yaml
```yaml
teleterm:
telegram_token: "my_tele_token"
shell_executor: "/bin/bash"
```

2. Run teleterm

To run teleterm simply run `teleterm` and log info will displayed.

![Teleterm Running](docs/teleterm-running-on.png)

# Available Bot Command



## Available Bot Command
| Command |Desc |
| ------------- |:-------------:|
|/lock `<true/false>`|Lock/unlock acces to account
| /cmd `<terminal command>` | exec terminal command and directly get log
| /cmdf `<terminal command>` | exec terminal command then save log to file
|/get `<file path>`| Download File From server/host
|send File|When you send File directly saved to server or host

# Version History
v1.0
- read telegram token from .env file
- exec command and directly get response log
- exec command then save log to file
- telegram user can receive log text
- sending/uploading file [Document(not included > image, video, and audio)] to server/host device
- Downloading File from server/host device
| ------------- |:-------------|
|/refresh |Refresh the bot system
| /run `<command>`| executing command
| /getfile `<filepath>`| transfer donwload file from bot server
|/addbutton `<button_name>!!<command>`| add button shortcut
|/deletebutton `<button_name>`|delete button shortcut


## Run Command
To run command from telegram simply send message using following format :
```bash
/run <command>
```
for example :
```bash
/run ping -c 5 8.8.8.8
```
output replied by telegram bot :

![Run command](docs/teleterm-run-cmd.png)

## Add Button Shortcut
To run command from telegram button you need to add buttons simply send message using following format:
```bash
/addbutton <button_name>!!<command>
```
for example :
```bash
/addbutton ping!!ping -c 5 8.8.8.8
```
output replied by telegram bot :

![Add Button](docs/teleterm-addbutton.png)

then new button will appeared :

![Show Buttons](docs/teleterm-buttons.png)

## Shortcut Button
To run command using shortcut simply click the button telegram bot will find the exec command from database.

## Delete Button Shortcut
To delete shortcut button simply send message using following format:
```bash
/deletebutton <button_name>
```
for example :
```bash
/deletebutton ping
```
output replied by telegram bot :

![Delete Button](docs/teleterm-deletebutton.png)

then updated button will appeared.

## Uploading File
To upload file simply send document on telegram:

![Upload File](docs/teleterm-upload.png)

By default will upload on cwd path if you not add target path on file mention.

output replied by telegram bot :

![Upload Success](docs/teleterm-upload-success.png)

## Download file
To donwload file simply send message using following format:
```bash
/getfile <filepath>
```

Filepath is filepath on where teleterm running on

for example :
```bash
/getfile /home/raspi/hello.txt
```
output replied by telegram bot :

![Downloaded File](docs/teleterm-downloadfile.png)
Binary file added docs/teleterm-addbutton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/teleterm-buttons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/teleterm-deletebutton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/teleterm-downloadfile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/teleterm-run-cmd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/teleterm-running-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/teleterm-running.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/teleterm-upload-success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/teleterm-upload.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion tmp/build-errors.log

This file was deleted.

Binary file removed tmp/main
Binary file not shown.