63 lines
1.6 KiB
Python
63 lines
1.6 KiB
Python
import threading
|
|
import time
|
|
import Event
|
|
from logger import Logger
|
|
from SimpleXMLRPCServer import SimpleXMLRPCServer
|
|
|
|
import Entry
|
|
|
|
class LocalException(Exception):
|
|
def __init__(self, msg):
|
|
self.msg = msg
|
|
|
|
class XmlRpcServer(SimpleXMLRPCServer):
|
|
@classmethod
|
|
def setClassParams(cls, entries, adminPwd):
|
|
cls.entries = entries
|
|
cls.adminPwd = adminPwd
|
|
|
|
|
|
def _dispatch(self, method, params):
|
|
try:
|
|
# We are forcing the 'export_' prefix on methods that are
|
|
# callable through XML-RPC to prevent potential security
|
|
# problems
|
|
func = getattr(self, 'export_' + method)
|
|
except AttributeError:
|
|
raise Exception('method "%s" is not supported' % method)
|
|
else:
|
|
return func(*params)
|
|
|
|
def export_register(self, subdomain, sharedSecret, email):
|
|
try:
|
|
dynid = subdomain
|
|
zone = 'yadynns.net'
|
|
|
|
if XmlRpcServer.entries.has_key(dynid):
|
|
raise LocalException("duplicate dynid")
|
|
for entry in XmlRpcServer.entries.values():
|
|
if entry.name == subdomain and entry.zone == zone:
|
|
raise LocalException("duplicate full name")
|
|
newEntry = Entry.Entry(dynid, sharedSecret, subdomain, zone)
|
|
XmlRpcServer.entries[dynid] = newEntry
|
|
|
|
return 'ok'
|
|
except LocalException, e:
|
|
return 'nok ' + e.msg
|
|
|
|
|
|
|
|
|
|
|
|
class XmlRpcReceiver(threading.Thread):
|
|
def __init__(self, xmlRpcRecvAddr, entries, adminPwd):
|
|
threading.Thread.__init__(self)
|
|
self.xmlRpcRecvAddr = xmlRpcRecvAddr
|
|
XmlRpcServer.setClassParams(entries, adminPwd)
|
|
self.setDaemon(True)
|
|
|
|
def run(self):
|
|
server = XmlRpcServer(self.xmlRpcRecvAddr)
|
|
server.serve_forever()
|
|
|