File: auth.rb

package info (click to toggle)
geotoad 3.9.0-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 840 kB
  • ctags: 170
  • sloc: ruby: 3,297; makefile: 30
file content (53 lines) | stat: -rw-r--r-- 1,654 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# $Id: auth.rb 557 2006-03-09 03:18:21Z thomas $

module Auth
    include Common
    include Display
    
    def login(user, password)
        debug "login called for user=#{user} pass=#{password}"
        getLoginValues
        cookie = getLoginCookie(user, password)
        return cookie
    end
    
    def getLoginValues
        @postVars = Hash.new
        
        page = ShadowFetch.new('http://www.geocaching.com/login/')
        data = page.fetch
        
        data.each do |line| 
            case line
            when /^\<input type=\"hidden\" name=\"(.*?)\" value=\"(.*?)\" \/\>/
                debug "found hidden post variable: #{$1}"
                @postVars[$1]=$2
            when /\<form name=\"frmLogin\" method=\"post\" action=\"(.*?)\"/
                @postURL='http://www.geocaching.com/login/' + $1
                @postURL.gsub!('&amp;', '&')
                debug "post URL is #{@postURL}"
            end
        end
    end
    
    def getLoginCookie(user, password)
        page = ShadowFetch.new(@postURL)
        page.localExpiry=1
        @postVars['myUsername']=user
        @postVars['myPassword']=password
        @postVars['cookie']='on'
        @postVars['Button1']='Login'
        page.postVars=@postVars
        data = page.fetch
        cookie = page.cookie
        debug "getLoginCookie got cookie: #{cookie}"
        if (cookie =~ /userid/) && (cookie =~ /(ASP.NET_SessionId=\w+)/) 
            debug "userid found in cookie, rock on. Setting session to #{$1}"
            cookie=$1
            return cookie
        else
            debug "login failed"
            return nil
        end
    end
end