summaryrefslogtreecommitdiffstats
path: root/lib/api
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-03-15 12:14:39 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-03-15 12:14:39 +0100
commit563c2a12f101ff0e95a419729d3663bbe3ab2df1 (patch)
treef663ad8c472972ff5edb858e6455a069bf375a9a /lib/api
parenta15713bcbfcb7f232a9ef9470a8935b78fe8f62c (diff)
parent78d62915289072290ac0a3c1644ceb6127694699 (diff)
downloadwebadmin-563c2a12f101ff0e95a419729d3663bbe3ab2df1.tar.gz
Merge branch 'dev/recipient_policy'
Conflicts: lib/api/kolab_api_service_form_value.php
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/kolab_api_service_form_value.php111
1 files changed, 65 insertions, 46 deletions
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index d6d67f9..752057c 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -122,6 +122,10 @@ class kolab_api_service_form_value extends kolab_api_service
return $result;
}
+ private function generate_alias($postdata, $attribs = array())
+ {
+ return $this->generate_secondary_mail($postdata, $attribs);
+ }
private function generate_cn($postdata, $attribs = array())
{
@@ -133,6 +137,7 @@ class kolab_api_service_form_value extends kolab_api_service
}
}
+ // TODO: Generate using policy from configuration
$cn = trim($postdata['givenname'] . " " . $postdata['sn']);
return $cn;
@@ -149,11 +154,20 @@ class kolab_api_service_form_value extends kolab_api_service
}
}
+ // TODO: Generate using policy from configuration
$displayname = $postdata['givenname'];
if ($postdata['sn']) {
$displayname = $postdata['sn'] . ", " . $displayname;
}
+ // TODO: Figure out what may be sent as an additional comment;
+ //
+ // Examples:
+ //
+ // - van Meeuwen, Jeroen (Kolab Systems)
+ // - Doe, John (Contractor)
+ //
+
return $displayname;
}
}
@@ -179,60 +193,23 @@ class kolab_api_service_form_value extends kolab_api_service
}
}
- $uid = iconv('UTF-8', 'ASCII//TRANSLIT', $postdata['sn']);
- $uid = strtolower($uid);
- $uid = preg_replace('/[^a-z-_]/i', '', $uid);
-
- $orig_uid = $uid;
-
- $auth = Auth::get_instance($_SESSION['user']->get_domain());
-
- $x = 2;
- while ($auth->user_find_by_attribute(array('uid' => $uid))) {
- $uid = $orig_uid . $x;
- $x++;
- }
+ // TODO: Home directory attribute to use
+ $uid = $this->generate_uid($postdata, $attribs);
// TODO: Home directory base path from configuration?
+
return '/home/' . $uid;
}
}
private function generate_mail($postdata, $attribs = array())
{
- if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['mail'])) {
- // Use Data Please
- foreach ($attribs['auto_form_fields']['mail']['data'] as $key) {
- if (!isset($postdata[$key])) {
- throw new Exception("Key not set: " . $key, 12356);
- }
- }
-
- $givenname = iconv('UTF-8', 'ASCII//TRANSLIT', $postdata['givenname']);
- $sn = iconv('UTF-8', 'ASCII//TRANSLIT', $postdata['sn']);
-
- $givenname = strtolower($givenname);
- $sn = strtolower($sn);
-
- $givenname = preg_replace('/[^a-z-_]/i', '', $givenname);
- $sn = preg_replace('/[^a-z-_]/i', '', $sn);
-
- $local = trim($givenname . '.' . $sn, '.');
- $mail = $local . '@' . $_SESSION['user']->get_domain();
-
- $orig_mail = $mail;
-
- $auth = Auth::get_instance($_SESSION['user']->get_domain());
-
- $x = 2;
- while ($auth->user_find_by_attribute(array('mail' => $mail))) {
- list($mail_local, $mail_domain) = explode('@', $orig_mail);
- $mail = $mail_local . $x . '@' . $mail_domain;
- $x++;
- }
+ return $this->generate_primary_mail($postdata, $attribs);
+ }
- return $mail;
- }
+ private function generate_mailalternateaddress($postdata, $attribs = array())
+ {
+ return $this->generate_secondary_mail($postdata, $attribs);
}
private function generate_mailhost($postdata, $attribs = array())
@@ -245,6 +222,7 @@ class kolab_api_service_form_value extends kolab_api_service
private function generate_password($postdata, $attribs = array())
{
+ // TODO: Password complexity policy.
exec("head -c 200 /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c15", $userpassword_plain);
return $userpassword_plain[0];
}
@@ -254,6 +232,47 @@ class kolab_api_service_form_value extends kolab_api_service
return $this->generate_password($postdata, $attribs);
}
+ private function generate_primary_mail($postdata, $attribs = array())
+ {
+ if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['mail'])) {
+ // Use Data Please
+ foreach ($attribs['auto_form_fields']['mail']['data'] as $key) {
+ if (!isset($postdata[$key])) {
+ throw new Exception("Key not set: " . $key, 12356);
+ }
+ }
+
+ $primary_mail = kolab_recipient_policy::primary_mail($postdata);
+
+ return array('mail' => $primary_mail);
+ }
+ }
+
+ private function generate_secondary_mail($postdata, $attribs = array())
+ {
+ $secondary_mail_address = Array();
+
+ if (isset($attribs['auto_form_fields'])) {
+ if (isset($attribs['auto_form_fields']['alias'])) {
+ $secondary_mail_key = 'alias';
+ } elseif (isset($attribs['auto_form_fields']['mailalternateaddress'])) {
+ $secondary_mail_key = 'mailalternateaddress';
+ } else {
+ throw new Exception("No valid input for secondary mail address(es)", 478);
+ }
+
+ foreach ($attribs['auto_form_fields'][$secondary_mail_key]['data'] as $key) {
+ if (!isset($postdata[$key])) {
+ throw new Exception("Key not set: " . $key, 456789);
+ }
+ }
+
+ $secondary_mail = kolab_recipient_policy::secondary_mail($postdata);
+
+ return Array($secondary_mail_key => $secondary_mail);
+ }
+ }
+
private function generate_uid($postdata, $attribs = array())
{
if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['uid'])) {
@@ -264,6 +283,7 @@ class kolab_api_service_form_value extends kolab_api_service
}
}
+ // TODO: Use preferredlanguage
$uid = iconv('UTF-8', 'ASCII//TRANSLIT', $postdata['sn']);
$uid = strtolower($uid);
$uid = preg_replace('/[^a-z-_]/i', '', $uid);
@@ -288,7 +308,6 @@ class kolab_api_service_form_value extends kolab_api_service
$auth = Auth::get_instance($_SESSION['user']->get_domain());
// TODO: Actually poll $auth for users with a uidNumber set, and take the next one.
-
return 500;
}
}