From b36386676be7a498069bc69f86ce222d9b5bb6d2 Mon Sep 17 00:00:00 2001 From: SJ Date: Sat, 20 Jul 2013 11:15:13 +0200 Subject: [PATCH] enhanced accounting --- webui/controller/accounting/accounting.php | 29 +++++++--- webui/model/saas/ldap.php | 36 +++++++++++++ webui/model/user/auth.php | 54 ++++--------------- webui/system/misc.php | 43 +++++++++++++++ .../templates/accounting/accounting.tpl | 34 +++++++----- .../default/templates/accounting/accounts.tpl | 32 +++++++++++ 6 files changed, 167 insertions(+), 61 deletions(-) create mode 100644 webui/view/theme/default/templates/accounting/accounts.tpl diff --git a/webui/controller/accounting/accounting.php b/webui/controller/accounting/accounting.php index 683ab0c6..fa20d1c6 100644 --- a/webui/controller/accounting/accounting.php +++ b/webui/controller/accounting/accounting.php @@ -15,7 +15,9 @@ class ControllerAccountingAccounting extends Controller { $this->load->model('user/user'); $this->load->model('group/group'); $this->load->model('accounting/accounting'); - $counters = new ModelAccountingAccounting(); + if(ENABLE_SAAS == 1) { + $this->load->model('saas/ldap'); + } $this->data['page'] = 0; $this->data['page_len'] = get_page_length(); @@ -58,17 +60,32 @@ class ControllerAccountingAccounting extends Controller { if(@$this->request->get['view'] == "email") { $this->data['view'] = 'email'; $this->data['viewname'] = $this->data['text_email']; - $this->data['accounting'] = $counters->get_accounting('email',$this->data['search'], $this->data['page'], $this->data['page_len'], $this->data['sort'], $this->data['order']); - $this->data['total_records'] = $counters->count_accounting('email',$this->data['search']); + $this->data['accounting'] = $this->model_accounting_accounting->get_accounting('email',$this->data['search'], $this->data['page'], $this->data['page_len'], $this->data['sort'], $this->data['order']); + $this->data['total_records'] = $this->model_accounting_accounting->count_accounting('email',$this->data['search']); } if(@$this->request->get['view'] == "domain") { $this->data['view'] = 'domain'; $this->data['viewname'] = $this->data['text_domain']; - $this->data['accounting'] = $counters->get_accounting('domain',$this->data['search'], $this->data['page'], $this->data['page_len'], $this->data['sort'], $this->data['order']); - $this->data['total_records'] = $counters->count_accounting('domain',$this->data['search']); + $this->data['accounting'] = $this->model_accounting_accounting->get_accounting('domain',$this->data['search'], $this->data['page'], $this->data['page_len'], $this->data['sort'], $this->data['order']); + $this->data['total_records'] = $this->model_accounting_accounting->count_accounting('domain',$this->data['search']); + + if(ENABLE_SAAS == 1) { + $this->data['accounts'] = array(); + + foreach($this->data['accounting'] as $a) { + $this->data['accounts'][$a['item']] = $this->model_saas_ldap->get_accounts_in_domain($a['item']); + } + } } - + + if(@$this->request->get['view'] == "accounts" && isset($this->request->get['domain'])) { + $this->template = "accounting/accounts.tpl"; + $this->data['domain'] = $this->request->get['domain']; + $this->data['accounts'] = $this->model_saas_ldap->get_accounts_in_domain($this->request->get['domain']); + } + + if($this->data['accounting']) { foreach($this->data['accounting'] as $id=>$row) { if($this->data['sorttype'] == 0){ diff --git a/webui/model/saas/ldap.php b/webui/model/saas/ldap.php index 2ea7a16b..264757a3 100644 --- a/webui/model/saas/ldap.php +++ b/webui/model/saas/ldap.php @@ -55,6 +55,42 @@ class ModelSaasLdap extends Model return array(); } + + public function get_accounts_in_domain($domain = '') { + $ldap_type = ''; + $ldap_host = LDAP_HOST; + $ldap_base_dn = LDAP_BASE_DN; + $ldap_helper_dn = LDAP_HELPER_DN; + $ldap_helper_password = LDAP_HELPER_PASSWORD; + + if(ENABLE_SAAS == 1) { + $a = $this->model_saas_ldap->get_ldap_params_by_email("aaa@" . $domain); + + if(count($a) >= 5) { + $ldap_type = $a[0]; + $ldap_host = $a[1]; + $ldap_base_dn = $a[2]; + $ldap_helper_dn = $a[3]; + $ldap_helper_password = $a[4]; + } + } + + list($ldap_mail_attr, $ldap_account_objectclass, $ldap_distributionlist_attr, $ldap_distributionlist_objectclass) = get_ldap_attribute_names($ldap_type); + + if($ldap_host == '' || $ldap_helper_password == '') { return array(); } + + $ldap = new LDAP($ldap_host, $ldap_helper_dn, $ldap_helper_password); + + if($ldap->is_bind_ok()) { + + $query = $ldap->query($ldap_base_dn, "(&(objectClass=$ldap_account_objectclass)($ldap_mail_attr=*@$domain))", array($ldap_mail_attr)); + + if($query->num_rows > 0) { asort($query->rows); return $query->rows; } + } + + return array(); + } + } ?> diff --git a/webui/model/user/auth.php b/webui/model/user/auth.php index b4473f0e..e9e0514c 100644 --- a/webui/model/user/auth.php +++ b/webui/model/user/auth.php @@ -62,60 +62,28 @@ class ModelUserAuth extends Model { private function checkLoginAgainstLDAP($username = '', $password = '') { - + $ldap_type = ''; $ldap_host = LDAP_HOST; $ldap_base_dn = LDAP_BASE_DN; $ldap_helper_dn = LDAP_HELPER_DN; $ldap_helper_password = LDAP_HELPER_PASSWORD; - $ldap_mail_attr = LDAP_MAIL_ATTR; - $ldap_account_objectclass = LDAP_ACCOUNT_OBJECTCLASS; - $ldap_distributionlist_attr = LDAP_DISTRIBUTIONLIST_ATTR; - $ldap_distributionlist_objectclass = LDAP_DISTRIBUTIONLIST_OBJECTCLASS; - if(ENABLE_SAAS == 1) { $a = $this->model_saas_ldap->get_ldap_params_by_email($username); - $ldap_type = $a[0]; - $ldap_host = $a[1]; - $ldap_base_dn = $a[2]; - $ldap_helper_dn = $a[3]; - $ldap_helper_password = $a[4]; - - switch ($ldap_type) { - - case 'AD': - $ldap_mail_attr = 'mail'; - $ldap_account_objectclass = 'user'; - $ldap_distributionlist_attr = 'member'; - $ldap_distributionlist_objectclass = 'group'; - break; - - case 'zimbra': - $ldap_mail_attr = 'mail'; - $ldap_account_objectclass = 'zimbraAccount'; - $ldap_distributionlist_attr = 'zimbraMailForwardingAddress'; - $ldap_distributionlist_objectclass = 'zimbraDistributionList'; - break; - - case 'iredmail': - $ldap_mail_attr = 'mail'; - $ldap_account_objectclass = 'mailUser'; - $ldap_distributionlist_attr = 'memberOfGroup'; - $ldap_distributionlist_objectclass = 'mailList'; - break; - - case 'lotus': - $ldap_mail_attr = 'mail'; - $ldap_account_objectclass = 'dominoPerson'; - $ldap_distributionlist_attr = 'mail'; - $ldap_distributionlist_objectclass = 'dominoGroup'; - break; - - + if(count($a) >= 5) { + $ldap_type = $a[0]; + $ldap_host = $a[1]; + $ldap_base_dn = $a[2]; + $ldap_helper_dn = $a[3]; + $ldap_helper_password = $a[4]; } } + list($ldap_mail_attr, $ldap_account_objectclass, $ldap_distributionlist_attr, $ldap_distributionlist_objectclass) = get_ldap_attribute_names($ldap_type); + + if($ldap_host == '' || $ldap_helper_password == '') { return 0; } + $ldap = new LDAP($ldap_host, $ldap_helper_dn, $ldap_helper_password); if($ldap->is_bind_ok()) { diff --git a/webui/system/misc.php b/webui/system/misc.php index 57ec6021..f5b29045 100644 --- a/webui/system/misc.php +++ b/webui/system/misc.php @@ -492,5 +492,48 @@ function safe_feof($fp, &$start = NULL) { } +function get_ldap_attribute_names($ldap_type = '') { + + $ldap_mail_attr = LDAP_MAIL_ATTR; + $ldap_account_objectclass = LDAP_ACCOUNT_OBJECTCLASS; + $ldap_distributionlist_attr = LDAP_DISTRIBUTIONLIST_ATTR; + $ldap_distributionlist_objectclass = LDAP_DISTRIBUTIONLIST_OBJECTCLASS; + + switch ($ldap_type) { + + case 'AD': + $ldap_mail_attr = 'mail'; + $ldap_account_objectclass = 'user'; + $ldap_distributionlist_attr = 'member'; + $ldap_distributionlist_objectclass = 'group'; + break; + + case 'zimbra': + $ldap_mail_attr = 'mail'; + $ldap_account_objectclass = 'zimbraAccount'; + $ldap_distributionlist_attr = 'zimbraMailForwardingAddress'; + $ldap_distributionlist_objectclass = 'zimbraDistributionList'; + break; + + case 'iredmail': + $ldap_mail_attr = 'mail'; + $ldap_account_objectclass = 'mailUser'; + $ldap_distributionlist_attr = 'memberOfGroup'; + $ldap_distributionlist_objectclass = 'mailList'; + break; + + case 'lotus': + $ldap_mail_attr = 'mail'; + $ldap_account_objectclass = 'dominoPerson'; + $ldap_distributionlist_attr = 'mail'; + $ldap_distributionlist_objectclass = 'dominoGroup'; + break; + + + } + + return array($ldap_mail_attr, $ldap_account_objectclass, $ldap_distributionlist_attr, $ldap_distributionlist_objectclass); +} + ?> diff --git a/webui/view/theme/default/templates/accounting/accounting.tpl b/webui/view/theme/default/templates/accounting/accounting.tpl index 9463911e..67acbf4f 100644 --- a/webui/view/theme/default/templates/accounting/accounting.tpl +++ b/webui/view/theme/default/templates/accounting/accounting.tpl @@ -28,24 +28,34 @@   - Sent - Received + + - Oldest Record - Newest Record - Items - Size - Avg Size - Items - Size - Avg Size + + + + + + + + + + + + + + + + + + @@ -84,6 +94,6 @@ - No Emails Found + - \ No newline at end of file + diff --git a/webui/view/theme/default/templates/accounting/accounts.tpl b/webui/view/theme/default/templates/accounting/accounts.tpl new file mode 100644 index 00000000..ecd2b0fa --- /dev/null +++ b/webui/view/theme/default/templates/accounting/accounts.tpl @@ -0,0 +1,32 @@ + +

+'.$text_accounting_email.''; } else { echo ''.$text_accounting_email.''; } ?> | +'.$text_accounting_domain.''; } else { echo ''.$text_accounting_domain.''; } ?> +

+ +

+ + 0) { ?> + + + + + + + + + + + + +
(@)
+ + + + + + + +

+ +