Check that we are permitted to call method on specified peer

@param object $mnet_peer A mnet_peer object with details of the remote host we're connecting to
@return bool True if we permit calls to method on specified peer, False otherwise.
544983
function permission_to_call($mnet_peer) {
        global $DB, $CFG, $USER;

        // Executing any system method is permitted.
        $system_methods = array('system/listMethods', 'system/methodSignature', 'system/methodHelp', 'system/listServices');
        if (in_array($this->method, $system_methods) ) {
            return true;
        }

        $hostids = array($mnet_peer->id);
        if (!empty($CFG->mnet_all_hosts_id)) {
            $hostids[] = $CFG->mnet_all_hosts_id;
        }
        // At this point, we don't care if the remote host implements the
        // method we're trying to call. We just want to know that:
        // 1. The method belongs to some service, as far as OUR host knows
        // 2. We are allowed to subscribe to that service on this mnet_peer

        list($hostidsql, $hostidparams) = $DB->get_in_or_equal($hostids);

        $sql = "SELECT r.id
                  FROM {mnet_remote_rpc} r
            INNER JOIN {mnet_remote_service2rpc} s2r ON s2r.rpcid = r.id
            INNER JOIN {mnet_host2service} h2s ON h2s.serviceid = s2r.serviceid
                 WHERE r.xmlrpcpath = ?
                       AND h2s.subscribe = ?
                       AND h2s.hostid $hostidsql";

        $params = array($this->method, 1);
        $params = array_merge($params, $hostidparams);

        if ($DB->record_exists_sql($sql, $params)) {
            return true;
        }

        $this->error[] = '7:User with ID '. $USER->id .
                         ' attempted to call unauthorised method '.
                         $this->method.' on host '.
                         $mnet_peer->wwwroot;
        return false;
    }
1193906
public function support(ResourceNode $resourceNode, string $actionName, string $method): bool
    {
        $action = $this->get($resourceNode, $actionName);

        if (empty($action) || !in_array($method, $action->getApi())) {
            return false;
        }

        return true;
    }
1229420
public function canAddrequest()
    {
        if (!$this->actor) {
            return false;
        }

        if (!$this->getItem()) {
            return false;
        }

        return $this->getItem()->authorize('requester', array('viewer' => $this->actor));
    }
924547
protected function httpMethodNotAllowed(string $method_name) {
		$class_name = __CLASS__;
		$message = "Method: [{$method_name}] Not Allowed in property " . "[\$httpMethodNames] on class [{$class_name}]";
		
		throw new MethodNotAllowedException($this->httpMethodNames, $message);
	}
266214
public function has($name, $checkAbstractFactories = true, $usePeeringServiceManagers = false)
    {
        if (parent::has($name, $checkAbstractFactories, $usePeeringServiceManagers)) {
            return true;
        }

        if (is_array($name)) {
            return false;
        }

        $class = strtr($name, '.', '\\');
        if ($this->autoAddInvokableClass && class_exists($class)) {
            $this->setInvokableClass($name, $class);
            return true;
        }

        return false;
    }
1269831
def canonical_peer( self, peer ):
        
        their_host, their_port = url_to_host_port( peer )

        if their_host in ['127.0.0.1', '::1']:
            their_host = 'localhost'

        return "%s:%s" % (their_host, their_port)
461151
public function isIpAuthorized(ResourceNode $resourceNode): bool
    {
        $allowed = $resourceNode->getAllowedIps();
        if (!empty($allowed)) {
            $currentParts = explode('.', $_SERVER['REMOTE_ADDR']);

            foreach ($allowed as $allowedIp) {
                $allowedParts = explode('.', $allowedIp);
                $allowBlock = [];

                foreach ($allowedParts as $key => $val) {
                    if (isset($currentParts[$key])) {
                        $allowBlock[] = ($val === $currentParts[$key] || '*' === $val);
                    }
                }

                if (!in_array(false, $allowBlock)) {
                    return true;
                }
            }

            // the current user ip is not in the allowed list
            return false;
        }

        // the current resource does not restrict ips
        return true;
    }
1286593
def _allowAnotherAt(cls, parent):
        """"""
        site = parent.get_site()
        if site is None:
            return False
        return not cls.peers().descendant_of(site.root_page).exists()
1258088
protected function method($method)
    {
        if (strtolower($this->request->getMethod()) != strtolower($method)) {
            throw new MethodNotAllowedException('No matching method for HTTP method "'.$this->request->getMethod().'"');
        }
        return true;
    }
905422
def notify(self):
        
        if self.__method is not None:
            self.__method(self.__peer)
            return True
        return False
1363933
public static function canCallAPI()
    {
        $lastCall = Setting::getSetting('twitter', 'last_api_call');

        if ($lastCall == null) {
            return true;
        } else {
            $lastCall = new \DateTime($lastCall);
        }

        $now = new \DateTime();
        $interval = $lastCall->diff($now);

        // Are we at least one minute ago?
        if ($interval->i >= 1) {
            return true;
        } else {
            return false;
        }
    }
716498
public static function allowOnlyJsonRequest($jsonpAttribute = 'callback')
    {
        if (static::isJsonRequested() === false) {
            throw new BadRequestHttpException();
        }
        Yii::$app->response->format =
            Yii::$app->request->get($jsonpAttribute)
                ? Response::FORMAT_JSONP
                : Response::FORMAT_JSON;
    }
25101
public function canCall( string $api_key, string $region, string $resource, string $endpoint ): bool
	{
		return $this->storage->canCall($api_key, $region, $resource, $endpoint);
	}
142444
private boolean pingSecondaryProtocol(Protocol protocol) {
    try {
      if (protocol != null && protocol.isConnected() && protocol.ping()) {
        return true;
      }
    } catch (Exception e) {
      protocol.close();

      if (setSecondaryHostFail()) {
        addToBlacklist(protocol.getHostAddress());
      }
    }
    return false;
  }
758141
public function send($method_name, $params)
    {
        $this->token++;
        if ($this->token > 655360) {
            $this->token = 0;
        }
        if ($this->client->isConnected()) {
            $this->client->send($this->pack->pack(['m' => $method_name, 'p' => $params, 't' => $this->token]));
            return "[$this->ip][$method_name][$this->token]";
        } else {
            return false;
        }
    }
1170867
def _permission_denied_check(request):
    '''

    '''
    allowed_ips = settings.EUL_INDEXER_ALLOWED_IPS
    if allowed_ips != "ANY" and not request.META['REMOTE_ADDR'] in allowed_ips:
        return True

    return False
832328
def new_connection(self, remote_ip, remote_port):
        
        self.state.set_state('new')
        self._message = Message(Peer(remote_ip, remote_port))

        decision, response_sent = self.is_allowed('accept_new_connection',
                                                  self._message.peer)
        if decision:
            if not response_sent:
                self.handle_input('greet')
            self._set_size_restrictions()
        else:
            if not response_sent:
                self.reply(554, 'SMTP service not available')
            self.close_connection()