From e9448522834921d8a1efd80be3275c50fe4cf90e Mon Sep 17 00:00:00 2001 From: SJ Date: Fri, 22 Jun 2012 12:30:55 +0200 Subject: [PATCH] added group handling feature --- src/config.h | 2 +- util/db-mysql.sql | 16 +- util/db-upgrade-0.18-vs-0.19.sql | 15 ++ webui/config.php | 2 + webui/controller/group/add.php | 84 ++++++++++ webui/controller/group/edit.php | 104 +++++++++++++ webui/controller/group/list.php | 85 ++++++++++ webui/controller/group/remove.php | 76 +++++++++ webui/controller/user/add.php | 2 + webui/controller/user/edit.php | 4 +- webui/language/en/messages.php | 7 + webui/language/hu/messages.iso-8859-2.php | 7 + webui/language/hu/messages.php | 7 + webui/model/group/group.php | 145 ++++++++++++++++++ webui/model/user/auth.php | 5 +- webui/model/user/user.php | 20 ++- .../default/templates/common/menu-admin.tpl | 3 +- .../theme/default/templates/group/add.tpl | 35 +++++ .../theme/default/templates/group/edit.tpl | 39 +++++ .../theme/default/templates/group/list.tpl | 57 +++++++ .../theme/default/templates/group/remove.tpl | 13 ++ .../view/theme/default/templates/user/add.tpl | 14 ++ .../theme/default/templates/user/edit.tpl | 13 ++ 23 files changed, 744 insertions(+), 11 deletions(-) create mode 100644 util/db-upgrade-0.18-vs-0.19.sql create mode 100644 webui/controller/group/add.php create mode 100644 webui/controller/group/edit.php create mode 100644 webui/controller/group/list.php create mode 100644 webui/controller/group/remove.php create mode 100644 webui/model/group/group.php create mode 100644 webui/view/theme/default/templates/group/add.tpl create mode 100644 webui/view/theme/default/templates/group/edit.tpl create mode 100644 webui/view/theme/default/templates/group/list.tpl create mode 100644 webui/view/theme/default/templates/group/remove.tpl diff --git a/src/config.h b/src/config.h index 6fde428f..c8e082d3 100644 --- a/src/config.h +++ b/src/config.h @@ -11,7 +11,7 @@ #define PROGNAME "piler" -#define VERSION "0.1.18" +#define VERSION "0.1.19" #define PROGINFO VERSION ", Janos SUTO \n\n" CONFIGURE_PARAMS "\n" diff --git a/util/db-mysql.sql b/util/db-mysql.sql index 94161674..a6618d26 100644 --- a/util/db-mysql.sql +++ b/util/db-mysql.sql @@ -189,6 +189,7 @@ create index `user_settings_idx` on `user_settings`(`username`); drop table if exists `user`; create table if not exists `user` ( `uid` int unsigned not null primary key, + `gid` int default 0, `username` char(64) not null unique, `realname` char(64) default null, `password` char(48) default null, @@ -197,7 +198,7 @@ create table if not exists `user` ( `isadmin` tinyint default 0 ) Engine=InnoDB; -insert into `user` (`uid`, `username`, `realname`, `password`, `isadmin`, `domain`) values (0, 'admin', 'built-in piler admin', '$1$PItc7d$zsUgON3JRrbdGS11t9JQW1', 1, 'local'); +insert into `user` (`uid`, `gid`, `username`, `realname`, `password`, `isadmin`, `domain`) values (0, 0, 'admin', 'built-in piler admin', '$1$PItc7d$zsUgON3JRrbdGS11t9JQW1', 1, 'local'); drop table if exists `email`; create table if not exists `email` ( @@ -216,6 +217,19 @@ create table if not exists `email_groups` ( ) ENGINE=InnoDB; +create table if not exists `group` ( + `id` bigint unsigned not null auto_increment primary key, + `groupname` char(255) not null unique +) ENGINE=InnoDB; + + +create table if not exists `group_email` ( + `id` bigint unsigned not null, + `email` char(128) not null, + key `group_email_idx` (`id`) +) ENGINE=InnoDB; + + create table if not exists `remote` ( `remotedomain` char(64) not null primary key, `remotehost` char(64) not null, diff --git a/util/db-upgrade-0.18-vs-0.19.sql b/util/db-upgrade-0.18-vs-0.19.sql new file mode 100644 index 00000000..b2c7372c --- /dev/null +++ b/util/db-upgrade-0.18-vs-0.19.sql @@ -0,0 +1,15 @@ +create table if not exists `group` ( + `id` bigint unsigned not null auto_increment primary key, + `groupname` char(255) not null unique +) ENGINE=InnoDB; + + +create table if not exists `group_email` ( + `id` bigint unsigned not null, + `email` char(128) not null, + key `group_email_idx` (`id`) +) ENGINE=InnoDB; + +alter table `user` add column `gid` int default 0; + + diff --git a/webui/config.php b/webui/config.php index 366ec7ac..5834b62d 100644 --- a/webui/config.php +++ b/webui/config.php @@ -80,6 +80,8 @@ define('DB_PASSWORD', 'piler'); define('DB_DATABASE', 'piler'); define('TABLE_USER', 'user'); +define('TABLE_GROUP', 'group'); +define('TABLE_GROUP_EMAIL', 'group_email'); define('TABLE_EMAIL', 'email'); define('TABLE_META', 'metadata'); define('TABLE_ATTACHMENT', 'attachment'); diff --git a/webui/controller/group/add.php b/webui/controller/group/add.php new file mode 100644 index 00000000..8d834736 --- /dev/null +++ b/webui/controller/group/add.php @@ -0,0 +1,84 @@ +id = "content"; + $this->template = "group/add.tpl"; + $this->layout = "common/layout"; + + + $request = Registry::get('request'); + $db = Registry::get('db'); + + $this->load->model('group/group'); + + $this->document->title = $this->data['text_group_management']; + + /* check if we are admin */ + + if(Registry::get('admin_user') == 1) { + + if($this->request->server['REQUEST_METHOD'] == 'POST') { + $ret = 0; + + if($this->validate() == true){ + $ret = $this->model_group_group->add_group($this->request->post); + + if($ret == 1){ + $this->data['x'] = $this->data['text_successfully_added']; + } else { + $this->data['errorstring'] = $this->data['text_failed_to_add'] . ": " . $ret; + } + } + else { + $this->data['errorstring'] = array_pop($this->error); + } + + if($ret == 0) { + + //$this->data['post'] = $this->request->post; + //$this->data['next_group_id'] = $this->model_group_group->getNextUid(); + + } + } + else { + //$this->data['next_group_id'] = $this->model_group_group->getNextUid(); + } + } + 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['groupname'])) { + $this->error['group'] = $this->data['text_missing_data']; + } + + + if (!$this->error) { + return true; + } else { + return false; + } + + } + + + +} + +?> diff --git a/webui/controller/group/edit.php b/webui/controller/group/edit.php new file mode 100644 index 00000000..4343e998 --- /dev/null +++ b/webui/controller/group/edit.php @@ -0,0 +1,104 @@ +data['id'] = 0; + + $this->id = "content"; + $this->template = "group/edit.tpl"; + $this->layout = "common/layout"; + + + $request = Registry::get('request'); + $db = Registry::get('db'); + $language = Registry::get('language'); + + $this->load->model('group/group'); + + + $this->document->title = $language->get('text_group_management'); + + $this->data['domains'] = array(); + + + if(isset($this->request->get['id']) && is_numeric($this->request->get['id']) && $this->request->get['id'] > 0) { + $this->data['id'] = $this->request->get['id']; + } + + if(isset($this->request->post['id']) && is_numeric($this->request->post['id']) && $this->request->post['id'] > 0) { + $this->data['id'] = $this->request->post['id']; + } + + + /* check if we are admin */ + + if(Registry::get('admin_user') == 1) { + + if($this->request->server['REQUEST_METHOD'] == 'POST') { + if($this->validate() == true){ + + $ret = $this->model_group_group->update_group($this->request->post); + + if($ret == 1){ + $this->data['x'] = $this->data['text_successfully_modified']; + } else { + $this->template = "common/error.tpl"; + $this->data['errorstring'] = $this->data['text_failed_to_modify'] . ": " . $ret; + } + + //$__groupname = $this->request->post['groupname']; + } + else { + $this->template = "common/error.tpl"; + $this->data['errorstring'] = array_pop($this->error); + } + } + else { + $this->data['group'] = $this->model_group_group->get_domain_by_id($this->data['id']); + $this->data['email'] = $this->model_group_group->get_emails_by_group_id($this->data['id']); + + //$this->data['user']['group_membership'] = $this->model_user_user->get_additional_uids($this->data['uid']); + //$this->data['emails'] = $this->model_user_user->getEmails($this->data['user']['username']); + + } + } + 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['groupname'])) { + $this->error['group'] = $this->data['text_missing_data']; + } + + if(!isset($this->request->post['id']) || !is_numeric($this->request->post['id']) || (int)$this->request->post['id'] < 0) { + $this->error['id'] = $this->data['text_invalid_data']; + } + + + if (!$this->error) { + return true; + } else { + return false; + } + + } + + + +} + +?> diff --git a/webui/controller/group/list.php b/webui/controller/group/list.php new file mode 100644 index 00000000..71539d30 --- /dev/null +++ b/webui/controller/group/list.php @@ -0,0 +1,85 @@ +id = "content"; + $this->template = "group/list.tpl"; + $this->layout = "common/layout"; + + + $request = Registry::get('request'); + $db = Registry::get('db'); + $language = Registry::get('language'); + + $this->load->model('group/group'); + + $this->document->title = $language->get('text_group_management'); + + + $this->data['page'] = 0; + $this->data['page_len'] = get_page_length(); + + $this->data['total_users'] = 0; + + $users = array(); + + + /* get search term if there's any */ + + if($this->request->server['REQUEST_METHOD'] == 'POST'){ + $this->data['search'] = @$this->request->post['search']; + } + else { + $this->data['search'] = @$this->request->get['search']; + } + + /* get page */ + + 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['sort'] = 'groupname'; + + $this->data['order'] = (int)@$this->request->get['order']; + + if(@$this->request->get['sort'] == "uid") { $this->data['sort'] = "uid"; } + if(@$this->request->get['sort'] == "realname") { $this->data['sort'] = "realname"; } + if(@$this->request->get['sort'] == "email") { $this->data['sort'] = "email"; } + if(@$this->request->get['sort'] == "domain") { $this->data['sort'] = "domain"; } + if(@$this->request->get['sort'] == "policy") { $this->data['sort'] = "policy_group"; } + + + /* check if we are admin */ + + if(Registry::get('admin_user') == 1) { + + $this->data['groups'] = $this->model_group_group->get_groups($this->data['search'], $this->data['page'], $this->data['page_len'], + $this->data['sort'], $this->data['order']); + + $this->data['total_groups'] = $this->model_group_group->count_groups($this->data['search']); + } + else { + $this->template = "common/error.tpl"; + $this->data['errorstring'] = $this->data['text_you_are_not_admin']; + } + + + $this->data['prev_page'] = $this->data['page'] - 1; + $this->data['next_page'] = $this->data['page'] + 1; + + $this->data['total_pages'] = floor($this->data['total_users'] / $this->data['page_len']); + + + $this->render(); + } + + +} + +?> diff --git a/webui/controller/group/remove.php b/webui/controller/group/remove.php new file mode 100644 index 00000000..77ee862e --- /dev/null +++ b/webui/controller/group/remove.php @@ -0,0 +1,76 @@ +id = "content"; + $this->template = "group/remove.tpl"; + $this->layout = "common/layout"; + + + $request = Registry::get('request'); + $db = Registry::get('db'); + + $this->load->model('group/group'); + + $this->document->title = $this->data['text_group_management']; + + + $this->data['username'] = Registry::get('username'); + + $this->data['id'] = (int)@$this->request->get['id']; + $this->data['group'] = @$this->request->get['group']; + $this->data['confirmed'] = (int)@$this->request->get['confirmed']; + + + if($this->validate() == true) { + + if($this->data['confirmed'] == 1) { + $ret = $this->model_group_group->delete_group($this->data['id']); + 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['id']) || !is_numeric($this->request->get['id']) || $this->request->get['id'] < 1 ) { + $this->error['groupname'] = $this->data['text_invalid_data']; + } + + + if (!$this->error) { + return true; + } else { + return false; + } + + } + + +} + +?> diff --git a/webui/controller/user/add.php b/webui/controller/user/add.php index bb326c94..0b056289 100644 --- a/webui/controller/user/add.php +++ b/webui/controller/user/add.php @@ -16,6 +16,7 @@ class ControllerUserAdd extends Controller { $db = Registry::get('db'); $this->load->model('user/user'); + $this->load->model('group/group'); $this->document->title = $this->data['text_user_management']; @@ -59,6 +60,7 @@ class ControllerUserAdd extends Controller { } else { $this->data['next_user_id'] = $this->model_user_user->getNextUid(); + $this->data['groups'] = $this->model_group_group->get_groups(); } } else { diff --git a/webui/controller/user/edit.php b/webui/controller/user/edit.php index 11317db2..924b4c55 100644 --- a/webui/controller/user/edit.php +++ b/webui/controller/user/edit.php @@ -19,6 +19,7 @@ class ControllerUserEdit extends Controller { $language = Registry::get('language'); $this->load->model('user/user'); + $this->load->model('group/group'); $this->document->title = $language->get('text_user_management'); @@ -69,7 +70,8 @@ class ControllerUserEdit extends Controller { } } else { - $this->data['user'] = $this->model_user_user->getUserByUid($this->data['uid']); + $this->data['user'] = $this->model_user_user->get_user_by_uid($this->data['uid']); + $this->data['groups'] = $this->model_group_group->get_groups(); $this->data['user']['group_membership'] = $this->model_user_user->get_additional_uids($this->data['uid']); diff --git a/webui/language/en/messages.php b/webui/language/en/messages.php index 221c169b..0ae7beac 100644 --- a/webui/language/en/messages.php +++ b/webui/language/en/messages.php @@ -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_group'] = "Add group"; $_['text_add_new_rule'] = "Add rule"; $_['text_add_new_user_alias'] = "Add new user"; $_['text_add_policy'] = "Add new policy"; @@ -88,6 +89,7 @@ $_['text_exact_domain_name_or_email_address'] = "exact domain name or email addr $_['text_exclude'] = "Exclude"; $_['text_existing_domains'] = "Existing domains"; $_['text_existing_email'] = "Existing email"; +$_['text_existing_groups'] = "Existing groups"; $_['text_existing_policies'] = "Existing policies"; $_['text_existing_rules'] = "Existing rules"; $_['text_existing_user'] = "Existing user"; @@ -109,6 +111,9 @@ $_['text_from'] = "From"; $_['text_from_domain'] = "From domain"; $_['text_group_id'] = "Group id"; +$_['text_groupname'] = "Group name"; +$_['text_groups'] = "Groups"; +$_['text_group_management'] = "Group management"; $_['text_group_membership'] = "Group membership"; $_['text_health'] = "Health"; @@ -220,6 +225,7 @@ $_['text_remove_selected_uids'] = "Remove selected uids"; $_['text_remove_policy'] = "Remove policy"; $_['text_remove_rule'] = "Remove rule"; $_['text_remove_this_policy'] = "Remove this policy"; +$_['text_remove_this_group'] = "Remove this group"; $_['text_remove_this_user'] = "Remove this user"; $_['text_reset_counters'] = "Reset counters"; $_['text_restore_message'] = "restore message"; @@ -286,6 +292,7 @@ $_['text_unknown'] = "unknown"; $_['text_update_selected_uids'] = "Update selected uids"; $_['text_uptime'] = "Uptime"; $_['text_user'] = "User"; +$_['text_users'] = "Users"; $_['text_user_id'] = "User id"; $_['text_user_auditor'] = "Auditor"; $_['text_user_domainadmin'] = "Domain admin"; diff --git a/webui/language/hu/messages.iso-8859-2.php b/webui/language/hu/messages.iso-8859-2.php index 073f08ca..a36b8eb2 100644 --- a/webui/language/hu/messages.iso-8859-2.php +++ b/webui/language/hu/messages.iso-8859-2.php @@ -7,6 +7,7 @@ $_['text_ad_sync_status'] = "AD szinkroniz $_['text_add'] = "Felvesz"; $_['text_add_new_email_address'] = "Új email cím"; $_['text_add_new_domain'] = "Új domain"; +$_['text_add_new_group'] = "Új csoport"; $_['text_add_new_rule'] = "Új szabály"; $_['text_add_new_user_alias'] = "Új felhasználó"; $_['text_add_policy'] = "Új házirend"; @@ -88,6 +89,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_groups'] = "Létező csoportok"; $_['text_existing_policies'] = "Létező házirendek"; $_['text_existing_rules'] = "Létező szabályok"; $_['text_existing_user'] = "Létező felhasználó"; @@ -115,6 +117,9 @@ $_['text_history'] = "T $_['text_home'] = "Kezdőlap"; $_['text_group_id'] = "Csoport azonosító"; +$_['text_groupname'] = "Csoportnév"; +$_['text_groups'] = "Csoportok"; +$_['text_group_management'] = "Csoport"; $_['text_group_membership'] = "Csoport tagság"; $_['text_image'] = "kép"; @@ -220,6 +225,7 @@ $_['text_remove_message2'] = "lev $_['text_remove_selected_uids'] = "Kijelölt azonosítók törlése"; $_['text_remove_policy'] = "Házirend törlése"; $_['text_remove_rule'] = "Szabály törlése"; +$_['text_remove_this_group'] = "Csoport törlése"; $_['text_remove_this_policy'] = "Házirend törlése"; $_['text_remove_this_user'] = "Felhasználó törlése"; $_['text_reset_counters'] = "Számlálók nullázása"; @@ -287,6 +293,7 @@ $_['text_unauthorized_view_message'] = "jogosulatlan $_['text_update_selected_uids'] = "Kijelölt azonosítók módosítása"; $_['text_uptime'] = "Uptime"; $_['text_user'] = "Felhasználó"; +$_['text_users'] = "Felhasználók"; $_['text_user_id'] = "Felhasználó azonosító"; $_['text_user_auditor'] = "Auditor"; $_['text_user_domainadmin'] = "Domain admin"; diff --git a/webui/language/hu/messages.php b/webui/language/hu/messages.php index 9430e661..7da603db 100644 --- a/webui/language/hu/messages.php +++ b/webui/language/hu/messages.php @@ -7,6 +7,7 @@ $_['text_ad_sync_status'] = "AD szinkronizáciĂł státusz"; $_['text_add'] = "Felvesz"; $_['text_add_new_email_address'] = "Ăšj email cĂ­m"; $_['text_add_new_domain'] = "Ăšj domain"; +$_['text_add_new_group'] = "Ăšj csoport"; $_['text_add_new_rule'] = "Ăšj szabály"; $_['text_add_new_user_alias'] = "Ăšj felhasználĂł"; $_['text_add_policy'] = "Ăšj házirend"; @@ -88,6 +89,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_groups'] = "LĂ©tezĹ‘ csoportok"; $_['text_existing_policies'] = "LĂ©tezĹ‘ házirendek"; $_['text_existing_rules'] = "LĂ©tezĹ‘ szabályok"; $_['text_existing_user'] = "LĂ©tezĹ‘ felhasználĂł"; @@ -115,6 +117,9 @@ $_['text_history'] = "TörtĂ©net"; $_['text_home'] = "KezdĹ‘lap"; $_['text_group_id'] = "Csoport azonosĂ­tĂł"; +$_['text_groupname'] = "CsoportnĂ©v"; +$_['text_groups'] = "Csoportok"; +$_['text_group_management'] = "Csoport"; $_['text_group_membership'] = "Csoport tagság"; $_['text_image'] = "kĂ©p"; @@ -220,6 +225,7 @@ $_['text_remove_message2'] = "levĂ©l törlĂ©se"; $_['text_remove_selected_uids'] = "Kijelölt azonosĂ­tĂłk törlĂ©se"; $_['text_remove_policy'] = "Házirend törlĂ©se"; $_['text_remove_rule'] = "Szabály törlĂ©se"; +$_['text_remove_this_group'] = "Csoport törlĂ©se"; $_['text_remove_this_policy'] = "Házirend törlĂ©se"; $_['text_remove_this_user'] = "FelhasználĂł törlĂ©se"; $_['text_reset_counters'] = "SzámlálĂłk nullázása"; @@ -287,6 +293,7 @@ $_['text_unauthorized_view_message'] = "jogosulatlan ĂĽzenet megtekintĂ©s"; $_['text_update_selected_uids'] = "Kijelölt azonosĂ­tĂłk mĂłdosĂ­tása"; $_['text_uptime'] = "Uptime"; $_['text_user'] = "FelhasználĂł"; +$_['text_users'] = "FelhasználĂłk"; $_['text_user_id'] = "FelhasználĂł azonosĂ­tĂł"; $_['text_user_auditor'] = "Auditor"; $_['text_user_domainadmin'] = "Domain admin"; diff --git a/webui/model/group/group.php b/webui/model/group/group.php new file mode 100644 index 00000000..5f1ee153 --- /dev/null +++ b/webui/model/group/group.php @@ -0,0 +1,145 @@ + 0) { $limit = " LIMIT " . (int)$from . ", " . (int)$page_len; } + + $query = $this->db->query("SELECT `id`, `groupname` FROM `" . TABLE_GROUP . "` $where_cond $_order $limit", $Q); + + foreach ($query->rows as $q) { + + $groups[] = array( + 'id' => $q['id'], + 'groupname' => $q['groupname'] + ); + } + + return $groups; + } + + + public function get_emails_by_group_id($id = 0) { + $emails = ''; + + $query = $this->db->query("SELECT `email` FROM `" . TABLE_GROUP_EMAIL . "` WHERE id=?", array($id)); + + foreach ($query->rows as $q) { + $emails .= $q['email'] . "\n"; + } + + return preg_replace("/\n$/", "", $emails); + } + + + public function count_groups($search = '') { + $where_cond = ""; + $Q = array(); + + $search = preg_replace("/\s{1,}/", "", $search) . '%'; + + if($search){ + $where_cond .= " WHERE `groupname` like '?'"; + array_push($Q, $search); + } + + $query = $this->db->query("SELECT COUNT(*) AS num FROM `" . TABLE_GROUP . "` $where_cond", $Q); + + return $query->num_rows; + } + + + public function add_group($group = array()) { + + if(!isset($group['groupname']) || $group['groupname'] == "") { return -1; } + + $query = $this->db->query("INSERT INTO `" . TABLE_GROUP . "` (groupname) VALUES(?)", array($group['groupname']) ); + + if($query->error == 1 || $this->db->countAffected() == 0){ return $group['groupname']; } + + $gid = $this->db->getLastId(); + + $emails = explode("\n", $group['email']); + foreach ($emails as $email) { + $email = rtrim($email); + if(validemail($email)) { + $query = $this->db->query("INSERT INTO `" . TABLE_GROUP_EMAIL . "` (id, email) VALUES(?,?)", array($gid, $email)); + } + } + + + LOGGER("add group: " . $group['groupname'] . ", id=" . (int)$gid); + + return 1; + } + + + public function update_group($group = array()) { + LOGGER("update user: " . $group['groupname'] . ", id=" . (int)$group['id']); + + $query = $this->db->query("UPDATE `" . TABLE_GROUP . "` SET `groupname`=? WHERE id=?", array($group['groupname'], (int)$group['id'])); + + $query = $this->db->query("DELETE FROM `" . TABLE_GROUP_EMAIL . "` WHERE id=?", array($group['id'])); + + $emails = explode("\n", $group['email']); + foreach ($emails as $email) { + $email = rtrim($email); + + if(validemail($email)) { + $query = $this->db->query("INSERT INTO `" . TABLE_GROUP_EMAIL . "` (id, email) VALUES(?,?)", array($group['id'], $email)); + } + } + + return $this->db->countAffected(); + } + + + public function get_domain_by_id($id = 0) { + if(!is_numeric($id) || (int)$id < 0){ + return array(); + } + + $query = $this->db->query("SELECT * FROM `" . TABLE_GROUP . "` WHERE id=?", array((int)$id)); + + return $query->row; + } + + + public function delete_group($id = 0) { + + $query = $this->db->query("DELETE FROM `" . TABLE_GROUP_EMAIL . "` WHERE id=?", array($id)); + + $query = $this->db->query("DELETE FROM `" . TABLE_GROUP . "` WHERE id=?", array((int)$id)); + + LOGGER("remove group: id=$id"); + + return $this->db->countAffected(); + } + + +} + +?> diff --git a/webui/model/user/auth.php b/webui/model/user/auth.php index 72d467c6..8971b236 100644 --- a/webui/model/user/auth.php +++ b/webui/model/user/auth.php @@ -4,7 +4,7 @@ class ModelUserAuth extends Model { public function checkLogin($username = '', $password = '') { - $query = $this->db->query("SELECT " . TABLE_USER . ".username, " . TABLE_USER . ".uid, " . TABLE_USER . ".realname, " . TABLE_USER . ".dn, " . TABLE_USER . ".password, " . TABLE_USER . ".isadmin, " . TABLE_USER . ".domain FROM " . TABLE_USER . ", " . TABLE_EMAIL . " WHERE " . TABLE_EMAIL . ".email=? AND " . TABLE_EMAIL . ".uid=" . TABLE_USER . ".uid", array($username)); + $query = $this->db->query("SELECT " . TABLE_USER . ".username, " . TABLE_USER . ".uid, " . TABLE_USER . ".gid, " . TABLE_USER . ".realname, " . TABLE_USER . ".dn, " . TABLE_USER . ".password, " . TABLE_USER . ".isadmin, " . TABLE_USER . ".domain FROM " . TABLE_USER . ", " . TABLE_EMAIL . " WHERE " . TABLE_EMAIL . ".email=? AND " . TABLE_EMAIL . ".uid=" . TABLE_USER . ".uid", array($username)); if(!isset($query->row['password'])) { return 0; } @@ -14,12 +14,13 @@ class ModelUserAuth extends Model { $_SESSION['username'] = $query->row['username']; $_SESSION['uid'] = $query->row['uid']; + $_SESSION['gid'] = $query->row['gid']; $_SESSION['admin_user'] = $query->row['isadmin']; $_SESSION['email'] = $username; $_SESSION['domain'] = $query->row['domain']; $_SESSION['realname'] = $query->row['realname']; - $_SESSION['emails'] = $this->model_user_user->get_users_all_email_addresses($query->row['uid']); + $_SESSION['emails'] = $this->model_user_user->get_users_all_email_addresses($query->row['uid'], $query->row['gid']); AUDIT(ACTION_LOGIN, $username, '', '', 'successful auth against user table'); diff --git a/webui/model/user/user.php b/webui/model/user/user.php index c5d20a47..68e49ef0 100644 --- a/webui/model/user/user.php +++ b/webui/model/user/user.php @@ -57,7 +57,7 @@ class ModelUserUser extends Model { } - public function get_users_all_email_addresses($uid = 0) { + public function get_users_all_email_addresses($uid = 0, $gid = 0) { $data = array(); $uids = $uid; @@ -79,6 +79,15 @@ class ModelUserUser extends Model { } + + $query = $this->db->query("SELECT email FROM `" . TABLE_GROUP_EMAIL . "` WHERE id=?", array($gid)); + + if(isset($query->rows)) { + foreach ($query->rows as $q) { + if(!in_array($email, $data)) { array_push($data, $q['email']); } + } + } + return $data; } @@ -150,7 +159,7 @@ class ModelUserUser extends Model { } - public function getUserByUid($uid = 0) { + public function get_user_by_uid($uid = 0) { if(!is_numeric($uid) || (int)$uid < 0){ return array(); } @@ -209,13 +218,14 @@ class ModelUserUser extends Model { if($page_len > 0) { $limit = " LIMIT " . (int)$from . ", " . (int)$page_len; } - $query = $this->db->query("SELECT " . TABLE_USER . ".uid, isadmin, username, realname, domain, email FROM " . TABLE_USER . "," . TABLE_EMAIL . " $where_cond group by " . TABLE_USER . ".uid $_order $limit"); + $query = $this->db->query("SELECT " . TABLE_USER . ".uid, gid, isadmin, username, realname, domain, email FROM " . TABLE_USER . "," . TABLE_EMAIL . " $where_cond group by " . TABLE_USER . ".uid $_order $limit"); foreach ($query->rows as $q) { if(Registry::get('admin_user') == 1 || (isset($q['domain']) && $q['domain'] == $my_domain[0]) ) { $users[] = array( 'uid' => $q['uid'], + 'gid' => $q['gid'], 'username' => $q['username'], 'realname' => $q['realname'], 'domain' => isset($q['domain']) ? $q['domain'] : "", @@ -313,7 +323,7 @@ class ModelUserUser extends Model { $encrypted_password = crypt($user['password']); - $query = $this->db->query("INSERT INTO " . TABLE_USER . " (uid, username, realname, password, domain, dn, isadmin) VALUES(?,?,?,?,?,?,?)", array((int)$user['uid'], $user['username'], $user['realname'], $encrypted_password, $user['domain'], @$user['dn'], (int)$user['isadmin'])); + $query = $this->db->query("INSERT INTO " . TABLE_USER . " (uid, gid, username, realname, password, domain, dn, isadmin) VALUES(?,?,?,?,?,?,?,?)", array((int)$user['uid'], (int)$user['gid'], $user['username'], $user['realname'], $encrypted_password, $user['domain'], @$user['dn'], (int)$user['isadmin'])); if($query->error == 1 || $this->db->countAffected() == 0){ return $user['username']; } @@ -377,7 +387,7 @@ class ModelUserUser extends Model { if($this->db->countAffected() != 1) { return 0; } } - $query = $this->db->query("UPDATE " . TABLE_USER . " SET username=?, realname=?, domain=?, dn=?, isadmin=? WHERE uid=?", array($user['username'], $user['realname'], $user['domain'], @$user['dn'], $user['isadmin'], (int)$user['uid'])); + $query = $this->db->query("UPDATE " . TABLE_USER . " SET username=?, realname=?, domain=?, gid=?, dn=?, isadmin=? WHERE uid=?", array($user['username'], $user['realname'], $user['domain'], $user['gid'], @$user['dn'], $user['isadmin'], (int)$user['uid'])); /* first, remove all his email addresses */ diff --git a/webui/view/theme/default/templates/common/menu-admin.tpl b/webui/view/theme/default/templates/common/menu-admin.tpl index c45a1bbb..a9afe08c 100644 --- a/webui/view/theme/default/templates/common/menu-admin.tpl +++ b/webui/view/theme/default/templates/common/menu-admin.tpl @@ -25,7 +25,8 @@
  • id="active">