4 commits - lib/api lib/client lib/kolab_api_service.php lib/locale
Jeroen van Meeuwen
vanmeeuwen at kolabsys.com
Tue Oct 30 17:07:50 CET 2012
lib/api/kolab_api_service_form_value.php | 133 ++++++++++++++++++++++++++++++-
lib/client/kolab_client_task_user.php | 5 +
lib/kolab_api_service.php | 16 +++
lib/locale/en_US.php | 5 +
4 files changed, 153 insertions(+), 6 deletions(-)
New commits:
commit 7f2df1a71edc03e45acc457e58b5097796dff298
Merge: 4ed5d8b 76b24b9
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Tue Oct 30 17:07:44 2012 +0100
Merge branch 'master' of ssh://git.kolab.org/git/kolab-wap
commit 4ed5d8bac6679405c00121b1a061b49f5f54d9cf
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Tue Oct 30 17:07:12 2012 +0100
Add functions to generate and validate Asterisk account attributes
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index fbd55fc..25c44b5 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -198,11 +198,11 @@ class kolab_api_service_form_value extends kolab_api_service
*/
public function validate($getdata, $postdata)
{
- //console("Executing validate() for \$getdata, \$postdata", $getdata, $postdata);
-
$attribs = $this->object_type_attributes($postdata['object_type'], $postdata['type_id']);
$result = array();
+ Log::trace("kolab_api_form_value::validate() \$postdata: " . var_export($postdata, TRUE));
+
foreach ((array)$postdata as $attr_name => $attr_value) {
if (empty($attr_name) || $attr_name == 'type_id' || $attr_name == 'object_type') {
continue;
@@ -222,16 +222,19 @@ class kolab_api_service_form_value extends kolab_api_service
}
if (array_key_exists($attr_name, $attribs['form_fields']) && !empty($attribs['form_fields'][$attr_name]['optional']) && !$attribs['form_fields'][$attr_name]['optional']) {
- $result[$attr_name] = $this->{$method_name}($attr_value);
+ $result[$attr_name] = $this->{$method_name}($attr_value, $postdata);
} else {
try {
- $result[$attr_name] = $this->{$method_name}($attr_value);
+ $result[$attr_name] = $this->{$method_name}($attr_value, $postdata);
} catch (Exception $e) {
Log::debug("Attribute $attr_name did not validate, but it is not a required attribute. Not saving. (Error was: $e)");
}
}
+
}
+ Log::trace("kolab_api_form_value::validate() \$result: " . var_export($result, TRUE));
+
return $result;
}
@@ -240,6 +243,115 @@ class kolab_api_service_form_value extends kolab_api_service
return $this->generate_secondary_mail($postdata, $attribs);
}
+ private function generate_astaccountcallerid($postdata, $attribs = array())
+ {
+ if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['astaccountcallerid'])) {
+ // Use Data Please
+ foreach ($attribs['auto_form_fields']['astaccountcallerid']['data'] as $key) {
+ if (!isset($postdata[$key])) {
+ throw new Exception("Key not set: " . $key, 12356);
+ }
+ }
+
+ // TODO: Correct this with what is in 'data'...
+ return $this->generate_cn($postdata, $attribs);
+ }
+ }
+
+ private function generate_astaccountdefaultuser($postdata, $attribs = array())
+ {
+ if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['astaccountdefaultuser'])) {
+ // Use Data Please
+ foreach ($attribs['auto_form_fields']['astaccountdefaultuser']['data'] as $key) {
+ if (!isset($postdata[$key])) {
+ throw new Exception("Key not set: " . $key, 12356);
+ }
+ }
+
+ return $this->generate_uid($postdata, $attribs);
+ }
+ }
+
+ private function generate_astaccountmailbox($postdata, $attribs = array())
+ {
+ if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['astaccountmailbox'])) {
+ // Use Data Please
+ foreach ($attribs['auto_form_fields']['astaccountmailbox']['data'] as $key) {
+ if (!isset($postdata[$key])) {
+ throw new Exception("Key not set: " . $key, 12356);
+ }
+ }
+
+ return $this->generate_uid($postdata, $attribs);
+ }
+ }
+
+ private function generate_astaccountregistrationcontext($postdata, $attribs = array())
+ {
+ if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['astaccountregistrationcontext'])) {
+ // Use Data Please
+ foreach ($attribs['auto_form_fields']['astaccountregistrationcontext']['data'] as $key) {
+ if (!isset($postdata[$key])) {
+ throw new Exception("Key not set: " . $key, 12356);
+ }
+ }
+
+ return $this->generate_uid($postdata, $attribs);
+ }
+ }
+
+ private function generate_astaccountregistrationexten($postdata, $attribs = array())
+ {
+ if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['astaccountregistrationexten'])) {
+ $search = array(
+ 'params' => array(
+ 'objectclass' => array(
+ 'type' => 'exact',
+ 'value' => 'asterisksipuser',
+ ),
+ ),
+ );
+
+ $auth = Auth::get_instance($_SESSION['user']->get_domain());
+ $conf = Conf::get_instance();
+ $users = $auth->list_users(NULL, Array('astaccountregistrationexten'), $search);
+
+ $lower_astaccountregistrationexten = $conf->get('astaccountregistrationexten_lower_barrier');
+ if (!$lower_astaccountregistrationexten) {
+ $lower_astaccountregistrationexten = 200;
+ }
+
+ // Start at the lower barrier + 1
+ $lower_astaccountregistrationexten = ($lower_astaccountregistrationexten + 1);
+
+ $higher_astaccountregistrationexten = $conf->get('astaccountregistrationexten_higher_barrier');
+ if (!$higher_astaccountregistrationexten) {
+ $higher_astaccountregistrationexten = 300;
+ }
+
+ $astaccountregistrationextens = Array();
+
+ foreach ($users['list'] as $dn => $attributes) {
+ if (!array_key_exists('astaccountregistrationexten', $attributes)) {
+ continue;
+ }
+
+ if ($attributes['astaccountregistrationexten'] > $highest_astaccountregistrationexten) {
+ $astaccountregistrationextens[] = $attributes['astaccountregistrationexten'];
+ }
+ }
+
+ for ($i = $lower_astaccountregistrationexten; $i < $higher_astaccountregistrationexten; $i++) {
+ if (!in_array($i, $astaccountregistrationextens)) {
+ $astaccountregistrationexten = $i;
+ break;
+ }
+ }
+
+ return $astaccountregistrationexten;
+ }
+ }
+
private function generate_cn($postdata, $attribs = array())
{
if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['cn'])) {
@@ -892,6 +1004,19 @@ class kolab_api_service_form_value extends kolab_api_service
}
+ private function validate_astaccountrealmedpassword($value, $postdata)
+ {
+ if (!array_key_exists('uid', $postdata) || empty($postdata['uid'])) {
+ $postdata['uid'] = $this->generate_uid($postdata);
+ }
+
+ $str = $postdata['uid'] . ":" . $_SESSION['user']->get_domain() . ":" . $postdata['userpassword'];
+
+ Log::trace("Inserting astaccountrealmedpassword with value md5('" . $str . "');");
+
+ return md5($str);
+ }
+
private function validate_mail($value)
{
$auth = Auth::get_instance();
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index a2eda00..ea62318 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -264,7 +264,17 @@ abstract class kolab_api_service
$form_service = $this->controller->get_service('form_value');
// With the result, start validating the input
- $form_service->validate(null, $attribs);
+ $validate_result = $form_service->validate(null, $attribs);
+
+ $special_attr_validate = Array();
+
+ foreach ($validate_result as $attr_name => $value) {
+ if (!empty($value) && $value !== "OK" && $value !== 0) {
+ $special_attr_validate[$attr_name] = $value;
+ }
+ }
+
+ Log::trace("kolab_api_service::parse_input_attributes() \$special_attr_validate: " . var_export($special_attr_validate, TRUE));
$result = array();
@@ -316,7 +326,9 @@ abstract class kolab_api_service
}
}
- Log::trace("parse_input_attributes result", $result);
+ $result = array_merge($result, $special_attr_validate);
+
+ Log::trace("parse_input_attributes result (merge of \$result and \$special_attr_validate)", $result);
return $result;
}
commit 24311b40a521fed384d5d26b297eb88a8088f5c3
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Mon Oct 29 19:24:01 2012 +0100
Add label text for Asterisk attributes
diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php
index 798deb0..ec9b3ca 100644
--- a/lib/locale/en_US.php
+++ b/lib/locale/en_US.php
@@ -203,17 +203,22 @@ $LANG['user.alias'] = 'Secondary Email Address(es)';
$LANG['user.astaccountallowedcodec'] = 'Allowed codec(s)';
$LANG['user.astaccountcallerid'] = 'Caller ID';
$LANG['user.astaccountcontext'] = 'Account Context';
+$LANG['user.astaccountdefaultuser'] = 'Asterisk Account Default User';
$LANG['user.astaccountdeny'] = 'Account deny';
$LANG['user.astaccounthost'] = 'Asterisk Host';
+$LANG['user.astaccountmailbox'] = 'Mailbox';
$LANG['user.astaccountnat'] = 'Account uses NAT';
$LANG['user.astaccountname'] = 'Asterisk Account Name';
$LANG['user.astaccountqualify'] = 'Account Qualify';
$LANG['user.astaccountrealmedpassword'] = 'Realmed Account Password';
+$LANG['user.astaccountregistrationexten'] = 'Extension';
+$LANG['user.astaccountregistrationcontext'] = 'Registration Context';
$LANG['user.astaccountsecret'] = 'Plaintext Password';
$LANG['user.astaccounttype'] = 'Account Type';
$LANG['user.astcontext'] = 'Asterisk Context';
$LANG['user.asterisk'] = 'Asterisk SIP';
$LANG['user.astextension'] = 'Asterisk Extension';
+$LANG['user.astvoicemailpassword'] = 'Voicemail PIN Code';
$LANG['user.c'] = 'Country';
$LANG['user.city'] = 'City';
$LANG['user.cn'] = 'Common name';
commit c259737b24851f75d5d7bc6f8b0d20714df66c21
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Mon Oct 29 19:23:34 2012 +0100
Add Asterisk attributes used to the correct pane
diff --git a/lib/client/kolab_client_task_user.php b/lib/client/kolab_client_task_user.php
index d67e7e3..166f8a5 100644
--- a/lib/client/kolab_client_task_user.php
+++ b/lib/client/kolab_client_task_user.php
@@ -275,16 +275,21 @@ class kolab_client_task_user extends kolab_client_task
'astaccountallowedcodec' => 'asterisk',
'astaccountcallerid' => 'asterisk',
'astaccountcontext' => 'asterisk',
+ 'astaccountdefaultuser' => 'asterisk',
'astaccountdeny' => 'asterisk',
'astaccounthost' => 'asterisk',
+ 'astaccountmailbox' => 'asterisk',
'astaccountnat' => 'asterisk',
'astaccountname' => 'asterisk',
'astaccountqualify' => 'asterisk',
'astaccountrealmedpassword' => 'asterisk',
+ 'astaccountregistrationexten' => 'asterisk',
+ 'astaccountregistrationcontext' => 'asterisk',
'astaccountsecret' => 'asterisk',
'astaccounttype' => 'asterisk',
'astcontext' => 'asterisk',
'astextension' => 'asterisk',
+ 'astvoicemailpassword' => 'asterisk',
);
// Prepare fields
More information about the commits
mailing list