Quelques exemples de code SOAP…
authorProgfou <jean-christophe.andre@auf.org>
Mon, 9 Sep 2013 18:36:47 +0000 (14:36 -0400)
committerProgfou <jean-christophe.andre@auf.org>
Mon, 9 Sep 2013 18:36:47 +0000 (14:36 -0400)
soap/soap-client.php [new file with mode: 0644]
soap/soap-server.py [new file with mode: 0644]

diff --git a/soap/soap-client.php b/soap/soap-client.php
new file mode 100644 (file)
index 0000000..1a91290
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+# Debian-Depends: php-soap # pour SOAP
+# Debian-Depends: php[45]-curl # pour HTTPS
+include_once("SOAP/Client.php");
+$params = Array("username"=>'test', "password"=>'toto');
+$soapclient = new SOAP_Client("https://example.org/soap");
+$ret = $soapclient->call('crypt6', $params);
+if (PEAR::isError($ret))
+       print("Error: " . $ret->getMessage() . "\n");
+else
+       print("Ok: " . $ret . "\n");
+?>
diff --git a/soap/soap-server.py b/soap/soap-server.py
new file mode 100644 (file)
index 0000000..6546685
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# Debian-Depends: python-soaplib
+# Debian-Suggests: python-wsgiref
+from soaplib.wsgi_soap import SimpleWSGISoapApp
+from soaplib.service import soapmethod
+from soaplib.serializers.primitive import String, Integer, Array
+from random import choice
+from crypt import crypt
+
+class CryptService(SimpleWSGISoapApp):
+
+    def make_salt(self, count=16):
+        choices = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./'
+        return ''.join([choice(choices) for x in range(count)])
+
+    def crypt(self, username, password, method):
+        return crypt(password, '$%s$%s$' % (method, self.make_salt()) )
+
+    @soapmethod(String, String, _returns=String)
+    def crypt1(self, username, password):
+        """
+        GNU libc's crypt function, method 1 (SHA-160).
+        @param username the username
+        @param password the password
+        @return the encrypted password
+        """
+        return self.crypt(username, password, '1')
+
+    @soapmethod(String, String, _returns=String)
+    def crypt5(self, username, password):
+        """
+        GNU libc's crypt function, method 5 (SHA-256).
+        @param username the username
+        @param password the password
+        @return the encrypted password
+        """
+        return self.crypt(username, password, '5')
+
+    @soapmethod(String, String, _returns=String)
+    def crypt6(self, username, password):
+        """
+        GNU libc's crypt function, method 6 (SHA-512).
+        @param username the username
+        @param password the password
+        @return the encrypted password
+        """
+        return self.crypt(username, password, '6')
+
+application = CryptService()
+
+if __name__=='__main__':
+    from wsgiref.simple_server import make_server
+    server = make_server('', 8000, application)
+    server.serve_forever()