Changeset 6687

Show
Ignore:
Timestamp:
10/02/08 11:17:43 (2 months ago)
Author:
dduponchelle
Message:

New ACL Functions added in order to use Actions Access.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/centreon/www/include/common/common-Func-ACL.php

    r6646 r6687  
    247247         * 
    248248         * @param{TAB}int{TAB}$argument1{TAB}Mon premier argument 
    249          * @param{TAB}string{TAB}$argument2{TAB}Mon deuxième argument 
     249         * @param{TAB}string{TAB}$argument2{TAB}Mon deuxiᅵme argument 
    250250         * @return{TAB}int{TAB}Ma valeur de retour 
    251251         */ 
     
    330330         * 
    331331         * @param{TAB}int{TAB}$argument1{TAB}Mon premier argument 
    332          * @param{TAB}string{TAB}$argument2{TAB}Mon deuxième argument 
     332         * @param{TAB}string{TAB}$argument2{TAB}Mon deuxiᅵme argument 
    333333         * @return{TAB}int{TAB}Ma valeur de retour 
    334334         */ 
     
    369369         * 
    370370         * @param{TAB}int{TAB}$argument1{TAB}Mon premier argument 
    371          * @param{TAB}string{TAB}$argument2{TAB}Mon deuxième argument 
     371         * @param{TAB}string{TAB}$argument2{TAB}Mon deuxiᅵme argument 
    372372         * @return{TAB}int{TAB}Ma valeur de retour 
    373373         */ 
     
    407407         * 
    408408         * @param{TAB}int{TAB}$argument1{TAB}Mon premier argument 
    409          * @param{TAB}string{TAB}$argument2{TAB}Mon deuxième argument 
     409         * @param{TAB}string{TAB}$argument2{TAB}Mon deuxiᅵme argument 
    410410         * @return{TAB}int{TAB}Ma valeur de retour 
    411411         */ 
     
    431431         * 
    432432         * @param{TAB}int{TAB}$argument1{TAB}Mon premier argument 
    433          * @param{TAB}string{TAB}$argument2{TAB}Mon deuxième argument 
     433         * @param{TAB}string{TAB}$argument2{TAB}Mon deuxiᅵme argument 
    434434         * @return{TAB}int{TAB}Ma valeur de retour 
    435435         */ 
     
    478478         * 
    479479         * @param{TAB}int{TAB}$argument1{TAB}Mon premier argument 
    480          * @param{TAB}string{TAB}$argument2{TAB}Mon deuxième argument 
     480         * @param{TAB}string{TAB}$argument2{TAB}Mon deuxiᅵme argument 
    481481         * @return{TAB}int{TAB}Ma valeur de retour 
    482482         */ 
     
    528528         * 
    529529         * @param{TAB}int{TAB}$argument1{TAB}Mon premier argument 
    530          * @param{TAB}string{TAB}$argument2{TAB}Mon deuxième argument 
     530         * @param{TAB}string{TAB}$argument2{TAB}Mon deuxiᅵme argument 
    531531         * @return{TAB}int{TAB}Ma valeur de retour 
    532532         */ 
     
    581581         * 
    582582         * @param{TAB}int{TAB}$argument1{TAB}Mon premier argument 
    583          * @param{TAB}string{TAB}$argument2{TAB}Mon deuxième argument 
     583         * @param{TAB}string{TAB}$argument2{TAB}Mon deuxiᅵme argument 
    584584         * @return{TAB}int{TAB}Ma valeur de retour 
    585585         */ 
     
    616616         * 
    617617         * @param{TAB}int{TAB}$argument1{TAB}Mon premier argument 
    618          * @param{TAB}string{TAB}$argument2{TAB}Mon deuxième argument 
     618         * @param{TAB}string{TAB}$argument2{TAB}Mon deuxiᅵme argument 
    619619         * @return{TAB}int{TAB}Ma valeur de retour 
    620620         */ 
     
    640640         * 
    641641         * @param{TAB}int{TAB}$argument1{TAB}Mon premier argument 
    642          * @param{TAB}string{TAB}$argument2{TAB}Mon deuxième argument 
     642         * @param{TAB}string{TAB}$argument2{TAB}Mon deuxiᅵme argument 
    643643         * @return{TAB}int{TAB}Ma valeur de retour 
    644644         */ 
     
    664664         * 
    665665         * @param{TAB}int{TAB}$argument1{TAB}Mon premier argument 
    666          * @param{TAB}string{TAB}$argument2{TAB}Mon deuxième argument 
     666         * @param{TAB}string{TAB}$argument2{TAB}Mon deuxiᅵme argument 
    667667         * @return{TAB}int{TAB}Ma valeur de retour 
    668668         */ 
     
    688688         * 
    689689         * @param{TAB}int{TAB}$argument1{TAB}Mon premier argument 
    690          * @param{TAB}string{TAB}$argument2{TAB}Mon deuxième argument 
     690         * @param{TAB}string{TAB}$argument2{TAB}Mon deuxiᅵme argument 
    691691         * @return{TAB}int{TAB}Ma valeur de retour 
    692692         */ 
     
    712712         * 
    713713         * @param{TAB}int{TAB}$argument1{TAB}Mon premier argument 
    714          * @param{TAB}string{TAB}$argument2{TAB}Mon deuxième argument 
     714         * @param{TAB}string{TAB}$argument2{TAB}Mon deuxiᅵme argument 
    715715         * @return{TAB}int{TAB}Ma valeur de retour 
    716716         */ 
     
    743743         * 
    744744         * @param{TAB}int{TAB}$argument1{TAB}Mon premier argument 
    745          * @param{TAB}string{TAB}$argument2{TAB}Mon deuxième argument 
     745         * @param{TAB}string{TAB}$argument2{TAB}Mon deuxiᅵme argument 
    746746         * @return{TAB}int{TAB}Ma valeur de retour 
    747747         */ 
     
    767767         * 
    768768         * @param{TAB}int{TAB}$argument1{TAB}Mon premier argument 
    769          * @param{TAB}string{TAB}$argument2{TAB}Mon deuxième argument 
     769         * @param{TAB}string{TAB}$argument2{TAB}Mon deuxiᅵme argument 
    770770         * @return{TAB}int{TAB}Ma valeur de retour 
    771771         */ 
     
    791791                return array(); 
    792792        } 
     793         
     794/* 
     795 * function getActionsACLList 
     796 * This function is designed to return a list of actions allowed for an user 
     797 * 
     798 * <code> 
     799 *              $authorized_actions = array(); 
     800 *              $authorized_actions = getActionsACLList($GroupListofUser); 
     801 * </code> 
     802 * 
     803 * Input is a list of ACL groups of user 
     804 * @param       array ( [0] => Group1 [1] => Groupx )  
     805 *  
     806 * Output is a list of actions allowed for a user like: 
     807 * @return array ( [0] => service_notifications [1] => service_schedule_check [2] => service_schedule_downtime [3] => ... ) 
     808 */ 
     809        function getActionsACLList($GroupListofUser){    
     810                global $pearDB;          
     811                 
     812                $i = 0; 
     813                $idsRequest = "";  
     814                # Formating a variable in order to include on the request 
     815                foreach($GroupListofUser as $id) { 
     816                        $idsRequest .= "`acl_group_id` = ".$id.""; 
     817                        if($i < count($GroupListofUser)-1) { 
     818                                $idsRequest .= " OR "; 
     819                        } 
     820                $i++; 
     821                } 
     822                 
     823                if($idsRequest != "") 
     824                { 
     825                        # Request in order to list the 'acl_action_id' linked with groups of user 
     826                        $request = "SELECT acl_action_id FROM `acl_group_actions_relations` WHERE ".$idsRequest; 
     827                        $DBRESULT =& $pearDB->query($request); 
     828                        if (PEAR::isError($DBRESULT)) print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
     829                         
     830                        $idsActions = array(); 
     831                        while ($rule =& $DBRESULT->fetchRow()){ 
     832                                $idsActions[] =  $rule["acl_action_id"]; 
     833                        } 
     834                 
     835                        $i = 0; 
     836                        $idsRequest = ""; 
     837                        # Formating a variable in order to include on the request 
     838                        foreach($idsActions as $id) { 
     839                                $idsRequest .= "`acl_action_id` = ".$id.""; 
     840                                if($i <= count($GroupListofUser)) { 
     841                                        $idsRequest .= " OR "; 
     842                                } 
     843                        $i++; 
     844                        } 
     845                        unset($idsActions); 
     846                         
     847                        # Request in order to list Actions Access enabled 
     848                        $request = "SELECT acl_action_id FROM `acl_actions` WHERE acl_action_activate = '1' AND ($idsRequest)"; 
     849                        $DBRESULT =& $pearDB->query($request); 
     850                        if (PEAR::isError($DBRESULT)) print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
     851                        $idsActions = array(); 
     852                        while ($rule =& $DBRESULT->fetchRow()){ 
     853                                $idsActions[] =  $rule["acl_action_id"]; 
     854                        } 
     855                         
     856                        $i = 0; 
     857                        $idsRequest = ""; 
     858                        # Formating a variable in order to include on the request 
     859                        foreach($idsActions as $id) { 
     860                                $idsRequest .= "`acl_action_rule_id` = ".$id.""; 
     861                                if($i < count($idsActions)-1) { 
     862                                        $idsRequest .= " OR "; 
     863                                } 
     864                        $i++; 
     865                        } 
     866         
     867                        if(isset($idsRequest) && $idsRequest != "") { 
     868                                # Request in order to list the 'acl_action_name' linked with rules of user               
     869                                $request = "SELECT acl_action_name FROM `acl_actions_rules` WHERE $idsRequest"; 
     870                                $DBRESULT =& $pearDB->query($request); 
     871                                if (PEAR::isError($DBRESULT)) print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
     872                 
     873                                $authorized_actions = array(); 
     874                                while ($actions =& $DBRESULT->fetchRow()){ 
     875                                        $authorized_actions[] = $actions["acl_action_name"]; 
     876                                } 
     877                                return $authorized_actions;      
     878                        } 
     879                } 
     880        return NULL; 
     881        } 
     882         
     883/* 
     884 * function verifyActionsACLofUser 
     885 * This function is designed to verify if user is allowed to perform an action 
     886 * 
     887 * <code> 
     888 *              // Un exemple with the action "host_comment" 
     889 *              $authorized_actions = false; 
     890 *              $authorized_actions = getActionsACLList("host_comment"); 
     891 *              print $authorized_actions; // (print true or false if user is allowed or not) 
     892 * </code> 
     893 * 
     894 * Input is the name of the action, names are in the "DB-Func.php" of the "Actions Access" configuration interface (function listActions()). 
     895 * @param       string "service_checks"  
     896 *  
     897 * Output is true or false 
     898 * @return string true/false 
     899 */ 
     900        function verifyActionsACLofUser($action_name){ 
     901                global $pearDB;  
     902                $GroupListofUser = array(); 
     903                $authorized_actions = array(); 
     904                $authorisation = false; 
     905                 
     906                $GroupListofUser =  getGroupListofUser($pearDB); 
     907                $authorized_actions = getActionsACLList($GroupListofUser); 
     908                if(count($authorized_actions) == 0) $actions = true; 
     909                 
     910                if(isset($authorized_actions)) { 
     911                        foreach($authorized_actions as $list) { 
     912                                if($list == $action_name) $authorisation = true;  
     913                        } 
     914                } 
     915 
     916                return $authorisation; 
     917        } 
    793918?>