mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-06 23:07:56 +08:00
Add files via upload
This commit is contained in:
parent
4d6f22c336
commit
442caf4f90
6 changed files with 300 additions and 0 deletions
10
plugins/change-passwords-customsql/README.md
Normal file
10
plugins/change-passwords-customsql/README.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
Rainloop change password custom mysql plugin
|
||||
============================================
|
||||
|
||||
This plugin adds change password capability to Rainloop webmail by write your own SQL statement
|
||||
|
||||
##### Installation is simple:
|
||||
|
||||
1. Drop the change-password-customsql in the plugins directory (eg. _RainLoopDir_/data/data_xxxxx/_default/plugins/*)
|
||||
2. In rainloop admin panel go to Plugins, and activate change-password-customsql.
|
||||
3. Enter mysql details on the plugin config screen.
|
|
@ -0,0 +1,211 @@
|
|||
<?php
|
||||
|
||||
class ChangePasswordCustomSqlDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $mHost = '127.0.0.1';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $mUser = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $mPass = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $mDatabase = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $mTable = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $mSql = '';
|
||||
|
||||
/**
|
||||
* @var \MailSo\Log\Logger
|
||||
*/
|
||||
private $oLogger = null;
|
||||
|
||||
/**
|
||||
* @param string $mHost
|
||||
*
|
||||
* @return \ChangePasswordCustomSqlDriver
|
||||
*/
|
||||
public function SetmHost($mHost)
|
||||
{
|
||||
$this->mHost = $mHost;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mUser
|
||||
*
|
||||
* @return \ChangePasswordCustomSqlDriver
|
||||
*/
|
||||
public function SetmUser($mUser)
|
||||
{
|
||||
$this->mUser = $mUser;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mPass
|
||||
*
|
||||
* @return \ChangePasswordCustomSqlDriver
|
||||
*/
|
||||
public function SetmPass($mPass)
|
||||
{
|
||||
$this->mPass = $mPass;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mDatabase
|
||||
*
|
||||
* @return \ChangePasswordCustomSqlDriver
|
||||
*/
|
||||
public function SetmDatabase($mDatabase)
|
||||
{
|
||||
$this->mDatabase = $mDatabase;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mTable
|
||||
*
|
||||
* @return \ChangePasswordCustomSqlDriver
|
||||
*/
|
||||
public function SetmTable($mTable)
|
||||
{
|
||||
$this->mTable = $mTable;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mSql
|
||||
*
|
||||
* @return \ChangePasswordCustomSqlDriver
|
||||
*/
|
||||
public function SetmSql($mSql)
|
||||
{
|
||||
$this->mSql = $mSql;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \MailSo\Log\Logger $oLogger
|
||||
*
|
||||
* @return \ChangePasswordCustomSqlDriver
|
||||
*/
|
||||
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->Email() &&
|
||||
\RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->sAllowedEmails);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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());
|
||||
}
|
||||
|
||||
$bResult = false;
|
||||
|
||||
$dsn = 'mysql:host='.$this->mHost.';dbname='.$this->mDatabase.';charset=utf8';
|
||||
$options = array(
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
PDO::ATTR_PERSISTENT => true,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO($dsn,$this->mUser,$this->mPass,$options);
|
||||
|
||||
//prepare SQL varaibles
|
||||
$sEmail = $oAccount->Email();
|
||||
$sEmailUser = \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail);
|
||||
$sEmailDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail);
|
||||
|
||||
//simple check
|
||||
|
||||
$old = array(':email', ':oldpass', ':newpass', ':domain', ':username', ':table' );
|
||||
$new = array($sEmail, $sPrevPassword, $sNewPassword, $sEmailDomain, $sEmailUser, $this->mTable);
|
||||
|
||||
$this->mSql = str_replace($old, $new, $this->mSql);
|
||||
|
||||
$update = $conn->prepare($this->mSql);
|
||||
$mSqlReturn = $update->execute(array());
|
||||
/* $mSqlReturn = $update->execute(array(
|
||||
':email' => $sEmail,
|
||||
':oldpass' => $sPrevPassword,
|
||||
':newpass' => $sNewPassword,
|
||||
':domain' => $sEmailDomain,
|
||||
':username' => $sEmailUser,
|
||||
':table' => $this->mTable
|
||||
));
|
||||
*/
|
||||
if ($mSqlReturn == true)
|
||||
{
|
||||
$bResult = true;
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Success! Password changed.');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$bResult = false;
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Something went wrong. Either current password is incorrect, or new password does not match criteria.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
{
|
||||
$bResult = false;
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->WriteException($oException);
|
||||
}
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Martin Vilimovsky (vilimovsky@mvcs.cz)
|
||||
|
||||
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 @@
|
|||
You can use your own SQL (MySQL) statement (with wildcards) to change password
|
|
@ -0,0 +1 @@
|
|||
1.0
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
class ChangePasswordCustomSqlPlugin 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__.'/ChangePasswordCustomSqlDriver.php';
|
||||
|
||||
$oProvider = new ChangePasswordCustomSqlDriver();
|
||||
|
||||
$oProvider
|
||||
->SetLogger($this->Manager()->Actions()->Logger())
|
||||
->SetmHost($this->Config()->Get('plugin', 'mHost', ''))
|
||||
->SetmUser($this->Config()->Get('plugin', 'mUser', ''))
|
||||
->SetmPass($this->Config()->Get('plugin', 'mPass', ''))
|
||||
->SetmDatabase($this->Config()->Get('plugin', 'mDatabase', ''))
|
||||
->SetmTable($this->Config()->Get('plugin', 'mTable', ''))
|
||||
->SetmSql($this->Config()->Get('plugin', 'mSql', ''))
|
||||
;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function configMapping()
|
||||
{
|
||||
return array(
|
||||
\RainLoop\Plugins\Property::NewInstance('mHost')->SetLabel('MySQL Host')
|
||||
->SetDefaultValue('127.0.0.1'),
|
||||
\RainLoop\Plugins\Property::NewInstance('mUser')->SetLabel('MySQL User'),
|
||||
\RainLoop\Plugins\Property::NewInstance('mPass')->SetLabel('MySQL Password')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD),
|
||||
\RainLoop\Plugins\Property::NewInstance('mDatabase')->SetLabel('MySQL Database'),
|
||||
\RainLoop\Plugins\Property::NewInstance('mTable')->SetLabel('MySQL Table'),
|
||||
\RainLoop\Plugins\Property::NewInstance('mSql')->SetLabel('SQL statement')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
|
||||
->SetDescription('SQL statement (allowed wildcards :table, :email, :oldpass, :newpass, :domain, :username).When using MD5 OR SHA1 at tables, write it directly here as SQL functions. Fro non-SQL encryptions use another plugin or wait for new version.')
|
||||
->SetDefaultValue('UPDATE :table SET password = md5(:newpass) WHERE domain = :domain AND username = :username and oldpass = md5(:oldpass)')
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue