gforge-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gforge-commits] gforge/common/include System.class, NONE, 1.1 Group.cla


From: cbayle
Subject: [Gforge-commits] gforge/common/include System.class, NONE, 1.1 Group.class, 1.43, 1.44 User.class, 1.32, 1.33 ldap.php, 1.14, NONE
Date: Sun, 09 May 2004 13:15:39 -0500

Update of /cvsroot/gforge/gforge/common/include
In directory db.perdue.net:/tmp/cvs-serv13096/common/include

Modified Files:
        Group.class User.class 
Added Files:
        System.class 
Removed Files:
        ldap.php 
Log Message:
OO rewrite of system interaction


--- NEW FILE: System.class ---
<?php
/**
 * System class
 *
 * Class to interact with the system
 *
 * @version   $Id: System.class,v 1.1 2004/05/09 18:15:37 cbayle Exp $
 * @author Christian Bayle
 * @date 2004-02-05
 *
 * This file is part of GForge.
 *
 * GForge is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * GForge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GForge; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * Constants
 */
        
/**
 * Value to add to group_id to get unix gid
 *
 * @var constant                $GID_ADD
 */
$GID_ADD = 10000;
        
/**
 * Value to add to unix_uid to get unix uid
 * 
 * @var constant                $UID_ADD
 */
$UID_ADD = 20000;
        
/**
 * Value to add to unix gid to get unix uid of anoncvs special user
 *
 * @var constant                $ANONCVS_UID_ADD
 */
$ANONCVS_UID_ADD = 50000;

class System extends Error {
        /**
        *       System()
        *
        */
        function System() {
                $this->Error();
                return true;
        }

        /*
        * User management functions
        */

        /**
        * sys_check_user() - Check for the existence of a user
        * 
        * @param                int             The user ID of the user to check
        * @returns true on success/false on error
        *
        */
        function sys_check_user($user_id) {
                $user =& user_get_object($user_id);
                if (!$user) {
                        return false;
                }
                return true;
        }

        /**
        * sys_create_user() - Create a user
        *
        * @param                int     The user ID of the user to create
        * @returns The return status
        *
        */
        function sys_create_user($user_id) {
                $user = &user_get_object($user_id);
                if (!$user) {
                        return false;
                }
                return true;
        }

        /**
        * sys_check_create_user() - Check that a user has been created
        *
        * @param                int             The ID of the user to check
        * @returns true on success/false on error
        *
        */
        function sys_check_create_user($user_id) {
                return true;
        }

        /**
        * sys_remove_user() - Remove a user
        *
        * @param                int             The user ID of the user to 
remove
        * @returns true on success/false on failure
        *
        */
        function sys_remove_user($user_id) {
                return true;
        }

        /**
        * sys_user_set_attribute() - Set an attribute for a user
        *
        * @param                int             The user ID 
        * @param                string  The attribute to set
        * @param                string  The new value of the attribute
        * @returns true on success/false on error
        *
        */
        function sys_user_set_attribute($user_id,$attr,$value) {
                return true;
        }

        /*
        * Group management functions
        */
        
        /**
        * sys_check_group() - Check for the existence of a group
        * 
        * @param                int             The ID of the group to check
        * @returns true on success/false on error
        *
        */
        function sys_check_group($group_id) {
                return true;
        }

        /**
        * sys_create_group() - Create a group
        * 
        * @param                int             The ID of the group to create
        * @returns true on success/false on error
        *
        */
        function sys_create_group($group_id) {
                return true;
        }

        /**
        * sys_remove_group() - Remove a group
        * 
        * @param                int             The ID of the group to remove
        * @returns true on success/false on error
        *
        */
        function sys_remove_group($group_id) {
                return true;
        }

        /**
        * sys_group_add_user() - Add a user to a group
        *
        * @param                int             The ID of the group two which 
the user will be added
        * @param                int             The ID of the user to add
        * @param                bool    Only add this user to CVS
        * @returns true on success/false on error
        *
        */
        function sys_group_add_user($group_id,$user_id,$cvs_only=0) {
                return true;
        }

        /**
        * sys_group_remove_user() - Remove a user from a group
        *
        * @param                int             The ID of the group from which 
to remove the user
        * @param                int             The ID of the user to remove
        * @param                bool    Only remove user from CVS group
        * @returns true on success/false on error
        *
        */
        function sys_group_remove_user($group_id,$user_id,$cvs_only=0) {
                return true;
        }
}

// Local Variables:
// mode: php
// c-file-style: "bsd"
// End:

?>

Index: Group.class
===================================================================
RCS file: /cvsroot/gforge/gforge/common/include/Group.class,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- Group.class 15 Mar 2004 23:48:42 -0000      1.43
+++ Group.class 9 May 2004 18:15:37 -0000       1.44
@@ -584,7 +584,7 @@
         *      @access public.
         */
        function setStatus(&$user, $status) {
-               global $Language;
+               global $Language,$SYS;
 
                $perm =& $this->getPermission($user);
 
@@ -631,10 +631,10 @@
 
                if ($status=='A') {
                        // Activate LDAP group, if not yet
-                       if (!sf_ldap_check_group($this->getID())) {
+                       if (!$SYS->sys_check_group($this->getID())) {
 
-                               if (!sf_ldap_create_group($this->getID())) {
-                                       
$this->setError(sf_ldap_get_error_msg());
+                               if (!$SYS->sys_create_group($this->getID())) {
+                                       
$this->setError($SYS->getErrorMessage());
                                        db_rollback();
                                        return false;
                                }
@@ -647,10 +647,10 @@
 
                /* Otherwise, the group is not active, and make sure that
                   LDAP group is not active either */
-               } else if (sf_ldap_check_group($this->getID())) {
+               } else if ($SYS->sys_check_group($this->getID())) {
 
-                       if (!sf_ldap_remove_group($this->getID())) {
-                               $this->setError(sf_ldap_get_error_msg());
+                       if (!$SYS->sys_remove_group($this->getID())) {
+                               $this->setError($SYS->getErrorMessage());
                                db_rollback();
                                return false;
                        }
@@ -1163,6 +1163,7 @@
         *      @access public.
         */
        function addUser($user_unix_name) {
+               global $Language,$SYS;
                /*
                        Admins can add users to groups
                */
@@ -1211,12 +1212,12 @@
                                if ( !db_result($res_newuser,0,'unix_uid') ) {
                                        
$user=&user_get_object($form_newuid,$res_newuser);
                                        if (!$user->setUpUnixUID()) {
-                                               $this->setError('ERROR: Cannot 
assign UNIX uid to the user');
+                                               $this->setError('ERROR: Cannot 
assign UNIX uid to the user: '.$user->getErrorMessage());
                                                db_rollback();
                                                return false;
                                        }
-                                       if (!sf_ldap_create_user($form_newuid)) 
{
-                                               
$this->setError(sf_ldap_get_error_msg());
+                                       if 
(!$SYS->sys_create_user($form_newuid)) {
+                                               
$this->setError($SYS->getErrorMessage());
                                                db_rollback();
                                                return false;
                                        }
@@ -1224,8 +1225,8 @@
                                        //
                                        //      User already had unix account
                                        //
-                                       if 
(!sf_ldap_check_create_user($form_newuid)) {
-                                               
$this->setError(sf_ldap_get_error_msg());
+                                       if 
(!$SYS->sys_check_create_user($form_newuid)) {
+                                               
$this->setError($SYS->getErrorMessage());
                                                db_rollback();
                                                return false;
                                        }
@@ -1247,8 +1248,8 @@
                                //
                                //      set up their ldap info
                                //
-                               if 
(!sf_ldap_group_add_user($this->getID(),$form_newuid)) {
-                                       
$this->setError(sf_ldap_get_error_msg());
+                               if 
(!$SYS->sys_group_add_user($this->getID(),$form_newuid)) {
+                                       
$this->setError($SYS->getErrorMessage());
                                        db_rollback();
                                        return false;
                                }
@@ -1261,18 +1262,18 @@
                                //
                                
$user=&user_get_object($form_newuid,$res_newuser);
                                if (!$user->setUpUnixUID()) {
-                                       $this->setError('ERROR: could not set 
up unix_uid for user: '.$user->getErrorMessage());
+                                       $this->setError('ERROR: Cannot assign 
UNIX uid to the user: '.$user->getErrorMessage());
                                        db_rollback();
                                        return false;
                                } else {
                                        $user->fetchData($user->getID());
-                                       if 
(!sf_ldap_check_create_user($form_newuid)) {
-                                               
$this->setError(sf_ldap_get_error_msg());
+                                       if 
(!$SYS->sys_check_create_user($form_newuid)) {
+                                               
$this->setError($SYS->getErrorMessage());
                                                db_rollback();
                                                return false;
                                        }
-                                               if 
(!sf_ldap_group_add_user($this->getID(),$form_newuid)) {
-                                               
$this->setError(sf_ldap_get_error_msg());
+                                               if 
(!$SYS->sys_group_add_user($this->getID(),$form_newuid)) {
+                                               
$this->setError($SYS->getErrorMessage());
                                                db_rollback();
                                                return false;
                                        }
@@ -1305,6 +1306,7 @@
         *      @return boolean success.
         */ 
        function removeUser($user_id) {
+               global $Language,$SYS;
 
                if ($user_id==user_getid()) {
                        //users can remove themselves
@@ -1343,8 +1345,8 @@
                                WHERE group_id='".$this->getID()."') 
                                AND user_id='$user_id'");
 
-                       if 
(!sf_ldap_group_remove_user($this->getID(),$user_id)) {
-                               $this->setError(sf_ldap_get_error_msg());
+                       if 
(!$SYS->sys_group_remove_user($this->getID(),$user_id)) {
+                               $this->setError($SYS->getErrorMessage());
                                db_rollback();
                                return false;
                        }
@@ -1371,6 +1373,7 @@
         *      @return boolean success.
         */      
        function 
updateUser($user_id,$admin_flags='',$forum_flags=0,$project_flags=1,$doc_flags=0,$cvs_flags=1,$release_flags=1,$member_role=100,$artifact_flags=0)
 {
+               global $Language,$SYS;
 
        $perm =& $this->getPermission( session_get_user() );
 
@@ -1409,14 +1412,14 @@
                //      else - restricted.
                //
                if ($cvs_flags>1) {
-                       if 
(!sf_ldap_user_set_attribute($user_id,"debGforgeCvsShell","/bin/bash")) {
-                               $this->setError(sf_ldap_get_error_msg());
+                       if 
(!$SYS->sys_user_set_attribute($user_id,"debGforgeCvsShell","/bin/bash")) {
+                               $this->setError($SYS->getErrorMessage());
                                db_rollback();
                                return false;
                        }
                } else {
-                       if 
(!sf_ldap_user_set_attribute($user_id,"debGforgeCvsShell","/bin/cvssh")) {
-                               $this->setError(sf_ldap_get_error_msg());
+                       if 
(!$SYS->sys_user_set_attribute($user_id,"debGforgeCvsShell","/bin/cvssh")) {
+                               $this->setError($SYS->getErrorMessage());
                                db_rollback();
                                return false;
                        }
@@ -1427,14 +1430,14 @@
                //      one to be promoted to CVS group, else, demoted.
                //
                if ($cvs_flags>0) {
-                       if (!sf_ldap_group_add_user($this->getID(),$user_id,1)) 
{
-                               $this->setError(sf_ldap_get_error_msg());
+                       if 
(!$SYS->sys_group_add_user($this->getID(),$user_id,1)) {
+                               $this->setError($SYS->getErrorMessage());
                                db_rollback();
                                return false;
                        }
                } else {
-                       if 
(!sf_ldap_group_remove_user($this->getID(),$user_id,1)) {
-                               $this->setError(sf_ldap_get_error_msg());
+                       if 
(!$SYS->sys_group_remove_user($this->getID(),$user_id,1)) {
+                               $this->setError($SYS->getErrorMessage());
                                db_rollback();
                                return false;
                        }

Index: User.class
===================================================================
RCS file: /cvsroot/gforge/gforge/common/include/User.class,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- User.class  16 Apr 2004 11:34:12 -0000      1.32
+++ User.class  9 May 2004 18:15:37 -0000       1.33
@@ -544,10 +544,16 @@
        /**
         *      setUnixStatus - Sets status of activation of unix account.
         *
-        *  @param      string  The unix status.
+        *      @param  string  The unix status.
+        *      N       no_unix_account
+        *      A       active
+        *      S       suspended
+        *      D       deleted
+        *
         *      @return boolean success.
         */
        function setUnixStatus($status) {
+               global $Language,$SYS;
                db_begin();
                if ($status != 'N') {
                        $this->setUpUnixUID () ;
@@ -565,15 +571,15 @@
                        return false;
                } else {
                        if ($status == 'A') {
-                               if (!sf_ldap_check_create_user($this->getID())) 
{
-                                       
$this->setError(sf_ldap_get_error_msg());
+                               if 
(!$SYS->sys_check_create_user($this->getID())) {
+                                       
$this->setError($SYS->getErrorMessage());
                                        db_rollback();
                                        return false;
                                }
                        } else {
-                               if (sf_ldap_check_user($this->getID())) {
-                                       if 
(!sf_ldap_remove_user($this->getID())) {
-                                               
$this->setError(sf_ldap_get_error_msg());
+                               if ($SYS->sys_check_user($this->getID())) {
+                                       if 
(!$SYS->sys_remove_user($this->getID())) {
+                                               
$this->setError($SYS->getErrorMessage());
                                                db_rollback();
                                                return false;
                                        }
@@ -783,6 +789,7 @@
         *      @return boolean success.
         */
        function setShell($shell) {
+               global $Language,$SYS;
                $shells = file('/etc/shells');
                $shells[count($shells)] = "/bin/cvssh";
                $out_shells = array();
@@ -811,10 +818,10 @@
                } else {
                        // Now change LDAP attribute, but only if corresponding
                        // entry exists (i.e. if user have shell access)
-                       if (sf_ldap_check_user($this->getID()))
+                       if ($SYS->sys_check_user($this->getID()))
                        {
-                               if 
(!sf_ldap_user_set_attribute($this->getID(),"loginShell",$shell)) {
-                                       
$this->setError(sf_ldap_get_error_msg());
+                               if 
(!$SYS->sys_user_set_attribute($this->getID(),"loginShell",$shell)) {
+                                       
$this->setError($SYS->getErrorMessage());
                                        db_rollback();
                                        return false;
                                }
@@ -825,11 +832,6 @@
                return true;
        }
 
-       /**
-        *      getUnixUid - this user's unix_uid.
-        *
-        *      @return int     This user's unix_uid.
-        */
        function getUnixUID() {
                return $this->data_array['unix_uid'];
        }
@@ -1105,6 +1107,7 @@
         *      @return boolean success.
         */
        function setPasswd($passwd) {
+               global $Language,$SYS;
                if (!account_pwvalid($passwd)) {
                        $this->setError('Error: '.$GLOBALS['register_error']);
                        return false;
@@ -1127,9 +1130,9 @@
                } else {
                        // Now change LDAP password, but only if corresponding
                        // entry exists (i.e. if user have shell access)
-                       if (sf_ldap_check_user($this->getID())) {
-                               if 
(!sf_ldap_user_set_attribute($this->getID(),"userPassword",'{crypt}'.$unix_pw)) 
{
-                                       
$this->setError(sf_ldap_get_error_msg());
+                       if ($SYS->sys_check_user($this->getID())) {
+                               if 
(!$SYS->sys_user_set_attribute($this->getID(),"userPassword",'{crypt}'.$unix_pw))
 {
+                                       
$this->setError($SYS->getErrorMessage());
                                        db_rollback();
                                        return false;
                                }

--- ldap.php DELETED ---





reply via email to

[Prev in Thread] Current Thread [Next in Thread]