示例#1
0
def kernelEvent(data):
    type, dir = data.split("@", 1)
    if not dir.startswith("/class/net/"):
        return
    devname = dir[11:]
    flag = 1

    ifc = netutils.IF(devname)
    if type == "add":
        if not ifc.isWireless():
            return
        devuid = ifc.deviceUID()
        notify("Net.Link", "deviceChanged", ("added", "wifi", devuid, netutils.deviceName(devuid)))
        conns = DB.listDB()
        for conn in conns:
            dev = Dev(conn)
            if dev.ifc and dev.ifc.name == devname:
                if dev.state == "up":
                    dev.up()
                    return
                flag = 0
        if flag:
            notify("Net.Link", "deviceChanged", ("new", "wifi", devuid, netutils.deviceName(devuid)))

    elif type == "remove":
        conns = DB.listDB()
        for conn in conns:
            dev = Dev(conn)
            # FIXME: ifc is not enough here :(
            if dev.ifc and dev.ifc.name == devname:
                if dev.state == "up":
                    notify("Net.Link", "stateChanged", (dev.name, "inaccessible", "Device removed"))
        notify("Net.Link", "deviceChanged", ("removed", "wifi", devname, ""))
示例#2
0
def kernelEvent(data):
    type, dir = data.split("@", 1)
    if not dir.startswith("/class/net/"):
        return
    devname = dir[11:]
    flag = 1

    if type == "add":
        ifc = netutils.IF(devname)
        if ifc.isWireless():
            return
        devuid = ifc.deviceUID()
        notify("Net.Link", "deviceChanged", ("add", "net", devuid, netutils.deviceName(devuid)))
        conns = DB.listDB()
        for conn in conns:
            dev = Dev(conn)
            if dev.ifc and dev.ifc.name == devname:
                if dev.state == "up":
                    dev.up()
                    return
                flag = 0
        if flag:
            notify("Net.Link", "deviceChanged", ("new", "net", devuid, netutils.deviceName(devuid)))

    elif type == "remove":
        conns = DB.listDB()
        for conn in conns:
            dev = Dev(conn)
            # FIXME: dev.ifc is not enough :(
            if dev.ifc and dev.ifc.name == devname:
                if dev.state == "up":
                    notify("Net.Link", "stateChanged", (dev.name, "inaccessible", "Device removed"))
        notify("Net.Link", "deviceChanged", ("removed", "net", devname, ""))
示例#3
0
def deviceList():
    iflist = {}
    for ifc in netutils.interfaces():
        if ifc.isWireless():
            uid = ifc.deviceUID()
            info = netutils.deviceName(uid)
            iflist[uid] = info
    return iflist
示例#4
0
文件: link.py 项目: blue-devil/kuller
def deviceList():
    iflist = {}
    for ifc in netutils.interfaces():
        if ifc.isWireless():
            uid = ifc.deviceUID()
            info = netutils.deviceName(uid)
            iflist[uid] = info
    return iflist
示例#5
0
def kernelEvent(data):
    type, dir = data.split("@", 1)
    if not "/net/" in dir:
        return
    device = dir.split("/net/")[-1]
    new = True

    if type == "add":
        # Get device information
        ifc = netutils.IF(device)
        device_id = ifc.deviceUID()
        if not ifc.isWireless():
            return
        # Notify clients
        notify("Network.Link", "deviceChanged",
               ("add", "wifi", device_id, netutils.deviceName(device_id)))
        # Bring related connection up
        for pn in listProfiles():
            profile = Profile(pn)
            if profile.info.get("device", None) == device_id:
                new = False
                if profile.info.get("state", "down").startswith("unplugged"):
                    setState(pn, "up")
                    break
        # Notify clients if device has no connections
        if new:
            notify("Network.Link", "deviceChanged",
                   ("new", "wifi", device_id, netutils.deviceName(device_id)))
    elif type == "remove":
        # Bring related connection down
        for pn in listProfiles():
            profile = Profile(pn)
            if profile.info.get("device",
                                "").split(":")[-1].split("_")[-1] == device:
                if profile.info.get("state", "down").startswith("up"):
                    # Stop ifplug daemon
                    plugService(device, "down", wireless=True)
                    setState(pn, "unplugged")
                    break
        # Notify clients
        notify("Network.Link", "deviceChanged",
               ("removed", "wifi", device, ""))
示例#6
0
def connectionInfo(name=None):
    dev = Dev(name, True)
    d = {}
    d["name"] = name
    if dev.uid:
        d["device_id"] = dev.uid
        d["device_name"] = netutils.deviceName(dev.uid)
    if dev.remote:
        d["remote"] = dev.remote
        if dev.apmac:
            d["apmac"] = dev.apmac
        if dev.channel:
            d["channel"] = dev.channel
    d["net_mode"] = dev.mode
    if dev.address:
        d["net_address"] = dev.address
    if dev.mask:
        d["net_mask"] = dev.mask
    if dev.gateway:
        d["net_gateway"] = dev.gateway
    d["namemode"] = dev.namemode
    if dev.nameserver:
        d["nameserver"] = dev.nameserver
    if dev.device_mode:
        d["device_mode"] = dev.device_mode
    if dev.state == "up":
        if dev.ifc:
            if dev.mode == "auto":
                if dev.ifc.isAuto() and dev.ifc.isUp():
                    state = "up "
                    try:
                        state += dev.ifc.getAddress()[0]
                    except:
                        pass
                else:
                    state = "inaccessible " + _(dhcp_fail_msg)
            else:
                if dev.ifc.isUp():
                    state = "up "
                    try:
                        state += dev.ifc.getAddress()[0]
                    except:
                        pass
                else:
                    state = "down"
        else:
            state = "inaccessible " + _(no_device_msg)
    else:
        if dev.ifc:
            state = "down"
        else:
            state = "unavailable"
    d["state"] = state
    return d
示例#7
0
def connectionInfo(name=None):
    dev = Dev(name, True)
    d = {}
    d["name"] = name
    if dev.uid:
        d["device_id"] = dev.uid
        d["device_name"] = netutils.deviceName(dev.uid)
    if dev.remote:
        d["remote"] = dev.remote
        if dev.apmac:
            d["apmac"] = dev.apmac
        if dev.channel:
            d["channel"] = dev.channel
    d["net_mode"] = dev.mode
    if dev.address:
        d["net_address"] = dev.address
    if dev.mask:
        d["net_mask"] = dev.mask
    if dev.gateway:
        d["net_gateway"] = dev.gateway
    d["namemode"] = dev.namemode
    if dev.nameserver:
        d["nameserver"] = dev.nameserver
    if dev.device_mode:
        d["device_mode"] = dev.device_mode
    if dev.state == "up":
        if dev.ifc:
            if dev.mode == "auto":
                if dev.ifc.isAuto() and dev.ifc.isUp():
                    state = "up "
                    try:
                        state += dev.ifc.getAddress()[0]
                    except:
                        pass
                else:
                    state = "inaccessible " + _(dhcp_fail_msg)
            else:
                if dev.ifc.isUp():
                    state = "up "
                    try:
                        state += dev.ifc.getAddress()[0]
                    except:
                        pass
                else:
                    state = "down"
        else:
            state = "inaccessible " + _(no_device_msg)
    else:
        if dev.ifc:
            state = "down"
        else:
            state = "unavailable"
    d["state"] = state
    return d
示例#8
0
文件: link.py 项目: blue-devil/kuller
def kernelEvent(data):
    type, dir = data.split("@", 1)
    if not "/net/" in dir:
        return
    device = dir.split("/net/")[-1]
    new = True

    if type == "add":
        # Get device information
        ifc = netutils.IF(device)
        device_id = ifc.deviceUID()
        if not ifc.isWireless():
            return
        # Notify clients
        notify("Network.Link", "deviceChanged", ("add", "wifi", device_id, netutils.deviceName(device_id)))
        # Bring related connection up
        for pn in listProfiles():
            profile = Profile(pn)
            if profile.info.get("device", None) == device_id:
                new = False
                if profile.info.get("state", "down").startswith("unplugged"):
                    setState(pn, "up")
                    break
        # Notify clients if device has no connections
        if new:
            notify("Network.Link", "deviceChanged", ("new", "wifi", device_id, netutils.deviceName(device_id)))
    elif type == "remove":
        # Bring related connection down
        for pn in listProfiles():
            profile = Profile(pn)
            if profile.info.get("device", "").split(":")[-1].split("_")[-1] == device:
                if profile.info.get("state", "down").startswith("up"):
                    # Stop ifplug daemon
                    plugService(device, "down", wireless=True)
                    setState(pn, "unplugged")
                    break
        # Notify clients
        notify("Network.Link", "deviceChanged", ("removed", "wifi", device, ""))
示例#9
0
 def findInterfaces(wireless=True):
     ifaces = []
     for iface in netutils.interfaces():
         if iface.name.startswith("lo") or iface.name.startswith("pan"):
             continue
         if not wireless and iface.isWireless():
             continue
         if iface.isEthernet():
             dev_id = iface.deviceUID()
             dev_name = netutils.deviceName(iface.deviceUID())
             if " - " in dev_name:
                 dev_name = dev_name.split(" - ")[1]
             ifaces.append("%s\t%s" % (dev_id, dev_name))
     return ifaces
示例#10
0
 def findInterfaces(wireless=True):
     ifaces = []
     for iface in netutils.interfaces():
         if iface.name.startswith("lo") or iface.name.startswith("pan"):
             continue
         if not wireless and iface.isWireless():
             continue
         if iface.isEthernet():
             dev_id = iface.deviceUID()
             dev_name = netutils.deviceName(iface.deviceUID())
             if " - " in dev_name:
                 dev_name = dev_name.split(" - ")[1]
             ifaces.append("%s\t%s" % (dev_id, dev_name))
     return ifaces
示例#11
0
def connectionInfo(name):
    profile = Profile(name)
    device = profile.info["device"]
    return {
        "name": name,
        "device_id": device,
        "device_name": netutils.deviceName(device),
        "net_mode": profile.info.get("net_mode", "auto"),
        "net_address": profile.info.get("net_address", ""),
        "net_mask": profile.info.get("net_mask", ""),
        "net_gateway": profile.info.get("net_gateway", ""),
        "name_mode": profile.info.get("name_mode", "default"),
        "name_server": profile.info.get("name_server", ""),
        "state": profile.info.get("state", "down"),
    }
示例#12
0
def connectionInfo(name):
    profile = Profile(name)
    device = profile.info.get("device", "")
    return {
        "name": name,
        "device_id": device,
        "device_name": netutils.deviceName(device),
        "net_mode": profile.info.get("net_mode", "auto"),
        "net_address": profile.info.get("net_address", ""),
        "net_mask": profile.info.get("net_mask", ""),
        "net_gateway": profile.info.get("net_gateway", ""),
        "name_mode": profile.info.get("name_mode", "default"),
        "name_server": profile.info.get("name_server", ""),
        "state": profile.info.get("state", "down"),
    }