Browse files

Merge branch 'master' of https://github.com/jonatasoliveira/djangodas…

  • Loading branch information...
2 parents 0ef03ab + 6f4e5f4 commit 61e6d993e69509ab57144f2348883d98d5f21721 root committed Jul 31, 2011
Showing with 136 additions and 1 deletion.
  1. +13 −1 bin/mdnscli
  2. +32 −0 bin/mdnsd-slave
  3. +1 −0 libs/pyManDNS_Cli.py
  4. +90 −0 libs/pyManDNS_Slave.py
View
14 bin/mdnscli
@@ -67,7 +67,19 @@ kwargs = dict([x for x in args._get_kwargs() if x[0] not in ('cls', 'method', 'h
if args.cls == 'domain':
domain = pyManDNS_Cli_Domain(args.host, args.port)
method = getattr(domain, args.method)
- print method(**kwargs)
+ result = method(**kwargs)
+
+ if args.method == "list":
+
+ for i in result["result"]:
+ print i["domain"]
+
+ else:
+ print result["message"]
+
+ if result["result"]:
+ print result["result"]
+
else:
print 'ERROR, the args: %s' % args
View
32 bin/mdnsd-slave
@@ -0,0 +1,32 @@
+#!/usr/bin/python
+# pyManDNS is a very easy script to Manage yout DNS
+#
+import sys
+import os
+sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/../libs')
+import re
+import ConfigParser
+from SimpleXMLRPCServer import SimpleXMLRPCServer
+from pyManDNS_Slave import pyManDNS_Slave
+
+# Parse config file
+config = ConfigParser.ConfigParser()
+config.read(os.path.dirname(os.path.realpath(__file__)) + '/../etc/pyManDNS.cfg');
+
+dir_db_files = config.get('Bind','dir.db_files')
+pySlave = pyManDNS_Slave(dir_db_files)
+
+master_server_host = config.get('Server','server.host')
+master_server_port = 3336
+
+pySlave.startDomainSlaveWrapper("127.0.0.1","3334")
+pySlave.domainSlave.set_dir_db_file(dir_db_files)
+pySlave.domainSlave.create_zone_file(1)
+#pySlave.domainSlave.reload()
+
+#server = SimpleXMLRPCServer((server_host, int(server_port)), allow_none=True)
+#server.register_instance(pySlave, True)
+#
+#print 'Server-slave started'
+#
+#server.serve_forever()
View
1 libs/pyManDNS_Cli.py
@@ -19,6 +19,7 @@ def _connect(self):
class pyManDNS_Cli_Domain(ConnectXMLRPC):
+
def _kwargs_to_args_ordenated(self, **kwargs):
# The XML-RPC doesn't accept named params. The keys are
# to ordenate the params and use as **params.
View
90 libs/pyManDNS_Slave.py
@@ -0,0 +1,90 @@
+import xmlrpclib
+import socket
+
+def success(msg=None, result=None):
+ return dict(type='success', message=msg, result=result)
+
+def error(msg=None, result=None):
+ return dict(type='error', message=msg, result=result)
+
+class ConnectXMLRPC(object):
+
+ def __init__(self, host, port):
+ self.host = host
+ self.port = port
+ self._connect()
+
+ def _connect(self):
+ try:
+ self.client = xmlrpclib.ServerProxy('http://%s:%s' % (self.host, self.port), allow_none=True)
+ except Exception, msg:
+ return dict(type='error', message=msg)
+
+class DomainSlaveWrapper(ConnectXMLRPC):
+ """
+ This class is used to separate the entities namespaces in the XML-RPC server.
+
+ Usage in the server (example):
+ >>> import xmlrpclib
+ >>> client = xmlrpclib.ServerProxy('http://localhost:3000')
+ >>> client.domain.list()
+ """
+
+# def __init__(self,dir_db_files):
+# self.dir_db_files = dir_db_files
+
+ def set_dir_db_file(self,dir_db_file):
+ self.dir_db_file = dir_db_file
+
+ def create_zone_file(self,verbose):
+ try:
+ result = self.client.domain.list()
+
+ zones = ""
+
+ for domain_row in result["result"]:
+
+ zones += "zone \"" + domain_row["domain"] + "\" {\n"
+ zones += "\ttype slave;\n"
+ zones += "\tfile \"" + self.dir_db_file + "/db.slave." + domain_row["domain"] + "\";\n"
+ zones += "\tmasters { 192.168.1.204; };\n"
+ zones += "};\n\n"
+
+ file = open("/var/named/chroot/etc/named.pyManDNS.slaves.zones", "w")
+ file.write(zones);
+ file.close()
+
+ except socket.error, msg:
+ print 'erro!!'
+
+# ''' Visualiza db file '''
+# def show(self,v_domain):
+#
+# msg = self.pyZones.read_db_file(v_domain)
+#
+# return success(msg=msg)
+#
+# ''' Get dominio '''
+# def get(self,v_domain):
+#
+# domains_table = self.pyTables.domains_table()
+# records_table = self.pyTables.records_table()
+#
+# domains_result = self.engine.execute(
+# domains_table.select().where("domain=:domain"),domain=v_domain)
+# domain_row = domains_result.first()
+#
+# if domain_row:
+# # return domain_row
+# return success(result=domain_row)
+# else:
+# msg = "ERROR: Dominio not found"
+# return error(msg=msg)
+
+class pyManDNS_Slave(object):
+
+ def __init__(self,dir_db_files):
+ self.dir_db_files = dir_db_files
+
+ def startDomainSlaveWrapper(self,host,port):
+ self.domainSlave = DomainSlaveWrapper(host,port)

0 comments on commit 61e6d99

Please sign in to comment.