convert to using pybindxml for scraping zone/server information from bind in server zone list
This commit is contained in:
parent
c2daf46358
commit
d8900c4075
|
@ -10,6 +10,7 @@ Packages:
|
|||
|
||||
* [Django](http://www.djangoproject.com)
|
||||
* Python Modules
|
||||
* [pybindxml](https://pypi.python.org/pypi?name=pybindxml&:action=display): This is a shared library I wrote to scrape and stick into Python dict objects various server/zone data from a BIND DNS server.
|
||||
* [python-beautifulsoup](http://www.crummy.com/software/BeautifulSoup/)
|
||||
* [python-dnspython](http://www.dnspython.org/)
|
||||
* [python-sqlite](http://docs.python.org/2/library/sqlite3.html) (If you will be using Sqlite for server and key storage)
|
||||
|
|
|
@ -6,6 +6,7 @@ import urllib2
|
|||
|
||||
# 3rd Party
|
||||
from BeautifulSoup import BeautifulStoneSoup as BS
|
||||
from pybindxml import reader as bindreader
|
||||
import dns.exception
|
||||
import dns.query
|
||||
import dns.tsig
|
||||
|
@ -70,28 +71,9 @@ class BindServer(models.Model):
|
|||
String zone_class,
|
||||
String zone_serial }
|
||||
"""
|
||||
zone_req = urllib2.Request("http://%s:%s" % (self.hostname, self.statistics_port))
|
||||
try:
|
||||
http_request = urllib2.urlopen(zone_req)
|
||||
except urllib2.URLError, err:
|
||||
raise exceptions.ZoneException(err)
|
||||
|
||||
return_array = []
|
||||
xmloutput = http_request.read()
|
||||
mysoup = BS(xmloutput)
|
||||
views = mysoup.findAll("view")
|
||||
for view in views:
|
||||
view_name = view.find("name").string
|
||||
for zone in view.findAll("zone"):
|
||||
zone_name, zone_class = zone.find("name").string.split("/")
|
||||
zone_serial = zone.find("serial").string
|
||||
if zone_class == "IN":
|
||||
return_array.append({"view_name" : view_name,
|
||||
"zone_name" : zone_name,
|
||||
"zone_class" : zone_class,
|
||||
"zone_serial" : zone_serial })
|
||||
|
||||
return return_array
|
||||
zone_data = bindreader.BindXmlReader(host=self.hostname, port=self.statistics_port)
|
||||
zone_data.get_stats()
|
||||
return zone_data
|
||||
|
||||
def list_zone_records(self, zone_name):
|
||||
""" List all records in a specific zone.
|
||||
|
|
|
@ -10,18 +10,18 @@ Server Zone List for {{ dns_server }}
|
|||
<tr>
|
||||
<th>Zone</th>
|
||||
<th>View</th>
|
||||
<th>Class</th>
|
||||
<th>Serial Number</th>
|
||||
</tr>
|
||||
{% for current_zone in zone_array %}
|
||||
{% for current_zone, cz_data in zone_array.stats.zone_stats.iteritems %}
|
||||
{% for current_view, cv_data in cz_data.iteritems %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{% url "zone_list" dns_server=dns_server zone_name=current_zone.zone_name %}"> {{ current_zone.zone_name }}</a>
|
||||
<a href="{% url "zone_list" dns_server=dns_server zone_name=current_zone %}"> {{ current_zone }}</a>
|
||||
</td>
|
||||
<td>{{ current_zone.view_name }}</td>
|
||||
<td>{{ current_zone.zone_class }}</td>
|
||||
<td>{{ current_zone.zone_serial }}</td>
|
||||
<td>{{ current_view }}</td>
|
||||
<td>{{ cv_data.serial }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
|
|
|
@ -23,6 +23,12 @@ except ImportError:
|
|||
print "Package is typically called 'python-dnspython.'\n"
|
||||
errors += 1
|
||||
|
||||
try:
|
||||
import pybindxml
|
||||
except ImportError:
|
||||
print "Could not import pybindxml. This is a required module for Binder.\n"
|
||||
errors += 1
|
||||
|
||||
try:
|
||||
import flup
|
||||
except ImportError:
|
||||
|
|
Loading…
Reference in New Issue