def emergency(): try: if hardwareconfig.checkLock()==False: lockScreen() #truecrypt forces volume dismount and discards any key data if fileconfig.config.get('TRIGGERS','dismount_tc') == 'True': tcPath = fileconfig.config.get('TRIGGERS','tc_path') try: subprocess.call([tcPath,"/dismount","/force","/wipecache","/quit","/silent"]) except: pass if fileconfig.config.get('TRIGGERS','exec_shellscript') == 'True': try: key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"SOFTWARE\Lockwatcher") scriptPath = str(_winreg.QueryValueEx(key,'SDScript')[0]) except: key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"SOFTWARE\Wow6432Node\Lockwatcher") scriptPath = str(_winreg.QueryValueEx(key,'SDScript')[0]) if os.path.exists(scriptPath): try: timeLimit = float(fileconfig.config.get('TRIGGERS','script_timeout')) except: timelimit = 5.0 thread = execScript(scriptPath) thread.run(timeout=timeLimit) except: pass #shutdown: force application close, no timeout shutdownPath = 'shutdown.exe' #maybe better to find+use full path subprocess.call([shutdownPath,"-s","-t","00","-f"])
def eventHandle(event_type,eventReason): locked = hardwareconfig.checkLock() while True: #this can be a race condition with configfile alterations. keep trying if we get a bad reading try: alwaysTriggers = fileconfig.config.get('TRIGGERS','ALWAYSTRIGGERS').split(',') lockedTriggers = fileconfig.config.get('TRIGGERS','LOCKEDTRIGGERS').split(',') testMode = fileconfig.config.get('TRIGGERS','test_mode') break except: time.sleep(0.3) continue if (event_type in alwaysTriggers) or (event_type in lockedTriggers and locked == True): eventQueue.put(("Log","[%s - *Trigger ACTIVATED*]. %s"%(lockedStateText[locked],eventReason))) if testMode == 'False': #allow recovery in situations where the computer would otherwise shutdown as soon as it starts up if time.time() < startupTime + 90: eventQueue.put(("Log",'Shutdown cancelled - Not allowed within 90 seconds of lockwatcher start')) else: eventQueue.put(("Kill",eventReason)) else: eventQueue.put(("Log",'Shutdown cancelled - test mode active')) else: '''log the ignored trigger (but not the 2nd killswitch because a logfile containing every press of the letter 'p' is going to be a mess)''' if event_type not in ['E_MOUSE_MOVE','E_MOUSE_BTN','E_KILL_SWITCH_2']: eventQueue.put(("Log","[%s - Trigger ignored]. %s"%(lockedStateText[locked],eventReason)))
def executeRemoteCommand(command): result = True if command == REMOTE_LOCK: if hardwareconfig.checkLock() == False: AFroutines.lockScreen() result = sendemail.sendEmail("Command successful","Screen locked") eventQueue.put(("Log",'Screen locked due to remote command')) else: eventQueue.put(("Log",'Lock screen failed - command received while locked')) result = sendemail.sendEmail("Command failed","Screen already locked") elif command == REMOTE_STARTMONITOR: #cant check ispy camera status, just have to assume it was not monitoring iSpyPath = fileconfig.config.get('TRIGGERS','ispy_path') roomCamID = fileconfig.config.get('TRIGGERS','room_cam_id') if os.path.exists(iSpyPath): eventQueue.put(("Log","Starting room camera due to remote command")) else: eventQueue.put(("Log","iSpy executable not found - cannot fulfill remote command")) return subprocess.call([iSpyPath,'commands bringonline,2,%s'%roomCamID]) result = sendemail.sendEmail("Command successful","Movement monitoring initiated. Have a nice day.") elif command == REMOTE_STOPMONITOR: #cant check ispy camera status, just have to assume it was already monitoring iSpyPath = fileconfig.config.get('TRIGGERS','ispy_path') roomCamID = fileconfig.config.get('TRIGGERS','room_cam_id') if os.path.exists(iSpyPath): eventQueue.put(("Log","Stopping room camera due to remote command")) else: eventQueue.put(("Log","iSpy executable not found - cannot fulfill remote command")) return subprocess.call([iSpyPath,'commands takeoffline,2,%s'%roomCamID]) result = sendemail.sendEmail("Command successful","Movement monitoring disabled. Welcome home!") elif command == REMOTE_SHUTDOWN: result = sendemail.sendEmail("Command successful","Shutting down...") eventQueue.put(("Log","Initiating standard shutdown due to remote command")) AFroutines.standardShutdown() elif command == REMOTE_KILLSWITCH: eventQueue.put(("Log","Initiating emergency shutdown due to remote command")) AFroutines.emergency() if result != True: eventQueue.put(('Log','Mail send failed: %s'%result))
def emergency(): try: if hardwareconfig.checkLock() == False: lockScreen() #truecrypt forces volume dismount and discards any key data if fileconfig.config.get('TRIGGERS', 'dismount_tc') == 'True': tcPath = fileconfig.config.get('TRIGGERS', 'tc_path') try: subprocess.call([ tcPath, "/dismount", "/force", "/wipecache", "/quit", "/silent" ]) except: pass if fileconfig.config.get('TRIGGERS', 'exec_shellscript') == 'True': try: key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\Lockwatcher") scriptPath = str(_winreg.QueryValueEx(key, 'SDScript')[0]) except: key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\Wow6432Node\Lockwatcher") scriptPath = str(_winreg.QueryValueEx(key, 'SDScript')[0]) if os.path.exists(scriptPath): try: timeLimit = float( fileconfig.config.get('TRIGGERS', 'script_timeout')) except: timelimit = 5.0 thread = execScript(scriptPath) thread.run(timeout=timeLimit) except: pass #shutdown: force application close, no timeout shutdownPath = 'shutdown.exe' #maybe better to find+use full path subprocess.call([shutdownPath, "-s", "-t", "00", "-f"])
def eventHandle(event_type, eventReason): locked = hardwareconfig.checkLock() while True: #this can be a race condition with configfile alterations. keep trying if we get a bad reading try: alwaysTriggers = fileconfig.config.get('TRIGGERS', 'ALWAYSTRIGGERS').split(',') lockedTriggers = fileconfig.config.get('TRIGGERS', 'LOCKEDTRIGGERS').split(',') testMode = fileconfig.config.get('TRIGGERS', 'test_mode') break except: time.sleep(0.3) continue if (event_type in alwaysTriggers) or (event_type in lockedTriggers and locked == True): eventQueue.put(("Log", "[%s - *Trigger ACTIVATED*]. %s" % (lockedStateText[locked], eventReason))) if testMode == 'False': #allow recovery in situations where the computer would otherwise shutdown as soon as it starts up if time.time() < startupTime + 90: eventQueue.put(( "Log", 'Shutdown cancelled - Not allowed within 90 seconds of lockwatcher start' )) else: eventQueue.put(("Kill", eventReason)) else: eventQueue.put(("Log", 'Shutdown cancelled - test mode active')) else: '''log the ignored trigger (but not the 2nd killswitch because a logfile containing every press of the letter 'p' is going to be a mess)''' if event_type not in [ 'E_MOUSE_MOVE', 'E_MOUSE_BTN', 'E_KILL_SWITCH_2' ]: eventQueue.put(("Log", "[%s - Trigger ignored]. %s" % (lockedStateText[locked], eventReason)))
def executeRemoteCommand(command): result = True if command == REMOTE_LOCK: if hardwareconfig.checkLock() == False: AFroutines.lockScreen() result = sendemail.sendEmail("Command successful", "Screen locked") eventQueue.put(("Log", 'Screen locked due to remote command')) else: eventQueue.put( ("Log", 'Lock screen failed - command received while locked')) result = sendemail.sendEmail("Command failed", "Screen already locked") elif command == REMOTE_STARTMONITOR: #cant check ispy camera status, just have to assume it was not monitoring iSpyPath = fileconfig.config.get('TRIGGERS', 'ispy_path') roomCamID = fileconfig.config.get('TRIGGERS', 'room_cam_id') if os.path.exists(iSpyPath): eventQueue.put( ("Log", "Starting room camera due to remote command")) else: eventQueue.put( ("Log", "iSpy executable not found - cannot fulfill remote command")) return subprocess.call([iSpyPath, 'commands bringonline,2,%s' % roomCamID]) result = sendemail.sendEmail( "Command successful", "Movement monitoring initiated. Have a nice day.") elif command == REMOTE_STOPMONITOR: #cant check ispy camera status, just have to assume it was already monitoring iSpyPath = fileconfig.config.get('TRIGGERS', 'ispy_path') roomCamID = fileconfig.config.get('TRIGGERS', 'room_cam_id') if os.path.exists(iSpyPath): eventQueue.put( ("Log", "Stopping room camera due to remote command")) else: eventQueue.put( ("Log", "iSpy executable not found - cannot fulfill remote command")) return subprocess.call([iSpyPath, 'commands takeoffline,2,%s' % roomCamID]) result = sendemail.sendEmail( "Command successful", "Movement monitoring disabled. Welcome home!") elif command == REMOTE_SHUTDOWN: result = sendemail.sendEmail("Command successful", "Shutting down...") eventQueue.put( ("Log", "Initiating standard shutdown due to remote command")) AFroutines.standardShutdown() elif command == REMOTE_KILLSWITCH: eventQueue.put( ("Log", "Initiating emergency shutdown due to remote command")) AFroutines.emergency() if result != True: eventQueue.put(('Log', 'Mail send failed: %s' % result))