[X2go-Commits] x2gobroker.git - master (branch) updated: 0.0.0.5-70-gbea0b74

X2Go dev team git-admin at x2go.org
Wed Mar 6 11:45:42 CET 2013


The branch, master has been updated
       via  bea0b745fc4d5842b715684d00b8fea7ea79a5f8 (commit)
       via  620cf778695448fb38394e5b476974aa1815c639 (commit)
       via  cc0ae3ddb38a1212ab5e63715344e7befdc4b544 (commit)
       via  aa84ed46e7d201c60b72b70b2be26c02bdbcecee (commit)
       via  d1b123d29807d11997c79697ac7b998264ed2fea (commit)
       via  83b347f272687471a93d46449704893256ca88de (commit)
       via  1333f57a70b1c03a127d6995cdc0ddd171c19b84 (commit)
       via  f395518f6ce01794e96aae35014225d29c594505 (commit)
       via  eb322fcd5727c3e9d6f80da831f9e0f177f589c9 (commit)
       via  dcdbce376f33afe485535d4bca6cb39f06b91c12 (commit)
       via  ea189372b4d143c6937ffb5a682a9ba0c3eb281c (commit)
       via  63ca4fa3a6bccff85f1ebc51548cd8a1b95c62af (commit)
       via  f744b3940f0b8cf705b9add326ed67703ee07243 (commit)
       via  ff5809f40d1735d77dc0f97936934c0f9927f433 (commit)
       via  30c5d7913cd73b6172673983ee37160f3a5c9f71 (commit)
       via  e9fd1798964afb34fdd2d11a1ec5b0d23628ff65 (commit)
       via  93a9f3f41318e472eb0ac964126a7189f4c80897 (commit)
       via  4a05d3411c0da68f013201e68b396f77a082344e (commit)
       via  01f3a1d9c79f9bf60a28e1c20250afdb5abc09f0 (commit)
       via  391fa36de255a6e17e817fe7127d85f81db015ee (commit)
       via  b6a0588c151b322dfcf2418b6d6df289946710d1 (commit)
       via  9fcd2186c96f07d41302fae68112e9b3dd7fb66e (commit)
      from  838bdf9fccfd43bae4b23ccc141d75fccaeaa7de (commit)

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:
 debian/changelog                            |    8 +++-
 debian/control                              |    4 +-
 lib/x2gobroker-agent.pl                     |    2 +-
 sbin/x2gobroker                             |   54 ++++++++++++++----------
 x2gobroker/agent.py                         |   12 ++++--
 x2gobroker/authmechs/pam_authmech.py        |   17 ++++++--
 x2gobroker/brokers/base_broker.py           |   18 ++++----
 x2gobroker/loggers.py                       |   19 +++++++++
 x2gobroker/tests/test_web_plain_base.py     |   17 ++++----
 x2gobroker/tests/test_web_plain_zeroconf.py |   14 +++----
 x2gobroker/web/extras.py                    |    9 ++--
 x2gobroker/web/html.py                      |   45 +++++++++-----------
 x2gobroker/web/json.py                      |    4 +-
 x2gobroker/web/plain.py                     |   60 ++++++++++++++-------------
 14 files changed, 165 insertions(+), 118 deletions(-)

The diff of changes is:
diff --git a/debian/changelog b/debian/changelog
index 57c160d..38548f4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,7 +4,13 @@ x2gobroker (0.0.0.6-0~x2go1) UNRELEASED; urgency=low
   * New upstream version (0.0.0.6):
     - Rewrite empty user parameter in session profile. Fill in
       the UID that has been used for broker authentication.
-    - Implement session autologin feature.
+    - Implement session autologin feature. (Fixes: #134).
+    - If X2Go Session Broker's PAM Auth Service is not available, try to
+      fallback to direct PAM authentication (only works if x2gobroker
+      runs as super-user root).
+    - Switch from webpy to using tornado as http engine.
+    - Divert tornado log requests into the broker's logger instances.
+    - Add workaround to handle bug #138 in x2goclient.
   * /debian/*.default:
     - Be more explanatory about the X2GOBROKER_DEBUG option and allow
       to enable debug mode for the different services independently.
diff --git a/debian/control b/debian/control
index 38cfc6b..ece5439 100644
--- a/debian/control
+++ b/debian/control
@@ -22,7 +22,7 @@ Depends:
  python,
  python-argparse,
  python-setproctitle,
- python-webpy (>= 1:0.37),
+ python-tornado,
  python-x2gobroker (>= ${source:Version}), python-x2gobroker (<< ${source:Version}.1~),
 Suggests:
  apache2 | httpd,
@@ -150,7 +150,7 @@ Depends:
  ${python:Depends},
  python-pampy,
  python-netaddr,
- python-webpy (>= 1:0.37),
+ python-tornado,
  python-paramiko,
 Suggests:
  apache2 | httpd,
diff --git a/lib/x2gobroker-agent.pl b/lib/x2gobroker-agent.pl
index 52a26d5..12f38d2 100755
--- a/lib/x2gobroker-agent.pl
+++ b/lib/x2gobroker-agent.pl
@@ -88,7 +88,7 @@ sub DelAuthKey
 	{
 		$authkeyfile = "$home/$authkeyfile";
 	}
-	system("su - $uid -c \"sed -e s\!'$pubkey\\n'\!''\! -e '/^\$/d' -i $authkeyfile\" 1>/dev/null 2>/dev/null");
+	system("su - $uid -c \"sed -e s\!'$pubkey'\!''\! -e '/^\$/d' -i $authkeyfile\" 1>/dev/null 2>/dev/null");
 }
 
 $< = $>;
diff --git a/sbin/x2gobroker b/sbin/x2gobroker
index fb6d052..3951539 100755
--- a/sbin/x2gobroker
+++ b/sbin/x2gobroker
@@ -27,8 +27,9 @@ import argparse
 import socket
 import logging
 import thread
-import web
-from web.wsgiserver import CherryPyWSGIServer
+import tornado.web
+import tornado.httpserver
+import tornado.ioloop
 
 try:
     import x2gobroker.defaults
@@ -38,7 +39,7 @@ except ImportError:
 
 from x2gobroker import __VERSION__
 from x2gobroker import __AUTHOR__
-from x2gobroker.loggers import logger_broker, logger_access, logger_error
+from x2gobroker.loggers import logger_broker, logger_access, logger_error, tornado_log_request
 
 # raise log level to DEBUG if requested...
 if x2gobroker.defaults.X2GOBROKER_DEBUG and not x2gobroker.defaults.X2GOBROKER_TESTSUITE:
@@ -97,14 +98,15 @@ if __name__ == "__main__":
         x2gobroker.defaults.X2GOBROKER_DEBUG = cmdline_args.debug
 
     # some people just give the port but prepend a colon, webpy does not like this, so we strip if off
+    cmdline_args.bind = cmdline_args.bind.lstrip('*')
     cmdline_args.bind = cmdline_args.bind.lstrip(':')
 
-    # tweak cmdline args so that they become suitable for the web.py framework
-    if len(sys.argv) <= 1:
-        sys.argv.append('')
-        sys.argv.append('')
-    sys.argv[1] = cmdline_args.bind
-    sys.argv[2:] = []
+    if ':' in cmdline_args.bind:
+        bind_address, bind_port = cmdline_args.bind.split(':')[0:2]
+        bind_port = int(bind_port)
+    else:
+        bind_address = None
+        bind_port = int(cmdline_args.bind)
 
 # import classes serving the different web.py URLs
 import x2gobroker.web.plain
@@ -112,25 +114,33 @@ import x2gobroker.web.plain
 #import x2gobroker.web.html
 import x2gobroker.web.extras
 
-# switch on https:// mode
-if x2gobroker.defaults.X2GOBROKER_SSL_CERTFILE and x2gobroker.defaults.X2GOBROKER_SSL_KEYFILE:
-    CherryPyWSGIServer.ssl_certificate = x2gobroker.defaults.X2GOBROKER_SSL_CERTFILE
-    CherryPyWSGIServer.ssl_private_key = x2gobroker.defaults.X2GOBROKER_SSL_KEYFILE
-
 # define the web.py URLs
-urls = ( '/plain/(.*)', 'x2gobroker.web.plain.X2GoBrokerWeb',
-#         '/json/(.*)', 'x2gobroker.web.json.X2GoBrokerWeb',
-#         '/html/(.*)', 'x2gobroker.web.html.X2GoBrokerWeb',
-          '/pubkeys/', 'x2gobroker.web.extras.X2GoBrokerPubKeyService',
+urls = ( ('/plain/(.*)', x2gobroker.web.plain.X2GoBrokerWeb,),
+#        ('/json/(.*)', x2gobroker.web.json.X2GoBrokerWeb,),
+#        ('/html/(.*)', x2gobroker.web.html.X2GoBrokerWeb,),
+         ('/pubkeys/', x2gobroker.web.extras.X2GoBrokerPubKeyService,),
        )
 
-app = web.application(urls, globals(), autoreload=False)
-app.internalerror = web.debugerror
-application = app.wsgifunc()
+settings = {
+    'log_function': tornado_log_request,
+}
+application = tornado.web.Application(urls, **settings)
 
 # run the web.py standalone daemon...
 if __name__ == "__main__":
     try:
-        thread.start_new_thread(app.run(), ())
+        if x2gobroker.defaults.X2GOBROKER_SSL_CERTFILE and x2gobroker.defaults.X2GOBROKER_SSL_KEYFILE:
+            # switch on https:// mode
+            http_server = tornado.httpserver.HTTPServer(application,
+                                                        ssl_options={
+                                                            "certfile": x2gobroker.defaults.X2GOBROKER_SSL_CERTFILE,
+                                                            "keyfile": x2gobroker.defaults.X2GOBROKER_SSL_KEYFILE,
+                                                        },
+            )
+        else:
+            # run without https
+            http_server = tornado.httpserver.HTTPServer(application)
+        http_server.listen(bind_port, address=bind_address)
+        tornado.ioloop.IOLoop.instance().start()
     except socket.error, e:
         print (e)
diff --git a/x2gobroker/agent.py b/x2gobroker/agent.py
index b32489a..9b63f00 100644
--- a/x2gobroker/agent.py
+++ b/x2gobroker/agent.py
@@ -44,7 +44,10 @@ class delayed_execution(threading.Thread):
         self.start()
 
     def run(self):
-        time.sleep(self.delay)
+        i = 0
+        while i < self.delay:
+            time.sleep(1)
+            i += 1
         self.agent_func(**self.kwargs)
 
 
@@ -106,7 +109,10 @@ def call_remote_broker_agent(username, mode, cmdline_args=[], remote_agent=None)
 
     remote_username = x2gobroker.defaults.X2GOBROKER_AGENT_USER
     remote_hostname = remote_agent[u'hostname']
-    remote_port = int(remote_agent[u'port'])
+    if remote_agent.has_key(u'port'):
+        remote_port = int(remote_agent[u'port'])
+    else:
+        remote_port = 22
 
     # now, connect and use paramiko Client to negotiate SSH2 across the connection
     try:
@@ -225,7 +231,7 @@ def delete_authorized_key(username, pubkey_hash, authorized_keys_file='%h/.x2go/
         _hostname = remote_agent['hostname']
 
     if delay_deletion > 0:
-        delayed_execution(delete_authorized_key, delay=60, username=username, authorized_keys_file=authorized_keys_file, query_mode=query_mode, remote_agent=remote_agent, )
+        delayed_execution(delete_authorized_key, delay=delay_deletion, username=username, pubkey_hash=pubkey_hash, authorized_keys_file=authorized_keys_file, query_mode=query_mode, remote_agent=remote_agent, )
         logger_broker.debug('Scheduled deletion of authorized key in {delay}s: user={user}, host={host}'.format(delay=delay_deletion, user=username, host=_hostname))
     else:
         if query_mode.upper() == u'LOCAL':
diff --git a/x2gobroker/authmechs/pam_authmech.py b/x2gobroker/authmechs/pam_authmech.py
index b46d1a2..7ea2023 100644
--- a/x2gobroker/authmechs/pam_authmech.py
+++ b/x2gobroker/authmechs/pam_authmech.py
@@ -18,15 +18,26 @@
 # Free Software Foundation, Inc.,
 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
+# modules
+from socket import error
+import pam
+
+# X2Go Session Broker modules
 import x2gobroker.authservice
 
 class X2GoBrokerAuthMech(object):
 
     def authenticate(self, username, password):
 
-        # do a simple PAM authentication against the PAM service ,,x2gobroker''
         if username and password:
-            if x2gobroker.authservice.authenticate(username, password, service="x2gobroker"):
-                return True
+            try:
+                # query the X2Go Session Broker's PAM Auth Service
+                if x2gobroker.authservice.authenticate(username, password, service="x2gobroker"):
+                    return True
+
+            except error:
+                # fallback to direct PAM authentication against the PAM service ,,x2gobroker''
+                if pam.authenticate(username, password, service="x2gobroker"):
+                    return True
 
         return False
diff --git a/x2gobroker/brokers/base_broker.py b/x2gobroker/brokers/base_broker.py
index 6062815..9001039 100644
--- a/x2gobroker/brokers/base_broker.py
+++ b/x2gobroker/brokers/base_broker.py
@@ -433,7 +433,7 @@ class X2GoBroker(object):
         _default_auth_mech = "pam"
         _auth_mech = ""
 
-        if self.config.has_value(self.backend_name, 'auth-mech'):
+        if self.config.has_value(self.backend_name, 'auth-mech') and self.config.get_value(self.backend_name, 'auth-mech'):
             _auth_mech = self.config.get_value(self.backend_name, 'auth-mech').lower()
             logger_broker.debug('base_broker.X2GoBroker.get_authentication_mechanism(): found auth-mech in backend config section »{backend}«: {value}. This one has precendence over the default value.'.format(backend=self.backend_name, value=_auth_mech))
 
@@ -454,7 +454,7 @@ class X2GoBroker(object):
         """
         _default_agent_query_mode = "LOCAL"
         _agent_query_mode = ""
-        if self.config.has_value(self.backend_name, 'agent-query-mode'):
+        if self.config.has_value(self.backend_name, 'agent-query-mode') and self.config.get_value(self.backend_name, 'agent-query-mode'):
             _agent_query_mode = self.config.get_value(self.backend_name, 'agent-query-mode').lower()
             logger_broker.debug('base_broker.X2GoBroker.get_agent_query_mode(): found agent-query-mode in backend config section »{backend}«: {value}. This one has precendence over the default value.'.format(backend=self.backend_name, value=_agent_query_mode))
 
@@ -871,13 +871,13 @@ class X2GoBroker(object):
             selected_session.update({
                 'authentication_privkey': privkey,
             })
-            #x2gobroker.agent.delete_authorized_key(username=username,
-            #                                       pubkey_hash=pubkey,
-            #                                       authorized_keys_file=self.get_authorized_keys_file(profile_id),
-            #                                       query_mode=agent_query_mode,
-            #                                       remote_agent=remote_agent,
-            #                                       delay_deletion=60,
-            #),
+            x2gobroker.agent.delete_authorized_key(username=username,
+                                                   pubkey_hash=pubkey,
+                                                   authorized_keys_file=self.get_authorized_keys_file(profile_id),
+                                                   query_mode=agent_query_mode,
+                                                   remote_agent=remote_agent,
+                                                   delay_deletion=20,
+            ),
 
         return selected_session
 
diff --git a/x2gobroker/loggers.py b/x2gobroker/loggers.py
index 5be50f3..e7eabe0 100644
--- a/x2gobroker/loggers.py
+++ b/x2gobroker/loggers.py
@@ -70,3 +70,22 @@ else:
     logger_error = logging.getLogger('error')
     logger_error.addHandler(stderr_handler)
     logger_error.propagate = 0
+
+def tornado_log_request(handler):
+    """\
+    Function for overriding the log_request method in
+    C{tornado.web.RequestHandler}.
+
+    @param handler: handler
+    @type handler: C{obj}
+
+    """
+    if handler.get_status() < 400:
+        log_method = logger_access.info
+    elif handler.get_status() < 500:
+        log_method = logger_access.warning
+    else:
+        log_method = logger_error.error
+    request_time = 1000.0 * handler.request.request_time()
+    log_method("%d %s %.2fms", handler.get_status(),
+               handler._request_summary(), request_time)
diff --git a/x2gobroker/tests/test_web_plain_base.py b/x2gobroker/tests/test_web_plain_base.py
index 74953ff..dd5a3ba 100644
--- a/x2gobroker/tests/test_web_plain_base.py
+++ b/x2gobroker/tests/test_web_plain_base.py
@@ -21,21 +21,20 @@ import unittest
 import tempfile
 from paste.fixture import TestApp
 from nose.tools import *
-import web
+import tornado.wsgi
 
 # Python X2GoBroker modules
 import x2gobroker.defaults
 import x2gobroker.web.plain
 
-urls = ( '/plain/(.*)', 'x2gobroker.web.plain.X2GoBrokerWeb',)
-app = web.application(urls, globals())
+urls = ( ('/plain/(.*)', x2gobroker.web.plain.X2GoBrokerWeb,) ,)
+application = tornado.wsgi.WSGIApplication(urls)
 
 class TestX2GoBrokerWebPlainBase(unittest.TestCase):
 
     ### TEST RESPONSE: is enabled?
 
     def test_isenabled(self):
-        middleware = []
         _config = """
 [base]
 enable = false
@@ -45,7 +44,7 @@ enable = false
         tf.seek(0)
         _cf_bak = x2gobroker.defaults.X2GOBROKER_CONFIG
         x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name
-        testApp = TestApp(app.wsgifunc(*middleware))
+        testApp = TestApp(application)
         r = testApp.get('/plain/base/', expect_errors=True)
         assert_equal(r.status, 404)
         tf.close()
@@ -57,7 +56,7 @@ enable = true
         print >> tf, _config
         tf.seek(0)
         x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name
-        testApp = TestApp(app.wsgifunc(*middleware))
+        testApp = TestApp(application)
         r = testApp.get('/plain/base/', expect_errors=True)
         assert_equal(r.status, 401)
         tf.close()
@@ -66,8 +65,7 @@ enable = true
     ### TEST RESPONSE: simple authentication (check_access)
 
     def test_checkaccess(self):
-        middleware = []
-        testApp = TestApp(app.wsgifunc(*middleware))
+        testApp = TestApp(application)
         r = testApp.get('/plain/base/', expect_errors=True)
         assert_equal(r.status, 401)
         _config = """
@@ -88,7 +86,6 @@ auth-mech = testsuite
     ### TEST TASK: listsessions (nothing should be returned for the base backend)
 
     def test_listsessions(self):
-        middleware = []
         _config = """
 [base]
 enable = true
@@ -99,7 +96,7 @@ auth-mech = testsuite
         tf.seek(0)
         _cf_bak = x2gobroker.defaults.X2GOBROKER_CONFIG
         x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name
-        testApp = TestApp(app.wsgifunc(*middleware))
+        testApp = TestApp(application)
         r = testApp.get('/plain/base/', params={'user': 'test', 'password': 'sweet',  'task': 'listsessions', }, expect_errors=True)
         assert_equal(r.status, 200)
         r.mustcontain('Access granted')
diff --git a/x2gobroker/tests/test_web_plain_zeroconf.py b/x2gobroker/tests/test_web_plain_zeroconf.py
index c258646..dad829b 100644
--- a/x2gobroker/tests/test_web_plain_zeroconf.py
+++ b/x2gobroker/tests/test_web_plain_zeroconf.py
@@ -21,21 +21,20 @@ import unittest
 import tempfile
 from paste.fixture import TestApp
 from nose.tools import *
-import web
+import tornado.wsgi
 
 # Python X2GoBroker modules
 import x2gobroker.defaults
 import x2gobroker.web.plain
 
-urls = ( '/plain/(.*)', 'x2gobroker.web.plain.X2GoBrokerWeb',)
-app = web.application(urls, globals())
+urls = ( ('/plain/(.*)', x2gobroker.web.plain.X2GoBrokerWeb,) ,)
+application = tornado.wsgi.WSGIApplication(urls)
 
 class TestX2GoBrokerWebPlainZeroconf(unittest.TestCase):
 
     ### TEST TASK: listsessions (you can influence the session command via the X2Go Broker's configurationfile)
 
     def test_listsessions_checkcommand(self):
-        middleware = []
         _config = """
 [zeroconf]
 enable = true
@@ -46,7 +45,7 @@ desktop-shell = KDE
         print >> tf, _config
         tf.seek(0)
         x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name
-        testApp = TestApp(app.wsgifunc(*middleware))
+        testApp = TestApp(application)
         r = testApp.get('/plain/zeroconf/', params={'user': 'test', 'password': 'sweet',  'task': 'listsessions', }, expect_errors=True)
         assert_equal(r.status, 200)
         r.mustcontain('Access granted')
@@ -69,7 +68,7 @@ desktop-shell = GNOME
         print >> tf, _config
         tf.seek(0)
         x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name
-        testApp = TestApp(app.wsgifunc(*middleware))
+        testApp = TestApp(application)
         r = testApp.get('/plain/zeroconf/', params={'user': 'test', 'password': 'sweet',  'task': 'listsessions', }, expect_errors=True)
         assert_equal(r.status, 200)
         r.mustcontain('Access granted')
@@ -85,7 +84,6 @@ desktop-shell = GNOME
     ### TEST TASK: selectsession (returns localhost as the only server, no SSH key, no session info)
 
     def test_selectsession(self):
-        middleware = []
         _config = """
 [zeroconf]
 enable = true
@@ -95,7 +93,7 @@ auth-mech = testsuite
         print >> tf, _config
         tf.seek(0)
         x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name
-        testApp = TestApp(app.wsgifunc(*middleware))
+        testApp = TestApp(application)
         r = testApp.get('/plain/zeroconf/', params={'user': 'test', 'password': 'sweet',  'task': 'selectsession', 'sid': 'LOCALHOST',}, expect_errors=True)
         assert_equal(r.status, 200)
         r.mustcontain('Access granted')
diff --git a/x2gobroker/web/extras.py b/x2gobroker/web/extras.py
index 75571e6..df48008 100644
--- a/x2gobroker/web/extras.py
+++ b/x2gobroker/web/extras.py
@@ -23,13 +23,14 @@
 # modules
 import os.path
 import paramiko
+import tornado.web
 
 import x2gobroker._paramiko
 x2gobroker._paramiko.monkey_patch_paramiko()
 
 import x2gobroker.defaults
 
-class X2GoBrokerPubKeyService:
+class X2GoBrokerPubKeyService(tornado.web.RequestHandler):
 
     http_header_items = {
         'Content-Type': 'text/plain; charset=utf-8',
@@ -39,7 +40,7 @@ class X2GoBrokerPubKeyService:
     def _gen_http_header(self):
 
         for http_header_item in self.http_header_items.keys():
-            web.header(http_header_item, self.http_header_items[http_header_item])
+            self.add_header(http_header_item, self.http_header_items[http_header_item])
 
     def GET(self):
 
@@ -56,6 +57,6 @@ class X2GoBrokerPubKeyService:
             output += 'ssh-dss {pubkey} {user}@{hostname}\n'.format(pubkey=str(pubkey.get_base64()), user=x2gobroker.defaults.X2GOBROKER_DAEMON_USER, hostname=x2gobroker.defaults.X2GOBROKER_HOSTNAME)
 
         if not output:
-            return web.notfound()
+            raise tornado.web.HTTPError(404)
 
-        return output
+        self.write(output)
diff --git a/x2gobroker/web/html.py b/x2gobroker/web/html.py
index 1a0b1db..a604239 100644
--- a/x2gobroker/web/html.py
+++ b/x2gobroker/web/html.py
@@ -21,12 +21,13 @@
 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
 # modules
-import web
+import tornado.web
 
 # Python X2Go Broker modules
 from x2gobroker.defaults import X2GOBROKER_DEFAULT_BACKEND as _X2GOBROKER_DEFAULT_BACKEND
 
-class X2GoBrokerWeb:
+
+class X2GoBrokerWeb(tornado.web.RequestHandler):
 
     http_header_items = {
         'Content-Type': 'text/html; charset=utf-8',
@@ -61,12 +62,13 @@ $output
     def _gen_http_header(self):
 
         for http_header_item in self.http_header_items.keys():
-            web.header(http_header_item, self.http_header_items[http_header_item])
+            self.add_header(http_header_item, self.http_header_items[http_header_item])
 
-    def GET(self, backend):
-        return self.POST(backend)
+    def get(self, backend):
+        self._gen_http_header()
+        return self.post(backend)
 
-    def POST(self, backend):
+    def post(self, backend):
 
         if not backend:
             backend = _X2GOBROKER_DEFAULT_BACKEND
@@ -81,25 +83,16 @@ $output
         backend_config = broker_backend.get_backend_config(backend)
 
         if not backend_config['enable']:
-            return web.notfound()
-
-        data = web.input()
-        try: username = data.user
-        except AttributeError: username = ''
-        try: password = data.password
-        except AttributeError: password = ''
-        try: authid = data.authid
-        except AttributeError: authid = ''
-        try: task = data.task
-        except AttributeError: task = ''
-        try: session_name = data.sid
-        except AttributeError: session_name = ''
-        try: new_password = data.newpass
-        except AttributeError: new_password = ''
+            raise tornado.web.HTTPError(404)
 
-        output = ''
+        username = self.get_argument('user', default='')
+        password = self.get_argument('password', default='')
+        cookie = self.get_argument('cookie', default='')
+        task = self.get_argument('task')
+        profile_id = self.get_argument('sid', default='')
+        new_password = self.get_argument('newpass', default='')
 
-        self._gen_http_header()
+        output = ''
 
         if broker_backend.check_access(username=username, password=password, authid=authid):
 
@@ -116,6 +109,8 @@ $output
                 ###
                 pass
 
-            return self.page(self.html_header_items, output)
+            self.write(output)
+            return
+
+        raise tornado.web.HTTPError(401)
 
-        return self.page(self.html_header_items, "<hr>Access denied")
diff --git a/x2gobroker/web/json.py b/x2gobroker/web/json.py
index ef35a0f..2e97f89 100644
--- a/x2gobroker/web/json.py
+++ b/x2gobroker/web/json.py
@@ -21,8 +21,10 @@
 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
 # modules
+import tornado.web
 
-class X2GoBrokerWeb:
+
+class X2GoBrokerWeb(tornado.web.RequestHandler):
 
     # MUSIC OF THE FUTURE
     pass
\ No newline at end of file
diff --git a/x2gobroker/web/plain.py b/x2gobroker/web/plain.py
index c9fd55b..f85bc98 100644
--- a/x2gobroker/web/plain.py
+++ b/x2gobroker/web/plain.py
@@ -21,15 +21,16 @@
 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
 # modules
-import web
 import types
+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
 
-class X2GoBrokerWeb:
+class X2GoBrokerWeb(tornado.web.RequestHandler):
 
     http_header_items = {
         'Content-Type': 'text/plain; charset=utf-8',
@@ -39,15 +40,16 @@ class X2GoBrokerWeb:
     def _gen_http_header(self):
 
         for http_header_item in self.http_header_items.keys():
-            web.header(http_header_item, self.http_header_items[http_header_item])
+            self.add_header(http_header_item, self.http_header_items[http_header_item])
 
-    def GET(self, backend):
+    def get(self, backend):
         if x2gobroker.defaults.X2GOBROKER_DEBUG:
+            self._gen_http_header()
             logger_broker.warn('GET http request detected, if unwanted: disable X2GOBROKER_DEBUG')
-            return self.POST(backend)
-        return web.notfound()
+            return self.post(backend)
+        raise tornado.web.HTTPError(404)
 
-    def POST(self, backend):
+    def post(self, backend):
 
         if not backend:
             backend = x2gobroker.defaults.X2GOBROKER_DEFAULT_BACKEND
@@ -61,36 +63,34 @@ class X2GoBrokerWeb:
         exec("broker_backend = x2gobroker.brokers.{backend}_broker.X2GoBroker()".format(backend=backend))
         global_config = broker_backend.get_global_config()
 
+        # if the broker backend is disabled in the configuration, pretend to have nothing on offer
+        if not broker_backend.is_enabled():
+            raise tornado.web.HTTPError(404)
+
+        # FIXME: this is to work around a bug in X2Go Client (http://bugs.x2go.org/138)
+        content_type = self.request.headers.get("Content-Type", "")
+        if not content_type.startswith("application/x-www-form-urlencoded"):
+            for name, values in parse_qs_bytes(native_str(self.request.body)).iteritems():
+                self.request.arguments.setdefault(name, []).extend(values)
+
         # set the client address for the broker backend
-        ip = web.ctx.env.get('HTTP_X_FORWARDED_FOR', web.ctx.get('ip', ''))
+        ip = self.request.remote_ip
         if ip:
             logger_broker.info('client address is {address}'.format(address=ip))
             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')
-            return web.notfound()
+            raise tornado.web.HTTPError(404)
 
-        # if the broker backend is disabled in the configuration, pretend to have nothing on offer
-        if not broker_backend.is_enabled():
-            return web.notfound()
-
-        data = web.input()
-        try: username = data.user
-        except AttributeError: username = ''
-        try: password = data.password
-        except AttributeError: password = ''
-        try: cookie = data.cookie
-        except AttributeError: cookie = ''
-        try: task = data.task
-        except AttributeError: task = ''
-        try: profile_id = data.sid
-        except AttributeError: profile_id = ''
-        try: new_password = data.newpass
-        except AttributeError: new_password = ''
+        username = self.get_argument('user', default='')
+        password = self.get_argument('password', default='')
+        cookie = self.get_argument('cookie', default='')
+        task = self.get_argument('task', default='')
+        profile_id = self.get_argument('sid', default='')
+        new_password = self.get_argument('newpass', default='')
 
         output = ''
-        self._gen_http_header()
 
         logger_broker.debug ('username: {username}, password: {password}, task: {task}, profile_id: {profile_id}'.format(username=username, password='XXXXX', task=task, profile_id=profile_id))
         if broker_backend.check_access(username=username, password=password, cookie=cookie):
@@ -160,6 +160,8 @@ class X2GoBrokerWeb:
                             output += "SESSION_INFO:"
                             output += profile_info['session_info'] + "\n"
 
-            return output
+            self.write(output)
+            return
+
+        raise tornado.web.HTTPError(401)
 
-        return web.unauthorized()


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