*** schoolserver-orig.py	2009-06-01 22:01:27.000000000 +0800
--- schoolserver.py	2009-06-01 22:18:04.000000000 +0800
***************
*** 1,3 ****
--- 1,19 ----
+ # Copyright (C) 2007, 2008 One Laptop Per Child
+ #
+ # This program is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU General Public License as published by
+ # the Free Software Foundation; either version 2 of the License, or
+ # (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+ # along with this program; if not, write to the Free Software
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ 
  import logging
  from gettext import gettext as _
  from xmlrpclib import ServerProxy, Error
***************
*** 5,30 ****
  import os
  import gconf
  
  from sugar.profile import get_profile
  
  REGISTER_URL = 'http://schoolserver:8080/'
  
  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()
      nick = client.get_string('/desktop/sugar/user/nick')
  
      server = ServerProxy(url)
--- 21,120 ----
  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
+ 
+ # taken from the XS server /home/idmgr/test/local-register ********************
+ 
+ def fake_serial():
+     return ''.join([random.choice(string.ascii_uppercase) for y in range(3)] +
+                    [random.choice('01234567890') for y in range(8)])
+ def fake_uuid():
+     return ''.join([random.choice(string.hexdigits + '-') for y in range(40)])
+ 
+ # 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
+ # - we get the strings from the mac address
+ # - remove ':' from the mac address string
+ # - concat with random hexdigits to get 40 hex chars
+ 
+ def gen_soas_uuid():
+   u1 = getMacAddress().replace(':','');
+   u1_count = 40 - len(u1)
+   u2 = ''.join([random.choice(string.hexdigits + '-') for y in range(int(u1_count))])
+   uuid = u1 + u2
+   return uuid
+ 
+ # ******************************************************************************
+ 
  class RegisterError(Exception):
      pass
  
  def register_laptop(url=REGISTER_URL):
  
      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)
+     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)
