diff --git a/code/admin/config.xml b/code/admin/config.xml index fed8ecc..a219f9a 100755 --- a/code/admin/config.xml +++ b/code/admin/config.xml @@ -3,6 +3,13 @@
+ + + + + GET + uid:number searches logs for a particular user" UNASSIGNED_HASH="No user for this API Key" +COM_API_CONFIG_IPS_DESC="Ristrict APIs to specific IP address" +COM_API_CONFIG_IPS_LBL="IP Address/IP Range/CIDR Block" +COM_API_CONFIG_REQ_LT_LBL="Rate Frequency" +COM_API_CONFIG_REQ_LT_DESC="Request limit frequency" + ; Permissions JACTION_MANAGELOGS="Manage Logs" JACTION_MANAGELOGS_DESC="Allows users in this group to manage API logs." diff --git a/code/site/language/en-GB/en-GB.com_api.ini b/code/site/language/en-GB/en-GB.com_api.ini index 29b2c4b..5ba548a 100644 --- a/code/site/language/en-GB/en-GB.com_api.ini +++ b/code/site/language/en-GB/en-GB.com_api.ini @@ -40,6 +40,7 @@ COM_API_NOT_AUTH_MSG="You are not authorized to view this resource." COM_API_RATE_LIMIT_EXCEEDED="API Rate Limit Exceeded" COM_API_UNAUTHORIZED_REGISTER="You are not authorized to create a key." COM_API_PLUGIN_NO_ENCODER="Content type cannot be encoded." +COM_API_IP_RISRICTED="API Acess Is Not Allowed from your IP." COM_API_PUBLISHED="Published" COM_API_UNPUBLISHED="Unpublished" diff --git a/code/site/libraries/plugin.php b/code/site/libraries/plugin.php index 393e68b..11a41b8 100755 --- a/code/site/libraries/plugin.php +++ b/code/site/libraries/plugin.php @@ -280,7 +280,7 @@ final public function getResourceAccess($resource, $method = 'GET', $returnParam final public function fetchResource($resource_name = null) { $this->log(); - + $app = Factory::getApplication(); if ($resource_name == null) { $resource_name = $this->get('resource'); @@ -311,6 +311,16 @@ final public function fetchResource($resource_name = null) ApiError::raiseError(403, Text::_('COM_API_RATE_LIMIT_EXCEEDED'), 'APIUnauthorisedException'); } + $ip_address = $app->input->server->get('REMOTE_ADDR', '', 'STRING'); + $ips = $this->params->get('ip_address', '*'); + + if ($ips === "*"){}else{ + if (!IpHelper::IPinList($ip_address,$ips)) + { + ApiError::raiseError(403, Text::_('COM_API_IP_RISRICTED'), 'APIUnauthorisedException'); + } + } + $this->lastUsed(); if ($resource_obj !== false) @@ -370,24 +380,27 @@ final private function checkRequestLimit() $ip_address = $app->input->server->get('REMOTE_ADDR', '', 'STRING'); $time = $this->params->get('request_limit_time', 'hour'); - + $now = Factory::getDate(); switch ($time) { case 'day': $offset = 60 * 60 * 24; + $now->modify('-1 day'); break; case 'minute': $offset = 60; + $now->modify('-1 minute'); break; case 'hour': default: $offset = 60 * 60; + $now->modify('-1 hour'); break; } - $query_time = time() - $offset; + $query_time = $now->toSql(); $db = Factory::getDBO(); $query = $db->getQuery(true);