X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=play-sound-status.py;h=63197389aa72385c0eeed223bcd62724b76b4ddb;hb=859a411f5baa30255edefce58904542cbac5dd14;hp=ea193f27ab59315666dbc8724a518cbce9a3f13c;hpb=c1d893877efb1c5edd24dbd5bb8fc41379c01ebf;p=svn42.git diff --git a/play-sound-status.py b/play-sound-status.py index ea193f2..6319738 100755 --- a/play-sound-status.py +++ b/play-sound-status.py @@ -14,11 +14,12 @@ import socket import subprocess import types import ConfigParser +import traceback logger = logging.getLogger() logger.setLevel(logging.INFO) lh_syslog = logging.handlers.SysLogHandler(address="/dev/log",facility=logging.handlers.SysLogHandler.LOG_LOCAL2) -lh_syslog.setFormatter(logging.Formatter('update-web-status.py: %(levelname)s %(message)s')) +lh_syslog.setFormatter(logging.Formatter('play-sound-status.py: %(levelname)s %(message)s')) logger.addHandler(lh_syslog) lh_stderr = logging.StreamHandler() logger.addHandler(lh_stderr) @@ -27,10 +28,34 @@ class UWSConfig: def __init__(self,configfile=None): self.configfile=configfile self.config_parser=ConfigParser.ConfigParser() - self.config_parser.add_section('playsound') - self.config_parser.set('playsound','remote_cmd',"ssh -i /flash/tuer/id_rsa -o PasswordAuthentication=no -o StrictHostKeyChecking=no %RHOST% %RCMD%") - self.config_parser.set('playsound','remote_host',"root@slug.realraum.at") - self.config_parser.set('playsound','remote_cmd',"/home/playmp3.sh /home/half-life-door.mp3") + self.config_parser.add_section('halflife2') + self.config_parser.set('halflife2','remote_cmd',"ssh -i /flash/tuer/id_rsa -o PasswordAuthentication=no -o StrictHostKeyChecking=no %RHOST% %RSHELL%") + self.config_parser.set('halflife2','remote_host',"root@slug.realraum.at") + self.config_parser.set('halflife2','remote_shell',"/home/playmp3.sh /home/half-life-door.mp3") + self.config_parser.set('halflife2','delay',"3.0") + self.config_parser.set('halflife2','type',"remotecmd") + self.config_parser.add_section('tardis') + self.config_parser.set('tardis','remote_cmd',"ssh -i /flash/tuer/id_rsa -o PasswordAuthentication=no -o StrictHostKeyChecking=no %RHOST% %RSHELL%") + self.config_parser.set('tardis','remote_host',"root@slug.realraum.at") + self.config_parser.set('tardis','remote_shell',"/home/playmp3.sh /home/tardis.mp3") + self.config_parser.set('tardis','delay',"3.0") + self.config_parser.set('tardis','type',"remotecmd") + self.config_parser.add_section('sg1aliengreeting') + self.config_parser.set('sg1aliengreeting','remote_cmd',"ssh -i /flash/tuer/id_rsa -o PasswordAuthentication=no -o StrictHostKeyChecking=no %RHOST% %RSHELL%") + self.config_parser.set('sg1aliengreeting','remote_host',"root@slug.realraum.at") + self.config_parser.set('sg1aliengreeting','remote_shell',"/home/playmp3.sh /home/sg1aliengreeting.mp3") + self.config_parser.set('sg1aliengreeting','delay',"3.0") + self.config_parser.set('sg1aliengreeting','type',"remotecmd") + self.config_parser.add_section('monkeyscream') + self.config_parser.set('monkeyscream','remote_cmd',"ssh -i /flash/tuer/id_rsa -o PasswordAuthentication=no -o StrictHostKeyChecking=no %RHOST% %RSHELL%") + self.config_parser.set('monkeyscream','remote_host',"root@slug.realraum.at") + self.config_parser.set('monkeyscream','remote_shell',"/home/playmp3.sh /home/monkeyscream.mp3") + self.config_parser.set('monkeyscream','delay',"3.0") + self.config_parser.set('monkeyscream','type',"remotecmd") + 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','xro',"tardis") self.config_parser.add_section('debug') self.config_parser.set('debug','enabled',"False") self.config_parser.add_section('tracker') @@ -79,6 +104,15 @@ class UWSConfig: logging.error("Error writing Configfile: "+str(io_ex)) self.configfile=None + def getValue(self, name): + underscore_pos=name.find('_') + if underscore_pos < 0: + raise AttributeError + try: + return self.config_parser.get(name[0:underscore_pos], name[underscore_pos+1:]) + except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): + return None + def __getattr__(self, name): underscore_pos=name.find('_') if underscore_pos < 0: @@ -90,12 +124,11 @@ class UWSConfig: -def playRemoteSound(uwscfg): - global sshp - uwscfg.checkConfigUpdates() +def playRemoteSound(config): + global sshp,uwscfg sshp = None try: - cmd = uwscfg.sensors_remote_cmd.replace("%RHOST%",uwscfg.playsound_remote_host).replace("%RCMD%",uwscfg.playsound_remote_cmd).split(" ") + cmd = uwscfg.getValue(config+"_remote_cmd").replace("%RHOST%",uwscfg.getValue(config+"_remote_host")).replace("%RSHELL%",uwscfg.getValue(config+"_remote_shell")).split(" ") logging.debug("playRemoteSound: Executing: "+" ".join(cmd)) sshp = subprocess.Popen(cmd, bufsize=1024, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False) logging.debug("playRemoteSound: pid %d: running=%d" % (sshp.pid,sshp.poll() is None)) @@ -118,7 +151,24 @@ def playRemoteSound(uwscfg): subprocess.call(["kill","-9",str(sshp.pid)]) time.sleep(5) - +def playThemeOf(user): + global uwscfg + uwscfg.checkConfigUpdates() + type=None + config=uwscfg.getValue("mapping_"+str(user)) + if config is None: + config=uwscfg.getValue("mapping_default") + type=uwscfg.getValue(config+"_type") + if type is None: + type="remotecmd" + delay=uwscfg.getValue(config+"_delay") + logging.debug("playThemeOf, user=%s, config=%s, type=%s, delay=%s" % (user,config,type,delay)) + if not delay is None: + time.sleep(float(delay)) + if type == "remotecmd": + playRemoteSound(config) + else: + logging.debug("playThemeOf: Error, unknown type") def popenTimeout1(cmd, pinput, returncode_ok=[0], ptimeout = 20.0, pcheckint = 0.25): logging.debug("popenTimeout1: starting: " + cmd) @@ -202,6 +252,7 @@ else: #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) )?(.+)') while True: try: if not os.path.exists(uwscfg.tracker_socket): @@ -230,13 +281,13 @@ while True: last_status=(status == "yes") unixts_panic_button=None if last_status: - playRemoteSound() + playThemeOf(user=m.group(3)) continue m = RE_BUTTON.match(line) if not m is None: - pass #insert panic action here - continue + playThemeOf(user="panic") + continue except Exception, ex: logging.error("main: "+str(ex))