mirror of
https://bitbucket.org/jsuto/piler.git
synced 2025-06-12 23:27:03 +02:00
webui code cleanup
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
|
||||
class ModelStatCounter extends Model {
|
||||
|
||||
public function getCounters(){
|
||||
public function get_counters(){
|
||||
$counter = array();
|
||||
$asize = 0;
|
||||
|
||||
@ -32,7 +32,7 @@ class ModelStatCounter extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function resetCounters(){
|
||||
public function reset_counters(){
|
||||
|
||||
if(MEMCACHED_ENABLED) {
|
||||
$memcache = Registry::get('memcache');
|
||||
|
@ -50,7 +50,7 @@ class ModelUserAuth extends Model {
|
||||
$_SESSION['admin_user'] = 0;
|
||||
$_SESSION['email'] = $user['username'];
|
||||
|
||||
$this->changePassword($user['username'], $password);
|
||||
$this->change_password($user['username'], $password);
|
||||
|
||||
AUDIT(ACTION_LOGIN, $user['username'], '', '', 'changed password in local table');
|
||||
|
||||
@ -64,7 +64,7 @@ class ModelUserAuth extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function changePassword($username = '', $password = '') {
|
||||
public function change_password($username = '', $password = '') {
|
||||
if($username == "" || $password == ""){ return 0; }
|
||||
|
||||
$query = $this->db->query("UPDATE " . TABLE_USER . " SET password=? WHERE username=?", array(crypt($password), $username));
|
||||
|
@ -4,18 +4,10 @@
|
||||
class ModelUserImport extends Model {
|
||||
|
||||
|
||||
public function getLdapParameters() {
|
||||
$my_domain = $this->model_user_user->getDomains();
|
||||
$query = $this->db->query("SELECT remotehost, basedn, binddn FROM " . TABLE_REMOTE . " WHERE remotedomain=?", array($my_domain[0]));
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
|
||||
public function queryRemoteUsers($host) {
|
||||
public function query_remote_users($host) {
|
||||
$data = array();
|
||||
|
||||
LOGGER("running queryRemoteUsers() ...");
|
||||
LOGGER("running query_remote_users() ...");
|
||||
|
||||
$attrs = array("cn", "mail", "mailAlternateAddress", "memberdn", "memberaddr");
|
||||
$mailAttr = 'mail';
|
||||
@ -111,7 +103,7 @@ class ModelUserImport extends Model {
|
||||
|
||||
|
||||
|
||||
public function fillRemoteTable($host = array(), $domain = '') {
|
||||
public function fill_remote_table($host = array(), $domain = '') {
|
||||
if($domain == '') { return 0; }
|
||||
|
||||
/*
|
||||
@ -141,7 +133,7 @@ class ModelUserImport extends Model {
|
||||
|
||||
|
||||
|
||||
public function processUsers($users = array(), $globals = array()) {
|
||||
public function process_users($users = array(), $globals = array()) {
|
||||
$late_add = array();
|
||||
$uids = array();
|
||||
$exclude = array();
|
||||
@ -149,7 +141,7 @@ class ModelUserImport extends Model {
|
||||
$deleteduser = 0;
|
||||
$n = 0;
|
||||
|
||||
LOGGER("running processUsers() ...");
|
||||
LOGGER("running process_users() ...");
|
||||
|
||||
/* build a list of DNs to exclude from the import */
|
||||
|
||||
@ -170,7 +162,7 @@ class ModelUserImport extends Model {
|
||||
|
||||
/* Does this DN exist in the user table ? */
|
||||
|
||||
$__user = $this->model_user_user->getUserByDN($_user['dn']);
|
||||
$__user = $this->model_user_user->get_user_by_dn($_user['dn']);
|
||||
|
||||
if(isset($__user['uid'])) {
|
||||
|
||||
@ -180,7 +172,7 @@ class ModelUserImport extends Model {
|
||||
/* if so, then verify the email addresses */
|
||||
|
||||
$changed = 0;
|
||||
$emails = $this->model_user_user->getEmailsByUid($__user['uid']);
|
||||
$emails = $this->model_user_user->get_emails_by_uid($__user['uid']);
|
||||
|
||||
/* first let's add the new email addresses */
|
||||
|
||||
@ -189,7 +181,7 @@ class ModelUserImport extends Model {
|
||||
|
||||
foreach ($ldap_emails as $email) {
|
||||
if(!in_array($email, $sql_emails)) {
|
||||
$rc = $this->model_user_user->addEmail($__user['uid'], $email);
|
||||
$rc = $this->model_user_user->add_email($__user['uid'], $email);
|
||||
$changed++;
|
||||
|
||||
/* in case of an error add it to the $late_add array() */
|
||||
@ -208,7 +200,7 @@ class ModelUserImport extends Model {
|
||||
|
||||
foreach ($sql_emails as $email) {
|
||||
if(!in_array($email, $ldap_emails)) {
|
||||
$rc = $this->model_user_user->removeEmail($__user['uid'], $email);
|
||||
$rc = $this->model_user_user->remove_email($__user['uid'], $email);
|
||||
$changed++;
|
||||
}
|
||||
}
|
||||
@ -224,7 +216,7 @@ class ModelUserImport extends Model {
|
||||
$user = $this->createNewUserArray($_user['dn'], $_user['username'], $_user['realname'], $_user['emails'], $globals);
|
||||
array_push($uids, $user['uid']);
|
||||
|
||||
$rc = $this->model_user_user->addUser($user);
|
||||
$rc = $this->model_user_user->add_user($user);
|
||||
if($rc == 1) { $newuser++; }
|
||||
}
|
||||
}
|
||||
@ -233,7 +225,7 @@ class ModelUserImport extends Model {
|
||||
/* add the rest to the email table */
|
||||
|
||||
foreach ($late_add as $new) {
|
||||
$rc = $this->model_user_user->addEmail($new['uid'], $new['email']);
|
||||
$rc = $this->model_user_user->add_email($new['uid'], $new['email']);
|
||||
if($rc == 1) { $newuser++; }
|
||||
}
|
||||
|
||||
@ -258,7 +250,7 @@ class ModelUserImport extends Model {
|
||||
foreach ($users as $user) {
|
||||
if($user['members']) {
|
||||
|
||||
$group = $this->model_user_user->getUserByDN($user['dn']);
|
||||
$group = $this->model_user_user->get_user_by_dn($user['dn']);
|
||||
|
||||
$members = explode("\n", $user['members']);
|
||||
if(count($members) > 0) {
|
||||
@ -269,9 +261,9 @@ class ModelUserImport extends Model {
|
||||
|
||||
foreach ($members as $member) {
|
||||
if(validemail($member)) {
|
||||
$__user = $this->model_user_user->getUserByEmail($member);
|
||||
$__user = $this->model_user_user->get_user_by_email($member);
|
||||
} else {
|
||||
$__user = $this->model_user_user->getUserByDN($member);
|
||||
$__user = $this->model_user_user->get_user_by_dn($member);
|
||||
}
|
||||
|
||||
if(isset($group['uid']) && isset($__user['uid'])) {
|
||||
@ -291,7 +283,7 @@ class ModelUserImport extends Model {
|
||||
private function createNewUserArray($dn = '', $username = '', $realname = '', $emails = '', $globals = array()) {
|
||||
$user = array();
|
||||
|
||||
$user['uid'] = $this->model_user_user->getNextUid();
|
||||
$user['uid'] = $this->model_user_user->get_next_uid();
|
||||
$user['gid'] = $globals['gid'];
|
||||
|
||||
$user['email'] = $emails;
|
||||
@ -322,7 +314,7 @@ class ModelUserImport extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function trashPassword($users = array()) {
|
||||
public function trash_password($users = array()) {
|
||||
foreach ($users as $user) {
|
||||
$query = $this->db->query("UPDATE " . TABLE_USER . " SET password='*' WHERE dn=?", array($user['dn']));
|
||||
$rc = $this->db->countAffected();
|
||||
|
@ -3,7 +3,7 @@
|
||||
class ModelUserUser extends Model {
|
||||
|
||||
|
||||
public function checkUID($uid) {
|
||||
public function check_uid($uid) {
|
||||
if($uid == "") { return 0; }
|
||||
|
||||
if(!is_numeric($uid)) { return 0; }
|
||||
@ -14,7 +14,7 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function getUidByName($username = '') {
|
||||
public function get_uid_by_name($username = '') {
|
||||
if($username == ""){ return -1; }
|
||||
|
||||
$query = $this->db->query("SELECT uid FROM " . TABLE_USER . " WHERE username=?", array($username));
|
||||
@ -27,18 +27,6 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function getUsernameByUid($uid = 0) {
|
||||
|
||||
$query = $this->db->query("SELECT username FROM " . TABLE_USER . " WHERE uid=?", array((int)$uid));
|
||||
|
||||
if(isset($query->row['username'])){
|
||||
return $query->row['username'];
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public function get_uid_by_email($email = '') {
|
||||
$query = $this->db->query("SELECT uid FROM " . TABLE_EMAIL . " WHERE email=?", array($email));
|
||||
|
||||
@ -109,19 +97,7 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function getEmailAddress($username = '') {
|
||||
|
||||
$query = $this->db->query("SELECT " . TABLE_EMAIL . ".email AS email FROM " . TABLE_EMAIL . "," . TABLE_USER . " WHERE " . TABLE_EMAIL . ".uid=" . TABLE_USER . ".uid AND " . TABLE_USER . ".username=? LIMIT 1", array($username));
|
||||
|
||||
if(isset($query->row['email'])){
|
||||
return $query->row['email'];
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public function getEmails($username = '') {
|
||||
public function get_emails($username = '') {
|
||||
$emails = "";
|
||||
|
||||
$query = $this->db->query("SELECT " . TABLE_EMAIL . ".email AS email FROM " . TABLE_EMAIL . "," . TABLE_USER . " WHERE " . TABLE_EMAIL . ".uid=" . TABLE_USER . ".uid AND " . TABLE_USER . ".username=?", array($username));
|
||||
@ -134,7 +110,7 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function getEmailsByUid($uid = 0) {
|
||||
public function get_emails_by_uid($uid = 0) {
|
||||
$emails = "";
|
||||
|
||||
$query = $this->db->query("SELECT email FROM " . TABLE_EMAIL . " WHERE uid=?", array((int)$uid));
|
||||
@ -146,7 +122,7 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function getUserByDN($dn = '') {
|
||||
public function get_user_by_dn($dn = '') {
|
||||
if($dn == '') { return array(); }
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . TABLE_USER . " WHERE dn=?", array($dn));
|
||||
@ -170,7 +146,7 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function getUserByEmail($email = '') {
|
||||
public function get_user_by_email($email = '') {
|
||||
if($email == '') {
|
||||
return array();
|
||||
}
|
||||
@ -181,20 +157,7 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function getUsernameByEmail($email = '') {
|
||||
$username = "";
|
||||
|
||||
if($email == '') { return $username; }
|
||||
|
||||
$query = $this->db->query("SELECT username FROM " . TABLE_USER . " WHERE uid IN (SELECT uid FROM " . TABLE_EMAIL . " WHERE email=?)", array($email));
|
||||
|
||||
if(isset($query->row['username'])) { $username = $query->row['username']; }
|
||||
|
||||
return $username;
|
||||
}
|
||||
|
||||
|
||||
public function getUsers($search = '', $page = 0, $page_len = 0, $sort = 'username', $order = 0) {
|
||||
public function get_users($search = '', $page = 0, $page_len = 0, $sort = 'username', $order = 0) {
|
||||
$where_cond = " WHERE " . TABLE_USER . ".uid=" . TABLE_EMAIL . ".uid ";
|
||||
$_order = "";
|
||||
$users = array();
|
||||
@ -240,7 +203,7 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function howManyUsers($search = '') {
|
||||
public function count_users($search = '') {
|
||||
$where_cond = "";
|
||||
|
||||
if($search){
|
||||
@ -279,7 +242,7 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function getNextUid() {
|
||||
public function get_next_uid() {
|
||||
|
||||
$query = $this->db->query("SELECT MAX(uid) AS last_id FROM " . TABLE_USER);
|
||||
|
||||
@ -291,11 +254,11 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function addUser($user) {
|
||||
public function add_user($user) {
|
||||
LOGGER("add user: " . $user['username'] . ", uid=" . (int)$user['uid']);
|
||||
|
||||
if(!isset($user['domain']) || $user['domain'] == "") { return -1; }
|
||||
if(!isset($user['username']) || $user['username'] == "" || $this->getUidByName($user['username']) > 0) { return -1; }
|
||||
if(!isset($user['username']) || $user['username'] == "" || $this->get_uid_by_name($user['username']) > 0) { return -1; }
|
||||
|
||||
$emails = explode("\n", $user['email']);
|
||||
foreach ($emails as $email) {
|
||||
@ -330,7 +293,7 @@ class ModelUserUser extends Model {
|
||||
foreach ($emails as $email) {
|
||||
$email = rtrim($email);
|
||||
|
||||
$ret = $this->addEmail((int)$user['uid'], $email);
|
||||
$ret = $this->add_email((int)$user['uid'], $email);
|
||||
if($ret == 0) { return -2; }
|
||||
}
|
||||
|
||||
@ -339,7 +302,7 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function addEmail($uid = 0, $email = '') {
|
||||
public function add_email($uid = 0, $email = '') {
|
||||
if($uid < 1 || $email == ""){ return 0; }
|
||||
|
||||
$query = $this->db->query("INSERT INTO " . TABLE_EMAIL . " (uid, email) VALUES(?,?)", array((int)$uid, $email));
|
||||
@ -352,7 +315,7 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function removeEmail($uid = 0, $email = '') {
|
||||
public function remove_email($uid = 0, $email = '') {
|
||||
if((int)$uid < 1 || $email == ""){ return 0; }
|
||||
|
||||
$query = $this->db->query("DELETE FROM " . TABLE_EMAIL . " WHERE uid=? AND email=?", array((int)$uid, $email));
|
||||
@ -365,7 +328,7 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function updateUser($user) {
|
||||
public function update_user($user) {
|
||||
LOGGER("update user: " . $user['username'] . ", uid=" . (int)$user['uid']);
|
||||
|
||||
$emails = explode("\n", $user['email']);
|
||||
@ -413,8 +376,8 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function deleteUser($uid) {
|
||||
if(!$this->checkUID($uid)){ return 0; }
|
||||
public function delete_user($uid) {
|
||||
if(!$this->check_uid($uid)){ return 0; }
|
||||
|
||||
$query = $this->db->query("DELETE FROM " . TABLE_EMAIL . " WHERE uid=?", array((int)$uid));
|
||||
$query = $this->db->query("DELETE FROM " . TABLE_USER . " WHERE uid=?", array((int)$uid));
|
||||
|
Reference in New Issue
Block a user