# -*- coding: utf-8 -*-
#Copyright (C) 2009 Sandro Knauß <bugs@sandroknauss.de>
#This program is free software; you can redistribute it and/or modify it under the terms
#of the GNU General Public License as published by the Free Software Foundation;
#either version 3 of the License, or any later version.
#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
#without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#See the GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, see <http://www.gnu.org/licenses/>.
# Server code
from xmlrpc import SecureUserDBXMLRPCServer,UserDB
from user import User, Admin, NotSupportedFeature
import anbieter
import ConfigParser
class MyUserDB(UserDB):
def __init__(self, userlist,jobqueue):
UserDB.__init__(self, None,userlist,jobqueue)
def createUser(self, user):
self.userlist[self.createHash(user)]=user["class"](self.jobqueue)
class MySipgate(anbieter.sipgate):
def __init__(self,user="",password="" ):
anbieter.sipgate.__init__(self, user, password)
def setJob(self, job):
self.job=job
def updateStatus(self, arranged=None, failed=None):
if arranged:
self.job.addGood(arranged)
if failed:
self.job.addFailed(failed)
class MySMTP(anbieter.SMTP):
def __init__(self,config_filename=None,section="smtp"):
anbieter.SMTP.__init__(self,config_filename,section)
def setJob(self, job):
self.job=job
def updateStatus(self, arranged=None, failed=None):
if arranged:
self.job.addGood(arranged)
if failed:
self.job.addFailed(failed)
class MySmstrade(anbieter.smstrade):
def __init__(self ):
anbieter.smstrade.__init__(self )
def setJob(self, job):
self.job=job
def updateStatus(self, arranged=None, failed=None):
if arranged:
self.job.addGood(arranged)
if failed:
self.job.addFailed(failed)
def start(userlist):
from multiprocessing import Queue
from multiprocessing.managers import BaseManager
class MyManager(BaseManager):
pass
MyManager.register('MessageJob', MessageJob)
manager = MyManager()
manager.start()
#anbieter erzeugen und konfigurieren
sip=MySipgate()
sip.read_basic_config("iro.conf")
localhost=MySMTP()
localhost.read_basic_config("iro.conf")
smstrade=MySmstrade()
smstrade.read_basic_config("iro.conf")
#Benutzerdatenbank erstellen
queue = Queue()
provider={"sms":{"sipgate":sip, "smstrade":smstrade, "default":sip, },
"fax":{"sipgate":sip, "default":sip, },
"mail":{"localhost":localhost, "default":localhost, }, }
jobqueue=Jobs(manager, queue, provider)
userdb=MyUserDB(userlist,jobqueue)
#working thread erstellen
from worker import Worker
worker=Worker(queue)
worker.start()
#Server starten
cp = ConfigParser.ConfigParser()
cp.read(["iro.conf"])
cert=cp.get('server', 'cert')
key=cp.get('server', 'key')
server = SecureUserDBXMLRPCServer(addr=("localhost", 8000),
userdb=userdb,
certificate=cert,privatekey=key)
server.relam="xmlrpc"
print "Server started..."
server.serve_forever()
worker.terminate()
if __name__ == '__main__':
userlist=[{"name":"test","password":"test", "class":User},
{"name":"test2","password":"test2", "class": Admin}]
start(userlist)