1 | *** schoolserver-orig.py 2009-06-01 22:01:27.000000000 +0800 |
---|
2 | --- schoolserver.py 2009-06-01 22:18:04.000000000 +0800 |
---|
3 | *************** |
---|
4 | *** 1,3 **** |
---|
5 | --- 1,19 ---- |
---|
6 | + # Copyright (C) 2007, 2008 One Laptop Per Child |
---|
7 | + # |
---|
8 | + # This program is free software; you can redistribute it and/or modify |
---|
9 | + # it under the terms of the GNU General Public License as published by |
---|
10 | + # the Free Software Foundation; either version 2 of the License, or |
---|
11 | + # (at your option) any later version. |
---|
12 | + # |
---|
13 | + # This program is distributed in the hope that it will be useful, |
---|
14 | + # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | + # GNU General Public License for more details. |
---|
17 | + # |
---|
18 | + # You should have received a copy of the GNU General Public License |
---|
19 | + # along with this program; if not, write to the Free Software |
---|
20 | + # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
21 | + |
---|
22 | import logging |
---|
23 | from gettext import gettext as _ |
---|
24 | from xmlrpclib import ServerProxy, Error |
---|
25 | *************** |
---|
26 | *** 5,30 **** |
---|
27 | import os |
---|
28 | import gconf |
---|
29 | |
---|
30 | from sugar.profile import get_profile |
---|
31 | |
---|
32 | REGISTER_URL = 'http://schoolserver:8080/' |
---|
33 | |
---|
34 | class RegisterError(Exception): |
---|
35 | pass |
---|
36 | |
---|
37 | def register_laptop(url=REGISTER_URL): |
---|
38 | - if not have_ofw_tree(): |
---|
39 | - logging.error('Registration: Cannot obtain data needed to register.') |
---|
40 | - raise RegisterError(_('Cannot obtain data needed for registration.')) |
---|
41 | - |
---|
42 | - sn = read_ofw('mfg-data/SN') |
---|
43 | - uuid = read_ofw('mfg-data/U#') |
---|
44 | - sn = sn or 'SHF00000000' |
---|
45 | - uuid = uuid or '00000000-0000-0000-0000-000000000000' |
---|
46 | |
---|
47 | profile = get_profile() |
---|
48 | |
---|
49 | client = gconf.client_get_default() |
---|
50 | nick = client.get_string('/desktop/sugar/user/nick') |
---|
51 | |
---|
52 | server = ServerProxy(url) |
---|
53 | --- 21,120 ---- |
---|
54 | import os |
---|
55 | import gconf |
---|
56 | |
---|
57 | + import string, random, time |
---|
58 | + import subprocess |
---|
59 | + |
---|
60 | + import time |
---|
61 | + import datetime |
---|
62 | + |
---|
63 | from sugar.profile import get_profile |
---|
64 | |
---|
65 | REGISTER_URL = 'http://schoolserver:8080/' |
---|
66 | |
---|
67 | + # HAM : SoaS |
---|
68 | + # (ham@solutiongrove.com) |
---|
69 | + # defs to enable registration on SoaS |
---|
70 | + |
---|
71 | + # taken from the XS server /home/idmgr/test/local-register ******************** |
---|
72 | + |
---|
73 | + def fake_serial(): |
---|
74 | + return ''.join([random.choice(string.ascii_uppercase) for y in range(3)] + |
---|
75 | + [random.choice('01234567890') for y in range(8)]) |
---|
76 | + def fake_uuid(): |
---|
77 | + return ''.join([random.choice(string.hexdigits + '-') for y in range(40)]) |
---|
78 | + |
---|
79 | + # utilities ******************************************************************** |
---|
80 | + |
---|
81 | + def getEpoch(): |
---|
82 | + t = datetime.datetime.now() |
---|
83 | + e = time.mktime(t.timetuple()) |
---|
84 | + return e |
---|
85 | + |
---|
86 | + def getMacAddress(): |
---|
87 | + for line in os.popen("/sbin/ifconfig"): |
---|
88 | + if line.find('Ether') > -1: |
---|
89 | + mac = line.split()[4] |
---|
90 | + break |
---|
91 | + return mac |
---|
92 | + |
---|
93 | + # generates the serial and uuid ************************************************ |
---|
94 | + |
---|
95 | + # to create a unique serial |
---|
96 | + # - we randomly get 3 letters |
---|
97 | + # - concat the above with the last 8 numbers from epoch seconds |
---|
98 | + |
---|
99 | + def gen_soas_serial(): |
---|
100 | + s1 = ''.join([random.choice(string.ascii_uppercase) for y in range(3)]) |
---|
101 | + s2 = str(int(getEpoch()))[-8:] |
---|
102 | + serial = s1 + s2 |
---|
103 | + return serial |
---|
104 | + |
---|
105 | + # to create a unique uuid |
---|
106 | + # - we get the strings from the mac address |
---|
107 | + # - remove ':' from the mac address string |
---|
108 | + # - concat with random hexdigits to get 40 hex chars |
---|
109 | + |
---|
110 | + def gen_soas_uuid(): |
---|
111 | + u1 = getMacAddress().replace(':',''); |
---|
112 | + u1_count = 40 - len(u1) |
---|
113 | + u2 = ''.join([random.choice(string.hexdigits + '-') for y in range(int(u1_count))]) |
---|
114 | + uuid = u1 + u2 |
---|
115 | + return uuid |
---|
116 | + |
---|
117 | + # ****************************************************************************** |
---|
118 | + |
---|
119 | class RegisterError(Exception): |
---|
120 | pass |
---|
121 | |
---|
122 | def register_laptop(url=REGISTER_URL): |
---|
123 | |
---|
124 | profile = get_profile() |
---|
125 | |
---|
126 | client = gconf.client_get_default() |
---|
127 | + |
---|
128 | + if not have_ofw_tree(): |
---|
129 | + # logging.error('Registration: Cannot obtain data needed to register.') |
---|
130 | + # raise RegisterError(_('Cannot obtain data needed for registration.')) |
---|
131 | + |
---|
132 | + # HAM : SoaS |
---|
133 | + # if we did not find an ofw directory |
---|
134 | + # let's generate the serial and uuid from the current time and mac address |
---|
135 | + # save the generated serial and uuid into gconf |
---|
136 | + |
---|
137 | + sn = gen_soas_serial() |
---|
138 | + uuid = gen_soas_uuid() |
---|
139 | + |
---|
140 | + # we need to save these for later use |
---|
141 | + # we need them to work with backups |
---|
142 | + |
---|
143 | + client.set_string('/desktop/sugar/soas_serial', sn) |
---|
144 | + client.set_string('/desktop/sugar/soas_uuid', uuid) |
---|
145 | + else: |
---|
146 | + sn = read_ofw('mfg-data/SN') |
---|
147 | + uuid = read_ofw('mfg-data/U#') |
---|
148 | + sn = sn or 'SHF00000000' |
---|
149 | + uuid = uuid or '00000000-0000-0000-0000-000000000000' |
---|
150 | + |
---|
151 | nick = client.get_string('/desktop/sugar/user/nick') |
---|
152 | |
---|
153 | server = ServerProxy(url) |
---|