예제 #1
0
def parse_addr_reservation_list(html):
    """
    Entries look like this:
        {status?}, {mac}, {ip_last_part}, {optional description}
        "1","00-11-11-11-11-11","52","",
        "1","00-11-11-11-11-11","52","R_user-cc5c756950",

    The status in front (0 or 1) is not important.
    It's 0 for all entries, when the list is empty,
    and 1 when there's at least one real entry.

    The IP prefix is always 192.168.1.

    The optional description only appears in entries
    not added manually, but automatically via a 'Reserve' checkbox in
    the connected clients list
    """
    regex = re.compile('^"0|1","(.+?)","([0-9]+)","(?:.*?)",\n')
    reservation_list = DHCPReservationList()
    reservation_list.set_reboot_requirement_status(False)
    for mac, ip_last_part in regex.findall(html):
        if ip_last_part == "0":
            continue
        ip = "192.168.1.%s" % ip_last_part
        item = DHCPReservationListItem()
        item.set_mac(converter.normalize_mac(mac))
        item.set_ip(ip)
        item.set_enabled_status(True)
        reservation_list.append(item)
    return reservation_list
예제 #2
0
def _parse_addr_reservations(html):
    regex = re.compile('name="smac[0-9]+" value="(.+?)"(?:.+?)name="sip[0-9]+" value="(.+?)">', re.DOTALL)

    reservation_list = DHCPReservationList()
    reservation_list.set_reboot_requirement_status(False)

    for mac, ip in regex.findall(html):
        item = DHCPReservationListItem()
        item.set_mac(converter.normalize_mac(mac))
        item.set_ip(ip)
        item.set_enabled_status(True)
        reservation_list.append(item)
    return reservation_list
예제 #3
0
def _parse_addr_reservation_list(contents):
    array_name = 'dhcpList'

    result = _extract_js_array_data(contents, array_name)
    result = result[:-2]    # the last 2 elements are not needed

    # each 3 subsequent items are related (mac_address, ip, is_enabled)
    list_raw = split_in_groups(result, 3)

    reservation_list = DHCPReservationList()
    for mac, ip, is_enabled in list_raw:
        item = DHCPReservationListItem()
        item.set_mac(converter.normalize_mac(mac))
        item.set_ip(ip)
        item.set_enabled_status(is_enabled == 1)
        reservation_list.append(item)

    return reservation_list
예제 #4
0
파일: base.py 프로젝트: ikresoft/roscraco
def _parse_addr_reservation_list(contents):
    array_name = 'dhcpList'

    result = _extract_js_array_data(contents, array_name)
    result = result[:-2]    # the last 2 elements are not needed

    # each 3 subsequent items are related (mac_address, ip, is_enabled)
    list_raw = split_in_groups(result, 3)

    reservation_list = DHCPReservationList()
    for mac, ip, is_enabled in list_raw:
        item = DHCPReservationListItem()
        item.set_mac(converter.normalize_mac(mac))
        item.set_ip(ip)
        item.set_enabled_status(is_enabled == 1)
        reservation_list.append(item)

    return reservation_list
예제 #5
0
def _parse_addr_reservation_list(html):
    lst = DHCPReservationList()
    lst.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 name="frmLan" method="POST" action="lan.cgi\?id=([0-9]+)">').search(html)
    if match_object is None:
        lst.set_internal_param('submit_token', None)
    else:
        lst.set_internal_param('submit_token', int(match_object.group(1)))

    regex = '<tr>(?:.+?)<span class="ttext">(.+?)</span></td>(?:.+?)<span class="ttext">(?:.+?)</span></td>(?:.+?)<span class="ttext">(.+?)</span></td></tr>'
    for ip, mac in re.compile(regex).findall(html):
        item = DHCPReservationListItem()
        item.set_ip(ip)
        item.set_mac(mac)
        lst.append(item)

    return lst
예제 #6
0
def parse_addr_reservation_list(html):
    """
    Entries look like this:
        {status?}, {mac}, {ip_last_part}, {optional description}
        "1","00-11-11-11-11-11","52","",
        "1","00-11-11-11-11-11","52","R_user-cc5c756950",

    The status in front (0 or 1) is not important.
    It's 0 for all entries, when the list is empty,
    and 1 when there's at least one real entry.

    The IP prefix is always 192.168.1.

    The optional description only appears in entries
    not added manually, but automatically via a 'Reserve' checkbox in
    the connected clients list
    """
    regex = re.compile('^"0|1","(.+?)","([0-9]+)","(?:.*?)",\n')
    reservation_list = DHCPReservationList()
    reservation_list.set_reboot_requirement_status(False)
    for mac, ip_last_part in regex.findall(html):
        if ip_last_part == '0':
            continue
        ip = '192.168.1.%s' % ip_last_part
        item = DHCPReservationListItem()
        item.set_mac(converter.normalize_mac(mac))
        item.set_ip(ip)
        item.set_enabled_status(True)
        reservation_list.append(item)
    return reservation_list
예제 #7
0
파일: v1_23.py 프로젝트: cyroxx/roscraco
def _parse_addr_reservation_list(html):
    regex = '//\s+nvram = \{(.+?)\};\n\nif '
    match_object = re.compile(regex, re.DOTALL).search(html)
    if match_object is None:
        raise RouterParseError('Cannot parse reservation list')

    array = _parse_data_structure(match_object.group(1))
    try:
        lst = DHCPReservationList()
        lst.set_reboot_requirement_status(False)

        for part in array['dhcpd_static'].split('>'):
            if part == '':
                continue
            mac, ip, name = part.split('<')
            item = DHCPReservationListItem()
            item.set_mac(mac)
            item.set_ip(ip)
            lst.append(item)
    except (KeyError, ValueError):
        raise RouterParseError('Bad nvram for reservation list')

    return lst
예제 #8
0
def _parse_addr_reservation_list(html):
    lst = DHCPReservationList()
    lst.set_reboot_requirement_status(False)
    regex = re.compile('<tr><td align=center width="50%" bgcolor="#C0C0C0">'
                       '<font size="2">(.+?)</td>(?:.+?)'
                       '<font size="2">(.+?)</td>(?:.+?)'
                       'name="select[0-9]+"', re.DOTALL)
    for mac, ip in regex.findall(html):
        item = DHCPReservationListItem()
        item.set_mac(mac)
        item.set_ip(ip)
        lst.append(item)
    return lst
예제 #9
0
def _parse_addr_reservations(html):
    regex = re.compile('name="smac[0-9]+" value="(.+?)"(?:.+?)name="sip[0-9]+" value="(.+?)">', re.DOTALL)

    reservation_list = DHCPReservationList()
    reservation_list.set_reboot_requirement_status(False)

    for mac, ip in regex.findall(html):
        item = DHCPReservationListItem()
        item.set_mac(converter.normalize_mac(mac))
        item.set_ip(ip)
        item.set_enabled_status(True)
        reservation_list.append(item)
    return reservation_list
예제 #10
0
파일: w268r.py 프로젝트: wblyy/roscraco
def _parse_addr_reservation_list(html):
    reservations = re.compile('var StaticList = new Array\((.*)\);').search(html)
    if reservations is None:
        raise RouterParseError('Cannot find reservations list.')
    reservations_list = reservations.group(1)

    results = re.compile(';(.+?);(.+?);([12]);(\d+)').findall(reservations_list)
    reservation_list = DHCPReservationList()
    reservation_list.set_reboot_requirement_status(False)
    for ip, mac, mac_bind, _time in results:
        item = DHCPReservationListItem()
        item.set_mac(converter.normalize_mac(mac))
        item.set_ip(ip)
        item.set_enabled_status(mac_bind == '1')
        reservation_list.append(item)
    return reservation_list
예제 #11
0
def _parse_addr_reservation_list(html):
    regex = '//\s+nvram = \{(.+?)\};\n\nif '
    match_object = re.compile(regex, re.DOTALL).search(html)
    if match_object is None:
        raise RouterParseError('Cannot parse reservation list')

    array = _parse_data_structure(match_object.group(1))
    try:
        lst = DHCPReservationList()
        lst.set_reboot_requirement_status(False)

        for part in array['dhcpd_static'].split('>'):
            if part == '':
                continue
            mac, ip, name = part.split('<')
            item = DHCPReservationListItem()
            item.set_mac(mac)
            item.set_ip(ip)
            lst.append(item)
    except (KeyError, ValueError):
        raise RouterParseError('Bad nvram for reservation list')

    return lst
예제 #12
0
 def get_addr_reservation_list(self):
     lst = DHCPReservationList()
     lst.set_reservation_support_status(False)
     lst.set_reboot_requirement_status(False)
     return lst
예제 #13
0
파일: cnwf514.py 프로젝트: cyroxx/roscraco
 def get_addr_reservation_list(self):
     lst = DHCPReservationList()
     lst.set_reservation_support_status(False)
     lst.set_reboot_requirement_status(False)
     return lst