enhanced accounting

This commit is contained in:
SJ 2013-07-20 11:15:13 +02:00
parent 5b6d7d60a1
commit b36386676b
6 changed files with 167 additions and 61 deletions

View File

@ -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,16 +60,31 @@ 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) {

View File

@ -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();
}
}
?>

View File

@ -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);
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];
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;
}
}
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()) {

View File

@ -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);
}
?>

View File

@ -28,24 +28,34 @@
<tr>
<th colspan="3">&nbsp;</th>
<th colspan="3">Sent</th>
<th colspan="3">Received</th>
<th colspan="3"><?php print $text_sent; ?></th>
<th colspan="3"><?php print $text_received; ?></th>
</tr>
<tr>
<th><?php echo $viewname; ?> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=item&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=item&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<th>Oldest Record <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=oldest&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=oldest&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<th>Newest Record <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=newest&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=newest&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<th>Items <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=sent&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=sent&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<th>Size <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=sentsize&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=sentsize&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<th>Avg Size <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=sentavg&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=sentavg&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<th>Items <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=recd&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=recd&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<th>Size <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=recdsize&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=recdsize&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<th>Avg Size <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=recdavg&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=recdavg&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<?php if(ENABLE_SAAS == 1) { ?>
<th><?php print $text_users; ?></th>
<?php } ?>
<th><?php print $text_oldest_record; ?> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=oldest&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=oldest&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<th><?php print $text_newest_record; ?> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=newest&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=newest&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<th><?php print $text_items; ?> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=sent&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=sent&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<th><?php print $text_size; ?> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=sentsize&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=sentsize&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<th><?php print $text_average_size; ?> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=sentavg&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=sentavg&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<th><?php print $text_items; ?> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=recd&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=recd&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<th><?php print $text_size; ?> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=recdsize&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=recdsize&amp;order=1"><i class="icon-chevron-down"></i></a></th>
<th><?php print $text_average_size; ?> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=recdavg&amp;order=0"><i class="icon-chevron-up"></i></a> <a href="index.php?route=accounting/accounting&amp;view=<?php echo $view; ?>&amp;sort=recdavg&amp;order=1"><i class="icon-chevron-down"></i></a></th>
</tr>
<?php foreach($accounting as $details) {?>
<tr>
<td><?php echo $details['item']; ?></td>
<?php if(ENABLE_SAAS == 1) { ?>
<td><a href="index.php?route=accounting/accounting&amp;view=accounts&amp;domain=<?php echo $details['item']; ?>"><?php echo count($accounts[$details['item']]); ?></a></td>
<?php } ?>
<td><?php echo date("d M Y",$details['oldest']); ?></td>
<td><?php echo date("d M Y",$details['newest']); ?></td>
<td>
@ -84,6 +94,6 @@
<?php } else { ?>
<tr>
<td colspan='6'>No Emails Found</td>
<td colspan='6'><?php print $text_no_email_found; ?></td>
</tr>
<?php } ?>

View File

@ -0,0 +1,32 @@
<p>
<?php if ($view == 'email') { echo '<strong>'.$text_accounting_email.'</strong>'; } else { echo '<a href="index.php?route=accounting/accounting&amp;view=email">'.$text_accounting_email.'</a>'; } ?> |
<?php if ($view == 'domain') { echo '<strong>'.$text_accounting_domain.'</strong>'; } else { echo '<a href="index.php?route=accounting/accounting&amp;view=domain">'.$text_accounting_domain.'</a>'; } ?>
</p>
<p><a href="index.php?route=accounting/accounting&amp;view=domain"><?php print $text_back; ?></a></p>
<?php if(count($accounts) > 0) { ?>
<table class="table table-striped table-condensed">
<tr>
<th><?php echo $text_email; ?> (@<?php print $domain; ?>) </th>
</tr>
<?php foreach($accounts as $a) {?>
<tr>
<td><?php echo $a['mail']; ?></td>
</tr>
<?php } ?>
</table>
<?php } else { ?>
<tr>
<td><?php print $text_no_email_found; ?></td>
</tr>
<?php } ?>
<p><a href="index.php?route=accounting/accounting&amp;view=domain"><?php print $text_back; ?></a></p>