app.py 947 B

123456789101112131415161718192021222324252627282930313233
  1. # -*- coding: UTF-8 -*-
  2. from flask import Flask, redirect, request
  3. from execUtil import get_client, run_cmd
  4. app = Flask(__name__, static_url_path="")
  5. @app.route("/", methods=['get'])
  6. def hello():
  7. print(request.json) # json参数
  8. return redirect("/index.html")
  9. @app.route("/exec", methods=['post'])
  10. def exe_str_cmd():
  11. """执行cmd"""
  12. try:
  13. req_json = request.json
  14. client = get_client(req_json)
  15. # 转换执行字符串
  16. exec_str = "&&".join(list(filter(lambda x: not str.startswith(x, "#"),
  17. (req_json.get('exec_str_before') + '\n' + req_json.get(
  18. 'exec_str')).splitlines())))
  19. result_str = run_cmd(client, exec_str)
  20. client.close()
  21. return result_str
  22. # return "OK"
  23. except Exception as e:
  24. return str(e)
  25. if __name__ == '__main__':
  26. app.run(host='0.0.0.0', port=5000)