def create_profile(name, color=None): if not color: color = XoColor() client = GConf.Client.get_default() client.set_string('/desktop/sugar/user/nick', name) client.set_string('/desktop/sugar/user/color', color.to_string()) client.suggest_sync() if profile.get_pubkey() and profile.get_profile().privkey_hash: logging.info('Valid key pair found, skipping generation.') return # Generate keypair import commands keypath = os.path.join(env.get_profile_path(), 'owner.key') if os.path.exists(keypath): os.rename(keypath, keypath + '.broken') logging.warning('Existing private key %s moved to %s.broken', keypath, keypath) if os.path.exists(keypath + '.pub'): os.rename(keypath + '.pub', keypath + '.pub.broken') logging.warning('Existing public key %s.pub moved to %s.pub.broken', keypath, keypath) logging.debug("Generating user keypair") cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % (keypath, ) (s, o) = commands.getstatusoutput(cmd) if s != 0: logging.error('Could not generate key pair: %d %s', s, o) logging.debug("User keypair generated")
def _ensure_server_account(self, account_paths): for account_path in account_paths: if "gabble" in account_path: logging.debug("Already have a Gabble account") account = _Account(account_path) account.enable() return account logging.debug("Still dont have a Gabble account, creating one") nick = self._settings_user.get_string("nick") server = self._settings_collaboration.get_string("jabber-server") key_hash = get_profile().privkey_hash params = { "account": self._get_jabber_account_id(), "password": key_hash, "server": server, "resource": "sugar", "require-encryption": True, "ignore-ssl-errors": True, "register": True, "old-ssl": True, "port": dbus.UInt32(5223), } properties = {ACCOUNT + ".Enabled": True, ACCOUNT + ".Nickname": nick, ACCOUNT + ".ConnectAutomatically": True} bus = dbus.Bus() obj = bus.get_object(ACCOUNT_MANAGER_SERVICE, ACCOUNT_MANAGER_PATH) account_manager = dbus.Interface(obj, ACCOUNT_MANAGER) account_path = account_manager.CreateAccount("gabble", "jabber", "jabber", params, properties) return _Account(account_path)
def __init__(self): BaseBuddyModel.__init__(self) client = GConf.Client.get_default() self.props.nick = client.get_string('/desktop/sugar/user/nick') color = client.get_string('/desktop/sugar/user/color') self.props.color = XoColor(color) self.props.key = get_profile().pubkey self.connect('notify::nick', self.__property_changed_cb) self.connect('notify::color', self.__property_changed_cb) bus = dbus.SessionBus() bus.add_signal_receiver( self.__name_owner_changed_cb, signal_name='NameOwnerChanged', dbus_interface='org.freedesktop.DBus') bus_object = bus.get_object(dbus.BUS_DAEMON_NAME, dbus.BUS_DAEMON_PATH) for service in bus_object.ListNames( dbus_interface=dbus.BUS_DAEMON_IFACE): if service.startswith(CONNECTION + '.'): path = '/%s' % service.replace('.', '/') Connection(service, path, bus, ready_handler=self.__connection_ready_cb)
def __init__(self): BaseBuddyModel.__init__(self) self.props.nick = profile.get_nick_name() self.props.color = profile.get_color() self.props.key = profile.get_profile().pubkey self.connect('notify::nick', self.__property_changed_cb) self.connect('notify::color', self.__property_changed_cb) bus = dbus.SessionBus() bus.add_signal_receiver(self.__name_owner_changed_cb, signal_name='NameOwnerChanged', dbus_interface='org.freedesktop.DBus') bus_object = bus.get_object(dbus.BUS_DAEMON_NAME, dbus.BUS_DAEMON_PATH) for service in bus_object.ListNames( dbus_interface=dbus.BUS_DAEMON_IFACE): if service.startswith(CONNECTION + '.'): path = '/%s' % service.replace('.', '/') Connection(service, path, bus, ready_handler=self.__connection_ready_cb)
def check_profile(): profile = get_profile() path = os.path.join(env.get_profile_path(), 'config') if os.path.exists(path): profile.convert_profile() return profile.is_valid()
def create_profile(user_profile): settings = Gio.Settings('org.sugarlabs.user') settings.set_string('nick', user_profile.nickname) colors = user_profile.colors if colors is None: colors = XoColor() settings.set_string('color', colors.to_string()) if user_profile.gender is not None: settings.set_string('gender', user_profile.gender) else: settings.set_string('gender', '') settings.set_int('birth-timestamp', calculate_birth_timestamp(user_profile.age)) # settings.sync() # DEPRECATED from gi.repository import GConf client = GConf.Client.get_default() client.set_string('/desktop/sugar/user/nick', user_profile.nickname) client.set_string('/desktop/sugar/user/color', colors.to_string()) if user_profile.gender is not None: client.set_string('/desktop/sugar/user/gender', user_profile.gender) client.set_int('/desktop/sugar/user/birth_timestamp', calculate_birth_timestamp(user_profile.age)) client.suggest_sync() if profile.get_pubkey() and profile.get_profile().privkey_hash: logging.info('Valid key pair found, skipping generation.') return # Generate keypair keypath = os.path.join(env.get_profile_path(), 'owner.key') if os.path.exists(keypath): os.rename(keypath, keypath + '.broken') logging.warning('Existing private key %s moved to %s.broken', keypath, keypath) if os.path.exists(keypath + '.pub'): os.rename(keypath + '.pub', keypath + '.pub.broken') logging.warning('Existing public key %s.pub moved to %s.pub.broken', keypath, keypath) logging.debug("Generating user keypair") cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % (keypath, ) (s, o) = subprocess.getstatusoutput(cmd) if s != 0: logging.error('Could not generate key pair: %d %s', s, o) logging.debug("User keypair generated")
def _get_published_name(self): """Construct the published name based on the public key Limit the name to be only 8 characters maximum. The avahi service name has a 64 character limit. It consists of the room name, the published name and the host name. """ public_key_hash = sha1(get_profile().pubkey).hexdigest() return public_key_hash[:8]
def register_laptop(url=_REGISTER_URL): profile = get_profile() if _have_ofw_tree(): sn = _read_mfg_data(os.path.join(_OFW_TREE, _MFG_SN)) uuid_ = _read_mfg_data(os.path.join(_OFW_TREE, _MFG_UUID)) elif _have_proc_device_tree(): sn = _read_mfg_data(os.path.join(_PROC_TREE, _MFG_SN)) uuid_ = _read_mfg_data(os.path.join(_PROC_TREE, _MFG_UUID)) else: sn = _generate_serial_number() uuid_ = str(uuid.uuid1()) sn = sn or 'SHF00000000' uuid_ = uuid_ or '00000000-0000-0000-0000-000000000000' nick = get_nick_name() settings = Gio.Settings('org.sugarlabs.collaboration') jabber_server = settings.get_string('jabber-server') _store_identifiers(sn, uuid_, jabber_server) if jabber_server: url = 'http://' + jabber_server + ':8080/' if sys.hexversion < 0x2070000: server = xmlrpclib.ServerProxy(url, _TimeoutTransport()) else: socket.setdefaulttimeout(_REGISTER_TIMEOUT) server = xmlrpclib.ServerProxy(url) try: data = server.register(sn, nick, uuid_, profile.pubkey) except (xmlrpclib.Error, TypeError, socket.error): logging.exception('Registration: cannot connect to server') raise RegisterError(_('Cannot connect to the server.')) finally: socket.setdefaulttimeout(None) if data['success'] != 'OK': logging.error('Registration: server could not complete request: %s', data['error']) raise RegisterError(_('The server could not complete the request.')) settings.set_string('jabber-server', data['jabberserver']) settings = Gio.Settings('org.sugarlabs') settings.set_string('backup-url', data['backupurl']) # DEPRECATED from gi.repository import GConf client = GConf.Client.get_default() client.set_string( '/desktop/sugar/collaboration/jabber_server', data['jabberserver']) client.set_string('/desktop/sugar/backup_url', data['backupurl']) return True
def create_profile(user_profile): settings = Gio.Settings('org.sugarlabs.user') if user_profile.nickname in [None, '']: nick = settings.get_string('nick') if nick is not None: logging.debug('recovering old nickname %s' % (nick)) user_profile.nickname = nick settings.set_string('nick', user_profile.nickname) colors = user_profile.colors if colors is None: colors = XoColor() settings.set_string('color', colors.to_string()) genderpicker.save_gender(user_profile.gender) agepicker.save_age(user_profile.age) # DEPRECATED from gi.repository import GConf client = GConf.Client.get_default() client.set_string('/desktop/sugar/user/nick', user_profile.nickname) client.set_string('/desktop/sugar/user/color', colors.to_string()) client.suggest_sync() if profile.get_pubkey() and profile.get_profile().privkey_hash: logging.info('Valid key pair found, skipping generation.') return # Generate keypair keypath = os.path.join(env.get_profile_path(), 'owner.key') if os.path.exists(keypath): os.rename(keypath, keypath + '.broken') logging.warning('Existing private key %s moved to %s.broken', keypath, keypath) if os.path.exists(keypath + '.pub'): os.rename(keypath + '.pub', keypath + '.pub.broken') logging.warning('Existing public key %s.pub moved to %s.pub.broken', keypath, keypath) logging.debug("Generating user keypair") cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % (keypath, ) (s, o) = commands.getstatusoutput(cmd) if s != 0: logging.error('Could not generate key pair: %d %s', s, o) logging.debug("User keypair generated")
def check_profile(): profile = get_profile() path = os.path.join(os.path.expanduser('~/.sugar'), 'debug') if not os.path.exists(path): profile.create_debug_file() path = os.path.join(env.get_profile_path(), 'config') if os.path.exists(path): profile.convert_profile() return profile.is_valid()
def _ensure_server_account(self, account_paths): for account_path in account_paths: if 'gabble' in account_path: logging.debug('Already have a Gabble account') account = _Account(account_path) account.enable() return account logging.debug('Still dont have a Gabble account, creating one') client = GConf.Client.get_default() nick = client.get_string('/desktop/sugar/user/nick') server = client.get_string('/desktop/sugar/collaboration' '/jabber_server') key_hash = get_profile().privkey_hash params = { 'account': self._get_jabber_account_id(), 'password': key_hash, 'server': server, 'resource': 'sugar', 'require-encryption': True, 'ignore-ssl-errors': True, 'register': True, 'old-ssl': True, 'port': dbus.UInt32(5223), } properties = { ACCOUNT + '.Enabled': True, ACCOUNT + '.Nickname': nick, ACCOUNT + '.ConnectAutomatically': True, } bus = dbus.Bus() obj = bus.get_object(ACCOUNT_MANAGER_SERVICE, ACCOUNT_MANAGER_PATH) account_manager = dbus.Interface(obj, ACCOUNT_MANAGER) account_path = account_manager.CreateAccount('gabble', 'jabber', 'jabber', params, properties) return _Account(account_path)
def _seed_xs_cookie(cookie_jar): """Create a HTTP Cookie to authenticate with the Schoolserver. Do nothing if the laptop is not registered with Schoolserver, or if the cookie already exists. """ settings = Gio.Settings('org.sugarlabs') backup_url = settings.get_string('backup-url') if not backup_url: _logger.debug('seed_xs_cookie: Not registered with Schoolserver') return settings = Gio.Settings('org.sugarlabs.collaboration') jabber_server = settings.get_string('jabber-server') soup_uri = Soup.URI() soup_uri.set_scheme('xmpp') soup_uri.set_host(jabber_server) soup_uri.set_path('/') xs_cookie = cookie_jar.get_cookies(soup_uri, for_http=False) if xs_cookie is not None: _logger.debug('seed_xs_cookie: Cookie exists already') return pubkey = profile.get_profile().pubkey cookie_data = { 'color': profile.get_color().to_string(), 'pkey_hash': sha1(pubkey).hexdigest() } expire = int(time.time()) + 10 * 365 * 24 * 60 * 60 xs_cookie = Soup.Cookie() xs_cookie.set_name('xoid') xs_cookie.set_value(json.dumps(cookie_data)) xs_cookie.set_domain(jabber_server) xs_cookie.set_path('/') xs_cookie.set_max_age(expire) cookie_jar.add_cookie(xs_cookie) _logger.debug('seed_xs_cookie: Updated cookie successfully')
def _seed_xs_cookie(cookie_jar): """Create a HTTP Cookie to authenticate with the Schoolserver. Do nothing if the laptop is not registered with Schoolserver, or if the cookie already exists. """ client = GConf.Client.get_default() backup_url = client.get_string('/desktop/sugar/backup_url') if backup_url == '': _logger.debug('seed_xs_cookie: Not registered with Schoolserver') return jabber_server = client.get_string( '/desktop/sugar/collaboration/jabber_server') soup_uri = Soup.URI() soup_uri.set_scheme('xmpp') soup_uri.set_host(jabber_server) soup_uri.set_path('/') xs_cookie = cookie_jar.get_cookies(soup_uri, for_http=False) if xs_cookie is not None: _logger.debug('seed_xs_cookie: Cookie exists already') return pubkey = profile.get_profile().pubkey cookie_data = {'color': profile.get_color().to_string(), 'pkey_hash': sha1(pubkey).hexdigest()} expire = int(time.time()) + 10 * 365 * 24 * 60 * 60 xs_cookie = Soup.Cookie() xs_cookie.set_name('xoid') xs_cookie.set_value(json.dumps(cookie_data)) xs_cookie.set_domain(jabber_server) xs_cookie.set_path('/') xs_cookie.set_max_age(expire) cookie_jar.add_cookie(xs_cookie) _logger.debug('seed_xs_cookie: Updated cookie successfully')
def _get_jabber_account_id(self): public_key_hash = sha1(get_profile().pubkey).hexdigest() server = self._settings_collaboration.get_string('jabber-server') return '%s@%s' % (public_key_hash, server)
def __init__(self, handle): #handle object contains command line inputs to this activity self.handle = handle _logger.debug('Activity id:%s.Object id: %s. uri:%s' % (handle.activity_id, handle.object_id, handle.uri)) self.passed_in_ds_object = None if handle.object_id and handle.object_id != '': self.passed_in_ds_object = datastore.get(handle.object_id) if self.passed_in_ds_object: d = self.passed_in_ds_object.metadata else: ds_object = self.get_new_dsobject() if hasattr(ds_object, 'get_object_id'): handle.object_id = ds_object.get_object_id() else: handle.object_id = ds_object.object_id _logger.debug( 'no initial datastore object id passed in via handle') #Save a global poiinter so remote procedure calls can communicate with pydebug global pydebug_instance pydebug_instance = self start_clock = time.clock() #init variables self.make_paths() self.save_icon_clicked = False self.source_directory = None self.data_file = None self.help = None self.help_x11 = None self.dirty = False self.sock = None #self.last_filename = None self.debug_dict = {} self.activity_dict = {} self.manifest_treeview = None #set up to recognize an re-display of playpen #self.set_title(_('PyDebug Activity')) self.ds = None #datastore pointer self._logger = _logger self.traceback = 'Context' self.abandon_changes = False self.delete_after_load = None self.find_window = None self.icon_outline = 'icon_square' self.icon_window = None self.last_icon_file = None self.activity_data_changed = False self.icon_basename = None #sugar 0.82 has a different way of getting colors and dies during init unless the following self.profile = profile.get_profile() self.profile.color = XoColor() #get the persistent data across all debug sessions and start using it self.get_config() #give the server a chance to get started so terminal can connect to it self.non_blocking_server() #glib.idle_add(self.non_blocking_server) # init the Classes we are subclassing _logger.debug('about to init superclass activity. Elapsed time: %f' % (time.clock() - start_clock)) Activity.__init__(self, handle, create_jobject=False) self.connect('realize', self.realize_cb) self.accelerator = Gtk.AccelGroup() self.add_accel_group(self.accelerator) #set up the PANES for the different functions of the debugger _logger.debug('about to set up Menu panes. Elapsed time: %f' % (time.clock() - start_clock)) self.panes = {} PANES = ['TERMINAL', 'EDITOR', 'PROJECT', 'HELP'] for i in range(len(PANES)): self.panes[PANES[i]] = i #toolbarbox needs to be available during init of modules self.toolbarbox = pytoolbar.ActivityToolbarBox(self) ######################################################################################### #init the sub functions TerminalGui.__init__(self, self, self.toolbarbox) EditorGui.__init__(self, self) ProjectGui.__init__(self, self) ##self.help = Help(self) self.util = Utilities(self) ######################################################################################### #if first time run on this machine, set up home directory if not os.path.isfile(os.path.join(self.debugger_home, '.bashrc')): self.setup_home_directory() # setup the search options self.s_opts = SearchOptions( where=S_WHERE.file, use_regex=False, ignore_caps=True, replace_all=False, #defaults to avoid creating #a new SearchOptions object for normal searches #should never be changed, just make a copy like: #SearchOptions(self.s_opts, forward=False) forward=True, stay=False) self.safe_to_replace = False ######################################################################################### _logger.debug( 'All app objects created. about to set up Display . Elapsed time: %f' % (time.clock() - start_clock)) self.canvas_list = [] self.canvas_list.append(self._get_terminal_canvas()) self.canvas_list.append(self._get_edit_canvas()) self.canvas_list.append(self._get_project_canvas()) self.canvas_list.append(self._get_help_canvas()) nb = Gtk.Notebook() nb.show() nb.set_show_tabs(False) for c in self.canvas_list: nb.append_page(c) self.pydebug_notebook = nb #the following call to the activity code puts our notebook under the stock toolbar self.set_canvas(nb) ##helpbar = self.help.get_help_toolbar() activity_button = ActivityToolbarButton(self) self.toolbarbox.toolbar.insert(activity_button, 0) # activity_button.show() self.toolbarbox.toolbar.insert( ToolbarButton(page=self.get_editbar(), icon_name='toolbar-edit'), -1) stop_button = StopButton(self) self.toolbarbox.toolbar.insert(stop_button, -1) ##self.toolbarbox.toolbar.insert(_('Help'), self.help.get_help_toolbar(), -1) self.set_toolbar_box(self.toolbarbox) self.toolbarbox.show_all() #set which PANE is visible initially self.set_visible_canvas(self.panes['PROJECT']) _logger.debug('about to setup_project_page. Elapsed time: %f' % (time.clock() - start_clock)) self.setup_project_page() _logger.debug( 'about Returned from setup_project_page. Elapsed time: %f' % (time.clock() - start_clock)) #get the journal datastore information and resume previous activity #self.metadata = self.ds if self.passed_in_ds_object and self.passed_in_ds_object.get_file_path( ): ds_file = self.passed_in_ds_object.get_file_path() else: ds_file = '' _logger.debug('about to call read routine Elapsed time: %f' % (time.clock() - start_clock)) self.read_file(ds_file) _logger.debug('about (end of init) Elapsed time: %f' % (time.clock() - start_clock))
def _get_jabber_account_id(self): public_key_hash = sha1(get_profile().pubkey).hexdigest() client = GConf.Client.get_default() server = client.get_string('/desktop/sugar/collaboration' '/jabber_server') return '%s@%s' % (public_key_hash, server)