added group handling feature

This commit is contained in:
SJ 2012-06-22 12:30:55 +02:00
parent 26807592b5
commit e944852283
23 changed files with 744 additions and 11 deletions

View File

@ -11,7 +11,7 @@
#define PROGNAME "piler" #define PROGNAME "piler"
#define VERSION "0.1.18" #define VERSION "0.1.19"
#define PROGINFO VERSION ", Janos SUTO <sj@acts.hu>\n\n" CONFIGURE_PARAMS "\n" #define PROGINFO VERSION ", Janos SUTO <sj@acts.hu>\n\n" CONFIGURE_PARAMS "\n"

View File

@ -189,6 +189,7 @@ create index `user_settings_idx` on `user_settings`(`username`);
drop table if exists `user`; drop table if exists `user`;
create table if not exists `user` ( create table if not exists `user` (
`uid` int unsigned not null primary key, `uid` int unsigned not null primary key,
`gid` int default 0,
`username` char(64) not null unique, `username` char(64) not null unique,
`realname` char(64) default null, `realname` char(64) default null,
`password` char(48) default null, `password` char(48) default null,
@ -197,7 +198,7 @@ create table if not exists `user` (
`isadmin` tinyint default 0 `isadmin` tinyint default 0
) Engine=InnoDB; ) 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`; drop table if exists `email`;
create table if not exists `email` ( create table if not exists `email` (
@ -216,6 +217,19 @@ create table if not exists `email_groups` (
) ENGINE=InnoDB; ) 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` ( create table if not exists `remote` (
`remotedomain` char(64) not null primary key, `remotedomain` char(64) not null primary key,
`remotehost` char(64) not null, `remotehost` char(64) not null,

View File

@ -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;

View File

@ -80,6 +80,8 @@ define('DB_PASSWORD', 'piler');
define('DB_DATABASE', 'piler'); define('DB_DATABASE', 'piler');
define('TABLE_USER', 'user'); define('TABLE_USER', 'user');
define('TABLE_GROUP', 'group');
define('TABLE_GROUP_EMAIL', 'group_email');
define('TABLE_EMAIL', 'email'); define('TABLE_EMAIL', 'email');
define('TABLE_META', 'metadata'); define('TABLE_META', 'metadata');
define('TABLE_ATTACHMENT', 'attachment'); define('TABLE_ATTACHMENT', 'attachment');

View File

@ -0,0 +1,84 @@
<?php
class ControllerGroupAdd extends Controller {
private $error = array();
private $domains = array();
public function index(){
$this->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;
}
}
}
?>

View File

@ -0,0 +1,104 @@
<?php
class ControllerGroupEdit extends Controller {
private $error = array();
private $domains = array();
public function index(){
$this->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;
}
}
}
?>

View File

@ -0,0 +1,85 @@
<?php
class ControllerGroupList extends Controller {
private $error = array();
public function index(){
$this->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();
}
}
?>

View File

@ -0,0 +1,76 @@
<?php
class ControllerGroupRemove extends Controller {
private $error = array();
private $domains = array();
private $d = array();
public function index(){
$this->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;
}
}
}
?>

View File

@ -16,6 +16,7 @@ class ControllerUserAdd extends Controller {
$db = Registry::get('db'); $db = Registry::get('db');
$this->load->model('user/user'); $this->load->model('user/user');
$this->load->model('group/group');
$this->document->title = $this->data['text_user_management']; $this->document->title = $this->data['text_user_management'];
@ -59,6 +60,7 @@ class ControllerUserAdd extends Controller {
} }
else { else {
$this->data['next_user_id'] = $this->model_user_user->getNextUid(); $this->data['next_user_id'] = $this->model_user_user->getNextUid();
$this->data['groups'] = $this->model_group_group->get_groups();
} }
} }
else { else {

View File

@ -19,6 +19,7 @@ class ControllerUserEdit extends Controller {
$language = Registry::get('language'); $language = Registry::get('language');
$this->load->model('user/user'); $this->load->model('user/user');
$this->load->model('group/group');
$this->document->title = $language->get('text_user_management'); $this->document->title = $language->get('text_user_management');
@ -69,7 +70,8 @@ class ControllerUserEdit extends Controller {
} }
} }
else { 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']); $this->data['user']['group_membership'] = $this->model_user_user->get_additional_uids($this->data['uid']);

View File

@ -7,6 +7,7 @@ $_['text_ad_sync_status'] = "AD synchronisation status";
$_['text_add'] = "Add"; $_['text_add'] = "Add";
$_['text_add_new_email_address'] = "New email address"; $_['text_add_new_email_address'] = "New email address";
$_['text_add_new_domain'] = "New domain"; $_['text_add_new_domain'] = "New domain";
$_['text_add_new_group'] = "Add group";
$_['text_add_new_rule'] = "Add rule"; $_['text_add_new_rule'] = "Add rule";
$_['text_add_new_user_alias'] = "Add new user"; $_['text_add_new_user_alias'] = "Add new user";
$_['text_add_policy'] = "Add new policy"; $_['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_exclude'] = "Exclude";
$_['text_existing_domains'] = "Existing domains"; $_['text_existing_domains'] = "Existing domains";
$_['text_existing_email'] = "Existing email"; $_['text_existing_email'] = "Existing email";
$_['text_existing_groups'] = "Existing groups";
$_['text_existing_policies'] = "Existing policies"; $_['text_existing_policies'] = "Existing policies";
$_['text_existing_rules'] = "Existing rules"; $_['text_existing_rules'] = "Existing rules";
$_['text_existing_user'] = "Existing user"; $_['text_existing_user'] = "Existing user";
@ -109,6 +111,9 @@ $_['text_from'] = "From";
$_['text_from_domain'] = "From domain"; $_['text_from_domain'] = "From domain";
$_['text_group_id'] = "Group id"; $_['text_group_id'] = "Group id";
$_['text_groupname'] = "Group name";
$_['text_groups'] = "Groups";
$_['text_group_management'] = "Group management";
$_['text_group_membership'] = "Group membership"; $_['text_group_membership'] = "Group membership";
$_['text_health'] = "Health"; $_['text_health'] = "Health";
@ -220,6 +225,7 @@ $_['text_remove_selected_uids'] = "Remove selected uids";
$_['text_remove_policy'] = "Remove policy"; $_['text_remove_policy'] = "Remove policy";
$_['text_remove_rule'] = "Remove rule"; $_['text_remove_rule'] = "Remove rule";
$_['text_remove_this_policy'] = "Remove this policy"; $_['text_remove_this_policy'] = "Remove this policy";
$_['text_remove_this_group'] = "Remove this group";
$_['text_remove_this_user'] = "Remove this user"; $_['text_remove_this_user'] = "Remove this user";
$_['text_reset_counters'] = "Reset counters"; $_['text_reset_counters'] = "Reset counters";
$_['text_restore_message'] = "restore message"; $_['text_restore_message'] = "restore message";
@ -286,6 +292,7 @@ $_['text_unknown'] = "unknown";
$_['text_update_selected_uids'] = "Update selected uids"; $_['text_update_selected_uids'] = "Update selected uids";
$_['text_uptime'] = "Uptime"; $_['text_uptime'] = "Uptime";
$_['text_user'] = "User"; $_['text_user'] = "User";
$_['text_users'] = "Users";
$_['text_user_id'] = "User id"; $_['text_user_id'] = "User id";
$_['text_user_auditor'] = "Auditor"; $_['text_user_auditor'] = "Auditor";
$_['text_user_domainadmin'] = "Domain admin"; $_['text_user_domainadmin'] = "Domain admin";

View File

@ -7,6 +7,7 @@ $_['text_ad_sync_status'] = "AD szinkroniz
$_['text_add'] = "Felvesz"; $_['text_add'] = "Felvesz";
$_['text_add_new_email_address'] = "Új email cím"; $_['text_add_new_email_address'] = "Új email cím";
$_['text_add_new_domain'] = "Új domain"; $_['text_add_new_domain'] = "Új domain";
$_['text_add_new_group'] = "Új csoport";
$_['text_add_new_rule'] = "Új szabály"; $_['text_add_new_rule'] = "Új szabály";
$_['text_add_new_user_alias'] = "Új felhasználó"; $_['text_add_new_user_alias'] = "Új felhasználó";
$_['text_add_policy'] = "Új házirend"; $_['text_add_policy'] = "Új házirend";
@ -88,6 +89,7 @@ $_['text_exact_domain_name_or_email_address'] = "pontos domainn
$_['text_exclude'] = "Kihagy"; $_['text_exclude'] = "Kihagy";
$_['text_existing_domains'] = "Létező domainek"; $_['text_existing_domains'] = "Létező domainek";
$_['text_existing_email'] = "Létező email"; $_['text_existing_email'] = "Létező email";
$_['text_existing_groups'] = "Létezõ csoportok";
$_['text_existing_policies'] = "Létező házirendek"; $_['text_existing_policies'] = "Létező házirendek";
$_['text_existing_rules'] = "Létező szabályok"; $_['text_existing_rules'] = "Létező szabályok";
$_['text_existing_user'] = "Létező felhasználó"; $_['text_existing_user'] = "Létező felhasználó";
@ -115,6 +117,9 @@ $_['text_history'] = "T
$_['text_home'] = "Kezdőlap"; $_['text_home'] = "Kezdőlap";
$_['text_group_id'] = "Csoport azonosító"; $_['text_group_id'] = "Csoport azonosító";
$_['text_groupname'] = "Csoportnév";
$_['text_groups'] = "Csoportok";
$_['text_group_management'] = "Csoport";
$_['text_group_membership'] = "Csoport tagság"; $_['text_group_membership'] = "Csoport tagság";
$_['text_image'] = "kép"; $_['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_selected_uids'] = "Kijelölt azonosítók törlése";
$_['text_remove_policy'] = "Házirend törlése"; $_['text_remove_policy'] = "Házirend törlése";
$_['text_remove_rule'] = "Szabály 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_policy'] = "Házirend törlése";
$_['text_remove_this_user'] = "Felhasználó törlése"; $_['text_remove_this_user'] = "Felhasználó törlése";
$_['text_reset_counters'] = "Számlálók nullázása"; $_['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_update_selected_uids'] = "Kijelölt azonosítók módosítása";
$_['text_uptime'] = "Uptime"; $_['text_uptime'] = "Uptime";
$_['text_user'] = "Felhasználó"; $_['text_user'] = "Felhasználó";
$_['text_users'] = "Felhasználók";
$_['text_user_id'] = "Felhasználó azonosító"; $_['text_user_id'] = "Felhasználó azonosító";
$_['text_user_auditor'] = "Auditor"; $_['text_user_auditor'] = "Auditor";
$_['text_user_domainadmin'] = "Domain admin"; $_['text_user_domainadmin'] = "Domain admin";

View File

@ -7,6 +7,7 @@ $_['text_ad_sync_status'] = "AD szinkronizáció státusz";
$_['text_add'] = "Felvesz"; $_['text_add'] = "Felvesz";
$_['text_add_new_email_address'] = "Új email cím"; $_['text_add_new_email_address'] = "Új email cím";
$_['text_add_new_domain'] = "Új domain"; $_['text_add_new_domain'] = "Új domain";
$_['text_add_new_group'] = "Új csoport";
$_['text_add_new_rule'] = "Új szabály"; $_['text_add_new_rule'] = "Új szabály";
$_['text_add_new_user_alias'] = "Új felhasználó"; $_['text_add_new_user_alias'] = "Új felhasználó";
$_['text_add_policy'] = "Új házirend"; $_['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_exclude'] = "Kihagy";
$_['text_existing_domains'] = "Létező domainek"; $_['text_existing_domains'] = "Létező domainek";
$_['text_existing_email'] = "Létező email"; $_['text_existing_email'] = "Létező email";
$_['text_existing_groups'] = "Létező csoportok";
$_['text_existing_policies'] = "Létező házirendek"; $_['text_existing_policies'] = "Létező házirendek";
$_['text_existing_rules'] = "Létező szabályok"; $_['text_existing_rules'] = "Létező szabályok";
$_['text_existing_user'] = "Létező felhasználó"; $_['text_existing_user'] = "Létező felhasználó";
@ -115,6 +117,9 @@ $_['text_history'] = "Történet";
$_['text_home'] = "Kezdőlap"; $_['text_home'] = "Kezdőlap";
$_['text_group_id'] = "Csoport azonosító"; $_['text_group_id'] = "Csoport azonosító";
$_['text_groupname'] = "Csoportnév";
$_['text_groups'] = "Csoportok";
$_['text_group_management'] = "Csoport";
$_['text_group_membership'] = "Csoport tagság"; $_['text_group_membership'] = "Csoport tagság";
$_['text_image'] = "kép"; $_['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_selected_uids'] = "Kijelölt azonosítók törlése";
$_['text_remove_policy'] = "Házirend törlése"; $_['text_remove_policy'] = "Házirend törlése";
$_['text_remove_rule'] = "Szabály 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_policy'] = "Házirend törlése";
$_['text_remove_this_user'] = "Felhasználó törlése"; $_['text_remove_this_user'] = "Felhasználó törlése";
$_['text_reset_counters'] = "Számlálók nullázása"; $_['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_update_selected_uids'] = "Kijelölt azonosítók módosítása";
$_['text_uptime'] = "Uptime"; $_['text_uptime'] = "Uptime";
$_['text_user'] = "Felhasználó"; $_['text_user'] = "Felhasználó";
$_['text_users'] = "Felhasználók";
$_['text_user_id'] = "Felhasználó azonosító"; $_['text_user_id'] = "Felhasználó azonosító";
$_['text_user_auditor'] = "Auditor"; $_['text_user_auditor'] = "Auditor";
$_['text_user_domainadmin'] = "Domain admin"; $_['text_user_domainadmin'] = "Domain admin";

145
webui/model/group/group.php Normal file
View File

@ -0,0 +1,145 @@
<?php
class ModelGroupGroup extends Model {
public function get_groups($search = '', $page = 0, $page_len = 0, $sort = 'groupname', $order = 0) {
$where_cond = '';
$_order = "";
$groups = array();
$Q = array();
$limit = "";
$from = (int)$page * (int)$page_len;
$search = preg_replace("/\s{1,}/", "", $search) . '%';
if($search){
$where_cond .= " WHERE `groupname` like ?";
array_push($Q, $search);
}
/* sort order */
if($order == 0) { $order = "ASC"; }
else { $order = "DESC"; }
$_order = "ORDER BY `$sort` $order";
if($page_len > 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();
}
}
?>

View File

@ -4,7 +4,7 @@ class ModelUserAuth extends Model {
public function checkLogin($username = '', $password = '') { 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; } if(!isset($query->row['password'])) { return 0; }
@ -14,12 +14,13 @@ class ModelUserAuth extends Model {
$_SESSION['username'] = $query->row['username']; $_SESSION['username'] = $query->row['username'];
$_SESSION['uid'] = $query->row['uid']; $_SESSION['uid'] = $query->row['uid'];
$_SESSION['gid'] = $query->row['gid'];
$_SESSION['admin_user'] = $query->row['isadmin']; $_SESSION['admin_user'] = $query->row['isadmin'];
$_SESSION['email'] = $username; $_SESSION['email'] = $username;
$_SESSION['domain'] = $query->row['domain']; $_SESSION['domain'] = $query->row['domain'];
$_SESSION['realname'] = $query->row['realname']; $_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'); AUDIT(ACTION_LOGIN, $username, '', '', 'successful auth against user table');

View File

@ -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(); $data = array();
$uids = $uid; $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; 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){ if(!is_numeric($uid) || (int)$uid < 0){
return array(); return array();
} }
@ -209,13 +218,14 @@ class ModelUserUser extends Model {
if($page_len > 0) { $limit = " LIMIT " . (int)$from . ", " . (int)$page_len; } 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) { foreach ($query->rows as $q) {
if(Registry::get('admin_user') == 1 || (isset($q['domain']) && $q['domain'] == $my_domain[0]) ) { if(Registry::get('admin_user') == 1 || (isset($q['domain']) && $q['domain'] == $my_domain[0]) ) {
$users[] = array( $users[] = array(
'uid' => $q['uid'], 'uid' => $q['uid'],
'gid' => $q['gid'],
'username' => $q['username'], 'username' => $q['username'],
'realname' => $q['realname'], 'realname' => $q['realname'],
'domain' => isset($q['domain']) ? $q['domain'] : "", 'domain' => isset($q['domain']) ? $q['domain'] : "",
@ -313,7 +323,7 @@ class ModelUserUser extends Model {
$encrypted_password = crypt($user['password']); $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']; } 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; } 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 */ /* first, remove all his email addresses */

View File

@ -25,7 +25,8 @@
<li class="search_li" style="font: 11px normal Arial, sans-serif;"><a class="hide" href="#"<?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 } ?>><?php print $text_administration; ?></a> <li class="search_li" style="font: 11px normal Arial, sans-serif;"><a class="hide" href="#"<?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 } ?>><?php print $text_administration; ?></a>
<ul class="sub_menu"> <ul class="sub_menu">
<li><a href="index.php?route=user/list"><?php print $text_user_management; ?></a></li> <li><a href="index.php?route=user/list"><?php print $text_users; ?></a></li>
<li><a href="index.php?route=group/list"><?php print $text_groups; ?></a></li>
<li><a href="index.php?route=domain/domain"><?php print $text_domain; ?></a></li> <li><a href="index.php?route=domain/domain"><?php print $text_domain; ?></a></li>
<li><a href="index.php?route=policy/archiving"><?php print $text_archiving_rules; ?></a></li> <li><a href="index.php?route=policy/archiving"><?php print $text_archiving_rules; ?></a></li>
<li><a href="index.php?route=policy/retention"><?php print $text_retention_rules; ?></a></li> <li><a href="index.php?route=policy/retention"><?php print $text_retention_rules; ?></a></li>

View File

@ -0,0 +1,35 @@
<h4><?php print $text_add_new_group; ?></h4>
<?php if(isset($errorstring)){ ?><p class="loginfailed"><?php print $text_error; ?>: <?php print $errorstring; ?></p><?php } ?>
<form action="index.php?route=group/add" name="adduser" method="post" autocomplete="off">
<div id="ss1">
<div class="domainrow">
<div class="domaincell"><?php print $text_groupname; ?>:</div>
<div class="domaincell"><input type="text" name="groupname" value="<?php if(isset($post['groupname'])){ print $post['groupname']; } ?>" class="text" /></div>
</div>
<div class="domainrow">
<div class="domaincell"><?php print $text_email_addresses; ?>:</div>
<div class="domaincell"><textarea style="height:280px;" name="email" class="domain"><?php if(isset($post['email'])){ print $post['email']; } ?></textarea></div>
</div>
<div class="domainrow">
<div class="domaincell">&nbsp;</div>
<div class="domaincell"><input type="submit" value="<?php print $text_add; ?>" /><input type="reset" value="<?php print $text_cancel; ?>" /></div>
</div>
</div>
</form>
<?php if(isset($x)){ print $x; ?>. <a href="index.php?route=group/list"><?php print $text_back; ?></a>
<?php } ?>

View File

@ -0,0 +1,39 @@
<?php if(isset($group)) { ?>
<form action="index.php?route=group/edit" name="addgroup" method="post" autocomplete="off">
<input type="hidden" name="id" value="<?php print $id; ?>" />
<div id="ss1">
<div class="domainrow">
<div class="domaincell"><?php print $text_groupname; ?>:</div>
<div class="domaincell"><input type="text" name="groupname" value="<?php print $group['groupname']; ?>" class="text" /></div>
</div>
<div class="domainrow">
<div class="domaincell"><?php print $text_email_addresses; ?>:</div>
<div class="domaincell"><textarea style="height:280px;" name="email" class="domain"><?php if(isset($email)){ print $email; } ?></textarea></div>
</div>
<div class="domainrow">
<div class="domaincell">&nbsp;</div>
<div class="domaincell"><input type="submit" value="<?php print $text_modify; ?>" /><input type="reset" value="<?php print $text_cancel; ?>" /></div>
</div>
</div>
</form>
<p>&nbsp;</p>
<p><a href="index.php?route=group/remove&amp;id=<?php print $group['id']; ?>&amp;group=<?php print $group['groupname']; ?>"><?php print $text_remove_this_group; ?>: <?php print $group['groupname']; ?></a></p>
<p>&nbsp;</p>
<p>
<?php } else if(isset($x)){ print $x; ?>.
<?php } ?>
<a href="index.php?route=group/list"><?php print $text_back; ?></a>
</p>

View File

@ -0,0 +1,57 @@
<p/>
<p><a href="index.php?route=group/add"><?php print $text_add_new_group; ?></a></p>
<h4><?php print $text_existing_groups; ?></h4>
<form method="post" name="search1" action="index.php?route=group/list">
<input type="text" name="search" value="<?php print $search; ?>" />
<input type="submit" value="<?php print $text_search; ?>" />
</form>
<p>&nbsp;</p>
<?php if(isset($groups) && count($groups) > 0){ ?>
<div id="pagenav">
<?php if($page > 0){ ?><a href="index.php?route=group/list&amp;page=0&amp;search=<?php print $search; ?>&amp;sort=<?php print $sort; ?>&amp;order=<?php print $order; ?>" class="navlink"><?php } ?> &laquo; <?php if($page > 0){ ?></a><?php } ?>
<?php if($page > 0){ ?><a href="index.php?route=group/list&amp;page=<?php print $prev_page; ?>&amp;search=<?php print $search; ?>&amp;sort=<?php print $sort; ?>&amp;order=<?php print $order; ?>" class="navlink"><?php } ?> &lsaquo; <?php if($page > 0){ ?></a><?php } ?>
<?php print $groups[0][$sort]; ?> - <?php print $groups[count($groups)-1][$sort]; ?>
<?php if($total_groups >= $page_len*($page+1) && $total_groups > $page_len){ ?><a href="index.php?route=group/list&amp;page=<?php print $next_page; ?>&amp;search=<?php print $search; ?>&amp;sort=<?php print $sort; ?>&amp;order=<?php print $order; ?>" class="navlink"><?php } ?> &rsaquo; <?php if($total_groups >= $page_len*($page+1) && $total_groups > $page_len){ ?></a><?php } ?>
<?php if($page < $total_pages){ ?><a href="index.php?route=group/list&amp;page=<?php print $total_pages; ?>&amp;search=<?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 id="ss1" style="margin-top: 10px;">
<div class="domainrow">
<div class="domaincell"><?php print $text_groupname; ?> <a href="index.php?route=group/list&amp;sort=groupname&amp;order=0"><img src="<?php print ICON_ARROW_UP; ?>" border="0"></a> <a href="index.php?route=group/list&amp;sort=groupname&amp;order=1"><img src="<?php print ICON_ARROW_DOWN; ?>" border="0"></a></div>
<div class="domaincell">&nbsp;</div>
</div>
<?php foreach($groups as $group) { ?>
<div class="domainrow">
<div class="domaincell"><?php print $group['groupname']; ?></div>
<div class="domaincell"><a href="index.php?route=group/edit&amp;id=<?php print $group['id']; ?>"><?php print $text_edit_or_view; ?></a></div>
</div>
<?php } ?>
</div>
<div id="pagenav">
<?php if($page > 0){ ?><a href="index.php?route=group/list&amp;page=0&amp;search=<?php print $search; ?>&amp;sort=<?php print $sort; ?>&amp;order=<?php print $order; ?>" class="navlink"><?php } ?> &laquo; <?php if($page > 0){ ?></a><?php } ?>
<?php if($page > 0){ ?><a href="index.php?route=group/list&amp;page=<?php print $prev_page; ?>&amp;search=<?php print $search; ?>&amp;sort=<?php print $sort; ?>&amp;order=<?php print $order; ?>" class="navlink"><?php } ?> &lsaquo; <?php if($page > 0){ ?></a><?php } ?>
<?php print $groups[0][$sort]; ?> - <?php print $groups[count($groups)-1][$sort]; ?>
<?php if($total_groups >= $page_len*($page+1) && $total_groups > $page_len){ ?><a href="index.php?route=group/list&amp;page=<?php print $next_page; ?>&amp;search=<?php print $search; ?>&amp;sort=<?php print $sort; ?>&amp;order=<?php print $order; ?>" class="navlink"><?php } ?> &rsaquo; <?php if($total_groups >= $page_len*($page+1) && $total_groups > $page_len){ ?></a><?php } ?>
<?php if($page < $total_pages){ ?><a href="index.php?route=group/list&amp;page=<?php print $total_pages; ?>&amp;search=<?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>
<?php } else { ?>
<?php print $text_not_found; ?>
<?php } ?>

View File

@ -0,0 +1,13 @@
<p>
<?php if($confirmed){ ?>
<?php print $x; ?>. <a href="index.php?route=group/list"><?php print $text_back; ?></a>
<?php } else { ?>
<a href="index.php?route=group/remove&amp;id=<?php print $id; ?>&amp;group=<?php print $group; ?>&amp;confirmed=1"><?php print $text_remove_this_group; ?>: <?php print $group; ?></a>
<?php } ?>
</p>

View File

@ -34,6 +34,20 @@
</div> </div>
</div> </div>
<div class="domainrow">
<div class="domaincell"><?php print $text_groups; ?>:</div>
<div class="domaincell">
<select name="gid">
<option value="0"<?php if(isset($post) && $post['gid'] == 0){ ?> selected="selected"<?php } ?>>-</option>
<?php foreach ($groups as $group) { ?>
<option value="<?php print $group['id']; ?>"<?php if(isset($post) && $post['gid'] == $group['id']){ ?> selected="selected"<?php } ?>><?php print $group['groupname']; ?></option>
<?php } ?>
</select>
</div>
</div>
<?php if(ENABLE_LDAP_IMPORT_FEATURE == 1) { ?> <?php if(ENABLE_LDAP_IMPORT_FEATURE == 1) { ?>
<div class="domainrow"> <div class="domainrow">
<div class="domaincell">LDAP DN:</div> <div class="domaincell">LDAP DN:</div>

View File

@ -34,6 +34,19 @@
</div> </div>
</div> </div>
<div class="domainrow">
<div class="domaincell"><?php print $text_groups; ?>:</div>
<div class="domaincell">
<select name="gid">
<option value="0"<?php if($user['gid'] == 0){ ?> selected="selected"<?php } ?>>-</option>
<?php foreach ($groups as $group) { ?>
<option value="<?php print $group['id']; ?>"<?php if($user['gid'] == $group['id']){ ?> selected="selected"<?php } ?>><?php print $group['groupname']; ?></option>
<?php } ?>
</select>
</div>
</div>
<?php if(ENABLE_LDAP_IMPORT_FEATURE == 1) { ?> <?php if(ENABLE_LDAP_IMPORT_FEATURE == 1) { ?>
<div class="domainrow"> <div class="domainrow">
<div class="domaincell">LDAP DN:</div> <div class="domaincell">LDAP DN:</div>