def __init__(self,configfile=None):
self.configfile=configfile
self.config_parser=ConfigParser.ConfigParser()
+ #make option variable names case sensitive
+ self.config_parser.optionxform = str
self.config_parser.add_section('cmdlog')
self.config_parser.set('cmdlog','cmd',"logger %ARG%")
self.config_parser.set('cmdlog','timeout',"2.0")
self.config_parser.add_section('gladosreplaced')
self.config_parser.set('gladosreplaced','arg',"/home/glados_replaced_with_life_fire.mp3")
self.config_parser.set('gladosreplaced','type',"slugplaymp3")
+ self.config_parser.add_section('nothing')
+ self.config_parser.set('nothing','type',"nothing")
self.config_parser.add_section('mapping')
self.config_parser.set('mapping','default',"halflife2")
self.config_parser.set('mapping','panic',"monkeyscream")
self.config_parser.set('mapping','stratos',"tardis")
self.config_parser.set('mapping','xro',"gladosreplaced")
self.config_parser.set('mapping','equinox',"gladosparty")
+ self.config_parser.set('mapping','Rachel',"nothing")
self.config_parser.add_section('debug')
self.config_parser.set('debug','enabled',"False")
self.config_parser.add_section('tracker')
-def runRemoteCommand(config,args=[]):
+def runRemoteCommand(remote_host,remote_shell,args=[]):
global sshp,uwscfg
sshp = None
try:
- cmd = "ssh -i /flash/tuer/id_rsa -o PasswordAuthentication=no -o StrictHostKeyChecking=no %RHOST% %RSHELL%".replace("%RHOST%",uwscfg.getValue(config+"_remote_host")).replace("%RSHELL%",uwscfg.getValue(config+"_remote_shell")).replace("%ARG%"," ".join(args)).split(" ")
- logging.debug("runRemoteCommand: Executing: "+" ".join(cmd))
- sshp = subprocess.Popen(cmd, bufsize=1024, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False)
+ cmd = "ssh -i /flash/tuer/id_rsa -o PasswordAuthentication=no -o StrictHostKeyChecking=no %RHOST% %RSHELL%"
+ cmd = cmd.replace("%RHOST%",remote_host).replace("%RSHELL%",remote_shell).replace("%ARG%", " ".join(args))
+ logging.debug("runRemoteCommand: Executing: "+cmd)
+ sshp = subprocess.Popen(cmd.split(" "), bufsize=1024, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False)
logging.debug("runRemoteCommand: pid %d: running=%d" % (sshp.pid,sshp.poll() is None))
if not sshp.poll() is None:
logging.error("runRemoteCommand: subprocess %d not started ?, returncode: %d" % (sshp.pid,sshp.returncode))
subprocess.call(["kill","-9",str(sshp.pid)])
time.sleep(5)
-def runShellCommand(config,args=[]):
+def runShellCommand(cmd,ptimeout,stdinput,args=[]):
global uwscfg
- cmd = uwscfg.getValue(config+"_cmd").replace("%ARG%"," ".join(args))
- ptimeout = uwscfg.getValue(config+"_timeout")
- stdinput = uwscfg.getValue(config+"_stdinput")
+ cmd = cmd.replace("%ARG%"," ".join(args))
if ptimeout is None or float(ptimeout) > 45:
ptimeout = 45
popenTimeout2(cmd,stdinput,float(ptimeout))
#"registered" actions
if action_type == "remotecmd":
- return runRemoteCommand(action_type,args)
+ return runRemoteCommand(uwscfg.getValue(action_name+"_remote_host"), uwscfg.getValue(action_name+"_remote_shell"), args)
elif action_type == "shellcmd":
- return runShellCommand(action_type,args)
+ return runShellCommand(cmd=uwscfg.getValue(action_name+"_cmd"), ptimeout=uwscfg.getValue(action_name+"_timeout"), stdinput=uwscfg.getValue(action_name+"_stdinput"), args=args)
+ elif action_type == "nothing":
+ return True
else:
return executeAction(action_type,args)
if config is None:
config=uwscfg.getValue("mapping_default")
logging.debug("playThemeOf: action for user %s: %s" % (user,config))
- executeAction(config)
+ executeAction(config,[])
def popenTimeout1(cmd, pinput, returncode_ok=[0], ptimeout = 20.0, pcheckint = 0.25):
logging.debug("popenTimeout1: starting: " + cmd)
#socket.setdefaulttimeout(10.0) #affects all new Socket Connections (urllib as well)
RE_PRESENCE = re.compile(r'Presence: (yes|no)(?:, (opened|closed), (.+))?')
RE_BUTTON = re.compile(r'PanicButton|button\d?')
-RE_REQUEST = re.compile(r'Request: (\w+) (?:(Card|Phone) )?(.+)')
+#RE_REQUEST = re.compile(r'Request: (\w+) (?:(Card|Phone) )?(.+)')
+RE_ERROR = re.compile(r'Error: (.+)')
+
while True:
try:
if not os.path.exists(uwscfg.tracker_socket):
if not m is None:
playThemeOf(user="panic")
continue
+
+ m = RE_ERROR.match(line)
+ if not m is None:
+ playThemeOf(user="error")
+ continue
except Exception, ex:
logging.error("main: "+str(ex))