def validate(self): errors = {} if not validator.is_valid_ip_address(self._ip_start): errors['ip_start'] = 'Invalid start IP: %s' % self._ip_start if not validator.is_valid_ip_address(self._ip_end): errors['ip_end'] = 'Invalid end IP: %s' % self._ip_end if converter.ip2long(self._ip_start) > converter.ip2long(self._ip_end): errors['ip_range'] = 'Invalid IP range: from %s to %s' % (self._ip_start, self._ip_end) return errors
def validate(self): errors = {} if not validator.is_valid_ip_address(self._ip_start): errors['ip_start'] = 'Invalid start IP: %s' % self._ip_start if not validator.is_valid_ip_address(self._ip_end): errors['ip_end'] = 'Invalid end IP: %s' % self._ip_end if converter.ip2long(self._ip_start) > converter.ip2long(self._ip_end): errors['ip_range'] = 'Invalid IP range: from %s to %s' % ( self._ip_start, self._ip_end) return errors
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
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