mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 03:59:21 +03:00
Changes for #1128
This commit is contained in:
parent
a504fd9298
commit
35bfff878d
3 changed files with 59 additions and 51 deletions
32
integrations/hestiacp/hestia.php
Normal file
32
integrations/hestiacp/hestia.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
|
||||
require_once '/var/lib/snappymail/index.php';
|
||||
|
||||
\SnappyMail\Repository::installPackage('plugin', 'change-password');
|
||||
\SnappyMail\Repository::installPackage('plugin', 'change-password-hestia');
|
||||
$sFile = APP_PRIVATE_DATA.'configs/plugin-change-password.json';
|
||||
if (!file_exists($sFile)) {
|
||||
file_put_contents('', json_encode([
|
||||
'plugin' => [
|
||||
'pass_min_length': 8,
|
||||
'pass_min_strength': 60,
|
||||
'driver_hestia_enabled': true,
|
||||
'driver_hestia_allowed_emails': '*',
|
||||
'hestia_host': gethostname(),
|
||||
'hestia_port': 8083 // $BACKEND_PORT
|
||||
]
|
||||
], JSON_PRETTY_PRINT));
|
||||
}
|
||||
// \SnappyMail\Repository::enablePackage('change-password');
|
||||
|
||||
\SnappyMail\Repository::installPackage('plugin', 'add-x-originating-ip-header');
|
||||
// \SnappyMail\Repository::enablePackage('add-x-originating-ip-header');
|
||||
|
||||
$sFile = APP_PRIVATE_DATA.'domains/hestia.json';
|
||||
if (!file_exists($sFile)) {
|
||||
$config = json_decode(file_get_contents(__DIR__ . '/app/domains/default.json'), true);
|
||||
$config['IMAP']['shortLogin'] = true;
|
||||
$config['SMTP']['shortLogin'] = true;
|
||||
file_put_contents($sFile, json_encode($config, JSON_PRETTY_PRINT));
|
||||
}
|
||||
|
|
@ -57,8 +57,8 @@ fi
|
|||
# Get current version
|
||||
if [ -f "/var/lib/snappymail/data/VERSION" ]; then
|
||||
version=$(cat $SM_INSTALL_DIR/data/VERSION);
|
||||
if [ "$version" == "$rl_v" ]; then
|
||||
echo "Error: Installed version ($version) is equal to the available version ($rl_v)"
|
||||
if [ "$version" == "$sm_v" ]; then
|
||||
echo "Error: Installed version ($version) is equal to the available version ($sm_v)"
|
||||
exit 2;
|
||||
else
|
||||
UPDATE="yes"
|
||||
|
|
@ -80,13 +80,19 @@ if [ "$UPDATE" == "no" ]; then
|
|||
mkdir $SM_CONFIG_DIR
|
||||
|
||||
cd "$SM_INSTALL_DIR"
|
||||
[ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$SM_URL" --retry-connrefused --quiet -O "${SM_INSTALL_DIR}/${SM_FILE}"
|
||||
[ ! -f "${SM_INSTALL_DIR}/${SM_FILE}" ] && wget "$SM_URL" --retry-connrefused --quiet -O "${SM_INSTALL_DIR}/${SM_FILE}"
|
||||
|
||||
if [ -f "${SM_INSTALL_DIR}/${SM_FILE}" ]; then
|
||||
echo "ERROR: Download failed, installation aborted."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Get current version
|
||||
|
||||
key=$(openssl rand -hex 4);
|
||||
|
||||
admin_account="admin_$key"
|
||||
admin_password=$(generate_password)
|
||||
r=$(generate_password)
|
||||
|
||||
echo "Username: admin_$key" > ~/.snappymail
|
||||
echo "Password: $admin_password" >> ~/.snappymail
|
||||
|
|
@ -97,12 +103,6 @@ if [ "$UPDATE" == "no" ]; then
|
|||
mv ./data $SM_CONFIG_DIR/
|
||||
ln -s $SM_CONFIG_DIR/data/ ./data
|
||||
|
||||
SALT=$(openssl rand -base64 64)
|
||||
cp ./data/VERSION ./data/INSTALLED
|
||||
echo "<?php //$SALT" > ./data/SALT.php
|
||||
echo "Forbidden" > ./data/index.php
|
||||
echo "Forbidden" > ./data/index.html
|
||||
|
||||
# Create database
|
||||
mysql -e "CREATE DATABASE snappymail"
|
||||
# Mysql available on system
|
||||
|
|
@ -110,23 +110,7 @@ if [ "$UPDATE" == "no" ]; then
|
|||
mysql -e "GRANT ALL ON snappymail.*
|
||||
TO snappymail@localhost IDENTIFIED BY '$r'"
|
||||
|
||||
mkdir -p $SM_CONFIG_DIR/data/_data_/_default_/configs
|
||||
php -f $HESTIA_INSTALL_DIR/snappymail/change_password.php "admin_$key" "$admin_password" "$r"
|
||||
mkdir -p $SM_CONFIG_DIR/data/_data_/_default_/domains
|
||||
cp -f $HESTIA_INSTALL_DIR/snappymail/default.ini $SM_CONFIG_DIR/data/_data_/_default_/domains
|
||||
mkdir -p $SM_CONFIG_DIR/data/_data_/_default_/plugins
|
||||
cp -f -r $HESTIA_INSTALL_DIR/snappymail/plugins/hestia-change-password/ $SM_CONFIG_DIR/data/_data_/_default_/plugins
|
||||
mkdir -p $SM_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header
|
||||
# Download add-x-originating-ip-header from snappymail github
|
||||
wget --quiet -O $SM_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/index.php https://raw.githubusercontent.com/the-djmaze/snappymail/master/plugins/add-x-originating-ip-header/index.php
|
||||
wget --quiet -O $SM_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/LICENSE https://raw.githubusercontent.com/the-djmaze/snappymail/master/plugins/add-x-originating-ip-header/LICENSE
|
||||
|
||||
cp -f $HESTIA_INSTALL_DIR/snappymail/plugins/plugin-add-x-originating-ip-header.ini $SM_CONFIG_DIR/data/_data_/_default_/configs/plugin-add-x-originating-ip-header.ini
|
||||
cp -f $HESTIA_INSTALL_DIR/snappymail/plugins/plugin-hestia-change-password.ini $SM_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
|
||||
|
||||
sed -i "s/%hostname%/$(hostname)/g" $SM_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
|
||||
sed -i "s/%port%/$BACKEND_PORT/g" $SM_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
|
||||
|
||||
php -f $HESTIA_INSTALL_DIR/snappymail/hestia.php "admin_$key" "$admin_password" "$r"
|
||||
|
||||
chown -R www-data:www-data ./data
|
||||
chown -R www-data:www-data $SM_CONFIG_DIR/
|
||||
|
|
@ -150,7 +134,7 @@ if [ "$UPDATE" == "no" ]; then
|
|||
fi
|
||||
|
||||
else
|
||||
[ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$SM_URL" --quiet -O "${SM_INSTALL_DIR}/${SM_FILE}"
|
||||
[ ! -f "${SM_INSTALL_DIR}/${SM_FILE}" ] && wget "$SM_URL" --quiet -O "${SM_INSTALL_DIR}/${SM_FILE}"
|
||||
version=$(cat $SM_INSTALL_DIR/data/VERSION);
|
||||
|
||||
tar -xzf snappymail-latest.tar.gz "data/VERSION" $SM_INSTALL_DIR/
|
||||
|
|
|
|||
|
|
@ -35,34 +35,26 @@ class ChangePasswordHestiaDriver
|
|||
->SetDescription('Ex: localhost or domain.com'),
|
||||
\RainLoop\Plugins\Property::NewInstance('hestia_port')->SetLabel('Hestia Port')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
|
||||
->SetDefaultValue(8083),
|
||||
\RainLoop\Plugins\Property::NewInstance('hestia_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('*')
|
||||
->SetDefaultValue(8083)
|
||||
);
|
||||
}
|
||||
|
||||
public function ChangePassword(\RainLoop\Model\Account $oAccount, string $sPrevPassword, string $sNewPassword) : bool
|
||||
{
|
||||
if (!\RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->oConfig->Get('plugin', 'hestia_allowed_emails', ''))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sHost = $this->oConfig->Get('plugin', 'hestia_login');
|
||||
$sPort = $this->oConfig->Get('plugin', 'hestia_port');
|
||||
|
||||
$HTTP = \SnappyMail\HTTP\Request::factory();
|
||||
$postvars = array(
|
||||
'email' => $oAccount->Email(),
|
||||
'password' => $sPrevPassword,
|
||||
'new' => $sNewPassword,
|
||||
);
|
||||
$cRequest = $HTTP->doRequest('POST','https://'.$sHost.':'.$sPort.'/reset/mail/',http_build_query($postvars));
|
||||
if($cRequest -> body == '==ok=='){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$sHost = $this->oConfig->Get('plugin', 'hestia_login');
|
||||
$sPort = $this->oConfig->Get('plugin', 'hestia_port');
|
||||
|
||||
$HTTP = \SnappyMail\HTTP\Request::factory();
|
||||
$postvars = array(
|
||||
'email' => $oAccount->Email(),
|
||||
'password' => $sPrevPassword,
|
||||
'new' => $sNewPassword,
|
||||
);
|
||||
$cRequest = $HTTP->doRequest('POST','https://'.$sHost.':'.$sPort.'/reset/mail/',http_build_query($postvars));
|
||||
return '==ok==' == $cRequest->body;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue