This commit is contained in:
the-djmaze 2023-05-16 16:51:42 +02:00
parent 35bfff878d
commit d5a0ac8da8
4 changed files with 73 additions and 34 deletions

View file

@ -1,32 +0,0 @@
<?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));
}

View file

@ -0,0 +1,60 @@
<?php
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
require_once '/var/lib/snappymail/index.php';
$oConfig = \RainLoop\Api::Config();
// Change default login data / key
$oConfig->Set('security', 'admin_login', $argv[1]);
$oConfig->Set('security', 'admin_panel_key', $argv[1]);
$oConfig->SetPassword($argv[2]);
// Allow Contacts to be saved in database
$oConfig->Set('contacts', 'enable', 'On');
$oConfig->Set('contacts', 'allow_sync', 'On');
$oConfig->Set('contacts', 'type', 'mysql');
$oConfig->Set('contacts', 'pdo_dsn', 'mysql:host=127.0.0.1;port=3306;dbname=snappymail');
$oConfig->Set('contacts', 'pdo_user', 'snappymail');
$oConfig->Set('contacts', 'pdo_password', $argv[3]);
// Plugins
$oConfig->Set('plugins', 'enable', 'On');
\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.'configs/plugin-add-x-originating-ip-header.json';
if (!file_exists($sFile)) {
file_put_contents('', json_encode([
'plugin' => [
'check_proxy' => true
]
], JSON_PRETTY_PRINT));
}
$oConfig->Save();
$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));
}

View file

@ -45,6 +45,8 @@ class ChangePasswordHestiaDriver
return false;
}
$this->oLogger->Write("Hestia: Try to change password for {$oAccount->Email()}");
$sHost = $this->oConfig->Get('plugin', 'hestia_login');
$sPort = $this->oConfig->Get('plugin', 'hestia_port');
@ -54,7 +56,15 @@ class ChangePasswordHestiaDriver
'password' => $sPrevPassword,
'new' => $sNewPassword,
);
$cRequest = $HTTP->doRequest('POST','https://'.$sHost.':'.$sPort.'/reset/mail/',http_build_query($postvars));
return '==ok==' == $cRequest->body;
$response = $HTTP->doRequest('POST', 'https://'.$sHost.':'.$sPort.'/reset/mail/', \http_build_query($postvars));
if (!$response) {
$this->oLogger->Write("Hestia[Error]: Response failed");
return false;
}
if ('==ok==' != $response->body) {
$this->oLogger->Write("Hestia[Error]: Response: {$response->status} {$response->body}");
return false;
}
return true;
}
}

View file

@ -84,6 +84,7 @@ trait Messages
$oParams->bHideDeleted = !empty($oSettingsLocal->GetConf('HideDeleted', 1));
}
// \ignore_user_abort(true);
$oMessageList = $this->MailClient()->MessageList($oParams);
if ($sHash) {
$this->cacheByKey($sHash);