a telegram bot for remote controlling a server
it is the system-admins's assistant telegram bot!
this is a pretty straightforward guide for setting up your own babaee robot.
- clone this repository.
- copy
config.py.default
intoconfig.py
. - configure
config.py
. you can do it manually or you can use easy config - run robot with command
python3 babaee.py
.
- create a telegram bot and note the bot token. (here is how to do it)
- clone this repository on the server
git clone 'https://github.com/ekm507/babaee.git'
- copy
config.py.default
intoconfig.py
file.
cp config.py.default config.py
to configure the bot, you can use easy_config.py
script. just run it and it will tell you what to do.
there are two ways to run this robot.
- by a non-root user
- by root user.
when run by non-root user, commands will be run as your user.
when run by root user, you can define users for each person interacting with robot. you may also give users root access for running commands.
thus, the way you run the robot, you need to configure it differently.
edit config.py
file.
-
edit
robot_token
in
config.py
file set robot tokenrobot_token = "token you get from botfather"
-
edit
admins_chat_id_list
.add your
chat_id
(you can add several ones)as an example:
# chat id of admins admins_chat_id_list = [ 12121212, 13131313, # integer ]
-
edit
forward_chat_id_list
it is possible to send a log from users commands to a telegram user.
for example:
# a list of chat id. bot will forward all incoming messages to these users. forward_chat_id_list = [ 12121212, # integers ]
edit config.py
file.
-
edit
robot_token
in
config.py
file set robot tokenrobot_token = "token you get from botfather"
-
edit
admins_chat_id_list
.add your
chat_id
(you can add several ones)as an example:
# chat id of admins admins_chat_id_list = [ 12121212, 13131313, # integer ]
-
edit
chatd_users
dict.each chat_id must be assigned to a user on your machine.
as an example:
chatid_users = { 12121212:'erfan', 13131313:'funny-user' # integer:string }
-
edit
sudoers_chatid
listit is possible to give a user root access.
for example if you want to let user 12121212 be able ro run commands as root:"
sudoers_chatid = [ 12121212, #integer ]
-
edit
forward_chat_id_list
it is possible to send a log from users commands to a telegram user, for instance root user's telegram.
for example:
# a list of chat id. bot will forward all incoming messages to these users. forward_chat_id_list = [ 12121212, # integers ]
run the bot using python3
python3 babaee.py
to use the bot, simply type linux commands in it.
however there are some special commands you can use.
- /help : robot help
- /sh : run command in shell
- /sudo : run command as root in shell
- /send : send a file from server to telegram
- /receive : receive a file from telegram into server
- /edit : edit a file
- /ps : list of running processes
- /exec : execute a python command in robot
- show a list of running subprocesses with a killing ability. (temporary solution: linux ps command)
- make an interface for other apps to let them communicatie with admin via telegram.
- make better logs. (how should they be?)
- write a better help file
- make a cli for configuration
- split telegram interface from the main code into a different file. this way robot can be used for other platforms, also testing can be easier.