Ticket #916: 0001-allow-sugar-on-a-stick-to-register-with-an-xs-server.patch

File 0001-allow-sugar-on-a-stick-to-register-with-an-xs-server.patch, 4.5 KB (added by hamiltonchua, 15 years ago)
  • src/jarabe/desktop/schoolserver.py

    From e25872187429fb6f4d2379a98a5c8fb3bc93fa12 Mon Sep 17 00:00:00 2001
    From: Hamilton Chua <hchua@enterprise2.localdomain>
    Date: Sun, 9 Aug 2009 12:39:12 +0800
    Subject: [PATCH] allow sugar on a stick to register with an xs server
    
    ---
     src/jarabe/desktop/schoolserver.py |  106 +++++++++++++++++++++++++++++++++---
     1 files changed, 98 insertions(+), 8 deletions(-)
    
    diff --git a/src/jarabe/desktop/schoolserver.py b/src/jarabe/desktop/schoolserver.py
    index 1dd9edc..2ec5a06 100644
    a b import socket 
    2121import os
    2222import gconf
    2323
     24import string, random, time
     25import subprocess
     26
     27import time
     28import datetime
     29
    2430from sugar.profile import get_profile
    2531
    2632REGISTER_URL = 'http://schoolserver:8080/'
    2733
     34# SoaS: ham@solutiongrove.com
     35# defs to enable registration on SoaS
     36
     37# utilities ********************************************************************
     38
     39def getEpoch():
     40  t = datetime.datetime.now()
     41  e = time.mktime(t.timetuple()) 
     42  return e
     43
     44# generates the serial and uuid ************************************************
     45
     46# to create a unique serial
     47# - we randomly get 3 letters
     48# - concat the above with the last 8 numbers from epoch seconds
     49
     50def gen_soas_serial():
     51  s1 = ''.join([random.choice(string.ascii_uppercase) for y in range(3)])
     52  s2 = str(int(getEpoch()))[-8:]
     53  serial = s1 + s2
     54  return serial
     55
     56# to create a unique uuid
     57
     58def gen_soas_uuid():
     59  u1_count = 40
     60  uuid = ''.join([random.choice(string.hexdigits + '-') for y in range(int(u1_count))])
     61  return uuid
     62
     63# write serial and uuid to file ************************************************
     64
     65def write_soas_info(sn,uuid,backup_url):
     66  # we presume that there is a /home/liveuser/.sugar directory
     67  soas_dir = '/home/liveuser/.sugar/soas/'
     68  # create the directory where we will put the files
     69  if not os.path.exists(soas_dir):
     70    os.mkdir(soas_dir)
     71  # check if a serial file exists, it might be from a failed registration
     72  # let's delete it first
     73  if os.path.exists(os.path.join(soas_dir, 'sn')):
     74    os.remove(os.path.join(soas_dir, 'sn'))
     75  # write the serial into a file
     76  serial_file = open(os.path.join(soas_dir, 'sn'),'w')
     77  serial_file.write(sn)
     78  serial_file.close()
     79  # check if a uuid file exists, it might be from a failed registration
     80  # let's delete it first
     81  if os.path.exists(os.path.join(soas_dir, 'uuid')):
     82    os.remove(os.path.join(soas_dir, 'uuid'))
     83  # write the uuid into a file
     84  uuid_file = open(os.path.join(soas_dir, 'uuid'),'w')
     85  uuid_file.write(uuid)
     86  uuid_file.close()
     87  if os.path.exists(os.path.join(soas_dir, 'backup_url')):
     88    os.remove(os.path.join(soas_dir, 'backup_url'))
     89  # write the backup_url to a file
     90  bu_file = open(os.path.join(soas_dir, 'backup_url'),'w')
     91  bu_file.write(backup_url)
     92  bu_file.close()
     93
     94# ******************************************************************************
     95
    2896class RegisterError(Exception):
    2997    pass
    3098
    3199def register_laptop(url=REGISTER_URL):
     100
     101    profile = get_profile()
     102    client = gconf.client_get_default()
     103
    32104    if not have_ofw_tree():
    33         logging.error('Registration: Cannot obtain data needed to register.')
    34         raise RegisterError(_('Cannot obtain data needed for registration.'))
     105        # logging.error('Registration: Cannot obtain data needed to register.')
     106        # raise RegisterError(_('Cannot obtain data needed for registration.'))
    35107
    36     sn = read_ofw('mfg-data/SN')
    37     uuid = read_ofw('mfg-data/U#')
    38     sn = sn or 'SHF00000000'
    39     uuid = uuid or '00000000-0000-0000-0000-000000000000'
     108        # SoaS  :
     109        # if we did not find an ofw directory
     110        # let's generate the serial and uuid from the current time
     111        # save the generated serial and uuid into files
    40112
    41     profile = get_profile()
     113        sn = gen_soas_serial()
     114        uuid = gen_soas_uuid()
     115
     116        # we want to use the text in the jabber server as our registration url
     117
     118        JABBER_SERVER = client.get_string('/desktop/sugar/collaboration/jabber_server')
     119
     120        # we need to save sn and uuid to work with backups
     121
     122        write_soas_info(sn,uuid,JABBER_SERVER)
     123
     124        # override the registration url to use
     125
     126        url = 'http://'+JABBER_SERVER+':8080/'
     127
     128    else:
     129        sn = read_ofw('mfg-data/SN')
     130        uuid = read_ofw('mfg-data/U#')
     131        sn = sn or 'SHF00000000'
     132        uuid = uuid or '00000000-0000-0000-0000-000000000000'
    42133
    43     client = gconf.client_get_default()
    44134    nick = client.get_string('/desktop/sugar/user/nick')
    45135
    46136    server = ServerProxy(url)