Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
inc.'ed the range search.
Browse files Browse the repository at this point in the history
  • Loading branch information
uberj committed Nov 8, 2012
1 parent 56cae47 commit 765efa4
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions invdns/dispatch.py
Expand Up @@ -164,9 +164,14 @@ def build_dns_parsers(base_parser):
# Search is a top level command. # Search is a top level command.
search = base_parser.add_parser('search', help="Search for stuff.", search = base_parser.add_parser('search', help="Search for stuff.",
add_help=True) add_help=True)
search.add_argument('-q', dest='query', type=str, help="A query string " search.add_argument('--query', '-q', dest='query', type=str, help="A "
"surrounded by quotes. I.E `search -q " "query string surrounded by quotes. I.E `search -q "
"'foo.bar.mozilla.com'`", required=True) "'foo.bar.mozilla.com'`", default=None, required=False)

search.add_argument('--range', '-r', dest='irange', type=str, help="Get "
"information and statistics about an IP range. "
"Specify the range using: <ip-start>,<ip-end> format "
"(no spaces", default=None, required=False)


# Build all the records # Build all the records


Expand All @@ -189,6 +194,42 @@ def search(self, nas):
"""This is the fast display minimal information search. Use the """This is the fast display minimal information search. Use the
object_search to get a more detailed view of a specific type of object. object_search to get a more detailed view of a specific type of object.
""" """
if nas.query:
return self.query(nas)
elif nas.irange:
return self.irange(nas)

def irange(self, nas):
tmp_url = "/core/range/usage_text/"
url = "{0}{1}".format(REMOTE, tmp_url)
headers = {'content-type': 'application/json'}
start, end = nas.irange.split(',')
search = {'start': start, 'end': end}
resp = requests.get(url, params=search, headers=headers, auth=auth)
if resp.status_code == 500:
resp_list = [_("CLIENT ERROR! (Please email this output to "
"a code monkey)")]
self.error_out(nas, search, resp, resp_list=resp_list)
return
results = self.get_resp_dict(resp)
def display_ranges(free_ranges):
ret_list = []
for fstart, fend in free_ranges:
ret_list.append( "{0} to {1}".format(fstart, fend))
return ret_list

if not results:
return 0, []
else:
if nas.p_json:
return 0, [json.dumps(results)]
resp_list = [ "# of Used IPs: {0}".format(results['used']),
"# of Unused IPs: {0}".format(results['unused']),
"------ Vacant IP ranges ------"]
resp_list += display_ranges(results['free_ranges'])
return 0, resp_list

def query(self, nas):
tmp_url = "/core/search/search_dns_text/" tmp_url = "/core/search/search_dns_text/"
url = "{0}{1}".format(REMOTE, tmp_url) url = "{0}{1}".format(REMOTE, tmp_url)
headers = {'content-type': 'application/json'} headers = {'content-type': 'application/json'}
Expand All @@ -199,11 +240,13 @@ def search(self, nas):
"a code monkey)")] "a code monkey)")]
self.error_out(nas, search, resp, resp_list=resp_list) self.error_out(nas, search, resp, resp_list=resp_list)
return return
results = resp.text.strip() results = self.get_resp_dict(resp)
if not results: if not results:
return 0, [] return 0, []
else: else:
return 0, [results] if nas.p_json:
return 0, [json.dumps(results)]
return 0, [results['text_response']]




registrar.register(SearchDispatch()) registrar.register(SearchDispatch())
Expand Down

0 comments on commit 765efa4

Please sign in to comment.