[asterisk-scf-commits] asterisk-scf/examples.git branch "master" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Wed Aug 3 14:47:12 CDT 2011
branch "master" has been updated
via 466b8d4f2d72ad8926253303e1379a92a587c6b3 (commit)
from 700889d2e714815b4b57c324cfef94d6d0b287ae (commit)
Summary of changes:
ExampleSipAuthHook.py | 105 +++++++++++++++++++++++++++++++++++++++++++++++++
README.txt | 6 +++
2 files changed, 111 insertions(+), 0 deletions(-)
create mode 100755 ExampleSipAuthHook.py
- Log -----------------------------------------------------------------
commit 466b8d4f2d72ad8926253303e1379a92a587c6b3
Author: Joshua Colp <jcolp at digium.com>
Date: Wed Aug 3 16:47:27 2011 -0300
Add an example SIP authentication hook python script.
diff --git a/ExampleSipAuthHook.py b/ExampleSipAuthHook.py
new file mode 100755
index 0000000..31e979d
--- /dev/null
+++ b/ExampleSipAuthHook.py
@@ -0,0 +1,105 @@
+#!/usr/bin/env python
+
+#
+# Asterisk SCF -- An open-source communications framework.
+#
+# Copyright (C) 2011, Digium, Inc.
+#
+# See http://www.asterisk.org for more information about
+# the Asterisk SCF project. Please do not directly contact
+# any of the maintainers of this project for assistance;
+# the project provides a web site, mailing lists and IRC
+# channels for your use.
+#
+# This program is free software, distributed under the terms of
+# the GNU General Public License Version 2. See the LICENSE.txt file
+# at the top of the source tree.
+#
+
+# Sip Example Authentication Hook
+
+import sys, threading, Ice, os, getopt
+
+Ice.loadSlice("--underscore -I" + os.environ["ASTSCF_HOME"] + " -I" + Ice.getSliceDir() + " --all " + os.environ["ASTSCF_HOME"] + "/AsteriskSCF/Core/Discovery/ServiceLocatorIf.ice")
+Ice.loadSlice("--underscore -I" + os.environ["ASTSCF_HOME"] + " -I" + Ice.getSliceDir() + " --all " + os.environ["ASTSCF_HOME"] + "/AsteriskSCF/SIP/SIPExtensionPointIf.ice")
+
+from AsteriskSCF.Core.Discovery.V1 import *
+from AsteriskSCF.SIP.ExtensionPoint.V1 import *
+from AsteriskSCF.System.Hook.V1 import *
+
+class ExampleAuthHook(AuthHook):
+ def challengeRequest(self, info, challenges):
+ result = HookResult()
+ result.status = HookStatus.Succeeded
+
+ challenge = MD5DigestChallenge()
+ challenge.username = "bob"
+ challenge.password = "alice"
+ challenge.realm = "example"
+ challenge.domain = [ "example.com" ]
+
+ challenges = [ challenge ]
+
+ return (result, challenges)
+
+class ExampleAuthHookApp(Ice.Application):
+ def usage(self):
+ """Print usage information for the example SIP authentication hook"""
+
+ print "Usage: " + self.appName() + " [--locator=stringified service locator proxy]"
+ print "Hook into a SIP component and provide authentication."
+ print ""
+ print "Mandatory arguments to long options are mandatory for short options too."
+ print "-h, --help display help information"
+ print "-l, --locator=PROXY use specified proxy for service locator"
+
+ def run(self, args):
+ try:
+ opts, arguments = getopt.getopt(args[1:], "hl:", ["help", "locator="])
+ except getopt.GetoptError, err:
+ print str(err)
+ self.usage()
+ return 1
+
+ serviceLocator = None
+ extensionPoint = None
+
+ for o, a in opts:
+ if o in ("-h", "--help"):
+ self.usage()
+ return 1
+
+ elif o in ("-l", "--locator"):
+ serviceLocator = ServiceLocatorPrx.checkedCast(self.communicator().stringToProxy(a))
+
+ if serviceLocator == None:
+ print >> sys.stderr, "No service locator proxy specified. For usage details please run " + sys.argv[0] + " --help"
+ return -1
+
+ serviceLocatorParams = ServiceLocatorParams()
+ serviceLocatorParams.category = "SipAuthExtensionPoint"
+
+ try:
+ service = serviceLocator.locate(serviceLocatorParams)
+ except AsteriskSCF.Core.Discovery.V1.ServiceNotFound:
+ print >> sys.stderr, "SIP authentication extension point could not be found in service locator."
+ return -1
+
+ extensionPoint = AuthExtensionPointPrx.checkedCast(service)
+
+ adapter = self.communicator().createObjectAdapterWithEndpoints("ExampleAuthHookApp", "default");
+ adapter.activate();
+
+ hook = ExampleAuthHook()
+
+ proxy = AuthHookPrx.uncheckedCast(adapter.addWithUUID(hook))
+
+ extensionPoint.addAuthHook(proxy, 1, [ RequestType.DialogEstablishing ])
+
+ self.communicator().waitForShutdown()
+ extensionPoint.removeAuthHook(proxy)
+
+ return 0
+
+app = ExampleAuthHookApp()
+sys.exit(app.main(sys.argv))
diff --git a/README.txt b/README.txt
index d0fa295..b792160 100644
--- a/README.txt
+++ b/README.txt
@@ -25,3 +25,9 @@ When sessions are added to a bridge, it then adds itself as a SessionListener. A
events on bridges and sessions are caught by this script. The script simply prints
a message to stdout when an event is received. For usage information, run
'Bridge_SessionListener.py -h' .
+
+* ExampleSipAuthHook.py
+
+This scripts attaches to the SIP session gateway and challenges for authentication
+using the username 'bob' and the password 'alice'. For usage information, run
+'ExampleSipAuthHook.py -h' .
-----------------------------------------------------------------------
--
asterisk-scf/examples.git
More information about the asterisk-scf-commits
mailing list