add customer level

This commit is contained in:
Wolfgang Hottgenroth 2009-02-21 20:35:51 +01:00
parent 31c92eae50
commit cb38eef50f
8 changed files with 161 additions and 43 deletions

View File

@ -9,25 +9,39 @@ class AdminFuncException(Exception):
class AdminFuncs(object):
@classmethod
def setParams(cls, entries, adminPwd):
def setParams(cls, entries, customers):
cls.entries = entries
cls.adminPwd = adminPwd
cls.customers = customers
@classmethod
def register(cls, dynid, subdomain, zone, sharedSecret, checksum):
di = "%s %s %s %s %s" % (dynid, subdomain, zone, sharedSecret, AdminFuncs.adminPwd)
try:
customer = AdminFuncs.customers[zone]
except KeyError:
raise AdminFuncException("access denied")
adminPwd = customer.adminPwd
maxEntries = customer.maxEntries
di = "%s %s %s %s %s" % (dynid, subdomain, zone, sharedSecret, adminPwd)
d = md5.new(di).hexdigest()
Logger.debug("%s, received: %s, calculated: %s" % (di, checksum, d))
if d != checksum:
raise AdminFuncException("access denied: %s" % di)
raise AdminFuncException("access denied")
if AdminFuncs.entries.has_key(dynid):
raise AdminFuncException("duplicate dynid")
entryCnt = 0
for entry in AdminFuncs.entries.values():
if entry.zone == zone:
entryCnt += 1
if entry.name == subdomain and entry.zone == zone:
raise AdminFuncException("duplicate full name")
if entryCnt >= maxEntries and maxEntries != 0:
raise AdminFuncException("too much entries")
newEntry = Entry.Entry(dynid, sharedSecret, subdomain, zone)
AdminFuncs.entries[dynid] = newEntry

View File

@ -5,6 +5,7 @@ import sys
import time
import Entry
import Customer
from logger import Logger
@ -14,9 +15,9 @@ class LocalMyCmdException(Exception):
class MyCmd(cmd.Cmd):
@classmethod
def setClassParams(cls, entries, adminPwd):
def setClassParams(cls, entries, customers):
cls.entries = entries
cls.adminPwd = adminPwd
cls.customers = customers
def __init__(self, i, o):
cmd.Cmd.__init__(self, completekey=None, stdin=i, stdout=o)
@ -123,6 +124,79 @@ class MyCmd(cmd.Cmd):
self.stdout.write("Bye\n")
return True
def do_addcust(self, l):
try:
parts = l.split(' ')
if len(parts) != 5:
raise LocalMyCmdException("illegal number of arguments")
(zone, adminPwd, contact, email, maxEntries) = parts
if MyCmd.customers.has_key(zone):
raise LocalMyCmdException("duplicate zone")
try:
maxEntries = int(maxEntries)
except ValueError:
raise LocalMyCmdException("maxEntries is no number")
newCustomer = Customer.Customer(zone, adminPwd, contact, email, maxEntries)
MyCmd.customers[zone] = newCustomer
self.stdout.write("Done\n")
except LocalMyCmdException, e:
self.stdout.write("Failure: %s\n" % str(e.msg))
def do_editcust(self, l):
try:
parts = l.split(' ')
if len(parts) != 3:
raise LocalMyCmdException("illegal number of arguments")
(zone, attr, value) = parts
if not MyCmd.customers.has_key(zone):
raise LocalMyCmdException("unknown zone")
if attr == 'adminPwd':
MyCmd.customers[zone].adminPwd = value
elif attr == 'contact':
MyCmd.customers[zone].contact = value
elif attr == 'email':
MyCmd.customers[zone].email = value
elif attr == 'maxEntries':
try:
MyCmd.customers[zone].maxEntries = int(value)
except ValueError:
raise LocalMyCmdException("value is no number")
else:
raise LocalMyCmdException("unknown attribute to change")
self.stdout.write("Done\n")
except LocalMyCmdException, e:
self.stdout.write("Failure: %s\n" % str(e.msg))
def do_deletecust(self, l):
try:
parts = l.split(' ')
if len(parts) != 1:
raise LocalMyCmdException("illegal number of arguments")
zone = parts[0]
if not MyCmd.customers.has_key(zone):
raise LocalMyCmdException("unknown zone")
del MyCmd.entries[x]
self.stdout.write("Done\n")
except LocalMyCmdException, e:
self.stdout.write("Failure: %s\n" % str(e.msg))
def do_listcust(self, l):
try:
parts = l.split(' ')
if len(parts) != 1:
raise LocalMyCmdException("illegal number of arguments")
x = parts[0]
if x == 'all':
for customer in MyCmd.customers.values():
self.stdout.write(str(customer) + "\n")
elif MyCmd.customers.has_key(x):
self.stdout.write(str(MyCmd.customers[x]) + "\n")
else:
raise LocalMyCmdException("unknown zone")
except LocalMyCmdException, e:
self.stdout.write("Failure: %s\n" % str(e.msg))
class CmdHandler(SocketServer.StreamRequestHandler):

10
server/Customer.py Normal file
View File

@ -0,0 +1,10 @@
class Customer(object):
def __init__(self, zone, adminPwd, contact, email, maxEntries):
self.zone = zone
self.adminPwd = adminPwd
self.contact = contact
self.email = email
self.maxEntries = maxEntries
def __str__(self):
return "Customer[zone=%s, adminPwd=%s, contact=%s, email=%s, maxEntries=%d]" % (self.zone, self.adminPwd, self.contact, self.email, self.maxEntries)

View File

@ -9,7 +9,7 @@ class Entry(object):
self.addressInDns = '0.0.0.0'
def __str__(self):
return "dynid=%s, name=%s, zone=%s, sharedSecret=%s, address=%s (%s), lastEventTime=%d" % (self.dynid, self.name, self.zone, self.sharedSecret, self.address, self.addressInDns, self.lastEventTime)
return "Entry[dynid=%s, name=%s, zone=%s, sharedSecret=%s, address=%s (%s), lastEventTime=%d]" % (self.dynid, self.name, self.zone, self.sharedSecret, self.address, self.addressInDns, self.lastEventTime)

View File

@ -23,9 +23,8 @@ class HttpCmdHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def log_request(self, code='-', size='-'): pass
@classmethod
def setClassParams(cls, entries, adminPwd, dnsq, nullAddress):
def setClassParams(cls, entries, dnsq, nullAddress):
cls.entries = entries
cls.adminPwd = adminPwd
cls.dnsq = dnsq
cls.nullAddress = nullAddress
@ -109,10 +108,10 @@ class HttpCmdServer(SocketServer.ThreadingTCPServer):
class HttpCmdReceiver(threading.Thread):
def __init__(self, httpCmdRecvAddr, entries, adminPwd, dnsq, nullAddress):
def __init__(self, httpCmdRecvAddr, entries, dnsq, nullAddress):
threading.Thread.__init__(self)
self.httpCmdRecvAddr = httpCmdRecvAddr
HttpCmdHandler.setClassParams(entries, adminPwd, dnsq, nullAddress)
HttpCmdHandler.setClassParams(entries, dnsq, nullAddress)
self.setDaemon(True)
def run(self):

View File

@ -12,9 +12,8 @@ class LocalException(Exception):
class XmlRpcServer(SimpleXMLRPCServer):
@classmethod
def setClassParams(cls, entries, adminPwd):
def setClassParams(cls, entries):
cls.entries = entries
cls.adminPwd = adminPwd
def _dispatch(self, method, params):
@ -38,10 +37,10 @@ class XmlRpcServer(SimpleXMLRPCServer):
class XmlRpcReceiver(threading.Thread):
def __init__(self, xmlRpcRecvAddr, entries, adminPwd):
def __init__(self, xmlRpcRecvAddr, entries):
threading.Thread.__init__(self)
self.xmlRpcRecvAddr = xmlRpcRecvAddr
XmlRpcServer.setClassParams(entries, adminPwd)
XmlRpcServer.setClassParams(entries)
self.setDaemon(True)
def run(self):

15
server/testxml Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env python
import sys
import xmlrpclib
import md5
(x, dynid, subdomain, zone, sharedSecret, adminPwd) = sys.argv
d = "%s %s %s %s %s" % (dynid, subdomain, zone, sharedSecret, adminPwd)
checksum = md5.new(d).hexdigest()
s = xmlrpclib.ServerProxy("http://localhost:8024")
r = s.register(dynid, subdomain, zone, sharedSecret, checksum, "test@test.de")
print r

View File

@ -20,35 +20,37 @@ import AdminFuncs
#MSG_TIME_CORRIDOR = 120
#EVENT_LIFE_TIME = 60
#NULL_ADDRESS = '0.0.0.0'
#TTL = 120
#EXPIRY_PERIOD = 30
#NAMESERVER = '127.0.0.1'
#NAMESERVER_PORT = 5300
#TSIGKEY = { "yadyn." : "+xLH8GuZnEgBljuIEM/iDA==" }
#PID_FILE = "/tmp/yadyn/yadyn.pid"
#ENTRIES_FILE = "/tmp/yadyn/entries"
#ACTIONLOG_DIR = "/tmp/yadyn/actionlog"
#ADMIN_PWD = 'test123'
#DNS_DUMMY = False
#DEBUG = True
MSG_TIME_CORRIDOR = 120
EVENT_LIFE_TIME = 600
EVENT_LIFE_TIME = 120
NULL_ADDRESS = '0.0.0.0'
TTL = 120
EXPIRY_PERIOD = 300
NAMESERVER = '88.198.170.2'
NAMESERVER_PORT = 53
EXPIRY_PERIOD = 120
NAMESERVER = '127.0.0.1'
NAMESERVER_PORT = 5300
TSIGKEY = { "yadyn." : "+xLH8GuZnEgBljuIEM/iDA==" }
PID_FILE = "/var/db/yadyn/yadyn.pid"
ENTRIES_FILE = "/var/db/yadyn/entries"
ACTIONLOG_DIR = "/var/db/yadyn/actionlog"
PID_FILE = "/tmp/yadyn/yadyn.pid"
ENTRIES_FILE = "/tmp/yadyn/entries"
CUSTOMERS_FILE = "/tmp/yadyn/customers"
ACTIONLOG_DIR = "/tmp/yadyn/actionlog"
ADMIN_PWD = 'test123'
DNS_DUMMY = False
DEBUG = False
DEBUG = True
#MSG_TIME_CORRIDOR = 120
#EVENT_LIFE_TIME = 600
#NULL_ADDRESS = '0.0.0.0'
#TTL = 120
#EXPIRY_PERIOD = 300
#NAMESERVER = '88.198.170.2'
#NAMESERVER_PORT = 53
#TSIGKEY = { "yadyn." : "+xLH8GuZnEgBljuIEM/iDA==" }
#PID_FILE = "/var/db/yadyn/yadyn.pid"
#ENTRIES_FILE = "/var/db/yadyn/entries"
#CUSTOMERS_FILE = "/var/db/yadyn/customers"
#ACTIONLOG_DIR = "/var/db/yadyn/actionlog"
#ADMIN_PWD = 'test123'
#DNS_DUMMY = False
#DEBUG = False
@ -74,7 +76,10 @@ if DEBUG:
Logger.log("yadyn starting")
entries = shelve.open(ENTRIES_FILE, flag='c', writeback=True)
Logger.debug("Shelve opened")
Logger.debug("Entry shelve opened")
customers = shelve.open(CUSTOMERS_FILE, flag='c', writeback=True)
Logger.debug("Customer shelve opened")
try:
eventq = Queue.Queue()
@ -83,7 +88,7 @@ try:
Event.Event.setParams(entries, MSG_TIME_CORRIDOR, dnsq)
AdminFuncs.AdminFuncs.setParams(entries, ADMIN_PWD)
AdminFuncs.AdminFuncs.setParams(entries, customers)
dynHandler = DynHandler.DynHandler(eventq)
dynHandler.start()
@ -101,15 +106,15 @@ try:
expirer.start()
Logger.debug("Expirer started")
cmdReceiver = CmdReceiver.CmdReceiver(("", 8023), entries, ADMIN_PWD)
cmdReceiver = CmdReceiver.CmdReceiver(("", 8023), entries, customers)
cmdReceiver.start()
Logger.debug("CmdReceiver started")
xmlRpcReceiver = XmlRpcReceiver.XmlRpcReceiver(("", 8024), entries, ADMIN_PWD)
xmlRpcReceiver = XmlRpcReceiver.XmlRpcReceiver(("", 8024), entries)
xmlRpcReceiver.start()
Logger.debug("XmlRpcReceiver started")
httpCmdReceiver = HttpCmdReceiver.HttpCmdReceiver(("", 8025), entries, ADMIN_PWD, dnsq, NULL_ADDRESS)
httpCmdReceiver = HttpCmdReceiver.HttpCmdReceiver(("", 8025), entries, dnsq, NULL_ADDRESS)
httpCmdReceiver.start()
Logger.debug("httpCmdReceiver started")
@ -118,8 +123,10 @@ try:
Logger.log("yadyn running")
while True:
entries.sync()
customers.sync()
time.sleep(10)
finally:
entries.close()
customers.close()
Logger.debug("Shelves closed")
Logger.log("yadyn terminating")