[X2Go-Commits] x2gobroker.git - build-main (branch) updated: 0.0.1.0-78-gd4416c7

X2Go dev team git-admin at x2go.org
Sun May 19 13:03:44 CEST 2013


The branch, build-main has been updated
  discards  f6f6b32e0a8eea06cdf1d888941e4b748ac51bb6 (commit)
  discards  1c22ef97db768e352e9b0b6ec4bb3802f2983946 (commit)
  discards  4922dbc886553349ce9f76fbebe4fee2ccc7dc63 (commit)
  discards  1e70ec048687676bd15654ff60aed29f26288d75 (commit)
  discards  692561e8fe83789863ae6a04e6e4a747f859bc03 (commit)
  discards  abc72963617a4c27b376efacbc46cfbe4de4237a (commit)
  discards  7da7e324930cf1e2265672853609746244fa374e (commit)
  discards  710f44fe7f9ff77d0896a250b2de52f2b4cc0a3a (commit)
  discards  9b780d88aafa5432de58ca2c0606fe7a0048b1bc (commit)
  discards  18a92d3014e5060b7fc959518ad822f572e89691 (commit)
  discards  112ebe4f0f5494b18ebda527d6920aa5e1440fae (commit)
  discards  041db4bb343d596e5861c54d80db45ab622cbf9d (commit)
  discards  e6a7f9f6dec729233e9aa9f1c9ea4978f06f14e0 (commit)
  discards  26d9b1918943c437fbe3e88f651c66fcb2fc7443 (commit)
  discards  1eedf8bc5e22bf396159d00c6dfd18837e29b941 (commit)
  discards  6d488f01366743827558f8cb208b687207d19de7 (commit)
  discards  77c3a2cea7defd21f3af1edc17f29095b3329ef3 (commit)
  discards  bc41924e2929edfe733ba6d9c9646bfeafa7e511 (commit)
  discards  d9edb503e4b28793fb7b7a3848d24bd6df97fa7f (commit)
  discards  27257d282bf6be8bc7d511824283725df634e045 (commit)
  discards  ace673b6219a685077cc15370395190190ba94c1 (commit)
  discards  a007b3e4f9a645c500c033cf6517542d76d6ad0b (commit)
  discards  d459b5ba3c9024cdc56f3af809f364e27ae8453d (commit)
  discards  cd4bad34085b1f22461b25d3590e93b9d77961b1 (commit)
  discards  087c7780d2eeed2810160c79da7cc3a8c62526b8 (commit)
  discards  5d0e87dc21b65c1ddbc3b9de20d6cd9424625e1e (commit)
  discards  5c84b2ac39cabc4f1ae3051fb220c7f65149d561 (commit)
  discards  8cf905c4399d9737cb613acadaa1d6f6d5683f96 (commit)
  discards  78623cec81402fea0f8e36c01fa15261cd1abba3 (commit)
  discards  3af1d8018a7df5db02d46162b08a66cb6d6ddb11 (commit)
  discards  f4ff0ae355ed058f2fdf8e2267cb3ad7812e097c (commit)
  discards  ca48248f7042f81ec2ba9d25907e0d2545007cc6 (commit)
  discards  620140e5cc38e3f84d014042f54c1235347c4923 (commit)
  discards  e4f4a3be711ee2246032b555da42151dfb232af8 (commit)
  discards  0318f27362e56d6587c82d63926cfe677eaccffd (commit)
  discards  bf9ca01cd94266ee47c6ce056a702a942803124c (commit)
  discards  d6e31e806eeb92472e1eaa2c87c3bae3f5d94dc4 (commit)
  discards  ad12802c5aa0c60a2586d5874f638ef1dd7dc8e3 (commit)
  discards  11cc12dd2fe8c0d0e171bb79e8272c7ee60528c9 (commit)
  discards  26dd0105562fbdebc0662b8f86d78a3a8d71c2fa (commit)
  discards  ca33ea93056615c370586d9f1054b29695b56393 (commit)
  discards  6089879c268eaafb9cd3bdc76dc9f06346ef592f (commit)
  discards  bff088d523cccbcbe5c6836eaf61e05bc2145df7 (commit)
  discards  1298863cc62b9167f4a270cf5262d8d234fe56b0 (commit)
       via  d4416c7a93cc6cf8b85fa0f98987699e480c0b41 (commit)
       via  5ea2e5f75a03fa58146c25889608deeaabbee5d5 (commit)
       via  a7da5f74195abfd7b40f4fbf902f4329186ac17b (commit)
       via  a53f3b66d7f514295bd071871211ec82ad4d1147 (commit)
       via  cd6780f54b5ad4df8e3d83d7ecdfaca58d78cfdd (commit)
       via  f0ad3869aa976cfef4472c0a1137d01ea956fce0 (commit)
       via  85ffd94dae231162d20c38c9c7a2c7dab99b6e0c (commit)
       via  ad71a6de92eb31ef0f3a3aae4aec16067573c35b (commit)
       via  81642aaf1a9a448bb00906fc6d57d2a324ae5a59 (commit)
       via  31a93ead8a1fada72e134a8f9e48e6f8c30beb05 (commit)
       via  87e42dc92a6aa376c672c903ccaa59284718d0e9 (commit)
       via  9472cbc3b80ab0349feb5a020756c8bce9489be1 (commit)
       via  2a8a92b9a806b0bddee8893db10871941d0d3827 (commit)
       via  c03f569500958547e14dc7f17b3fed546be79777 (commit)
       via  4595a5dc63ae5a80d2c210ba4469390acb11fd2f (commit)
       via  23c88c33da8d3294bb74e854bc6f883ea63b7c9a (commit)
       via  ad4f3af5a457d985aba08002d37bc3941528eba9 (commit)
       via  f179ced3058fdf13019f66c3a2123025800f9dbd (commit)
       via  0e636fb79ad5035c932a21fa52c5223d31aee9b5 (commit)
       via  b4c67f1174da40d1ed53b64f994a866de1de7606 (commit)
       via  e34d0691e5830ab901da3ba0998a73e5f7fb0c31 (commit)
       via  2b634eef55315243b77ad07cd81d2c8e722e2542 (commit)
       via  3d70999fd322b0d4ae0724ea9e6d7a2598286e57 (commit)
       via  b38f22b7ebbcbf943f7a554d5ee1f0a5c08c335b (commit)
       via  a23c56abf93b0f641589132105e52e9105cbbab8 (commit)
       via  e0ab1116e6f665674ac57a2b80a2be5f640bd593 (commit)
       via  3d553c0c30e15dbe643c9208d857d387bbd9c7d4 (commit)
       via  f4fc469442dcdb43047f2165ccda4f6c0e25df4e (commit)
       via  e115d0666c21ebecd8c7c8549192ffe4bbf02071 (commit)
       via  75f4cb8a59b9e8591aaed2f92dce4a6781ff8299 (commit)
       via  688b8ea22350b99660413a3333926bfa81d19609 (commit)
       via  dc9eb932798d2679780d1343e1ab3ea4fa7386cc (commit)
       via  b487008f79052cc4da52e7e6093ff99a3d1a80af (commit)
       via  8c27295aedf58ab801edad949dde0ca121eb5f18 (commit)
       via  e1c90224f4e364345e9e76aa3db086988e03a056 (commit)
       via  e6bbdb5bb97de5ee01cd9e659ba43f1dde5c7376 (commit)
       via  6ab6f454d8976ab5c42937e44e81ab2bf570f9e6 (commit)
       via  e19494d1cf6fa3f04f946d50196c3a5123835ba2 (commit)
       via  c09f1966fdde02156a5371b2a909b13b3620dc4f (commit)
       via  5b884430d73643ab81fc0aac11f22e52be8706ee (commit)
       via  3fd14f204a2f570d88c95b455fdcffd57b99ed4e (commit)
       via  870b98422e7e2ceff6e2f2c5f90172e63109b75a (commit)
       via  8546ee4fcd4c094b1a1a7a04ba81ed549055920e (commit)
       via  b57e5c7d732c94056ded5046bd2f475074a3d933 (commit)
       via  ac6024e007f2a0f5a63d82513a7370c72378925a (commit)
       via  bf62865e24d79f1c697c2ff2d353c52001e41041 (commit)
       via  3366ab187d971a0de2bf2f13d33c02e24ce77ed5 (commit)
       via  87e0d33ee82cbbc48ff738d5fa33a49a7b9f904f (commit)
       via  f5c77c7654c180c9f55f175b9dc2a611a4a26a1c (commit)
       via  12ace4ff77e043274948ada6f13ffedc5e561d26 (commit)
       via  d3a17b136b23755840e13547152011193c2febe9 (commit)
       via  cbe481e17814bf14404b4adc95fc6ae53efa52a1 (commit)
       via  5f08ed5c43d6c8c96515f5628d3a60cb0c386ab7 (commit)
       via  a505addd53fee98a0445278c838447b4b20e3d1b (commit)
       via  9ec668c96ad7a70e1024194c3f7eae7ea3e9e6ba (commit)
       via  b075080bcd2a1510f4ac820f752580000712e509 (commit)
       via  d76dcd7f32e82452e74e167ff9de4020403ecb84 (commit)
       via  b24fe4ed32dc3f3066f20b4f93f1df5bbbdaa778 (commit)
       via  b440438bdbdcdd248957f6e2e0cfe4deaab895b5 (commit)
       via  830502fcaa69733d4c5f6561d335a5f7032c4baa (commit)
       via  317325dd112ba89775ff81984ef985f061a81b21 (commit)
       via  2cee942cb70599dd79ef3cf7f93fc2aeaa950472 (commit)
       via  0beb6626be0dd1c9d0363435268def8df85f1380 (commit)
       via  d14d83a114d66019fe9fa031f3a367c65224cf6a (commit)
       via  8130c9d12e3447fda3064b4b3f1ba0aef1015341 (commit)
       via  00fb61c3429809f7511f7bda5667a77facd96918 (commit)
       via  e341bd86111730b2919697a74ac18d759d2a9e74 (commit)
       via  c9c92dbff6b4e9ee872eb738121dbd51da94d329 (commit)
       via  1734e9987eebeaf7574c42c28b92f010fb827008 (commit)
       via  cd9500b7a1d12cd973af7726dbead83b79bc8581 (commit)
       via  890debb62b31a29ed482d392e7d276c5d9936d90 (commit)
       via  aea8e30472982caf3be18c73e3175becfc6d6b4a (commit)
       via  19582aa37e0e3cab202c43cd7497d791cbeee1b3 (commit)

This update added new revisions after undoing existing revisions.  That is
to say, the old revision is not a strict subset of the new revision.  This
situation occurs when you --force push a change and generate a repository
containing something like this:

 * -- * -- B -- O -- O -- O (f6f6b32e0a8eea06cdf1d888941e4b748ac51bb6)
            \
             N -- N -- N (d4416c7a93cc6cf8b85fa0f98987699e480c0b41)

When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
-----------------------------------------------------------------------

Summary of changes:
 etc/x2gobroker.conf                         |    5 +
 sbin/x2gobroker                             |    2 +
 x2gobroker/brokers/base_broker.py           |    3 +
 x2gobroker/defaults.py                      |    2 +
 x2gobroker/tests/test_broker_base.py        |    1 +
 x2gobroker/tests/test_broker_zeroconf.py    |    2 -
 x2gobroker/tests/test_web_plain_zeroconf.py |    9 +-
 x2gobroker/tests/test_web_uccs_zeroconf.py  |   80 +++++++++
 x2gobroker/uccsjson.py                      |  245 +++++++++++++++++++++++++++
 x2gobroker/web/uccs.py                      |  165 ++++++++++++++++++
 10 files changed, 507 insertions(+), 7 deletions(-)
 create mode 100644 x2gobroker/tests/test_web_uccs_zeroconf.py
 create mode 100644 x2gobroker/uccsjson.py
 create mode 100644 x2gobroker/web/uccs.py

The diff of changes is:
diff --git a/etc/x2gobroker.conf b/etc/x2gobroker.conf
index 24a530f..cf544bb 100644
--- a/etc/x2gobroker.conf
+++ b/etc/x2gobroker.conf
@@ -71,6 +71,11 @@
 # enable {base_url}/plain/
 #enable-plain-output = true
 
+# enable {base_url}/uccs/
+#enable-uccs-output = false
+# use this URL base to create URL field in UCCS-style JSON output
+#my-uccs-url-base = http://localhost:8080/
+
 # enable {base_url}/json/ (THIS IS FUTURE, mg-20121129)
 #enable-json-output = false
 
diff --git a/sbin/x2gobroker b/sbin/x2gobroker
index c23e195..aff9f8d 100755
--- a/sbin/x2gobroker
+++ b/sbin/x2gobroker
@@ -107,12 +107,14 @@ if __name__ == "__main__":
 
 # import classes serving the different web.py URLs
 import x2gobroker.web.plain
+import x2gobroker.web.uccs
 #import x2gobroker.web.json
 #import x2gobroker.web.html
 import x2gobroker.web.extras
 
 # define the web.py URLs
 urls = ( ('/plain/(.*)', x2gobroker.web.plain.X2GoBrokerWeb,),
+         ('/uccs/(.*)', x2gobroker.web.uccs.X2GoBrokerWeb,),
 #        ('/json/(.*)', x2gobroker.web.json.X2GoBrokerWeb,),
 #        ('/html/(.*)', x2gobroker.web.html.X2GoBrokerWeb,),
          ('/pubkeys(|/)$', x2gobroker.web.extras.X2GoBrokerPubKeyService,),
diff --git a/x2gobroker/brokers/base_broker.py b/x2gobroker/brokers/base_broker.py
index 2ce0ba4..3cac792 100644
--- a/x2gobroker/brokers/base_broker.py
+++ b/x2gobroker/brokers/base_broker.py
@@ -731,6 +731,9 @@ class X2GoBroker(object):
 
         access = False
         access = self._do_authenticate(username=username, password=password)
+        if not access and "@" in username:
+            _username = username.split('@')[0]
+            access = self._do_authenticate(username=_username, password=password)
         logger_broker.debug('base_broker.X2GoBroker.check_access(): result of authentication check is: {access}'.format(access=access))
 
         ### HANDLING OF DYNAMIC AUTHENTICATION ID HASHES
diff --git a/x2gobroker/defaults.py b/x2gobroker/defaults.py
index 7961f7d..f46e1b8 100644
--- a/x2gobroker/defaults.py
+++ b/x2gobroker/defaults.py
@@ -118,6 +118,8 @@ X2GOBROKER_CONFIG_DEFAULTS = {
         u'use-static-cookie': False,
         u'my-cookie': uuid.uuid4(),
         u'enable-plain-output': True,
+        u'enable-uccs-output': False,
+        u'my-uccs-url-base': 'http://localhost:8080/',
         u'enable-json-output': False,
         u'enable-html-output':  False,
         u'default-auth-mech': u'pam',
diff --git a/x2gobroker/tests/test_broker_base.py b/x2gobroker/tests/test_broker_base.py
index ff06542..1371724 100644
--- a/x2gobroker/tests/test_broker_base.py
+++ b/x2gobroker/tests/test_broker_base.py
@@ -307,6 +307,7 @@ check-credentials = false
             'pack': '16m-jpeg',
             'user': '',
             'host': [u'localhost'],
+            'directrdp': False,
         }
         _profile = base_backend.get_profile_defaults()
         self.assertEqual(len(_expected_profile.keys()), len(_profile.keys()))
diff --git a/x2gobroker/tests/test_broker_zeroconf.py b/x2gobroker/tests/test_broker_zeroconf.py
index 1a42278..485e8bd 100644
--- a/x2gobroker/tests/test_broker_zeroconf.py
+++ b/x2gobroker/tests/test_broker_zeroconf.py
@@ -75,8 +75,6 @@ class TestX2GoBrokerBackendZeroconf(unittest.TestCase):
         _test_profiles = {
             _key: list_of_profiles['unittest']
         }
-        for key in _profiles[_key]:
-            print key, _profiles[_key][key], _test_profiles[_key][key]
         self.assertEqual(_profiles, _test_profiles)
 
     ### TEST: select_profile() method
diff --git a/x2gobroker/tests/test_web_plain_zeroconf.py b/x2gobroker/tests/test_web_plain_zeroconf.py
index dad829b..8b98daf 100644
--- a/x2gobroker/tests/test_web_plain_zeroconf.py
+++ b/x2gobroker/tests/test_web_plain_zeroconf.py
@@ -52,11 +52,10 @@ desktop-shell = KDE
         r.mustcontain('START_USER_SESSIONS')
         r.mustcontain('command=KDE')
         r.mustcontain('END_USER_SESSIONS')
-        # FIXME: get html tags out of the text/plain web renderer, needs patching of X2Go Client
-        #r.mustcontain(no='<BR>',)
-        #r.mustcontain(no='<br>',)
-        #r.mustcontain(no='<BR />', )
-        #r.mustcontain(no='<br />', )
+        r.mustcontain(no='<BR>',)
+        r.mustcontain(no='<br>',)
+        r.mustcontain(no='<BR />', )
+        r.mustcontain(no='<br />', )
         tf.close()
         _config = """
 [zeroconf]
diff --git a/x2gobroker/tests/test_web_uccs_zeroconf.py b/x2gobroker/tests/test_web_uccs_zeroconf.py
new file mode 100644
index 0000000..6c5d2b5
--- /dev/null
+++ b/x2gobroker/tests/test_web_uccs_zeroconf.py
@@ -0,0 +1,80 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2012 by Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
+#
+# X2Go Session Broker is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# X2Go Session Broker 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program; if not, write to the
+# Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+
+import unittest
+import tempfile
+from paste.fixture import TestApp
+from nose.tools import *
+import tornado.wsgi
+import json
+
+# Python X2GoBroker modules
+import x2gobroker.defaults
+import x2gobroker.web.uccs
+
+urls = ( ('/uccs/(.*)', x2gobroker.web.uccs.X2GoBrokerWeb,) ,)
+application = tornado.wsgi.WSGIApplication(urls)
+
+class TestX2GoBrokerWebUccsZeroConf(unittest.TestCase):
+
+    ### TEST TASK: listsessions (you can influence the session command via the X2Go Broker's configurationfile)
+
+    def test_listsessions(self):
+        _expected_result = {
+            u'URL': u'http://localhost:8080/uccs/zeroconf',
+            u'AdditionalManagementServers': [],
+            u'Name': u'X2Go Session Broker',
+            u'RemoteDesktopServers': [
+                {
+                    u'Username': u'',
+                    u'Protocol': u'x2go',
+                    u'Name': u'LOCALHOST',
+                    u'URL': u'localhost:22',
+                    u'SessionTypeRequired': True,
+                    u'Password': None
+                },
+            ],
+        }
+        _config = """
+[global]
+enable-uccs-output=true
+
+[zeroconf]
+enable = true
+auth-mech = testsuite
+desktop-shell = KDE
+"""
+        tf = tempfile.NamedTemporaryFile()
+        print >> tf, _config
+        tf.seek(0)
+        x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name
+        testApp = TestApp(application)
+        r = testApp.get('/uccs/zeroconf/', params={'user': 'test', 'password': 'sweet',  'task': 'listsessions', }, expect_errors=True)
+        assert_equal(r.status, 200)
+        body = r.normal_body
+        result = json.loads(body)
+        self.assertEqual(_expected_result, result)
+        tf.close()
+
+
+def test_suite():
+    from unittest import TestSuite, makeSuite
+    suite = TestSuite()
+    suite.addTest(makeSuite(TestX2GoBrokerWebUccsZeroConf))
+    return suite
diff --git a/x2gobroker/uccsjson.py b/x2gobroker/uccsjson.py
new file mode 100644
index 0000000..ca61dab
--- /dev/null
+++ b/x2gobroker/uccsjson.py
@@ -0,0 +1,245 @@
+# Copyright (C) 2012 by Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
+# Copyright (C) 2012 by Oleksandr Shneyder <oleksandr.shneyder at obviously-nice.de>
+# Copyright (C) 2012 by Heinz-Markus Graesing <heinz-m.graesing at obviously-nice.de>
+#
+# X2Go Session Broker is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# X2Go Session Broker 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program; if not, write to the
+# Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+
+import json
+
+def convert_to_builtin_type(obj):
+    """\
+    Helper function for converting Python objects to dictionaries.
+    Used for doing JSON dumps.
+
+    """
+    d = { }
+    d.update(obj.__dict__)
+    return d
+
+class ManagementServer():
+    """\
+    Base class for generating UCCS compatible JSON object.
+
+    """
+    def __init__(self, url, name):
+        """\
+        Initializ instance.
+
+        @param url: URL of the UCCS broker server
+        @type url: C{unicode}
+        @param name: human-readable, descriptive server name
+        @type name: C{unicode}
+
+        """
+        self.RemoteDesktopServers = []
+        self.AdditionalManagementServers = []
+        self.URL = unicode(url)
+        self.Name = unicode(name)
+
+    def set_default(self, ts_name):
+        """\
+        Define the default (terminal) server instance.
+
+        @param ts_name: name of the terminal server that is to be set as default
+        @type ts_name: C{unicode}
+
+        """
+        if isinstance(ts_name, str):
+            self.DefaultServer = unicode(ts_name)
+        elif isinstance(domain, unicode):
+            self.DefaultServer = ts_name
+        else:
+            raise TypeError("set_default expects a string argument")
+
+    def add_terminalserver(self, server):
+        """\
+        Add a terminal server to this management server object.
+
+        @param server: instance of class L{RDPServer} or L{X2GoServer}.
+        @type server: C{obj}
+
+        """
+        self.RemoteDesktopServers.append(server)
+
+    # NOT USED!!!
+    #def add_additional_management_server(self, amserver):
+    #    if isinstance(amserver, AdditionalManagementServer):
+    #        self.AdditionalManagementServers.append(amserver)
+    #    else:
+    #        raise TypeError("add_additional_management_server expects a "\
+    #            "AdditionalManagementServer argument")
+
+    def toJson(self):
+        """\
+        Dump this instance as JSON object.
+
+        """
+        return json.dumps(self, default=convert_to_builtin_type, sort_keys=True, indent=4)
+
+
+# NOT USED!!!
+#class AdditionalManagementServer():
+#    def __init__(self, url, name):
+#        self.URL = url
+#        self.Name = name
+
+
+class RDPServer():
+    """\
+    Instantiate a UCCS compatible RDP server session profile object.
+
+    """
+    def __init__(self, host, name, username=None, password=None):
+        """\
+        @param host: hostname of RDP server host
+        @type host: C{unicode}
+        @param name: session profile name
+        @type name: C{unicode}
+        @param username: username to be used for login
+        @type username: C{unicode}
+        @param password: password to be used for login
+        @type password: C{unicode}
+
+        """
+        self.URL = unicode(host)
+        self.Name = unicode(name)
+        self.Protocol = u'freerdp'
+        self.DomainRequired = True
+        self.Username = unicode(username)
+        self.Password = unicode(password)
+
+    def set_domain(self, domain):
+        """\
+        Set the domain for this RDP server.
+
+        @param domain: the domain name to be set
+        @type domain: C{unicode}
+
+        @raise TypeError: domain has to be C{str} or C{unicode}
+
+        """
+        if isinstance(domain, str):
+            self.WindowsDomain = unicode(domain)
+        elif isinstance(domain, unicode):
+            self.WindowsDomain = domain
+        else:
+            raise TypeError("set_domain() expects a string or unicode argument")
+
+    def toJson(self):
+        """\
+        Dump this instance as JSON object.
+
+        """
+        return json.dumps(self, default=convert_to_builtin_type, sort_keys=True, indent=4)
+
+
+class ICAServer():
+    """\
+    Instantiate a UCCS compatible ICA server session profile object.
+
+    """
+    def __init__(self, host, name, username=None, password=None):
+        """\
+        @param host: hostname of ICA server host
+        @type host: C{unicode}
+        @param name: session profile name
+        @type name: C{unicode}
+        @param username: username to be used for login
+        @type username: C{unicode}
+        @param password: password to be used for login
+        @type password: C{unicode}
+
+        """
+        self.URL = unicode(host)
+        self.Name = unicode(name)
+        self.Protocol = u'ica'
+        self.DomainRequired = unicode(True)
+        self.Username = unicode(username)
+        self.Password = unicode(password)
+
+    def set_domain(self, domain):
+        """\
+        Set the domain for this ICA server.
+
+        @param domain: the domain name to be set
+        @type domain: C{unicode}
+
+        @raise TypeError: domain has to be C{str} or C{unicode}
+
+        """
+        if isinstance(domain, str):
+            self.WindowsDomain = unicode(domain)
+        elif isinstance(domain, unicode):
+            self.WindowsDomain = domain
+        else:
+            raise TypeError("set_domain() expects a string or unicode argument")
+
+    def toJson(self):
+        """\
+        Dump this instance as JSON object.
+
+        """
+        return json.dumps(self, default=convert_to_builtin_type, sort_keys=True, indent=4)
+
+
+class X2GoServer():
+    """\
+    Instantiate a UCCS compatible X2Go Server session profile object.
+
+    """
+    def __init__(self, host, name, username=None, password=None):
+        """\
+        @param host: hostname of X2Go Server host
+        @type host: C{unicode}
+        @param name: session profile name
+        @type name: C{unicode}
+        @param username: username to be used for login
+        @type username: C{unicode}
+        @param password: password to be used for login
+        @type password: C{unicode}
+
+        """
+        self.URL = unicode(host)
+        self.Name = unicode(name)
+        self.Protocol = u'x2go'
+        self.SessionTypeRequired = True
+        self.Username = unicode(username)
+        self.Password = unicode(password)
+
+    def set_session_type(self, session_type):
+        """\
+        Set the session type to be used with this X2Go Server.
+
+        @param session_type: the session type to be set
+        @type session_type: C{unicode}
+
+        @raise TypeError: session_type has to be C{str} or C{unicode}
+
+        """
+        if isinstance(session_type, str):
+            self.SessionType = unicode(session_type)
+        elif isinstance(session_type, unicode):
+            self.SessionType = session_type
+        else:
+            raise TypeError("set_session_type() expects a string or unicode argument")
+
+    def toJson(self):
+        """\
+        Dump this instance as JSON object.
+
+        """
+        return json.dumps(self, default=convert_to_builtin_type, sort_keys=True, indent=4)
+
diff --git a/x2gobroker/web/uccs.py b/x2gobroker/web/uccs.py
new file mode 100644
index 0000000..db59f24
--- /dev/null
+++ b/x2gobroker/web/uccs.py
@@ -0,0 +1,165 @@
+#!/usr/bin/env python
+
+# This file is part of the  X2Go Project - http://www.x2go.org
+# Copyright (C) 2011-2012 by Oleksandr Shneyder <oleksandr.shneyder at obviously-nice.de>
+# Copyright (C) 2011-2012 by Heinz-Markus Graesing <heinz-m.graesing at obviously-nice.de>
+# Copyright (C) 2012 by Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
+#
+# X2Go Session Broker is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# X2Go Session Broker 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program; if not, write to the
+# Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# modules
+import types
+import re
+import base64
+import tornado.web
+from tornado.escape import native_str, parse_qs_bytes
+
+# Python X2Go Broker modules
+import x2gobroker.defaults
+
+from x2gobroker.loggers import logger_broker, logger_error
+import x2gobroker.uccsjson
+
+def require_basic_auth(realm, validate_callback):
+    def require_basic_auth_decorator(handler_class):
+        def wrap_execute(handler_execute):
+            def require_basic_auth(handler, kwargs):
+                def create_auth_header():
+                    handler.set_status(401)
+                    handler.set_header('WWW-Authenticate', 'Basic realm="{realm}"'.format(realm=realm))
+                    handler._transforms = []
+                    handler.finish()
+
+                auth_header = handler.request.headers.get('Authorization')
+                if auth_header is None or not auth_header.startswith('Basic '):
+                    create_auth_header()
+                else:
+                    auth_decoded = base64.decodestring(auth_header[6:])
+                    kwargs['basicauth_user'], kwargs['basicauth_pass'] = [ unicode(s) for s in auth_decoded.split(':', 2) ]
+                    if validate_callback(handler_class, kwargs['basicauth_user'], kwargs['basicauth_pass']):
+                        return True
+                    else:
+                        create_auth_header()
+            def _execute(self, transforms, *args, **kwargs):
+                if not require_basic_auth(self, kwargs):
+                    return False
+                return handler_execute(self, transforms, *args, **kwargs)
+            return _execute
+
+        handler_class._execute = wrap_execute(handler_class._execute)
+        return handler_class
+    return require_basic_auth_decorator
+
+
+def credentials_validate(handler_class, username, password):
+    import x2gobroker.brokers.base_broker
+    # FIXME: with the below hack, the backend broker detection in X2GoBrokerWeb is disabled, only global options
+    #        from x2gobroker.conf are available here...
+    return x2gobroker.brokers.base_broker.X2GoBroker().check_access(username=username, password=password)
+
+
+ at require_basic_auth('Authentication required', credentials_validate)
+class X2GoBrokerWeb(tornado.web.RequestHandler):
+
+    http_header_items = {
+        'Content-Type': 'text/plain; charset=utf-8',
+        'Expires': '+1h',
+    }
+
+    def _gen_http_header(self):
+
+        for http_header_item in self.http_header_items.keys():
+            self.set_header(http_header_item, self.http_header_items[http_header_item])
+
+    def get(self, backend, basicauth_user, basicauth_pass):
+        if x2gobroker.defaults.X2GOBROKER_DEBUG:
+            self._gen_http_header()
+            logger_broker.warn('GET http request detected, if unwanted: disable X2GOBROKER_DEBUG')
+            return self.head(backend, basicauth_user, basicauth_pass)
+        raise tornado.web.HTTPError(404)
+
+    def head(self, backend, basicauth_user, basicauth_pass):
+
+        if not backend:
+            backend = x2gobroker.defaults.X2GOBROKER_DEFAULT_BACKEND
+        else:
+            backend = backend.rstrip('/')
+
+        api_version = 4
+        if re.match('.*/api/[0-9].*', backend):
+            # get the first and the third item as backend, api_version
+            backend, api_version = backend.split('/')[:3:2]
+            api_version = int(api_version)
+
+        try:
+            # dynamically detect broker backend from given URL
+            exec("import x2gobroker.brokers.{backend}_broker".format(backend=backend))
+            exec("self.broker_backend = x2gobroker.brokers.{backend}_broker.X2GoBroker()".format(backend=backend))
+        except ImportError:
+            # throw a 404 if the backend does not exist
+            raise tornado.web.HTTPError(404)
+
+        global_config = self.broker_backend.get_global_config()
+
+        # if the broker backend is disabled in the configuration, pretend to have nothing on offer
+        if not self.broker_backend.is_enabled():
+            raise tornado.web.HTTPError(404)
+
+        # set the client address for the broker backend
+        ip = self.request.remote_ip
+        if ip:
+            logger_broker.info('client address is {address}'.format(address=ip))
+            self.broker_backend.set_client_address(ip)
+        elif not x2gobroker.defaults.X2GOBROKER_DEBUG:
+            # if the client IP is not set, we pretend to have nothing on offer
+            logger_error.error('client could not provide an IP address, pretending: 404 Not Found')
+            raise tornado.web.HTTPError(404)
+
+        username, password = basicauth_user, basicauth_pass
+        cookie = ''
+
+        output = ''
+
+        logger_broker.debug ('Authenticated as username: {username}, with password: <hidden>'.format(username=username))
+
+        ###
+        ### CONFIRM SUCCESSFUL AUTHENTICATION FIRST
+        ###
+
+        profiles = self.broker_backend.list_profiles(username)
+        urlbase = self.broker_backend.get_global_value('my-uccs-url-base').rstrip('/')
+        ms = x2gobroker.uccsjson.ManagementServer('{urlbase}/uccs/{backend}'.format(urlbase=urlbase, backend=backend), 'X2Go Session Broker')
+
+        profile_ids = profiles.keys()
+        profile_ids.sort()
+
+        for profile_id in profile_ids:
+
+            if profiles[profile_id][u'directrdp']:
+                pass
+            else:
+                ts = x2gobroker.uccsjson.X2GoServer(
+                        host='{hostname}:{port}'.format(hostname=profiles[profile_id][u'host'], port=profiles[profile_id][u'sshport']),
+                        name=profiles[profile_id][u'name'],
+                        username=profiles[profile_id][u'user'],
+                )
+            ms.add_terminalserver(ts)
+
+        output += ms.toJson()
+
+        self.write(output)
+        return
+


hooks/post-receive
-- 
x2gobroker.git (HTTP(S) Session broker for X2Go)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "x2gobroker.git" (HTTP(S) Session broker for X2Go).




More information about the x2go-commits mailing list