示例#1
0
文件: user.php 项目: nibble-arts/oliv
 public static function superUser($user)
 {
     $userRight = OLIVUser::getRight($user);
     if ($userRight) {
         if ($userRight->attributes()->su) {
             return TRUE;
         } else {
             return FALSE;
         }
     }
     return FALSE;
 }
示例#2
0
 private static function checkAccess($access, $strict = FALSE)
 {
     $owner = "";
     $group = "";
     $rights = "000";
     $ownRight = "";
     $groupRight = "";
     $allRight = "";
     //echoall($access);
     //------------------------------------------------------------------------------
     // get requested rights
     $owner = (string) $access->attributes()->owner;
     $group = (string) $access->attributes()->group;
     $rights = (string) $access->attributes()->access;
     $ownRight = intval(substr($rights, 0, 1));
     $groupRight = intval(substr($rights, 1, 1));
     $allRight = intval(substr($rights, 2, 1));
     //------------------------------------------------------------------------------
     // get user rights
     $userRight = OLIVUser::getRight(status::OLIV_USER());
     $userOwner = $userRight->getName();
     $userGroup = OLIVUser::getGroup(status::OLIV_USER());
     //echoall($group);
     //------------------------------------------------------------------------------
     // no rights requested
     // reset rights
     $r = $w = $x = 0;
     // if no rights found, check strict parameter
     if (!$ownRight and !$groupRight and !$allRight) {
         if (!$strict) {
             $r = $w = $x = 1;
         } else {
             $r = $w = $x = 0;
         }
     }
     //print_r($userGroup->asXML());
     //------------------------------------------------------------------------------
     // give all rights if superuser
     if (status::OLIV_SU()) {
         $r = $w = $x = 1;
     }
     //------------------------------------------------------------------------------
     // check owner
     if (status::OLIV_USER()) {
         if ($owner == $userOwner) {
             if ($ownRight & 4) {
                 $r = 1;
             }
             if ($ownRight & 2) {
                 $w = 1;
             }
             if ($ownRight & 1) {
                 $x = 1;
             }
         }
     }
     //------------------------------------------------------------------------------
     // check group
     if ($userGroup) {
         if ($group == (string) $userGroup->{$group}->getName()) {
             if ($groupRight & 4) {
                 $r = 1;
             }
             if ($groupRight & 2) {
                 $w = 1;
             }
             if ($groupRight & 1) {
                 $x = 1;
             }
         }
     }
     //------------------------------------------------------------------------------
     // check all rights
     if ($access) {
         if ($allRight & 4) {
             $r = 1;
         }
         if ($allRight & 2) {
             $w = 1;
         }
         if ($allRight & 1) {
             $x = 1;
         }
     }
     return array("r" => $r, "w" => $w, "x" => $x);
 }