8 commits - doc/kolab_wap.sql lib/api
Daniel Hoffend
hoffend at kolabsys.com
Thu Feb 19 11:15:19 CET 2015
doc/kolab_wap.sql | 2
lib/api/kolab_api_service_form_value.php | 95 +++++++++++++++++++++++++------
2 files changed, 78 insertions(+), 19 deletions(-)
New commits:
commit 062c8eb97bed4ff3d505f10f6a7cf0fe8c3fa66c
Author: Daniel Hoffend <dh at dotlan.net>
Date: Wed Feb 18 23:32:30 2015 +0100
check cn attribute during generation
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 26a2fbf..320acf9 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -581,6 +581,9 @@ class kolab_api_service_form_value extends kolab_api_service
return '';
}
+ // check format (will throw exception)
+ $this->validate_cn_sharedfolder($postdata['cn']);
+
$cn = $postdata['cn'];
$imap_hierarchysep = '/';
commit 3b8d87403f8e178f2b4a333b675ea697759c12f7
Author: Daniel Hoffend <dh at dotlan.net>
Date: Wed Feb 18 23:21:47 2015 +0100
revert the targetfolder naming to the mail attribute
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 86e1a26..26a2fbf 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -581,22 +581,10 @@ class kolab_api_service_form_value extends kolab_api_service
return '';
}
- // determine the @emaildomain part
- $email_domain = '';
- $at_index = strrpos($postdata['mail'], "@");
- if (!(is_bool($at_index) && !$at_index)) {
- $email_domain = substr($postdata['mail'], $at_index+1);
- }
-
- // if no email is set or domain isn't valid return empty
- if (!$email_domain || !in_array($email_domain, $this->_get_valid_domains())) {
- return '';
- }
-
$cn = $postdata['cn'];
$imap_hierarchysep = '/';
- return $cn ? 'shared' . $imap_hierarchysep . $cn . '@' . $email_domain : '';
+ return $cn ? 'shared' . $imap_hierarchysep . $cn . '@' . $_SESSION['user']->get_domain() : '';
}
}
commit 77e67f34ac5560caad011a4e85e2a87ad11275dd
Author: Daniel Hoffend <dh at dotlan.net>
Date: Wed Feb 18 23:00:07 2015 +0100
added more characaters to check for cn / kolabTargetFolder. @ % ^
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 6b32523..86e1a26 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -1335,8 +1335,8 @@ class kolab_api_service_form_value extends kolab_api_service
private function validate_cn_sharedfolder($value, $postdata = array(), $validation_type = null)
{
- if (preg_match('/["\']/',$value)) {
- throw new Exception("Folder name contains invalid characters: \" ']");
+ if (preg_match('/["\'@%+^]/',$value)) {
+ throw new Exception("Folder name contains invalid characters: \" ' @ % + ^");
}
return 'OK';
@@ -1344,13 +1344,9 @@ class kolab_api_service_form_value extends kolab_api_service
private function validate_kolabtargetfolder_sharedfolder($value, $postdata = array(), $validation_type = null)
{
- if (preg_match('/["\'\+]/',$value)) {
- throw new Exception("Target IMAP Folder contains invalid characters \" ' +");
- }
-
$domains = $this->_get_valid_domains();
- if (!preg_match('#^shared/[^"\'\\+]+@('.implode("|",$domains).')$#',$value)) {
- throw new Exception("Target IMAP Folder has to match the following format: 'shared/foldername at mydomain.org'"&& folderpart == cn (other));
+ if (!preg_match('#^shared/[^"\'\\+@%^]+@('.implode("|",$domains).')$#',$value)) {
+ throw new Exception("Target IMAP Folder has to match the following format: 'shared/foldername at mydomain.org' and the foldername can't contain invalid characters: \" ' @ % + ^");
}
// TODO: check for duplicate shared folder
commit e712eaf3caff0e5e114410bdb2cdb9d7b2ace1eb
Author: Daniel Hoffend <dh at dotlan.net>
Date: Wed Feb 18 22:41:45 2015 +0100
use $my_primary_domain parameter to reduce one lookup
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 2dd9aa9..6b32523 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -1657,7 +1657,7 @@ class kolab_api_service_form_value extends kolab_api_service
$valid = false;
Log::trace("_validate_email_address_in_any_of_mydomains(\$mail_address = " . var_export($mail_address, TRUE) . ")");
- if (in_array($email_domain, $this->_get_valid_domains())) {
+ if (in_array($email_domain, $this->_get_valid_domains($my_primary_domain))) {
$valid = true;
}
commit d45ceadf3e8ed70f839579d98dbc1a95ee6f6f0c
Author: Daniel Hoffend <dh at dotlan.net>
Date: Wed Feb 18 20:46:18 2015 +0100
add validate_cn_sharedfolder + validate_kolabtargetfolder_sharedfolder
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 3f40310..2dd9aa9 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -576,10 +576,27 @@ class kolab_api_service_form_value extends kolab_api_service
}
}
+ // no cn given then return empty
+ if (!trim($postdata['cn'])) {
+ return '';
+ }
+
+ // determine the @emaildomain part
+ $email_domain = '';
+ $at_index = strrpos($postdata['mail'], "@");
+ if (!(is_bool($at_index) && !$at_index)) {
+ $email_domain = substr($postdata['mail'], $at_index+1);
+ }
+
+ // if no email is set or domain isn't valid return empty
+ if (!$email_domain || !in_array($email_domain, $this->_get_valid_domains())) {
+ return '';
+ }
+
$cn = $postdata['cn'];
$imap_hierarchysep = '/';
- return $cn ? 'shared' . $imap_hierarchysep . $cn . '@' . $_SESSION['user']->get_domain() : '';
+ return $cn ? 'shared' . $imap_hierarchysep . $cn . '@' . $email_domain : '';
}
}
@@ -1316,6 +1333,32 @@ class kolab_api_service_form_value extends kolab_api_service
return 'OK';
}
+ private function validate_cn_sharedfolder($value, $postdata = array(), $validation_type = null)
+ {
+ if (preg_match('/["\']/',$value)) {
+ throw new Exception("Folder name contains invalid characters: \" ']");
+ }
+
+ return 'OK';
+ }
+
+ private function validate_kolabtargetfolder_sharedfolder($value, $postdata = array(), $validation_type = null)
+ {
+ if (preg_match('/["\'\+]/',$value)) {
+ throw new Exception("Target IMAP Folder contains invalid characters \" ' +");
+ }
+
+ $domains = $this->_get_valid_domains();
+ if (!preg_match('#^shared/[^"\'\\+]+@('.implode("|",$domains).')$#',$value)) {
+ throw new Exception("Target IMAP Folder has to match the following format: 'shared/foldername at mydomain.org'"&& folderpart == cn (other));
+ }
+
+ // TODO: check for duplicate shared folder
+ // same kolabTargetFolder && type = 'mail || type != mail && folderpart == cn (other)
+
+ return 'OK';
+ }
+
private function _list_options_members($postdata, $attribs = array())
{
// return specified records only, by exact DN attributes
@@ -1566,32 +1609,22 @@ class kolab_api_service_form_value extends kolab_api_service
return $valid;
}
- private function _validate_email_address_in_any_of_my_domains($mail_address)
+ private function _get_valid_domains($my_primary_domain = null)
{
- $at_index = strrpos($mail_address, "@");
- if (is_bool($at_index) && !$at_index) {
- throw new Exception("Invalid email address: No domain name space", 235);
- } else {
- $email_domain = substr($mail_address, $at_index+1);
- }
-
- $my_primary_domain = $_SESSION['user']->get_domain();
-
- if ($email_domain == $my_primary_domain) {
- return true;
- }
+ $my_primary_domain = $my_primary_domain !== null
+ ? $my_primary_domain
+ : $_SESSION['user']->get_domain();
$auth = Auth::get_instance();
$conf = Conf::get_instance();
$all_domains = $auth->list_domains();
$all_domains = $all_domains['list'];
- $valid_domains = array();
$dna = $conf->get('domain_name_attribute');
- $valid = false;
- Log::trace("_validate_email_address_in_any_of_mydomains(\$mail_address = " . var_export($mail_address, TRUE) . ")");
- Log::trace("\$all_domains includes: " . var_export($all_domains, TRUE) . " (must include domain for \$mail_address)");
+ Log::trace("__get_valid_domains( " . $my_primary_domain . ")");
+ Log::trace("\$all_domains includes: " . var_export($all_domains, TRUE) . " (must include domain for \$my_primary_domain)");
+ $valid_domains = array();
foreach ($all_domains as $domain_id => $domain_attrs) {
if (!is_array($domain_attrs[$dna])) {
$domain_attrs[$dna] = (array)($domain_attrs[$dna]);
@@ -1602,7 +1635,29 @@ class kolab_api_service_form_value extends kolab_api_service
}
}
- if (in_array($email_domain, $valid_domains)) {
+ return $valid_domains;
+ }
+
+ private function _validate_email_address_in_any_of_my_domains($mail_address)
+ {
+ $at_index = strrpos($mail_address, "@");
+ if (is_bool($at_index) && !$at_index) {
+ throw new Exception("Invalid email address: No domain name space", 235);
+ } else {
+ $email_domain = substr($mail_address, $at_index+1);
+ }
+
+ $my_primary_domain = $_SESSION['user']->get_domain();
+
+ if ($email_domain == $my_primary_domain) {
+ Log::trace("Found email address to be in one of my domains.");
+ return true;
+ }
+
+ $valid = false;
+ Log::trace("_validate_email_address_in_any_of_mydomains(\$mail_address = " . var_export($mail_address, TRUE) . ")");
+
+ if (in_array($email_domain, $this->_get_valid_domains())) {
$valid = true;
}
commit c49af8e285556d5c7ba27c30987c3633e952f4e1
Author: Daniel Hoffend <dh at dotlan.net>
Date: Wed Feb 18 00:14:27 2015 +0100
fixed cn creation
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index bd53f9c..3f40310 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -576,8 +576,8 @@ class kolab_api_service_form_value extends kolab_api_service
}
}
+ $cn = $postdata['cn'];
$imap_hierarchysep = '/';
- $cn = $this->generate_cn_resource($postdata, $attribs);
return $cn ? 'shared' . $imap_hierarchysep . $cn . '@' . $_SESSION['user']->get_domain() : '';
}
commit 4f264bed6b5e50741b653c5961280c2180680b03
Author: Daniel Hoffend <dh at dotlan.net>
Date: Mon Feb 16 23:44:11 2015 +0100
set kolabtargetfolder to generated based on cn
diff --git a/doc/kolab_wap.sql b/doc/kolab_wap.sql
index 871c130..1338ba4 100644
--- a/doc/kolab_wap.sql
+++ b/doc/kolab_wap.sql
@@ -179,7 +179,7 @@ CREATE TABLE `sharedfolder_types` (
LOCK TABLES `sharedfolder_types` WRITE;
/*!40000 ALTER TABLE `sharedfolder_types` DISABLE KEYS */;
-INSERT INTO `sharedfolder_types` VALUES (1,'addressbook','Shared Address Book','A shared address book','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"contact\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]}}',0),(2,'calendar','Shared Calendar','A shared calendar','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"event\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]}}',0),(3,'journal','Shared Journal','A shared journal','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"journal\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]}}',0),(4,'task','Shared Tasks','A shared tasks folder','{\"auto_form_fields\":[],\"fields\":{\"ko
labfoldertype\":[\"task\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]}}',0),(5,'note','Shared Notes','A shared Notes folder','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"note\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]}}',0),(6,'file','Shared Files','A shared Files folder','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"file\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]}}',0),(7,'mail','Shared Mail Folder','A shared mail folder','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"mail\"],\"objectclass\":[\"top\",\"kolabsharedfolder\",\"mailrecipient\"]},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"option
al\":true,\"default\":\"anyone, lrs\"},\"cn\":[],\"alias\":{\"type\":\"list\",\"optional\":true},\"kolabdelegate\":{\"type\":\"list\",\"autocomplete\":true,\"optional\":true},\"kolaballowsmtprecipient\":{\"type\":\"list\",\"optional\":true},\"kolaballowsmtpsender\":{\"type\":\"list\",\"optional\":true},\"kolabtargetfolder\":[],\"mail\":[]}}',0);
+INSERT INTO `sharedfolder_types` VALUES (1,'addressbook','Shared Address Book','A shared address book','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"contact\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]}}',0),(2,'calendar','Shared Calendar','A shared calendar','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"event\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]}}',0),(3,'journal','Shared Journal','A shared journal','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"journal\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]}}',0),(4,'task','Shared Tasks','A shared tasks folder','{\"auto_form_fields\":[],\"fields\":{\"ko
labfoldertype\":[\"task\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]}}',0),(5,'note','Shared Notes','A shared Notes folder','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"note\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]}}',0),(6,'file','Shared Files','A shared Files folder','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"file\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]}}',0),(7,'mail','Shared Mail Folder','A shared mail folder','{\"fields\":{\"objectclass\":[\"kolabsharedfolder\",\"mailrecipient\",\"top\"],\"kolabfoldertype\":\"mail\"},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"an
yone, lrs\"},\"alias\":{\"type\":\"list\",\"optional\":true},\"cn\":[],\"kolaballowsmtprecipient\":{\"type\":\"list\",\"optional\":true},\"kolaballowsmtpsender\":{\"type\":\"list\",\"optional\":true},\"kolabdelegate\":{\"type\":\"list\",\"autocomplete\":true,\"optional\":true},\"mail\":[]},\"auto_form_fields\":{\"kolabtargetfolder\":{\"data\":[\"cn\"]}}}',0);
/*!40000 ALTER TABLE `sharedfolder_types` ENABLE KEYS */;
UNLOCK TABLES;
commit f72cede2e6b4022e8fed43a0c694f933dae15ca6
Author: Daniel Hoffend <dh at dotlan.net>
Date: Mon Feb 16 23:42:09 2015 +0100
added generate_kolabtargetfolder_sharedfolder() for shared mailboxes
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 230cff6..bd53f9c 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -566,6 +566,23 @@ class kolab_api_service_form_value extends kolab_api_service
}
}
+ private function generate_kolabtargetfolder_sharedfolder($postdata, $attribs = array())
+ {
+ if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['kolabtargetfolder'])) {
+ // Use Data Please
+ foreach ($attribs['auto_form_fields']['kolabtargetfolder']['data'] as $key) {
+ if (!isset($postdata[$key])) {
+ throw new Exception("Key not set: " . $key, 12356);
+ }
+ }
+
+ $imap_hierarchysep = '/';
+ $cn = $this->generate_cn_resource($postdata, $attribs);
+
+ return $cn ? 'shared' . $imap_hierarchysep . $cn . '@' . $_SESSION['user']->get_domain() : '';
+ }
+ }
+
private function generate_kolabtargetfolder_resource($postdata, $attribs = array())
{
if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['kolabtargetfolder'])) {
More information about the commits
mailing list