| 34 | # SoaS: ham@solutiongrove.com |
| 35 | # defs to enable registration on SoaS |
| 36 | |
| 37 | # utilities ******************************************************************** |
| 38 | |
| 39 | def 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 | |
| 50 | def 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 | |
| 58 | def 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 | |
| 65 | def 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 | |
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' |