From: konrad Date: Sun, 25 Apr 2010 08:45:36 +0000 (+0000) Subject: start of flag system X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=fe73ef3e23057ab0bf478dceae8192ce650219b6;p=web%2Fkonrad%2Fsmoke.git start of flag system git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@436 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/wob/basics.wolf b/wob/basics.wolf index d686019..e7a78e3 100644 --- a/wob/basics.wolf +++ b/wob/basics.wolf @@ -17,8 +17,8 @@ - - + + @@ -41,4 +41,7 @@ + + + diff --git a/wob/user.wolf b/wob/user.wolf index 08de0f3..d44b6d4 100644 --- a/wob/user.wolf +++ b/wob/user.wolf @@ -32,12 +32,12 @@ - + - + diff --git a/www/inc/machine/session.php b/www/inc/machine/session.php index a61cebf..41e51a9 100644 --- a/www/inc/machine/session.php +++ b/www/inc/machine/session.php @@ -23,6 +23,7 @@ class Session protected $user=""; protected $roles; protected $rights; + protected $flags; /**construct the session object, check validity*/ public function __construct($trans) @@ -30,12 +31,14 @@ class Session global $db,$session; $this->roles=array(); $this->rights=array(); + $this->flags=array(); $sid=$trans->getHeader("Wob-SessionId"); $res=$db->select("session","sessionid,user","sessionid=".$db->escapeString($sid)); if(count($res)>0){ $this->sessid=$sid; $this->user=$res[0]["user"]; $this->initRights(); + $this->initFlags($res[0]["flags"]); } $session=$this; } @@ -76,12 +79,34 @@ class Session } } + /**internal: retrieve and remember the flags of this user*/ + protected function initFlags($flg) + { + global $db; + $this->flags=explode(" ",$flg); + $res=$db->select("userrole","role","uname=".$db->escapeString($this->user)); + for($i=0;$iselect("role","flags","rolename=".$db->escapeString($res[$i][0])); + if(count($res2)>0){ + foreach(explode(" ",$res2[0][0]) as $f) + if(!in_array($f,$this->flags)) + $this->flags[]=$f; + } + } + } + /**returns all rights of this user*/ public function getRights(){return $this->rights;} /**returns all roles of this user*/ public function getRoles(){return $this->roles;} + /**returns the flags of this user*/ + public function getFlags(){return $this->flags;} + + /**returns whether the user has a specific flag*/ + public function hasFlag($f){return in_array($f,$this->flags);} + /**creates a new session, called from the Login transaction*/ static public function login($trans) { @@ -206,8 +231,30 @@ class Session { global $db; if(in_array("_admin",$this->roles))return true; + if(in_array("_admin",$this->flags))return true; return in_array($transaction,$this->rights); } + + /**checks the given flags item pattern (string or array of strings) and returns true if they match*/ + public function checkFlags($iflg) + { + //admin shortcut + if($this->hasFlag("_admin"))return true; + if(in_array("_admin",$this-roles))return true; + //actual check + if(is_array($iflg))$fp=$iflg; + else $fp=explode(" ",$iflg); + foreach($fp as $f){ + if($f[0]=="+"){ + if(!$this->hasFlag(substr($f,1)))return false; + }else + if($f[0]=="-"){ + if($this->hasFlag(substr($f,1)))return false; + } + else return false; + } + return true; + } }; /**dummy class used by browsed pages to represent the virtual web user*/ @@ -220,11 +267,19 @@ class DummyWebSession extends Session $this->user="(web)"; //fake web role, web pages check for it $this->roles=array("_web"); + $this->flags=array("_web"); //get rights $this->rights=array(); - $res2=$db->select("roleright","rightname","rolename=".$db->escapeString($res[$i][0])); + $res2=$db->select("roleright","rightname","rolename='_web'"); for($j=0;$jrights[]=$res2[$j][0]; + //get flags + $res2=$db->select("role","flags","rolename='_web'"); + if(count($res2)>0){ + foreach(explode(" ",$res2[0][0]) as $f) + if(!in_array($f,$this->flags)) + $this->flags[]=$f; + } } }