-
Notifications
You must be signed in to change notification settings - Fork 1
/
webshell.py
executable file
·43 lines (36 loc) · 1.48 KB
/
webshell.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python -u
from sys import stdout
from collections import OrderedDict
import subprocess
# The following dict defines the allowed commands which should be available
# through webshell. This is also a security feature as it only executes
# commands which are in this dict
ALLOWED_COMMANDS = OrderedDict([
["du -sch ~/Downloads/*", "du -sch ~/Downloads/*"],
["du -sch ~/dirty/*", "du -sch ~/dirty/*"],
["series", "~/bin/series"],
["tree ~/Queue/", "tree -l ~/dlna/Queue*"],
["rm ~/Downloads/*", "rm ~/Downloads/*"],
["killall junkie", "killall junkie"],
["remove_watched_episodes", "~/projects/Scripts/remove_watched_episodes.sh"],
["restart minidlna", "sudo service minidlna restart"],
["tv on/off", "irsend SEND_ONCE lg KEY_POWER"],
["tv prog+", "irsend SEND_ONCE lg KEY_CHANNELUP"],
["tv prog-", "irsend SEND_ONCE lg KEY_CHANNELDOWN"],
["sound on/off", "irsend SEND_ONCE logitech POWER"],
["sound vol+", "irsend SEND_ONCE logitech VOL_PLUS"],
["sound vol-", "irsend SEND_ONCE logitech VOL_MINUS"],
])
# send the allowed commands to th shell
for cmd in ALLOWED_COMMANDS.keys():
print "COMMAND###%s\n" % cmd
stdout.flush()
while True:
cmd = raw_input()
if cmd in ALLOWED_COMMANDS:
try:
print subprocess.check_output(ALLOWED_COMMANDS[cmd], shell=True)
print "[program exited]"
except Exception, e:
print "ERROR: %s" % e
stdout.flush()