Move plugins to webmail repository.

This commit is contained in:
RainLoop Team 2013-11-20 16:26:00 +04:00
parent 17958b15cb
commit cf0968b5a8
32 changed files with 4348 additions and 0 deletions

View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2013 RainLoop Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1 @@
Adds X-Originating-IP header to outgoing message, containing sender's IP address.

View file

@ -0,0 +1 @@
1.1

View file

@ -0,0 +1,38 @@
<?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)
{
$oMessage->SetCustomHeader(
\MailSo\Mime\Enumerations\Header::X_ORIGINATING_IP,
$this->Manager()->Actions()->Http()->GetClientIp(
!!$this->Config()->Get('plugin', 'check_proxy', false))
);
}
}
/**
* @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)
);
}
}

View file

@ -0,0 +1,51 @@
<?php
class ChangePasswordExampleDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
{
/**
* @var array
*/
private $aDomains = array();
/**
* @param array $aDomains
*
* @return bool
*/
public function SetAllowedDomains($aDomains)
{
if (\is_array($aDomains) && 0 < \count($aDomains))
{
$this->aDomains = $aDomains;
}
return $this;
}
/**
* @param \RainLoop\Account $oAccount
*
* @return bool
*/
public function PasswordChangePossibility($oAccount)
{
return $oAccount && $oAccount->Domain() &&
\in_array(\strtolower($oAccount->Domain()->Name()), $this->aDomains);
}
/**
* @param \RainLoop\Account $oAccount
* @param string $sPrevPassword
* @param string $sNewPassword
*
* @return bool
*/
public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
{
$bResult = false;
// TODO
return $bResult;
}
}

View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2013 RainLoop Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1 @@
1.0

View file

@ -0,0 +1,49 @@
<?php
class ChangePasswordExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
{
public function Init()
{
$this->addHook('main.fabrica', 'MainFabrica');
}
/**
* @param string $sName
* @param mixed $oProvider
*/
public function MainFabrica($sName, &$oProvider)
{
switch ($sName)
{
case 'change-password':
include_once __DIR__.'/ChangePasswordExampleDriver.php';
$oProvider = new ChangePasswordExampleDriver();
$sDomains = \strtolower(\trim(\preg_replace('/[\s;,]+/', ' ',
$this->Config()->Get('plugin', 'domains', ''))));
if (0 < \strlen($sDomains))
{
$aDomains = \explode(' ', $sDomains);
$oProvider->SetAllowedDomains($aDomains);
}
break;
}
}
/**
* @return array
*/
public function configMapping()
{
return array(
\RainLoop\Plugins\Property::NewInstance('domains')->SetLabel('Allowed Domains')
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
->SetDescription('Allowed domains, space as delimiter')
->SetDefaultValue('domain1.com domain2.com')
);
}
}

View file

@ -0,0 +1,700 @@
<?php
namespace TijsVerkoyen\CssToInlineStyles;
/**
* CSS to Inline Styles class
*
* @author Tijs Verkoyen <php-css-to-inline-styles@verkoyen.eu>
* @version 1.1.0
* @copyright Copyright (c), Tijs Verkoyen. All rights reserved.
* @license BSD License
*/
class CssToInlineStyles
{
/**
* The CSS to use
*
* @var string
*/
private $css;
/**
* The processed CSS rules
*
* @var array
*/
private $cssRules;
/**
* Should the generated HTML be cleaned
*
* @var bool
*/
private $cleanup = false;
/**
* The encoding to use.
*
* @var string
*/
private $encoding = 'UTF-8';
/**
* The HTML to process
*
* @var string
*/
private $html;
/**
* Use inline-styles block as CSS
*
* @var bool
*/
private $useInlineStylesBlock = false;
/*
* Strip original style tags
*
* @var bool
*/
private $stripOriginalStyleTags = false;
/**
* Creates an instance, you could set the HTML and CSS here, or load it
* later.
*
* @return void
* @param string[optional] $html The HTML to process.
* @param string[optional] $css The CSS to use.
*/
public function __construct($html = null, $css = null)
{
if($html !== null) $this->setHTML($html);
if($css !== null) $this->setCSS($css);
}
/**
* Convert a CSS-selector into an xPath-query
*
* @return string
* @param string $selector The CSS-selector.
*/
private function buildXPathQuery($selector)
{
// redefine
$selector = (string) $selector;
// the CSS selector
$cssSelector = array(
// E F, Matches any F element that is a descendant of an E element
'/(\w)\s+(\w)/',
// E > F, Matches any F element that is a child of an element E
'/(\w)\s*>\s*(\w)/',
// E:first-child, Matches element E when E is the first child of its parent
'/(\w):first-child/',
// E + F, Matches any F element immediately preceded by an element
'/(\w)\s*\+\s*(\w)/',
// E[foo], Matches any E element with the "foo" attribute set (whatever the value)
'/(\w)\[([\w\-]+)]/',
// E[foo="warning"], Matches any E element whose "foo" attribute value is exactly equal to "warning"
'/(\w)\[([\w\-]+)\=\"(.*)\"]/',
// div.warning, HTML only. The same as DIV[class~="warning"]
'/(\w+|\*)+\.([\w\-]+)+/',
// .warning, HTML only. The same as *[class~="warning"]
'/\.([\w\-]+)/',
// E#myid, Matches any E element with id-attribute equal to "myid"
'/(\w+)+\#([\w\-]+)/',
// #myid, Matches any element with id-attribute equal to "myid"
'/\#([\w\-]+)/'
);
// the xPath-equivalent
$xPathQuery = array(
// E F, Matches any F element that is a descendant of an E element
'\1//\2',
// E > F, Matches any F element that is a child of an element E
'\1/\2',
// E:first-child, Matches element E when E is the first child of its parent
'*[1]/self::\1',
// E + F, Matches any F element immediately preceded by an element
'\1/following-sibling::*[1]/self::\2',
// E[foo], Matches any E element with the "foo" attribute set (whatever the value)
'\1 [ @\2 ]',
// E[foo="warning"], Matches any E element whose "foo" attribute value is exactly equal to "warning"
'\1[ contains( concat( " ", @\2, " " ), concat( " ", "\3", " " ) ) ]',
// div.warning, HTML only. The same as DIV[class~="warning"]
'\1[ contains( concat( " ", @class, " " ), concat( " ", "\2", " " ) ) ]',
// .warning, HTML only. The same as *[class~="warning"]
'*[ contains( concat( " ", @class, " " ), concat( " ", "\1", " " ) ) ]',
// E#myid, Matches any E element with id-attribute equal to "myid"
'\1[ @id = "\2" ]',
// #myid, Matches any element with id-attribute equal to "myid"
'*[ @id = "\1" ]'
);
// return
$xPath = (string) '//' . preg_replace($cssSelector, $xPathQuery, $selector);
return str_replace('] *', ']//*', $xPath);
}
/**
* Calculate the specifity for the CSS-selector
*
* @return int
* @param string $selector The selector to calculate the specifity for.
*/
private function calculateCSSSpecifity($selector)
{
// cleanup selector
$selector = str_replace(array('>', '+'), array(' > ', ' + '), $selector);
// init var
$specifity = 0;
// split the selector into chunks based on spaces
$chunks = explode(' ', $selector);
// loop chunks
foreach ($chunks as $chunk) {
// an ID is important, so give it a high specifity
if(strstr($chunk, '#') !== false) $specifity += 100;
// classes are more important than a tag, but less important then an ID
elseif(strstr($chunk, '.')) $specifity += 10;
// anything else isn't that important
else $specifity += 1;
}
// return
return $specifity;
}
/**
* Cleanup the generated HTML
*
* @return string
* @param string $html The HTML to cleanup.
*/
private function cleanupHTML($html)
{
// remove classes
$html = preg_replace('/(\s)+class="(.*)"(\s)+/U', ' ', $html);
// remove IDs
$html = preg_replace('/(\s)+id="(.*)"(\s)+/U', ' ', $html);
// return
return $html;
}
/**
* Converts the loaded HTML into an HTML-string with inline styles based on the loaded CSS
*
* @return string
* @param bool[optional] $outputXHTML Should we output valid XHTML?
*/
public function convert($outputXHTML = false)
{
// redefine
$outputXHTML = (bool) $outputXHTML;
// validate
if($this->html == null) throw new Exception('No HTML provided.');
// should we use inline style-block
if ($this->useInlineStylesBlock) {
// init var
$matches = array();
// match the style blocks
preg_match_all('|<style(.*)>(.*)</style>|isU', $this->html, $matches);
// any style-blocks found?
if (!empty($matches[2])) {
// add
foreach($matches[2] as $match) $this->css .= trim($match) ."\n";
}
}
// process css
$this->processCSS();
// create new DOMDocument
$document = new \DOMDocument('1.0', $this->getEncoding());
// set error level
libxml_use_internal_errors(true);
// load HTML
// $document->loadHTML($this->html);
$document->loadHTML('<'.'?xml version="1.0" encoding="'.$this->getEncoding().'"?'.'><head><meta http-equiv="Content-Type" content="text/html; charset='.$this->getEncoding().'"></head>'.$this->html);
// create new XPath
$xPath = new \DOMXPath($document);
// any rules?
if (!empty($this->cssRules)) {
// loop rules
foreach ($this->cssRules as $rule) {
// init var
$query = $this->buildXPathQuery($rule['selector']);
// validate query
if($query === false) continue;
// search elements
$elements = $xPath->query($query);
// validate elements
if($elements === false) continue;
// loop found elements
foreach ($elements as $element) {
// no styles stored?
if ($element->attributes->getNamedItem(
'data-css-to-inline-styles-original-styles'
) == null) {
// init var
$originalStyle = '';
if ($element->attributes->getNamedItem('style') !== null) {
$originalStyle = $element->attributes->getNamedItem('style')->value;
}
// store original styles
$element->setAttribute(
'data-css-to-inline-styles-original-styles',
$originalStyle
);
// clear the styles
$element->setAttribute('style', '');
}
// init var
$properties = array();
// get current styles
$stylesAttribute = $element->attributes->getNamedItem('style');
// any styles defined before?
if ($stylesAttribute !== null) {
// get value for the styles attribute
$definedStyles = (string) $stylesAttribute->value;
// split into properties
$definedProperties = (array) explode(';', $definedStyles);
// loop properties
foreach ($definedProperties as $property) {
// validate property
if($property == '') continue;
// split into chunks
$chunks = (array) explode(':', trim($property), 2);
// validate
if(!isset($chunks[1])) continue;
// loop chunks
$properties[$chunks[0]] = trim($chunks[1]);
}
}
// add new properties into the list
foreach ($rule['properties'] as $key => $value) {
$properties[$key] = $value;
}
// build string
$propertyChunks = array();
// build chunks
foreach ($properties as $key => $values) {
foreach ((array) $values as $value) {
$propertyChunks[] = $key . ': ' . $value . ';';
}
}
// build properties string
$propertiesString = implode(' ', $propertyChunks);
// set attribute
if ($propertiesString != '') {
$element->setAttribute('style', $propertiesString);
}
}
}
// reapply original styles
$query = $this->buildXPathQuery(
'*[@data-css-to-inline-styles-original-styles]'
);
// validate query
if($query === false) return;
// search elements
$elements = $xPath->query($query);
// loop found elements
foreach ($elements as $element) {
// get the original styles
$originalStyle = $element->attributes->getNamedItem(
'data-css-to-inline-styles-original-styles'
)->value;
if ($originalStyle != '') {
$originalProperties = array();
$originalStyles = (array) explode(';', $originalStyle);
foreach ($originalStyles as $property) {
// validate property
if($property == '') continue;
// split into chunks
$chunks = (array) explode(':', trim($property), 2);
// validate
if(!isset($chunks[1])) continue;
// loop chunks
$originalProperties[$chunks[0]] = trim($chunks[1]);
}
// get current styles
$stylesAttribute = $element->attributes->getNamedItem('style');
$properties = array();
// any styles defined before?
if ($stylesAttribute !== null) {
// get value for the styles attribute
$definedStyles = (string) $stylesAttribute->value;
// split into properties
$definedProperties = (array) explode(';', $definedStyles);
// loop properties
foreach ($definedProperties as $property) {
// validate property
if($property == '') continue;
// split into chunks
$chunks = (array) explode(':', trim($property), 2);
// validate
if(!isset($chunks[1])) continue;
// loop chunks
$properties[$chunks[0]] = trim($chunks[1]);
}
}
// add new properties into the list
foreach ($originalProperties as $key => $value) {
$properties[$key] = $value;
}
// build string
$propertyChunks = array();
// build chunks
foreach ($properties as $key => $values) {
foreach ((array) $values as $value) {
$propertyChunks[] = $key . ': ' . $value . ';';
}
}
// build properties string
$propertiesString = implode(' ', $propertyChunks);
// set attribute
if($propertiesString != '') $element->setAttribute(
'style', $propertiesString
);
}
// remove placeholder
$element->removeAttribute(
'data-css-to-inline-styles-original-styles'
);
}
}
// should we output XHTML?
if ($outputXHTML) {
// set formating
$document->formatOutput = true;
// get the HTML as XML
$html = $document->saveXML(null, LIBXML_NOEMPTYTAG);
// get start of the XML-declaration
$startPosition = strpos($html, '<?xml');
// valid start position?
if ($startPosition !== false) {
// get end of the xml-declaration
$endPosition = strpos($html, '?>', $startPosition);
// remove the XML-header
$html = ltrim(substr($html, $endPosition + 1));
}
}
// just regular HTML 4.01 as it should be used in newsletters
else {
// get the HTML
$html = $document->saveHTML();
}
// cleanup the HTML if we need to
if($this->cleanup) $html = $this->cleanupHTML($html);
// strip original style tags if we need to
if ($this->stripOriginalStyleTags) {
$html = $this->stripOriginalStyleTags($html);
}
// return
return $html;
}
/**
* Get the encoding to use
*
* @return string
*/
private function getEncoding()
{
return $this->encoding;
}
/**
* Process the loaded CSS
*
* @return void
*/
private function processCSS()
{
// init vars
$css = (string) $this->css;
// remove newlines
$css = str_replace(array("\r", "\n"), '', $css);
// replace double quotes by single quotes
$css = str_replace('"', '\'', $css);
// remove comments
$css = preg_replace('|/\*.*?\*/|', '', $css);
// remove spaces
$css = preg_replace('/\s\s+/', ' ', $css);
// rules are splitted by }
$rules = (array) explode('}', $css);
// init var
$i = 1;
// loop rules
foreach ($rules as $rule) {
// split into chunks
$chunks = explode('{', $rule);
// invalid rule?
if(!isset($chunks[1])) continue;
// set the selectors
$selectors = trim($chunks[0]);
// get cssProperties
$cssProperties = trim($chunks[1]);
// split multiple selectors
$selectors = (array) explode(',', $selectors);
// loop selectors
foreach ($selectors as $selector) {
// cleanup
$selector = trim($selector);
// build an array for each selector
$ruleSet = array();
// store selector
$ruleSet['selector'] = $selector;
// process the properties
$ruleSet['properties'] = $this->processCSSProperties(
$cssProperties
);
// calculate specifity
$ruleSet['specifity'] = $this->calculateCSSSpecifity(
$selector
) + $i;
// add into global rules
$this->cssRules[] = $ruleSet;
}
// increment
$i++;
}
// sort based on specifity
if (!empty($this->cssRules)) {
usort($this->cssRules, array(__CLASS__, 'sortOnSpecifity'));
}
}
/**
* Process the CSS-properties
*
* @return array
* @param string $propertyString The CSS-properties.
*/
private function processCSSProperties($propertyString)
{
// split into chunks
$properties = (array) explode(';', $propertyString);
// init var
$pairs = array();
// loop properties
foreach ($properties as $property) {
// split into chunks
$chunks = (array) explode(':', $property, 2);
// validate
if(!isset($chunks[1])) continue;
// cleanup
$chunks[0] = trim($chunks[0]);
$chunks[1] = trim($chunks[1]);
// add to pairs array
if(!isset($pairs[$chunks[0]]) ||
!in_array($chunks[1], $pairs[$chunks[0]])) {
$pairs[$chunks[0]][] = $chunks[1];
}
}
// sort the pairs
ksort($pairs);
// return
return $pairs;
}
/**
* Should the IDs and classes be removed?
*
* @return void
* @param bool[optional] $on Should we enable cleanup?
*/
public function setCleanup($on = true)
{
$this->cleanup = (bool) $on;
}
/**
* Set CSS to use
*
* @return void
* @param string $css The CSS to use.
*/
public function setCSS($css)
{
$this->css = (string) $css;
}
/**
* Set the encoding to use with the DOMDocument
*
* @return void
* @param string $encoding The encoding to use.
*/
public function setEncoding($encoding)
{
$this->encoding = (string) $encoding;
}
/**
* Set HTML to process
*
* @return void
* @param string $html The HTML to process.
*/
public function setHTML($html)
{
$this->html = (string) $html;
}
/**
* Set use of inline styles block
* If this is enabled the class will use the style-block in the HTML.
*
* @return void
* @param bool[optional] $on Should we process inline styles?
*/
public function setUseInlineStylesBlock($on = true)
{
$this->useInlineStylesBlock = (bool) $on;
}
/**
* Set strip original style tags
* If this is enabled the class will remove all style tags in the HTML.
*
* @return void
* @param bool[optional] $onShould we process inline styles?
*/
public function setStripOriginalStyleTags($on = true)
{
$this->stripOriginalStyleTags = (bool) $on;
}
/**
* Strip style tags into the generated HTML
*
* @return string
* @param string $html The HTML to strip style tags.
*/
private function stripOriginalStyleTags($html)
{
return preg_replace('|<style(.*)>(.*)</style>|isU', '', $html);
}
/**
* Sort an array on the specifity element
*
* @return int
* @param array $e1 The first element.
* @param array $e2 The second element.
*/
private static function sortOnSpecifity($e1, $e2)
{
// validate
if(!isset($e1['specifity']) || !isset($e2['specifity'])) return 0;
// lower
if($e1['specifity'] < $e2['specifity']) return -1;
// higher
if($e1['specifity'] > $e2['specifity']) return 1;
// fallback
return 0;
}
}

View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2013 RainLoop Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1 @@
Plugin used for processing complex embedded styles in mail messages. In some cases, it can improve rendering HTML mails.

View file

@ -0,0 +1 @@
1.3

View file

@ -0,0 +1,29 @@
<?php
class ConvertHeadersStylesPlugin extends \RainLoop\Plugins\AbstractPlugin
{
public function Init()
{
$this->addHook('filter.result-message', 'FilterResultMessage');
}
/**
* @param \MailSo\Mail\Message &$oMessage
*/
public function FilterResultMessage(&$oMessage)
{
if ($oMessage)
{
$sHtml = $oMessage->Html();
if ($sHtml && 0 < strlen($sHtml))
{
include_once __DIR__.'/CssToInlineStyles.php';
$oCSSToInlineStyles = new \TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($sHtml);
$oCSSToInlineStyles->setEncoding('utf-8');
$oCSSToInlineStyles->setUseInlineStylesBlock(true);
$oMessage->SetHtml($oCSSToInlineStyles->convert().'<!-- convert-headers-styles-plugin -->');
}
}
}
}

View file

@ -0,0 +1,159 @@
<?php
class CpanelChangePasswordDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
{
/**
* @var string
*/
private $sHost = '';
/**
* @var int
*/
private $iPost = 2087;
/**
* @var string
*/
private $sUser = '';
/**
* @var string
*/
private $sPassword = '';
/**
* @var array
*/
private $aDomains = array();
/**
* @var \MailSo\Log\Logger
*/
private $oLogger = null;
/**
* @param string $sHost
* @param int $iPost
* @param bool $sSsl
* @param string $sUser
* @param string $sPassword
*
* @return \CpanleChangePasswordDriver
*/
public function SetConfig($sHost, $iPost, $sSsl, $sUser, $sPassword)
{
$this->sHost = $sHost;
$this->iPost = $iPost;
$this->sSsl = $sSsl;
$this->sUser = $sUser;
$this->sPassword = $sPassword;
return $this;
}
/**
* @param array $aDomains
*
* @return \CpanleChangePasswordDriver
*/
public function SetAllowedDomains($aDomains)
{
if (\is_array($aDomains) && 0 < \count($aDomains))
{
$this->aDomains = $aDomains;
}
return $this;
}
/**
* @param \MailSo\Log\Logger $oLogger
*
* @return \CpanleChangePasswordDriver
*/
public function SetLogger($oLogger)
{
if ($oLogger instanceof \MailSo\Log\Logger)
{
$this->oLogger = $oLogger;
}
return $this;
}
/**
* @param \RainLoop\Account $oAccount
*
* @return bool
*/
public function PasswordChangePossibility($oAccount)
{
return $oAccount && $oAccount->Domain() &&
\in_array(\strtolower($oAccount->Domain()->Name()), $this->aDomains);
}
/**
* @param \RainLoop\Account $oAccount
* @param string $sPrevPassword
* @param string $sNewPassword
*
* @return bool
*/
public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
{
if ($this->oLogger)
{
$this->oLogger->Write('Try to change password for '.$oAccount->Email());
}
include_once __DIR__.'/xmlapi.php';
$bResult = false;
if (!empty($this->sHost) && 0 < $this->iPost &&
0 < \strlen($this->sUser) && 0 < \strlen($this->sPassword) &&
$oAccount && \class_exists('xmlapi'))
{
try
{
$oXmlApi = new \xmlapi($this->sHost);
$oXmlApi->set_port($this->iPost);
$oXmlApi->set_protocol($this->sSsl ? 'https' : 'http');
$oXmlApi->set_debug(false);
$oXmlApi->set_output('json');
$oXmlApi->set_http_client('curl');
$oXmlApi->password_auth($this->sUser, $this->sPassword);
$sEmail = $oAccount->Email();
$aArgs = array(
'email' => \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail),
'domain' => \MailSo\Base\Utils::GetDomainFromEmail($sEmail),
'password' => $sNewPassword
);
$sResult = $oXmlApi->api2_query($this->sUser, 'Email', 'passwdpop', $aArgs);
if ($sResult)
{
$aResult = @\json_decode($sResult, true);
$bResult = isset($aResult['cpanelresult']['data'][0]['result']) &&
!!$aResult['cpanelresult']['data'][0]['result'];
}
if (!$bResult && $this->oLogger)
{
$this->oLogger->Write('CPANEL: '.$sResult, \MailSo\Log\Enumerations\Type::ERROR);
}
}
catch (\Exception $oException)
{
if ($this->oLogger)
{
$this->oLogger->WriteException($oException);
}
}
}
return $bResult;
}
}

View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2013 RainLoop Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1 @@
1.1

View file

@ -0,0 +1,73 @@
<?php
class CpanelChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
{
public function Init()
{
$this->addHook('main.fabrica', 'MainFabrica');
}
/**
* @param string $sName
* @param mixed $oProvider
*/
public function MainFabrica($sName, &$oProvider)
{
switch ($sName)
{
case 'change-password':
$sHost = \trim($this->Config()->Get('plugin', 'host', ''));
$iPost = (int) $this->Config()->Get('plugin', 'port', 2087);
$sUser = (string) $this->Config()->Get('plugin', 'user', '');
$sPassword = (string) $this->Config()->Get('plugin', 'password', '');
$sSsl = (bool) $this->Config()->Get('plugin', 'ssl', false);
if (!empty($sHost) && 0 < $iPost && 0 < \strlen($sUser) && 0 < \strlen($sPassword))
{
include_once __DIR__.'/CpanelChangePasswordDriver.php';
$oProvider = new CpanelChangePasswordDriver();
$oProvider->SetLogger($this->Manager()->Actions()->Logger());
$oProvider->SetConfig($sHost, $iPost, $sSsl, $sUser, $sPassword);
$sDomains = \strtolower(\trim(\preg_replace('/[\s;,]+/', ' ',
$this->Config()->Get('plugin', 'domains', ''))));
if (0 < \strlen($sDomains))
{
$aDomains = \explode(' ', $sDomains);
$oProvider->SetAllowedDomains($aDomains);
}
}
break;
}
}
/**
* @return array
*/
public function configMapping()
{
return array(
\RainLoop\Plugins\Property::NewInstance('host')->SetLabel('cPanel Host')
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('port')->SetLabel('cPanel Port')
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
->SetDefaultValue(2087),
\RainLoop\Plugins\Property::NewInstance('ssl')->SetLabel('Use SSL')
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
->SetDefaultValue(false),
\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('cPanel User')
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('cPanel Password')
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('domains')->SetLabel('Allowed Domains')
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
->SetDescription('Allowed domains, space as delimiter')
->SetDefaultValue('domain1.com domain2.com')
);
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2013 RainLoop Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1 @@
Embed Google Analytics (Universal Analytics) code into your webmail installation pages.

View file

@ -0,0 +1 @@
1.4

View file

@ -0,0 +1,43 @@
<?php
class GoogleAnalyticsPlugin extends \RainLoop\Plugins\AbstractPlugin
{
/**
* @return void
*/
public function Init()
{
if ('' !== $this->Config()->Get('plugin', 'account', ''))
{
$this->addJs('js/include.js');
}
}
/**
* @return array
*/
public function configMapping()
{
return array(
\RainLoop\Plugins\Property::NewInstance('account')->SetLabel('Account')
->SetAllowedInJs(true)
->SetDescription('UA-XXXXXXXX-X')
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('domain_name')->SetLabel('Domain Name')
->SetAllowedInJs(true)
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('universal_analytics')->SetLabel('Use Universal Analytics')
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
->SetAllowedInJs(true)
->SetDefaultValue(true),
\RainLoop\Plugins\Property::NewInstance('track_pageview')->SetLabel('Track Pageview')
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
->SetAllowedInJs(true)
->SetDefaultValue(true),
\RainLoop\Plugins\Property::NewInstance('send_events')->SetLabel('Send Events')
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
->SetAllowedInJs(true)
->SetDefaultValue(false)
);
}
}

View file

@ -0,0 +1,95 @@
$(function () {
var
sAccount = window.rl.pluginSettingsGet('google-analytics', 'account'),
sDomain = window.rl.pluginSettingsGet('google-analytics', 'domain_name'),
bUniversalAnalytics = !!window.rl.pluginSettingsGet('google-analytics', 'universal_analytics'),
bTrackPageview = !!window.rl.pluginSettingsGet('google-analytics', 'track_pageview'),
bSendEvent = !!window.rl.pluginSettingsGet('google-analytics', 'send_events'),
fSendEvent = null
;
if (sAccount && '' !== sAccount)
{
if (bUniversalAnalytics)
{
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
if (window.ga)
{
if (sDomain)
{
window.ga('create', sAccount, sDomain);
}
else
{
window.ga('create', sAccount);
}
if (bTrackPageview)
{
window.ga('send', 'pageview');
window.setInterval(function () {
window.ga('send', 'pageview');
}, 1000 * 60 * 2);
}
if (bSendEvent)
{
fSendEvent = function(sCategory, sAction, sLabel) {
window.ga('send', 'event', sCategory, sAction, sLabel);
};
}
}
}
else
{
window._gaq = window._gaq || [];
window._gaq.push(['_setAccount', sAccount]);
if (sDomain)
{
window._gaq.push(['_setDomainName', sDomain]);
}
if (bTrackPageview)
{
window._gaq.push(['_trackPageview']);
window.setInterval(function () {
window._gaq.push(['_trackPageview']);
}, 1000 * 60 * 2);
}
if (bSendEvent)
{
fSendEvent = function(sCategory, sAction, sLabel) {
window._gaq.push(['_trackEvent', sCategory, sAction, sLabel]);
};
}
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
}
if (fSendEvent)
{
window.rl.addHook('ajax-default-response', function (sAction, oData, sType) {
switch (sAction)
{
case 'Login':
case 'SendMessage':
case 'MessageMove':
case 'MessageDelete':
fSendEvent('RainLoop', sAction,
'success' === sType && oData && oData['Result'] ? 'true' : 'false');
break;
}
});
}
}
});

20
plugins/recaptcha/LICENSE Normal file
View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2013 RainLoop Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

3
plugins/recaptcha/README Normal file
View file

@ -0,0 +1,3 @@
A CAPTCHA is a program that can generate and grade tests that humans can pass but current computer programs cannot.
For example, humans can read distorted text as the one shown below, but current computer programs can't.
More info at http://www.google.com/recaptcha

View file

@ -0,0 +1 @@
1.8

140
plugins/recaptcha/index.php Normal file
View file

@ -0,0 +1,140 @@
<?php
class RecaptchaPlugin extends \RainLoop\Plugins\AbstractPlugin
{
/**
* @return void
*/
public function Init()
{
$this->UseLangs(true);
$this->addJs('js/recaptcha.js');
$this->addHook('ajax.action-pre-call', 'AjaxActionPreCall');
$this->addHook('filter.ajax-response', 'FilterAjaxResponse');
$this->addTemplate('templates/PluginLoginReCaptchaGroup.html');
$this->addTemplateHook('Login', 'BottomControlGroup', 'PluginLoginReCaptchaGroup');
}
/**
* @return array
*/
public function configMapping()
{
return array(
\RainLoop\Plugins\Property::NewInstance('public_key')->SetLabel('Public Key')
->SetAllowedInJs(true)
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('private_key')->SetLabel('Private Key')
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('error_limit')->SetLabel('Limit')
->SetDefaultValue(0)
->SetType(\RainLoop\Enumerations\PluginPropertyType::SELECTION)
->SetDefaultValue(array(0, 1, 2, 3, 4, 5))
->SetDescription('')
);
}
/**
* @return string
*/
private function getCaptchaCacherKey()
{
return 'Captcha/Login/'.\RainLoop\Utils::GetConnectionToken();
}
/**
* @return int
*/
private function getLimit()
{
$iConfigLimit = $this->Config()->Get('plugin', 'error_limit', 0);
if (0 < $iConfigLimit)
{
$oCacher = $this->Manager()->Actions()->Cacher();
$sLimit = $oCacher && $oCacher->IsInited() ? $oCacher->Get($this->getCaptchaCacherKey()) : '0';
if (0 < strlen($sLimit) && is_numeric($sLimit))
{
$iConfigLimit -= (int) $sLimit;
}
}
return $iConfigLimit;
}
/**
* @return void
*/
public function FilterAppDataPluginSection($bAdmin, $bAuth, &$aData)
{
if (!$bAdmin && !$bAuth && is_array($aData))
{
$aData['show_captcha_on_login'] = 1 > $this->getLimit();
}
}
/**
* @param string $sAction
*/
public function AjaxActionPreCall($sAction)
{
if ('Login' === $sAction && 0 >= $this->getLimit())
{
require_once __DIR__.'/recaptchalib.php';
$oResp = recaptcha_check_answer(
$this->Config()->Get('plugin', 'private_key', ''),
isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '',
$this->Manager()->Actions()->GetActionParam('RecaptchaChallenge', ''),
$this->Manager()->Actions()->GetActionParam('RecaptchaResponse', '')
);
if (!$oResp || !isset($oResp->is_valid) || !$oResp->is_valid)
{
$this->Manager()->Actions()->Logger()->WriteDump($oResp);
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CaptchaError);
}
}
}
/**
* @param string $sAction
* @param array $aResponseItem
*/
public function FilterAjaxResponse($sAction, &$aResponseItem)
{
if ('Login' === $sAction && $aResponseItem && isset($aResponseItem['Result']))
{
$oCacher = $this->Manager()->Actions()->Cacher();
$iConfigLimit = (int) $this->Config()->Get('plugin', 'error_limit', 0);
$sKey = $this->getCaptchaCacherKey();
if (0 < $iConfigLimit && $oCacher && $oCacher->IsInited())
{
if (false === $aResponseItem['Result'])
{
$iLimit = 0;
$sLimut = $oCacher->Get($sKey);
if (0 < strlen($sLimut) && is_numeric($sLimut))
{
$iLimit = (int) $sLimut;
}
$oCacher->Set($sKey, ++$iLimit);
if ($iConfigLimit <= $iLimit)
{
$aResponseItem['Captcha'] = true;
}
}
else
{
$oCacher->Delete($sKey);
}
}
}
}
}

View file

@ -0,0 +1,71 @@
$(function () {
var
bShown = false
;
function ShowRecaptcha()
{
if (window.Recaptcha)
{
if (bShown)
{
window.Recaptcha.reload();
}
else
{
window.Recaptcha.create(window.rl.pluginSettingsGet('recaptcha', 'public_key'), 'recaptcha-place', {
'theme': 'custom',
'lang': window.rl.settingsGet('Language')
});
}
bShown = true;
}
}
function StartRecaptcha()
{
if (!window.Recaptcha)
{
$.getScript('//www.google.com/recaptcha/api/js/recaptcha_ajax.js', ShowRecaptcha);
}
else
{
ShowRecaptcha();
}
}
window.rl.addHook('view-model-on-show', function (sName, oViewModel) {
if ('LoginViewModel' === sName && oViewModel && window.rl.pluginSettingsGet('recaptcha', 'show_captcha_on_login'))
{
StartRecaptcha();
}
});
window.rl.addHook('ajax-default-request', function (sAction, oParameters) {
if ('Login' === sAction && oParameters && bShown && window.Recaptcha)
{
oParameters['RecaptchaChallenge'] = window.Recaptcha.get_challenge();
oParameters['RecaptchaResponse'] = window.Recaptcha.get_response();
}
});
window.rl.addHook('ajax-default-response', function (sAction, oData, sType) {
if ('Login' === sAction)
{
if (!oData || 'success' !== sType || !oData['Result'])
{
if (bShown && window.Recaptcha)
{
window.Recaptcha.reload();
}
else if (oData && oData['Captcha'])
{
StartRecaptcha();
}
}
}
});
});

View file

@ -0,0 +1,2 @@
[PLUGIN]
LABEL_ENTER_THE_WORDS_ABOVE = "Enter the words above"

View file

@ -0,0 +1,2 @@
[PLUGIN]
LABEL_ENTER_THE_WORDS_ABOVE = "Введите слова с изображения"

View file

@ -0,0 +1,280 @@
<?php
/*
* This is a PHP library that handles calling reCAPTCHA.
* - Documentation and latest version
* http://recaptcha.net/plugins/php/
* - Get a reCAPTCHA API Key
* https://www.google.com/recaptcha/admin/create
* - Discussion group
* http://groups.google.com/group/recaptcha
*
* Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
* AUTHORS:
* Mike Crawford
* Ben Maurer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* The reCAPTCHA server URL's
*/
define("RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api");
define("RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api");
define("RECAPTCHA_VERIFY_SERVER", "www.google.com");
/**
* Encodes the given data into a query string format
* @param $data - array of string elements to be encoded
* @return string - encoded request
*/
function _recaptcha_qsencode ($data) {
$req = "";
foreach ( $data as $key => $value )
$req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
// Cut the last '&'
$req=substr($req,0,strlen($req)-1);
return $req;
}
/**
* Submits an HTTP POST to a reCAPTCHA server
* @param string $host
* @param string $path
* @param array $data
* @param int port
* @return array response
*/
function _recaptcha_http_post($host, $path, $data, $port = 80) {
$req = _recaptcha_qsencode ($data);
$http_request = "POST $path HTTP/1.0\r\n";
$http_request .= "Host: $host\r\n";
$http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
$http_request .= "Content-Length: " . strlen($req) . "\r\n";
$http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
$http_request .= "\r\n";
$http_request .= $req;
$response = '';
if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
die ('Could not open socket');
}
fwrite($fs, $http_request);
while ( !feof($fs) )
$response .= fgets($fs, 1160); // One TCP-IP packet
fclose($fs);
$response = explode("\r\n\r\n", $response, 2);
return $response;
}
/**
* Gets the challenge HTML (javascript and non-javascript version).
* This is called from the browser, and the resulting reCAPTCHA HTML widget
* is embedded within the HTML form it was called from.
* @param string $pubkey A public key for reCAPTCHA
* @param string $error The error given by reCAPTCHA (optional, default is null)
* @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
* @return string - The HTML to be embedded in the user's form.
*/
function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
{
if ($pubkey == null || $pubkey == '') {
die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
}
if ($use_ssl) {
$server = RECAPTCHA_API_SECURE_SERVER;
} else {
$server = RECAPTCHA_API_SERVER;
}
$errorpart = "";
if ($error) {
$errorpart = "&amp;error=" . $error;
}
return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
<noscript>
<iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>';
}
/**
* A ReCaptchaResponse is returned from recaptcha_check_answer()
*/
class ReCaptchaResponse {
var $is_valid;
var $error;
}
/**
* Calls an HTTP POST function to verify if the user's guess was correct
* @param string $privkey
* @param string $remoteip
* @param string $challenge
* @param string $response
* @param array $extra_params an array of extra variables to post to the server
* @return ReCaptchaResponse
*/
function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
{
if ($privkey == null || $privkey == '') {
$recaptcha_response = new ReCaptchaResponse();
$recaptcha_response->is_valid = false;
$recaptcha_response->error = 'To use reCAPTCHA you must get an API key from <a href=\'https://www.google.com/recaptcha/admin/create\'>https://www.google.com/recaptcha/admin/create</a>';
return $recaptcha_response;
}
if ($remoteip == null || $remoteip == '') {
$recaptcha_response = new ReCaptchaResponse();
$recaptcha_response->is_valid = false;
$recaptcha_response->error = 'For security reasons, you must pass the remote ip to reCAPTCHA';
return $recaptcha_response;
}
//discard spam submissions
if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
$recaptcha_response = new ReCaptchaResponse();
$recaptcha_response->is_valid = false;
$recaptcha_response->error = 'incorrect-captcha-sol';
return $recaptcha_response;
}
$response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
array (
'privatekey' => $privkey,
'remoteip' => $remoteip,
'challenge' => $challenge,
'response' => $response
) + $extra_params
);
$answers = explode ("\n", $response [1]);
$recaptcha_response = new ReCaptchaResponse();
if (trim ($answers [0]) == 'true') {
$recaptcha_response->is_valid = true;
}
else {
$recaptcha_response->is_valid = false;
$recaptcha_response->error = $answers [1];
}
return $recaptcha_response;
}
/**
* gets a URL where the user can sign up for reCAPTCHA. If your application
* has a configuration page where you enter a key, you should provide a link
* using this function.
* @param string $domain The domain where the page is hosted
* @param string $appname The name of your application
*/
function recaptcha_get_signup_url ($domain = null, $appname = null) {
return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname));
}
function _recaptcha_aes_pad($val) {
$block_size = 16;
$numpad = $block_size - (strlen ($val) % $block_size);
return str_pad($val, strlen ($val) + $numpad, chr($numpad));
}
/* Mailhide related code */
function _recaptcha_aes_encrypt($val,$ky) {
if (! function_exists ("mcrypt_encrypt")) {
die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
}
$mode=MCRYPT_MODE_CBC;
$enc=MCRYPT_RIJNDAEL_128;
$val=_recaptcha_aes_pad($val);
return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
}
function _recaptcha_mailhide_urlbase64 ($x) {
return strtr(base64_encode ($x), '+/', '-_');
}
/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
function recaptcha_mailhide_url($pubkey, $privkey, $email) {
if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
"you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>");
}
$ky = pack('H*', $privkey);
$cryptmail = _recaptcha_aes_encrypt ($email, $ky);
return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
}
/**
* gets the parts of the email to expose to the user.
* eg, given johndoe@example,com return ["john", "example.com"].
* the email is then displayed as john...@example.com
*/
function _recaptcha_mailhide_email_parts ($email) {
$arr = preg_split("/@/", $email );
if (strlen ($arr[0]) <= 4) {
$arr[0] = substr ($arr[0], 0, 1);
} else if (strlen ($arr[0]) <= 6) {
$arr[0] = substr ($arr[0], 0, 3);
} else {
$arr[0] = substr ($arr[0], 0, 4);
}
return $arr;
}
/**
* Gets html to display an email address given a public an private key.
* to get a key, go to:
*
* http://www.google.com/recaptcha/mailhide/apikey
*/
function recaptcha_mailhide_html($pubkey, $privkey, $email) {
$emailparts = _recaptcha_mailhide_email_parts ($email);
$url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
"' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]);
}

View file

@ -0,0 +1,14 @@
<div class="recaptcha-control-group" id="recaptcha-place" style="display: none">
<div class="control-group">
<div id="recaptcha_image" style="border-radius: 3px"></div>
</div>
<div class="control-group">
<div class="input-append">
<input class="i18n inputLoginForm inputCAPTCHA span4" type="text" autocomplete="off"
id="recaptcha_response_field" data-i18n-placeholder="PLUGIN/LABEL_ENTER_THE_WORDS_ABOVE" />
<span class="add-on">
<i class="icon-repeat" onclick="Recaptcha.reload()" style="cursor: pointer"></i>
</span>
</div>
</div>
</div>