rmobio 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,83 @@
1
+ #
2
+ # Copyright (C) 2007 Mobio Networks, Inc.
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ #
17
+
18
+ =begin
19
+ this provides advertising call from AdMobs
20
+ =end
21
+ require 'net/http'
22
+ require 'uri'
23
+ require 'md5'
24
+
25
+ module Rmobio
26
+ module Ads
27
+ module AdMobs
28
+
29
+ def getAd(keywords)
30
+ puts "AdMobs"
31
+ admob_params = {:admob_site_id => "a147c0944fbb5e8", # REQUIRED - get from admob.com
32
+ :admob_pc => "", # OPTIONAL - Postal Code, e.g. "90210"
33
+ :admob_dob => "", # OPTIONAL - Date of Birth formatted like YYYYMMDD, e.g. "19800229"
34
+ :admob_gender => "", # OPTIONAL - Gender, m[ale] or f[emale]
35
+ :admob_keywords => keywords}
36
+ # change to "live" when ready to deploy
37
+ admob_mode = "test"
38
+
39
+ admob_endpoint = "http://r.admob.com/ad_source.php"
40
+ admob_version = "20071126-RUBY-19db4ba7ab087721"
41
+ admob_timeout = 1.0
42
+ admob_ignore = Set["HTTP_PRAGMA", "HTTP_CACHE_CONTROL", "HTTP_CONNECTION", "HTTP_USER_AGENT", "HTTP_COOKIE"]
43
+ # build url
44
+ admob_post = {}
45
+ admob_post["s"] = admob_params[:admob_site_id]
46
+ admob_post["u"] = request.user_agent
47
+ admob_post["i"] = request.remote_ip
48
+ admob_post["p"] = request.request_uri
49
+ admob_post["t"] = MD5.hexdigest(session.session_id)
50
+ admob_post["v"] = admob_version
51
+ admob_post["d[pc]"] = admob_params[:admob_pc]
52
+ admob_post["d[dob]"] = admob_params[:admob_dob]
53
+ admob_post["d[gender]"] = admob_params[:admob_gender]
54
+ admob_post["k"] = admob_params[:admob_keywords]
55
+ request.env.each {|k,v| admob_post["h[#{k}]"] = v unless admob_ignore.include?(k.upcase)}
56
+ admob_post["m"] = "test" if admob_mode == "test"
57
+ begin # request ad
58
+ admob_uri = URI.parse(admob_endpoint)
59
+ admob_request = Net::HTTP::Post.new(admob_uri.path)
60
+ admob_request.set_form_data(admob_post)
61
+ admob_conn = Net::HTTP.new(admob_uri.host, admob_uri.port)
62
+ admob_conn.read_timeout = admob_timeout
63
+ admob_conn.open_timeout = admob_timeout
64
+ admob_response = admob_conn.start {|admob_http| admob_http.request(admob_request) }
65
+ admob_contents = admob_response.body
66
+ rescue Timeout::Error => te
67
+ admob_contents = "<img src=\"http://t.admob.com/li.php/c.gif/#{admob_params[:admob_site_id]}/1/#{admob_timeout}/#{MD5.hexdigest(request.request_uri)}\" alt=\"\" width=\"1\" height=\"1\" />"
68
+ rescue
69
+ end
70
+ @ad=admob_contents
71
+ end
72
+
73
+ # the keyword search version also evaluates the supplied page so
74
+ # for admobs they are the same
75
+ def getAdByPage
76
+ getAd("")
77
+ end
78
+
79
+ end
80
+ end
81
+ end
82
+
83
+
@@ -0,0 +1,190 @@
1
+ #
2
+ # Copyright (C) 2007 Mobio Networks, Inc.
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ #
17
+
18
+ =begin
19
+ provides advertisement fetch for Google's Mobile Adsense
20
+ (alpha level keyword version
21
+ and released "page scraping version"
22
+ =end
23
+ require 'digest/sha1'
24
+ require 'collections/sequenced_hash'
25
+
26
+ module Rmobio
27
+ module Ads
28
+ module AdSense
29
+
30
+
31
+ @@adsense=$ADSENSE
32
+ @@adServer="http://pagead2.googlesyndication.com/pagead/ads"
33
+ @@adClient="ca-mb-pub-0061196910475770"
34
+ @@mobioUseragent="Mobio" # we should probably come up with a better string
35
+
36
+ # Determines whether this request should involve adSense.
37
+ def doAdSense()
38
+ # is adsense enabled for the project?
39
+ if (@@adsense != 1)
40
+ return false
41
+ end
42
+
43
+ # returns true of false depending on what client is making this request.
44
+ if (@client == 'facebook')
45
+ return false
46
+ else
47
+ return true
48
+ end
49
+ end
50
+
51
+ def getAdParms
52
+ getAd(params[:keywords])
53
+ end
54
+
55
+
56
+ #$GLOBALS['google']['ad_type']='text';
57
+ #$GLOBALS['google']['channel']='8618723264';
58
+ #$GLOBALS['google']['client']='pub-0061196910475770';
59
+ #$GLOBALS['google']['format']='mobile_single';
60
+ #$GLOBALS['google']['https']=$_SERVER['HTTPS'];
61
+ #$GLOBALS['google']['host']=$_SERVER['HTTP_HOST'];
62
+ #$GLOBALS['google']['ip']=$_SERVER['REMOTE_ADDR'];
63
+ #$GLOBALS['google']['markup']='xhtml';
64
+ #$GLOBALS['google']['oe']='utf8';
65
+ #$GLOBALS['google']['output']='xhtml';
66
+ #$GLOBALS['google']['ref']=$_SERVER['HTTP_REFERER'];
67
+ #$GLOBALS['google']['url']=$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
68
+ #$GLOBALS['google']['useragent']=$_SERVER['HTTP_USER_AGENT'];
69
+
70
+ def getAdByPage
71
+ if (doAdSense())
72
+ @@userId=request.env['HTTP_USERID']
73
+ if (@@userId.nil?)
74
+ @@userId="101"
75
+ end
76
+
77
+ adArgs= SequencedHash.new
78
+ adArgs["ad_type"]="text"
79
+ adArgs["channel"]="8618723264"
80
+ adArgs["client"]="pub-0061196910475770"
81
+ adArgs["format"]="mobile_single"
82
+ adArgs["host"]=request.host
83
+ adArgs["ip"]=request.remote_ip
84
+ adArgs["markup"]="xhtml"
85
+ adArgs["output"]="xhtml"
86
+ adArgs["oe"]="utf8"
87
+ adArgs["ref"]=request.referer
88
+ adArgs["url"]="http://"+request.env["HTTP_HOST"]+request.env["REQUEST_URI"]
89
+ #adArgs["useragent"]=request.user_agent
90
+ adArgs["eip"]=Digest::SHA1.hexdigest(@@userId)[0..20] # oneway hashed userid
91
+
92
+ # now built the URL to call out to based upon the base URL and ad hash
93
+ adURL=@@adServer + "?"
94
+ first=1 # dont put ampersand on first one
95
+ adArgs.each_key do |x|
96
+ if adArgs[x]
97
+ (adURL=adURL+"&") unless first
98
+ first=nil # start putting in &s
99
+ adURL = adURL + x + "=" + adArgs[x]
100
+ end
101
+ end
102
+ # ok, now call google's mobile adSense service and get back the full ad
103
+ @pagead=open(adURL).read
104
+ end
105
+ end
106
+
107
+ # this returns an adfrom Google's mobile AdSense, given a supplied set of keywords
108
+ def getAd(keywords)
109
+ puts "Adsense"
110
+ doTinyUrl=true
111
+ if (doAdSense())
112
+ @@userId=request.env['HTTP_USERID']
113
+ if (@@userId.nil?)
114
+ @@userId="101"
115
+ end
116
+ # build up the various arguments in the adArgs hash
117
+ adArgs= SequencedHash.new
118
+ adArgs["ad_type"]="text"
119
+ adArgs["client"]=@@adClient # get it from gateway instead!
120
+ adArgs["format"]="mobile_single"
121
+ adArgs["ip"]=request.remote_ip
122
+ adArgs["markup"]="xhtml"
123
+ adArgs["output"]="wml"
124
+ adArgs["oe"]="utf-8"
125
+ adArgs["url"]="http:%3A%2Fwww.getmobio.com" # mobio's home site
126
+ adArgs["useragent"]=@@mobioUseragent # user agent for our browser.
127
+ adArgs["eip"]=Digest::SHA1.hexdigest(@@userId)[0..20] # oneway hashed userid
128
+ if (keywords)
129
+ adArgs["kw"]=CGI::escape(keywords)
130
+ adArgs["kw_type"]="broad"
131
+ end
132
+ # now built the URL to call out to based upon the base URL and ad hash
133
+ adURL=@@adServer + "?"
134
+ first=1 # dont put ampersand on first one
135
+ adArgs.each_key do |x|
136
+ if adArgs[x]
137
+ (adURL=adURL+"&") unless first
138
+ first=nil # start putting in &s
139
+ adURL = adURL + x + "=" + adArgs[x]
140
+ end
141
+ end
142
+ # ok, now call google's mobile adSense service and get back the full ad
143
+ @ad=open(adURL).read
144
+ if @ad
145
+ logger.info "Returned ad" + @ad
146
+ adDoc = REXML::Document.new @ad
147
+ @text = adDoc.elements['//p']
148
+ if @text # do we have a <p> element
149
+ # ok, now text has the full ad display content including links
150
+ # grab @url, @urltext (link text for url), @phone, @phonetext (link text for call)
151
+ if defined? @text[1].attributes['href'] and @text[1].attributes['href']
152
+ @adurl = doTinyUrl ? tinyUrl(@text[1].attributes['href']) : @text[1].attributes['href']
153
+ else
154
+ @adurl = "nolink.rwap"
155
+ end
156
+ @urltext=@text[1].text
157
+ @extratext=@text[2].to_s if @text[2] # this should have everything else that is not a child element
158
+ if (@text.size>3 and @text[3]) # only process @text[3] for phone stuff if it exists
159
+ @phone = (doTinyUrl ? tinyUrl(@text[3].attributes['href']) : @text[3].attributes['href']) if defined? @text[3].attributes['href'] and @text[3].attributes['href']
160
+ @phonetext=@text[3].text if defined? @text[3].text and @text[3].text
161
+ end
162
+ end
163
+ end # if we get an ad back from adsense
164
+ @ad # return the full ad text
165
+ end
166
+ end
167
+
168
+ private
169
+
170
+ def tinyUrl(url)
171
+ shrinker="http://tinyurl.com/create.php?url="+url
172
+ result=open(shrinker).read
173
+ # ITS NOT WELLFORMED HTML SO WE CAN'T USE XML TO PARSE
174
+ #result=result.gsub(/\<\/head\>/,"</link></base></head>")
175
+ #resultDoc= Document.new result
176
+ #tinyText=resultDoc.elements['//blockquote'][1]
177
+ #tinyLink=tinyText.elements['./b'].text
178
+ # find the second <blockquote> and extra out the contents of it
179
+ pattern='<blockquote><b>'
180
+ firstblock=result.index(pattern)
181
+ if (firstblock)
182
+ secondblock=result[firstblock+1...result.size].index('<blockquote><b>')+ firstblock+1 + pattern.size
183
+ endsecondblock=result[secondblock...result.size].index('</b>') + secondblock
184
+ tinyLink=result[secondblock...endsecondblock]
185
+ end
186
+ end
187
+
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,54 @@
1
+ #
2
+ # Copyright (C) 2007 Mobio Networks, Inc.
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ #
17
+
18
+ =begin
19
+ this provides advertising fetch for m_khoj
20
+ =end
21
+ require 'uri'
22
+ require 'open-uri'
23
+
24
+ module Rmobio
25
+ module Ads
26
+ module MKhoj
27
+
28
+
29
+ def getAd(keywords)
30
+ getAdByPage # keywords have no effect in mKhoj
31
+ end
32
+
33
+ def getAdByPage
34
+ puts "mKhoj getAd"
35
+ handset = request.user_agent if request.user_agent
36
+ # handset="nokia6030/"
37
+ handset = URI.escape(handset)
38
+ #carrier = URI.escape(request.remote_ip)
39
+ carrier="59.181.113.59" # only works with India carriers!!
40
+
41
+ adUrl="http://www.mkhoj.com/view/Traffic/ShowAd.aspx?siteId=330ed28f-0de9-4c4f-b0a8-1f2118358c80&handset=nokia6030/&carrier=59.181.113.59"
42
+ logger.info "Calling: " + adUrl
43
+ #adUrl = "http://www.mkhoj.com/view/Traffic/ShowAd.aspx?siteId=330ed28f-0de9-4c4f-b0a8-1f2118358c80&handset="+handset+"&carrier="+carrier
44
+ begin
45
+ @ad = open(adUrl).read
46
+ logger.info "Returned ad: " + @ad
47
+ rescue
48
+ end
49
+ @ad
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,106 @@
1
+ #
2
+ # Copyright (C) 2007 Mobio Networks, Inc.
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ #
17
+
18
+ require 'collections/sequenced_hash'
19
+
20
+ module Rmobio
21
+ module Ads
22
+ module Smaato
23
+ @@adServer="http://dev.soma.smaato.com:8080/wap/reqAd.jsp"
24
+
25
+ def getAdByPage
26
+ getAd(nil)
27
+ end
28
+
29
+ # this returns an adfrom Google's mobile AdSense, given a supplied set of keywords
30
+ def getAd(keywords)
31
+ logger.info "Smaato ad retrieval"
32
+ =begin
33
+ Example:
34
+ http://dev.soma.smaato.com:8080/wap/reqAd.jsp?pub=3517&adspace=137
35
+ &format=JPG&numads=10&offline=true&user=&response=XML
36
+ &width=176&height=208&device=Sony&devip=123.45.67.89&carrier=o2
37
+ &lang=de
38
+ =end
39
+ @@userId=request.env['HTTP_USERID']
40
+ if (@@userId.nil?)
41
+ @@userId="101"
42
+ end
43
+ # build up the various arguments in the adArgs hash
44
+ adArgs= SequencedHash.new
45
+ adArgs["pub"]="3517" # replace with real publisher ID
46
+ adArgs["adspace"]="137" # what is the ad space and published ID taht we need
47
+ adArgs["format"]="JPG"
48
+ adArgs["numads"]="1"
49
+ adArgs["offline"]="true"
50
+ adArgs["width"]="176" # get these from device capabilities service instead!
51
+ adArgs["height"]="208" # get these from device capabilities service instead
52
+ adArgs["response"]="XML"
53
+ adArgs["user"]=@@userId # user agent for our browser.
54
+ if (keywords)
55
+ adArgs["kws"]=CGI::escape(keywords)
56
+ end
57
+ # now built the URL to call out to based upon the base URL and ad hash
58
+ adURL=@@adServer + "?"
59
+ first=1 # dont put ampersand on first one
60
+ adArgs.each_key do |x|
61
+ if adArgs[x]
62
+ (adURL=adURL+"&") unless first
63
+ first=nil # start putting in &s
64
+ adURL = adURL + x + "=" + adArgs[x]
65
+ end
66
+ end
67
+ =begin
68
+ CALL:
69
+ http://dev.soma.smaato.com:8080/wap/reqAd.jsp?
70
+ pub=3517&adspace=0&format=JPG&numads=1&offline=false&width=100&height=100&response=XML&user=101&kws=India
71
+
72
+ =end
73
+ # ok, now call google's mobile adSense service and get back the full ad
74
+ @adxml=open(adURL).read
75
+ =begin
76
+ RESULT:
77
+ <?xml version="1.0"?><response xmlns="http://dev.soma.smaato.com:8080/wap/"
78
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
79
+ xsi:schemaLocation="http://dev.soma.smaato.com:8080/wap/ http://dev.soma.smaato.com:8080/wap/smaatoapi.xsd">
80
+ <event-response><status>error</status><error>375</error><desc>No request data found.</desc></event-response>
81
+ <status>success</status><user><id>101</id></user>
82
+ <ads>
83
+ <ad id="1358" type="JPEG" width="112" height="20" refresh="1206058763039" caching="false" priority="0">
84
+ <log-id>77bbb740be3c54debc5076f2be48df41</log-id><valid start="1204849163039" end="1212707963039" max="999999" />
85
+ <link>http://dev.soma.smaato.com:8080/wap/getAd.jsp?id=1358&amp;l=77bbb740be3c54debc5076f2be48df41&amp;o=false</link><action target="http://dev.soma.smaato.com:8080/wap/lp.jsp?id=1358&amp;l=77bbb740be3c54debc5076f2be48df41&amp;o=false&amp;a=6&amp;t=http://www.smaato.mobi" type="LINK" acc="server" />
86
+ <adtext />
87
+ </ad>
88
+ </ads>
89
+ </response>
90
+ =end
91
+ if (@adxml)
92
+ adDoc = REXML::Document.new @adxml
93
+ @adelement = adDoc.elements["//ad"]
94
+ if (@adelement)
95
+ @adurl=@adelement.elements["link"].text
96
+ @urltext=@adelement.elements["adtext"].text
97
+ @urltext||="LINK TO AD"
98
+ end
99
+ end
100
+ end
101
+
102
+
103
+
104
+ end
105
+ end
106
+ end
data/lib/rmobio/ads.rb ADDED
@@ -0,0 +1,24 @@
1
+ #
2
+ # Copyright (C) 2007 Mobio Networks, Inc.
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ #
17
+
18
+ =begin
19
+ note that we require use of the new Mobio config yml schema created by Lars
20
+ and documented at http://opssrv01/wiki/index.php/Mobio_Rails_Application_Framework_2.0#Use_Config_Manager
21
+ =end
22
+ adlib="rmobio/ads/" + MOBIO_CONFIG['ad_network']
23
+ require adlib
24
+ eval("include " + adlib.camelize)
@@ -0,0 +1,155 @@
1
+ #
2
+ # Copyright (C) 2007 Mobio Networks, Inc.
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ #
17
+
18
+ =begin
19
+ Some summary should go here
20
+ =end
21
+ require 'rmobio/utils'
22
+
23
+ module Rmobio
24
+ module Auth
25
+
26
+ def get_msisdn()
27
+
28
+ logHeaders()
29
+ msisdn=request.env["HTTP_X_MSISDN"]
30
+ msisdn=request.env["HTTP_X_NOKIA_MSISDN"] if msisdn ==nil
31
+ msisdn=request.env["HTTP_MSISDN"] if msisdn ==nil
32
+
33
+ if msisdn != nil
34
+ logger.debug "msisdn = #{msisdn}"
35
+ if msisdn.length == 11
36
+ msisdn=msisdn[1..-1]
37
+ end
38
+ if msisdn.length == 10
39
+ msisdn='91' + msisdn
40
+ end
41
+ end
42
+
43
+ if(msisdn!=nil)
44
+ if(msisdn.length == 12)
45
+ return msisdn
46
+ end
47
+ end
48
+ return ''
49
+
50
+ end
51
+ #== get_user_attributes
52
+ #=== To get Access Attribuest
53
+ #=== Sample device url:
54
+ # http://marge.mobiolabs.com/gateway/public/authorizationServices/getAccessAttributes?auth_identity=910000000000&domain=airtel
55
+ #=== Sample returned client info:
56
+ #<?xml version="1.0" encoding="UTF-8"?>
57
+ # <DomainAccessAttributes xmlns="http://mobio.net/ws/platform/schema/UserAccessAttributeService">
58
+ # <authorizationId>910000000000</authorizationId>
59
+ # <domain>airtel</domain>
60
+ # <attribute>ROLE_USER</attribute>
61
+ # <attribute>Second Attribute</attribute>
62
+ # </DomainAccessAttributes>
63
+
64
+ def get_user_attributes(user_access_att_url)
65
+ temp=Array.new
66
+ logger.debug("url= #{user_access_att_url}")
67
+ if user_access_att_url
68
+ doc = Hpricot(open(user_access_att_url))
69
+ doc.search("//attribute").each do |attributeElement|
70
+ logger.debug "att = #{attributeElement.innerHTML} "
71
+ temp<<attributeElement.innerHTML
72
+ end
73
+ end
74
+ temp
75
+ end
76
+ #== authorize filter
77
+ #== This filter will get the domain name from the request uri and application name from the environment setting.
78
+ # Then construct the application domain pair, like: "cricket-wap-airtel".
79
+ # The filter then check the session attribute of "shared_session_auth", and compare with the application domain pair.
80
+ # If the session attribute doesn't match the application domain pair, it will call the getUserAccessAttribute from
81
+ # gateway. and store into the session. If the new accessAttribute match the app-domain pair, filter the chain.
82
+ # If no, redirect to auth application.
83
+ #
84
+ #==
85
+
86
+ def authorize
87
+ logger.debug('authorize filter:')
88
+ if params[:burl]
89
+ burl =params[:burl].gsub(/&/,'&amp;')
90
+ else
91
+ burl= ''
92
+ end
93
+ #get domain from url
94
+ #req_url=request.request_uri
95
+ #token_list = []
96
+ #tokenize(req_url) do |token|
97
+ # token_list << token
98
+ #end
99
+ surl=request.protocol + request.host_with_port + request.request_uri
100
+ logger.debug(" surl 0-=== #{surl}")
101
+ uritokens = request.request_uri.split('/')
102
+ domain=''
103
+ uritokens.each_with_index do |w,index|
104
+ if(w=='w')
105
+ domain =uritokens[index+1]
106
+ end
107
+ end
108
+
109
+ no_auth_domains =MOBIO_CONFIG['no_auth_domains']
110
+ if (no_auth_domains != nil)
111
+ no_auth_domains.each do |d|
112
+ if(domain == d)
113
+ logger.debug("No auth for domain: #{d}")
114
+ return
115
+ end
116
+ end
117
+ end
118
+ logger.debug("Here is the interpreted new domain: #{domain}")
119
+ #get label from env
120
+ #label=$env['APP_LABEL']
121
+ label= MOBIO_CONFIG['app_label']
122
+ logger.debug("here is the label #{label}")
123
+ label_domain=label +'-wap-'+domain
124
+ if (session[:shared_session_auth])
125
+ attributes=session[:shared_session_auth]
126
+ attributes.each do |attr|
127
+ logger.debug("attribute #{attr}")
128
+ if(attr==label_domain)
129
+ logger.debug('find good')
130
+ #for debug
131
+ #session[:shared_session_auth]=nil
132
+ return
133
+ end
134
+ end
135
+ end
136
+ logger.debug('get result')
137
+ user_access_att_url= MOBIO_CONFIG['http_access_attribute_service_url'] + get_msisdn() + '&domain=' + domain
138
+ result=get_user_attributes(user_access_att_url)
139
+ logger.debug("result = #{result[0]}")
140
+ session[:shared_session_auth]=result
141
+ result.each do |attr|
142
+ logger.debug("attribute #{attr}")
143
+ if(attr==label_domain)
144
+ logger.debug('find good finally')
145
+ return
146
+ end
147
+ end
148
+ auth_app_url=MOBIO_CONFIG['authorization_app_url'] + '?label=' + label + '&domain=' + domain + '&burl=' + burl + '&surl=' + surl
149
+ redirect_to("#{auth_app_url}")
150
+
151
+ end
152
+
153
+ end #end Auth
154
+
155
+ end #end Mobio
data/lib/rmobio/cas.rb ADDED
@@ -0,0 +1,24 @@
1
+ #
2
+ # Copyright (C) 2007 Mobio Networks, Inc.
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ #
17
+
18
+ module Rmobio
19
+ module Cas
20
+ class MobioServiceTicketValidator < CAS::ServiceTicketValidator
21
+
22
+ end
23
+ end
24
+ end