示例#1
0
文件: wifi.py 项目: JingLuoS/pywifi-1
 def enc_type(self, ap_id):
     ''' Detailed encryption type supported by ap_id 
     '''
     if self.wireless.GetWirelessProperty(ap_id, 'encryption'):
         for i in range(len(misc.LoadEncryptionMethods())):
             if str(self.wireless.GetWirelessProperty(
                     ap_id, 'encryption_method'
             )).lower() in misc.LoadEncryptionMethods()[i]['type']:
                 return (misc.LoadEncryptionMethods()[i]['name'],
                         misc.LoadEncryptionMethods()[i]['required'])
     else:
         return ('No Encryption','')
示例#2
0
    def __init__(self, name, parent):
        AdvancedSettingsDialog.__init__(self)
        self.wired = True

        self.set_default = urwid.CheckBox(
            _('Use as default profile (overwrites any previous default)'))
        #self.cur_default =
        # Add widgets to listbox
        self._w.body.body.append(self.set_default)

        self.parent = parent
        encryption_t = _('Use Encryption')

        self.encryption_chkbox = urwid.CheckBox(
            encryption_t, on_state_change=self.encryption_toggle)
        self.encryption_combo = ComboBox(callback=self.combo_on_change)
        self.pile_encrypt = None
        # _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_combo)
        self.encrypt_types = misc.LoadEncryptionMethods(wired=True)
        self.set_values()

        self.prof_name = name
        title = _('Configuring preferences for wired profile "$A"'). \
            replace('$A', self.prof_name)
        self._w.header = urwid.Text(('header', title), align='right')

        self.set_values()
示例#3
0
    def Init(self):
        
        self._PosX = self._Index * self._Screen._Width
        self._Width = self._Screen._Width
        self._Height = self._Screen._Height

        #self._CanvasHWND = pygame.Surface((self._Width,self._Height))
        self._CanvasHWND = self._Screen._CanvasHWND

        ps = WifiListSelector()
        ps._Parent = self
        ps._Width = Width - 12
        
        self._Ps = ps
        self._PsIndex = 0
        
        msgbox = WifiListMessageBox()
        msgbox._CanvasHWND = self._CanvasHWND
        msgbox.Init(" ",fonts["veramono12"])
        msgbox._Parent = self
        
        self._MsgBox = msgbox 

        self._EncMethods = misc.LoadEncryptionMethods() # load predefined templates from /etc/wicd/...

        """
  {
    'fields': [],
    'name': 'WPA 1/2 (Passphrase)',
    'optional': [],
    'protected': [
      ['apsk', 'Preshared_Key'],
    ],
    'required': [
      ['apsk', 'Preshared_Key'],
    ],
    'type': 'wpa-psk',
  },
        """
        
        self.UpdateNetList(force_check=True,firstrun=True)

        self._Scroller = ListScroller()
        self._Scroller._Parent = self
        self._Scroller._PosX = 2
        self._Scroller._PosY = 2
        self._Scroller.Init()


        self._InfoPage = WifiInfoPage()
        self._InfoPage._Screen = self._Screen
        self._InfoPage._Name   = "Wifi info"
        self._InfoPage.Init()
示例#4
0
    def __init__(self, networkID):
        """ Build the wireless settings dialog. """
        AdvancedSettingsDialog.__init__(
            self, wireless.GetWirelessProperty(networkID, 'essid'))
        # Set up encryption stuff
        self.networkID = networkID
        self.combo_encryption = gtk.combo_box_new_text()
        self.chkbox_encryption = gtk.CheckButton(language['use_encryption'])
        self.chkbox_global_settings = gtk.CheckButton(
            language['global_settings'])
        # Make the vbox to hold the encryption stuff.
        self.vbox_encrypt_info = gtk.VBox(False, 0)
        self.toggle_encryption()
        self.chkbox_encryption.set_active(False)
        self.combo_encryption.set_sensitive(False)
        self.encrypt_types = misc.LoadEncryptionMethods()

        information_button = gtk.Button(stock=gtk.STOCK_INFO)
        self.button_hbox.pack_start(information_button, False, False)
        information_button.connect(
            'clicked',
            lambda *a, **k: WirelessInformationDialog(networkID, self))
        information_button.show()

        # Build the encryption menu
        activeID = -1  # Set the menu to this item when we are done
        for x, enc_type in enumerate(self.encrypt_types):
            self.combo_encryption.append_text(enc_type['name'])
            if enc_type['type'] == wireless.GetWirelessProperty(
                    networkID, "enctype"):
                activeID = x
        self.combo_encryption.set_active(activeID)
        if activeID != -1:
            self.chkbox_encryption.set_active(True)
            self.combo_encryption.set_sensitive(True)
            self.vbox_encrypt_info.set_sensitive(True)
        else:
            self.combo_encryption.set_active(0)
        self.change_encrypt_method()

        self.nonspecific_box.pack_start(self.chkbox_global_settings, False,
                                        False)
        self.nonspecific_box.pack_start(self.chkbox_encryption, False, False)
        self.nonspecific_box.pack_start(self.combo_encryption, False, False)
        self.nonspecific_box.pack_start(self.vbox_encrypt_info, False, False)

        # Connect signals.
        self.chkbox_encryption.connect("toggled", self.toggle_encryption)
        self.combo_encryption.connect("changed", self.change_encrypt_method)
        self.script_button.connect("clicked", self.edit_scripts)
        self.des = self.connect("destroy", self.destroy_called)
示例#5
0
    def __init__(self, networkID, parent):
        AdvancedSettingsDialog.__init__(self)
        self.wired = False

        self.bitrates = None

        self.networkid = networkID
        self.parent = parent
        global_settings_t = \
            _('Use these settings for all networks sharing this essid')
        encryption_t = _('Use Encryption')
        autoconnect_t = _('Automatically connect to this network')
        bitrate_t = _('Wireless bitrate')
        allow_lower_bitrates_t = _('Allow lower bitrates')

        self.global_settings_chkbox = urwid.CheckBox(global_settings_t)
        self.encryption_chkbox = urwid.CheckBox(
            encryption_t, on_state_change=self.encryption_toggle)
        self.encryption_combo = ComboBox(callback=self.combo_on_change)
        self.autoconnect_chkbox = urwid.CheckBox(autoconnect_t)
        self.bitrate_combo = ComboBox(bitrate_t)
        self.allow_lower_bitrates_chkbox = \
            urwid.CheckBox(allow_lower_bitrates_t)

        self.pile_encrypt = None
        # _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.bitrate_combo)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.allow_lower_bitrates_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(urwid.Text(''))
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.global_settings_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.autoconnect_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_combo)
        self.encrypt_types = misc.LoadEncryptionMethods()
        self.set_values()

        title = (_(
            'Configuring preferences for wireless network "$A" ($B)').replace(
                '$A',
                wireless.GetWirelessProperty(networkID, 'essid')).replace(
                    '$B', wireless.GetWirelessProperty(networkID, 'bssid')))
        self._w.header = urwid.Text(('header', title), align='right')
示例#6
0
    def change_encrypt_method(self):
        #self.lbox_encrypt = urwid.ListBox()
        self.encryption_info = {}
        wid,ID = self.encryption_combo.get_focus()
        methods = misc.LoadEncryptionMethods()

        if self._w.body.body.__contains__(self.pile_encrypt):
            self._w.body.body.pop(self._w.body.body.__len__()-1)

        # If nothing is selected, select the first entry.
        if ID == -1:
            self.encryption_combo.set_focus(0)
            ID = 0

        theList = []
        for type_ in ['required', 'optional']:
            fields = methods[ID][type_]
            for field in fields:
                if language.has_key(field[1]):
                    edit = MaskingEdit(('editcp',language[field[1].lower().replace(' ','_')]+': '))
                else:
                    edit = MaskingEdit(('editcp',field[1].replace('_',' ')+': '))
                edit.set_mask_mode('no_focus')
                theList.append(edit)
                # Add the data to any array, so that the information
                # can be easily accessed by giving the name of the wanted
                # data.
                self.encryption_info[field[0]] = [edit, type_]

                edit.set_edit_text(noneToBlankString(
                    wireless.GetWirelessProperty(self.networkid, field[0])))

        #FIXME: This causes the entire pile to light up upon use.
        # Make this into a listbox?
        self.pile_encrypt = DynWrap(urwid.Pile(theList),attrs=('editbx','editnfc'))
        self._w.body.body.insert(self._w.body.body.__len__(),self.pile_encrypt)
示例#7
0
    def __init__(self,networkID,parent):
        global wireless, daemon
        AdvancedSettingsDialog.__init__(self)
        self.networkid = networkID
        self.parent = parent
        global_settings_t = language['global_settings']
        encryption_t = language['use_encryption']
        autoconnect_t = language['automatic_connect']
        
        self.global_settings_chkbox = urwid.CheckBox(global_settings_t)
        self.encryption_chkbox = urwid.CheckBox(encryption_t,on_state_change=self.encryption_toggle)
        self.encryption_combo = ComboBox(callback=self.combo_on_change)
        self.autoconnect_chkbox = urwid.CheckBox(autoconnect_t)
        self.pile_encrypt = None
        # _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker :-)
        self._listbox.body.append(self.global_settings_chkbox)
        self._listbox.body.append(self.autoconnect_chkbox)
        self._listbox.body.append(self.encryption_chkbox)
        self._listbox.body.append(self.encryption_combo)
        self.encrypt_types = misc.LoadEncryptionMethods()
        self.set_values()

        title = language['configuring_wireless'].replace('$A',wireless.GetWirelessProperty(networkID,'essid')).replace('$B',wireless.GetWirelessProperty(networkID,'bssid'))
        self._w.header = urwid.Text(('header',title),align='right' )
示例#8
0
        if status() != 'done':
            exit_status = 6
        op_performed = True


def str_properties(prop):
    """ Pretty print optional and required properties. """
    if len(prop) == 0:
        return "None"
    else:
        tmp = [(x[0], x[1].replace('_', ' ')) for x in type['required']]
        return ', '.join("%s (%s)" % (x, y) for x, y in tmp)


if options.wireless and options.list_encryption_types:
    et = misc.LoadEncryptionMethods()
    # print 'Installed encryption templates:'
    print(('%s\t%-20s\t%s' % ('#', 'Name', 'Description')))
    i = 0
    for t in et:
        print(('%s\t%-20s\t%s' % (i, t['type'], t['name'])))
        print(('  Req: %s' % str_properties(t['required'])))
        print('---')
        # don't print optionals (yet)
        #print '  Opt: %s' % str_properties(type['optional'])
        i += 1
    op_performed = True

if options.save and options.network > -1:
    if options.wireless:
        is_valid_wireless_network_id(options.network)
示例#9
0
def main():
    misc.RenameProcess('wicd-cli')

    exit_status = 0

    bus = dbus.SystemBus()
    try:
        daemon = dbus.Interface(
            bus.get_object('org.wicd.daemon', '/org/wicd/daemon'),
            'org.wicd.daemon')
        wireless = dbus.Interface(
            bus.get_object('org.wicd.daemon', '/org/wicd/daemon/wireless'),
            'org.wicd.daemon.wireless')
        wired = dbus.Interface(
            bus.get_object('org.wicd.daemon', '/org/wicd/daemon/wired'),
            'org.wicd.daemon.wired')
        config = dbus.Interface(
            bus.get_object('org.wicd.daemon', '/org/wicd/daemon/config'),
            'org.wicd.daemon.config')
    except dbus.DBusException:
        print('Error: Could not connect to the daemon. '
              'Please make sure it is running.')
        sys.exit(3)

    if not daemon:
        print('Error connecting to wicd via D-Bus. '
              'Please make sure the wicd service is running.')
        sys.exit(3)

    options = parse_args()
    op_performed = False

    if not (options.wireless or options.wired) and not options.status:
        print("Please use --wireless or --wired to specify "
              "the type of connection to operate on.")

    if options.status:
        status, info = daemon.GetConnectionStatus()
        if status in (misc.WIRED, misc.WIRELESS):
            connected = True
            status_msg = _('Connected')
            if status == misc.WIRED:
                conn_type = _('Wired')
            else:
                conn_type = _('Wireless')
        else:
            connected = False
            status_msg = misc._const_status_dict[status]

        print(_('Connection status') + ': ' + status_msg)
        if connected:
            print(_('Connection type') + ': ' + conn_type)
            if status == misc.WIRELESS:
                strength = daemon.FormatSignalForPrinting(info[2])
                print(
                    _('Connected to $A at $B (IP: $C)').replace(
                        '$A',
                        info[1]).replace('$B',
                                         strength).replace('$C', info[0]))
                print(_('Network ID: $A').replace('$A', info[3]))
            else:
                print(
                    _('Connected to wired network (IP: $A)').replace(
                        '$A', info[0]))
        else:
            if status == misc.CONNECTING:
                if info[0] == 'wired':
                    print(_('Connecting to wired network.'))
                elif info[0] == 'wireless':
                    print(
                        _('Connecting to wireless network "$A".').replace(
                            '$A', info[1]))
        op_performed = True

    if options.scan and options.wireless:
        # synchronized scan
        wireless.Scan(True)
        op_performed = True

    if options.load_profile and options.wired:
        is_valid_wired_network_profile(wired, options.name)
        wired.ReadWiredNetworkProfile(options.name)
        op_performed = True

    if options.list_networks:
        if options.wireless:
            print('#\tBSSID\t\t\tChannel\tESSID')
            for network_id in range(0, wireless.GetNumberOfNetworks()):
                print('%s\t%s\t%s\t%s' %
                      (network_id,
                       wireless.GetWirelessProperty(network_id, 'bssid'),
                       wireless.GetWirelessProperty(network_id, 'channel'),
                       wireless.GetWirelessProperty(network_id, 'essid')))
        elif options.wired:
            print('#\tProfile name')
            i = 0
            for profile in wired.GetWiredProfileList():
                print('%s\t%s' % (i, profile))
                i += 1
        op_performed = True

    if options.network_details:
        if options.wireless:
            if options.network >= 0:
                is_valid_wireless_network_id(wireless, options.network)
                network_id = options.network
            else:
                network_id = wireless.GetCurrentNetworkID(0)
                is_valid_wireless_network_id(wireless, network_id)
                # we're connected to a network, print IP
                print("IP: %s" % wireless.GetWirelessIP(0))

            print("Essid: %s" %
                  wireless.GetWirelessProperty(network_id, "essid"))
            print("Bssid: %s" %
                  wireless.GetWirelessProperty(network_id, "bssid"))
            if wireless.GetWirelessProperty(network_id, "encryption"):
                print("Encryption: On")
                print("Encryption Method: %s" % wireless.GetWirelessProperty(
                    network_id, "encryption_method"))
            else:
                print("Encryption: Off")
            print("Quality: %s" %
                  wireless.GetWirelessProperty(network_id, "quality"))
            print("Mode: %s" %
                  wireless.GetWirelessProperty(network_id, "mode"))
            print("Channel: %s" %
                  wireless.GetWirelessProperty(network_id, "channel"))
            print("Bit Rates: %s" %
                  wireless.GetWirelessProperty(network_id, "bitrates"))
        op_performed = True

    # network properties

    if options.network_property:
        options.network_property = options.network_property.lower()
        if options.wireless:
            if options.network >= 0:
                is_valid_wireless_network_id(wireless, options.network)
                network_id = options.network
            else:
                network_id = wireless.GetCurrentNetworkID(0)
                is_valid_wireless_network_id(wireless, network_id)
            if not options.set_to:
                print(
                    wireless.GetWirelessProperty(network_id,
                                                 options.network_property))
            else:
                wireless.SetWirelessProperty(network_id,
                                             options.network_property,
                                             options.set_to)
        elif options.wired:
            if not options.set_to:
                print(wired.GetWiredProperty(options.network_property))
            else:
                wired.SetWiredProperty(options.network_property,
                                       options.set_to)
        op_performed = True

    if options.disconnect:
        daemon.Disconnect()
        if options.wireless:
            if wireless.GetCurrentNetworkID(0) > -1:
                print("Disconnecting from %s on %s" %
                      (wireless.GetCurrentNetwork(0),
                       wireless.DetectWirelessInterface()))
        elif options.wired:
            if wired.CheckPluggedIn():
                print("Disconnecting from wired connection on %s" %
                      wired.DetectWiredInterface())
        op_performed = True

    if options.connect:
        check = None
        if options.wireless and options.network > -1:
            is_valid_wireless_network_id(wireless, options.network)
            name = wireless.GetWirelessProperty(options.network, 'essid')
            encryption = wireless.GetWirelessProperty(options.network,
                                                      'enctype')
            print("Connecting to %s with %s on %s" %
                  (name, encryption, wireless.DetectWirelessInterface()))
            wireless.ConnectWireless(options.network)

            check = wireless.CheckIfWirelessConnecting
            status = wireless.CheckWirelessConnectingStatus
            message = wireless.CheckWirelessConnectingMessage
        elif options.wired:
            print("Connecting to wired connection on %s" %
                  wired.DetectWiredInterface())
            wired.ConnectWired()

            check = wired.CheckIfWiredConnecting
            status = wired.CheckWiredConnectingStatus
            message = wired.CheckWiredConnectingMessage
        else:
            check = lambda: False
            status = lambda: False
            message = lambda: False

        # update user on what the daemon is doing
        last = None
        if check:
            while check():
                next_ = status()
                if next_ != last:
                    # avoid a race condition where status is updated
                    # to "done" after the loop check
                    if next_ == "done":
                        break
                    print(message())
                    last = next_
            print("done!")
            if status() != 'done':
                exit_status = 6
            op_performed = True

    if options.wireless and options.list_encryption_types:
        encryption_types = misc.LoadEncryptionMethods()
        # print 'Installed encryption templates:'
        print('%s\t%-20s\t%s' % ('#', 'Name', 'Description'))
        i = 0
        for encryption_type in encryption_types:
            print('%s\t%-20s\t%s' %
                  (i, encryption_type['type'], encryption_type['name']))
            print('  Req: %s' %
                  str_properties(encryption_type, encryption_type['required']))
            print('---')
            # don't print optionals (yet)
            # print '  Opt: %s' % str_properties(encryption_type,
            #                                    encryption_type['optional'])
            i += 1
        op_performed = True

    if options.save and options.network > -1:
        if options.wireless:
            is_valid_wireless_network_id(wireless, options.network)
            config.SaveWirelessNetworkProfile(options.network)
        elif options.wired:
            config.SaveWiredNetworkProfile(options.name)
        op_performed = True

    if not op_performed:
        print("No operations performed.")

    sys.exit(exit_status)