Created
April 13, 2012 04:59
-
-
Save jyio/2373824 to your computer and use it in GitHub Desktop.
demonstration of bottle.py + subprocess
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | |
<html> | |
<head> | |
<title>SCP</title> | |
<meta name="generator" content="Bluefish 2.0.1" > | |
<meta name="author" content="adam" > | |
<meta name="date" content="2011-01-15T09:39:02-0600" > | |
<meta name="copyright" content=""> | |
<meta name="keywords" content=""> | |
<meta name="description" content="Santa Clause Web Interface"> | |
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW"> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<meta http-equiv="content-style-type" content="text/css"> | |
<meta http-equiv="expires" content="0"> | |
</head> | |
<body> | |
<p> | |
</p> | |
<h1 style="text-align: left;">Welcome to Santa Control</h1> | |
<div style="text-align: center;"> | |
<div style="position: absolute; left: 182px; top: 94px;"><br> | |
</div> | |
<div | |
style="position: absolute; left: 91px; top: 77px; width: 92px; height: 50px;"> | |
<form action="/cgi-bin/SantaLogin.cgi" method="get"> <input | |
name="device" value="/dev/ttyUSB0" type="hidden"> <input value="Login" | |
type="submit"> </form> | |
</div> | |
<object data="/santa.jpg" type="image/jpg"></object> | |
<div style="position: absolute; left: 11px; top: 163px; height: 106px;"> | |
<form action="/cgi-bin/cmd.sh" method="get"> <input name="device" | |
value="/dev/ttyUSB0" type="hidden"> <input class="bginput" | |
value="walk" name="command" type="submit"> | |
<input alt="56456356" value="stop" name="command" | |
type="submit"> <input | |
value="fire" name="command" type="submit"> <br> | |
<br> | |
<br> | |
<br> | |
<input value="logoff" name="command" type="submit"> <br> | |
<br> | |
<br> | |
<input class="bginput" | |
value="rampage" name="command" type="submit"> | |
</form> | |
</div> | |
</div> | |
<pre><!--#include virtual="/cgi-bin/cgi.cgi" --></pre> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/botbrew/bin/python | |
import subprocess | |
from bottle import route, run, request, response, static_file | |
@route('/') | |
def index(): | |
return static_file('index.html',root='./static') | |
@route('/cgi-bin/SantaLogin.cgi') | |
def santa_login(): | |
device = request.query.device | |
print '\tlogin > '+device | |
with open(device,'w') as f: | |
f.write('Santa\rHo\r') | |
with open('./static/index.html','r') as f: | |
response.content_type = 'text/html' | |
return f.read()+'\nlogged in to '+device | |
@route('/cgi-bin/cmd.sh') | |
def santa_command(): | |
device = request.query.device | |
command = request.query.command | |
print '\t'+command+' > '+device | |
with open(device,'w') as f: | |
f.write(command+'\r') | |
with open('./static/index.html','r') as f: | |
response.content_type = 'text/html' | |
return f.read()+'\n'+command+'ing command sent to '+device | |
@route('/uptime') | |
def run_uptime(): | |
return '<pre>%s</pre>'%subprocess.Popen(["busybox","uptime"],stdout=subprocess.PIPE).communicate()[0] | |
@route('/ps') | |
def run_ps(): | |
return '<pre>%s</pre>'%subprocess.Popen(["ps"],stdout=subprocess.PIPE).communicate()[0] | |
@route('/<filepath:path>') | |
def static(filepath): | |
return static_file(filepath,root='./static') | |
run(host='0.0.0.0',port=8080) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment