[X2Go-Commits] [x2gobroker] 01/01: Change pre and post scripts to use common codebase across frontends. (Fixes: #469). Add ability to have script run in select session after server is selected.

git-admin at x2go.org git-admin at x2go.org
Wed Apr 2 16:30:39 CEST 2014


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository x2gobroker.

commit 8018b7388e551d3d9df690fd2e1eb6ca4deb2ce1
Author: Josh Lukens <jlukens at botch.com>
Date:   Wed Apr 2 16:30:00 2014 +0200

    Change pre and post scripts to use common codebase across frontends. (Fixes: #469). Add ability to have script run in select session after server is selected.
---
 debian/changelog                           |    2 ++
 etc/x2gobroker.conf                        |    8 ++++++--
 x2gobroker/brokers/base_broker.py          |   24 ++++++++++++++++++++++
 x2gobroker/defaults.py                     |    1 +
 x2gobroker/optional_scripts/base_script.py |    4 ++--
 x2gobroker/web/json.py                     |   17 +++++-----------
 x2gobroker/web/plain.py                    |   30 ++++++----------------------
 7 files changed, 46 insertions(+), 40 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 15988f0..d7350da 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -149,6 +149,8 @@ x2gobroker (0.0.3.0-0x2go1) UNRELEASED; urgency=low
       (Fixes: #447).
     - Add support to run pre and post authentication scripts. (Fixes: #449).
     - Add auth mechanism https_get. (Fixes: #450).
+    - Change pre and post scripts to use common codebase across frontends. (Fixes: #469).
+    - Add ability to have script run in select session after server is selected.
 
  -- Mike Gabriel <mike.gabriel at das-netzwerkteam.de>  Fri, 07 Jun 2013 23:25:30 +0200
 
diff --git a/etc/x2gobroker.conf b/etc/x2gobroker.conf
index 10df0c4..8dbab39 100644
--- a/etc/x2gobroker.conf
+++ b/etc/x2gobroker.conf
@@ -50,10 +50,14 @@
 
 # Pre and Post authentication scripts give you the option to run outside scripts
 # or adjust the values of variables for users logging in.  Pre scripts run just
-# before user authentication and Post scripts run just after.  Set to list of
-# scripts, comma seperated, with no spaces between.
+# before user authentication and Post scripts run just after even if authentication fails.
+# Select Session scripts run after load balancing right before the chosen server is sent
+# to the client.
+#
+# Set to list of scripts, comma seperated, with no spaces between.
 #pre_auth_scripts =
 #post_auth_scripts =
+#select_session_scripts =
 
 # Every server-client communication (between X2Go Client and broker) has to be
 # accompanied by this initial authentication cookie if require-cookie is set above.
diff --git a/x2gobroker/brokers/base_broker.py b/x2gobroker/brokers/base_broker.py
index 2b1cdf4..8aef096 100644
--- a/x2gobroker/brokers/base_broker.py
+++ b/x2gobroker/brokers/base_broker.py
@@ -1142,3 +1142,27 @@ class X2GoBroker(object):
 
         """
         return False
+
+    def run_optional_script(self, script_type, username, password, task, profile_id, ip, cookie, authed=None, server=None):
+        """\
+        Run all optional scripts of type script_type.  Called with 3 different script types:
+          pre_auth_scripts - before authentication happens
+          post_auth_scripts - after authentication but before anything else occurs
+          select_session_scripts - after load balancing before a specific server is sent to the client
+
+        These scripts allow for both addional actions to be performed as well as the mangling of any relevant fields.
+
+        """
+
+        if len(global_config[script_type]) != 0:
+            for script in global_config[script_type]:
+                try:
+                    my_script=None
+                    exec("import x2gobroker.optional_scripts.{script}_script".format(script=script))
+                    exec("my_script = x2gobroker.optional_scripts.{script}_script.X2GoBrokerOptionalScript()".format(script=script))
+                    logger_broker.debug ('Calling {script_type} {script} with username: {username}, password: {password}, task: {task}, profile_id: {profile_id}, ip: {ip}, cookie: {cookie}, authed: {authed}, server: {server}'.format(script_type=script_type,script=script,username=username, password='XXXXX', task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=authed, server=server))
+                    username, password, task, profile_id, ip, cookie, authed, server = my_script.run_me(username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=authed, server=server)
+                    logger_broker.debug ('Finished {script_type} {script} with username: {username}, password: {password}, task: {task}, profile_id: {profile_id}, ip: {ip}, cookie: {cookie}, authed: {authed}, server: {server}'.format(script_type=script_type,script=script,username=username, password='XXXXX', task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=authed, server=server))
+                except ImportError:
+                    logger_error.error('No such optional script \'{script}\''.format(script=script))
+        return username, password, task, profile_id, ip, cookie, authed, server
diff --git a/x2gobroker/defaults.py b/x2gobroker/defaults.py
index 0cdc323..5ae9ccb 100644
--- a/x2gobroker/defaults.py
+++ b/x2gobroker/defaults.py
@@ -188,6 +188,7 @@ X2GOBROKER_CONFIG_DEFAULTS = {
         u'verify-ip': True,
         u'pre_auth_scripts': [],
         u'post_auth_scripts': [],
+        u'select_session_scripts': [],
         u'my-cookie': uuid.uuid4(),
         u'enable-plain-output': True,
         u'enable-json-output': True,
diff --git a/x2gobroker/optional_scripts/base_script.py b/x2gobroker/optional_scripts/base_script.py
index e284362..dd9e5e2 100755
--- a/x2gobroker/optional_scripts/base_script.py
+++ b/x2gobroker/optional_scripts/base_script.py
@@ -20,5 +20,5 @@
 
 class X2GoBrokerOptionalScript(object):
 
-    def run_me(self, username, password, task, profile_id, ip, cookie):
-        return username, password, task, profile_id, ip, cookie
+    def run_me(self, username, password, task, profile_id, ip, cookie, authed, server):
+        return username, password, task, profile_id, ip, cookie, authed, server
diff --git a/x2gobroker/web/json.py b/x2gobroker/web/json.py
index 08cb973..b88ca5d 100644
--- a/x2gobroker/web/json.py
+++ b/x2gobroker/web/json.py
@@ -125,21 +125,13 @@ class X2GoBrokerWeb(_RequestHandler):
             'task': task,
         }
 
-        if len(global_config['pre_auth_scripts']) != 0:
-            for script in global_config['pre_auth_scripts']:
-                try:
-                    post_auth_script=None
-                    exec("import x2gobroker.optional_scripts.{script}_script".format(script=script))
-                    exec("pre_auth_script = x2gobroker.optional_scripts.{script}_script.X2GoBrokerOptionalScript()".format(script=script))
-                    logger_broker.debug ('Calling pre-auth script {script} with username: {username}, password: {password}, task: {task}, profile_id: {profile_id}, ip: {ip}, cookie: {cookie}'.format(script=script,username=username, password='XXXXX', task=task, profile_id=profile_id, ip=ip, cookie=cookie))
-                    username, password, task, profile_id, ip, cookie = pre_auth_script.run_me(username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie)
-                    logger_broker.debug ('Pre-auth script {script} finished with username: {username}, password: {password}, task: {task}, profile_id: {profile_id}, ip: {ip}, cookie: {cookie}'.format(script=script,username=username, password='XXXXX', task=task, profile_id=profile_id, ip=ip, cookie=cookie))
-                except ImportError:
-                    logger_error.error('No such optional script \'{script}\''.format(script=script))
+        username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='pre_auth_scripts', username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie)
 
         logger_broker.debug ('username: {username}, password: {password}, task: {task}, profile_id: {profile_id}, cookie: {cookie}'.format(username=username, password='XXXXX', task=task, profile_id=profile_id, cookie=cookie))
         access, next_cookie = broker_backend.check_access(username=username, password=password, ip=ip, cookie=cookie)
 
+        username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='post_auth_scripts', username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=access)
+
         if access:
 
             if len(global_config['post_auth_scripts']) != 0:
@@ -199,7 +191,8 @@ class X2GoBrokerWeb(_RequestHandler):
 
                     profile_info = broker_backend.select_session(profile_id=profile_id, username=username, pubkey=pubkey)
                     if profile_info.has_key('server'):
-                        selected_session['server'] = "{server}".format(server=profile_info['server'])
+                        username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='select_session_scripts', username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=access, server=profile_info['server'])
+                        selected_session['server'] = "{server}".format(server=server)
                         if profile_info.has_key('port'):
                             selected_session['port'] = "{port}".format(port=profile_info['port'])
                         else:
diff --git a/x2gobroker/web/plain.py b/x2gobroker/web/plain.py
index 150818b..be4a81d 100644
--- a/x2gobroker/web/plain.py
+++ b/x2gobroker/web/plain.py
@@ -115,33 +115,14 @@ class X2GoBrokerWeb(_RequestHandler):
 
         output = ''
 
-        if len(global_config['pre_auth_scripts']) != 0:
-            for script in global_config['pre_auth_scripts']:
-                try:
-                    post_auth_script=None
-                    exec("import x2gobroker.optional_scripts.{script}_script".format(script=script))
-                    exec("pre_auth_script = x2gobroker.optional_scripts.{script}_script.X2GoBrokerOptionalScript()".format(script=script))
-                    logger_broker.debug ('Calling pre-auth script {script} with username: {username}, password: {password}, task: {task}, profile_id: {profile_id}, ip: {ip}, cookie: {cookie}'.format(script=script,username=username, password='XXXXX', task=task, profile_id=profile_id, ip=ip, cookie=cookie))
-                    username, password, task, profile_id, ip, cookie = pre_auth_script.run_me(username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie)
-                    logger_broker.debug ('Pre-auth script {script} finished with username: {username}, password: {password}, task: {task}, profile_id: {profile_id}, ip: {ip}, cookie: {cookie}'.format(script=script,username=username, password='XXXXX', task=task, profile_id=profile_id, ip=ip, cookie=cookie))
-                except ImportError:
-                    logger_error.error('No such optional script \'{script}\''.format(script=script))
+        username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='pre_auth_scripts', username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie)
 
         logger_broker.debug ('username: {username}, password: {password}, task: {task}, profile_id: {profile_id}, cookie: {cookie}'.format(username=username, password='XXXXX', task=task, profile_id=profile_id, cookie=cookie))
         access, next_cookie = broker_backend.check_access(username=username, password=password, ip=ip, cookie=cookie)
 
+        username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='post_auth_scripts', username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=access)
+
         if access:
-            if len(global_config['post_auth_scripts']) != 0:
-                for script in global_config['post_auth_scripts']:
-                    try:
-                        post_auth_script=None
-                        exec("import x2gobroker.optional_scripts.{script}_script".format(script=script))
-                        exec("post_auth_script = x2gobroker.optional_scripts.{script}_script.X2GoBrokerOptionalScript()".format(script=script))
-                        logger_broker.debug ('Calling post-auth script {script} with username: {username}, password: {password}, task: {task}, profile_id: {profile_id}, ip: {ip}, cookie: {cookie}'.format(script=script,username=username, password='XXXXX', task=task, profile_id=profile_id, ip=ip, cookie=cookie))
-                        username, password, task, profile_id, ip, cookie = post_auth_script.run_me(username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie)
-                        logger_broker.debug ('Post-auth script {script} finished with username: {username}, password: {password}, task: {task}, profile_id: {profile_id}, ip: {ip}, cookie: {cookie}'.format(script=script,username=username, password='XXXXX', task=task, profile_id=profile_id, ip=ip, cookie=cookie))
-                    except ImportError:
-                        logger_error.error('No such optional script \'{script}\''.format(script=script))
 
             ###
             ### CONFIRM SUCCESSFUL AUTHENTICATION FIRST
@@ -192,9 +173,11 @@ class X2GoBrokerWeb(_RequestHandler):
                 if profile_id:
 
                     profile_info = broker_backend.select_session(profile_id=profile_id, username=username, pubkey=pubkey)
+
                     if profile_info.has_key('server'):
+                        username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='select_session_scripts', username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=access, server=profile_info['server'])
                         output += "SERVER:"
-                        output += profile_info['server']
+                        output += server
                         if profile_info.has_key('port'):
                             output += ":{port}".format(port=profile_info['port'])
                         output += "\n"
@@ -208,4 +191,3 @@ class X2GoBrokerWeb(_RequestHandler):
             return
 
         raise tornado.web.HTTPError(401)
-

--
Alioth's /srv/git/_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git



More information about the x2go-commits mailing list