GithubHelp home page GithubHelp logo

uncelvel / telesys Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nhanhoadocs/telesys

0.0 1.0 0.0 2.9 MB

Bot Telegram cho phép thực hiện các thao tác start/stop/restart service trên Server

Shell 0.68% Python 99.32%

telesys's Introduction

Tools cho phép tạo mới 1 bot Telelegram có thể thực hiện các lệnh Start, Stop, Restart các Service trên Server Linux

Tính năng

  • Cho phép restart, stop, start service đang running trên Server
  • Limit danh sách user có thể thao tác
  • Thao tác check và thao tác với service loại bỏ các Inject command bash () { :; }; || ... Ex:systemctl status httpd||{echo,'abc'}
  • Advance: Có thể thực hiện các câu lệnh của linux khi tương tác với telegram_bot

Cách sử dụng

1. Create và lấy API bot

  • Chat với @BotFather để lấy token

    /start
    /newbot
    {your_bot_name}
    {your_bot_name}_bot

  • Lấy ID của user thao tác với bot (Nhằm xác thực)

    • Truy cập đường dẫn

      https://api.telegram.org/bot{TOKEN}/getUpdates
    • Thực hiện thao tác chat với bot để lấy id user

Sau khi lấy được Token và User_id thì tiến hành cài đặt bot

2. Cài đặt môi trường

Yêu cầu python3.6 và chạy với venv (Phía dưới là hướng dẫn chạy trên CentOS7)

Cài đặt python3.6

  • Thêm Repo

    sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm
  • Update để cập nhật repo mới

    sudo yum update
  • Download và cài đặt python36

    sudo yum install -y python36u python36u-libs python36u-devel python36u-pip

Cài đặt Virtual Environment

  • Cài đặt pip

    yum install wget -y
    wget https://bootstrap.pypa.io/get-pip.py
    sudo python3.6 get-pip.py
  • Cài đặt venv

    sudo pip3.6 install virtualenv
  • Tạo môi trường riêng cho ứng dụng

    mkdir Project
    cd Project
    virtualenv venv -p python3.6
    source venv/bin/activate

3. Download sourcode và cài đặt requirement

  • Clone bot về source về

    yum install git -y
    git clone http://github.com/nhanhoadocs/telesys.git 
  • Cài đặt requirement packet

    cd telesys
    pip install -r requirement.txt
  • Cấu hình cho trong file setting.ini

    TOKEN = {token của bot}
    # Cho phep thuc hien stop/start/restart
    chat_id_normal = {userid1},{userid2}
    # Cho phep thuc hien chay command dac biet
    chat_id_special = {userid2},{userid3}

4. Cài đặt Supervisor để quản lý bot, giữ bot luôn hoạt động

  • Cài đặt

    yum install supervisor -y 
  • Cấu hình Supervisord

    cat << EOF >> /etc/supervisord.d/telebot.ini
    [program:telebot]
    command = /root/Project/venv/bin/python /root/Project/telesys/telebot.py
    autostart=true
    autorestart=true
    startrereies=5
    stderr_logfile=/var/log/supervisor/telebot.log
    stdout_logfile=/var/log/supervisor/telebot.err.log
    EOF
  • Start Supervisord để khởi chạy bot

    systemctl start supervisord
  • Kiểm tra bot running

    supervisorctl

    Kết quả như sau là bot đang running

    [root@localhost ~]# supervisorctl
    telebot                          RUNNING   pid 25840, uptime 0:00:06
    supervisor>
  • Chúng ta có thể thao tác stop/start bot như sau

    supervisor> stop telebot
    telebot: stopped
    supervisor> status telebot
    telebot                          STOPPED   Jan 19 11:29 AM
    supervisor> start telebot
    telebot: started
    supervisor> status
    telebot                          RUNNING   pid 25850, uptime 0:00:11
    supervisor> exit
  • Để kiểm tra bot running tiến hành thao tác với bot

Hoàn tất

telesys's People

Contributors

uncelvel avatar

Watchers

James Cloos 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.