Пример #1
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')
Пример #2
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')
Пример #3
0
def _parse_wireless_settings(security_type, html_basic, html_advanced):
    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_ascii_wep_password_support_status(False)
    settings.set_reboot_requirement_status(False)

    # Determine the submit token.. some WGR614v9 models have such a token
    # It's either some form of CSRF protection or something else..
    match_object = re.compile(
        '<form method="POST" action="wireless.cgi\?id=([0-9]+)">').search(
            html_basic)
    if match_object is None:
        settings.set_internal_param('submit_token', None)
    else:
        settings.set_internal_param('submit_token', int(match_object.group(1)))

    if security_type == 'WEP':
        if '<option selected value="1">64bit</option>' in html_basic:
            settings.set_security_type(WirelessSettings.SECURITY_TYPE_WEP64)
        elif '<option selected value="2">128bit</option>' in html_basic:
            settings.set_security_type(WirelessSettings.SECURITY_TYPE_WEP128)
        else:
            raise RouterParseError('Cannot determine WEP key length')

        settings.set_password(__parse_wep_password(html_basic))
    elif security_type == 'WPA-PSK':
        settings.set_security_type(WirelessSettings.SECURITY_TYPE_WPA)
        # password extraction is done below
    elif security_type in ('WPA2-PSK', 'WPA-AUTO-PSK'):
        settings.set_security_type(WirelessSettings.SECURITY_TYPE_WPA2)
        # password extraction is done below
    else:  # security_type = `Disable` or something else that we don't handle..
        settings.set_security_type(WirelessSettings.SECURITY_TYPE_NONE)
        settings.set_password('')

    if settings.security_type_is_wpa:
        regex = re.compile(
            '<input type="text" name="passphrase" size=20 maxLength=64 value="(.+?)" onFocus'
        )
        match_object = regex.search(html_basic)
        if match_object is None:
            raise RouterParseError('Cannot determine WPA password')
        password = match_object.group(1)
        if '*****' in password:
            # WGR614v7 doesn't present us with the real password, but substitutes it with * chars
            # that's not the case for v8 and v9 though
            password = None
        settings.set_password(password)

    regex = re.compile('<input type="text" name="ssid" value="(.+?)"')
    match_object = regex.search(html_basic)
    if match_object is None:
        raise RouterParseError('Cannot determine SSID')
    settings.set_ssid(match_object.group(1))

    regex = re.compile(
        '<input type="hidden" name="initChannel" value="([0-9]+)">')
    match_object = regex.search(html_basic)
    if match_object is None:
        raise RouterParseError('Cannot determine channel')
    settings.set_channel(int(match_object.group(1)))

    if '<input type="checkbox"  checked name="enable_ap" value="enable_ap">' in html_advanced:
        is_enabled = True
    else:
        is_enabled = False
    settings.set_enabled_status(is_enabled)

    if '<input type="checkbox"  checked name="ssid_bc" value="ssid_bc">' in html_advanced:
        is_broadcasting = True
    else:
        is_broadcasting = False
    settings.set_ssid_broadcast_status(is_broadcasting)

    if '<input type="checkbox"  checked name="enable_wmm" value="enable_wmm">' in html_advanced:
        is_wmm_enabled = True
    else:
        is_wmm_enabled = False
    settings.set_internal_param('enable_wmm', is_wmm_enabled)

    regex = re.compile(
        "Select Region(?:.+?)<option selected value=\"([0-9]+)\">")
    match_object = regex.search(html_basic)
    if match_object is None:
        raise RouterParseError('Cannot determine Region value')
    settings.set_internal_param('WRegion', int(match_object.group(1)))

    return settings
Пример #4
0
def _parse_wireless_settings(security_type, html_basic, html_advanced):
    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_ascii_wep_password_support_status(False)
    settings.set_reboot_requirement_status(False)

    # Determine the submit token.. some WGR614v9 models have such a token
    # It's either some form of CSRF protection or something else..
    match_object = re.compile('<form method="POST" action="wireless.cgi\?id=([0-9]+)">').search(html_basic)
    if match_object is None:
        settings.set_internal_param('submit_token', None)
    else:
        settings.set_internal_param('submit_token', int(match_object.group(1)))

    if security_type == 'WEP':
        if '<option selected value="1">64bit</option>' in html_basic:
            settings.set_security_type(WirelessSettings.SECURITY_TYPE_WEP64)
        elif '<option selected value="2">128bit</option>' in html_basic:
            settings.set_security_type(WirelessSettings.SECURITY_TYPE_WEP128)
        else:
            raise RouterParseError('Cannot determine WEP key length')

        settings.set_password(__parse_wep_password(html_basic))
    elif security_type == 'WPA-PSK':
        settings.set_security_type(WirelessSettings.SECURITY_TYPE_WPA)
        # password extraction is done below
    elif security_type in ('WPA2-PSK', 'WPA-AUTO-PSK'):
        settings.set_security_type(WirelessSettings.SECURITY_TYPE_WPA2)
        # password extraction is done below
    else: # security_type = `Disable` or something else that we don't handle..
        settings.set_security_type(WirelessSettings.SECURITY_TYPE_NONE)
        settings.set_password('')

    if settings.security_type_is_wpa:
        regex = re.compile('<input type="text" name="passphrase" size=20 maxLength=64 value="(.+?)" onFocus')
        match_object = regex.search(html_basic)
        if match_object is None:
            raise RouterParseError('Cannot determine WPA password')
        password = match_object.group(1)
        if '*****' in password:
            # WGR614v7 doesn't present us with the real password, but substitutes it with * chars
            # that's not the case for v8 and v9 though
            password = None
        settings.set_password(password)

    regex = re.compile('<input type="text" name="ssid" value="(.+?)"')
    match_object = regex.search(html_basic)
    if match_object is None:
        raise RouterParseError('Cannot determine SSID')
    settings.set_ssid(match_object.group(1))


    regex = re.compile('<input type="hidden" name="initChannel" value="([0-9]+)">')
    match_object = regex.search(html_basic)
    if match_object is None:
        raise RouterParseError('Cannot determine channel')
    settings.set_channel(int(match_object.group(1)))


    if '<input type="checkbox"  checked name="enable_ap" value="enable_ap">' in html_advanced:
        is_enabled = True
    else:
        is_enabled = False
    settings.set_enabled_status(is_enabled)


    if '<input type="checkbox"  checked name="ssid_bc" value="ssid_bc">' in html_advanced:
        is_broadcasting = True
    else:
        is_broadcasting = False
    settings.set_ssid_broadcast_status(is_broadcasting)


    if '<input type="checkbox"  checked name="enable_wmm" value="enable_wmm">' in html_advanced:
        is_wmm_enabled = True
    else:
        is_wmm_enabled = False
    settings.set_internal_param('enable_wmm', is_wmm_enabled)


    regex = re.compile("Select Region(?:.+?)<option selected value=\"([0-9]+)\">")
    match_object = regex.search(html_basic)
    if match_object is None:
        raise RouterParseError('Cannot determine Region value')
    settings.set_internal_param('WRegion', int(match_object.group(1)))

    return settings