1
0
Fork 0

- replaced SOAP with XML-RPC

- add keywords
- add ServiceFacade, SettingsManager, DomainManager
- add xmlrpcclient
- add xmlrpcserver


git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@184 a67ec6bc-e5d5-0310-a910-815c51eb3124
This commit is contained in:
Jan Dittberner 2006-04-15 20:00:23 +00:00
parent 2c8c2228c0
commit 985810317a
9 changed files with 144 additions and 81 deletions

View File

@ -0,0 +1,12 @@
#
# Domain manager class for gnuviech-admin tool backend
# (c) 2006 Jan Dittberner <jan@dittberner.info>
# $Id$
#
from SessionManager import Session
class DomainManager:
def listDomains(self, session):
if isinstance(session, Session):
return 'a,b,c'
return ''

View File

@ -1,66 +0,0 @@
#!/usr/bin/python
#
# File: soapserver.py
# (c) 2006 Jan Dittberner <jan@dittberner.info>
# $Id$
#
import SOAPpy
import logging
import Settings
class _GnuviechLoggingInstance:
"""
Logging instance base class
"""
def __init__(self, logname):
"""
Initializes a logging instance
"""
self.logger = logging.getLogger(logname)
hdlr = logging.FileHandler('soapserver.log')
hdlr.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(name)s %(message)s'))
self.logger.addHandler(hdlr)
self.logger.setLevel(logging.DEBUG)
class Services(_GnuviechLoggingInstance):
"""
The class provides all services.
"""
def __init__(self):
"""
Construtor
"""
_GnuviechLoggingInstance.__init__(self, 'GnuviechAdminServices')
def echo(self, param0):
"""
This method echoes its parameter
"""
self.logger.debug("calling echo with " + param0)
return param0 + param0
class SOAPServer(SOAPpy.SOAPServer, _GnuviechLoggingInstance):
"""
SOAP Server class for the gnuviech administration tool backend
"""
def __init__(self):
"""
This method creates the SOAPServer and registers the methods to be
available to connected SOAP clients.
"""
SOAPpy.SOAPServer.__init__(self, Settings.soapaddress)
_GnuviechLoggingInstance.__init__(self, 'GnuviechAdminSOAPServer')
self.services = Services()
self.registerObject(self.services, Settings.namespace)
self.logger.debug("registered function echo")
def main(self):
"""
Starts serving SOAP requests.
"""
self.logger.debug("serving SOAP")
self.serve_forever()
if __name__ == "__main__":
server = SOAPServer()
server.main()

View File

@ -0,0 +1,37 @@
#
# Service facade for gnuviech-admin tool backend
# (c) 2006 Jan Dittberner <jan@dittberner.info>
# $Id$
#
from SessionManager import *
from DomainManager import *
class ServiceFacade:
def __init__(self):
self.sessionManager = SessionManager()
self.domainManager = DomainManager()
"""
This class implements the facade to the services provided by the
gnuviech admin backend.
"""
def login(self, login, password):
"""
Logs in the user specified by the given login and password.
The method creates a session and returns the session id which
has to be sent back by subsequent requests. If the login is
invalid the returned id is 0
"""
try:
return self.sessionManager.newSession(login, password)
except InvalidLoginError, ile:
return 0
def listdomains(self, sessionid):
"""
Lists the domains the given session may see.
"""
try:
session = self.sessionManager.getSession(sessionid)
return self.domainManager.listDomains(session)
except InvalidSessionError, ise:
return ""

View File

@ -0,0 +1,37 @@
#
# Session manager class for gnuviech-admin tool backend
# (c) 2006 Jan Dittberner <jan@dittberner.info>
# $Id$
#
import Settings
import os
class InvalidLoginError(Exception):
pass
class InvalidSessionError(Exception):
pass
class Session:
def __init__(self, id, login, rights, uid, gid):
self.id = id
self.login = login
self.right = rights
self.uid = uid
self.gid = gid
class SessionManager:
def _getSessionFile(self, sessionid):
if os.path.exists(Settings.SESSIONDIR) and \
os.path.isdir(Settings.SESSIONDIR):
return file(os.path.join(SETTINGS.SESSIONDIR, sessionid))
return None
def newSession(self, login, password):
raise InvalidLoginError()
def getSession(self, sessionid):
raise InvalidSessionError()
def deleteSession(self, sessionid):
self._getSessionFile(sessionid)

View File

@ -1,22 +1,22 @@
#!/usr/bin/env python
#
# Settings for gnuviech-admin tool backend
# (c) 2006 Jan Dittberner <jan@dittberner.info>
# $Id:Settings.py 847 2006-02-21 21:21:30Z jan $
#
ALLPREFIX = '/home/jan/gnvadmtest'
dbsettings = { 'dbuser': 'exim4',
DBSETTINGS = { 'dbuser': 'exim4',
'dbpassword' : 'CotOgigmeIk5',
'dbname' : 'gnuviechadmin' }
# courier:jevhi3Wriav
# gnuviech:SIKKnsyXsV5yU
'dbname' : 'gnuviechadmin' }
# courier:jevhi3Wriav
# gnuviech:SIKKnsyXsV5yU
mailsender = 'root@gnuviech.info'
mailreceiver = 'root@gnuviech.info'
popgroup = 'poponly'
popgroup = 'poponly'
pophome = '/home/mail/'
webhome = '/home/www/'
namespace = 'urn:gnuviech-admin-services'
MAIL_SENDER = 'root@gnuviech.info'
MAIL_RECEIVER = 'root@gnuviech.info'
POPGROUP = 'poponly'
POPHOME = ALLPREFIX + '/home/mail/'
WEBHOME = ALLPREFIX + '/home/www/'
USERPREFIX = 'usr'
soapaddress = ('127.0.0.1', 8080);
GNUVIECHADMINDIR = ALLPREFIX + '/var/lib/gnuviechadmin'
SESSIONDIR = GNUVIECHADMINDIR + '/sessions'

View File

@ -5,4 +5,5 @@
#
"""
This package contains classes for the gnuviech administration tool backend.
"""
"""
from ServiceFacade import *

View File

@ -10,7 +10,7 @@ class gnuviechadmin(ServiceSOAPBinding):
<!--
Webservice description for gnuviechadmin
(c) 2006 Jan Dittberner <jan@dittberner.info>
Version: $Id: gnuviechadmin.wsdl 863 2006-03-07 22:26:55Z jan $
Version: $Id$
--><wsdl:definitions name=\"gnuviechadmin\" targetNamespace=\"https://ssl.gnuviech.info/gnuviechadmin/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:tns=\"https://ssl.gnuviech.info/gnuviechadmin/\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">
<wsdl:types>
<xsd:schema targetNamespace=\"https://ssl.gnuviech.info/gnuviechadmin/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">

21
backend/xmlrpcserver.py Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/python
#
# XML-RPC server for gnuviech-admin tool
# (c) 2006 Jan Dittberner
# $Id$
#
from DocXMLRPCServer import DocXMLRPCServer
from GnuviechAdmin import ServiceFacade
def startRPCServer():
server = DocXMLRPCServer(("localhost", 8080))
server.register_introspection_functions()
server.register_instance(ServiceFacade())
try:
server.serve_forever()
except KeyboardInterrupt:
server.server_close()
if __name__ == "__main__":
startRPCServer()

21
frontend/common/xmlrpcclient.py Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/python
# XML-RPC-Client
# (c) 2006 Jan Dittberner
# version: $Id$
#
from xmlrpclib import ServerProxy
import logging, sys
if __name__ == '__main__':
server = ServerProxy('http://localhost:8080')
logger = logging.getLogger()
logging.basicConfig()
try:
sessionid = server.login('jan', 'heyyou97')
if sessionid:
server.listDomains(sessionid)
else:
print "login failed"
except Exception, v:
logger.exception(v)