Whitelist working
This commit is contained in:
parent
5411c00ee9
commit
3f7f9ce7e6
1 changed files with 39 additions and 1 deletions
|
@ -22,7 +22,7 @@ class App
|
|||
* Main application loop
|
||||
*/
|
||||
public function start(){
|
||||
if($this->checkIfRequestMethodIsPost() && $this->checkAuthorization()) {
|
||||
if($this->checkIfRequestMethodIsPost() && $this->checkAuthorization() && $this->checkIfIpOnWhitelistAndWhitelistEnabled()) {
|
||||
$this->handleIncomingData();
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,25 @@ class App
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if whitelist and ip address is in whitelist
|
||||
*/
|
||||
private function checkIfIpOnWhitelistAndWhitelistEnabled(){
|
||||
if($this->config->ip_whitelist)
|
||||
{
|
||||
if(in_array($this->getRealIPAddr(),$this->config->ips_whitelist_list))
|
||||
{
|
||||
return true;
|
||||
}else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check if request method is post
|
||||
* @return bool
|
||||
|
@ -70,4 +89,23 @@ class App
|
|||
$xmpp->sendMessage($wh->getMessage());
|
||||
$xmpp->disconnect();
|
||||
}
|
||||
|
||||
private function getRealIPAddr()
|
||||
{
|
||||
if (!empty($_SERVER['HTTP_CLIENT_IP']))
|
||||
{
|
||||
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
||||
}
|
||||
|
||||
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
|
||||
{
|
||||
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
|
||||
return $ip;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue