Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List of ip addresses that can use an API key #72

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion application/config/rest.php
Expand Up @@ -217,7 +217,8 @@
`method` varchar(6) NOT NULL,
`params` text NOT NULL,
`api_key` varchar(40) NOT NULL,
`ip_address` varchar(15) NOT NULL,
`is_public_key` tinyint(1) NOT NULL DEFAULT NULL ,
`ip_addresses` TEXT NULL DEFAULT NULL ,
`time` int(11) NOT NULL,
`authorized` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
Expand Down
38 changes: 36 additions & 2 deletions application/libraries/REST_Controller.php
Expand Up @@ -434,8 +434,42 @@ protected function _detect_api_key()

$this->rest->key = $row->key;

isset($row->level) AND $this->rest->level = $row->level;
isset($row->ignore_limits) AND $this->rest->ignore_limits = $row->ignore_limits;
if(isset($row->level))
{
$this->rest->level = $row->level;
}

if(isset($row->ignore_limits))
{
$this->rest->ignore_limits = $row->ignore_limits;
}

if(isset($row->is_public_key))
{

// Check for a list of valid ip addresses
if(isset($row->ip_addresses))
{
$list_ip_addresses = explode("\n", $row->ip_addresses);
$found_address = FALSE;

foreach($list_ip_addresses as $ip_address)
{
if($this->input->ip_address() == $ip_address)
{
$found_address = TRUE;
break;
}
}

return $found_address;
}
else
{
// There should be at least one IP address for this public key.
return FALSE;
}
}

return TRUE;
}
Expand Down