def ip_check(self): e = self.Builder.get_object("net_ip") address = e.props.text try: if address.count(".") != 3: raise Exception a = inet_aton(address) except: e.props.secondary_icon_name = "dialog-error" e.props.secondary_icon_tooltip_text = _("Invalid IP address") raise a_netmask = inet_aton("255.255.255.0") a_masked = mask_ip4_address(a, a_netmask) for iface, ip, netmask, masked in self.interfaces: # print mask_ip4_address(a, netmask).encode("hex_codec"), masked.encode("hex_codec") if a == ip: e.props.secondary_icon_name = "dialog-error" e.props.secondary_icon_tooltip_text = _( "IP address conflicts with interface %s which has the same address" % iface) raise Exception elif mask_ip4_address(a, netmask) == masked: e.props.secondary_icon_name = "dialog-warning" e.props.secondary_icon_tooltip_text = _( "IP address overlaps with subnet of interface" " %s, which has the following configuration %s/%s\nThis may cause incorrect network behavior" % (iface, inet_ntoa(ip), inet_ntoa(netmask))) return e.props.secondary_icon_name = None
def ip_check(self): e = self.Builder.get_object("net_ip") address = e.props.text try: if address.count(".") != 3: raise Exception a = inet_aton(address) except: e.props.secondary_icon_name = "dialog-error" e.props.secondary_icon_tooltip_text = _("Invalid IP address") raise a_netmask = inet_aton("255.255.255.0") a_masked = mask_ip4_address(a, a_netmask) for iface, ip, netmask, masked in self.interfaces: # print mask_ip4_address(a, netmask).encode("hex_codec"), masked.encode("hex_codec") if a == ip: e.props.secondary_icon_name = "dialog-error" e.props.secondary_icon_tooltip_text = _("IP address conflicts with interface %s which has the same address" % iface) raise Exception elif mask_ip4_address(a, netmask) == masked: e.props.secondary_icon_name = "dialog-warning" e.props.secondary_icon_tooltip_text = _("IP address overlaps with subnet of interface" " %s, which has the following configuration %s/%s\nThis may cause incorrect network behavior" % (iface, inet_ntoa(ip), inet_ntoa(netmask))) return e.props.secondary_icon_name = None
def _generate_subnet_config(self): dns = self.get_dns_servers() masked_ip = mask_ip4_address(self.netconf.ip4_address, self.netconf.ip4_mask) start, end = calc_ip_range(self.netconf.ip4_address) subnet = "#### BLUEMAN AUTOMAGIC SUBNET ####\n" subnet += "# Everything inside this section is destroyed after config change\n" subnet += """subnet %(ip_mask)s netmask %(netmask)s { option domain-name-servers %(dns)s; option subnet-mask %(netmask)s; option routers %(rtr)s; range %(start)s %(end)s; }\n""" % { "ip_mask": inet_ntoa(masked_ip), "netmask": inet_ntoa(self.netconf.ip4_mask), "dns": dns, "rtr": inet_ntoa(self.netconf.ip4_address), "start": inet_ntoa(start), "end": inet_ntoa(end) } subnet += "#### END BLUEMAN AUTOMAGIC SUBNET ####\n" return subnet
def ip_check(self): entry = self.Builder.get_object("net_ip") try: ipaddr = ipaddress.IPv4Address(entry.props.text) a = inet_aton(str(ipaddr)) except ipaddress.AddressValueError: entry.props.secondary_icon_name = "dialog-error" entry.props.secondary_icon_tooltip_text = _("Invalid IP address") raise for iface, ip, netmask, masked in self.interfaces: if a == ip: error_message = _("IP address conflicts with interface %s which has the same address" % iface) tooltip_text = error_message entry.props.secondary_icon_name = "dialog-error" entry.props.secondary_icon_tooltip_text = tooltip_text raise ValueError(error_message) elif mask_ip4_address(a, netmask) == masked: tooltip_text = _( "IP address overlaps with subnet of interface %s, which has the following configuration %s/%s\n" "This may cause incorrect network behavior" % (iface, inet_ntoa(ip), inet_ntoa(netmask))) entry.props.secondary_icon_name = "dialog-warning" entry.props.secondary_icon_tooltip_text = tooltip_text return entry.props.secondary_icon_name = None
def on_load(self, container): self.Builder = Gtk.Builder() self.Builder.set_translation_domain("blueman") self.Builder.add_from_file(UI_PATH + "/services-network.ui") self.widget = self.Builder.get_object("network") self.ignored_keys = [] container.pack_start(self.widget, True, True, 0) self.interfaces = [] for iface in get_net_interfaces(): if iface != "lo" and iface != "pan1": print(iface) ip = inet_aton(get_net_address(iface)) mask = inet_aton(get_net_netmask(iface)) self.interfaces.append((iface, ip, mask, mask_ip4_address(ip, mask))) self.setup_network() try: self.ip_check() except: pass return (_("Network"), "network-workgroup")
def on_load(self, container): self.Builder = Gtk.Builder() self.Builder.set_translation_domain("blueman") bind_textdomain_codeset("blueman", "UTF-8") self.Builder.add_from_file(UI_PATH + "/services-network.ui") self.widget = self.Builder.get_object("network_frame") container.pack_start(self.widget, True, True, 0) self.interfaces = [] for iface in get_net_interfaces(): if iface != "lo" and iface != "pan1": logging.info(iface) ip = inet_aton(get_net_address(iface)) mask = inet_aton(get_net_netmask(iface)) self.interfaces.append( (iface, ip, mask, mask_ip4_address(ip, mask))) self.setup_network() try: self.ip_check() except Exception as e: logging.exception(e) return (_("Network"), "network-workgroup")
def on_load(self, container): self.Builder = Gtk.Builder() self.Builder.set_translation_domain("blueman") self.Builder.add_from_file(UI_PATH + "/services-network.ui") self.widget = self.Builder.get_object("network") self.ignored_keys = [] container.pack_start(self.widget, True, True, 0) self.interfaces = [] for iface in get_net_interfaces(): if iface != "lo" and iface != "pan1": print(iface) ip = inet_aton(get_net_address(iface)) mask = inet_aton(get_net_netmask(iface)) self.interfaces.append( (iface, ip, mask, mask_ip4_address(ip, mask))) self.setup_network() try: self.ip_check() except: pass return (_("Network"), "network-workgroup")
def _generate_config(self): dns = get_dns_servers() masked_ip = mask_ip4_address(self.netconf.ip4_address, self.netconf.ip4_mask) start, end = calc_ip_range(self.netconf.ip4_address) return UDHCP_CONF_TEMPLATE % {"ip_mask": inet_ntoa(masked_ip), "dns": dns, "rtr": inet_ntoa(self.netconf.ip4_address), "start": inet_ntoa(start), "end": inet_ntoa(end)}
def _generate_config(self): dns = get_dns_servers() masked_ip = mask_ip4_address(self.netconf.ip4_address, self.netconf.ip4_mask) start, end = calc_ip_range(self.netconf.ip4_address) return """start %(start)s end %(end)s interface pan1 pidfile /var/run/udhcpd.pan1.pid option subnet %(ip_mask)s option dns %(dns)s option router %(rtr)s """ % {"ip_mask": inet_ntoa(masked_ip), "dns": dns, "rtr": inet_ntoa(self.netconf.ip4_address), "start": inet_ntoa(start), "end": inet_ntoa(end) }
def _generate_subnet_config(self): dns = get_dns_servers() masked_ip = mask_ip4_address(self.netconf.ip4_address, self.netconf.ip4_mask) start, end = calc_ip_range(self.netconf.ip4_address) subnet = "#### BLUEMAN AUTOMAGIC SUBNET ####\n" subnet += "# Everything inside this section is destroyed after config change\n" subnet += """subnet %(ip_mask)s netmask %(netmask)s { option domain-name-servers %(dns)s; option subnet-mask %(netmask)s; option routers %(rtr)s; range %(start)s %(end)s; }\n""" % {"ip_mask": inet_ntoa(masked_ip), "netmask": inet_ntoa(self.netconf.ip4_mask), "dns": dns, "rtr": inet_ntoa(self.netconf.ip4_address), "start": inet_ntoa(start), "end": inet_ntoa(end)} subnet += "#### END BLUEMAN AUTOMAGIC SUBNET ####\n" return subnet
def on_load(self, container): self.Builder = Gtk.Builder() self.Builder.set_translation_domain("blueman") bind_textdomain_codeset("blueman", "UTF-8") self.Builder.add_from_file(UI_PATH + "/services-network.ui") self.widget = self.Builder.get_object("network_frame") container.pack_start(self.widget, True, True, 0) self.interfaces = [] for iface in get_net_interfaces(): if iface != "lo" and iface != "pan1": logging.info(iface) ip = inet_aton(get_net_address(iface)) mask = inet_aton(get_net_netmask(iface)) self.interfaces.append((iface, ip, mask, mask_ip4_address(ip, mask))) self.setup_network() try: self.ip_check() except Exception as e: logging.exception(e) return (_("Network"), "network-workgroup")