summaryrefslogtreecommitdiff
path: root/dev-python/pygooglevoice/files/pygooglevoice-0.5-auth.patch
blob: fbbadbac7a5ff2edf1f15ae2a6dd5613ed1866b8 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
--- pygooglevoice-0.5.orig/bin/asterisk-gvoice-setup
+++ pygooglevoice-0.5/bin/asterisk-gvoice-setup
@@ -66,6 +66,7 @@
 exten => _X.,n,System(gvoice -b -e \${ACCTNAME} -p \${ACCTPASS} call \${EXTEN} \${RINGBACK})
 exten => _X.,n,Set(PARKINGEXTEN=\${CALLPARK})
 exten => _X.,n,Park()
+exten => _X.,n,ParkAndAnnounce(pbx-transfer:PARKED|45|Console/dsp)
 
 [custom-park]
 exten => s,1,Wait(4)
--- pygooglevoice-0.5.orig/googlevoice/settings.py
+++ pygooglevoice-0.5/googlevoice/settings.py
@@ -19,7 +19,8 @@
 """
 
 DEBUG = False
-LOGIN = 'https://www.google.com/accounts/ServiceLoginAuth?service=grandcentral'
+LOGIN = 'https://www.google.com/accounts/ClientLogin'
+SERVICE = 'grandcentral'
 FEEDS = ('inbox', 'starred', 'all', 'spam', 'trash', 'voicemail', 'sms',
         'recorded', 'placed', 'received', 'missed')
 
@@ -50,4 +51,4 @@
 XML_RECORDED = XML_RECENT + 'recorded/'
 XML_PLACED = XML_RECENT + 'placed/'
 XML_RECEIVED = XML_RECENT + 'received/'
-XML_MISSED = XML_RECENT + 'missed/'
\ No newline at end of file
+XML_MISSED = XML_RECENT + 'missed/'
--- pygooglevoice-0.5.orig/googlevoice/util.py
+++ pygooglevoice-0.5/googlevoice/util.py
@@ -6,11 +6,11 @@
 from pprint import pprint
 try:
     from urllib2 import build_opener,install_opener, \
-        HTTPCookieProcessor,Request,urlopen
+        HTTPCookieProcessor,Request,urlopen,HTTPError
     from urllib import urlencode,quote
 except ImportError:
     from urllib.request import build_opener,install_opener, \
-        HTTPCookieProcessor,Request,urlopen
+        HTTPCookieProcessor,Request,urlopen,HTTPError
     from urllib.parse import urlencode,quote
 try:
     from http.cookiejar import LWPCookieJar as CookieJar
--- pygooglevoice-0.5.orig/googlevoice/voice.py
+++ pygooglevoice-0.5/googlevoice/voice.py
@@ -39,7 +39,8 @@
         except NameError:
             regex = r"('_rnr_se':) '(.+)'"
         try:
-            sp = re.search(regex, urlopen(settings.INBOX).read()).group(2)
+            response = self.__do_page('inbox', data=None, headers = {'Authorization': 'GoogleLogin auth=%s' % self._auth })
+            sp = re.search(regex, response.read()).group(2)
         except AttributeError:
             sp = None
         self._special = sp
@@ -65,12 +66,19 @@
             from getpass import getpass
             passwd = getpass()
 
-        content = self.__do_page('login').read()
-        # holy hackjob
-        galx = re.search(r"name=\"GALX\"\s+value=\"(.+)\"", content).group(1)
-        self.__do_page('login', {'Email': email, 'Passwd': passwd, 'GALX': galx})
-        
-        del email, passwd
+        response = self.__do_page('login', {'accountType': 'HOSTED_OR_GOOGLE' ,'Email': email, 'Passwd': passwd, 'service': 'grandcentral' })
+
+        respMap = dict( line.strip().split('=', 1) for line in response.readlines() )
+        response.close()
+
+        if respMap.has_key('Auth'):
+            self._auth = respMap['Auth']
+        elif respMap.has_key('Error'):
+            if respMap['Error'] == 'CaptchaRequired':
+                raise LoginError('Clear the captcha at: %s' % respMap['Url'])
+            raise LoginError(respMap['Error'])
+
+        del email, passwd, respMap
         
         try:
             assert self.special
@@ -84,7 +92,7 @@
         Logs out an instance and makes sure it does not still have a session
         """
         self.__do_page('logout')
-        del self._special 
+        del self._special, self._auth 
         assert self.special == None
         return self
         
@@ -200,7 +208,11 @@
             return urlopen(Request(getattr(settings, page) + data, None, headers))
         if data:
             headers.update({'Content-type': 'application/x-www-form-urlencoded;charset=utf-8'})
-        return urlopen(Request(getattr(settings, page), data, headers))
+            headers.update({'Content-length': '%d' % len(data)})
+        try:
+            return urlopen(Request(getattr(settings, page), data, headers))
+        except (HTTPError), e:
+            return e
 
     def __validate_special_page(self, page, data={}, **kwargs):
         """
@@ -215,11 +227,14 @@
         """
         Add self.special to request data
         """
-        assert self.special, 'You must login before using this page'
+        assert self.special and self._auth, 'You must login before using this page'
         if isinstance(data, tuple):
             data += ('_rnr_se', self.special)
         elif isinstance(data, dict):
             data.update({'_rnr_se': self.special})
+
+        headers.update({'Authorization': 'GoogleLogin auth=%s' % self._auth})
+
         return self.__do_page(page, data, headers)
         
     _Phone__do_special_page = __do_special_page