Last active
August 29, 2015 13:56
-
-
Save thomaswitt/9037276 to your computer and use it in GitHub Desktop.
As the sipgate guys appearently don't have an API to fetch all users and SIP credentials for provisioning, you have to crawl their web-site. Ugly, but it works. The crawl may take quite some time, so you're better off caching it. If there's somebody listening from @sipgate: please provide a clean API …
This file contains 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
require 'mechanize' | |
m = Mechanize.new | |
users = [] | |
rooms = [] | |
login = m.get('https://secure.live.sipgate.de/settings/setup') | |
login.form do |f| | |
f.username = 'name@company.com' | |
f.password = 'secret_password' | |
end | |
ulist = m.submit(login.form, login.form.buttons.first) | |
$stderr.print "Crawling users" | |
ulist.links_with(href: %r{^/settings/phone/index/webuser/}).each do |link| | |
$stderr.print "." | |
next unless link.node.at_css('span.sortby_lastname') | |
user = link.click | |
sipId = user.search(".sipId").first['value'] | |
sipPw = user.search(".sipPassword").first['value'] | |
intNumber = user.search("div.tag.delDirectdial").first.text rescue '' | |
extNumber = user.search("div.tag.delNumberToPerson").first.text rescue '' | |
mobileNumber = user.search("p.pill.externalNumber").first.text.strip rescue '' | |
details = user.link_with(text: 'Weitere Einstellungen').click | |
userEmail = details.search("#email").first.text | |
users.push([userEmail, sipId, sipPw, intNumber, extNumber, mobileNumber]) | |
end | |
$stderr.puts "done" | |
$stderr.print "Crawling rooms" | |
rlist = ulist.link_with(text: 'Telefone ohne Benutzer').click | |
rlist.links_with(href: %r{^/settings/setup/unlinked/extension/}).each do |link| | |
$stderr.print "." | |
next unless link.node.at_css('span.sortby_name') | |
roomPhone = link.click | |
phoneName = roomPhone.at('p.alias').text | |
sipId = roomPhone.search(".sipId").first['value'] | |
sipPw = roomPhone.search(".sipPassword").first['value'] | |
rooms.push([phoneName, sipId, sipPw]) | |
end | |
$stderr.puts "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment