-
Notifications
You must be signed in to change notification settings - Fork 22
/
shell2telegram.1
302 lines (287 loc) · 7.28 KB
/
shell2telegram.1
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "SHELL2TELEGRAM" "" "January 2022" "" ""
.
.SH "NAME"
\fBshell2telegram\fR
.
.SH "shell2telegram"
Create Telegram bot from command\-line
.
.SH "Install"
MacOS:
.
.IP "" 4
.
.nf
brew tap msoap/tools
brew install shell2telegram
# update:
brew upgrade shell2telegram
.
.fi
.
.IP "" 0
.
.P
Or download binaries from: releases \fIhttps://github\.com/msoap/shell2telegram/releases\fR (OS X/Linux/Windows/RaspberryPi)
.
.P
Or build from source:
.
.IP "" 4
.
.nf
# set $GOPATH if needed
go install github\.com/msoap/shell2telegram@latest
ln \-s $GOPATH/bin/shell2telegram ~/bin/shell2telegram # or add $GOPATH/bin to $PATH
.
.fi
.
.IP "" 0
.
.P
Or build image and run with Docker\. Example of \fBtest\-bot\.Dockerfile\fR for bot who say current date:
.
.IP "" 4
.
.nf
FROM msoap/shell2telegram
# may be install some alpine packages:
# RUN apk add \-\-no\-cache \.\.\.
ENV TB_TOKEN=*******
CMD ["/date", "date"]
.
.fi
.
.IP "" 0
.
.P
And build and run:
.
.IP "" 4
.
.nf
docker build \-f test\-bot\.Dockerfile \-t test\-bot \.
docker run \-\-rm test\-bot
# or run with set token from command line
docker run \-e TB_TOKEN=******* \-\-rm test\-bot
.
.fi
.
.IP "" 0
.
.P
Using snap (Ubuntu or any Linux distribution with snap):
.
.IP "" 4
.
.nf
# install stable version:
sudo snap install shell2telegram
# install the latest version:
sudo snap install \-\-edge shell2telegram
# update
sudo snap refresh shell2telegram
.
.fi
.
.IP "" 0
.
.P
Notice: the snap\-package has its own sandbox with the \fB/bin\fR, \fB/usr/bin\fR directories which are not equal to system\-wide \fBPATH\fR directories\.
.
.SH "Usage"
Get token from BotFather bot \fIhttps://telegram\.me/BotFather\fR, and set TB_TOKEN var in shell
.
.IP "" 4
.
.nf
export TB_TOKEN=*******
shell2telegram [options] /chat_command \'shell command\' /chat_command2 \'shell command2\'
options:
\-allow\-users=<NAMES> : telegram users who are allowed to chat with the bot ("user1,user2")
\-root\-users=<NAMES> : telegram users, who confirms new users in their private chat ("user1,user2")
\-allow\-all : allow all users (DANGEROUS!)
\-add\-exit : adding "/shell2telegram exit" command for terminate bot (for roots only)
\-log\-commands : logging all commands
\-tb\-token=<TOKEN> : setting bot token (or set TB_TOKEN variable)
\-timeout=N : setting timeout for bot (default 60 sec)
\-description=<TITLE> : setting description of bot
\-bind\-addr=<ADDRESS> : address to listen incoming webhook requests
\-webhook=<URL> : url for registering a webhook
\-persistent\-users : load/save users from file (default ~/\.config/shell2telegram\.json)
\-users\-db=<FILENAME> : file for store users
\-cache=N : caching command out for N seconds
\-one\-thread : run each shell command in one thread
\-public : bot is public (don\'t add /auth* commands)
\-sh\-timeout=N : set timeout for execute shell command (in seconds)
\-shell="shell" : shell for execute command, "" \- without shell (default "sh")
\-version
\-help
.
.fi
.
.IP "" 0
.
.P
If not define \-allow\-users/\-root\-users options \- authorize users via secret code from console or via chat with exists root users\.
.
.P
All text after /chat_command will be sent to STDIN of shell command\.
.
.SH "Special chat commands"
for private chats only:
.
.IP "\(bu" 4
\fB/:plain_text\fR \- get user message without any /command\.
.
.IP "" 0
.
.P
TODO:
.
.IP "\(bu" 4
\fB/:image\fR \- for get image from user\. Example: \fB/:image \'cat > file\.jpg; echo ok\'\fR
.
.IP "\(bu" 4
\fB/:file\fR \- for get file from user
.
.IP "\(bu" 4
\fB/:location\fR \- for get geo\-location from user
.
.IP "" 0
.
.P
Possible long\-running shell processes (for example alarm/timer bot)\.
.
.P
Autodetect images (png/jpg/gif/bmp) out from shell command, for example: \fB/get_image \'cat file\.png\'\fR
.
.P
Setting environment variables for shell commands:
.
.IP "\(bu" 4
S2T_LOGIN \- telegram @login (may be empty)
.
.IP "\(bu" 4
S2T_USERID \- telegram user ID
.
.IP "\(bu" 4
S2T_USERNAME \- telegram user name
.
.IP "\(bu" 4
S2T_CHATID \- chat ID
.
.IP "" 0
.
.SH "Modificators for bot commands"
.
.IP "\(bu" 4
\fB:desc\fR \- setting the description of command, \fB/cmd:desc="Command name" \'shell cmd\'\fR
.
.IP "\(bu" 4
\fB:vars\fR \- to create environment variables instead of text output to STDIN, \fB/cmd:vars=VAR1,VAR2 \'echo $VAR1 / $VAR2\'\fR
.
.IP "\(bu" 4
\fB:md\fR \- to send message as markdown text, \fB/cmd:md \'echo "*bold* and _italic_"\'\fR
.
.IP "" 0
.
.P
TODO:
.
.IP "\(bu" 4
\fB/cmd:cron=3600\fR — periodic exec command, \fB/cmd:on args\fR \- on, \fB/cmd:off\fR \- off
.
.IP "" 0
.
.SH "Predefined bot commands"
.
.IP "\(bu" 4
\fB/help\fR \- list available commands
.
.IP "\(bu" 4
\fB/auth\fR \- begin authorize new user
.
.IP "\(bu" 4
\fB/auth <CODE>\fR \- authorize with code from console or from exists root user
.
.IP "\(bu" 4
\fB/authroot\fR \- same for new root user
.
.IP "\(bu" 4
\fB/authroot <CODE>\fR \- same for new root user
.
.IP "" 0
.
.P
for root users only:
.
.IP "\(bu" 4
\fB/shell2telegram stat\fR \- show users statistics
.
.IP "\(bu" 4
\fB/shell2telegram search <query>\fR \- search users by name/id
.
.IP "\(bu" 4
\fB/shell2telegram ban <user_id|@username>\fR \- ban user
.
.IP "\(bu" 4
\fB/shell2telegram exit\fR \- terminate bot (for run with \-add\-exit)
.
.IP "\(bu" 4
\fB/shell2telegram desc <description>\fR \- set bot description
.
.IP "\(bu" 4
\fB/shell2telegram rm </command>\fR \- delete command
.
.IP "\(bu" 4
\fB/shell2telegram broadcast_to_root <message>\fR \- send message to all root users in private chat
.
.IP "\(bu" 4
\fB/shell2telegram message_to_user <user_id|@username> <message>\fR \- send message to user in private chat
.
.IP "\(bu" 4
\fB/shell2telegram version\fR \- show version
.
.IP "" 0
.
.SH "Examples"
.
.nf
# system information
shell2telegram /top:desc="System information" \'top \-l 1 | head \-10\' /date \'date\' /ps \'ps aux \-m | head \-20\'
# sort any input
shell2telegram /:plain_text sort
# alarm bot:
# /alarm time_in_seconds message
shell2telegram /alarm:vars=SLEEP,MSG \'sleep $SLEEP; echo Hello $S2T_USERNAME; echo Alarm: $MSG\'
# sound volume control via telegram (Mac OS)
shell2telegram /get \'osascript \-e "output volume of (get volume settings)"\' \e
/up \'osascript \-e "set volume output volume (($(osascript \-e "output volume of (get volume settings)")+10))"\' \e
/down \'osascript \-e "set volume output volume (($(osascript \-e "output volume of (get volume settings)")\-10))"\'
# using with webhook instead of poll
shell2telegram \-bind\-addr=0\.0\.0\.0:8080 \-webhook=https://bot\.example\.com/path/to/bot \e
/date /date
# command with Markdown formating, calendar in monospace font
shell2telegram /cal:md \'echo "\e`\e`\e`$(ncal)\e`\e`\e`"\'
.
.fi
.
.SH "Links"
.
.IP "\(bu" 4
Telegram channel about shell2telegram \fIhttps://telegram\.me/shell2telegram\fR
.
.IP "\(bu" 4
About Telegram bots \fIhttps://core\.telegram\.org/bots\fR
.
.IP "\(bu" 4
Golang bindings for the Telegram Bot API \fIhttps://github\.com/go\-telegram\-bot\-api/telegram\-bot\-api\fR
.
.IP "\(bu" 4
shell2http \- shell commands as http\-server \fIhttps://github\.com/msoap/shell2http\fR
.
.IP "" 0