Code Monkey home page Code Monkey logo

cmd2browser's Introduction

cmd2browser

Execute system commands and display outputs to a browser

A python application that can be modified to execute system commands and then display the outputs to a Web browser.

github stats

Install Prerequisites

Install Python (v3) and PIP:

  1. Visit https://linuxize.com/post/how-to-install-python-3-7-on-ubuntu-18-04/ to learn how to install Python
  2. Visit https://www.shellhacks.com/python-install-pip-mac-ubuntu-centos/ to learn how to install PIP
  3. Run the following commands to install Python flask and PYyaml modules:
  pip install flask
  pip install PYyaml

Install and Launch the App

  1. Download the code
   git clone https://github.com/paulmchen/cmd2browser.git
  1. Go to /cmd2browser folder and Launch the app
  python app.py

Verify

  1. Start a browser session and use the following URL to validate examples provided
  1. http://127.0.0.1:5000/ls/
  2. http://127.0.0.1:5000/docker_ps/

Tips

  • When you are connecting to the server from another client IP, you would need to add your client IP address to the white list in config/config.yaml. By default, the server will reject any non-local connections from any remote clients. Modify the following line by adding your client IP address to the white list of the server:
  ip_whitelist: '[''192.168.1.2'', ''192.168.1.3'', ''127.0.0.1'']'
  • To add a new command line call and then send its output to a web browser, you can create a new def function in app.py. For example, to call a system command "kubectl get pods", add the following 'def' to app.py:
  @app.route('/kc_pods/')
  def get_kc_pods():
      try:
          return command.run("kubectl get pods")
      except subprocess.CalledProcessError as e:
          return message.error_500_msg
  • To support a command that may not return results immediately, you can use exec_command_async function instead. exec_command_async takes 2 input parameters. The first parameter is the command that you want to run, for example, top, the 2nd parameter exec_time_in_seconds is the elapse time to indicate how long it needs to wait in seconds before the browser session should resume to fetch outputs and then terminate the process of the command. Note: ensure that you set a proper value of the exec_time_in_seconds to avoid from command process being terminated before it is completed.
  # Example: call async command, e.g. top
  @app.route('/top/')
  def get_top():
      try:
          return command.run_async("top", 2)
      except subprocess.CalledProcessError as e:
          return message.error_500_msg

Launch the following URL to verify your new command line execution from your favourite browser:

http://127.0.0.1:5000/kc_pods/

cmd2browser's People

Contributors

paulmchen avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

chenp02 lukeskity

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.