docs/DevelopmentGuide.odt docs/DevelopmentGuide.pdf LICENSE .pydevproject setup/openussd.spec src/config src/libs src/logs src/test
by Isaac Sanni-Thomas
.pydevproject | 4 -
LICENSE | 31 +++++++++
docs/DevelopmentGuide.odt |binary
docs/DevelopmentGuide.pdf |binary
setup/openussd.spec | 2
src/config/masteragent.cfg | 31 ---------
src/config/routes.cfg | 17 -----
src/config/testconfig.py | 11 ---
src/libs/__init__.pyc |binary
src/libs/core/__init__.py | 5 +
src/libs/core/__init__.pyc |binary
src/libs/core/confighandler.py | 106 +++++++++++++++++++++++++++++++
src/libs/core/dbhandler.py | 52 +++++++++++++++
src/libs/core/loghandler.py | 46 +++++++++++++
src/libs/info/cli/cli.py | 3
src/libs/masteragent/masteragent.py | 37 ++++++++++
src/libs/masteragent/routeinvoker.py | 21 ++++++
src/libs/pilot/pilot.py | 24 +++++++
src/libs/soap/soapserver.py | 41 ++++++++++++
src/logs/cli.log | 3
src/logs/debug.log | 1
src/logs/webui.log | 2
src/test/performanceTester.py | 119 +++++++++++++++++++++++++++++++++++
23 files changed, 494 insertions(+), 62 deletions(-)
New commits:
commit 22b508629e664213a1fee0cd7da5e80efe67d596
Author: Isaac d3vnull Sanni-Thomas <d3vnull.r00t(a)gmail.com>
Date: Thu Feb 24 11:38:50 2011 +0000
Config reader and parser set for ini file.Added db handler code
diff --git a/.pydevproject b/.pydevproject
index 139399d..db83591 100644
--- a/.pydevproject
+++ b/.pydevproject
@@ -2,8 +2,8 @@
<?eclipse-pydev version="1.0"?>
<pydev_project>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Python</pydev_property>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.6</pydev_property>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python</pydev_property>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/openussd/src</path>
</pydev_pathproperty>
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..567959b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,31 @@
+OpenUSSD is licensed under the Modified BSD License
+
+Copyright (C) 2003-2011 Isaac d3vnull Sanni-Thomas
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+3. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS
+OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/docs/DevelopmentGuide.odt b/docs/DevelopmentGuide.odt
index 0cb6e80..3d8593e 100644
Binary files a/docs/DevelopmentGuide.odt and b/docs/DevelopmentGuide.odt differ
diff --git a/docs/DevelopmentGuide.pdf b/docs/DevelopmentGuide.pdf
index 014c0fd..6141e3f 100644
Binary files a/docs/DevelopmentGuide.pdf and b/docs/DevelopmentGuide.pdf differ
diff --git a/setup/openussd.spec b/setup/openussd.spec
index b197f87..24a26a3 100644
--- a/setup/openussd.spec
+++ b/setup/openussd.spec
@@ -11,7 +11,7 @@ BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildRequires:memcached
BuildRequires:python-suds
-BuildRequires:
+BuildRequires:python-eventlet
Requires:
%description
diff --git a/src/config/masteragent.cfg b/src/config/masteragent.cfg
deleted file mode 100644
index 3e2f12b..0000000
--- a/src/config/masteragent.cfg
+++ /dev/null
@@ -1,31 +0,0 @@
-[main]
-masteragent_port=29999
-pilot_port=28888
-
-[gateway]
-id=airtel-ke
-host=10.10.10.220
-port=8080
-type=smpp
-username=demouser
-password=demopass
-
-
-[gateway]
-id=MTN
-host=127.0.0.1
-port=8080
-type=soap
-role=server
-methods=getmessage
-parameters=message,messageid,msisdn,sessionid
-
-
-[gateway]
-id=safaricom-ke
-host=127.0.0.1
-port=8090
-type=xmlrpc
-role=server
-methods=postrequest
-parameters=message,messageid,msisdn,sessionid
diff --git a/src/config/routes.cfg b/src/config/routes.cfg
deleted file mode 100644
index 31173c8..0000000
--- a/src/config/routes.cfg
+++ /dev/null
@@ -1,17 +0,0 @@
-[route]
-gateway_id=MTN
-shortcode=*
-method=http-post
-agent="http://open.ussd.com/openussd/mtnhandler.php"
-
-[route]
-gateway_id=safaricom-ke
-shortcode=*
-method=smpp
-port=3030
-
-[route]
-gateway_id=airtel-ke
-shortcode=*
-method=http-get
-agent="http://fiifi.baidoo.com:2300/ussdproc/airtel.jsp"
diff --git a/src/config/testconfig.py b/src/config/testconfig.py
deleted file mode 100644
index 432083d..0000000
--- a/src/config/testconfig.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-import ConfigParser
-config=ConfigParser.ConfigParser()
-config.read('masteragent.cfg')
-print config.sections()
-print ""
-
-print "Checking routes config file"
-routeconfig=ConfigParser.ConfigParser()
-routeconfig.read('routes.cfg')
-print routeconfig.sections()
diff --git a/src/libs/__init__.pyc b/src/libs/__init__.pyc
new file mode 100644
index 0000000..0186b7f
Binary files /dev/null and b/src/libs/__init__.pyc differ
diff --git a/src/libs/core/__init__.py b/src/libs/core/__init__.py
new file mode 100644
index 0000000..7c9658c
--- /dev/null
+++ b/src/libs/core/__init__.py
@@ -0,0 +1,5 @@
+'''
+Created on Jan 4, 2011
+
+@author: d3vnull
+'''
diff --git a/src/libs/core/__init__.pyc b/src/libs/core/__init__.pyc
new file mode 100644
index 0000000..cff3d79
Binary files /dev/null and b/src/libs/core/__init__.pyc differ
diff --git a/src/libs/core/confighandler.py b/src/libs/core/confighandler.py
new file mode 100644
index 0000000..dc3fe06
--- /dev/null
+++ b/src/libs/core/confighandler.py
@@ -0,0 +1,106 @@
+'''
+Created on Jan 24, 2011
+
+@author: d3vnull
+'''
+
+MASTERAGENT_CONFIG="configs/masteragent.ini"
+
+GATEWAY_CONFIG="configs/gateway.ini"
+
+ROUTES_CONFIG="configs/routes.ini"
+
+from ConfigParser import SafeConfigParser
+import ConfigParser
+
+class Confighandler:
+
+ DB_USER=""
+ DB_PASS=""
+ DB_HOST=""
+ DB_NAME=""
+ DB_TYPE=""
+
+ MASTERAGENT_PORT=""
+
+ ##########################################################################
+ #
+ #
+ ##########################################################################
+ def setConfigs(self):
+ try:
+ """ SetDBconfig reads the config file and set global values for
+ use"""
+
+ config = ConfigParser.RawConfigParser()
+ config.read(MASTERAGENT_CONFIG)
+
+ # Settings with values are treated as before:
+ self.DB_USER=config.get("main", "dbuser")
+ self.DB_HOST=config.get("main", "dbhost")
+ self.DB_PASS=config.get("main", "dbpass")
+ self.DB_NAME=config.get("main", "dbname")
+
+ self.DB_TYPE=config.get("main", "type")
+
+ self.MASTERAGENT_PORT=config.get("main", "port")
+
+ except:
+ print "Error found parsing config file in masteragent.ini"
+
+
+ return 0
+
+
+
+ def xmlrpc(self):
+ """parses xmlrpc config lines"""
+ vals=[]
+ SERVER="localhost"
+ ROLE="SERVER"
+ PORT=0
+ FUNCTIONS=""
+ PARAMETERS=""
+ return vals
+
+
+
+ def httpxml(self):
+ """Parses raw xml post lines"""
+ vals=[]
+ SERVER="localhost"
+ ROLE="SERVER"
+ PORT=0
+ FUNCTIONS=""
+ PARAMETERS=""
+ return vals
+
+ def smpp(self):
+ """ Parses smpp config lines"""
+ vals=[]
+ SERVER="localhost"
+ ROLE="SERVER"
+ PORT=0
+ FUNCTIONS=""
+ PARAMETERS=""
+ return vals
+
+
+ def soap(self):
+ """ Parses SOAP lines"""
+ vals=[]
+ SERVER="localhost"
+ ROLE="SERVER"
+ PORT=0
+ FUNCTIONS=""
+ PARAMETERS=""
+ return vals
+
+ def http(self):
+ """Parses plain http lines"""
+ vals=[]
+ SERVER="localhost"
+ ROLE="SERVER"
+ PORT=0
+ PARAMETERS=""
+ return vals
\ No newline at end of file
diff --git a/src/libs/core/dbhandler.py b/src/libs/core/dbhandler.py
new file mode 100644
index 0000000..35175ad
--- /dev/null
+++ b/src/libs/core/dbhandler.py
@@ -0,0 +1,52 @@
+'''
+Created on Jan 24, 2011
+
+@author: d3vnull
+'''
+import MySQLdb #for mysql users
+import psycopg2 #for postgresql users
+
+from confighandler import Confighandler
+
+
+configs=Confighandler()
+
+class dbhandler:
+
+ configs.setConfigs() #Read the DB values into the DB params below
+ DB_TYPE=configs.DB_TYPE
+ DB_HOST=configs.DB_HOST
+ DB_PASS=configs.DB_PASS
+ DB_USER=configs.DB_PASS
+ DB_NAME=configs.DB_NAME
+
+ #CHECK WHICH CONNECTION WE HAVE AND RUN THE QUERY
+ if(DB_TYPE=="postgresql"):
+ print "Found postgresql in config.Openussd will attempt connection"
+
+ elif(DB_TYPE=="mysql"):
+ print "Found mysql in config. Openussd will attempt connection"
+
+
+
+
+
+ ##########################################################################
+ #
+ #
+ #
+ ###########################################################################
+ def query(self,query):
+ """query functions runs a query and returns the result"""
+
+ result=[]
+
+
+
+
+
+
+
+
+
+ return result
\ No newline at end of file
diff --git a/src/libs/core/loghandler.py b/src/libs/core/loghandler.py
new file mode 100644
index 0000000..5ff17f9
--- /dev/null
+++ b/src/libs/core/loghandler.py
@@ -0,0 +1,46 @@
+'''
+Created on Jan 24, 2011
+
+@author: d3vnull
+'''
+
+
+#####################################
+# Logs anything in connection with
+# the cli such as commands invoked
+######################################
+def logger(type,message):
+ import logging
+ import syslog
+
+ log_file=""
+ logtype=""
+ #SET LOG FILE
+ if type=="webui":
+ logtype="loghandler.webui"
+ log_file="logs/webui.log"
+ elif type=="cli":
+ logtype="loghandler.webui"
+ log_file="logs/cli.log"
+ elif type=="masteragent":
+ logtype="loghandler.webui"
+ log_file="logs/masteragent.log"
+ elif type=="routes":
+ logtype="loghandler.webui"
+ log_file="logs/routes.log"
+ elif type=="pilot":
+ logtype="loghandler.webui"
+ log_file="logs/pilot.log"
+ elif type=="infobase":
+ logtype="loghandler.webui"
+ log_file="logs/infobase.log"
+ elif type=="debug":
+ logtype="loghandler.webui"
+ log_file="logs/debug.log"
+
+ logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s',filename=log_file,filemode='a')
+ # Set up a specific logger with our desired output level
+ webui_logger= logging.getLogger(logtype)
+
+ webui_logger.debug(' %s ' % message)
+ return 0
diff --git a/src/libs/info/cli/cli.py b/src/libs/info/cli/cli.py
new file mode 100644
index 0000000..25004eb
--- /dev/null
+++ b/src/libs/info/cli/cli.py
@@ -0,0 +1,3 @@
+#!/usr/bin/env python
+import optparse
+import argparse
diff --git a/src/libs/masteragent/masteragent.py b/src/libs/masteragent/masteragent.py
index e69de29..7822e6b 100644
--- a/src/libs/masteragent/masteragent.py
+++ b/src/libs/masteragent/masteragent.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+import eventlet
+from libs.core.confighandler import *
+"""\
+Simple server that listens on port 6000 and echos back every input to
+the client. To try out the server, start it up by running this file.
+
+Connect to it with:
+ telnet localhost 6000
+
+You terminate your connection by terminating telnet (typically Ctrl-]
+and then 'quit')
+"""
+def handle(fd):
+ print "client connected"
+ while True:
+ # pass through every non-eof line
+ x = fd.readline()
+ if not x: break
+ fd.write(x)
+ fd.flush()
+ print "echoed", x,
+ print "client disconnected"
+
+
+
+
+print "server socket listening on port 6000"
+server = eventlet.listen(('0.0.0.0', 6000))
+pool = eventlet.GreenPool()
+while True:
+ try:
+ new_sock, address = server.accept()
+ print "accepted", address
+ pool.spawn_n(handle, new_sock.makefile('rw'))
+ except (SystemExit, KeyboardInterrupt):
+ break
\ No newline at end of file
diff --git a/src/libs/masteragent/routeinvoker.py b/src/libs/masteragent/routeinvoker.py
new file mode 100644
index 0000000..a2e6c85
--- /dev/null
+++ b/src/libs/masteragent/routeinvoker.py
@@ -0,0 +1,21 @@
+'''
+Created on Jan 24, 2011
+
+@author: d3vnull
+'''
+
+class routeinvoker:
+
+
+
+ #############################################
+ #
+ #Selects a route from memcached for an incoming
+ # session and forwards it
+ #############################################
+ def selectroute(self):
+ routeurl=""
+
+
+
+ return routeurl
\ No newline at end of file
diff --git a/src/libs/pilot/pilot.py b/src/libs/pilot/pilot.py
index e69de29..2d6fbcc 100644
--- a/src/libs/pilot/pilot.py
+++ b/src/libs/pilot/pilot.py
@@ -0,0 +1,24 @@
+"""Spawn multiple workers and collect their results.
+
+Demonstrates how to use the eventlet.green.socket module.
+"""
+import eventlet
+from eventlet.green import socket
+
+def geturl(url):
+ c = socket.socket()
+ ip = socket.gethostbyname(url)
+ c.connect((ip, 80))
+ print '%s connected' % url
+ c.sendall('GET /\r\n\r\n')
+ return c.recv(1024)
+
+urls = ['www.google.com', 'www.yandex.ru', 'www.python.org']
+pile = eventlet.GreenPile()
+for x in urls:
+ pile.spawn(geturl, x)
+
+# note that the pile acts as a collection of return values from the functions
+# if any exceptions are raised by the function they'll get raised here
+for url, result in zip(urls, pile):
+ print '%s: %s' % (url, repr(result)[:50])
\ No newline at end of file
diff --git a/src/libs/soap/soapserver.py b/src/libs/soap/soapserver.py
new file mode 100644
index 0000000..f613eab
--- /dev/null
+++ b/src/libs/soap/soapserver.py
@@ -0,0 +1,41 @@
+import SOAPpy
+
+def printString():
+ return "Hello1"
+
+
+def _runSOAPServer():
+ server = SOAPpy.SOAPServer(("home", 8080))
+ server.registerFunction(printString)
+ server.serve_forever()
+
+#if __name__ == '__main__':
+ _runSOAPServer()
+
+
+from suds.client import Client
+client = Client("http://localhost:7789/wsdl")
+print client
+
+from soaplib.wsgi_soap import SimpleWSGISoapApp
+from soaplib.service import soapmethod
+from soaplib.serializers.primitive import Array, String
+
+class HelloWorldService(SimpleWSGISoapApp):
+ @soapmethod(_returns=Array(String))
+ def hello(self):
+ "A method that says hello"
+ return ["hello", "world"]
+
+if __name__=='__main__':
+ from twisted.web import server, wsgi, resource
+ from twisted.internet import reactor
+ server_name='0.0.0.0'
+ server_port=8080
+ root = resource.Resource()
+ root.putChild("hello", wsgi.WSGIResource(reactor,
+reactor.getThreadPool(), HelloWorldService()))
+ reactor.listenTCP(server_port, server.Site(root), interface=server_name)
+ reactor.run()
+
+
diff --git a/src/logs/cli.log b/src/logs/cli.log
index e69de29..01194a2 100644
--- a/src/logs/cli.log
+++ b/src/logs/cli.log
@@ -0,0 +1,3 @@
+
+2011-01-24 12:09:39,498 Testing CLI logger.....
+2011-01-24 12:09:39,498 Testing Webui logger.....
diff --git a/src/logs/debug.log b/src/logs/debug.log
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/src/logs/debug.log
@@ -0,0 +1 @@
+
diff --git a/src/logs/webui.log b/src/logs/webui.log
index e69de29..ecc8f63 100644
--- a/src/logs/webui.log
+++ b/src/logs/webui.log
@@ -0,0 +1,2 @@
+
+2011-01-24 12:29:45,150 Testing Webui logger.....
diff --git a/src/test/performanceTester.py b/src/test/performanceTester.py
new file mode 100644
index 0000000..57c5274
--- /dev/null
+++ b/src/test/performanceTester.py
@@ -0,0 +1,119 @@
+#!/usr/bin/python
+
+import greenlet
+import optparse
+
+tasks = []
+accum = list()
+sum = 0
+vecA = vecB = None
+
+def mulNAccum(idx, val1, val2) :
+global accum
+accum.insert(idx, val1*val2)
+#print idx,val1*val2,accum
+
+def createTasks(HowMany):
+global vecA, vecB
+vecA = range(0, HowMany)
+vecB = range(0, HowMany)
+for i in range(0,HowMany):
+ tasks.append(greenlet.greenlet(run=mulNAccum,parent=greenlet.getcurrent()))
+
+def executeTasks(HowMany):
+global tasks
+global accum
+global sum
+
+for i in range(0,HowMany):
+ tasks[i].switch(i, vecA[i],vecB[i])
+#print "tasks finished executing ...\n"
+# print accum
+for i in range(0, len(accum)):
+ sum = sum + accum[i]
+
+print "Sum of matrix multiplication: %d\n" % sum
+
+if __name__ == "__main__":
+parser = optparse.OptionParser()
+parser.add_option("--items", "-i", default=10, action="store", type="int", dest="HowMany", help="number of elements in matrix array to process")
+(options, args) = parser.parse_args()
+
+createTasks(options.HowMany)
+executeTasks(options.HowMany)
+
+
+Similar program using the for-loop a.k.a iterative approach
+
+
+#!/usr/bin/python
+
+import optparse
+
+sum = 0
+vecA = vecB = None
+
+def execMatrixAdd_Iter(HowMany):
+global vecA, vecB, sum
+vecA = range(0, HowMany)
+vecB = range(0, HowMany)
+for i in range(0, HowMany):
+ temp = vecA[i] * vecB[i]
+ sum = temp + sum
+print "iteration version of matrix add: %d\n" % sum
+
+
+if __name__ == "__main__":
+parser = optparse.OptionParser()
+parser.add_option("--items", "-i", default=10, action="store", type="int", dest="HowMany", help="number of elements in matrix array to process")
+(options, args) = parser.parse_args()
+execMatrixAdd_Iter(options.HowMany)
+
+
+Last script using Linden Lab's eventlet
+
+
+#!/usr/bin/python
+
+import eventlet
+import eventlet.api
+import optparse
+
+tasks = []
+accum = list()
+sum = 0
+vecA = vecB = None
+
+def mulNAccum(idx, val1, val2) :
+global accum
+accum.insert(idx, val1*val2)
+#print idx,val1*val2,accum
+
+def createTasks(HowMany):
+global vecA, vecB
+vecA = range(0, HowMany)
+vecB = range(0, HowMany)
+for i in range(0,HowMany):
+ tasks.append(eventlet.api.spawn(mulNAccum, i, vecA[i-1], vecB[i-1]))
+
+def executeTasks(HowMany):
+global tasks
+global accum
+global sum
+
+for i in range(0,HowMany):
+ tasks[i].switch()
+#print "tasks finished executing ...\n"
+# print accum
+for i in range(0, len(accum)):
+ sum = sum + accum[i]
+
+print "Sum of matrix multiplication: %d\n" % sum
+
+if __name__ == "__main__":
+parser = optparse.OptionParser()
+parser.add_option("--items", "-i", default=10, action="store", type="int", dest="HowMany", help="number of elements in matrix array to process")
+(options, args) = parser.parse_args()
+
+createTasks(options.HowMany)
+executeTasks(options.HowMany)
13 years, 2 months