コード例 #1
0
ファイル: captiv.py プロジェクト: wraith-wireless/captiv8
def configure(win,conf):
    """
     shows options to configure captiv8 for running
     :param win: the main window
     :param conf: current state of configuration dict
    """
    # create our on/off for radio buttons
    BON = curses.ACS_DIAMOND
    BOFF = '_'

    # create an inputs dict to hold the begin locations of inputs
    ins = {} # input -> (start_y,start_x,endx)

    # create a copy of conf to manipulate
    newconf = {}
    for c in conf: newconf[c] = conf[c]

    # create new window (new window will cover the main window)
    # get sizes for coord translation
    nr,nc = win.getmaxyx()               # size of the main window
    ny,nx = 15,50                        # size of new window
    zy,zx = (nr-ny)/2,(nc-nx)/2          # 0,0 (top left corner) of new window
    confwin = curses.newwin(ny,nx,zy,zx)

    # draw a blue border and write title
    confwin.attron(CPS[BLUE])
    confwin.border(0)
    confwin.attron(CPS[BLUE])
    confwin.addstr(1,1,"Configure Options",CPS[BLUE])

    # ssid option, add if present add a clear button to the right
    confwin.addstr(2,1,"SSID: " + '_'*_SSIDLEN_,CPS[WHITE])
    ins['SSID'] = (2+zy,len("SSID: ")+zx+1,len("SSID: ")+zx+_SSIDLEN_)
    if newconf['SSID']:
        for i,s in enumerate(newconf['SSID']):
            confwin.addch(ins['SSID'][0]-zy,ins['SSID'][1]-zx+i,s,CPS[GREEN])

    # allow for up to 6 devices to choose in rows of 2 x 3
    confwin.addstr(3,1,"Select dev:",CPS[WHITE]) # the sub title
    i = 4 # current row
    j = 0 # current dev
    devs = pyw.winterfaces()[:8]
    if not newconf['dev'] in devs: newconf['dev'] = None
    for dev in devs:
        stds = ""
        monitor = True
        nl80211 = True
        try:
            card = pyw.getcard(dev)
            stds = pyw.devstds(card)
            monitor = 'monitor' in pyw.devmodes(card)
        except pyric.error:
            # assume just related to current dev
            nl80211 = False
        devopt = "{0}. (_) {1}".format(j+1,dev)
        if stds: devopt += " IEEE 802.11{0}".format(''.join(stds))
        if monitor and nl80211:
            confwin.addstr(i,2,devopt,CPS[WHITE])
            ins[j] = (i+zy,len("n. (")+zx+2,len("n. (")+zx+3)
            if newconf['dev'] == dev:
                confwin.addch(ins[j][0]-zy,ins[j][1]-zx,BON,CPS[GREEN])
        else:
            # make it gray
            errmsg = ""
            if not monitor: errmsg = "No monitor mode"
            elif not nl80211: errmsg = "No nl80211"
            confwin.addstr(i,2,devopt,CPS[GRAY])
            confwin.addstr(i,3,'X',CPS[GRAY])
            confwin.addstr(i,len(devopt)+3,errmsg,CPS[GRAY])
        i += 1
        j += 1

    # connect option, select current if present
    confwin.addstr(i,1,"Connect: (_) auto (_) manual",CPS[WHITE])
    ins['auto'] = (i+zy,len("Connect: (")+zx+1,len("Connect: (")+zx+2)
    ins['manual'] = (i+zy,
                     len("Connect: (_) auto (")+zx+1,
                     len("Connect: (_) auto (")+zx+2)
    if newconf['connect']:
        confwin.addch(ins[newconf['connect']][0]-zy,
                      ins[newconf['connect']][1]-zx,
                      BON,CPS[GREEN])

    # we want two buttons Set and Cancel. Make these buttons centered. Underline
    # the first character
    btn1 = "Set"
    btn2 = "Cancel"
    btnlen = len(btn1) + len(btn2) + 1  # add a space
    btncen = (nx-btnlen) / 2            # center point for both
    # btn 1 -> underline first character
    y,x = ny-2,btncen-(len(btn1)-1)
    confwin.addstr(y,x,btn1[0],CPS[BUTTON]|curses.A_UNDERLINE)
    confwin.addstr(y,x+1,btn1[1:],CPS[BUTTON])
    ins['set'] = (y+zy,x+zx,x+zx+len(btn1)-1)
    # btn 2 -> underline first character
    y,x = ny-2,btncen+2
    confwin.addstr(y,x,btn2[0],CPS[BUTTON]|curses.A_UNDERLINE)
    confwin.addstr(y,x+1,btn2[1:],CPS[BUTTON])
    ins['cancel'] = (y+zy,x+zx,x+zx+len(btn2)-1)
    confwin.refresh()

    # capture the focus and run our execution loop
    confwin.keypad(1) # enable IOT read mouse events
    store = False
    while True:
        _ev = confwin.getch()
        if _ev == curses.KEY_MOUSE:
            # handle mouse, determine if we should check/uncheck etc
            try:
                _,mx,my,_,b = curses.getmouse()
            except curses.error:
                continue

            if b == curses.BUTTON1_CLICKED:
                # determine if we're inside a option area
                if my == ins['set'][0]:
                    if ins['set'][1] <= mx <= ins['set'][2]:
                        store = True
                        break
                    elif ins['cancel'][1] <= mx <= ins['cancel'][2]:
                        break
                elif my == ins['SSID'][0]:
                    if ins['SSID'][1] <= mx <= ins['SSID'][2]:
                        # move the cursor to the first entry char & turn on
                        curs = ins['SSID'][0],ins['SSID'][1]
                        confwin.move(curs[0]-zy,curs[1]-zx)
                        curses.curs_set(1)

                        # loop until we get <ENTER>
                        while True:
                            # get the next char
                            _ev = confwin.getch()
                            if _ev == ascii.NL or _ev == curses.KEY_ENTER: break
                            elif _ev == ascii.BS or _ev == curses.KEY_BACKSPACE:
                                if curs[1] == ins['SSID'][1]: continue
                                # delete (write over with '-') prev char, then move back
                                curs = curs[0],curs[1]-1
                                confwin.addch(curs[0]-zy,
                                               curs[1]-zx,
                                               BOFF,
                                               CPS[WHITE])
                                confwin.move(curs[0]-zy,curs[1]-zx)
                            else:
                                if curs[1] > ins['SSID'][2]:
                                    curses.flash()
                                    continue

                                # add the character, (cursor moves on its own)
                                # update our pointer for the next entry
                                try:
                                    confwin.addstr(curs[0]-zy,
                                                   curs[1]-zx,
                                                   chr(_ev),
                                                   CPS[GREEN])
                                    curs = curs[0],curs[1]+1
                                except ValueError:
                                    # put this back on and see if the outer
                                    # loop can do something with it
                                    curses.ungetch(_ev)
                                    break
                        curses.curs_set(0) # turn off the cursor
                elif my == ins['auto'][0]:
                    if ins['auto'][1] <= mx <= ins['auto'][2]:
                        if newconf['connect'] == 'manual':
                            # turn off manual
                            confwin.addch(ins['manual'][0]-zy,
                                          ins['manual'][1]-zx,
                                          BOFF,CPS[WHITE])
                        newconf['connect'] = 'auto'
                        confwin.addch(my-zy,mx-zx,BON,CPS[GREEN])
                        confwin.refresh()
                    elif ins['manual'][1] <= mx <= ins['manual'][2]:
                        if newconf['connect'] == 'auto':
                            # turn off auto
                            confwin.addch(ins['auto'][0]-zy,
                                          ins['auto'][1]-zx,
                                          BOFF,CPS[WHITE])
                        newconf['connect'] = 'manual'
                        confwin.addch(my-zy,mx-zx,BON,CPS[GREEN])
                        confwin.refresh()
                else:
                    # check for each listed device
                    for d in range(j):
                        if my == ins[d][0] and ins[d][1] <= mx <= ins[d][2]:
                            # check the selected dev
                            confwin.addch(my-zy,mx-zx,BON,CPS[GREEN])

                            # determine if a previously selected needs to be unchecked
                            if newconf['dev'] is None: pass
                            elif newconf['dev'] != devs[d]:
                                i = devs.index(newconf['dev'])
                                confwin.addch(ins[i][0]-zy,
                                              ins[i][1]-zx,
                                              BOFF,
                                              CPS[WHITE])
                            newconf['dev'] = devs[d]
                            confwin.refresh()
                            break # exit the for loop
        else:
            try:
                _ch = chr(_ev).upper()
            except ValueError:
                continue
            if _ch == 'S':
                store = True
                break
            elif _ch == 'C': break
            elif _ch == 'L':
                pass

    # only 'radio buttons' are kept, check if a SSID was entered and add if so
    if store:
        ssid = confwin.instr(ins['SSID'][0]-zy,ins['SSID'][1]-zx,_SSIDLEN_)
        ssid = ssid.strip('_').strip() # remove training lines, & spaces
        if ssid: newconf['SSID'] = ssid

    # delete this window and return
    del confwin  # remove the window
    return newconf if store else None
コード例 #2
0
	def read_network_interfaces(self):
		import pyric.pyw as pyw
		
		network_info = ''
		try:
			network_info = pyw.interfaces()
		except:
			pass

		self.available_share = [_('none'),'auto']
		unavailable_net = ['wlan9','lo']
		if self.bridge.GetValue():
			unavailable_net.append('eth0')

		for i in network_info:
			if not 'can' in i and not 'canable' in i and not i in unavailable_net: self.available_share.append(i)

		self.share.Clear()
		for i in self.available_share:
			self.share.Append(i)
		
		type=''
		phy=''
		AP=-1
		GHz=-1
		
		self.available_ap_device = []
		self.available_ap_device.append([_('none'),'',-1,-1,'none'])
		
		for i in pyw.winterfaces():
			if 'wlan' in i:
				try:
					wlan = 'wlan9'  #AP allways on wlan9
					w0 = pyw.getcard(i)
					mac = subprocess.check_output(('cat /sys/class/net/'+i+'/address').split()).decode()[:-1]

					AP = -1
					if 'AP' in pyw.phyinfo(w0)['modes']:AP = 0

					GHz = -1
					if 'a' in pyw.devstds(w0): GHz = 1

					if b'usb' in subprocess.check_output(('ls -l /sys/class/net/'+i).split()):
						type  = 'usb'
						if AP > -1:
								self.available_ap_device.append([mac+' '+type, mac, type, GHz, wlan])
					else:
						type = 'on board'
						do_exist = False
						for j in self.available_ap_device:
							if j[1] == mac: do_exist = True
						if not do_exist:
							self.available_ap_device.append([mac+' '+type, mac, type, GHz, wlan])
				except: pass

		if not ('Raspberry Pi 2' in self.rpimodel) and len(self.available_ap_device) == 2:
			for i in self.available_ap_device:
				if 'on board' == i[2]:
					type = 'AP and Station'
					wlan = 'uap'
					self.available_ap_device.append([i[1]+' '+type, i[1], type, i[3], wlan])

		self.available_ap_device2 = []
		for i in self.available_ap_device:
			self.available_ap_device2.append(i[0])
			
		self.ap_device.Clear()
		for i in self.available_ap_device2:
			self.ap_device.Append(i)
コード例 #3
0
 def get_supported_wifi_standards(self, iface):
     '''
     Get info about supported WiFi standards, i.e. 802.11a/n/g/ac/b
     '''
     w0 = self.get_wifi_chard(iface)  # get a card for interface
     return pyw.devstds(w0)
コード例 #4
0
ファイル: pyw.unittest.py プロジェクト: wifiphisher/WiPy
 def test_devchs(self):
     self.assertListEqual(pri["stds"], pyw.devstds(self.card))
コード例 #5
0
ファイル: pyw.unittest.py プロジェクト: pgawlowicz/PyRIC
 def test_devchs(self):
     if _python3:
         self.assertCountEqual(pri['stds'],pyw.devstds(self.card))
     else:
         self.assertItemsEqual(pri['stds'],pyw.devstds(self.card))
コード例 #6
0
    def getinfo(self):
        try:
            self.data['macaddress'] = netifaces.ifaddresses(
                self._if)[netifaces.AF_LINK][0]['addr']
        except:
            self.data['macaddress'] = None
        try:
            self.data['ipaddress'] = netifaces.ifaddresses(
                self._if)[netifaces.AF_INET][0]['addr']
        except:
            self.data['ipaddress'] = None
        try:
            self.data['vendorstr'] = self.udevnet.data[
                self._if + "_id_vendor_from_database"]
        except:
            self.data['vendorstr'] = None
        try:
            self.data['vendoroui'] = self.udevnet.data[self._if +
                                                       "_id_oui_from_database"]
        except:
            self.data['vendoroui'] = None
        try:
            self.data['vendor'] = self.udevnet.data[self._if + "_id_vendor"]
        except:
            self.data['vendor'] = None
        # Hack for onboard raspberry devices
        if type(self.data['vendoroui']) is str:
            if re.search("^Raspberry", self.data['vendoroui']):
                self.data['vendor'] = "RaspberryPi"

        try:
            self.data['driver'] = self.udevnet.data[self._if +
                                                    "_id_net_driver"]
        except:
            try:
                self.data['driver'] = self.udevnet.data[self._if +
                                                        "_id_usb_driver"]
            except:
                self.data['driver'] = None
        try:
            self.data['model'] = self.udevnet.data[self._if + "_id_model_id"]
        except:
            self.data['model'] = None
        try:
            self.data['modelstr'] = self.udevnet.data[
                self._if + "_id_model_from_database"]
        except:
            self.data['modelstr'] = None
        try:
            self.data['netname'] = self.udevnet.data[
                self._if + "_id_net_name_from_database"]
        except:
            try:
                self.data['netname'] = self.udevnet.data[
                    self._if + "_id_net_name_onboard"]
            except:
                try:
                    self.data['netname'] = self.udevnet.data[
                        self._if + "_id_net_name_slot"]
                except:
                    try:
                        self.data['netname'] = self.udevnet.data[
                            self._if + "_id_net_name_path"]
                    except:
                        try:
                            self.data['netname'] = self.udevnet.data[
                                self._if + "_id_net_name_mac"]
                        except:
                            self.data['netname'] = None
        try:
            self.data['type'] = self.udevnet.data[self._if + "_devtype"]
            if self.data['type'] == "wlan": self.data['type'] = "Wireless"
        except:
            try:
                if re.search("^en", self.data['netname']):
                    self.data['type'] = "Ethernet"
                elif re.search("^wl", self.data['netname']):
                    self.data['type'] = "Wireless"
                else:
                    self.data['type'] = None
            except:
                self.data['type'] = None

        # Stop here if we don't have a wireless card
        if self.data['type'] != "Wireless":
            return
        # Retrieve wireless info
        try:
            _ifobj = pyw.getcard(self._if)
            _ifinfo = pyw.ifinfo(_ifobj)
            _devinfo = pyw.devinfo(_ifobj)
            _physinfo = pyw.phyinfo(_ifobj)
            _linkinfo = pyw.link(_ifobj)
        except:
            pass
        try:
            self.data['isup'] = pyw.isup(_ifobj)
        except:
            self.data['isup'] = None
        try:
            self.data['blocked'] = pyw.isblocked(_ifobj)
        except:
            self.data['blocked'] = None
        try:
            self.data['mode'] = _devinfo['mode']
        except:
            self.data['mode'] = None
        try:
            self.data['modes'] = _physinfo['modes']
        except:
            self.data['modes'] = None
        try:
            self.data['bands'] = _physinfo['bands']
        except:
            self.data['bands'] = None
        try:
            self.data['standards'] = pyw.devstds(_ifobj)
        except:
            self.data['standards'] = None
        try:
            self.data['freqs'] = pyw.devfreqs(_ifobj)
        except:
            self.data['freqs'] = None
        try:
            self.data['txpower'] = pyw.txget(_ifobj)
        except:
            self.data['txpower'] = None
        try:
            self.data['chans'] = pyw.devchs(_ifobj)
        except:
            self.data['chans'] = None
        try:
            self.data['reg'] = pyw.regget(_ifobj)
        except:
            self.data['reg'] = None
        try:
            self.data['chipset'] = _ifinfo['chipset']
        except:
            self.data['chipset'] = None
        try:
            self.data['state'] = _linkinfo['stat']
        except:
            self.data['state'] = None
        try:
            self.data['ssid'] = _linkinfo['ssid']
        except:
            self.data['ssid'] = None
        try:
            self.data['chw'] = _devinfo['CHW']
        except:
            self.data['chw'] = None
        try:
            self.data['frequency'] = _devinfo['RF']
        except:
            self.data['frequency'] = None
        try:
            self.data['rss'] = _linkinfo['rss']
        except:
            self.data['rss'] = None
        try:
            self.data['wtx'] = _linkinfo['tx']
        except:
            self.data['wtx'] = None
        try:
            self.data['wrx'] = _linkinfo['rx']
        except:
            self.data['wrx'] = None
コード例 #7
0
ファイル: pyw.unittest.py プロジェクト: wraith-wireless/PyRIC
 def test_devchs(self):
     self.assertListEqual(pri['stds'],pyw.devstds(self.card))
コード例 #8
0
ファイル: netinfo.py プロジェクト: fnoop/maverick
    def getinfo(self):
        try:
            self.data['macaddress'] = netifaces.ifaddresses(self._if)[netifaces.AF_LINK][0]['addr']
        except:
            self.data['macaddress'] = None
        try:
            self.data['ipaddress'] = netifaces.ifaddresses(self._if)[netifaces.AF_INET][0]['addr']
        except:
            self.data['ipaddress'] = None
        try:
            self.data['vendorstr'] = self.udevnet.data[self._if+"_id_vendor_from_database"]
        except:
            self.data['vendorstr'] = None
        try:
            self.data['vendoroui'] = self.udevnet.data[self._if+"_id_oui_from_database"]
        except:
            self.data['vendoroui'] = None
        try:
            self.data['vendor'] = self.udevnet.data[self._if+"_id_vendor"]
        except:
            self.data['vendor'] = None
        # Hack for onboard raspberry devices
        if type(self.data['vendoroui']) is str:
            if re.search("^Raspberry", self.data['vendoroui']):
                self.data['vendor'] = "RaspberryPi"

        try:
            self.data['driver'] = self.udevnet.data[self._if+"_id_net_driver"]
        except:
            try:
                self.data['driver'] = self.udevnet.data[self._if+"_id_usb_driver"]
            except:
                self.data['driver'] = None
        try:
            self.data['model'] = self.udevnet.data[self._if+"_id_model_id"]
        except:
            self.data['model'] = None
        try:
            self.data['modelstr'] = self.udevnet.data[self._if+"_id_model_from_database"]
        except:
            self.data['modelstr'] = None
        try:
            self.data['netname'] = self.udevnet.data[self._if+"_id_net_name_from_database"]
        except:
            try:
                self.data['netname'] = self.udevnet.data[self._if+"_id_net_name_onboard"]
            except:
                try:
                    self.data['netname'] = self.udevnet.data[self._if+"_id_net_name_slot"]
                except:
                    try:
                        self.data['netname'] = self.udevnet.data[self._if+"_id_net_name_path"]
                    except:
                        try:
                            self.data['netname'] = self.udevnet.data[self._if+"_id_net_name_mac"]
                        except:
                            self.data['netname'] = None
        try:
            self.data['type'] = self.udevnet.data[self._if+"_devtype"]
            if self.data['type'] == "wlan": self.data['type'] = "Wireless"
        except:
            try:
                if re.search("^en", self.data['netname']):
                    self.data['type'] = "Ethernet"
                elif re.search("^wl", self.data['netname']):
                    self.data['type'] = "Wireless"
                else:
                    self.data['type'] = None
            except:
                self.data['type'] = None

        # Stop here if we don't have a wireless card
        if self.data['type'] != "Wireless":
            return
        # Retrieve wireless info
        try:
            _ifobj = pyw.getcard(self._if)
            _ifinfo = pyw.ifinfo(_ifobj)
            _devinfo = pyw.devinfo(_ifobj)
            _physinfo = pyw.phyinfo(_ifobj)
            _linkinfo = pyw.link(_ifobj)
        except:
            pass
        try:
            self.data['isup'] = pyw.isup(_ifobj)
        except:
            self.data['isup'] = None
        try:
            self.data['blocked'] = pyw.isblocked(_ifobj)
        except:
            self.data['blocked'] = None
        try:
            self.data['mode'] = _devinfo['mode']
        except:
            self.data['mode'] = None
        try:
            self.data['modes'] = _physinfo['modes']
        except:
            self.data['modes'] = None
        try:
            self.data['bands'] = _physinfo['bands']
        except:
            self.data['bands'] = None
        try:
            self.data['standards'] = pyw.devstds(_ifobj)
        except:
            self.data['standards'] = None
        try:
            self.data['freqs'] = pyw.devfreqs(_ifobj)
        except:
            self.data['freqs'] = None
        try:
            self.data['txpower'] = pyw.txget(_ifobj)
        except:
            self.data['txpower'] = None
        try:
            self.data['chans'] = pyw.devchs(_ifobj)
        except:
            self.data['chans'] = None
        try:
            self.data['reg'] = pyw.regget(_ifobj)
        except:
            self.data['reg'] = None
        try:
            self.data['chipset'] = _ifinfo['chipset']
        except:
            self.data['chipset'] = None
        try:
            self.data['state'] = _linkinfo['stat']
        except:
            self.data['state'] = None
        try:
            self.data['ssid'] = _linkinfo['ssid']
        except:
            self.data['ssid'] = None
        try:
            self.data['chw'] = _devinfo['CHW']
        except:
            self.data['chw'] = None
        try:
            self.data['frequency'] = _devinfo['RF']
        except:
            self.data['frequency'] = None
        try:
            self.data['rss'] = _linkinfo['rss']
        except:
            self.data['rss'] = None
        try:
            self.data['wtx'] = _linkinfo['tx']
        except:
            self.data['wtx'] = None
        try:
            self.data['wrx'] = _linkinfo['rx']
        except:
            self.data['wrx'] = None