Commit dbdd074c authored by Akhil's avatar Akhil 😶
Browse files

Check SQL raw backend config validity

parent 1356b23e
......@@ -6,11 +6,10 @@ use OCP\IConfig;
use OCP\ILogger;
use OCA\EcloudAccounts\Exception\DbConnectionParamsException;
use Doctrine\DBAL\DriverManager;
use Exception;
use Throwable;
class MailboxMapper
{
private $config;
private $conn;
private $logger;
......@@ -22,22 +21,35 @@ class MailboxMapper
$this->initConnection();
}
private function initConnection() {
private function initConnection()
{
try {
$params = $this->getConnectionParams();
$this->conn = DriverManager::getConnection($params);
}
catch(Exception $e) {
} catch (Throwable $e) {
$this->logger->info('Error connecting to SQL raw backend: ' . $e->getMessage());
}
}
private function isDbConfigValid($config) : bool
{
if (!$config || !is_array($config)) {
return false;
}
return isset($config['db_name'])
&& isset($config['mariadb_charset'])
&& isset($config['db_user'])
&& isset($config['db_password'])
&& isset($config['db_host'])
&& isset($config['db_port']) ;
}
private function getConnectionParams()
{
$config = $this->config->getSystemValue('user_backend_sql_raw');
if (!$config) {
throw new DbConnectionParamsException('Database connection params for mailbox not available in config.php!');
if (!$this->isDbConfigValid($config)) {
throw new DbConnectionParamsException('Invalid SQL raw configuration!');
}
$params = [
......
......@@ -10,6 +10,7 @@ use OCA\EcloudAccounts\AppInfo\Application;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\ILogger;
use OCP\IConfig;
use OCP\User\Events\BeforeUserDeletedEvent;
use OCA\EcloudAccounts\Service\LDAPConnectionService;
......@@ -18,11 +19,13 @@ require_once 'curl.class.php';
class BeforeUserDeletedListener implements IEventListener
{
private $logger;
private $config;
private $LDAPConnectionService;
public function __construct(ILogger $logger, LDAPConnectionService $LDAPConnectionService)
public function __construct(ILogger $logger, IConfig $config, LDAPConnectionService $LDAPConnectionService)
{
$this->logger = $logger;
$this->config = $config;
$this->LDAPConnectionService = $LDAPConnectionService;
}
......@@ -71,9 +74,9 @@ class BeforeUserDeletedListener implements IEventListener
*/
public function ecloudDelete(string $userID, string $welcomeDomain, string $welcomeSecret, string $email, bool $isUserOnLDAP = false)
{
$endpoint = 'postDelete.php';
$endpoint = '/postDelete.php';
if ($isUserOnLDAP) {
$endpoint = 'postDeleteLDAP.php';
$endpoint = '/postDeleteLDAP.php';
}
$postDeleteUrl = "https://" . $welcomeDomain . $endpoint;
$curl = new Curl();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment