commit
ed7144950b
@ -26,6 +26,7 @@ RUN echo "@community https://nl.alpinelinux.org/alpine/v3.7/community" >> /etc/a
|
|||||||
php7-openssl@community \
|
php7-openssl@community \
|
||||||
php7-json@community \
|
php7-json@community \
|
||||||
php7-zlib@community \
|
php7-zlib@community \
|
||||||
|
php7-pdo_pgsql@community \
|
||||||
php7-pdo_mysql@community \
|
php7-pdo_mysql@community \
|
||||||
php7-pdo_sqlite@community \
|
php7-pdo_sqlite@community \
|
||||||
php7-sqlite3@community \
|
php7-sqlite3@community \
|
||||||
|
@ -11,7 +11,7 @@ Rainloop is a simple, modern & fast web-based client. More details on the [offic
|
|||||||
- Lightweight & secure image (no root process)
|
- Lightweight & secure image (no root process)
|
||||||
- Based on Alpine
|
- Based on Alpine
|
||||||
- Latest Rainloop **Community Edition** (stable)
|
- Latest Rainloop **Community Edition** (stable)
|
||||||
- Contacts (DB) : sqlite, or mysql (server not built-in)
|
- Contacts (DB) : sqlite, mysql or pgsql (server not built-in)
|
||||||
- With Nginx and PHP7
|
- With Nginx and PHP7
|
||||||
- Postfixadmin-change-password plugin
|
- Postfixadmin-change-password plugin
|
||||||
|
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
class ChangePasswordPostfixAdminDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
|
class ChangePasswordPostfixAdminDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $sEngine = 'MySQL';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -57,6 +62,17 @@ class ChangePasswordPostfixAdminDriver implements \RainLoop\Providers\ChangePass
|
|||||||
*/
|
*/
|
||||||
private $oLogger = null;
|
private $oLogger = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sEngine
|
||||||
|
*
|
||||||
|
* @return \ChangePasswordPostfixAdminDriver
|
||||||
|
*/
|
||||||
|
public function SetEngine($sEngine)
|
||||||
|
{
|
||||||
|
$this->sEngine = $sEngine;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $sHost
|
* @param string $sHost
|
||||||
*
|
*
|
||||||
@ -215,7 +231,19 @@ class ChangePasswordPostfixAdminDriver implements \RainLoop\Providers\ChangePass
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$sDsn = 'mysql:host='.$this->sHost.';port='.$this->iPort.';dbname='.$this->sDatabase;
|
$sDsn = '';
|
||||||
|
switch($this->sEngine){
|
||||||
|
case 'MySQL':
|
||||||
|
$sDsn = 'mysql:host='.$this->sHost.';port='.$this->iPort.';dbname='.$this->sDatabase;
|
||||||
|
break;
|
||||||
|
case 'PostgreSQL':
|
||||||
|
$sDsn = 'pgsql:host='.$this->sHost.';port='.$this->iPort.';dbname='.$this->sDatabase;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$sDsn = 'mysql:host='.$this->sHost.';port='.$this->iPort.';dbname='.$this->sDatabase;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$oPdo = new \PDO($sDsn, $this->sUser, $this->sPassword);
|
$oPdo = new \PDO($sDsn, $this->sUser, $this->sPassword);
|
||||||
$oPdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
$oPdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||||
@ -267,6 +295,11 @@ class ChangePasswordPostfixAdminDriver implements \RainLoop\Providers\ChangePass
|
|||||||
$sResult = '{PLAIN}' . $sPassword;
|
$sResult = '{PLAIN}' . $sPassword;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'md5crypt':
|
||||||
|
include_once __DIR__.'/md5crypt.php';
|
||||||
|
$sResult = '{MD5-CRYPT}' . md5crypt($sPassword);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'md5':
|
case 'md5':
|
||||||
$sResult = '{PLAIN-MD5}' . md5($sPassword);
|
$sResult = '{PLAIN-MD5}' . md5($sPassword);
|
||||||
break;
|
break;
|
||||||
@ -284,7 +317,8 @@ class ChangePasswordPostfixAdminDriver implements \RainLoop\Providers\ChangePass
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'mysql_encrypt':
|
case 'mysql_encrypt':
|
||||||
$oStmt = $oPdo->prepare('SELECT ENCRYPT(?) AS encpass');
|
if($this->sEngine == 'MySQL'){
|
||||||
|
$oStmt = $oPdo->prepare('SELECT ENCRYPT(?) AS encpass');
|
||||||
if ($oStmt->execute(array($sPassword)))
|
if ($oStmt->execute(array($sPassword)))
|
||||||
{
|
{
|
||||||
$aFetchResult = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
|
$aFetchResult = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
@ -293,7 +327,10 @@ class ChangePasswordPostfixAdminDriver implements \RainLoop\Providers\ChangePass
|
|||||||
$sResult = $aFetchResult[0]['encpass'];
|
$sResult = $aFetchResult[0]['encpass'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
}else{
|
||||||
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CouldNotSaveNewPassword);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sResult;
|
return $sResult;
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2015 RainLoop Team, @zaffkea
|
||||||
|
|
||||||
|
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.
|
@ -0,0 +1 @@
|
|||||||
|
Plugin that adds functionality to change the email account password (PostfixAdmin).
|
@ -0,0 +1 @@
|
|||||||
|
1.3
|
@ -1,95 +1,100 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class PostfixadminChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
|
class PostfixadminChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
{
|
{
|
||||||
public function Init()
|
public function Init()
|
||||||
{
|
{
|
||||||
$this->addHook('main.fabrica', 'MainFabrica');
|
$this->addHook('main.fabrica', 'MainFabrica');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function Supported()
|
public function Supported()
|
||||||
{
|
{
|
||||||
if (!extension_loaded('pdo') || !class_exists('PDO'))
|
if (!extension_loaded('pdo') || !class_exists('PDO'))
|
||||||
{
|
{
|
||||||
return 'The PHP exention PDO (mysql) must be installed to use this plugin';
|
return 'The PHP extension PDO must be installed to use this plugin';
|
||||||
}
|
}
|
||||||
|
|
||||||
$aDrivers = \PDO::getAvailableDrivers();
|
$aDrivers = \PDO::getAvailableDrivers();
|
||||||
if (!is_array($aDrivers) || !in_array('mysql', $aDrivers))
|
if (!is_array($aDrivers) || (!in_array('mysql', $aDrivers) && !in_array('pgsql', $aDrivers)))
|
||||||
{
|
{
|
||||||
return 'The PHP exention PDO (mysql) must be installed to use this plugin';
|
return 'The PHP extension PDO (mysql or pgsql) must be installed to use this plugin';
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $sName
|
* @param string $sName
|
||||||
* @param mixed $oProvider
|
* @param mixed $oProvider
|
||||||
*/
|
*/
|
||||||
public function MainFabrica($sName, &$oProvider)
|
public function MainFabrica($sName, &$oProvider)
|
||||||
{
|
{
|
||||||
switch ($sName)
|
switch ($sName)
|
||||||
{
|
{
|
||||||
case 'change-password':
|
case 'change-password':
|
||||||
|
|
||||||
include_once __DIR__.'/ChangePasswordPostfixAdminDriver.php';
|
include_once __DIR__.'/ChangePasswordPostfixAdminDriver.php';
|
||||||
|
|
||||||
$oProvider = new ChangePasswordPostfixAdminDriver();
|
$oProvider = new ChangePasswordPostfixAdminDriver();
|
||||||
|
|
||||||
$oProvider
|
$oProvider
|
||||||
->SetHost($this->Config()->Get('plugin', 'host', ''))
|
->SetEngine($this->Config()->Get('plugin', 'engine',''))
|
||||||
->SetPort((int) $this->Config()->Get('plugin', 'port', 3306))
|
->SetHost($this->Config()->Get('plugin', 'host', ''))
|
||||||
->SetDatabase($this->Config()->Get('plugin', 'database', ''))
|
->SetPort((int) $this->Config()->Get('plugin', 'port', 3306))
|
||||||
->SetTable($this->Config()->Get('plugin', 'table', ''))
|
->SetDatabase($this->Config()->Get('plugin', 'database', ''))
|
||||||
->SetUserColumn($this->Config()->Get('plugin', 'usercol', ''))
|
->SetTable($this->Config()->Get('plugin', 'table', ''))
|
||||||
->SetPasswordColumn($this->Config()->Get('plugin', 'passcol', ''))
|
->SetUserColumn($this->Config()->Get('plugin', 'usercol', ''))
|
||||||
->SetUser($this->Config()->Get('plugin', 'user', ''))
|
->SetPasswordColumn($this->Config()->Get('plugin', 'passcol', ''))
|
||||||
->SetPassword($this->Config()->Get('plugin', 'password', ''))
|
->SetUser($this->Config()->Get('plugin', 'user', ''))
|
||||||
->SetEncrypt($this->Config()->Get('plugin', 'encrypt', ''))
|
->SetPassword($this->Config()->Get('plugin', 'password', ''))
|
||||||
->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))))
|
->SetEncrypt($this->Config()->Get('plugin', 'encrypt', ''))
|
||||||
->SetLogger($this->Manager()->Actions()->Logger())
|
->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))))
|
||||||
;
|
->SetLogger($this->Manager()->Actions()->Logger())
|
||||||
|
;
|
||||||
break;
|
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
* @return array
|
/**
|
||||||
*/
|
* @return array
|
||||||
public function configMapping()
|
*/
|
||||||
{
|
public function configMapping()
|
||||||
return array(
|
{
|
||||||
\RainLoop\Plugins\Property::NewInstance('host')->SetLabel('MySQL Host')
|
return array(
|
||||||
->SetDefaultValue('mariadb'),
|
\RainLoop\Plugins\Property::NewInstance('engine')->SetLabel('Engine')
|
||||||
\RainLoop\Plugins\Property::NewInstance('port')->SetLabel('MySQL Port')
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::SELECTION)
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
|
->SetDefaultValue(array('MySQL', 'PostgreSQL'))
|
||||||
->SetDefaultValue(3306),
|
->SetDescription('Database Engine'),
|
||||||
\RainLoop\Plugins\Property::NewInstance('database')->SetLabel('MySQL Database')
|
\RainLoop\Plugins\Property::NewInstance('host')->SetLabel('Host')
|
||||||
->SetDefaultValue('postfix'),
|
->SetDefaultValue('127.0.0.1'),
|
||||||
\RainLoop\Plugins\Property::NewInstance('table')->SetLabel('MySQL table')
|
\RainLoop\Plugins\Property::NewInstance('port')->SetLabel('Port')
|
||||||
->SetDefaultValue('mailbox'),
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
|
||||||
\RainLoop\Plugins\Property::NewInstance('usercol')->SetLabel('MySQL username column')
|
->SetDefaultValue(3306),
|
||||||
->SetDefaultValue('username'),
|
\RainLoop\Plugins\Property::NewInstance('database')->SetLabel('Database')
|
||||||
\RainLoop\Plugins\Property::NewInstance('passcol')->SetLabel('MySQL password column')
|
->SetDefaultValue('postfixadmin'),
|
||||||
->SetDefaultValue('password'),
|
\RainLoop\Plugins\Property::NewInstance('table')->SetLabel('table')
|
||||||
\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('MySQL User')
|
->SetDefaultValue('mailbox'),
|
||||||
->SetDefaultValue('postfix'),
|
\RainLoop\Plugins\Property::NewInstance('usercol')->SetLabel('username column')
|
||||||
\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('MySQL Password')
|
->SetDefaultValue('username'),
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
|
\RainLoop\Plugins\Property::NewInstance('passcol')->SetLabel('password column')
|
||||||
->SetDefaultValue(''),
|
->SetDefaultValue('password'),
|
||||||
\RainLoop\Plugins\Property::NewInstance('encrypt')->SetLabel('Encrypt')
|
\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('User')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::SELECTION)
|
->SetDefaultValue('postfixadmin'),
|
||||||
->SetDefaultValue(array('SHA512-CRYPT','SHA256-CRYPT','md5', 'system', 'cleartext', 'mysql_encrypt'))
|
\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('Password')
|
||||||
->SetDescription('In what way do you want the passwords to be crypted ?'),
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
|
||||||
\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
|
->SetDefaultValue(''),
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
|
\RainLoop\Plugins\Property::NewInstance('encrypt')->SetLabel('Encrypt')
|
||||||
->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: user1@domain1.net user2@domain1.net *@domain2.net')
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::SELECTION)
|
||||||
->SetDefaultValue('*')
|
->SetDefaultValue(array('md5crypt', 'md5', 'system', 'cleartext', 'mysql_encrypt', 'SHA256-CRYPT', 'SHA512-CRYPT'))
|
||||||
);
|
->SetDescription('In what way do you want the passwords to be crypted ?'),
|
||||||
}
|
\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
|
||||||
}
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
|
||||||
|
->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: user1@domain1.net user2@domain1.net *@domain2.net')
|
||||||
|
->SetDefaultValue('*')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -0,0 +1,139 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// md5crypt
|
||||||
|
// Action: Creates MD5 encrypted password
|
||||||
|
// Call: md5crypt (string cleartextpassword)
|
||||||
|
|
||||||
|
function md5crypt($pw, $salt = "", $magic = "")
|
||||||
|
{
|
||||||
|
$MAGIC = "$1$";
|
||||||
|
|
||||||
|
if ($magic == "")
|
||||||
|
{
|
||||||
|
$magic = $MAGIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($salt == "")
|
||||||
|
{
|
||||||
|
$salt = create_salt();
|
||||||
|
}
|
||||||
|
|
||||||
|
$slist = explode("$", $salt);
|
||||||
|
if (isset($slist[0]) && $slist[0] == "1")
|
||||||
|
{
|
||||||
|
$salt = $slist[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
$salt = substr($salt, 0, 8);
|
||||||
|
$ctx = $pw.$magic.$salt;
|
||||||
|
$final = hex2bin(md5($pw.$salt.$pw));
|
||||||
|
|
||||||
|
for ($i = strlen($pw); $i > 0; $i -= 16)
|
||||||
|
{
|
||||||
|
if ($i > 16)
|
||||||
|
{
|
||||||
|
$ctx .= substr($final,0,16);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$ctx .= substr($final,0,$i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$i = strlen($pw);
|
||||||
|
|
||||||
|
while ($i > 0)
|
||||||
|
{
|
||||||
|
if ($i & 1)
|
||||||
|
{
|
||||||
|
$ctx .= chr(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$ctx .= $pw[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
$i = $i >> 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$final = hex2bin(md5($ctx));
|
||||||
|
|
||||||
|
for ($i=0; $i<1000; $i++)
|
||||||
|
{
|
||||||
|
$ctx1 = "";
|
||||||
|
if ($i & 1)
|
||||||
|
{
|
||||||
|
$ctx1 .= $pw;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$ctx1 .= substr($final,0,16);
|
||||||
|
}
|
||||||
|
if ($i % 3)
|
||||||
|
{
|
||||||
|
$ctx1 .= $salt;
|
||||||
|
}
|
||||||
|
if ($i % 7)
|
||||||
|
{
|
||||||
|
$ctx1 .= $pw;
|
||||||
|
}
|
||||||
|
if ($i & 1)
|
||||||
|
{
|
||||||
|
$ctx1 .= substr($final, 0, 16);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$ctx1 .= $pw;
|
||||||
|
}
|
||||||
|
|
||||||
|
$final = hex2bin(md5($ctx1));
|
||||||
|
}
|
||||||
|
|
||||||
|
$passwd = "";
|
||||||
|
$passwd .= to64(((ord($final[0]) << 16) | (ord($final[6]) << 8) | (ord($final[12]))), 4);
|
||||||
|
$passwd .= to64(((ord($final[1]) << 16) | (ord($final[7]) << 8) | (ord($final[13]))), 4);
|
||||||
|
$passwd .= to64(((ord($final[2]) << 16) | (ord($final[8]) << 8) | (ord($final[14]))), 4);
|
||||||
|
$passwd .= to64(((ord($final[3]) << 16) | (ord($final[9]) << 8) | (ord($final[15]))), 4);
|
||||||
|
$passwd .= to64(((ord($final[4]) << 16) | (ord($final[10]) << 8) | (ord($final[5]))), 4);
|
||||||
|
$passwd .= to64(ord($final[11]), 2);
|
||||||
|
|
||||||
|
return $magic.$salt.'$'.$passwd;
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_salt()
|
||||||
|
{
|
||||||
|
srand((double) microtime() * 1000000);
|
||||||
|
return substr(md5(rand(0,9999999)), 0, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PHP around 5.3.8 includes hex2bin as native function - http://php.net/hex2bin
|
||||||
|
if (!function_exists('hex2bin'))
|
||||||
|
{
|
||||||
|
function hex2bin($str)
|
||||||
|
{
|
||||||
|
$len = strlen($str);
|
||||||
|
$nstr = "";
|
||||||
|
for ($i = 0; $i < $len; $i += 2)
|
||||||
|
{
|
||||||
|
$num = sscanf(substr($str, $i, 2), "%x");
|
||||||
|
$nstr .= chr($num[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $nstr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function to64($v, $n)
|
||||||
|
{
|
||||||
|
$ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||||
|
$ret = "";
|
||||||
|
|
||||||
|
while (($n - 1) >= 0)
|
||||||
|
{
|
||||||
|
$n--;
|
||||||
|
$ret .= $ITOA64[$v & 0x3f];
|
||||||
|
$v = $v >> 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user