added support for multiple AD

This commit is contained in:
SJ
2013-07-08 11:31:17 +02:00
parent d3073dd444
commit bc16df8778
24 changed files with 636 additions and 95 deletions

View File

@ -14,14 +14,21 @@ class ControllerDomainDomain extends Controller {
$request = Registry::get('request');
$db = Registry::get('db');
$ldap_id = 0;
$this->load->model('domain/domain');
if(ENABLE_SAAS == 1) {
$this->load->model('saas/ldap');
$this->data['ldap'] = $this->model_saas_ldap->get();
$ldap_id = $this->request->post['ldap_id'];
}
$this->document->title = $this->data['text_domain'];
$this->data['username'] = Registry::get('username');
$this->data['page'] = 0;
$this->data['page_len'] = get_page_length();
@ -54,7 +61,7 @@ class ControllerDomainDomain extends Controller {
if($this->request->server['REQUEST_METHOD'] == 'POST') {
if($this->validate() == true) {
if($this->model_domain_domain->addDomain($this->request->post['domain'], $this->request->post['mapped']) == 1) {
if($this->model_domain_domain->addDomain($this->request->post['domain'], $this->request->post['mapped'], $ldap_id) == 1) {
$this->data['x'] = $this->data['text_successfully_added'];
} else {
$this->template = "common/error.tpl";

View File

@ -0,0 +1,82 @@
<?php
class ControllerDomainDomains extends Controller {
private $error = array();
public function index(){
$this->id = "content";
$this->template = "domain/domains.tpl";
$this->layout = "common/layout-email";
$request = Registry::get('request');
$db = Registry::get('db');
$language = Registry::get('language');
$this->load->model('domain/domain');
//$this->document->title = $language->get('text_group_management');
$this->data['page'] = 0;
$this->data['page_len'] = get_page_length();
$this->data['total'] = 0;
$this->data['sort'] = 'domain';
$this->data['term'] = '';
if(!isset($this->request->get['term']) || strlen($this->request->get['term']) < 1) { die("no data"); }
if(isset($this->request->get['page']) && is_numeric($this->request->get['page']) && $this->request->get['page'] > 0) {
$this->data['page'] = $this->request->get['page'];
}
$this->data['search'] = $this->request->get['term'];
/* check if we are admin */
if(Registry::get('admin_user') == 1) {
// for autocomplete
if(strlen($this->request->get['term']) >= 2) {
$domains = $this->model_domain_domain->get_domains_by_string($this->request->get['term']);
$i = 0;
$s = '[ ';
foreach($domains as $domain) {
$i++;
$s .= '{ "id": "' . $i . '", "value": "' . $domain['domain'] . '" },';
}
$s = preg_replace("/,$/", "", $s) . " ]";
print $s;
}
// for domain list
if(strlen($this->request->get['term']) == 1) {
$this->data['domains'] = $this->model_domain_domain->get_domains_by_string($this->request->get['term'], $this->data['page'], $this->data['page_len']);
$this->data['total'] = $this->model_domain_domain->count_domains($this->request->get['term']);
$this->data['prev_page'] = $this->data['page'] - 1;
$this->data['next_page'] = $this->data['page'] + 1;
$this->data['total_pages'] = floor($this->data['total'] / $this->data['page_len']);
$this->render();
}
}
}
}
?>

View File

@ -0,0 +1,100 @@
<?php
class ControllerLdapList extends Controller {
private $error = array();
public function index(){
$this->id = "content";
$this->template = "ldap/list.tpl";
$this->layout = "common/layout";
$request = Registry::get('request');
$db = Registry::get('db');
$this->load->model('saas/ldap');
$this->document->title = $this->data['text_ldap'];
$this->data['username'] = Registry::get('username');
$this->data['page'] = 0;
$this->data['page_len'] = get_page_length();
$this->data['total'] = 0;
$this->data['entries'] = array();
/* check if we are admin */
if(Registry::get('admin_user') == 1) {
if($this->request->server['REQUEST_METHOD'] == 'POST') {
if($this->validate() == true) {
if($this->model_saas_ldap->add($this->request->post) == 1) {
$this->data['x'] = $this->data['text_successfully_added'];
} else {
$this->template = "common/error.tpl";
$this->data['errorstring'] = $this->data['text_failed_to_add'];
}
}
else {
$this->template = "common/error.tpl";
$this->data['errorstring'] = array_pop($this->error);
}
}
$this->data['entries'] = $this->model_saas_ldap->get();
}
else {
$this->template = "common/error.tpl";
$this->data['errorstring'] = $this->data['text_you_are_not_admin'];
}
$this->render();
}
private function validate() {
if(!isset($this->request->post['description']) || strlen($this->request->post['description']) < 1) {
$this->error['description'] = $this->data['text_invalid_data'];
}
if(!isset($this->request->post['ldap_host']) || strlen($this->request->post['ldap_host']) < 1) {
$this->error['ldap_host'] = $this->data['text_invalid_data'];
}
if(!isset($this->request->post['ldap_base_dn']) || strlen($this->request->post['ldap_base_dn']) < 1) {
$this->error['ldap_base_dn'] = $this->data['text_invalid_data'];
}
if(!isset($this->request->post['ldap_bind_dn']) || strlen($this->request->post['ldap_bind_dn']) < 1) {
$this->error['ldap_bind_dn'] = $this->data['text_invalid_data'];
}
if(!isset($this->request->post['ldap_bind_pw']) || strlen($this->request->post['ldap_bind_pw']) < 1) {
$this->error['ldap_bind_pw'] = $this->data['text_invalid_data'];
}
if (!$this->error) {
return true;
} else {
return false;
}
}
}
?>

View File

@ -0,0 +1,79 @@
<?php
class ControllerLdapRemove extends Controller {
private $error = array();
private $domains = array();
private $d = array();
public function index(){
$this->id = "content";
$this->template = "ldap/remove.tpl";
$this->layout = "common/layout";
$request = Registry::get('request');
$db = Registry::get('db');
$this->load->model('saas/ldap');
$this->document->title = $this->data['text_ldap'];
$this->data['username'] = Registry::get('username');
$this->data['id'] = $this->request->get['id'];
$this->data['description'] = $this->request->get['description'];
$this->data['confirmed'] = (int)$this->request->get['confirmed'];
if($this->validate() == true) {
if($this->data['confirmed'] == 1) {
$ret = $this->model_saas_ldap->delete($this->data['id'], $this->data['description']);
if($ret == 1){
$this->data['x'] = $this->data['text_successfully_removed'];
}
else {
$this->data['x'] = $this->data['text_failed_to_remove'];
}
}
}
else {
$this->template = "common/error.tpl";
$this->data['errorstring'] = array_pop($this->error);
}
$this->render();
}
private function validate() {
if(Registry::get('admin_user') == 0) {
$this->error['admin'] = $this->data['text_you_are_not_admin'];
}
if(!isset($this->request->get['description']) || strlen($this->request->get['description']) < 1) {
$this->error['description'] = $this->data['text_invalid_data'];
}
if(!isset($this->request->get['id']) || !is_numeric($this->request->get['id'])) {
$this->error['id'] = $this->data['text_invalid_data'];
}
if (!$this->error) {
return true;
} else {
return false;
}
}
}
?>

View File

@ -0,0 +1,37 @@
<?php
class ControllerLdapTest extends Controller {
private $error = array();
public function index(){
$this->id = "content";
$this->template = "ldap/list.tpl";
$this->layout = "common/layout";
$request = Registry::get('request');
$db = Registry::get('db');
$lang = Registry::get('language');
$ldap = new LDAP($this->request->post['ldap_host'], $this->request->post['ldap_bind_dn'], $this->request->post['ldap_bind_pw']);
if($ldap->is_bind_ok()) {
print "<span class=\"text-success\">" . $lang->data['text_connection_ok'] . "</span> ";
$query = $ldap->query($this->request->post['ldap_base_dn'], "(mail=*)", array());
if($query->num_rows < 1) {
print "<span class=\"text-error\">" . $lang->data['text_not_found_any_email_address'] . "</span> ";
}
}
else {
print "<span class=\"text-error\">" . $lang->data['text_connection_failed'] . "</span> ";
}
}
}
?>

View File

@ -26,6 +26,10 @@ class ControllerLoginLogin extends Controller {
$this->load->model('user/prefs');
$this->load->model('folder/folder');
if(ENABLE_SAAS == 1) {
$this->load->model('saas/ldap');
}
$this->document->title = $this->data['text_login'];
if($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate() == true) {