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

45 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class AddXOriginatingIpHeaderPlugin extends \RainLoop\Plugins\AbstractPlugin
{
const
NAME = 'X-Originating-IP',
VERSION = '2.0',
DESCRIPTION = 'Adds X-Originating-IP header to outgoing message, containing sender\'s IP address.';
public function Init() : void
{
$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
*/
protected function configMapping() : array
{
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)
);
}
}