/** * 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; }
/** * Create a new UserHost in database * * @param integer $id * @param string $title * @param string $user * @param string $host * @param string $userExcluded * @param string $hostExcluded * @param mixed $info */ protected function createUserHost($id, $title, $user, $host, $userExcluded, $hostExcluded, $info = false) { /** @var UserHost $userHost */ $userHost = new UserHost(); $userHost->setId($id)->setUser($user)->setHost($host)->setUserExcluded($userExcluded)->setHostExcluded($hostExcluded)->setTitle($title); if ($info) { $userHost->setInfo($info); } else { $userHost->setInfo($title); } array_push($this->rights, $userHost); $this->manager->persist($userHost); $this->manager->flush(); }