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

@ -16,8 +16,9 @@ piler's crontab:
### mandatory
*/5 * * * * LC_ALL=C mpstat | tail -1 | awk '{print $11}' > /var/piler/stat/cpu.stat
*/15 * * * * /usr/local/bin/indexer --quiet delta1 --rotate && sleep 2 && /usr/local/bin/indexer --quiet --merge main1 delta1 --merge-dst-range deleted 0 0 --rotate
*/5 * * * * LC_ALL=C mpstat | tail -1 | awk '{print $11}' > /var/piler/stat/cpu.stat
5,35 2-23 * * * /usr/local/bin/indexer --quiet delta1 --rotate && sleep 2 && /usr/local/bin/indexer --quiet --merge dailydelta1 delta1 --merge-dst-range deleted 0 0 --rotate
15 0 * * * /usr/local/bin/indexer --quiet --merge main1 dailydelta1 --merge-dst-range deleted 0 0 --rotate && sleep 2 && /usr/local/bin/indexer --quiet dailydelta1 --rotate
*/15 * * * * /usr/local/bin/indexer --quiet tag1 --rotate
*/15 * * * * /usr/local/bin/indexer --quiet note1 --rotate

View File

@ -53,6 +53,12 @@ source main4 : base
sql_query = SELECT id, `from`, `to`, `fromdomain`, `todomain`, `subject`, `arrived`, `sent`, `body`, `size`, `direction`, `folder`, `attachments`, `attachment_types` FROM sph_index WHERE id=-1;
}
source dailydelta : base
{
sql_query_pre = SET NAMES utf8
sql_query = SELECT id, `from`, `to`, `fromdomain`, `todomain`, `subject`, `arrived`, `sent`, `body`, `size`, `direction`, `folder`, `attachments`, `attachment_types` FROM sph_index WHERE id=-1;
}
source tag : base
{
sql_query_pre = SET NAMES utf8
@ -120,6 +126,17 @@ index main4
min_word_len = 1
}
index dailydelta1
{
source = dailydelta
path = /var/piler/sphinx/dailydelta1
docinfo = extern
charset_type = utf-8
enable_star = 1
min_prefix_len = 6
min_word_len = 1
}
index delta1
{
source = delta

View File

@ -24,6 +24,8 @@ $config['THEME'] = 'default';
$config['SITE_NAME'] = 'piler.yourdomain.com';
$config['SITE_URL'] = 'http://piler.yourdomain.com/';
$config['ENABLE_SAAS'] = 0;
$config['TIMEZONE'] = 'Europe/Budapest';
$config['PROVIDED_BY'] = 'www.mailpiler.org';
@ -147,7 +149,7 @@ $config['DB_DATABASE'] = 'piler';
$config['SPHINX_DRIVER'] = 'sphinx';
$config['SPHINX_DATABASE'] = 'sphinx';
$config['SPHINX_HOSTNAME'] = '127.0.0.1:9306';
$config['SPHINX_MAIN_INDEX'] = 'main1,main2,main3,main4';
$config['SPHINX_MAIN_INDEX'] = 'dailydelta1,main1,main2,main3,main4';
$config['SPHINX_TAG_INDEX'] = 'tag1';
$config['SPHINX_NOTE_INDEX'] = 'note1';
@ -255,6 +257,7 @@ define('TABLE_AUDIT', 'audit');
define('TABLE_ARCHIVING_RULE', 'archiving_rule');
define('TABLE_RETENTION_RULE', 'retention_rule');
define('TABLE_OPTION', 'option');
define('TABLE_LDAP', 'ldap');
define('TABLE_GOOGLE', 'google');
define('TABLE_GOOGLE_IMAP', 'google_imap');
define('VIEW_MESSAGES', 'v_messages');

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) {

View File

@ -1,13 +1,5 @@
<?php
function go_to_setup() {
Header("Location: setup/setup.php");
exit;
}
$stat = stat("config.php") or go_to_setup();
if($stat[7] < 15){ go_to_setup(); }
session_start();

View File

@ -6,6 +6,7 @@ $_['text_active_incoming_queue_sender'] = "Aktive + Eingangswarteschlange zu Abs
$_['text_ad_sync_status'] = "Status AD-Synchronisation";
$_['text_add'] = "Hinzufügen";
$_['text_add_new_email_address'] = "Neue E-Mail-Adresse";
$_['text_add_new_entry'] = "New entry";
$_['text_add_new_domain'] = "Neue Domäne";
$_['text_add_new_group'] = "Gruppe hinzufügen";
$_['text_add_new_rule'] = "Regel hinzufügen";
@ -39,6 +40,8 @@ $_['text_clienthost'] = "Clientrechner";
$_['text_close'] = "Schließen";
$_['text_compressed'] = "komprimiert";
$_['text_confirm_to_reset_counters'] = "Zurücksetzen des Zählers bestätigen";
$_['text_connection_failed'] = "Connection failed";
$_['text_connection_ok'] = "Connection OK";
$_['text_content_filter'] = "Inhaltsfilter";
$_['text_conversation_available'] = "Zugehörige Nachrichten vorhanden";
$_['text_copied'] = "Kopiert";
@ -99,6 +102,7 @@ $_['text_exact_domain_name_or_email_address'] = "Genauer Domänenname oder E-Mai
$_['text_exclude'] = "Ausschließen";
$_['text_existing_domains'] = "Vorhandene Domänen";
$_['text_existing_email'] = "Vorhandene E-Mail";
$_['text_existing_entries'] = "Existing entries";
$_['text_existing_folders'] = "Vorhandene Ordner";
$_['text_existing_groups'] = "Vorhandene Gruppen";
$_['text_existing_policies'] = "Vorhandene Methoden";
@ -157,9 +161,10 @@ $_['text_language'] = "Sprache";
$_['text_last'] = "Letzte";
$_['text_last_update'] = "Letzte Aktualisierung";
$_['text_latest_emails'] = "Letzte Nachrichten";
$_['text_ldap_basedn'] = "LDAP-Basis-DN";
$_['text_ldap_binddn'] = "LDAP-Anmelde-DN";
$_['text_ldap_bindpw'] = "LDAP-Anmelde-Passwort";
$_['text_ldap'] = "LDAP";
$_['text_ldap_base_dn'] = "LDAP-Basis-DN";
$_['text_ldap_bind_dn'] = "LDAP-Anmelde-DN";
$_['text_ldap_bind_pw'] = "LDAP-Anmelde-Passwort";
$_['text_ldap_host'] = "LDAP-Host";
$_['text_ldap_type'] = "LDAP-Typ";
$_['text_load'] = "Laden";
@ -303,6 +308,7 @@ $_['text_swap_usage'] = "Auslagerungsspeicher";
$_['text_tag_selected_messages'] = "Ausgewählte Nachrichten kategorisieren";
$_['text_tagged'] = "Kategorisiert";
$_['text_tags'] = "Kategorie(n)";
$_['text_test_connection'] = "Test connection";
$_['text_text'] = "Text";
$_['text_text2'] = "Nachricht";
$_['text_theme'] = "Thema";

View File

@ -7,6 +7,7 @@ $_['text_ad_sync_status'] = "AD synchronisation status";
$_['text_add'] = "Add";
$_['text_add_new_email_address'] = "New email address";
$_['text_add_new_domain'] = "New domain";
$_['text_add_new_entry'] = "New entry";
$_['text_add_new_group'] = "Add group";
$_['text_add_new_rule'] = "Add rule";
$_['text_add_new_user_alias'] = "Add new user";
@ -39,6 +40,8 @@ $_['text_clienthost'] = "Client host";
$_['text_close'] = "Close";
$_['text_compressed'] = "compressed";
$_['text_confirm_to_reset_counters'] = "Confirm to reset counters";
$_['text_connection_failed'] = "Connection failed";
$_['text_connection_ok'] = "Connection OK";
$_['text_content_filter'] = "Content filter";
$_['text_conversation_available'] = "Conversation available";
$_['text_copied'] = "Copied";
@ -102,6 +105,7 @@ $_['text_existing_email'] = "Existing email";
$_['text_existing_folders'] = "Existing folders";
$_['text_existing_groups'] = "Existing groups";
$_['text_existing_policies'] = "Existing policies";
$_['text_existing_entries'] = "Existing entries";
$_['text_existing_rules'] = "Existing rules";
$_['text_existing_user'] = "Existing user";
$_['text_existing_users'] = "Existing users";
@ -157,9 +161,10 @@ $_['text_language'] = "Language";
$_['text_last'] = "Last";
$_['text_last_update'] = "Last update";
$_['text_latest_emails'] = "Latest emails";
$_['text_ldap_basedn'] = "LDAP base DN";
$_['text_ldap_binddn'] = "LDAP bind DN";
$_['text_ldap_bindpw'] = "LDAP bind password";
$_['text_ldap'] = "LDAP";
$_['text_ldap_base_dn'] = "LDAP base DN";
$_['text_ldap_bind_dn'] = "LDAP bind DN";
$_['text_ldap_bind_pw'] = "LDAP bind password";
$_['text_ldap_host'] = "LDAP host";
$_['text_ldap_type'] = "LDAP type";
$_['text_load'] = "Load";
@ -303,6 +308,7 @@ $_['text_swap_usage'] = "Swap usage";
$_['text_tag_selected_messages'] = "Tag selected messages";
$_['text_tagged'] = "Tagged";
$_['text_tags'] = "Tags";
$_['text_test_connection'] = "Test connection";
$_['text_text'] = "Text";
$_['text_text2'] = "text";
$_['text_theme'] = "Theme";

View File

@ -6,6 +6,7 @@ $_['text_active_incoming_queue_sender'] = "akt
$_['text_ad_sync_status'] = "AD szinkronizáció státusz";
$_['text_add'] = "Felvesz";
$_['text_add_new_email_address'] = "Új email cím";
$_['text_add_new_entry'] = "Új bejegyzés";
$_['text_add_new_domain'] = "Új domain";
$_['text_add_new_group'] = "Új csoport";
$_['text_add_new_rule'] = "Új szabály";
@ -39,6 +40,8 @@ $_['text_clienthost'] = "Kliens g
$_['text_close'] = "Bezár";
$_['text_compressed'] = "tömörített";
$_['text_confirm_to_reset_counters'] = "Számlálók nullázásának megerősítése";
$_['text_connection_failed'] = "Sikertelen kapcsolat";
$_['text_connection_ok'] = "Sikeres kapcsolat";
$_['text_content_filter'] = "Tartalomszűrő";
$_['text_conversation_available'] = "Levélváltás elérhető";
$_['text_copied'] = "Átmásolva";
@ -99,6 +102,7 @@ $_['text_exact_domain_name_or_email_address'] = "pontos domainn
$_['text_exclude'] = "Kihagy";
$_['text_existing_domains'] = "Létező domainek";
$_['text_existing_email'] = "Létező email";
$_['text_existing_entries'] = "Jelenlegi bejegyzések";
$_['text_existing_groups'] = "Létező mappák";
$_['text_existing_groups'] = "Létező csoportok";
$_['text_existing_policies'] = "Létező házirendek";
@ -158,9 +162,10 @@ $_['text_language'] = "Nyelv";
$_['text_last'] = "Utolsó";
$_['text_latest_emails'] = "Legfrissebb emailek";
$_['text_last_update'] = "Utolsó frissítés";
$_['text_ldap_basedn'] = "LDAP alapértelmezett DN";
$_['text_ldap_binddn'] = "LDAP csatlakozási DN";
$_['text_ldap_bindpw'] = "LDAP csatlakozási jelszó";
$_['text_ldap'] = "LDAP";
$_['text_ldap_base_dn'] = "LDAP alapértelmezett DN";
$_['text_ldap_bind_dn'] = "LDAP csatlakozási DN";
$_['text_ldap_bind_pw'] = "LDAP csatlakozási jelszó";
$_['text_ldap_host'] = "LDAP kiszolgáló";
$_['text_ldap_type'] = "LDAP típus";
$_['text_load'] = "Betöltés";
@ -304,6 +309,7 @@ $_['text_swap_usage'] = "Swap haszn
$_['text_tag_selected_messages'] = "Kijelölt üzenetek címkézése";
$_['text_tagged'] = "Címkézve";
$_['text_tags'] = "Címkék";
$_['text_test_connection'] = "Kapcsolat tesztelése";
$_['text_text'] = "Szöveg";
$_['text_text2'] = "szöveg";
$_['text_theme'] = "Stílus";

View File

@ -6,6 +6,7 @@ $_['text_active_incoming_queue_sender'] = "aktív + bejövő üzenetsor (feladó
$_['text_ad_sync_status'] = "AD szinkronizáció státusz";
$_['text_add'] = "Felvesz";
$_['text_add_new_email_address'] = "Új email cím";
$_['text_add_new_entry'] = "Új bejegyzés";
$_['text_add_new_domain'] = "Új domain";
$_['text_add_new_group'] = "Új csoport";
$_['text_add_new_rule'] = "Új szabály";
@ -39,6 +40,8 @@ $_['text_clienthost'] = "Kliens gép";
$_['text_close'] = "Bezár";
$_['text_compressed'] = "tömörített";
$_['text_confirm_to_reset_counters'] = "Számlálók nullázásának megerősítése";
$_['text_connection_failed'] = "Sikertelen kapcsolat";
$_['text_connection_ok'] = "Sikeres kapcsolat";
$_['text_content_filter'] = "Tartalomszűrő";
$_['text_conversation_available'] = "Levélváltás elérhető";
$_['text_copied'] = "Átmásolva";
@ -99,6 +102,7 @@ $_['text_exact_domain_name_or_email_address'] = "pontos domainnév vagy email c
$_['text_exclude'] = "Kihagy";
$_['text_existing_domains'] = "Létező domainek";
$_['text_existing_email'] = "Létező email";
$_['text_existing_entries'] = "Jelenlegi bejegyzések";
$_['text_existing_groups'] = "Létező mappák";
$_['text_existing_groups'] = "Létező csoportok";
$_['text_existing_policies'] = "Létező házirendek";
@ -158,9 +162,10 @@ $_['text_language'] = "Nyelv";
$_['text_last'] = "Utolsó";
$_['text_latest_emails'] = "Legfrissebb emailek";
$_['text_last_update'] = "Utolsó frissítés";
$_['text_ldap_basedn'] = "LDAP alapértelmezett DN";
$_['text_ldap_binddn'] = "LDAP csatlakozási DN";
$_['text_ldap_bindpw'] = "LDAP csatlakozási jelszó";
$_['text_ldap'] = "LDAP";
$_['text_ldap_base_dn'] = "LDAP alapértelmezett DN";
$_['text_ldap_bind_dn'] = "LDAP csatlakozási DN";
$_['text_ldap_bind_pw'] = "LDAP csatlakozási jelszó";
$_['text_ldap_host'] = "LDAP kiszolgáló";
$_['text_ldap_type'] = "LDAP típus";
$_['text_load'] = "Betöltés";
@ -304,6 +309,7 @@ $_['text_swap_usage'] = "Swap használat";
$_['text_tag_selected_messages'] = "Kijelölt üzenetek címkézése";
$_['text_tagged'] = "Címkézve";
$_['text_tags'] = "Címkék";
$_['text_test_connection'] = "Kapcsolat tesztelése";
$_['text_text'] = "Szöveg";
$_['text_text2'] = "szöveg";
$_['text_theme'] = "Stílus";

View File

@ -3,12 +3,26 @@
class ModelDomainDomain extends Model {
public function getDomains() {
$data = array();
$query = $this->db->query("SELECT domain, mapped FROM " . TABLE_DOMAIN . " ORDER BY domain ASC");
$query = $this->db->query("SELECT domain, mapped, ldap_id FROM " . TABLE_DOMAIN . " ORDER BY domain ASC");
if(isset($query->rows)) { return $query->rows; }
if(isset($query->rows)) {
foreach($query->rows as $q) {
return array();
$ldap = '';
if($q['ldap_id'] > 0) {
$query2 = $this->db->query("SELECT description FROM " . TABLE_LDAP . " WHERE id=?", array($q['ldap_id']));
if(isset($query2->row)) { $ldap = $query2->row['description']; }
}
$data[] = array('domain' => $q['domain'], 'mapped' => $q['mapped'], 'ldap' => $ldap);
}
}
return $data;
}
@ -38,14 +52,14 @@ class ModelDomainDomain extends Model {
}
public function addDomain($domain = '', $mapped = '') {
public function addDomain($domain = '', $mapped = '', $ldap_id = 0) {
if($domain == "" || $mapped == "") { return 0; }
$domains = explode("\n", $domain);
foreach ($domains as $domain) {
$domain = rtrim($domain);
$query = $this->db->query("INSERT INTO " . TABLE_DOMAIN . " (domain, mapped) VALUES (?,?)", array($domain, $mapped));
$query = $this->db->query("INSERT INTO " . TABLE_DOMAIN . " (domain, mapped, ldap_id) VALUES (?,?,?)", array($domain, $mapped, $ldap_id));
$rc = $this->db->countAffected();

60
webui/model/saas/ldap.php Normal file
View File

@ -0,0 +1,60 @@
<?php
class ModelSaasLdap extends Model
{
public function get() {
$query = $this->db->query("SELECT id, description, ldap_host, ldap_base_dn, ldap_bind_dn FROM " . TABLE_LDAP . " ORDER BY description ASC");
if($query->num_rows > 0) { return $query->rows; }
return array();
}
public function delete($id = 0, $description = '') {
if($id == 0) { return 0; }
$query = $this->db->query("DELETE FROM " . TABLE_LDAP . " WHERE id=?", array($id));
$rc = $this->db->countAffected();
LOGGER("remove ldap entry: #$id, $description (rc=$rc)");
return $rc;
}
public function add($arr = array()) {
if(!isset($arr['description']) || !isset($arr['ldap_host'])) { return 0; }
$query = $this->db->query("INSERT INTO " . TABLE_LDAP . " (description, ldap_host, ldap_base_dn, ldap_bind_dn, ldap_bind_pw) VALUES (?,?,?,?,?)", array($arr['description'], $arr['ldap_host'], $arr['ldap_base_dn'], $arr['ldap_bind_dn'], $arr['ldap_bind_pw']));
$rc = $this->db->countAffected();
LOGGER("add ldap entry: " . $arr['description'] . " / " . $arr['ldap_host'] . " / " . $arr['ldap_base_dn'] . " (rc=$rc)");
if($rc == 1){ return 1; }
return 0;
}
public function get_ldap_params_by_email($email = '') {
$domain = '';
if($email == '') { return array(); }
list($l,$d) = explode("@", $email);
$query = $this->db->query("SELECT ldap_host, ldap_base_dn, ldap_bind_dn, ldap_bind_pw from " . TABLE_DOMAIN . " as d, " . TABLE_LDAP . " as l where d.ldap_id=l.id and d.domain=?", array($d));
if($query->num_rows > 0) { return array($query->row['ldap_host'], $query->row['ldap_base_dn'], $query->row['ldap_bind_dn'], $query->row['ldap_bind_pw']); }
return array();
}
}
?>

View File

@ -63,22 +63,36 @@ class ModelUserAuth extends Model {
private function checkLoginAgainstLDAP($username = '', $password = '') {
$ldap = new LDAP(LDAP_HOST, LDAP_HELPER_DN, LDAP_HELPER_PASSWORD);
$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($username);
$ldap_host = $a[0];
$ldap_base_dn = $a[1];
$ldap_helper_dn = $a[2];
$ldap_helper_password = $a[3];
}
$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 . "=$username))", array());
$query = $ldap->query($ldap_base_dn, "(&(objectClass=" . LDAP_ACCOUNT_OBJECTCLASS . ")(" . LDAP_MAIL_ATTR . "=$username))", array());
if(isset($query->row['dn']) && $query->row['dn']) {
$a = $query->row;
$ldap_auth = new LDAP(LDAP_HOST, $a['dn'], $password);
$ldap_auth = new LDAP($ldap_host, $a['dn'], $password);
if(ENABLE_SYSLOG == 1) { syslog(LOG_INFO, "ldap auth against '" . LDAP_HOST . "', dn: '" . $a['dn'] . "', result: " . $ldap_auth->is_bind_ok()); }
if(ENABLE_SYSLOG == 1) { syslog(LOG_INFO, "ldap auth against '" . $ldap_host . "', dn: '" . $a['dn'] . "', result: " . $ldap_auth->is_bind_ok()); }
if($ldap_auth->is_bind_ok()) {
$query = $ldap->query(LDAP_BASE_DN, "(|(&(objectClass=" . LDAP_ACCOUNT_OBJECTCLASS . ")(" . LDAP_MAIL_ATTR . "=$username))(&(objectClass=" . LDAP_DISTRIBUTIONLIST_OBJECTCLASS . ")(" . LDAP_DISTRIBUTIONLIST_ATTR . "=$username)" . ")(&(objectClass=" . LDAP_DISTRIBUTIONLIST_OBJECTCLASS . ")(" . LDAP_DISTRIBUTIONLIST_ATTR . "=" . stripslashes($a['dn']) . ")))", array());
$query = $ldap->query($ldap_base_dn, "(|(&(objectClass=" . LDAP_ACCOUNT_OBJECTCLASS . ")(" . LDAP_MAIL_ATTR . "=$username))(&(objectClass=" . LDAP_DISTRIBUTIONLIST_OBJECTCLASS . ")(" . LDAP_DISTRIBUTIONLIST_ATTR . "=$username)" . ")(&(objectClass=" . LDAP_DISTRIBUTIONLIST_OBJECTCLASS . ")(" . LDAP_DISTRIBUTIONLIST_ATTR . "=" . stripslashes($a['dn']) . ")))", array());
$is_auditor = $this->check_ldap_membership($query->rows);
@ -96,7 +110,7 @@ class ModelUserAuth extends Model {
}
}
else if(ENABLE_SYSLOG == 1) {
syslog(LOG_INFO, "cannot bind to '" . LDAP_HOST . "' as '" . LDAP_HELPER_DN . "'");
syslog(LOG_INFO, "cannot bind to '" . $ldap_host . "' as '" . $ldap_helper_dn . "'");
}
return 0;

View File

@ -876,9 +876,37 @@ var Piler =
$('#fldr_' + id).hide();
$('#fldr_collapse_' + id).hide();
$('#fldr_open_' + id).show();
},
test_ldap_connection:function()
{
Piler.log("[test_ldap_connection]");
jQuery.ajax('index.php?route=ldap/test', {
data: {
description: $('#description').val(),
ldap_host: $('#ldap_host').val(),
ldap_base_dn: $('#ldap_base_dn').val(),
ldap_bind_dn: $('#ldap_bind_dn').val(),
ldap_bind_pw: $('#ldap_bind_pw').val()
},
type: "POST"
})
.done( function(a) {
$('#LDAPTEST').html(a);
})
.fail(function(a, b) { alert("Problem retrieving XML data:" + b) });
},
clear_ldap_test: function()
{
$('#LDAPTEST').html('');
}
}

View File

@ -1,55 +0,0 @@
<?php if(Registry::get('username')) { ?>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<!-- <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a> -->
<a class="brand" href="/index.php?route=health/health" title="<?php print SITE_NAME; ?>"><img src="<?php print SITE_LOGO_SM; ?>" alt="<?php print SITE_NAME; ?>" /></a>
<!-- <div class="nav-collapse"> -->
<ul class="nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-desktop"></i>&nbsp;<?php print $text_monitor; ?>&nbsp;<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="index.php?route=stat/stat&timespan=daily"><i class="icon-bar-chart"></i>&nbsp;Statistics</a></li>
<li><a href="index.php?route=accounting/accounting&view=email"><i class="icon-tasks"></i>&nbsp;Accounting</a></li>
<li><a href="index.php?route=health/health"><i class="icon-medkit"></i>&nbsp;Health</a></li>
<?php if(ENABLE_AUDIT == 1) { ?>
<li><a href="index.php?route=audit/audit"><i class="icon-book"></i>&nbsp;<?php print $text_audit; ?></a></li>
<?php } ?>
</ul>
</li>
<li class="dropdown"<?php if(strstr($_SERVER['QUERY_STRING'], "domain/") || ($_SERVER['QUERY_STRING'] != "route=user/settings" && strstr($_SERVER['QUERY_STRING'], "user/")) || strstr($_SERVER['QUERY_STRING'], "policy/") || strstr($_SERVER['QUERY_STRING'], "import/")) { ?> id="active"<?php } ?>>
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-cogs"></i>&nbsp;<?php print $text_administration; ?>&nbsp;<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="index.php?route=user/list"><i class="icon-user"></i>&nbsp;<?php print $text_users; ?></a></li>
<li><a href="index.php?route=group/list"><i class="icon-group"></i>&nbsp;<?php print $text_groups; ?></a></li>
<li><a href="index.php?route=domain/domain"><i class="icon-globe"></i>&nbsp;<?php print $text_domain; ?></a></li>
<li><a href="index.php?route=policy/archiving"><i class="icon-folder-open"></i>&nbsp;<?php print $text_archiving_rules; ?></a></li>
<li><a href="index.php?route=policy/retention"><i class="icon-time"></i>&nbsp;<?php print $text_retention_rules; ?></a></li>
</ul>
</li>
</ul>
<ul class="nav pull-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-user icon-white"></i>&nbsp;<?php if(isset($_SESSION['realname'])) { print $_SESSION['realname']; ?>&nbsp;<?php } ?><b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="settings.php"><i class="icon-cog"></i>&nbsp;Settings</a></li>
<li class="divider"></li>
<li><a href="logout.php"><i class="icon-off"></i>&nbsp;<?php print $text_logout; ?></a></li>
</ul>
</li>
</ul>
<!-- </div><!--/.nav-collapse -->
</div>
</div>
</div>
<?php } ?>

View File

@ -35,6 +35,9 @@
<li><a href="index.php?route=user/list"><i class="icon-user"></i>&nbsp;<?php print $text_users; ?></a></li>
<li><a href="index.php?route=group/list"><i class="icon-group"></i>&nbsp;<?php print $text_groups; ?></a></li>
<li><a href="index.php?route=domain/domain"><i class="icon-globe"></i>&nbsp;<?php print $text_domain; ?></a></li>
<?php if(ENABLE_SAAS == 1) { ?>
<li><a href="index.php?route=ldap/list"><i class="icon-key"></i>&nbsp;<?php print $text_ldap; ?></a></li>
<?php } ?>
<li><a href="index.php?route=policy/archiving"><i class="icon-folder-open"></i>&nbsp;<?php print $text_archiving_rules; ?></a></li>
<li><a href="index.php?route=policy/retention"><i class="icon-time"></i>&nbsp;<?php print $text_retention_rules; ?></a></li>
</ul>

View File

@ -13,11 +13,25 @@
</div>
</div>
<div class="control-group">
<label class="control-label" for="mapped"><?php print $text_mapped_domain; ?>:</label>
<div class="controls">
<input type="text" class="text" name="mapped" placeholder="Mapped Domain" />
</div>
<label class="control-label" for="mapped"><?php print $text_mapped_domain; ?>:</label>
<div class="controls">
<input type="text" class="text" name="mapped" placeholder="Mapped Domain" />
</div>
</div>
<?php if(ENABLE_SAAS == 1) { ?>
<div class="control-group">
<label class="control-label" for="ldap_id"><?php print $text_ldap; ?>:</label>
<div class="controls">
<select name="ldap_id" id="ldap_id">
<?php foreach ($ldap as $l) { ?>
<option value="<?php print $l['id']; ?>"><?php print $l['description']; ?></option>
<?php } ?>
</select>
</div>
</div>
<?php } ?>
<div class="form-actions">
<input type="submit" value="<?php print $text_add; ?>" class="btn btn-primary" />
<input type="reset" value="<?php print $text_clear; ?>" class="btn" />
@ -35,6 +49,9 @@
<tr>
<th class="domaincell"><?php print $text_domain; ?></th>
<th class="domaincell"><?php print $text_mapped_domain; ?></th>
<?php if(ENABLE_SAAS == 1) { ?>
<th class="domaincell"><?php print $text_ldap; ?></th>
<?php } ?>
<th class="domaincell">&nbsp;</th>
</tr>
@ -42,6 +59,9 @@
<tr>
<td class="domaincell"><a href="index.php?route=user/list&search=@<?php print $domain['domain']; ?>"><?php print $domain['domain']; ?></a></td>
<td class="domaincell"><?php print $domain['mapped']; ?></td>
<?php if(ENABLE_SAAS == 1) { ?>
<td class="domaincell"><?php print $domain['ldap']; ?></td>
<?php } ?>
<td class="domaincell"><a href="index.php?route=domain/remove&amp;domain=<?php print urlencode($domain['domain']); ?>" onclick="javascript:confirm('Delete Domain','Delete','Cancel','<?php print urlencode($domain['domain']); ?>')"><?php print $text_remove; ?></a></td>
</tr>
<?php } ?>

View File

@ -0,0 +1,19 @@
<?php foreach($domains as $domain) { ?>
<a href="#" onclick="append_value_from_slider('domains', '<?php print $domain['domain']; ?>');"><?php print $domain['domain']; ?></a><br />
<?php } ?>
<div id="pagenav">
<?php if($page > 0){ ?><a href="index.php?route=domain/domains&amp;page=0&amp;term=<?php print $search; ?>&amp;sort=<?php print $sort; ?>&amp;order=<?php print $order; ?>" class="navlink"><?php } ?> &laquo; <?php if($page > 0){ ?></a><?php } ?>
&nbsp;
<?php if($page > 0){ ?><a href="index.php?route=domain/domains&amp;page=<?php print $prev_page; ?>&amp;term=<?php print $search; ?>&amp;sort=<?php print $sort; ?>&amp;order=<?php print $order; ?>" class="navlink"><?php } ?> &lsaquo; <?php if($page > 0){ ?></a><?php } ?>
&nbsp;
<?php if(count($domains) > 0) { print $domains[0][$sort]; ?> - <?php print $domains[count($domains)-1][$sort]; } ?>
&nbsp;
<?php if($total >= $page_len*($page+1) && $total > $page_len){ ?><a href="index.php?route=domain/domains&amp;page=<?php print $next_page; ?>&amp;term=<?php print $search; ?>&amp;sort=<?php print $sort; ?>&amp;order=<?php print $order; ?>" class="navlink"><?php } ?> &rsaquo; <?php if($total >= $page_len*($page+1) && $total > $page_len){ ?></a><?php } ?>
&nbsp;
<?php if($page < $total_pages){ ?><a href="index.php?route=domain/domains&amp;page=<?php print $total_pages; ?>&amp;term=<?php print $search; ?>&amp;sort=<?php print $sort; ?>&amp;order=<?php print $order; ?>" class="navlink"><?php } ?> &raquo; <?php if($page < $total_pages){ ?></a><?php } ?>
</div>
<div class="top20px"><a href="#" onclick="window.close();">close</a></div>

View File

@ -0,0 +1,81 @@
<h4><?php print $text_add_new_entry; ?></h4>
<?php if(isset($x)){ ?>
<div class="alert alert-info"><?php print $x; ?></div>
<?php } ?>
<form method="post" name="add1" action="index.php?route=ldap/list" class="form-horizontal">
<div class="control-group">
<label class="control-label" for="description"><?php print $text_description; ?>:</label>
<div class="controls">
<input type="text" class="text" name="description" id="description" placeholder="" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="ldap_host"><?php print $text_ldap_host; ?>:</label>
<div class="controls">
<input type="text" class="text" name="ldap_host" id="ldap_host" placeholder="" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="ldap_base_dn"><?php print $text_ldap_base_dn; ?>:</label>
<div class="controls">
<input type="text" class="text" name="ldap_base_dn" id="ldap_base_dn" placeholder="" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="ldap_bind_dn"><?php print $text_ldap_bind_dn; ?>:</label>
<div class="controls">
<input type="text" class="text" name="ldap_bind_dn" id="ldap_bind_dn" placeholder="" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="ldap_bind_pw"><?php print $text_ldap_bind_pw; ?>:</label>
<div class="controls">
<input type="password" class="password" name="ldap_bind_pw" id="ldap_bind_pw" placeholder="" /> <input type="button" value="<?php print $text_test_connection; ?>" class="btn btn-danger" onclick="Piler.test_ldap_connection(); return false;" /> <span id="LDAPTEST"></span>
</div>
</div>
<div class="form-actions">
<input type="submit" value="<?php print $text_add; ?>" class="btn btn-primary" />
<input type="reset" value="<?php print $text_clear; ?>" class="btn" onclick="Piler.clear_ldap_test();" />
</div>
</form>
<h4><?php print $text_existing_entries; ?></h4>
<div class="listarea">
<?php if(isset($entries)){ ?>
<table id="ss1" class="table table-striped table-condensed">
<tr>
<th class="domaincell"><?php print $text_description; ?></th>
<th class="domaincell"><?php print $text_ldap_host; ?></th>
<td class="domaincell"><?php print $text_ldap_base_dn; ?></td>
<td class="domaincell"><?php print $text_ldap_bind_dn; ?></td>
<th class="domaincell">&nbsp;</th>
</tr>
<?php foreach($entries as $e) { ?>
<tr>
<td class="domaincell"><?php print $e['description']; ?></td>
<td class="domaincell"><?php print $e['ldap_host']; ?></td>
<td class="domaincell"><?php print $e['ldap_base_dn']; ?></td>
<td class="domaincell"><?php print $e['ldap_bind_dn']; ?></td>
<td class="domaincell"><a href="index.php?route=ldap/remove&amp;id=<?php print $e['id']; ?>&amp;description=<?php print urlencode($e['description']); ?>&amp;confirmed=1" onclick="if(confirm('<?php print $text_remove; ?>: ' + '\'<?php print $e['description']; ?>\'')) return true; return false;"><?php print $text_remove; ?></a></td>
</tr>
<?php } ?>
</div>
<?php } else { ?>
<div class="alert alert-error lead">
<?php print $text_not_found; ?>
</div>
<?php } ?>
</div>

View File

@ -0,0 +1,11 @@
<p>
<?php if($confirmed){ ?>
<?php print $x; ?>. <a href="index.php?route=ldap/list"><?php print $text_back; ?></a>
<?php } ?>
</p>