Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- apt-get install python3-pip net-tools nano cowsay
- pip3 install Flask==1.0.2
- cat << EOF > /opt/cowsay.py
- import sys
- import os.path
- import subprocess
- from flask import Flask
- from flask import request
- localport = 8000
- localhost = "0.0.0.0"
- app = Flask(__name__)
- #http://0.0.0.0:8000/?text=My%20Text
- @app.route("/", methods=['GET'])
- def root():
- myexec = "/usr/games/cowsay"
- mytext = request.args.get('text', default = "Hello World", type = str)
- try:
- process = subprocess.Popen([myexec, mytext], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
- myimg = process.communicate()[0]
- myimg = myimg.decode("utf-8")
- except:
- myimg = ""
- myhtml = "<pre>"+myimg.replace("\n", "</br>")+"</pre>"
- return myhtml
- if __name__ == "__main__":
- app.run(debug=True, host=localhost, port=localport)
- EOF
- chmod 755 /opt/cowsay.py
- cat << EOF > /lib/systemd/system/cowsay.service
- [Unit]
- Description=Simple webserver that prints Cowsay
- [Service]
- ExecStart=python3 /opt/cowsay.py
- StandardOutput=null
- #Uncomment:
- #User=cowsay
- #Group=users
- #if you want to run script as a different user than root
- [Install]
- WantedBy=multi-user.target
- Alias=cowsay.service
- EOF
- systemctl enable cowsay.service
- systemctl start cowsay.service
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement