123456789101112131415161718192021222324252627282930313233 |
- # -*- coding: UTF-8 -*-
- from flask import Flask, redirect, request
- from execUtil import get_client, run_cmd
- app = Flask(__name__, static_url_path="")
- @app.route("/", methods=['get'])
- def hello():
- print(request.json) # json参数
- return redirect("/index.html")
- @app.route("/exec", methods=['post'])
- def exe_str_cmd():
- """执行cmd"""
- try:
- req_json = request.json
- client = get_client(req_json)
- # 转换执行字符串
- exec_str = "&&".join(list(filter(lambda x: not str.startswith(x, "#"),
- (req_json.get('exec_str_before') + '\n' + req_json.get(
- 'exec_str')).splitlines())))
- result_str = run_cmd(client, exec_str)
- client.close()
- return result_str
- # return "OK"
- except Exception as e:
- return str(e)
- if __name__ == '__main__':
- app.run(host='0.0.0.0', port=5000)
|