snappymail/plugins/add-x-originating-ip-header/index.php

40 lines
1,023 B
PHP
Raw Normal View History

2013-11-20 20:26:00 +08:00
<?php
class AddXOriginatingIpHeaderPlugin extends \RainLoop\Plugins\AbstractPlugin
{
public function Init()
{
$this->addHook('filter.build-message', 'FilterBuildMessage');
}
/**
* @param \MailSo\Mime\Message $oMessage
*/
public function FilterBuildMessage(&$oMessage)
{
if ($oMessage instanceof \MailSo\Mime\Message)
{
2013-12-10 19:09:58 +08:00
$sIP = $this->Manager()->Actions()->Http()->GetClientIp(
!!$this->Config()->Get('plugin', 'check_proxy', false));
2013-11-20 20:26:00 +08:00
$oMessage->SetCustomHeader(
\MailSo\Mime\Enumerations\Header::X_ORIGINATING_IP,
2013-12-10 19:09:58 +08:00
$this->Manager()->Actions()->Http()->IsLocalhost($sIP) ? '127.0.0.1' : $sIP
2013-11-20 20:26:00 +08:00
);
}
}
/**
* @return array
*/
public function configMapping()
{
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)
);
}
}