/**
  * Issues a new token for a client asking to connect,
  * OR returns an already generated token based on
  * client IP if that token is not yet validated.
  *
  * In effect: only one token can be requested per IP at
  * the same time, but any number of tokens can be valid
  * for the same IP.
  *
  * This is done in part to prevent hammering, in part
  * to prevent confusion if client accidentally requests
  * two tokens and system administrator is unaware which
  * one was intended.
  *
  * @return Token
  */
 public function issueNewToken()
 {
     $clientIpLong = ip2long($_SERVER['REMOTE_ADDR']);
     $existingUnvalidatedTokenRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('token', 'tx_rpc_token', sprintf('client_ip = %d AND validated = 0', $clientIpLong));
     if ($existingUnvalidatedTokenRecord) {
         return new Token($existingUnvalidatedTokenRecord['token']);
     }
     $token = new Token(sha1(microtime(TRUE) . $_SERVER['REMOTE_ADDR']));
     $this->getDatabaseConnection()->exec_INSERTquery('tx_rpc_token', array('token' => $token->getTokenValue(), 'client_ip' => $clientIpLong));
     return $token;
 }
 /**
  * @param Token $token
  * @param TaskInterface $task
  * @return boolean
  */
 public function tokenHasAccessToTask(Token $token, TaskInterface $task)
 {
     $tokenRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('allowed_tasks', 'tx_rpc_token', sprintf("token = '%s' AND validated = 1", $token->getTokenValue()));
     return is_array($tokenRecord) && in_array($task->getTaskConfiguration()->getId(), GeneralUtility::trimExplode(',', $tokenRecord['allowed_tasks']));
 }
Пример #3
0
 /**
  * @return string
  */
 public function compile()
 {
     return json_encode(array('token' => $this->token->getTokenValue(), 'task' => $this->task, 'arguments' => $this->arguments), JSON_HEX_TAG | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_HEX_APOS);
 }