Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 61e6d993e69509ab57144f2348883d98d5f21721 2 parents 0ef03ab + 6f4e5f4
root authored
14 bin/mdnscli
@@ -67,7 +67,19 @@ kwargs = dict([x for x in args._get_kwargs() if x[0] not in ('cls', 'method', 'h
67 67 if args.cls == 'domain':
68 68 domain = pyManDNS_Cli_Domain(args.host, args.port)
69 69 method = getattr(domain, args.method)
70   - print method(**kwargs)
  70 + result = method(**kwargs)
  71 +
  72 + if args.method == "list":
  73 +
  74 + for i in result["result"]:
  75 + print i["domain"]
  76 +
  77 + else:
  78 + print result["message"]
  79 +
  80 + if result["result"]:
  81 + print result["result"]
  82 +
71 83 else:
72 84 print 'ERROR, the args: %s' % args
73 85
32 bin/mdnsd-slave
... ... @@ -0,0 +1,32 @@
  1 +#!/usr/bin/python
  2 +# pyManDNS is a very easy script to Manage yout DNS
  3 +#
  4 +import sys
  5 +import os
  6 +sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/../libs')
  7 +import re
  8 +import ConfigParser
  9 +from SimpleXMLRPCServer import SimpleXMLRPCServer
  10 +from pyManDNS_Slave import pyManDNS_Slave
  11 +
  12 +# Parse config file
  13 +config = ConfigParser.ConfigParser()
  14 +config.read(os.path.dirname(os.path.realpath(__file__)) + '/../etc/pyManDNS.cfg');
  15 +
  16 +dir_db_files = config.get('Bind','dir.db_files')
  17 +pySlave = pyManDNS_Slave(dir_db_files)
  18 +
  19 +master_server_host = config.get('Server','server.host')
  20 +master_server_port = 3336
  21 +
  22 +pySlave.startDomainSlaveWrapper("127.0.0.1","3334")
  23 +pySlave.domainSlave.set_dir_db_file(dir_db_files)
  24 +pySlave.domainSlave.create_zone_file(1)
  25 +#pySlave.domainSlave.reload()
  26 +
  27 +#server = SimpleXMLRPCServer((server_host, int(server_port)), allow_none=True)
  28 +#server.register_instance(pySlave, True)
  29 +#
  30 +#print 'Server-slave started'
  31 +#
  32 +#server.serve_forever()
1  libs/pyManDNS_Cli.py
@@ -19,6 +19,7 @@ def _connect(self):
19 19
20 20
21 21 class pyManDNS_Cli_Domain(ConnectXMLRPC):
  22 +
22 23 def _kwargs_to_args_ordenated(self, **kwargs):
23 24 # The XML-RPC doesn't accept named params. The keys are
24 25 # to ordenate the params and use as **params.
90 libs/pyManDNS_Slave.py
... ... @@ -0,0 +1,90 @@
  1 +import xmlrpclib
  2 +import socket
  3 +
  4 +def success(msg=None, result=None):
  5 + return dict(type='success', message=msg, result=result)
  6 +
  7 +def error(msg=None, result=None):
  8 + return dict(type='error', message=msg, result=result)
  9 +
  10 +class ConnectXMLRPC(object):
  11 +
  12 + def __init__(self, host, port):
  13 + self.host = host
  14 + self.port = port
  15 + self._connect()
  16 +
  17 + def _connect(self):
  18 + try:
  19 + self.client = xmlrpclib.ServerProxy('http://%s:%s' % (self.host, self.port), allow_none=True)
  20 + except Exception, msg:
  21 + return dict(type='error', message=msg)
  22 +
  23 +class DomainSlaveWrapper(ConnectXMLRPC):
  24 + """
  25 + This class is used to separate the entities namespaces in the XML-RPC server.
  26 +
  27 + Usage in the server (example):
  28 + >>> import xmlrpclib
  29 + >>> client = xmlrpclib.ServerProxy('http://localhost:3000')
  30 + >>> client.domain.list()
  31 + """
  32 +
  33 +# def __init__(self,dir_db_files):
  34 +# self.dir_db_files = dir_db_files
  35 +
  36 + def set_dir_db_file(self,dir_db_file):
  37 + self.dir_db_file = dir_db_file
  38 +
  39 + def create_zone_file(self,verbose):
  40 + try:
  41 + result = self.client.domain.list()
  42 +
  43 + zones = ""
  44 +
  45 + for domain_row in result["result"]:
  46 +
  47 + zones += "zone \"" + domain_row["domain"] + "\" {\n"
  48 + zones += "\ttype slave;\n"
  49 + zones += "\tfile \"" + self.dir_db_file + "/db.slave." + domain_row["domain"] + "\";\n"
  50 + zones += "\tmasters { 192.168.1.204; };\n"
  51 + zones += "};\n\n"
  52 +
  53 + file = open("/var/named/chroot/etc/named.pyManDNS.slaves.zones", "w")
  54 + file.write(zones);
  55 + file.close()
  56 +
  57 + except socket.error, msg:
  58 + print 'erro!!'
  59 +
  60 +# ''' Visualiza db file '''
  61 +# def show(self,v_domain):
  62 +#
  63 +# msg = self.pyZones.read_db_file(v_domain)
  64 +#
  65 +# return success(msg=msg)
  66 +#
  67 +# ''' Get dominio '''
  68 +# def get(self,v_domain):
  69 +#
  70 +# domains_table = self.pyTables.domains_table()
  71 +# records_table = self.pyTables.records_table()
  72 +#
  73 +# domains_result = self.engine.execute(
  74 +# domains_table.select().where("domain=:domain"),domain=v_domain)
  75 +# domain_row = domains_result.first()
  76 +#
  77 +# if domain_row:
  78 +# # return domain_row
  79 +# return success(result=domain_row)
  80 +# else:
  81 +# msg = "ERROR: Dominio not found"
  82 +# return error(msg=msg)
  83 +
  84 +class pyManDNS_Slave(object):
  85 +
  86 + def __init__(self,dir_db_files):
  87 + self.dir_db_files = dir_db_files
  88 +
  89 + def startDomainSlaveWrapper(self,host,port):
  90 + self.domainSlave = DomainSlaveWrapper(host,port)

0 comments on commit 61e6d99

Please sign in to comment.
Something went wrong with that request. Please try again.