mirror of
https://bitbucket.org/jsuto/piler.git
synced 2025-06-12 23:27:03 +02:00
added the webui to the tarball
This commit is contained in:
136
webui/controller/user/add.php
Normal file
136
webui/controller/user/add.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
|
||||
class ControllerUserAdd extends Controller {
|
||||
private $error = array();
|
||||
private $domains = array();
|
||||
|
||||
public function index(){
|
||||
|
||||
$this->id = "content";
|
||||
$this->template = "user/add.tpl";
|
||||
$this->layout = "common/layout";
|
||||
|
||||
|
||||
$request = Registry::get('request');
|
||||
$db = Registry::get('db');
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$this->document->title = $this->data['text_user_management'];
|
||||
|
||||
$this->data['domains'] = array();
|
||||
|
||||
/* check if we are admin */
|
||||
|
||||
if(Registry::get('admin_user') == 1) {
|
||||
|
||||
/* query available domains */
|
||||
|
||||
$this->data['domains'] = $this->model_user_user->get_domains();
|
||||
|
||||
$this->domains = $this->model_user_user->get_email_domains();
|
||||
|
||||
|
||||
if($this->request->server['REQUEST_METHOD'] == 'POST') {
|
||||
$ret = 0;
|
||||
|
||||
if($this->validate() == true){
|
||||
$ret = $this->model_user_user->addUser($this->request->post);
|
||||
|
||||
$_SESSION['last_domain'] = $this->request->post['domain'];
|
||||
|
||||
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_user_id'] = $this->model_user_user->getNextUid();
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->data['next_user_id'] = $this->model_user_user->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['password']) || !isset($this->request->post['password2']) ) {
|
||||
$this->error['password'] = $this->data['text_missing_password'];
|
||||
}
|
||||
|
||||
if(strlen(@$this->request->post['password']) < MIN_PASSWORD_LENGTH || strlen(@$this->request->post['password2']) < MIN_PASSWORD_LENGTH) {
|
||||
$this->error['password'] = $this->data['text_too_short_password'];
|
||||
}
|
||||
|
||||
if($this->request->post['password'] != $this->request->post['password2']) {
|
||||
$this->error['password'] = $this->data['text_password_mismatch'];
|
||||
}
|
||||
|
||||
if(!isset($this->request->post['uid']) || !is_numeric($this->request->post['uid']) || $this->request->post['uid'] < 0) {
|
||||
$this->error['uid'] = $this->data['text_invalid_uid'];
|
||||
}
|
||||
|
||||
if(!isset($this->request->post['email']) || strlen($this->request->post['email']) < 3) {
|
||||
$this->error['email'] = $this->data['text_invalid_email'];
|
||||
}
|
||||
else {
|
||||
$emails = explode("\n", $this->request->post['email']);
|
||||
foreach ($emails as $email) {
|
||||
$email = rtrim($email);
|
||||
$ret = checkemail($email, $this->domains);
|
||||
if($ret == 0) {
|
||||
$this->error['email'] = $this->data['text_invalid_email'] . ": $email";
|
||||
}
|
||||
else if($ret == -1) {
|
||||
$this->error['email'] = $this->data['text_email_in_unknown_domain'] . ": $email";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!isset($this->request->post['username']) || strlen($this->request->post['username']) < 2) {
|
||||
$this->error['username'] = $this->data['text_invalid_username'];
|
||||
}
|
||||
|
||||
if(isset($this->request->post['username']) && $this->model_user_user->getUidByName($this->request->post['username']) > 0) {
|
||||
$this->error['username'] = $this->data['text_existing_user'];
|
||||
}
|
||||
|
||||
if(!isset($this->request->post['domain'])) {
|
||||
$this->error['domain'] = $this->data['text_missing_data'];
|
||||
}
|
||||
|
||||
|
||||
if (!$this->error) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
142
webui/controller/user/edit.php
Normal file
142
webui/controller/user/edit.php
Normal file
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
|
||||
class ControllerUserEdit extends Controller {
|
||||
private $error = array();
|
||||
private $domains = array();
|
||||
|
||||
public function index(){
|
||||
$this->data['uid'] = 0;
|
||||
$this->data['email'] = "";
|
||||
|
||||
$this->id = "content";
|
||||
$this->template = "user/edit.tpl";
|
||||
$this->layout = "common/layout";
|
||||
|
||||
|
||||
$request = Registry::get('request');
|
||||
$db = Registry::get('db');
|
||||
$language = Registry::get('language');
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
|
||||
$this->document->title = $language->get('text_user_management');
|
||||
|
||||
$this->data['domains'] = array();
|
||||
|
||||
|
||||
if(isset($this->request->get['uid']) && is_numeric($this->request->get['uid']) && $this->request->get['uid'] > 0) {
|
||||
$this->data['uid'] = $this->request->get['uid'];
|
||||
}
|
||||
|
||||
if(isset($this->request->post['uid']) && is_numeric($this->request->post['uid']) && $this->request->post['uid'] > 0) {
|
||||
$this->data['uid'] = $this->request->post['uid'];
|
||||
}
|
||||
|
||||
|
||||
$this->domains = $this->model_user_user->get_email_domains();
|
||||
|
||||
|
||||
if(isset($this->request->get['email']) && checkemail($this->request->get['email'], $this->domains) == 1) {
|
||||
$this->data['email'] = $this->request->get['email'];
|
||||
}
|
||||
|
||||
|
||||
/* check if we are admin */
|
||||
|
||||
if(Registry::get('admin_user') == 1) {
|
||||
|
||||
$this->data['domains'] = $this->model_user_user->get_domains();
|
||||
|
||||
if($this->request->server['REQUEST_METHOD'] == 'POST') {
|
||||
if($this->validate() == true){
|
||||
|
||||
$ret = $this->model_user_user->updateUser($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;
|
||||
}
|
||||
|
||||
$__username = $this->request->post['username'];
|
||||
}
|
||||
else {
|
||||
$this->template = "common/error.tpl";
|
||||
$this->data['errorstring'] = array_pop($this->error);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->data['user'] = $this->model_user_user->getUserByUid($this->data['uid']);
|
||||
|
||||
$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['password']) && strlen(@$this->request->post['password']) > 1) {
|
||||
|
||||
if(strlen(@$this->request->post['password']) < MIN_PASSWORD_LENGTH || strlen(@$this->request->post['password2']) < MIN_PASSWORD_LENGTH) {
|
||||
$this->error['password'] = $this->data['text_invalid_password'];
|
||||
}
|
||||
|
||||
if($this->request->post['password'] != $this->request->post['password2']) {
|
||||
$this->error['password'] = $this->data['text_password_mismatch'];
|
||||
}
|
||||
}
|
||||
|
||||
if(!isset($this->request->post['uid']) || !is_numeric($this->request->post['uid']) || (int)$this->request->post['uid'] < 0) {
|
||||
$this->error['uid'] = $this->data['text_invalid_uid'];
|
||||
}
|
||||
|
||||
if(strlen(@$this->request->post['email']) < 4) {
|
||||
$this->error['email'] = $this->data['text_invalid_email'];
|
||||
} else {
|
||||
$emails = explode("\n", $this->request->post['email']);
|
||||
foreach ($emails as $email) {
|
||||
$email = rtrim($email);
|
||||
$ret = checkemail($email, $this->domains);
|
||||
if($ret == 0) {
|
||||
$this->error['email'] = $this->data['text_invalid_email'] . ": $email";
|
||||
}
|
||||
else if($ret == -1) {
|
||||
$this->error['email'] = $this->data['text_email_in_unknown_domain'] . ": $email";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!isset($this->request->post['username']) || strlen($this->request->post['username']) < 2 ) {
|
||||
$this->error['username'] = $this->data['text_invalid_username'];
|
||||
}
|
||||
|
||||
|
||||
if (!$this->error) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
101
webui/controller/user/list.php
Normal file
101
webui/controller/user/list.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
|
||||
class ControllerUserList extends Controller {
|
||||
private $error = array();
|
||||
|
||||
public function index(){
|
||||
|
||||
$this->id = "content";
|
||||
$this->template = "user/list.tpl";
|
||||
$this->layout = "common/layout";
|
||||
|
||||
|
||||
$request = Registry::get('request');
|
||||
$db = Registry::get('db');
|
||||
$language = Registry::get('language');
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$this->document->title = $language->get('text_user_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'] = 'username';
|
||||
|
||||
$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) {
|
||||
|
||||
$users = $this->model_user_user->getUsers($this->data['search'], $this->data['page'], $this->data['page_len'],
|
||||
$this->data['sort'], $this->data['order']);
|
||||
|
||||
$this->data['total_users'] = $this->model_user_user->howManyUsers($this->data['search']);
|
||||
|
||||
foreach ($users as $user) {
|
||||
$policy_group = DEFAULT_POLICY;
|
||||
|
||||
$this->data['users'][] = array(
|
||||
'uid' => $user['uid'],
|
||||
'username' => $user['username'],
|
||||
'realname' => $user['realname'],
|
||||
'email' => $user['email'],
|
||||
'shortemail' => short_email($user['email']),
|
||||
'domain' => $user['domain'],
|
||||
'policy_group' => $policy_group,
|
||||
'isadmin' => $user['isadmin']
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
76
webui/controller/user/remove.php
Normal file
76
webui/controller/user/remove.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
|
||||
class ControllerUserRemove extends Controller {
|
||||
private $error = array();
|
||||
private $domains = array();
|
||||
private $d = array();
|
||||
|
||||
public function index(){
|
||||
|
||||
$this->id = "content";
|
||||
$this->template = "user/remove.tpl";
|
||||
$this->layout = "common/layout";
|
||||
|
||||
|
||||
$request = Registry::get('request');
|
||||
$db = Registry::get('db');
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$this->document->title = $this->data['text_user_management'];
|
||||
|
||||
|
||||
$this->data['username'] = Registry::get('username');
|
||||
|
||||
$this->data['uid'] = (int)@$this->request->get['uid'];
|
||||
$this->data['user'] = @$this->request->get['user'];
|
||||
$this->data['confirmed'] = (int)@$this->request->get['confirmed'];
|
||||
|
||||
|
||||
if($this->validate() == true) {
|
||||
|
||||
if($this->data['confirmed'] == 1) {
|
||||
$ret = $this->model_user_user->deleteUser($this->data['uid']);
|
||||
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['uid']) || !is_numeric($this->request->get['uid']) || $this->request->get['uid'] < 1 ) {
|
||||
$this->error['username'] = $this->data['text_invalid_uid'];
|
||||
}
|
||||
|
||||
|
||||
if (!$this->error) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
78
webui/controller/user/settings.php
Normal file
78
webui/controller/user/settings.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
|
||||
class ControllerUserSettings extends Controller {
|
||||
private $error = array();
|
||||
|
||||
public function index(){
|
||||
|
||||
$this->id = "content";
|
||||
$this->template = "user/settings.tpl";
|
||||
$this->layout = "common/layout";
|
||||
|
||||
|
||||
$request = Registry::get('request');
|
||||
$db = Registry::get('db');
|
||||
|
||||
$this->load->model('user/auth');
|
||||
$this->load->model('user/prefs');
|
||||
|
||||
|
||||
$this->document->title = $this->data['text_home'];
|
||||
|
||||
|
||||
if(isset($this->request->post['pagelen']) && isset($this->request->post['lang']) && isset($this->request->post['theme'])) {
|
||||
$this->model_user_prefs->set_user_preferences(Registry::get('username'), $this->request->post);
|
||||
|
||||
AUDIT(ACTION_CHANGE_USER_SETTINGS, '', '', '', 'lang:' . $this->request->post['lang'] . ', pagelen:' . $this->request->post['pagelen'] . ', theme:' . $this->request->post['theme']);
|
||||
|
||||
Header("Location: settings.php");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if($this->request->server['REQUEST_METHOD'] == 'POST' && PASSWORD_CHANGE_ENABLED == 1 && $this->validate() == true) {
|
||||
|
||||
if($this->model_user_auth->changePassword(Registry::get('username'), $this->request->post['password']) == 1) {
|
||||
$this->data['x'] = $this->data['text_password_changed'];
|
||||
}
|
||||
else {
|
||||
$this->data['x'] = $this->data['text_failed_to_change_password'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->data['page_len'] = get_page_length();
|
||||
|
||||
$this->render();
|
||||
}
|
||||
|
||||
|
||||
private function validate() {
|
||||
|
||||
if(!isset($this->request->post['password']) || !isset($this->request->post['password2']) ) {
|
||||
$this->error['password'] = $this->data['text_missing_password'];
|
||||
}
|
||||
|
||||
if(strlen(@$this->request->post['password']) < MIN_PASSWORD_LENGTH || strlen(@$this->request->post['password2']) < MIN_PASSWORD_LENGTH) {
|
||||
$this->error['password'] = $this->data['text_invalid_password'];
|
||||
}
|
||||
|
||||
if($this->request->post['password'] != $this->request->post['password2']) {
|
||||
$this->error['password'] = $this->data['text_password_mismatch'];
|
||||
}
|
||||
|
||||
|
||||
if (!$this->error) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user