Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/cookiemagic.py
diff options
context:
space:
mode:
Diffstat (limited to 'cookiemagic.py')
-rw-r--r--cookiemagic.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/cookiemagic.py b/cookiemagic.py
new file mode 100644
index 0000000..de1b024
--- /dev/null
+++ b/cookiemagic.py
@@ -0,0 +1,57 @@
+import logging
+from gettext import gettext as _
+import re
+
+import sha
+import xmlrpclib
+import gconf
+import os
+import base64
+import time
+import shutil
+import cjson
+
+from sugar import profile
+
+class XSCookieTransport(xmlrpclib.Transport):
+ XSCOOKIE = 'xoid'
+ def __init__(self, SESSION_ID_STRING='PHPSESSID'):
+ xmlrpclib.Transport.__init__(self)
+ self.mycookies=None
+ self.mysessid=None
+ self.SESSION_ID_STRING = SESSION_ID_STRING
+
+ def request(self, host, handler, request_body, verbose=0):
+ # issue XML-RPC request
+ h = self.make_connection(host)
+ if verbose:
+ h.set_debuglevel(1)
+ self.send_request(h, handler, request_body)
+ self.send_host(h, host)
+ h.putheader("Cookie", "%s=%s" % ('xoid',self.__get_xs_cookie()) )
+ self.send_content(h, request_body)
+ errcode, errmsg, headers = h.getreply()
+ if errcode != 200:
+ raise xmlrpclib.ProtocolError(
+ host + handler,
+ errcode, errmsg,
+ headers )
+ self.verbose = verbose
+ try:
+ sock = h._conn.sock
+ except AttributeError:
+ sock = None
+ return self._parse_response(h.getfile(), sock)
+
+ def __get_xs_cookie(self,):
+ ''' Create a HTTP Cookie to authenticate with the Schoolserver
+ '''
+ # Get Sugar's public key, and use its hash and the colors as the cookie
+ pubkey = profile.get_profile().pubkey
+ cookie_data = {'color': profile.get_color().to_string(),
+ 'pkey_hash': sha.new(pubkey).hexdigest()}
+
+
+ cookie = cjson.encode(cookie_data)
+
+ return cookie \ No newline at end of file