示例#1
0
 /**
  * Authorizes the given user at the api
  *
  * @param $rp2InstanceUrl
  * @param $rp2ApiUser
  * @param $rp2ApiPwd
  * @return bool
  */
 public function auth($rp2InstanceUrl, $rp2ApiUser, $rp2ApiPwd)
 {
     $duration = microtime(1);
     log::debug('Setting RPC-URL', "bbRpc::setUrl({$rp2InstanceUrl})");
     bbRpc::setUrl($rp2InstanceUrl);
     $userId = bbRpc::auth($rp2ApiUser, $rp2ApiPwd);
     $duration = round(microtime(1) - $duration, 3);
     if (!$userId) {
         log::warning("Login failed from " . $_SERVER['REMOTE_ADDR'] . " within {$duration} sec.", "bbRpc::auth({$rp2ApiUser}, *****)", $_SERVER);
         $this->fetchRpcLog();
         return false;
     } else {
         // https://doku.premium-admin.eu/doku.php/api/methoden/bbrpc/setutf8native
         log::info("Login successful from " . $_SERVER['REMOTE_ADDR'] . " within {$duration} sec.", "bbRpc::auth({$rp2ApiUser}, *****)");
         $this->fetchRpcLog();
         log::debug('Set UTF-8', 'bbRpc::setUTF8Native(true)');
         bbRpc::setUTF8Native(true);
         $this->fetchRpcLog();
         return true;
     }
 }
示例#2
0
 /**
  * Wrapper for all api-calls with build-in caching
  *
  * @param $sMethod
  * @param array $hArgs
  * @param null $hPlaceholders
  * @param bool|string $cache
  * @return null
  * @throws \Exception
  */
 private function getRpcResponse($sMethod, $hArgs = array(), $hPlaceholders = null, $cache = true)
 {
     $requestString = '';
     foreach ($this->rpcParams as $name => $value) {
         /*if (!is_string($value) && !is_bool($value))
           {
               throw new module\exception("Sorry, Params can't be ".\gettype($value));
           }*/
         $requestString .= empty($requestString) ? $sMethod . '(' : ',';
         $requestString .= "'{$name}' => '{$value}'";
     }
     $requestString .= ')';
     if ($cache === true && isset($this->rpcCache[$requestString])) {
         module\log::debug('Getting RPC-Response from runtime-cache', __METHOD__ . "({$requestString})");
         return $this->rpcCache[$requestString];
     } else {
         if ($cache === 'memcache') {
             throw new module\exception('Sorry, memcach is not implemented yet');
         } else {
             $duration = microtime(1);
             global $_BBRPC_Msgs;
             $this->rpcCache[$requestString] = bbRpc::call($sMethod, $hArgs, $hPlaceholders);
             $duration = round(microtime(1) - $duration, 3);
             $resultCounter = count($this->rpcCache[$requestString]);
             module\log::debug("Performing RPC-Request within {$duration} sec.", __METHOD__);
             module\log::debug("Getting {$resultCounter} rows ", $requestString);
             $this->fetchRpcLog();
         }
     }
     return $this->rpcCache[$requestString];
 }