2020-03-11 21:17:52 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class AddXOriginatingIpHeaderPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|
|
|
|
{
|
2021-02-10 16:50:20 +08:00
|
|
|
|
const
|
|
|
|
|
NAME = 'X-Originating-IP',
|
|
|
|
|
VERSION = '2.0',
|
|
|
|
|
DESCRIPTION = 'Adds X-Originating-IP header to outgoing message, containing sender\'s IP address.';
|
|
|
|
|
|
2020-08-31 00:04:54 +08:00
|
|
|
|
public function Init() : void
|
2020-03-11 21:17:52 +08:00
|
|
|
|
{
|
|
|
|
|
$this->addHook('filter.build-message', 'FilterBuildMessage');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param \MailSo\Mime\Message $oMessage
|
|
|
|
|
*/
|
|
|
|
|
public function FilterBuildMessage(&$oMessage)
|
|
|
|
|
{
|
|
|
|
|
if ($oMessage instanceof \MailSo\Mime\Message)
|
|
|
|
|
{
|
|
|
|
|
$sIP = $this->Manager()->Actions()->Http()->GetClientIp(
|
|
|
|
|
!!$this->Config()->Get('plugin', 'check_proxy', false));
|
|
|
|
|
|
|
|
|
|
$oMessage->SetCustomHeader(
|
|
|
|
|
\MailSo\Mime\Enumerations\Header::X_ORIGINATING_IP,
|
|
|
|
|
$this->Manager()->Actions()->Http()->IsLocalhost($sIP) ? '127.0.0.1' : $sIP
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-08-31 00:04:54 +08:00
|
|
|
|
protected function configMapping() : array
|
2020-03-11 21:17:52 +08:00
|
|
|
|
{
|
|
|
|
|
return array(
|
|
|
|
|
\RainLoop\Plugins\Property::NewInstance('check_proxy')
|
|
|
|
|
->SetLabel('Сheck User Proxy')
|
|
|
|
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
|
|
|
|
->SetDescription('Enable, if you need to check proxy header')
|
|
|
|
|
->SetDefaultValue(false)
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-08-31 00:04:54 +08:00
|
|
|
|
}
|