Exemple #1
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
Exemple #2
0
def _parse_wireless_settings(basic, security, security_settings):
    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)
    # Changes take effect immediately without needing to reboot.
    settings.set_reboot_requirement_status(False)

    match_obj = re.compile('var enablewireless= "([01])";').search(basic)
    if match_obj is None:
        raise RouterParseError('Cannot determine wireless enabled status.')
    settings.set_enabled_status(match_obj.group(1) == '1')

    match_obj = re.compile('var channel_index  = "(\d+)";').search(basic)
    if match_obj is None:
        raise RouterParseError('Cannot determine wireless channel.')
    settings.set_channel(int(match_obj.group(1)))

    match_obj = re.compile('var broadcastssidEnable  = "([01])";').search(basic)
    if match_obj is None:
        raise RouterParseError('Cannot determine broadcast status.')
    # this is reversed, 0 means enable..
    settings.set_ssid_broadcast_status(match_obj.group(1) == '0')

    security_params = security_settings.strip().split('\r')
    settings.set_ssid(security_params[0])

    sec_type = security_params[2]
    if sec_type == 'WPA2PSK':
        security_type = WirelessSettings.SECURITY_TYPE_WPA2
        settings.set_password(security_params[13])
    elif sec_type == 'WPAPSK':
        security_type = WirelessSettings.SECURITY_TYPE_WPA
        settings.set_password(security_params[13])
    elif sec_type == 'WEPAUTO':
        # let's determine wep64 or wep128 by inspecting the first password
        wep_key_1 = security_params[6]
        if len(wep_key_1) in (5, 10):
            # 5 chars is for ASCII passwords, 10 is for HEX
            security_type = WirelessSettings.SECURITY_TYPE_WEP64
        else:
            security_type = WirelessSettings.SECURITY_TYPE_WEP128
        settings.set_password(wep_key_1)
    else:
        security_type = WirelessSettings.SECURITY_TYPE_NONE
    settings.set_security_type(security_type)

    return settings
Exemple #3
0
def _parse_wireless_settings(html_basic, html_advanced, html_security,
                             html_wep):
    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)

    markup = '<input type=checkbox name="wlanDisabled0" value="ON" checked'
    settings.set_enabled_status(markup not in html_basic)

    regex = re.compile('defaultChan\[wlan_idx\]=([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)))

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

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

    if '<option selected value=1>WEP' in html_security:
        passwords = re.compile('form.key10.value = "(.*?)";').findall(html_wep)
        # We expect 3 matches: 1) irrelevant 2) wep128 pass 3) wep64 pass
        if len(passwords) != 3:
            raise RouterParseError('Wrong number of passwords retrieved:'
                                   ' %d' % len(passwords))
        key_len_64 = '<input type=radio name="wepKeyLen0" value="wep64" checked>'
        if key_len_64 in html_security:
            settings.set_security_type(WirelessSettings.SECURITY_TYPE_WEP64)
            settings.set_password(passwords[2])
        else:
            settings.set_security_type(WirelessSettings.SECURITY_TYPE_WEP128)
            settings.set_password(passwords[1])
    elif '<option selected value=2>WPA' in html_security:
        settings.set_security_type(WirelessSettings.SECURITY_TYPE_WPA)
    elif '<option selected value=4>WPA2' in html_security:
        settings.set_security_type(WirelessSettings.SECURITY_TYPE_WPA2)
    else:
        settings.set_security_type(WirelessSettings.SECURITY_TYPE_NONE)

    return settings
Exemple #4
0
def _parse_wireless_settings(html_basic, html_advanced, html_security, html_wep):
    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)

    markup = '<input type=checkbox name="wlanDisabled0" value="ON" checked'
    settings.set_enabled_status(markup not in html_basic)

    regex = re.compile('defaultChan\[wlan_idx\]=([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)))

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

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

    if '<option selected value=1>WEP' in html_security:
        passwords = re.compile('form.key10.value = "(.*?)";').findall(html_wep)
        # We expect 3 matches: 1) irrelevant 2) wep128 pass 3) wep64 pass
        if len(passwords) != 3:
            raise RouterParseError('Wrong number of passwords retrieved:'
                                   ' %d' % len(passwords))
        key_len_64 = '<input type=radio name="wepKeyLen0" value="wep64" checked>'
        if key_len_64 in html_security:
            settings.set_security_type(WirelessSettings.SECURITY_TYPE_WEP64)
            settings.set_password(passwords[2])
        else:
            settings.set_security_type(WirelessSettings.SECURITY_TYPE_WEP128)
            settings.set_password(passwords[1])
    elif '<option selected value=2>WPA' in html_security:
        settings.set_security_type(WirelessSettings.SECURITY_TYPE_WPA)
    elif '<option selected value=4>WPA2' in html_security:
        settings.set_security_type(WirelessSettings.SECURITY_TYPE_WPA2)
    else:
        settings.set_security_type(WirelessSettings.SECURITY_TYPE_NONE)

    return settings
Exemple #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')
Exemple #6
0
def _parse_wireless_settings_WR340G(html_settings):
    """Extracts the Wireless settings from the page contents for a WR340G router."""

    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)

    settings_array = _extract_js_array_data(html_settings, 'wlanPara')
    wlan_list_array = _extract_js_array_data(html_settings, 'wlanList')

    security_type = int(settings_array[18])
    if security_type == 1: # WEP of some sort
        bit_length = int(wlan_list_array[1])
        if bit_length == 13: # 128 bit length
            security_type = WirelessSettings.SECURITY_TYPE_WEP128
        else:
            security_type = WirelessSettings.SECURITY_TYPE_WEP64
    elif security_type == 3: # WPA-PSK (WPA or WPA2)
        # string like '331', '332', '333'
        # we're interested in the 3rd char, which deals with WPA-PSK/WPA2-PSK
        # 3rd char possible values {1: WPA, 2: WPA2, 3: Automatic (WPA + WPA2)}
        security_options = settings_array[19]

        if int(security_options[2]) == 1:
            security_type = WirelessSettings.SECURITY_TYPE_WPA
        else:
            security_type = WirelessSettings.SECURITY_TYPE_WPA2
    else: # type is either 0 (no security) or 2 (WPA-Enterprise)
        security_type = WirelessSettings.SECURITY_TYPE_NONE
    obj.set_security_type(security_type)

    password = wlan_list_array[0] if obj.security_type_is_wep else settings_array[26]
    obj.set_password(password)

    obj.set_ssid(settings_array[2])
    obj.set_enabled_status(settings_array[8] != 0)
    obj.set_ssid_broadcast_status(settings_array[9] == 1)
    # We don't need to reboot manually..
    # The router reboots by itself when settings are pushed.
    obj.set_reboot_requirement_status(False)
    obj.set_channel(settings_array[6])
    obj.set_internal_param('region', settings_array[4])
    obj.set_internal_param('mode', settings_array[7])

    return obj
Exemple #7
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')
Exemple #8
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
Exemple #9
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
Exemple #10
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