#!/usr/bin/python # # Thinkpad Anti Theft Script # Janitha Karunaratne # # This is made to work with Gnome Screensaver and Ts_smapi for /sys/device/platform/hdaps/position # Change the Variables and point them to the files you want to execute to make the sounds # # Copyright 2008 Janitha Karunaratne # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import fileinput import os import time import sys ### Variables ############################################################################### hdaps = "/sys/devices/platform/hdaps/position" threshold_alert = 10 threshold_alarm = 40 sound_armed = "mp3-cmdline /home/j/projects/theftalarm/bleep.mp3 -q" sound_alert = "mp3-cmdline /home/j/projects/theftalarm/alert.mp3 -q" sound_alarm = "mp3-cmdline /home/j/projects/theftalarm/alarm.mp3 -q -g 1000" ### Give few Seconds to Arm the Laptop ############################################################################### os.system("gnome-screensaver-command -l") for i in range(0, 3): os.system(sound_armed) time.sleep(1) os.system(sound_alert) ### Set Defaults ############################################################################### file = open(hdaps) value = file.readline() bx = int(value.partition("(")[2].partition(",")[0]) by = int(value.partition(",")[2].partition(")")[0]) print bx print by file.close() x = bx y = by while x > bx-threshold_alarm and x < bx+threshold_alarm and y > by-threshold_alarm and y < by+threshold_alarm: time.sleep(0.05) # Read HDAPS values file = open(hdaps) value = file.readline() x = int(value.partition("(")[2].partition(",")[0]) y = int(value.partition(",")[2].partition(")")[0]) file.close() if x < bx-threshold_alert or x > bx+threshold_alert or y < by-threshold_alert or y > by+threshold_alert: diff = abs(bx-x) + abs(by-y) gain_diff = int((diff*100.0) / (threshold_alarm))*2 #print "alert",gain_diff cmd = sound_alert + " -g " + `gain_diff` #print cmd os.system(cmd) if os.popen('gnome-screensaver-command -q').readlines()[0].find("inactive") > 0: sys.exit(0) while 1: if os.popen('gnome-screensaver-command -q').readlines()[0].find("inactive") > 0: sys.exit(0) print "Alarm!" os.system(sound_alarm) time.sleep(1.4)