Martin Langhoff wrote:
On Fri, Feb 13, 2009 at 12:19 AM, Simon Schampijer <si...@schampijer.de> wrote:
When thinking about it a bit more - the big plus with your approach that
it's only affects Browse - code wise, which is when back porting to 0.82 a
big plus, actually maybe the only way.
Bingo! I think you're starting to read my mind...
m
Please find attached the patch against master.
- i use the backup_url to see if we are associated with a schoolserver
- why did you use the jabber server for this 'xs_fqdn = prof.jabber_server'?
- c.execute('''CREATE TABLE IF NOT EXISTS
+ moz_cookies
+ (id INTEGER PRIMARY KEY,
+ name TEXT,
+ value TEXT,
+ host TEXT,
+ path TEXT,
+ expiry INTEGER,
+ lastAccessed INTEGER,
+ isSecure INTEGER,
+ isHttpOnly INTEGER);''')
- is the ';' correct here or a typo?
- i only except for sqlite3.Error
- what bothers me a bit is that you don't get an error when the database
does not exist - sqlite creates a new one actually - so we might return
as well on 'if not os.path.exists(os.path.join(_profile_path,
'cookies.sqlite'))'
- the method could even be a function as it does not interact at all
with the class itself, not sure what is nicer
Best,
Simon
diff --git a/webactivity.py b/webactivity.py
index f7f2459..e283cb5 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -26,7 +26,10 @@ import sha
import base64
import time
import shutil
-
+import sqlite3
+import cjson
+import gconf
+
from sugar.activity import activity
from sugar.graphics import style
import telepathy
@@ -96,6 +99,8 @@ class WebActivity(activity.Activity):
self._browser = Browser()
+ self._seed_xs_cookie()
+
toolbox = activity.ActivityToolbox(self)
self._edit_toolbar = EditToolbar(self._browser)
@@ -465,3 +470,55 @@ class WebActivity(activity.Activity):
def get_document_path(self, async_cb, async_err_cb):
self._browser.get_source(async_cb, async_err_cb)
+ def _seed_xs_cookie(self):
+ ''' Create a HTTP Cookie to authenticate with the Schoolserver
+ '''
+ client = gconf.client_get_default()
+ backup_url = client.get_string('/desktop/sugar/backup_url')
+ if not backup_url:
+ _logger.debug('seed_xs_cookie: Not registered with Schoolserver')
+ return
+
+ pubkey = profile.get_profile().pubkey
+ cookie_data = {'color': profile.get_color().to_string(),
+ 'pkey_hash': sha.new(pubkey).hexdigest()}
+
+ db_path = os.path.join(_profile_path, 'cookies.sqlite')
+ try:
+ cookies_db = sqlite3.connect(db_path)
+ c = cookies_db.cursor()
+
+ c.execute('''CREATE TABLE IF NOT EXISTS
+ moz_cookies
+ (id INTEGER PRIMARY KEY,
+ name TEXT,
+ value TEXT,
+ host TEXT,
+ path TEXT,
+ expiry INTEGER,
+ lastAccessed INTEGER,
+ isSecure INTEGER,
+ isHttpOnly INTEGER)''')
+
+ c.execute('''SELECT id
+ FROM moz_cookies
+ WHERE name=? AND host=? AND path=?''',
+ ('xoid', backup_url, '/'))
+
+ if c.fetchone():
+ _logger.debug('seed_xs_cookie: Cookie exists already')
+ return
+
+ expire = int(time.time()) + 10*365*24*60*60
+ c.execute('''INSERT INTO moz_cookies (name, value, host,
+ path, expiry, lastAccessed,
+ isSecure, isHttpOnly)
+ VALUES(?,?,?,?,?,?,?,?)''',
+ ( 'xoid', cjson.encode(cookie_data), backup_url,
+ '/', expire, 0, 0, 0 ))
+ cookies_db.commit()
+ cookies_db.close()
+ except sqlite3.Error, e:
+ _logger.error('seed_xs_cookie: %s' % e)
+ else:
+ _logger.debug('seed_xs_cookie: Updated cookie successfully')
_______________________________________________
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel