Created
November 14, 2011 17:03
-
-
Save mschae/1364462 to your computer and use it in GitHub Desktop.
Fritz.Box Anrufmonitor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires the following gems: | |
# - prowler (v. 1.2) | |
# - gdata | |
# Also requires prowl on your iPhone | |
# As always: Feel free to use as is, I'm not responsible for anything | |
prowl_api_key = "" | |
fritz_box_host = "" | |
google = { | |
:user => "", | |
:password => "" | |
} | |
country_prefix = "" # e.g. +49 | |
require 'rubygems' | |
require 'prowler' | |
require 'socket' | |
require 'gdata' | |
def standardize_phone phone | |
phone.gsub(/[\-\/ ]/, "").gsub(/^0/, country_prefix) | |
end | |
def get_contacts client, google | |
contacts = {} | |
stream = client.get("https://www.google.com/m8/feeds/contacts/#{google[:user]}/full?max-results=10000") | |
stream.to_xml.elements.each("entry") do |entry| | |
name = entry.elements["title"] | |
entry.elements.each("gd:phoneNumber") do |number| | |
number = standardize_phone(number.text) if number | |
contacts[number] = name.text | |
end | |
end | |
contacts | |
end | |
# setup prowler | |
Prowler.configure do |config| | |
config.api_key = prowl_api_key | |
config.application = "Fritz.Box Anrufmonitor" | |
end | |
# setup socket | |
socket = TCPSocket.open(fritz_box_host, 1012) | |
# setup google | |
client = GData::Client::Contacts.new | |
client.clientlogin google[:user], google[:password] | |
# run | |
while line = socket.gets | |
contacts = get_contacts client, google | |
time, event, null, from, to, account = line.split(";") | |
from = standardize_phone(from) | |
from = "#{contacts[from]} (#{from})" if contacts[from] | |
case event # using case for easy extensibility | |
when /RING/ | |
Prowler.notify "Anruf von #{from} an #{to}", "Um: #{time}\nVon: #{from}\nAn: #{to}\n" rescue nil # if prowl decides to be an asshole | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment