GithubHelp home page GithubHelp logo

slackbot-os-command-injection's Introduction

Build Status Coverage Status

slackbot-os-command-injection

コマンドを投げると実行してその結果を返してくれるbotです
https://qiita.com/odanado/items/fb5a5e996b302d4b4ca4

必要なもの

  • Docker
  • docker-compose

前準備

ビルド

docker-compose build base
docker-compose build

環境変数

.env ファイルを作って,そこに SLACK_TOKE を書いて下さい

cat .env
SLACK_TOKEN=xoxb-11111111111-xxxxxxxxxxxxxxxxxxxxxxxx

起動方法

docker-compose up -d bot

言語を追加するには

langs/ 以下に言語名でディレクトリ作って,その中に Dockerfileconfig.yml を書いて下さい
そして docker-compose.yml を編集してください   できればテストもあると嬉しいです

slackbot-os-command-injection's People

Contributors

eliza0x avatar keyakko avatar odanado avatar xztaityozx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

slackbot-os-command-injection's Issues

プロセス数の制限

"--ulimit nproc=10:10"はコンテナを動かしているユーザー単位でのプロセス数制限であるため,コンテナ単位でプロセス数を制限できる"--pids-limit"オプションに変更するべき

Dockerコマンドに渡すオプションの変更

現在Dockerに渡すオプションについては特に何も考えず設定した値を使っている.
#10 にあるように,このままでは不備がある.メモリやCPUの割り当てについて今一度考え直したい

コンパイルオプションについて

今のところpythonの辞書型によってコンパイルオプションを指定しているが,yaml形式などのテキストファイルとして定義し,それを読み込む形式のほうがtravis ciと類似するため,わかりやすいのではないか

botから返答が帰ってこない

現在init_loggerで生成されるlogファイルは,pythonのソースコードがあるディレクトリ以下のlogs/に保存される仕様となっている
ただ,初期状態ではlogs/ディレクトリが存在しないため,エラーでcode_runner.pyを実行できなくなっている
logs/ディレクトリを作るか,/logsディレクトリに保存先を変更するべき

ホスト名の変更

ホスト名がランダムで毎回変化するより,毎回同じであるべきだと思うのでそう変更するべき
docker run--hostnameオプションで指定できる

機能改善

  • ファイルサイズの上限を上げる
  • コンパイル時間と実行時間を別に計算する
  • CodeRunnerが実行時間の上限を決める
  • コンパイルエラーも表示する

プロセス数の上限について

現状ではconstant.pyでStartArgs['--pids-limit'] = '5'と上限は5に決めているが,この状態でbotを実行すると

bash: fork: retry: Resource temporarily unavailable
bash: fork: retry: No child processes

Session terminated, terminating shell... ...terminated.

とfork出来ずエラーが返ってくる
プロセス数の上限を10にした方が良い

クラスDockerのインタフェースについて

今のところ,/tmp/workspaceにソースコードが存在する仮定の元で,言語の種類を受け取りその結果を返す仕様になっている
しかし,言語とソースコードを受け取ってその実行結果を返すようにするのが自然ではないか

日本語が表示されない

bash以外の言語で日本語を表示しようとすると文字化けするか,文字コードエラーで落ちる
恐らく locale -a にja_jp.utf-8がないせい?

PRの敷居を下げる

現状PRを投げるには

  • Docker
  • docker-compose
  • python

の知識が求められる
これのせいでPR投げる難易度が増しているのでなんとかしたい.特にpythonを知らなくてもいいようにしたい

pythonのテストとdocker-compose.ymlは自動生成するようにしたい

Dockerというクラス名について

クラスDockerはDockerコマンドのwrapperであることは確かだが,このプロジェクトにおける役割は与えられたプログラミング言語のソースコードを実行することであるため,CodeRunner,CommandRunnerあたりが名前として適切ではないか

UnicodeEncodeError in python3

メンション

@os-command-injection python
print('あ')

結果

言語: python
実行時間: 0.02
標準エラー出力:
Traceback (most recent call last):
File "Main.py", line 1, in <module>
print('\u3042')
UnicodeEncodeError: 'ascii' codec can't encode character '\u3042' in position 0: ordinal not in range(128)

メッセージの変更

slackのrtm APIではメッセージが変更された時にもmessageイベントが飛んできて次のような形式になる.

{'channel': 'C2TMAR8UT',
 'event_ts': '1477985840.420796',
 'hidden': True,
 'message': {'edited': {'ts': '1477985840.000000', 'user': 'U14STMS95'},
             'text': '<@U2TPBRFK5>\nls -l',
             'ts': '1477985818.000023',
             'type': 'message',
             'user': 'U14STMS95'},
 'previous_message': {'text': '<@U2TPBRFK5>\nhostname',
                      'ts': '1477985818.000023',
                      'type': 'message',
                      'user': 'U14STMS95'},
 'subtype': 'message_changed',
 'ts': '1477985840.000025',
 'type': 'message'}

この時data['text']で,ユーザーの発言にアクセスしようとしてもキーが存在せずKeyError: 'text'が吐かれる.
修正されたメッセージに対しては何もしないように,プログラムを変更するべき

実行結果での言語表示

メンション

@os-command-injection cc
int main(){}

実行結果

言語: cc
実行時間: 0.32

現状,上記のようにユーザーが指定した言語がそのまま実行結果に使われている.aliasを指定された場合は,ちゃんと変換するべき

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.