summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xeconnman-bin.in212
1 files changed, 197 insertions, 15 deletions
diff --git a/econnman-bin.in b/econnman-bin.in
index 2715f1d..4f23acb 100755
--- a/econnman-bin.in
+++ b/econnman-bin.in
@@ -56,10 +56,10 @@ except:
56 56
57dbus_ml = DBusEcoreMainLoop() 57dbus_ml = DBusEcoreMainLoop()
58bus = dbus.SystemBus(mainloop=dbus_ml) 58bus = dbus.SystemBus(mainloop=dbus_ml)
59log = logging.getLogger("econnman") 59log = logging.getLogger("econnman-bin")
60log_handler = logging.StreamHandler() 60log_handler = logging.StreamHandler()
61log_formatter = logging.Formatter( 61log_formatter = logging.Formatter(
62 "%(relativeCreated)d %(levelname)s %(name)s: %(message)s" 62 "%(created)d %(name)s [%(levelname)s]:: %(message)s (@lineno %(lineno)d)"
63 ) 63 )
64log_handler.setFormatter(log_formatter) 64log_handler.setFormatter(log_formatter)
65log.addHandler(log_handler) 65log.addHandler(log_handler)
@@ -347,6 +347,20 @@ class ObjectView(object):
347 sc.callback_changed_add(callback) 347 sc.callback_changed_add(callback)
348 return sc, items 348 return sc, items
349 349
350 def add_label_and_segment_control(self, box, options, callback, label):
351 lb = self.add_label(box, label)
352
353 sc = SegmentControl(box)
354 sc.size_hint_weight = EXPAND_HORIZ
355 sc.size_hint_align = FILL_BOTH
356 items = {}
357 for o in options:
358 items[o] = sc.item_add(None, o)
359 sc.show()
360 box.pack_end(sc)
361 sc.callback_changed_add(callback)
362 return lb, sc, items
363
350 def add_frame_and_box(self, box, label): 364 def add_frame_and_box(self, box, label):
351 fr = Frame(box) 365 fr = Frame(box)
352 fr.size_hint_weight = EXPAND_HORIZ 366 fr.size_hint_weight = EXPAND_HORIZ
@@ -925,6 +939,28 @@ class ServiceView(ObjectView):
925 """ 939 """
926 bus_interface = "net.connman.Service" 940 bus_interface = "net.connman.Service"
927 941
942 ipv4_fields = (#("Method", "ipv4_method"),
943 ("Address", "ipv4_address"),
944 ("Netmask", "ipv4_netmask"),
945 ("Gateway", "ipv4_gateway"),
946 )
947 ipv6_fields = (#("Method", "ipv6_method"),
948 ("Address", "ipv6_address"),
949 ("Prefix Length", "ipv6_prefix_length"),
950 ("Gateway", "ipv6_gateway"),
951 #("Privacy", "ipv6_privacy"),
952 )
953 proxy_fields = (("Method", "proxy_method"),
954 ("URL", "proxy_url"),
955 ("Servers", "proxy_servers"),
956 ("Excludes", "proxy_excludes"),
957 )
958 vpn_fields = ( # named Provider in spec
959 ("Host", "vpn_host"),
960 ("Domain", "vpn_domain"),
961 ("Name", "vpn_name"),
962 ("Type", "vpn_type"),
963 )
928 eth_fields = (("Method", "eth_method"), 964 eth_fields = (("Method", "eth_method"),
929 ("Interface", "eth_iface"), 965 ("Interface", "eth_iface"),
930 ("Address", "eth_addr"), 966 ("Address", "eth_addr"),
@@ -932,15 +968,6 @@ class ServiceView(ObjectView):
932 ("Speed", "eth_speed"), 968 ("Speed", "eth_speed"),
933 ("Duplex", "eth_duplex"), 969 ("Duplex", "eth_duplex"),
934 ) 970 )
935 vpn_fields = (("Host", "vpn_host"),
936 ("Domain", "vpn_domain"),
937 ("Name", "vpn_name"),
938 ("Type", "vpn_type"),
939 )
940 ipv4_fields = (("Address", "ipv4_address"),
941 ("Netmask", "ipv4_netmask"),
942 ("Gateway", "ipv4_gateway"),
943 )
944 971
945 top_widgets = ( 972 top_widgets = (
946 "connect", 973 "connect",
@@ -959,6 +986,7 @@ class ServiceView(ObjectView):
959 "domains_label", 986 "domains_label",
960 "domains_entry", 987 "domains_entry",
961 "ipv4_frame", 988 "ipv4_frame",
989 "ipv6_frame",
962 "proxy_frame", 990 "proxy_frame",
963 "ethernet_frame", 991 "ethernet_frame",
964 "vpn_frame", 992 "vpn_frame",
@@ -1033,10 +1061,22 @@ class ServiceView(ObjectView):
1033 en.callback_unfocused_add(self._on_ipv4_property_unfocused) 1061 en.callback_unfocused_add(self._on_ipv4_property_unfocused)
1034 setattr(self, attr, en) 1062 setattr(self, attr, en)
1035 1063
1036 # section: IPv6: similar to ipv4? refactor ipv4? 1064 # section: IPv6
1037 if properties.get("IPv6"): 1065 self.ipv6_properties = {"IPv6": {}, "IPv6.Configuration": {}}
1038 fr, bx = self.add_frame_and_box(self.box, "IPv6") 1066 fr, bx = self.add_frame_and_box(self.box, "IPv6")
1039 lb = self.add_label(bx, "TODO") 1067 self.ipv6_frame = fr
1068 self.ipv6_box = bx
1069 options = ("Automatic", "Manual", "Off")
1070 self.ipv6_method, self.ipv6_method_items = self.add_segment_control(
1071 bx, options, self._on_ipv6_method)
1072 for name, attr in self.ipv6_fields:
1073 lb, en = self.add_label_and_entry(bx, name)
1074 en.callback_activated_add(self._on_ipv6_property_changed)
1075 en.callback_unfocused_add(self._on_ipv6_property_unfocused)
1076 setattr(self, attr, en)
1077 options = ("Disabled", "Enabled", "Prefered")
1078 self.ipv6_privacy_lb, self.ipv6_privacy, self.ipv6_privacy_items = self.add_label_and_segment_control(
1079 bx, options, self._on_ipv6_privacy, "Privacy")
1040 1080
1041 # section: Proxy: custom contents for direct, auto and manual 1081 # section: Proxy: custom contents for direct, auto and manual
1042 # - direct: nothing 1082 # - direct: nothing
@@ -1186,6 +1226,11 @@ class ServiceView(ObjectView):
1186 self.ipv4_address.disabled = value 1226 self.ipv4_address.disabled = value
1187 self.ipv4_netmask.disabled = value 1227 self.ipv4_netmask.disabled = value
1188 self.ipv4_gateway.disabled = value 1228 self.ipv4_gateway.disabled = value
1229 self.ipv6_method.disabled = value
1230 self.ipv6_address.disabled = value
1231 self.ipv6_prefix_length.disabled = value
1232 self.ipv6_gateway.disabled = value
1233 self.ipv6_privacy.disabled = value
1189 self.proxy_method.disabled = value 1234 self.proxy_method.disabled = value
1190 elif name == "Favorite": 1235 elif name == "Favorite":
1191 value = bool(value) 1236 value = bool(value)
@@ -1250,6 +1295,47 @@ class ServiceView(ObjectView):
1250 self.ipv4_method_items["Off"].selected = True 1295 self.ipv4_method_items["Off"].selected = True
1251 elif method: 1296 elif method:
1252 log.error("Unknown method: %s", method) 1297 log.error("Unknown method: %s", method)
1298 elif name in ("IPv6", "IPv6.Configuration"):
1299 self.ipv6_properties[name] = value
1300 used = self.ipv6_properties["IPv6"]
1301 conf = self.ipv6_properties["IPv6.Configuration"]
1302
1303 def get_val(name):
1304 v = used.get(name) or conf.get(name)
1305 if not v:
1306 return ""
1307 return str(v)
1308 self.ipv6_address.text = get_val("Address")
1309 self.ipv6_prefix_length.text = get_val("PrefixLength")
1310 self.ipv6_gateway.text = get_val("Gateway")
1311
1312 method = str(conf.get("Method", ""))
1313 editable = (method == "manual") and (not self.immutable)
1314 self.ipv6_address.editable = editable
1315 self.ipv6_prefix_length.editable = editable
1316 self.ipv6_gateway.editable = editable
1317 # privacy has only meaning if Method is set to "auto"
1318 editable = (method == "auto") and (not self.immutable)
1319 self.ipv6_privacy.disabled = not editable
1320
1321 if method in ("auto", "fixed", "6to4"):
1322 self.ipv6_method_items["Automatic"].selected = True
1323 elif method == "manual":
1324 self.ipv6_method_items["Manual"].selected = True
1325 elif method == "off":
1326 self.ipv6_method_items["Off"].selected = True
1327 elif method:
1328 log.error("Unknown method: %s", method)
1329
1330 privacy = str(conf.get("Privacy", ""))
1331 if privacy == "disabled":
1332 self.ipv6_privacy_items["Disabled"].selected = True
1333 elif privacy == "enabled":
1334 self.ipv6_privacy_items["Enabled"].selected = True
1335 elif privacy == "prefered":
1336 self.ipv6_privacy_items["Prefered"].selected = True
1337 elif privacy:
1338 log.error("Unknown privacy: %s", privacy)
1253 1339
1254 elif name in ("Proxy", "Proxy.Configuration"): 1340 elif name in ("Proxy", "Proxy.Configuration"):
1255 self.proxy_properties[name] = value 1341 self.proxy_properties[name] = value
@@ -1437,6 +1523,102 @@ class ServiceView(ObjectView):
1437 self.ipv4_netmask.text = get_val("Netmask") 1523 self.ipv4_netmask.text = get_val("Netmask")
1438 self.ipv4_gateway.text = get_val("Gateway") 1524 self.ipv4_gateway.text = get_val("Gateway")
1439 1525
1526 def _ipv6_apply(self):
1527 value = self.ipv6_method.item_selected.text
1528 if value == "Automatic":
1529 method = "auto"
1530 elif value == "Manual":
1531 method = "manual"
1532 elif value == "Off":
1533 method = "off"
1534
1535 def make_variant(s):
1536 return dbus.String(s, variant_level=1)
1537 new = {"Method": make_variant(method)}
1538 if method == "manual":
1539 if self.ipv6_address.text:
1540 new["Address"] = make_variant(self.ipv6_address.text)
1541 if self.ipv6_prefix_length.text:
1542 new["PrefixLength"] = make_variant(self.ipv6_prefix_length.text)
1543 if self.ipv6_gateway.text:
1544 new["Gateway"] = make_variant(self.ipv6_gateway.text)
1545 value = self.ipv6_privacy.item_selected.text
1546 if value:
1547 new["Privacy"] = make_variant(value)
1548 if len(new) == 1: # no properties yet
1549 return
1550
1551 conf = self.ipv6_properties["IPv6.Configuration"]
1552 changed = []
1553 for k, v in new.items():
1554 if conf.get(k) != v:
1555 changed.append(k)
1556 log.debug("Changed IPv6: %s", ", ".join(changed))
1557 if not changed:
1558 return
1559
1560 def on_reply():
1561 log.info("Set IPv6=%s", new)
1562
1563 def on_error(exc):
1564 log.error("Failed to set IPv6.Configuration=%s: %s", new, exc)
1565 popup_error(self.obj, "Failed to Apply IPv6",
1566 exc.get_dbus_message())
1567 self.bus_obj.SetProperty(
1568 "IPv6.Configuration", new,
1569 reply_handler=on_reply, error_handler=on_error
1570 )
1571
1572 def _on_ipv6_method(self, obj, item):
1573 if item.text == "Automatic":
1574 method = "auto"
1575 elif item.text == "Manual":
1576 method = "manual"
1577 elif item.text == "Off":
1578 method = "off"
1579 conf = self.ipv6_properties["IPv6.Configuration"]
1580
1581 editable = (method == "manual") and (not self.immutable)
1582 self.ipv6_address.editable = editable
1583 self.ipv6_prefix_length.editable = editable
1584 self.ipv6_gateway.editable = editable
1585 # privacy has only meaning if Method is set to "auto"
1586 editable = (method == "auto") and (not self.immutable)
1587 self.ipv6_privacy.disabled = not editable
1588
1589 if method == conf["Method"]:
1590 return
1591 self._ipv6_apply()
1592
1593 def _on_ipv6_privacy(self, obj, item):
1594 if item.text == "Disabled":
1595 privacy = "disabled"
1596 elif item.text == "Enabled":
1597 privacy = "enabled"
1598 elif item.text == "Prefered":
1599 privacy = "prefered"
1600 conf = self.ipv6_properties["IPv6.Configuration"]
1601 if privacy == conf["Privacy"]:
1602 return
1603 self._ipv6_apply()
1604
1605 def _on_ipv6_property_changed(self, obj):
1606 self._ipv6_apply()
1607
1608 def _on_ipv6_property_unfocused(self, obj):
1609 used = self.ipv6_properties["IPv6"]
1610 conf = self.ipv6_properties["IPv6.Configuration"]
1611
1612 def get_val(name):
1613 v = used.get(name) or conf.get(name)
1614 if not v:
1615 return ""
1616 return str(v)
1617 self.ipv6_address.text = get_val("Address")
1618 self.ipv6_prefix_length.text = get_val("PrefixLength")
1619 self.ipv6_gateway.text = get_val("Gateway")
1620 #self.ipv6_privacy.text = get_val("Privacy")
1621
1440 def _on_proxy_method(self, obj, item): 1622 def _on_proxy_method(self, obj, item):
1441 if item.text == "Direct": 1623 if item.text == "Direct":
1442 method = "direct" 1624 method = "direct"