/** * check if command it to be executed under given "circumstances" (user and host matching) * @return boolean */ public function checkRights() { // no requirements assigned -> execute always if (!$this->rights) { return true; } $result = true; $requiredUser = $this->rights->getUser(); $requiredHost = $this->rights->getHost(); $excludedUser = $this->rights->getUserExcluded(); $excludedHost = $this->rights->getHostExcluded(); $user = getenv('USERNAME') ?: getenv('USER'); $host = gethostname(); // check user requirements if ($requiredUser) { $result = $result && preg_match("{" . $requiredUser . "}", $user); } // check excluded user requirements if ($excludedUser) { $result = $result && !preg_match("{" . $excludedUser . "}", $user); } // check host requirements if ($requiredHost) { $result = $result && preg_match("{" . $requiredHost . "}", $host); } // check excluded host requirements if ($excludedHost) { $result = $result && !preg_match("{" . $excludedHost . "}", $host); } return $result; }