def dhcp_acquire(self, device): if device not in self.quering: self.quering.append(device) else: return if device != "": def reply(_obj, result, _user_data): logging.info(result) Notification(_("Bluetooth Network"), _("Interface %(0)s bound to IP address %(1)s") % {"0": device, "1": result}, icon_name="network-workgroup", pos_hint=self.Applet.Plugins.StatusIcon.geometry).show() self.quering.remove(device) def err(_obj, result, _user_data): logging.warning(result) Notification(_("Bluetooth Network"), _("Failed to obtain an IP address on %s") % (device), icon_name="network-workgroup", pos_hint=self.Applet.Plugins.StatusIcon.geometry).show() self.quering.remove(device) Notification(_("Bluetooth Network"), _("Trying to obtain an IP address on %s\nPlease wait..." % device), icon_name="network-workgroup", pos_hint=self.Applet.Plugins.StatusIcon.geometry).show() m = Mechanism() m.DhcpClient(str('(s)'), device, result_handler=reply, error_handler=err, timeout=120)
def on_apply(self): if self.on_query_apply_state() == True: dprint("network apply") m = Mechanism() nap_enable = self.Builder.get_object("nap-enable") if nap_enable.props.active: r_dnsmasq = self.Builder.get_object("r_dnsmasq") if r_dnsmasq.props.active: stype = "DnsMasqHandler" else: stype = "DhcpdHandler" net_ip = self.Builder.get_object("net_ip") net_nat = self.Builder.get_object("net_nat") try: m.EnableNetwork(inet_aton(net_ip.props.text), inet_aton("255.255.255.0"), stype) except Exception as e: d = NetworkErrorDialog(e) d.run() d.destroy() return else: m.DisableNetwork() self.clear_options()
def __init__(self): GObject.GObject.__init__(self) self.state = True self.hardblocked = False self.switches = {} mode = os.stat("/dev/rfkill").st_mode flags = 0 if os.getuid() == 0: flags = os.O_RDWR else: if (mode & stat.S_IWOTH) == 0: flags = os.O_RDONLY else: flags = os.O_RDWR if (mode & stat.S_IROTH) == 0: m = Mechanism() m.DevRfkillChmod() flags |= os.O_NONBLOCK self.fd = os.open("/dev/rfkill", flags) ref = weakref.ref(self) self.iom = GObject.io_add_watch(self.fd, GObject.IO_IN | GObject.IO_ERR | GObject.IO_HUP, lambda *args: ref() and ref().io_event(*args))
def RegisterModem(self, device_path, rfcomm_device): dev = Bluez.Device(device_path) props = dev.get_properties() m = Mechanism() def reply(): dprint("Registered modem") def err(excp): d = Gtk.MessageDialog(None, type=Gtk.MessageType.WARNING) d.props.icon_name = "blueman" d.props.text = _("CDMA or GSM not supported") d.props.secondary_text = _( "The device %s does not appear to support GSM/CDMA.\nThis connection will not work." ) % props["Alias"] d.add_button(Gtk.STOCK_OK, Gtk.ResponseType.NO) resp = d.run() d.destroy() m.HalRegisterModemPort(rfcomm_device, props["Address"], reply_handler=reply, error_handler=err)
def SetGlobalState(self, state, **kwargs): dprint("set", state) # if we have permission, we just send an event, else we use the dbus interface if os.getuid() == 0: event = struct.pack("IBBBB", 0, RFKillType.BLUETOOTH, RFKillOp.CHANGE_ALL, (0 if state else 1), 0) os.write(self.fd, event) else: m = Mechanism() m.SetRfkillState(state, **kwargs)
def connect(self): c = Config("gsm_settings/" + self.device.Address) if c.props.apn == None: c.props.apn = "" if c.props.number == None: c.props.number = "*99#" m = Mechanism() m.PPPConnect(self.port, c.props.number, c.props.apn, reply_handler=self.on_connected, error_handler=self.on_error, timeout=200)
def connect(self): c = Config( "org.blueman.gsmsettings", "/org/blueman/gsmsettings/%s/" % self.service.device.Address) m = Mechanism() m.PPPConnect(self.port, c["number"], c["apn"], reply_handler=self.on_connected, error_handler=self.on_error, timeout=200)
def connect(self, reply_handler=None, error_handler=None): channel = get_rfcomm_channel(self.device['Address']) if channel == 0: error = RFCOMMError("Failed to get rfcomm channel") if error_handler: error_handler(error) return True else: raise error try: port_id = create_rfcomm_device( Adapter(self.device["Adapter"])['Address'], self.device["Address"], channel) filename = '/dev/rfcomm%d' % port_id logging.info('Starting rfcomm watcher as root') Mechanism().open_rfcomm('(d)', port_id) mon = Gio.File.new_for_path(filename).monitor_file( Gio.FileMonitorFlags.NONE) self.file_changed_handler = mon.connect('changed', self.on_file_changed, port_id) self.try_replace_root_watcher(mon, filename, port_id) if reply_handler: reply_handler(filename) except RFCOMMError as e: if error_handler: error_handler(e) else: raise e return True
def on_apply(self): if self.get_options() != []: vals = ["Sink"] if self.cb_a2dp.props.active: vals.append("Source") if self.cb_hsp.props.active: vals.append("Gateway") try: m = Mechanism() m.SetBluezConfig("audio.conf", "General", "Enable", ",".join(vals)) m.SaveBluezConfig("audio.conf") m.RestartBluez() except dbus.DBusException, e: dprint(e) else: self.clear_options()
def load_nap_settings(self): logging.info("Loading NAP settings") def reply(*_): pass def err(_obj, result, _user_data): d = NetworkErrorDialog( result, "You might not be able to connect to the Bluetooth network via this machine" ) d.expander.props.margin_left = 9 d.run() d.destroy() m = Mechanism() m.ReloadNetwork(result_handler=reply, error_handler=err)
def try_replace_root_watcher(self, monitor, path, port): if not os.access(path, os.R_OK | os.W_OK): return logging.info('User was granted access to %s' % path) logging.info('Replacing root watcher') Mechanism().close_rfcomm('(d)', port) subprocess.Popen([RFCOMM_WATCHER_PATH, path]) monitor.disconnect(self.file_changed_handler)
def load_nap_settings(self): dprint("Loading NAP settings") def reply(): pass def err(excp): d = NetworkErrorDialog( excp, "You might not be able to connect to the Bluetooth network via this machine" ) d.expander.props.margin_left = 9 d.run() d.destroy() m = Mechanism() m.ReloadNetwork(reply_handler=reply, error_handler=err)
def on_apply(self): if self.on_query_apply_state() == True: dprint("network apply") m = Mechanism() nap_enable = self.Builder.get_object("nap_enable") if nap_enable.props.active: r_dnsmasq = self.Builder.get_object("r_dnsmasq") if r_dnsmasq.props.active: stype = "DnsMasqHandler" else: stype = "DhcpdHandler" net_ip = self.Builder.get_object("net_ip") net_nat = self.Builder.get_object("net_nat") try: m.EnableNetwork(inet_aton(net_ip.props.text), inet_aton("255.255.255.0"), stype) if not self.NetConf.props.nap_enable: # race condition workaround self.ignored_keys.append("nap_enable") self.NetConf.props.nap_enable = True except Exception as e: lines = str(e).splitlines() d = Gtk.MessageDialog(None, buttons=Gtk.ButtonsType.OK, type=Gtk.MessageType.ERROR) d.props.icon_name = "dialog-error" d.props.text = _("Failed to apply network settings") d.props.secondary_text = lines[-1] d.run() d.destroy() return else: if self.NetConf.props.nap_enable: # race condition workaround self.ignored_keys.append("nap_enable") self.NetConf.props.nap_enable = False m.DisableNetwork() self.clear_options()
def on_power_state_change_requested(self, _, state, cb): dprint(state) def reply(*_): cb(True) def error(*_): cb(False) Mechanism().SetRfkillState(state, reply_handler=reply, error_handler=error)
def dhcp_acquire(self, device): if device not in self.quering: self.quering.append(device) else: return if device != "": def reply(ip_address): Notification(_("Bluetooth Network"), _("Interface %(0)s bound to IP address %(1)s") % { "0": device, "1": ip_address }, pixbuf=get_icon("gtk-network", 48), status_icon=self.Applet.Plugins.StatusIcon) self.quering.remove(device) def err(msg): dprint(msg) Notification(_("Bluetooth Network"), _("Failed to obtain an IP address on %s") % (device), pixbuf=get_icon("gtk-network", 48), status_icon=self.Applet.Plugins.StatusIcon) self.quering.remove(device) Notification( _("Bluetooth Network"), _("Trying to obtain an IP address on %s\nPlease wait..." % device), pixbuf=get_icon("gtk-network", 48), status_icon=self.Applet.Plugins.StatusIcon) m = Mechanism() m.DhcpClient(device, reply_handler=reply, error_handler=err, timeout=120)
def load_nap_settings(self): dprint("Loading NAP settings") def reply(): pass def err(excp): lines = str(excp).splitlines() d = Gtk.MessageDialog(None, buttons=Gtk.ButtonsType.OK, type=Gtk.MessageType.ERROR) d.props.text = _("Failed to apply network settings") d.props.secondary_text = lines[-1] + "\n\n" + _( "You might not be able to connect to the Bluetooth network via this machine" ) d.run() d.destroy() m = Mechanism() m.ReloadNetwork(reply_handler=reply, error_handler=err)
def on_power_state_change_requested(self, _, state, cb): logging.info(state) def reply(*_): cb(True) def error(*_): cb(False) Mechanism().SetRfkillState(str('(b)'), state, result_handler=reply, error_handler=error)
def connect(self, reply_handler=None, error_handler=None): props = self.device.get_properties() try: # TODO: Channel? port_id = create_rfcomm_device(Adapter(props['Adapter']).get_properties()['Address'], props['Address'], 1) Mechanism().open_rfcomm(port_id) if reply_handler: reply_handler('/dev/rfcomm%d' % port_id) except Exception as e: if error_handler: error_handler(e) else: raise e return True
def on_apply(self): if self.on_query_apply_state(): logging.info("network apply") m = Mechanism() nap_enable = self.Builder.get_object("nap-enable") if nap_enable.props.active: if self.Builder.get_object("r_dhcpd").props.active: stype = "DhcpdHandler" elif self.Builder.get_object("r_dnsmasq").props.active: stype = "DnsMasqHandler" elif self.Builder.get_object("r_udhcpd").props.active: stype = "UdhcpdHandler" net_ip = self.Builder.get_object("net_ip") try: m.EnableNetwork('(ayays)', inet_aton(net_ip.props.text), inet_aton("255.255.255.0"), stype) if not self.Config["nap-enable"]: self.Config["nap-enable"] = True except Exception as e: d = ErrorDialog("<b>Failed to apply network settings</b>", excp=e, parent=self.widget.get_toplevel()) d.run() d.destroy() return else: self.Config["nap-enable"] = False m.DisableNetwork() self.clear_options()
def connect(self, reply_handler=None, error_handler=None): try: # TODO: Channel? port_id = create_rfcomm_device( Adapter(self.device["Adapter"])['Address'], self.device["Address"], 1) Mechanism().open_rfcomm(str('(d)'), port_id) if reply_handler: reply_handler('/dev/rfcomm%d' % port_id) except Exception as e: if error_handler: error_handler(e) else: raise e return True
def on_power_state_change_requested(self, _, state, cb): logging.info(state) def reply(*_): cb(True) def error(*_): cb(False) if self._connman_proxy: logging.debug("Using connman to set state: %s" % state) self._connman_proxy.SetProperty('(sv)', 'Powered', GLib.Variant.new_boolean(state), result_handler=reply, error_handler=error) else: logging.debug("Using mechanism to set state: %s" % state) Mechanism().SetRfkillState('(b)', state, result_handler=reply, error_handler=error)
def connect(self, reply_handler=None, error_handler=None): props = self.device.get_properties() short_uuid = uuid128_to_uuid16(self.uuid) channel = get_rfcomm_channel(short_uuid, props['Address']) if channel == 0: error = RFCOMMError("Failed to get rfcomm channel") if error_handler: error_handler(error) return True else: raise error try: port_id = create_rfcomm_device(Adapter(props['Adapter']).get_properties()['Address'], props['Address'], channel) Mechanism().open_rfcomm(port_id) if reply_handler: reply_handler('/dev/rfcomm%d' % port_id) except RFCOMMError as e: if error_handler: error_handler(e) else: raise e return True
def disconnect(self, port): Mechanism().PPPDisconnect(port) super().disconnect(port)
def on_network_prop_changed(self, key, value, path): if key == "Interface": if value != "": m = Mechanism() m.HalRegisterNetDev(value)
def disconnect(self, *args): Mechanism().close_rfcomm(args[0])
def disconnect(self, *args): Mechanism().close_rfcomm(args[0]) release_rfcomm_device(args[0])
def UnregisterModem(self, device): m = Mechanism() m.HalUnregisterModemPortDev(device) dprint("Unregistered modem")