def __init__(self, name, want=False): dict = DB.getDB(name) if want: if not dict: fail("No such connection") self.uid = _get(dict, "device", None) self.name = name self.ifc = None if self.uid: self.ifc = netutils.findInterface(self.uid) self.state = _get(dict, "state", "down") self.remote = _get(dict, "remote", None) self.apmac = _get(dict, "apmac", None) self.mode = _get(dict, "mode", "auto") self.address = _get(dict, "address", None) self.mask = _get(dict, "mask", None) self.gateway = _get(dict, "gateway", None) self.authmode = _get(dict, "authmode", "none") self.user = _get(dict, "user", "") self.password = _get(dict, "password", "") self.channel = _get(dict, "channel", "") self.auth = _get(dict, "auth", "") self.user_anon = _get(dict, "user_anon", "") self.auth_inner = _get(dict, "phase2", "") self.auth_ca_cert = _get(dict, "ca_cert", "") self.auth_client_cert = _get(dict, "client_cert", "") self.auth_private_key = _get(dict, "private_key", "") self.auth_private_key_pass = _get(dict, "private_key_passwd", "") self.namemode = _get(dict, "namemode", "default") self.nameserver = _get(dict, "nameserver", None) self.device_mode = _get(dict, "device_mode", "Managed")
def scanRemote(device): if device: ifc = netutils.findInterface(device) if ifc: wifi = Wireless(ifc) points = map(lambda x: x.id(), wifi.scanSSID()) return points return []
def checkKillSwitch(self, deviceList): result = False from pardus import netutils for device in deviceList: interface = netutils.findInterface(device) rfkillstate = interface.sysValue("device/rf_kill") if rfkillstate and int(rfkillstate) != RFKILL_STATE_HARD_BLOCKED: result = True break return result
def __init__(self, name, want=False): dict = DB.getDB(name) if want: if not dict: fail("No such connection") self.uid = _get(dict, "device", None) self.name = name self.ifc = None if self.uid: self.ifc = netutils.findInterface(self.uid) self.state = _get(dict, "state", "down") self.remote = _get(dict, "remote", None) self.apmac = _get(dict, "apmac", None) self.mode = _get(dict, "mode", "auto") self.address = _get(dict, "address", None) self.mask = _get(dict, "mask", None) self.gateway = _get(dict, "gateway", None) self.authmode = _get(dict, "authmode", "none") self.user = _get(dict, "user", "") self.password = _get(dict, "password", "") self.namemode = _get(dict, "namemode", "default") self.nameserver = _get(dict, "nameserver", None)
def __init__(self, name, want=False): dict = DB.getDB(name) if want: if not dict: fail("No such connection") self.uid = _get(dict, "device", None) self.name = name self.ifc = None if self.uid: self.ifc = netutils.findInterface(self.uid) self.state = _get(dict, "state", "down") self.mode = _get(dict, "mode", "auto") self.address = _get(dict, "address", None) self.mask = _get(dict, "mask", None) self.gateway = _get(dict, "gateway", None) self.namemode = _get(dict, "namemode", "default") self.nameserver = _get(dict, "nameserver", None) self.mtu = _get(dict, "mtu", 1500) try: self.mtu = int(self.mtu) except: self.mtu = 1500
def setState(name, state): profile = Profile(name) ifname = profile.info["device"].split(":")[-1].split("_")[-1] iface = netutils.findInterface(profile.info["device"]) if state == "unplugged" or not iface: # Reset Network Stack unregisterNameServers(ifname) if state == "down": # Save state to profile database profile.info["state"] = "down" profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "down", "")) else: # Save state to profile database profile.info["state"] = "unplugged" profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "unplugged", "")) # Run profile script (/etc/network/netlink.d/profilename.down) callScript(name, "down") return # Here we go... device_mode = profile.info.get("device_mode", "managed") if device_mode == "managed": if state == "up": # Stop other profiles on same device stopSameDevice(name) # Notify clients notify("Network.Link", "stateChanged", (name, "connecting", "")) # Save state to profile database profile.info["state"] = "connecting" profile.save(no_notify=True) # Wifi settings wifi = Wireless(iface) wifi.setSSID(profile.info["remote"]) # Set encryption try: wifi.setEncryption(getAuthMethod(name), getAuthParameters(name)) except Exception, e: # Stop ifplug deamon plugService(ifname, "down") # Save state to profile database profile.info["state"] = "inaccessible %s" % unicode(e) profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "inaccessible", unicode(e))) fail(unicode(e)) if profile.info.get("net_mode", "auto") == "auto": # Start DHCP client ret = iface.startAuto() if ret == 0 and iface.isUp(): if "net_address" in profile.info or "net_gateway" in profile.info: net_address = profile.info.get("net_address", None) net_mask = profile.info.get("net_mask", "255.255.255.0") net_gateway = profile.info.get("net_gateway", None) if net_address: iface.setAddress(net_address, net_mask) if not net_gateway: gateways = iface.autoGateways() if len(gateways): net_gateway = gateways[0] if net_gateway: route = netutils.Route() route.setDefault(net_gateway) elif iface.getAddress(): net_address = iface.getAddress()[0] else: # Bring device down iface.down() # Save state to profile database profile.info["state"] = "inaccessible %s" % _(MSG_DHCP_FAILED) profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "inaccessible", _(MSG_DHCP_FAILED))) return # Set nameservers registerNameServers(profile, iface) # Save state to profile database profile.info["state"] = "up " + net_address profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "up", net_address)) # Run profile script (/etc/network/netlink.d/profilename.up) callScript(name, "up") # Start ifplug daemon plugService(ifname, "up", wireless=True) else: # Bring device down iface.down() # Save state to profile database profile.info["state"] = "inaccessible %s" % _(MSG_DHCP_FAILED) profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "inaccessible", _(MSG_DHCP_FAILED))) else: try: net_address = profile.info["net_address"] net_mask = profile.info["net_mask"] except KeyError: return # Set address iface.setAddress(net_address, net_mask) # Bring up interface if iface.up() == None: fail(_(MSG_NO_DRIVER)) # Set default gateway net_gateway = profile.info.get("net_gateway", "") if net_gateway: route = netutils.Route() route.setDefault(net_gateway) # Set nameservers registerNameServers(profile, iface) # Save state to profile database profile.info["state"] = "up " + net_address profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "up", net_address)) # Run profile script (/etc/network/netlink.d/profilename.up) callScript(name, "up") # Start ifplug deamon plugService(ifname, "up") elif state == "down": if profile.info.get("net_mode", "auto") == "auto": iface.stopAuto() # Set encryption to none wifi = Wireless(iface) wifi.setEncryption(None, None) # Reset Network Stack unregisterNameServers(ifname) # Bring device down iface.down() # Save state to profile database profile.info["state"] = "down" profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "down", "")) # Run profile script (/etc/network/netlink.d/profilename.down) callScript(name, "down")
def setState(name, state): profile = Profile(name) iface = netutils.findInterface(profile.info["device"]) if state == "up": # Stop other profiles on same device stopSameDevice(name) # Notify clients notify("Network.Link", "stateChanged", (name, "connecting", "")) # Save state to profile database profile.info["state"] = "connecting" profile.save(no_notify=True) if profile.info.get("net_mode", "auto") == "auto": # Start DHCP client ret = iface.startAuto() if ret == 0 and iface.isUp() and iface.getAddress(): address = iface.getAddress() # Set nameservers registerNameServers(profile, iface) # Save state to profile database profile.info["state"] = "up " + address[0] profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "up", address[0])) else: iface.down() # Save state to profile database profile.info["state"] = "down" profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "inaccesible", _(MSG_DHCP_FAILED))) else: try: net_address = profile.info["net_address"] net_mask = profile.info["net_mask"] net_gateway = profile.info["net_gateway"] except KeyError: return # Set address iface.setAddress(net_address, net_mask) iface.up() # Set default gateway route = netutils.Route() route.setDefault(net_gateway) # Set nameservers registerNameServers(profile, iface) # Save state to profile database profile.info["state"] = "up " + net_address profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "up", net_address)) elif state == "down": if profile.info.get("net_mode", "auto") == "auto": iface.stopAuto() iface.down() # Reset Network Stack unregisterNameServers(iface) # Save state to profile database profile.info["state"] = "down" profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "down", ""))
def setState(name, state): profile = Profile(name) iface = netutils.findInterface(profile.info["device"]) device_mode = profile.info.get("device_mode", "managed") if device_mode == "managed": if state == "up": # Stop other profiles on same device stopSameDevice(name) # Notify clients notify("Network.Link", "stateChanged", (name, "connecting", "")) # Save state to profile database profile.info["state"] = "connecting" profile.save(no_notify=True) # Wifi settings wifi = Wireless(iface) wifi.setSSID(profile.info["remote"]) # Set encryption wifi.setEncryption(getAuthMethod(name), getAuthParameters(name)) if profile.info.get("net_mode", "auto") == "auto": # Start DHCP client ret = iface.startAuto() if ret == 0 and iface.isUp() and iface.getAddress(): address = iface.getAddress() # Set nameservers registerNameServers(profile, iface) # Save state to profile database profile.info["state"] = "up " + address[0] profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "up", address[0])) else: iface.down() # Save state to profile database profile.info["state"] = "down" profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "inaccesible", _(MSG_DHCP_FAILED))) else: try: net_address = profile.info["net_address"] net_mask = profile.info["net_mask"] net_gateway = profile.info["net_gateway"] except KeyError: return # Set address iface.setAddress(net_address, net_mask) # Bring up interface iface.up() # Set default gateway route = netutils.Route() route.setDefault(net_gateway) # Set nameservers registerNameServers(profile, iface) # Save state to profile database profile.info["state"] = "up " + net_address profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "up", net_address)) elif state == "down": if profile.info.get("net_mode", "auto") == "auto": iface.stopAuto() # Set encryption to none wifi = Wireless(iface) wifi.setEncryption(None, None) # Reset Network Stack unregisterNameServers(iface) # Bring down interface iface.down() # Save state to profile database profile.info["state"] = "down" profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, "down", "")) elif device_mode == "adhoc": # TODO: AdHoc support pass
def refreshBrowser(self): if self.animator.state() != 0: # Refreshing browser when animator is active causes blindness if not self.refreshBrowser in self.animatorFinishHook: self.animatorFinishHook.append(self.refreshBrowser) return aa = time.time() self.ui.filterBox.clear() self.probedDevices = [] menu = QtGui.QMenu(self) for package in self.packages: info = self.packages[package] devices = self.iface.devices(package) # Add filter menu entry if len(devices): self.ui.filterBox.addItem(info["name"], QVariant(package)) if info["type"] == "wifi": self.ui.filterBox.addItem(i18n("Available Profiles"), QVariant("essid")) wifiScanner = WifiPopup(self) self.ui.buttonScan.setMenu(wifiScanner) # Create devices menu entry if len(devices) > 0: # Create profile menu with current devices for device in devices.keys(): if self.packages[package]['type'] in ('net', 'wifi'): menuItem = QtGui.QAction("%s - %s" % (self.packages[package]['name'], findInterface(device).name), self) menuItem.setData(QVariant("%s::%s" % (package,device))) self.connect(menuItem, SIGNAL("triggered()"), self.createConnection) # Store a list of probed devices if device not in self.probedDevices: self.probedDevices.append(device) menu.addAction(menuItem) menu.addSeparator() if self.packages[package]['type'] == 'dialup': pppMenu = QtGui.QMenu(self.packages[package]['name'], self) devices = self.iface.devices(package) for device in devices.keys(): menuItem = QtGui.QAction(device, self) menuItem.setData(QVariant("%s::%s" % (package,device))) self.connect(menuItem, SIGNAL("triggered()"), self.createConnection) pppMenu.addAction(menuItem) menu.addMenu(pppMenu) menu.addSeparator() if len(self.packages) > 0: self.ui.buttonCreate.setMenu(menu) self.ui.filterBox.insertItem(0, i18n("All Profiles"), QVariant("all")) else: self.ui.buttonCreate.setText(i18n("No Device Found")) self.ui.buttonCreate.setEnabled(False) self.ui.filterBox.insertItem(0, i18n("No Device Found")) self.ui.filterBox.setEnabled(False) self.ui.filterBox.setCurrentIndex(0) # Fill the list self.fillProfileList()
def setState(name, state): profile = Profile(name) ifname = profile.info["device"].split(":")[-1].split("_")[-1] iface = netutils.findInterface(profile.info["device"]) def saveState(_state, _msg=""): # Save state to profile database if _msg: profile.info["state"] = _state + " " + _msg else: profile.info["state"] = _state profile.save(no_notify=True) # Notify clients notify("Network.Link", "stateChanged", (name, _state, _msg)) # Run profile script if _state in ["down", "inaccessible", "unplugged"]: callScript(name, "down") elif _state in ["up"]: callScript(name, "up") if iface and state == "up": if iface.up() == None: fail(_(MSG_NO_DRIVER)) # Check cable state saveState("connecting") plug = False for i in xrange(10): if plugCheck(ifname): plug = True break time.sleep(0.5) if not plug: saveState("unplugged") return if state == "unplugged" or not iface: # Reset Network Stack unregisterNameServers(ifname) if state == "down": saveState("down") else: saveState("unplugged") return # Here we go... if state == "up": # Reset interface address iface.setAddress("0.0.0.0", "0.0.0.0") # Stop other profiles on same device stopSameDevice(name) # Save state saveState("connecting") # Do whatever you need to do... if profile.info.get("net_mode", "auto") == "auto": # Start DHCP client ret = iface.startAuto() if ret == 0 and iface.isUp(): if "net_address" in profile.info or "net_gateway" in profile.info: net_address = profile.info.get("net_address", None) net_mask = profile.info.get("net_mask", "255.255.255.0") net_gateway = profile.info.get("net_gateway", None) if net_address: iface.setAddress(net_address, net_mask) if not net_gateway: gateways = iface.autoGateways() if len(gateways): net_gateway = gateways[0] if net_gateway: route = netutils.Route() route.setDefault(net_gateway) elif iface.getAddress(): net_address = iface.getAddress()[0] else: # Bring device down iface.down() # Save state saveState("inaccessible", _(MSG_DHCP_FAILED)) return # Set nameservers registerNameServers(profile, iface) # Save state saveState("up", net_address) # Start ifplug deamon plugService(ifname, "up") else: # Bring device down iface.down() # Save state saveState("inaccessible", _(MSG_DHCP_FAILED)) else: try: net_address = profile.info["net_address"] net_mask = profile.info["net_mask"] except KeyError: return # Set address iface.setAddress(net_address, net_mask) if iface.up() == None: fail(_(MSG_NO_DRIVER)) # Set default gateway net_gateway = profile.info.get("net_gateway", "") if net_gateway: route = netutils.Route() route.setDefault(net_gateway) # Set nameservers registerNameServers(profile, iface) # Save state saveState("up", net_address) # Start ifplug deamon plugService(ifname, "up") elif state == "down": if profile.info.get("net_mode", "auto") == "auto": iface.stopAuto() # Bring device down iface.down() # Reset Network Stack unregisterNameServers(ifname) # Save state saveState("down")