Example #1
0
    def do_apply(self):
        if not self.netconf.locked("dhcp") or self.netconf.ip4_changed:
            if self.netconf.ip4_changed:
                self.do_remove()

            dhcp_config, existing_subnet = self._read_dhcp_config()

            subnet = self._generate_subnet_config()

            # if subnet != self.existing_subnet:
            f = open(DHCP_CONFIG_FILE, "w")
            f.write(dhcp_config)
            f.write(subnet)
            f.close()

            cmd = [
                have("dhcpd3") or have("dhcpd"), "-pf",
                "/var/run/dhcpd.pan1.pid", "pan1"
            ]
            p = Popen(cmd)

            ret = p.wait()

            if ret == 0:
                dprint("dhcpd started correctly")
                f = open("/var/run/dhcpd.pan1.pid", "r")
                self.pid = int(f.read())
                f.close()
                dprint("pid", self.pid)
                self.netconf.lock("dhcp")
            else:
                raise NetworkSetupError(
                    "dhcpd failed to start. Check the system log for errors")
Example #2
0
    def do_apply(self):
        if not self.netconf.locked("dhcp") or self.netconf.ip4_changed:
            if self.netconf.ip4_changed:
                self.do_remove()

            dhcp_config, existing_subnet = self._read_dhcp_config()

            subnet = self._generate_subnet_config()

            # if subnet != self.existing_subnet:
            f = open(DHCP_CONFIG_FILE, "w")
            f.write(dhcp_config)
            f.write(subnet)
            f.close()

            cmd = [have("dhcpd3") or have("dhcpd"), "-pf", "/var/run/dhcpd-server/dhcp.pan1.pid", "pan1"]
            p = Popen(cmd)

            ret = p.wait()

            if ret == 0:
                dprint("dhcpd started correctly")
                f = open("/var/run/dhcp-server/dhcpd.pan1.pid", "r")
                self.pid = int(f.read())
                f.close()
                dprint("pid", self.pid)
                self.netconf.lock("dhcp")
            else:
                raise Exception("dhcpd failed to start. Check the system log for errors")
Example #3
0
    def do_apply(self):
        if not self.netconf.locked("dhcp") or self.netconf.ip4_changed:
            if self.netconf.ip4_changed:
                self.do_remove()

            dhcp_config, existing_subnet = self._read_dhcp_config()

            subnet = self._generate_subnet_config()

            # if subnet != self.existing_subnet:
            with open(DHCP_CONFIG_FILE, "w") as f:
                f.write(dhcp_config)
                f.write(subnet)

            cmd = [
                have("dhcpd3") or have("dhcpd"), "-pf",
                "/var/run/dhcpd.pan1.pid", "pan1"
            ]
            p = Popen(cmd, stderr=PIPE)

            error = p.communicate()[1]

            if p.returncode == 0:
                logging.info("dhcpd started correctly")
                with open("/var/run/dhcpd.pan1.pid", "r") as f:
                    self.pid = int(f.read())
                logging.info("pid %s" % self.pid)
                self.netconf.lock("dhcp")
            else:
                error_msg = error.decode("UTF-8").strip()
                logging.info(error_msg)
                raise NetworkSetupError("dhcpd failed to start: %s " %
                                        error_msg)
Example #4
0
    def do_apply(self):
        if not self.netconf.locked("dhcp") or self.netconf.ip4_changed:
            if self.netconf.ip4_changed:
                self.do_remove()

            dhcp_config, existing_subnet = self._read_dhcp_config()

            subnet = self._generate_subnet_config()

            # if subnet != self.existing_subnet:
            f = open(DHCP_CONFIG_FILE, "w")
            f.write(dhcp_config)
            f.write(subnet)
            f.close()

            cmd = [have("dhcpd3") or have("dhcpd"), "-pf", "/var/run/dhcpd.pan1.pid", "pan1"]
            p = Popen(cmd, stderr=PIPE)

            error = p.communicate()[1]

            if p.returncode == 0:
                logging.info("dhcpd started correctly")
                f = open("/var/run/dhcpd.pan1.pid", "r")
                self.pid = int(f.read())
                f.close()
                logging.info("pid %s" % self.pid)
                self.netconf.lock("dhcp")
            else:
                error_msg = error.decode("UTF-8").strip()
                logging.info(error_msg)
                raise NetworkSetupError("dhcpd failed to start: %s " % error_msg)
Example #5
0
    def apply_settings(self):
        if self != NetConf.get_default():
            NetConf.get_default().remove_settings()
            NetConf.default_inst = self

        try:
            create_bridge("pan1")
        except BridgeException as e:
            if e.errno != errno.EEXIST:
                raise

        if self.ip4_changed or not self.locked("netconfig"):
            self.enable_ip4_forwarding()

            if have("ip"):
                ret = call(["ip", "link", "set", "dev", "pan1", "up"])
                if ret != 0:
                    raise NetworkSetupError(
                        "Failed to bring up interface pan1")
                ret = call([
                    "ip", "address", "add", "/".join(
                        (self.ip4_address, self.ip4_mask)), "dev", "pan1"
                ])
                if ret != 0:
                    raise NetworkSetupError(
                        "Failed to add ip address %s with netmask %s" %
                        (self.ip4_address, self.ip4_mask))
            elif have('ifconfig'):
                ret = call([
                    "ifconfig", "pan1", self.ip4_address, "netmask",
                    self.ip4_mask, "up"
                ])
                if ret != 0:
                    raise NetworkSetupError(
                        "Failed to add ip address %s with netmask %s" %
                        (self.ip4_address, self.ip4_mask))
            else:
                raise NetworkSetupError(
                    "Neither ifconfig or ip commands are found. Please install net-tools or iproute2"
                )

            self.lock("netconfig")

        if self.ip4_changed or not self.locked("iptables"):
            self.del_ipt_rules()

            self.add_ipt_rule(
                "nat", "POSTROUTING",
                "-s %s/%s -j MASQUERADE" % (self.ip4_address, self.ip4_mask))
            self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT")
            self.add_ipt_rule("filter", "FORWARD", "-o pan1 -j ACCEPT")
            self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT")
            self.lock("iptables")

        if self.dhcp_handler:
            self.dhcp_handler.do_apply()
        self.ip4_changed = False

        self.store()
Example #6
0
    def do_apply(self):
        if not self.netconf.locked("dhcp") or self.netconf.ip4_changed:
            if self.netconf.ip4_changed:
                self.do_remove()

            config_file, config_path = mkstemp(prefix="udhcpd-")
            os.write(config_file, self._generate_config().encode('UTF-8'))
            os.close(config_file)

            logging.info("Running udhcpd with config file %s" % config_path)
            cmd = [have("udhcpd"), "-S", config_path]
            p = Popen(cmd)
            p.wait()

            # udhcpd takes time to create pid file
            sleep(0.1)

            pid = read_pid_file("/var/run/udhcpd.pan1.pid")

            if p.pid and is_running("udhcpd", pid):
                logging.info("udhcpd started correctly")
                self.pid = pid
                logging.info("pid %s" % self.pid)
                self.netconf.lock("dhcp")
            else:
                raise Exception(
                    "udhcpd failed to start. Check the system log for errors")

            os.remove(config_path)
Example #7
0
    def do_apply(self):
        if not self.netconf.locked("dhcp") or self.netconf.ip4_changed:
            if self.netconf.ip4_changed:
                self.do_remove()

            ipiface = ipaddress.ip_interface('/'.join((self.netconf.ip4_address, '255.255.255.0')))
            cmd = [have("dnsmasq"), "--port=0", "--pid-file=/var/run/dnsmasq.pan1.pid", "--except-interface=lo",
                   "--interface=pan1", "--bind-interfaces",
                   "--dhcp-range=%s,%s,60m" % (ipiface.network[2], ipiface.network[-2]),
                   "--dhcp-option=option:router,%s" % self.netconf.ip4_address]

            logging.info(cmd)
            p = Popen(cmd, stderr=PIPE)

            error = p.communicate()[1]

            if not error:
                logging.info("Dnsmasq started correctly")
                f = open("/var/run/dnsmasq.pan1.pid", "r")
                self.pid = int(f.read())
                f.close()
                logging.info("pid %s" % self.pid)
                self.netconf.lock("dhcp")
            else:
                error_msg = error.decode("UTF-8").strip()
                logging.info(error_msg)
                raise NetworkSetupError("dnsmasq failed to start: %s" % error_msg)
Example #8
0
    def do_apply(self):
        if not self.netconf.locked("dhcp") or self.netconf.ip4_changed:
            if self.netconf.ip4_changed:
                self.do_remove()

            if 1:
                rtr = "--dhcp-option=option:router,%s" % inet_ntoa(self.netconf.ip4_address)
            else:
                rtr = "--dhcp-option=3 --dhcp-option=6"  # no route and no dns

            start, end = calc_ip_range(self.netconf.ip4_address)

            args = "--pid-file=/var/run/dnsmasq.pan1.pid --bind-interfaces --dhcp-range=%s,%s,60m --except-interface=lo --interface=pan1 %s" % (inet_ntoa(start), inet_ntoa(end), rtr)

            cmd = [have("dnsmasq")] + args.split(" ")
            dprint(cmd)
            p = Popen(cmd)

            ret = p.wait()

            if ret == 0:
                dprint("Dnsmasq started correctly")
                f = open("/var/run/dnsmasq.pan1.pid", "r")
                self.pid = int(f.read())
                f.close()
                dprint("pid", self.pid)
                self.netconf.lock("dhcp")
            else:
                raise Exception("dnsmasq failed to start. Check the system log for errors")
Example #9
0
    def do_apply(self):
        if not self.netconf.locked("dhcp") or self.netconf.ip4_changed:
            if self.netconf.ip4_changed:
                self.do_remove()

            config_file, config_path = mkstemp(prefix="udhcpd-")
            os.write(config_file, self._generate_config().encode('UTF-8'))
            os.close(config_file)

            logging.info("Running udhcpd with config file %s" % config_path)
            cmd = [have("udhcpd"), "-S", config_path]
            p = Popen(cmd, stderr=PIPE)
            error = p.communicate()[1]

            # udhcpd takes time to create pid file
            sleep(0.1)

            pid = read_pid_file("/var/run/udhcpd.pan1.pid")

            if p.pid and is_running("udhcpd", pid):
                logging.info("udhcpd started correctly")
                self.pid = pid
                logging.info("pid %s" % self.pid)
                self.netconf.lock("dhcp")
            else:
                error_msg = error.decode("UTF-8").strip()
                logging.info(error_msg)
                raise NetworkSetupError("udhcpd failed to start: %s" % error_msg)

            os.remove(config_path)
Example #10
0
    def do_apply(self):
        if not self.netconf.locked("dhcp") or self.netconf.ip4_changed:
            if self.netconf.ip4_changed:
                self.do_remove()

            config_file, config_path = mkstemp(prefix="udhcpd-")
            os.write(config_file, self._generate_config().encode('UTF-8'))
            os.close(config_file)

            logging.info("Running udhcpd with config file %s" % config_path)
            cmd = [have("udhcpd"), "-S", config_path]
            p = Popen(cmd, stderr=PIPE)
            error = p.communicate()[1]

            # udhcpd takes time to create pid file
            sleep(0.1)

            pid = read_pid_file("/var/run/udhcpd.pan1.pid")

            if p.pid and is_running("udhcpd", pid):
                logging.info("udhcpd started correctly")
                self.pid = pid
                logging.info("pid %s" % self.pid)
                self.netconf.lock("dhcp")
            else:
                error_msg = error.decode("UTF-8").strip()
                logging.info(error_msg)
                raise NetworkSetupError("udhcpd failed to start: %s" %
                                        error_msg)

            os.remove(config_path)
Example #11
0
    def do_apply(self):
        if not self.netconf.locked("dhcp") or self.netconf.ip4_changed:
            if self.netconf.ip4_changed:
                self.do_remove()

            if 1:
                rtr = "--dhcp-option=option:router,%s" % inet_ntoa(
                    self.netconf.ip4_address)
            else:
                rtr = "--dhcp-option=3 --dhcp-option=6"  # no route and no dns

            start, end = calc_ip_range(self.netconf.ip4_address)

            args = "--pid-file=/var/run/dnsmasq.pan1.pid --bind-interfaces --dhcp-range=%s,%s,60m --except-interface=lo --interface=pan1 %s" % (
                inet_ntoa(start), inet_ntoa(end), rtr)

            cmd = [have("dnsmasq")] + args.split(" ")
            dprint(cmd)
            p = Popen(cmd)

            ret = p.wait()

            if ret == 0:
                dprint("Dnsmasq started correctly")
                f = open("/var/run/dnsmasq.pan1.pid", "r")
                self.pid = int(f.read())
                f.close()
                dprint("pid", self.pid)
                self.netconf.lock("dhcp")
            else:
                raise NetworkSetupError(
                    "dnsmasq failed to start. Check the system log for errors")
Example #12
0
    def do_apply(self):
        if not self.netconf.locked("dhcp") or self.netconf.ip4_changed:
            if self.netconf.ip4_changed:
                self.do_remove()

            start, end = calc_ip_range(self.netconf.ip4_address)
            cmd = [have("dnsmasq"), "--pid-file=/var/run/dnsmasq.pan1.pid", "--except-interface=lo",
                   "--interface=pan1", "--bind-interfaces",
                   "--dhcp-range=%s,%s,60m" % (inet_ntoa(start), inet_ntoa(end)),
                   "--dhcp-option=option:router,%s" % inet_ntoa(self.netconf.ip4_address)]

            logging.info(cmd)
            p = Popen(cmd, stderr=PIPE)

            error = p.communicate()[1]

            if not error:
                logging.info("Dnsmasq started correctly")
                f = open("/var/run/dnsmasq.pan1.pid", "r")
                self.pid = int(f.read())
                f.close()
                logging.info("pid %s" % self.pid)
                self.netconf.lock("dhcp")
            else:
                error_msg = error.decode("UTF-8").strip()
                logging.info(error_msg)
                raise NetworkSetupError("dnsmasq failed to start: %s" % error_msg)
Example #13
0
    def do_apply(self):
        if not self.netconf.locked("dhcp") or self.netconf.ip4_changed:
            if self.netconf.ip4_changed:
                self.do_remove()

            config_file, config_path = mkstemp(prefix="udhcpd-")
            os.write(config_file, self._generate_config().encode('UTF-8'))
            os.close(config_file)

            dprint("Running udhcpd with config file %s" % config_path)
            cmd = [have("udhcpd"), "-S", config_path]
            p = Popen(cmd)
            p.wait()

            # udhcpd takes time to create pid file
            sleep(0.1)

            pid = read_pid_file("/var/run/udhcpd.pan1.pid")

            if p.pid and is_running("udhcpd", pid):
                dprint("udhcpd started correctly")
                self.pid = pid
                dprint("pid", self.pid)
                self.netconf.lock("dhcp")
            else:
                raise Exception("udhcpd failed to start. Check the system log for errors")

            os.remove(config_path)
Example #14
0
    def do_apply(self):
        if not self.netconf.locked("dhcp") or self.netconf.ip4_changed:
            if self.netconf.ip4_changed:
                self.do_remove()

            ipiface = ipaddress.ip_interface('/'.join(
                (self.netconf.ip4_address, '255.255.255.0')))
            cmd = [
                have("dnsmasq"), "--port=0",
                "--pid-file=/var/run/dnsmasq.pan1.pid",
                "--except-interface=lo", "--interface=pan1",
                "--bind-interfaces",
                "--dhcp-range=%s,%s,60m" %
                (ipiface.network[2], ipiface.network[-2]),
                "--dhcp-option=option:router,%s" % self.netconf.ip4_address
            ]

            logging.info(cmd)
            p = Popen(cmd, stderr=PIPE)

            error = p.communicate()[1]

            if not error:
                logging.info("Dnsmasq started correctly")
                with open("/var/run/dnsmasq.pan1.pid", "r") as f:
                    self.pid = int(f.read())
                logging.info("pid %s" % self.pid)
                self.netconf.lock("dhcp")
            else:
                error_msg = error.decode("UTF-8").strip()
                logging.info(error_msg)
                raise NetworkSetupError("dnsmasq failed to start: %s" %
                                        error_msg)
Example #15
0
    def apply_settings(self):
        if self != NetConf.get_default():
            NetConf.get_default().remove_settings()
            NetConf.default_inst = self

        try:
            create_bridge("pan1")
        except BridgeException as e:
            if e.errno != errno.EEXIST:
                raise

        if self.ip4_changed or not self.locked("netconfig"):
            self.enable_ip4_forwarding()

            if have("ip"):
                ret = call(["ip", "link", "set", "dev", "pan1", "up"])
                if ret != 0:
                    raise NetworkSetupError("Failed to bring up interface pan1")
                ret = call(["ip", "address", "add", "/".join((self.ip4_address, self.ip4_mask)), "dev", "pan1"])
                if ret != 0:
                    raise NetworkSetupError("Failed to add ip address %s with netmask %s" % (self.ip4_address,
                                                                                             self.ip4_mask))
            elif have('ifconfig'):
                ret = call(["ifconfig", "pan1", self.ip4_address, "netmask", self.ip4_mask, "up"])
                if ret != 0:
                    raise NetworkSetupError("Failed to add ip address %s with netmask %s" % (self.ip4_address,
                                                                                             self.ip4_mask))
            else:
                raise NetworkSetupError(
                    "Neither ifconfig or ip commands are found. Please install net-tools or iproute2")

            self.lock("netconfig")

        if self.ip4_changed or not self.locked("iptables"):
            self.del_ipt_rules()

            self.add_ipt_rule("nat", "POSTROUTING", "-s %s/%s -j MASQUERADE" % (self.ip4_address, self.ip4_mask))
            self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT")
            self.add_ipt_rule("filter", "FORWARD", "-o pan1 -j ACCEPT")
            self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT")
            self.lock("iptables")

        if self.dhcp_handler:
            self.dhcp_handler.do_apply()
        self.ip4_changed = False

        self.store()
Example #16
0
    def __init__(self, interface: str, timeout: int = 30) -> None:
        super().__init__()

        self._interface = interface
        self._timeout = timeout

        self._command = None
        for command in self.COMMANDS:
            path = have(command[0])
            if path:
                self._command = [path] + command[1:] + [self._interface]
                break
Example #17
0
    def __init__(self, interface, timeout=30):
        super(DhcpClient, self).__init__()

        self._interface = interface
        self._timeout = timeout

        self._command = None
        for command in self.COMMANDS:
            path = have(command[0])
            if path:
                self._command = [path] + command[1:] + [self._interface]
                break
        self._client = None
Example #18
0
    def __init__(self, interface: str, timeout: int = 30) -> None:
        """The interface name has to be trusted / sanitized!"""
        super().__init__()

        self._interface = interface
        self._timeout = timeout

        self._command = None
        for command in self.COMMANDS:
            path = have(command[0])
            if path:
                self._command = [path] + command[1:] + [self._interface]
                break
Example #19
0
    def __init__(self, interface, timeout=30):
        super(DhcpClient, self).__init__()

        self._interface = interface
        self._timeout = timeout

        self._command = None
        for command in self.COMMANDS:
            path = have(command[0])
            if path:
                self._command = [path] + command[1:] + [self._interface]
                break
        self._client = None
Example #20
0
    def apply_settings(self):
        if self.ip4_address is None or self.ip4_mask is None:
            if self.ip4_changed:
                self.ip4_changed = False
            self.store()
            return

        if self != NetConf.get_default():
            NetConf.get_default().remove_settings()
            NetConf.default_inst = self

        try:
            create_bridge("pan1")
        except BridgeException as e:
            if e.errno != errno.EEXIST:
                raise

        ip_str = inet_ntoa(self.ip4_address)
        mask_str = inet_ntoa(self.ip4_mask)

        if self.ip4_changed or not self.locked("netconfig"):
            self.enable_ip4_forwarding()

            if have("ip"):
                ret = call(["ip", "link", "set", "dev", "pan1", "up"])
                if ret != 0:
                    raise NetworkSetupError("Failed to bring up interface pan1")
                ret = call(["ip", "address", "add", "/".join((ip_str, mask_str)), "dev", "pan1"])
                if ret != 0:
                    raise NetworkSetupError("Failed to add ip address %s with netmask %s" % (ip_str, mask_str))
            else:
                ret = call(["ifconfig", "pan1", ip_str, "netmask", mask_str, "up"])
                if ret != 0:
                    raise NetworkSetupError("Failed to add ip address %s with netmask %s" % (ip_str, mask_str))

            self.lock("netconfig")

        if self.ip4_changed or not self.locked("iptables"):
            self.del_ipt_rules()

            self.add_ipt_rule("nat", "POSTROUTING", "-s %s/%s -j MASQUERADE" % (ip_str, mask_str))
            self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT")
            self.add_ipt_rule("filter", "FORWARD", "-o pan1 -j ACCEPT")
            self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT")
            self.lock("iptables")

        if self.dhcp_handler:
            self.dhcp_handler.do_apply()
        self.ip4_changed = False

        self.store()
Example #21
0
    def apply_settings(self):
        if self.ip4_address is None or self.ip4_mask is None:
            if self.ip4_changed:
                self.ip4_changed = False
            self.store()
            return

        if self != NetConf.get_default():
            NetConf.get_default().remove_settings()
            NetConf.default_inst = self

        try:
            create_bridge("pan1")
        except BridgeException as e:
            if e.errno != errno.EEXIST:
                raise

        ip_str = inet_ntoa(self.ip4_address)
        mask_str = inet_ntoa(self.ip4_mask)

        if self.ip4_changed or not self.locked("netconfig"):
            self.enable_ip4_forwarding()

            if have("ip"):
                ret = call(["ip", "link", "set", "pan1", "up"])
                if ret != 0:
                    raise NetworkSetupError("Failed to bring up interface pan1")
                ret = call(["ip", "address", "add", "/".join((ip_str, mask_str)), "dev", "pan1"])
                if ret != 0:
                    raise NetworkSetupError("Failed to add ip address %s with netmask %s" % (ip_str, mask_str))
            else:
                ret = call(["ifconfig", "pan1", ip_str, "netmask", mask_str, "up"])
                if ret != 0:
                    raise NetworkSetupError("Failed to add ip address %s with netmask %s" % (ip_str, mask_str))

            self.lock("netconfig")

        if self.ip4_changed or not self.locked("iptables"):
            self.del_ipt_rules()

            self.add_ipt_rule("nat", "POSTROUTING", "-s %s/%s -j MASQUERADE" % (ip_str, mask_str))
            self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT")
            self.add_ipt_rule("filter", "FORWARD", "-o pan1 -j ACCEPT")
            self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT")
            self.lock("iptables")

        if self.dhcp_handler:
            self.dhcp_handler.do_apply()
        self.ip4_changed = False

        self.store()
Example #22
0
    def setup_network(self):
        self.Config = Config("org.blueman.network")

        gn_enable = self.Builder.get_object("gn-enable")
        # latest bluez does not support GN, apparently
        gn_enable.props.visible = False

        nap_enable = self.Builder.get_object("nap-enable")
        r_dnsmasq = self.Builder.get_object("r_dnsmasq")
        r_dhcpd = self.Builder.get_object("r_dhcpd")
        net_ip = self.Builder.get_object("net_ip")
        net_nat = self.Builder.get_object("net_nat")
        rb_nm = self.Builder.get_object("rb_nm")
        rb_blueman = self.Builder.get_object("rb_blueman")
        rb_dun_nm = self.Builder.get_object("rb_dun_nm")
        rb_dun_blueman = self.Builder.get_object("rb_dun_blueman")

        nap_frame = self.Builder.get_object("nap_frame")
        warning = self.Builder.get_object("warning")

        rb_blueman.props.active = self.Config["dhcp-client"]

        if not self.Config["nap-enable"]:
            nap_frame.props.sensitive = False

        nc = NetConf.get_default()
        if nc.ip4_address != None:
            net_ip.props.text = inet_ntoa(nc.ip4_address)
        else:
            net_ip.props.text = "10.%d.%d.1" % (randint(0, 255), randint(
                0, 255))

        #if ns["masq"] != 0:
        #	net_nat.props.active = ns["masq"]

        if nc.get_dhcp_handler() == None:
            nap_frame.props.sensitive = False
            nap_enable.props.active = False
        else:
            if nc.get_dhcp_handler() == DnsMasqHandler:
                r_dnsmasq.props.active = True
            else:
                r_dhcpd.props.active = True

        if not have("dnsmasq") and not have("dhcpd3") and not have("dhcpd"):
            nap_frame.props.sensitive = False
            warning.props.visible = True
            warning.props.sensitive = True
            nap_enable.props.sensitive = False

        if not have("dnsmasq"):
            r_dnsmasq.props.sensitive = False
            r_dnsmasq.props.active = False
            r_dhcpd.props.active = True

        if not have("dhcpd3") and not have("dhcpd"):
            r_dhcpd.props.sensitive = False
            r_dhcpd.props.active = False
            r_dnsmasq.props.active = True

        r_dnsmasq.connect("toggled",
                          lambda x: self.option_changed_notify("dnsmasq"))
        net_ip.connect("changed",
                       lambda x: self.option_changed_notify("ip", False))

        self.Config.bind_to_widget("nat", net_nat, "active")
        self.Config.bind_to_widget("gn-enable", gn_enable, "active")
        self.Config.bind_to_widget("nap-enable", nap_frame, "sensitive")
        self.Config.bind_to_widget("nap-enable", nap_enable, "active")

        applet = AppletService()

        avail_plugins = applet.QueryAvailablePlugins()
        active_plugins = applet.QueryPlugins()

        def dun_support_toggled(rb, x):
            if rb.props.active and x == "nm":
                applet.SetPluginConfig("PPPSupport", False)
                applet.SetPluginConfig("NMDUNSupport", True)
            elif rb.props.active and x == "blueman":
                applet.SetPluginConfig("NMDUNSupport", False)
                applet.SetPluginConfig("PPPSupport", True)

        def pan_support_toggled(rb, x):
            if rb.props.active and x == "nm":
                applet.SetPluginConfig("DhcpClient", False)
                applet.SetPluginConfig("NMPANSupport", True)

            elif rb.props.active and x == "blueman":
                applet.SetPluginConfig("NMPANSupport", False)
                applet.SetPluginConfig("DhcpClient", True)

        if "PPPSupport" in active_plugins:
            rb_dun_blueman.props.active = True

        if "NMDUNSupport" in avail_plugins:
            rb_dun_nm.props.sensitive = True
        else:
            rb_dun_nm.props.sensitive = False
            rb_dun_nm.props.tooltip_text = _(
                "Not currently supported with this setup")

        if "NMPANSupport" in avail_plugins:
            rb_nm.props.sensitive = True
        else:
            rb_nm.props.sensitive = False
            rb_nm.props.tooltip_text = _(
                "Not currently supported with this setup")

        if "NMPANSupport" in active_plugins:
            rb_nm.props.active = True

        if "NMDUNSupport" in active_plugins:
            rb_dun_nm.props.active = True

        rb_nm.connect("toggled", pan_support_toggled, "nm")
        rb_blueman.connect("toggled", pan_support_toggled, "blueman")

        rb_dun_nm.connect("toggled", dun_support_toggled, "nm")
        rb_dun_blueman.connect("toggled", dun_support_toggled, "blueman")
Example #23
0
    def setup_network(self):
        self.NetConf = Config("network")
        self.NetConf.connect("property-changed", self.on_property_changed)

        gn_enable = self.Builder.get_object("gn_enable")
        # latest bluez does not support GN, apparently
        gn_enable.props.visible = False

        nap_enable = self.Builder.get_object("nap_enable")
        r_dnsmasq = self.Builder.get_object("r_dnsmasq")
        r_dhcpd = self.Builder.get_object("r_dhcpd")
        net_ip = self.Builder.get_object("net_ip")
        net_nat = self.Builder.get_object("net_nat")
        rb_nm = self.Builder.get_object("rb_nm")
        rb_blueman = self.Builder.get_object("rb_blueman")
        rb_dun_nm = self.Builder.get_object("rb_dun_nm")
        rb_dun_blueman = self.Builder.get_object("rb_dun_blueman")

        nap_frame = self.Builder.get_object("nap_frame")
        warning = self.Builder.get_object("warning")

        rb_blueman.props.active = self.NetConf.props.dhcp_client
        nap_enable.props.active = self.NetConf.props.nap_enable
        gn_enable.props.active = self.NetConf.props.gn_enable

        net_ip.props.text = "10.%d.%d.1" % (randint(0, 255), randint(0, 255))

        if not self.NetConf.props.nap_enable:
            nap_frame.props.sensitive = False

        nc = NetConf.get_default()
        if nc.ip4_address != None:
            net_ip.props.text = inet_ntoa(nc.ip4_address)
            #if not self.NetConf.props.nap_enable:
            #	self.ignored_keys.append("nap_enable")
            self.NetConf.props.nap_enable = True


        #if ns["masq"] != 0:
        #	net_nat.props.active = ns["masq"]

        if nc.get_dhcp_handler() == None:
            nap_frame.props.sensitive = False
            nap_enable.props.active = False
            if self.NetConf.props.nap_enable or self.NetConf.props.nap_enable == None:
                self.ignored_keys.append("nap_enable")
            self.NetConf.props.nap_enable = False


        else:
            if nc.get_dhcp_handler() == DnsMasqHandler:
                r_dnsmasq.props.active = True
            else:
                r_dhcpd.props.active = True

        if not have("dnsmasq") and not have("dhcpd3") and not have("dhcpd"):
            nap_frame.props.sensitive = False
            warning.props.visible = True
            warning.props.sensitive = True
            nap_enable.props.sensitive = False
            if self.NetConf.props.nap_enable or self.NetConf.props.nap_enable == None:
                self.ignored_keys.append("nap_enable")
            self.NetConf.props.nap_enable = False

        if not have("dnsmasq"):
            r_dnsmasq.props.sensitive = False
            r_dnsmasq.props.active = False
            r_dhcpd.props.active = True

        if not have("dhcpd3") and not have("dhcpd"):
            r_dhcpd.props.sensitive = False
            r_dhcpd.props.active = False
            r_dnsmasq.props.active = True

        r_dnsmasq.connect("toggled", lambda x: self.option_changed_notify("dnsmasq"))

        net_nat.connect("toggled", lambda x: self.on_property_changed(self.NetConf, "nat", x.props.active))
        net_ip.connect("changed", lambda x: self.on_property_changed(self.NetConf, "ip", x.props.text))
        gn_enable.connect("toggled", lambda x: setattr(self.NetConf.props, "gn_enable", x.props.active))
        nap_enable.connect("toggled", lambda x: self.on_property_changed(self.NetConf, "nap_enable", x.props.active))

        applet = AppletService()

        avail_plugins = applet.QueryAvailablePlugins()
        active_plugins = applet.QueryPlugins()

        def dun_support_toggled(rb, x):
            if rb.props.active and x == "nm":
                applet.SetPluginConfig("PPPSupport", False)
                applet.SetPluginConfig("NMDUNSupport", True)
            elif rb.props.active and x == "blueman":
                applet.SetPluginConfig("NMDUNSupport", False)
                applet.SetPluginConfig("PPPSupport", True)

        def pan_support_toggled(rb, x):
            if rb.props.active and x == "nm":
                applet.SetPluginConfig("DhcpClient", False)
                applet.SetPluginConfig("NMPANSupport", True)

            elif rb.props.active and x == "blueman":
                applet.SetPluginConfig("NMPANSupport", False)
                applet.SetPluginConfig("DhcpClient", True)


        if "PPPSupport" in active_plugins:
            rb_dun_blueman.props.active = True

        if "NMDUNSupport" in avail_plugins:
            rb_dun_nm.props.sensitive = True
        else:
            rb_dun_nm.props.sensitive = False
            rb_dun_nm.props.tooltip_text = _("Not currently supported with this setup")

        if "NMPANSupport" in avail_plugins:
            rb_nm.props.sensitive = True
        else:
            rb_nm.props.sensitive = False
            rb_nm.props.tooltip_text = _("Not currently supported with this setup")

        if "NMPANSupport" in active_plugins:
            rb_nm.props.active = True

        if "NMDUNSupport" in active_plugins:
            rb_dun_nm.props.active = True

        rb_nm.connect("toggled", pan_support_toggled, "nm")
        rb_blueman.connect("toggled", pan_support_toggled, "blueman")

        rb_dun_nm.connect("toggled", dun_support_toggled, "nm")
        rb_dun_blueman.connect("toggled", dun_support_toggled, "blueman")
Example #24
0
    def setup_network(self):
        self.Config = Config("org.blueman.network")

        nap_enable = self.Builder.get_object("nap-enable")
        r_dnsmasq = self.Builder.get_object("r_dnsmasq")
        r_dhcpd = self.Builder.get_object("r_dhcpd")
        r_udhcpd = self.Builder.get_object("r_udhcpd")
        net_ip = self.Builder.get_object("net_ip")
        rb_nm = self.Builder.get_object("rb_nm")
        rb_blueman = self.Builder.get_object("rb_blueman")
        rb_dun_nm = self.Builder.get_object("rb_dun_nm")
        rb_dun_blueman = self.Builder.get_object("rb_dun_blueman")

        nap_frame = self.Builder.get_object("nap_frame")
        warning = self.Builder.get_object("warning")

        if not self.Config["nap-enable"]:
            nap_frame.props.sensitive = False

        nc = NetConf.get_default()
        if nc.ip4_address is not None:
            net_ip.props.text = inet_ntoa(nc.ip4_address)
            nap_enable.props.active = True
        else:
            net_ip.props.text = "10.%d.%d.1" % (randint(0, 255), randint(0, 255))

        if nc.get_dhcp_handler() is None:
            nap_frame.props.sensitive = False
            nap_enable.props.active = False
            r_dnsmasq.props.active = True
            self.Config["nap-enable"] = False

        have_dhcpd = have("dhcpd3") or have("dhcpd")
        have_dnsmasq = have("dnsmasq")
        have_udhcpd = have("udhcpd")

        if nc.get_dhcp_handler() == DnsMasqHandler and have_dnsmasq:
            r_dnsmasq.props.active = True
        elif nc.get_dhcp_handler() == DhcpdHandler and have_dhcpd:
            r_dhcpd.props.active = True
        elif nc.get_dhcp_handler() == UdhcpdHandler and have_udhcpd:
            r_udhcpd.props.active = True
        else:
            r_dnsmasq.props.active = True

        if not have_dnsmasq and not have_dhcpd and not have_udhcpd:
            nap_frame.props.sensitive = False
            warning.props.visible = True
            warning.props.sensitive = True
            nap_enable.props.sensitive = False
            self.Config["nap-enable"] = False

        if not have_dnsmasq:
            r_dnsmasq.props.sensitive = False
            r_dnsmasq.props.active = False

        if not have_dhcpd:
            r_dhcpd.props.sensitive = False
            r_dhcpd.props.active = False

        if not have_udhcpd:
            r_udhcpd.props.sensitive = False
            r_udhcpd.props.active = False

        r_dnsmasq.connect("toggled", lambda x: self.option_changed_notify("dnsmasq"))
        r_dhcpd.connect("toggled", lambda x: self.option_changed_notify("dhcpd"))
        r_udhcpd.connect("toggled", lambda x: self.option_changed_notify("udhcpd"))

        net_ip.connect("changed", lambda x: self.option_changed_notify("ip", False))
        nap_enable.connect("toggled", lambda x: self.option_changed_notify("nap_enable"))

        self.Config.bind_to_widget("nap-enable", nap_enable, "active", Gio.SettingsBindFlags.GET)

        nap_enable.bind_property("active", nap_frame, "sensitive", 0)

        applet = AppletService()

        avail_plugins = applet.QueryAvailablePlugins()
        active_plugins = applet.QueryPlugins()

        def dun_support_toggled(rb, x):
            if rb.props.active and x == "nm":
                applet.SetPluginConfig('(sb)', "PPPSupport", False)
                applet.SetPluginConfig('(sb)', "NMDUNSupport", True)
            elif rb.props.active and x == "blueman":
                applet.SetPluginConfig('(sb)', "NMDUNSupport", False)
                applet.SetPluginConfig('(sb)', "PPPSupport", True)

        def pan_support_toggled(rb, x):
            if rb.props.active and x == "nm":
                applet.SetPluginConfig('(sb)', "DhcpClient", False)
                applet.SetPluginConfig('(sb)', "NMPANSupport", True)

            elif rb.props.active and x == "blueman":
                applet.SetPluginConfig('(sb)', "NMPANSupport", False)
                applet.SetPluginConfig('(sb)', "DhcpClient", True)

        if "PPPSupport" in active_plugins:
            rb_dun_blueman.props.active = True

        if "NMDUNSupport" in avail_plugins:
            rb_dun_nm.props.sensitive = True
        else:
            rb_dun_nm.props.sensitive = False
            rb_dun_nm.props.tooltip_text = _("Not currently supported with this setup")

        if "DhcpClient" in active_plugins:
            rb_blueman.props.active = True

        if "NMPANSupport" in avail_plugins:
            rb_nm.props.sensitive = True
        else:
            rb_nm.props.sensitive = False
            rb_nm.props.tooltip_text = _("Not currently supported with this setup")

        if "NMPANSupport" in active_plugins:
            rb_nm.props.active = True

        if "NMDUNSupport" in active_plugins:
            rb_dun_nm.props.active = True

        rb_nm.connect("toggled", pan_support_toggled, "nm")
        rb_blueman.connect("toggled", pan_support_toggled, "blueman")

        rb_dun_nm.connect("toggled", dun_support_toggled, "nm")
        rb_dun_blueman.connect("toggled", dun_support_toggled, "blueman")
Example #25
0
def get_binary(*names):
    for name in names:
        path = have(name)
        if path:
            return path
    raise FileNotFoundError(f"{' '.join(names)} not found")
Example #26
0
    def setup_network(self):
        self.Config = Config("org.blueman.network")

        nap_enable = self.Builder.get_object("nap-enable")
        r_dnsmasq = self.Builder.get_object("r_dnsmasq")
        r_dhcpd = self.Builder.get_object("r_dhcpd")
        r_udhcpd = self.Builder.get_object("r_udhcpd")
        net_ip = self.Builder.get_object("net_ip")
        rb_nm = self.Builder.get_object("rb_nm")
        rb_blueman = self.Builder.get_object("rb_blueman")
        rb_dun_nm = self.Builder.get_object("rb_dun_nm")
        rb_dun_blueman = self.Builder.get_object("rb_dun_blueman")

        nap_frame = self.Builder.get_object("nap_frame")
        warning = self.Builder.get_object("warning")

        rb_blueman.props.active = self.Config["dhcp-client"]

        if not self.Config["nap-enable"]:
            nap_frame.props.sensitive = False

        nc = NetConf.get_default()
        if nc.ip4_address is not None:
            net_ip.props.text = inet_ntoa(nc.ip4_address)
            nap_enable.props.active = True
        else:
            net_ip.props.text = "10.%d.%d.1" % (randint(0, 255), randint(0, 255))

        if nc.get_dhcp_handler() is None:
            nap_frame.props.sensitive = False
            nap_enable.props.active = False
            r_dnsmasq.props.active = True
            self.Config["nap-enable"] = False

        if nc.get_dhcp_handler() == DnsMasqHandler:
            r_dnsmasq.props.active = True
        elif nc.get_dhcp_handler() == DhcpdHandler:
            r_dhcpd.props.active = True
        elif nc.get_dhcp_handler() == UdhcpdHandler:
            r_udhcpd.props.active = True

        if not have("dnsmasq") and not have("dhcpd3") and not have("dhcpd") and not have("udhcpd"):
            nap_frame.props.sensitive = False
            warning.props.visible = True
            warning.props.sensitive = True
            nap_enable.props.sensitive = False
            self.Config["nap-enable"] = False

        if not have("dnsmasq"):
            r_dnsmasq.props.sensitive = False
            r_dnsmasq.props.active = False

        if not have("dhcpd3") and not have("dhcpd"):
            r_dhcpd.props.sensitive = False
            r_dhcpd.props.active = False

        if not have("udhcpd"):
            r_udhcpd.props.sensitive = False
            r_udhcpd.props.active = False

        r_dnsmasq.connect("toggled", lambda x: self.option_changed_notify("dnsmasq"))
        r_udhcpd.connect("toggled", lambda x: self.option_changed_notify("udhcpd"))

        net_ip.connect("changed", lambda x: self.option_changed_notify("ip", False))
        nap_enable.connect("toggled", lambda x: self.option_changed_notify("nap_enable"))

        self.Config.bind_to_widget("nap-enable", nap_enable, "active", Gio.SettingsBindFlags.GET)

        nap_enable.bind_property("active", nap_frame, "sensitive", 0)

        applet = AppletService()

        avail_plugins = applet.QueryAvailablePlugins()
        active_plugins = applet.QueryPlugins()

        def dun_support_toggled(rb, x):
            if rb.props.active and x == "nm":
                applet.SetPluginConfig('(sb)', "PPPSupport", False)
                applet.SetPluginConfig('(sb)', "NMDUNSupport", True)
            elif rb.props.active and x == "blueman":
                applet.SetPluginConfig('(sb)', "NMDUNSupport", False)
                applet.SetPluginConfig('(sb)', "PPPSupport", True)

        def pan_support_toggled(rb, x):
            if rb.props.active and x == "nm":
                applet.SetPluginConfig('(sb)', "DhcpClient", False)
                applet.SetPluginConfig('(sb)', "NMPANSupport", True)

            elif rb.props.active and x == "blueman":
                applet.SetPluginConfig('(sb)', "NMPANSupport", False)
                applet.SetPluginConfig('(sb)', "DhcpClient", True)

        if "PPPSupport" in active_plugins:
            rb_dun_blueman.props.active = True

        if "NMDUNSupport" in avail_plugins:
            rb_dun_nm.props.sensitive = True
        else:
            rb_dun_nm.props.sensitive = False
            rb_dun_nm.props.tooltip_text = _("Not currently supported with this setup")

        if "NMPANSupport" in avail_plugins:
            rb_nm.props.sensitive = True
        else:
            rb_nm.props.sensitive = False
            rb_nm.props.tooltip_text = _("Not currently supported with this setup")

        if "NMPANSupport" in active_plugins:
            rb_nm.props.active = True

        if "NMDUNSupport" in active_plugins:
            rb_dun_nm.props.active = True

        rb_nm.connect("toggled", pan_support_toggled, "nm")
        rb_blueman.connect("toggled", pan_support_toggled, "blueman")

        rb_dun_nm.connect("toggled", dun_support_toggled, "nm")
        rb_dun_blueman.connect("toggled", dun_support_toggled, "blueman")