2 commits - pykolab/wap_client share/templates

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Fri Sep 28 13:30:16 CEST 2012


 pykolab/wap_client/__init__.py                          |  111 +++++++---------
 share/templates/roundcubemail/acl.inc.php.tpl           |    2 
 share/templates/roundcubemail/calendar.inc.php.tpl      |    2 
 share/templates/roundcubemail/db.inc.php.tpl            |    2 
 share/templates/roundcubemail/kolab.inc.php.tpl         |    2 
 share/templates/roundcubemail/kolab_auth.inc.php.tpl    |    2 
 share/templates/roundcubemail/kolab_folders.inc.php.tpl |    2 
 share/templates/roundcubemail/main.inc.php.tpl          |    2 
 share/templates/roundcubemail/managesieve.inc.php.tpl   |    2 
 share/templates/roundcubemail/owncloud.inc.php.tpl      |    4 
 share/templates/roundcubemail/password.inc.php.tpl      |    2 
 share/templates/roundcubemail/terms.inc.php.tpl         |    2 
 12 files changed, 67 insertions(+), 68 deletions(-)

New commits:
commit 32fccd69f5857fa4922b20ed7ba29ccdcde1a7ec
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri Sep 28 12:29:31 2012 +0100

    Enhance wap client interaction

diff --git a/pykolab/wap_client/__init__.py b/pykolab/wap_client/__init__.py
index d5b0f50..af66d36 100644
--- a/pykolab/wap_client/__init__.py
+++ b/pykolab/wap_client/__init__.py
@@ -1,6 +1,7 @@
 
 import json
 import httplib
+import urllib
 import sys
 from urlparse import urlparse
 
@@ -45,25 +46,15 @@ from connect import connect
 def authenticate(username=None, password=None, domain=None):
     global session_id
 
-    conf_username = conf.get('ldap', 'service_bind_dn')
-    conf_password = conf.get('ldap', 'service_bind_pw')
-
     if username == None:
-        username = utils.ask_question("Login", default=conf_username)
-
-    if username == conf_username:
-        password = conf_password
-
-    if username == conf.get('ldap', 'bind_dn'):
-        password = conf.get('ldap', 'bind_pw')
-
+        username = conf.get('ldap', 'bind_dn')
     if password == None:
-        password = utils.ask_question("Password", default=conf_password, password=True)
+        password = conf.get('ldap', 'bind_pw')
 
     if domain == None:
         domain = conf.get('kolab', 'primary_domain')
 
-    params = json.dumps(
+    post = json.dumps(
             {
                     'username': username,
                     'password': password,
@@ -71,7 +62,7 @@ def authenticate(username=None, password=None, domain=None):
                 }
         )
 
-    response = request('POST', "system.authenticate", params)
+    response = request('POST', "system.authenticate", post=post)
 
     if response.has_key('session_token'):
         session_id = response['session_token']
@@ -113,12 +104,13 @@ def domain_add(domain, parent=None):
             log.error(_("Invalid parent domain"))
             return
 
-    params = json.dumps(params)
+    post = json.dumps(params)
 
-    return request('POST', 'domain.add', params)
+    return request('POST', 'domain.add', post=post)
 
 def domain_info(domain):
-    return request('GET', 'domain.info?domain=%s' % (domain))
+    get = { 'domain': domain }
+    return request('GET', 'domain.info', get=get)
 
 def domains_capabilities():
     return request('GET', 'domains.capabilities')
@@ -127,9 +119,9 @@ def domains_list():
     return request('GET', 'domains.list')
 
 def form_value_generate(params):
-    params = json.dumps(params)
+    post = json.dumps(params)
 
-    return request('POST', 'form_value.generate', params)
+    return request('POST', 'form_value.generate', post=post)
 
 def get_group_input():
     group_types = group_types_list()
@@ -238,8 +230,8 @@ def group_types_list():
 def groups_list():
     return request('GET', 'groups.list')
 
-def request(method, api_uri, params=None, headers={}):
-    response_data = request_raw(method, api_uri, params, headers)
+def request(method, api_uri, get=None, post=None, headers={}):
+    response_data = request_raw(method, api_uri, get, post, headers)
 
     if response_data['status'] == "OK":
         del response_data['status']
@@ -247,15 +239,26 @@ def request(method, api_uri, params=None, headers={}):
     else:
         return response_data['result']
 
-def request_raw(method, api_uri, params=None, headers={}):
+def request_raw(method, api_uri, get=None, post=None, headers={}):
     global session_id
 
     if not session_id == None:
         headers["X-Session-Token"] = session_id
 
     conn = connect()
-    log.debug(_("Requesting %r with params %r") % ("%s/%s" % (API_BASE,api_uri), params), level=8)
-    conn.request(method.upper(), "%s/%s" % (API_BASE,api_uri), params, headers)
+
+    if conf.debuglevel > 8:
+        conn.set_debuglevel(9)
+
+    if not get == None:
+        _get = "?%s" % (urllib.urlencode(get))
+    else:
+        _get = ""
+
+    log.debug(_("Requesting %r with params %r") % ("%s/%s" % (API_BASE,api_uri), (get, post)), level=8)
+
+    conn.request(method.upper(), "%s/%s%s" % (API_BASE, api_uri, _get), post, headers)
+
     response = conn.getresponse()
 
     data = response.read()
@@ -281,7 +284,10 @@ def system_get_domain():
 def system_select_domain(domain=None):
     if domain == None:
         domain = utils.ask_question("Domain name")
-    return request('GET', 'system.select_domain?domain=%s' % (domain))
+
+    get = { 'domain': domain }
+
+    return request('GET', 'system.select_domain', get=get)
 
 def user_add(params=None):
     if params == None:
@@ -297,9 +303,9 @@ def user_delete(params=None):
                 'user': utils.ask_question("Username for user to delete", "user")
             }
 
-    params = json.dumps(params)
+    post = json.dumps(params)
 
-    return request('POST', 'user.delete', params)
+    return request('POST', 'user.delete', post=post)
 
 def user_edit(params=None):
     if params == None:
@@ -307,9 +313,9 @@ def user_edit(params=None):
                 'user': utils.ask_question("Username for user to edit", "user")
             }
 
-    params = json.dumps(params)
+    get = json.dumps(params)
 
-    user = request('GET', 'user.info', params)
+    user = request('GET', 'user.info', get=get)
 
     return user
 
@@ -317,38 +323,38 @@ def user_form_value_generate_cn(params=None):
     if params == None:
         params = get_user_input()
 
-    params = json.dumps(params)
+    post = json.dumps(params)
 
-    return request('POST', 'user_form_value.generate_cn', params)
+    return request('POST', 'user_form_value.generate_cn', post=post)
 
 def user_form_value_generate_displayname(params=None):
     if params == None:
         params = get_user_input()
 
-    params = json.dumps(params)
+    post = json.dumps(params)
 
-    return request('POST', 'user_form_value.generate_displayname', params)
+    return request('POST', 'user_form_value.generate_displayname', post=post)
 
 def user_form_value_generate_mail(params=None):
     if params == None:
         params = get_user_input()
 
-    params = json.dumps(params)
+    post = json.dumps(params)
 
-    return request('POST', 'user_form_value.generate_mail', params)
+    return request('POST', 'user_form_value.generate_mail', post=post)
 
 def form_value_generate_password(*args, **kw):
     return request('GET', 'form_value.generate_password')
 
 def form_value_list_options(attribute_name, *args, **kw):
-    params = json.dumps({'attribute': attribute_name})
+    post = json.dumps({'attribute': attribute_name})
 
-    return request('POST', 'form_value.list_options', params)
+    return request('POST', 'form_value.list_options', post=post)
 
 def form_value_select_options(attribute_name, *args, **kw):
-    params = json.dumps({'attributes': [attribute_name]})
+    post = json.dumps({'attributes': [attribute_name]})
 
-    return request('POST', 'form_value.select_options', params)
+    return request('POST', 'form_value.select_options', post=post)
 
 def role_find_by_attribute(params=None):
     if params == None:
@@ -356,7 +362,8 @@ def role_find_by_attribute(params=None):
     else:
         role_name = params['cn']
 
-    role = request('GET', 'role.find_by_attribute?cn=%s' % (role_name))
+    get = { 'cn': role_name }
+    role = request('GET', 'role.find_by_attribute', get=get)
 
     return role
 
@@ -385,25 +392,16 @@ def role_delete(params=None):
                 'role': role.keys()[0]
             }
 
-    params = json.dumps(params)
+    post = json.dumps(params)
 
-    return request('POST', 'role.delete', params)
+    return request('POST', 'role.delete', post=post)
 
-def role_info(params=None):
-    if params == None:
-        role_name = utils.ask_question("Role name")
-        role = role_find_by_attribute({'cn': role_name})
-        params = {
-                'role': role
-            }
+def role_info(role_name):
+    role = role_find_by_attribute({'cn': role_name})
 
-    if not params.has_key('role'):
-        role = role_find_by_attribute(params)
-        params = {
-                'role': role
-            }
+    get = { 'role': role['id'] }
 
-    role = request('GET', 'role.info?role=%s' % (params['role'].keys()[0]))
+    role = request('GET', 'role.info', get=get)
 
     return role
 
@@ -425,7 +423,8 @@ def user_form_value_generate_userpassword(*args, **kw):
 def user_info(user=None):
     if user == None:
         user = utils.ask_question("User email address")
-    user = request('GET', 'user.info?user=%s' % (user))
+    _params = { 'user': user }
+    user = request('GET', 'user.info?%s' % (urllib.urlencode(_params)))
     return user
 
 def user_types_list():


commit 67c5648fc635876b96c8e128593d833a761f7d57
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Tue Sep 18 10:19:53 2012 +0100

    Fix syntax error

diff --git a/share/templates/roundcubemail/acl.inc.php.tpl b/share/templates/roundcubemail/acl.inc.php.tpl
index 12cdc51..f4b651c 100644
--- a/share/templates/roundcubemail/acl.inc.php.tpl
+++ b/share/templates/roundcubemail/acl.inc.php.tpl
@@ -4,7 +4,7 @@
     \$rcmail_config['acl_users_field'] = 'mail';
     \$rcmail_config['acl_users_filter'] = 'objectClass=kolabInetOrgPerson';
 
-    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__)) {
+    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__))) {
         include_once(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__));
     }
 
diff --git a/share/templates/roundcubemail/calendar.inc.php.tpl b/share/templates/roundcubemail/calendar.inc.php.tpl
index b7b668f..a7cf6d2 100644
--- a/share/templates/roundcubemail/calendar.inc.php.tpl
+++ b/share/templates/roundcubemail/calendar.inc.php.tpl
@@ -8,7 +8,7 @@
     \$rcmail_config['calendar_work_end'] = 18;
     \$rcmail_config['calendar_event_coloring'] = 0;
 
-    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__)) {
+    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__))) {
         include_once(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__));
     }
 
diff --git a/share/templates/roundcubemail/db.inc.php.tpl b/share/templates/roundcubemail/db.inc.php.tpl
index caec957..1257f18 100644
--- a/share/templates/roundcubemail/db.inc.php.tpl
+++ b/share/templates/roundcubemail/db.inc.php.tpl
@@ -4,7 +4,7 @@
 
     \$rcmail_config['db_dsnw'] = '$mysql_uri';
 
-    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__)) {
+    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__))) {
         include_once(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__));
     }
 
diff --git a/share/templates/roundcubemail/kolab.inc.php.tpl b/share/templates/roundcubemail/kolab.inc.php.tpl
index f6fc5f4..49cc50b 100644
--- a/share/templates/roundcubemail/kolab.inc.php.tpl
+++ b/share/templates/roundcubemail/kolab.inc.php.tpl
@@ -2,7 +2,7 @@
 
     \$rcmail_config['kolab_freebusy_server'] = 'http://' . \$_SERVER["HTTP_HOST"] . '/freebusy';
 
-    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__)) {
+    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__))) {
         include_once(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__));
     }
 
diff --git a/share/templates/roundcubemail/kolab_auth.inc.php.tpl b/share/templates/roundcubemail/kolab_auth.inc.php.tpl
index 5568c0a..6044232 100644
--- a/share/templates/roundcubemail/kolab_auth.inc.php.tpl
+++ b/share/templates/roundcubemail/kolab_auth.inc.php.tpl
@@ -63,7 +63,7 @@
     // which adds privilege to login as another user.
     \$rcmail_config['kolab_auth_group'] = 'Kolab Helpdesk';
 
-    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__)) {
+    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__))) {
         include_once(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__));
     }
 
diff --git a/share/templates/roundcubemail/kolab_folders.inc.php.tpl b/share/templates/roundcubemail/kolab_folders.inc.php.tpl
index 7f0598d..806f060 100644
--- a/share/templates/roundcubemail/kolab_folders.inc.php.tpl
+++ b/share/templates/roundcubemail/kolab_folders.inc.php.tpl
@@ -12,7 +12,7 @@
     \$rcmail_config['kolab_folders_mail_outbox'] = '';
     \$rcmail_config['kolab_folders_mail_wastebasket'] = '';
 
-    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__)) {
+    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__))) {
         include_once(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__));
     }
 
diff --git a/share/templates/roundcubemail/main.inc.php.tpl b/share/templates/roundcubemail/main.inc.php.tpl
index ba6c1e9..39afa10 100644
--- a/share/templates/roundcubemail/main.inc.php.tpl
+++ b/share/templates/roundcubemail/main.inc.php.tpl
@@ -110,7 +110,7 @@
             'contextmenu',
         );
 
-    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__)) {
+    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__))) {
         include_once(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__));
     }
 
diff --git a/share/templates/roundcubemail/managesieve.inc.php.tpl b/share/templates/roundcubemail/managesieve.inc.php.tpl
index 48fa544..8ab9998 100644
--- a/share/templates/roundcubemail/managesieve.inc.php.tpl
+++ b/share/templates/roundcubemail/managesieve.inc.php.tpl
@@ -11,7 +11,7 @@
     \$rcmail_config['managesieve_disabled_extensions'] = array();
     \$rcmail_config['managesieve_debug'] = true;
 
-    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__)) {
+    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__))) {
         include_once(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__));
     }
 
diff --git a/share/templates/roundcubemail/owncloud.inc.php.tpl b/share/templates/roundcubemail/owncloud.inc.php.tpl
index f5268fa..089849a 100644
--- a/share/templates/roundcubemail/owncloud.inc.php.tpl
+++ b/share/templates/roundcubemail/owncloud.inc.php.tpl
@@ -2,8 +2,8 @@
     // ownCloud URL
     \$rcmail_config['owncloud_url'] = 'http://' . \$_SERVER["HTTP_HOST"] . '/owncloud';
 
-    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__)) {
+    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__))) {
         include_once(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__));
     }
 
-?>
\ No newline at end of file
+?>
diff --git a/share/templates/roundcubemail/password.inc.php.tpl b/share/templates/roundcubemail/password.inc.php.tpl
index 9fd28d3..7aa45db 100644
--- a/share/templates/roundcubemail/password.inc.php.tpl
+++ b/share/templates/roundcubemail/password.inc.php.tpl
@@ -148,7 +148,7 @@
     // Whenever the password is changed, the attribute will be updated if set
     \$rcmail_config['password_ldap_samba_lchattr'] = '';
 
-    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__)) {
+    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__))) {
         include_once(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__));
     }
 
diff --git a/share/templates/roundcubemail/terms.inc.php.tpl b/share/templates/roundcubemail/terms.inc.php.tpl
index a5292f2..05e9f36 100644
--- a/share/templates/roundcubemail/terms.inc.php.tpl
+++ b/share/templates/roundcubemail/terms.inc.php.tpl
@@ -15,7 +15,7 @@
     // always request terms agreement after login
     \$rcmail_config['terms_always'] = false;
 
-    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__)) {
+    if (file_exists(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__))) {
         include_once(RCMAIL_CONFIG_DIR . '/' . \$_SERVER["HTTP_HOST"] . '/' . basename(__FILE__));
     }
 





More information about the commits mailing list