Projects
Kolab:3.4
kolab-webadmin
feature-autogenerate-kolabtargetfolder.patch
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File feature-autogenerate-kolabtargetfolder.patch of Package kolab-webadmin
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\":{\"kolabfoldertype\":[\"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\",\"optional\":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\":{\"kolabfoldertype\":[\"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\":\"anyone, 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; diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php index 230cff6..320acf9 100644 --- a/lib/api/kolab_api_service_form_value.php +++ b/lib/api/kolab_api_service_form_value.php @@ -566,6 +566,31 @@ 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); + } + } + + // no cn given then return empty + if (!trim($postdata['cn'])) { + return ''; + } + + // check format (will throw exception) + $this->validate_cn_sharedfolder($postdata['cn']); + + $cn = $postdata['cn']; + $imap_hierarchysep = '/'; + + 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'])) { @@ -1299,6 +1324,28 @@ 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) + { + $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@mydomain.org' and the foldername can't contain invalid characters: \" ' @ % + ^"); + } + + // 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 @@ -1549,32 +1596,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]); @@ -1585,7 +1622,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($my_primary_domain))) { $valid = true; }
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.