Skip to content

Instantly share code, notes, and snippets.

@vordan
Last active October 8, 2021 16:51
Show Gist options
  • Save vordan/9c0fa7418a99a1903573d15b03416add to your computer and use it in GitHub Desktop.
Save vordan/9c0fa7418a99a1903573d15b03416add to your computer and use it in GitHub Desktop.
OSTicket API - completely disable IP validation for API key
OSTicket API Key
How to completely disable IP validation
========================================
Open the file /include/class.api.php
The solution is to remove the three references to: $_SERVER['REMOTE_ADDR']
That then completely disables any IP validation however the API key will still be validated.
You will still need to attach an IP to the API key in the admin panel - just use 99.99.99.99
================================
Just replace this code:
function requireApiKey() {
if(!($key=$this->getApiKey()))
return $this->exerr(401, __('Valid API key required'));
elseif (!$key->isActive() || $key->getIPAddr()!=$_SERVER['REMOTE_ADDR'])
return $this->exerr(401, __('API key not found/active or source IP not authorized'));
return $key;
}
function getApiKey() {
if (!$this->apikey && isset($_SERVER['HTTP_X_API_KEY']) && isset($_SERVER['REMOTE_ADDR']))
$this->apikey = API::lookupByKey($_SERVER['HTTP_X_API_KEY'], $_SERVER['REMOTE_ADDR']);
return $this->apikey;
}
================================
Replace with this code:
function requireApiKey() {
if(!($key=$this->getApiKey()))
return $this->exerr(401, __('Valid API key required'));
elseif (!$key->isActive())
return $this->exerr(401, __('API key not found/active or source IP not authorized'));
return $key;
}
function getApiKey() {
if (!$this->apikey && isset($_SERVER['HTTP_X_API_KEY']))
$this->apikey = API::lookupByKey($_SERVER['HTTP_X_API_KEY']);
return $this->apikey;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment