예제 #1
0
def _parse_dhcp_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 DHCP settings')

    array = _parse_data_structure(match_object.group(1))

    try:
        ip_start, ip_end = array['dhcpd_startip'], array['dhcpd_endip']
        is_enabled = array['lan_proto'] == 'dhcp'
    except KeyError:
        raise RouterParseError('Bad nvram for DHCP settings')

    if not validator.is_valid_ip_address(ip_start):
        raise RouterParseError('Invalid DHCP start IP: %s' % ip_start)

    if not validator.is_valid_ip_address(ip_end):
        raise RouterParseError('Invalid DHCP end IP: %s' % ip_end)

    obj = DHCPServerSettings()
    obj.set_enabled_status(is_enabled)
    obj.set_ip_start(ip_start)
    obj.set_ip_end(ip_end)
    obj.ensure_valid()
    return obj
예제 #2
0
def parse_dhcp_settings(html):
    is_enabled = '<INPUT TYPE=CHECKBOX NAME=_HE CHECKED>' in html

    # 192.168.1 is hardcoded.. only the last part changes
    regex = re.compile('<INPUT NAME=HR0 VALUE="([0-9]+)" SIZE=3 MAXLENGTH=3>')
    match_object = regex.search(html)
    if match_object is None:
        raise RouterParseError('Cannot parse dhcp start ip!')
    ip_last_part = match_object.group(1)
    ip_start = '192.168.1.%s' % ip_last_part

    # get the pool size to determine what the last IP is
    regex = re.compile('document.forms\[0\]\._HR1\.value=([0-9]+)-([0-9]+)')
    match_object = regex.search(html)
    if match_object is None:
        raise RouterParseError('Cannot parse dhcp pool size!')
    num1, num2 = map(int, match_object.groups())
    pool_size = num1 - num2
    ip_start_long = converter.ip2long(ip_start)
    ip_end_long = ip_start_long + pool_size
    ip_end = converter.long2ip(ip_end_long)

    settings = DHCPServerSettings()
    settings.set_enabled_status(is_enabled)
    settings.set_ip_start(ip_start)
    settings.set_ip_end(ip_end)
    settings.ensure_valid()
    return settings
예제 #3
0
def parse_dhcp_settings(html):
    is_enabled = "<INPUT TYPE=CHECKBOX NAME=_HE CHECKED>" in html

    # 192.168.1 is hardcoded.. only the last part changes
    regex = re.compile('<INPUT NAME=HR0 VALUE="([0-9]+)" SIZE=3 MAXLENGTH=3>')
    match_object = regex.search(html)
    if match_object is None:
        raise RouterParseError("Cannot parse dhcp start ip!")
    ip_last_part = match_object.group(1)
    ip_start = "192.168.1.%s" % ip_last_part

    # get the pool size to determine what the last IP is
    regex = re.compile("document.forms\[0\]\._HR1\.value=([0-9]+)-([0-9]+)")
    match_object = regex.search(html)
    if match_object is None:
        raise RouterParseError("Cannot parse dhcp pool size!")
    num1, num2 = map(int, match_object.groups())
    pool_size = num1 - num2
    ip_start_long = converter.ip2long(ip_start)
    ip_end_long = ip_start_long + pool_size
    ip_end = converter.long2ip(ip_end_long)

    settings = DHCPServerSettings()
    settings.set_enabled_status(is_enabled)
    settings.set_ip_start(ip_start)
    settings.set_ip_end(ip_end)
    settings.ensure_valid()
    return settings
예제 #4
0
파일: v1_23.py 프로젝트: cyroxx/roscraco
def _parse_dhcp_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 DHCP settings')

    array = _parse_data_structure(match_object.group(1))

    try:
        ip_start, ip_end = array['dhcpd_startip'], array['dhcpd_endip']
        is_enabled = array['lan_proto'] == 'dhcp'
    except KeyError:
        raise RouterParseError('Bad nvram for DHCP settings')

    if not validator.is_valid_ip_address(ip_start):
        raise RouterParseError('Invalid DHCP start IP: %s' % ip_start)

    if not validator.is_valid_ip_address(ip_end):
        raise RouterParseError('Invalid DHCP end IP: %s' % ip_end)

    obj = DHCPServerSettings()
    obj.set_enabled_status(is_enabled)
    obj.set_ip_start(ip_start)
    obj.set_ip_end(ip_end)
    obj.ensure_valid()
    return obj
예제 #5
0
파일: w268r.py 프로젝트: wblyy/roscraco
def _parse_dhcp_settings(html):
    settings = DHCPServerSettings()

    match_obj = re.compile('document.LANDhcpsSet.DHEN.checked = (0|1);').search(html)
    if match_obj is None:
        raise RouterParseError('Cannot determine DHCP enabled status')
    settings.set_enabled_status(match_obj.group(1) == '1')

    match_obj = re.compile('document.LANDhcpsSet.dips.value = \(\("(.+?)"').search(html)
    if match_obj is None:
        raise RouterParseError('Cannot determine DHCP start IP address')
    ip_start = match_obj.group(1)
    if not validator.is_valid_ip_address(ip_start):
        raise RouterParseError('IP start address is invalid: %s' % ip_start)
    settings.set_ip_start(ip_start)

    match_obj = re.compile('document.LANDhcpsSet.dipe.value = \(\("(.+?)"').search(html)
    if match_obj is None:
        raise RouterParseError('Cannot determine DHCP end IP address')
    ip_end = match_obj.group(1)
    if not validator.is_valid_ip_address(ip_end):
        raise RouterParseError('IP end address is invalid: %s' % ip_end)
    settings.set_ip_end(ip_end)

    return settings
예제 #6
0
def _parse_dhcp_settings(html):
    regex = re.compile('name="dhcpRange(?:Start|End)" size="15" maxlength="15" value="(.+?)"')
    try:
        ip_start, ip_end = regex.findall(html)
    except ValueError:
        raise RouterParseError('Cannot find DHCP start/end range')
    else:
        settings = DHCPServerSettings()
        settings.set_ip_start(ip_start)
        settings.set_ip_end(ip_end)
        settings.set_enabled_status('<option selected value="2"><script>dw(Enable)</script></option>' in html)
        settings.ensure_valid()

        return settings
예제 #7
0
def _parse_dhcp_settings(html):
    settings = DHCPServerSettings()
    settings.set_enabled_status('<INPUT name=lan_proto type=hidden value= "dhcp">' in html)

    match_object = re.compile('<INPUT name=dhcp_start type=hidden value= "(.+?)"').search(html)
    if match_object is None:
        raise RouterParseError('Cannot determine DHCP start IP')
    settings.set_ip_start(match_object.group(1))

    match_object = re.compile('<INPUT name=dhcp_end type=hidden value= "(.+?)"').search(html)
    if match_object is None:
        raise RouterParseError('Cannot determine DHCP end IP')
    settings.set_ip_end(match_object.group(1))

    settings.ensure_valid()

    return settings
예제 #8
0
def _parse_dhcp_settings(html):
    regex = re.compile('name="dhcpRange(?:Start|End)" size="15" maxlength="15" value="(.+?)"')
    try:
        ip_start, ip_end = regex.findall(html)
    except ValueError:
        raise RouterParseError('Cannot find DHCP start/end range')
    else:
        settings = DHCPServerSettings()
        settings.set_ip_start(ip_start)
        settings.set_ip_end(ip_end)
        settings.set_enabled_status('<option selected value="2"><script>dw(Enable)</script></option>' in html)
        settings.ensure_valid()

        return settings
예제 #9
0
파일: base.py 프로젝트: ikresoft/roscraco
def _parse_dhcp_settings(html):
    settings = DHCPServerSettings()

    array = _extract_js_array_data(html, 'DHCPPara')

    try:
        settings.set_enabled_status(int(array[0]) == 1)
        settings.set_ip_start(array[1])
        settings.set_ip_end(array[2])
    except IndexError as e:
        raise RouterParseError(repr(e))

    settings.ensure_valid()
    return settings
예제 #10
0
def _parse_dhcp_settings(html):
    settings = DHCPServerSettings()

    array = _extract_js_array_data(html, 'DHCPPara')

    try:
        settings.set_enabled_status(int(array[0]) == 1)
        settings.set_ip_start(array[1])
        settings.set_ip_end(array[2])
    except IndexError, e:
        raise RouterParseError(repr(e))
예제 #11
0
파일: cnwf514.py 프로젝트: cyroxx/roscraco
def _parse_dhcp_settings(html):
    settings = DHCPServerSettings()
    settings.set_enabled_status('<option selected value="2">Server</option>' in html)

    match_object = re.compile('<input type="text" name="dhcpRangeStart" size="12" maxlength="15" value="(.+?)">').search(html)
    if match_object is None:
        raise RouterParseError("Cannot determine DHCP start IP")
    settings.set_ip_start(match_object.group(1))

    match_object = re.compile('<input type="text" name="dhcpRangeEnd" size="12" maxlength="15" value="(.+?)">').search(html)
    if match_object is None:
        raise RouterParseError("Cannot determine DHCP end IP")
    settings.set_ip_end(match_object.group(1))

    settings.ensure_valid()

    return settings
예제 #12
0
def _parse_dhcp_settings(html):
    is_enabled = 'var choice= 2 ;' in html

    regex = re.compile('<input type=text name="dhcpRangeStart" size=16 '
                       'maxlength=15 value="(.+?)"'
                       '(?:.+?)'
                       '<input type=text name="dhcpRangeEnd" size=16 '
                       'maxlength=15 value="(.+?)"', re.DOTALL)
    match_object = regex.search(html)
    if match_object is None:
        raise RouterParseError('Cannot determine DMZ range!')
    for ip in match_object.groups():
        if not validator.is_valid_ip_address(ip):
            raise RouterParseError('Invalid DHCP IP: %s' % ip)

    ip_start, ip_end = match_object.groups()
    obj = DHCPServerSettings()
    obj.set_enabled_status(is_enabled)
    obj.set_ip_start(ip_start)
    obj.set_ip_end(ip_end)
    obj.ensure_valid()
    return obj
예제 #13
0
def _parse_dhcp_settings(html):
    settings = DHCPServerSettings()
    settings.set_enabled_status(
        '<option selected value="2">Server</option>' in html)

    match_object = re.compile(
        '<input type="text" name="dhcpRangeStart" size="12" maxlength="15" value="(.+?)">'
    ).search(html)
    if match_object is None:
        raise RouterParseError("Cannot determine DHCP start IP")
    settings.set_ip_start(match_object.group(1))

    match_object = re.compile(
        '<input type="text" name="dhcpRangeEnd" size="12" maxlength="15" value="(.+?)">'
    ).search(html)
    if match_object is None:
        raise RouterParseError("Cannot determine DHCP end IP")
    settings.set_ip_end(match_object.group(1))

    settings.ensure_valid()

    return settings