--- schoolserver.py.orig	2009-07-25 16:25:35.684441380 +0800
+++ schoolserver.py	2009-07-24 21:41:11.977611098 +0800
@@ -21,26 +21,118 @@
 import os
 import gconf
 
+import string, random, time
+import subprocess
+
+import time
+import datetime
+
 from sugar.profile import get_profile
 
-REGISTER_URL = 'http://schoolserver:8080/'
+# HAM : SoaS
+# (ham@solutiongrove.com)
+# defs to enable registration on SoaS
+
+# use whatever is specified in the jabber server field for REGISTER_URL
+# REGISTER_URL = 'http://schoolserver:8080/'
+client = gconf.client_get_default()
+REGISTER_URL = 'http://'+client.get_string('/desktop/sugar/collaboration/jabber_server')+':8080/'
+
+# utilities ********************************************************************
+
+def getEpoch():
+  t = datetime.datetime.now()
+  e = time.mktime(t.timetuple())  
+  return e
+
+def getMacAddress():
+  for line in os.popen("/sbin/ifconfig"):
+    if line.find('Ether') > -1:
+      mac = line.split()[4]
+      break
+  return mac 
+
+# generates the serial and uuid ************************************************
+
+# to create a unique serial
+# - we randomly get 3 letters
+# - concat the above with the last 8 numbers from epoch seconds
+
+def gen_soas_serial():
+  s1 = ''.join([random.choice(string.ascii_uppercase) for y in range(3)])
+  s2 = str(int(getEpoch()))[-8:]
+  serial = s1 + s2 
+  return serial
+
+# to create a unique uuid
+# - create uuid using random hexdigits up to 40 characters
+
+def gen_soas_uuid():
+  u1_count = 40 
+  uuid = ''.join([random.choice(string.hexdigits + '-') for y in range(int(u1_count))])
+  return uuid
+
+# write serial and uuid to file ************************************************
+
+def write_soas_info(sn,uuid):
+  # we presume that there is a /home/liveuser/.sugar directory
+  soas_dir = '/home/liveuser/.sugar/soas/'
+  # create the directory where we will put the files
+  if not os.path.exists(soas_dir):
+    os.mkdir(soas_dir)
+  # check if a serial file exists, it might be from a failed registration
+  # let's delete it first
+  if os.path.exists(os.path.join(soas_dir, 'sn')):
+    os.remove(os.path.join(soas_dir, 'sn'))
+  # write the serial into a file
+  serial_file = open(os.path.join(soas_dir, 'sn'),'w')
+  serial_file.write(sn)
+  serial_file.close()
+  # check if a uuid file exists, it might be from a failed registration
+  # let's delete it first
+  if os.path.exists(os.path.join(soas_dir, 'uuid')):
+    os.remove(os.path.join(soas_dir, 'uuid'))
+  # write the uuid into a file
+  uuid_file = open(os.path.join(soas_dir, 'uuid'),'w')
+  uuid_file.write(uuid)
+  uuid_file.close()
+
+# ******************************************************************************
 
 class RegisterError(Exception):
     pass
 
 def register_laptop(url=REGISTER_URL):
-    if not have_ofw_tree():
-        logging.error('Registration: Cannot obtain data needed to register.')
-        raise RegisterError(_('Cannot obtain data needed for registration.'))
-
-    sn = read_ofw('mfg-data/SN')
-    uuid = read_ofw('mfg-data/U#')
-    sn = sn or 'SHF00000000'
-    uuid = uuid or '00000000-0000-0000-0000-000000000000'
 
     profile = get_profile()
 
     client = gconf.client_get_default()
+
+    if not have_ofw_tree():
+        # logging.error('Registration: Cannot obtain data needed to register.')
+        # raise RegisterError(_('Cannot obtain data needed for registration.'))
+
+        # HAM : SoaS 
+        # if we did not find an ofw directory
+        # let's generate the serial and uuid from the current time and mac address
+        # save the generated serial and uuid into gconf
+
+        sn = gen_soas_serial()
+        uuid = gen_soas_uuid()
+
+        # we need to save these for later use
+        # we need them to work with backups
+        # client.set_string('/desktop/sugar/soas_serial', sn)
+        # client.set_string('/desktop/sugar/soas_uuid', uuid)
+
+        write_soas_info(sn,uuid)
+
+    else:
+        sn = read_ofw('mfg-data/SN')
+        uuid = read_ofw('mfg-data/U#')
+        sn = sn or 'SHF00000000'
+        uuid = uuid or '00000000-0000-0000-0000-000000000000'
+
     nick = client.get_string('/desktop/sugar/user/nick')
 
     server = ServerProxy(url)
