Image 01
profile-image

malfi

Malfino Malfano
SMS Widget

Plasma 4 Extensions by nethad 20 comments

Quote:
$ cat ~/.kde/share/apps/plasma/plasmoids/sms-widget/contents/code/providers/arcor_de.rb

require 'net/http'
require 'net/https'
require 'uri'

module Provider

class ArcorDE < AbstractProvider

@sms_sender

@login_name
@password

def initialize(sms_sender)
@sms_sender = sms_sender
@login_name = @sms_sender.get_main.login_name
@password = @sms_sender.get_main.password
end

def send(to, text)
use_ssl = 1

trans =Iconv.new('ISO-8859-1','UTF-8') # new converter-object encoding from UTF-8 to ISO-8859-1
text=URI.escape(trans.iconv(text)) # convert message to ISO-8859-1 and escape it for use in URL

#SmsWidget::Main.logger.debug "login = #{@login_name}\npassword = #{@password}\nto = #{to}\ntext = #{text}\nuse_ssl = #{use_ssl}"

# URLs
referer_url = 'https://www.arcor.de/login/login.jsp'
login_url = 'https://www.arcor.de/login/login.jsp'
send_url = 'https://www.arcor.de/ums/ums_neu_sms.jsp'

# Settings
user_agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10"
redirect = ''
cookie = ''
if use_ssl
port = 443
else
port = 80
end

# Now do the login
login_uri = URI.parse(login_url)

http = Net::HTTP.new(login_uri.host, port)
http.ca_path = "/etc/ssl/certs"
http.use_ssl = use_ssl
post_data = "user_name=#{@login_name}&password=#{@password}&login=Login&goto=&protocol=https"

post_headers = { 'Referer' => referer_url, 'Cookie' => cookie, 'Content-Type' => 'application/x-www-form-urlencoded'}

resp, data = http.post(login_uri.path, post_data, post_headers)

cookie = resp.response['set-cookie'].split('; ')[0]
SmsWidget::Main.logger.info 'accepted cookie: ' + cookie

#resp.each { |key, val|
# SmsWidget::Main.logger.debug "#{key} => #{val}"
#}


while redirect = resp.response['location'] do
SmsWidget::Main.logger.info 'redirected to: ' + redirect
resp = http.get(redirect, {'Cookie' => cookie})
end
#SmsWidget::Main.logger.debug "arcor de login data: #{resp.body}"

if resp.body.include? 'Der Login ist fehlgeschlagen'
raise InvalidPasswordOrUsernameException
end

#now we can send the message
send_uri = URI.parse(send_url)

http = Net::HTTP.new(send_uri.host, port)
http.use_ssl = use_ssl
post_data = "emailAdressen=#{@login_name}%40arcor.de&useOwnMobile=on&empfaengerAn=#{to}&nachricht=#{text}&gesendetkopiesms=on&senden=Senden&firstVisitOfPage=foo&ordnername=Posteingang&part=0"

post_headers = { 'Referer' => login_url, 'Cookie' => cookie, 'Content-Type' => 'application/x-www-form-urlencoded'}


sent=false

#resp, data = http.post(send_uri.path, post_data, post_headers)
resp = http.post(send_uri.path, post_data, post_headers)

while redirect = resp.response['location'] do
SmsWidget::Main.logger.info 'redirected to: ' + redirect
resp = http.get(redirect, {'Cookie' => cookie})
end

if resp.body.include? 'Die SMS wurde im Gesendet-Ordner gespeichert'
#exit 0
sms_sent()
sent=true
end

unless sent
sms_not_sent("something went wrong")
end
end



end

end


Quote:
$ tail -n 15 ~/.kde/share/apps/plasma/plasmoids/sms-widget/contents/code/provider_list.yml
class: OrangeCH
icon: orangech.png
password_needed: true
own_number_needed: false
arcor.de:
login_needed: true
help: Enter your login name and your password.
class: ArcorDE
icon: orangech.png
password_needed: true
own_number_needed: false
"":
login_needed: true
password_needed: true
own_number_needed: false
- Oct 08 2010