Esempio n. 1
0
def _parse_wireless_settings(html_main, html_basic, html_advanced, html_security):
    obj = WirelessSettings()
    obj.add_security_support(WirelessSettings.SECURITY_TYPE_WEP64)
    obj.add_security_support(WirelessSettings.SECURITY_TYPE_WEP128)
    obj.add_security_support(WirelessSettings.SECURITY_TYPE_WPA)
    obj.add_security_support(WirelessSettings.SECURITY_TYPE_WPA2)

    obj.set_auto_channel_support(False)

    # the naming of the radio button is weird!
    is_enabled = '<input type="radio" name="wlanDisabled" value="yes" checked>' in html_main
    obj.set_enabled_status(is_enabled)


    match_object = re.compile('document.wlanSetup.ssid.value="(.+?)";').search(html_basic)
    if match_object is None:
        raise RouterParseError('Cannot determine SSID')
    obj.set_ssid(match_object.group(1))

    match_object = re.compile('var defaultChan = ([0-9]+)[\s\n]').search(html_basic)
    if match_object is None:
        raise RouterParseError('Cannot determine channel')
    obj.set_channel(int(match_object.group(1)))

    is_broadcasting_ssid = '<input type="radio" name="hiddenSSID" value="no" checked>' in html_advanced
    obj.set_ssid_broadcast_status(is_broadcasting_ssid)

    match_object = re.compile('methodVal = ([0-3]);').search(html_security)
    if match_object is None:
        raise RouterParseError('Cannot determine security type')
    security_type = int(match_object.group(1))
    if security_type == 0:
        obj.set_security_type(obj.__class__.SECURITY_TYPE_NONE)
    elif security_type == 1: # WEP of some sort
        match_object = re.compile('var wepTbl =\s+new Array\("([0-9]+)"\);').search(html_security)
        if match_object is None:
            raise RouterParseError('Cannot determine WEP bit length')
        if int(match_object.group(1)) in (0, 1):
            obj.set_security_type(obj.__class__.SECURITY_TYPE_WEP64)
        else:
            obj.set_security_type(obj.__class__.SECURITY_TYPE_WEP128)

        # WEP passwords cannot be extracted! It shows "***" only
    elif security_type == 2: # WPA of some sort
        match_object = re.compile('var wpaCipherTbl =(?:\s+)?new Array\("([0-9]+)"\);').search(html_security)
        if match_object is None:
            raise RouterParseError('Cannot determine WPA type')
        if int(match_object.group(1)) in (0, 1, 3): # 0, 1 = WPA; 3 = mixed
            obj.set_security_type(obj.__class__.SECURITY_TYPE_WPA)
        else: # all other values are WPA2 only
            obj.set_security_type(obj.__class__.SECURITY_TYPE_WPA2)

        match_object = re.compile('var pskValueTbl = new Array\("(.+?)"\);').search(html_security)
        if match_object is None:
            raise RouterParseError('Cannot determine WPA password')
        obj.set_password(match_object.group(1))
    else: # 3 = WPA Radius
        raise NotImplementedError('Security type not supported')

    return obj
Esempio n. 2
0
def _parse_wireless_settings(html_main, html_basic, html_advanced, html_security):
    obj = WirelessSettings()
    obj.add_security_support(WirelessSettings.SECURITY_TYPE_WEP64)
    obj.add_security_support(WirelessSettings.SECURITY_TYPE_WEP128)
    obj.add_security_support(WirelessSettings.SECURITY_TYPE_WPA)
    obj.add_security_support(WirelessSettings.SECURITY_TYPE_WPA2)

    obj.set_auto_channel_support(False)

    # the naming of the radio button is weird!
    is_enabled = '<input type="radio" name="wlanDisabled" value="yes" checked>' in html_main
    obj.set_enabled_status(is_enabled)


    match_object = re.compile('document.wlanSetup.ssid.value="(.+?)";').search(html_basic)
    if match_object is None:
        raise RouterParseError('Cannot determine SSID')
    obj.set_ssid(match_object.group(1))

    match_object = re.compile('var defaultChan = ([0-9]+)[\s\n]').search(html_basic)
    if match_object is None:
        raise RouterParseError('Cannot determine channel')
    obj.set_channel(int(match_object.group(1)))

    is_broadcasting_ssid = '<input type="radio" name="hiddenSSID" value="no" checked>' in html_advanced
    obj.set_ssid_broadcast_status(is_broadcasting_ssid)

    match_object = re.compile('methodVal = ([0-3]);').search(html_security)
    if match_object is None:
        raise RouterParseError('Cannot determine security type')
    security_type = int(match_object.group(1))
    if security_type == 0:
        obj.set_security_type(obj.__class__.SECURITY_TYPE_NONE)
    elif security_type == 1: # WEP of some sort
        match_object = re.compile('var wepTbl =\s+new Array\("([0-9]+)"\);').search(html_security)
        if match_object is None:
            raise RouterParseError('Cannot determine WEP bit length')
        if int(match_object.group(1)) in (0, 1):
            obj.set_security_type(obj.__class__.SECURITY_TYPE_WEP64)
        else:
            obj.set_security_type(obj.__class__.SECURITY_TYPE_WEP128)

        # WEP passwords cannot be extracted! It shows "***" only
    elif security_type == 2: # WPA of some sort
        match_object = re.compile('var wpaCipherTbl =(?:\s+)?new Array\("([0-9]+)"\);').search(html_security)
        if match_object is None:
            raise RouterParseError('Cannot determine WPA type')
        if int(match_object.group(1)) in (0, 1, 3): # 0, 1 = WPA; 3 = mixed
            obj.set_security_type(obj.__class__.SECURITY_TYPE_WPA)
        else: # all other values are WPA2 only
            obj.set_security_type(obj.__class__.SECURITY_TYPE_WPA2)

        match_object = re.compile('var pskValueTbl = new Array\("(.+?)"\);').search(html_security)
        if match_object is None:
            raise RouterParseError('Cannot determine WPA password')
        obj.set_password(match_object.group(1))
    else: # 3 = WPA Radius
        raise NotImplementedError('Security type not supported')

    return obj
Esempio n. 3
0
def parse_wireless_setting(security_type, html):
    obj = WirelessSettings()
    obj.add_security_support(WirelessSettings.SECURITY_TYPE_WEP64)
    obj.add_security_support(WirelessSettings.SECURITY_TYPE_WEP128)
    obj.add_security_support(WirelessSettings.SECURITY_TYPE_WPA)
    obj.set_auto_channel_support(False)
    obj.set_reboot_requirement_status(False)

    regex = re.compile('if \(""==""\) document\.forms\[0\]\.ZN\.value=' 'unescape\("(.+?)"\);')
    match_object = regex.search(html)
    if match_object is None:
        raise RouterParseError("Cannot parse ssid!")
    ssid = match_object.group(1)
    obj.set_ssid(ssid)

    # security_type is either a valid value or 'wep',
    # in which case we've got to resolve it to WEP64 or WEP128
    if security_type == "wep":
        regex = re.compile("(?:.+?)<OPTION CHECKED>(?:.+?)dw\(wlan\[25\]\)" "(?:.+?)</SCRIPT>", re.DOTALL)
        if regex.search(html) is not None:
            security_type = WirelessSettings.SECURITY_TYPE_WEP64
        else:
            security_type = WirelessSettings.SECURITY_TYPE_WEP128

        regex = re.compile('<INPUT NAME=ZO0 VALUE="(.+?)" SIZE=26')
        match_object = regex.search(html)
        if match_object is None:
            raise RouterParseError("Cannot parse WEP password!")
        obj.set_password(match_object.group(1))
    elif security_type == WirelessSettings.SECURITY_TYPE_WPA:
        regex = re.compile('document\.forms\[0\]\.PK\.value=unescape\("(.+?)"\);')
        match_object = regex.search(html)
        if match_object is None:
            raise RouterParseError("Cannot parse WPA password!")
        obj.set_password(match_object.group(1))
    else:  # No security
        obj.set_password("")
    obj.set_security_type(security_type)

    regex = re.compile('if\(i==([0-9]+)\)\nsel="SELECTED"')
    match_object = regex.search(html)
    if match_object is None:
        raise RouterParseError("Cannot parse channel!")
    obj.set_channel(int(match_object.group(1)))

    # `_esv` is either 0 or 1 and controls SSID broadcasting
    if "_esv=1" in html:
        obj.set_ssid_broadcast_status(False)

    regex = re.compile('wdv0=\("(.+?)"=="(.+?)"\)\?true:false')
    match_object = regex.search(html)
    if match_object is None:
        raise RouterParseError("Cannot parse enabled status!")
    val1, val2 = match_object.groups()
    obj.set_enabled_status(val1 == val2)

    return obj
Esempio n. 4
0
def _parse_wireless_settings(html):
    regex = '//\s+nvram = \{(.+?)\};\n\nxob = '
    match_object = re.compile(regex, re.DOTALL).search(html)
    if match_object is None:
        raise RouterParseError('Cannot parse wireless settings')

    array = _parse_data_structure(match_object.group(1))

    try:
        settings = WirelessSettings()
        settings.add_security_support(WirelessSettings.SECURITY_TYPE_WEP64)
        settings.add_security_support(WirelessSettings.SECURITY_TYPE_WEP128)
        settings.add_security_support(WirelessSettings.SECURITY_TYPE_WPA)
        settings.add_security_support(WirelessSettings.SECURITY_TYPE_WPA2)

        settings.set_reboot_requirement_status(False)
        settings.set_auto_channel_support(False)
        settings.set_ascii_wep_password_support_status(False)

        # Let's preserve all the settings, so that it's
        # easier to generate the data later
        settings.set_internal_param('nvram', array)

        sec_type = array['security_mode2']
        settings.set_security_type(WirelessSettings.SECURITY_TYPE_NONE)
        settings.set_password('')
        if sec_type == 'wep':
            if array['wl_wep_bit'] == '64':
                settings.set_security_type(
                    WirelessSettings.SECURITY_TYPE_WEP64)
            else:
                settings.set_security_type(
                    WirelessSettings.SECURITY_TYPE_WEP128)
            settings.set_password(array['wl_key1'])
        elif sec_type == 'wpa_personal':
            settings.set_security_type(WirelessSettings.SECURITY_TYPE_WPA)
            settings.set_password(array['wl_wpa_psk'])
        elif sec_type == 'wpa2_personal':
            settings.set_security_type(WirelessSettings.SECURITY_TYPE_WPA2)
            settings.set_password(array['wl_wpa_psk'])

        settings.set_ssid(array['wl_ssid'])
        settings.set_channel(array['wl_channel'])
        settings.set_ssid_broadcast_status(array['wl_closed'] == '0')
        settings.set_enabled_status(array['wl_radio'] == '1')
        return settings
    except (KeyError, ValueError):
        raise RouterParseError('Bad nvram for wireless settings')
Esempio n. 5
0
def _parse_wireless_settings(html):
    regex = '//\s+nvram = \{(.+?)\};\n\nxob = '
    match_object = re.compile(regex, re.DOTALL).search(html)
    if match_object is None:
        raise RouterParseError('Cannot parse wireless settings')

    array = _parse_data_structure(match_object.group(1))

    try:
        settings = WirelessSettings()
        settings.add_security_support(WirelessSettings.SECURITY_TYPE_WEP64)
        settings.add_security_support(WirelessSettings.SECURITY_TYPE_WEP128)
        settings.add_security_support(WirelessSettings.SECURITY_TYPE_WPA)
        settings.add_security_support(WirelessSettings.SECURITY_TYPE_WPA2)

        settings.set_reboot_requirement_status(False)
        settings.set_auto_channel_support(False)
        settings.set_ascii_wep_password_support_status(False)

        # Let's preserve all the settings, so that it's
        # easier to generate the data later
        settings.set_internal_param('nvram', array)

        sec_type = array['security_mode2']
        settings.set_security_type(WirelessSettings.SECURITY_TYPE_NONE)
        settings.set_password('')
        if sec_type == 'wep':
            if array['wl_wep_bit'] == '64':
                settings.set_security_type(WirelessSettings.SECURITY_TYPE_WEP64)
            else:
                settings.set_security_type(WirelessSettings.SECURITY_TYPE_WEP128)
            settings.set_password(array['wl_key1'])
        elif sec_type == 'wpa_personal':
            settings.set_security_type(WirelessSettings.SECURITY_TYPE_WPA)
            settings.set_password(array['wl_wpa_psk'])
        elif sec_type == 'wpa2_personal':
            settings.set_security_type(WirelessSettings.SECURITY_TYPE_WPA2)
            settings.set_password(array['wl_wpa_psk'])

        settings.set_ssid(array['wl_ssid'])
        settings.set_channel(array['wl_channel'])
        settings.set_ssid_broadcast_status(array['wl_closed'] == '0')
        settings.set_enabled_status(array['wl_radio'] == '1')
        return settings
    except (KeyError, ValueError):
        raise RouterParseError('Bad nvram for wireless settings')
Esempio n. 6
0
def parse_wireless_setting(security_type, html):
    obj = WirelessSettings()
    obj.add_security_support(WirelessSettings.SECURITY_TYPE_WEP64)
    obj.add_security_support(WirelessSettings.SECURITY_TYPE_WEP128)
    obj.add_security_support(WirelessSettings.SECURITY_TYPE_WPA)
    obj.set_auto_channel_support(False)
    obj.set_reboot_requirement_status(False)

    regex = re.compile('if \(""==""\) document\.forms\[0\]\.ZN\.value='
                       'unescape\("(.+?)"\);')
    match_object = regex.search(html)
    if match_object is None:
        raise RouterParseError('Cannot parse ssid!')
    ssid = match_object.group(1)
    obj.set_ssid(ssid)

    # security_type is either a valid value or 'wep',
    # in which case we've got to resolve it to WEP64 or WEP128
    if security_type == 'wep':
        regex = re.compile(
            '(?:.+?)<OPTION CHECKED>(?:.+?)dw\(wlan\[25\]\)'
            '(?:.+?)</SCRIPT>', re.DOTALL)
        if regex.search(html) is not None:
            security_type = WirelessSettings.SECURITY_TYPE_WEP64
        else:
            security_type = WirelessSettings.SECURITY_TYPE_WEP128

        regex = re.compile('<INPUT NAME=ZO0 VALUE="(.+?)" SIZE=26')
        match_object = regex.search(html)
        if match_object is None:
            raise RouterParseError('Cannot parse WEP password!')
        obj.set_password(match_object.group(1))
    elif security_type == WirelessSettings.SECURITY_TYPE_WPA:
        regex = re.compile(
            'document\.forms\[0\]\.PK\.value=unescape\("(.+?)"\);')
        match_object = regex.search(html)
        if match_object is None:
            raise RouterParseError('Cannot parse WPA password!')
        obj.set_password(match_object.group(1))
    else:  # No security
        obj.set_password('')
    obj.set_security_type(security_type)

    regex = re.compile('if\(i==([0-9]+)\)\nsel="SELECTED"')
    match_object = regex.search(html)
    if match_object is None:
        raise RouterParseError('Cannot parse channel!')
    obj.set_channel(int(match_object.group(1)))

    # `_esv` is either 0 or 1 and controls SSID broadcasting
    if '_esv=1' in html:
        obj.set_ssid_broadcast_status(False)

    regex = re.compile('wdv0=\("(.+?)"=="(.+?)"\)\?true:false')
    match_object = regex.search(html)
    if match_object is None:
        raise RouterParseError('Cannot parse enabled status!')
    val1, val2 = match_object.groups()
    obj.set_enabled_status(val1 == val2)

    return obj